@michelj/context-guard 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,6 +14,7 @@ Context Guard 是一个给 Codex 用的项目记忆 skill。它把任务主线
14
14
  - **支持多语言记录**:按项目偏好用中文或英文写 context。
15
15
  - **处理任务切换**:遇到新方向、支线任务或中断任务时,帮助 Codex park/resume。
16
16
  - **测试由人类设计**:Codex 只复用已确认检查,或提出草案等待用户确认,不静默创建长期测试。
17
+ - **用功能链覆盖 bad case**:优先把多个 bad case 挂到同一条真实功能/工作流测试链上,而不是为每个 bad case 单独造测试。
17
18
  - **默认运行已确认测试**:用户创建或确认的测试,默认每次开发结束都要运行;只有用户说明不必每次运行时才降频。
18
19
  - **提供测试中台入口**:`dev-complete` 会统一运行已确认的 always-run 测试,成功清理临时产物,失败保留证据。
19
20
 
@@ -22,13 +23,19 @@ Context Guard 是一个给 Codex 用的项目记忆 skill。它把任务主线
22
23
  使用 npx 安装:
23
24
 
24
25
  ```bash
25
- npx context-guard install
26
+ npx @michelj/context-guard install
27
+ ```
28
+
29
+ 也可以全局安装,让 npm 包自动把 skill 复制到 Codex 的 skill 目录:
30
+
31
+ ```bash
32
+ npm install -g @michelj/context-guard --registry=https://registry.npmjs.org
26
33
  ```
27
34
 
28
35
  只有当你明确希望安装 Codex 生命周期 hook 提醒时,才加 `--with-hooks`:
29
36
 
30
37
  ```bash
31
- npx context-guard install --with-hooks
38
+ npx @michelj/context-guard install --with-hooks
32
39
  ```
33
40
 
34
41
  npm 包正式发布前,也可以直接从 GitHub 使用:
@@ -42,14 +49,14 @@ npx github:Michel-Johnson/Context-Guard-Skill install
42
49
  ```bash
43
50
  git clone git@github.com:Michel-Johnson/Context-Guard-Skill.git
44
51
  cd Context-Guard-Skill
45
- mkdir -p ~/.agents/skills/context-guard
46
- rsync -a --delete skills/context-guard/ ~/.agents/skills/context-guard/
52
+ mkdir -p ~/.codex/skills/context-guard
53
+ rsync -a --delete skills/context-guard/ ~/.codex/skills/context-guard/
47
54
  ```
48
55
 
49
56
  安装后 Codex 应该能发现:
50
57
 
51
58
  ```text
52
- ~/.agents/skills/context-guard/SKILL.md
59
+ ~/.codex/skills/context-guard/SKILL.md
53
60
  ```
54
61
 
55
62
  ## Context 保存在哪里
@@ -70,39 +77,60 @@ Context 必须保存在当前打开的本地项目里:
70
77
  如果手动运行脚本,建议显式传入项目根目录:
71
78
 
72
79
  ```bash
73
- python3 ~/.agents/skills/context-guard/scripts/context_guard.py show-roadmap --root /path/to/project
80
+ python3 ~/.codex/skills/context-guard/scripts/context_guard.py show-roadmap --root /path/to/project
74
81
  ```
75
82
 
76
83
  注册一个用户已确认的自动化测试:
77
84
 
78
85
  ```bash
79
- python3 ~/.agents/skills/context-guard/scripts/context_guard.py test-hub-add \
86
+ python3 ~/.codex/skills/context-guard/scripts/context_guard.py test-hub-add \
80
87
  --root /path/to/project \
81
88
  --title "Markdown 预览渲染" \
82
89
  --command-text "npm test"
83
90
  ```
84
91
 
92
+ 注册一条用户已确认的功能链测试:
93
+
94
+ ```bash
95
+ python3 ~/.codex/skills/context-guard/scripts/context_guard.py feature-chain-add \
96
+ --root /path/to/project \
97
+ --title "GPU 监控按钮" \
98
+ --entry "点击 GPU 监控按钮" \
99
+ --exit-check "打开包含有效 grafana_url 的监控页" \
100
+ --command-text "npm test -- gpu-monitor"
101
+ ```
102
+
103
+ 把 bad case 挂到功能链的具体环节:
104
+
105
+ ```bash
106
+ python3 ~/.codex/skills/context-guard/scripts/context_guard.py feature-chain-attach-bc \
107
+ --root /path/to/project \
108
+ --chain-id FC-... \
109
+ --node-title "后端返回监控 URL" \
110
+ --bad-case BC-... \
111
+ --check "grafana_url 不为空,前端不会卡住"
112
+ ```
113
+
85
114
  开发完成后交给测试中台:
