cleargate 0.14.0 → 0.15.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 (149) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/MANIFEST.json +71 -15
  3. package/dist/admin-api/index.cjs +0 -1
  4. package/dist/admin-api/index.js +1 -2
  5. package/dist/auth/factory.cjs +0 -1
  6. package/dist/auth/factory.js +2 -3
  7. package/dist/auth/require-token.cjs +0 -1
  8. package/dist/auth/require-token.js +1 -2
  9. package/dist/auth/token-store.cjs +0 -1
  10. package/dist/auth/token-store.js +1 -2
  11. package/dist/{bootstrap-root-QKSA5V75.js → bootstrap-root-2H5HVTCC.js} +1 -2
  12. package/dist/{chunk-PDE37WFQ.js → chunk-A7MSQUU7.js} +2 -3
  13. package/dist/{chunk-BTSZOEWC.js → chunk-P6KEDAK2.js} +0 -1
  14. package/dist/{chunk-E3X7IE5E.js → chunk-PY6FHGV5.js} +1 -2
  15. package/dist/{chunk-5DI2Z3C2.js → chunk-Y53ZZYYU.js} +1 -2
  16. package/dist/cli.cjs +1564 -1414
  17. package/dist/cli.js +1514 -1364
  18. package/dist/lib/ledger.cjs +0 -1
  19. package/dist/lib/ledger.js +1 -2
  20. package/dist/lib/lifecycle-reconcile.cjs +0 -1
  21. package/dist/lib/lifecycle-reconcile.js +2 -3
  22. package/dist/{whoami-EANGN46Z.js → whoami-JKQQPABQ.js} +3 -4
  23. package/package.json +4 -3
  24. package/templates/cleargate-planning/.claude/agents/architect.md +4 -2
  25. package/templates/cleargate-planning/.claude/agents/developer.md +4 -11
  26. package/templates/cleargate-planning/.claude/agents/qa.md +14 -6
  27. package/templates/cleargate-planning/.claude/hooks/pending-task-sentinel.sh +2 -2
  28. package/templates/cleargate-planning/.claude/skills/sprint-execution/SKILL.md +19 -1
  29. package/templates/cleargate-planning/.cleargate/config.example.yml +16 -0
  30. package/templates/cleargate-planning/.cleargate/scripts/close_sprint.deferred-verify.red.node.test.ts +245 -0
  31. package/templates/cleargate-planning/.cleargate/scripts/close_sprint.mjs +227 -0
  32. package/templates/cleargate-planning/.cleargate/scripts/gate-checks.json +5 -4
  33. package/templates/cleargate-planning/.cleargate/scripts/init_sprint.mjs +75 -2
  34. package/templates/cleargate-planning/.cleargate/scripts/pre_gate_common.sh +48 -0
  35. package/templates/cleargate-planning/.cleargate/scripts/pre_gate_runner.sh +57 -1
  36. package/templates/cleargate-planning/.cleargate/scripts/provision_worktree_config.sh +155 -0
  37. package/templates/cleargate-planning/.cleargate/scripts/qa_red_lint.mjs +380 -0
  38. package/templates/cleargate-planning/.cleargate/scripts/run_script.sh +34 -1
  39. package/templates/cleargate-planning/.cleargate/scripts/test/cr077_eviction.red.sh +113 -0
  40. package/templates/cleargate-planning/.cleargate/scripts/test/cr078_init.test.sh +309 -0
  41. package/templates/cleargate-planning/.cleargate/scripts/test/cr079_provision.red.sh +262 -0
  42. package/templates/cleargate-planning/.cleargate/scripts/test/cr080_wrapper.test.sh +177 -0
  43. package/templates/cleargate-planning/.cleargate/scripts/test/cr081_qa_red_lint.red.sh +348 -0
  44. package/templates/cleargate-planning/.cleargate/sprint-runs/_off-sprint/.session-totals.json +1 -0
  45. package/templates/cleargate-planning/.cleargate/sprint-runs/_off-sprint/token-ledger.jsonl +27 -0
  46. package/templates/cleargate-planning/.cleargate/templates/sprint_context.md +17 -0
  47. package/templates/cleargate-planning/.cleargate/templates/story.md +1 -0
  48. package/templates/cleargate-planning/MANIFEST.json +71 -15
  49. package/dist/admin-api/index.cjs.map +0 -1
  50. package/dist/admin-api/index.js.map +0 -1
  51. package/dist/auth/factory.cjs.map +0 -1
  52. package/dist/auth/factory.js.map +0 -1
  53. package/dist/auth/require-token.cjs.map +0 -1
  54. package/dist/auth/require-token.js.map +0 -1
  55. package/dist/auth/token-store.cjs.map +0 -1
  56. package/dist/auth/token-store.js.map +0 -1
  57. package/dist/bootstrap-root-QKSA5V75.js.map +0 -1
  58. package/dist/chunk-5DI2Z3C2.js.map +0 -1
  59. package/dist/chunk-BTSZOEWC.js.map +0 -1
  60. package/dist/chunk-E3X7IE5E.js.map +0 -1
  61. package/dist/chunk-PDE37WFQ.js.map +0 -1
  62. package/dist/cli.cjs.map +0 -1
  63. package/dist/cli.js.map +0 -1
  64. package/dist/lib/ledger.cjs.map +0 -1
  65. package/dist/lib/ledger.js.map +0 -1
  66. package/dist/lib/lifecycle-reconcile.cjs.map +0 -1
  67. package/dist/lib/lifecycle-reconcile.js.map +0 -1
  68. package/dist/templates/cleargate-planning/.claude/agents/architect-reader.md +0 -61
  69. package/dist/templates/cleargate-planning/.claude/agents/architect-synth.md +0 -124
  70. package/dist/templates/cleargate-planning/.claude/agents/architect.md +0 -230
  71. package/dist/templates/cleargate-planning/.claude/agents/cleargate-wiki-contradict.md +0 -108
  72. package/dist/templates/cleargate-planning/.claude/agents/cleargate-wiki-ingest.md +0 -194
  73. package/dist/templates/cleargate-planning/.claude/agents/cleargate-wiki-lint.md +0 -261
  74. package/dist/templates/cleargate-planning/.claude/agents/cleargate-wiki-query.md +0 -143
  75. package/dist/templates/cleargate-planning/.claude/agents/developer.md +0 -185
  76. package/dist/templates/cleargate-planning/.claude/agents/devops.md +0 -257
  77. package/dist/templates/cleargate-planning/.claude/agents/qa.md +0 -171
  78. package/dist/templates/cleargate-planning/.claude/agents/reporter.md +0 -274
  79. package/dist/templates/cleargate-planning/.claude/hooks/pending-task-sentinel.sh +0 -209
  80. package/dist/templates/cleargate-planning/.claude/hooks/pre-commit-surface-gate.sh +0 -33
  81. package/dist/templates/cleargate-planning/.claude/hooks/pre-commit-test-ratchet.sh +0 -58
  82. package/dist/templates/cleargate-planning/.claude/hooks/pre-commit.sh +0 -19
  83. package/dist/templates/cleargate-planning/.claude/hooks/pre-edit-gate.sh +0 -162
  84. package/dist/templates/cleargate-planning/.claude/hooks/pre-tool-use-autonomy.sh +0 -58
  85. package/dist/templates/cleargate-planning/.claude/hooks/pre-tool-use-task.sh +0 -148
  86. package/dist/templates/cleargate-planning/.claude/hooks/session-start.sh +0 -75
  87. package/dist/templates/cleargate-planning/.claude/hooks/stamp-and-gate.sh +0 -43
  88. package/dist/templates/cleargate-planning/.claude/hooks/token-ledger.sh +0 -590
  89. package/dist/templates/cleargate-planning/.claude/settings.json +0 -68
  90. package/dist/templates/cleargate-planning/.claude/skills/flashcard/SKILL.md +0 -102
  91. package/dist/templates/cleargate-planning/.claude/skills/sprint-execution/SKILL.md +0 -742
  92. package/dist/templates/cleargate-planning/.cleargate/FLASHCARD.md +0 -7
  93. package/dist/templates/cleargate-planning/.cleargate/config.example.yml +0 -67
  94. package/dist/templates/cleargate-planning/.cleargate/config.yml +0 -18
  95. package/dist/templates/cleargate-planning/.cleargate/delivery/archive/.gitkeep +0 -0
  96. package/dist/templates/cleargate-planning/.cleargate/delivery/pending-sync/.gitkeep +0 -0
  97. package/dist/templates/cleargate-planning/.cleargate/knowledge/cleargate-enforcement.md +0 -551
  98. package/dist/templates/cleargate-planning/.cleargate/knowledge/cleargate-protocol.md +0 -878
  99. package/dist/templates/cleargate-planning/.cleargate/knowledge/mid-sprint-triage-rubric.md +0 -160
  100. package/dist/templates/cleargate-planning/.cleargate/knowledge/readiness-gates.md +0 -213
  101. package/dist/templates/cleargate-planning/.cleargate/knowledge/sprint-closeout-checklist.md +0 -71
  102. package/dist/templates/cleargate-planning/.cleargate/scripts/_migrate-schema-v3.mjs +0 -120
  103. package/dist/templates/cleargate-planning/.cleargate/scripts/assert_story_files.mjs +0 -265
  104. package/dist/templates/cleargate-planning/.cleargate/scripts/close_sprint.mjs +0 -1012
  105. package/dist/templates/cleargate-planning/.cleargate/scripts/collision_surface.sh +0 -114
  106. package/dist/templates/cleargate-planning/.cleargate/scripts/constants.mjs +0 -62
  107. package/dist/templates/cleargate-planning/.cleargate/scripts/dedupe_frontmatter.mjs +0 -219
  108. package/dist/templates/cleargate-planning/.cleargate/scripts/file_surface_diff.sh +0 -320
  109. package/dist/templates/cleargate-planning/.cleargate/scripts/gate-checks.json +0 -15
  110. package/dist/templates/cleargate-planning/.cleargate/scripts/init_gate_config.sh +0 -38
  111. package/dist/templates/cleargate-planning/.cleargate/scripts/init_sprint.mjs +0 -240
  112. package/dist/templates/cleargate-planning/.cleargate/scripts/launch_wave.mjs +0 -341
  113. package/dist/templates/cleargate-planning/.cleargate/scripts/lib/report-filename.mjs +0 -54
  114. package/dist/templates/cleargate-planning/.cleargate/scripts/pre_gate_common.sh +0 -206
  115. package/dist/templates/cleargate-planning/.cleargate/scripts/pre_gate_runner.sh +0 -371
  116. package/dist/templates/cleargate-planning/.cleargate/scripts/prefill_report.mjs +0 -280
  117. package/dist/templates/cleargate-planning/.cleargate/scripts/prep_doc_refresh.mjs +0 -378
  118. package/dist/templates/cleargate-planning/.cleargate/scripts/prep_qa_context.mjs +0 -888
  119. package/dist/templates/cleargate-planning/.cleargate/scripts/run_script.sh +0 -209
  120. package/dist/templates/cleargate-planning/.cleargate/scripts/sprint_trends.mjs +0 -71
  121. package/dist/templates/cleargate-planning/.cleargate/scripts/state.schema.json +0 -127
  122. package/dist/templates/cleargate-planning/.cleargate/scripts/suggest_improvements.mjs +0 -717
  123. package/dist/templates/cleargate-planning/.cleargate/scripts/surface-whitelist.txt +0 -27
  124. package/dist/templates/cleargate-planning/.cleargate/scripts/test/test_assert_story_files.sh +0 -261
  125. package/dist/templates/cleargate-planning/.cleargate/scripts/test/test_file_surface.sh +0 -210
  126. package/dist/templates/cleargate-planning/.cleargate/scripts/test/test_flashcard_gate.sh +0 -190
  127. package/dist/templates/cleargate-planning/.cleargate/scripts/test/test_prep_qa_context.sh +0 -482
  128. package/dist/templates/cleargate-planning/.cleargate/scripts/test/test_test_ratchet.sh +0 -327
  129. package/dist/templates/cleargate-planning/.cleargate/scripts/test_ratchet.mjs +0 -261
  130. package/dist/templates/cleargate-planning/.cleargate/scripts/update_state.mjs +0 -246
  131. package/dist/templates/cleargate-planning/.cleargate/scripts/validate_bounce_readiness.mjs +0 -111
  132. package/dist/templates/cleargate-planning/.cleargate/scripts/validate_state.mjs +0 -184
  133. package/dist/templates/cleargate-planning/.cleargate/scripts/write_dispatch.sh +0 -172
  134. package/dist/templates/cleargate-planning/.cleargate/templates/Bug.md +0 -126
  135. package/dist/templates/cleargate-planning/.cleargate/templates/CR.md +0 -130
  136. package/dist/templates/cleargate-planning/.cleargate/templates/Sprint Plan Template.md +0 -137
  137. package/dist/templates/cleargate-planning/.cleargate/templates/epic.md +0 -166
  138. package/dist/templates/cleargate-planning/.cleargate/templates/hotfix.md +0 -111
  139. package/dist/templates/cleargate-planning/.cleargate/templates/initiative.md +0 -122
  140. package/dist/templates/cleargate-planning/.cleargate/templates/sprint_context.md +0 -50
  141. package/dist/templates/cleargate-planning/.cleargate/templates/sprint_report.md +0 -224
  142. package/dist/templates/cleargate-planning/.cleargate/templates/story.md +0 -213
  143. package/dist/templates/cleargate-planning/CLAUDE.md +0 -66
  144. package/dist/templates/cleargate-planning/MANIFEST.json +0 -503
  145. package/dist/templates/synthesis/active-sprint.md +0 -30
  146. package/dist/templates/synthesis/open-gates.md +0 -38
  147. package/dist/templates/synthesis/product-state.md +0 -31
  148. package/dist/templates/synthesis/roadmap.md +0 -63
  149. package/dist/whoami-EANGN46Z.js.map +0 -1
