its-magic 0.1.3-1 → 0.1.3-3

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 (49) 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/scripts/check_intake_template_parity.py +119 -0
  6. package/template/.cursor/commands/auto.md +90 -0
  7. package/template/.cursor/commands/execute.md +26 -0
  8. package/template/.cursor/commands/refresh-context.md +32 -0
  9. package/template/.cursor/commands/sovereign-critic.md +104 -0
  10. package/template/.cursor/rules/sovereign-role-manifest.mdc.example +27 -0
  11. package/template/.cursor/scratchpad.local.example.md +539 -378
  12. package/template/.cursor/scratchpad.md +141 -0
  13. package/template/.cursor/sovereign-role-manifest.yaml.example +53 -0
  14. package/template/decisions/DEC-0104.md +279 -0
  15. package/template/decisions/DEC-0105.md +231 -0
  16. package/template/decisions/DEC-0107.md +246 -0
  17. package/template/docs/engineering/architecture.md +78 -0
  18. package/template/docs/engineering/auto-orchestration-reference.md +7 -0
  19. package/template/docs/engineering/context/installer-owned-paths.manifest +8 -0
  20. package/template/docs/engineering/reason_codes.md +411 -0
  21. package/template/docs/engineering/runbook.md +988 -0
  22. package/template/docs/engineering/sovereign-memory/.gitkeep +0 -0
  23. package/template/docs/engineering/sovereign-memory/retrospectives/.gitkeep +0 -0
  24. package/template/handoffs/sovereign_decisions/.gitkeep +0 -0
  25. package/template/handoffs/sovereign_deferrals/.gitkeep +0 -0
  26. package/template/handoffs/sovereign_role_reviews.jsonl +0 -0
  27. package/template/scripts/__pycache__/decision_ledger_lib.cpython-312.pyc +0 -0
  28. package/template/scripts/check_intake_template_parity.py +119 -0
  29. package/template/scripts/decision_ledger_lib.py +732 -0
  30. package/template/scripts/ledger_validate.py +153 -0
  31. package/template/scripts/parallel_dev_arbiter.py +923 -0
  32. package/template/scripts/release_trigger_adapters.py +843 -0
  33. package/template/scripts/self_healing_deploy_lib.py +463 -0
  34. package/template/scripts/self_healing_deploy_validate.py +78 -0
  35. package/template/scripts/sovereign_convergence_lib.py +994 -0
  36. package/template/scripts/sovereign_convergence_validate.py +206 -0
  37. package/template/scripts/sovereign_critic_lib.py +629 -0
  38. package/template/scripts/sovereign_critic_validate.py +131 -0
  39. package/template/scripts/sovereign_loop_lib.py +828 -0
  40. package/template/scripts/sovereign_loop_validate.py +122 -0
  41. package/template/scripts/sovereign_memory_lib.py +869 -0
  42. package/template/scripts/sovereign_memory_validate.py +153 -0
  43. package/template/scripts/sovereign_role_manifest_lib.py +547 -0
  44. package/template/scripts/sovereign_role_manifest_validate.py +105 -0
  45. package/template/tests/scratchpad_example_parity_test.py +124 -0
  46. package/template/tests/us0108_contract_test.py +207 -0
  47. package/template/tests/us0109_contract_test.py +209 -0
  48. package/template/tests/us0109_us0110_compose_test.py +34 -0
  49. 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-3",
4
4
  "description": "its-magic - AI dev team workflow for Cursor.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -13,6 +13,9 @@ Scoped modes (DEC-0073 §10 / US-0090):
13
13
  --scope=us-0096 DEC-0082 delivery modes surfaces (US-0096).
14
14
  --scope=project-readme DEC-0083 project README bootstrap surfaces (US-0097).
15
15
  --scope=dev-environment DEC-0084 dev auto-launch profile surfaces (US-0098).
16
+ --scope=sovereign-parallel-dev DEC-0108 parallel instance arbitrage surfaces (US-0108).
17
+ --scope=sovereign-self-healing-deploy DEC-0109 self-healing deploy loop surfaces (US-0109).
18
+ --scope=release-trigger-adapter DEC-0111 release trigger adapter surfaces (US-0111).
16
19
  --scope=all union of all tables.
