contract-driven-delivery 1.11.0 → 1.16.0

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 (41) hide show
  1. package/CHANGELOG.md +205 -0
  2. package/README.md +194 -24
  3. package/assets/CLAUDE.template.md +10 -0
  4. package/assets/CODEX.template.md +39 -0
  5. package/assets/agents/backend-engineer.md +4 -23
  6. package/assets/agents/change-classifier.md +130 -24
  7. package/assets/agents/ci-cd-gatekeeper.md +4 -23
  8. package/assets/agents/contract-reviewer.md +4 -23
  9. package/assets/agents/dependency-security-reviewer.md +4 -22
  10. package/assets/agents/e2e-resilience-engineer.md +4 -23
  11. package/assets/agents/frontend-engineer.md +4 -23
  12. package/assets/agents/monkey-test-engineer.md +4 -23
  13. package/assets/agents/qa-reviewer.md +4 -23
  14. package/assets/agents/repo-context-scanner.md +4 -22
  15. package/assets/agents/spec-architect.md +4 -23
  16. package/assets/agents/spec-drift-auditor.md +4 -22
  17. package/assets/agents/stress-soak-engineer.md +4 -23
  18. package/assets/agents/test-strategist.md +4 -23
  19. package/assets/agents/ui-ux-reviewer.md +4 -22
  20. package/assets/agents/visual-reviewer.md +4 -22
  21. package/assets/cdd/context-policy.json +25 -0
  22. package/assets/cdd/model-policy.json +24 -0
  23. package/assets/contracts/api/api-contract.md +3 -0
  24. package/assets/contracts/api/api-inventory.md +7 -0
  25. package/assets/contracts/api/error-format.md +7 -0
  26. package/assets/contracts/business/business-rules.md +3 -0
  27. package/assets/contracts/ci/ci-gate-contract.md +3 -0
  28. package/assets/contracts/css/css-contract.md +3 -0
  29. package/assets/contracts/css/design-tokens.md +7 -0
  30. package/assets/contracts/data/data-shape-contract.md +3 -0
  31. package/assets/contracts/env/env-contract.md +3 -0
  32. package/assets/hooks/post-tool-use-files-read.sh +55 -0
  33. package/assets/skills/cdd-close/SKILL.md +37 -10
  34. package/assets/skills/cdd-new/SKILL.md +200 -164
  35. package/assets/skills/cdd-resume/SKILL.md +31 -3
  36. package/assets/skills/contract-driven-delivery/references/agent-log-protocol.md +117 -0
  37. package/assets/specs-templates/context-manifest.md +44 -0
  38. package/assets/specs-templates/tasks.md +4 -0
  39. package/dist/cli/index.js +2149 -342
  40. package/docs/release-checklist.md +39 -0
  41. package/package.json +6 -3
@@ -49,6 +49,42 @@ If no description is provided, ask the user: "Please describe the change you wan
49
49
 
50
50
  ---
51
51
 
52
+ ## Step 0: Request quality check (BEFORE classifier)
53
+
54
+ Non-engineers often submit ambiguous requests like "fix the slow report" or
55
+ "make it nicer". These cost a full classifier round-trip when the right move is
56
+ to ask back. Before scaffolding anything, verify the request contains all
57
+ three elements below. Rephrase the request internally in this shape:
58
+
59
+ | Element | Example | Required? |
60
+ |---|---|---|
61
+ | 1. Affected surface | "the order export page", "the JWT login flow" | always |
62
+ | 2. Desired behavior change | "complete in <10s", "support 2FA via TOTP" | always |
63
+ | 3. Observable success criterion | "1000-row export finishes without timeout", "user with 2FA can log in end-to-end" | always |
64
+
65
+ If any element is missing or ambiguous, **STOP. Do NOT call `cdd-kit new` or
66
+ the classifier.** Ask the user back in this exact shape:
67
+
68
+ ```
69
+ Before I start a tracked change, I need to lock down three things:
70
+
71
+ Affected surface: <best guess from request, or empty>
72
+ Desired behavior: <best guess, or empty>
73
+ Success criterion: <empty — please fill>
74
+
75
+ Could you confirm or fill in the missing pieces?
76
+ ```
77
+
78
+ Only proceed to Step 1 once all three are answered or the user explicitly says
79
+ "proceed without success criterion". Record the user's clarifications verbatim
80
+ in `change-request.md` § Original Request.
81
+
82
+ The cost of this step: 1 short message round-trip. The cost of skipping it:
83
+ one full classifier+contract-reviewer cycle, often 5-10× more tokens, plus an
84
+ inevitable re-classification when the agents discover the ambiguity.
85
+
86
+ ---
87
+
52
88
  ## Write Responsibilities
