its-magic 0.1.3-1 → 0.1.3-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/installer.ps1 +8 -0
  2. package/installer.py +8 -0
  3. package/installer.sh +1 -0
  4. package/package.json +1 -1
  5. package/template/.cursor/commands/auto.md +90 -0
  6. package/template/.cursor/commands/execute.md +26 -0
  7. package/template/.cursor/commands/refresh-context.md +32 -0
  8. package/template/.cursor/commands/sovereign-critic.md +104 -0
  9. package/template/.cursor/rules/sovereign-role-manifest.mdc.example +27 -0
  10. package/template/.cursor/scratchpad.md +141 -0
  11. package/template/.cursor/sovereign-role-manifest.yaml.example +53 -0
  12. package/template/decisions/DEC-0104.md +279 -0
  13. package/template/decisions/DEC-0105.md +231 -0
  14. package/template/decisions/DEC-0107.md +246 -0
  15. package/template/docs/engineering/architecture.md +78 -0
  16. package/template/docs/engineering/auto-orchestration-reference.md +7 -0
  17. package/template/docs/engineering/context/installer-owned-paths.manifest +8 -0
  18. package/template/docs/engineering/reason_codes.md +411 -0
  19. package/template/docs/engineering/runbook.md +922 -0
  20. package/template/docs/engineering/sovereign-memory/.gitkeep +0 -0
  21. package/template/docs/engineering/sovereign-memory/retrospectives/.gitkeep +0 -0
  22. package/template/handoffs/sovereign_decisions/.gitkeep +0 -0
  23. package/template/handoffs/sovereign_deferrals/.gitkeep +0 -0
  24. package/template/handoffs/sovereign_role_reviews.jsonl +0 -0
  25. package/template/scripts/__pycache__/decision_ledger_lib.cpython-312.pyc +0 -0
  26. package/template/scripts/check_intake_template_parity.py +119 -0
  27. package/template/scripts/decision_ledger_lib.py +732 -0
  28. package/template/scripts/ledger_validate.py +153 -0
  29. package/template/scripts/parallel_dev_arbiter.py +923 -0
  30. package/template/scripts/release_trigger_adapters.py +843 -0
  31. package/template/scripts/self_healing_deploy_lib.py +463 -0
  32. package/template/scripts/self_healing_deploy_validate.py +78 -0
  33. package/template/scripts/sovereign_convergence_lib.py +994 -0
  34. package/template/scripts/sovereign_convergence_validate.py +206 -0
  35. package/template/scripts/sovereign_critic_lib.py +629 -0
  36. package/template/scripts/sovereign_critic_validate.py +131 -0
  37. package/template/scripts/sovereign_loop_lib.py +828 -0
  38. package/template/scripts/sovereign_loop_validate.py +122 -0
  39. package/template/scripts/sovereign_memory_lib.py +869 -0
  40. package/template/scripts/sovereign_memory_validate.py +153 -0
  41. package/template/scripts/sovereign_role_manifest_lib.py +547 -0
  42. package/template/scripts/sovereign_role_manifest_validate.py +105 -0
  43. package/template/tests/us0108_contract_test.py +207 -0
  44. package/template/tests/us0109_contract_test.py +209 -0
  45. package/template/tests/us0109_us0110_compose_test.py +34 -0
  46. package/template/tests/us0111_contract_test.py +345 -0