17
20
  """
18
21
 
@@ -297,6 +300,115 @@ DOWNSTREAM_CI_GUARD_PAIRS: tuple[tuple[str, str], ...] = (
297
300
  ),
298
301
  )
299
302
 
303
+ SOVEREIGN_ROLE_MANIFEST_PAIRS: tuple[tuple[str, str], ...] = (
304
+ (
305
+ ".cursor/sovereign-role-manifest.yaml",
306
+ "template/.cursor/sovereign-role-manifest.yaml.example",
307
+ ),
308
+ (
309
+ ".cursor/scratchpad.md",
310
+ "template/.cursor/scratchpad.md",
311
+ ),
312
+ (
313
+ "scripts/sovereign_role_manifest_validate.py",
314
+ "template/scripts/sovereign_role_manifest_validate.py",
315
+ ),
316
+ (
317
+ "scripts/sovereign_role_manifest_lib.py",
318
+ "template/scripts/sovereign_role_manifest_lib.py",
319
+ ),
320
+ (
321
+ "docs/engineering/runbook.md",
322
+ "template/docs/engineering/runbook.md",
323
+ ),
324
+ (
325
+ "docs/engineering/reason_codes.md",
326
+ "template/docs/engineering/reason_codes.md",
327
+ ),
328
+ (
329
+ "handoffs/sovereign_role_reviews.jsonl",
330
+ "template/handoffs/sovereign_role_reviews.jsonl",
331
+ ),
332
+ )
333
+
334
+ SOVEREIGN_PARALLEL_DEV_PAIRS: tuple[tuple[str, str], ...] = (
335
+ (
336
+ ".cursor/scratchpad.md",
337
+ "template/.cursor/scratchpad.md",
338
+ ),
339
+ (
340
+ "scripts/parallel_dev_arbiter.py",
341
+ "template/scripts/parallel_dev_arbiter.py",
342
+ ),
343
+ (
344
+ "tests/us0108_contract_test.py",
345
+ "template/tests/us0108_contract_test.py",
346
+ ),
347
+ (
348
+ "docs/engineering/runbook.md",
349
+ "template/docs/engineering/runbook.md",
350
+ ),
351
+ (
352
+ "docs/engineering/reason_codes.md",
353
+ "template/docs/engineering/reason_codes.md",
354
+ ),
355
+ (
356
+ "scripts/check_intake_template_parity.py",
357
+ "template/scripts/check_intake_template_parity.py",
358
+ ),
359
+ )
360
+
361
+ SOVEREIGN_SELF_HEALING_DEPLOY_PAIRS: tuple[tuple[str, str], ...] = (
362
+ (
363
+ ".cursor/scratchpad.md",
364
+ "template/.cursor/scratchpad.md",
365
+ ),
366
+ (
367
+ "scripts/self_healing_deploy_lib.py",
368
+ "template/scripts/self_healing_deploy_lib.py",
369
+ ),
370
+ (
371
+ "scripts/self_healing_deploy_validate.py",
372
+ "template/scripts/self_healing_deploy_validate.py",
373
+ ),
374
+ (
375
+ "tests/us0109_contract_test.py",
376
+ "template/tests/us0109_contract_test.py",
377
+ ),
378
+ (
379
+ "docs/engineering/runbook.md",
380
+ "template/docs/engineering/runbook.md",
381
+ ),
382
+ (
383
+ "docs/engineering/reason_codes.md",
384
+ "template/docs/engineering/reason_codes.md",
385
+ ),
386
+ )
387
+
388
+ # US-0111 release trigger adapter parity pairs
389
+ RELEASE_TRIGGER_ADAPTER_PAIRS: tuple[tuple[str, str], ...] = (
390
+ (
391
+ "scripts/release_trigger_adapters.py",
392
+ "template/scripts/release_trigger_adapters.py",
393
+ ),
394
+ (
395
+ "tests/us0111_contract_test.py",
396
+ "template/tests/us0111_contract_test.py",
397
+ ),
398
+ (
399
+ "docs/engineering/runbook.md",
400
+ "template/docs/engineering/runbook.md",
401
+ ),
402
+ (
403
+ "docs/engineering/reason_codes.md",
404
+ "template/docs/engineering/reason_codes.md",
405
+ ),
406
+ (
407
+ "scripts/check_intake_template_parity.py",
408
+ "template/scripts/check_intake_template_parity.py",
409
+ ),
410
+ )
411
+
300
412
  SCOPES: dict[str, tuple[tuple[str, str], ...]] = {
301
413
  "intake": INTAKE_TEMPLATE_PAIRS,
302
414
  "caveman-compress": CAVEMAN_COMPRESS_PAIRS,
@@ -312,6 +424,10 @@ SCOPES: dict[str, tuple[tuple[str, str], ...]] = {
312
424
  "release-changelog": RELEASE_CHANGELOG_PAIRS,
313
425
  "model-tier": MODEL_TIER_PAIRS,
314
426
  "model-tier-overrides": MODEL_TIER_OVERRIDES_PAIRS,
427
+ "sovereign-role-manifest": SOVEREIGN_ROLE_MANIFEST_PAIRS,
428
+ "sovereign-parallel-dev": SOVEREIGN_PARALLEL_DEV_PAIRS,
429
+ "sovereign-self-healing-deploy": SOVEREIGN_SELF_HEALING_DEPLOY_PAIRS,
430
+ "release-trigger-adapter": RELEASE_TRIGGER_ADAPTER_PAIRS,
315
431
  "all": (
316
432
  INTAKE_TEMPLATE_PAIRS
317
433
  + CAVEMAN_COMPRESS_PAIRS
@@ -327,6 +443,9 @@ SCOPES: dict[str, tuple[tuple[str, str], ...]] = {
327
443
  + RELEASE_CHANGELOG_PAIRS
328
444
  + MODEL_TIER_PAIRS
329
445
  + MODEL_TIER_OVERRIDES_PAIRS
446
+ + SOVEREIGN_ROLE_MANIFEST_PAIRS
447
+ + SOVEREIGN_SELF_HEALING_DEPLOY_PAIRS
448
+ + RELEASE_TRIGGER_ADAPTER_PAIRS
330
449
  ),
331
450
  }
332
451
 
@@ -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`.