53
89
 
54
90
  **This distinction is critical — follow it for every step:**
@@ -72,7 +108,7 @@ If the classifier marks an artifact as `no` or leaves it blank, **do not create
72
108
 
73
109
  The 5 always-required artifacts are: `change-request.md`, `change-classification.md`, `test-plan.md`, `ci-gates.md`, `tasks.md`.
74
110
 
75
- ## Step 1: Generate change-id and scaffold
111
+ ## Step 1: Generate change-id, scaffold, and scan context
76
112
 
77
113
  Derive a `change-id` from the description:
78
114
  - kebab-case, max 5 words
@@ -80,191 +116,103 @@ Derive a `change-id` from the description:
80
116
 
81
117
  Check that `specs/changes/<change-id>/` does not already exist. If it does, append `-2` (or next available suffix).
82
118
 
83
- **Create all scaffold files using Write (do NOT run a Python script; do NOT use Edit on pre-existing files):**
119
+ Create the scaffold with the CLI so every provider gets the same templates:
84
120
 
85
- Create `specs/changes/<change-id>/change-request.md` with the user's description filled in:
121
+ ```bash
122
+ cdd-kit new <change-id>
86
123
  ```
87
- # Change Request: <change-id>
88
-
89
- ## Original Request
90
- <user's exact description, verbatim>
91
-
92
- ## Business / User Goal
93
- <infer from the description>
94
-
95
- ## Non-goals
96
124
 
97
- ## Constraints
125
+ Then build deterministic context indexes before invoking any classifier:
98
126
 
99
- ## Known Context
100
-
101
- ## Open Questions
102
-
103
- ## Requested Delivery Date / Priority
104
- as soon as possible
105
- ```
106
-
107
- Create `specs/changes/<change-id>/change-classification.md` with blank template:
127
+ ```bash
128
+ cdd-kit context-scan
108
129
  ```
109
- # Change Classification
110
130
 
111
- ## Change Types
112
- - primary:
113
- - secondary:
131
+ Verify these files exist:
132
+ - `specs/changes/<change-id>/context-manifest.md`
133
+ - `specs/context/project-map.md`
134
+ - `specs/context/contracts-index.md`
114
135
 
115
- ## Risk Level
116
- - low / medium / high / critical
136
+ Do not use broad search or ad hoc reads to classify the change before `context-scan` has completed.
117
137
 
118
- ## Impact Radius
119
- - isolated / module-level / cross-module / system-wide
138
+ The generated scaffold contains the artifacts listed in the table below. **All
139
+ templates are written from disk by `cdd-kit new` — do not paste template bodies
140
+ into this prompt.** The on-disk source of truth lives in `specs/templates/` of
141
+ the kit and is bundled into every install.
120
142
 
121
- ## Tier
122
- - 0 / 1 / 2 / 3 / 4 / 5
123
-
124
- ## Architecture Review Required
125
- - yes / no
126
- - reason: (fill only if yes)
127
-
128
- ## Required Artifacts
129
- Always required: change-request.md, change-classification.md, test-plan.md, ci-gates.md, tasks.md
130
-
131
- ## Optional Artifacts (default: no — set yes only with explicit reason)
132
- | artifact | create? | reason |
143
+ | File | Source | Your job |
133
144
  |---|---|---|
134
- | current-behavior.md | no | |
135
- | proposal.md | no | |
136
- | spec.md | no | |
137
- | design.md | no | |
138
- | qa-report.md | no | |
139
- | regression-report.md | no | |
140
-
141
- ## Required Contracts
142
- - API:
143
- - CSS/UI:
144
- - Env:
145
- - Data shape:
146
- - Business logic:
147
- - CI/CD:
148
-
149
- ## Required Test Families
150
- - unit:
151
- - contract:
152
- - integration:
153
- - E2E:
154
- - visual:
155
- - data-boundary:
156
- - resilience:
157
- - fuzz/monkey:
158
- - stress:
159
- - soak:
160
-
161
- ## Required Agents
162
-
163
- ## Assumptions / Clarifications
164
- ```
145
+ | `change-request.md` | `specs/templates/change-request.md` | Fill the `## Original Request` section with the user's exact description before invoking the classifier; leave the rest blank |
146
+ | `change-classification.md` | `specs/templates/change-classification.md` | Replace blank template with classifier output (Step 2) |
147
+ | `test-plan.md` | `specs/templates/test-plan.md` | `test-strategist` writes this directly |
148
+ | `ci-gates.md` | `specs/templates/ci-gates.md` | `ci-cd-gatekeeper` writes this directly |
149
+ | `tasks.md` | `specs/templates/tasks.md` | Tick checkboxes as agents complete; backfill `tier:` frontmatter from classifier (Step 2.4) |
150
+ | `context-manifest.md` | `specs/templates/context-manifest.md` | Replace from classifier `## Context Manifest Draft` (Step 2) |
165
151
 
