cleargate 0.8.2 → 0.11.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 (122) hide show
  1. package/CHANGELOG.md +210 -0
  2. package/README.md +22 -1
  3. package/dist/MANIFEST.json +276 -31
  4. package/dist/chunk-HZPJ5QX4.js +459 -0
  5. package/dist/chunk-HZPJ5QX4.js.map +1 -0
  6. package/dist/{chunk-OM4FAEA7.js → chunk-Q3BTSXCK.js} +69 -3
  7. package/dist/chunk-Q3BTSXCK.js.map +1 -0
  8. package/dist/cli.cjs +2888 -598
  9. package/dist/cli.cjs.map +1 -1
  10. package/dist/cli.js +2481 -619
  11. package/dist/cli.js.map +1 -1
  12. package/dist/lib/ledger.cjs +120 -0
  13. package/dist/lib/ledger.cjs.map +1 -0
  14. package/dist/lib/ledger.d.cts +64 -0
  15. package/dist/lib/ledger.d.ts +64 -0
  16. package/dist/lib/ledger.js +96 -0
  17. package/dist/lib/ledger.js.map +1 -0
  18. package/dist/lib/lifecycle-reconcile.cjs +497 -0
  19. package/dist/lib/lifecycle-reconcile.cjs.map +1 -0
  20. package/dist/lib/lifecycle-reconcile.d.cts +136 -0
  21. package/dist/lib/lifecycle-reconcile.d.ts +136 -0
  22. package/dist/lib/lifecycle-reconcile.js +20 -0
  23. package/dist/lib/lifecycle-reconcile.js.map +1 -0
  24. package/dist/templates/cleargate-planning/.claude/agents/architect.md +65 -10
  25. package/dist/templates/cleargate-planning/.claude/agents/cleargate-wiki-contradict.md +108 -0
  26. package/dist/templates/cleargate-planning/.claude/agents/cleargate-wiki-ingest.md +49 -3
  27. package/dist/templates/cleargate-planning/.claude/agents/cleargate-wiki-lint.md +6 -1
  28. package/dist/templates/cleargate-planning/.claude/agents/developer.md +51 -2
  29. package/dist/templates/cleargate-planning/.claude/agents/devops.md +249 -0
  30. package/dist/templates/cleargate-planning/.claude/agents/qa.md +91 -1
  31. package/dist/templates/cleargate-planning/.claude/agents/reporter.md +72 -14
  32. package/dist/templates/cleargate-planning/.claude/hooks/pre-commit-surface-gate.sh +21 -0
  33. package/dist/templates/cleargate-planning/.claude/hooks/pre-tool-use-task.sh +148 -0
  34. package/dist/templates/cleargate-planning/.claude/hooks/session-start.sh +6 -0
  35. package/dist/templates/cleargate-planning/.claude/hooks/stamp-and-gate.sh +12 -1
  36. package/dist/templates/cleargate-planning/.claude/hooks/token-ledger.sh +334 -96
  37. package/dist/templates/cleargate-planning/.claude/settings.json +4 -0
  38. package/dist/templates/cleargate-planning/.claude/skills/sprint-execution/SKILL.md +644 -0
  39. package/dist/templates/cleargate-planning/.cleargate/config.example.yml +19 -0
  40. package/dist/templates/cleargate-planning/.cleargate/knowledge/cleargate-enforcement.md +542 -0
  41. package/dist/templates/cleargate-planning/.cleargate/knowledge/cleargate-protocol.md +102 -428
  42. package/dist/templates/cleargate-planning/.cleargate/knowledge/mid-sprint-triage-rubric.md +160 -0
  43. package/dist/templates/cleargate-planning/.cleargate/knowledge/readiness-gates.md +72 -9
  44. package/dist/templates/cleargate-planning/.cleargate/knowledge/sprint-closeout-checklist.md +71 -0
  45. package/dist/templates/cleargate-planning/.cleargate/scripts/assert_story_files.mjs +24 -2
  46. package/dist/templates/cleargate-planning/.cleargate/scripts/close_sprint.mjs +471 -29
  47. package/dist/templates/cleargate-planning/.cleargate/scripts/dedupe_frontmatter.mjs +219 -0
  48. package/dist/templates/cleargate-planning/.cleargate/scripts/gate-checks.json +3 -3
  49. package/dist/templates/cleargate-planning/.cleargate/scripts/init_sprint.mjs +86 -10
  50. package/dist/templates/cleargate-planning/.cleargate/scripts/lib/report-filename.mjs +54 -0
  51. package/dist/templates/cleargate-planning/.cleargate/scripts/prep_doc_refresh.mjs +378 -0
  52. package/dist/templates/cleargate-planning/.cleargate/scripts/prep_qa_context.mjs +888 -0
  53. package/dist/templates/cleargate-planning/.cleargate/scripts/run_script.sh +173 -87
  54. package/dist/templates/cleargate-planning/.cleargate/scripts/sprint_trends.mjs +71 -0
  55. package/dist/templates/cleargate-planning/.cleargate/scripts/suggest_improvements.mjs +483 -13
  56. package/dist/templates/cleargate-planning/.cleargate/scripts/test/test_prep_qa_context.sh +482 -0
  57. package/dist/templates/cleargate-planning/.cleargate/scripts/validate_state.mjs +32 -8
  58. package/dist/templates/cleargate-planning/.cleargate/scripts/write_dispatch.sh +136 -0
  59. package/dist/templates/cleargate-planning/.cleargate/templates/Bug.md +27 -1
  60. package/dist/templates/cleargate-planning/.cleargate/templates/CR.md +35 -1
  61. package/dist/templates/cleargate-planning/.cleargate/templates/Sprint Plan Template.md +48 -14
  62. package/dist/templates/cleargate-planning/.cleargate/templates/epic.md +40 -3
  63. package/dist/templates/cleargate-planning/.cleargate/templates/hotfix.md +53 -0
  64. package/dist/templates/cleargate-planning/.cleargate/templates/initiative.md +98 -29
  65. package/dist/templates/cleargate-planning/.cleargate/templates/proposal.md +17 -4
  66. package/dist/templates/cleargate-planning/.cleargate/templates/sprint_context.md +8 -0
  67. package/dist/templates/cleargate-planning/.cleargate/templates/sprint_report.md +23 -4
  68. package/dist/templates/cleargate-planning/.cleargate/templates/story.md +58 -3
  69. package/dist/templates/cleargate-planning/CLAUDE.md +30 -10
  70. package/dist/templates/cleargate-planning/MANIFEST.json +276 -31
  71. package/dist/{whoami-CX7CXJD5.js → whoami-W4U6DPVG.js} +17 -17
  72. package/dist/whoami-W4U6DPVG.js.map +1 -0
  73. package/package.json +20 -6
  74. package/templates/cleargate-planning/.claude/agents/architect.md +65 -10
  75. package/templates/cleargate-planning/.claude/agents/cleargate-wiki-contradict.md +108 -0
  76. package/templates/cleargate-planning/.claude/agents/cleargate-wiki-ingest.md +49 -3
  77. package/templates/cleargate-planning/.claude/agents/cleargate-wiki-lint.md +6 -1
  78. package/templates/cleargate-planning/.claude/agents/developer.md +51 -2
  79. package/templates/cleargate-planning/.claude/agents/devops.md +249 -0
  80. package/templates/cleargate-planning/.claude/agents/qa.md +91 -1
  81. package/templates/cleargate-planning/.claude/agents/reporter.md +72 -14
  82. package/templates/cleargate-planning/.claude/hooks/pre-commit-surface-gate.sh +21 -0
  83. package/templates/cleargate-planning/.claude/hooks/pre-tool-use-task.sh +148 -0
  84. package/templates/cleargate-planning/.claude/hooks/session-start.sh +6 -0
  85. package/templates/cleargate-planning/.claude/hooks/stamp-and-gate.sh +12 -1
  86. package/templates/cleargate-planning/.claude/hooks/token-ledger.sh +334 -96
  87. package/templates/cleargate-planning/.claude/settings.json +4 -0
  88. package/templates/cleargate-planning/.claude/skills/sprint-execution/SKILL.md +644 -0
  89. package/templates/cleargate-planning/.cleargate/config.example.yml +19 -0
  90. package/templates/cleargate-planning/.cleargate/knowledge/cleargate-enforcement.md +542 -0
  91. package/templates/cleargate-planning/.cleargate/knowledge/cleargate-protocol.md +102 -428
  92. package/templates/cleargate-planning/.cleargate/knowledge/mid-sprint-triage-rubric.md +160 -0
  93. package/templates/cleargate-planning/.cleargate/knowledge/readiness-gates.md +72 -9
  94. package/templates/cleargate-planning/.cleargate/knowledge/sprint-closeout-checklist.md +71 -0
  95. package/templates/cleargate-planning/.cleargate/scripts/assert_story_files.mjs +24 -2
  96. package/templates/cleargate-planning/.cleargate/scripts/close_sprint.mjs +471 -29
  97. package/templates/cleargate-planning/.cleargate/scripts/dedupe_frontmatter.mjs +219 -0
  98. package/templates/cleargate-planning/.cleargate/scripts/gate-checks.json +3 -3
  99. package/templates/cleargate-planning/.cleargate/scripts/init_sprint.mjs +86 -10
  100. package/templates/cleargate-planning/.cleargate/scripts/lib/report-filename.mjs +54 -0
  101. package/templates/cleargate-planning/.cleargate/scripts/prep_doc_refresh.mjs +378 -0
  102. package/templates/cleargate-planning/.cleargate/scripts/prep_qa_context.mjs +888 -0
  103. package/templates/cleargate-planning/.cleargate/scripts/run_script.sh +173 -87
  104. package/templates/cleargate-planning/.cleargate/scripts/sprint_trends.mjs +71 -0
  105. package/templates/cleargate-planning/.cleargate/scripts/suggest_improvements.mjs +483 -13
  106. package/templates/cleargate-planning/.cleargate/scripts/test/test_prep_qa_context.sh +482 -0
  107. package/templates/cleargate-planning/.cleargate/scripts/validate_state.mjs +32 -8
  108. package/templates/cleargate-planning/.cleargate/scripts/write_dispatch.sh +136 -0
  109. package/templates/cleargate-planning/.cleargate/templates/Bug.md +27 -1
  110. package/templates/cleargate-planning/.cleargate/templates/CR.md +35 -1
  111. package/templates/cleargate-planning/.cleargate/templates/Sprint Plan Template.md +48 -14
  112. package/templates/cleargate-planning/.cleargate/templates/epic.md +40 -3
  113. package/templates/cleargate-planning/.cleargate/templates/hotfix.md +53 -0
  114. package/templates/cleargate-planning/.cleargate/templates/initiative.md +98 -29
  115. package/templates/cleargate-planning/.cleargate/templates/sprint_context.md +8 -0
  116. package/templates/cleargate-planning/.cleargate/templates/sprint_report.md +23 -4
  117. package/templates/cleargate-planning/.cleargate/templates/story.md +58 -3
  118. package/templates/cleargate-planning/CLAUDE.md +30 -10
  119. package/templates/cleargate-planning/MANIFEST.json +276 -31
  120. package/dist/chunk-OM4FAEA7.js.map +0 -1
  121. package/dist/whoami-CX7CXJD5.js.map +0 -1
  122. package/templates/cleargate-planning/.cleargate/templates/proposal.md +0 -61
