its-magic 0.1.2-9 → 0.1.2

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 (232) hide show
  1. package/README.md +1602 -755
  2. package/bin/its-magic.js +121 -11
  3. package/bin/postinstall.js +21 -0
  4. package/installer.ps1 +759 -0
  5. package/installer.py +981 -0
  6. package/installer.sh +649 -0
  7. package/package.json +18 -14
  8. package/scripts/check_intake_template_parity.py +284 -0
  9. package/scripts/doc_profile_lib.py +415 -0
  10. package/scripts/guard_installer_publish.py +88 -0
  11. package/scripts/intake_bug_routing_guard.py +67 -0
  12. package/scripts/intake_evidence_lib.py +802 -0
  13. package/scripts/intake_evidence_validate.py +73 -0
  14. package/scripts/materialize_codebase_map.py +184 -0
  15. package/scripts/remote_config_summary.py +243 -0
  16. package/template/.cursor/agents/curator.mdc +35 -0
  17. package/template/.cursor/agents/dev.mdc +29 -0
  18. package/template/.cursor/agents/po.mdc +141 -0
  19. package/template/.cursor/agents/qa.mdc +28 -0
  20. package/template/.cursor/agents/release.mdc +28 -0
  21. package/template/.cursor/agents/security.mdc +98 -0
  22. package/template/.cursor/agents/tech-lead.mdc +57 -0
  23. package/template/.cursor/commands/architecture.md +127 -0
  24. package/template/.cursor/commands/ask.md +55 -0
  25. package/template/.cursor/commands/auto.md +533 -0
  26. package/template/.cursor/commands/discovery.md +47 -0
  27. package/template/.cursor/commands/execute.md +343 -0
  28. package/template/.cursor/commands/intake.md +323 -0
  29. package/template/.cursor/commands/map-codebase.md +46 -0
  30. package/template/.cursor/commands/memory-audit.md +175 -0
  31. package/template/.cursor/commands/milestone-complete.md +51 -0
  32. package/template/.cursor/commands/milestone-start.md +59 -0
  33. package/template/.cursor/commands/pause.md +64 -0
  34. package/{.cursor/commands/gsd-phase-context.md → template/.cursor/commands/phase-context.md} +6 -2
  35. package/template/.cursor/commands/plan-verify.md +34 -0
  36. package/template/.cursor/commands/qa.md +226 -0
  37. package/template/.cursor/commands/quick.md +41 -0
  38. package/template/.cursor/commands/refresh-context.md +82 -0
  39. package/template/.cursor/commands/release.md +505 -0
  40. package/template/.cursor/commands/research.md +49 -0
  41. package/template/.cursor/commands/resume.md +67 -0
  42. package/template/.cursor/commands/security-review.md +81 -0
  43. package/template/.cursor/commands/sprint-plan.md +103 -0
  44. package/template/.cursor/commands/status-reconcile.md +95 -0
  45. package/template/.cursor/commands/verify-work.md +152 -0
  46. package/template/.cursor/dev-environment.json.example +22 -0
  47. package/{.cursor → template/.cursor}/hooks/README.md +3 -2
  48. package/{.cursor/hooks/gsd-hook.py → template/.cursor/hooks/hook.py} +15 -6
  49. package/template/.cursor/hooks.json +26 -0
  50. package/template/.cursor/remote.json +31 -0
  51. package/template/.cursor/rules/caveman.mdc +184 -0
  52. package/template/.cursor/rules/coding-standards.mdc +39 -0
  53. package/template/.cursor/rules/core.mdc +111 -0
  54. package/template/.cursor/rules/handoffs.mdc +27 -0
  55. package/template/.cursor/rules/quality.mdc +49 -0
  56. package/template/.cursor/scratchpad.local.example.md +323 -0
  57. package/template/.cursor/scratchpad.md +324 -0
  58. package/{.cursor/skills/gsd-team → template/.cursor/skills/its-magic}/SKILL.md +2 -2
  59. package/template/.cursorignore +6 -0
  60. package/template/.env.example +28 -0
  61. package/template/.github/workflows/ci.yml +194 -0
  62. package/{.github → template/.github}/workflows/deploy.yml +5 -2
  63. package/template/.its-magic-version +1 -0
  64. package/template/README.md +1602 -0
  65. package/template/decisions/DEC-0001.md +11 -0
  66. package/template/decisions/DEC-0002.md +11 -0
  67. package/template/docs/developer/README.md +44 -0
  68. package/template/docs/engineering/architecture.md +9 -0
  69. package/template/docs/engineering/artifact-ordering-policy.md +48 -0
  70. package/template/docs/engineering/artifact-ownership-policy.md +57 -0
  71. package/template/docs/engineering/auto-orchestration-reference.md +1211 -0
  72. package/{docs → template/docs}/engineering/codebase-map.md +0 -5
  73. package/template/docs/engineering/compatibility-report.md +20 -0
  74. package/template/docs/engineering/compatibility-signals.md +7 -0
  75. package/template/docs/engineering/component-scope-report.md +16 -0
  76. package/template/docs/engineering/component-scope.md +19 -0
  77. package/template/docs/engineering/context/installer-owned-paths.manifest +96 -0
  78. package/template/docs/engineering/context/readme-section-affinity.json +30 -0
  79. package/template/docs/engineering/decisions.md +16 -0
  80. package/template/docs/engineering/legacy-drift-audit.md +21 -0
  81. package/template/docs/engineering/manifests/components/api-gateway.manifest.yaml +12 -0
  82. package/template/docs/engineering/manifests/registry.manifest.yaml +20 -0
  83. package/template/docs/engineering/manifests/repo.manifest.yaml +11 -0
  84. package/template/docs/engineering/phase-context.md +16 -0
  85. package/template/docs/engineering/release-targets.json +123 -0
  86. package/template/docs/engineering/research.md +29 -0
  87. package/template/docs/engineering/runbook.md +2320 -0
  88. package/template/docs/engineering/runtime-connectivity.md +81 -0
  89. package/template/docs/engineering/security-review.md +33 -0
  90. package/template/docs/engineering/spec-pack/README.md +20 -0
  91. package/template/docs/engineering/state-archive/README.md +15 -0
  92. package/template/docs/engineering/state.md +20 -0
  93. package/template/docs/engineering/status-normalization-report.md +19 -0
  94. package/template/docs/engineering/token-cost-parity-manifest.md +16 -0
  95. package/template/docs/engineering/us-0084-remote-e2e.md +44 -0
  96. package/template/docs/product/acceptance.md +1 -0
  97. package/template/docs/product/backlog.md +5 -0
  98. package/template/docs/product/vision.md +11 -0
  99. package/template/docs/user-guides/README.md +40 -0
  100. package/{handoffs → template/handoffs}/dev_to_qa.md +0 -3
  101. package/{handoffs → template/handoffs}/po_to_tl.md +0 -3
  102. package/{handoffs → template/handoffs}/qa_to_dev.md +1 -2
  103. package/template/handoffs/release_notes.md +51 -0
  104. package/template/handoffs/release_queue.md +47 -0
  105. package/template/handoffs/release_to_dev.md +31 -0
  106. package/template/handoffs/releases/Sxxxx-release-notes.md +62 -0
  107. package/template/handoffs/resume_brief.md +14 -0
  108. package/{handoffs → template/handoffs}/tl_to_dev.md +0 -2
  109. package/template/handoffs/token_cost_runs/README.md +26 -0
  110. package/template/its_magic/.its-magic-version +1 -0
  111. package/template/its_magic/README.md +9 -0
  112. package/template/scripts/auto_outer_driver.py +521 -0
  113. package/template/scripts/caveman_compress_input.py +903 -0
  114. package/template/scripts/check_downstream_ci_guard.py +67 -0
  115. package/template/scripts/check_intake_template_parity.py +284 -0
  116. package/template/scripts/check_token_cost_parity.py +69 -0
  117. package/template/scripts/dev_environment_lib.py +463 -0
  118. package/template/scripts/doc_profile_lib.py +415 -0
  119. package/template/scripts/downstream_ci_guard_lib.py +222 -0
  120. package/template/scripts/enforce-triad-hot-surface.py +753 -0
  121. package/template/scripts/guard_installer_publish.py +88 -0
  122. package/template/scripts/intake_bug_resume_brief_refresh.py +303 -0
  123. package/template/scripts/intake_bug_routing_guard.py +67 -0
  124. package/template/scripts/intake_evidence_lib.py +802 -0
  125. package/template/scripts/intake_evidence_validate.py +73 -0
  126. package/template/scripts/materialize_codebase_map.py +184 -0
  127. package/template/scripts/pack_json_validate.py +130 -0
  128. package/template/scripts/project_readme_coverage_lib.py +417 -0
  129. package/template/scripts/readme_feature_coverage_lib.py +608 -0
  130. package/template/scripts/remote_config_summary.py +243 -0
  131. package/template/scripts/sync_push_gates.py +198 -0
  132. package/template/scripts/token_cost_compare.py +40 -0
  133. package/template/scripts/token_cost_lib.py +108 -0
  134. package/template/scripts/uat_probe_lib.py +868 -0
  135. package/template/scripts/validate-and-push.ps1 +280 -0
  136. package/template/scripts/validate-and-push.sh +243 -0
  137. package/template/scripts/validate_doc_profile.py +103 -0
  138. package/template/scripts/validate_project_readme_coverage.py +151 -0
  139. package/template/scripts/validate_readme_feature_coverage.py +140 -0
  140. package/template/sprints/S0001/progress.md +1 -0
  141. package/template/sprints/S0001/qa-findings.md +9 -0
  142. package/template/sprints/S0001/release-findings.md +24 -0
  143. package/template/sprints/S0001/sprint.md +9 -0
  144. package/template/sprints/S0001/summary.md +7 -0
  145. package/template/sprints/S0001/tasks.md +1 -0
  146. package/template/sprints/S0001/uat.json +6 -0
  147. package/template/sprints/S0001/uat.md +5 -0
  148. package/template/sprints/quick/Q0001/summary.md +1 -0
  149. package/{sprints → template/sprints}/quick/Q0001/task.json +0 -1
  150. package/.cursor/agents/curator.mdc +0 -21
  151. package/.cursor/agents/dev.mdc +0 -20
  152. package/.cursor/agents/po.mdc +0 -19
  153. package/.cursor/agents/qa.mdc +0 -19
  154. package/.cursor/agents/release.mdc +0 -19
  155. package/.cursor/agents/tech-lead.mdc +0 -21
  156. package/.cursor/commands/gsd-architecture.md +0 -29
  157. package/.cursor/commands/gsd-auto.md +0 -27
  158. package/.cursor/commands/gsd-discovery.md +0 -27
  159. package/.cursor/commands/gsd-execute.md +0 -32
  160. package/.cursor/commands/gsd-intake.md +0 -28
  161. package/.cursor/commands/gsd-map-codebase.md +0 -25
  162. package/.cursor/commands/gsd-milestone-complete.md +0 -24
  163. package/.cursor/commands/gsd-milestone-start.md +0 -26
  164. package/.cursor/commands/gsd-pause.md +0 -25
  165. package/.cursor/commands/gsd-plan-verify.md +0 -26
  166. package/.cursor/commands/gsd-qa.md +0 -28
  167. package/.cursor/commands/gsd-quick.md +0 -24
  168. package/.cursor/commands/gsd-refresh-context.md +0 -26
  169. package/.cursor/commands/gsd-release.md +0 -29
  170. package/.cursor/commands/gsd-research.md +0 -28
  171. package/.cursor/commands/gsd-resume.md +0 -26
  172. package/.cursor/commands/gsd-sprint-plan.md +0 -30
  173. package/.cursor/commands/gsd-verify-work.md +0 -25
  174. package/.cursor/hooks.json +0 -26
  175. package/.cursor/plans/cursor-gsd-team-kit_8cfee9b8.plan.md +0 -57
  176. package/.cursor/remote.json +0 -18
  177. package/.cursor/rules/gsd-core.mdc +0 -18
  178. package/.cursor/rules/gsd-handoffs.mdc +0 -10
  179. package/.cursor/rules/gsd-quality.mdc +0 -15
  180. package/.cursor/scratchpad.md +0 -34
  181. package/.github/workflows/ci.yml +0 -47
  182. package/decisions/DEC-0001.md +0 -21
  183. package/decisions/DEC-0002.md +0 -21
  184. package/docs/engineering/architecture.md +0 -354
  185. package/docs/engineering/decisions.md +0 -6
  186. package/docs/engineering/research.md +0 -11
  187. package/docs/engineering/runbook.md +0 -32
  188. package/docs/engineering/state.md +0 -33
  189. package/docs/product/acceptance.md +0 -6
  190. package/docs/product/backlog.md +0 -7
  191. package/docs/product/vision.md +0 -46
  192. package/gsd-installer.ps1 +0 -189
  193. package/gsd-installer.py +0 -195
  194. package/gsd-installer.sh +0 -201
  195. package/handoffs/release_notes.md +0 -14
  196. package/handoffs/resume_brief.md +0 -8
  197. package/milestones/M0001/milestone.json +0 -7
  198. package/milestones/M0001/phases.json +0 -9
  199. package/milestones/M0001/progress.md +0 -3
  200. package/milestones/M0001/summary.md +0 -3
  201. package/scripts/generate-release-notes.ps1 +0 -74
  202. package/scripts/generate-release-notes.sh +0 -63
  203. package/scripts/release-all.ps1 +0 -423
  204. package/scripts/release-all.sh +0 -226
  205. package/sprints/S0001/progress.md +0 -4
  206. package/sprints/S0001/qa-findings.md +0 -113
  207. package/sprints/S0001/sprint.md +0 -70
  208. package/sprints/S0001/summary.md +0 -46
  209. package/sprints/S0001/tasks.md +0 -35
  210. package/sprints/S0001/uat.json +0 -8
  211. package/sprints/S0001/uat.md +0 -8
  212. package/sprints/quick/Q0001/summary.md +0 -3
  213. /package/{.cursor/rules/gsd-escalation.mdc → template/.cursor/rules/escalation.mdc} +0 -0
  214. /package/{.cursor/skills/gsd-team → template/.cursor/skills/its-magic}/templates/acceptance.json +0 -0
  215. /package/{.cursor/skills/gsd-team → template/.cursor/skills/its-magic}/templates/acceptance.md +0 -0
  216. /package/{.cursor/skills/gsd-team → template/.cursor/skills/its-magic}/templates/architecture.json +0 -0
  217. /package/{.cursor/skills/gsd-team → template/.cursor/skills/its-magic}/templates/architecture.md +0 -0
  218. /package/{.cursor/skills/gsd-team → template/.cursor/skills/its-magic}/templates/decision.json +0 -0
  219. /package/{.cursor/skills/gsd-team → template/.cursor/skills/its-magic}/templates/decision.md +0 -0
  220. /package/{.cursor/skills/gsd-team → template/.cursor/skills/its-magic}/templates/handoff.json +0 -0
  221. /package/{.cursor/skills/gsd-team → template/.cursor/skills/its-magic}/templates/handoff.md +0 -0
  222. /package/{.cursor/skills/gsd-team → template/.cursor/skills/its-magic}/templates/milestone.json +0 -0
  223. /package/{.cursor/skills/gsd-team → template/.cursor/skills/its-magic}/templates/phase-context.json +0 -0
  224. /package/{.cursor/skills/gsd-team → template/.cursor/skills/its-magic}/templates/plan-verify.json +0 -0
  225. /package/{.cursor/skills/gsd-team → template/.cursor/skills/its-magic}/templates/sprint.json +0 -0
  226. /package/{.cursor/skills/gsd-team → template/.cursor/skills/its-magic}/templates/sprint.md +0 -0
  227. /package/{.cursor/skills/gsd-team → template/.cursor/skills/its-magic}/templates/story.json +0 -0
  228. /package/{.cursor/skills/gsd-team → template/.cursor/skills/its-magic}/templates/story.md +0 -0
  229. /package/{.cursor/skills/gsd-team → template/.cursor/skills/its-magic}/templates/uat.json +0 -0
  230. /package/{docs → template/docs}/engineering/context/phase-template.json +0 -0
  231. /package/{docs → template/docs}/engineering/dependencies.json +0 -0
  232. /package/{sprints → template/sprints}/S0001/plan-verify.json +0 -0