166
- Create `specs/changes/<change-id>/test-plan.md` with blank template:
167
- ```
168
- # Test Plan: <change-id>
152
+ If `cdd-kit new` reports a missing template, run `cdd-kit upgrade --yes`.
169
153
 
170
- ## Acceptance Criteria → Test Mapping
171
- | criterion id | test family | test file path | tier |
172
- |---|---|---|---|
154
+ ---
173
155
 
174
- ## Test Families Required
175
- | family | tier | notes |
176
- |---|---|---|
177
- | (unit / contract / integration / e2e / data-boundary / resilience / monkey / stress / soak) | | |
156
+ ## Step 2: Classify the change
178
157
 
179
- ## Out of Scope
158
+ Invoke `change-classifier` agent with:
159
+ - The user's change description
160
+ - `specs/changes/<change-id>/change-request.md`
161
+ - `specs/changes/<change-id>/context-manifest.md`
162
+ - `specs/context/project-map.md`
163
+ - `specs/context/contracts-index.md`
180
164
 
181
- ## Notes
182
- (Keep under 10 lines. Implementation detail belongs in the test files themselves.)
183
- ```
165
+ Do not authorize the classifier to read `contracts/`, `src/`, `tests/`, or broad repository search during initial classification. It must use the context indexes to propose candidate paths.
184
166
 
185
- Create `specs/changes/<change-id>/ci-gates.md` with blank template:
186
- ```
187
- # CI Gates: <change-id>
167
+ The classifier must include a `## Context Manifest Draft` section with:
168
+ - affected surfaces
169
+ - allowed paths for each required agent work packet
170
+ - required contracts
171
+ - required tests
172
+ - any context expansion requests that must be approved before implementation
188
173
 
189
- ## Required Gates (block merge if failing)
174
+ **change-classifier is read-only** it will return its output as text.
190
175
 
191
- ## Informational Gates (report only)
176
+ ### If the classifier returns `## Atomic Split Proposal`
192
177
 
193
- ## Nightly / Weekly / Manual Gates
178
+ The classifier has decided this request is too big for a single change. Do
179
+ NOT proceed with the rest of `/cdd-new`. Instead:
194
180
 
195
- ## Promotion Policy
196
- ```
197
-
198
- Create `specs/changes/<change-id>/tasks.md` with ALL checkboxes unchecked:
199
- ```
200
- ---
201
- change-id: <change-id>
202
- status: in-progress
203
- ---
181
+ 1. Show the user the full `## Atomic Split Proposal` table verbatim.
182
+ 2. Ask: "Run these as separate changes (recommended), or force a single
183
+ monolithic change?"
184
+ 3. If user picks "separate":
185
+ - For each row in the proposal table, run `cdd-kit new <change-id>` with
186
+ the listed `--depends-on`.
187
+ - Then say: "I created N change directories. Want me to run `/cdd-new`
188
+ against the first one now?" — wait for confirmation; do not auto-loop.
189
+ 4. If user picks "force monolithic":
190
+ - Re-invoke change-classifier with `force-monolithic` appended to the
191
+ change-request and proceed with whatever Tier the classifier returns.
192
+ 5. Delete the partially-scaffolded change directory you created in Step 1
193
+ if the user picked "separate" and the originally-derived change-id is
194
+ not in the proposal — it would otherwise sit empty and confuse `cdd-kit
195
+ list`.
204
196
 