@@ -0,0 +1,160 @@
1
+ # Mid-Sprint Triage Rubric
2
+
3
+ **CR-047 · SPRINT-23 · Authoritative Reference**
4
+
5
+ This document is the authoritative rubric for classifying mid-sprint user input. It complements the operational routing table in SKILL.md §C.10 (new rubric section). Read this doc to understand *why* a class exists; read SKILL.md §C.11 (post-CR-047 renumber) to see *how* routing works in practice.
6
+
7
+ ---
8
+
9
+ ## Overview
10
+
11
+ When a user injects input during an active sprint (between story kickoff and story merge), the orchestrator must classify it before routing. Unclassified input leads to either silent scope creep or unnecessary story restarts. The four classes below are mutually exclusive and exhaustive.
12
+
13
+ **Classifier aid:** `cleargate-cli/src/lib/triage-classifier.ts` exports a `classify()` pure function that performs keyword-heuristic pre-classification. Output is advisory — the orchestrator confirms before acting. `confidence: 'low'` always requires human verification.
14
+
15
+ ---
16
+
17
+ ## Class 1: Bug
18
+
19
+ **Definition:** The user reports that existing implemented behaviour is incorrect, broken, or regressed against the current story's acceptance spec. A bug does NOT introduce new requirements — it identifies a gap between the spec and the actual behaviour.
20
+
21
+ **Keywords (heuristic):** broken, crashes, doesn't work, does not work, regression, nothing works, not working, failed, failure, error, exception, bug, defect, broke.
22
+
23
+ **Boundary cases:**
24
+ - "The button is broken" → Bug (existing behaviour broken vs spec).
25
+ - "The button should also glow" → NOT Bug; this is Scope Change (new requirement).
26
+ - "After the deploy nothing works" → Bug (regression language).
27
+
28
+ **Worked examples:**
29
+
30
+ 1. "The login button is broken — it throws a 500 error instead of returning 401."
31
+ → Class: Bug · Route: re-open story, Dev fixes, QA re-verifies.
32
+
33
+ 2. "After the deploy the email sending stopped working."
34
+ → Class: Bug · Route: same as above.
35
+
36
+ **Routing rules:**
37
+
38
+ - Increment `qa_bounces` via `update_state.mjs <story-id> --qa-bounce`.
39
+ - Re-open the story; Developer fixes; QA re-verifies (full loop).
40
+ - Log in sprint §4 Execution Log: date + story ID + one-line description.
41
+ - Human approval: NOT required (orchestrator routes autonomously).
42
+
43
+ **Bounce-counter impact:** `qa_bounces++`. If `qa_bounces ≥ 3` → `Escalated`, halt.
44
+
45
+ ---
46
+
47
+ ## Class 2: Spec Clarification
48
+
49
+ **Definition:** The user asks a question or requests clarification about an existing requirement without adding new scope. The story's acceptance Gherkin remains unchanged after the clarification — at most, ambiguous language in §1.2 gets updated in place.
50
+
51
+ **Keywords (heuristic):** what does, what is, clarify, clarification, is the same as, the same as, same as, mean in, mean by, what do you mean, does it include, is this, should it.
52
+
53
+ **Boundary cases:**
54
+ - "What does 'eligible' mean in §3?" → Clarification (no new scope).
55
+ - "Is 'merged' the same as 'closed'?" → Clarification (terminology disambiguation).
56
+ - "What does 'eligible' mean — and should we also check for X?" → SPLIT: Clarification + Scope Change. Handle separately.
57
+
58
+ **Worked examples:**
59
+
60
+ 1. "What does 'eligible' mean in the eligibility check requirement?"
61
+ → Class: Clarification · Update §1.2 with the answer; no story restart.
62
+
63
+ 2. "Is 'merged' the same as 'closed' for the purposes of the state machine?"
64
+ → Class: Clarification · Add a definition note; no counter impact.
65
+
66
+ **Routing rules:**
67
+
68
+ - No counter increment.
69
+ - Update §1.2 (Acceptance Criteria) in place with the clarified definition.
70
+ - Re-run only the impacted test(s) (not full loop).
71
+ - Log in sprint §4 Execution Log: date + story ID + one-line clarification.
72
+ - Human approval: NOT required for terminology clarifications. Required if the clarification reveals a spec gap (surface to human before updating §1.2).
73
+
74
+ **Bounce-counter impact:** None.
75
+
76
+ ---
77
+
78
+ ## Class 3: Scope Change
79
+
80
+ **Definition:** The user introduces a net-new requirement that was not in the original story spec. Even if "obvious" or "related", if the Gherkin would need a new scenario, it is Scope Change.
81
+
82
+ **Keywords (heuristic):** also need, we also need, plus add, additionally, new requirement, add a, add an, plus, as well, in addition, new feature, extend with.
83
+
84
+ **Boundary cases:**
85
+ - "We also need a CSV export" → Scope Change (new feature).
86
+ - "Plus add audit logging" → Scope Change (additional requirement).
87
+ - "The export is broken" → NOT Scope Change; this is Bug.
88
+
89
+ **Worked examples:**
90
+
91
+ 1. "We also need a CSV export alongside the existing JSON export."
92
+ → Class: Scope Change · Quarantine into new story in `pending-sync/`. Current story unchanged.
93
+
94
+ 2. "Plus add audit logging for all admin actions."
95
+ → Class: Scope Change · Same quarantine routing.
96
+
97
+ **Routing rules:**
98
+
99
+ - **Quarantine by default.** Create a new Story file in `.cleargate/delivery/pending-sync/` for the next sprint.
100
+ - Current story proceeds UNCHANGED.
101
+ - **Goal-critical override:** if the new requirement is critical to the active sprint goal, escalate to human: *"This scope-change is goal-critical: the sprint goal is `<verbatim>` and without this change, the goal will not be met. Add to current sprint? (Adding mid-sprint requires explicit ack.)"*
102
+ - Log in sprint §4 Execution Log: date + new story ID + one-line description.
103
+ - Human approval: REQUIRED for mid-sprint addition; NOT required for quarantine.
104
+
105
+ **Bounce-counter impact:** None (quarantine path). If mid-sprint addition approved: treat as a new story dispatch (all counters reset for the new story).
106
+
107
+ ---
108
+
109
+ ## Class 4: Approach Change
110
+
111
+ **Definition:** The user proposes a different implementation technique or technology for the same spec. The acceptance Gherkin remains identical — only the *how* changes, not the *what*.
112
+
113
+ **Keywords (heuristic):** instead of, switch to, different way, different approach, replace with, rather than, alternative, migrate to.
114
+
115
+ **Boundary cases:**
116
+ - "Instead of polling, switch to websockets" → Approach Change (same behaviour spec, different mechanism).
117
+ - "Switch to Postgres instead of Redis for invite storage" → Approach Change (storage backend, same API).
118
+ - "Instead of storing invites, delete them" → NOT Approach Change; this is Scope Change (spec changes).
119
+
120
+ **Worked examples:**
121
+
122
+ 1. "Instead of polling the API every 5 seconds, switch to websockets for real-time updates."
123
+ → Class: Approach Change · No counter; reset Developer context; re-spawn with updated approach note.
124
+
125
+ 2. "Use a different algorithm — BFS instead of DFS for the graph traversal."
126
+ → Class: Approach Change · Same routing.
127
+
128
+ **Routing rules:**
129
+
130
+ - No counter increment.
131
+ - Reset Developer context (re-spawn Developer with the updated approach in the dispatch prompt).
132
+ - Story Gherkin and acceptance criteria remain UNCHANGED.
133
+ - Log in sprint §4 Execution Log: date + story ID + one-line approach delta.
134
+ - Human approval: NOT required if the approach is technically equivalent. Required if the approach change affects cost, timeline, or cross-story surfaces.
135
+
136
+ **Bounce-counter impact:** None.
137
+
138
+ ---
139
+
140
+ ## Routing Summary Table
141
+
142
+ | Class | Trigger | Counter | Human Approval | Routing Action |
143
+ |---|---|---|---|---|
144
+ | Bug | Defect vs spec | `qa_bounces++` | No | Re-open story; Dev fix; QA re-verify |
145
+ | Spec Clarification | Ambiguity question | None | No (yes if spec gap) | Update §1.2 in place; re-run impacted test |
146
+ | Scope Change | Net-new requirement | None | YES for mid-sprint add | Quarantine to next sprint (default); escalate if goal-critical |
147
+ | Approach Change | Different impl, same spec | None | No (yes if cross-story impact) | Reset Dev context; re-spawn with updated approach |
148
+
149
+ ---
150
+
151
+ ## Cross-References
152
+
153
+ - **SKILL.md §C.10** — NEW Mid-Sprint Triage section (operational routing table, added by CR-047).
154
+ - **SKILL.md §C.11** — Mid-cycle User Input table (pre-CR-047 §C.10; renumbered to §C.11 by this CR).
155
+ - **`cleargate-cli/src/lib/triage-classifier.ts`** — keyword-heuristic classifier (advisory, not authoritative).
156
+ - **SKILL.md §C.3.5** — TPV Gate (Architect-only wiring check between QA-Red and Developer).
157
+
158
+ ---
159
+
160
+ _This document is append-only. Add new examples or boundary cases at the bottom of the relevant class block. Do not restructure class ordering — it matches the classifier priority (bug → approach → scope → clarification)._
@@ -6,7 +6,7 @@ This file is the single source of truth for ClearGate's machine-checkable readin
6
6
 