@@ -0,0 +1,2320 @@
1
+ # Runbook
2
+
3
+ ## Commands
4
+
5
+ TEST_COMMAND: powershell -ExecutionPolicy Bypass -File "tests/run-tests.ps1"
6
+ LINT_COMMAND:
7
+ TYPECHECK_COMMAND:
8
+ DEPLOY_STAGING_COMMAND: echo "No staging deploy target configured for this repository"
9
+ DEPLOY_PROD_COMMAND: echo "No production deploy target configured for this repository"
10
+
11
+ LINT_FIX_COMMAND:
12
+ FORMAT_COMMAND:
13
+ CI_AUTO_FIX: false
14
+ TEST_TIMEOUT_SECONDS: 120
15
+
16
+ ## Notes
17
+ - Leave a command blank to skip that step.
18
+ - Use explicit commands, not placeholders.
19
+ - `TEST_TIMEOUT_SECONDS` limits how long any subprocess can run during tests.
20
+ Prevents hangs from prompts, network waits, or infinite loops.
21
+ - `LINT_FIX_COMMAND` / `FORMAT_COMMAND` are used by CI auto-fix when checks fail
22
+ (e.g. `npx eslint --fix .` or `npx prettier --write .`).
23
+ - `CI_AUTO_FIX`: set to `true` to enable the automatic fix-and-retry loop in
24
+ GitHub Actions. When `false` (default), CI reports failures but does not
25
+ attempt auto-fix commits.
26
+
27
+ ## Intentional empty commands (US-0015)
28
+
29
+ For this template/installer repository, the following command keys may be
30
+ intentionally empty in the shipped template; they are not configuration errors:
31
+
32
+ - `TEST_COMMAND` (blank until installer bootstrap per stack; **DEC-0056**)
33
+ - `LINT_COMMAND`
34
+ - `FORMAT_COMMAND`
35
+ - `TYPECHECK_COMMAND`
36
+
37
+ Teams may set these keys when needed for their own project stack.
38
+
39
+ ## OS-aware runbook command bootstrap (US-0063 / DEC-0046)
40
+
41
+ Installer/upgrade flows auto-bootstrap runbook command keys with deterministic
42
+ precedence:
43
+
44
+ - `user override > detected defaults > safe fail-fast`
45
+ - user-provided non-empty values are never overwritten
46
+ - defaults are inferred from OS + project stack markers
47
+ (`package.json` scripts, `pyproject.toml`, `go.mod`, platform test scripts)
48
+
49
+ Baseline detection contract:
50
+
51
+ - `TEST_COMMAND` is mandatory for push-eligible quality gates.
52
+ - `LINT_COMMAND` and `TYPECHECK_COMMAND` are optional and only auto-populated
53
+ when confidently detectable.
54
+ - if `TEST_COMMAND` remains unresolved/invalid, installer fails fast with:
55
+ - `[RUNBOOK_BOOTSTRAP_ERROR] TEST_COMMAND_UNRESOLVED`, or
56
+ - `[RUNBOOK_BOOTSTRAP_ERROR] TEST_COMMAND_INVALID:<reason>`
57
+
58
+ Remediation:
59
+
60
+ - define `TEST_COMMAND` explicitly in `docs/engineering/runbook.md`, or
61
+ - add detectable stack markers/scripts then rerun installer upgrade.
62
+
63
+ ## Codebase map bootstrap (US-0082 / DEC-0065)
64
+
65
+ **Goal:** `docs/engineering/codebase-map.md` exists in fresh repos without ad-hoc
66
+ operator memory, while **`/map-codebase`** stays the explicit manual analysis
67
+ command.
68
+
69
+ ### Responsibility
70
+
71
+ | Path | Owner | Mechanism |
72
+ |------|-------|-----------|
73
+ | Primary | **`/architecture`** (tech-lead) | Before **`/sprint-plan`**, run `python scripts/materialize_codebase_map.py --trigger architecture` from repo root |
74
+ | Optional refresh | **`/refresh-context`** (curator) | Same script with `--trigger refresh-context` only when scratchpad sets **`CODEBASE_MAP_REFRESH_ON_ROLLOVER=1`** (default off) |
75
+ | Manual / deep pass | Operator | **`/map-codebase`** |
76
+
77
+ ### Write surfaces
78
+
79
+ Same as **`/map-codebase`**: `docs/engineering/codebase-map.md`,
80
+ `docs/engineering/dependencies.json`. The materializer does **not** append
81
+ `docs/engineering/state.md`. Non-bootstrap maps (no bootstrap sentinel in the
82
+ file) are never replaced silently.
83
+
84
+ ### Deterministic diagnostics
85
+
86
+ - **`CODEBASE_MAP_MISSING`** — use when a lifecycle checkpoint requires the map
87
+ but it is absent and generation did not run (e.g. custom **`/auto`** profile
88
+ skipped **`architecture`**).
89
+ - **`CODEBASE_MAP_BLOCKED:<subreason>`** — materializer or policy blocked
90
+ creation (`policy_skip`, permissions, etc.); stdout includes remediation
91
+ pointing here and to **`/map-codebase`**.
92
+
93
+ **Command:** `python scripts/materialize_codebase_map.py --repo .`
94
+ **Tests:** `python tests/codebase_map_materialize_test.py`
95
+
96
+ Normative architecture: `docs/engineering/architecture.md` (**# US-0082**).
97
+
98
+ ## Documentation profile validation (US-0077 / DEC-0059)
99
+
100
+ **Goal:** keep root `README.md` (user channel) and `docs/developer/README.md`
101
+ (developer shard) aligned with merged scratchpad keys `DOC_AUDIENCE_PROFILE` and
102
+ `DOC_DETAIL_LEVEL`, with deterministic reason codes and active/`template/` parity.
103
+
104
+ ### Scratchpad keys
105
+
106
+ - `DOC_AUDIENCE_PROFILE`: `user` \| `developer` \| `both` (empty defaults to `both` during transition).
107
+ - `DOC_DETAIL_LEVEL`: `concise` \| `balanced` \| `technical-deep` (empty defaults to `balanced`).
108
+ - Invalid values → `DOC_PROFILE_INVALID`. Merge/read failures → `DOC_PROFILE_MERGE_ERROR`.
109
+ - Optional modes `SPEC_PACK_MODE` / `USER_GUIDE_MODE` stay additive only: when `0`, this
110
+ validator does not require spec-pack or user-guide files.
111
+
112
+ ### Command
113
+
114
+ ```bash
115
+ python scripts/validate_doc_profile.py --repo .
116
+ python scripts/validate_doc_profile.py --repo . --no-template-parity # fixture trees without template/
117
+ ```
118
+
119
+ ### Installer hook
120
+
121
+ `installer.py` scratchpad post-install refreshes missing normative `##` sections
122
+ (non-destructive append) from the resolved profile, then operators should keep
123
+ content accurate. Re-run `python installer.py --scratchpad-postinstall --target <repo> --mode missing`
124
+ after template upgrades if needed.
125
+
126
+ Normative H2 titles and matrix: `docs/engineering/architecture.md` (`# US-0077`).
127
+
128
+ ## README feature coverage validation (US-0091 / DEC-0074)
129
+
130
+ **Goal:** ensure every DONE user-visible backlog item (`US-xxxx` / `BUG-xxxx` with
131
+ `user_visible: true`) has operator blurbs in **`its_magic/README.md`** (framework catalog)
132
+ and traceability rows in `docs/developer/README.md`, without inventing new `USER_*` / `DEV_*`
133
+ H2 literals (**DEC-0059** composes; **US-0030** delta gate unchanged). Consumer root
134
+ `README.md` is **out of scope** for this gate — see **US-0097** / **DEC-0083**.
135
+
136
+ ### Delta vs static doc gates
137
+
138
+ | Gate | Question | Remediation |
139
+ |------|----------|-------------|
140
+ | **US-0030** (delta) | Did this sprint change commands/flags without README/runbook updates? | Update command docs for changed surfaces; agent checklist in `/release` step 3 family. |
141
+ | **US-0091** (static) | Is every DONE user-visible item documented in the framework README family? | Backfill **`its_magic/README.md`** + DEV shard; set `user_visible:` marker; run validator `--report`. |
142
+
143
+ ### Scratchpad key
144
+
145
+ - `README_FEATURE_COVERAGE_ENFORCE`: `0` \| `1` (default `0` until backfill completes).
146
+ - When `0`: `/release` step **3f** records `skipped` evidence; migration heuristic H1–H8
147
+ may classify unset `user_visible` during backfill.
148
+ - When `1`: explicit `user_visible:` required on all DONE items; heuristic disabled;
149
+ `/release` runs blocking validator.
150
+
151
+ **Activation (same commit as backfill):** complete audit + three-file backfill → explicit
152
+ `user_visible:` markers → verify `--report` shows `coverage_missing: []` → flip `0` → `1`.
153
+
154
+ ### Commands
155
+
156
+ ```bash
157
+ python scripts/validate_readme_feature_coverage.py --self-test
158
+ python scripts/validate_readme_feature_coverage.py --repo . --report
159
+ python scripts/validate_readme_feature_coverage.py --repo . --audit-out docs/engineering/context/readme-feature-coverage-audit.json
160
+ python scripts/validate_readme_feature_coverage.py --repo . --enforce
161
+ python scripts/check_intake_template_parity.py --scope=readme-feature-coverage
162
+ ```
163
+
164
+ Reason codes: `README_FEATURE_COVERAGE_BLOCKED`, `README_FEATURE_COVERAGE_GAP:<id>`,
165
+ `README_FEATURE_COVERAGE_PARITY_FAIL`, `README_FEATURE_COVERAGE_INPUT_INVALID`,
166
+ `README_FEATURE_COVERAGE_PROFILE_VIOLATION`.
167
+
168
+ Normative predicate + affinity manifest: `decisions/DEC-0074.md`,
169
+ `docs/engineering/context/readme-section-affinity.json`.
170
+
171
+ ## Project README coverage validation (US-0097 / DEC-0083)
172
+
173
+ **Goal:** ensure project-owned root `README.md` has a bootstrap scaffold and growing
174
+ feature catalog under `<!-- project-readme-feature-catalog -->` for every DONE
175
+ `user_visible: true` backlog item. Framework catalog remains in **`its_magic/README.md`**
176
+ (**US-0091** gate **3f** — independent from project gate **3g**).
177
+
178
+ ### Placeholder sentinels S1–S5
179
+
180
+ | Signal | Detection rule | Verdict |
181
+ |--------|----------------|---------|
182
+ | **S1** | H1 `# its-magic — AI dev team` | placeholder |
183
+ | **S2** | `<!-- readme-feature-coverage-catalog -->` | placeholder |
184
+ | **S3** | Heading `Feature coverage catalog (US-0091)` | placeholder |
185
+ | **S4** | Byte-identical to `template/README.md` | placeholder |
186
+ | **S5** | None of S1–S4 + custom title/purpose | **operator-authored** — preserve |
187
+
188
+ **Detection order**: `FRAMEWORK_KIT_REPO=1` → S1–S4 → S5. Hybrid roots fail closed with
189
+ `PROJECT_README_MIGRATION_AMBIGUOUS` or `PROJECT_README_SENTINEL_CONFLICT`.
190
+
191
+ ### Migration algorithm M1–M5
192
+
193
+ | Step | Condition | Action |
194
+ |------|-----------|--------|
195
+ | **M1** | `FRAMEWORK_KIT_REPO=1` | Skip consumer migration |
196
+ | **M2** | Root **S5** | Preserve root; copy to **`its_magic/README.md`** if missing |
197
+ | **M3** | Root **S1–S4**, **`its_magic/`** missing | Lift root → **`its_magic/README.md`** |
198
+ | **M4** | Root **S1–S4** after **M3** | Replace root with project scaffold |
199
+ | **M5** | Hybrid / ambiguous | Fail closed |
200
+
201
+ ### Scratchpad keys
202
+
203
+ - `PROJECT_README_ENFORCE`: `0` \| `1` (default `1` post-bootstrap).
204
+ - `FRAMEWORK_KIT_REPO`: `0` \| `1` (default `0`; consumer repos never `1`).
205
+
206
+ **Grandfathering:** set `PROJECT_README_ENFORCE=0` during migration; flip to `1` when
207
+ `validate_project_readme_coverage.py --report` shows `coverage_missing: []`.
208
+
209
+ ### Commands
210
+
211
+ ```bash
212
+ python scripts/validate_project_readme_coverage.py --self-test
213
+ python scripts/validate_project_readme_coverage.py --repo . --report
214
+ python scripts/validate_project_readme_coverage.py --repo . --audit-out docs/engineering/context/project-readme-coverage-audit.json
215
+ python scripts/validate_project_readme_coverage.py --repo . --enforce
216
+ python scripts/check_intake_template_parity.py --scope=project-readme
217
+ ```
218
+
219
+ Reason codes: `PROJECT_README_COVERAGE_BLOCKED`, `PROJECT_README_COVERAGE_GAP:<id>`,
220
+ `PROJECT_README_DELTA_SKIPPED`, `PROJECT_README_BOOTSTRAP_SKIPPED`,
221
+ `PROJECT_README_MIGRATION_AMBIGUOUS`, `PROJECT_README_SENTINEL_CONFLICT`,
222
+ `PROJECT_README_PLACEHOLDER_UNRESOLVED`, `PROJECT_README_ENFORCE_SKIPPED`,
223
+ `PROJECT_README_INPUT_INVALID`.
224
+
225
+ ### Operator recipes (US-0097)
226
+
227
+ | Scenario | Operator action |
228
+ |----------|-----------------|
229
+ | Fresh consumer repo | First **`/execute`** bootstraps project README; framework catalog in **`its_magic/`** |
230
+ | Legacy framework root README | Run **`upgrade`** — migration **M3**/**M4** lifts to **`its_magic/`** + project scaffold |
231
+ | Operator-authored root (S5) | Migration preserves root; adds **`its_magic/README.md`** if missing |
232
+ | Hybrid / ambiguous root | Fix manually per **`PROJECT_README_MIGRATION_AMBIGUOUS`** — remove mixed sentinel + custom prose |
233
+ | Migration window | Set **`PROJECT_README_ENFORCE=0`**; backfill catalog bullets; flip to **`1`** when **`--report`** clean |
234
+ | Kit repo dogfooding | Set **`FRAMEWORK_KIT_REPO=1`** — skip consumer bootstrap (**23a**/**23b**) and project validator root check |
235
+
236
+ **Troubleshooting:** `PROJECT_README_COVERAGE_BLOCKED` at release **3g** → run `--report`,
237
+ backfill missing `US-xxxx` bullets under `<!-- project-readme-feature-catalog -->`.
238
+ `PROJECT_README_MIGRATION_AMBIGUOUS` → split framework content to **`its_magic/README.md`**
239
+ manually, then re-run migration. Implementation tranche order: A (installer + migration) →
240
+ B (bootstrap) → C (execute **23** + release **3g** + scratchpad) → D (validators + tests).
241
+
242
+ Normative contract: `decisions/DEC-0083.md`, `docs/engineering/architecture.md` `# US-0097`.
243
+
244
+ ## Dev environment auto-launch (US-0098 / DEC-0084)
245
+
246
+ **Goal:** execute-phase bounded rebuild/restart of dev stacks plus **Connect** surfacing after
247
+ implementation changes — distinct from **US-0065** phase QA, **US-0086** test routing, and
248
+ **US-0067** release hints. Default-off scratchpad gate; **no** `.env` reads (**US-0085**).
249
+
250
+ ### Operator recipes
251
+
252
+ | Scenario | Operator action |
253
+ |----------|-----------------|
254
+ | Enable dev auto-launch | Set **`DEV_AUTO_LAUNCH_PROFILE=deterministic_v1`** in scratchpad |
255
+ | Seed profile | Copy **`template/.cursor/dev-environment.json.example`** → **`.cursor/dev-environment.json`**; set compose **`service`** + **`*Env`** connect refs |
256
+ | Force relaunch | Send exact phrase **`refresh dev environment`** (case-sensitive whole phrase) |
257
+ | Profile off / manual mode | Leave **`DEV_AUTO_LAUNCH_PROFILE=off`** (default) — execute step **24** zero overhead |
258
+ | Ambiguous stack | Fix compose path or seed profile; remediate **`DEV_ENV_DETECT_AMBIGUOUS`** |
259
+ | Remote + local both on | **US-0086** remote wins over **docker-host-local** — see precedence in **`DEC-0084`** §3 |
260
+ | Bind-mount hot reload | Default skip on source-only docker changes; use refresh or **`restart_on_source_change=true`** |
261
+
262
+ ### Troubleshooting (`DEV_ENV_*` reason codes)
263
+
264
+ **Profile family:** **`DEV_ENV_PROFILE_DISABLED`**, **`DEV_ENV_PROFILE_INVALID`**,
265
+ **`DEV_ENV_PROFILE_MISSING`**, **`DEV_ENV_DETECT_AMBIGUOUS`**, **`DEV_ENV_COMPOSE_UNRESOLVED`**,
266
+ **`DEV_ENV_TARGET_DISABLED`**, **`DEV_ENV_SECRET_SURFACE_VIOLATION`**.
267
+
268
+ **Relaunch family:** **`DEV_ENV_RELAUNCH_SKIPPED_NO_SURFACE`**, **`DEV_ENV_RELAUNCH_SKIPPED_PROFILE_OFF`**,
269
+ **`DEV_ENV_RELAUNCH_FAILED`**, **`DEV_ENV_RELAUNCH_RETRY_EXHAUSTED`**, **`DEV_ENV_RELAUNCH_TIMEOUT`**,
270
+ **`DEV_ENV_CONNECT_UNAVAILABLE`**.
271
+
272
+ ### Commands
273
+
274
+ ```bash
275
+ python scripts/dev_environment_lib.py --self-test
276
+ python scripts/dev_environment_lib.py --load .cursor/dev-environment.json
277
+ python scripts/check_intake_template_parity.py --scope=dev-environment
278
+ pytest -k us0098 tests/auto_command_contract_test.py
279
+ ```
280
+
281
+ Implementation tranche order: **A** (schema + scratchpad) → **B** (stdlib helper) → **C** (execute step **24** + docs) → **D** (contract tests + parity + harness).
282
+
283
+ Normative contract: `decisions/DEC-0084.md`, `docs/engineering/architecture.md` `# US-0098`.
284
+
285
+ ## User-visible internal metadata guard (US-0071 / DEC-0053)
286
+
287
+ **Goal:** keep planning-shaped identifiers out of **operator-visible software
288
+ channels** (CLI/installer/validate-and-push strings), while they remain valid in
289
+ internal documentation trees and in source comments that are not emitted to
290
+ users.
291
+
292
+ ### Forbidden tokens (user-visible channels only)
293
+
294
+ Match planning-shaped tokens:
295
+
296
+ - `US-[0-9]{4}`
297
+ - `DEC-[0-9]{4}`
298
+ - `R-[0-9]{4}`
299
+
300
+ ### Inclusive scan roots (deterministic)
301
+
302
+ From repository root, the checker walks **only**:
303
+
304
+ - `bin/**` (`*.js`)
305
+ - `installer.py`, `installer.ps1`, `installer.sh`
306
+ - `packaging/**` (`*.js`, `*.py`, `*.ps1`, `*.sh`)
307
+ - `scripts/validate-and-push.ps1`, `scripts/validate-and-push.sh`
308
+
309
+ Paths outside this set are **not** scanned by this tool (for example `docs/**`,
310
+ `.cursor/**`, `sprints/**`, `handoffs/**`, `decisions/**` remain free to use
311
+ story/decision/research IDs). If a new operator-visible deliverable is added
312
+ outside these roots, extend the scan list or you risk
313
+ `METADATA_SANITIZATION_SCOPE_AMBIGUOUS` classification during review.
314
+
315
+ ### Command
316
+
317
+ ```bash
318
+ python scripts/check-user-visible-metadata.py
319
+ python scripts/check-user-visible-metadata.py --json
320
+ ```
321
+
322
+ ### Reason codes (minimum)
323
+
324
+ - `USER_VISIBLE_INTERNAL_METADATA_DETECTED` — forbidden token matched inside a
325
+ scanned user-visible string/literal.
326
+ - `METADATA_SANITIZATION_POLICY_MISSING` — checker entrypoint missing or
327
+ unusable.
328
+ - `METADATA_SANITIZATION_SCOPE_AMBIGUOUS` — cannot classify whether a path
329
+ belongs in inclusive scan roots; treat as fail-closed until the runbook table
330
+ is updated.
331
+
332
+ ### Findings / remediation (contract)
333
+
334
+ On failure, diagnostics must cite **evidence_ref** (`path:line:column` when
335
+ available), **token class** (`US` \| `DEC` \| `R`), and remediation: remove the
336
+ token from operator-visible strings; keep traceability in allowlisted internal
337
+ artifacts or non-emitting comments per `DEC-0053`.
338
+
339
+ ## Guided intake mode (US-0033)
340
+
341
+ Intake interaction behavior is controlled by one switch in
342
+ `.cursor/scratchpad.md`:
343
+
344
+ - `INTAKE_GUIDED_MODE=1` (default): guided PO behavior
345
+ - targeted follow-up questions only when acceptance is ambiguous
346
+ - at least one viable option/alternative before recommendation
347
+ - explicit user decision authority
348
+ - intake-time research persisted in `docs/engineering/research.md`
349
+ - `INTAKE_GUIDED_MODE=0`: low-touch intake
350
+ - no proactive follow-up/options/research overhead unless user asks
351
+ - duplicate/overlap backlog check remains mandatory baseline safety
352
+
353
+ ## Intake decomposition and risk-aware questioning (US-0051)
354
+
355
+ When guided mode is enabled (`INTAKE_GUIDED_MODE=1`), intake adds bounded
356
+ decomposition and adaptive questioning behavior:
357
+
358
+ - Run deterministic breadth/risk heuristics before persisting a story:
359
+ - feature/workflow-step count
360
+ - cross-cutting impact surface
361
+ - acceptance breadth
362
+ - risk/unknown dependency surface
363
+ - If heuristics indicate broad/high-risk intake:
364
+ - propose bounded multi-story decomposition (typically 2-5 stories)
365
+ - prefer vertical-slice/workflow-step stories with independent user value
366
+ - avoid technical-layer-only splits unless user explicitly requests
367
+ - Preserve user authority explicitly before persistence:
368
+ - user can accept, merge, or adjust the proposed split
369
+ - Keep adaptive questioning concise and bounded:
370
+ - ask ambiguity-driven questions plus risk-triggered questions
371
+ - stop after bounded rounds or when acceptance confidence is sufficient
372
+ - Low-touch compatibility (`INTAKE_GUIDED_MODE=0`):
373
+ - no forced decomposition
374
+ - single-story default unless user explicitly asks for decomposition
375
+ - duplicate/overlap safety remains mandatory
376
+ - Traceability requirement:
377
+ - intake output must capture decomposition/questioning evidence in
378
+ `docs/product/backlog.md`, `docs/product/acceptance.md`, and
379
+ `handoffs/po_to_tl.md`.
380
+
381
+ ## Mandatory intake question packs and persistence coverage gate (US-0068 / DEC-0050)
382
+
383
+ Intake persistence is fail-closed unless required topic coverage is complete (or
384
+ bounded assumptions are explicitly confirmed).
385
+
386
+ Deterministic pack contract:
387
+
388
+ - `first-intake-pack` (first/new/broad intake)
389
+ - required topics:
390
+ - `users_problem`
391
+ - `runtime_target_environment`
392
+ - `language_framework_runtime`
393
+ - `architecture_preference`
394
+ - `ui_design_expectations`
395
+ - `security_compliance`
396
+ - `non_functional_priorities`
397
+ - `scope_timeline`
398
+ - `small-intake-pack` (small follow-up intake)
399
+ - required topics:
400
+ - `outcome_success_criteria`
401
+ - `impacted_components`
402
+ - `constraints_compatibility_risks`
403
+ - `required_tests_acceptance_checks`
404
+ - `done_definition`
405
+
406
+ Pack selection and coverage behavior:
407
+
408
+ - Select exactly one pack per intake write path.
409
+ - Unknown/ambiguous stack or project cues must fail closed to
410
+ `first-intake-pack`.
411
+ - Required coverage must be evaluated before writing
412
+ `docs/product/backlog.md` or `docs/product/acceptance.md`.
413
+ - Incomplete required coverage blocks persistence unless assumptions are
414
+ explicitly confirmed.
415
+
416
+ Deterministic fail-closed reason codes:
417
+
418
+ - `INTAKE_REQUIRED_TOPIC_MISSING`
419
+ - `INTAKE_REQUIRED_PACK_INCOMPLETE`
420
+ - `INTAKE_ASSUMPTION_CONFIRMATION_REQUIRED`
421
+ - `INTAKE_PERSISTENCE_BLOCKED`
422
+
423
+ Required remediation output on block:
424
+
425
+ - include `missing_topics`
426
+ - provide targeted follow-up prompts for missing required topics
427
+ - request explicit assumption confirmation when assumptions are used
428
+
429
+ Required persisted intake evidence fields:
430
+
431
+ - `asked_topics`
432
+ - `missing_topics`
433
+ - `assumptions_confirmed`
434
+
435
+ ## First-intake full-plan coverage gate (US-0081 / DEC-0064)
436
+
437
+ For first/new/broad intake (`selected_pack=first-intake-pack`), persistence is
438
+ additionally blocked unless complete-plan coverage is machine-verifiable.
439
+
440
+ Required coverage contract fields:
441
+
442
+ - `plan_area_inventory[]` with unique stable `plan_area_id` values
443
+ - `plan_area_coverage[]` with exactly one row per `plan_area_id`
444
+ - xor mapping per row: `story_ids[]` or `deferred_ref` + `deferred_reason`
445
+ - `coverage_complete=true` only when derived validation succeeds
446
+
447
+ Coverage diagnostics (under umbrella `INTAKE_PERSISTENCE_BLOCKED`):
448
+
449
+ - `INTAKE_PLAN_COVERAGE_MISSING`
450
+ - `INTAKE_PLAN_AREA_ID_INVALID`
451
+ - `INTAKE_PLAN_COVERAGE_CONTRACT_INVALID`
452
+ - `INTAKE_PLAN_DEFERRED_REF_MISSING`
453
+
454
+ Guided and low-touch parity:
455
+
456
+ - `INTAKE_GUIDED_MODE=1` and `INTAKE_GUIDED_MODE=0` must run the same
457
+ first-intake complete-plan validator path.
458
+ - Low-touch may reduce optional prompts but cannot bypass complete-plan coverage
459
+ validation.
460
+
461
+ ## Interactive intake evidence validation (US-0078 / DEC-0060 / US-0083 / DEC-0067)
462
+
463
+ - Interactive intake evidence validation (US-0078 / DEC-0060) — automation/harness anchor; extended rules for **US-0083** / **DEC-0067** follow in this section.
464
+
465
+ **US-0078** adds machine-verifiable **`topic_coverage`** rows, canonical **`ie:`** refs
466
+ (**DEC-0060**), asked-vs-covered enforcement, and **`assumption_confirmation_ref`**
467
+ binding before backlog/acceptance writes.
468
+
469
+ - Validator entrypoints: `python scripts/intake_evidence_validate.py --self-test`;
470
+ `python scripts/intake_evidence_validate.py --file <bundle.json>` or `--stdin`.
471
+ - Library: `scripts/intake_evidence_lib.py` (shared rules for tests and tooling).
472
+ - Regression: `tests/intake_evidence_fixtures_test.py` (R-0055 **AC-8** matrix tiers A/B),
473
+ invoked from `tests/run-tests.ps1` / `tests/run-tests.sh` §26k.
474
+ - **Packaged installs (BUG-0001 / DEC-0063)**: `intake_evidence_validate.py`, `intake_evidence_lib.py`, and `intake_bug_routing_guard.py` are mirrored under `template/scripts/` and listed in `docs/engineering/context/installer-owned-paths.manifest` so fresh install and `upgrade` copy them to the consumer’s `scripts/`. Drift guard: `python scripts/check_intake_template_parity.py --repo .` (also §26N in `tests/run-tests.*`). **Release (S0060)**: operator notes `handoffs/releases/S0060-release-notes.md` (gate summary + verify steps).
475
+ - **US-0084**: `remote_config_summary.py` and `guard_installer_publish.py` use the same **`template/scripts/`** mirror + manifest rows; npm **`package.json` `files`** also lists the active copies for publish.
476
+ - **Installer completeness gate (BUG-0003 / DEC-0066)**: post-install invariant checks every path in `[required_install_script_paths]` from `docs/engineering/context/installer-owned-paths.manifest`. Missing paths fail closed with `INSTALL_COMPLETENESS_FAILED` and `INSTALL_REQUIRED_SCRIPT_MISSING:<path>`. Remediation: update manifest parity (active + `template/`), ensure required script exists under `template/scripts/`, keep install/clean ownership paired, then rerun `its-magic --mode missing|upgrade` (or `python installer.py --validate-install-completeness --target <repo>` for direct diagnostics).
477
+ - **Guided** and **low-touch** (`INTAKE_GUIDED_MODE=0`) share the **same** pre-persistence
478
+ validation pipeline; mandatory pack evidence is never skipped.
479
+ - Legacy intake evidence without **`ie:`** refs remains **grandfathered** for display until the
480
+ next intake-driven mutation, which must supply full evidence (**DEC-0060** §5).
481
+ - **Delegated required-topic path (US-0083 / DEC-0067)**:
482
+ - Allowed: `topic_coverage[].satisfied_by=delegation_ref` with required
483
+ `delegation_scope`, `delegation_rationale`, `delegation_confidence` (`low|medium|high`).
484
+ - Missing delegation fields fail closed with `INTAKE_DELEGATION_EVIDENCE_MISSING`.
485
+ - Malformed delegation values or invalid `ie:` binding fail closed with
486
+ `INTAKE_DELEGATION_EVIDENCE_INVALID`.
487
+ - Non-delegated unresolved required topics remain unchanged fail-closed
488
+ (`INTAKE_REQUIRED_TOPIC_MISSING` path).
489
+ - **Repetitive-ask suppression with accounting (US-0083 AC-1)**:
490
+ - When equivalent evidence already exists, avoid re-asking by recording row-level
491
+ `evidence_source=equivalent_evidence_ref` plus `equivalent_evidence_ref`.
492
+ - Required-topic accounting remains explicit through `topic_coverage` rows.
493
+
494
+ ## Bug issues (US-0079 / DEC-0061)
495
+
496
+ - **Canonical ids**: **`BUG-####`** in **`docs/product/backlog.md`** **`## Bug issues (canonical)`**; status literals **`OPEN`** | **`DONE`** only — illegal values fail **`BUG_VALIDATION_STATUS_INVALID`**.
497
+ - **Minimum fields** (non-empty): **`environment`**, **`steps_to_reproduce`**, **`expected`**, **`actual`**, **`evidence_refs`** — missing/empty → **`BUG_VALIDATION_FIELD_EMPTY`** (or **`BUG_VALIDATION_SECTION_MISSING`** when the region is absent).
498
+ - **Ordering**: bug blocks sorted by id ascending — violation → **`BUG_VALIDATION_ORDER_INVERSION`**.
499
+ - **Intake routing**: merged **`INTAKE_WORK_ITEM_KIND=story|bug`** and/or explicit **`/intake bug`**; defect-shaped prose with **`story`** kind → **`INTAKE_BUG_ROUTING_REQUIRED`** via **`python scripts/intake_bug_routing_guard.py`** (**DEC-0061** §5). Mismatch/conflict → **`INTAKE_WORK_ITEM_KIND_MISMATCH`** family (documented in command surfaces).
500
+ - **Acceptance reconciliation**: **`docs/product/acceptance.md`** **`## Bug acceptance (canonical)`** checkbox rows must match backlog bug status — drift codes **`BUG_RECONCILE_ACCEPTANCE_*`**.
501
+ - **Commands**:
502
+ - `python scripts/bug_issue_validate.py --self-test`
503
+ - `python scripts/bug_issue_validate.py --backlog docs/product/backlog.md [--check-acceptance] [--print-next-id]`
504
+ - `python scripts/intake_bug_routing_guard.py --kind story|bug --file <path>` (or **`--stdin`**)
505
+ - **Regression**: `tests/bug_issue_fixtures_test.py` (R-0056 Tier A/B), invoked from **`tests/run-tests.ps1` / `tests/run-tests.sh`** §26L.
506
+
507
+ ## Optional ID namespace bootstrap (US-0052)
508
+
509
+ Fresh-project ID bootstrap is optional and default-off in
510
+ `.cursor/scratchpad.md`:
511
+
512
+ - `ID_NAMESPACE_BOOTSTRAP=0|1` (default `0`)
513
+
514
+ Deterministic behavior:
515
+
516
+ - If `ID_NAMESPACE_BOOTSTRAP=1`, evaluate freshness eligibility before creating
517
+ new IDs:
518
+ - no `US-` IDs in `docs/product/backlog.md`
519
+ - no `DEC-` IDs in `docs/engineering/decisions.md` (and no existing
520
+ `decisions/DEC-*.md`)
521
+ - no `R-` IDs in `docs/engineering/research.md`
522
+ - If eligible, first created IDs start at:
523
+ - `US-0001` for intake stories
524
+ - `DEC-0001` for architecture decisions
525
+ - `R-0001` for research entries
526
+ - If not eligible (or mode is off), continue from highest existing ID in each
527
+ namespace.
528
+ - Never rewrite/renumber historical IDs.
529
+ - If bootstrap is requested but ineligible, emit deterministic diagnostic
530
+ `ID_BOOTSTRAP_NOT_FRESH` and continue with highest-existing continuation.
531
+
532
+ ## Context compaction and token profile mode (US-0053 / DEC-0035)
533
+
534
+ Tiered token-cost control is explicit and defaulted in `.cursor/scratchpad.md`:
535
+
536
+ - `TOKEN_PROFILE=lean|balanced|full` (default `balanced`)
537
+
538
+ Deterministic profile semantics:
539
+
540
+ - `lean`: lowest context breadth / token cost defaults while preserving mandatory
541
+ quality/release gates.
542
+ - `balanced`: moderate context breadth / token cost.
543
+ - `full`: highest context breadth / token cost for complex/high-uncertainty work.
544
+
545
+ Manual override precedence:
546
+
547
+ - Explicit flag values remain authoritative for that flag.
548
+ - If a flag is explicitly set, it overrides profile defaults.
549
+ - Profile changes must not disable mandatory gate contracts
550
+ (`/qa`, `/verify-work`, `/release`).
551
+
552
+ ### Token-cost evidence + comparability (US-0080 / DEC-0062)
553
+
554
+ - **Fresh context**: spawn **new** subagents per `/auto` phase; avoid carrying prior chat
555
+ reasoning as phase input.
556
+ - **`start-from`**: use **`/auto start-from=<canonical_phase_id>`** when resuming so the
557
+ schedule intersection matches materialized **`resolved_phase_plan`** (**`DEC-0052`**).
558
+ - **`TOKEN_PROFILE`**: **TOKEN_PROFILE controls context breadth / token cost only**;
559
+ does **not** change automation level, drain, outer-driver invocation, or remove
560
+ isolation, strict-proof, role, or release gates.
561
+ - **Metrics**: append-only **`handoffs/token_cost_runs/<orchestrator_run_id>.md`** (or
562
+ **`.jsonl`**); copy path into **`token_cost_evidence_ref`** on **`state.md`** checkpoints.
563
+ - **AC-2**: compare **`cache_read_tokens`** only when **`run_class_hash`** matches; else
564
+ **`TOKEN_COST_RUN_CLASS_MISMATCH`**.
565
+ - **`delivery_mode`** (US-0096 / DEC-0082): required key in sorted JSON run-class object
566
+ (amends **DEC-0062**). Evidence rows in **`handoffs/token_cost_runs/<orchestrator_run_id>.md`**
567
+ **must** include **`delivery_mode`** column. **`ultra_lean`** vs **`standard`** on same story →
568
+ **`TOKEN_COST_RUN_CLASS_MISMATCH`**. Tranche A target: **≥10%** **`cache_read_tokens`** reduction
569
+ on matched **`standard`** runs vs pre-US-0096 baseline.
570
+ - **CI/repo checks**: `python scripts/check_token_cost_parity.py --repo .` (manifest-listed
571
+ active/`template/` pairs); **`tests/run-tests.ps1`** / **`tests/run-tests.sh`** §26M.
572
+
573
+ ### Delivery modes (US-0096 / DEC-0082)
574
+
575
+ > **`DELIVERY_MODE`** controls lifecycle shape and artifact surfaces only. **`TOKEN_PROFILE`** controls context breadth / token cost only (**DEC-0062**). **`CAVEMAN_MODE`** controls reply voice only (**DEC-0072**). None substitutes for another.
576
+
577
+ | Key | Values | Default |
578
+ |-----|--------|---------|
579
+ | **`DELIVERY_MODE`** | `standard` \| `ultra_lean` \| `mega_quick` | `standard` |
580
+ | **`LEAN_MEMORY_READ`** | `0` \| `1` | `1` |
581
+ | **`LEAN_MEMORY_WRITE`** | `0` \| `1` | `1` |
582
+ | **`LEAN_COLD_READ_MAX_SECTIONS`** | int ≥ 1 | `4` |
583
+ | **`LEAN_STATE_INDEX_ROWS`** | int ≥ 30 | `80` |
584
+ | **`AUTO_DELIVERY_ROUTING`** | `scratchpad_only` \| `backlog_then_scratchpad` | `scratchpad_only` |
585
+
586
+ **Tranche A default hot caps** (example scratchpad; explicit operator values override):
587
+ **`STATE_HOT_MAX_LINES=1000`**, **`PO_TO_TL_HOT_MAX_LINES=650`**, **`ARCH_HOT_MAX_LINES=3000`**.
588
+
589
+ #### Operator recipes
590
+
591
+ | Mode | When to use | Avoid when |
592
+ |------|-------------|------------|
593
+ | **`standard`** | Full lifecycle, cross-cutting stories, companion DEC, release gates | N/A (default) |
594
+ | **`ultra_lean`** | P1 stories with clear AC, token budget pressure, institutional memory needed | Mid-story mode switch; no validator/index |
595
+ | **`mega_quick`** | ≤3 AC, single component, docs-only or tiny fix | Architecture-first; existing **`Sxxxx`**; bug segments |
596
+
597
+ #### Tranche A universal wins (always-on)
598
+
599
+ 1. **Narrow-read** in all phase command **`Inputs`** — cite **`phase-context.md`** + story section
600
+ anchor; forbid full-file reads when heading exists.
601
+ 2. **Delta handoffs** — append delta paragraphs to handoff bodies; no full rewrites of prior content.
602
+ 3. **Touch-graph reads** — before **`/execute`**, read **`docs/engineering/codebase-map.md`**
603
+ component slice + touched paths from sprint/tasks or pack.
604
+
605
+ #### `ultra_lean` E2E operator recipe (`build+verify`)
606
+
607
+ 1. Set **`DELIVERY_MODE=ultra_lean`**, **`LEAN_MEMORY_READ=1`**, **`LEAN_MEMORY_WRITE=1`**.
608
+ 2. Run **`/auto`** — expect four macro-phases: **`spec`**, **`plan`**, **`build+verify`**, **`ship`**.
609
+ 3. **`build+verify`** merges execute + qa + verify-work in one spawn; **`AUTO_IMPLEMENTATION_LOOP`**
610
+ loops inside macro-phase until green or cap.
611
+ 4. Warm memory: **`work/<story_id>/pack.json`** (validate with **`scripts/pack_json_validate.py`**).
612
+ 5. Hot index: **`handoffs/active-context.md`** (30–80 lines; **not** triad).
613
+
614
+ #### Layered memory + gates
615
+
616
+ - active-context.md is NOT a triad member — triad enforcement unchanged (**DEC-0054**).
617
+ - Rollover → **`handoffs/archive/active-context-<story_id>-<utc>.md`** on oversize or segment close.
618
+ - **`LEAN_MEMORY_READ=0`** or **`LEAN_MEMORY_WRITE=0`** on **`ultra_lean`** → **`LEAN_MEMORY_DISABLED`**.
619
+
620
+ #### Quality floor (all lean modes)
621
+
622
+ - Tests run before stop.
623
+ - AC traceability in **`pack.json`** or **`task.json`**.
624
+ - New patterns → architecture/decision delta.
625
+ - **`active-context.md`** updated on material learnings.
626
+ - No secrets / publish bypass (**`RELEASE_PUBLISH_MODE`** unchanged).
627
+
628
+ #### Backlog routing (optional)
629
+
630
+ When **`AUTO_DELIVERY_ROUTING=backlog_then_scratchpad`**, story row may declare optional
631
+ **`delivery_mode:`** field. Precedence: argv **`delivery-mode=`** → story row → scratchpad → **`standard`**.
632
+
633
+ **Release status (S0086 / US-0096)**: **`released`** (`2026-06-13T16:00:00Z`); **`US-0096`** **DONE** in canonical backlog. Operator verify: **`handoffs/releases/S0086-release-notes.md`** **## Verify**; publish skipped while **`RELEASE_PUBLISH_MODE=confirm`**.
634
+
635
+ Context compaction policy:
636
+
637
+ - `docs/engineering/state.md` is a compact hot surface for current execution
638
+ context and recent checkpoints.
639
+ - Historical state packs belong in `docs/engineering/state-archive/` and are
640
+ append-only/non-destructive.
641
+ - `docs/engineering/decisions.md` is a compact index with bounded summaries and
642
+ canonical links to full records in `decisions/DEC-xxxx.md`.
643
+ - Enforced rollover thresholds:
644
+ - `STATE_HOT_MAX_LINES` (default `1200`)
645
+ - `STATE_HOT_MAX_CHECKPOINTS` (default `80`)
646
+ - `PO_TO_TL_HOT_MAX_LINES` (default `800`)
647
+ - `PO_TO_TL_HOT_MAX_SECTIONS` (default `60`)
648
+ - `ARCH_HOT_MAX_LINES` (default `3500`)
649
+ - `ARCH_HOT_MAX_STORY_SECTIONS` (default `120`)
650
+ Thresholds resolve from merged `.cursor/scratchpad.md` +
651
+ `.cursor/scratchpad.local.md` (DEC-0054 triad contract).
652
+ When a cap is exceeded, the mutating phase must run rollover **before**
653
+ completion or fail closed (no successful completion with an oversize hot
654
+ surface).
655
+
656
+ ### Triad hot-surface enforcement (DEC-0054)
657
+
658
+ Canonical hot/archive surfaces:
659
+
660
+ - `docs/engineering/state.md` → `docs/engineering/state-archive/state-pack-*.md`
661
+ - `handoffs/po_to_tl.md` → `handoffs/archive/po-to-tl-pack-*.md`
662
+ - `docs/engineering/architecture.md` →
663
+ `docs/engineering/architecture-archive/architecture-pack-*.md`
664
+
665
+ Operator commands:
666
+
667
+ ```bash
668
+ python scripts/enforce-triad-hot-surface.py --check
669
+ python scripts/enforce-triad-hot-surface.py --rollover
670
+ ```
671
+
672
+ - `--check` verifies all three surfaces are within policy (CI-safe).
673
+ - `--rollover` archives oldest contiguous units into the next deterministic pack
674
+ name; reruns are idempotent when already within caps.
675
+ - Successful rollover records a verification tuple:
676
+ `boundary`, `moved`, `retained` (counts / lines), `pack_ref`.
677
+
678
+ Rollover fail-safe reason codes:
679
+
680
+ - `STATE_ARCHIVE_BOUNDARY_AMBIGUOUS`
681
+ - `STATE_ARCHIVE_WRITE_FAILED`
682
+ - `STATE_ARCHIVE_VERIFICATION_FAILED`
683
+ - `STATE_ARCHIVE_REQUIRED`
684
+ - `ARTIFACT_HOT_SURFACE_OVERSIZE`
685
+ - `ARCH_STORY_HEADING_LEVEL_INVALID`
686
+ - `CONTEXT_BUDGET_EXCEEDED`
687
+
688
+ **Architecture file blocked on rollover?** If story sections use legacy H2 `## US-xxxx`
689
+ headings, the archiver now recognizes them for rollover after **BUG-0010**. For new work,
690
+ `/architecture` must append H1 `# US-xxxx` (or `# BUG-xxxx` for defects). To converge an
691
+ existing repo, optionally normalize `## US-xxxx` → `# US-xxxx` manually (count decrease is
692
+ allowed; adding new `## US-` story headings is blocked).
693
+
694
+ ### Minimal-read defaults by phase (bounded escalation)
695
+
696
+ Read `docs/engineering/phase-context.md` first, then the **required** paths for
697
+ your phase. If unresolved, expand once to the **single** archive pack named in
698
+ the latest verification tuple for that surface. Do not load entire archive
699
+ directories by default.
700
+
701
+ | Phase | Required reads (default) | Combined line budget (guidance) |
702
+ |-------|--------------------------|----------------------------------|
703
+ | `/intake` | `phase-context.md`, target story in `docs/product/backlog.md`, `handoffs/po_to_tl.md` (tail) | ≤ 900 lines |
704
+ | `/discovery` | `phase-context.md`, `docs/product/vision.md` (story notes), `handoffs/po_to_tl.md` (tail) | ≤ 900 lines |
705
+ | `/research` | `phase-context.md`, `docs/engineering/research.md` (target entry), `docs/product/backlog.md` (target story) | ≤ 800 lines |
706
+ | `/architecture` | `phase-context.md`, `docs/engineering/architecture.md` (target story section), `docs/engineering/research.md` | ≤ 1200 lines |
707
+ | `/sprint-plan` | `phase-context.md`, `docs/engineering/architecture.md` (target story), `handoffs/tl_to_dev.md` | ≤ 1000 lines |
708
+ | `/plan-verify` | `phase-context.md`, `sprints/Sxxxx/tasks.md`, `docs/product/backlog.md` (ACs) | ≤ 900 lines |
709
+ | `/execute` | `phase-context.md`, `sprints/Sxxxx/tasks.md`, `handoffs/tl_to_dev.md` | ≤ 800 lines |
710
+ | `/qa` | `phase-context.md`, `sprints/Sxxxx/`, `tests/report.md` | ≤ 900 lines |
711
+ | `/verify-work` | `phase-context.md`, `sprints/Sxxxx/uat.json`, QA findings | ≤ 600 lines |
712
+ | `/release` | `phase-context.md`, release queue + sprint release findings | ≤ 700 lines |
713
+ | `/refresh-context` | `phase-context.md`, `docs/engineering/state.md` (tail), `docs/product/backlog.md` (status) | ≤ 900 lines |
714
+ | `/auto` (resolver) | `phase-context.md`, `handoffs/resume_brief.md`, `docs/engineering/state.md` (tail) | ≤ 700 lines |
715
+
716
+ If the default set is insufficient, escalate with an explicit note citing
717
+ `pack_ref`. Unbounded broad reads fail closed with `CONTEXT_BUDGET_EXCEEDED`.
718
+
719
+ `/ask` retrieval policy:
720
+
721
+ - Use question-scoped narrow reads first.
722
+ - Expand context in bounded steps only when unresolved.
723
+ - If unresolved after bounded expansion, answer with explicit "not found in
724
+ current artifacts" rather than broad speculative reads.
725
+
726
+ ## Configurable multi-target publish mode (US-0054 / DEC-0036)
727
+
728
+ Post-release publish orchestration is configurable and default-safe:
729
+
730
+ - `RELEASE_PUBLISH_MODE=disabled|confirm|auto` (default `confirm`)
731
+ - `RELEASE_TARGETS_FILE=docs/engineering/release-targets.json`
732
+ - `RELEASE_TARGETS_DEFAULT=` optional comma-separated default target IDs
733
+
734
+ Target schema contract:
735
+
736
+ - Canonical target config file: `docs/engineering/release-targets.json`
737
+ - Supported target types:
738
+ - `npm`, `choco`, `brew`, `git`, `docker`, `cloud`
739
+ - `custom` (generic command target)
740
+ - `ssh` (host/user/port/auth reference + remote command)
741
+ - Connectivity metadata (for operator-safe remote/local context):
742
+ - `runtime.mode` (`local|remote`)
743
+ - endpoint fields (`domainEnv|ipEnv|hostEnv`, `port`, `protocol`)
744
+ - optional ingress metadata (`traefik.enabled`, `router`, `entrypoint`, `tls`)
745
+ - optional `dockerOverSsh` object for ssh/dockerd remote execution context
746
+ - Each target entry must define deterministic fields:
747
+ - `id` (stable unique target ID)
748
+ - `type`
749
+ - `enabled` (`true|false`)
750
+ - `order` (deterministic execution ordering)
751
+ - execution details (`command` for non-ssh, `remoteCommand` + host/user/auth refs for `ssh`)
752
+
753
+ Safety contract:
754
+
755
+ - Mandatory release gates remain unchanged and must pass before any publish
756
+ target execution.
757
+ - `confirm` mode requires explicit operator approval before publish execution.
758
+ - Sensitive fields must be env-referenced (`*Env` keys); inline secret literals
759
+ are not allowed.
760
+ - Invalid target config must fail fast with deterministic diagnostics and no
761
+ partial side effects.
762
+ - Invalid remote connectivity metadata must fail fast with
763
+ `REMOTE_CONNECTIVITY_CONFIG_INVALID`.
764
+ - Canonical operator endpoint summary is written to
765
+ `docs/engineering/runtime-connectivity.md` with sanitized values only.
766
+
767
+ ## Release operator hints contract (US-0067 / DEC-0049)
768
+
769
+ Release outputs must include deterministic operator-ready hints with mandatory
770
+ section order:
771
+
772
+ `Run -> Connect -> Verify -> Credentials -> Known Issues`
773
+
774
+ Required fields for canonical sprint notes
775
+ (`handoffs/releases/Sxxxx-release-notes.md`):
776
+
777
+ - `Run`: `start_command`, `runtime_mode`, `runtime_context_ref`
778
+ - `Connect`: `service_url`, `service_port`, `health_endpoint`
779
+ - `Verify`: deterministic `verification_steps`, `expected_health_signal`
780
+ - `Credentials`: env-reference-only source refs and expected value-source
781
+ location guidance (never inline secrets)
782
+ - `Known Issues`: concise issue list or explicit `None`
783
+
784
+ Legacy pointer contract (`handoffs/release_notes.md`):
785
+
786
+ - keep concise latest run/connect/verify summary only
787
+ - always link to canonical sprint-scoped release notes for full details
788
+
789
+ Fail-closed reason codes:
790
+
791
+ - `RELEASE_OPERATOR_HINTS_MISSING`
792
+ - `RELEASE_OPERATOR_HINTS_AMBIGUOUS`
793
+ - `RELEASE_OPERATOR_HINTS_SECRET_EXPOSURE`
794
+
795
+ ## Deterministic status reconciliation mode (US-0055 / DEC-0037)
796
+
797
+ Use the dedicated reconciliation command to normalize status drift across
798
+ canonical and derived artifacts:
799
+
800
+ - Command: `/status-reconcile`
801
+ - Canonical source: `docs/product/backlog.md` (story `Status`)
802
+ - Derived surfaces: `docs/product/acceptance.md`, `docs/engineering/state.md`,
803
+ `handoffs/resume_brief.md`
804
+
805
+ Deterministic behavior:
806
+
807
+ - Detects mismatches (for example DONE + unchecked ACs, acceptance drift, resume drift).
808
+ - Applies target-scoped reconciliation only to mismatched story blocks/rows.
809
+ - Preserves canonical ownership; derived artifacts reconcile to backlog status.
810
+ - Updates `handoffs/resume_brief.md` to next OPEN story and intended phase.
811
+ - Writes auditable rows to `docs/engineering/status-normalization-report.md`.
812
+
813
+ Reason-code baseline:
814
+
815
+ - `STATUS_RECONCILE_APPLIED`
816
+ - `STATUS_RECONCILE_NOOP`
817
+ - `STATUS_RECONCILE_MISSING_INPUT`
818
+ - `STATUS_RECONCILE_CANONICAL_CONFLICT`
819
+ - `STATUS_RECONCILE_PHASE_AMBIGUOUS`
820
+ - `STATUS_RECONCILE_EVIDENCE_MISSING`
821
+
822
+ ## Optional cross-repo observability mode (US-0034)
823
+
824
+ Compatibility visibility is optional and default-off in `.cursor/scratchpad.md`:
825
+
826
+ - `CROSS_REPO_OBSERVABILITY=0|1` (default `0`)
827
+ - `COMPATIBILITY_GATE_ON_CRITICAL=0|1` (default `1`)
828
+ - `COMPATIBILITY_SOURCES=` monitored source declarations
829
+
830
+ Default-off behavior:
831
+ - With `CROSS_REPO_OBSERVABILITY=0`, `/intake`, `/architecture`, `/execute`,
832
+ and `/qa` add zero required compatibility overhead.
833
+
834
+ Enabled behavior (`CROSS_REPO_OBSERVABILITY=1`):
835
+ - Use canonical artifacts:
836
+ - `docs/engineering/compatibility-report.md`
837
+ - `docs/engineering/compatibility-signals.md`
838
+ - `docs/engineering/manifests/registry.manifest.yaml`
839
+ - `docs/engineering/manifests/repo.manifest.yaml`
840
+ - Record findings with severity, affected modules, evidence refs, and
841
+ recommended actions.
842
+ - If unresolved critical findings exist and
843
+ `COMPATIBILITY_GATE_ON_CRITICAL=1`, trigger decision gate before release
844
+ progression (`COMPATIBILITY_CRITICAL_OPEN`).
845
+
846
+ ## Optional component-scoped execution mode (US-0035)
847
+
848
+ Component-scoped execution is optional and default-off:
849
+
850
+ - `COMPONENT_SCOPE_MODE=0|1` (default `0`)
851
+ - `TARGET_COMPONENTS=` comma-separated scoped component IDs
852
+
853
+ Default-off behavior:
854
+ - With `COMPONENT_SCOPE_MODE=0`, workflow phases add zero required scope
855
+ overhead.
856
+
857
+ Enabled behavior (`COMPONENT_SCOPE_MODE=1`):
858
+ - Declare scope in `docs/engineering/component-scope.md`:
859
+ - `target_components[]`
860
+ - `non_target_components[]`
861
+ - `allowed_interface_touch[]`
862
+ - `/sprint-plan` tasks declare `target_component_ids` and
863
+ `expected_impacted_interfaces`.
864
+ - `/execute` enforces scope-first behavior.
865
+ - `/qa` verifies unaffected-component checks and records evidence in
866
+ `docs/engineering/component-scope-report.md`.
867
+ - If unapproved out-of-scope impact remains open, release must stop at decision
868
+ gate (`COMPONENT_SCOPE_VIOLATION_UNAPPROVED`).
869
+
870
+ ## Optional spec-pack documentation mode (US-0031)
871
+
872
+ Spec-pack mode is optional and default-off in `.cursor/scratchpad.md`:
873
+
874
+ - `SPEC_PACK_MODE=0|1` (default `0`)
875
+
876
+ Default-off behavior:
877
+ - With `SPEC_PACK_MODE=0`, `/intake`, `/architecture`, `/execute`, `/qa`, and
878
+ `/release` add no required spec-pack steps (zero overhead).
879
+
880
+ Enabled behavior (`SPEC_PACK_MODE=1`):
881
+
882
+ **Canonical names and locations** (per story):
883
+ - Design Concept: `docs/engineering/spec-pack/<story_id>-design-concept.md`
884
+ - CRS (Customer/Product Requirements Summary): `docs/engineering/spec-pack/<story_id>-crs.md`
885
+ - Technical Specification: `docs/engineering/spec-pack/<story_id>-technical-specification.md`
886
+
887
+ **Traceability**: Backlog story ID (e.g. `US-0031`) maps 1:1 to the three
888
+ artifacts above. Handoffs and state should reference these paths when
889
+ spec-pack mode is enabled.
890
+
891
+ **Minimum required sections** (completeness is testable; validation blocks
892
+ only when enabled and a required section is missing or empty):
893
+
894
+ - Design Concept: `# Summary`, `# Goals`, `# Non-goals`, `# Key decisions`
895
+ - CRS: `# Purpose`, `# Scope`, `# Acceptance criteria ref`
896
+ - Technical Specification: `# Overview`, `# Components`, `# Interfaces`, `# Non-functional`
897
+
898
+ **Validation**: When `SPEC_PACK_MODE=1`, release gate checks that for the
899
+ target sprint story, all three artifacts exist and each required section
900
+ above is present and non-empty. If not, release is blocked with reason code
901
+ `SPEC_PACK_INCOMPLETE` and remediation guidance.
902
+
903
+ **Ownership (role/phase)**:
904
+ - Design Concept: Tech Lead, `/architecture` (create/update).
905
+ - CRS: PO, `/intake` (create/update for new story); Tech Lead may extend in
906
+ architecture.
907
+ - Technical Specification: Tech Lead, `/architecture` (create); Dev, `/execute`
908
+ (update when implementation details change).
909
+
910
+ ## Optional user-guide documentation mode (US-0032)
911
+
912
+ User-guide mode is optional and default-off in `.cursor/scratchpad.md`:
913
+
914
+ - `USER_GUIDE_MODE=0|1` (default `0`)
915
+
916
+ Default-off behavior:
917
+ - With `USER_GUIDE_MODE=0`, `/intake`, `/architecture`, `/sprint-plan`, `/execute`,
918
+ `/qa`, and `/release` add no required user-guide steps or blocking checks (zero overhead).
919
+
920
+ Enabled behavior (`USER_GUIDE_MODE=1`):
921
+
922
+ **Canonical location and naming** (per feature story):
923
+ - One guide per feature story: `docs/user-guides/US-xxxx.md` (e.g. `docs/user-guides/US-0032.md`).
924
+ - Story ID `US-xxxx` is the stable identifier; create/update the guide when the story is in scope.
925
+
926
+ **Minimum required schema** (structural validation only; completeness is testable):
927
+ - `# Purpose`
928
+ - `# Prerequisites`
929
+ - `# Usage steps`
930
+ - `# Example`
931
+ - `# Limitations`
932
+ - `# Troubleshooting`
933
+
934
+ **Traceability**: Story ID maps 1:1 to the user-guide artifact. Handoffs and release
935
+ context should reference `docs/user-guides/US-xxxx.md` for the target story when
936
+ user-guide mode is enabled.
937
+
938
+ **Validation**: When `USER_GUIDE_MODE=1`, release gate checks that for the target
939
+ sprint story, the guide file exists at the canonical path and each required section
940
+ above is present and non-empty. If not, release is blocked with reason code
941
+ `USER_GUIDE_INCOMPLETE` and remediation guidance (create or complete the guide).
942
+
943
+ **Boundary with spec-pack (US-0031)**: User guides are end-user facing how-to
944
+ documentation only. They do not duplicate Design Concept, CRS, or Technical
945
+ Specification content; user guides may reference spec-pack artifacts but must not
946
+ replicate their ownership or technical scope. See runbook/README separation guidance.
947
+
948
+ ## Legacy DONE-story drift detection and guard (US-0049)
949
+
950
+ Stories that are DONE in backlog but lack aligned acceptance/traceability or
951
+ release representation are in **legacy drift**. US-0049 adds detection, bounded
952
+ repair, and an ongoing guard at release/reconciliation (DEC-0031).
953
+
954
+ **Detection rule** — A story is in legacy drift when:
955
+ - Backlog status is **DONE**, and
956
+ - At least one of:
957
+ - Acceptance checklist item for that story is **unchecked**
958
+ - Traceability index or `docs/engineering/state.md` **lacks an entry** for that story
959
+ - Release artifacts (e.g. `handoffs/releases/Sxxxx-release-notes.md`, queue row)
960
+ **lack clear representation** for that story
961
+
962
+ **Bounded repair**: Only stories matching the rule above may be mutated; no broad
963
+ rewrite of unrelated backlog/acceptance/state/release artifacts.
964
+
965
+ **Canonical audit artifact**: `docs/engineering/legacy-drift-audit.md`
966
+ - Required fields per entry: story ID, prior acceptance state, prior traceability
967
+ state, resolved state(s), reason code, evidence reference.
968
+ - Append-only; one-time backfill and ongoing guard append entries when drift is
969
+ detected and repaired (or when guard blocks and reports).
970
+
971
+ **Reason-code vocabulary** (with remediation):
972
+ - `BACKLOG_DONE_ACCEPTANCE_UNCHECKED` — Backlog DONE but acceptance item unchecked.
973
+ Remediation: set acceptance checkbox from canonical release/state evidence or run one-time backfill.
974
+ - `BACKLOG_DONE_TRACEABILITY_MISSING` — Backlog DONE but traceability/state lacks entry.
975
+ Remediation: add traceability row in `docs/engineering/state.md` from backlog/release evidence or run backfill.
976
+ - `BACKLOG_DONE_RELEASE_ARTIFACT_MISSING` — Backlog DONE but release artifacts lack representation.
977
+ Remediation: ensure release notes or queue row exists for the story’s sprint or run backfill.
978
+
979
+ **One-time backfill mode**: Explicit trigger (e.g. dedicated check or `/memory-audit`-related path).
980
+ - Run detection once over all DONE stories; for each legacy-drift story, perform
981
+ target-scoped repair and append an entry to `docs/engineering/legacy-drift-audit.md`.
982
+ - Idempotent when no drift: no mutations; report empty or "no drift".
983
+ - Only stories matching the detection rule are mutated.
984
+
985
+ **Ongoing guard**: At release or reconciliation boundary (or dedicated check).
986
+ - When legacy drift is detected, either **block** with explicit reason code and
987
+ remediation, or **repair** target-scoped and append audit entry (policy documented).
988
+ - Behavior is deterministic; operators get explicit diagnostics.
989
+
990
+ ## Memory drift auditing
991
+
992
+ Run `/memory-audit` at key workflow checkpoints to verify artifact consistency:
993
+
994
+ - **Pre-handoff**: before writing `handoffs/dev_to_qa.md` or any role handoff.
995
+ - **Pre-QA**: before running `/qa` or `/verify-work`.
996
+ - **Pre-release**: before running `/release`.
997
+ - **Ad-hoc**: after external code changes, long pauses, or whenever artifacts
998
+ feel stale.
999
+
1000
+ Output: `docs/engineering/memory-drift-report.md` — an advisory report with
1001
+ severity-classified findings. The command is read-only and non-blocking.
1002
+
1003
+ Interpreting results:
1004
+ - **high**: artifact contradicts repository state — fix before next handoff/release.
1005
+ - **medium**: artifact is likely stale — fix before release.
1006
+ - **low**: minor inconsistency — fix during `/refresh-context` or next sprint.
1007
+
1008
+ Template drift findings (active vs `template/`) are listed for reference only
1009
+ and belong to US-0017 scope.
1010
+
1011
+ Follow-up commands: `/refresh-context`, `/sprint-plan`, `/verify-work`, `/intake`.
1012
+
1013
+ ## Remote execution validation contract
1014
+
1015
+ Remote execution is mode-aware and default-off:
1016
+
1017
+ - `REMOTE_EXECUTION=0`: skip remote-config validation entirely (zero overhead).
1018
+ - `REMOTE_EXECUTION=1`: validate `.cursor/remote.json` before remote activities;
1019
+ fail fast on first blocking issue.
1020
+
1021
+ Validation classes (remote-enabled mode):
1022
+
1023
+ 1. Presence: config file exists at `REMOTE_CONFIG` (default `.cursor/remote.json`)
1024
+ 2. Syntax: JSON parses cleanly
1025
+ 3. Contract: required fields/types/enums
1026
+ 4. Semantics: `defaultTarget` points to an existing enabled target; target ids
1027
+ are unique
1028
+ 5. Security: no inline secret-like literals; env-var refs only for sensitive values
1029
+
1030
+ Required contract summary:
1031
+
1032
+ - Root: `version` (integer), `defaultTarget` (string), `targets` (array)
1033
+ - Target: `id` (string), `type` (`docker|ssh|vm`), `enabled` (boolean),
1034
+ `host` (string), `port` (integer `1..65535`), `workspaceRoot` (string)
1035
+ - Optional auth: `auth.mode` (`none|env`); if `env`, use `*Env` references
1036
+
1037
+ Error message format (actionable, fail-fast):
1038
+
1039
+ - `[REMOTE_CONFIG_ERROR] <path>: expected <rule>, got <actual>. Fix: <hint>.`
1040
+
1041
+ Operator troubleshooting:
1042
+
1043
+ - Missing config file:
1044
+ - Copy from `template/.cursor/remote.json`, or disable remote mode.
1045
+ - Malformed JSON:
1046
+ - Fix syntax (commas/brackets/quotes), then retry.
1047
+ - Invalid value or enum:
1048
+ - Correct field value to the documented contract.
1049
+ - Security violation (inline secret-like literal):
1050
+ - Replace with env-var reference fields (`tokenEnv`, `passwordEnv`,
1051
+ `privateKeyPathEnv`, ...).
1052
+
1053
+ ### Manual vs automation routing (US-0086)
1054
+
1055
+ Manual and automation modes are intentionally separate:
1056
+
1057
+ - Manual mode (`AUTO_REMOTE_AUTOMATION_PROFILE=off`) keeps local-first behavior.
1058
+ No automatic remote routing is allowed, and `TEST_COMMAND` is never silently
1059
+ rerouted to remote targets.
1060
+ - Automation mode (`AUTO_REMOTE_AUTOMATION_PROFILE=deterministic_v1`) may route
1061
+ to Docker/SSH/local targets using deterministic precedence.
1062
+ - Explicit NL intent literal is constrained to `start container <target_id>`.
1063
+ Unknown or disabled targets fail closed.
1064
+
1065
+ Deterministic fail-closed reason codes:
1066
+
1067
+ - `REMOTE_AUTOMATION_MODE_OFF`
1068
+ - `REMOTE_TARGET_UNKNOWN`
1069
+ - `REMOTE_TARGET_DISABLED`
1070
+ - `REMOTE_TARGET_UNROUTABLE`
1071
+
1072
+ Security continuity (`US-0085` / `DEC-0071`) remains mandatory in all modes:
1073
+
1074
+ - Never read `.env` from agent automation.
1075
+ - Never print secret values in command output, logs, handoffs, or state.
1076
+ - Names-only evidence format is required (`secret_surface=names_only`).
1077
+
1078
+ ### Remote-routing evidence tuple (execute/qa/release)
1079
+
1080
+ When automation routing is used, include this tuple in handoffs/state artifacts:
1081
+
1082
+ - `target_id`
1083
+ - `environment_label`
1084
+ - `automation_profile`
1085
+ - `routing_source` (`explicit_intent|heuristic_fallback|local_default`)
1086
+ - `secret_surface=names_only`
1087
+
1088
+ If routing is not used (mode off/local default), still record:
1089
+
1090
+ - `target_id=local-default`
1091
+ - `environment_label=local`
1092
+ - `automation_profile=off`
1093
+ - `routing_source=local_default`
1094
+ - `secret_surface=names_only`
1095
+
1096
+ ### Published npm `installer.sh` / POSIX dash (US-0084)
1097
+
1098
+ - **Symptom**: `set: Illegal option -` on an early line when running `its-magic` or
1099
+ `sh installer.sh` on Debian/Ubuntu (**`/bin/sh`** → **dash**).
1100
+ - **Common causes**: bash-only `set` options (`pipefail`, `-o errexit`, `-u` bundles)
1101
+ on the **unconditional** startup path, or **CRLF** line endings in the file that
1102
+ ships from npm.
1103
+ - **`sh` vs `bash`**: the Unix CLI path uses **`sh` + `installer.sh`** (**BUG-0004** /
1104
+ **DEC-0068**). Do not assume bash for the first lines of **`installer.sh`**.
1105
+ - **Remediation**:
1106
+ - Upgrade to an **its-magic** build that includes **US-0084** (LF + POSIX guards).
1107
+ - Normalize to **LF** only (e.g. `dos2unix installer.sh`, or fix checkout —
1108
+ root **`.gitattributes`** uses `*.sh text eol=lf`).
1109
+ - Reinstall from npm after verifying maintainer gates:
1110
+ `python scripts/guard_installer_publish.py` (also **`npm run guard:installer`**
1111
+ / **`prepublishOnly`**).
1112
+ - **Normative**: **`docs/engineering/architecture.md`** **`# US-0084`**.
1113
+
1114
+ ### Automated checks (US-0084)
1115
+
1116
+ - `python tests/installer_shell_bug0004_test.py` — CR/LF rejection, forbidden
1117
+ `set` tokens, optional **`dash -n`** when **`dash`** is on **`PATH`**.
1118
+ - `python scripts/guard_installer_publish.py` — same checks for publish/CI
1119
+ (**`prepublishOnly`**).
1120
+ - `python scripts/remote_config_summary.py` — with **`REMOTE_EXECUTION=1`**,
1121
+ read-only summary of **`REMOTE_CONFIG`** (default **`.cursor/remote.json`**);
1122
+ stdout is **names-only** (no secret values). **`DEC-0070`**: when
1123
+ **`REMOTE_EXECUTION=0`**, the helper exits **0** and skips validation
1124
+ (stderr skip reason).
1125
+
1126
+ ### Optional deterministic CI routing recipe (US-0086)
1127
+
1128
+ Use this only when CI needs explicit remote-target hints; keep it opt-in.
1129
+
1130
+ 1. Define explicit path filters:
1131
+ - container surfaces: `Dockerfile*`, `docker-compose*.yml`, container scripts
1132
+ - ssh/runtime infra surfaces: deployment ssh scripts, host runtime scripts
1133
+ 2. Route using explicit matrix labels (`local`, `docker`, `ssh`) with no
1134
+ implicit fallback logic outside documented defaults.
1135
+ 3. Keep manual mode unchanged: if `AUTO_REMOTE_AUTOMATION_PROFILE=off`, run
1136
+ local path and do not apply remote routing.
1137
+ 4. Emit names-only evidence (`target_id`, `environment_label`,
1138
+ `automation_profile`, `routing_source`, `secret_surface=names_only`) into
1139
+ CI logs/artifacts.
1140
+
1141
+ ## Runtime QA autopilot contract (US-0065 / DEC-0047)
1142
+
1143
+ Generated-project validation requires runtime proof, not static checks alone.
1144
+
1145
+ Mandatory runtime stage order:
1146
+
1147
+ `startup -> readiness/connectivity -> log scan -> bounded retry -> verdict`
1148
+
1149
+ Deterministic runtime failure reason codes:
1150
+
1151
+ - `RUNTIME_STARTUP_FAILED`
1152
+ - `RUNTIME_ENDPOINT_UNREACHABLE`
1153
+ - `RUNTIME_LOG_CRITICAL_DETECTED`
1154
+ - `RUNTIME_RETRY_BUDGET_EXHAUSTED`
1155
+ - `RUNTIME_STACK_PROFILE_UNRESOLVED`
1156
+
1157
+ Runtime evidence schema (record in QA findings):
1158
+
1159
+ - `runtime_startup_command`
1160
+ - `runtime_stack_profile` (`node|python|go|java|dotnet`)
1161
+ - `runtime_mode` (`local|remote`)
1162
+ - `runtime_health_target`
1163
+ - `runtime_health_result`
1164
+ - `runtime_log_summary` (severity counts and key error signals)
1165
+ - `runtime_retry_count`
1166
+ - `runtime_retry_ledger` (`attempt`, `delay_ms`, `outcome`)
1167
+ - `runtime_final_verdict`
1168
+ - `runtime_reason_code`
1169
+ - `runtime_evidence_refs`
1170
+
1171
+ Bounded retry policy:
1172
+
1173
+ - retry only transient startup/connectivity failures
1174
+ - enforce configured max-attempt cap (`attempt <= max`)
1175
+ - fail fast on non-transient critical runtime log signals
1176
+
1177
+ Stack/profile resolution:
1178
+
1179
+ - Minimum supported runtime profiles: Node, Python, Go, Java, .NET.
1180
+ - Unknown or ambiguous profile must fail closed with
1181
+ `RUNTIME_STACK_PROFILE_UNRESOLVED`.
1182
+
1183
+ Webapp verification path (when applicable):
1184
+
1185
+ - include browser-surface load validation
1186
+ - capture console error summary and failed network request summary
1187
+ - add these signals to `runtime_log_summary` and evidence refs
1188
+
1189
+ Optional debug escalation (bounded):
1190
+
1191
+ - use for reproducible runtime failures only
1192
+ - keep instrumentation bounded and reversible
1193
+ - record applied debug steps and explicit cleanup confirmation
1194
+
1195
+ ## Generated test scaffolding + auto-run contract (US-0066 / DEC-0048)
1196
+
1197
+ Generated app projects require deterministic baseline test scaffolding and
1198
+ automatic QA test execution evidence.
1199
+
1200
+ Detection/profile contract:
1201
+
1202
+ - Resolve one deterministic stack profile from:
1203
+ `node|python|go|java|dotnet` (minimum supported).
1204
+ - If profile cannot be resolved, fail closed with
1205
+ `TEST_SCAFFOLD_STACK_UNRESOLVED`.
1206
+ - If detected stack is outside supported baseline set, fail closed with
1207
+ `TEST_SCAFFOLD_UNSUPPORTED_STACK`.
1208
+
1209
+ Generation contract (`/execute`):
1210
+
1211
+ - Generate only missing baseline assets for:
1212
+ - unit tests
1213
+ - integration tests
1214
+ - acceptance tests
1215
+ - Use stable scaffold paths so reruns are idempotent (no duplicate file churn).
1216
+ - Record generated paths and actions in execution evidence.
1217
+ - If generation fails, fail closed with `TEST_SCAFFOLD_GENERATION_FAILED`.
1218
+
1219
+ Runbook command wiring:
1220
+
1221
+ - `TEST_COMMAND` baseline is stack-aware and deterministic.
1222
+ - Non-destructive precedence is mandatory:
1223
+ - preserve user-authored non-empty `TEST_COMMAND`,
1224
+ - write baseline command only when `TEST_COMMAND` is missing/unset.
1225
+
1226
+ QA auto-run evidence contract (`/qa`):
1227
+
1228
+ - Execute generated baseline tests automatically.
1229
+ - Record evidence fields:
1230
+ - `generated_test_stack_profile`
1231
+ - `generated_test_command`
1232
+ - `generated_test_result`
1233
+ - `generated_test_output_ref`
1234
+ - `generated_test_paths_ref`
1235
+ - `generated_test_reason_code`
1236
+
1237
+ Runtime boundary with US-0065:
1238
+
1239
+ - Generated static test PASS is required but never sufficient for QA PASS.
1240
+ - Runtime-autopilot verdict remains mandatory; non-starting apps cannot PASS QA.
1241
+
1242
+ ## Auto continuation resume contract
1243
+
1244
+ `/auto` continuation uses deterministic phase resolution (DEC-0017):
1245
+
1246
+ 1. explicit `/auto start-from=<phase>`
1247
+ 2. `handoffs/resume_brief.md`
1248
+ 3. conservative `docs/engineering/state.md` fallback
1249
+ 4. fail-fast
1250
+
1251
+ Canonical `start-from` phase IDs:
1252
+ `intake`, `discovery`, `research`, `architecture`, `sprint-plan`,
1253
+ `plan-verify`, `execute`, `qa`, `verify-work`, `release`, `refresh-context`.
1254
+
1255
+ Conflict and stale-source policy:
1256
+ - Explicit valid override wins.
1257
+ - If no override and `resume_brief` conflicts with `state`, fail fast.
1258
+ - If `resume_brief` exists but is stale/unparseable, fail fast.
1259
+ - Use state fallback only when `resume_brief` is absent.
1260
+
1261
+ Fail-fast error format:
1262
+ - `[AUTO_RESUME_ERROR] <code>: <summary>. Source=<source>. Fix: <action>.`
1263
+
1264
+ Required error codes:
1265
+ - `INVALID_START_FROM`
1266
+ - `RESUME_BRIEF_MISSING`
1267
+ - `RESUME_BRIEF_STALE`
1268
+ - `RESUME_BRIEF_UNPARSEABLE`
1269
+ - `RESUME_STATE_CONFLICT`
1270
+ - `STATE_PHASE_AMBIGUOUS`
1271
+ - `STATE_PHASE_UNRECOVERABLE`
1272
+
1273
+ Breadcrumbs required for inspectability:
1274
+ - `resolution_source`, `resolved_start_phase`, `stop_reason`, `stop_phase`,
1275
+ `timestamp`.
1276
+ - Record in `docs/engineering/state.md`; update `handoffs/resume_brief.md` when
1277
+ auto stops before completion.
1278
+
1279
+ Stop-condition preservation:
1280
+ - continuation does not bypass decision gates, missing-input blockers,
1281
+ pause requests, or loop max cycle limits.
1282
+
1283
+ ## Per-phase subagent isolation evidence (US-0048 / DEC-0029)
1284
+
1285
+ Per-phase fresh-context isolation is enforced with auditable, fail-closed
1286
+ evidence.
1287
+
1288
+ ### Canonical evidence store and locations
1289
+
1290
+ - Canonical evidence store: `docs/engineering/state.md` (append-only checkpoints).
1291
+ - Cross-references are allowed in phase artifacts and handoffs:
1292
+ - `handoffs/dev_to_qa.md`, `handoffs/qa_to_dev.md`
1293
+ - `handoffs/resume_brief.md` (pause/resume provenance)
1294
+ - `sprints/Sxxxx/summary.md`, `sprints/Sxxxx/qa-findings.md`, `sprints/Sxxxx/uat.*`,
1295
+ `sprints/Sxxxx/release-findings.md`
1296
+
1297
+ ### Required schema (one entry per phase run)
1298
+
1299
+ Each phase run must append an isolation evidence entry containing:
1300
+
1301
+ - `phase_id`: canonical phase id (`intake|discovery|research|architecture|sprint-plan|plan-verify|execute|qa|verify-work|release|refresh-context|pause|resume`)
1302
+ - `role`: subagent role executing the phase (`po|curator|tech-lead|dev|qa|release|security`)
1303
+ - `fresh_context_marker`: a marker unique to the fresh subagent context for this phase run
1304
+ - `timestamp`: ISO UTC timestamp
1305
+ - `evidence_ref`: canonical path to the primary artifact written/validated for the phase run
1306
+
1307
+ ### Gate behavior (fail closed)
1308
+
1309
+ - Missing evidence blocks progression with `PHASE_CONTEXT_ISOLATION_MISSING`.
1310
+ - Invalid schema/fields blocks progression with `ISOLATION_EVIDENCE_INVALID`.
1311
+ - Stale evidence (reused marker across runs or older than the resumed boundary)
1312
+ blocks progression with `ISOLATION_EVIDENCE_STALE`.
1313
+ - Orchestrator executing phase work without spawning a fresh subagent context is
1314
+ a hard violation: `PHASE_CONTEXT_ISOLATION_VIOLATION`.
1315
+
1316
+ Remediation (all cases): re-run the affected phase in a fresh subagent context
1317
+ and write new isolation evidence before proceeding.
1318
+
1319
+ ### Reason codes and remediation (US-0048)
1320
+
1321
+ - `PHASE_CONTEXT_ISOLATION_MISSING`: no isolation evidence entry found for a
1322
+ required phase run. Fix: rerun the phase in a fresh subagent and append the
1323
+ required evidence fields.
1324
+ - `ISOLATION_EVIDENCE_INVALID`: evidence entry present but missing required
1325
+ fields or contains invalid `phase_id`/`role`. Fix: rerun the phase and write a
1326
+ corrected entry.
1327
+ - `ISOLATION_EVIDENCE_STALE`: evidence is reused across runs/cycles or predates
1328
+ the latest resume boundary. Fix: rerun the phase and write a new
1329
+ `fresh_context_marker`.
1330
+ - `PHASE_CONTEXT_ISOLATION_VIOLATION`: phase work was performed without a fresh
1331
+ subagent context (for example orchestrator performed phase writes). Fix: stop,
1332
+ revert unsafe artifacts if needed, rerun the phase correctly, and ensure
1333
+ orchestration-only behavior.
1334
+
1335
+ ## Strict runtime proof contract (US-0056 / DEC-0038)
1336
+
1337
+ Strict runtime proof augments artifact-level isolation evidence. `/auto`,
1338
+ `/verify-work`, and `/release` must validate runtime attestation tuples at phase
1339
+ boundaries before continuation/finalization.
1340
+
1341
+ Required runtime attestation tuple fields:
1342
+
1343
+ - `orchestrator_run_id`
1344
+ - `runtime_proof_id` (unique per phase run)
1345
+ - `phase_id`
1346
+ - `role`
1347
+ - `proof_issued_at` (ISO UTC / RFC3339)
1348
+ - `proof_ttl_seconds`
1349
+ - `proof_hash`
1350
+
1351
+ Deterministic fail-closed reason codes:
1352
+
1353
+ - `RUNTIME_PROOF_MISSING`
1354
+ - `RUNTIME_PROOF_INVALID`
1355
+ - `RUNTIME_PROOF_REUSED`
1356
+ - `RUNTIME_PROOF_STALE`
1357
+ - `RUNTIME_PROOF_AMBIGUOUS_LINK`
1358
+
1359
+ Boundary behavior:
1360
+
1361
+ - Missing/invalid/reused/stale/ambiguous runtime proof blocks progression.
1362
+ - Release finalization must consume strict runtime proof in addition to existing
1363
+ isolation evidence checks.
1364
+ - Pause/resume provenance must reference latest valid strict-proof boundary.
1365
+
1366
+ ## Strict `/auto` phase→role enforcement (US-0069 / DEC-0051)
1367
+
1368
+ `/auto` must treat phase roles as a **fail-closed admission and checkpoint
1369
+ contract** (see `decisions/DEC-0051.md` and `/auto` command text).
1370
+
1371
+ ### Canonical matrix and scratchpad alternates
1372
+
1373
+ - Fixed phase→role defaults are documented in `/auto` (for example `execute` →
1374
+ `dev`, `release` → `release`).
1375
+ - Alternate phases resolve **one** expected role via scratchpad:
1376
+ - `AUTO_ROLE_RESEARCH`: `po` \| `tech-lead` (empty → default `tech-lead`)
1377
+ - `AUTO_ROLE_PLAN_VERIFY`: `qa` \| `tech-lead` (empty → default `qa`)
1378
+ - `AUTO_ROLE_REFRESH_CONTEXT`: `curator` \| `po` (empty → default `curator`)
1379
+ - Non-empty values outside the allowed set fail closed (no unrelated-role
1380
+ substitution).
1381
+
1382
+ ### Preflight and checkpoints
1383
+
1384
+ - **Preflight (before spawn)**: resolve expected role; verify the required
1385
+ subagent capability exists. Missing capability → `PHASE_ROLE_CAPABILITY_MISSING`
1386
+ with `phase_id`, expected role, observed result, remediation. Do not spawn a
1387
+ substitute role.
1388
+ - **Post-completion**: isolation evidence `role` and strict-proof `role` must
1389
+ both match the same preflight-resolved role; else `PHASE_ROLE_MISMATCH`.
1390
+ - **`proof_hash`**: SHA-256 over sorted-key JSON of the strict-proof tuple fields
1391
+ (`orchestrator_run_id`, `runtime_proof_id`, `phase_id`, `role`,
1392
+ `proof_issued_at`, `proof_ttl_seconds`).
1393
+
1394
+ ### Execute default deny and rare override
1395
+
1396
+ - Default: `execute` requires `dev`.
1397
+ - Override allowed only when **both** hold:
1398
+ `AUTO_EXECUTE_ROLE_OVERRIDE=allowed_non_dev_execute` and
1399
+ `EXECUTE_OVERRIDE_GOVERNANCE_REF` references a parseable approved exception (for
1400
+ example `DEC-xxxx` or a documented state anchor).
1401
+
1402
+ ### Continuation parity
1403
+
1404
+ - Every `/auto` run recomputes role policy and preflight; `start-from`, fresh
1405
+ `resume_brief`, and `state.md` fallback cannot bypass the gate with stale role
1406
+ intent alone.
1407
+
1408
+ ## Configurable `/auto` phase plan (US-0070 / DEC-0052)
1409
+
1410
+ `/auto` schedules a **resolved ordered phase plan** from merged scratchpad
1411
+ before any spawn. See `decisions/DEC-0052.md` and `/auto` command text.
1412
+
1413
+ ### Selectors (exactly one active mode)
1414
+
1415
+ - `AUTO_PHASE_PLAN=full` (default when unset and no other selector is set)
1416
+ - `AUTO_PHASE_EXCLUDE=<csv>` — remove listed canonical phase ids from `full`
1417
+ - `AUTO_PHASE_INCLUDE=<csv>` — only listed ids, re-sorted into canonical lifecycle order
1418
+ - `AUTO_PHASE_PROFILE=<name>` — expand a named profile (unknown → fail closed)
1419
+ - `AUTO_PHASE_HIGH_RISK_ACK=<token>` — required when a documented high-risk profile demands acknowledgment
1420
+
1421
+ Conflicting selectors → `PHASE_POLICY_CONFLICT` (no plan materialization).
1422
+
1423
+ ### Materialization and gates
1424
+
1425
+ - Expand → apply **non-skippable reinstatement** (`qa`, `verify-work`, `release`,
1426
+ plus evidence-chain closure per `/auto`) → intersect **`start-from` / resume
1427
+ anchor** with the plan → **empty intersection** →
1428
+ `START_FROM_PHASE_PLAN_EMPTY_INTERSECTION`.
1429
+ - Record `resolved_phase_plan`, `skipped_phases` (+ reasons such as
1430
+ `policy_exclude`, `non_skippable_gate`), and **phase boundary status** entries
1431
+ in continuation breadcrumbs (`docs/engineering/state.md`).
1432
+ - **Backlog-drain**, **bulk execute**, and **team scope** paths must **reload**
1433
+ scratchpad phase-selection inputs and **recompute** the plan at each bounded
1434
+ boundary (no silent revival of omitted phases).
1435
+
1436
+ ### Failure codes (deterministic)
1437
+
1438
+ - `PHASE_POLICY_CONFLICT`
1439
+ - `PHASE_PLAN_UNKNOWN_PHASE`
1440
+ - `PHASE_PLAN_EMPTY_INCLUDE`
1441
+ - `PHASE_PLAN_UNKNOWN_PROFILE`
1442
+ - `PHASE_PLAN_INVALID_AUTO_PHASE_PLAN`
1443
+ - `PHASE_PLAN_HIGH_RISK_ACK_REQUIRED`
1444
+ - `START_FROM_PHASE_PLAN_EMPTY_INTERSECTION`
1445
+
1446
+ ## Optional backlog-drain auto mode (US-0044)
1447
+
1448
+ `/auto` can optionally continue across multiple planned stories when explicitly
1449
+ enabled in scratchpad.
1450
+
1451
+ Controls:
1452
+ - `AUTO_BACKLOG_DRAIN=0|1` (default `0`)
1453
+ - `AUTO_BACKLOG_MAX_STORIES=<n>` (default `1`)
1454
+ - `AUTO_BACKLOG_ON_BLOCK=stop|skip` (default `stop`)
1455
+ - `AUTO_STORY_SELECTION=priority_then_backlog_order` (default)
1456
+
1457
+ Semantics:
1458
+ - With `AUTO_BACKLOG_DRAIN=0`, keep current single-segment continuation behavior.
1459
+ - With `AUTO_BACKLOG_DRAIN=1`, select next eligible OPEN story
1460
+ deterministically and run full lifecycle story-by-story until bounded limit,
1461
+ no eligible stories, or a mandatory stop condition.
1462
+ - Decision gates remain mandatory and pause progression until user decision.
1463
+
1464
+ ## Targeted bug auto drain (US-0087)
1465
+
1466
+ Use **`/auto`** with an explicit **OPEN** bug binding when you want defect-scoped
1467
+ continuation instead of story **`AUTO_BACKLOG_DRAIN`**.
1468
+
1469
+ **Canonical argv** (exact literals; no aliases in v1):
1470
+
1471
+ - **`bug-target=BUG-####`** — single **OPEN** bug from **`docs/product/backlog.md`**
1472
+ **`## Bug issues (canonical)`** (example: **`bug-target=BUG-0007`**).
1473
+ - **`bug-target=all-open`** — walk all **OPEN** bugs in ascending **numeric**
1474
+ **`BUG-####`** order (optional per-run cap: **`AUTO_BUG_MAX_ITEMS`**).
1475
+
1476
+ **Scratchpad** (merged; default-off — see **`.cursor/scratchpad.md`** and
1477
+ **`template/.cursor/scratchpad.local.example.md`**):
1478
+
1479
+ - **`AUTO_BUG_QUEUE`**, **`AUTO_BUG_TARGET`**, **`AUTO_BUG_MAX_ITEMS`**, **`AUTO_BUG_ON_BLOCK`**
1480
+
1481
+ **Mutex**: do **not** enable **`AUTO_BACKLOG_DRAIN=1`** and **`AUTO_BUG_QUEUE=1`**
1482
+ together **without** an explicit **`bug-target=`** argv on that invocation — fail
1483
+ closed **`AUTO_SCHEDULER_CONFLICT`**. Supply **`bug-target=`** to select the bug
1484
+ scheduler for that run (normative detail: **`docs/engineering/auto-orchestration-reference.md`**
1485
+ **Optional bug-queue mode (US-0087)** and **`docs/engineering/architecture.md`**
1486
+ **`# US-0087`**).
1487
+
1488
+ **Fail-closed codes**: **`AUTO_BUG_QUEUE_EMPTY`**, **`AUTO_BUG_TARGET_UNKNOWN`**,
1489
+ **`AUTO_BUG_TARGET_NOT_OPEN`**, **`AUTO_SCHEDULER_CONFLICT`** — plus spawn-only
1490
+ orchestrator rules (**`BUG-0006`**, **`US-0069`**, **`AUTO_ORCHESTRATOR_PHASE_EXECUTION`**;
1491
+ see **`.cursor/commands/auto.md`**).
1492
+
1493
+ ## Continuous `/auto` + backlog drain (US-0088)
1494
+
1495
+ **Goal:** a single `/auto` run (or documented equivalent outer driver) advances
1496
+ through all intersected lifecycle phases until a deterministic stop, and
1497
+ `AUTO_BACKLOG_DRAIN=1` can continue across multiple OPEN stories without routine
1498
+ operator chatter.
1499
+
1500
+ ### Quick start
1501
+
1502
+ ```
1503
+ /auto # full lifecycle, single story
1504
+ /auto start-from=execute # resume from execute phase
1505
+ ```
1506
+
1507
+ With backlog drain enabled (`.cursor/scratchpad.md`):
1508
+
1509
+ ```
1510
+ AUTO_BACKLOG_DRAIN=1
1511
+ AUTO_BACKLOG_MAX_STORIES=5
1512
+ AUTO_BACKLOG_ON_BLOCK=stop
1513
+ ```
1514
+
1515
+ ### Normative reference
1516
+
1517
+ Multi-phase iteration lives in
1518
+ **`docs/engineering/auto-orchestration-reference.md`** **`## Steps`** item 5
1519
+ (cross-anchor: **"reference Step 5"**). The compact steps in
1520
+ **`.cursor/commands/auto.md`** point to that block unambiguously.
1521
+
1522
+ ### Caps and safety guards
1523
+
1524
+ | Control | Default | Purpose |
1525
+ |---------|---------|---------|
1526
+ | `AUTO_BACKLOG_MAX_STORIES` | `1` | Max stories per drain run |
1527
+ | `AUTO_LOOP_MAX_CYCLES` | `5` | Max execute-QA cycles per story |
1528
+ | `AUTO_PAUSE_REQUEST` | `0` | Set to `1` to request graceful stop at next safe boundary |
1529
+ | `AUTO_PAUSE_POLICY` | `after_phase` | Stop boundary granularity |
1530
+
1531
+ ### Decision gates
1532
+
1533
+ Decision gates are **never** suppressed — even when `AUTO_QUIET=1`. When a gate
1534
+ fires, the run stops and waits for operator resolution before continuing.
1535
+
1536
+ ### `AUTO_QUIET` (default off)
1537
+
1538
+ Set `AUTO_QUIET=1` in `.cursor/scratchpad.md` to suppress **routine** per-phase
1539
+ success chatter. Non-suppressible notifications:
1540
+
1541
+ - `decision_gate`
1542
+ - Errors / `missing_input`
1543
+ - `pause_request`
1544
+ - `loop_max`
1545
+ - `blocked`
1546
+ - Segment handoff / drain advance
1547
+
1548
+ `AUTO_QUIET` is **orthogonal** to `TOKEN_PROFILE` (**DEC-0035** / **US-0080**):
1549
+ `TOKEN_PROFILE` controls context breadth and token cost, not notification policy.
1550
+
1551
+ Under **`full_autonomy`** IDE native chain (**US-0095**), drain advance suppresses
1552
+ routine prose when **`AUTO_QUIET=1`** but **must not** emit mandatory outer-driver
1553
+ wait instructions between segments.
1554
+
1555
+ ### Native in-chat auto-chain (US-0095)
1556
+
1557
+ **Primary IDE recipe** for hands-off delivery when **`AUTO_FLOW_MODE=full_autonomy`**
1558
+ (default-off): run **`/auto` once in Cursor** — orchestrator self-chains in-chat
1559
+ across phases and drain segments via **foreground sequential** Task loop in the
1560
+ **same /auto orchestrator session**.
1561
+
1562
+ #### Enable and run (IDE primary)
1563
+
1564
+ 1. Set in merged scratchpad:
1565
+ - `AUTO_FLOW_MODE=full_autonomy`
1566
+ - Optional: `AUTO_BACKLOG_DRAIN=1`, caps (`AUTO_LOOP_MAX_CYCLES`, `AUTO_BACKLOG_MAX_STORIES`, `AUTO_BLOCK_RETRY_MAX`)
1567
+ 2. Run **`/auto`** once in Cursor Agent panel (no `--invoke-cmd`).
1568
+ 3. Orchestrator continues in-chat until hard stop, drain budget exhausted, or
1569
+ **`NATIVE_CHAIN_UNAVAILABLE`** (optional fallback: outer driver below).
1570
+
1571
+ Normative detail: **`.cursor/commands/auto.md`** § **Native in-chat auto-chain (US-0095)**
1572
+ and **`docs/engineering/auto-orchestration-reference.md`** § **Native in-chat auto-chain**.
1573
+
1574
+ #### Primary / fallback boundary
1575
+
1576
+ | Context | Native in-chat chain | Outer driver | Messaging |
1577
+ |---------|---------------------|--------------|-----------|
1578
+ | **Cursor IDE + `full_autonomy`** | **Primary** | **Optional fallback** | No mandatory outer-driver drain recipe |
1579
+ | **Headless / CI** | Unavailable | **Recommended** | Runbook: headless primary |
1580
+ | **`--invoke-cmd`** | N/A | **Required** bridge | Document in runbook |
1581
+ | **`NATIVE_CHAIN_UNAVAILABLE`** | Stops | Suggested (**optional** tone) | Non-suppressible |
1582
+
1583
+ ### BUG-0012 regression verify
1584
+
1585
+ Multi-segment operator E2E recipe — validates native-chain orchestrator compliance
1586
+ (**DEC-0081**) after **US-0095** contract delivery.
1587
+
1588
+ 1. **Scratchpad**: set **`AUTO_FLOW_MODE=full_autonomy`**, **`AUTO_BACKLOG_DRAIN=1`**,
1589
+ **`AUTO_BACKLOG_MAX_STORIES≥2`**, **`AUTO_QUIET=1`** in merged `.cursor/scratchpad.md`.
1590
+ 2. **Backlog**: ensure **≥2 OPEN stories** in `docs/product/backlog.md`.
1591
+ 3. **Invoke**: run **`/auto`** once in Cursor IDE Agent panel (no `--invoke-cmd`).
1592
+ 4. **Complete segment A**: let orchestration finish **story A** through **`refresh-context`**.
1593
+ 5. **Pass criteria**: orchestrator drain-advances to **story B** first phase **without**
1594
+ operator re-**`/auto`** and **without** forbidden terminal prose (no mandatory
1595
+ `re-run /auto`, no mandatory outer driver, no `segment exhausted` terminal when
1596
+ continuation pending).
1597
+ 6. **Evidence**: `docs/engineering/state.md` segment boundary shows
1598
+ **`drain_advance_action=spawned`**, **`native_chain_continuing=true`**;
1599
+ `handoffs/resume_brief.md` top pointer advances **`story_id`** to story B.
1600
+
1601
+ Normative detail: **`.cursor/commands/auto.md`** § **Orchestrator post-subagent continuation
1602
+ mandate (BUG-0012)** and architecture **`# BUG-0012`**.
1603
+
1604
+ ### Full-autonomy outer driver (US-0092) — fallback
1605
+
1606
+ Opt-in **`AUTO_FLOW_MODE=full_autonomy`** (exact literal, default-off) also enables
1607
+ the shipped stdlib outer driver as **optional** / **fallback** for headless/CI or
1608
+ when native in-chat chain is unavailable. Spawn-only preserved — the driver loops hook
1609
+ invocations; it never performs phase-role work. **Not required** for IDE drain.
1610
+
1611
+ #### Enable and run (headless/CI fallback)
1612
+
1613
+ 1. Set in merged scratchpad (`.cursor/scratchpad.md` + optional local overrides):
1614
+ - `AUTO_FLOW_MODE=full_autonomy`
1615
+ - Optional: `AUTO_BACKLOG_DRAIN=1`, `AUTO_BUG_QUEUE=1` (scheduler mutex per US-0087)
1616
+ - Caps: `AUTO_LOOP_MAX_CYCLES`, `AUTO_BACKLOG_MAX_STORIES`, `AUTO_BLOCK_RETRY_MAX` (default `3`)
1617
+ - Optional: `AUTO_OUTER_DRIVER_TIMEOUT_SECONDS` (unset = no timeout)
1618
+ 2. Run once: `python scripts/auto_outer_driver.py --repo .`
1619
+ 3. Interpret exit code (driver prints reason tokens on stderr):
1620
+
1621
+ | Exit | Meaning |
1622
+ |------|---------|
1623
+ | **0** | `completed` — segment/portfolio terminal per policy |
1624
+ | **1** | Hard stop — `decision_gate`, unrecoverable `error`, isolation/strict-proof, security deny |
1625
+ | **2** | Configuration — `AUTO_FLOW_MODE` not `full_autonomy` (`AUTO_FLOW_MODE_NOT_FULL_AUTONOMY`) |
1626
+ | **3** | `loop_max` — `AUTO_LOOP_MAX_CYCLES` exhausted |
1627
+ | **4** | `BACKLOG_MAX_STORIES_REACHED` / drain cap |
1628
+ | **5** | `pause_request` / `AUTO_PAUSE_REQUEST` |
1629
+ | **6** | `BLOCK_RETRY_CAP_EXHAUSTED` |
1630
+ | **124** | Hook/subprocess timeout |
1631
+
1632
+ `--dry-run` emits planned `/auto` hook invocations and drain-advance scheduling
1633
+ without side effects. `--invoke-cmd` overrides the default normative `/auto …` line.
1634
+
1635
+ #### Security (US-0092 / DEC-0078)
1636
+
1637
+ - **No** auto-read **`.env`** or secret paths.
1638
+ - **No** intake evidence mutation under automation.
1639
+ - **No** publish without **`RELEASE_PUBLISH_MODE=auto`** (explicit opt-in; default-off).
1640
+ - Block-retry ledger **`handoffs/auto_block_retry/<orchestrator_run_id>.jsonl`** is
1641
+ names-only — no secrets, no file contents.
1642
+
1643
+ UAT self-verify: **`scripts/uat_probe_lib.py`** shared by **`/verify-work`** and **`/qa`**.
1644
+
1645
+ ### Browser UAT self-test (US-0093)
1646
+
1647
+ Enable Cursor browser-integrated UAT probes for web acceptance steps (**DEC-0079**).
1648
+
1649
+ #### Scratchpad keys
1650
+
1651
+ | Key | Values | Default | Notes |
1652
+ |-----|--------|---------|-------|
1653
+ | `UAT_BROWSER_PROBE_MODE` | `cursor` \| `http_fallback` \| `playwright_fallback` | `cursor` | Primary probe path |
1654
+ | `UAT_BROWSER_FALLBACK_CHAIN` | `0` \| `1` | `1` | HTTP → Playwright after MCP unavailable |
1655
+ | `UAT_PROCESS_HEALTH_POLL_SECONDS` | int | `60` | Readiness poll cap |
1656
+ | `UAT_PROCESS_HEALTH_POLL_INTERVAL_SECONDS` | int | `2` | Poll interval |
1657
+ | `DEV_SERVER_PORT` | int | unset | Port override |
1658
+ | `DEV_SERVER_COMMAND` | command | unset | Startup override |
1659
+
1660
+ Orthogonal to **`PERMISSION_MODE`** and Cursor browser approval modes. Health URLs from
1661
+ **`docs/engineering/runtime-connectivity.md`** first.
1662
+
1663
+ #### CI recipe
1664
+
1665
+ Set **`UAT_BROWSER_PROBE_MODE=http_fallback`** in CI — never false PASS without agent evidence.
1666
+
1667
+ #### Evidence layout
1668
+
1669
+ Binary artifacts under **`sprints/Sxxxx/evidence/browser/`** (gitignored OK). JSON carries path
1670
+ refs only. Validate agent write-back:
1671
+ `python scripts/uat_probe_lib.py --merge-result sprints/Sxxxx/evidence/browser/fragment.json`.
1672
+
1673
+ #### Manual override
1674
+
1675
+ Use **`@browser`** in Agent panel or invoke browser tools manually when MCP sequence needs operator
1676
+ approval for production-like targets.
1677
+
1678
+ ### Caveman mode (US-0089)
1679
+
1680
+ Optional response-side terse / imperative assistant voice. **Default off.**
1681
+ When `CAVEMAN_MODE=0` (or absent), this mode adds **zero** behavioral change
1682
+ and the assistant responds exactly as it did pre-US-0089. Full contract:
1683
+ **DEC-0072** + `docs/engineering/architecture.md` `# US-0089` +
1684
+ `.cursor/rules/caveman.mdc`.
1685
+
1686
+ Non-substitution with `TOKEN_PROFILE`:
1687
+
1688
+ `TOKEN_PROFILE` controls context breadth. `CAVEMAN_MODE` controls reply voice. Neither substitutes for the other; setting one does not change the other. Combine freely.
1689
+
1690
+ #### Scratchpad keys
1691
+
1692
+ | Key | Values | Default | Notes |
1693
+ |-----|--------|---------|-------|
1694
+ | `CAVEMAN_MODE` | `0` \| `1` | `0` | `0` = pre-US-0089 behavior. `1` = voice rule active. Absence = `0`. |
1695
+ | `CAVEMAN_LEVEL` | `lite` \| `full` \| `ultra` or empty | empty | With `MODE=0`: inert. With `MODE=1` and empty: treat as `full`. Unknown value → `CAVEMAN_LEVEL_UNKNOWN` (fail closed; fall back to pre-US-0089 voice while continuing the turn). |
1696
+ | `CAVEMAN_COMPRESS_INPUT` | `0` \| `1` | `0` | **Reserved for US-0090.** Documented no-op in US-0089. |
1697
+ | `CAVEMAN_FILE_SCOPE` | string | empty | **Reserved for US-0090.** Documented no-op in US-0089. |
1698
+
1699
+ #### Canonical operator toggle phrases
1700
+
1701
+ | Phrase | Effect |
1702
+ |--------|--------|
1703
+ | `caveman on` | Enable Caveman voice for the session (overlay). Effective from the next assistant turn. |
1704
+ | `caveman off` | Disable Caveman voice for the session (overlay). Effective from the next assistant turn. |
1705
+ | `stop caveman` | Alias for `caveman off`. |
1706
+ | `normal mode` | Alias for `caveman off`. |
1707
+ | `caveman: lite|full|ultra` | Set level for the session (implies `caveman on`). Effective from the next assistant turn. Accepts the three literal tokens `caveman: lite`, `caveman: full`, `caveman: ultra`. |
1708
+
1709
+ #### Determinism semantics
1710
+
1711
+ - Scratchpad `CAVEMAN_MODE` / `CAVEMAN_LEVEL` are **authoritative across
1712
+ subagent spawns**; session toggle phrases are overlays for the current
1713
+ conversation only and do NOT persist across a fresh subagent context.
1714
+ - Session toggle phrases apply **as an overlay for the next assistant
1715
+ turn**; they never rewrite the current turn's machine-verifiable
1716
+ artifacts (gate messages, reason codes, strict-proof tuples, isolation
1717
+ evidence fields).
1718
+ - Within a session, the **last explicit toggle wins**. Ambiguous phrases
1719
+ are **not** recognized — only the literal matches in the table above.
1720
+
1721
+ #### Literal-region invariant (rule-enforced)
1722
+
1723
+ Under `CAVEMAN_MODE=1`, the 9 literal regions enumerated in
1724
+ `.cursor/rules/caveman.mdc` (fenced code, paths, AC checklists, reason
1725
+ codes, IDs, contract markers, strict-proof tuple fields, isolation
1726
+ evidence fields, git refs) render byte-literal. The non-suppressible gate
1727
+ vocabulary inherited from **US-0088** (`decision_gate`, `error`, `pause`,
1728
+ `loop_max`, `blocked`, `missing input`, `[BUG_VALIDATION_OK]`,
1729
+ `[INTAKE_EVIDENCE_VALIDATION_OK]`, `[SCRATCHPAD_PAIR_OK]`) also renders
1730
+ byte-literal even at `CAVEMAN_LEVEL=ultra`.
1731
+
1732
+ #### Voice compression levels
1733
+
1734
+ Compact before/after examples (full contract: `.cursor/rules/caveman.mdc`):
1735
+
1736
+ | Scenario | Level | Before | After |
1737
+ |----------|-------|--------|-------|
1738
+ | Technical explain | `full` | "The spawn-only orchestrator must dispatch a fresh subagent for each phase." | "Spawn-only orchestrator dispatches fresh subagent per phase. Next: run `/execute`." |
1739
+ | Destructive warning (auto-clarity break) | (pause) | "I will run `git push --force` to fix the remote." | "Destructive: `git push --force` rewrites remote history. Confirm branch and remote before proceeding." |
1740
+
1741
+ Normative voice-compression contract (precedence, drop rules, persistence,
1742
+ 9-zone deferral): **`.cursor/rules/caveman.mdc`** — `## Voice compression
1743
+ (when CAVEMAN_MODE=1)`.
1744
+
1745
+ ### Caveman input compression (US-0090)
1746
+
1747
+ Optional **input-side** file compression. **Default off.** Operator-initiated,
1748
+ script-invoked only. Never fires autonomously. Full contract:
1749
+ **DEC-0073** + `docs/engineering/architecture.md` `# US-0090` +
1750
+ `scripts/caveman_compress_input.py`.
1751
+
1752
+ Non-substitution with `TOKEN_PROFILE` and `CAVEMAN_MODE`:
1753
+
1754
+ `TOKEN_PROFILE` controls context breadth. `CAVEMAN_MODE` controls reply voice. `CAVEMAN_COMPRESS_INPUT` controls input-side file compression. All three axes are orthogonal: setting one does not change the others, and none substitutes for another.
1755
+
1756
+ #### Activation gate (DEC-0073 §2)
1757
+
1758
+ All three conditions must hold before any mutation occurs:
1759
+
1760
+ 1. `CAVEMAN_COMPRESS_INPUT=1` in `.cursor/scratchpad.md`.
1761
+ 2. `CAVEMAN_FILE_SCOPE` non-empty.
1762
+ 3. CLI invoked with `--write`.
1763
+
1764
+ Any failing condition short-circuits with a reason code from §7 and exit `2`.
1765
+ Default / unset / partial state = no-op.
1766
+
1767
+ #### Sidecar originals (DEC-0073 §3)
1768
+
1769
+ Before mutating any file, the script writes the pre-mutation bytes to
1770
+ `docs/.caveman-originals/<relative/path>/<filename>`. Atomic order: sidecar
1771
+ first (temp + replace), then target (temp + replace). The tree is anchored
1772
+ by `docs/.caveman-originals/.gitkeep` and excluded from VCS by the repo-root
1773
+ `.gitignore` anchor for US-0090.
1774
+
1775
+ #### Deny-list policy (DEC-0073 §4)
1776
+
1777
+ Layered, read in this order (**deny always wins**):
1778
+
1779
+ 1. Hard-coded baseline in `scripts/caveman_compress_input.py` (`DENY_BASELINE`).
1780
+ 2. Merged secret-like patterns from repo-root `.gitignore` (`.env*`, `*secret*`,
1781
+ `*credential*`, `*token*`, `*private*`).
1782
+ 3. Optional `.cursorignore` overlay when
1783
+ `CAVEMAN_COMPRESS_INGEST_CURSORIGNORE=1` in scratchpad.
1784
+
1785
+ Deny-list baseline is versioned via `deny_list_version` (SHA-256 of sorted
1786
+ canonical JSON) and reported by `--report`.
1787
+
1788
+ #### Allow-list grammar (DEC-0073 §5)
1789
+
1790
+ Three forms in `CAVEMAN_FILE_SCOPE`:
1791
+
1792
+ | Form | Example | Notes |
1793
+ |------|---------|-------|
1794
+ | Named profile | `docs-prose-only` | Frozen v1 table; new profiles require subsequent DEC. |
1795
+ | Raw CSV globs | `docs/user-guides/**/*.md,handoffs/archive/*.md` | Forward slashes only. |
1796
+ | Hybrid | `profile:docs-prose-only;globs:handoffs/archive/*.md` | One profile per scope; unknown tokens fail closed. |
1797
+
1798
+ #### Safe-mode minifier (DEC-0073 §6)
1799
+
1800
+ Four-step, strictly idempotent pipeline:
1801
+
1802
+ 1. Collapse two-or-more consecutive blank lines into a single blank line
1803
+ (outside fenced code).
1804
+ 2. Trim trailing whitespace on non-fence lines.
1805
+ 3. Normalize `CRLF` / `CR` → `LF`.
1806
+ 4. Preserve the source file's EOF-newline status.
1807
+
1808
+ Aggressive mode is **deferred**; v1 ships safe-mode only. All safe-mode
1809
+ transformations keep the 9 DEC-0072 §4 literal regions byte-identical; any
1810
+ drift is fail-closed with `CAVEMAN_COMPRESS_LITERAL_REGION_DAMAGED`.
1811
+
1812
+ #### Reason-code vocabulary (DEC-0073 §7)
1813
+
1814
+ Nine codes in three families. No post-write codes.
1815
+
1816
+ | Family | Code |
1817
+ |--------|------|
1818
+ | Gating | `CAVEMAN_COMPRESS_MODE_DISABLED` |
1819
+ | Gating | `CAVEMAN_COMPRESS_FLAG_CONFLICT` |
1820
+ | Scope | `CAVEMAN_COMPRESS_SCOPE_EMPTY` |
1821
+ | Scope | `CAVEMAN_COMPRESS_SCOPE_UNKNOWN_PROFILE` |
1822
+ | Scope | `CAVEMAN_COMPRESS_SCOPE_VIOLATION` |
1823
+ | Integrity | `CAVEMAN_COMPRESS_DENY_HIT` |
1824
+ | Integrity | `CAVEMAN_COMPRESS_NOT_IDEMPOTENT` |
1825
+ | Integrity | `CAVEMAN_COMPRESS_LITERAL_REGION_DAMAGED` |
1826
+ | Integrity | `CAVEMAN_COMPRESS_ORIGINAL_MISSING` |
1827
+
1828
+ Additions require a subsequent DEC amending §7.
1829
+
1830
+ #### CLI contract (DEC-0073 §8)
1831
+
1832
+ | Flag | Semantics |
1833
+ |------|-----------|
1834
+ | `--dry-run` | (default) inventory + diff summary to stdout; no mutation. |
1835
+ | `--write` | Perform sidecar + target mutation on eligible files (sidecar first). |
1836
+ | `--verify-originals` | Walk sidecar tree; verify bidirectional presence; fail closed with `CAVEMAN_COMPRESS_ORIGINAL_MISSING` on orphan. |
1837
+ | `--report` | Emit canonical JSON report on stdout (incompatible with `--write`). |
1838
+
1839
+ #### Scratchpad keys (US-0090 additions)
1840
+
1841
+ | Key | Values | Default | Notes |
1842
+ |-----|--------|---------|-------|
1843
+ | `CAVEMAN_COMPRESS_INPUT` | `0` \| `1` | `0` | Activation gate bit (DEC-0073 §2). |
1844
+ | `CAVEMAN_FILE_SCOPE` | string | empty | Profile name, CSV globs, or hybrid (§5). |
1845
+ | `CAVEMAN_COMPRESS_INGEST_CURSORIGNORE` | `0` \| `1` | `0` | Optional overlay (§4). |
1846
+
1847
+ #### Template parity (DEC-0073 §10)
1848
+
1849
+ The following pairs are byte-identical between active and template copies and
1850
+ installer-owned (BUG-0003 / DEC-0066): `scripts/caveman_compress_input.py`,
1851
+ `docs/engineering/context/installer-owned-paths.manifest`,
1852
+ `docs/engineering/runbook.md`, `docs/engineering/auto-orchestration-reference.md`.
1853
+ Verify with `python scripts/check_intake_template_parity.py --scope=caveman-compress`.
1854
+ Negative parity (must NOT track): `.cursor/rules/caveman.mdc` (US-0089
1855
+ rule-set; US-0090 adds no new Cursor rule).
1856
+
1857
+ ### Outer-driver equivalence (AC-1, Option B)
1858
+
1859
+ When a single Cursor `/auto` invocation cannot schedule multiple subagent turns,
1860
+ operators may use an outer driver (script or manual re-invocation with
1861
+ `start-from` / refreshed `resume_brief`). This is deterministically equivalent
1862
+ when: same phase order, same isolation + strict-proof per phase, same stop
1863
+ reasons, same `resume_brief` + `state.md` refresh at every boundary.
1864
+
1865
+ ### Drain advance behavior
1866
+
1867
+ When `AUTO_BACKLOG_DRAIN=1` and a story reaches its terminal boundary:
1868
+
1869
+ 1. Orchestrator reloads merged scratchpad phase-selection inputs.
1870
+ 2. Orchestrator recomputes the materialized phase plan for the next story.
1871
+ 3. Selects the next eligible OPEN story per `AUTO_STORY_SELECTION`.
1872
+ 4. Runs the full resolved lifecycle for that story until stop or cap.
1873
+
1874
+ Notify operator on segment handoff (non-routine, non-suppressible).
1875
+
1876
+ ### Stop reasons
1877
+
1878
+ `completed`, `decision_gate`, `missing_input`, `pause_request`, `loop_max`,
1879
+ `error`, `blocked`. See the **Deterministic stop matrix** in
1880
+ **`docs/engineering/auto-orchestration-reference.md`** §
1881
+ **Continuous multi-phase execution (US-0088)**.
1882
+
1883
+ ### Troubleshooting
1884
+
1885
+ | Symptom | Likely cause | Fix |
1886
+ |---------|-------------|-----|
1887
+ | Run stops after one phase | Older `/auto` text without continuous semantics | Update to latest; verify **reference Step 5** anchor exists |
1888
+ | `RESUME_BRIEF_STALE` mid-run | Brief not refreshed at phase boundary | Ensure paired `resume_brief` + `state.md` refresh per DEC-0069 |
1889
+ | `AUTO_SCHEDULER_CONFLICT` | Both `AUTO_BACKLOG_DRAIN=1` and `AUTO_BUG_QUEUE=1` without `bug-target=` argv | Supply explicit `bug-target=` or disable one scheduler |
1890
+ | `BACKLOG_MAX_STORIES_REACHED` | Drain cap hit | Increase `AUTO_BACKLOG_MAX_STORIES` or run another `/auto` |
1891
+
1892
+ ### Downstream CI packaging job leak (BUG-0009 / DEC-0075)
1893
+
1894
+ **CI still runs its-magic packaging jobs?** Your project received a pre-fix workflow.
1895
+ Run **`its-magic --target <repo> --mode upgrade`** (or **`--mode clean`** then reinstall)
1896
+ to refresh `.github/workflows/ci.yml` from the corrected template. After upgrade, GitHub
1897
+ Actions should show only **`checks`** and **`auto-fix`** jobs — not `npm-test`,
1898
+ `brew-test`, or `choco-test`.
1899
+
1900
+ Scope reminder: fix applies to **new installs/upgrades**; stale repos heal on next upgrade
1901
+ (**US-0018**).
1902
+
1903
+ ## Explicit bulk sprint planning mode (US-0046)
1904
+
1905
+ `/sprint-plan` stays single-scope by default. Bulk planning is opt-in via
1906
+ explicit argument:
1907
+
1908
+ - `/sprint-plan --bulk`
1909
+
1910
+ Deterministic controls from `.cursor/scratchpad.md`:
1911
+ - `SPRINT_BULK_MAX_STORIES` (candidate OPEN stories per run)
1912
+ - `SPRINT_BULK_MAX_SPRINTS` (max generated sprints per run)
1913
+ - `SPRINT_BULK_SELECTION=priority_then_backlog_order`
1914
+
1915
+ Deterministic behavior:
1916
+ - Select eligible OPEN stories by configured selection order.
1917
+ - Generate one or more bounded sprint plans while preserving per-sprint sizing
1918
+ guardrails (`SPRINT_MAX_TASKS`, `SPRINT_AUTO_SPLIT`).
1919
+ - Stop with explicit reason codes when bounded or blocked:
1920
+ - `SPRINT_BULK_MAX_STORIES_REACHED`
1921
+ - `SPRINT_BULK_MAX_SPRINTS_REACHED`
1922
+ - `SPRINT_BULK_NO_ELIGIBLE_STORIES`
1923
+ - `SPRINT_BULK_MISSING_ACCEPTANCE`
1924
+
1925
+ ## Explicit bulk execute mode (US-0047)
1926
+
1927
+ `/auto` remains non-bulk by default. Bulk execution is explicit and can be
1928
+ enabled per run (`/auto --execute-bulk`) or by scratchpad switch.
1929
+
1930
+ Deterministic controls:
1931
+ - `AUTO_EXECUTE_BULK=0|1` (default `0`)
1932
+ - `AUTO_EXECUTE_MAX_ITEMS=<n>` (default `1`)
1933
+ - `AUTO_EXECUTE_ON_BLOCK=stop|skip` (default `stop`)
1934
+ - `AUTO_EXECUTE_SELECTION=planned_then_priority` (default)
1935
+ - `AUTO_TEAM_SCOPE_ENFORCE=0|1` (default `1`)
1936
+
1937
+ Execution semantics:
1938
+ - Select eligible planned items deterministically.
1939
+ - Preserve strict isolation:
1940
+ - fresh subagent per phase
1941
+ - fresh subagent per execute<->QA loop cycle
1942
+ - Enforce bounded stop behavior:
1943
+ - `EXEC_BULK_MAX_ITEMS_REACHED`
1944
+ - `EXEC_BULK_NO_ELIGIBLE_ITEMS`
1945
+ - `EXEC_BULK_ITEM_BLOCKED_STOP`
1946
+ - `EXEC_BULK_ITEM_BLOCKED_SKIPPED`
1947
+
1948
+ Team mode guardrails (`TEAM_MODE=1`):
1949
+ - Capture team context snapshot in breadcrumbs:
1950
+ - `TEAM_MODE`, `TEAM_MEMBER`, `ACTIVE_TASK_IDS`
1951
+ - With enforcement enabled, out-of-scope tasks are never mutated and must emit:
1952
+ - `EXEC_TEAM_SCOPE_BLOCKED` (stop policy)
1953
+ - `EXEC_TEAM_SCOPE_SKIPPED` (skip policy)
1954
+
1955
+ ## Sync policy and guarded auto-push contract (US-0038 / DEC-0018)
1956
+
1957
+ Sync policy controls (from `.cursor/scratchpad.md`):
1958
+ - `SYNC_POLICY_MODE`: `disabled|manual|by_phase|by_milestone|custom_phase_list`
1959
+ - `SYNC_CUSTOM_PHASES`: comma-separated canonical phase IDs for custom mode
1960
+ - `ALLOW_AUTO_PUSH`: `0|1`
1961
+ - `AUTO_PUSH_BRANCH_ALLOWLIST`: comma-separated branches/patterns
1962
+
1963
+ Default-safe behavior:
1964
+ - Default mode is `manual` (non-auto).
1965
+ - `disabled` and `manual` are near-zero-overhead modes (no auto-push attempts).
1966
+ - Unset/invalid mode fails closed to `manual`.
1967
+
1968
+ Phase-boundary-only evaluation:
1969
+ - Evaluate sync eligibility only at completed phase boundaries.
1970
+ - Never evaluate during partial or in-progress work units.
1971
+
1972
+ Guarded auto-push eligibility (all required):
1973
+ 1. Boundary trigger is eligible for current mode.
1974
+ 2. `ALLOW_AUTO_PUSH=1`.
1975
+ 3. QA-first restriction passes (feature work cannot auto-push before QA pass).
1976
+ 4. No unresolved blocking QA findings / unresolved critical issues.
1977
+ 5. Branch safety passes:
1978
+ - protected/default branches denied by default,
1979
+ - allow only explicitly allowlisted branches.
1980
+ 6. Mandatory check chain passes.
1981
+
1982
+ Mandatory pre-push check chain:
1983
+ 1. `TEST_COMMAND` (mandatory baseline)
1984
+ 2. `LINT_COMMAND` (only if configured)
1985
+ 3. `TYPECHECK_COMMAND` (only if configured)
1986
+
1987
+ Rules:
1988
+ - Missing `TEST_COMMAND` blocks push (`TEST_COMMAND_MISSING`).
1989
+ - Failing `TEST_COMMAND` blocks push (`TEST_FAILED`).
1990
+ - Timed-out `TEST_COMMAND` blocks push (`TEST_TIMEOUT`).
1991
+ - Optional check failures block push when configured (`OPTIONAL_CHECK_FAILED`).
1992
+ - Optional checks that are not configured must be reported as `skipped`.
1993
+
1994
+ Deterministic reason-code baseline:
1995
+ - `SYNC_DISABLED`
1996
+ - `MANUAL_MODE_NO_AUTO`
1997
+ - `SYNC_TRIGGER_NOT_ELIGIBLE`
1998
+ - `AUTO_PUSH_NOT_ENABLED`
1999
+ - `PRE_QA_AUTOPUSH_FORBIDDEN`
2000
+ - `BLOCKING_QA_FINDINGS`
2001
+ - `BRANCH_NOT_ALLOWLISTED`
2002
+ - `TEST_COMMAND_MISSING`
2003
+ - `TEST_FAILED`
2004
+ - `TEST_TIMEOUT`
2005
+ - `OPTIONAL_CHECK_FAILED`
2006
+ - `SYNC_PUSHED`
2007
+
2008
+ ## Executable validate-and-push wiring (DEC-0058)
2009
+
2010
+ Scratchpad **`SYNC_*` / `ALLOW_AUTO_PUSH` / `AUTO_PUSH_BRANCH_ALLOWLIST`** are read from the
2011
+ **merged** scratchpad only (installer merge: local → materialized baseline → example; same
2012
+ precedence as installer post-install validation). **`scripts/validate-and-push.ps1`** and
2013
+ **`scripts/validate-and-push.sh`** call **`python scripts/sync_push_gates.py`** for policy;
2014
+ **`docs/engineering/runbook.md`** remains the sole source for **`TEST_COMMAND`** and optional
2015
+ lint/typecheck commands.
2016
+
2017
+ **Operator rule:** changing scratchpad alone does **not** run **`git push`**. Run
2018
+ **`validate-and-push`** (or CI) after an eligible boundary. For **`by_phase`**, **`by_milestone`**,
2019
+ and **`custom_phase_list`**, scheduling is **operator or CI** responsibility.
2020
+
2021
+ **`SYNC_PHASE_BOUNDARY`:** optional environment variable (canonical phase id, case-insensitive).
2022
+ When **`SYNC_POLICY_MODE=custom_phase_list`**, the variable must be set and must appear in
2023
+ **`SYNC_CUSTOM_PHASES`** (comma-separated) or the script exits **`SYNC_TRIGGER_NOT_ELIGIBLE`**.
2024
+
2025
+ **Dry-run:** **`powershell .../validate-and-push.ps1 -DryRun`** or
2026
+ **`bash scripts/validate-and-push.sh --dry-run ...`** — runs merge/policy and the runbook check
2027
+ chain, then prints **`SYNC_PUSHED`** without **`git push`**.
2028
+
2029
+ **Branch allowlist matching (`AUTO_PUSH_BRANCH_ALLOWLIST`):** comma-separated entries; each entry
2030
+ is either an exact branch name or a **`fnmatch`** pattern (for example `release/*`). An empty
2031
+ allowlist denies every branch (**`BRANCH_NOT_ALLOWLISTED`**).
2032
+
2033
+ **QA scan (bounded):** files under **`sprints/S####/qa-findings.md`** (four digits). Blocking
2034
+ rules match **`DEC-0058`** §6. **`PRE_QA_AUTOPUSH_FORBIDDEN`** applies on branches other than
2035
+ **`main`** / **`master`** when **no** such **`qa-findings.md`** file exists yet (feature-line
2036
+ signal; see architecture **US-0076**).
2037
+
2038
+ **Python:** merged policy evaluation requires **Python 3** on **`PATH`** (**`PYTHON_NOT_ON_PATH`**
2039
+ if missing).
2040
+
2041
+ Required sync evidence fields:
2042
+ - `phase_boundary`
2043
+ - `policy_mode`
2044
+ - `trigger_source` (`manual|auto`)
2045
+ - `branch`
2046
+ - `checks` (`test|lint|typecheck`: `pass|fail|skipped`)
2047
+ - `qa_status_snapshot`
2048
+ - `push_decision` (`pushed|blocked|not_eligible`)
2049
+ - `reason_code`
2050
+ - `evidence_refs`
2051
+
2052
+ ## Release gate chain (US-0039 / DEC-0019)
2053
+
2054
+ Deterministic mandatory gate order; no step may be skipped or reordered:
2055
+
2056
+ 1. **Check-in test gate** — Latest `TEST_COMMAND` evidence must be present and passing.
2057
+ 2. **QA completion gate** — No unresolved blocking findings in sprint QA context.
2058
+ 3. **UAT completion gate** — UAT artifacts populated and verified; no placeholder or unresolved-fail state.
2059
+ 4. **Isolation compliance gate** — Per-phase isolation evidence present and valid (US-0048 / DEC-0029).
2060
+ 5. **Release finalization** — Notes, queue, backlog/runbook/state updates only after gates 1–4 pass.
2061
+
2062
+ Default: no bypass. Override only via explicit decision gate with rationale and evidence (DEC-0019).
2063
+
2064
+ **Optional-command compatibility (US-0039 / AC-10)**: Blank optional runbook keys (`LINT_COMMAND`, `TYPECHECK_COMMAND`) must not cause release to fail. Mandatory gates are check-in test + QA + UAT + isolation only; optional checks run only when configured and are reported as `skipped` when not configured. Release does not require lint/typecheck evidence when those keys are blank.
2065
+
2066
+ **Per-gate audit verdict schema (US-0039)** — For TL/QA auditability, record per gate:
2067
+
2068
+ - `gate` (check-in_test | qa | uat | isolation | finalization)
2069
+ - `verdict` (pass | fail | override)
2070
+ - `reason_code` (e.g. RELEASE_TEST_FAILED, RELEASE_QA_BLOCKERS_OPEN, RELEASE_UAT_INCOMPLETE, RELEASE_GATE_OVERRIDE_APPROVED)
2071
+ - `remediation` (short remediation steps when fail/override)
2072
+ - `evidence_refs` (paths to tests/report.md, qa-findings.md, uat.json, release-findings.md, DEC-xxxx as applicable)
2073
+
2074
+ Record in `sprints/Sxxxx/release-findings.md` and/or `handoffs/release_queue.md` `gate_snapshot`; state checkpoint in `docs/engineering/state.md` may reference the same.
2075
+
2076
+ ## Release queue and sprint notes contract (US-0040 / DEC-0020)
2077
+
2078
+ Canonical release artifacts:
2079
+ - `handoffs/releases/Sxxxx-release-notes.md` (canonical per-sprint notes)
2080
+ - `handoffs/release_queue.md` (canonical queue tracker)
2081
+ - `handoffs/release_notes.md` (legacy-compatible latest pointer/summary)
2082
+
2083
+ Queue row required fields:
2084
+ - `sprint_id`
2085
+ - `story_refs`
2086
+ - `status` (`planned|ready|unreleased|released|blocked`)
2087
+ - `last_updated`
2088
+ - `release_notes_ref`
2089
+ - `gate_snapshot`
2090
+ - `release_version` (optional before finalization)
2091
+
2092
+ Deterministic transition semantics:
2093
+ - target sprint only may change during one `/release` run
2094
+ - entering release flow sets target row to `unreleased`
2095
+ - successful finalization transitions same row to `released`
2096
+ - no non-target sprint row mutation
2097
+
2098
+ Fail-safe reason codes:
2099
+ - `RELEASE_SPRINT_UNRESOLVED`
2100
+ - `LEGACY_NOTES_SPRINT_UNRESOLVED`
2101
+ - `QUEUE_ENTRY_MISSING`
2102
+ - `NOTES_REF_MISSING`
2103
+ - `STATUS_TRANSITION_INVALID`
2104
+
2105
+ Mismatch and unresolved-sprint policy:
2106
+ - fail closed for finalization when sprint identity or queue/notes metadata is
2107
+ inconsistent
2108
+ - preserve existing notes artifacts by default (non-destructive)
2109
+ - do not auto-reconcile by deleting/rebuilding unrelated sprint history
2110
+ - include remediation steps in queue/state and rerun `/release` after correction
2111
+
2112
+ ## Post-QA release issue workflow (US-0042)
2113
+
2114
+ When `/release` finds a blocker after QA has passed, document it in a dedicated
2115
+ release findings artifact (separate from QA findings):
2116
+
2117
+ - Canonical artifact: `sprints/Sxxxx/release-findings.md`
2118
+ - Canonical handoff back to implementation: `handoffs/release_to_dev.md`
2119
+
2120
+ Required release-findings content:
2121
+ - gate status (`PASS|BLOCKED`)
2122
+ - blocking and non-blocking findings
2123
+ - deterministic reason code(s)
2124
+ - evidence refs
2125
+ - remediation steps and rerun criteria
2126
+
2127
+ Boundary rule:
2128
+ - QA-phase defects remain in `sprints/Sxxxx/qa-findings.md`.
2129
+ - Post-QA release-gate defects must be recorded in
2130
+ `sprints/Sxxxx/release-findings.md`.
2131
+
2132
+ ## Backlog reconciliation invariant (US-0043)
2133
+
2134
+ At release finalization boundary, target sprint stories must be synchronized in
2135
+ `docs/product/backlog.md` using canonical release evidence precedence.
2136
+
2137
+ Contract:
2138
+ - Scope is target sprint stories only (no global backlog mutation).
2139
+ - If release evidence is PASS, set story status to `DONE` and reconcile
2140
+ acceptance checkboxes to checked state.
2141
+ - If sprint is `released` but backlog story state remains contradictory
2142
+ (`OPEN`/unchecked), fail safe with reason code `BACKLOG_STATUS_DRIFT`.
2143
+ - Record remediation guidance and evidence refs in release artifacts before rerun.
2144
+
2145
+ ## Canonical status ownership and normalization guard (US-0045)
2146
+
2147
+ Canonical owner:
2148
+ - `docs/product/backlog.md` is the authority for story status (`OPEN|DONE`).
2149
+ - `docs/product/acceptance.md` and `docs/engineering/state.md` are derived views.
2150
+
2151
+ Deterministic reconciliation rules:
2152
+ 1. Read canonical story status from backlog.
2153
+ 2. Validate target sprint release evidence for status transitions.
2154
+ 3. Reconcile derived acceptance/state views from canonical backlog status.
2155
+ 4. Keep mutation scope target-scoped only; never broad-rewrite unrelated stories.
2156
+
2157
+ One-time normalization procedure:
2158
+ - Run an initial normalization pass for historically drifted stories.
2159
+ - Write all changed rows to `docs/engineering/status-normalization-report.md`
2160
+ including prior values, resolved values, evidence references, and timestamp.
2161
+ - On future runs, append only delta entries; do not rewrite historical report rows.
2162
+
2163
+ Fail-safe reason codes:
2164
+ - `BACKLOG_STATUS_DRIFT`: release evidence contradicts backlog/AC state.
2165
+ - `CANONICAL_STATUS_CONFLICT`: canonical backlog state conflicts with derived
2166
+ status resolution at reconciliation boundary.
2167
+
2168
+ ## Lifecycle QA matrix (US-0041)
2169
+
2170
+ Use this matrix to validate end-to-end installer/CLI lifecycle behavior:
2171
+
2172
+ | Scenario | Primary command path | Coverage location | Required evidence |
2173
+ |---|---|---|---|
2174
+ | Fresh install (`missing`) | `its-magic --mode missing --create` and direct installer | `tests/run-tests.ps1`, `tests/run-tests.sh` | Required files exist + `its_magic/.its-magic-version` exists |
2175
+ | Overwrite + backup | `its-magic --mode overwrite --backup` and direct installer | `tests/run-tests.ps1`, `tests/run-tests.sh` | Backup snapshot contains overwritten framework file |
2176
+ | Upgrade lifecycle | `its-magic --mode upgrade` and direct installer | `tests/run-tests.ps1`, `tests/run-tests.sh`, npm local tests | Framework file restored, scratchpad example refreshed, user local scratchpad preserved |
2177
+ | Clean-repo safety | `its-magic --clean-repo --yes` and direct installer clean path | `tests/run-tests.ps1`, `tests/run-tests.sh`, CI lifecycle subset | Framework artifacts removed, non-framework marker preserved |
2178
+ | Negative path | invalid mode/args | `tests/run-tests.ps1`, `tests/run-tests.sh` | Deterministic non-zero fail-fast behavior |
2179
+ | Platform parity subset | npm/brew/choco CI jobs | `.github/workflows/ci.yml` | Lifecycle subset passes on all three runners |
2180
+
2181
+ ## Scratchpad example upgrade contract (US-0057 / DEC-0039 / DEC-0057)
2182
+
2183
+ `its-magic --mode upgrade` treats `.cursor/scratchpad.local.example.md` as
2184
+ framework-owned and `.cursor/scratchpad.local.md` as user-owned.
2185
+
2186
+ Expected deterministic outcome:
2187
+ - Framework-owned example is refreshed to latest release contract **before** baseline
2188
+ materialization runs in `installer.py --scratchpad-postinstall` (**DEC-0057** ordering).
2189
+ - User local scratchpad remains preserved without overwrite.
2190
+ - Installer output reports manifest copy status for the example file where applicable
2191
+ (`added|updated|unchanged`) **and** `[SCRATCHPAD_LAYER]` diagnostics from post-install
2192
+ (`example_refresh`, `baseline_materialize` / `baseline_skip`, `user_local` preserved).
2193
+ - CI regression: `python scripts/check-scratchpad-pair-parity.py --repo <root>` exit `0`
2194
+ when active and `template/` baseline/example pairs share the same automation `KEY=`
2195
+ set and catalog `#` headers from `# Core behavior` (**US-0075** **AC-11**).
2196
+
2197
+ ## Scratchpad delivery Model B (US-0073 / DEC-0055)
2198
+
2199
+ - Install manifest ships `.cursor/scratchpad.local.example.md` (framework catalog)
2200
+ but **does not** list `.cursor/scratchpad.md` as a copied file. The installer
2201
+ **materializes** `.cursor/scratchpad.md` from the packaged template when absent
2202
+ (`missing`, `interactive`, `upgrade`) or refreshes it on `overwrite`.
2203
+ - Merge precedence for automation readers: **local > materialized baseline > example**
2204
+ (same invariant as `DEC-0055`).
2205
+ - Post-install validation fails closed with `[SCRATCHPAD_MERGE_ERROR]` /
2206
+ `[SCRATCHPAD_MATERIALIZE_ERROR]` when layers are missing or required keys are
2207
+ empty after merge (`US-0073` `AC-4`).
2208
+ - `installer.ps1` / `installer.sh` delegate materialize+validate to
2209
+ `python installer.py --scratchpad-postinstall` (Python 3 required on PATH).
2210
+ - Recovery: `python installer.py --scratchpad-postinstall --target <repo> --mode missing`
2211
+ (or re-run a full install).
2212
+
2213
+ ## Deterministic artifact ordering and write discipline (US-0058 / DEC-0040)
2214
+
2215
+ Canonical policy source:
2216
+ - `docs/engineering/artifact-ordering-policy.md`
2217
+
2218
+ Required write discipline:
2219
+ - `docs/engineering/state.md`: append-bottom checkpoint writes only.
2220
+ - `docs/product/backlog.md`: sorted-canonical story ordering by numeric `US-xxxx`.
2221
+ - `docs/product/acceptance.md`: sorted-canonical row ordering aligned to backlog.
2222
+ - Handoff surfaces use explicit policy (`prepend-top` or `append-bottom`) per
2223
+ matrix and command contract.
2224
+
2225
+ Fail-safe contract:
2226
+ - Missing/ambiguous placement anchors fail closed with
2227
+ `ARTIFACT_ORDERING_ANCHOR_AMBIGUOUS`.
2228
+ - Non-monotonic `state.md` checkpoint timestamps fail closed with
2229
+ `STATE_TIMESTAMP_NON_MONOTONIC`.
2230
+ - No partial mutation on fail-safe path.
2231
+ - Re-run without semantic changes must be ordering-idempotent.
2232
+
2233
+ ## Cross-phase artifact ownership guard (US-0061 / DEC-0043)
2234
+
2235
+ Canonical policy source:
2236
+ - `docs/engineering/artifact-ownership-policy.md`
2237
+
2238
+ Required ownership discipline:
2239
+ - Each phase may mutate only its declared owned scopes for target context.
2240
+ - Cross-phase non-owned section rewrite/deletion is forbidden by default.
2241
+ - `docs/engineering/architecture.md` is history-preserving: append new story
2242
+ sections or mutate target section only; unrelated story-section deletion is
2243
+ prohibited.
2244
+
2245
+ Fail-safe contract:
2246
+ - Ownership violations fail closed with `PHASE_OWNERSHIP_VIOLATION`.
2247
+ - Missing evidence on override-authorized mutation path fails closed with
2248
+ `PHASE_OVERRIDE_EVIDENCE_MISSING`.
2249
+ - Architecture history deletion detection fails with
2250
+ `ARCH_HISTORY_DELETION_DETECTED`.
2251
+ - No partial mutation on fail-safe path.
2252
+
2253
+ Execution guidance:
2254
+ - Local baseline: run `sh tests/run-tests.sh` (or `powershell -ExecutionPolicy Bypass -File tests/run-tests.ps1`).
2255
+ - Packaging smoke: run npm local tests in `packaging/npm/`.
2256
+ - CI evidence: inspect `npm-test`, `brew-test`, and `choco-test` job logs.
2257
+
2258
+ ## Intake runtime capability and single-writer safety (US-0059 / DEC-0041)
2259
+
2260
+ `/intake` enforces deterministic runtime preflight and drift safety before
2261
+ artifact mutation.
2262
+
2263
+ Capability preflight:
2264
+ - Required role capability: `po` subagent.
2265
+ - Default policy: fail fast when unavailable with
2266
+ `SUBAGENT_CAPABILITY_UNAVAILABLE`.
2267
+ - Fallback policy is explicit only:
2268
+ - `INTAKE_SUBAGENT_FALLBACK=deny` (default): no silent fallback.
2269
+ - `INTAKE_SUBAGENT_FALLBACK=allow`: explicit operator opt-in for fallback path.
2270
+
2271
+ Single-writer drift safety:
2272
+ - Intake run binds a deterministic writer/run identity (`writer_id`,
2273
+ `intake_run_id`) to target artifacts.
2274
+ - Self-write updates for the active writer/run are valid and must not trigger
2275
+ concurrent drift blockers.
2276
+ - External concurrent conflicting writes fail safe with
2277
+ `INTAKE_CONCURRENT_WRITER_DETECTED`.
2278
+ - Fail-safe path performs no partial overwrite.
2279
+
2280
+ ## Post-release operator commands (S0070 / BUG-0008 — released `2026-04-05`)
2281
+
2282
+ **S0070** **`released`**; **`BUG-0008`** **DONE** in canonical backlog. In-repo version **`its-magic@0.1.2-41`**. **`/release`** skipped registry publish while **`RELEASE_PUBLISH_MODE=disabled`** — operators still run the steps below when pushing to npm or validating on Debian.
2283
+
2284
+ - **Tests (canonical):** `powershell -ExecutionPolicy Bypass -File "tests/run-tests.ps1"` — refresh **`tests/report.md`**; release gate used **793**/0 @ **2026-04-05T20:21:40Z** with **US-0071** harness rows **PASS**.
2285
+ - **Prepublish:** `npm run prepublishOnly` (runs **`guard:installer`**).
2286
+ - **Publish:** `npm publish` — set **`RELEASE_PUBLISH_MODE`** to **`confirm`** or **`auto`** when ready; no inline registry secrets in docs.
2287
+ - **Debian global E2E (optional follow-up):** **`DEFERRED_DEBIAN_E2E_NO_RUNTIME`** was waived for the release cycle — when a Debian/SSH target exists (**US-0086**), run `npm install -g its-magic@0.1.2-41` (or equivalent), `cat -A` on installed `template/docs/engineering/context/installer-owned-paths.manifest` (no `^M$`), then `its-magic --target <repo> --mode missing` without `[INSTALL_MANIFEST_ERROR]`.
2288
+
2289
+ ## Operator `.env` setup (US-0085 / DEC-0071)
2290
+
2291
+ ### Quick start
2292
+
2293
+ 1. Copy the committed template: `cp .env.example .env`
2294
+ 2. Fill in values for each variable relevant to your environment.
2295
+ 3. Source before remote, SSH, or release operations:
2296
+ - **Bash/Zsh**: `source .env` or `set -a; source .env; set +a`
2297
+ - **PowerShell**: `Get-Content .env | ForEach-Object { if ($_ -match '^([^#]\S+?)=(.*)$') { [Environment]::SetEnvironmentVariable($Matches[1], $Matches[2], 'Process') } }`
2298
+ 4. Run `python scripts/print_remote_env_hint.py` to verify parity between
2299
+ `.env.example` and the `*Env` fields in JSON configs.
2300
+
2301
+ ### Forbidden
2302
+
2303
+ - **Committing `.env`**: `.env` is gitignored; never add it to version control.
2304
+ - **Agents reading `.env`**: AI agents must not open, attach, read, search
2305
+ inside, or index `.env` or `.env.*` files (enforced via `.cursorignore` and
2306
+ Cursor rules). Use env var **names** in prose only.
2307
+
2308
+ ### Allowed
2309
+
2310
+ - Running `ssh`, `docker`, `python scripts/remote_config_summary.py` after
2311
+ sourcing `.env` — the process inherits normal environment variables.
2312
+ - Referencing env var **names** (not values) in documentation and handoffs.
2313
+
2314
+ ## Project run steps
2315
+
2316
+ ### Prerequisites
2317
+
2318
+ ### Local run
2319
+
2320
+ ### Tests