205
- <!-- [x]=done [-]=N/A [ ]=pending -->
206
-
207
- # Tasks: <change-id>
208
-
209
- ## 1. Preparation
210
- - [ ] 1.1 Confirm classification and required artifacts
211
- - [ ] 1.2 Confirm contracts to update
212
- - [ ] 1.3 Confirm CI/CD gate plan
213
-
214
- ## 2. Contract Updates
215
- - [ ] 2.1 API contract
216
- - [ ] 2.2 CSS/UI contract
217
- - [ ] 2.3 Env contract
218
- - [ ] 2.4 Data shape contract
219
- - [ ] 2.5 Business logic contract
220
- - [ ] 2.6 CI/CD contract
221
-
222
- ## 3. Tests First
223
- - [ ] 3.1 Unit/contract tests
224
- - [ ] 3.2 Integration tests
225
- - [ ] 3.3 E2E/resilience tests
226
- - [ ] 3.4 Data-boundary/monkey tests
227
- - [ ] 3.5 Stress/soak tests if required
228
-
229
- ## 4. Implementation
230
- - [ ] 4.1 Backend
231
- - [ ] 4.2 Frontend
232
- - [ ] 4.3 Env/deploy
233
- - [ ] 4.4 CI/CD workflows
234
-
235
- ## 5. Review
236
- - [ ] 5.1 UI/UX review
237
- - [ ] 5.2 Visual review
238
- - [ ] 5.3 Contract review
239
- - [ ] 5.4 QA review
240
-
241
- ## 6. Verification
242
- - [ ] 6.1 Local gates
243
- - [ ] 6.2 PR required gates
244
- - [ ] 6.3 Informational gates
245
- - [ ] 6.4 Nightly/weekly/manual gates if required
246
-
247
- ## 7. Archive
248
- - [ ] 7.1 Archive change
249
- - [ ] 7.2 Promote durable learnings to contracts or CLAUDE.md
250
- ```
197
+ ### Classifier output lint (B8): refuse stub responses
251
198
 
252
- ---
199
+ Before writing any files, verify the classifier response contains:
253
200
 
254
- ## Step 2: Classify the change
201
+ - `## Tier` followed by `- N` where N is a single digit 0-5 (NOT `0 / 1 / 2 / 3 / 4 / 5` — that is the unfilled placeholder).
202
+ - `## Required Agents` with at least one agent name.
203
+ - `## Inferred Acceptance Criteria` with at least one filled `AC-1: …` line.
255
204
 
256
- Invoke `change-classifier` agent with:
257
- - The user's change description
258
- - The project profile at `specs/project-profile.md` (if it exists)
259
- - The existing contracts in `contracts/` (if any)
205
+ If any of these are missing or still hold the literal placeholder text, STOP. Re-prompt the classifier with the missing pieces named explicitly. Do NOT write classification.md — gate will reject it as a stub anyway and you will have wasted the round-trip.
260
206
 
261
- **change-classifier is read-only** it will return its output as text. After it responds:
207
+ ### When the classifier output passes lint
262
208
 
263
209
  1. **YOU write** `specs/changes/<change-id>/change-classification.md` — replace the blank template with the classifier's classification output.
264
210
  2. **YOU write** `specs/changes/<change-id>/agent-log/change-classifier.md` — copy the Agent Log block from the classifier's response.
265
- 3. **YOU tick** `tasks.md` item `1.1`.
211
+ 3. **YOU update** `specs/changes/<change-id>/context-manifest.md` from the classifier's `## Context Manifest Draft`.
212
+ 4. **YOU update** `tasks.md` frontmatter: set `tier: <N>` to the classifier's tier digit. This is now the authoritative source for `cdd-kit gate` tier-based agent enforcement (the classification.md `## Tier` section is fallback only).
213
+ 5. **YOU tick** `tasks.md` item `1.1`.
266
214
 
267
- Wait until these three writes are done before continuing.
215
+ Wait until these five writes are done before continuing.
268
216
 
269
217
  **After writing change-classification.md**: read the classifier's `## Tasks Not Applicable` list. For each listed task ID (e.g., `2.2`, `4.2`), update `tasks.md` to change that item from `[ ]` to `[-]`. Do this before invoking any other agent.
270
218
 
