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
package/installer.ps1 CHANGED
@@ -129,6 +129,14 @@ function Classify-File($RelPath) {
129
129
  $frameworkExact = @(
130
130
  '.cursor/hooks.json',
131
131
  '.cursor/scratchpad.local.example.md',
132
+ '.cursor/model-catalog.local.example.json',
133
+ '.cursor/model-catalog.local.example.cursor-only.json',
134
+ '.cursor/model-catalog.local.example.level-1-easy.json',
135
+ '.cursor/model-catalog.local.example.level-2-complex.json',
136
+ '.cursor/model-catalog.local.example.level-3-mega.json',
137
+ '.cursor/model-catalog.local.example.level-4-super.json',
138
+ '.cursor/model-catalog.local.example.role-based-balanced.json',
139
+ '.cursor/model-catalog.local.example.role-based-highend.json',
132
140
  'its_magic/.its-magic-version',
133
141
  'its_magic/README.md'
134
142
  )
package/installer.py CHANGED
@@ -145,6 +145,14 @@ FRAMEWORK_PREFIXES = (
145
145
  )
146
146
  FRAMEWORK_EXACT = {
147
147
  ".cursor/hooks.json", ".cursor/scratchpad.local.example.md",
148
+ ".cursor/model-catalog.local.example.json",
149
+ ".cursor/model-catalog.local.example.cursor-only.json",
150
+ ".cursor/model-catalog.local.example.level-1-easy.json",
151
+ ".cursor/model-catalog.local.example.level-2-complex.json",
152
+ ".cursor/model-catalog.local.example.level-3-mega.json",
153
+ ".cursor/model-catalog.local.example.level-4-super.json",
154
+ ".cursor/model-catalog.local.example.role-based-balanced.json",
155
+ ".cursor/model-catalog.local.example.role-based-highend.json",
148
156
  ".its-magic-version", "its_magic/.its-magic-version", "its_magic/README.md",
149
157
  }
150
158
  USER_DATA_PREFIXES = (
package/installer.sh CHANGED
@@ -182,6 +182,7 @@ classify_file() {
182
182
  README.md) echo "mixed" ;;
183
183
  .cursor/commands/*|.cursor/rules/*|.cursor/agents/*|.cursor/skills/*) echo "framework" ;;
184
184
  .cursor/hooks/*|.cursor/hooks.json|.cursor/scratchpad.local.example.md) echo "framework" ;;
185
+ .cursor/model-catalog.local.example*.json) echo "framework" ;;
185
186
  .github/workflows/*|scripts/validate-and-push*|scripts/sync_push_gates.py|docs/engineering/context/*|its_magic/*) echo "framework" ;;
186
187
  .its-magic-version|its_magic/.its-magic-version|its_magic/README.md) echo "framework" ;;
187
188
  docs/product/*|docs/engineering/*|docs/user-guides/*) echo "user-data" ;;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "its-magic",
3
- "version": "0.1.3-1",
3
+ "version": "0.1.3-2",
4
4
  "description": "its-magic - AI dev team workflow for Cursor.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -522,6 +522,96 @@ used for resume/materialization failures):
522
522
  8. Sync verdict recording when eligible — reference step 12.
523
523
  9. Backlog-drain / bulk per-item summaries when enabled — reference step 13.
524
524
 
525
+ ## Cross-model adversarial critic post-phase hook (US-0104 / DEC-0104)
526
+
527
+ **Default-off**: `CROSS_MODEL_REVIEW=0` → **zero overhead** — no critic spawn, no findings
528
+ writes, no anti-slop gate. Existing phase lifecycle unchanged.
529
+
530
+ When `CROSS_MODEL_REVIEW=1`, after each **producer** phase subagent returns, orchestrator
531
+ **MUST Task-spawn** fresh **`/sovereign-critic`** subagent (spawn-only per **BUG-0006** /
532
+ **US-0048** / **US-0023**). Orchestrator must not execute critic evaluation in-process.
533
+
534
+ ### Hook sequence
535
+
536
+ 1. Resolve `producer_model_id` from phase context or `model_tier_lib.resolve_model_for_phase`.
537
+ 2. Call `select_critic_model(producer_model_id, scratchpad, phase_id)`.
538
+ 3. If `degraded=True` (`CROSS_MODEL_DEGRADED_MODE`): three **sequential** fresh subagent spawns
539
+ (same `model_id`, different lens prompts — challenger, architect, subtractor); all findings
540
+ record `degraded_mode=true`.
541
+ 4. Else: parallel jury via single critic subagent running all three lenses.
542
+ 5. Append findings to `handoffs/sovereign_critic_findings.jsonl`; validate with
543
+ `python scripts/sovereign_critic_validate.py --repo . --enforce`.
544
+ 6. When `AI_DECISION_LEDGER=1`, call `patch_ledger_cross_model_reviewed(...)`.
545
+
546
+ ### Anti-slop rework loop
547
+
548
+ After `/sovereign-critic`:
549
+
550
+ 1. Compute `anti_slop_aggregate = compute_anti_slop_aggregate(lens_scores)` (min of lens scores).
551
+ 2. Compare against `CROSS_MODEL_ANTISLOP_THRESHOLD` (default **6**).
552
+ 3. If aggregate **< threshold** and open **blocking** findings exist:
553
+ - Increment `rework_generation` for `(orchestrator_run_id, phase_id)`.
554
+ - If `rework_generation < CROSS_MODEL_REWORK_MAX` (default **2**): re-spawn producer phase
555
+ with fresh context; pass critic summary as read-only input → **`CROSS_MODEL_ANTISLOP_FAIL`**
556
+ (rework, not terminal).
557
+ - Else → **`CROSS_MODEL_REWORK_CAP_EXHAUSTED`** decision gate (operator waive or abort).
558
+
559
+ ### Isolation `model_id` v2
560
+
561
+ When `CROSS_MODEL_REVIEW=1`, both producer and critic isolation evidence rows require additive
562
+ **`model_id`**. Missing → fail-closed **`ISOLATION_EVIDENCE_MODEL_ID_MISSING`**.
563
+
564
+ ## Sovereign memory mistake-tagging hooks (US-0105 / DEC-0105)
565
+
566
+ **Default-off**: `SOVEREIGN_MEMORY=0` → **zero overhead** — no `mistakes.jsonl` writes.
567
+
568
+ When `SOVEREIGN_MEMORY=1`, orchestrator calls `record_mistake_hook(...)` from
569
+ `scripts/sovereign_memory_lib.py` on detectable failure events (closed `mistake_tag` enum):
570
+
571
+ | Trigger | `mistake_tag` | `failure_reason_code` |
572
+ |---------|---------------|----------------------|
573
+ | Auto-loop fix exhaust (`AUTO_IMPLEMENTATION_LOOP=1`) | `fix_failed` | `FIX_FAILED` |
574
+ | Execute revert/rollback | `revert_applied` | `REVERT_APPLIED` |
575
+ | Plan-fidelity hard stop (`classify_deviation` blocking) | `plan_fidelity_violation` | `PLAN_FIDELITY_VIOLATION` |
576
+ | Extended-mode scope add without override | `scope_creep` | `PLAN_FIDELITY_SCOPE_GATE` |
577
+
578
+ **US-0103 compose**: hooks may read ledger context for `provenance_ref` but must not mutate
579
+ ledger schema. Retrospectives under `sovereign-memory/retrospectives/` are **not injected v1**.
580
+
581
+ ## Sovereign Loop Mode (US-0107 / DEC-0107)
582
+
583
+ **Default-off**: `AUTO_SOVEREIGN=0` → **zero overhead** — no deferral reads/writes, no advance,
584
+ no notifications. Requires **`SOVEREIGN_GOAL_MODE=goal_convergence`** when enabled (fail-closed
585
+ **`SOVEREIGN_LOOP_GOAL_MODE_REQUIRED`**).
586
+
587
+ ### Advance hook (post-segment)
588
+
589
+ After each native-chain segment completes ( **`stop_phase=refresh-context`** ), when
590
+ `AUTO_SOVEREIGN=1` and goal convergence active, orchestrator calls
591
+ `advance_sovereign_loop(repo, scratchpad, orchestrator_run_id=...)` from
592
+ `scripts/sovereign_loop_lib.py`. Sovereign terminal stops are **additive** to the US-0088 /
593
+ US-0092 stop matrix — do not replace `decision_gate`, `loop_max`, or security deny.
594
+
595
+ ### Drain-generate (spawn-only PO / US-0095)
596
+
597
+ When advance returns `action=drain_generate`:
598
+
599
+ 1. Build PO spawn inputs via `build_drain_generate_spawn_inputs(...)` (vision narrow-read;
600
+ optional `sovereign_memory_digest` when `SOVEREIGN_MEMORY=1`).
601
+ 2. **MUST Task-spawn** fresh **PO** subagent (spawn-only per **US-0069** / **US-0095**) with
602
+ ephemeral work item id `drain-gen-{orchestrator_run_id}-{iteration}` — **not** a backlog row
603
+ until accepted.
604
+ 3. PO returns up to **3** candidates in `DrainGenerateCandidateBundle` v1.
605
+ 4. **Decision gate (mandatory per candidate)**: operator accept → **`/intake`** or controlled
606
+ backlog append; reject → discard. **No auto-append** without gate (**US-0092** hard gate).
607
+
608
+ ### Deferral register operator path
609
+
610
+ - Append: `append_deferral(...)` → `handoffs/sovereign_deferrals.jsonl` (create-on-first-write).
611
+ - Resolve: `resolve_deferral(repo, deferral_id, orchestrator_run_id=...)`.
612
+ - Validate: `python scripts/sovereign_loop_validate.py --repo . --enforce`.
613
+ - **US-0109** integration: downstream writer appends `DEPLOY_DEFERRED` rows (`work_item_kind=deploy`).
614
+
525
615
  ## Backward compatibility
526
616
 
527
617
  Default manual/interactive unchanged; `/resume` remains valid; deterministic precedence
@@ -22,6 +22,7 @@ At the end of `/execute`, append an isolation evidence entry to
22
22
  - `fresh_context_marker=<new marker for this subagent>`
23
23
  - `timestamp=<ISO UTC>`
24
24
  - `evidence_ref=<primary output ref>` (recommended: `handoffs/dev_to_qa.md` and the target sprint `sprints/Sxxxx/summary.md`)
25
+ - `model_id=<resolved model slug or alias>` — **required when `CROSS_MODEL_REVIEW=1`** (US-0104 v2 additive extension); omit when `CROSS_MODEL_REVIEW=0`. Missing → fail-closed **`ISOLATION_EVIDENCE_MODEL_ID_MISSING`**.
25
26
 
26
27
  In an execute↔QA implementation loop (`AUTO_IMPLEMENTATION_LOOP=1`), each new
27
28
  `/execute` cycle must have a new `fresh_context_marker` (marker reuse is treated
@@ -32,6 +33,10 @@ as stale isolation evidence).
32
33
  - **Narrow-read (US-0053 / US-0096 Tranche A)**: Start at docs/engineering/phase-context.md
33
34
  and the story section anchor in vision/architecture/decisions when a heading exists; forbid
34
35
  full-file reads when a section heading exists.
36
+ - **Sovereign memory digest (US-0105 / DEC-0105)**: When merged scratchpad `SOVEREIGN_MEMORY=1`,
37
+ spawn assembler appends read-only **`sovereign_memory_digest`** block after phase-context
38
+ narrow-read and before role instructions via `build_injection_digest_block(...)` from
39
+ `scripts/sovereign_memory_lib.py`. Zero overhead when `SOVEREIGN_MEMORY=0` (default).
35
40
  - `sprints/S0001/tasks.md`
36
41
  - `handoffs/tl_to_dev.md`
37
42
  - Optional: `handoffs/qa_to_dev.md` when fixing QA findings
@@ -341,3 +346,24 @@ Reason codes: **`UAT_BROWSER_UNAVAILABLE`**, **`UAT_BROWSER_PROBE_FAILED`**,
341
346
  remote cues (compose when both fire).
342
347
  - Active + `template/.cursor/commands/execute.md` byte-identical step **24** block.
343
348
 
349
+ 25. Cross-model critic evidence tuple (US-0104 / DEC-0104):
350
+ - **25 preamble**: Read merged scratchpad `CROSS_MODEL_REVIEW` (default `0`). When `0`,
351
+ skip **25a** with zero overhead — no `critic_evidence` block required.
352
+ - **25a Handoff block**: When `CROSS_MODEL_REVIEW=1`, append fenced JSON under
353
+ **`### critic_evidence`** in `handoffs/dev_to_qa.md` using
354
+ `build_critic_evidence_block(...)` from `scripts/sovereign_critic_lib.py`:
355
+ `producer_model_id`, `critic_model_id`, `anti_slop_aggregate`, `rework_generation`,
356
+ `degraded_mode`, `findings_path`.
357
+ - Isolation evidence for `/execute` must include **`model_id`** on the producer row when
358
+ critic is enabled (see Isolation evidence write requirement above).
359
+ - Active + `template/.cursor/commands/execute.md` byte-identical step **25** block.
360
+
361
+ 26. Sovereign memory mistake hook — revert/rollback (US-0105 / DEC-0105):
362
+ - **26 preamble**: Read merged scratchpad `SOVEREIGN_MEMORY` (default `0`). When `0`, skip
363
+ with zero overhead.
364
+ - **26a Revert path**: When git revert or rollback is applied during execute findings
365
+ remediation, call `record_mistake_hook(mistake_tag="revert_applied", ...)` from
366
+ `scripts/sovereign_memory_lib.py` with `failure_reason_code=REVERT_APPLIED`. Optional
367
+ `provenance_ref` may cite ledger context (**US-0103** read-only — do not mutate ledger schema).
368
+ - Active + `template/.cursor/commands/execute.md` byte-identical step **26** block.
369
+
@@ -56,6 +56,38 @@ description: "its-magic refresh context: compact state and decisions."
56
56
  - record verification tuple fields (`boundary`, `moved`, `retained`,
57
57
  `pack_ref`) in the new `state.md` checkpoint when any rollover occurred;
58
58
  idempotent reruns must not duplicate archived content.
59
+ 3b. **Goal progress emission (US-0110 / DEC-0110)**: when merged scratchpad
60
+ `SOVEREIGN_GOAL_MODE=goal_convergence` and sovereign loop is active, run from repo root:
61
+
62
+ ```bash
63
+ python scripts/sovereign_convergence_lib.py --emit-resume-brief --repo . --orchestrator-run-id <run_id>
64
+ ```
65
+
66
+ Writes a fenced JSON block under **`### goal_progress`** in `handoffs/resume_brief.md`.
67
+ Placement: after the latest **`## Latest orchestration pointer`** section, before
68
+ **`## Prior orchestration pointer`**. Skip entirely when `SOVEREIGN_GOAL_MODE=phase_driven`
69
+ (zero overhead). Validate shape with:
70
+
71
+ ```bash
72
+ python scripts/sovereign_convergence_validate.py --repo . --enforce
73
+ ```
74
+
75
+ 3c. **Sovereign memory curator retrospective + ledger promotion (US-0105 / DEC-0105)**:
76
+ after release segment close, when merged scratchpad `SOVEREIGN_MEMORY=1`:
77
+
78
+ 1. `write_retrospective(sprint_id, body)` →
79
+ `docs/engineering/sovereign-memory/retrospectives/<sprint_id>.md` with
80
+ `{sprint_id, story_ids[], release_ref, summary, learnings[], promoted_entry_ids[]}`.
81
+ 2. When **also** `AI_DECISION_LEDGER=1`: `promote_from_ledger(orchestrator_run_id, ...)`
82
+ copies subset to `decisions-log.jsonl` with `provenance_ref=ledger:<decision_id>`.
83
+ 3. When ledger off or filter empty → informational **`SOVEREIGN_MEMORY_PROMOTION_SKIPPED`**.
84
+
85
+ Retrospectives are human audit only — **not injected v1**. Skip entirely when
86
+ `SOVEREIGN_MEMORY=0` (zero overhead). Validate JSONL when files exist:
87
+
88
+ ```bash
89
+ python scripts/sovereign_memory_validate.py --repo . --enforce
90
+ ```
59
91
 
60
92
  ## Deterministic artifact ordering contract (US-0058 / DEC-0040)
61
93
 
@@ -0,0 +1,104 @@
1
+ ---
2
+ description: "its-magic sovereign-critic: cross-model adversarial review after producer phase."
3
+ ---
4
+
5
+ # /sovereign-critic
6
+
7
+ ## Subagents
8
+ - tech-lead (default critic role; fresh context per US-0048 / US-0023)
9
+
10
+ ## Execution model
11
+ - Run `/sovereign-critic` in a **fresh critic subagent** context only.
12
+ - Invoked by **`/auto`** orchestrator **after** a producer phase completes when
13
+ `CROSS_MODEL_REVIEW=1` (default-off — zero overhead when `0`).
14
+ - Orchestrator **must not** execute critic work in-process (**BUG-0006** spawn-only).
15
+ - All three lenses run per invocation (parallel jury when distinct critic model;
16
+ sequential fresh spawns in degraded single-model-multi-lens mode).
17
+
18
+ ## Inputs
19
+
20
+ - `phase_id` — completed producer phase id (DEC-0086 canonical)
21
+ - `role` — producer logical role (`po`, `tech-lead`, `dev`, `qa`, …)
22
+ - `evidence_ref` — primary artifact refs for the completed phase
23
+ - `producer_model_id` — resolved slug or alias (`fast`, `inherit`, vendor slug)
24
+ - `artifact_digest` — bounded summary of phase deliverables under review
25
+ - `orchestrator_run_id` — partition key for rework counter
26
+
27
+ ## Model selection
28
+
29
+ Resolve critic via `scripts/sovereign_critic_lib.py`:
30
+
31
+ ```python
32
+ select_critic_model(producer_model_id, scratchpad, phase_id)
33
+ ```
34
+
35
+ - Tier opposition: producer `strong`/`balanced` → critic `cheap`; producer `cheap` → critic `strong`.
36
+ - Same normalized slug → `degraded_mode=true`, reason `CROSS_MODEL_DEGRADED_MODE`.
37
+ - Catalog miss → degraded fallback (three sequential lens spawns, same `model_id`).
38
+
39
+ ## Three-lens evaluation (all lenses per invocation)
40
+
41
+ | Lens | Focus | Checklist (2.5 pts each) |
42
+ |------|-------|--------------------------|
43
+ | **`challenger`** | Edge cases, races, failure modes, boundaries | edge_case_cited; failure_mode_named; concurrency_considered; input_boundary_tested |
44
+ | **`architect`** | Coupling, layering, dependency direction | coupling_named; layer_boundary_stated; dependency_direction_explicit; interface_contract_mentioned |
45
+ | **`subtractor`** | Over-engineering, YAGNI, scope creep | unnecessary_abstraction_flagged; yagni_applied; premature_generalization_challenged; scope_creep_identified |
46
+
47
+ ### Lens prompt templates
48
+
49
+ **Challenger** — Find edge cases, race conditions, failure modes, and boundary violations in the phase artifacts. Cite specific paths. Report checklist hits and propose blocking findings when convergence should halt.
50
+
51
+ **Architect** — Evaluate coupling, layer boundaries, dependency direction, and interface contracts. Name modules and layers explicitly. Flag violations that block release readiness.
52
+
53
+ **Subtractor** — Challenge over-engineering, premature abstraction, YAGNI violations, and scope creep. Prefer minimal diffs aligned with task scope.
54
+
55
+ ## Anti-slop scoring
56
+
57
+ Per lens: `score_lens_antislop(lens, checklist_hits)` → int 0–10.
58
+ Aggregate: `compute_anti_slop_aggregate(lens_scores)` → `min(lens_scores)`.
59
+
60
+ Agent-reported `anti_slop_score` must be ≤ rubric ceiling (lib clamps down).
61
+
62
+ ## Reconciliation
63
+
64
+ After all lens findings are collected, run `reconcile_findings(raw_findings)`:
65
+
66
+ - ≥2 lenses share `issue_key` → `confidence=high`, `single_finder=false`
67
+ - Exactly 1 lens → `confidence=medium`, `single_finder=true`
68
+
69
+ ## Outputs (artifacts)
70
+
71
+ - Append findings to **`handoffs/sovereign_critic_findings.jsonl`** (15-field v1 schema)
72
+ - Optional **`cross_reviewer_findings`** block in sprint **`qa-findings.md`** via
73
+ `build_qa_cross_reviewer_block(repo)`
74
+ - When `AI_DECISION_LEDGER=1`, call `patch_ledger_cross_model_reviewed(...)` with
75
+ `cross_model_reviewed=True`
76
+
77
+ ## Isolation evidence (US-0048 + US-0104 v2)
78
+
79
+ At the end of `/sovereign-critic`, append isolation evidence to `docs/engineering/state.md`:
80
+
81
+ - `phase_id=sovereign-critic`
82
+ - `role=tech-lead` (or configured critic role)
83
+ - `fresh_context_marker=<new marker for this critic subagent>`
84
+ - `timestamp=<ISO UTC>`
85
+ - `evidence_ref=<findings path + reviewed artifacts>`
86
+ - `model_id=<critic_model_id>` — **required when `CROSS_MODEL_REVIEW=1`**; omit when `0`
87
+
88
+ Missing `model_id` when critic enabled → fail-closed **`ISOLATION_EVIDENCE_MODEL_ID_MISSING`**.
89
+
90
+ ## Stop conditions
91
+
92
+ - `CROSS_MODEL_REVIEW=0` → skip entirely (zero overhead)
93
+ - `CROSS_MODEL_CRITIC_SPAWN_FAILED` → blocking orchestrator hook failure
94
+ - `CROSS_MODEL_FINDINGS_INVALID` → schema validation failure
95
+ - `CROSS_MODEL_RECONCILE_FAILED` → jury merge error
96
+
97
+ ## Validator
98
+
99
+ ```bash
100
+ python scripts/sovereign_critic_validate.py --repo . --enforce
101
+ python scripts/sovereign_critic_validate.py --open-blocking --repo .
102
+ ```
103
+
104
+ Success literal: **`[SOVEREIGN_CRITIC_VALIDATION_OK]`**.
@@ -0,0 +1,27 @@
1
+ ---
2
+ description: "Sovereign Role-Behavior Manifest enforcement (US-0106 / DEC-0106)"
3
+ globs:
4
+ ---
5
+
6
+ - When `SOVEREIGN_ROLE_MANIFEST=1` in scratchpad, the sovereign role manifest at
7
+ `.cursor/sovereign-role-manifest.yaml` is the additive per-role objective and
8
+ inter-role review obligation layer on top of US-0069 spawn machinery.
9
+ - Review spawns are supplementary post-phase hooks — they never substitute for
10
+ the US-0069 producer role.
11
+ - Validate manifest with `python scripts/sovereign_role_manifest_validate.py --repo .`.
12
+ - Schema v1 requires 6 sections: `schema_version`, `roles[]`, `review_obligations[]`,
13
+ `allowed_self_overrides`, `cross_model_policy`, `escalation_rules`.
14
+ - Six role IDs: `po`, `tech-lead`, `dev`, `qa`, `release`, `curator`.
15
+ - Review foci: `user_value_drift`, `testability`, `buildability`, `deployability`.
16
+ - Cross-model default orders: `role_review_first`, `critic_first`, `critic_only`, `role_review_only`.
17
+ - Secret-literal scan: no `api_key`, `token`, `password`, `secret`, `private_key` shaped
18
+ literals in `objective_function` fields (`SOVEREIGN_ROLE_SECRET_DETECTED`).
19
+ - Objective injection char cap: `SOVEREIGN_ROLE_OBJECTIVE_MAX_CHARS` (default 512).
20
+ - Obligation dispatch per-phase cap: `SOVEREIGN_ROLE_REVIEW_MAX_PER_PHASE` (default 2).
21
+ - Rework cap: `SOVEREIGN_ROLE_REVIEW_REWORK_MAX` (default 1).
22
+ - Default-off: `SOVEREIGN_ROLE_MANIFEST=0` → zero overhead (no file I/O).
23
+ - Compose guards: US-0069 phase→role matrix unchanged, US-0104 critic schema unchanged.
24
+ - Reason codes: `SOVEREIGN_ROLE_MANIFEST_DISABLED`, `SOVEREIGN_ROLE_MANIFEST_SCHEMA_INVALID`,
25
+ `SOVEREIGN_ROLE_UNKNOWN_ROLE`, `SOVEREIGN_ROLE_UNKNOWN_PHASE`, `SOVEREIGN_ROLE_SECRET_DETECTED`,
26
+ `SOVEREIGN_ROLE_OBJECTIVE_OVERFLOW`, `ROLE_REVIEW_DISPATCH_FAILED`, `ROLE_REVIEW_SPAWN_FAILED`,
27
+ `ROLE_REVIEW_BLOCKED`, `ROLE_REVIEW_DEFERRAL_FAILED`, `ROLE_REVIEW_REWORK_CAP`.
@@ -384,3 +384,144 @@ MODEL_PROVIDER_MODE=cursor
384
384
  # MODEL_QA=<your-vendor-slug>
385
385
  # MODEL_REFRESH-CONTEXT=<your-vendor-slug>
386
386
  # MODEL_ASK participates in step 1 like any other phase (no special-case bypass).
387
+ #
388
+ # AI Decision Ledger + Plan Fidelity (US-0103 / DEC-0103)
389
+ # Sovereign-loop foundation. Default-off — zero overhead when AI_DECISION_LEDGER=0.
390
+ # - AI_DECISION_LEDGER: 0|1 (default 0) — when 0: no ledger reads/writes/schema checks.
391
+ # - AUTO_PLAN_FIDELITY: strict|relaxed|extended (default strict) — active only when ledger enabled.
392
+ # strict = any unapproved drop/reorder/scope-add → PLAN_FIDELITY_VIOLATION hard stop
393
+ # relaxed = drop/reorder allowed (ledger entry); scope-add still hard stop
394
+ # extended = scope-add allowed (extension report); drop/reorder allowed
395
+ AI_DECISION_LEDGER=0
396
+ AUTO_PLAN_FIDELITY=strict
397
+ #
398
+ # Goal-Based Convergence (US-0110 / DEC-0110)
399
+ # Default-off sovereign-loop terminal predicate. When SOVEREIGN_GOAL_MODE=phase_driven,
400
+ # zero overhead — no evaluation, no goal_progress block, no partial-delivery write.
401
+ # Compose do NOT amend US-0088 / US-0092 / US-0095 / US-0044 / US-0103 (read-only surfaces).
402
+ # - SOVEREIGN_GOAL_MODE: phase_driven|goal_convergence (default phase_driven)
403
+ # - SOVEREIGN_GOAL: explicit goal text (wins over vision auto-derive; default empty)
404
+ # - SOVEREIGN_GOAL_TOP_N: int >= 1 vision paragraph count for auto-derive (default 3)
405
+ # - SOVEREIGN_GOAL_MAX_CHARS: int >= 64 truncation cap (default 512)
406
+ # - SOVEREIGN_GOAL_TIMEOUT_MAX: int >= 0 iteration-count cap (0 = disabled; not wall-clock)
407
+ SOVEREIGN_GOAL_MODE=phase_driven
408
+ SOVEREIGN_GOAL=
409
+ SOVEREIGN_GOAL_TOP_N=3
410
+ SOVEREIGN_GOAL_MAX_CHARS=512
411
+ SOVEREIGN_GOAL_TIMEOUT_MAX=0
412
+ #
413
+ # Cross-Model Adversarial Critic (US-0104 / DEC-0104)
414
+ # Default-off cross-model review. When CROSS_MODEL_REVIEW=0, zero overhead — no critic
415
+ # spawn, no findings writes, no anti-slop gate. Compose do NOT amend US-0048 / US-0069 /
416
+ # US-0023 / US-0110 / US-0103 (additive surfaces only).
417
+ # - CROSS_MODEL_REVIEW: 0|1 (default 0)
418
+ # - CROSS_MODEL_ANTISLOP_THRESHOLD: int 0-10 aggregate floor (default 6)
419
+ # - CROSS_MODEL_REWORK_MAX: int >= 0 producer re-spawns per (run, phase) (default 2)
420
+ CROSS_MODEL_REVIEW=0
421
+ CROSS_MODEL_ANTISLOP_THRESHOLD=6
422
+ CROSS_MODEL_REWORK_MAX=2
423
+ #
424
+ # Sovereign Memory (US-0105 / DEC-0105)
425
+ # Default-off institutional memory. When SOVEREIGN_MEMORY=0, zero overhead —
426
+ # no JSONL writes, no injection reads, no spawn digest assembly.
427
+ # Compose do NOT amend US-0029 / US-0080 / US-0103 / US-0072 / US-0096.
428
+ # - SOVEREIGN_MEMORY: 0|1 (default 0)
429
+ # - SOVEREIGN_MEMORY_TOP_N: int >= 0 (default 5) — global recent pool (all four JSONL families)
430
+ # - SOVEREIGN_MEMORY_TOP_K: int >= 0 (default 3) — high-impact pool (patterns + mistakes only)
431
+ # - SOVEREIGN_MEMORY_MAX_CHARS: int >= 0 (default 2048) — hard cap on assembled digest_text
432
+ # - SOVEREIGN_MEMORY_JSONL_MAX_LINES: int >= 1 (default 500) — active JSONL line cap before archive rollover
433
+ SOVEREIGN_MEMORY=0
434
+ SOVEREIGN_MEMORY_TOP_N=5
435
+ SOVEREIGN_MEMORY_TOP_K=3
436
+ SOVEREIGN_MEMORY_MAX_CHARS=2048
437
+ SOVEREIGN_MEMORY_JSONL_MAX_LINES=500
438
+ #
439
+ # Sovereign Loop Mode (US-0107 / DEC-0107)
440
+ # Default-off project orchestration. When AUTO_SOVEREIGN=0, zero overhead — no deferral
441
+ # reads/writes, no advance, no notifications. Requires SOVEREIGN_GOAL_MODE=goal_convergence
442
+ # when enabled (fail-closed SOVEREIGN_LOOP_GOAL_MODE_REQUIRED). Compose do NOT amend
443
+ # US-0088 / US-0092 / US-0095 / US-0044 / US-0103 / US-0105 / US-0110 (additive hooks only).
444
+ # - AUTO_SOVEREIGN: 0|1 (default 0)
445
+ # - AUTO_SOVEREIGN_DEFERRAL_MAX: int >= 1 (default 50) — max open deferral rows
446
+ # - AUTO_SOVEREIGN_DRAIN_GENERATE_MAX: int >= 0 (default 3) — drain-generate iterations per run
447
+ # - AUTO_SOVEREIGN_DEFERRAL_POLICY: stop|skip|resolve_first (default resolve_first)
448
+ # - SOVEREIGN_NOTIFY_TARGET: off|ntfy|email|hook (default off)
449
+ # - SOVEREIGN_NOTIFY_NTFY_TOPIC: string (default empty — local-only)
450
+ # - SOVEREIGN_NOTIFY_NTFY_BASE: URL (default empty — local-only ntfy base override)
451
+ # - SOVEREIGN_NOTIFY_HOOK_URL: URL (default empty — local-only webhook)
452
+ # - SOVEREIGN_NOTIFY_EMAIL_TO: email (default empty — email v1 deferred)
453
+ AUTO_SOVEREIGN=0
454
+ AUTO_SOVEREIGN_DEFERRAL_MAX=50
455
+ AUTO_SOVEREIGN_DRAIN_GENERATE_MAX=3
456
+ AUTO_SOVEREIGN_DEFERRAL_POLICY=resolve_first
457
+ SOVEREIGN_NOTIFY_TARGET=off
458
+ SOVEREIGN_NOTIFY_NTFY_TOPIC=
459
+ SOVEREIGN_NOTIFY_NTFY_BASE=
460
+ SOVEREIGN_NOTIFY_HOOK_URL=
461
+ SOVEREIGN_NOTIFY_EMAIL_TO=
462
+ #
463
+ # Sovereign Role-Behavior Manifest (US-0106 / DEC-0106)
464
+ # Default-off per-role objective + inter-role review obligations. When SOVEREIGN_ROLE_MANIFEST=0,
465
+ # zero overhead — no manifest reads, no objective injection, no review dispatch.
466
+ # Compose do NOT amend US-0069 (phase→role matrix unchanged; review spawns supplementary),
467
+ # US-0104 (critic lenses + findings schema unchanged; role reviews additive),
468
+ # US-0003 / US-0023 / US-0103 / US-0105 / US-0107 (unchanged surfaces).
469
+ # - SOVEREIGN_ROLE_MANIFEST: 0|1 (default 0)
470
+ # - SOVEREIGN_ROLE_OBJECTIVE_MAX_CHARS: int >= 1 (default 512) — hard truncate for injection
471
+ # - SOVEREIGN_ROLE_REVIEW_MAX_PER_PHASE: int >= 0 (default 2) — per-phase review cap
472
+ # - SOVEREIGN_ROLE_REVIEW_REWORK_MAX: int >= 0 (default 1) — bounded rework before decision gate
473
+ SOVEREIGN_ROLE_MANIFEST=0
474
+ SOVEREIGN_ROLE_OBJECTIVE_MAX_CHARS=512
475
+ SOVEREIGN_ROLE_REVIEW_MAX_PER_PHASE=2
476
+ SOVEREIGN_ROLE_REVIEW_REWORK_MAX=1
477
+ #
478
+ # Parallel Instance Arbitrage (US-0108 / DEC-0108)
479
+ # Default-off parallel execute-phase instance orchestration. When SOVEREIGN_PARALLEL_DEV=0,
480
+ # zero overhead — no worktrees, no parallel QA, no pick JSON, no resource guard.
481
+ # Compose do NOT amend US-0047 (bulk execute unchanged), US-0092 (full autonomy unchanged),
482
+ # US-0103 (ledger schema unchanged; read-only consumer), US-0104 (critic schema unchanged;
483
+ # read-only anti_slop_score consumer), US-0107 (sovereign loop unchanged; consumer only).
484
+ # - SOVEREIGN_PARALLEL_DEV: 0|1 (default 0) — global enable gate
485
+ # - AUTO_SOVEREIGN_PARALLEL_N: int >= 1 (default 3) — instances per execute cycle
486
+ # - AUTO_SOVEREIGN_PARALLEL_MAX_TOTAL: int >= 1 (default 6) — system-wide instance cap
487
+ # - AUTO_SOVEREIGN_MERGE_RESOLVE: first_pass_wins|last_pass_wins|winner_takes_all|manual (default first_pass_wins)
488
+ # - AUTO_SOVEREIGN_WORKTREE_KEEP: 0|1 (default 0) — retain loser worktrees for debugging
489
+ # - AUTO_SOVEREIGN_PARALLEL_QA: 0|1 (default 0) — enable parallel QA cross-review (v2)
490
+ # - AUTO_SOVEREIGN_PARALLEL_QA_ARBITER: critic_first_pass|majority_vote (default critic_first_pass)
491
+ # - AUTO_SOVEREIGN_PARALLEL_ANTI_SLOP_THRESHOLD: int 0-10 (default 6) — anti-slop floor
492
+ # - AUTO_SOVEREIGN_PARALLEL_REWORK_MAX: int >= 0 (default 2) — per-instance rework cap
493
+ # - AUTO_SOVEREIGN_PARALLEL_MERGE_TIMEOUT_SEC: int >= 10 (default 60) — merge timeout
494
+ # - AUTO_SOVEREIGN_PARALLEL_MODEL_<idx>: model slug per instance (optional)
495
+ # - AUTO_SOVEREIGN_PARALLEL_LENS_<idx>: lens config per instance (optional)
496
+ SOVEREIGN_PARALLEL_DEV=0
497
+ AUTO_SOVEREIGN_PARALLEL_N=3
498
+ AUTO_SOVEREIGN_PARALLEL_MAX_TOTAL=6
499
+ AUTO_SOVEREIGN_MERGE_RESOLVE=first_pass_wins
500
+ AUTO_SOVEREIGN_WORKTREE_KEEP=0
501
+ AUTO_SOVEREIGN_PARALLEL_QA=0
502
+ AUTO_SOVEREIGN_PARALLEL_QA_ARBITER=critic_first_pass
503
+ AUTO_SOVEREIGN_PARALLEL_ANTI_SLOP_THRESHOLD=6
504
+ AUTO_SOVEREIGN_PARALLEL_REWORK_MAX=2
505
+ AUTO_SOVEREIGN_PARALLEL_MERGE_TIMEOUT_SEC=60
506
+ #
507
+ # Self-Healing Deploy Loop (US-0109 / DEC-0109)
508
+ # Default-off auto-heal post-publish probe + bounded retry + DEPLOY_DEFERRED.
509
+ # When AUTO_SOVEREIGN_SELF_HEALING_DEPLOY=0 zero overhead, byte-identical US-0054 publish path —
510
+ # no probe, no retry, no deferral, no execute steps 29-31. Compose do NOT amend US-0054 / US-0100 /
511
+ # US-0103 / US-0107 / US-0110 (US-0109 consumer-only hook after US-0054 publish PASS).
512
+ # - AUTO_SOVEREIGN_SELF_HEALING_DEPLOY: 0|1 (default 0) — global gate
513
+ # - AUTO_SOVEREIGN_DEPLOY_RETRY_MAX: int >= 1 (default 3) — max retry attempts after probe FAIL
514
+ # - AUTO_SOVEREIGN_DEPLOY_SMOKE_TIMEOUT_SEC: int >= 1 (default 30) — per-stage probe HTTP timeout
515
+ # - AUTO_SOVEREIGN_DEPLOY_PROBE_KIND: health_endpoint|acceptance_smoke|both (default both)
516
+ # - SOVEREIGN_DEPLOY_ACCEPTANCE_SMOKE_PATH: repo-relative path (default tests/deploy_smoke/)
517
+ # - AUTO_SOVEREIGN_DEPLOY_HEALTH_ENDPOINT: names-only env ref (US-0085 compose); empty = unresolvable
518
+ # Reason codes (DEC-0109 §7): DEPLOY_HEALING_DISABLED (info), DEPLOY_HEALING_SMOKE_HEALTH_FAIL,
519
+ # DEPLOY_HEALING_SMOKE_ACCEPTANCE_FAIL, DEPLOY_HEALING_RETRY_ATTEMPT,
520
+ # DEPLOY_HEALING_RETRY_CAP_EXHAUSTED, DEPLOY_HEALING_DEFERRED,
521
+ # DEPLOY_HEALING_PROBE_TARGET_MISSING, DEPLOY_HEALING_TIMEOUT.
522
+ AUTO_SOVEREIGN_SELF_HEALING_DEPLOY=0
523
+ AUTO_SOVEREIGN_DEPLOY_RETRY_MAX=3
524
+ AUTO_SOVEREIGN_DEPLOY_SMOKE_TIMEOUT_SEC=30
525
+ AUTO_SOVEREIGN_DEPLOY_PROBE_KIND=both
526
+ SOVEREIGN_DEPLOY_ACCEPTANCE_SMOKE_PATH=tests/deploy_smoke/
527
+ AUTO_SOVEREIGN_DEPLOY_HEALTH_ENDPOINT=
@@ -0,0 +1,53 @@
1
+ schema_version: 1
2
+ roles:
3
+ - role_id: po
4
+ objective_function: Maximize user value delivery through discovery, intake, and acceptance criteria
5
+ - role_id: tech-lead
6
+ objective_function: Produce buildable architecture aligned to user value and testable scope
7
+ - role_id: dev
8
+ objective_function: Implement planned tasks with artifact discipline and zero regression
9
+ - role_id: qa
10
+ objective_function: Verify test plan, runtime evidence, and blocking-findings disposition
11
+ - role_id: release
12
+ objective_function: Gate release surfaces, parity, and operator-facing connectivity
13
+ - role_id: curator
14
+ objective_function: Keep state, decisions, and research surfaces compact and current
15
+ review_obligations:
16
+ - obligation_id: O1
17
+ reviewer_role: po
18
+ target_role: tech-lead
19
+ trigger_phase: architecture
20
+ review_focus: user_value_drift
21
+ artifact_refs:
22
+ - docs/engineering/architecture.md
23
+ blocking: false
24
+ - obligation_id: O2
25
+ reviewer_role: qa
26
+ target_role: po
27
+ trigger_phase: intake
28
+ review_focus: testability
29
+ artifact_refs:
30
+ - docs/product/acceptance.md
31
+ blocking: false
32
+ - obligation_id: O3
33
+ reviewer_role: dev
34
+ target_role: tech-lead
35
+ trigger_phase: architecture
36
+ review_focus: buildability
37
+ artifact_refs:
38
+ - docs/engineering/architecture.md
39
+ blocking: false
40
+ - obligation_id: O4
41
+ reviewer_role: release
42
+ target_role: qa
43
+ trigger_phase: qa
44
+ review_focus: deployability
45
+ artifact_refs:
46
+ - sprints/Sxxxx/qa-findings.md
47
+ blocking: false
48
+ allowed_self_overrides: [verbosity, detail_level, tone]
49
+ cross_model_policy:
50
+ default_order: role_review_first
51
+ escalation_rules:
52
+ rework_max: 1
53
+ decision_gate: operator