@@ -1,7 +0,0 @@
1
- # ClearGate Flashcards
2
-
3
- One-liner gotcha log. Newest first. Grep by tag (e.g. `grep '#schema'`).
4
- Active cards have no marker; `[S]` = stale, `[R]` = resolved (see `.claude/skills/flashcard/SKILL.md` Rules 7–8).
5
- Format: `YYYY-MM-DD · #tags · [marker]? lesson`
6
-
7
- ---
@@ -1,67 +0,0 @@
1
- # ClearGate per-repo configuration.
2
- # Copy to .cleargate/config.yml and edit. All keys optional.
3
-
4
- # wiki:
5
- # index_token_ceiling: 8000 # chars budget for wiki/index.md (STORY-015-03)
6
- # # Allowlist of bucket directories the wiki ingests/builds pages for.
7
- # # Only these buckets get per-item pages, index rows, and synthesis listings;
8
- # # every other bucket is skipped (build + ingest + synthesis). Omit the key
9
- # # entirely to ingest ALL buckets (the default). Valid buckets:
10
- # # epics | stories | sprints | proposals | initiatives | crs | bugs
11
- # ingest_buckets:
12
- # - epics
13
- # - sprints # sprint reports
14
- # - crs
15
- # - bugs
16
- # - initiatives
17
-
18
- # gates:
19
- # precommit: "<command run before every commit — typecheck + tests>"
20
- # test: "<command to run the test suite>"
21
- # typecheck: "<command to run the type checker>"
22
- # lint: "<command to run the linter>"
23
-
24
- # Node example:
25
- # gates:
26
- # precommit: "npm run typecheck && npm test"
27
- # test: "npm test"
28
- # typecheck: "npm run typecheck"
29
- # lint: "npm run lint"
30
-
31
- # Node + vitest, AI-orchestrator-friendly (caps worker pool RAM):
32
- # Vitest defaults to one tinypool worker per CPU. With 3+ parallel agents during
33
- # sprint waves (developer/QA), workers stack: 9 cores × 3 agents × ~400MB heap
34
- # = ~10GB peak RAM. Cap the pool by editing vitest.config.ts directly (CLI
35
- # overrides like `--pool-options.forks.maxForks=N` collide with tinypool's
36
- # minThreads/maxThreads validation when pool=forks):
37
- #
38
- # // vitest.config.ts
39
- # import { defineConfig } from 'vitest/config';
40
- # const maxForks = Number(process.env.VITEST_MAX_FORKS ?? 2);
41
- # export default defineConfig({
42
- # test: {
43
- # pool: 'forks',
44
- # poolOptions: { forks: { minForks: 1, maxForks } },
45
- # },
46
- # });
47
- #
48
- # CI pipelines with plentiful RAM should set VITEST_MAX_FORKS=<cpu-count>.
49
-
50
- # Go example:
51
- # gates:
52
- # precommit: "go vet ./... && go test ./..."
53
- # test: "go test ./..."
54
- # typecheck: "go build ./..."
55
-
56
- # Python example:
57
- # gates:
58
- # precommit: "mypy . && pytest"
59
- # test: "pytest"
60
- # typecheck: "mypy ."
61
-
62
- # Rust example:
63
- # gates:
64
- # precommit: "cargo check && cargo test"
65
- # test: "cargo test"
66
- # typecheck: "cargo check"
67
- # lint: "cargo clippy"
@@ -1,18 +0,0 @@
1
- # ClearGate per-repo configuration.
2
- # See config.example.yml for the full schema (gates, ceilings, all options).
3
- # This file is seeded by `cleargate init`. Edit freely — re-init will not
4
- # clobber your changes (skipped when it differs, unless you pass --force).
5
-
6
- wiki:
7
- # Buckets the compiled wiki ingests pages for. `stories` is intentionally
8
- # omitted: story pages are too granular/numerous for the awareness layer, so
9
- # the wiki tracks epics/sprints/proposals/crs/bugs/initiatives instead.
10
- # Stories still sync to ClearGate via `cleargate push` — only the local wiki
11
- # skips them. Add `stories` here if you want per-story wiki pages back.
12
- ingest_buckets:
13
- - epics
14
- - sprints
15
- - proposals
16
- - crs
17
- - bugs
18
- - initiatives
@@ -1,551 +0,0 @@
1
- # ClearGate Enforcement
2
-
3
- Hook-enforced rules surfaced by CLI errors. AI agents read this file when a hook trips, not at session start. Source split from `cleargate-protocol.md` per EPIC-024 (2026-04-30).
4
-
5
- ## Index
6
-
7
- | New § | Source § | Title |
8
- |---|---|---|
9
- | §1 | protocol §15 | Worktree Lifecycle |
10
- | §2 | protocol §16 | User Walkthrough on Sprint Branch |
11
- | §3 | protocol §17 | Mid-Sprint Change Request Triage |
12
- | §4 | protocol §18 | Immediate Flashcard Gate |
13
- | §5 | protocol §19 | Execution Mode Routing (retired — see §15 Operator Emergency Levers) |
14
- | §6 | protocol §20 | File-Surface Contract |
15
- | §7 | protocol §22 | Advisory Readiness Gates on Push — CR-010 |
16
- | §8 | protocol §23 | Doctor Exit-Code Semantics |
17
- | §9 | protocol §24 | Lane Routing |
18
- | §10 | protocol §25 | Lifecycle Reconciliation (CR-017) |
19
- | §11 | protocol §26 | Decomposition Gate (CR-017) |
20
- | §12 | protocol §27 | Gate 3.5 — Sprint Close Acknowledgement (CR-019) |
21
- | §15 | — | Operator Emergency Levers (STORY-070-01) |
22
-
23
- ---
24
-
25
- ## 1. Worktree Lifecycle (source: protocol §15)
26
-
27
- **Always enforced** (STORY-070-01: `execution_mode` retired — single always-enforced behavior). Every story transition that would run a Developer agent MUST follow these procedures before any file edits begin. Set `CLEARGATE_ADVISORY=1` for break-glass downgrade to warnings (see §15).
28
-
29
- ### §1.1 Branch hierarchy
30
-
31
- The branch hierarchy for a sprint is:
32
-
33
- ```
34
- main
35
- └── sprint/S-XX ← cut at sprint start; never commit directly
36
- └── story/STORY-NNN-NN ← cut when story transitions Ready → Bouncing
37
- ```
38
-
39
- - **Sprint branch** is cut from `main` once at the start of each sprint:
40
- ```bash
41
- git checkout -b sprint/S-XX main
42
- ```
43
- - **Story branch** is cut from the active sprint branch when the story enters `Bouncing` state:
44
- ```bash
45
- git checkout sprint/S-XX
46
- git checkout -b story/STORY-NNN-NN sprint/S-XX
47
- ```
48
- - Story branches are **never** cut from `main` directly; they always track the sprint branch as parent.
49
-
50
- ### §1.2 Worktree commands
51
-
52
- Per-story working trees live under `.worktrees/` at repo root. Each story gets its own isolated filesystem view.
53
-
54
- **Create worktree (story starts bouncing):**
55
- ```bash
56
- git worktree add .worktrees/STORY-NNN-NN -b story/STORY-NNN-NN sprint/S-XX
57
- ```
58
-
59
- **Verify worktree:**
60
- ```bash
61
- git worktree list
62
- # .../repo <sha> [sprint/S-XX]
63
- # .../repo/.worktrees/STORY-NNN-NN <sha> [story/STORY-NNN-NN]
64
- ```
65
-
66
- **Merge story back into sprint branch (story passes QA + Architect):**
67
- ```bash
68
- git checkout sprint/S-XX
69
- git merge story/STORY-NNN-NN --no-ff -m "merge(story/STORY-NNN-NN): STORY-NNN-NN <title>"
70
- ```
71
-
72
- **Remove worktree and story branch (after successful merge):**
73
- ```bash
74
- git worktree remove .worktrees/STORY-NNN-NN
75
- git branch -d story/STORY-NNN-NN
76
- ```
77
-
78
- **Prune stale worktree refs:**
79
- ```bash
80
- git worktree prune
81
- ```
82
-
83
- All commands must be run from the **repo root** (not from inside `.worktrees/`), except Developer Agent file edits which happen inside the assigned worktree path.
84
-
85
- ### §1.3 MCP nested-repo rule
86
-
87
- **The `mcp/` directory is a nested independent git repository.** Running `git worktree add` inside `mcp/` would create a worktree scoped to the nested repo, not to the outer ClearGate repo. This is a git footgun: the outer repo cannot track, merge, or remove the inner worktree via its own git commands.
88
-
89
- **Rule:** Never run `git worktree add` inside `mcp/`. If a story requires edits to `mcp/`, the Developer Agent must edit `mcp/` from inside the outer worktree (`.worktrees/STORY-NNN-NN/mcp/...`) — the nested repo's files are visible there as a subdirectory, not as a separate git context. MCP-native worktree support is deferred to Q3.
90
-
91
- ### §1.4 Local state.json is in-flight authority
92
-
93
- During a story's execution, `state.json` at `.cleargate/sprint-runs/<sprint-id>/state.json` is the single source of truth for story state. The MCP server is a **post-facto audit** channel: it receives state updates after each transition but is never consulted during execution. If MCP is unavailable, execution continues uninterrupted; state.json records the ground truth that MCP will eventually replicate. (Source: EPIC-013 Q7 resolution.)
94
-
95
- ### §1.5 Enforcement gates
96
-
97
- **Always enforced.** Attempting to run a Developer Agent on a story without a matching `.worktrees/STORY-NNN-NN/` path present causes `validate_bounce_readiness.mjs` to exit non-zero and the orchestrator to halt the story transition. Set `CLEARGATE_ADVISORY=1` (§15) for break-glass downgrade.
98
-
99
- ### §1.6 Parallel-wave worktree contract (source: protocol §23)
100
-
101
- Under `execution_mode: v2-parallel` a wave runs multiple per-story segments concurrently, each in its OWN ClearGate-managed `.worktrees/STORY-X` (created via `git worktree add .worktrees/STORY-X -b story/STORY-X sprint/S-NN` — **not** the Workflow tool's `isolation:'worktree'`, which strips gitignored `/.claude/` + `/mcp/` and cuts off the wrong base; spike decision 2). Two file-surface axes:
102
-
103
- - **Per-worktree `.git` index (no race).** Each segment commits inside its own worktree with an isolated `.git` index, so the pre-commit surface gate (`file_surface_diff.sh`) runs per-worktree and parallel in-segment commits do **not** race each other. File-disjointness between co-waved stories is the Architect's `waves.json` guarantee (STORY-033-03's five-clause predicate), not a runtime lock.
104
- - **Shared sprint-branch axis (serial barrier merge).** `sprint/S-NN` is a single-writer axis. The barrier therefore merges each GREEN `story/STORY-X` to `sprint/S-NN` **serially — one worktree at a time, never two concurrently** (protocol §23.3). Concurrent `git worktree add` at wave launch is avoided by pre-creating all wave worktrees serially before any segment runs.
105
-
106
- The kill-switch (`execution_mode: v2-serial` OR `CLEARGATE_PARALLEL_WAVES=off`) reverts to the serial §1.2 worktree lifecycle with zero behavior change.
107
-
108
- ---
109
-
110
- ## 2. User Walkthrough on Sprint Branch (source: protocol §16)
111
-
112
- **Always enforced** (STORY-070-01): the sprint branch MUST NOT merge to `main` until the walkthrough is complete and all `UR:bug` items are resolved.
113
-
114
- ### §2.1 Walkthrough trigger
115
-
116
- After all stories in the sprint are merged into `sprint/S-XX` (every story state ∈ `TERMINAL_STATES`) and before `sprint/S-XX` merges to `main`, the orchestrator invites the user to test the running application on the sprint branch.
117
-
118
- ### §2.2 Feedback classification
119
-
120
- User feedback during the walkthrough is classified into exactly two event types:
121
-
122
- | Event type | Definition | Bug-Fix Tax effect |
123
- |---|---|---|
124
- | `UR:review-feedback` | Enhancement, polish, copy change, or UX preference — does NOT fix broken behavior | Does NOT increment Bug-Fix Tax |
125
- | `UR:bug` | Defect, crash, wrong output, or behavior broken relative to spec | DOES increment Bug-Fix Tax |
126
-
127
- **Classification rule:** when in doubt, ask the user one targeted question — "Is this broken relative to spec, or a preference?" Do not default to `UR:bug`.
128
-
129
- ### §2.3 Logging
130
-
131
- Each piece of walkthrough feedback MUST be logged in the sprint markdown file under `## 4. Execution Log` with the event prefix:
132
-
133
- ```
134
- UR:review-feedback 2026-04-21 — copy should say "Sign in" not "Log in" (resolved: STORY-013-09-dev.md commit abc123)
135
- UR:bug 2026-04-21 — create-project button 500s on submit (resolved: STORY-013-10-dev.md commit def456)
136
- ```
137
-
138
- ### §2.4 Resolution gate
139
-
140
- The sprint branch MUST NOT merge to `main` while any `UR:bug` item is unresolved. `UR:review-feedback` items MAY be deferred to the next sprint with orchestrator + user acknowledgment logged.
141
-
142
- ---
143
-
144
- ## 3. Mid-Sprint Change Request Triage (source: protocol §17)
145
-
146
- **Always enforced** (STORY-070-01): every user-injected change during a bounce MUST be classified before routing.
147
-
148
- ### §3.1 Classification table
149
-
150
- When the user injects new input during a QA bounce or active story execution, the orchestrator classifies the input into one of four categories:
151
-
152
- | Event type | Definition | Bounce-counter effect | Routing |
153
- |---|---|---|---|
154
- | `CR:bug` | Defect introduced by the current story's implementation | Counts toward Bug-Fix Tax; increments `qa_bounces` | Re-open story; Developer fixes; QA re-verifies |
155
- | `CR:spec-clarification` | Clarification of existing spec — no new scope, removes ambiguity | Does NOT increment any bounce counter | Update story acceptance criteria in place; re-run impacted test |
156
- | `CR:scope-change` | Net-new requirement or expansion of story scope | Deferred: create a new Story in `pending-sync/`; current story continues unchanged | New Story ID assigned; current bounce counter unaffected |
157
- | `CR:approach-change` | Switch implementation approach without changing functional spec | Does NOT increment bounce counter; resets Developer context | Re-spawn Developer with updated approach note; same story ID |
158
-
159
- ### §3.2 Logging
160
-
161
- Each mid-sprint CR MUST be logged in the sprint markdown file under `## 4. Execution Log` with the event prefix:
162
-
163
- ```
164
- CR:spec-clarification 2026-04-21 — endpoint must return project slug (clarified in STORY-013-05 §1.2; no new scope)
165
- CR:scope-change 2026-04-21 — user requests audit log table (new STORY-013-11 created in pending-sync/)
166
- ```
167
-
168
- ### §3.3 Scope-change quarantine
169
-
170
- A `CR:scope-change` MUST NOT be folded into the current story's commit. Create a new Story file and handle in a future sprint or as a mid-sprint addition (requires orchestrator + user explicit sign-off to add mid-sprint).
171
-
172
- ---
173
-
174
- ## 4. Immediate Flashcard Gate (source: protocol §18)
175
-
176
- **Always enforced** (STORY-070-01): the orchestrator MUST NOT create the next story's worktree until all `flashcards_flagged` entries from the prior story's dev + QA reports are processed.
177
-
178
- **V-Bounce reference:** `skills/agent-team/SKILL.md` §"Step 5.5: Immediate Flashcard Recording (Hard Gate)" at pinned SHA `2b8477ab65e39e594ee8b6d8cf13a210498eaded`.
179
-
180
- ### §4.1 Trigger
181
-
182
- After story N's commit merges into `sprint/S-XX` and QA approves, the orchestrator collects `flashcards_flagged` from both:
183
- - `STORY-NNN-NN-dev.md` (Developer Agent output report)
184
- - `STORY-NNN-NN-qa.md` (QA Agent output report)
185
-
186
- The two lists are merged (union, deduplication by exact string match). If the combined list is empty, the gate passes immediately.
187
-
188
- ### §4.2 Processing rule
189
-
190
- For each entry in the merged `flashcards_flagged` list, the orchestrator MUST take exactly one of two actions before creating story N+1's worktree:
191
-
192
- | Action | Effect | Record location |
193
- |---|---|---|
194
- | **Approve** | Append the one-liner verbatim to `.cleargate/FLASHCARD.md` (newest-first, per SKILL.md format) | The card itself is the record |
195
- | **Reject** | Discard the entry — do NOT append to `FLASHCARD.md` | Sprint §4 Execution Log: `FLASHCARD-REJECT YYYY-MM-DD — "<card text>" — reason: <one sentence>` |
196
-
197
- ### §4.3 Worktree creation gate
198
-
199
- The orchestrator MUST NOT run `git worktree add .worktrees/STORY-NNN-NN ...` for story N+1 until the §4.2 processing loop is complete (every entry either approved or rejected). This is a blocking serial step, not a background task.
200
-
201
- ### §4.4 Cards format
202
-
203
- Each entry in `flashcards_flagged` MUST conform to the format required by `.claude/skills/flashcard/SKILL.md`:
204
-
205
- ```
206
- YYYY-MM-DD · #tag1 #tag2 · lesson ≤120 chars
207
- ```
208
-
209
- The orchestrator may reformat an entry that violates the format before appending, but must log the reformat in sprint §4 Execution Log.
210
-
211
- ### §4.5 Historical note
212
-
213
- Before STORY-070-01, this gate was advisory under `execution_mode: v1` and mandatory under `execution_mode: v2`. The `execution_mode` field is now retired — this gate is always enforced.
214
-
215
- ### §4.6 PreToolUse hook enforcement
216
-
217
- The `pending-task-sentinel.sh` PreToolUse hook automatically enforces the flashcard gate before every Task (subagent) dispatch. This is implemented by STORY-014-03.
218
-
219
- **Hash-marker convention:**
220
-
221
- Each `flashcards_flagged` card is identified by the first 12 hexadecimal characters of its SHA-1 hash (computed with `shasum -a 1`):
222
-
223
- ```bash
224
- HASH="$(printf '%s' "<card text>" | shasum -a 1 | cut -c1-12)"
225
- ```
226
-
227
- Hash stability: the same card string always produces the same hash. The hash is computed over the exact card string as it appears in the report's `flashcards_flagged` list (after stripping surrounding quotes).
228
-
229
- **Processed marker:**
230
-
231
- To mark a card as processed (approved or rejected by the orchestrator), touch the marker file:
232
-
233
- ```bash
234
- touch .cleargate/sprint-runs/<sprint-id>/.processed-<hash>
235
- ```
236
-
237
- The marker files are gitignored via the existing `.cleargate/sprint-runs/` gitignore rule and serve only as local bookkeeping.
238
-
239
- **Enforcement logic:**
240
-
241
- 1. The hook globs `SPRINT_DIR/STORY-*-dev.md` and `SPRINT_DIR/STORY-*-qa.md` (flat layout — no `reports/` subdirectory).
242
- 2. For each report file, it parses the `flashcards_flagged:` YAML list (inline `[]` and block `- "text"` forms both supported).
243
- 3. For each card, it computes the 12-char SHA-1 hash and checks for the `.processed-<hash>` marker in `SPRINT_DIR`.
244
- 4. If any card is unprocessed:
245
- - exits non-zero (blocks Task spawn) with stderr listing each unprocessed card and the `touch` command hint.
246
- 5. If `flashcards_flagged: []` or no report files exist, the gate passes immediately.
247
-
248
- **Bypass:**
249
-
250
- Set `SKIP_FLASHCARD_GATE=1` in the environment to bypass the gate entirely (both v1 and v2). This bypass is intended for CI and bootstrap scenarios where the hook runs without sprint context. Bypasses should be disabled once M1 is closed; the orchestrator tracks this in the sprint §4 Execution Log.
251
-
252
- ---
253
-
254
- ## 5. Execution Mode Routing (retired — source: protocol §19)
255
-
256
- **STORY-070-01: `execution_mode` field is retired.** All gates are always enforced. This section is preserved for historical context only. See §15 (Operator Emergency Levers) for the break-glass escape hatch.
257
-
258
- ### §5.1 Historical flag semantics (retired)
259
-
260
- The `execution_mode: "v1" | "v2"` field previously controlled whether protocol §§1–18 were enforcing or advisory for a sprint. As of STORY-070-01, this distinction is removed — the v2 (enforcing) behavior is unconditionally active. The field is stripped from state.json by the `_migrate-schema-v3.mjs` migrator on first read.
261
-
262
- ### §5.2 Sprint-scoped flag (retired)
263
-
264
- Previously sprint-scoped. Now irrelevant — all sprints use the single always-enforced behavior.
265
-
266
- ### §5.3 Orchestrator routing rule (retired)
267
-
268
- Previously, before spawning any agent, the orchestrator read the `execution_mode` frontmatter field and routed accordingly. As of STORY-070-01, this field is retired. The orchestrator always applies §§1–18 as mandatory gates. Use `CLEARGATE_ADVISORY=1` (§15) for break-glass.
269
-
270
- ### §5.4 CLI inert-mode message (retired)
271
-
272
- Previously, v2-only CLI commands would print `v1 mode active — command inert` when `execution_mode: "v1"` was set. This behavior is retired — all CLI commands are always active.
273
-
274
- ### §5.5 Default value (retired)
275
-
276
- Previously defaulted to `"v1"`. The field no longer exists in new state.json files.
277
-
278
- ---
279
-
280
- ## 6. File-Surface Contract (source: protocol §20)
281
-
282
- Each story's §3.1 "Context & Files" table is the **authoritative file surface** for that story's commit. The pre-commit hook enforces this contract automatically. **Always enforced** (STORY-070-01: `execution_mode` retired).
283
-
284
- ### §6.1 Rule
285
-
286
- A Developer agent MUST NOT stage and commit any file not declared in the active story's §3.1 table, unless that file matches a whitelist entry in `.cleargate/scripts/surface-whitelist.txt`.
287
-
288
- Off-surface edits require one of:
289
- 1. A CR:scope-change item approved before the commit, OR
290
- 2. An updated §3.1 table committed in the same story (self-amending surface — rare, must be explicitly justified in the commit message).
291
-
292
- ### §6.2 Hook mechanics
293
-
294
- The gate runs as `.cleargate/scripts/file_surface_diff.sh` invoked via `.claude/hooks/pre-commit-surface-gate.sh` and dispatched from `.claude/hooks/pre-commit.sh`. The dispatcher is symlinked to `.git/hooks/pre-commit`.
295
-
296
- - Under v2: off-surface files cause a non-zero exit — the commit is blocked.
297
- - Under v1: the hook prints a warning but exits 0 (advisory only).
298
- - `SKIP_SURFACE_GATE=1` env variable bypasses the gate entirely (use sparingly; log bypass in sprint §4 Execution Log).
299
-
300
- ### §6.3 §3.1 table contract
301
-
302
- The §3.1 table in `story.md` template uses a two-column `| Item | Value |` pipe table. The parser:
303
- - Scans between the `### 3.1` heading and the next `### ` heading.
304
- - Only processes rows where the Value cell contains `.` or `/` (path-shaped values).
305
- - Strips backticks from values.
306
- - Splits on `, ` to handle multiple paths in one cell.
307
- - Ignores header and separator rows.
308
-
309
- Non-path rows (e.g., "Mirrors", "New Files Needed: Yes/No") are silently skipped.
310
-
311
- ### §6.4 Whitelist
312
-
313
- `.cleargate/scripts/surface-whitelist.txt` declares auto-generated files that are always admitted regardless of story surface. Seed entries include: `cleargate-planning/MANIFEST.json`, `.cleargate/hook-log/*`, `.cleargate/sprint-runs/**/token-ledger.jsonl`, `.cleargate/sprint-runs/**/.pending-task-*.json`, `.cleargate/sprint-runs/**/state.json`.
314
-
315
- ### §6.5 Install (dogfood)
316
-
317
- On `cleargate init`, the scaffold automatically installs the `.git/hooks/pre-commit` symlink. For existing dogfood repositories, install once by hand:
318
-
319
- ```bash
320
- ln -sf ../../.claude/hooks/pre-commit.sh .git/hooks/pre-commit
321
- ```
322
-
323
- Log this step in the sprint §4 Execution Log.
324
-
325
- ---
326
-
327
- ## 7. Advisory Readiness Gates on Push (v2) — CR-010 (source: protocol §22)
328
-
329
- ### §7.1 Two-tier push gate semantics
330
-
331
- Push-time gate enforcement uses two distinct tiers:
332
-
333
- **Tier 1 — `approved: true` (hard reject, unchanged):**
334
- `cleargate_push_item` throws `PushNotApprovedError` when `payload.approved !== true`. This is the human go/no-go gate. No advisory mode or env knob overrides it.
335
-
336
- **Tier 2 — `cached_gate_result` (advisory by default):**
337
- When `cached_gate_result.pass === false`, the push proceeds in default advisory mode. The pushed item's body receives a single advisory prefix line placed immediately after the H1 heading (or as the first line if no H1 exists):
338
-
339
- ```
340
- [advisory: gate_failed — <comma-separated criterion ids>]
341
- ```
342
-
343
- Body content beyond the advisory prefix is byte-identical to the input. The push result includes `gate_status: 'open'` and `failing_criteria: [...]` as response metadata (not persisted to the DB schema).
344
-
345
- ### §7.2 Strict-mode opt-in and audit log
346
-
347
- Set `STRICT_PUSH_GATES=true` on the MCP server to restore pre-CR-010 hard-reject behavior (`PushGateFailedError`, no DB write). Default: `false` (advisory mode).
348
-
349
- Advisory pushes (gate_status='open') are recorded in `audit_log` with `result='ok'` — the push succeeded. The `failing_criteria` are surfaced in the push response shape, not in a new audit column. No schema migration is required.
350
- **Rationale:** PM-tool answer-collection requires items to land before readiness answers arrive; advisory mode enables this. See CR-010 §0 for full evidence.
351
-
352
- ---
353
-
354
- ## 8. Doctor Exit-Code Semantics (source: protocol §23)
355
-
356
- `cleargate doctor` exits with one of three codes (all modes: default, `--session-start`, `--can-edit`, `--check-scaffold`, `--pricing`). Hooks branch on the integer, not on stdout.
357
- - `0` — clean. No blockers, no config errors. Stdout MAY include informational lines.
358
- - `1` — blocked items or advisory issues (gate failures, stamp errors, drifted SHAs, missing ledger rows). Stdout lists each blocker.
359
- - `2` — ClearGate misconfigured or partially installed (missing `.cleargate/`, missing `MANIFEST.json`, missing `auth.json`, hook resolver failure). Stdout emits a remediation hint. See `cleargate doctor --help`.
360
-
361
- ---
362
-
363
- ## 9. Lane Routing (source: protocol §24)
364
-
365
- A story is eligible for `lane: fast` only if all seven checks pass (any false → `standard`):
366
- 1. **Size cap.** ≤2 files AND ≤50 LOC net (tests count; generated files do not).
367
- 2. **No forbidden surfaces.** Story does not modify: `mcp/src/db/` / `**/migrations/` (schema); `mcp/src/auth/` / `mcp/src/admin-api/auth-*` (auth); `cleargate.config.json` / `mcp/src/config.ts` (runtime config); `mcp/src/adapters/` (adapter API); `cleargate-planning/MANIFEST.json` (scaffold manifest); security-relevant code (token handling, invite verification, gate enforcement).
368
- 3. **No new dependency.** No new package added to any `package.json`.
369
- 4. **Single acceptance scenario or doc-only.** Exactly one `Scenario:` block (or zero for doc-only). `Scenario Outline:` or multiple scenarios → `standard`.
370
- 5. **Existing tests cover the runtime change.** Named test file exists and includes the affected module, OR story is doc/comment/non-runtime config only.
371
- 6. **`expected_bounce_exposure: low`.** `med` or `high` is auto-`standard`.
372
- 7. **No epic-spanning subsystem touches.** All affected files live under the parent epic's declared scope directories.
373
-
374
- **Demotion mechanics.** Demotion is one-way (`fast → standard`). Trigger: pre-gate scanner failure OR post-merge test failure on a fast-lane story. On demotion: set `lane = "standard"`, write `lane_demoted_at` (ISO-8601), `lane_demotion_reason`, reset `qa_bounces = 0` and `arch_bounces = 0` (see STORY-022-02 schema). Architect plan is invoked and QA spawned per standard contract.
375
-
376
- Event-type `LD` (Lane Demotion) is recorded in sprint markdown §4 alongside existing `UR` and `CR` events; Reporter aggregates into §3 Execution Metrics > Fast-Track Demotion Rate.
377
-
378
- ---
379
-
380
- ## 10. Lifecycle Reconciliation (CR-017) (source: protocol §25)
381
-
382
- ### §10.1 Purpose
383
-
384
- Artifact lifecycle drift occurs when a Developer agent commits `feat(STORY-NNN-NN): ...` but the artifact's `status:` field is never advanced and the file is never moved to `archive/`. CR-017 enforces status reconciliation at two sprint boundaries: sprint close and sprint kickoff.
385
-
386
- ### §10.2 Verb-to-Status Map (v1)
387
-
388
- | Commit verb pattern | Applies to types | Expected terminal status | Expected location |
389
- |---|---|---|---|
390
- | `feat(STORY-NNN-NN): ...` | STORY | `Done` | `archive/` |
391
- | `feat(<TYPE>-NNN): ...` where TYPE ∈ {EPIC, CR} | EPIC, CR | `Completed` OR `Done` | `archive/` |
392
- | `fix(BUG-NNN): ...` | BUG | `Verified` | `archive/` |
393
- | `fix(HOTFIX-NNN-NN): ...` | HOTFIX | `Verified`, `Done`, OR `Completed` | `archive/` |
394
- | `merge: <TYPE>-NNN → ...` | any | ignored — merge commits carry no expectation | n/a |
395
- | `chore(...)`, `docs:`, `refactor:`, `test:`, `file(...)`, `plan(...)` | n/a | no expectation | n/a |
396
- | `feat(BUG-NNN): ...` (verb mismatch) | BUG | soft warning only — does NOT block in v1 | n/a |
397
-
398
- Multi-ID commits: scanner parses subject + first non-empty body line for ALL ID patterns matching `(STORY-\d{3}-\d{2}|CR-\d{3}|BUG-\d{3}|EPIC-\d{3}|HOTFIX-\d{3}-\d{2})`. Each ID gets independent validation. Unknown IDs (no file found) are skipped silently.
399
-
400
- ### §10.3 Carry-Over Semantics
401
-
402
- An artifact with `carry_over: true` in its frontmatter is silently skipped by the lifecycle reconciler — it does not appear in `drift` or `clean` counts. Carry-over is set **explicitly by the human at sprint close** as a deliberate "keep open across boundary" signal. It is never auto-inferred. `close_sprint.mjs` does NOT auto-promote `carry_over: true` artifacts into the next sprint plan.
403
-
404
- ### §10.4 Invocation Points and Gate Mode
405
-
406
- | Phase | Invocation | Mode |
407
- |---|---|---|
408
- | **Sprint close** | `close_sprint.mjs` Step 2.6 via `cleargate sprint reconcile-lifecycle <id>` | Block-by-default. Drift → exit 1 with punch list. |
409
- | **Sprint kickoff — lifecycle layer** | `cleargate sprint init` before `init_sprint.mjs` | **warn-only** when `lifecycle_init_mode: "warn"` in sprint frontmatter (default for SPRINT-15); **block** when `lifecycle_init_mode: "block"` (SPRINT-16+). `--allow-drift` flag skips the warn/block but records a waiver in `context_source:`. |
410
- | **Always active** | Both gates always run (STORY-070-01: single enforced behavior). | n/a |
411
-
412
- ### §10.5 v2 Escalation Path
413
-
414
- `lifecycle_init_mode: "warn"` was the grace setting for SPRINT-15 (already-in-flight artifacts). Starting with SPRINT-16, set `lifecycle_init_mode: "block"` in the sprint frontmatter to enforce hard blocking at kickoff. After one clean SPRINT-15 close, the `warn` grace period ends.
415
-
416
- ---
417
-
418
- ## 11. Decomposition Gate (CR-017) (source: protocol §26)
419
-
420
- ### §11.1 Purpose
421
-
422
- A sprint that references `epics: ["EPIC-X"]` in its plan cannot activate until EPIC-X has been decomposed into at least one `STORY-X-NN_*.md` file with `parent_epic_ref: EPIC-X`. Similarly, a `proposals: ["PROPOSAL-Z"]` reference requires that an EPIC file citing PROPOSAL-Z in its `context_source:` exists. Decomposition is between-sprints transition work — not story-tracked, no Gherkin on the decomposition itself, no QA — but the gate at `cleargate sprint init` verifies the output.
423
-
424
- ### §11.2 Gate Rules
425
-
426
- 1. **Epic → stories.** For each ID in sprint frontmatter `epics:`, a file `EPIC-NNN_*.md` must exist in `pending-sync/` AND at least one `STORY-NNN-NN_*.md` must have `parent_epic_ref: EPIC-NNN` in its frontmatter. Violation: `reason: 'no-child-stories'`.
427
- 2. **Proposal → epic.** For each ID in sprint frontmatter `proposals:`, a file `EPIC-NNN_*.md` must exist in `pending-sync/` with `context_source:` containing the proposal ID string. Violation: `reason: 'no-decomposed-epic'`.
428
- 3. **Anchor file missing.** If the referenced file does not exist at all: `reason: 'file-missing'`.
429
-
430
- ### §11.3 No-Waiver Policy
431
-
432
- The decomposition gate cannot be waived with `--allow-drift`. Passing `--allow-drift` with an outstanding decomposition failure still exits 1 and emits:
433
-
434
- ```
435
- decomposition gate cannot be waived; complete the decomposition or push start_date.
436
- ```
437
-
438
- If the Architect cannot deliver the decomposition before the activating sprint's `start_date`, push `start_date` — do not relax the gate.
439
-
440
- ### §11.4 Invocation
441
-
442
- `cleargate sprint init` calls `reconcileDecomposition()` BEFORE shelling out to `init_sprint.mjs`. A non-empty `missing[]` result exits 1 with a punch list. Always enforced (STORY-070-01).
443
-
444
- ---
445
-
446
- ## 12. Gate 3.5 — Sprint Close Acknowledgement (CR-019) (source: protocol §27)
447
-
448
- ### §12.1 Gate Posture
449
-
450
- Sprint close is a **Gate-3-class action** — same posture as `cleargate_push_item` push-approval (§4 Gate 3), which already requires `approved: true` + explicit human confirmation. Authorising the execution loop ("start sprint NN") does NOT authorise the close. Close requires its own dedicated human approval.
451
-
452
- ### §12.2 Two-Step Protocol
453
-
454
- 1. **Step A — Orchestrator:** runs `node .cleargate/scripts/close_sprint.mjs <sprint-id>` with no flags. The script validates Steps 1–2.6, prefills the report stub if missing, and exits 0 with the exact prompt: `Review the report, then confirm close by re-running with --assume-ack`. The orchestrator surfaces this prompt verbatim to the human and **halts**.
455
- 2. **Step B — Human:** reviews `REPORT.md`, then either runs `node .cleargate/scripts/close_sprint.mjs <sprint-id> --assume-ack` themselves, or explicitly tells the orchestrator "approved, close it" — at which point the orchestrator may pass the flag on the human's behalf.
456
-
457
- ### §12.3 Flag Reservation
458
-
459
- `--assume-ack` is reserved for **automated test environments only**. The conversational orchestrator (the human-facing agent) is a non-test environment and MUST NOT pass `--assume-ack` on its own initiative. Violation of this rule is a Gate-3 breach equivalent to calling `cleargate_push_item` without `approved: true`.
460
-
461
- ## 13. Sprint Execution Gate (Gate 3) (source: new in CR-021)
462
-
463
- Before sprint state transitions Ready → Active, the orchestrator MUST invoke
464
- `cleargate sprint preflight <sprint-id>` and verify all four checks pass:
465
-
466
- 1. **Previous sprint Completed.** Scan `.cleargate/wiki/active-sprint.md` and
467
- `pending-sync/SPRINT-*.md`. The sprint immediately preceding `<sprint-id>`
468
- in the linear sequence must have `sprint_status: "Completed"` in its
469
- `state.json`. Skip the check if there is no preceding sprint (SPRINT-01).
470
-
471
- 2. **No leftover worktrees.** Run `git worktree list` and verify no path
472
- matches `.worktrees/STORY-*`. Leftover worktrees indicate a story from a
473
- prior sprint that wasn't merged or removed cleanly.
474
-
475
- 3. **Sprint branch ref free.** Run `git show-ref refs/heads/sprint/S-NN`. The
476
- ref must NOT exist (we're about to cut it). If it exists, the sprint
477
- was previously started or the prior cleanup didn't complete.
478
-
479
- 4. **`main` is clean.** Run `git status --porcelain` on a `main` checkout.
480
- No uncommitted changes (modified, untracked, staged) may exist.
481
-
482
- On any failure, the script exits 1 with a punch list. The orchestrator surfaces
483
- the failure verbatim to the human and halts. Resolution is per-item:
484
- - Prev sprint not closed → run `cleargate sprint close <prev-id>` first
485
- - Leftover worktree → `git worktree remove` if abandoned, or merge if work in progress
486
- - Branch ref exists → investigate; force-deletion only with explicit human approval
487
- - Dirty main → human commits / stashes / discards as appropriate
488
-
489
- This gate is **always enforced** (STORY-070-01: single always-enforced behavior).
490
-
491
-
492
-
493
- ## 14. Sprint Close Gate (Gate 4) — Pre-close + Post-close additions (source: CR-022)
494
-
495
- `close_sprint.mjs` runs an 8-step close pipeline. Steps 2.7, 2.8, 6.5, 6.6, 6.7, and 8 were added in SPRINT-19 by CR-022 to harden the close pipeline against the issues observed in SPRINT-18 (worktrees left open, sprint branch unmerged, no post-close handoff visibility).
496
-
497
- ### §14.1 Step 2.7 — Worktree-Closed Pre-close Check
498
-
499
- Before any close action, the script verifies no leftover story worktrees remain. Runs `git worktree list --porcelain` and matches paths under `.worktrees/`.
500
-
501
- - **Enforcement (v2):** any leftover worktree halts the close (exit 1) with `Step 2.7 failed: leftover worktree at <path>`. Resolution: `git worktree remove` the abandoned worktree, or merge the in-flight story first.
502
- - **Advisory (v1):** prints `Step 2.7 warning: leftover worktree at <path> (advisory in v1)` to stderr but continues.
503
- - **Test seams:** `CLEARGATE_SKIP_WORKTREE_CHECK=1` (full bypass), `CLEARGATE_FORCE_WORKTREE_PATHS` (test injection).
504
-
505
- ### §14.2 Step 2.8 — Sprint-Merged-to-Main Verify
506
-
507
- Verifies the sprint branch (`sprint/S-NN`) tip is an ancestor of `main`. Runs `git merge-base --is-ancestor <sprint-tip> <main-tip>`.
508
-
509
- - **Enforcement (v2):** unmerged sprint halts the close (exit 1) with `Step 2.8 failed: sprint branch not merged to main`. Resolution: merge `sprint/S-NN` into `main` first.
510
- - **Advisory (v1):** prints `Step 2.8 warning: sprint branch unmerged (advisory in v1)` to stderr but continues.
511
- - **Test seams:** `CLEARGATE_SKIP_MERGE_CHECK=1`, `CLEARGATE_FORCE_MERGE_STATUS=merged|unmerged`, `CLEARGATE_REPO_ROOT` (test override).
512
-
513
- ### §14.3 Steps 6.5 / 6.6 / 6.7 — Post-close additions
514
-
515
- Three non-fatal post-close steps fold into `improvement-suggestions.md`:
516
- - **Step 6.5:** invokes `sprint_trends.mjs` (stub — full implementation deferred to CR-027).
517
- - **Step 6.6:** scans for skill-candidate patterns via `suggest_improvements.mjs --skill-candidates`.
518
- - **Step 6.7:** scans for stale flashcards via `suggest_improvements.mjs --flashcard-cleanup`.
519
-
520
- Each step has its own skip seam (`CLEARGATE_SKIP_SPRINT_TRENDS=1`, `CLEARGATE_SKIP_SKILL_CANDIDATES=1`, `CLEARGATE_SKIP_FLASHCARD_CLEANUP=1`). Failures are non-fatal — printed as `Step 6.x warning:` and the pipeline continues.
521
-
522
- ### §14.4 Step 8 — Verbose post-close handoff list
523
-
524
- Prints a 6-item handoff to stdout summarizing: (1) commits in sprint, (2) merge state, (3) wiki ingest status, (4) flashcard count, (5) artifacts written, (6) next-sprint preflight reminder. The next-sprint ID is computed by parsing the numeric portion of the closing sprint and incrementing it (e.g., SPRINT-19 → SPRINT-20).
525
-
526
- This step replaces the prior 3-line "pipeline complete" summary with explicit action-oriented output for the conversational orchestrator to relay to the human.
527
-
528
- ### §14.5 `--allow-wiki-lint-debt` waiver flag
529
-
530
- `cleargate sprint archive --allow-wiki-lint-debt` waives wiki-lint findings during archive. Reserved for cases where pre-existing wiki-lint debt blocks otherwise-clean archives (e.g., 34 broken-backlink findings carried since SPRINT-16). Without the flag, lint findings cause `archive` to roll back. The flag emits the verbatim Gherkin message `wiki-lint debt waived via --allow-wiki-lint-debt flag` and continues.
531
-
532
- Reporter bundle cap raised from 80KB → 160KB (`MAX_BUNDLE_BYTES` in `prep_reporter_context.mjs`) to absorb heavy-strategy sprint reports. Override via `VITEST_MAX_FORKS`-style `MAX_BUNDLE_BYTES` future env.
533
-
534
- ---
535
-
536
- ## 15. Operator Emergency Levers (STORY-070-01)
537
-
538
- **Internal break-glass env vars for ClearGate operators.** These are undocumented in normal user-facing docs; they exist to allow the framework to progress when a gate blocks incorrectly. Do not use routinely — gate failures are signals of real problems.
539
-
540
- ### `CLEARGATE_ADVISORY=1`
541
-
542
- When set to the exact string `'1'`, all gate failures in the CLI (`cleargate sprint preflight`, `cleargate sprint init`, etc.) are **downgraded from hard exits to stderr warnings** prefixed with `[advisory]`. The command exits 0.
543
-
544
- **Semantics:**
545
- - Only the exact string `'1'` is truthy. Values `'0'`, `'true'`, `'yes'`, `''`, or absent → gate failures remain fatal.
546
- - Implemented in `cleargate-cli/src/util/gate-mode.ts` via `isAdvisory()`.
547
- - Does NOT downgrade migrator errors or parse failures — those remain fatal regardless.
548
-
549
- **When to use:** CI environments bootstrapping a new ClearGate install, or during a sprint where a transient gate failure (e.g., stale state.json) would otherwise block a human-confirmed safe operation.
550
-
551
- **Log advisory use:** Record any use of `CLEARGATE_ADVISORY=1` in the sprint §4 Execution Log.