86
115
 
87
116
  ```bash
88
- python3 ~/.agents/skills/context-guard/scripts/context_guard.py dev-complete --root /path/to/project --jobs 2
117
+ python3 ~/.codex/skills/context-guard/scripts/context_guard.py dev-complete --root /path/to/project --jobs 2
89
118
  ```
90
119
 
91
- 查看测试中台页面;需要一键运行时启动 localhost 控制台:
120
+ 查看只读测试中台页面:
92
121
 
93
122
  ```bash
94
- python3 ~/.agents/skills/context-guard/scripts/context_guard.py show-test-hub --root /path/to/project --open
95
- python3 ~/.agents/skills/context-guard/scripts/context_guard.py serve-test-hub --root /path/to/project --port 8772 --open
123
+ python3 ~/.codex/skills/context-guard/scripts/context_guard.py show-test-hub --root /path/to/project --open
96
124
  ```
97
125
 
98
126
  简单管理测试:
99
127
 
100
128
  ```bash
101
- python3 ~/.agents/skills/context-guard/scripts/context_guard.py test-hub-list --root /path/to/project
102
- python3 ~/.agents/skills/context-guard/scripts/context_guard.py test-hub-disable --root /path/to/project --test-id TC-... --reason "暂时不需要每次运行"
103
- python3 ~/.agents/skills/context-guard/scripts/context_guard.py test-hub-enable --root /path/to/project --test-id TC-...
104
- python3 ~/.agents/skills/context-guard/scripts/context_guard.py test-hub-set-policy --root /path/to/project --test-id TC-... --run-policy relevant-only --reason "只和编辑器改动相关"
105
- python3 ~/.agents/skills/context-guard/scripts/context_guard.py test-hub-remove --root /path/to/project --test-id TC-...
129
+ python3 ~/.codex/skills/context-guard/scripts/context_guard.py test-hub-list --root /path/to/project
130
+ python3 ~/.codex/skills/context-guard/scripts/context_guard.py test-hub-disable --root /path/to/project --test-id TC-... --reason "暂时不需要每次运行"
131
+ python3 ~/.codex/skills/context-guard/scripts/context_guard.py test-hub-enable --root /path/to/project --test-id TC-...
132
+ python3 ~/.codex/skills/context-guard/scripts/context_guard.py test-hub-set-policy --root /path/to/project --test-id TC-... --run-policy relevant-only --reason "只和编辑器改动相关"
133
+ python3 ~/.codex/skills/context-guard/scripts/context_guard.py test-hub-remove --root /path/to/project --test-id TC-...
106
134
  ```
107
135
 
108
136
  ## 常用方式
@@ -122,31 +150,31 @@ Use $context-guard to show the roadmap.
122
150
  初始化项目 context:
123
151
 
124
152
  ```bash
125
- python3 ~/.agents/skills/context-guard/scripts/context_guard.py init --root /path/to/project
153
+ python3 ~/.codex/skills/context-guard/scripts/context_guard.py init --root /path/to/project
126
154
  ```
127
155
 
128
156
  设置记录语言:
129
157
 
130
158
  ```bash
131
- python3 ~/.agents/skills/context-guard/scripts/context_guard.py set-language --root /path/to/project --language 中文
159
+ python3 ~/.codex/skills/context-guard/scripts/context_guard.py set-language --root /path/to/project --language 中文
132
160
  ```
133
161
 
134
162
  生成路线图:
135
163
 
136
164
  ```bash
137
- python3 ~/.agents/skills/context-guard/scripts/context_guard.py show-roadmap --root /path/to/project
165
+ python3 ~/.codex/skills/context-guard/scripts/context_guard.py show-roadmap --root /path/to/project
138
166
  ```
139
167
 
140
168
  也可以用 npm CLI 作为轻量封装:
141
169
 
142
170
  ```bash
143
- npx context-guard show-roadmap --root /path/to/project
171
+ npx @michelj/context-guard show-roadmap --root /path/to/project
144
172
  ```
145
173
 
146
174
  创建支线任务:
147
175
 
148
176
  ```bash
149
- python3 ~/.agents/skills/context-guard/scripts/context_guard.py create-branch-task \
177
+ python3 ~/.codex/skills/context-guard/scripts/context_guard.py create-branch-task \
150
178
  --root /path/to/project \
151
179
  --title "支线任务标题" \
152
180
  --branch "支线名称" \
@@ -156,7 +184,7 @@ python3 ~/.agents/skills/context-guard/scripts/context_guard.py create-branch-ta
156
184
  记录路线图节点:
157
185
 
158
186
  ```bash
159
- python3 ~/.agents/skills/context-guard/scripts/context_guard.py checkpoint-roadmap-node \
187
+ python3 ~/.codex/skills/context-guard/scripts/context_guard.py checkpoint-roadmap-node \
160
188
  --root /path/to/project \
161
189
  --title "给 Codex 看的源标题" \
162
190
  --display-title "给用户看的短标题" \
@@ -192,9 +220,12 @@ python3 ~/.agents/skills/context-guard/scripts/context_guard.py checkpoint-roadm
192
220
  - 用户看的标题要像人话,不要像实现日志。
193
221
  - bad case 要能帮助未来避免复发。
194
222
  - 测试设计权属于人类;Codex 可以执行已确认检查,或提出待确认草案。
223
+ - 测试的长期单位优先是功能链:一个明确入口、一段真实流程、多个检查点、覆盖多个 bad case。
224
+ - 新 bad case 优先挂到已有功能链节点;没有匹配功能链时,再提出新的功能链草案。
195
225
  - 用户确认的测试默认是 `every-dev-completion`;只有用户要求时,Codex 才能改成其他运行频率。
196
- - 已确认的自动化测试应进入 `.codex/context/test-hub/registry.json`,由 `dev-complete` 统一调度。
197
- - 测试中台保持简单:一个注册表、一个 `dev-complete` runner、一个最近结果、一个轻量 HTML 控制台和几个管理命令。
226
+ - 已确认的自动化测试应进入 `.codex/context/test-hub/registry.json` 或 `.codex/context/test-hub/feature-chains.json`,由 `dev-complete` 统一调度。
227
+ - 测试中台保持简单:一个注册表、一个 `dev-complete` runner、一个最近结果、一个只读 HTML 状态页和几个管理命令。
228
+ - Codex 最终总结必须说明当前测试中台结果:已确认的 always-run 测试是否全部通过、失败、阻塞,或当前没有这类测试。
198
229
  - 测试链路优先复用已有命令、脚本、截图或人工检查。
199
230
  - 不要为了每个 bad case 都新写脚本。
200
231
  - 前端或 HTML 改动结束前,应实际查看页面或截图,确认没有明显视觉错误。
@@ -275,6 +275,44 @@ Preferred bad-case source format is one `### BC-YYYYMMDD-001: Title` section per
275
275
 
276
276
  Recording and display must stay connected. Every bad case that should appear on a roadmap must have either `Roadmap nodes:` / `Nodes:` pointing to one or more `NODE-...` IDs, or the roadmap node must list that case under `Linked bad cases:`. Do not rely on task-level proximity alone.
277
277
 
278
+ ### Feature-Oriented Test Chains
279
+
280
+ Use as few durable test chains as possible to cover as many bad-case recurrence checks as possible. The durable testing unit is a feature or workflow chain, not an individual bad case.
281
+
282
+ A feature chain has:
283
+
284
+ - a clear input or entry point, such as clicking a button, submitting a task, opening a page, or starting a workflow
285
+ - ordered checkpoints that match the real user/business flow
286
+ - strict red and green conditions for the final result and any critical intermediate step
287
+ - linked bad cases attached to the specific checkpoint where they can recur
288
+
289
+ When a new bad case appears:
290
+
291
+ 1. First ask whether it belongs to an existing feature chain.
292
+ 2. If it does, attach the bad case to the matching chain node and strengthen that node's checkpoint instead of creating a separate long-lived test.
293
+ 3. If no existing chain matches the feature or workflow, propose a new feature chain with the same short human-facing confirmation style as task cases.
294
+ 4. Only approve or automate the chain after user confirmation, unless the user explicitly provided the exact test to implement.
295
+
296
+ Store feature chains in `.codex/context/test-hub/feature-chains.json`. Use:
297
+
298
+ ```bash
299
+ python3 ~/.agents/skills/context-guard/scripts/context_guard.py feature-chain-add \
300
+ --root <project> \
301
+ --title "GPU 监控按钮" \
302
+ --entry "点击 GPU 监控按钮" \
303
+ --exit-check "打开包含有效 grafana_url 的监控页" \
304
+ --command-text "<approved command>"
305
+
306
+ python3 ~/.agents/skills/context-guard/scripts/context_guard.py feature-chain-attach-bc \
307
+ --root <project> \
308
+ --chain-id FC-YYYYMMDD-001 \
309
+ --node-title "后端返回监控 URL" \
310
+ --bad-case BC-YYYYMMDD-001 \
311
+ --check "grafana_url 不为空且前端没有卡住"
312
+ ```
313
+
314
+ Approved feature chains with `Run policy: every-dev-completion` are included in `dev-complete` and the Stop hook. Relevant-only or proposed chains remain context until the user approves or asks to run them.
315
+
278
316
  ### Task-Oriented Test Cases
