@michelj/context-guard 0.4.2 → 0.4.4

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.
Files changed (36) hide show
  1. package/README.md +113 -150
  2. package/README.zh-CN.md +113 -150
  3. package/SKILL.md +46 -0
  4. package/agents/openai.yaml +4 -0
  5. package/bin/context-guard-skill.js +234 -46
  6. package/bin/postinstall.js +1 -1
  7. package/hooks.json +29 -5
  8. package/package.json +12 -5
  9. package/prototype/workbench.html +4933 -0
  10. package/references/bug-record-template.md +37 -0
  11. package/references/context-template.md +19 -0
  12. package/scripts/context_guard.py +806 -0
  13. package/scripts/context_guard_hook.py +302 -0
  14. package/scripts/map_owns.py +769 -0
  15. package/skills/context-guard/README.md +0 -234
  16. package/skills/context-guard/README.zh-CN.md +0 -234
  17. package/skills/context-guard/SKILL.md +0 -558
  18. package/skills/context-guard/agents/openai.yaml +0 -4
  19. package/skills/context-guard/references/context-template.md +0 -290
  20. package/skills/context-guard/references/register-template.md +0 -85
  21. package/skills/context-guard/references/task-case-template.md +0 -63
  22. package/skills/context-guard/scripts/context_guard.py +0 -4886
  23. package/skills/context-guard/scripts/context_guard_hook.py +0 -522
  24. package/skills/context-guard/tests/BC-20260618-063.sh +0 -116
  25. package/skills/context-guard/tests/BC-20260618-065.sh +0 -66
  26. package/skills/context-guard/tests/BC-20260626-080.sh +0 -48
  27. package/skills/context-guard/tests/BC-20260626-081.sh +0 -40
  28. package/skills/context-guard/tests/BC-20260626-082.sh +0 -32
  29. package/skills/context-guard/tests/BC-20260626-083.sh +0 -66
  30. package/skills/context-guard/tests/BC-20260627-084.sh +0 -74
  31. package/skills/context-guard/tests/BC-20260630-086.sh +0 -50
  32. package/skills/context-guard/tests/BC-20260630-087.sh +0 -103
  33. package/skills/context-guard/tests/BC-20260630-088.sh +0 -32
  34. package/skills/context-guard/tests/BC-20260630-089.sh +0 -63
  35. package/skills/context-guard/tests/BC-20260701-090.sh +0 -83
  36. package/skills/context-guard/tests/BC-20260702-096.sh +0 -45
package/README.md CHANGED
@@ -2,233 +2,196 @@
2
2
 
3
3
  Language: **English** | [中文](README.zh-CN.md)
4
4
 
5
- Context Guard is a Codex skill for durable project memory. It keeps the task route, branches, bad cases, and verification paths inside the project's own `.codex/context/` folder, so Codex can understand where the work is, what went wrong before, and how to avoid repeating fixed mistakes across sessions.
5
+ Context Guard is a durable project-memory skill for Codex, Cursor, and Claude. It keeps the task route, branches, bad cases, and verification paths inside the project's own `.codex/context/` folder, so agents can understand where the work is, what went wrong before, and how to avoid repeating fixed mistakes across sessions.
6
6
 
7
7
  ## What It Does
8
8
 