7
7
  ## Predicate Vocabulary
8
8
 
9
- There are exactly **6 predicate shapes**. No other shapes are recognized; a check string that does not match one of these forms throws a parse error at evaluation time.
9
+ There are exactly **7 predicate shapes**. No other shapes are recognized; a check string that does not match one of these forms throws a parse error at evaluation time.
10
10
 
11
11
  **1. `frontmatter(<ref>).<field> <op> <value>`**
12
12
  Reads a frontmatter field from a document. `<ref>` is either `.` (the document being evaluated) or a frontmatter key whose value is a relative path to another document (e.g. `context_source`). `<op>` is one of `==`, `!=`, `>=`, `<=`. `<value>` is a literal string, number, or boolean. Example: `frontmatter(context_source).approved == true` reads the file named by the evaluated document's `context_source` key and asserts its `approved` field equals `true`.
@@ -15,7 +15,13 @@ Reads a frontmatter field from a document. `<ref>` is either `.` (the document b
15
15
  Performs a case-sensitive substring search on the document body (everything after the frontmatter block). The negated form `body does not contain` passes when the string is absent. Example: `body does not contain 'TBD'` fails if the literal string `TBD` appears anywhere in the body.
16
16
 
17
17
  **3. `section(<N>) has <count> <item-type>`**
18
- Splits the document body on `## ` heading boundaries (1-indexed) and counts items of a given type within section N. `<count>` is an expression like `≥1`, `≥3`, or `0` (exact zero). `<item-type>` is one of `checked-checkbox` (lines matching `- [x]`), `unchecked-checkbox` (lines matching `- [ ]`), or `listed-item` (lines matching `- ` regardless of checkbox state). Example: `section(2) has ≥1 checked-checkbox` asserts that the second `##` section contains at least one checked markdown checkbox.
18
+ Splits the document body on `## ` heading boundaries (1-indexed) and counts items of a given type within section N. `<count>` is an expression like `≥1`, `≥3`, or `0` (exact zero). `<item-type>` is one of:
19
+ - `checked-checkbox` — lines matching `- [x]`
20
+ - `unchecked-checkbox` — lines matching `- [ ]`
21
+ - `listed-item` — lines matching `- ` regardless of checkbox state (bullet-precise; use when checkbox/task-list semantics are required, e.g. DoD)
22
+ - `declared-item` — any line that declares a structured item: bullet lines (`- ...`), table data rows (`| ... |` lines following a `|---|`-style separator within the section), or definition-list terms (lines matching `**Item:**`, `Item:`, `*Item*:` etc.). Use `declared-item` when the gate cares only that the author declared at least N entries in section N, regardless of presentation format (table vs bullet vs def-list).
23
+
24
+ Example: `section(2) has ≥1 checked-checkbox` asserts that the second `##` section contains at least one checked markdown checkbox. Example: `section(3) has ≥1 declared-item` passes when §3 contains at least one bullet, table data row, or definition-list term.
19
25
 
20
26
  **4. `file-exists(<path>)`**
21
27
  Asserts that a file exists on disk at the given path, resolved relative to the project root. Example: `file-exists(.cleargate/knowledge/cleargate-protocol.md)` passes when that file is present in the working tree.
@@ -26,6 +32,9 @@ Reads `.cleargate/wiki/index.md` and asserts that the wiki index contains a refe
26
32
  **6. `status-of(<[[ID]]>) == <value>`**
27
33
  Resolves the given ID via the wiki index, reads that page's compiled frontmatter `status:` field, and compares it to `<value>`. Status values in the live corpus are textual strings (`Draft`, `Ready`, `Active`, `Done`) — not emoji. Example: `status-of([[EPIC-008]]) == Active` passes when EPIC-008's wiki page has `status: Active`. Note: this predicate returns `unknown` (evaluates to fail) when the wiki index is stale and the item is not yet compiled. Run `cleargate wiki build` before relying on `status-of` predicates.
28
34
 
35
+ **7. `existing-surfaces-verified`**
36
+ Closed-set predicate (no parameters). Locates the `## Existing Surfaces` section in the document body, extracts path-shaped substrings via regex, asserts each cited path exists on disk relative to the project root. Passes when section is absent (defers to `reuse-audit-recorded`) OR all cited paths exist OR section contains a "no overlap found" / "no existing surface" / "no prior implementation" / "audit returned empty" sentinel. Sandbox-rejected paths (escaping project root) are treated as missing. Example: `existing-surfaces-verified` against an Epic body whose `## Existing Surfaces` cites `cleargate-cli/src/lib/work-item-type.ts:detectWorkItemTypeFromFm` passes when that path exists.
37
+
29
38
  ---
30
39
 
31
40
  ## Severity Model
@@ -60,16 +69,28 @@ The asymmetry exists because Proposal documents are human-authored strategy arti
60
69
  transition: ready-for-decomposition
61
70
  severity: enforcing
62
71
  criteria:
63
- - id: proposal-approved
72
+ - id: parent-approved-proposal
64
73
  check: "frontmatter(context_source).approved == true"
74
+ or_group: parent-approved
75
+ - id: parent-approved-initiative
76
+ check: "frontmatter(context_source).status == 'Triaged'"
77
+ or_group: parent-approved
65
78
  - id: no-tbds
66
79
  check: "body does not contain marker 'TBD'"
67
80
  - id: scope-in-populated
68
- check: "section(2) has ≥1 listed-item"
81
+ check: "section(3) has ≥1 declared-item"
69
82
  - id: affected-files-declared
70
- check: "section(4) has ≥1 listed-item"
83
+ check: "section(5) has ≥1 declared-item"
71
84
  - id: interrogation-resolved
72
85
  check: "body does not contain 'Unresolved'"
86
+ - id: discovery-checked
87
+ check: "frontmatter(.).context_source != null"
88
+ - id: reuse-audit-recorded
89
+ check: "body contains '## Existing Surfaces'"
90
+ - id: existing-surfaces-verified
91
+ check: "existing-surfaces-verified"
92
+ - id: simplest-form-justified
93
+ check: "body contains '## Why not simpler?'"
73
94
  ```
74
95
 
75
96
  ```yaml
@@ -87,6 +108,8 @@ The asymmetry exists because Proposal documents are human-authored strategy arti
87
108
  check: "body does not contain marker 'TBD'"
88
109
  - id: interrogation-resolved
89
110
  check: "body does not contain 'Unresolved'"
111
+ - id: discovery-checked
112
+ check: "frontmatter(.).context_source != null"
90
113
  ```
91
114
 
92
115
  ```yaml
@@ -99,11 +122,19 @@ The asymmetry exists because Proposal documents are human-authored strategy arti
99
122
  - id: no-tbds
100
123
  check: "body does not contain marker 'TBD'"
101
124
  - id: implementation-files-declared
102
- check: "section(3) has ≥1 listed-item"
125
+ check: "section(3) has ≥1 declared-item"
103
126
  - id: dod-declared
104
127
  check: "section(4) has ≥1 listed-item"
105
128
  - id: gherkin-present
106
129
  check: "body contains 'Scenario:'"
130
+ - id: discovery-checked
131
+ check: "frontmatter(.).context_source != null"
132
+ - id: reuse-audit-recorded
133
+ check: "body contains '## Existing Surfaces'"
134
+ - id: existing-surfaces-verified
135
+ check: "existing-surfaces-verified"
136
+ - id: simplest-form-justified
137
+ check: "body contains '## Why not simpler?'"
107
138
  ```
108
139
 
109
140
  ```yaml
@@ -112,11 +143,17 @@ The asymmetry exists because Proposal documents are human-authored strategy arti
112
143
  severity: enforcing
113
144
  criteria:
114
145
  - id: blast-radius-populated
115
- check: "section(2) has ≥1 listed-item"
146
+ check: "section(2) has ≥1 declared-item"
116
147
  - id: no-tbds
117
148
  check: "body does not contain marker 'TBD'"
118
149
  - id: sandbox-paths-declared
119
- check: "section(2) has ≥1 listed-item"
150
+ check: "section(3) has ≥1 declared-item"
151
+ - id: discovery-checked
152
+ check: "frontmatter(.).context_source != null"
153
+ - id: reuse-audit-recorded
154
+ check: "body contains '## Existing Surfaces'"
155
+ - id: existing-surfaces-verified
156
+ check: "existing-surfaces-verified"
120
157
  ```
121
158
 
122
159
  ```yaml
@@ -125,9 +162,35 @@ The asymmetry exists because Proposal documents are human-authored strategy arti
125
162
  severity: enforcing
126
163
  criteria:
127
164
  - id: repro-steps-deterministic
128
- check: "section(2) has ≥3 listed-item"
165
+ check: "section(2) has ≥3 declared-item"
129
166
  - id: severity-set
130
167
  check: "frontmatter(.).severity != null"
131
168
  - id: no-tbds
132
169
  check: "body does not contain marker 'TBD'"
170
+ - id: discovery-checked
171
+ check: "frontmatter(.).context_source != null"
172
+ ```
173
+
174
+ ```yaml
175
+ - work_item_type: sprint
176
+ transition: ready-for-execution
177
+ severity: enforcing
178
+ criteria:
179
+ - id: risk-table-populated
180
+ check: "body contains '| Mitigation'"
181
+ - id: discovery-checked
182
+ check: "frontmatter(.).context_source != null"
183
+ ```
184
+
185
+ ```yaml
186
+ - work_item_type: initiative
187
+ transition: ready-for-decomposition
188
+ severity: advisory
189
+ criteria:
190
+ - id: no-tbds
191
+ check: "body does not contain marker 'TBD'"
192
+ - id: user-flow-populated
193
+ check: "section(1) has ≥1 listed-item"
194
+ - id: success-criteria-populated
195
+ check: "section(5) has ≥1 listed-item"
133
196
  ```
@@ -0,0 +1,71 @@
1
+ # Sprint Closeout Doc & Metadata Refresh Checklist
2
+
3
+ > Read at sprint close (Gate 4 ack). Each item names a surface that may need
4
+ > updating based on what shipped this sprint. Trigger conditions tell you when
5
+ > review is required vs when the surface can be skipped.
6
+ >
7
+ > Use `node .cleargate/scripts/prep_doc_refresh.mjs <sprint-id>` to generate
8
+ > a per-sprint tailored checklist that pre-checks items based on actual
9
+ > changed files in the sprint window.
10
+
11
+ ### 1. Project READMEs
12
+ | Surface | Trigger condition |
13
+ |---|---|
14
+ | `README.md` | Any feature shipped that changes user-visible product behavior |
15
+ | `cleargate-cli/README.md` | Any change to `cleargate-cli/src/commands/*.ts` |
16
+ | `cleargate-planning/README.md` | Any change under `cleargate-planning/` |
17
+ | `mcp/README.md` | Any change under `mcp/src/` (note: nested repo; check separately) |
18
+ | `admin/README.md` | Any change under `admin/` (currently stub) |
19
+
20
+ ### 2. CHANGELOG files (Common-Changelog format per STORY-016-03)
21
+ | Surface | Trigger condition |
22
+ |---|---|
23
+ | `cleargate-cli/CHANGELOG.md` | Any user-visible change in `cleargate-cli/` (CLI surface, error messages, package contents) |
24
+ | `mcp/CHANGELOG.md` | Any user-visible change in `mcp/` (if file exists) |
25
+
26
+ ### 3. Manifest / package metadata
27
+ | Surface | Trigger condition |
28
+ |---|---|
29
+ | `cleargate-planning/MANIFEST.json` | Any change to `.claude/agents/*.md`, `.cleargate/templates/*`, `.cleargate/knowledge/*`, or `.cleargate/scripts/*`. Run `cleargate doctor` to verify scaffold registry. |
30
+ | `cleargate-cli/package.json` | Version bump only if releasing this sprint (release lane is separate from sprint close) |
31
+ | `mcp/package.json` | Version bump only if releasing this sprint |
32
+
33
+ ### 4. CLAUDE.md "Active state" subsection
34
+ | Surface | Trigger condition |
35
+ |---|---|
36
+ | `CLAUDE.md` lines containing "Active state (as of YYYY-MM-DD)" | Any EPIC / CR / Bug / Hotfix archived this sprint, OR any stack version bumped |
37
+ | `cleargate-planning/CLAUDE.md` mirror | Same edit as live (CLEARGATE-tag-block region only — outside-block diverges intentionally) |
38
+
39
+ ### 5. Wiki surfaces (auto-rebuilt by PostToolUse hooks; verify after close)
40
+ | Surface | Verify by |
41
+ |---|---|
42
+ | `.cleargate/wiki/active-sprint.md` | Read top of file; confirm sprint ID, status, and date are current |
43
+ | `.cleargate/wiki/index.md` | Read; confirm new artifacts (epics, stories, CRs) appear in the relevant sections |
44
+ | `.cleargate/wiki/product-state.md` | Read; confirm shipped capabilities are listed |
45
+ | `.cleargate/wiki/roadmap.md` | Read; confirm closed sprint moved from Active to Completed section |
46
+
47
+ ### 6. INDEX surfaces (manual updates)
48
+ | Surface | Trigger condition |
49
+ |---|---|
50
+ | `.cleargate/INDEX.md` | If maintained as a curated roadmap; update when sprint closes |
51
+ | `.cleargate/delivery/INDEX.md` | Update epic/sprint map when new artifacts archived |
52
+
53
+ ### 7. Frontmatter version stamps
54
+ | Surface | Action |
55
+ |---|---|
56
+ | Any `.cleargate/templates/*.md` modified this sprint | Run `cleargate stamp <path>` to bump `updated_at_version` |
57
+ | `.cleargate/knowledge/cleargate-protocol.md` (post-EPIC-024 slim) | Same |
58
+ | `.cleargate/knowledge/cleargate-enforcement.md` (post-EPIC-024 split) | Same |
59
+ | Any other `.cleargate/knowledge/*.md` modified | Same |
60
+
61
+ ### 8. Knowledge doc cross-references
62
+ | Surface | Action |
63
+ |---|---|
64
+ | Any knowledge doc that cites `§N` of protocol or enforcement.md | Verify post-rewrite resolution still works (covered for SPRINT-17 specifically by STORY-024-02; revisit if any future § reorganization happens) |
65
+
66
+ ### 9. Mirror parity audit
67
+ | Surface | Action |
68
+ |---|---|
69
+ | `cleargate-planning/.claude/` | `diff -r .claude/agents/ cleargate-planning/.claude/agents/` empty (excluding skills/ flashcards/, hooks/, settings.json which differ intentionally) |
70
+ | `cleargate-planning/.cleargate/templates/` | `diff -r .cleargate/templates/ cleargate-planning/.cleargate/templates/` empty |
71
+ | `cleargate-planning/.cleargate/knowledge/` | `diff -r .cleargate/knowledge/ cleargate-planning/.cleargate/knowledge/` empty |
@@ -71,7 +71,7 @@ function extractDeliverablesSection(content) {
71
71
  *
72
72
  * STORY before CR/BUG/EPIC/HOTFIX, PROPOSAL before PROP — BUG-010 longest-first rule.
73
73
  */
74
- function extractWorkItemIds(text) {
74
+ export function extractWorkItemIds(text) {
75
75
  const re = /(STORY-\d+-\d+|(CR|BUG|EPIC|HOTFIX)-\d+|(PROPOSAL|PROP)-\d+)/g;
76
76
  const raw = [];
77
77
  let m;
@@ -87,7 +87,7 @@ function extractWorkItemIds(text) {
87
87
  * Check whether pending-sync OR archive contains a file matching <ID>_*.md
88
88
  * Returns the matching absolute path or null.
89
89
  */
90
- function findWorkItemFile(repoRoot, workItemId) {
90
+ export function findWorkItemFile(repoRoot, workItemId) {
91
91
  const searchDirs = [
92
92
  path.join(repoRoot, '.cleargate', 'delivery', 'pending-sync'),
93
93
  path.join(repoRoot, '.cleargate', 'delivery', 'archive'),
@@ -207,6 +207,28 @@ function main() {
207
207
 
208
208
  const sprintFilePath = path.resolve(args[0]);
209
209
 
210
+ // CR-027: --emit-json flag — extract work-item IDs and print JSON to stdout.
211
+ // Used by sprint.ts checkPerItemReadinessGates (path-a shell-out protocol).
212
+ // When this flag is present, skip the file-presence/approval triage and exit 0.
213
+ if (args.includes('--emit-json')) {
214
+ let content;
215
+ try {
216
+ content = fs.readFileSync(sprintFilePath, 'utf8');
217
+ } catch (err) {
218
+ process.stderr.write(`Error: cannot read sprint file: ${err.message}\n`);
219
+ process.exit(2);
220
+ }
221
+ const section = extractDeliverablesSection(content);
222
+ if (section === null) {
223
+ // No §1 section found — emit empty list (not an error for this flag)
224
+ process.stdout.write(JSON.stringify({ workItemIds: [] }) + '\n');
225
+ process.exit(0);
226
+ }
227
+ const workItemIds = extractWorkItemIds(section);
228
+ process.stdout.write(JSON.stringify({ workItemIds }) + '\n');
229
+ process.exit(0);
230
+ }
231
+
210
232
  // Allow test-isolation override of execution_mode
211
233
  const execMode = process.env.CLEARGATE_EXEC_MODE ?? 'v2';
212
234