its-magic 0.1.2-39 → 0.1.2-42

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.
@@ -1,1525 +1,1772 @@
1
- # Runbook
2
-
3
- ## Commands
4
-
5
- TEST_COMMAND:
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
- ## User-visible internal metadata guard (US-0071 / DEC-0053)
129
-
130
- **Goal:** keep planning-shaped identifiers out of **operator-visible software
131
- channels** (CLI/installer/validate-and-push strings), while they remain valid in
132
- internal documentation trees and in source comments that are not emitted to
133
- users.
134
-
135
- ### Forbidden tokens (user-visible channels only)
136
-
137
- Match planning-shaped tokens:
138
-
139
- - `US-[0-9]{4}`
140
- - `DEC-[0-9]{4}`
141
- - `R-[0-9]{4}`
142
-
143
- ### Inclusive scan roots (deterministic)
144
-
145
- From repository root, the checker walks **only**:
146
-
147
- - `bin/**` (`*.js`)
148
- - `installer.py`, `installer.ps1`, `installer.sh`
149
- - `packaging/**` (`*.js`, `*.py`, `*.ps1`, `*.sh`)
150
- - `scripts/validate-and-push.ps1`, `scripts/validate-and-push.sh`
151
-
152
- Paths outside this set are **not** scanned by this tool (for example `docs/**`,
153
- `.cursor/**`, `sprints/**`, `handoffs/**`, `decisions/**` remain free to use
154
- story/decision/research IDs). If a new operator-visible deliverable is added
155
- outside these roots, extend the scan list or you risk
156
- `METADATA_SANITIZATION_SCOPE_AMBIGUOUS` classification during review.
157
-
158
- ### Command
159
-
160
- ```bash
161
- python scripts/check-user-visible-metadata.py
162
- python scripts/check-user-visible-metadata.py --json
163
- ```
164
-
165
- ### Reason codes (minimum)
166
-
167
- - `USER_VISIBLE_INTERNAL_METADATA_DETECTED` — forbidden token matched inside a
168
- scanned user-visible string/literal.
169
- - `METADATA_SANITIZATION_POLICY_MISSING` — checker entrypoint missing or
170
- unusable.
171
- - `METADATA_SANITIZATION_SCOPE_AMBIGUOUS` — cannot classify whether a path
172
- belongs in inclusive scan roots; treat as fail-closed until the runbook table
173
- is updated.
174
-
175
- ### Findings / remediation (contract)
176
-
177
- On failure, diagnostics must cite **evidence_ref** (`path:line:column` when
178
- available), **token class** (`US` \| `DEC` \| `R`), and remediation: remove the
179
- token from operator-visible strings; keep traceability in allowlisted internal
180
- artifacts or non-emitting comments per `DEC-0053`.
181
-
182
- ## Guided intake mode (US-0033)
183
-
184
- Intake interaction behavior is controlled by one switch in
185
- `.cursor/scratchpad.md`:
186
-
187
- - `INTAKE_GUIDED_MODE=1` (default): guided PO behavior
188
- - targeted follow-up questions only when acceptance is ambiguous
189
- - at least one viable option/alternative before recommendation
190
- - explicit user decision authority
191
- - intake-time research persisted in `docs/engineering/research.md`
192
- - `INTAKE_GUIDED_MODE=0`: low-touch intake
193
- - no proactive follow-up/options/research overhead unless user asks
194
- - duplicate/overlap backlog check remains mandatory baseline safety
195
-
196
- ## Intake decomposition and risk-aware questioning (US-0051)
197
-
198
- When guided mode is enabled (`INTAKE_GUIDED_MODE=1`), intake adds bounded
199
- decomposition and adaptive questioning behavior:
200
-
201
- - Run deterministic breadth/risk heuristics before persisting a story:
202
- - feature/workflow-step count
203
- - cross-cutting impact surface
204
- - acceptance breadth
205
- - risk/unknown dependency surface
206
- - If heuristics indicate broad/high-risk intake:
207
- - propose bounded multi-story decomposition (typically 2-5 stories)
208
- - prefer vertical-slice/workflow-step stories with independent user value
209
- - avoid technical-layer-only splits unless user explicitly requests
210
- - Preserve user authority explicitly before persistence:
211
- - user can accept, merge, or adjust the proposed split
212
- - Keep adaptive questioning concise and bounded:
213
- - ask ambiguity-driven questions plus risk-triggered questions
214
- - stop after bounded rounds or when acceptance confidence is sufficient
215
- - Low-touch compatibility (`INTAKE_GUIDED_MODE=0`):
216
- - no forced decomposition
217
- - single-story default unless user explicitly asks for decomposition
218
- - duplicate/overlap safety remains mandatory
219
- - Traceability requirement:
220
- - intake output must capture decomposition/questioning evidence in
221
- `docs/product/backlog.md`, `docs/product/acceptance.md`, and
222
- `handoffs/po_to_tl.md`.
223
-
224
- ## Mandatory intake question packs and persistence coverage gate (US-0068 / DEC-0050)
225
-
226
- Intake persistence is fail-closed unless required topic coverage is complete (or
227
- bounded assumptions are explicitly confirmed).
228
-
229
- Deterministic pack contract:
230
-
231
- - `first-intake-pack` (first/new/broad intake)
232
- - required topics:
233
- - `users_problem`
234
- - `runtime_target_environment`
235
- - `language_framework_runtime`
236
- - `architecture_preference`
237
- - `ui_design_expectations`
238
- - `security_compliance`
239
- - `non_functional_priorities`
240
- - `scope_timeline`
241
- - `small-intake-pack` (small follow-up intake)
242
- - required topics:
243
- - `outcome_success_criteria`
244
- - `impacted_components`
245
- - `constraints_compatibility_risks`
246
- - `required_tests_acceptance_checks`
247
- - `done_definition`
248
-
249
- Pack selection and coverage behavior:
250
-
251
- - Select exactly one pack per intake write path.
252
- - Unknown/ambiguous stack or project cues must fail closed to
253
- `first-intake-pack`.
254
- - Required coverage must be evaluated before writing
255
- `docs/product/backlog.md` or `docs/product/acceptance.md`.
256
- - Incomplete required coverage blocks persistence unless assumptions are
257
- explicitly confirmed.
258
-
259
- Deterministic fail-closed reason codes:
260
-
261
- - `INTAKE_REQUIRED_TOPIC_MISSING`
262
- - `INTAKE_REQUIRED_PACK_INCOMPLETE`
263
- - `INTAKE_ASSUMPTION_CONFIRMATION_REQUIRED`
264
- - `INTAKE_PERSISTENCE_BLOCKED`
265
-
266
- Required remediation output on block:
267
-
268
- - include `missing_topics`
269
- - provide targeted follow-up prompts for missing required topics
270
- - request explicit assumption confirmation when assumptions are used
271
-
272
- Required persisted intake evidence fields:
273
-
274
- - `asked_topics`
275
- - `missing_topics`
276
- - `assumptions_confirmed`
277
-
278
- ## First-intake full-plan coverage gate (US-0081 / DEC-0064)
279
-
280
- For first/new/broad intake (`selected_pack=first-intake-pack`), persistence is
281
- additionally blocked unless complete-plan coverage is machine-verifiable.
282
-
283
- Required coverage contract fields:
284
-
285
- - `plan_area_inventory[]` with unique stable `plan_area_id` values
286
- - `plan_area_coverage[]` with exactly one row per `plan_area_id`
287
- - xor mapping per row: `story_ids[]` or `deferred_ref` + `deferred_reason`
288
- - `coverage_complete=true` only when derived validation succeeds
289
-
290
- Coverage diagnostics (under umbrella `INTAKE_PERSISTENCE_BLOCKED`):
291
-
292
- - `INTAKE_PLAN_COVERAGE_MISSING`
293
- - `INTAKE_PLAN_AREA_ID_INVALID`
294
- - `INTAKE_PLAN_COVERAGE_CONTRACT_INVALID`
295
- - `INTAKE_PLAN_DEFERRED_REF_MISSING`
296
-
297
- Guided and low-touch parity:
298
-
299
- - `INTAKE_GUIDED_MODE=1` and `INTAKE_GUIDED_MODE=0` must run the same
300
- first-intake complete-plan validator path.
301
- - Low-touch may reduce optional prompts but cannot bypass complete-plan coverage
302
- validation.
303
-
304
- ## Interactive intake evidence validation (US-0078 / DEC-0060 / US-0083 / DEC-0067)
305
-
306
- **US-0078** adds machine-verifiable **`topic_coverage`** rows, canonical **`ie:`** refs
307
- (**DEC-0060**), asked-vs-covered enforcement, and **`assumption_confirmation_ref`**
308
- binding before backlog/acceptance writes.
309
-
310
- - Validator entrypoints: `python scripts/intake_evidence_validate.py --self-test`;
311
- `python scripts/intake_evidence_validate.py --file <bundle.json>` or `--stdin`.
312
- - Library: `scripts/intake_evidence_lib.py` (shared rules for tests and tooling).
313
- - Regression: `tests/intake_evidence_fixtures_test.py` (R-0055 **AC-8** matrix tiers A/B),
314
- invoked from `tests/run-tests.ps1` / `tests/run-tests.sh` §26k.
315
- - **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).
316
- - **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).
317
- - **Guided** and **low-touch** (`INTAKE_GUIDED_MODE=0`) share the **same** pre-persistence
318
- validation pipeline; mandatory pack evidence is never skipped.
319
- - Legacy intake evidence without **`ie:`** refs remains **grandfathered** for display until the
320
- next intake-driven mutation, which must supply full evidence (**DEC-0060** §5).
321
- - **Delegated required-topic path (US-0083 / DEC-0067)**:
322
- - Allowed: `topic_coverage[].satisfied_by=delegation_ref` with required
323
- `delegation_scope`, `delegation_rationale`, `delegation_confidence` (`low|medium|high`).
324
- - Missing delegation fields fail closed with `INTAKE_DELEGATION_EVIDENCE_MISSING`.
325
- - Malformed delegation values or invalid `ie:` binding fail closed with
326
- `INTAKE_DELEGATION_EVIDENCE_INVALID`.
327
- - Non-delegated unresolved required topics remain unchanged fail-closed
328
- (`INTAKE_REQUIRED_TOPIC_MISSING` path).
329
- - **Repetitive-ask suppression with accounting (US-0083 AC-1)**:
330
- - When equivalent evidence already exists, avoid re-asking by recording row-level
331
- `evidence_source=equivalent_evidence_ref` plus `equivalent_evidence_ref`.
332
- - Required-topic accounting remains explicit through `topic_coverage` rows.
333
-
334
- ## Bug issues (US-0079 / DEC-0061)
335
-
336
- - **Canonical ids**: **`BUG-####`** in **`docs/product/backlog.md`** **`## Bug issues (canonical)`**; status literals **`OPEN`** | **`DONE`** only — illegal values fail **`BUG_VALIDATION_STATUS_INVALID`**.
337
- - **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).
338
- - **Ordering**: bug blocks sorted by id ascending — violation → **`BUG_VALIDATION_ORDER_INVERSION`**.
339
- - **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).
340
- - **Acceptance reconciliation**: **`docs/product/acceptance.md`** **`## Bug acceptance (canonical)`** checkbox rows must match backlog bug status drift codes **`BUG_RECONCILE_ACCEPTANCE_*`**.
341
- - **Commands**:
342
- - `python scripts/bug_issue_validate.py --self-test`
343
- - `python scripts/bug_issue_validate.py --backlog docs/product/backlog.md [--check-acceptance] [--print-next-id]`
344
- - `python scripts/intake_bug_routing_guard.py --kind story|bug --file <path>` (or **`--stdin`**)
345
- - **Regression**: `tests/bug_issue_fixtures_test.py` (R-0056 Tier A/B), invoked from **`tests/run-tests.ps1` / `tests/run-tests.sh`** §26L.
346
-
347
- ## Optional ID namespace bootstrap (US-0052)
348
-
349
- Fresh-project ID bootstrap is optional and default-off in
350
- `.cursor/scratchpad.md`:
351
-
352
- - `ID_NAMESPACE_BOOTSTRAP=0|1` (default `0`)
353
-
354
- Deterministic behavior:
355
-
356
- - If `ID_NAMESPACE_BOOTSTRAP=1`, evaluate freshness eligibility before creating
357
- new IDs:
358
- - no `US-` IDs in `docs/product/backlog.md`
359
- - no `DEC-` IDs in `docs/engineering/decisions.md` (and no existing
360
- `decisions/DEC-*.md`)
361
- - no `R-` IDs in `docs/engineering/research.md`
362
- - If eligible, first created IDs start at:
363
- - `US-0001` for intake stories
364
- - `DEC-0001` for architecture decisions
365
- - `R-0001` for research entries
366
- - If not eligible (or mode is off), continue from highest existing ID in each
367
- namespace.
368
- - Never rewrite/renumber historical IDs.
369
- - If bootstrap is requested but ineligible, emit deterministic diagnostic
370
- `ID_BOOTSTRAP_NOT_FRESH` and continue with highest-existing continuation.
371
-
372
- ## Context compaction and token profile mode (US-0053 / DEC-0035)
373
-
374
- Tiered token-cost control is explicit and defaulted in `.cursor/scratchpad.md`:
375
-
376
- - `TOKEN_PROFILE=lean|balanced|full` (default `balanced`)
377
-
378
- Deterministic profile semantics:
379
-
380
- - `lean`: reduce non-critical overhead defaults (for example aggressive research,
381
- autonomous loops, broad-context retrieval), while preserving mandatory
382
- quality/release gates.
383
- - `balanced`: preserve current capability profile with moderate overhead.
384
- - `full`: maximize context breadth and autonomy for complex/high-uncertainty work.
385
-
386
- Manual override precedence:
387
-
388
- - Explicit flag values remain authoritative for that flag.
389
- - If a flag is explicitly set, it overrides profile defaults.
390
- - Profile changes must not disable mandatory gate contracts
391
- (`/qa`, `/verify-work`, `/release`).
392
-
393
- ### Token-cost evidence + comparability (US-0080 / DEC-0062)
394
-
395
- - **Fresh context**: spawn **new** subagents per `/auto` phase; avoid carrying prior chat
396
- reasoning as phase input.
397
- - **`start-from`**: use **`/auto start-from=<canonical_phase_id>`** when resuming so the
398
- schedule intersection matches materialized **`resolved_phase_plan`** (**`DEC-0052`**).
399
- - **`TOKEN_PROFILE`**: `lean` lowers default automation breadth; does **not** remove
400
- isolation, strict-proof, role, or release gates.
401
- - **Metrics**: append-only **`handoffs/token_cost_runs/<orchestrator_run_id>.md`** (or
402
- **`.jsonl`**); copy path into **`token_cost_evidence_ref`** on **`state.md`** checkpoints.
403
- - **AC-2**: compare **`cache_read_tokens`** only when **`run_class_hash`** matches; else
404
- **`TOKEN_COST_RUN_CLASS_MISMATCH`**.
405
- - **CI/repo checks**: `python scripts/check_token_cost_parity.py --repo .` (manifest-listed
406
- active/`template/` pairs); **`tests/run-tests.ps1`** / **`tests/run-tests.sh`** §26M.
407
-
408
- Context compaction policy:
409
-
410
- - `docs/engineering/state.md` is a compact hot surface for current execution
411
- context and recent checkpoints.
412
- - Historical state packs belong in `docs/engineering/state-archive/` and are
413
- append-only/non-destructive.
414
- - `docs/engineering/decisions.md` is a compact index with bounded summaries and
415
- canonical links to full records in `decisions/DEC-xxxx.md`.
416
- - Enforced rollover thresholds:
417
- - `STATE_HOT_MAX_LINES` (default `1200`)
418
- - `STATE_HOT_MAX_CHECKPOINTS` (default `80`)
419
- - `PO_TO_TL_HOT_MAX_LINES` (default `800`)
420
- - `PO_TO_TL_HOT_MAX_SECTIONS` (default `60`)
421
- - `ARCH_HOT_MAX_LINES` (default `3500`)
422
- - `ARCH_HOT_MAX_STORY_SECTIONS` (default `120`)
423
- Thresholds resolve from merged `.cursor/scratchpad.md` +
424
- `.cursor/scratchpad.local.md` (DEC-0054 triad contract).
425
- When a cap is exceeded, the mutating phase must run rollover **before**
426
- completion or fail closed (no successful completion with an oversize hot
427
- surface).
428
-
429
- ### Triad hot-surface enforcement (DEC-0054)
430
-
431
- Canonical hot/archive surfaces:
432
-
433
- - `docs/engineering/state.md` → `docs/engineering/state-archive/state-pack-*.md`
434
- - `handoffs/po_to_tl.md` → `handoffs/archive/po-to-tl-pack-*.md`
435
- - `docs/engineering/architecture.md` →
436
- `docs/engineering/architecture-archive/architecture-pack-*.md`
437
-
438
- Operator commands:
439
-
440
- ```bash
441
- python scripts/enforce-triad-hot-surface.py --check
442
- python scripts/enforce-triad-hot-surface.py --rollover
443
- ```
444
-
445
- - `--check` verifies all three surfaces are within policy (CI-safe).
446
- - `--rollover` archives oldest contiguous units into the next deterministic pack
447
- name; reruns are idempotent when already within caps.
448
- - Successful rollover records a verification tuple:
449
- `boundary`, `moved`, `retained` (counts / lines), `pack_ref`.
450
-
451
- Rollover fail-safe reason codes:
452
-
453
- - `STATE_ARCHIVE_BOUNDARY_AMBIGUOUS`
454
- - `STATE_ARCHIVE_WRITE_FAILED`
455
- - `STATE_ARCHIVE_VERIFICATION_FAILED`
456
- - `STATE_ARCHIVE_REQUIRED`
457
- - `ARTIFACT_HOT_SURFACE_OVERSIZE`
458
- - `CONTEXT_BUDGET_EXCEEDED`
459
-
460
- ### Minimal-read defaults by phase (bounded escalation)
461
-
462
- Read `docs/engineering/phase-context.md` first, then the **required** paths for
463
- your phase. If unresolved, expand once to the **single** archive pack named in
464
- the latest verification tuple for that surface. Do not load entire archive
465
- directories by default.
466
-
467
- | Phase | Required reads (default) | Combined line budget (guidance) |
468
- |-------|--------------------------|----------------------------------|
469
- | `/intake` | `phase-context.md`, target story in `docs/product/backlog.md`, `handoffs/po_to_tl.md` (tail) | ≤ 900 lines |
470
- | `/discovery` | `phase-context.md`, `docs/product/vision.md` (story notes), `handoffs/po_to_tl.md` (tail) | 900 lines |
471
- | `/research` | `phase-context.md`, `docs/engineering/research.md` (target entry), `docs/product/backlog.md` (target story) | ≤ 800 lines |
472
- | `/architecture` | `phase-context.md`, `docs/engineering/architecture.md` (target story section), `docs/engineering/research.md` | ≤ 1200 lines |
473
- | `/sprint-plan` | `phase-context.md`, `docs/engineering/architecture.md` (target story), `handoffs/tl_to_dev.md` | ≤ 1000 lines |
474
- | `/plan-verify` | `phase-context.md`, `sprints/Sxxxx/tasks.md`, `docs/product/backlog.md` (ACs) | ≤ 900 lines |
475
- | `/execute` | `phase-context.md`, `sprints/Sxxxx/tasks.md`, `handoffs/tl_to_dev.md` | ≤ 800 lines |
476
- | `/qa` | `phase-context.md`, `sprints/Sxxxx/`, `tests/report.md` | ≤ 900 lines |
477
- | `/verify-work` | `phase-context.md`, `sprints/Sxxxx/uat.json`, QA findings | ≤ 600 lines |
478
- | `/release` | `phase-context.md`, release queue + sprint release findings | ≤ 700 lines |
479
- | `/refresh-context` | `phase-context.md`, `docs/engineering/state.md` (tail), `docs/product/backlog.md` (status) | ≤ 900 lines |
480
- | `/auto` (resolver) | `phase-context.md`, `handoffs/resume_brief.md`, `docs/engineering/state.md` (tail) | ≤ 700 lines |
481
-
482
- If the default set is insufficient, escalate with an explicit note citing
483
- `pack_ref`. Unbounded broad reads fail closed with `CONTEXT_BUDGET_EXCEEDED`.
484
-
485
- `/ask` retrieval policy:
486
-
487
- - Use question-scoped narrow reads first.
488
- - Expand context in bounded steps only when unresolved.
489
- - If unresolved after bounded expansion, answer with explicit "not found in
490
- current artifacts" rather than broad speculative reads.
491
-
492
- ## Configurable multi-target publish mode (US-0054 / DEC-0036)
493
-
494
- Post-release publish orchestration is configurable and default-safe:
495
-
496
- - `RELEASE_PUBLISH_MODE=disabled|confirm|auto` (default `confirm`)
497
- - `RELEASE_TARGETS_FILE=docs/engineering/release-targets.json`
498
- - `RELEASE_TARGETS_DEFAULT=` optional comma-separated default target IDs
499
-
500
- Target schema contract:
501
-
502
- - Canonical target config file: `docs/engineering/release-targets.json`
503
- - Supported target types:
504
- - `npm`, `choco`, `brew`, `git`, `docker`, `cloud`
505
- - `custom` (generic command target)
506
- - `ssh` (host/user/port/auth reference + remote command)
507
- - Connectivity metadata (for operator-safe remote/local context):
508
- - `runtime.mode` (`local|remote`)
509
- - endpoint fields (`domainEnv|ipEnv|hostEnv`, `port`, `protocol`)
510
- - optional ingress metadata (`traefik.enabled`, `router`, `entrypoint`, `tls`)
511
- - optional `dockerOverSsh` object for ssh/dockerd remote execution context
512
- - Each target entry must define deterministic fields:
513
- - `id` (stable unique target ID)
514
- - `type`
515
- - `enabled` (`true|false`)
516
- - `order` (deterministic execution ordering)
517
- - execution details (`command` for non-ssh, `remoteCommand` + host/user/auth refs for `ssh`)
518
-
519
- Safety contract:
520
-
521
- - Mandatory release gates remain unchanged and must pass before any publish
522
- target execution.
523
- - `confirm` mode requires explicit operator approval before publish execution.
524
- - Sensitive fields must be env-referenced (`*Env` keys); inline secret literals
525
- are not allowed.
526
- - Invalid target config must fail fast with deterministic diagnostics and no
527
- partial side effects.
528
- - Invalid remote connectivity metadata must fail fast with
529
- `REMOTE_CONNECTIVITY_CONFIG_INVALID`.
530
- - Canonical operator endpoint summary is written to
531
- `docs/engineering/runtime-connectivity.md` with sanitized values only.
532
-
533
- ## Release operator hints contract (US-0067 / DEC-0049)
534
-
535
- Release outputs must include deterministic operator-ready hints with mandatory
536
- section order:
537
-
538
- `Run -> Connect -> Verify -> Credentials -> Known Issues`
539
-
540
- Required fields for canonical sprint notes
541
- (`handoffs/releases/Sxxxx-release-notes.md`):
542
-
543
- - `Run`: `start_command`, `runtime_mode`, `runtime_context_ref`
544
- - `Connect`: `service_url`, `service_port`, `health_endpoint`
545
- - `Verify`: deterministic `verification_steps`, `expected_health_signal`
546
- - `Credentials`: env-reference-only source refs and expected value-source
547
- location guidance (never inline secrets)
548
- - `Known Issues`: concise issue list or explicit `None`
549
-
550
- Legacy pointer contract (`handoffs/release_notes.md`):
551
-
552
- - keep concise latest run/connect/verify summary only
553
- - always link to canonical sprint-scoped release notes for full details
554
-
555
- Fail-closed reason codes:
556
-
557
- - `RELEASE_OPERATOR_HINTS_MISSING`
558
- - `RELEASE_OPERATOR_HINTS_AMBIGUOUS`
559
- - `RELEASE_OPERATOR_HINTS_SECRET_EXPOSURE`
560
-
561
- ## Deterministic status reconciliation mode (US-0055 / DEC-0037)
562
-
563
- Use the dedicated reconciliation command to normalize status drift across
564
- canonical and derived artifacts:
565
-
566
- - Command: `/status-reconcile`
567
- - Canonical source: `docs/product/backlog.md` (story `Status`)
568
- - Derived surfaces: `docs/product/acceptance.md`, `docs/engineering/state.md`,
569
- `handoffs/resume_brief.md`
570
-
571
- Deterministic behavior:
572
-
573
- - Detects mismatches (for example DONE + unchecked ACs, acceptance drift, resume drift).
574
- - Applies target-scoped reconciliation only to mismatched story blocks/rows.
575
- - Preserves canonical ownership; derived artifacts reconcile to backlog status.
576
- - Updates `handoffs/resume_brief.md` to next OPEN story and intended phase.
577
- - Writes auditable rows to `docs/engineering/status-normalization-report.md`.
578
-
579
- Reason-code baseline:
580
-
581
- - `STATUS_RECONCILE_APPLIED`
582
- - `STATUS_RECONCILE_NOOP`
583
- - `STATUS_RECONCILE_MISSING_INPUT`
584
- - `STATUS_RECONCILE_CANONICAL_CONFLICT`
585
- - `STATUS_RECONCILE_PHASE_AMBIGUOUS`
586
- - `STATUS_RECONCILE_EVIDENCE_MISSING`
587
-
588
- ## Optional cross-repo observability mode (US-0034)
589
-
590
- Compatibility visibility is optional and default-off in `.cursor/scratchpad.md`:
591
-
592
- - `CROSS_REPO_OBSERVABILITY=0|1` (default `0`)
593
- - `COMPATIBILITY_GATE_ON_CRITICAL=0|1` (default `1`)
594
- - `COMPATIBILITY_SOURCES=` monitored source declarations
595
-
596
- Default-off behavior:
597
- - With `CROSS_REPO_OBSERVABILITY=0`, `/intake`, `/architecture`, `/execute`,
598
- and `/qa` add zero required compatibility overhead.
599
-
600
- Enabled behavior (`CROSS_REPO_OBSERVABILITY=1`):
601
- - Use canonical artifacts:
602
- - `docs/engineering/compatibility-report.md`
603
- - `docs/engineering/compatibility-signals.md`
604
- - `docs/engineering/manifests/registry.manifest.yaml`
605
- - `docs/engineering/manifests/repo.manifest.yaml`
606
- - Record findings with severity, affected modules, evidence refs, and
607
- recommended actions.
608
- - If unresolved critical findings exist and
609
- `COMPATIBILITY_GATE_ON_CRITICAL=1`, trigger decision gate before release
610
- progression (`COMPATIBILITY_CRITICAL_OPEN`).
611
-
612
- ## Optional component-scoped execution mode (US-0035)
613
-
614
- Component-scoped execution is optional and default-off:
615
-
616
- - `COMPONENT_SCOPE_MODE=0|1` (default `0`)
617
- - `TARGET_COMPONENTS=` comma-separated scoped component IDs
618
-
619
- Default-off behavior:
620
- - With `COMPONENT_SCOPE_MODE=0`, workflow phases add zero required scope
621
- overhead.
622
-
623
- Enabled behavior (`COMPONENT_SCOPE_MODE=1`):
624
- - Declare scope in `docs/engineering/component-scope.md`:
625
- - `target_components[]`
626
- - `non_target_components[]`
627
- - `allowed_interface_touch[]`
628
- - `/sprint-plan` tasks declare `target_component_ids` and
629
- `expected_impacted_interfaces`.
630
- - `/execute` enforces scope-first behavior.
631
- - `/qa` verifies unaffected-component checks and records evidence in
632
- `docs/engineering/component-scope-report.md`.
633
- - If unapproved out-of-scope impact remains open, release must stop at decision
634
- gate (`COMPONENT_SCOPE_VIOLATION_UNAPPROVED`).
635
-
636
- ## Optional spec-pack documentation mode (US-0031)
637
-
638
- Spec-pack mode is optional and default-off in `.cursor/scratchpad.md`:
639
-
640
- - `SPEC_PACK_MODE=0|1` (default `0`)
641
-
642
- Default-off behavior:
643
- - With `SPEC_PACK_MODE=0`, `/intake`, `/architecture`, `/execute`, `/qa`, and
644
- `/release` add no required spec-pack steps (zero overhead).
645
-
646
- Enabled behavior (`SPEC_PACK_MODE=1`):
647
-
648
- **Canonical names and locations** (per story):
649
- - Design Concept: `docs/engineering/spec-pack/<story_id>-design-concept.md`
650
- - CRS (Customer/Product Requirements Summary): `docs/engineering/spec-pack/<story_id>-crs.md`
651
- - Technical Specification: `docs/engineering/spec-pack/<story_id>-technical-specification.md`
652
-
653
- **Traceability**: Backlog story ID (e.g. `US-0031`) maps 1:1 to the three
654
- artifacts above. Handoffs and state should reference these paths when
655
- spec-pack mode is enabled.
656
-
657
- **Minimum required sections** (completeness is testable; validation blocks
658
- only when enabled and a required section is missing or empty):
659
-
660
- - Design Concept: `# Summary`, `# Goals`, `# Non-goals`, `# Key decisions`
661
- - CRS: `# Purpose`, `# Scope`, `# Acceptance criteria ref`
662
- - Technical Specification: `# Overview`, `# Components`, `# Interfaces`, `# Non-functional`
663
-
664
- **Validation**: When `SPEC_PACK_MODE=1`, release gate checks that for the
665
- target sprint story, all three artifacts exist and each required section
666
- above is present and non-empty. If not, release is blocked with reason code
667
- `SPEC_PACK_INCOMPLETE` and remediation guidance.
668
-
669
- **Ownership (role/phase)**:
670
- - Design Concept: Tech Lead, `/architecture` (create/update).
671
- - CRS: PO, `/intake` (create/update for new story); Tech Lead may extend in
672
- architecture.
673
- - Technical Specification: Tech Lead, `/architecture` (create); Dev, `/execute`
674
- (update when implementation details change).
675
-
676
- ## Optional user-guide documentation mode (US-0032)
677
-
678
- User-guide mode is optional and default-off in `.cursor/scratchpad.md`:
679
-
680
- - `USER_GUIDE_MODE=0|1` (default `0`)
681
-
682
- Default-off behavior:
683
- - With `USER_GUIDE_MODE=0`, `/intake`, `/architecture`, `/sprint-plan`, `/execute`,
684
- `/qa`, and `/release` add no required user-guide steps or blocking checks (zero overhead).
685
-
686
- Enabled behavior (`USER_GUIDE_MODE=1`):
687
-
688
- **Canonical location and naming** (per feature story):
689
- - One guide per feature story: `docs/user-guides/US-xxxx.md` (e.g. `docs/user-guides/US-0032.md`).
690
- - Story ID `US-xxxx` is the stable identifier; create/update the guide when the story is in scope.
691
-
692
- **Minimum required schema** (structural validation only; completeness is testable):
693
- - `# Purpose`
694
- - `# Prerequisites`
695
- - `# Usage steps`
696
- - `# Example`
697
- - `# Limitations`
698
- - `# Troubleshooting`
699
-
700
- **Traceability**: Story ID maps 1:1 to the user-guide artifact. Handoffs and release
701
- context should reference `docs/user-guides/US-xxxx.md` for the target story when
702
- user-guide mode is enabled.
703
-
704
- **Validation**: When `USER_GUIDE_MODE=1`, release gate checks that for the target
705
- sprint story, the guide file exists at the canonical path and each required section
706
- above is present and non-empty. If not, release is blocked with reason code
707
- `USER_GUIDE_INCOMPLETE` and remediation guidance (create or complete the guide).
708
-
709
- **Boundary with spec-pack (US-0031)**: User guides are end-user facing how-to
710
- documentation only. They do not duplicate Design Concept, CRS, or Technical
711
- Specification content; user guides may reference spec-pack artifacts but must not
712
- replicate their ownership or technical scope. See runbook/README separation guidance.
713
-
714
- ## Legacy DONE-story drift detection and guard (US-0049)
715
-
716
- Stories that are DONE in backlog but lack aligned acceptance/traceability or
717
- release representation are in **legacy drift**. US-0049 adds detection, bounded
718
- repair, and an ongoing guard at release/reconciliation (DEC-0031).
719
-
720
- **Detection rule** A story is in legacy drift when:
721
- - Backlog status is **DONE**, and
722
- - At least one of:
723
- - Acceptance checklist item for that story is **unchecked**
724
- - Traceability index or `docs/engineering/state.md` **lacks an entry** for that story
725
- - Release artifacts (e.g. `handoffs/releases/Sxxxx-release-notes.md`, queue row)
726
- **lack clear representation** for that story
727
-
728
- **Bounded repair**: Only stories matching the rule above may be mutated; no broad
729
- rewrite of unrelated backlog/acceptance/state/release artifacts.
730
-
731
- **Canonical audit artifact**: `docs/engineering/legacy-drift-audit.md`
732
- - Required fields per entry: story ID, prior acceptance state, prior traceability
733
- state, resolved state(s), reason code, evidence reference.
734
- - Append-only; one-time backfill and ongoing guard append entries when drift is
735
- detected and repaired (or when guard blocks and reports).
736
-
737
- **Reason-code vocabulary** (with remediation):
738
- - `BACKLOG_DONE_ACCEPTANCE_UNCHECKED` Backlog DONE but acceptance item unchecked.
739
- Remediation: set acceptance checkbox from canonical release/state evidence or run one-time backfill.
740
- - `BACKLOG_DONE_TRACEABILITY_MISSING` Backlog DONE but traceability/state lacks entry.
741
- Remediation: add traceability row in `docs/engineering/state.md` from backlog/release evidence or run backfill.
742
- - `BACKLOG_DONE_RELEASE_ARTIFACT_MISSING` Backlog DONE but release artifacts lack representation.
743
- Remediation: ensure release notes or queue row exists for the story’s sprint or run backfill.
744
-
745
- **One-time backfill mode**: Explicit trigger (e.g. dedicated check or `/memory-audit`-related path).
746
- - Run detection once over all DONE stories; for each legacy-drift story, perform
747
- target-scoped repair and append an entry to `docs/engineering/legacy-drift-audit.md`.
748
- - Idempotent when no drift: no mutations; report empty or "no drift".
749
- - Only stories matching the detection rule are mutated.
750
-
751
- **Ongoing guard**: At release or reconciliation boundary (or dedicated check).
752
- - When legacy drift is detected, either **block** with explicit reason code and
753
- remediation, or **repair** target-scoped and append audit entry (policy documented).
754
- - Behavior is deterministic; operators get explicit diagnostics.
755
-
756
- ## Memory drift auditing
757
-
758
- Run `/memory-audit` at key workflow checkpoints to verify artifact consistency:
759
-
760
- - **Pre-handoff**: before writing `handoffs/dev_to_qa.md` or any role handoff.
761
- - **Pre-QA**: before running `/qa` or `/verify-work`.
762
- - **Pre-release**: before running `/release`.
763
- - **Ad-hoc**: after external code changes, long pauses, or whenever artifacts
764
- feel stale.
765
-
766
- Output: `docs/engineering/memory-drift-report.md` an advisory report with
767
- severity-classified findings. The command is read-only and non-blocking.
768
-
769
- Interpreting results:
770
- - **high**: artifact contradicts repository state fix before next handoff/release.
771
- - **medium**: artifact is likely stale — fix before release.
772
- - **low**: minor inconsistency — fix during `/refresh-context` or next sprint.
773
-
774
- Template drift findings (active vs `template/`) are listed for reference only
775
- and belong to US-0017 scope.
776
-
777
- Follow-up commands: `/refresh-context`, `/sprint-plan`, `/verify-work`, `/intake`.
778
-
779
- ## Remote execution validation contract
780
-
781
- Remote execution is mode-aware and default-off:
782
-
783
- - `REMOTE_EXECUTION=0`: skip remote-config validation entirely (zero overhead).
784
- - `REMOTE_EXECUTION=1`: validate `.cursor/remote.json` before remote activities;
785
- fail fast on first blocking issue.
786
-
787
- Validation classes (remote-enabled mode):
788
-
789
- 1. Presence: config file exists at `REMOTE_CONFIG` (default `.cursor/remote.json`)
790
- 2. Syntax: JSON parses cleanly
791
- 3. Contract: required fields/types/enums
792
- 4. Semantics: `defaultTarget` points to an existing enabled target; target ids
793
- are unique
794
- 5. Security: no inline secret-like literals; env-var refs only for sensitive values
795
-
796
- Required contract summary:
797
-
798
- - Root: `version` (integer), `defaultTarget` (string), `targets` (array)
799
- - Target: `id` (string), `type` (`docker|ssh|vm`), `enabled` (boolean),
800
- `host` (string), `port` (integer `1..65535`), `workspaceRoot` (string)
801
- - Optional auth: `auth.mode` (`none|env`); if `env`, use `*Env` references
802
-
803
- Error message format (actionable, fail-fast):
804
-
805
- - `[REMOTE_CONFIG_ERROR] <path>: expected <rule>, got <actual>. Fix: <hint>.`
806
-
807
- Operator troubleshooting:
808
-
809
- - Missing config file:
810
- - Copy from `template/.cursor/remote.json`, or disable remote mode.
811
- - Malformed JSON:
812
- - Fix syntax (commas/brackets/quotes), then retry.
813
- - Invalid value or enum:
814
- - Correct field value to the documented contract.
815
- - Security violation (inline secret-like literal):
816
- - Replace with env-var reference fields (`tokenEnv`, `passwordEnv`,
817
- `privateKeyPathEnv`, ...).
818
-
819
- ## Runtime QA autopilot contract (US-0065 / DEC-0047)
820
-
821
- Generated-project validation requires runtime proof, not static checks alone.
822
-
823
- Mandatory runtime stage order:
824
-
825
- `startup -> readiness/connectivity -> log scan -> bounded retry -> verdict`
826
-
827
- Deterministic runtime failure reason codes:
828
-
829
- - `RUNTIME_STARTUP_FAILED`
830
- - `RUNTIME_ENDPOINT_UNREACHABLE`
831
- - `RUNTIME_LOG_CRITICAL_DETECTED`
832
- - `RUNTIME_RETRY_BUDGET_EXHAUSTED`
833
- - `RUNTIME_STACK_PROFILE_UNRESOLVED`
834
-
835
- Runtime evidence schema (record in QA findings):
836
-
837
- - `runtime_startup_command`
838
- - `runtime_stack_profile` (`node|python|go|java|dotnet`)
839
- - `runtime_mode` (`local|remote`)
840
- - `runtime_health_target`
841
- - `runtime_health_result`
842
- - `runtime_log_summary` (severity counts and key error signals)
843
- - `runtime_retry_count`
844
- - `runtime_retry_ledger` (`attempt`, `delay_ms`, `outcome`)
845
- - `runtime_final_verdict`
846
- - `runtime_reason_code`
847
- - `runtime_evidence_refs`
848
-
849
- Bounded retry policy:
850
-
851
- - retry only transient startup/connectivity failures
852
- - enforce configured max-attempt cap (`attempt <= max`)
853
- - fail fast on non-transient critical runtime log signals
854
-
855
- Stack/profile resolution:
856
-
857
- - Minimum supported runtime profiles: Node, Python, Go, Java, .NET.
858
- - Unknown or ambiguous profile must fail closed with
859
- `RUNTIME_STACK_PROFILE_UNRESOLVED`.
860
-
861
- Webapp verification path (when applicable):
862
-
863
- - include browser-surface load validation
864
- - capture console error summary and failed network request summary
865
- - add these signals to `runtime_log_summary` and evidence refs
866
-
867
- Optional debug escalation (bounded):
868
-
869
- - use for reproducible runtime failures only
870
- - keep instrumentation bounded and reversible
871
- - record applied debug steps and explicit cleanup confirmation
872
-
873
- ## Generated test scaffolding + auto-run contract (US-0066 / DEC-0048)
874
-
875
- Generated app projects require deterministic baseline test scaffolding and
876
- automatic QA test execution evidence.
877
-
878
- Detection/profile contract:
879
-
880
- - Resolve one deterministic stack profile from:
881
- `node|python|go|java|dotnet` (minimum supported).
882
- - If profile cannot be resolved, fail closed with
883
- `TEST_SCAFFOLD_STACK_UNRESOLVED`.
884
- - If detected stack is outside supported baseline set, fail closed with
885
- `TEST_SCAFFOLD_UNSUPPORTED_STACK`.
886
-
887
- Generation contract (`/execute`):
888
-
889
- - Generate only missing baseline assets for:
890
- - unit tests
891
- - integration tests
892
- - acceptance tests
893
- - Use stable scaffold paths so reruns are idempotent (no duplicate file churn).
894
- - Record generated paths and actions in execution evidence.
895
- - If generation fails, fail closed with `TEST_SCAFFOLD_GENERATION_FAILED`.
896
-
897
- Runbook command wiring:
898
-
899
- - `TEST_COMMAND` baseline is stack-aware and deterministic.
900
- - Non-destructive precedence is mandatory:
901
- - preserve user-authored non-empty `TEST_COMMAND`,
902
- - write baseline command only when `TEST_COMMAND` is missing/unset.
903
-
904
- QA auto-run evidence contract (`/qa`):
905
-
906
- - Execute generated baseline tests automatically.
907
- - Record evidence fields:
908
- - `generated_test_stack_profile`
909
- - `generated_test_command`
910
- - `generated_test_result`
911
- - `generated_test_output_ref`
912
- - `generated_test_paths_ref`
913
- - `generated_test_reason_code`
914
-
915
- Runtime boundary with US-0065:
916
-
917
- - Generated static test PASS is required but never sufficient for QA PASS.
918
- - Runtime-autopilot verdict remains mandatory; non-starting apps cannot PASS QA.
919
-
920
- ## Auto continuation resume contract
921
-
922
- `/auto` continuation uses deterministic phase resolution (DEC-0017):
923
-
924
- 1. explicit `/auto start-from=<phase>`
925
- 2. `handoffs/resume_brief.md`
926
- 3. conservative `docs/engineering/state.md` fallback
927
- 4. fail-fast
928
-
929
- Canonical `start-from` phase IDs:
930
- `intake`, `discovery`, `research`, `architecture`, `sprint-plan`,
931
- `plan-verify`, `execute`, `qa`, `verify-work`, `release`, `refresh-context`.
932
-
933
- Conflict and stale-source policy:
934
- - Explicit valid override wins.
935
- - If no override and `resume_brief` conflicts with `state`, fail fast.
936
- - If `resume_brief` exists but is stale/unparseable, fail fast.
937
- - Use state fallback only when `resume_brief` is absent.
938
-
939
- Fail-fast error format:
940
- - `[AUTO_RESUME_ERROR] <code>: <summary>. Source=<source>. Fix: <action>.`
941
-
942
- Required error codes:
943
- - `INVALID_START_FROM`
944
- - `RESUME_BRIEF_MISSING`
945
- - `RESUME_BRIEF_STALE`
946
- - `RESUME_BRIEF_UNPARSEABLE`
947
- - `RESUME_STATE_CONFLICT`
948
- - `STATE_PHASE_AMBIGUOUS`
949
- - `STATE_PHASE_UNRECOVERABLE`
950
-
951
- Breadcrumbs required for inspectability:
952
- - `resolution_source`, `resolved_start_phase`, `stop_reason`, `stop_phase`,
953
- `timestamp`.
954
- - Record in `docs/engineering/state.md`; update `handoffs/resume_brief.md` when
955
- auto stops before completion.
956
-
957
- Stop-condition preservation:
958
- - continuation does not bypass decision gates, missing-input blockers,
959
- pause requests, or loop max cycle limits.
960
-
961
- ## Per-phase subagent isolation evidence (US-0048 / DEC-0029)
962
-
963
- Per-phase fresh-context isolation is enforced with auditable, fail-closed
964
- evidence.
965
-
966
- ### Canonical evidence store and locations
967
-
968
- - Canonical evidence store: `docs/engineering/state.md` (append-only checkpoints).
969
- - Cross-references are allowed in phase artifacts and handoffs:
970
- - `handoffs/dev_to_qa.md`, `handoffs/qa_to_dev.md`
971
- - `handoffs/resume_brief.md` (pause/resume provenance)
972
- - `sprints/Sxxxx/summary.md`, `sprints/Sxxxx/qa-findings.md`, `sprints/Sxxxx/uat.*`,
973
- `sprints/Sxxxx/release-findings.md`
974
-
975
- ### Required schema (one entry per phase run)
976
-
977
- Each phase run must append an isolation evidence entry containing:
978
-
979
- - `phase_id`: canonical phase id (`intake|discovery|research|architecture|sprint-plan|plan-verify|execute|qa|verify-work|release|refresh-context|pause|resume`)
980
- - `role`: subagent role executing the phase (`po|curator|tech-lead|dev|qa|release|security`)
981
- - `fresh_context_marker`: a marker unique to the fresh subagent context for this phase run
982
- - `timestamp`: ISO UTC timestamp
983
- - `evidence_ref`: canonical path to the primary artifact written/validated for the phase run
984
-
985
- ### Gate behavior (fail closed)
986
-
987
- - Missing evidence blocks progression with `PHASE_CONTEXT_ISOLATION_MISSING`.
988
- - Invalid schema/fields blocks progression with `ISOLATION_EVIDENCE_INVALID`.
989
- - Stale evidence (reused marker across runs or older than the resumed boundary)
990
- blocks progression with `ISOLATION_EVIDENCE_STALE`.
991
- - Orchestrator executing phase work without spawning a fresh subagent context is
992
- a hard violation: `PHASE_CONTEXT_ISOLATION_VIOLATION`.
993
-
994
- Remediation (all cases): re-run the affected phase in a fresh subagent context
995
- and write new isolation evidence before proceeding.
996
-
997
- ### Reason codes and remediation (US-0048)
998
-
999
- - `PHASE_CONTEXT_ISOLATION_MISSING`: no isolation evidence entry found for a
1000
- required phase run. Fix: rerun the phase in a fresh subagent and append the
1001
- required evidence fields.
1002
- - `ISOLATION_EVIDENCE_INVALID`: evidence entry present but missing required
1003
- fields or contains invalid `phase_id`/`role`. Fix: rerun the phase and write a
1004
- corrected entry.
1005
- - `ISOLATION_EVIDENCE_STALE`: evidence is reused across runs/cycles or predates
1006
- the latest resume boundary. Fix: rerun the phase and write a new
1007
- `fresh_context_marker`.
1008
- - `PHASE_CONTEXT_ISOLATION_VIOLATION`: phase work was performed without a fresh
1009
- subagent context (for example orchestrator performed phase writes). Fix: stop,
1010
- revert unsafe artifacts if needed, rerun the phase correctly, and ensure
1011
- orchestration-only behavior.
1012
-
1013
- ## Strict runtime proof contract (US-0056 / DEC-0038)
1014
-
1015
- Strict runtime proof augments artifact-level isolation evidence. `/auto`,
1016
- `/verify-work`, and `/release` must validate runtime attestation tuples at phase
1017
- boundaries before continuation/finalization.
1018
-
1019
- Required runtime attestation tuple fields:
1020
-
1021
- - `orchestrator_run_id`
1022
- - `runtime_proof_id` (unique per phase run)
1023
- - `phase_id`
1024
- - `role`
1025
- - `proof_issued_at` (ISO UTC / RFC3339)
1026
- - `proof_ttl_seconds`
1027
- - `proof_hash`
1028
-
1029
- Deterministic fail-closed reason codes:
1030
-
1031
- - `RUNTIME_PROOF_MISSING`
1032
- - `RUNTIME_PROOF_INVALID`
1033
- - `RUNTIME_PROOF_REUSED`
1034
- - `RUNTIME_PROOF_STALE`
1035
- - `RUNTIME_PROOF_AMBIGUOUS_LINK`
1036
-
1037
- Boundary behavior:
1038
-
1039
- - Missing/invalid/reused/stale/ambiguous runtime proof blocks progression.
1040
- - Release finalization must consume strict runtime proof in addition to existing
1041
- isolation evidence checks.
1042
- - Pause/resume provenance must reference latest valid strict-proof boundary.
1043
-
1044
- ## Strict `/auto` phase→role enforcement (US-0069 / DEC-0051)
1045
-
1046
- `/auto` must treat phase roles as a **fail-closed admission and checkpoint
1047
- contract** (see `decisions/DEC-0051.md` and `/auto` command text).
1048
-
1049
- ### Canonical matrix and scratchpad alternates
1050
-
1051
- - Fixed phase→role defaults are documented in `/auto` (for example `execute` →
1052
- `dev`, `release` `release`).
1053
- - Alternate phases resolve **one** expected role via scratchpad:
1054
- - `AUTO_ROLE_RESEARCH`: `po` \| `tech-lead` (empty default `tech-lead`)
1055
- - `AUTO_ROLE_PLAN_VERIFY`: `qa` \| `tech-lead` (empty → default `qa`)
1056
- - `AUTO_ROLE_REFRESH_CONTEXT`: `curator` \| `po` (empty → default `curator`)
1057
- - Non-empty values outside the allowed set fail closed (no unrelated-role
1058
- substitution).
1059
-
1060
- ### Preflight and checkpoints
1061
-
1062
- - **Preflight (before spawn)**: resolve expected role; verify the required
1063
- subagent capability exists. Missing capability → `PHASE_ROLE_CAPABILITY_MISSING`
1064
- with `phase_id`, expected role, observed result, remediation. Do not spawn a
1065
- substitute role.
1066
- - **Post-completion**: isolation evidence `role` and strict-proof `role` must
1067
- both match the same preflight-resolved role; else `PHASE_ROLE_MISMATCH`.
1068
- - **`proof_hash`**: SHA-256 over sorted-key JSON of the strict-proof tuple fields
1069
- (`orchestrator_run_id`, `runtime_proof_id`, `phase_id`, `role`,
1070
- `proof_issued_at`, `proof_ttl_seconds`).
1071
-
1072
- ### Execute default deny and rare override
1073
-
1074
- - Default: `execute` requires `dev`.
1075
- - Override allowed only when **both** hold:
1076
- `AUTO_EXECUTE_ROLE_OVERRIDE=allowed_non_dev_execute` and
1077
- `EXECUTE_OVERRIDE_GOVERNANCE_REF` references a parseable approved exception (for
1078
- example `DEC-xxxx` or a documented state anchor).
1079
-
1080
- ### Continuation parity
1081
-
1082
- - Every `/auto` run recomputes role policy and preflight; `start-from`, fresh
1083
- `resume_brief`, and `state.md` fallback cannot bypass the gate with stale role
1084
- intent alone.
1085
-
1086
- ## Configurable `/auto` phase plan (US-0070 / DEC-0052)
1087
-
1088
- `/auto` schedules a **resolved ordered phase plan** from merged scratchpad
1089
- before any spawn. See `decisions/DEC-0052.md` and `/auto` command text.
1090
-
1091
- ### Selectors (exactly one active mode)
1092
-
1093
- - `AUTO_PHASE_PLAN=full` (default when unset and no other selector is set)
1094
- - `AUTO_PHASE_EXCLUDE=<csv>` remove listed canonical phase ids from `full`
1095
- - `AUTO_PHASE_INCLUDE=<csv>` — only listed ids, re-sorted into canonical lifecycle order
1096
- - `AUTO_PHASE_PROFILE=<name>` expand a named profile (unknown → fail closed)
1097
- - `AUTO_PHASE_HIGH_RISK_ACK=<token>` required when a documented high-risk profile demands acknowledgment
1098
-
1099
- Conflicting selectors `PHASE_POLICY_CONFLICT` (no plan materialization).
1100
-
1101
- ### Materialization and gates
1102
-
1103
- - Expand → apply **non-skippable reinstatement** (`qa`, `verify-work`, `release`,
1104
- plus evidence-chain closure per `/auto`) → intersect **`start-from` / resume
1105
- anchor** with the plan → **empty intersection** →
1106
- `START_FROM_PHASE_PLAN_EMPTY_INTERSECTION`.
1107
- - Record `resolved_phase_plan`, `skipped_phases` (+ reasons such as
1108
- `policy_exclude`, `non_skippable_gate`), and **phase boundary status** entries
1109
- in continuation breadcrumbs (`docs/engineering/state.md`).
1110
- - **Backlog-drain**, **bulk execute**, and **team scope** paths must **reload**
1111
- scratchpad phase-selection inputs and **recompute** the plan at each bounded
1112
- boundary (no silent revival of omitted phases).
1113
-
1114
- ### Failure codes (deterministic)
1115
-
1116
- - `PHASE_POLICY_CONFLICT`
1117
- - `PHASE_PLAN_UNKNOWN_PHASE`
1118
- - `PHASE_PLAN_EMPTY_INCLUDE`
1119
- - `PHASE_PLAN_UNKNOWN_PROFILE`
1120
- - `PHASE_PLAN_INVALID_AUTO_PHASE_PLAN`
1121
- - `PHASE_PLAN_HIGH_RISK_ACK_REQUIRED`
1122
- - `START_FROM_PHASE_PLAN_EMPTY_INTERSECTION`
1123
-
1124
- ## Optional backlog-drain auto mode (US-0044)
1125
-
1126
- `/auto` can optionally continue across multiple planned stories when explicitly
1127
- enabled in scratchpad.
1128
-
1129
- Controls:
1130
- - `AUTO_BACKLOG_DRAIN=0|1` (default `0`)
1131
- - `AUTO_BACKLOG_MAX_STORIES=<n>` (default `1`)
1132
- - `AUTO_BACKLOG_ON_BLOCK=stop|skip` (default `stop`)
1133
- - `AUTO_STORY_SELECTION=priority_then_backlog_order` (default)
1134
-
1135
- Semantics:
1136
- - With `AUTO_BACKLOG_DRAIN=0`, keep current single-segment continuation behavior.
1137
- - With `AUTO_BACKLOG_DRAIN=1`, select next eligible OPEN story
1138
- deterministically and run full lifecycle story-by-story until bounded limit,
1139
- no eligible stories, or a mandatory stop condition.
1140
- - Decision gates remain mandatory and pause progression until user decision.
1141
-
1142
- ## Explicit bulk sprint planning mode (US-0046)
1143
-
1144
- `/sprint-plan` stays single-scope by default. Bulk planning is opt-in via
1145
- explicit argument:
1146
-
1147
- - `/sprint-plan --bulk`
1148
-
1149
- Deterministic controls from `.cursor/scratchpad.md`:
1150
- - `SPRINT_BULK_MAX_STORIES` (candidate OPEN stories per run)
1151
- - `SPRINT_BULK_MAX_SPRINTS` (max generated sprints per run)
1152
- - `SPRINT_BULK_SELECTION=priority_then_backlog_order`
1153
-
1154
- Deterministic behavior:
1155
- - Select eligible OPEN stories by configured selection order.
1156
- - Generate one or more bounded sprint plans while preserving per-sprint sizing
1157
- guardrails (`SPRINT_MAX_TASKS`, `SPRINT_AUTO_SPLIT`).
1158
- - Stop with explicit reason codes when bounded or blocked:
1159
- - `SPRINT_BULK_MAX_STORIES_REACHED`
1160
- - `SPRINT_BULK_MAX_SPRINTS_REACHED`
1161
- - `SPRINT_BULK_NO_ELIGIBLE_STORIES`
1162
- - `SPRINT_BULK_MISSING_ACCEPTANCE`
1163
-
1164
- ## Explicit bulk execute mode (US-0047)
1165
-
1166
- `/auto` remains non-bulk by default. Bulk execution is explicit and can be
1167
- enabled per run (`/auto --execute-bulk`) or by scratchpad switch.
1168
-
1169
- Deterministic controls:
1170
- - `AUTO_EXECUTE_BULK=0|1` (default `0`)
1171
- - `AUTO_EXECUTE_MAX_ITEMS=<n>` (default `1`)
1172
- - `AUTO_EXECUTE_ON_BLOCK=stop|skip` (default `stop`)
1173
- - `AUTO_EXECUTE_SELECTION=planned_then_priority` (default)
1174
- - `AUTO_TEAM_SCOPE_ENFORCE=0|1` (default `1`)
1175
-
1176
- Execution semantics:
1177
- - Select eligible planned items deterministically.
1178
- - Preserve strict isolation:
1179
- - fresh subagent per phase
1180
- - fresh subagent per execute<->QA loop cycle
1181
- - Enforce bounded stop behavior:
1182
- - `EXEC_BULK_MAX_ITEMS_REACHED`
1183
- - `EXEC_BULK_NO_ELIGIBLE_ITEMS`
1184
- - `EXEC_BULK_ITEM_BLOCKED_STOP`
1185
- - `EXEC_BULK_ITEM_BLOCKED_SKIPPED`
1186
-
1187
- Team mode guardrails (`TEAM_MODE=1`):
1188
- - Capture team context snapshot in breadcrumbs:
1189
- - `TEAM_MODE`, `TEAM_MEMBER`, `ACTIVE_TASK_IDS`
1190
- - With enforcement enabled, out-of-scope tasks are never mutated and must emit:
1191
- - `EXEC_TEAM_SCOPE_BLOCKED` (stop policy)
1192
- - `EXEC_TEAM_SCOPE_SKIPPED` (skip policy)
1193
-
1194
- ## Sync policy and guarded auto-push contract (US-0038 / DEC-0018)
1195
-
1196
- Sync policy controls (from `.cursor/scratchpad.md`):
1197
- - `SYNC_POLICY_MODE`: `disabled|manual|by_phase|by_milestone|custom_phase_list`
1198
- - `SYNC_CUSTOM_PHASES`: comma-separated canonical phase IDs for custom mode
1199
- - `ALLOW_AUTO_PUSH`: `0|1`
1200
- - `AUTO_PUSH_BRANCH_ALLOWLIST`: comma-separated branches/patterns
1201
-
1202
- Default-safe behavior:
1203
- - Default mode is `manual` (non-auto).
1204
- - `disabled` and `manual` are near-zero-overhead modes (no auto-push attempts).
1205
- - Unset/invalid mode fails closed to `manual`.
1206
-
1207
- Phase-boundary-only evaluation:
1208
- - Evaluate sync eligibility only at completed phase boundaries.
1209
- - Never evaluate during partial or in-progress work units.
1210
-
1211
- Guarded auto-push eligibility (all required):
1212
- 1. Boundary trigger is eligible for current mode.
1213
- 2. `ALLOW_AUTO_PUSH=1`.
1214
- 3. QA-first restriction passes (feature work cannot auto-push before QA pass).
1215
- 4. No unresolved blocking QA findings / unresolved critical issues.
1216
- 5. Branch safety passes:
1217
- - protected/default branches denied by default,
1218
- - allow only explicitly allowlisted branches.
1219
- 6. Mandatory check chain passes.
1220
-
1221
- Mandatory pre-push check chain:
1222
- 1. `TEST_COMMAND` (mandatory baseline)
1223
- 2. `LINT_COMMAND` (only if configured)
1224
- 3. `TYPECHECK_COMMAND` (only if configured)
1225
-
1226
- Rules:
1227
- - Missing `TEST_COMMAND` blocks push (`TEST_COMMAND_MISSING`).
1228
- - Failing `TEST_COMMAND` blocks push (`TEST_FAILED`).
1229
- - Timed-out `TEST_COMMAND` blocks push (`TEST_TIMEOUT`).
1230
- - Optional check failures block push when configured (`OPTIONAL_CHECK_FAILED`).
1231
- - Optional checks that are not configured must be reported as `skipped`.
1232
-
1233
- Deterministic reason-code baseline:
1234
- - `SYNC_DISABLED`
1235
- - `MANUAL_MODE_NO_AUTO`
1236
- - `SYNC_TRIGGER_NOT_ELIGIBLE`
1237
- - `AUTO_PUSH_NOT_ENABLED`
1238
- - `PRE_QA_AUTOPUSH_FORBIDDEN`
1239
- - `BLOCKING_QA_FINDINGS`
1240
- - `BRANCH_NOT_ALLOWLISTED`
1241
- - `TEST_COMMAND_MISSING`
1242
- - `TEST_FAILED`
1243
- - `TEST_TIMEOUT`
1244
- - `OPTIONAL_CHECK_FAILED`
1245
- - `SYNC_PUSHED`
1246
-
1247
- ## Executable validate-and-push wiring (DEC-0058)
1248
-
1249
- Scratchpad **`SYNC_*` / `ALLOW_AUTO_PUSH` / `AUTO_PUSH_BRANCH_ALLOWLIST`** are read from the
1250
- **merged** scratchpad only (installer merge: local → materialized baseline → example; same
1251
- precedence as installer post-install validation). **`scripts/validate-and-push.ps1`** and
1252
- **`scripts/validate-and-push.sh`** call **`python scripts/sync_push_gates.py`** for policy;
1253
- **`docs/engineering/runbook.md`** remains the sole source for **`TEST_COMMAND`** and optional
1254
- lint/typecheck commands.
1255
-
1256
- **Operator rule:** changing scratchpad alone does **not** run **`git push`**. Run
1257
- **`validate-and-push`** (or CI) after an eligible boundary. For **`by_phase`**, **`by_milestone`**,
1258
- and **`custom_phase_list`**, scheduling is **operator or CI** responsibility.
1259
-
1260
- **`SYNC_PHASE_BOUNDARY`:** optional environment variable (canonical phase id, case-insensitive).
1261
- When **`SYNC_POLICY_MODE=custom_phase_list`**, the variable must be set and must appear in
1262
- **`SYNC_CUSTOM_PHASES`** (comma-separated) or the script exits **`SYNC_TRIGGER_NOT_ELIGIBLE`**.
1263
-
1264
- **Dry-run:** **`powershell .../validate-and-push.ps1 -DryRun`** or
1265
- **`bash scripts/validate-and-push.sh --dry-run ...`** runs merge/policy and the runbook check
1266
- chain, then prints **`SYNC_PUSHED`** without **`git push`**.
1267
-
1268
- **Branch allowlist matching (`AUTO_PUSH_BRANCH_ALLOWLIST`):** comma-separated entries; each entry
1269
- is either an exact branch name or a **`fnmatch`** pattern (for example `release/*`). An empty
1270
- allowlist denies every branch (**`BRANCH_NOT_ALLOWLISTED`**).
1271
-
1272
- **QA scan (bounded):** files under **`sprints/S####/qa-findings.md`** (four digits). Blocking
1273
- rules match **`DEC-0058`** §6. **`PRE_QA_AUTOPUSH_FORBIDDEN`** applies on branches other than
1274
- **`main`** / **`master`** when **no** such **`qa-findings.md`** file exists yet (feature-line
1275
- signal; see architecture **US-0076**).
1276
-
1277
- **Python:** merged policy evaluation requires **Python 3** on **`PATH`** (**`PYTHON_NOT_ON_PATH`**
1278
- if missing).
1279
-
1280
- Required sync evidence fields:
1281
- - `phase_boundary`
1282
- - `policy_mode`
1283
- - `trigger_source` (`manual|auto`)
1284
- - `branch`
1285
- - `checks` (`test|lint|typecheck`: `pass|fail|skipped`)
1286
- - `qa_status_snapshot`
1287
- - `push_decision` (`pushed|blocked|not_eligible`)
1288
- - `reason_code`
1289
- - `evidence_refs`
1290
-
1291
- ## Release gate chain (US-0039 / DEC-0019)
1292
-
1293
- Deterministic mandatory gate order; no step may be skipped or reordered:
1294
-
1295
- 1. **Check-in test gate** — Latest `TEST_COMMAND` evidence must be present and passing.
1296
- 2. **QA completion gate** No unresolved blocking findings in sprint QA context.
1297
- 3. **UAT completion gate** UAT artifacts populated and verified; no placeholder or unresolved-fail state.
1298
- 4. **Isolation compliance gate** Per-phase isolation evidence present and valid (US-0048 / DEC-0029).
1299
- 5. **Release finalization** — Notes, queue, backlog/runbook/state updates only after gates 1–4 pass.
1300
-
1301
- Default: no bypass. Override only via explicit decision gate with rationale and evidence (DEC-0019).
1302
-
1303
- **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.
1304
-
1305
- **Per-gate audit verdict schema (US-0039)** — For TL/QA auditability, record per gate:
1306
-
1307
- - `gate` (check-in_test | qa | uat | isolation | finalization)
1308
- - `verdict` (pass | fail | override)
1309
- - `reason_code` (e.g. RELEASE_TEST_FAILED, RELEASE_QA_BLOCKERS_OPEN, RELEASE_UAT_INCOMPLETE, RELEASE_GATE_OVERRIDE_APPROVED)
1310
- - `remediation` (short remediation steps when fail/override)
1311
- - `evidence_refs` (paths to tests/report.md, qa-findings.md, uat.json, release-findings.md, DEC-xxxx as applicable)
1312
-
1313
- 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.
1314
-
1315
- ## Release queue and sprint notes contract (US-0040 / DEC-0020)
1316
-
1317
- Canonical release artifacts:
1318
- - `handoffs/releases/Sxxxx-release-notes.md` (canonical per-sprint notes)
1319
- - `handoffs/release_queue.md` (canonical queue tracker)
1320
- - `handoffs/release_notes.md` (legacy-compatible latest pointer/summary)
1321
-
1322
- Queue row required fields:
1323
- - `sprint_id`
1324
- - `story_refs`
1325
- - `status` (`planned|ready|unreleased|released|blocked`)
1326
- - `last_updated`
1327
- - `release_notes_ref`
1328
- - `gate_snapshot`
1329
- - `release_version` (optional before finalization)
1330
-
1331
- Deterministic transition semantics:
1332
- - target sprint only may change during one `/release` run
1333
- - entering release flow sets target row to `unreleased`
1334
- - successful finalization transitions same row to `released`
1335
- - no non-target sprint row mutation
1336
-
1337
- Fail-safe reason codes:
1338
- - `RELEASE_SPRINT_UNRESOLVED`
1339
- - `LEGACY_NOTES_SPRINT_UNRESOLVED`
1340
- - `QUEUE_ENTRY_MISSING`
1341
- - `NOTES_REF_MISSING`
1342
- - `STATUS_TRANSITION_INVALID`
1343
-
1344
- Mismatch and unresolved-sprint policy:
1345
- - fail closed for finalization when sprint identity or queue/notes metadata is
1346
- inconsistent
1347
- - preserve existing notes artifacts by default (non-destructive)
1348
- - do not auto-reconcile by deleting/rebuilding unrelated sprint history
1349
- - include remediation steps in queue/state and rerun `/release` after correction
1350
-
1351
- ## Post-QA release issue workflow (US-0042)
1352
-
1353
- When `/release` finds a blocker after QA has passed, document it in a dedicated
1354
- release findings artifact (separate from QA findings):
1355
-
1356
- - Canonical artifact: `sprints/Sxxxx/release-findings.md`
1357
- - Canonical handoff back to implementation: `handoffs/release_to_dev.md`
1358
-
1359
- Required release-findings content:
1360
- - gate status (`PASS|BLOCKED`)
1361
- - blocking and non-blocking findings
1362
- - deterministic reason code(s)
1363
- - evidence refs
1364
- - remediation steps and rerun criteria
1365
-
1366
- Boundary rule:
1367
- - QA-phase defects remain in `sprints/Sxxxx/qa-findings.md`.
1368
- - Post-QA release-gate defects must be recorded in
1369
- `sprints/Sxxxx/release-findings.md`.
1370
-
1371
- ## Backlog reconciliation invariant (US-0043)
1372
-
1373
- At release finalization boundary, target sprint stories must be synchronized in
1374
- `docs/product/backlog.md` using canonical release evidence precedence.
1375
-
1376
- Contract:
1377
- - Scope is target sprint stories only (no global backlog mutation).
1378
- - If release evidence is PASS, set story status to `DONE` and reconcile
1379
- acceptance checkboxes to checked state.
1380
- - If sprint is `released` but backlog story state remains contradictory
1381
- (`OPEN`/unchecked), fail safe with reason code `BACKLOG_STATUS_DRIFT`.
1382
- - Record remediation guidance and evidence refs in release artifacts before rerun.
1383
-
1384
- ## Canonical status ownership and normalization guard (US-0045)
1385
-
1386
- Canonical owner:
1387
- - `docs/product/backlog.md` is the authority for story status (`OPEN|DONE`).
1388
- - `docs/product/acceptance.md` and `docs/engineering/state.md` are derived views.
1389
-
1390
- Deterministic reconciliation rules:
1391
- 1. Read canonical story status from backlog.
1392
- 2. Validate target sprint release evidence for status transitions.
1393
- 3. Reconcile derived acceptance/state views from canonical backlog status.
1394
- 4. Keep mutation scope target-scoped only; never broad-rewrite unrelated stories.
1395
-
1396
- One-time normalization procedure:
1397
- - Run an initial normalization pass for historically drifted stories.
1398
- - Write all changed rows to `docs/engineering/status-normalization-report.md`
1399
- including prior values, resolved values, evidence references, and timestamp.
1400
- - On future runs, append only delta entries; do not rewrite historical report rows.
1401
-
1402
- Fail-safe reason codes:
1403
- - `BACKLOG_STATUS_DRIFT`: release evidence contradicts backlog/AC state.
1404
- - `CANONICAL_STATUS_CONFLICT`: canonical backlog state conflicts with derived
1405
- status resolution at reconciliation boundary.
1406
-
1407
- ## Lifecycle QA matrix (US-0041)
1408
-
1409
- Use this matrix to validate end-to-end installer/CLI lifecycle behavior:
1410
-
1411
- | Scenario | Primary command path | Coverage location | Required evidence |
1412
- |---|---|---|---|
1413
- | 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 |
1414
- | Overwrite + backup | `its-magic --mode overwrite --backup` and direct installer | `tests/run-tests.ps1`, `tests/run-tests.sh` | Backup snapshot contains overwritten framework file |
1415
- | 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 |
1416
- | 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 |
1417
- | Negative path | invalid mode/args | `tests/run-tests.ps1`, `tests/run-tests.sh` | Deterministic non-zero fail-fast behavior |
1418
- | Platform parity subset | npm/brew/choco CI jobs | `.github/workflows/ci.yml` | Lifecycle subset passes on all three runners |
1419
-
1420
- ## Scratchpad example upgrade contract (US-0057 / DEC-0039 / DEC-0057)
1421
-
1422
- `its-magic --mode upgrade` treats `.cursor/scratchpad.local.example.md` as
1423
- framework-owned and `.cursor/scratchpad.local.md` as user-owned.
1424
-
1425
- Expected deterministic outcome:
1426
- - Framework-owned example is refreshed to latest release contract **before** baseline
1427
- materialization runs in `installer.py --scratchpad-postinstall` (**DEC-0057** ordering).
1428
- - User local scratchpad remains preserved without overwrite.
1429
- - Installer output reports manifest copy status for the example file where applicable
1430
- (`added|updated|unchanged`) **and** `[SCRATCHPAD_LAYER]` diagnostics from post-install
1431
- (`example_refresh`, `baseline_materialize` / `baseline_skip`, `user_local` preserved).
1432
- - CI regression: `python scripts/check-scratchpad-pair-parity.py --repo <root>` exit `0`
1433
- when active and `template/` baseline/example pairs share the same automation `KEY=`
1434
- set and catalog `#` headers from `# Core behavior` (**US-0075** **AC-11**).
1435
-
1436
- ## Scratchpad delivery Model B (US-0073 / DEC-0055)
1437
-
1438
- - Install manifest ships `.cursor/scratchpad.local.example.md` (framework catalog)
1439
- but **does not** list `.cursor/scratchpad.md` as a copied file. The installer
1440
- **materializes** `.cursor/scratchpad.md` from the packaged template when absent
1441
- (`missing`, `interactive`, `upgrade`) or refreshes it on `overwrite`.
1442
- - Merge precedence for automation readers: **local > materialized baseline > example**
1443
- (same invariant as `DEC-0055`).
1444
- - Post-install validation fails closed with `[SCRATCHPAD_MERGE_ERROR]` /
1445
- `[SCRATCHPAD_MATERIALIZE_ERROR]` when layers are missing or required keys are
1446
- empty after merge (`US-0073` `AC-4`).
1447
- - `installer.ps1` / `installer.sh` delegate materialize+validate to
1448
- `python installer.py --scratchpad-postinstall` (Python 3 required on PATH).
1449
- - Recovery: `python installer.py --scratchpad-postinstall --target <repo> --mode missing`
1450
- (or re-run a full install).
1451
-
1452
- ## Deterministic artifact ordering and write discipline (US-0058 / DEC-0040)
1453
-
1454
- Canonical policy source:
1455
- - `docs/engineering/artifact-ordering-policy.md`
1456
-
1457
- Required write discipline:
1458
- - `docs/engineering/state.md`: append-bottom checkpoint writes only.
1459
- - `docs/product/backlog.md`: sorted-canonical story ordering by numeric `US-xxxx`.
1460
- - `docs/product/acceptance.md`: sorted-canonical row ordering aligned to backlog.
1461
- - Handoff surfaces use explicit policy (`prepend-top` or `append-bottom`) per
1462
- matrix and command contract.
1463
-
1464
- Fail-safe contract:
1465
- - Missing/ambiguous placement anchors fail closed with
1466
- `ARTIFACT_ORDERING_ANCHOR_AMBIGUOUS`.
1467
- - Non-monotonic `state.md` checkpoint timestamps fail closed with
1468
- `STATE_TIMESTAMP_NON_MONOTONIC`.
1469
- - No partial mutation on fail-safe path.
1470
- - Re-run without semantic changes must be ordering-idempotent.
1471
-
1472
- ## Cross-phase artifact ownership guard (US-0061 / DEC-0043)
1473
-
1474
- Canonical policy source:
1475
- - `docs/engineering/artifact-ownership-policy.md`
1476
-
1477
- Required ownership discipline:
1478
- - Each phase may mutate only its declared owned scopes for target context.
1479
- - Cross-phase non-owned section rewrite/deletion is forbidden by default.
1480
- - `docs/engineering/architecture.md` is history-preserving: append new story
1481
- sections or mutate target section only; unrelated story-section deletion is
1482
- prohibited.
1483
-
1484
- Fail-safe contract:
1485
- - Ownership violations fail closed with `PHASE_OWNERSHIP_VIOLATION`.
1486
- - Missing evidence on override-authorized mutation path fails closed with
1487
- `PHASE_OVERRIDE_EVIDENCE_MISSING`.
1488
- - Architecture history deletion detection fails with
1489
- `ARCH_HISTORY_DELETION_DETECTED`.
1490
- - No partial mutation on fail-safe path.
1491
-
1492
- Execution guidance:
1493
- - Local baseline: run `sh tests/run-tests.sh` (or `powershell -ExecutionPolicy Bypass -File tests/run-tests.ps1`).
1494
- - Packaging smoke: run npm local tests in `packaging/npm/`.
1495
- - CI evidence: inspect `npm-test`, `brew-test`, and `choco-test` job logs.
1496
-
1497
- ## Intake runtime capability and single-writer safety (US-0059 / DEC-0041)
1498
-
1499
- `/intake` enforces deterministic runtime preflight and drift safety before
1500
- artifact mutation.
1501
-
1502
- Capability preflight:
1503
- - Required role capability: `po` subagent.
1504
- - Default policy: fail fast when unavailable with
1505
- `SUBAGENT_CAPABILITY_UNAVAILABLE`.
1506
- - Fallback policy is explicit only:
1507
- - `INTAKE_SUBAGENT_FALLBACK=deny` (default): no silent fallback.
1508
- - `INTAKE_SUBAGENT_FALLBACK=allow`: explicit operator opt-in for fallback path.
1509
-
1510
- Single-writer drift safety:
1511
- - Intake run binds a deterministic writer/run identity (`writer_id`,
1512
- `intake_run_id`) to target artifacts.
1513
- - Self-write updates for the active writer/run are valid and must not trigger
1514
- concurrent drift blockers.
1515
- - External concurrent conflicting writes fail safe with
1516
- `INTAKE_CONCURRENT_WRITER_DETECTED`.
1517
- - Fail-safe path performs no partial overwrite.
1518
-
1519
- ## Project run steps
1520
-
1521
- ### Prerequisites
1522
-
1523
- ### Local run
1524
-
1525
- ### Tests
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
+ ## User-visible internal metadata guard (US-0071 / DEC-0053)
129
+
130
+ **Goal:** keep planning-shaped identifiers out of **operator-visible software
131
+ channels** (CLI/installer/validate-and-push strings), while they remain valid in
132
+ internal documentation trees and in source comments that are not emitted to
133
+ users.
134
+
135
+ ### Forbidden tokens (user-visible channels only)
136
+
137
+ Match planning-shaped tokens:
138
+
139
+ - `US-[0-9]{4}`
140
+ - `DEC-[0-9]{4}`
141
+ - `R-[0-9]{4}`
142
+
143
+ ### Inclusive scan roots (deterministic)
144
+
145
+ From repository root, the checker walks **only**:
146
+
147
+ - `bin/**` (`*.js`)
148
+ - `installer.py`, `installer.ps1`, `installer.sh`
149
+ - `packaging/**` (`*.js`, `*.py`, `*.ps1`, `*.sh`)
150
+ - `scripts/validate-and-push.ps1`, `scripts/validate-and-push.sh`
151
+
152
+ Paths outside this set are **not** scanned by this tool (for example `docs/**`,
153
+ `.cursor/**`, `sprints/**`, `handoffs/**`, `decisions/**` remain free to use
154
+ story/decision/research IDs). If a new operator-visible deliverable is added
155
+ outside these roots, extend the scan list or you risk
156
+ `METADATA_SANITIZATION_SCOPE_AMBIGUOUS` classification during review.
157
+
158
+ ### Command
159
+
160
+ ```bash
161
+ python scripts/check-user-visible-metadata.py
162
+ python scripts/check-user-visible-metadata.py --json
163
+ ```
164
+
165
+ ### Reason codes (minimum)
166
+
167
+ - `USER_VISIBLE_INTERNAL_METADATA_DETECTED` — forbidden token matched inside a
168
+ scanned user-visible string/literal.
169
+ - `METADATA_SANITIZATION_POLICY_MISSING` — checker entrypoint missing or
170
+ unusable.
171
+ - `METADATA_SANITIZATION_SCOPE_AMBIGUOUS` — cannot classify whether a path
172
+ belongs in inclusive scan roots; treat as fail-closed until the runbook table
173
+ is updated.
174
+
175
+ ### Findings / remediation (contract)
176
+
177
+ On failure, diagnostics must cite **evidence_ref** (`path:line:column` when
178
+ available), **token class** (`US` \| `DEC` \| `R`), and remediation: remove the
179
+ token from operator-visible strings; keep traceability in allowlisted internal
180
+ artifacts or non-emitting comments per `DEC-0053`.
181
+
182
+ ## Guided intake mode (US-0033)
183
+
184
+ Intake interaction behavior is controlled by one switch in
185
+ `.cursor/scratchpad.md`:
186
+
187
+ - `INTAKE_GUIDED_MODE=1` (default): guided PO behavior
188
+ - targeted follow-up questions only when acceptance is ambiguous
189
+ - at least one viable option/alternative before recommendation
190
+ - explicit user decision authority
191
+ - intake-time research persisted in `docs/engineering/research.md`
192
+ - `INTAKE_GUIDED_MODE=0`: low-touch intake
193
+ - no proactive follow-up/options/research overhead unless user asks
194
+ - duplicate/overlap backlog check remains mandatory baseline safety
195
+
196
+ ## Intake decomposition and risk-aware questioning (US-0051)
197
+
198
+ When guided mode is enabled (`INTAKE_GUIDED_MODE=1`), intake adds bounded
199
+ decomposition and adaptive questioning behavior:
200
+
201
+ - Run deterministic breadth/risk heuristics before persisting a story:
202
+ - feature/workflow-step count
203
+ - cross-cutting impact surface
204
+ - acceptance breadth
205
+ - risk/unknown dependency surface
206
+ - If heuristics indicate broad/high-risk intake:
207
+ - propose bounded multi-story decomposition (typically 2-5 stories)
208
+ - prefer vertical-slice/workflow-step stories with independent user value
209
+ - avoid technical-layer-only splits unless user explicitly requests
210
+ - Preserve user authority explicitly before persistence:
211
+ - user can accept, merge, or adjust the proposed split
212
+ - Keep adaptive questioning concise and bounded:
213
+ - ask ambiguity-driven questions plus risk-triggered questions
214
+ - stop after bounded rounds or when acceptance confidence is sufficient
215
+ - Low-touch compatibility (`INTAKE_GUIDED_MODE=0`):
216
+ - no forced decomposition
217
+ - single-story default unless user explicitly asks for decomposition
218
+ - duplicate/overlap safety remains mandatory
219
+ - Traceability requirement:
220
+ - intake output must capture decomposition/questioning evidence in
221
+ `docs/product/backlog.md`, `docs/product/acceptance.md`, and
222
+ `handoffs/po_to_tl.md`.
223
+
224
+ ## Mandatory intake question packs and persistence coverage gate (US-0068 / DEC-0050)
225
+
226
+ Intake persistence is fail-closed unless required topic coverage is complete (or
227
+ bounded assumptions are explicitly confirmed).
228
+
229
+ Deterministic pack contract:
230
+
231
+ - `first-intake-pack` (first/new/broad intake)
232
+ - required topics:
233
+ - `users_problem`
234
+ - `runtime_target_environment`
235
+ - `language_framework_runtime`
236
+ - `architecture_preference`
237
+ - `ui_design_expectations`
238
+ - `security_compliance`
239
+ - `non_functional_priorities`
240
+ - `scope_timeline`
241
+ - `small-intake-pack` (small follow-up intake)
242
+ - required topics:
243
+ - `outcome_success_criteria`
244
+ - `impacted_components`
245
+ - `constraints_compatibility_risks`
246
+ - `required_tests_acceptance_checks`
247
+ - `done_definition`
248
+
249
+ Pack selection and coverage behavior:
250
+
251
+ - Select exactly one pack per intake write path.
252
+ - Unknown/ambiguous stack or project cues must fail closed to
253
+ `first-intake-pack`.
254
+ - Required coverage must be evaluated before writing
255
+ `docs/product/backlog.md` or `docs/product/acceptance.md`.
256
+ - Incomplete required coverage blocks persistence unless assumptions are
257
+ explicitly confirmed.
258
+
259
+ Deterministic fail-closed reason codes:
260
+
261
+ - `INTAKE_REQUIRED_TOPIC_MISSING`
262
+ - `INTAKE_REQUIRED_PACK_INCOMPLETE`
263
+ - `INTAKE_ASSUMPTION_CONFIRMATION_REQUIRED`
264
+ - `INTAKE_PERSISTENCE_BLOCKED`
265
+
266
+ Required remediation output on block:
267
+
268
+ - include `missing_topics`
269
+ - provide targeted follow-up prompts for missing required topics
270
+ - request explicit assumption confirmation when assumptions are used
271
+
272
+ Required persisted intake evidence fields:
273
+
274
+ - `asked_topics`
275
+ - `missing_topics`
276
+ - `assumptions_confirmed`
277
+
278
+ ## First-intake full-plan coverage gate (US-0081 / DEC-0064)
279
+
280
+ For first/new/broad intake (`selected_pack=first-intake-pack`), persistence is
281
+ additionally blocked unless complete-plan coverage is machine-verifiable.
282
+
283
+ Required coverage contract fields:
284
+
285
+ - `plan_area_inventory[]` with unique stable `plan_area_id` values
286
+ - `plan_area_coverage[]` with exactly one row per `plan_area_id`
287
+ - xor mapping per row: `story_ids[]` or `deferred_ref` + `deferred_reason`
288
+ - `coverage_complete=true` only when derived validation succeeds
289
+
290
+ Coverage diagnostics (under umbrella `INTAKE_PERSISTENCE_BLOCKED`):
291
+
292
+ - `INTAKE_PLAN_COVERAGE_MISSING`
293
+ - `INTAKE_PLAN_AREA_ID_INVALID`
294
+ - `INTAKE_PLAN_COVERAGE_CONTRACT_INVALID`
295
+ - `INTAKE_PLAN_DEFERRED_REF_MISSING`
296
+
297
+ Guided and low-touch parity:
298
+
299
+ - `INTAKE_GUIDED_MODE=1` and `INTAKE_GUIDED_MODE=0` must run the same
300
+ first-intake complete-plan validator path.
301
+ - Low-touch may reduce optional prompts but cannot bypass complete-plan coverage
302
+ validation.
303
+
304
+ ## Interactive intake evidence validation (US-0078 / DEC-0060 / US-0083 / DEC-0067)
305
+
306
+ - Interactive intake evidence validation (US-0078 / DEC-0060) — automation/harness anchor; extended rules for **US-0083** / **DEC-0067** follow in this section.
307
+
308
+ **US-0078** adds machine-verifiable **`topic_coverage`** rows, canonical **`ie:`** refs
309
+ (**DEC-0060**), asked-vs-covered enforcement, and **`assumption_confirmation_ref`**
310
+ binding before backlog/acceptance writes.
311
+
312
+ - Validator entrypoints: `python scripts/intake_evidence_validate.py --self-test`;
313
+ `python scripts/intake_evidence_validate.py --file <bundle.json>` or `--stdin`.
314
+ - Library: `scripts/intake_evidence_lib.py` (shared rules for tests and tooling).
315
+ - Regression: `tests/intake_evidence_fixtures_test.py` (R-0055 **AC-8** matrix tiers A/B),
316
+ invoked from `tests/run-tests.ps1` / `tests/run-tests.sh` §26k.
317
+ - **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).
318
+ - **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.
319
+ - **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).
320
+ - **Guided** and **low-touch** (`INTAKE_GUIDED_MODE=0`) share the **same** pre-persistence
321
+ validation pipeline; mandatory pack evidence is never skipped.
322
+ - Legacy intake evidence without **`ie:`** refs remains **grandfathered** for display until the
323
+ next intake-driven mutation, which must supply full evidence (**DEC-0060** §5).
324
+ - **Delegated required-topic path (US-0083 / DEC-0067)**:
325
+ - Allowed: `topic_coverage[].satisfied_by=delegation_ref` with required
326
+ `delegation_scope`, `delegation_rationale`, `delegation_confidence` (`low|medium|high`).
327
+ - Missing delegation fields fail closed with `INTAKE_DELEGATION_EVIDENCE_MISSING`.
328
+ - Malformed delegation values or invalid `ie:` binding fail closed with
329
+ `INTAKE_DELEGATION_EVIDENCE_INVALID`.
330
+ - Non-delegated unresolved required topics remain unchanged fail-closed
331
+ (`INTAKE_REQUIRED_TOPIC_MISSING` path).
332
+ - **Repetitive-ask suppression with accounting (US-0083 AC-1)**:
333
+ - When equivalent evidence already exists, avoid re-asking by recording row-level
334
+ `evidence_source=equivalent_evidence_ref` plus `equivalent_evidence_ref`.
335
+ - Required-topic accounting remains explicit through `topic_coverage` rows.
336
+
337
+ ## Bug issues (US-0079 / DEC-0061)
338
+
339
+ - **Canonical ids**: **`BUG-####`** in **`docs/product/backlog.md`** **`## Bug issues (canonical)`**; status literals **`OPEN`** | **`DONE`** only illegal values fail **`BUG_VALIDATION_STATUS_INVALID`**.
340
+ - **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).
341
+ - **Ordering**: bug blocks sorted by id ascending — violation → **`BUG_VALIDATION_ORDER_INVERSION`**.
342
+ - **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).
343
+ - **Acceptance reconciliation**: **`docs/product/acceptance.md`** **`## Bug acceptance (canonical)`** checkbox rows must match backlog bug status — drift codes **`BUG_RECONCILE_ACCEPTANCE_*`**.
344
+ - **Commands**:
345
+ - `python scripts/bug_issue_validate.py --self-test`
346
+ - `python scripts/bug_issue_validate.py --backlog docs/product/backlog.md [--check-acceptance] [--print-next-id]`
347
+ - `python scripts/intake_bug_routing_guard.py --kind story|bug --file <path>` (or **`--stdin`**)
348
+ - **Regression**: `tests/bug_issue_fixtures_test.py` (R-0056 Tier A/B), invoked from **`tests/run-tests.ps1` / `tests/run-tests.sh`** §26L.
349
+
350
+ ## Optional ID namespace bootstrap (US-0052)
351
+
352
+ Fresh-project ID bootstrap is optional and default-off in
353
+ `.cursor/scratchpad.md`:
354
+
355
+ - `ID_NAMESPACE_BOOTSTRAP=0|1` (default `0`)
356
+
357
+ Deterministic behavior:
358
+
359
+ - If `ID_NAMESPACE_BOOTSTRAP=1`, evaluate freshness eligibility before creating
360
+ new IDs:
361
+ - no `US-` IDs in `docs/product/backlog.md`
362
+ - no `DEC-` IDs in `docs/engineering/decisions.md` (and no existing
363
+ `decisions/DEC-*.md`)
364
+ - no `R-` IDs in `docs/engineering/research.md`
365
+ - If eligible, first created IDs start at:
366
+ - `US-0001` for intake stories
367
+ - `DEC-0001` for architecture decisions
368
+ - `R-0001` for research entries
369
+ - If not eligible (or mode is off), continue from highest existing ID in each
370
+ namespace.
371
+ - Never rewrite/renumber historical IDs.
372
+ - If bootstrap is requested but ineligible, emit deterministic diagnostic
373
+ `ID_BOOTSTRAP_NOT_FRESH` and continue with highest-existing continuation.
374
+
375
+ ## Context compaction and token profile mode (US-0053 / DEC-0035)
376
+
377
+ Tiered token-cost control is explicit and defaulted in `.cursor/scratchpad.md`:
378
+
379
+ - `TOKEN_PROFILE=lean|balanced|full` (default `balanced`)
380
+
381
+ Deterministic profile semantics:
382
+
383
+ - `lean`: reduce non-critical overhead defaults (for example aggressive research,
384
+ autonomous loops, broad-context retrieval), while preserving mandatory
385
+ quality/release gates.
386
+ - `balanced`: preserve current capability profile with moderate overhead.
387
+ - `full`: maximize context breadth and autonomy for complex/high-uncertainty work.
388
+
389
+ Manual override precedence:
390
+
391
+ - Explicit flag values remain authoritative for that flag.
392
+ - If a flag is explicitly set, it overrides profile defaults.
393
+ - Profile changes must not disable mandatory gate contracts
394
+ (`/qa`, `/verify-work`, `/release`).
395
+
396
+ ### Token-cost evidence + comparability (US-0080 / DEC-0062)
397
+
398
+ - **Fresh context**: spawn **new** subagents per `/auto` phase; avoid carrying prior chat
399
+ reasoning as phase input.
400
+ - **`start-from`**: use **`/auto start-from=<canonical_phase_id>`** when resuming so the
401
+ schedule intersection matches materialized **`resolved_phase_plan`** (**`DEC-0052`**).
402
+ - **`TOKEN_PROFILE`**: `lean` lowers default automation breadth; does **not** remove
403
+ isolation, strict-proof, role, or release gates.
404
+ - **Metrics**: append-only **`handoffs/token_cost_runs/<orchestrator_run_id>.md`** (or
405
+ **`.jsonl`**); copy path into **`token_cost_evidence_ref`** on **`state.md`** checkpoints.
406
+ - **AC-2**: compare **`cache_read_tokens`** only when **`run_class_hash`** matches; else
407
+ **`TOKEN_COST_RUN_CLASS_MISMATCH`**.
408
+ - **CI/repo checks**: `python scripts/check_token_cost_parity.py --repo .` (manifest-listed
409
+ active/`template/` pairs); **`tests/run-tests.ps1`** / **`tests/run-tests.sh`** §26M.
410
+
411
+ Context compaction policy:
412
+
413
+ - `docs/engineering/state.md` is a compact hot surface for current execution
414
+ context and recent checkpoints.
415
+ - Historical state packs belong in `docs/engineering/state-archive/` and are
416
+ append-only/non-destructive.
417
+ - `docs/engineering/decisions.md` is a compact index with bounded summaries and
418
+ canonical links to full records in `decisions/DEC-xxxx.md`.
419
+ - Enforced rollover thresholds:
420
+ - `STATE_HOT_MAX_LINES` (default `1200`)
421
+ - `STATE_HOT_MAX_CHECKPOINTS` (default `80`)
422
+ - `PO_TO_TL_HOT_MAX_LINES` (default `800`)
423
+ - `PO_TO_TL_HOT_MAX_SECTIONS` (default `60`)
424
+ - `ARCH_HOT_MAX_LINES` (default `3500`)
425
+ - `ARCH_HOT_MAX_STORY_SECTIONS` (default `120`)
426
+ Thresholds resolve from merged `.cursor/scratchpad.md` +
427
+ `.cursor/scratchpad.local.md` (DEC-0054 triad contract).
428
+ When a cap is exceeded, the mutating phase must run rollover **before**
429
+ completion or fail closed (no successful completion with an oversize hot
430
+ surface).
431
+
432
+ ### Triad hot-surface enforcement (DEC-0054)
433
+
434
+ Canonical hot/archive surfaces:
435
+
436
+ - `docs/engineering/state.md` → `docs/engineering/state-archive/state-pack-*.md`
437
+ - `handoffs/po_to_tl.md` → `handoffs/archive/po-to-tl-pack-*.md`
438
+ - `docs/engineering/architecture.md` →
439
+ `docs/engineering/architecture-archive/architecture-pack-*.md`
440
+
441
+ Operator commands:
442
+
443
+ ```bash
444
+ python scripts/enforce-triad-hot-surface.py --check
445
+ python scripts/enforce-triad-hot-surface.py --rollover
446
+ ```
447
+
448
+ - `--check` verifies all three surfaces are within policy (CI-safe).
449
+ - `--rollover` archives oldest contiguous units into the next deterministic pack
450
+ name; reruns are idempotent when already within caps.
451
+ - Successful rollover records a verification tuple:
452
+ `boundary`, `moved`, `retained` (counts / lines), `pack_ref`.
453
+
454
+ Rollover fail-safe reason codes:
455
+
456
+ - `STATE_ARCHIVE_BOUNDARY_AMBIGUOUS`
457
+ - `STATE_ARCHIVE_WRITE_FAILED`
458
+ - `STATE_ARCHIVE_VERIFICATION_FAILED`
459
+ - `STATE_ARCHIVE_REQUIRED`
460
+ - `ARTIFACT_HOT_SURFACE_OVERSIZE`
461
+ - `CONTEXT_BUDGET_EXCEEDED`
462
+
463
+ ### Minimal-read defaults by phase (bounded escalation)
464
+
465
+ Read `docs/engineering/phase-context.md` first, then the **required** paths for
466
+ your phase. If unresolved, expand once to the **single** archive pack named in
467
+ the latest verification tuple for that surface. Do not load entire archive
468
+ directories by default.
469
+
470
+ | Phase | Required reads (default) | Combined line budget (guidance) |
471
+ |-------|--------------------------|----------------------------------|
472
+ | `/intake` | `phase-context.md`, target story in `docs/product/backlog.md`, `handoffs/po_to_tl.md` (tail) | ≤ 900 lines |
473
+ | `/discovery` | `phase-context.md`, `docs/product/vision.md` (story notes), `handoffs/po_to_tl.md` (tail) | ≤ 900 lines |
474
+ | `/research` | `phase-context.md`, `docs/engineering/research.md` (target entry), `docs/product/backlog.md` (target story) | ≤ 800 lines |
475
+ | `/architecture` | `phase-context.md`, `docs/engineering/architecture.md` (target story section), `docs/engineering/research.md` | ≤ 1200 lines |
476
+ | `/sprint-plan` | `phase-context.md`, `docs/engineering/architecture.md` (target story), `handoffs/tl_to_dev.md` | ≤ 1000 lines |
477
+ | `/plan-verify` | `phase-context.md`, `sprints/Sxxxx/tasks.md`, `docs/product/backlog.md` (ACs) | ≤ 900 lines |
478
+ | `/execute` | `phase-context.md`, `sprints/Sxxxx/tasks.md`, `handoffs/tl_to_dev.md` | ≤ 800 lines |
479
+ | `/qa` | `phase-context.md`, `sprints/Sxxxx/`, `tests/report.md` | ≤ 900 lines |
480
+ | `/verify-work` | `phase-context.md`, `sprints/Sxxxx/uat.json`, QA findings | ≤ 600 lines |
481
+ | `/release` | `phase-context.md`, release queue + sprint release findings | ≤ 700 lines |
482
+ | `/refresh-context` | `phase-context.md`, `docs/engineering/state.md` (tail), `docs/product/backlog.md` (status) | 900 lines |
483
+ | `/auto` (resolver) | `phase-context.md`, `handoffs/resume_brief.md`, `docs/engineering/state.md` (tail) | ≤ 700 lines |
484
+
485
+ If the default set is insufficient, escalate with an explicit note citing
486
+ `pack_ref`. Unbounded broad reads fail closed with `CONTEXT_BUDGET_EXCEEDED`.
487
+
488
+ `/ask` retrieval policy:
489
+
490
+ - Use question-scoped narrow reads first.
491
+ - Expand context in bounded steps only when unresolved.
492
+ - If unresolved after bounded expansion, answer with explicit "not found in
493
+ current artifacts" rather than broad speculative reads.
494
+
495
+ ## Configurable multi-target publish mode (US-0054 / DEC-0036)
496
+
497
+ Post-release publish orchestration is configurable and default-safe:
498
+
499
+ - `RELEASE_PUBLISH_MODE=disabled|confirm|auto` (default `confirm`)
500
+ - `RELEASE_TARGETS_FILE=docs/engineering/release-targets.json`
501
+ - `RELEASE_TARGETS_DEFAULT=` optional comma-separated default target IDs
502
+
503
+ Target schema contract:
504
+
505
+ - Canonical target config file: `docs/engineering/release-targets.json`
506
+ - Supported target types:
507
+ - `npm`, `choco`, `brew`, `git`, `docker`, `cloud`
508
+ - `custom` (generic command target)
509
+ - `ssh` (host/user/port/auth reference + remote command)
510
+ - Connectivity metadata (for operator-safe remote/local context):
511
+ - `runtime.mode` (`local|remote`)
512
+ - endpoint fields (`domainEnv|ipEnv|hostEnv`, `port`, `protocol`)
513
+ - optional ingress metadata (`traefik.enabled`, `router`, `entrypoint`, `tls`)
514
+ - optional `dockerOverSsh` object for ssh/dockerd remote execution context
515
+ - Each target entry must define deterministic fields:
516
+ - `id` (stable unique target ID)
517
+ - `type`
518
+ - `enabled` (`true|false`)
519
+ - `order` (deterministic execution ordering)
520
+ - execution details (`command` for non-ssh, `remoteCommand` + host/user/auth refs for `ssh`)
521
+
522
+ Safety contract:
523
+
524
+ - Mandatory release gates remain unchanged and must pass before any publish
525
+ target execution.
526
+ - `confirm` mode requires explicit operator approval before publish execution.
527
+ - Sensitive fields must be env-referenced (`*Env` keys); inline secret literals
528
+ are not allowed.
529
+ - Invalid target config must fail fast with deterministic diagnostics and no
530
+ partial side effects.
531
+ - Invalid remote connectivity metadata must fail fast with
532
+ `REMOTE_CONNECTIVITY_CONFIG_INVALID`.
533
+ - Canonical operator endpoint summary is written to
534
+ `docs/engineering/runtime-connectivity.md` with sanitized values only.
535
+
536
+ ## Release operator hints contract (US-0067 / DEC-0049)
537
+
538
+ Release outputs must include deterministic operator-ready hints with mandatory
539
+ section order:
540
+
541
+ `Run -> Connect -> Verify -> Credentials -> Known Issues`
542
+
543
+ Required fields for canonical sprint notes
544
+ (`handoffs/releases/Sxxxx-release-notes.md`):
545
+
546
+ - `Run`: `start_command`, `runtime_mode`, `runtime_context_ref`
547
+ - `Connect`: `service_url`, `service_port`, `health_endpoint`
548
+ - `Verify`: deterministic `verification_steps`, `expected_health_signal`
549
+ - `Credentials`: env-reference-only source refs and expected value-source
550
+ location guidance (never inline secrets)
551
+ - `Known Issues`: concise issue list or explicit `None`
552
+
553
+ Legacy pointer contract (`handoffs/release_notes.md`):
554
+
555
+ - keep concise latest run/connect/verify summary only
556
+ - always link to canonical sprint-scoped release notes for full details
557
+
558
+ Fail-closed reason codes:
559
+
560
+ - `RELEASE_OPERATOR_HINTS_MISSING`
561
+ - `RELEASE_OPERATOR_HINTS_AMBIGUOUS`
562
+ - `RELEASE_OPERATOR_HINTS_SECRET_EXPOSURE`
563
+
564
+ ## Deterministic status reconciliation mode (US-0055 / DEC-0037)
565
+
566
+ Use the dedicated reconciliation command to normalize status drift across
567
+ canonical and derived artifacts:
568
+
569
+ - Command: `/status-reconcile`
570
+ - Canonical source: `docs/product/backlog.md` (story `Status`)
571
+ - Derived surfaces: `docs/product/acceptance.md`, `docs/engineering/state.md`,
572
+ `handoffs/resume_brief.md`
573
+
574
+ Deterministic behavior:
575
+
576
+ - Detects mismatches (for example DONE + unchecked ACs, acceptance drift, resume drift).
577
+ - Applies target-scoped reconciliation only to mismatched story blocks/rows.
578
+ - Preserves canonical ownership; derived artifacts reconcile to backlog status.
579
+ - Updates `handoffs/resume_brief.md` to next OPEN story and intended phase.
580
+ - Writes auditable rows to `docs/engineering/status-normalization-report.md`.
581
+
582
+ Reason-code baseline:
583
+
584
+ - `STATUS_RECONCILE_APPLIED`
585
+ - `STATUS_RECONCILE_NOOP`
586
+ - `STATUS_RECONCILE_MISSING_INPUT`
587
+ - `STATUS_RECONCILE_CANONICAL_CONFLICT`
588
+ - `STATUS_RECONCILE_PHASE_AMBIGUOUS`
589
+ - `STATUS_RECONCILE_EVIDENCE_MISSING`
590
+
591
+ ## Optional cross-repo observability mode (US-0034)
592
+
593
+ Compatibility visibility is optional and default-off in `.cursor/scratchpad.md`:
594
+
595
+ - `CROSS_REPO_OBSERVABILITY=0|1` (default `0`)
596
+ - `COMPATIBILITY_GATE_ON_CRITICAL=0|1` (default `1`)
597
+ - `COMPATIBILITY_SOURCES=` monitored source declarations
598
+
599
+ Default-off behavior:
600
+ - With `CROSS_REPO_OBSERVABILITY=0`, `/intake`, `/architecture`, `/execute`,
601
+ and `/qa` add zero required compatibility overhead.
602
+
603
+ Enabled behavior (`CROSS_REPO_OBSERVABILITY=1`):
604
+ - Use canonical artifacts:
605
+ - `docs/engineering/compatibility-report.md`
606
+ - `docs/engineering/compatibility-signals.md`
607
+ - `docs/engineering/manifests/registry.manifest.yaml`
608
+ - `docs/engineering/manifests/repo.manifest.yaml`
609
+ - Record findings with severity, affected modules, evidence refs, and
610
+ recommended actions.
611
+ - If unresolved critical findings exist and
612
+ `COMPATIBILITY_GATE_ON_CRITICAL=1`, trigger decision gate before release
613
+ progression (`COMPATIBILITY_CRITICAL_OPEN`).
614
+
615
+ ## Optional component-scoped execution mode (US-0035)
616
+
617
+ Component-scoped execution is optional and default-off:
618
+
619
+ - `COMPONENT_SCOPE_MODE=0|1` (default `0`)
620
+ - `TARGET_COMPONENTS=` comma-separated scoped component IDs
621
+
622
+ Default-off behavior:
623
+ - With `COMPONENT_SCOPE_MODE=0`, workflow phases add zero required scope
624
+ overhead.
625
+
626
+ Enabled behavior (`COMPONENT_SCOPE_MODE=1`):
627
+ - Declare scope in `docs/engineering/component-scope.md`:
628
+ - `target_components[]`
629
+ - `non_target_components[]`
630
+ - `allowed_interface_touch[]`
631
+ - `/sprint-plan` tasks declare `target_component_ids` and
632
+ `expected_impacted_interfaces`.
633
+ - `/execute` enforces scope-first behavior.
634
+ - `/qa` verifies unaffected-component checks and records evidence in
635
+ `docs/engineering/component-scope-report.md`.
636
+ - If unapproved out-of-scope impact remains open, release must stop at decision
637
+ gate (`COMPONENT_SCOPE_VIOLATION_UNAPPROVED`).
638
+
639
+ ## Optional spec-pack documentation mode (US-0031)
640
+
641
+ Spec-pack mode is optional and default-off in `.cursor/scratchpad.md`:
642
+
643
+ - `SPEC_PACK_MODE=0|1` (default `0`)
644
+
645
+ Default-off behavior:
646
+ - With `SPEC_PACK_MODE=0`, `/intake`, `/architecture`, `/execute`, `/qa`, and
647
+ `/release` add no required spec-pack steps (zero overhead).
648
+
649
+ Enabled behavior (`SPEC_PACK_MODE=1`):
650
+
651
+ **Canonical names and locations** (per story):
652
+ - Design Concept: `docs/engineering/spec-pack/<story_id>-design-concept.md`
653
+ - CRS (Customer/Product Requirements Summary): `docs/engineering/spec-pack/<story_id>-crs.md`
654
+ - Technical Specification: `docs/engineering/spec-pack/<story_id>-technical-specification.md`
655
+
656
+ **Traceability**: Backlog story ID (e.g. `US-0031`) maps 1:1 to the three
657
+ artifacts above. Handoffs and state should reference these paths when
658
+ spec-pack mode is enabled.
659
+
660
+ **Minimum required sections** (completeness is testable; validation blocks
661
+ only when enabled and a required section is missing or empty):
662
+
663
+ - Design Concept: `# Summary`, `# Goals`, `# Non-goals`, `# Key decisions`
664
+ - CRS: `# Purpose`, `# Scope`, `# Acceptance criteria ref`
665
+ - Technical Specification: `# Overview`, `# Components`, `# Interfaces`, `# Non-functional`
666
+
667
+ **Validation**: When `SPEC_PACK_MODE=1`, release gate checks that for the
668
+ target sprint story, all three artifacts exist and each required section
669
+ above is present and non-empty. If not, release is blocked with reason code
670
+ `SPEC_PACK_INCOMPLETE` and remediation guidance.
671
+
672
+ **Ownership (role/phase)**:
673
+ - Design Concept: Tech Lead, `/architecture` (create/update).
674
+ - CRS: PO, `/intake` (create/update for new story); Tech Lead may extend in
675
+ architecture.
676
+ - Technical Specification: Tech Lead, `/architecture` (create); Dev, `/execute`
677
+ (update when implementation details change).
678
+
679
+ ## Optional user-guide documentation mode (US-0032)
680
+
681
+ User-guide mode is optional and default-off in `.cursor/scratchpad.md`:
682
+
683
+ - `USER_GUIDE_MODE=0|1` (default `0`)
684
+
685
+ Default-off behavior:
686
+ - With `USER_GUIDE_MODE=0`, `/intake`, `/architecture`, `/sprint-plan`, `/execute`,
687
+ `/qa`, and `/release` add no required user-guide steps or blocking checks (zero overhead).
688
+
689
+ Enabled behavior (`USER_GUIDE_MODE=1`):
690
+
691
+ **Canonical location and naming** (per feature story):
692
+ - One guide per feature story: `docs/user-guides/US-xxxx.md` (e.g. `docs/user-guides/US-0032.md`).
693
+ - Story ID `US-xxxx` is the stable identifier; create/update the guide when the story is in scope.
694
+
695
+ **Minimum required schema** (structural validation only; completeness is testable):
696
+ - `# Purpose`
697
+ - `# Prerequisites`
698
+ - `# Usage steps`
699
+ - `# Example`
700
+ - `# Limitations`
701
+ - `# Troubleshooting`
702
+
703
+ **Traceability**: Story ID maps 1:1 to the user-guide artifact. Handoffs and release
704
+ context should reference `docs/user-guides/US-xxxx.md` for the target story when
705
+ user-guide mode is enabled.
706
+
707
+ **Validation**: When `USER_GUIDE_MODE=1`, release gate checks that for the target
708
+ sprint story, the guide file exists at the canonical path and each required section
709
+ above is present and non-empty. If not, release is blocked with reason code
710
+ `USER_GUIDE_INCOMPLETE` and remediation guidance (create or complete the guide).
711
+
712
+ **Boundary with spec-pack (US-0031)**: User guides are end-user facing how-to
713
+ documentation only. They do not duplicate Design Concept, CRS, or Technical
714
+ Specification content; user guides may reference spec-pack artifacts but must not
715
+ replicate their ownership or technical scope. See runbook/README separation guidance.
716
+
717
+ ## Legacy DONE-story drift detection and guard (US-0049)
718
+
719
+ Stories that are DONE in backlog but lack aligned acceptance/traceability or
720
+ release representation are in **legacy drift**. US-0049 adds detection, bounded
721
+ repair, and an ongoing guard at release/reconciliation (DEC-0031).
722
+
723
+ **Detection rule** A story is in legacy drift when:
724
+ - Backlog status is **DONE**, and
725
+ - At least one of:
726
+ - Acceptance checklist item for that story is **unchecked**
727
+ - Traceability index or `docs/engineering/state.md` **lacks an entry** for that story
728
+ - Release artifacts (e.g. `handoffs/releases/Sxxxx-release-notes.md`, queue row)
729
+ **lack clear representation** for that story
730
+
731
+ **Bounded repair**: Only stories matching the rule above may be mutated; no broad
732
+ rewrite of unrelated backlog/acceptance/state/release artifacts.
733
+
734
+ **Canonical audit artifact**: `docs/engineering/legacy-drift-audit.md`
735
+ - Required fields per entry: story ID, prior acceptance state, prior traceability
736
+ state, resolved state(s), reason code, evidence reference.
737
+ - Append-only; one-time backfill and ongoing guard append entries when drift is
738
+ detected and repaired (or when guard blocks and reports).
739
+
740
+ **Reason-code vocabulary** (with remediation):
741
+ - `BACKLOG_DONE_ACCEPTANCE_UNCHECKED` Backlog DONE but acceptance item unchecked.
742
+ Remediation: set acceptance checkbox from canonical release/state evidence or run one-time backfill.
743
+ - `BACKLOG_DONE_TRACEABILITY_MISSING` Backlog DONE but traceability/state lacks entry.
744
+ Remediation: add traceability row in `docs/engineering/state.md` from backlog/release evidence or run backfill.
745
+ - `BACKLOG_DONE_RELEASE_ARTIFACT_MISSING` Backlog DONE but release artifacts lack representation.
746
+ Remediation: ensure release notes or queue row exists for the story’s sprint or run backfill.
747
+
748
+ **One-time backfill mode**: Explicit trigger (e.g. dedicated check or `/memory-audit`-related path).
749
+ - Run detection once over all DONE stories; for each legacy-drift story, perform
750
+ target-scoped repair and append an entry to `docs/engineering/legacy-drift-audit.md`.
751
+ - Idempotent when no drift: no mutations; report empty or "no drift".
752
+ - Only stories matching the detection rule are mutated.
753
+
754
+ **Ongoing guard**: At release or reconciliation boundary (or dedicated check).
755
+ - When legacy drift is detected, either **block** with explicit reason code and
756
+ remediation, or **repair** target-scoped and append audit entry (policy documented).
757
+ - Behavior is deterministic; operators get explicit diagnostics.
758
+
759
+ ## Memory drift auditing
760
+
761
+ Run `/memory-audit` at key workflow checkpoints to verify artifact consistency:
762
+
763
+ - **Pre-handoff**: before writing `handoffs/dev_to_qa.md` or any role handoff.
764
+ - **Pre-QA**: before running `/qa` or `/verify-work`.
765
+ - **Pre-release**: before running `/release`.
766
+ - **Ad-hoc**: after external code changes, long pauses, or whenever artifacts
767
+ feel stale.
768
+
769
+ Output: `docs/engineering/memory-drift-report.md` — an advisory report with
770
+ severity-classified findings. The command is read-only and non-blocking.
771
+
772
+ Interpreting results:
773
+ - **high**: artifact contradicts repository state — fix before next handoff/release.
774
+ - **medium**: artifact is likely stale fix before release.
775
+ - **low**: minor inconsistency — fix during `/refresh-context` or next sprint.
776
+
777
+ Template drift findings (active vs `template/`) are listed for reference only
778
+ and belong to US-0017 scope.
779
+
780
+ Follow-up commands: `/refresh-context`, `/sprint-plan`, `/verify-work`, `/intake`.
781
+
782
+ ## Remote execution validation contract
783
+
784
+ Remote execution is mode-aware and default-off:
785
+
786
+ - `REMOTE_EXECUTION=0`: skip remote-config validation entirely (zero overhead).
787
+ - `REMOTE_EXECUTION=1`: validate `.cursor/remote.json` before remote activities;
788
+ fail fast on first blocking issue.
789
+
790
+ Validation classes (remote-enabled mode):
791
+
792
+ 1. Presence: config file exists at `REMOTE_CONFIG` (default `.cursor/remote.json`)
793
+ 2. Syntax: JSON parses cleanly
794
+ 3. Contract: required fields/types/enums
795
+ 4. Semantics: `defaultTarget` points to an existing enabled target; target ids
796
+ are unique
797
+ 5. Security: no inline secret-like literals; env-var refs only for sensitive values
798
+
799
+ Required contract summary:
800
+
801
+ - Root: `version` (integer), `defaultTarget` (string), `targets` (array)
802
+ - Target: `id` (string), `type` (`docker|ssh|vm`), `enabled` (boolean),
803
+ `host` (string), `port` (integer `1..65535`), `workspaceRoot` (string)
804
+ - Optional auth: `auth.mode` (`none|env`); if `env`, use `*Env` references
805
+
806
+ Error message format (actionable, fail-fast):
807
+
808
+ - `[REMOTE_CONFIG_ERROR] <path>: expected <rule>, got <actual>. Fix: <hint>.`
809
+
810
+ Operator troubleshooting:
811
+
812
+ - Missing config file:
813
+ - Copy from `template/.cursor/remote.json`, or disable remote mode.
814
+ - Malformed JSON:
815
+ - Fix syntax (commas/brackets/quotes), then retry.
816
+ - Invalid value or enum:
817
+ - Correct field value to the documented contract.
818
+ - Security violation (inline secret-like literal):
819
+ - Replace with env-var reference fields (`tokenEnv`, `passwordEnv`,
820
+ `privateKeyPathEnv`, ...).
821
+
822
+ ### Manual vs automation routing (US-0086)
823
+
824
+ Manual and automation modes are intentionally separate:
825
+
826
+ - Manual mode (`AUTO_REMOTE_AUTOMATION_PROFILE=off`) keeps local-first behavior.
827
+ No automatic remote routing is allowed, and `TEST_COMMAND` is never silently
828
+ rerouted to remote targets.
829
+ - Automation mode (`AUTO_REMOTE_AUTOMATION_PROFILE=deterministic_v1`) may route
830
+ to Docker/SSH/local targets using deterministic precedence.
831
+ - Explicit NL intent literal is constrained to `start container <target_id>`.
832
+ Unknown or disabled targets fail closed.
833
+
834
+ Deterministic fail-closed reason codes:
835
+
836
+ - `REMOTE_AUTOMATION_MODE_OFF`
837
+ - `REMOTE_TARGET_UNKNOWN`
838
+ - `REMOTE_TARGET_DISABLED`
839
+ - `REMOTE_TARGET_UNROUTABLE`
840
+
841
+ Security continuity (`US-0085` / `DEC-0071`) remains mandatory in all modes:
842
+
843
+ - Never read `.env` from agent automation.
844
+ - Never print secret values in command output, logs, handoffs, or state.
845
+ - Names-only evidence format is required (`secret_surface=names_only`).
846
+
847
+ ### Remote-routing evidence tuple (execute/qa/release)
848
+
849
+ When automation routing is used, include this tuple in handoffs/state artifacts:
850
+
851
+ - `target_id`
852
+ - `environment_label`
853
+ - `automation_profile`
854
+ - `routing_source` (`explicit_intent|heuristic_fallback|local_default`)
855
+ - `secret_surface=names_only`
856
+
857
+ If routing is not used (mode off/local default), still record:
858
+
859
+ - `target_id=local-default`
860
+ - `environment_label=local`
861
+ - `automation_profile=off`
862
+ - `routing_source=local_default`
863
+ - `secret_surface=names_only`
864
+
865
+ ### Published npm `installer.sh` / POSIX dash (US-0084)
866
+
867
+ - **Symptom**: `set: Illegal option -` on an early line when running `its-magic` or
868
+ `sh installer.sh` on Debian/Ubuntu (**`/bin/sh`** → **dash**).
869
+ - **Common causes**: bash-only `set` options (`pipefail`, `-o errexit`, `-u` bundles)
870
+ on the **unconditional** startup path, or **CRLF** line endings in the file that
871
+ ships from npm.
872
+ - **`sh` vs `bash`**: the Unix CLI path uses **`sh` + `installer.sh`** (**BUG-0004** /
873
+ **DEC-0068**). Do not assume bash for the first lines of **`installer.sh`**.
874
+ - **Remediation**:
875
+ - Upgrade to an **its-magic** build that includes **US-0084** (LF + POSIX guards).
876
+ - Normalize to **LF** only (e.g. `dos2unix installer.sh`, or fix checkout —
877
+ root **`.gitattributes`** uses `*.sh text eol=lf`).
878
+ - Reinstall from npm after verifying maintainer gates:
879
+ `python scripts/guard_installer_publish.py` (also **`npm run guard:installer`**
880
+ / **`prepublishOnly`**).
881
+ - **Normative**: **`docs/engineering/architecture.md`** **`# US-0084`**.
882
+
883
+ ### Automated checks (US-0084)
884
+
885
+ - `python tests/installer_shell_bug0004_test.py` — CR/LF rejection, forbidden
886
+ `set` tokens, optional **`dash -n`** when **`dash`** is on **`PATH`**.
887
+ - `python scripts/guard_installer_publish.py` — same checks for publish/CI
888
+ (**`prepublishOnly`**).
889
+ - `python scripts/remote_config_summary.py` with **`REMOTE_EXECUTION=1`**,
890
+ read-only summary of **`REMOTE_CONFIG`** (default **`.cursor/remote.json`**);
891
+ stdout is **names-only** (no secret values). **`DEC-0070`**: when
892
+ **`REMOTE_EXECUTION=0`**, the helper exits **0** and skips validation
893
+ (stderr skip reason).
894
+
895
+ ### Optional deterministic CI routing recipe (US-0086)
896
+
897
+ Use this only when CI needs explicit remote-target hints; keep it opt-in.
898
+
899
+ 1. Define explicit path filters:
900
+ - container surfaces: `Dockerfile*`, `docker-compose*.yml`, container scripts
901
+ - ssh/runtime infra surfaces: deployment ssh scripts, host runtime scripts
902
+ 2. Route using explicit matrix labels (`local`, `docker`, `ssh`) with no
903
+ implicit fallback logic outside documented defaults.
904
+ 3. Keep manual mode unchanged: if `AUTO_REMOTE_AUTOMATION_PROFILE=off`, run
905
+ local path and do not apply remote routing.
906
+ 4. Emit names-only evidence (`target_id`, `environment_label`,
907
+ `automation_profile`, `routing_source`, `secret_surface=names_only`) into
908
+ CI logs/artifacts.
909
+
910
+ ## Runtime QA autopilot contract (US-0065 / DEC-0047)
911
+
912
+ Generated-project validation requires runtime proof, not static checks alone.
913
+
914
+ Mandatory runtime stage order:
915
+
916
+ `startup -> readiness/connectivity -> log scan -> bounded retry -> verdict`
917
+
918
+ Deterministic runtime failure reason codes:
919
+
920
+ - `RUNTIME_STARTUP_FAILED`
921
+ - `RUNTIME_ENDPOINT_UNREACHABLE`
922
+ - `RUNTIME_LOG_CRITICAL_DETECTED`
923
+ - `RUNTIME_RETRY_BUDGET_EXHAUSTED`
924
+ - `RUNTIME_STACK_PROFILE_UNRESOLVED`
925
+
926
+ Runtime evidence schema (record in QA findings):
927
+
928
+ - `runtime_startup_command`
929
+ - `runtime_stack_profile` (`node|python|go|java|dotnet`)
930
+ - `runtime_mode` (`local|remote`)
931
+ - `runtime_health_target`
932
+ - `runtime_health_result`
933
+ - `runtime_log_summary` (severity counts and key error signals)
934
+ - `runtime_retry_count`
935
+ - `runtime_retry_ledger` (`attempt`, `delay_ms`, `outcome`)
936
+ - `runtime_final_verdict`
937
+ - `runtime_reason_code`
938
+ - `runtime_evidence_refs`
939
+
940
+ Bounded retry policy:
941
+
942
+ - retry only transient startup/connectivity failures
943
+ - enforce configured max-attempt cap (`attempt <= max`)
944
+ - fail fast on non-transient critical runtime log signals
945
+
946
+ Stack/profile resolution:
947
+
948
+ - Minimum supported runtime profiles: Node, Python, Go, Java, .NET.
949
+ - Unknown or ambiguous profile must fail closed with
950
+ `RUNTIME_STACK_PROFILE_UNRESOLVED`.
951
+
952
+ Webapp verification path (when applicable):
953
+
954
+ - include browser-surface load validation
955
+ - capture console error summary and failed network request summary
956
+ - add these signals to `runtime_log_summary` and evidence refs
957
+
958
+ Optional debug escalation (bounded):
959
+
960
+ - use for reproducible runtime failures only
961
+ - keep instrumentation bounded and reversible
962
+ - record applied debug steps and explicit cleanup confirmation
963
+
964
+ ## Generated test scaffolding + auto-run contract (US-0066 / DEC-0048)
965
+
966
+ Generated app projects require deterministic baseline test scaffolding and
967
+ automatic QA test execution evidence.
968
+
969
+ Detection/profile contract:
970
+
971
+ - Resolve one deterministic stack profile from:
972
+ `node|python|go|java|dotnet` (minimum supported).
973
+ - If profile cannot be resolved, fail closed with
974
+ `TEST_SCAFFOLD_STACK_UNRESOLVED`.
975
+ - If detected stack is outside supported baseline set, fail closed with
976
+ `TEST_SCAFFOLD_UNSUPPORTED_STACK`.
977
+
978
+ Generation contract (`/execute`):
979
+
980
+ - Generate only missing baseline assets for:
981
+ - unit tests
982
+ - integration tests
983
+ - acceptance tests
984
+ - Use stable scaffold paths so reruns are idempotent (no duplicate file churn).
985
+ - Record generated paths and actions in execution evidence.
986
+ - If generation fails, fail closed with `TEST_SCAFFOLD_GENERATION_FAILED`.
987
+
988
+ Runbook command wiring:
989
+
990
+ - `TEST_COMMAND` baseline is stack-aware and deterministic.
991
+ - Non-destructive precedence is mandatory:
992
+ - preserve user-authored non-empty `TEST_COMMAND`,
993
+ - write baseline command only when `TEST_COMMAND` is missing/unset.
994
+
995
+ QA auto-run evidence contract (`/qa`):
996
+
997
+ - Execute generated baseline tests automatically.
998
+ - Record evidence fields:
999
+ - `generated_test_stack_profile`
1000
+ - `generated_test_command`
1001
+ - `generated_test_result`
1002
+ - `generated_test_output_ref`
1003
+ - `generated_test_paths_ref`
1004
+ - `generated_test_reason_code`
1005
+
1006
+ Runtime boundary with US-0065:
1007
+
1008
+ - Generated static test PASS is required but never sufficient for QA PASS.
1009
+ - Runtime-autopilot verdict remains mandatory; non-starting apps cannot PASS QA.
1010
+
1011
+ ## Auto continuation resume contract
1012
+
1013
+ `/auto` continuation uses deterministic phase resolution (DEC-0017):
1014
+
1015
+ 1. explicit `/auto start-from=<phase>`
1016
+ 2. `handoffs/resume_brief.md`
1017
+ 3. conservative `docs/engineering/state.md` fallback
1018
+ 4. fail-fast
1019
+
1020
+ Canonical `start-from` phase IDs:
1021
+ `intake`, `discovery`, `research`, `architecture`, `sprint-plan`,
1022
+ `plan-verify`, `execute`, `qa`, `verify-work`, `release`, `refresh-context`.
1023
+
1024
+ Conflict and stale-source policy:
1025
+ - Explicit valid override wins.
1026
+ - If no override and `resume_brief` conflicts with `state`, fail fast.
1027
+ - If `resume_brief` exists but is stale/unparseable, fail fast.
1028
+ - Use state fallback only when `resume_brief` is absent.
1029
+
1030
+ Fail-fast error format:
1031
+ - `[AUTO_RESUME_ERROR] <code>: <summary>. Source=<source>. Fix: <action>.`
1032
+
1033
+ Required error codes:
1034
+ - `INVALID_START_FROM`
1035
+ - `RESUME_BRIEF_MISSING`
1036
+ - `RESUME_BRIEF_STALE`
1037
+ - `RESUME_BRIEF_UNPARSEABLE`
1038
+ - `RESUME_STATE_CONFLICT`
1039
+ - `STATE_PHASE_AMBIGUOUS`
1040
+ - `STATE_PHASE_UNRECOVERABLE`
1041
+
1042
+ Breadcrumbs required for inspectability:
1043
+ - `resolution_source`, `resolved_start_phase`, `stop_reason`, `stop_phase`,
1044
+ `timestamp`.
1045
+ - Record in `docs/engineering/state.md`; update `handoffs/resume_brief.md` when
1046
+ auto stops before completion.
1047
+
1048
+ Stop-condition preservation:
1049
+ - continuation does not bypass decision gates, missing-input blockers,
1050
+ pause requests, or loop max cycle limits.
1051
+
1052
+ ## Per-phase subagent isolation evidence (US-0048 / DEC-0029)
1053
+
1054
+ Per-phase fresh-context isolation is enforced with auditable, fail-closed
1055
+ evidence.
1056
+
1057
+ ### Canonical evidence store and locations
1058
+
1059
+ - Canonical evidence store: `docs/engineering/state.md` (append-only checkpoints).
1060
+ - Cross-references are allowed in phase artifacts and handoffs:
1061
+ - `handoffs/dev_to_qa.md`, `handoffs/qa_to_dev.md`
1062
+ - `handoffs/resume_brief.md` (pause/resume provenance)
1063
+ - `sprints/Sxxxx/summary.md`, `sprints/Sxxxx/qa-findings.md`, `sprints/Sxxxx/uat.*`,
1064
+ `sprints/Sxxxx/release-findings.md`
1065
+
1066
+ ### Required schema (one entry per phase run)
1067
+
1068
+ Each phase run must append an isolation evidence entry containing:
1069
+
1070
+ - `phase_id`: canonical phase id (`intake|discovery|research|architecture|sprint-plan|plan-verify|execute|qa|verify-work|release|refresh-context|pause|resume`)
1071
+ - `role`: subagent role executing the phase (`po|curator|tech-lead|dev|qa|release|security`)
1072
+ - `fresh_context_marker`: a marker unique to the fresh subagent context for this phase run
1073
+ - `timestamp`: ISO UTC timestamp
1074
+ - `evidence_ref`: canonical path to the primary artifact written/validated for the phase run
1075
+
1076
+ ### Gate behavior (fail closed)
1077
+
1078
+ - Missing evidence blocks progression with `PHASE_CONTEXT_ISOLATION_MISSING`.
1079
+ - Invalid schema/fields blocks progression with `ISOLATION_EVIDENCE_INVALID`.
1080
+ - Stale evidence (reused marker across runs or older than the resumed boundary)
1081
+ blocks progression with `ISOLATION_EVIDENCE_STALE`.
1082
+ - Orchestrator executing phase work without spawning a fresh subagent context is
1083
+ a hard violation: `PHASE_CONTEXT_ISOLATION_VIOLATION`.
1084
+
1085
+ Remediation (all cases): re-run the affected phase in a fresh subagent context
1086
+ and write new isolation evidence before proceeding.
1087
+
1088
+ ### Reason codes and remediation (US-0048)
1089
+
1090
+ - `PHASE_CONTEXT_ISOLATION_MISSING`: no isolation evidence entry found for a
1091
+ required phase run. Fix: rerun the phase in a fresh subagent and append the
1092
+ required evidence fields.
1093
+ - `ISOLATION_EVIDENCE_INVALID`: evidence entry present but missing required
1094
+ fields or contains invalid `phase_id`/`role`. Fix: rerun the phase and write a
1095
+ corrected entry.
1096
+ - `ISOLATION_EVIDENCE_STALE`: evidence is reused across runs/cycles or predates
1097
+ the latest resume boundary. Fix: rerun the phase and write a new
1098
+ `fresh_context_marker`.
1099
+ - `PHASE_CONTEXT_ISOLATION_VIOLATION`: phase work was performed without a fresh
1100
+ subagent context (for example orchestrator performed phase writes). Fix: stop,
1101
+ revert unsafe artifacts if needed, rerun the phase correctly, and ensure
1102
+ orchestration-only behavior.
1103
+
1104
+ ## Strict runtime proof contract (US-0056 / DEC-0038)
1105
+
1106
+ Strict runtime proof augments artifact-level isolation evidence. `/auto`,
1107
+ `/verify-work`, and `/release` must validate runtime attestation tuples at phase
1108
+ boundaries before continuation/finalization.
1109
+
1110
+ Required runtime attestation tuple fields:
1111
+
1112
+ - `orchestrator_run_id`
1113
+ - `runtime_proof_id` (unique per phase run)
1114
+ - `phase_id`
1115
+ - `role`
1116
+ - `proof_issued_at` (ISO UTC / RFC3339)
1117
+ - `proof_ttl_seconds`
1118
+ - `proof_hash`
1119
+
1120
+ Deterministic fail-closed reason codes:
1121
+
1122
+ - `RUNTIME_PROOF_MISSING`
1123
+ - `RUNTIME_PROOF_INVALID`
1124
+ - `RUNTIME_PROOF_REUSED`
1125
+ - `RUNTIME_PROOF_STALE`
1126
+ - `RUNTIME_PROOF_AMBIGUOUS_LINK`
1127
+
1128
+ Boundary behavior:
1129
+
1130
+ - Missing/invalid/reused/stale/ambiguous runtime proof blocks progression.
1131
+ - Release finalization must consume strict runtime proof in addition to existing
1132
+ isolation evidence checks.
1133
+ - Pause/resume provenance must reference latest valid strict-proof boundary.
1134
+
1135
+ ## Strict `/auto` phase→role enforcement (US-0069 / DEC-0051)
1136
+
1137
+ `/auto` must treat phase roles as a **fail-closed admission and checkpoint
1138
+ contract** (see `decisions/DEC-0051.md` and `/auto` command text).
1139
+
1140
+ ### Canonical matrix and scratchpad alternates
1141
+
1142
+ - Fixed phase→role defaults are documented in `/auto` (for example `execute` →
1143
+ `dev`, `release` → `release`).
1144
+ - Alternate phases resolve **one** expected role via scratchpad:
1145
+ - `AUTO_ROLE_RESEARCH`: `po` \| `tech-lead` (empty → default `tech-lead`)
1146
+ - `AUTO_ROLE_PLAN_VERIFY`: `qa` \| `tech-lead` (empty → default `qa`)
1147
+ - `AUTO_ROLE_REFRESH_CONTEXT`: `curator` \| `po` (empty → default `curator`)
1148
+ - Non-empty values outside the allowed set fail closed (no unrelated-role
1149
+ substitution).
1150
+
1151
+ ### Preflight and checkpoints
1152
+
1153
+ - **Preflight (before spawn)**: resolve expected role; verify the required
1154
+ subagent capability exists. Missing capability → `PHASE_ROLE_CAPABILITY_MISSING`
1155
+ with `phase_id`, expected role, observed result, remediation. Do not spawn a
1156
+ substitute role.
1157
+ - **Post-completion**: isolation evidence `role` and strict-proof `role` must
1158
+ both match the same preflight-resolved role; else `PHASE_ROLE_MISMATCH`.
1159
+ - **`proof_hash`**: SHA-256 over sorted-key JSON of the strict-proof tuple fields
1160
+ (`orchestrator_run_id`, `runtime_proof_id`, `phase_id`, `role`,
1161
+ `proof_issued_at`, `proof_ttl_seconds`).
1162
+
1163
+ ### Execute default deny and rare override
1164
+
1165
+ - Default: `execute` requires `dev`.
1166
+ - Override allowed only when **both** hold:
1167
+ `AUTO_EXECUTE_ROLE_OVERRIDE=allowed_non_dev_execute` and
1168
+ `EXECUTE_OVERRIDE_GOVERNANCE_REF` references a parseable approved exception (for
1169
+ example `DEC-xxxx` or a documented state anchor).
1170
+
1171
+ ### Continuation parity
1172
+
1173
+ - Every `/auto` run recomputes role policy and preflight; `start-from`, fresh
1174
+ `resume_brief`, and `state.md` fallback cannot bypass the gate with stale role
1175
+ intent alone.
1176
+
1177
+ ## Configurable `/auto` phase plan (US-0070 / DEC-0052)
1178
+
1179
+ `/auto` schedules a **resolved ordered phase plan** from merged scratchpad
1180
+ before any spawn. See `decisions/DEC-0052.md` and `/auto` command text.
1181
+
1182
+ ### Selectors (exactly one active mode)
1183
+
1184
+ - `AUTO_PHASE_PLAN=full` (default when unset and no other selector is set)
1185
+ - `AUTO_PHASE_EXCLUDE=<csv>` — remove listed canonical phase ids from `full`
1186
+ - `AUTO_PHASE_INCLUDE=<csv>` — only listed ids, re-sorted into canonical lifecycle order
1187
+ - `AUTO_PHASE_PROFILE=<name>` expand a named profile (unknown → fail closed)
1188
+ - `AUTO_PHASE_HIGH_RISK_ACK=<token>` required when a documented high-risk profile demands acknowledgment
1189
+
1190
+ Conflicting selectors `PHASE_POLICY_CONFLICT` (no plan materialization).
1191
+
1192
+ ### Materialization and gates
1193
+
1194
+ - Expand apply **non-skippable reinstatement** (`qa`, `verify-work`, `release`,
1195
+ plus evidence-chain closure per `/auto`) → intersect **`start-from` / resume
1196
+ anchor** with the plan → **empty intersection** →
1197
+ `START_FROM_PHASE_PLAN_EMPTY_INTERSECTION`.
1198
+ - Record `resolved_phase_plan`, `skipped_phases` (+ reasons such as
1199
+ `policy_exclude`, `non_skippable_gate`), and **phase boundary status** entries
1200
+ in continuation breadcrumbs (`docs/engineering/state.md`).
1201
+ - **Backlog-drain**, **bulk execute**, and **team scope** paths must **reload**
1202
+ scratchpad phase-selection inputs and **recompute** the plan at each bounded
1203
+ boundary (no silent revival of omitted phases).
1204
+
1205
+ ### Failure codes (deterministic)
1206
+
1207
+ - `PHASE_POLICY_CONFLICT`
1208
+ - `PHASE_PLAN_UNKNOWN_PHASE`
1209
+ - `PHASE_PLAN_EMPTY_INCLUDE`
1210
+ - `PHASE_PLAN_UNKNOWN_PROFILE`
1211
+ - `PHASE_PLAN_INVALID_AUTO_PHASE_PLAN`
1212
+ - `PHASE_PLAN_HIGH_RISK_ACK_REQUIRED`
1213
+ - `START_FROM_PHASE_PLAN_EMPTY_INTERSECTION`
1214
+
1215
+ ## Optional backlog-drain auto mode (US-0044)
1216
+
1217
+ `/auto` can optionally continue across multiple planned stories when explicitly
1218
+ enabled in scratchpad.
1219
+
1220
+ Controls:
1221
+ - `AUTO_BACKLOG_DRAIN=0|1` (default `0`)
1222
+ - `AUTO_BACKLOG_MAX_STORIES=<n>` (default `1`)
1223
+ - `AUTO_BACKLOG_ON_BLOCK=stop|skip` (default `stop`)
1224
+ - `AUTO_STORY_SELECTION=priority_then_backlog_order` (default)
1225
+
1226
+ Semantics:
1227
+ - With `AUTO_BACKLOG_DRAIN=0`, keep current single-segment continuation behavior.
1228
+ - With `AUTO_BACKLOG_DRAIN=1`, select next eligible OPEN story
1229
+ deterministically and run full lifecycle story-by-story until bounded limit,
1230
+ no eligible stories, or a mandatory stop condition.
1231
+ - Decision gates remain mandatory and pause progression until user decision.
1232
+
1233
+ ## Targeted bug auto drain (US-0087)
1234
+
1235
+ Use **`/auto`** with an explicit **OPEN** bug binding when you want defect-scoped
1236
+ continuation instead of story **`AUTO_BACKLOG_DRAIN`**.
1237
+
1238
+ **Canonical argv** (exact literals; no aliases in v1):
1239
+
1240
+ - **`bug-target=BUG-####`** — single **OPEN** bug from **`docs/product/backlog.md`**
1241
+ **`## Bug issues (canonical)`** (example: **`bug-target=BUG-0007`**).
1242
+ - **`bug-target=all-open`** — walk all **OPEN** bugs in ascending **numeric**
1243
+ **`BUG-####`** order (optional per-run cap: **`AUTO_BUG_MAX_ITEMS`**).
1244
+
1245
+ **Scratchpad** (merged; default-off — see **`.cursor/scratchpad.md`** and
1246
+ **`template/.cursor/scratchpad.local.example.md`**):
1247
+
1248
+ - **`AUTO_BUG_QUEUE`**, **`AUTO_BUG_TARGET`**, **`AUTO_BUG_MAX_ITEMS`**, **`AUTO_BUG_ON_BLOCK`**
1249
+
1250
+ **Mutex**: do **not** enable **`AUTO_BACKLOG_DRAIN=1`** and **`AUTO_BUG_QUEUE=1`**
1251
+ together **without** an explicit **`bug-target=`** argv on that invocation — fail
1252
+ closed **`AUTO_SCHEDULER_CONFLICT`**. Supply **`bug-target=`** to select the bug
1253
+ scheduler for that run (normative detail: **`docs/engineering/auto-orchestration-reference.md`**
1254
+ **Optional bug-queue mode (US-0087)** and **`docs/engineering/architecture.md`**
1255
+ **`# US-0087`**).
1256
+
1257
+ **Fail-closed codes**: **`AUTO_BUG_QUEUE_EMPTY`**, **`AUTO_BUG_TARGET_UNKNOWN`**,
1258
+ **`AUTO_BUG_TARGET_NOT_OPEN`**, **`AUTO_SCHEDULER_CONFLICT`** plus spawn-only
1259
+ orchestrator rules (**`BUG-0006`**, **`US-0069`**, **`AUTO_ORCHESTRATOR_PHASE_EXECUTION`**;
1260
+ see **`.cursor/commands/auto.md`**).
1261
+
1262
+ ## Continuous `/auto` + backlog drain (US-0088)
1263
+
1264
+ **Goal:** a single `/auto` run (or documented equivalent outer driver) advances
1265
+ through all intersected lifecycle phases until a deterministic stop, and
1266
+ `AUTO_BACKLOG_DRAIN=1` can continue across multiple OPEN stories without routine
1267
+ operator chatter.
1268
+
1269
+ ### Quick start
1270
+
1271
+ ```
1272
+ /auto # full lifecycle, single story
1273
+ /auto start-from=execute # resume from execute phase
1274
+ ```
1275
+
1276
+ With backlog drain enabled (`.cursor/scratchpad.md`):
1277
+
1278
+ ```
1279
+ AUTO_BACKLOG_DRAIN=1
1280
+ AUTO_BACKLOG_MAX_STORIES=5
1281
+ AUTO_BACKLOG_ON_BLOCK=stop
1282
+ ```
1283
+
1284
+ ### Normative reference
1285
+
1286
+ Multi-phase iteration lives in
1287
+ **`docs/engineering/auto-orchestration-reference.md`** **`## Steps`** item 5
1288
+ (cross-anchor: **"reference Step 5"**). The compact steps in
1289
+ **`.cursor/commands/auto.md`** point to that block unambiguously.
1290
+
1291
+ ### Caps and safety guards
1292
+
1293
+ | Control | Default | Purpose |
1294
+ |---------|---------|---------|
1295
+ | `AUTO_BACKLOG_MAX_STORIES` | `1` | Max stories per drain run |
1296
+ | `AUTO_LOOP_MAX_CYCLES` | `5` | Max execute-QA cycles per story |
1297
+ | `AUTO_PAUSE_REQUEST` | `0` | Set to `1` to request graceful stop at next safe boundary |
1298
+ | `AUTO_PAUSE_POLICY` | `after_phase` | Stop boundary granularity |
1299
+
1300
+ ### Decision gates
1301
+
1302
+ Decision gates are **never** suppressed — even when `AUTO_QUIET=1`. When a gate
1303
+ fires, the run stops and waits for operator resolution before continuing.
1304
+
1305
+ ### `AUTO_QUIET` (default off)
1306
+
1307
+ Set `AUTO_QUIET=1` in `.cursor/scratchpad.md` to suppress **routine** per-phase
1308
+ success chatter. Non-suppressible notifications:
1309
+
1310
+ - `decision_gate`
1311
+ - Errors / `missing_input`
1312
+ - `pause_request`
1313
+ - `loop_max`
1314
+ - `blocked`
1315
+ - Segment handoff / drain advance
1316
+
1317
+ `AUTO_QUIET` is **orthogonal** to `TOKEN_PROFILE` (**DEC-0035** / **US-0080**):
1318
+ `TOKEN_PROFILE` controls context breadth and token cost, not notification policy.
1319
+
1320
+ ### Outer-driver equivalence (AC-1, Option B)
1321
+
1322
+ When a single Cursor `/auto` invocation cannot schedule multiple subagent turns,
1323
+ operators may use an outer driver (script or manual re-invocation with
1324
+ `start-from` / refreshed `resume_brief`). This is deterministically equivalent
1325
+ when: same phase order, same isolation + strict-proof per phase, same stop
1326
+ reasons, same `resume_brief` + `state.md` refresh at every boundary.
1327
+
1328
+ ### Drain advance behavior
1329
+
1330
+ When `AUTO_BACKLOG_DRAIN=1` and a story reaches its terminal boundary:
1331
+
1332
+ 1. Orchestrator reloads merged scratchpad phase-selection inputs.
1333
+ 2. Orchestrator recomputes the materialized phase plan for the next story.
1334
+ 3. Selects the next eligible OPEN story per `AUTO_STORY_SELECTION`.
1335
+ 4. Runs the full resolved lifecycle for that story until stop or cap.
1336
+
1337
+ Notify operator on segment handoff (non-routine, non-suppressible).
1338
+
1339
+ ### Stop reasons
1340
+
1341
+ `completed`, `decision_gate`, `missing_input`, `pause_request`, `loop_max`,
1342
+ `error`, `blocked`. See the **Deterministic stop matrix** in
1343
+ **`docs/engineering/auto-orchestration-reference.md`** §
1344
+ **Continuous multi-phase execution (US-0088)**.
1345
+
1346
+ ### Troubleshooting
1347
+
1348
+ | Symptom | Likely cause | Fix |
1349
+ |---------|-------------|-----|
1350
+ | Run stops after one phase | Older `/auto` text without continuous semantics | Update to latest; verify **reference Step 5** anchor exists |
1351
+ | `RESUME_BRIEF_STALE` mid-run | Brief not refreshed at phase boundary | Ensure paired `resume_brief` + `state.md` refresh per DEC-0069 |
1352
+ | `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 |
1353
+ | `BACKLOG_MAX_STORIES_REACHED` | Drain cap hit | Increase `AUTO_BACKLOG_MAX_STORIES` or run another `/auto` |
1354
+
1355
+ ## Explicit bulk sprint planning mode (US-0046)
1356
+
1357
+ `/sprint-plan` stays single-scope by default. Bulk planning is opt-in via
1358
+ explicit argument:
1359
+
1360
+ - `/sprint-plan --bulk`
1361
+
1362
+ Deterministic controls from `.cursor/scratchpad.md`:
1363
+ - `SPRINT_BULK_MAX_STORIES` (candidate OPEN stories per run)
1364
+ - `SPRINT_BULK_MAX_SPRINTS` (max generated sprints per run)
1365
+ - `SPRINT_BULK_SELECTION=priority_then_backlog_order`
1366
+
1367
+ Deterministic behavior:
1368
+ - Select eligible OPEN stories by configured selection order.
1369
+ - Generate one or more bounded sprint plans while preserving per-sprint sizing
1370
+ guardrails (`SPRINT_MAX_TASKS`, `SPRINT_AUTO_SPLIT`).
1371
+ - Stop with explicit reason codes when bounded or blocked:
1372
+ - `SPRINT_BULK_MAX_STORIES_REACHED`
1373
+ - `SPRINT_BULK_MAX_SPRINTS_REACHED`
1374
+ - `SPRINT_BULK_NO_ELIGIBLE_STORIES`
1375
+ - `SPRINT_BULK_MISSING_ACCEPTANCE`
1376
+
1377
+ ## Explicit bulk execute mode (US-0047)
1378
+
1379
+ `/auto` remains non-bulk by default. Bulk execution is explicit and can be
1380
+ enabled per run (`/auto --execute-bulk`) or by scratchpad switch.
1381
+
1382
+ Deterministic controls:
1383
+ - `AUTO_EXECUTE_BULK=0|1` (default `0`)
1384
+ - `AUTO_EXECUTE_MAX_ITEMS=<n>` (default `1`)
1385
+ - `AUTO_EXECUTE_ON_BLOCK=stop|skip` (default `stop`)
1386
+ - `AUTO_EXECUTE_SELECTION=planned_then_priority` (default)
1387
+ - `AUTO_TEAM_SCOPE_ENFORCE=0|1` (default `1`)
1388
+
1389
+ Execution semantics:
1390
+ - Select eligible planned items deterministically.
1391
+ - Preserve strict isolation:
1392
+ - fresh subagent per phase
1393
+ - fresh subagent per execute<->QA loop cycle
1394
+ - Enforce bounded stop behavior:
1395
+ - `EXEC_BULK_MAX_ITEMS_REACHED`
1396
+ - `EXEC_BULK_NO_ELIGIBLE_ITEMS`
1397
+ - `EXEC_BULK_ITEM_BLOCKED_STOP`
1398
+ - `EXEC_BULK_ITEM_BLOCKED_SKIPPED`
1399
+
1400
+ Team mode guardrails (`TEAM_MODE=1`):
1401
+ - Capture team context snapshot in breadcrumbs:
1402
+ - `TEAM_MODE`, `TEAM_MEMBER`, `ACTIVE_TASK_IDS`
1403
+ - With enforcement enabled, out-of-scope tasks are never mutated and must emit:
1404
+ - `EXEC_TEAM_SCOPE_BLOCKED` (stop policy)
1405
+ - `EXEC_TEAM_SCOPE_SKIPPED` (skip policy)
1406
+
1407
+ ## Sync policy and guarded auto-push contract (US-0038 / DEC-0018)
1408
+
1409
+ Sync policy controls (from `.cursor/scratchpad.md`):
1410
+ - `SYNC_POLICY_MODE`: `disabled|manual|by_phase|by_milestone|custom_phase_list`
1411
+ - `SYNC_CUSTOM_PHASES`: comma-separated canonical phase IDs for custom mode
1412
+ - `ALLOW_AUTO_PUSH`: `0|1`
1413
+ - `AUTO_PUSH_BRANCH_ALLOWLIST`: comma-separated branches/patterns
1414
+
1415
+ Default-safe behavior:
1416
+ - Default mode is `manual` (non-auto).
1417
+ - `disabled` and `manual` are near-zero-overhead modes (no auto-push attempts).
1418
+ - Unset/invalid mode fails closed to `manual`.
1419
+
1420
+ Phase-boundary-only evaluation:
1421
+ - Evaluate sync eligibility only at completed phase boundaries.
1422
+ - Never evaluate during partial or in-progress work units.
1423
+
1424
+ Guarded auto-push eligibility (all required):
1425
+ 1. Boundary trigger is eligible for current mode.
1426
+ 2. `ALLOW_AUTO_PUSH=1`.
1427
+ 3. QA-first restriction passes (feature work cannot auto-push before QA pass).
1428
+ 4. No unresolved blocking QA findings / unresolved critical issues.
1429
+ 5. Branch safety passes:
1430
+ - protected/default branches denied by default,
1431
+ - allow only explicitly allowlisted branches.
1432
+ 6. Mandatory check chain passes.
1433
+
1434
+ Mandatory pre-push check chain:
1435
+ 1. `TEST_COMMAND` (mandatory baseline)
1436
+ 2. `LINT_COMMAND` (only if configured)
1437
+ 3. `TYPECHECK_COMMAND` (only if configured)
1438
+
1439
+ Rules:
1440
+ - Missing `TEST_COMMAND` blocks push (`TEST_COMMAND_MISSING`).
1441
+ - Failing `TEST_COMMAND` blocks push (`TEST_FAILED`).
1442
+ - Timed-out `TEST_COMMAND` blocks push (`TEST_TIMEOUT`).
1443
+ - Optional check failures block push when configured (`OPTIONAL_CHECK_FAILED`).
1444
+ - Optional checks that are not configured must be reported as `skipped`.
1445
+
1446
+ Deterministic reason-code baseline:
1447
+ - `SYNC_DISABLED`
1448
+ - `MANUAL_MODE_NO_AUTO`
1449
+ - `SYNC_TRIGGER_NOT_ELIGIBLE`
1450
+ - `AUTO_PUSH_NOT_ENABLED`
1451
+ - `PRE_QA_AUTOPUSH_FORBIDDEN`
1452
+ - `BLOCKING_QA_FINDINGS`
1453
+ - `BRANCH_NOT_ALLOWLISTED`
1454
+ - `TEST_COMMAND_MISSING`
1455
+ - `TEST_FAILED`
1456
+ - `TEST_TIMEOUT`
1457
+ - `OPTIONAL_CHECK_FAILED`
1458
+ - `SYNC_PUSHED`
1459
+
1460
+ ## Executable validate-and-push wiring (DEC-0058)
1461
+
1462
+ Scratchpad **`SYNC_*` / `ALLOW_AUTO_PUSH` / `AUTO_PUSH_BRANCH_ALLOWLIST`** are read from the
1463
+ **merged** scratchpad only (installer merge: local → materialized baseline → example; same
1464
+ precedence as installer post-install validation). **`scripts/validate-and-push.ps1`** and
1465
+ **`scripts/validate-and-push.sh`** call **`python scripts/sync_push_gates.py`** for policy;
1466
+ **`docs/engineering/runbook.md`** remains the sole source for **`TEST_COMMAND`** and optional
1467
+ lint/typecheck commands.
1468
+
1469
+ **Operator rule:** changing scratchpad alone does **not** run **`git push`**. Run
1470
+ **`validate-and-push`** (or CI) after an eligible boundary. For **`by_phase`**, **`by_milestone`**,
1471
+ and **`custom_phase_list`**, scheduling is **operator or CI** responsibility.
1472
+
1473
+ **`SYNC_PHASE_BOUNDARY`:** optional environment variable (canonical phase id, case-insensitive).
1474
+ When **`SYNC_POLICY_MODE=custom_phase_list`**, the variable must be set and must appear in
1475
+ **`SYNC_CUSTOM_PHASES`** (comma-separated) or the script exits **`SYNC_TRIGGER_NOT_ELIGIBLE`**.
1476
+
1477
+ **Dry-run:** **`powershell .../validate-and-push.ps1 -DryRun`** or
1478
+ **`bash scripts/validate-and-push.sh --dry-run ...`** runs merge/policy and the runbook check
1479
+ chain, then prints **`SYNC_PUSHED`** without **`git push`**.
1480
+
1481
+ **Branch allowlist matching (`AUTO_PUSH_BRANCH_ALLOWLIST`):** comma-separated entries; each entry
1482
+ is either an exact branch name or a **`fnmatch`** pattern (for example `release/*`). An empty
1483
+ allowlist denies every branch (**`BRANCH_NOT_ALLOWLISTED`**).
1484
+
1485
+ **QA scan (bounded):** files under **`sprints/S####/qa-findings.md`** (four digits). Blocking
1486
+ rules match **`DEC-0058`** §6. **`PRE_QA_AUTOPUSH_FORBIDDEN`** applies on branches other than
1487
+ **`main`** / **`master`** when **no** such **`qa-findings.md`** file exists yet (feature-line
1488
+ signal; see architecture **US-0076**).
1489
+
1490
+ **Python:** merged policy evaluation requires **Python 3** on **`PATH`** (**`PYTHON_NOT_ON_PATH`**
1491
+ if missing).
1492
+
1493
+ Required sync evidence fields:
1494
+ - `phase_boundary`
1495
+ - `policy_mode`
1496
+ - `trigger_source` (`manual|auto`)
1497
+ - `branch`
1498
+ - `checks` (`test|lint|typecheck`: `pass|fail|skipped`)
1499
+ - `qa_status_snapshot`
1500
+ - `push_decision` (`pushed|blocked|not_eligible`)
1501
+ - `reason_code`
1502
+ - `evidence_refs`
1503
+
1504
+ ## Release gate chain (US-0039 / DEC-0019)
1505
+
1506
+ Deterministic mandatory gate order; no step may be skipped or reordered:
1507
+
1508
+ 1. **Check-in test gate** — Latest `TEST_COMMAND` evidence must be present and passing.
1509
+ 2. **QA completion gate** — No unresolved blocking findings in sprint QA context.
1510
+ 3. **UAT completion gate** — UAT artifacts populated and verified; no placeholder or unresolved-fail state.
1511
+ 4. **Isolation compliance gate** — Per-phase isolation evidence present and valid (US-0048 / DEC-0029).
1512
+ 5. **Release finalization** — Notes, queue, backlog/runbook/state updates only after gates 1–4 pass.
1513
+
1514
+ Default: no bypass. Override only via explicit decision gate with rationale and evidence (DEC-0019).
1515
+
1516
+ **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.
1517
+
1518
+ **Per-gate audit verdict schema (US-0039)** — For TL/QA auditability, record per gate:
1519
+
1520
+ - `gate` (check-in_test | qa | uat | isolation | finalization)
1521
+ - `verdict` (pass | fail | override)
1522
+ - `reason_code` (e.g. RELEASE_TEST_FAILED, RELEASE_QA_BLOCKERS_OPEN, RELEASE_UAT_INCOMPLETE, RELEASE_GATE_OVERRIDE_APPROVED)
1523
+ - `remediation` (short remediation steps when fail/override)
1524
+ - `evidence_refs` (paths to tests/report.md, qa-findings.md, uat.json, release-findings.md, DEC-xxxx as applicable)
1525
+
1526
+ 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.
1527
+
1528
+ ## Release queue and sprint notes contract (US-0040 / DEC-0020)
1529
+
1530
+ Canonical release artifacts:
1531
+ - `handoffs/releases/Sxxxx-release-notes.md` (canonical per-sprint notes)
1532
+ - `handoffs/release_queue.md` (canonical queue tracker)
1533
+ - `handoffs/release_notes.md` (legacy-compatible latest pointer/summary)
1534
+
1535
+ Queue row required fields:
1536
+ - `sprint_id`
1537
+ - `story_refs`
1538
+ - `status` (`planned|ready|unreleased|released|blocked`)
1539
+ - `last_updated`
1540
+ - `release_notes_ref`
1541
+ - `gate_snapshot`
1542
+ - `release_version` (optional before finalization)
1543
+
1544
+ Deterministic transition semantics:
1545
+ - target sprint only may change during one `/release` run
1546
+ - entering release flow sets target row to `unreleased`
1547
+ - successful finalization transitions same row to `released`
1548
+ - no non-target sprint row mutation
1549
+
1550
+ Fail-safe reason codes:
1551
+ - `RELEASE_SPRINT_UNRESOLVED`
1552
+ - `LEGACY_NOTES_SPRINT_UNRESOLVED`
1553
+ - `QUEUE_ENTRY_MISSING`
1554
+ - `NOTES_REF_MISSING`
1555
+ - `STATUS_TRANSITION_INVALID`
1556
+
1557
+ Mismatch and unresolved-sprint policy:
1558
+ - fail closed for finalization when sprint identity or queue/notes metadata is
1559
+ inconsistent
1560
+ - preserve existing notes artifacts by default (non-destructive)
1561
+ - do not auto-reconcile by deleting/rebuilding unrelated sprint history
1562
+ - include remediation steps in queue/state and rerun `/release` after correction
1563
+
1564
+ ## Post-QA release issue workflow (US-0042)
1565
+
1566
+ When `/release` finds a blocker after QA has passed, document it in a dedicated
1567
+ release findings artifact (separate from QA findings):
1568
+
1569
+ - Canonical artifact: `sprints/Sxxxx/release-findings.md`
1570
+ - Canonical handoff back to implementation: `handoffs/release_to_dev.md`
1571
+
1572
+ Required release-findings content:
1573
+ - gate status (`PASS|BLOCKED`)
1574
+ - blocking and non-blocking findings
1575
+ - deterministic reason code(s)
1576
+ - evidence refs
1577
+ - remediation steps and rerun criteria
1578
+
1579
+ Boundary rule:
1580
+ - QA-phase defects remain in `sprints/Sxxxx/qa-findings.md`.
1581
+ - Post-QA release-gate defects must be recorded in
1582
+ `sprints/Sxxxx/release-findings.md`.
1583
+
1584
+ ## Backlog reconciliation invariant (US-0043)
1585
+
1586
+ At release finalization boundary, target sprint stories must be synchronized in
1587
+ `docs/product/backlog.md` using canonical release evidence precedence.
1588
+
1589
+ Contract:
1590
+ - Scope is target sprint stories only (no global backlog mutation).
1591
+ - If release evidence is PASS, set story status to `DONE` and reconcile
1592
+ acceptance checkboxes to checked state.
1593
+ - If sprint is `released` but backlog story state remains contradictory
1594
+ (`OPEN`/unchecked), fail safe with reason code `BACKLOG_STATUS_DRIFT`.
1595
+ - Record remediation guidance and evidence refs in release artifacts before rerun.
1596
+
1597
+ ## Canonical status ownership and normalization guard (US-0045)
1598
+
1599
+ Canonical owner:
1600
+ - `docs/product/backlog.md` is the authority for story status (`OPEN|DONE`).
1601
+ - `docs/product/acceptance.md` and `docs/engineering/state.md` are derived views.
1602
+
1603
+ Deterministic reconciliation rules:
1604
+ 1. Read canonical story status from backlog.
1605
+ 2. Validate target sprint release evidence for status transitions.
1606
+ 3. Reconcile derived acceptance/state views from canonical backlog status.
1607
+ 4. Keep mutation scope target-scoped only; never broad-rewrite unrelated stories.
1608
+
1609
+ One-time normalization procedure:
1610
+ - Run an initial normalization pass for historically drifted stories.
1611
+ - Write all changed rows to `docs/engineering/status-normalization-report.md`
1612
+ including prior values, resolved values, evidence references, and timestamp.
1613
+ - On future runs, append only delta entries; do not rewrite historical report rows.
1614
+
1615
+ Fail-safe reason codes:
1616
+ - `BACKLOG_STATUS_DRIFT`: release evidence contradicts backlog/AC state.
1617
+ - `CANONICAL_STATUS_CONFLICT`: canonical backlog state conflicts with derived
1618
+ status resolution at reconciliation boundary.
1619
+
1620
+ ## Lifecycle QA matrix (US-0041)
1621
+
1622
+ Use this matrix to validate end-to-end installer/CLI lifecycle behavior:
1623
+
1624
+ | Scenario | Primary command path | Coverage location | Required evidence |
1625
+ |---|---|---|---|
1626
+ | 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 |
1627
+ | Overwrite + backup | `its-magic --mode overwrite --backup` and direct installer | `tests/run-tests.ps1`, `tests/run-tests.sh` | Backup snapshot contains overwritten framework file |
1628
+ | 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 |
1629
+ | 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 |
1630
+ | Negative path | invalid mode/args | `tests/run-tests.ps1`, `tests/run-tests.sh` | Deterministic non-zero fail-fast behavior |
1631
+ | Platform parity subset | npm/brew/choco CI jobs | `.github/workflows/ci.yml` | Lifecycle subset passes on all three runners |
1632
+
1633
+ ## Scratchpad example upgrade contract (US-0057 / DEC-0039 / DEC-0057)
1634
+
1635
+ `its-magic --mode upgrade` treats `.cursor/scratchpad.local.example.md` as
1636
+ framework-owned and `.cursor/scratchpad.local.md` as user-owned.
1637
+
1638
+ Expected deterministic outcome:
1639
+ - Framework-owned example is refreshed to latest release contract **before** baseline
1640
+ materialization runs in `installer.py --scratchpad-postinstall` (**DEC-0057** ordering).
1641
+ - User local scratchpad remains preserved without overwrite.
1642
+ - Installer output reports manifest copy status for the example file where applicable
1643
+ (`added|updated|unchanged`) **and** `[SCRATCHPAD_LAYER]` diagnostics from post-install
1644
+ (`example_refresh`, `baseline_materialize` / `baseline_skip`, `user_local` preserved).
1645
+ - CI regression: `python scripts/check-scratchpad-pair-parity.py --repo <root>` exit `0`
1646
+ when active and `template/` baseline/example pairs share the same automation `KEY=`
1647
+ set and catalog `#` headers from `# Core behavior` (**US-0075** **AC-11**).
1648
+
1649
+ ## Scratchpad delivery Model B (US-0073 / DEC-0055)
1650
+
1651
+ - Install manifest ships `.cursor/scratchpad.local.example.md` (framework catalog)
1652
+ but **does not** list `.cursor/scratchpad.md` as a copied file. The installer
1653
+ **materializes** `.cursor/scratchpad.md` from the packaged template when absent
1654
+ (`missing`, `interactive`, `upgrade`) or refreshes it on `overwrite`.
1655
+ - Merge precedence for automation readers: **local > materialized baseline > example**
1656
+ (same invariant as `DEC-0055`).
1657
+ - Post-install validation fails closed with `[SCRATCHPAD_MERGE_ERROR]` /
1658
+ `[SCRATCHPAD_MATERIALIZE_ERROR]` when layers are missing or required keys are
1659
+ empty after merge (`US-0073` `AC-4`).
1660
+ - `installer.ps1` / `installer.sh` delegate materialize+validate to
1661
+ `python installer.py --scratchpad-postinstall` (Python 3 required on PATH).
1662
+ - Recovery: `python installer.py --scratchpad-postinstall --target <repo> --mode missing`
1663
+ (or re-run a full install).
1664
+
1665
+ ## Deterministic artifact ordering and write discipline (US-0058 / DEC-0040)
1666
+
1667
+ Canonical policy source:
1668
+ - `docs/engineering/artifact-ordering-policy.md`
1669
+
1670
+ Required write discipline:
1671
+ - `docs/engineering/state.md`: append-bottom checkpoint writes only.
1672
+ - `docs/product/backlog.md`: sorted-canonical story ordering by numeric `US-xxxx`.
1673
+ - `docs/product/acceptance.md`: sorted-canonical row ordering aligned to backlog.
1674
+ - Handoff surfaces use explicit policy (`prepend-top` or `append-bottom`) per
1675
+ matrix and command contract.
1676
+
1677
+ Fail-safe contract:
1678
+ - Missing/ambiguous placement anchors fail closed with
1679
+ `ARTIFACT_ORDERING_ANCHOR_AMBIGUOUS`.
1680
+ - Non-monotonic `state.md` checkpoint timestamps fail closed with
1681
+ `STATE_TIMESTAMP_NON_MONOTONIC`.
1682
+ - No partial mutation on fail-safe path.
1683
+ - Re-run without semantic changes must be ordering-idempotent.
1684
+
1685
+ ## Cross-phase artifact ownership guard (US-0061 / DEC-0043)
1686
+
1687
+ Canonical policy source:
1688
+ - `docs/engineering/artifact-ownership-policy.md`
1689
+
1690
+ Required ownership discipline:
1691
+ - Each phase may mutate only its declared owned scopes for target context.
1692
+ - Cross-phase non-owned section rewrite/deletion is forbidden by default.
1693
+ - `docs/engineering/architecture.md` is history-preserving: append new story
1694
+ sections or mutate target section only; unrelated story-section deletion is
1695
+ prohibited.
1696
+
1697
+ Fail-safe contract:
1698
+ - Ownership violations fail closed with `PHASE_OWNERSHIP_VIOLATION`.
1699
+ - Missing evidence on override-authorized mutation path fails closed with
1700
+ `PHASE_OVERRIDE_EVIDENCE_MISSING`.
1701
+ - Architecture history deletion detection fails with
1702
+ `ARCH_HISTORY_DELETION_DETECTED`.
1703
+ - No partial mutation on fail-safe path.
1704
+
1705
+ Execution guidance:
1706
+ - Local baseline: run `sh tests/run-tests.sh` (or `powershell -ExecutionPolicy Bypass -File tests/run-tests.ps1`).
1707
+ - Packaging smoke: run npm local tests in `packaging/npm/`.
1708
+ - CI evidence: inspect `npm-test`, `brew-test`, and `choco-test` job logs.
1709
+
1710
+ ## Intake runtime capability and single-writer safety (US-0059 / DEC-0041)
1711
+
1712
+ `/intake` enforces deterministic runtime preflight and drift safety before
1713
+ artifact mutation.
1714
+
1715
+ Capability preflight:
1716
+ - Required role capability: `po` subagent.
1717
+ - Default policy: fail fast when unavailable with
1718
+ `SUBAGENT_CAPABILITY_UNAVAILABLE`.
1719
+ - Fallback policy is explicit only:
1720
+ - `INTAKE_SUBAGENT_FALLBACK=deny` (default): no silent fallback.
1721
+ - `INTAKE_SUBAGENT_FALLBACK=allow`: explicit operator opt-in for fallback path.
1722
+
1723
+ Single-writer drift safety:
1724
+ - Intake run binds a deterministic writer/run identity (`writer_id`,
1725
+ `intake_run_id`) to target artifacts.
1726
+ - Self-write updates for the active writer/run are valid and must not trigger
1727
+ concurrent drift blockers.
1728
+ - External concurrent conflicting writes fail safe with
1729
+ `INTAKE_CONCURRENT_WRITER_DETECTED`.
1730
+ - Fail-safe path performs no partial overwrite.
1731
+
1732
+ ## Post-release operator commands (S0070 / BUG-0008 — released `2026-04-05`)
1733
+
1734
+ **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.
1735
+
1736
+ - **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**.
1737
+ - **Prepublish:** `npm run prepublishOnly` (runs **`guard:installer`**).
1738
+ - **Publish:** `npm publish` — set **`RELEASE_PUBLISH_MODE`** to **`confirm`** or **`auto`** when ready; no inline registry secrets in docs.
1739
+ - **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]`.
1740
+
1741
+ ## Operator `.env` setup (US-0085 / DEC-0071)
1742
+
1743
+ ### Quick start
1744
+
1745
+ 1. Copy the committed template: `cp .env.example .env`
1746
+ 2. Fill in values for each variable relevant to your environment.
1747
+ 3. Source before remote, SSH, or release operations:
1748
+ - **Bash/Zsh**: `source .env` or `set -a; source .env; set +a`
1749
+ - **PowerShell**: `Get-Content .env | ForEach-Object { if ($_ -match '^([^#]\S+?)=(.*)$') { [Environment]::SetEnvironmentVariable($Matches[1], $Matches[2], 'Process') } }`
1750
+ 4. Run `python scripts/print_remote_env_hint.py` to verify parity between
1751
+ `.env.example` and the `*Env` fields in JSON configs.
1752
+
1753
+ ### Forbidden
1754
+
1755
+ - **Committing `.env`**: `.env` is gitignored; never add it to version control.
1756
+ - **Agents reading `.env`**: AI agents must not open, attach, read, search
1757
+ inside, or index `.env` or `.env.*` files (enforced via `.cursorignore` and
1758
+ Cursor rules). Use env var **names** in prose only.
1759
+
1760
+ ### Allowed
1761
+
1762
+ - Running `ssh`, `docker`, `python scripts/remote_config_summary.py` after
1763
+ sourcing `.env` — the process inherits normal environment variables.
1764
+ - Referencing env var **names** (not values) in documentation and handoffs.
1765
+
1766
+ ## Project run steps
1767
+
1768
+ ### Prerequisites
1769
+
1770
+ ### Local run
1771
+
1772
+ ### Tests