9
- - **Maintains project context**: creates and updates `.codex/context/`.
10
- - **Records the roadmap**: tracks main routes, side routes, branch points, and progress.
11
- - **Tracks bad cases**: records symptoms, triggers, causes, fixes, and recurrence checks.
12
- - **Generates Roadmap HTML**: shows a human-readable roadmap with clickable node details.
13
- - **Separates human and agent views**: HTML is for humans; Markdown/JSON are for Codex.
14
- - **Supports record language preferences**: writes future context in Chinese or English.
15
- - **Handles task switches**: parks, resumes, and branches interrupted work.
16
- - **Keeps tests human-designed**: Codex reuses approved checks or proposes drafts, but does not silently create durable tests.
17
- - **Covers bad cases with feature chains**: prefer one real feature/workflow chain covering multiple bad cases over one separate test per bad case.
18
- - **Runs approved tests by default**: user-created or user-approved tests run at every development completion unless the user sets another cadence.
19
- - **Provides a Test Hub entrypoint**: `dev-complete` runs approved always-run tests, cleans success artifacts, and preserves failed evidence.
9
+ - **Four stores**: sessions, bugs, tasks, map — in the opened project’s `.codex/context/`
10
+ - **First-use map**: the agent and the human decide the first layer together (several candidate cuts, then lock L1), then L2, then L3. Titles must be instantly readable. Later sessions open that map
11
+ - **Human workbench**: people confirm in `prototype/workbench.html`. Agents read small indexes, not the whole map
12
+ - **User wording**: durable prompts go in `user-messages.md`; secrets stay under `private/`
13
+ - **Record language**: Chinese or English per folder
14
+ - **Lifecycle**: create session records, retain user messages, and persist agent-identified bad cases through one command
20
15
 
21
- ## Install
16
+ v1 does **not** include Roadmap HTML, Test Hub, or feature chains.
22
17
 
23
- Install with npx:
18
+ ## Human workbench
24
19
 
25
- ```bash
26
- npx @michelj/context-guard install
27
- ```
20
+ People confirm the architecture map in the workbench. With hooks installed, a new session starts one local workbench instance and opens it in the browser. Agents read the small indexes under `.codex/context/`; they do not drive the canvas.
28
21
 