@@ -287,6 +235,58 @@ Change directory: specs/changes/<change-id>/
287
235
  ```
288
236
  This ensures the agent's Read scope restriction points to the correct directory.
289
237
 
238
+ ### Agent stage badges (UI v1)
239
+
240
+ When you announce that you are about to invoke an agent, prefix the
241
+ announcement with the matching emoji + role tag from the table below. This
242
+ helps a non-engineer scanning the chat stream tell what stage they are in
243
+ without reading the full prompt. Use the badges only in your own narration to
244
+ the user; do not put them inside the prompt sent to the agent.
245
+
246
+ | Stage | Agent | Badge |
247
+ |---|---|---|
248
+ | Decision | `change-classifier` | 🟣 `[classifier]` |
249
+ | Decision | `spec-architect` | 🟣 `[architect]` |
250
+ | Implementation | `backend-engineer` | 🔵 `[backend]` |
251
+ | Implementation | `frontend-engineer` | 🔵 `[frontend]` |
252
+ | Implementation | `ci-cd-gatekeeper` | 🔵 `[ci-cd]` |
253
+ | Implementation | `test-strategist` | 🟡 `[test-plan]` |
254
+ | Heavy testing (Tier 0–1 only) | `e2e-resilience-engineer` | 🟠 `[e2e]` |
255
+ | Heavy testing (Tier 0–1 only) | `monkey-test-engineer` | 🟠 `[monkey]` |
256
+ | Heavy testing (Tier 0–1 only) | `stress-soak-engineer` | 🟠 `[stress]` |
257
+ | Review | `contract-reviewer` | 🟢 `[contracts]` |
258
+ | Review | `qa-reviewer` | 🟢 `[qa]` |
259
+ | Review | `ui-ux-reviewer` | 🟢 `[ui-ux]` |
260
+ | Review | `visual-reviewer` | 🟢 `[visual]` |
261
+ | Review | `dependency-security-reviewer` | 🟢 `[deps-sec]` |
262
+ | Audit | `spec-drift-auditor` | ⚫ `[drift]` |
263
+ | Audit | `repo-context-scanner` | ⚫ `[repo-scan]` |
264
+
265
+ Color semantics:
266
+ - 🟣 purple: deciding what we will do (heavy model, opus-class)
267
+ - 🔵 blue: writing code (sonnet-class implementation)
268
+ - 🟡 yellow: planning tests (sonnet-class)
269
+ - 🟠 orange: heavy testing — only appears for Tier 0–1, signals high-risk scope
270
+ - 🟢 green: reviewing what was done (no code writes; just verdicts)
271
+ - ⚫ neutral: audits and scans (read-only background work)
272
+
273
+ Format: emoji is followed by a single space, then the bracket-tag, then the
274
+ human-readable narration.
275
+
276
+ Examples:
277
+
278
+ ```
279
+ 🟣 [classifier] Reading the request and project map…
280
+ 🟢 [contracts] Confirming the API contract is unchanged. (read-only)
281
+ 🔵 [backend] Implementing the JWT issuance endpoint and writing failing
282
+ tests first per TDD policy.
283
+ 🟠 [stress] Tier 1 high-risk change — running soak test for 30 min.
284
+ ```
285
+
286
+ These badges are pure narration. They MUST NOT be sent inside the agent's
287
+ prompt; the agent's behavior is defined by the agent prompt files in
288
+ `.claude/agents/<name>.md`, not by this badge.
289
+
290
290
  ---
291
291
 
292
292
  ### Tier 4–5 (low risk: docs, prompts, config-only, no behavior change)
@@ -381,14 +381,50 @@ cdd-kit gate <change-id>
381
381
  - YOU tick: `tasks.md` item `6.1`
382
382
  - Proceed to Step 5.
383
383
 
384
- **If gate fails**:
385
- 1. Read the gate error output carefully
386
- 2. Identify which artifact is missing, stub, or invalid
387
- 3. Re-invoke the specific agent responsible for that artifact with the exact fix required
388
- 4. Re-run `cdd-kit gate <change-id>`
389
- 5. Repeat until gate passes (max 3 iterations; if still failing after 3, report to user)
384
+ **If gate fails — structured fix-back routing**:
385
+
386
+ Capture gate's full stderr verbatim. Parse error lines and route each to the
387
+ right owner. The patterns below are exhaustive every gate error message
388
+ matches one of them.
389
+
390
+ | Error pattern | Route to | Re-invocation prompt seed |
391
+ |---|---|---|
392
+ | `agent-log/<name>.md: …` | the named agent | "PREVIOUS GATE FAILURE FOR THIS AGENT: <full error line>. Fix only your `agent-log/<name>.md`. Re-output your Agent Log block." |
393
+ | `change-classification.md: …` | `change-classifier` | "PREVIOUS CLASSIFICATION FAILED GATE: <error>. Re-emit only the failing section." |
394
+ | `context-manifest.md: …` | `change-classifier` | "PREVIOUS MANIFEST FAILED GATE: <error>. Re-emit `## Context Manifest Draft`." |
395
+ | `tasks.md: …` (frontmatter / pending) | YOU (main Claude) — direct edit | n/a — fix `tasks.md` yourself. Don't re-invoke an agent for a file you own. |
396
+ | `Tier <N> change requires agent-log/<X>.md` | invoke the missing agent `<X>` | "TIER <N> REQUIRES THIS LOG. Run your full work, not just the log." |
397
+ | `dependency <id>: upstream change is not completed` | n/a — STOP | Tell user: "Upstream change `<id>` must complete before this change can gate. Run `/cdd-new <id>` first or run `cdd-kit archive <id>` if it's already done." |
398
+ | `validators returned non-zero` | `contract-reviewer` | "PREVIOUS CONTRACT VALIDATION FAILED: <last 10 lines of validator stderr>. Reconcile contracts." |
399
+
400
+ **Re-invocation prompt template** (always use this exact prefix when re-invoking an agent for fix-back):
401
+
402
+ ```
403
+ CURRENT_CHANGE_ID: <change-id>
404
+ Change directory: specs/changes/<change-id>/
405
+
406
+ PREVIOUS GATE FAILURE FOR THIS AGENT (re-invocation):
407
+ <the exact gate error line(s) tied to this agent>
408
+
409
+ FIX TARGET:
410
+ <the specific file or section that needs to change>
411
+
412
+ REFERENCES:
413
+ - references/agent-log-protocol.md (log format)
414
+ - references/<agent-specific-standard>.md (if applicable)
415
+
416
+ Fix this exact issue without re-doing your prior work. Re-output only the
417
+ section that changed plus your updated Agent Log block.
418
+ ```
419
+
420
+ After re-invoking, re-run `cdd-kit gate <change-id>`. Repeat up to **3 times**. Each
421
+ iteration must be on a strictly smaller error set — if the same error returns
422
+ twice, halt and surface to user (an agent stuck in a loop is more expensive
423
+ than a human read).
390
424
 