@@ -0,0 +1,411 @@
1
+ # Reason Codes Index
2
+
3
+ Canonical inventory of fail-closed reason codes used across the its-magic framework.
4
+
5
+ Each code maps to a deterministic exit code or blocking behavior. Operators read this
6
+ document to interpret error messages, triage failures, and decide remediation steps.
7
+
8
+ ---
9
+
10
+ ## US-0103: AI Decision Ledger + Plan Fidelity (DEC-0103 §8)
11
+
12
+ Sovereign-loop foundation layer. Default-off (`AI_DECISION_LEDGER=0`) → zero overhead.
13
+ When enabled, every autonomous AI decision writes to an append-only JSONL ledger.
14
+ Plan fidelity tri-state (`strict|relaxed|extended`) governs deviation tolerance.
15
+
16
+ ### PLAN_FIDELITY_* (5 codes)
17
+
18
+ | Code | Meaning | Blocking |
19
+ |------|---------|----------|
20
+ | **`PLAN_FIDELITY_VIOLATION`** | Unapproved deviation under `strict` mode (drop/reorder AC) — **hard stop** | **Yes** — operator must approve override or revert |
21
+ | **`PLAN_FIDELITY_OVERRIDE`** | Operator-approved relaxation recorded in ledger | **No** — informational, ledger entry appended |
22
+ | **`PLAN_FIDELITY_SCOPE_GATE`** | New scope request (add story/feature) under `strict` or `relaxed` — **hard stop** | **Yes** — decision gate requires explicit scope acceptance |
23
+ | **`PLAN_FIDELITY_EXTENSION`** | Extended-mode non-blocking scope extension | **No** — recorded in extension report, QA cross-checks |
24
+ | **`PLAN_FIDELITY_REORDER`** | Relaxed/extended-mode AC drop/reorder recorded | **No** — ledger entry appended, QA cross-checks |
25
+
26
+ ### LEDGER_* (6 codes)
27
+
28
+ | Code | Meaning | Blocking |
29
+ |------|---------|----------|
30
+ | **`LEDGER_FILE_MISSING`** | `AI_DECISION_LEDGER=1` but no ledger file for current orchestrator run — **fail-closed** | **Yes** — QA hard stop, operator must create or disable |
31
+ | **`LEDGER_SCHEMA_INVALID`** | JSONL line fails 12-field schema v1 validation — **fail-closed** | **Yes** — QA hard stop, operator must remediate ledger |
32
+ | **`LEDGER_APPEND_FAILED`** | Append/fsync failed (permission error, I/O error, disk full) | **Yes** — execute phase cannot continue without ledger write |
33
+ | **`LEDGER_CORRUPT`** | Whole file fails UTF-8 decode or JSON parse — **fail-closed** | **Yes** — operator must manually repair or truncate ledger |
34
+ | **`LEDGER_READ_BOUND`** | Bounded read truncated (`last_n=100` for QA) | **No** — warning only, digest still emitted |
35
+ | **`LEDGER_DISABLED`** | `AI_DECISION_LEDGER=0` (default) — informational, zero overhead | **No** — no-op, no ledger reads/writes |
36
+
37
+ **Informational (not fail)**: `LEDGER_FILE_EMPTY` when ledger file exists but contains
38
+ zero parseable lines (emit at QA only, warn — not a hard stop unless `LEDGER_FILE_MISSING`
39
+ logic also triggers).
40
+
41
+ ### Exit-code mapping
42
+
43
+ | Code | Exit code (CLI) |
44
+ |------|-----------------|
45
+ | `PLAN_FIDELITY_VIOLATION`, `PLAN_FIDELITY_SCOPE_GATE`, `LEDGER_FILE_MISSING`, `LEDGER_SCHEMA_INVALID`, `LEDGER_CORRUPT`, `LEDGER_APPEND_FAILED` | `1` (fail-closed) |
46
+ | `PLAN_FIDELITY_OVERRIDE`, `PLAN_FIDELITY_EXTENSION`, `PLAN_FIDELITY_REORDER`, `LEDGER_READ_BOUND`, `LEDGER_DISABLED` | `0` (success / informational) |
47
+
48
+ ### Usage in CLI tools
49
+
50
+ - **`scripts/decision_ledger_lib.py`**: `append_entry()` returns `AppendResult(success, reason_code, reason_message)`.
51
+ - **`scripts/ledger_validate.py`**: `--file <path>` validates schema, emits `LEDGER_SCHEMA_INVALID` on first invalid line, `LEDGER_FILE_MISSING` if file absent.
52
+ - **`tests/us0103_contract_test.py`**: 8 contract tests assert enum cardinalities, default-off behavior, schema v1 invariants, tri-state deviation classifier, QA cross-check block shape, backward composition with US-0070/US-0069/US-0048.
53
+
54
+ ### Operational remediation
55
+
56
+ | Reason code | Operator action |
57
+ |-------------|-----------------|
58
+ | `PLAN_FIDELITY_VIOLATION` | Review `handoffs/sovereign_decisions/<run>.jsonl` last entry; if deviation justified, set `AUTO_PLAN_FIDELITY=relaxed` in `.cursor/scratchpad.local.md` and re-run `/execute`; otherwise revert AC changes |
59
+ | `PLAN_FIDELITY_SCOPE_GATE` | If scope-add is intentional, switch to `AUTO_PLAN_FIDELITY=extended` and document in `sprints/Sxxxx/extension-report.md`; otherwise drop new scope |
60
+ | `LEDGER_FILE_MISSING` | Ensure `handoffs/sovereign_decisions/` directory exists (create `.gitkeep` if missing); or set `AI_DECISION_LEDGER=0` to disable |
61
+ | `LEDGER_SCHEMA_INVALID` | Open ledger file, locate invalid line (validator prints line number), fix JSON syntax or missing field; if unrecoverable, truncate file to last valid line |
62
+ | `LEDGER_CORRUPT` | Ledger file contains non-UTF-8 bytes or malformed JSON throughout — manual repair required; consider `git restore` from prior commit or truncate to known-good prefix |
63
+ | `LEDGER_APPEND_FAILED` | Check disk space (`df -h`), file permissions (`ls -la handoffs/sovereign_decisions/`), and filesystem mount status; retry after remediation |
64
+ | `LEDGER_READ_BOUND` | No action required — QA digest still emitted; full file read available via `read_entries(ledger_path, last_n=None)` in library call |
65
+ | `LEDGER_DISABLED` | No action required — zero overhead when `AI_DECISION_LEDGER=0`; opt-in via `.cursor/scratchpad.local.md` if ledger auditing desired |
66
+
67
+ ### Related artifacts
68
+
69
+ - **Architecture**: `docs/engineering/architecture.md` `# US-0103` §8 (reason code inventory)
70
+ - **Decision record**: `decisions/DEC-0103.md` §8
71
+ - **Library**: `scripts/decision_ledger_lib.py` — `ReasonCode` enum (11 values total)
72
+ - **Validator**: `scripts/ledger_validate.py` — CLI exit codes map to reason codes
73
+ - **Contract tests**: `tests/us0103_contract_test.py` — `test_us0103_reason_code_inventory` asserts 5 `PLAN_FIDELITY_*` + 6 `LEDGER_*` parity
74
+
75
+ ---
76
+
77
+ ## US-0110: Goal-Based Convergence Loops (DEC-0110 §10)
78
+
79
+ Sovereign-loop terminal predicate. Default-off (`SOVEREIGN_GOAL_MODE=phase_driven`) → zero
80
+ overhead. When `goal_convergence`, `evaluate_convergence` reads composed surfaces only.
81
+
82
+ | Code | blocked_by? | Conjunct / trigger |
83
+ |------|-------------|-------------------|
84
+ | **`CONVERGENCE_OPEN_STORIES_REMAIN`** | yes | backlog clear — OPEN stories remain in `docs/product/backlog.md` |
85
+ | **`CONVERGENCE_DEFERRALS_PENDING`** | yes | zero deferrals — non-empty `handoffs/sovereign_deferrals.jsonl` |
86
+ | **`CONVERGENCE_CROSS_REVIEWER_OPEN`** | yes | critic resolved — open blocking cross-reviewer finding |
87
+ | **`CONVERGENCE_SMOKE_PROBE_FAIL`** | yes | smoke green — `tests/report.md` and/or active sprint UAT smoke step not PASS |
88
+ | **`CONVERGENCE_LEDGER_EXTENSIONS_UNAPPROVED`** | yes | ledger clean — unapproved extension/scope-gate without override |
89
+ | **`SOVEREIGN_GOAL_TIMEOUT`** | yes | iteration cap exhausted (`SOVEREIGN_GOAL_TIMEOUT_MAX`) |
90
+ | **`SOVEREIGN_GOAL_MODE_INVALID`** | yes | invalid `SOVEREIGN_GOAL_MODE` scratchpad enum |
91
+ | **`SOVEREIGN_GOAL_MISSING`** | no (warn) | empty goal under `phase_driven` — informational only |
92
+ | **`SOVEREIGN_GOAL_DERIVE_FAILED`** | yes | vision auto-derive failed (missing/empty vision) |
93
+ | **`CONVERGENCE_EVAL_FAILED`** | yes | evaluator internal error |
94
+
95
+ ### Operational remediation
96
+
97
+ | Reason code | Operator action |
98
+ |-------------|-----------------|
99
+ | `CONVERGENCE_OPEN_STORIES_REMAIN` | Complete or defer remaining OPEN stories; re-run drain loop |
100
+ | `CONVERGENCE_DEFERRALS_PENDING` | Resolve deferrals in register or drain-generate (US-0107) |
101
+ | `CONVERGENCE_CROSS_REVIEWER_OPEN` | Resolve critic findings; re-run `/qa` |
102
+ | `CONVERGENCE_SMOKE_PROBE_FAIL` | Fix failing tests/UAT smoke; refresh `tests/report.md` |
103
+ | `CONVERGENCE_LEDGER_EXTENSIONS_UNAPPROVED` | Add `PLAN_FIDELITY_OVERRIDE` or revert scope changes |
104
+ | `SOVEREIGN_GOAL_TIMEOUT` | Read `handoffs/sovereign_partial_delivery.md`; adjust goal or cap |
105
+ | `SOVEREIGN_GOAL_MODE_INVALID` | Set `SOVEREIGN_GOAL_MODE=phase_driven` or `goal_convergence` |
106
+ | `SOVEREIGN_GOAL_DERIVE_FAILED` | Set explicit `SOVEREIGN_GOAL` or populate `docs/product/vision.md` |
107
+ | `CONVERGENCE_EVAL_FAILED` | Check evaluator logs; re-run with `--self-test` |
108
+
109
+ ## US-0104: Cross-Model Adversarial Critic (DEC-0104 §11)
110
+
111
+ Default-off cross-model review (`CROSS_MODEL_REVIEW=0`) → zero overhead. When enabled,
112
+ `/auto` spawns `/sovereign-critic` after producer phases; findings append to
113
+ `handoffs/sovereign_critic_findings.jsonl`.
114
+
115
+ | Code | Blocking? | Surface |
116
+ |------|-----------|---------|
117
+ | **`CROSS_MODEL_REVIEW_DISABLED`** | no (info) | scratchpad gate off |
118
+ | **`CROSS_MODEL_CRITIC_SPAWN_FAILED`** | yes | orchestrator hook |
119
+ | **`CROSS_MODEL_MODEL_COLLISION`** | no → degraded | same slug resolved |
120
+ | **`CROSS_MODEL_ANTISLOP_FAIL`** | yes (rework) | score below threshold |
121
+ | **`CROSS_MODEL_REWORK_CAP_EXHAUSTED`** | yes (gate) | rework max hit |
122
+ | **`CROSS_MODEL_FINDINGS_INVALID`** | yes | schema validation |
123
+ | **`CROSS_MODEL_RECONCILE_FAILED`** | yes | jury merge error |
124
+ | **`CROSS_MODEL_DEGRADED_MODE`** | no (info) | single-model fallback |
125
+ | **`CROSS_MODEL_CRITIC_MODEL_UNAVAILABLE`** | yes → degraded | catalog miss |
126
+ | **`ISOLATION_EVIDENCE_MODEL_ID_MISSING`** | yes | critic enabled, evidence incomplete |
127
+
128
+ ### Operational remediation
129
+
130
+ | Reason code | Operator action |
131
+ |-------------|-----------------|
132
+ | `CROSS_MODEL_REVIEW_DISABLED` | Set `CROSS_MODEL_REVIEW=1` to enable critic |
133
+ | `CROSS_MODEL_CRITIC_SPAWN_FAILED` | Retry spawn; check Task tool availability |
134
+ | `CROSS_MODEL_ANTISLOP_FAIL` | Address critic findings; producer re-spawn (bounded) |
135
+ | `CROSS_MODEL_REWORK_CAP_EXHAUSTED` | Waive findings or abort; adjust `CROSS_MODEL_REWORK_MAX` |
136
+ | `CROSS_MODEL_FINDINGS_INVALID` | Fix JSONL schema; run `sovereign_critic_validate.py --enforce` |
137
+ | `CROSS_MODEL_DEGRADED_MODE` | Informational — single-model multi-lens fallback active |
138
+ | `ISOLATION_EVIDENCE_MODEL_ID_MISSING` | Add `model_id` to producer and critic isolation rows |
139
+
140
+ ### Related artifacts
141
+
142
+ - **Architecture**: `docs/engineering/architecture.md` `# US-0110`
143
+ - **Decision record**: `decisions/DEC-0110.md` §10
144
+ - **Library**: `scripts/sovereign_convergence_lib.py`
145
+ - **Validator**: `scripts/sovereign_convergence_validate.py`
146
+ - **Contract tests**: `tests/us0110_contract_test.py`
147
+
148
+ ---
149
+
150
+ ## US-0105 — Sovereign Memory (`SOVEREIGN_MEMORY_*`)
151
+
152
+ Default-off institutional memory (`SOVEREIGN_MEMORY=0`) → zero overhead. When enabled,
153
+ bounded JSONL learnings inject into phase spawns via `sovereign_memory_lib.py`.
154
+ Normative: **`decisions/DEC-0105.md`** §9; architecture **`# US-0105`**.
155
+
156
+ ### SOVEREIGN_MEMORY_* (8 codes)
157
+
158
+ | Reason code | Meaning | Blocking? |
159
+ |-------------|---------|-----------|
160
+ | **`SOVEREIGN_MEMORY_DISABLED`** | `SOVEREIGN_MEMORY=0` (default) — informational, zero overhead | **No** |
161
+ | **`SOVEREIGN_MEMORY_SCHEMA_INVALID`** | JSONL line fails v1 family schema — **fail-closed** | **Yes** |
162
+ | **`SOVEREIGN_MEMORY_APPEND_FAILED`** | Append/fsync failed (permission / I/O) | **Yes** |
163
+ | **`SOVEREIGN_MEMORY_DECISION_DUPLICATE`** | `decision_key` already present — skip append | **No** (skip) |
164
+ | **`SOVEREIGN_MEMORY_SECRET_DETECTED`** | Free-text field matches secret heuristics — **fail-closed** | **Yes** |
165
+ | **`SOVEREIGN_MEMORY_ARCHIVE_REQUIRED`** | JSONL rollover I/O failure — block append | **Yes** |
166
+ | **`SOVEREIGN_MEMORY_READ_BOUND`** | Tail read truncated during digest assembly | **No** (warning) |
167
+ | **`SOVEREIGN_MEMORY_PROMOTION_SKIPPED`** | Ledger off or promotion filter empty | **No** (info) |
168
+
169
+ ### Operator remediation
170
+
171
+ | Reason code | Operator action |
172
+ |-------------|-----------------|
173
+ | `SOVEREIGN_MEMORY_DISABLED` | Set `SOVEREIGN_MEMORY=1` to enable memory |
174
+ | `SOVEREIGN_MEMORY_SCHEMA_INVALID` | Fix JSONL line; run `sovereign_memory_validate.py --enforce` |
175
+ | `SOVEREIGN_MEMORY_APPEND_FAILED` | Check disk space and file permissions |
176
+ | `SOVEREIGN_MEMORY_DECISION_DUPLICATE` | No action — dedup skip is expected |
177
+ | `SOVEREIGN_MEMORY_SECRET_DETECTED` | Remove secret-shaped literals from entry text |
178
+ | `SOVEREIGN_MEMORY_ARCHIVE_REQUIRED` | Remediate archive I/O; check `sovereign-memory-archive/` permissions |
179
+ | `SOVEREIGN_MEMORY_READ_BOUND` | No action — digest still emitted within char cap |
180
+ | `SOVEREIGN_MEMORY_PROMOTION_SKIPPED` | Enable `AI_DECISION_LEDGER=1` or adjust promotion filter |
181
+
182
+ ### Related artifacts
183
+
184
+ - **Architecture**: `docs/engineering/architecture.md` `# US-0105`
185
+ - **Decision record**: `decisions/DEC-0105.md` §9
186
+ - **Library**: `scripts/sovereign_memory_lib.py`
187
+ - **Validator**: `scripts/sovereign_memory_validate.py`
188
+ - **Contract tests**: `tests/us0105_contract_test.py`
189
+
190
+ ---
191
+
192
+ ## US-0106 — Sovereign Role-Behavior Manifest (`SOVEREIGN_ROLE_*` / `ROLE_REVIEW_*`)
193
+
194
+ Default-off per-role objective + inter-role review obligations (`SOVEREIGN_ROLE_MANIFEST=0`) → zero
195
+ overhead. When enabled, orchestrator reads `.cursor/sovereign-role-manifest.yaml`, injects role-specific
196
+ objective blocks into subagent spawn context, and dispatches supplementary cross-role reviews after
197
+ phase completion (spawn-only per BUG-0006; distinct boundary_token `role_review`).
198
+
199
+ Normative: **`decisions/DEC-0106.md`** §2; architecture **`# US-0106`**.
200
+
201
+ ### SOVEREIGN_ROLE_* (6 codes)
202
+
203
+ | Reason code | Meaning | Blocking? |
204
+ |-------------|---------|-----------|
205
+ | **`SOVEREIGN_ROLE_MANIFEST_DISABLED`** | `SOVEREIGN_ROLE_MANIFEST=0` (default) — informational, zero overhead | **No** |
206
+ | **`SOVEREIGN_ROLE_MANIFEST_SCHEMA_INVALID`** | Manifest YAML parse or schema validation failed — **fail-closed** | **Yes** |
207
+ | **`SOVEREIGN_ROLE_UNKNOWN_ROLE`** | Manifest references `role_id` not in canonical set (`po`, `tech-lead`, `dev`, `qa`, `release`, `curator`) — **fail-closed** | **Yes** |
208
+ | **`SOVEREIGN_ROLE_UNKNOWN_PHASE`** | Manifest references `trigger_phase` not in canonical phase set — **fail-closed** | **Yes** |
209
+ | **`SOVEREIGN_ROLE_SECRET_DETECTED`** | Manifest `objective_function` contains secret-shaped literal (API key, token, password) — **fail-closed** | **Yes** |
210
+ | **`SOVEREIGN_ROLE_OBJECTIVE_OVERFLOW`** | `objective_function` exceeds 1024 chars at file load — **fail-closed** | **Yes** |
211
+
212
+ ### ROLE_REVIEW_* (5 codes)
213
+
214
+ | Reason code | Meaning | Blocking? |
215
+ |-------------|---------|-----------|
216
+ | **`ROLE_REVIEW_DISPATCH_FAILED`** | Append to `handoffs/sovereign_role_reviews.jsonl` failed (I/O, permissions) | **Yes** |
217
+ | **`ROLE_REVIEW_SPAWN_FAILED`** | Task tool spawn error for supplementary review subagent | **Yes** |
218
+ | **`ROLE_REVIEW_BLOCKED`** | Supplementary review verdict `fail` with `blocking=true`; producer phase cannot proceed | **Yes** (operator decision gate) |
219
+ | **`ROLE_REVIEW_DEFERRAL_FAILED`** | US-0107 deferral append failed during review escalation | **No** (fail-open log) |
220
+ | **`ROLE_REVIEW_REWORK_CAP`** | Rework cap exhausted (`SOVEREIGN_ROLE_REVIEW_REWORK_MAX`); operator decision gate required | **Yes** (operator decision gate) |
221
+
222
+ ### Operational remediation
223
+
224
+ | Reason code | Operator action |
225
+ |-------------|-----------------|
226
+ | `SOVEREIGN_ROLE_MANIFEST_DISABLED` | Set `SOVEREIGN_ROLE_MANIFEST=1` to enable role manifest |
227
+ | `SOVEREIGN_ROLE_MANIFEST_SCHEMA_INVALID` | Re-create manifest from `.cursor/sovereign-role-manifest.yaml.example`; re-run `scripts/sovereign_role_manifest_validate.py --file .cursor/sovereign-role-manifest.yaml` |
228
+ | `SOVEREIGN_ROLE_UNKNOWN_ROLE` | Edit manifest; replace `role_id` with canonical role (`po`, `tech-lead`, `dev`, `qa`, `release`, `curator`) |
229
+ | `SOVEREIGN_ROLE_UNKNOWN_PHASE` | Edit manifest; replace `trigger_phase` with canonical phase_id (see `/architecture` canonical phases) |
230
+ | `SOVEREIGN_ROLE_SECRET_DETECTED` | Replace secret-shaped literal in `objective_function` with placeholder; never commit real credentials |
231
+ | `SOVEREIGN_ROLE_OBJECTIVE_OVERFLOW` | Truncate or split `objective_function` (file max 1024 chars; validator hard caps) |
232
+ | `ROLE_REVIEW_DISPATCH_FAILED` | Retry dispatch; check file permissions on `handoffs/` directory |
233
+ | `ROLE_REVIEW_SPAWN_FAILED` | Retry spawn; if persistent, check Task tool availability or disable `SOVEREIGN_ROLE_MANIFEST` |
234
+ | `ROLE_REVIEW_BLOCKED` | Operator decision gate: waive review (set `blocking=false`), rework producer output, or disable manifest |
235
+ | `ROLE_REVIEW_DEFERRAL_FAILED` | Check `handoffs/sovereign_deferrals.jsonl` permissions; fail-open logged but not blocking |
236
+ | `ROLE_REVIEW_REWORK_CAP` | Operator decision: waive review, escalate to human reviewer, or disable manifest |
237
+
238
+ ### Related artifacts
239
+
240
+ - **Architecture**: `docs/engineering/architecture.md` `# US-0106`
241
+ - **Decision record**: `decisions/DEC-0106.md`
242
+ - **Library**: `scripts/sovereign_role_manifest_lib.py` — `ReasonCode` enum (11 values total)
243
+ - **Validator**: `scripts/sovereign_role_manifest_validate.py` — CLI exit codes map to reason codes
244
+ - **Contract tests**: `tests/us0106_contract_test.py` — 8 tests + 2 compose guards
245
+
246
+ ---
247
+
248
+ ## US-0107 — Sovereign Loop Mode (`SOVEREIGN_*` / `DEPLOY_DEFERRED`)
249
+
250
+ Default-off sovereign loop orchestration (`AUTO_SOVEREIGN=0`) → zero overhead. When enabled
251
+ with `SOVEREIGN_GOAL_MODE=goal_convergence`, manages deferral register, drain-generate,
252
+ notification dispatch, and convergence hooks via `sovereign_loop_lib.py`.
253
+ Normative: **`decisions/DEC-0107.md`** §9; architecture **`# US-0107`**.
254
+
255
+ ### SOVEREIGN_LOOP_* / SOVEREIGN_DEFERRAL_* / SOVEREIGN_DRAIN_* / SOVEREIGN_NOTIFY_* (12 codes)
256
+
257
+ | Reason code | Meaning | Blocking? |
258
+ |-------------|---------|-----------|
259
+ | **`SOVEREIGN_LOOP_DISABLED`** | `AUTO_SOVEREIGN=0` (default) — informational, zero overhead | **No** |
260
+ | **`SOVEREIGN_LOOP_GOAL_MODE_REQUIRED`** | `AUTO_SOVEREIGN=1` without `SOVEREIGN_GOAL_MODE=goal_convergence` — **fail-closed** | **Yes** |
261
+ | **`SOVEREIGN_DEFERRAL_CAP_EXCEEDED`** | Open deferral rows ≥ `AUTO_SOVEREIGN_DEFERRAL_MAX` — append rejected / sovereign terminal | **Yes** |
262
+ | **`SOVEREIGN_DEFERRAL_SCHEMA_INVALID`** | Deferral JSONL line fails v1 schema — **fail-closed** | **Yes** |
263
+ | **`SOVEREIGN_DEFERRAL_APPEND_FAILED`** | Deferral append/fsync failed (permission / I/O) | **Yes** |
264
+ | **`SOVEREIGN_DRAIN_GENERATE_CAP`** | Drain-generate iterations exhausted for run — sovereign terminal | **Yes** |
265
+ | **`SOVEREIGN_DRAIN_GENERATE_BLOCKED`** | Deferral policy or gate blocks drain-generate spawn | **Yes** |
266
+ | **`SOVEREIGN_NOTIFY_DISPATCH_FAILED`** | Notification adapter error — logged, loop continues (fail-open) | **No** (fail-open log) |
267
+ | **`SOVEREIGN_NOTIFY_TARGET_INVALID`** | Unknown notify target or email v1 deferred | **No** |
268
+ | **`SOVEREIGN_NOTIFY_CONFIG_MISSING`** | Notify target on but topic/URL absent — skip dispatch | **No** (skip) |
269
+ | **`SOVEREIGN_LOOP_ADVANCE_BLOCKED`** | Deferral policy `stop` or `resolve_first` blocks advance | **Yes** |
270
+ | **`DEPLOY_DEFERRED`** | Deploy smoke cap exhaustion — deferral row for **US-0109** writer | **No** (deferral row) |
271
+
272
+ ### Operator remediation
273
+
274
+ | Reason code | Operator action |
275
+ |-------------|-----------------|
276
+ | `SOVEREIGN_LOOP_DISABLED` | Set `AUTO_SOVEREIGN=1` and `SOVEREIGN_GOAL_MODE=goal_convergence` to enable |
277
+ | `SOVEREIGN_LOOP_GOAL_MODE_REQUIRED` | Set both `AUTO_SOVEREIGN=1` and `SOVEREIGN_GOAL_MODE=goal_convergence` in scratchpad.local |
278
+ | `SOVEREIGN_DEFERRAL_CAP_EXCEEDED` | Resolve open deferrals or raise `AUTO_SOVEREIGN_DEFERRAL_MAX` |
279
+ | `SOVEREIGN_DEFERRAL_SCHEMA_INVALID` | Fix JSONL line; run `sovereign_loop_validate.py --enforce` |
280
+ | `SOVEREIGN_DEFERRAL_APPEND_FAILED` | Check disk space and file permissions on `handoffs/sovereign_deferrals.jsonl` |
281
+ | `SOVEREIGN_DRAIN_GENERATE_CAP` | Review drain-generate proposals; adjust goal or raise cap; read partial-delivery report |
282
+ | `SOVEREIGN_DRAIN_GENERATE_BLOCKED` | Resolve open deferrals or change `AUTO_SOVEREIGN_DEFERRAL_POLICY` |
283
+ | `SOVEREIGN_NOTIFY_DISPATCH_FAILED` | Check ntfy/hook connectivity; notification failure does not block loop |
284
+ | `SOVEREIGN_NOTIFY_TARGET_INVALID` | Set valid `SOVEREIGN_NOTIFY_TARGET`; email deferred to v1.1 |
285
+ | `SOVEREIGN_NOTIFY_CONFIG_MISSING` | Set topic/URL in scratchpad.local or set `SOVEREIGN_NOTIFY_TARGET=off` |
286
+ | `SOVEREIGN_LOOP_ADVANCE_BLOCKED` | Resolve deferrals via `resolve_deferral` or change policy to `skip` |
287
+ | `DEPLOY_DEFERRED` | **US-0109** scope — resolve deploy deferral or retry smoke |
288
+
289
+ ### Related artifacts
290
+
291
+ - **Architecture**: `docs/engineering/architecture.md` `# US-0107`
292
+ - **Decision record**: `decisions/DEC-0107.md` §9
293
+ - **Library**: `scripts/sovereign_loop_lib.py`
294
+ - **Validator**: `scripts/sovereign_loop_validate.py`
295
+ - **Contract tests**: `tests/us0107_contract_test.py`
296
+
297
+ ---
298
+
299
+ ## US-0109 — Self-Healing Deploy Loop (`DEPLOY_HEALING_*` / `DEPLOY_SMOKE_*`)
300
+
301
+ Default-off post-deploy smoke probe + bounded retry loop (`AUTO_SOVEREIGN_SELF_HEALING_DEPLOY=0`) → zero
302
+ overhead, byte-identical US-0054 publish path. When enabled, after `[RELEASE_PUBLISH_OK]`, a two-stage
303
+ smoke probe (health HTTP GET + acceptance smoke runner) validates the deployed artifact. On probe FAIL,
304
+ publish PASS path re-entered idempotently up to `AUTO_SOVEREIGN_DEPLOY_RETRY_MAX`. After retry-cap
305
+ exhaustion, US-0107 `append_deferral(work_item_kind=deploy)` writes DEPLOY_DEFERRED row.
306
+ Normative: **`decisions/DEC-0109.md`** §7; architecture **`# US-0109`**.
307
+
308
+ ### DEPLOY_HEALING_* / DEPLOY_SMOKE_* (8 codes)
309
+
310
+ | Reason code | Meaning | Blocking? |
311
+ |-------------|---------|-----------|
312
+ | **`DEPLOY_HEALING_DISABLED`** | `AUTO_SOVEREIGN_SELF_HEALING_DEPLOY=0` (default) — informational, zero overhead | **No** |
313
+ | **`DEPLOY_HEALING_SMOKE_HEALTH_FAIL`** | Health HTTP GET non-2xx or connection refused | **Yes** (retry or defer) |
314
+ | **`DEPLOY_HEALING_SMOKE_ACCEPTANCE_FAIL`** | Acceptance smoke pytest runner non-zero exit | **Yes** (retry or defer) |
315
+ | **`DEPLOY_HEALING_RETRY_ATTEMPT`** | Per-attempt log entry during retry loop (`retry_count` tag) | **No** (info) |
316
+ | **`DEPLOY_HEALING_RETRY_CAP_EXHAUSTED`** | `AUTO_SOVEREIGN_DEPLOY_RETRY_MAX` reached — proceed to DEPLOY_DEFERRED | **Yes** (to defer) |
317
+ | **`DEPLOY_HEALING_DEFERRED`** | DEPLOY_DEFERRED tuple written via US-0107 `append_deferral` | **No** (deferral row) |
318
+ | **`DEPLOY_HEALING_PROBE_TARGET_MISSING`** | `AUTO_SOVEREIGN_DEPLOY_HEALTH_ENDPOINT` unresolvable from env — **fail-closed** | **Yes** (fail-closed) |
319
+ | **`DEPLOY_HEALING_TIMEOUT`** | Total bounded timeout exceeded (smoke HTTP timeout or pytest runner timeout) | **Yes** (blocking) |
320
+
321
+ `DEPLOY_DEFERRED` already reserved in US-0107 runbook — confirmed reuse.
322
+
323
+ ### Operator remediation
324
+
325
+ | Reason code | Operator action |
326
+ |-------------|-----------------|
327
+ | `DEPLOY_HEALING_DISABLED` | Set `AUTO_SOVEREIGN_SELF_HEALING_DEPLOY=1` to enable self-healing deploy |
328
+ | `DEPLOY_HEALING_SMOKE_HEALTH_FAIL` | Check target health endpoint reachability; verify `AUTO_SOVEREIGN_DEPLOY_HEALTH_ENDPOINT` env key resolves; run `self_healing_deploy_validate.py --self-test` |
329
+ | `DEPLOY_HEALING_SMOKE_ACCEPTANCE_FAIL` | Inspect smoke test logs in `SOVEREIGN_DEPLOY_ACCEPTANCE_SMOKE_PATH`; fix failing acceptance tests |
330
+ | `DEPLOY_HEALING_RETRY_ATTEMPT` | Informational per-attempt log; no action needed unless cap exhausted |
331
+ | `DEPLOY_HEALING_RETRY_CAP_EXHAUSTED` | Review `sprints/Sxxxx/summary.md` smoke probe output; raise `AUTO_SOVEREIGN_DEPLOY_RETRY_MAX` if transient; or resolve root cause |
332
+ | `DEPLOY_HEALING_DEFERRED` | Resolve DEPLOY_DEFERRED row in `handoffs/sovereign_deferrals.jsonl`; re-run `/release` after fix |
333
+ | `DEPLOY_HEALING_PROBE_TARGET_MISSING` | Set `AUTO_SOVEREIGN_DEPLOY_HEALTH_ENDPOINT` to a valid env key name in scratchpad.local; ensure env var contains URL |
334
+ | `DEPLOY_HEALING_TIMEOUT` | Raise `AUTO_SOVEREIGN_DEPLOY_SMOKE_TIMEOUT_SEC` for slow targets; investigate startup latency |
335
+
336
+ ### Related artifacts
337
+
338
+ - **Architecture**: `docs/engineering/architecture.md` `# US-0109`
339
+ - **Decision record**: `decisions/DEC-0109.md` §7
340
+ - **Library**: `scripts/self_healing_deploy_lib.py` — `ReasonCode` enum (8 values)
341
+ - **Validator**: `scripts/self_healing_deploy_validate.py` — CLI exit codes map to reason codes
342
+ - **Contract tests**: `tests/us0109_contract_test.py` — 8 core markers + 2 compose guards
343
+
344
+ ## US-0111 — Release trigger adapter family (trigger source dispatch, atomic version-file promotion)
345
+
346
+ Dispatch release flow by trigger source (GitHub webhook, npm publish, Git tag push, manual /release). Default source is `RELEASE_TRIGGER_SOURCE=manual` (zero behavior change vs pre-US-0111 /release path — byte-identical). Compose with existing release pipeline (US-0100); reuses `release_changelog_lib.compare_versions()` and `promote_unreleased()` without modification.
347
+
348
+ ### RELEASE_TRIGGER_* (9 codes)
349
+
350
+ | Code | Meaning | Blocking |
351
+ |------|---------|----------|
352
+ | **`RELEASE_TRIGGER_ADAPTER_FAILED`** | Trigger adapter dispatch failed (unknown source value) — unknown adapter name in registry. | **Yes** |
353
+ | **`RELEASE_TRIGGER_TAG_MISSING`** | Trigger source is git/github but no semantic version tag was found in the repository. | **Yes** |
354
+ | **`RELEASE_TRIGGER_PREVIOUS_MISSING`** | Cannot resolve previous version tag (required for diff-based changelog derivation). | **Yes** |
355
+ | **`RELEASE_TRIGGER_PACKAGE_JSON_MISSING`** | npm trigger source selected but `package.json` is absent from repository root. | **Yes** |
356
+ | **`RELEASE_TRIGGER_ATOMIC_PROMOTION_FAILED`** | Atomic rename (mv) of temporary version file to production path failed. | **Yes** |
357
+ | **`RELEASE_TRIGGER_NOTES_WRITE_FAILED`** | Per-version release notes write to `handoffs/releases/vX.Y.Z/release-notes.md` failed. | **Yes** |
358
+ | **`RELEASE_TRIGGER_EVENT_EMIT_FAILED`** | Failed to emit canonical `version_derivation` event to sovereign decision ledger (US-0107). | **Yes** |
359
+ | **`RELEASE_TRIGGER_COMPARE_VERSIONS_FAILED`** | Semver comparison between current and previous version failed (invalid format or equality check error). | **Yes** |
360
+ | **`RELEASE_TRIGGER_SOURCE_INVALID`** | `RELEASE_TRIGGER_SOURCE` in scratchpad is neither `auto` nor one of the four registered adapters (`github_webhook`, `npm_publish`, `git_tag_push`, `manual_release`). | **Yes** |
361
+
362
+ ### Operator remediation
363
+
364
+ | Reason code | Operator action |
365
+ |-------------|------------------|
366
+ | `RELEASE_TRIGGER_ADAPTER_FAILED` | Verify scratchpad `RELEASE_TRIGGER_SOURCE`; must be one of: `auto`, `github_webhook`, `npm_publish`, `git_tag_push`, `manual_release`. If `auto`, ensure only one trigger artifact exists in environment. |
367
+ | `RELEASE_TRIGGER_TAG_MISSING` | Tag current commit with a semantic version (`git tag vX.Y.Z && git push --tags`). |
368
+ | `RELEASE_TRIGGER_PREVIOUS_MISSING` | For initial releases, explicitly set `RELEASE_TRIGGER_PREVIOUS_VERSION=` in scratchpad. For subsequent releases, ensure at least one prior version tag exists in git history. |
369
+ | `RELEASE_TRIGGER_PACKAGE_JSON_MISSING` | Restore `package.json` to repository root (npm trigger requires it for version discovery). |
370
+ | `RELEASE_TRIGGER_ATOMIC_PROMOTION_FAILED` | Check filesystem permissions on target directory; verify no concurrent hold on the file; retry after resolving lock. |
371
+ | `RELEASE_TRIGGER_NOTES_WRITE_FAILED` | Check disk quota and directory permissions for `handoffs/releases/`; ensure no concurrent hold on target file. |
372
+ | `RELEASE_TRIGGER_EVENT_EMIT_FAILED` | Check ledger file permissions; ensure `handoffs/sovereign_decisions.jsonl` is writable; verify ledger schema compatibility. |
373
+ | `RELEASE_TRIGGER_COMPARE_VERSIONS_FAILED` | Verify both current and previous versions are valid semver (major.minor.patch); resolve any non-numeric suffixes or malformed tags. |
374
+ | `RELEASE_TRIGGER_SOURCE_INVALID` | Update scratchpad `RELEASE_TRIGGER_SOURCE` to `auto` or an explicit adapter name. Run `scripts/release_trigger_adapters.py --list` to see registered source names. |
375
+
376
+ ### Exit-code mapping
377
+
378
+ All 9 codes map to exit code `1` (fail-closed) — execution halts and requires operator intervention before proceeding.
379
+
380
+ ### Usage in CLI tools
381
+
382
+ - **`scripts/release_trigger_adapters.py`**: Adapter registry + dispatch logic; emits `RELEASE_TRIGGER_ADAPTER_FAILED` / `RELEASE_TRIGGER_SOURCE_INVALID` on invalid source.
383
+ - **`scripts/release_changelog_lib.py`**: Consumes `TriggerContext.version` and `TriggerContext.previous_version`; emits `RELEASE_TRIGGER_COMPARE_VERSIONS_FAILED` / `RELEASE_TRIGGER_PREVIOUS_MISSING` when version diff fails.
384
+ - **`scripts/release_promote_atomic.py`**: Orchestrates atomic promotion; emits `RELEASE_TRIGGER_ATOMIC_PROMOTION_FAILED` on rename failure.
385
+ - **`scripts/release_notes_emit.py`**: Writes per-version notes; emits `RELEASE_TRIGGER_NOTES_WRITE_FAILED` on I/O error.
386
+ - **Ledger integration**: Emits `version_derivation` decision type via `append_decision()` in `scripts/decision_ledger_lib.py`; emits `RELEASE_TRIGGER_EVENT_EMIT_FAILED` on ledger write failure.
387
+
388
+ ### Related artifacts
389
+
390
+ - **Architecture**: `docs/engineering/architecture.md` `# US-0111` (trigger adapter family + atomic version-file promotion)
391
+ - **Decision record**: `decisions/DEC-0111.md` (release trigger dispatch design)
392
+ - **Library**: `scripts/release_trigger_adapters.py` — adapter registry + `TriggerContext` dataclass
393
+ - **Contract tests**: `tests/us0111_contract_test.py` — adapter dispatch, previous-version resolution, atomic promotion, reason-code inventory
394
+
395
+ ---
396
+
397
+ ## Other stories
398
+
399
+ Reason codes for other stories live in their respective architecture sections:
400
+
401
+ - **US-0018** (installer upgrade): `UPGRADE_FILE_CLASSIFICATION_*`, `UPGRADE_VERSION_TRACKING_*`
402
+ - **US-0063** (runbook bootstrap): `RUNBOOK_BOOTSTRAP_ERROR`
403
+ - **US-0070** (phase selection): `PHASE_POLICY_CONFLICT`, `START_FROM_PHASE_PLAN_EMPTY_INTERSECTION`
404
+ - **US-0069** (phase role): `PHASE_ROLE_CAPABILITY_MISSING`
405
+ - **US-0048** (isolation): `PHASE_CONTEXT_ISOLATION_VIOLATION`
406
+ - **US-0087** (bug queue): `AUTO_BUG_QUEUE_EMPTY`, `AUTO_BUG_TARGET_*`
407
+ - **US-0086** (remote automation): `REMOTE_TARGET_*`, `REMOTE_AUTOMATION_MODE_OFF`
408
+ - **US-0092** (full autonomy): `AUTO_FLOW_MODE_CONFLICT`, `AUTO_OUTER_DRIVER_*`
409
+ - **US-0096** (delivery modes): `DELIVERY_MODE_UNKNOWN`, `LEAN_MEMORY_*`
410
+
411
+ See `docs/engineering/architecture.md` for normative definitions.