279
317
 
280
318
  When verification would otherwise become many tiny bug-specific tests, prefer a task-oriented case that simulates a real workflow end to end. A task case is a scenario with phases, checkpoints, logs, and linked bad-case coverage.
@@ -372,10 +410,10 @@ Use the Test Hub as the automation control plane for approved tests. The hub col
372
410
  - Register only user-created or user-approved tests. Do not auto-promote ordinary bad-case guards, roadmap `Test chain:` notes, or Codex implementation logs into the registry.
373
411
  - A registry entry with `status: approved | active | stable` and `run_policy: every-dev-completion` is part of the always-run set.
374
412
  - Manage registry tests with `test-hub-list`, `test-hub-enable`, `test-hub-disable`, `test-hub-set-policy`, and `test-hub-remove`.
375
- - Use `show-test-hub` to write the stable human-facing page at `.codex/context/test-hub/test-hub.html`.
376
- - Use `serve-test-hub` when the user wants a clickable local control panel. The static `file://` page is read-only; one-click test execution is only enabled from the localhost server.
413
+ - Use `show-test-hub` to write the stable read-only human-facing page at `.codex/context/test-hub/test-hub.html`.
414
+ - The Test Hub HTML is a status page only. Do not make users start tests from HTML buttons; approved tests run from the Stop hook or `dev-complete`.
377
415
  - Task cases in `.codex/context/task-cases/` may also join the always-run set only when they are `approved | active | stable`, have `Run policy: every-dev-completion`, and include an automated entry command.
378
- - At development completion, prefer `scripts/context_guard.py dev-complete --root <project>` over hand-running registered tests one by one. Use `--jobs <n>` only when parallel execution is safe for the registered tests.
416
+ - At development completion, the Stop hook should invoke `scripts/context_guard.py dev-complete --root <project>` so registered tests run automatically. If running manually, use `dev-complete` over hand-running tests one by one. Use `--jobs <n>` only when parallel execution is safe for the registered tests.
379
417
  - `dev-complete` must report passed, failed, and blocked tests. On full success it should clean the run artifacts; on failure or blocker it should preserve evidence under `.codex/context/test-hub/runs/`.
380
418
  - If the user says a test should not run every time, update the registry or task case run policy instead of silently skipping it.
381
419
  - If no approved every-dev-completion tests exist, the hub should report that clearly and exit successfully; Codex should not invent tests to fill the gap.
@@ -511,6 +549,7 @@ At the end of every response, include a compact context summary when development
511
549
  - Bad-case intake result from this turn.
512
550
  - BC archived/updated this turn. If none were changed, say `none`.
513
551
  - Current unresolved BC. Use concise human-readable bad-case titles and, when useful, one symptom phrase plus status; do not report only `BC-...` IDs. If none are open/deferred/recurred/unknown, say `none`.
552
+ - Current Test Hub status. Say whether all currently approved `every-dev-completion` tests passed, failed, blocked, or whether no approved always-run tests exist. Include concise counts such as `3 passed, 0 failed, 0 blocked`.
514
553
  - New or updated context, limited to key nodes and bad cases.
515
554
  - End-of-work self-check performed, including visual inspection evidence for frontend/layout artifacts or the exact blocker if visual inspection was not possible.
516
555
  - Previously resolved cases rechecked, including reused context, tests, commands, scripts, or manual checks.