391
- **Terminal state after 3 failures**: Add a line at the top of `tasks.md` reading `status: gate-blocked` and report all blocking items to the user. The change is paused — do not proceed to Step 5.
425
+ **Terminal state after 3 failures**: Update `tasks.md` frontmatter with
426
+ `status: gate-blocked` and report all remaining errors to the user, grouped
427
+ by responsible agent, so they know who to manually direct next.
392
428
 
393
429
  ---
394
430
 
@@ -37,7 +37,15 @@ If there are many mid-flight changes, suggest `cdd-kit migrate --all` instead.
37
37
 
38
38
  ## Step 1: Read current state
39
39
 
40
- Read `specs/changes/<change-id>/tasks.md`:
40
+ Read only these state files first:
41
+ - `specs/changes/<change-id>/tasks.md`
42
+ - `specs/changes/<change-id>/context-manifest.md` if present
43
+ - `specs/changes/<change-id>/agent-log/*.md`
44
+ - `specs/changes/<change-id>/change-classification.md`
45
+
46
+ Do not run broad repository search during resume. Do not read `src/`, `tests/`, or `contracts/` unless the current `context-manifest.md` authorizes that path or an approved expansion lists it.
47
+
48
+ From `tasks.md`:
41
49
  - Identify all `[x]` (done) items
42
50
  - Identify all `[-]` (N/A) items
43
51
  - Identify all `[ ]` (pending) items
@@ -46,6 +54,12 @@ Read `specs/changes/<change-id>/agent-log/` to list which agents have already ru
46
54
 
47
55
  Read `specs/changes/<change-id>/change-classification.md` to recall the tier and required agents.
48
56
 
57
+ Read `specs/changes/<change-id>/context-manifest.md`:
58
+ - Identify allowed paths and approved expansions.
59
+ - Identify pending Context Expansion Requests.
60
+ - If any request has `status: pending`, stop before invoking agents. Report the request id, requested paths, and reason; ask the user to approve, reject, or narrow it.
61
+ - If `context-manifest.md` is missing on a legacy change, run `cdd-kit migrate <change-id>` before continuing. For context-governed changes, missing manifest is blocking.
62
+
49
63
  ---
50
64
 
51
65
  ## Step 2: Report state and ask to continue
@@ -60,6 +74,8 @@ Status: <in-progress | gate-blocked>
60
74
 
61
75
  Completed agents: <list from agent-log/>
62
76
  Pending tasks: <list of [ ] items>
77
+ Pending context expansions: <none | list request ids and paths>
78
+ Allowed context: <short summary from context-manifest.md>
63
79
 