29
- Or install globally and let the package copy the skill into Codex's skill directory automatically:
22
+ **Current workbench:** [prototype/workbench.html](https://github.com/Michel-Johnson/Context-Guard-Skill/blob/main/prototype/workbench.html) · [open in browser](https://raw.githack.com/Michel-Johnson/Context-Guard-Skill/main/prototype/workbench.html)
30
23
 
31
- ```bash
32
- npm install -g @michelj/context-guard --registry=https://registry.npmjs.org
33
- ```
24
+ The first browser open may show GitHack’s “One more step” page (it is only a proxy and does not review the HTML). Click **Open the page**.
34
25
 
35
- Install hooks only when you explicitly want Context Guard reminders at Codex lifecycle events:
26
+ To decide the first layer: click the repo name, switch to **OpenClaw** (first use), then **See first-layer cuts**. Picking one lands it on the canvas. Titles are still prepared; the cut is yours.
36
27
 
37
- ```bash
38
- npx @michelj/context-guard install --with-hooks
39
- ```
28
+ The workbench chrome is Chinese or English. Use **中 / EN** in the top bar. Map titles, purposes, and memories stay in the language they were written.
40
29
 
41
- Use from GitHub before the npm package is published:
30
+ Start or stop it manually when needed:
42
31
 
43
32
  ```bash
44
- npx github:Michel-Johnson/Context-Guard-Skill install
33
+ context-guard workbench --root /path/to/project
34
+ context-guard workbench --root /path/to/project --stop
45
35
  ```
46
36
 
47
- Manual install is also supported:
37
+ ### Overview
48
38
 
49
- ```bash
50
- git clone git@github.com:Michel-Johnson/Context-Guard-Skill.git
51
- cd Context-Guard-Skill
52
- mkdir -p ~/.codex/skills/context-guard
53
- rsync -a --delete skills/context-guard/ ~/.codex/skills/context-guard/
54
- ```
39
+ Root catalog: 4–8 module cards. Click a card to enter. Bugs stay in the right-hand list.
55
40
 
56
- After installation, Codex should discover:
41
+ ![Workbench overview](docs/shots/workbench/overview.png)
57
42
 
58
- ```text
59
- ~/.codex/skills/context-guard/SKILL.md
60
- ```
43
+ ### Inside a module
61
44
 
62
- ## Where Context Lives
45
+ Work units hang under the module. Hierarchy is parent–child solid curves.
63
46
 
64
- Context must be saved under the local project currently opened in Codex:
47
+ ![Inside a module](docs/shots/workbench/module.png)
65
48
 
66
- ```text
67
- <Codex project root>/.codex/context/
68
- ```
49
+ ### Module relations
69
50
 
70
- Do not write project context into:
51
+ 「关系」 highlights produce/consume partners and dims the rest. It does not enter the module.
71
52
 
72
- - the skill install directory
73
- - a chat/thread directory
74
- - a temporary directory
75
- - an SSH remote server path
53
+ ![Module relations](docs/shots/workbench/relations.png)
76
54
 
77
- When running scripts manually, pass the project root explicitly:
55
+ ### Session flow
78
56
 
79
- ```bash
80
- python3 ~/.codex/skills/context-guard/scripts/context_guard.py show-roadmap --root /path/to/project
81
- ```
57
+ Click a bug with an assigned session. The path from the root to that node lights up; current session beads run along the chain.
58
+
59
+ ![Session flow](docs/shots/workbench/session-flow.png)
60
+
61
+ ### Auth / inspect mode
62
+
63
+ 「授权模式」 marks which slices this session’s agent may read. Grey cards are not authorized.
82
64
 
83
- Register a user-approved automated test:
65
+ ![Auth mode](docs/shots/workbench/auth-mode.png)
66
+
67
+ ## Install
68
+
69
+ Install with npx. The installer detects Codex, Cursor, and Claude, then installs both the skill and lifecycle hooks while preserving existing configuration:
84
70
 
85
71
  ```bash
86
- python3 ~/.codex/skills/context-guard/scripts/context_guard.py test-hub-add \
87
- --root /path/to/project \
88
- --title "Markdown preview rendering" \
89
- --command-text "npm test"
72
+ npx @michelj/context-guard install
90
73
  ```
91
74
 
92
- Register a user-approved feature-chain test:
75
+ Or install globally and let the package configure detected clients automatically:
93
76
 
94
77
  ```bash
95
- python3 ~/.codex/skills/context-guard/scripts/context_guard.py feature-chain-add \
96
- --root /path/to/project \
97
- --title "GPU monitor button" \
98
- --entry "Click the GPU monitor button" \
99
- --exit-check "Open a monitoring page with a valid grafana_url" \
100
- --command-text "npm test -- gpu-monitor"
78
+ npm install -g @michelj/context-guard --registry=https://registry.npmjs.org
101
79
  ```
102
80
 
103
- Attach a bad case to a specific feature-chain checkpoint:
81
+ Force installation for all three clients:
104
82
 
105
83
  ```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 "Backend returns monitor URL" \
110
- --bad-case BC-... \
111
- --check "grafana_url is non-empty and the frontend does not hang"
84
+ npx @michelj/context-guard install --platform all
112
85
  ```
113
86
 
114
- After development, hand completion to the Test Hub:
87
+ Hooks are installed by default. To copy only the skill, opt out explicitly:
115
88
 
116
89
  ```bash
117
- python3 ~/.codex/skills/context-guard/scripts/context_guard.py dev-complete --root /path/to/project --jobs 2
90
+ npx @michelj/context-guard install --no-hooks
118
91
  ```
119
92
 
120
- Open the read-only Test Hub page:
93
+ Default skill paths are `~/.codex/skills/context-guard`, `~/.cursor/skills/context-guard`, and `~/.claude/skills/context-guard`. The installer backs up and merges existing hook/settings files. For Codex it also enables `[features] hooks = true` and migrates the deprecated `codex_hooks` alias.
94
+
95
+ Use from GitHub before the npm package is published:
121
96
 
122
97
  ```bash
123
- python3 ~/.codex/skills/context-guard/scripts/context_guard.py show-test-hub --root /path/to/project --open
98
+ npx github:Michel-Johnson/Context-Guard-Skill install
124
99
  ```
125
100
 
126
- Manage tests lightly:
101
+ Manual install is also supported:
127
102
 
128
103
  ```bash
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 "not needed every time"
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 "only editor changes need it"
133
- python3 ~/.codex/skills/context-guard/scripts/context_guard.py test-hub-remove --root /path/to/project --test-id TC-...
104
+ git clone git@github.com:Michel-Johnson/Context-Guard-Skill.git
105
+ cd Context-Guard-Skill
106
+ mkdir -p ~/.codex/skills/context-guard
107
+ rsync -a --delete \
108
+ SKILL.md README.md README.zh-CN.md agents prototype references scripts \
109
+ ~/.codex/skills/context-guard/
134
110
  ```
135
111
 
136
- ## Common Usage
137
-
138
- Ask Codex to maintain context:
112
+ After installation, the matching clients should discover:
139
113
 
140
114
  ```text
141
- Use $context-guard to maintain this task context.
115
+ ~/.codex/skills/context-guard/SKILL.md
116
+ ~/.cursor/skills/context-guard/SKILL.md
117
+ ~/.claude/skills/context-guard/SKILL.md
142
118
  ```
143
119
 
144
- Show the current roadmap:
120
+ ## Publishing
121
+
122
+ GitHub Releases are not part of this package's delivery path. Users install the skill from npm, so publishing is driven by a version tag:
123
+
124
+ 1. Update `package.json` to the next stable version and merge that commit into `main`.
125
+ 2. Create the matching `vX.Y.Z` tag on that commit.
126
+ 3. Push the tag. `.github/workflows/npm-publish.yml` validates, packs, smoke-tests, and publishes that exact tarball to npm.
127
+
128
+ The workflow has no manual trigger. Pushing a matching version tag starts the complete publish pipeline automatically; the validated tarball is retained as a GitHub Actions artifact for 14 days. It reuses npm Trusted Publishing for `Michel-Johnson/Context-Guard-Skill`, workflow filename `npm-publish.yml`, with the `npm publish` action allowed. Local npm login is not required for Actions publishing. See the [release and recovery runbook](https://github.com/Michel-Johnson/Context-Guard-Skill/blob/main/docs/npm-release-runbook.md).
129
+
130
+ ## Where Context Lives
131
+
132
+ Context stays under the opened local project, independent of the client:
145
133
 
146
134
  ```text
147
- Use $context-guard to show the roadmap.
135
+ <project root>/.codex/context/
148
136
  ```
149
137
 
150
- Initialize project context:
138
+ Do not write project context into:
151
139
 
152
- ```bash
153
- python3 ~/.codex/skills/context-guard/scripts/context_guard.py init --root /path/to/project
154
- ```
140
+ - the skill install directory
141
+ - a chat/thread directory
142
+ - a temporary directory
143
+ - an SSH remote server path
155
144
 
156
- Set the record language:
145
+ Short user prompts that matter for future work are kept in:
157
146
 
158
- ```bash
159
- python3 ~/.codex/skills/context-guard/scripts/context_guard.py set-language --root /path/to/project --language English
147
+ ```text
148
+ <project root>/.codex/context/user-messages.md
160
149
  ```
161
150
 
162
- Generate the roadmap:
151
+ If the user provides a credential that future turns need, Context Guard records only a redacted pointer in public context. Raw durable secrets must stay local-only under:
163
152
 
164
- ```bash
165
- python3 ~/.codex/skills/context-guard/scripts/context_guard.py show-roadmap --root /path/to/project
153
+ ```text
154
+ <project root>/.codex/context/private/
166
155
  ```
167
156
 
168
- Or use the npm CLI as a thin wrapper:
157
+ When running scripts manually, pass the project root:
169
158
 
170
159
  ```bash
171
- npx @michelj/context-guard show-roadmap --root /path/to/project
160
+ python3 scripts/context_guard.py init --root /path/to/project
161
+ python3 scripts/context_guard.py set-language --root /path/to/project --language English
172
162
  ```
173
163
 
174
- Create a branch task:
164
+ On the first session, if `record_language` is still `unset`, the hook instructs the agent to ask “中文 or English?” and persist the answer. Later sessions do not ask again. The `workbench` command starts the local server and returns its browser URL.
175
165
 
176
- ```bash
177
- python3 ~/.codex/skills/context-guard/scripts/context_guard.py create-branch-task \
178
- --root /path/to/project \
179
- --title "branch task title" \
180
- --branch "branch name" \
181
- --parent-node NODE-YYYYMMDD-001
182
- ```
166
+ ## Common Usage
183
167
 
184
- Record a roadmap checkpoint:
168
+ ```text
169
+ Use $context-guard. Four stores: sessions, bugs, tasks, map.
170
+ ```
185
171
 
186
172
  ```bash
187
- python3 ~/.codex/skills/context-guard/scripts/context_guard.py checkpoint-roadmap-node \
188
- --root /path/to/project \
189
- --title "source title for Codex" \
190
- --display-title "short human title" \
191
- --user-request "what the user asked" \
192
- --progress-summary "current progress" \
193
- --method-summary "method used" \
194
- --branch Main \
195
- --level major \
196
- --outcome "result"
173
+ python3 scripts/context_guard.py init --root /path/to/project
174
+ python3 scripts/context_guard.py set-language --root /path/to/project --language English
175
+ python3 scripts/context_guard.py workbench --root /path/to/project
197
176
  ```
198
177
 
178
+ Run `context-guard workbench --root /path/to/project` to see the map.
179
+
199
180
  ## Main Files
200
181
 
201
182
  ```text
202
183
  .codex/context/
203
- |-- index.md # quick index and active task
204
- |-- roadmap.md # agent-readable roadmap
205
- |-- bad-cases.md # bad-case register
206
- |-- preferences.json # language and project preferences
207
- |-- roadmap/
208
- | |-- roadmap.html # human-facing roadmap
209
- | |-- roadmap.md # agent-readable export
210
- | `-- roadmap.json # structured index
211
- |-- tasks/ # task-level context
212
- |-- task-cases/ # task-oriented test cases
213
- |-- test-hub/ # test registry, latest result, and failed evidence
214
- `-- bad-case-tests/ # reusable bad-case checks
215
- ```
216
-
217
- ## Principles
218
-
219
- - Record only meaningful progress, not every small action.
220
- - Human-facing titles should read naturally, not like implementation logs.
221
- - A bad case should help future Codex prevent recurrence.
222
- - Test design belongs to humans; Codex can run approved checks or draft a proposal for confirmation.
223
- - Prefer feature chains as the durable testing unit: one clear entry, one real workflow, ordered checkpoints, and multiple covered bad cases.
224
- - Attach new bad cases to an existing feature-chain checkpoint first; propose a new chain only when no existing workflow matches.
225
- - User-approved tests default to `every-dev-completion`; Codex may lower that cadence only when the user asks.
226
- - Approved automated tests should go into `.codex/context/test-hub/registry.json` or `.codex/context/test-hub/feature-chains.json` and be scheduled through `dev-complete`.
227
- - Keep the Test Hub simple: one registry, one `dev-complete` runner, one latest-result file, one read-only HTML status page, and a few management commands.
228
- - Final Codex summaries should state the current Test Hub result: whether approved always-run tests all passed, failed, blocked, or do not exist.
229
- - Verification should reuse existing commands, scripts, screenshots, or manual checks first.
230
- - Do not create a new script for every bad case.
231
- - For frontend or HTML changes, inspect the rendered page or screenshot before claiming success.
232
- - For any new durable test case, draft a short task-case proposal and confirm with the user before making it active.
233
-
234
- See [`skills/context-guard/SKILL.md`](skills/context-guard/SKILL.md) for the full behavior rules.
184
+ |-- FIND.md
185
+ |-- sessions.jsonl
186
+ |-- sessions/
187
+ |-- bugs-index.json
188
+ |-- bugs/ and fixes/
189
+ |-- tasks/
190
+ |-- map.json
191
+ |-- owns-index.json and cards/ # generated
192
+ |-- preferences.json
193
+ |-- user-messages.md
194
+ `-- private/ # gitignored
195
+ ```
196
+
197
+ See [`SKILL.md`](SKILL.md) (one page) and `.codex/context/FIND.md`.