Files
EPEEAIKit/.cursor/rules/project/local-env-check.mdc

48 lines
1.6 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
description: 检查本地环境配置文件 .cursor/local-env.json 是否存在,不存在时自动探测并生成
globs:
alwaysApply: true
---
## 本地环境配置自动初始化
每次会话处理用户第一个任务前,检查 `.cursor/local-env.json` 是否存在:
### 文件存在时
读取并验证 JSON 格式正确、包含 `nodejs_path` 和 `shell` 两个字段。
字段缺失时补充探测(见下方流程),不覆盖已有字段。
### 文件不存在时
执行自动探测流程,生成 `.cursor/local-env.json`
```
1. 探测 shell 类型:
- Windows$env:OS 包含 "Windows")→ "powershell"
- macOS/Linux → 读取 $SHELL 环境变量末段bash/zsh/fish 等)
2. 探测 Node.js 路径:
- Windows运行 `where.exe node`,排除 Cursor 内置的 node
(路径含 "cursor" 的不算),取第一个有效结果的父目录
- macOS/Linux运行 `which node`,取父目录
- 找不到 → 设为 null
3. 写入 .cursor/local-env.json
{
"nodejs_path": "<探测到的路径或 null>",
"shell": "<探测到的 shell>"
}
4. 简要告知用户:
> 已自动生成本地环境配置 `.cursor/local-env.json`
> 检测到 Node.js 路径为 xxxshell 为 xxx。如需调整请手动编辑该文件。
```
### 注意事项
- `local-env.json` 已在 `.gitignore` 中,不会进入版本控制
- 该文件存储**设备绑定**的配置,与 `.env`(存储密钥/API key互补
- 只在文件不存在或字段缺失时触发探测,不会每次会话都重新探测
- 探测结果不一定准确(如多个 Node.js 版本并存),用户可随时手动修改