64
80
  Next agent to run: <agent-name> (based on tier flow and what's missing)
65
81
  ```
@@ -70,9 +86,19 @@ Ask the user: "Continue from <next-agent>? (yes/no)"
70
86
 
71
87
  ## Step 3: Continue the flow
72
88
 
73
- If user confirms, resume from the next agent in the Tier sequence (refer to `/cdd-new` Step 3 for the agent order).
89
+ If user confirms, resume from the next agent in the Tier sequence (refer to `/cdd-new` Step 3 for the agent order, and `/cdd-new` "Agent stage badges" for the colored badges to use in your narration).
90
+
91
+ **Critical**: Inject this block at the start of every agent prompt:
92
+
93
+ ```
94
+ CURRENT_CHANGE_ID: <change-id>
95
+ Change directory: specs/changes/<change-id>/
96
+ Context manifest: specs/changes/<change-id>/context-manifest.md
97
+ Read only paths allowed by the context manifest and approved expansions.
98
+ If more context is needed, stop and output a Context Expansion Request instead of reading outside the manifest.
99
+ ```
74
100
 
75
- **Critical**: Inject `CURRENT_CHANGE_ID: <change-id>` at the start of every agent prompt. Do NOT re-run agents that already have a `status: complete` agent-log.
101
+ Do NOT re-run agents that already have a `status: complete` agent-log.
76
102
 
77
103
  Continue until all required agents are done, then run `cdd-kit gate <change-id>`.
78
104
 
@@ -82,5 +108,7 @@ Continue until all required agents are done, then run `cdd-kit gate <change-id>`
82
108
 
83
109
  - Never re-run an agent that already has `status: complete` in its agent-log
84
110
  - Never start from Step 1 of `/cdd-new` — only resume from the next pending agent
111
+ - Never use broad search to reconstruct state; resume from `tasks.md`, `context-manifest.md`, and `agent-log/`
112
+ - Never continue past pending Context Expansion Requests
85
113
  - If tasks.md has `status: abandoned`, report to user and stop
86
114
  - If tasks.md has `status: gate-blocked`, go directly to gate retry (max 3)
@@ -0,0 +1,117 @@
1
+ # Agent Log Protocol
2
+
3
+ All cdd-kit agents share the same machine-verifiable agent-log format. This file
4
+ is the single source of truth — agent prompts reference it instead of inlining
5
+ the format. `cdd-kit gate` parses these files; drift here equals silent gate
6
+ skips, so do not re-document this in agent prompts.
7
+
8
+ ## Output target
9
+
10
+ Each agent writes (or has main Claude write) one file per run:
11
+
12
+ ```
13
+ specs/changes/<change-id>/agent-log/<agent-name>.md
14
+ ```
15
+
16
+ If the same agent runs more than once for a change (e.g., after fix-back),
17
+ overwrite the file — only the latest run is gate-relevant.
18
+
19
+ ## Required structure
20
+
21
+ ```
22
+ # <Agent Display Name> Log
23
+ - change-id: <id>
24
+ - timestamp: <ISO 8601, e.g. 2026-04-27T14:30:00Z>
25
+ - status: complete | needs-review | blocked
26
+ - files-read:
27
+ - <repo-relative path>
28
+ - <repo-relative path>
29
+ - artifacts:
30
+ - <evidence-type>: <concrete pointer>
31
+ - <evidence-type>: <concrete pointer>
32
+ - next-action: <one line, or "none">
33
+ ```
34
+
35
+ ### Field rules
36
+
37
+ - `change-id` — must match the directory name. Mismatch is a contract violation.
38
+ - `timestamp` — ISO 8601 UTC. Used by spec-drift-auditor for ordering.
39
+ - `status` — exactly one of `complete | needs-review | blocked`. Anything
40
+ else (e.g. `done`, `OK`, `pending`) fails gate.
41
+ - `files-read` — required for context-governed changes (`tasks.md` frontmatter
42
+ has `context-governance: v1`). Each entry must be a repo-relative path.
43
+ Absolute paths and `..` traversal are rejected. If you legitimately read
44
+ nothing beyond your own change directory, write:
45
+ ```
46
+ - files-read:
47
+ - specs/changes/<change-id>/
48
+ ```
49
+ - `artifacts` — concrete pointers only. Allowed forms:
50
+ - `path/to/file.ts:10-45`
51
+ - `tests/foo.test.ts::should reject empty body`
52
+ - `cdd-kit gate <id>: 0 errors` (command + outcome)
53
+ - `contracts/api/api-contract.md#endpoints` (file + anchor)
54
+ - **Never** `verified`, `OK`, `done`, or unscoped prose.
55
+ - `next-action` — when `status: blocked`, this must be ≥ 10 chars and
56
+ not `none`. When `status: complete`, `none` is acceptable.
57
+
58
+ ## Per-agent additional artifact requirements
59
+
60
+ Each agent prompt lists its own `### Required artifacts for this agent`. The
61
+ gate does not enforce those today; they are a discipline contract enforced by
62
+ `qa-reviewer` and `contract-reviewer`. If you add a required artifact in an
63
+ agent prompt, also update the qa-reviewer checklist.
64
+
65
+ ## Self-validation before submitting your response
66
+
67
+ **Every agent MUST self-validate its draft Agent Log block before finishing.**
68
+ A malformed log block forces `cdd-kit gate` to fail, which forces the skill
69
+ to re-invoke you, which costs the user another full agent round. Self-lint is
70
+ ~5 seconds; a re-run is minutes and dollars.
71
+
72
+ Before sending your final response, re-read your `## Agent Log` block and
73
+ verify each item:
74
+
75
+ - [ ] **All four required keys exist**: `status`, `files-read`, `artifacts`,
76
+ `next-action`. (Plus `change-id`, `timestamp` at the top.)
77
+ - [ ] **`status` is one of**: `complete`, `needs-review`, `blocked` — not
78
+ `done`, `OK`, `pending`, `wip`, or anything else.
79
+ - [ ] **Every `artifacts:` line has a concrete pointer**:
80
+ - GOOD: `tests-added: tests/foo.test.ts::should reject empty body`
81
+ - GOOD: `files-changed: src/api/users.ts:45-67`
82
+ - GOOD: `test-output: 5 passed (last 10 lines: …)`
83
+ - BAD: `tests-added: verified`
84
+ - BAD: `files-changed: yes`
85
+ - BAD: `contract: OK`
86
+ Reject any line whose value would not let a reviewer click through.
87
+ - [ ] **If `status: blocked`, `next-action`** is ≥ 10 chars, is NOT `none`,
88
+ `investigate further`, `tbd`, or `n/a`, and names the actual next step
89
+ a human can act on.
90
+ - [ ] **Every `files-read:` entry**: repo-relative path, no leading `/`,
91
+ no `..`, no `~`. If you read your own change directory only, write
92
+ `- specs/changes/<change-id>/`.
93
+
94
+ If any check fails, **fix the block before sending your response**. Do not
95
+ ship a known-bad log and rely on the gate to catch it.
96
+
97
+ ## Gate enforcement summary
98
+
99
+ `cdd-kit gate` rejects an agent log when any of these are true:
100
+
101
+ 1. The file is missing for a tier-required agent (see CONTRACTS for tier matrix).
102
+ 2. `status:` line is missing or has an unknown value.
103
+ 3. `status: blocked` without a concrete `next-action`.
104
+ 4. `files-read` is missing for a context-governed change, or contains an
105
+ absolute path / `..` segment / forbidden path.
106
+ 5. With `--strict`: any `- artifacts:` entry whose value looks like a path but
107
+ does not exist on disk.
108
+
109
+ ## Why this lives in references/
110
+
111
+ The historical mistake was duplicating the protocol inside every agent prompt.
112
+ Sixteen agents × ~30 lines = ~480 lines of identical text loaded on every
113
+ spawn. Moving it here:
114
+
115
+ - Cuts per-agent prompt size by 25–35%.
116
+ - Makes drift between agents impossible (one file to change).
117
+ - Lets gate.ts behavior, tests, and prompts stay in sync via this single doc.
@@ -0,0 +1,44 @@
1
+ # Context Manifest
2
+
3
+ This manifest defines the approved context boundaries for agents working on
4
+ this change. The forbidden-paths baseline lives in `.cdd/context-policy.json`
5
+ and is automatically applied by `cdd-kit gate` — do not duplicate it here.
6
+
7
+ ## Affected Surfaces
8
+ -
9
+
10
+ ## Allowed Paths
11
+ - specs/changes/<change-id>/
12
+ - specs/context/project-map.md
13
+ - specs/context/contracts-index.md
14
+
15
+ ## Required Contracts
16
+ -
17
+
18
+ ## Required Tests
19
+ -
20
+
21
+ ## Agent Work Packets
22
+
23
+ ### change-classifier
24
+ - allowed:
25
+ - specs/changes/<change-id>/
26
+ - specs/context/project-map.md
27
+ - specs/context/contracts-index.md
28
+
29
+ ## Context Expansion Requests
30
+
31
+ <!--
32
+ Agents must request context expansion instead of reading outside their work
33
+ packet. Format example for real requests:
34
+
35
+ - request-id: CER-001
36
+ requested_paths:
37
+ - src/example.ts
38
+ reason: why this file is required
39
+ status: pending
40
+ -->
41
+ -
42
+
43
+ ## Approved Expansions
44
+ -
@@ -1,6 +1,10 @@
1
1
  ---
2
2
  change-id: <change-id>
3
3
  status: in-progress
4
+ tier:
5
+ context-governance: v1
6
+ archive-tasks: ["7.1", "7.2"]
7
+ depends-on: []
4
8
  ---
5
9
 
6
10
  <!-- [x]=done [-]=N/A [ ]=pending -->