docs: 补充 Windows PowerShell 命令约束 (#28)
This commit is contained in:
@@ -181,6 +181,11 @@
|
|||||||
- 优先运行项目档案中记录的格式检查、静态检查、单元测试和必要的集成测试。
|
- 优先运行项目档案中记录的格式检查、静态检查、单元测试和必要的集成测试。
|
||||||
- 不能验证的真机、生产、迁移或并发行为必须写入工单;存在明确要求的任务快照时再同步记录。
|
- 不能验证的真机、生产、迁移或并发行为必须写入工单;存在明确要求的任务快照时再同步记录。
|
||||||
- Windows 环境优先使用当前已配置的 PowerShell;可选择时优先 PowerShell 7 `pwsh.exe`,不得仅为设置编码重复启动一层 PowerShell。
|
- Windows 环境优先使用当前已配置的 PowerShell;可选择时优先 PowerShell 7 `pwsh.exe`,不得仅为设置编码重复启动一层 PowerShell。
|
||||||
|
- Windows 命令不得默认套用 Bash 的 heredoc、变量、路径、引号或转义语法;只有明确调用 Bash、WSL 或 Git Bash,并确认路径与编码边界时才使用。
|
||||||
|
- PowerShell 中不需要变量展开的正则优先使用单引号;复杂正则优先使用变量或 `rg -e`,不得为了避开转义而改变查询语义或堆叠重复搜索。
|
||||||
|
- 多行 Python 使用单引号 PowerShell here-string 管道给 `python -`;起始标记后立即换行,结束标记单独占一行,不使用 Bash heredoc。
|
||||||
|
- `foreach`、`if` 等语句块的输出进入管道前使用 `$()`、`@()` 或变量;普通命令输出直接进入管道。
|
||||||
|
- `rg` 使用真实目录配合 `-g/--glob` 筛选路径;只有确实需要实体路径列表时才用 `Get-ChildItem` 展开并传递 `.FullName`。
|
||||||
- 文本文件读写在命令支持时显式指定 UTF-8;文件解码和控制台输出分别处理,只有出现真实乱码或已知宿主非 UTF-8 时才设置当前进程的输出编码或 Python UTF-8 环境变量。
|
- 文本文件读写在命令支持时显式指定 UTF-8;文件解码和控制台输出分别处理,只有出现真实乱码或已知宿主非 UTF-8 时才设置当前进程的输出编码或 Python UTF-8 环境变量。
|
||||||
- 不得默认使用 `-ExecutionPolicy Bypass`;只有可信 `.ps1`确实被执行策略阻止且没有更小替代方案时,才对该次进程使用并在工单记录原因。
|
- 不得默认使用 `-ExecutionPolicy Bypass`;只有可信 `.ps1`确实被执行策略阻止且没有更小替代方案时,才对该次进程使用并在工单记录原因。
|
||||||
|
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ CORE_DOCUMENT_REQUIREMENTS = {
|
|||||||
"docs/04-local-development-and-verification.md": (
|
"docs/04-local-development-and-verification.md": (
|
||||||
"## 环境要求",
|
"## 环境要求",
|
||||||
"## Windows PowerShell 与 UTF-8",
|
"## Windows PowerShell 与 UTF-8",
|
||||||
|
"### PowerShell 语法与外部命令",
|
||||||
"## 第一次运行",
|
"## 第一次运行",
|
||||||
"## 常用调试方式",
|
"## 常用调试方式",
|
||||||
"## 完成修改前",
|
"## 完成修改前",
|
||||||
@@ -349,6 +350,11 @@ def check_agent_efficiency_rules(errors: list[str], root: Path = ROOT) -> None:
|
|||||||
"不得把模板自带的本地 `docs/` 当作新项目 Wiki 已初始化的证据",
|
"不得把模板自带的本地 `docs/` 当作新项目 Wiki 已初始化的证据",
|
||||||
"提交只包含当前任务相关文件",
|
"提交只包含当前任务相关文件",
|
||||||
"不得仅为设置编码重复启动一层 PowerShell",
|
"不得仅为设置编码重复启动一层 PowerShell",
|
||||||
|
"不得默认套用 Bash",
|
||||||
|
"复杂正则优先使用变量或 `rg -e`",
|
||||||
|
"单引号 PowerShell here-string",
|
||||||
|
"`foreach`、`if` 等语句块",
|
||||||
|
"使用真实目录配合 `-g/--glob`",
|
||||||
"文件解码和控制台输出分别处理",
|
"文件解码和控制台输出分别处理",
|
||||||
"不得默认使用 `-ExecutionPolicy Bypass`",
|
"不得默认使用 `-ExecutionPolicy Bypass`",
|
||||||
"### 按治理模式选择最小设计证据",
|
"### 按治理模式选择最小设计证据",
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
generated: true (请先修改 Gitea Wiki,禁止直接编辑本文件)
|
generated: true (请先修改 Gitea Wiki,禁止直接编辑本文件)
|
||||||
wiki_page: Project-Profile
|
wiki_page: Project-Profile
|
||||||
wiki_url: https://git.ilapage.cn/OPC/dev_harness/wiki/Project-Profile.-
|
wiki_url: https://git.ilapage.cn/OPC/dev_harness/wiki/Project-Profile.-
|
||||||
wiki_revision: 5323a382fc19433c19441587120d5a0ee6447a24
|
wiki_revision: 54598b0fed91a852385386bd6fd920245f5dc1dd
|
||||||
synchronized_at: 2026-09-02T02:08:46Z
|
synchronized_at: 2026-09-02T07:17:36Z
|
||||||
<!-- gitea-wiki-mirror:end -->
|
<!-- gitea-wiki-mirror:end -->
|
||||||
|
|
||||||
# 项目档案
|
# 项目档案
|
||||||
@@ -65,7 +65,7 @@ synchronized_at: 2026-09-02T02:08:46Z
|
|||||||
|---|---|---|
|
|---|---|---|
|
||||||
| Harness 规则和模板 | Markdown、Gitea 1.25 | `AGENTS.md` |
|
| Harness 规则和模板 | Markdown、Gitea 1.25 | `AGENTS.md` |
|
||||||
| Wiki 镜像与结构检查 | Python 3 标准库 | `AGENTS.md` |
|
| Wiki 镜像与结构检查 | Python 3 标准库 | `AGENTS.md` |
|
||||||
| 主要开发环境 | Windows、PowerShell、Git | `AGENTS.md` |
|
| 主要开发环境 | Windows 10、PowerShell 7 `pwsh`(当前验证 7.3.12)、Git | `AGENTS.md` |
|
||||||
|
|
||||||
本项目不需要安装第三方 Python 包。复制到业务项目后,必须把真实语言、框架、版本和支持平台写入本节。
|
本项目不需要安装第三方 Python 包。复制到业务项目后,必须把真实语言、框架、版本和支持平台写入本节。
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
generated: true (请先修改 Gitea Wiki,禁止直接编辑本文件)
|
generated: true (请先修改 Gitea Wiki,禁止直接编辑本文件)
|
||||||
wiki_page: Local-Development-and-Verification
|
wiki_page: Local-Development-and-Verification
|
||||||
wiki_url: https://git.ilapage.cn/OPC/dev_harness/wiki/Local-Development-and-Verification.-
|
wiki_url: https://git.ilapage.cn/OPC/dev_harness/wiki/Local-Development-and-Verification.-
|
||||||
wiki_revision: a7f6ef9e0788065e5a81cfef5753a12b0f0bebc8
|
wiki_revision: a94b4eaa509f351b77274f007ae882e9e696fc8b
|
||||||
synchronized_at: 2026-08-27T07:00:30Z
|
synchronized_at: 2026-09-02T07:20:33Z
|
||||||
<!-- gitea-wiki-mirror:end -->
|
<!-- gitea-wiki-mirror:end -->
|
||||||
|
|
||||||
# 本地开发与验证
|
# 本地开发与验证
|
||||||
@@ -32,6 +32,41 @@ synchronized_at: 2026-08-27T07:00:30Z
|
|||||||
- 不得仅为设置编码重复启动一层 PowerShell;嵌套进程会增加启动时间、转义复杂度和错误定位成本。
|
- 不得仅为设置编码重复启动一层 PowerShell;嵌套进程会增加启动时间、转义复杂度和错误定位成本。
|
||||||
- 代码搜索仍优先使用代码图工具;非代码文本或图工具不足时优先使用 `rg`,不因本节改用 `Select-String`。
|
- 代码搜索仍优先使用代码图工具;非代码文本或图工具不足时优先使用 `rg`,不因本节改用 `Select-String`。
|
||||||
|
|
||||||
|
### PowerShell 语法与外部命令
|
||||||
|
|
||||||
|
- Windows 环境默认使用当前 PowerShell 语法,不套用 Bash 的 heredoc、变量、路径、引号或反斜杠转义规则。只有明确调用 Bash、WSL 或 Git Bash,并确认路径与编码边界时,才使用 Bash 专用语法。
|
||||||
|
- 不需要变量展开的正则和字符串优先用单引号;单引号字符串内部的单引号写成两个单引号。需要变量展开时才使用双引号。
|
||||||
|
- 正则同时包含单双引号或转义复杂时,优先赋值给变量、使用 `rg -e`,或拆成语义等价的简单查询;不得为了避开转义改变 AND/OR 条件或重复执行无关搜索。
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
rg -n 'error|warning' docs
|
||||||
|
$pattern = 'can''t match "value"'
|
||||||
|
rg -n -e $pattern docs
|
||||||
|
```
|
||||||
|
|
||||||
|
PowerShell 不支持 Bash heredoc。需要把多行 Python 送入标准输入时,使用单引号 here-string,避免 PowerShell 展开 Python 中的 dollar sign(`$`)等内容。起始标记后必须立即换行,结束标记必须单独占一行:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
@'
|
||||||
|
print("hello")
|
||||||
|
'@ | python -
|
||||||
|
```
|
||||||
|
|
||||||
|
`foreach`、`if` 等语句块不能裸放在管道左侧;需要管道输出时使用 `$()`、`@()` 或先赋值。普通命令输出无需包装:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
@(foreach ($number in 1..3) { $number }) |
|
||||||
|
Measure-Object
|
||||||
|
```
|
||||||
|
|
||||||
|
不要把含 `*` 的搜索路径直接作为 `rg` 路径参数。优先传入真实目录,并用 `-g/--glob` 让 ripgrep 筛选路径:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
rg -n -g '*.md' 'PowerShell' docs
|
||||||
|
```
|
||||||
|
|
||||||
|
只有确实需要把实体路径列表交给其他命令时,才使用 `Get-ChildItem` 展开并传递 `.FullName`;不要把 `Get-ChildItem -Filter` 设为所有 `rg` 搜索的固定前置。
|
||||||
|
|
||||||
### 文件编码
|
### 文件编码
|
||||||
|
|
||||||
文件解码与控制台输出编码是不同问题。读取 UTF-8 文本时,在命令支持的情况下显式指定编码和字面路径:
|
文件解码与控制台输出编码是不同问题。读取 UTF-8 文本时,在命令支持的情况下显式指定编码和字面路径:
|
||||||
|
|||||||
@@ -168,6 +168,22 @@ class CoreDocumentTests(unittest.TestCase):
|
|||||||
check_agent_efficiency_rules(errors)
|
check_agent_efficiency_rules(errors)
|
||||||
self.assertEqual(errors, [])
|
self.assertEqual(errors, [])
|
||||||
|
|
||||||
|
def test_windows_shell_rules_avoid_bash_and_ripgrep_traps(self) -> None:
|
||||||
|
agents = (ROOT / "AGENTS.md").read_text(encoding="utf-8")
|
||||||
|
profile = (ROOT / "docs/00-project-profile.md").read_text(encoding="utf-8")
|
||||||
|
local = (
|
||||||
|
ROOT / "docs/04-local-development-and-verification.md"
|
||||||
|
).read_text(encoding="utf-8")
|
||||||
|
self.assertIn("Windows 10", profile)
|
||||||
|
self.assertIn("PowerShell 7 `pwsh`", profile)
|
||||||
|
self.assertIn("不得默认套用 Bash", agents)
|
||||||
|
self.assertIn("复杂正则优先使用变量或 `rg -e`", agents)
|
||||||
|
self.assertIn("@'\nprint", local)
|
||||||
|
self.assertIn("@(foreach", local)
|
||||||
|
self.assertIn("rg -n -g '*.md'", local)
|
||||||
|
self.assertNotIn("通配目录必须先用 `Get-ChildItem -Filter`", local)
|
||||||
|
self.assertNotIn("正则本身同时包含单引号和双引号,优先拆成多个", local)
|
||||||
|
|
||||||
def test_deployment_template_is_required_and_mapped(self) -> None:
|
def test_deployment_template_is_required_and_mapped(self) -> None:
|
||||||
path = "docs/templates/deployment.md"
|
path = "docs/templates/deployment.md"
|
||||||
self.assertIn(path, REQUIRED_FILES)
|
self.assertIn(path, REQUIRED_FILES)
|
||||||
|
|||||||
Reference in New Issue
Block a user