its-magic 0.1.3-0 → 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 (61) 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 +62 -0
  6. package/template/.cursor/agents/curator.mdc +1 -0
  7. package/template/.cursor/agents/po.mdc +1 -0
  8. package/template/.cursor/agents/release.mdc +1 -0
  9. package/template/.cursor/commands/auto.md +90 -0
  10. package/template/.cursor/commands/execute.md +26 -0
  11. package/template/.cursor/commands/refresh-context.md +32 -0
  12. package/template/.cursor/commands/sovereign-critic.md +104 -0
  13. package/template/.cursor/model-catalog.local.example.cursor-only.json +9 -0
  14. package/template/.cursor/model-catalog.local.example.json +9 -0
  15. package/template/.cursor/model-catalog.local.example.level-1-easy.json +9 -0
  16. package/template/.cursor/model-catalog.local.example.level-2-complex.json +9 -0
  17. package/template/.cursor/model-catalog.local.example.level-3-mega.json +9 -0
  18. package/template/.cursor/model-catalog.local.example.level-4-super.json +9 -0
  19. package/template/.cursor/model-catalog.local.example.role-based-balanced.json +18 -0
  20. package/template/.cursor/model-catalog.local.example.role-based-highend.json +18 -0
  21. package/template/.cursor/rules/sovereign-role-manifest.mdc.example +27 -0
  22. package/template/.cursor/scratchpad.local.example.md +55 -0
  23. package/template/.cursor/scratchpad.md +203 -0
  24. package/template/.cursor/sovereign-role-manifest.yaml.example +53 -0
  25. package/template/decisions/DEC-0104.md +279 -0
  26. package/template/decisions/DEC-0105.md +231 -0
  27. package/template/decisions/DEC-0107.md +246 -0
  28. package/template/docs/engineering/architecture.md +78 -0
  29. package/template/docs/engineering/auto-orchestration-reference.md +7 -0
  30. package/template/docs/engineering/context/installer-owned-paths.manifest +8 -0
  31. package/template/docs/engineering/reason_codes.md +411 -0
  32. package/template/docs/engineering/runbook.md +1119 -0
  33. package/template/docs/engineering/sovereign-memory/.gitkeep +0 -0
  34. package/template/docs/engineering/sovereign-memory/retrospectives/.gitkeep +0 -0
  35. package/template/handoffs/sovereign_decisions/.gitkeep +0 -0
  36. package/template/handoffs/sovereign_deferrals/.gitkeep +0 -0
  37. package/template/handoffs/sovereign_role_reviews.jsonl +0 -0
  38. package/template/scripts/__pycache__/decision_ledger_lib.cpython-312.pyc +0 -0
  39. package/template/scripts/check_intake_template_parity.py +181 -0
  40. package/template/scripts/decision_ledger_lib.py +732 -0
  41. package/template/scripts/ledger_validate.py +153 -0
  42. package/template/scripts/model_tier_lib.py +680 -0
  43. package/template/scripts/model_tier_validate.py +368 -0
  44. package/template/scripts/parallel_dev_arbiter.py +923 -0
  45. package/template/scripts/release_trigger_adapters.py +843 -0
  46. package/template/scripts/self_healing_deploy_lib.py +463 -0
  47. package/template/scripts/self_healing_deploy_validate.py +78 -0
  48. package/template/scripts/sovereign_convergence_lib.py +994 -0
  49. package/template/scripts/sovereign_convergence_validate.py +206 -0
  50. package/template/scripts/sovereign_critic_lib.py +629 -0
  51. package/template/scripts/sovereign_critic_validate.py +131 -0
  52. package/template/scripts/sovereign_loop_lib.py +828 -0
  53. package/template/scripts/sovereign_loop_validate.py +122 -0
  54. package/template/scripts/sovereign_memory_lib.py +869 -0
  55. package/template/scripts/sovereign_memory_validate.py +153 -0
  56. package/template/scripts/sovereign_role_manifest_lib.py +547 -0
  57. package/template/scripts/sovereign_role_manifest_validate.py +105 -0
  58. package/template/tests/us0108_contract_test.py +207 -0
  59. package/template/tests/us0109_contract_test.py +209 -0
  60. package/template/tests/us0109_us0110_compose_test.py +34 -0
  61. 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-0",
3
+ "version": "0.1.3-2",
4
4
  "description": "its-magic - AI dev team workflow for Cursor.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -228,6 +228,64 @@ RELEASE_CHANGELOG_PAIRS: tuple[tuple[str, str], ...] = (
228
228
  ),
229
229
  )
230
230
 
231
+ MODEL_TIER_PAIRS: tuple[tuple[str, str], ...] = (
232
+ (
233
+ "scripts/model_tier_lib.py",
234
+ "template/scripts/model_tier_lib.py",
235
+ ),
236
+ (
237
+ "scripts/model_tier_validate.py",
238
+ "template/scripts/model_tier_validate.py",
239
+ ),
240
+ (
241
+ "docs/engineering/runbook.md",
242
+ "template/docs/engineering/runbook.md",
243
+ ),
244
+ (
245
+ ".cursor/scratchpad.md",
246
+ "template/.cursor/scratchpad.md",
247
+ ),
248
+ (
249
+ ".cursor/scratchpad.local.example.md",
250
+ "template/.cursor/scratchpad.local.example.md",
251
+ ),
252
+ (
253
+ "scripts/check_intake_template_parity.py",
254
+ "template/scripts/check_intake_template_parity.py",
255
+ ),
256
+ )
257
+
258
+ MODEL_TIER_OVERRIDES_PAIRS: tuple[tuple[str, str], ...] = (
259
+ (
260
+ ".cursor/scratchpad.md",
261
+ "template/.cursor/scratchpad.md",
262
+ ),
263
+ (
264
+ ".cursor/scratchpad.local.example.md",
265
+ "template/.cursor/scratchpad.local.example.md",
266
+ ),
267
+ (
268
+ ".cursor/model-catalog.local.example.role-based-balanced.json",
269
+ "template/.cursor/model-catalog.local.example.role-based-balanced.json",
270
+ ),
271
+ (
272
+ ".cursor/model-catalog.local.example.role-based-highend.json",
273
+ "template/.cursor/model-catalog.local.example.role-based-highend.json",
274
+ ),
275
+ (
276
+ "scripts/model_tier_lib.py",
277
+ "template/scripts/model_tier_lib.py",
278
+ ),
279
+ (
280
+ "scripts/model_tier_validate.py",
281
+ "template/scripts/model_tier_validate.py",
282
+ ),
283
+ (
284
+ "docs/engineering/runbook.md",
285
+ "template/docs/engineering/runbook.md",
286
+ ),
287
+ )
288
+
231
289
  DOWNSTREAM_CI_GUARD_PAIRS: tuple[tuple[str, str], ...] = (
232
290
  (
233
291
  "scripts/check_downstream_ci_guard.py",
@@ -252,6 +310,8 @@ SCOPES: dict[str, tuple[tuple[str, str], ...]] = {
252
310
  "project-readme": PROJECT_README_PAIRS,
253
311
  "dev-environment": DEV_ENVIRONMENT_PAIRS,
254
312
  "release-changelog": RELEASE_CHANGELOG_PAIRS,
313
+ "model-tier": MODEL_TIER_PAIRS,
314
+ "model-tier-overrides": MODEL_TIER_OVERRIDES_PAIRS,
255
315
  "all": (
256
316
  INTAKE_TEMPLATE_PAIRS
257
317
  + CAVEMAN_COMPRESS_PAIRS
@@ -265,6 +325,8 @@ SCOPES: dict[str, tuple[tuple[str, str], ...]] = {
265
325
  + PROJECT_README_PAIRS
266
326
  + DEV_ENVIRONMENT_PAIRS
267
327
  + RELEASE_CHANGELOG_PAIRS
328
+ + MODEL_TIER_PAIRS
329
+ + MODEL_TIER_OVERRIDES_PAIRS
268
330
  ),
269
331
  }
270
332
 
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  description: "Curator agent"
3
+ model: fast
3
4
  ---
4
5
 
5
6
  You are the Curator. Keep context compact and artifacts current.
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  description: "Product Owner agent"
3
+ model: inherit
3
4
  ---
4
5
 
5
6
  You are the PO. Your job is to clarify requirements and persist them.
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  description: "Release agent"
3
+ model: inherit
3
4
  ---
4
5
 
5
6
  You are Release. Prepare release notes and runbook commands.
@@ -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,9 @@
1
+ {
2
+ "schema_version": 1,
3
+ "tiers": {
4
+ "cheap": "composer-2.5-fast",
5
+ "balanced": "composer-2.5-standard",
6
+ "strong": "composer-2.5"
7
+ },
8
+ "notes": "Cursor-integrated models only. Uses Cursor's own Composer 2.5 family via stable Cursor model IDs. No external API key is required; everything routes through Cursor-managed infrastructure. Strong maps to the strongest available Composer 2.5 variant (often the default parent model when model: is omitted)."
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "schema_version": 1,
3
+ "tiers": {
4
+ "cheap": "<your-cheap-model-slug>",
5
+ "balanced": "<your-balanced-model-slug>",
6
+ "strong": "<your-strong-model-slug>"
7
+ },
8
+ "notes": "Copy this file to .cursor/model-catalog.local.json and replace placeholder slugs with vendor-specific model IDs. Enable with MODEL_RESOLVE=local_catalog in .cursor/scratchpad.local.md. All three tier keys are required."
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "schema_version": 1,
3
+ "tiers": {
4
+ "cheap": "qwen-3.7-plus",
5
+ "balanced": "composer-2.5-standard",
6
+ "strong": "glm-4.7"
7
+ },
8
+ "notes": "Level 1 — small/simple apps (CRUD, dashboard, bot, single-service). Cost-focused: Qwen3.7 Plus handles routine volume, Composer 2.5 Standard is the Cursor default, GLM-4.7 covers occasional architecture/release gates. Based on ai_modell_auslegung_cursor_highend.md 'Kleine unkomplizierte Apps'. Enable with MODEL_RESOLVE=local_catalog."
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "schema_version": 1,
3
+ "tiers": {
4
+ "cheap": "qwen-3.7-plus",
5
+ "balanced": "composer-2.5-standard",
6
+ "strong": "glm-5.2"
7
+ },
8
+ "notes": "Level 2 — complex apps (multi-service, auth, DB, FE+BE, Docker, API, worker/queue). Balanced: cheap Qwen for mass DEV, Composer 2.5 Standard as Cursor default, strong GLM-5.2 for architecture/QA/release gates. Based on ai_modell_auslegung_cursor_highend.md 'Komplexere Apps'. Enable with MODEL_RESOLVE=local_catalog."
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "schema_version": 1,
3
+ "tiers": {
4
+ "cheap": "qwen-3.7-plus",
5
+ "balanced": "glm-5.2",
6
+ "strong": "gpt-5.5"
7
+ },
8
+ "notes": "Level 3 — mega-complex software / modular monoliths (trading/finance platforms, multi-team systems, long-lived infrastructure). Strong GPT-5.5 for chief-architect/final-gate work, GLM-5.2 for SA/QA/RELEASE, Qwen for volume DEV. Based on ai_modell_auslegung_cursor_highend.md 'Mega-komplexe Software'. Enable with MODEL_RESOLVE=local_catalog."
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "schema_version": 1,
3
+ "tiers": {
4
+ "cheap": "qwen-3.7-plus",
5
+ "balanced": "kimi-k2.7-code",
6
+ "strong": "claude-opus-4.8"
7
+ },
8
+ "notes": "Level 4 — super-high-sophisticated / mission-critical (AI operating systems, critical infrastructure, long-horizon agent systems, high-risk security/privacy/finance). Chief-architect quality: Claude Opus 4.8 for critical gates, Kimi K2.7 Code for difficult long-horizon DEV, Qwen for cheap mass work. Based on ai_modell_auslegung_cursor_highend.md 'Super-High-Sophisticated Projects'. Enable with MODEL_RESOLVE=local_catalog."
9
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "schema_version": 2,
3
+ "tiers": {
4
+ "cheap": "<your-cheap-model-slug>",
5
+ "balanced": "<your-balanced-model-slug>",
6
+ "strong": "<your-strong-model-slug>"
7
+ },
8
+ "roles": {
9
+ "po": "<your-po-model-slug>",
10
+ "sa": "<your-sa-model-slug>",
11
+ "dev": "<your-dev-model-slug>",
12
+ "dev_difficult": "<your-dev-difficult-model-slug>",
13
+ "qa": "<your-qa-model-slug>",
14
+ "security": "<your-security-model-slug>",
15
+ "release": "<your-release-model-slug>"
16
+ },
17
+ "notes": "Role-based balanced preset (US-0102 / DEC-0087). Copy to .cursor/model-catalog.local.json and set MODEL_RESOLVE=role_catalog in .cursor/scratchpad.local.md. All tier and role keys required when roles section present."
18
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "schema_version": 2,
3
+ "tiers": {
4
+ "cheap": "<your-cheap-highend-slug>",
5
+ "balanced": "<your-balanced-highend-slug>",
6
+ "strong": "<your-strong-highend-slug>"
7
+ },
8
+ "roles": {
9
+ "po": "<your-po-highend-slug>",
10
+ "sa": "<your-sa-highend-slug>",
11
+ "dev": "<your-dev-highend-slug>",
12
+ "dev_difficult": "<your-dev-difficult-highend-slug>",
13
+ "qa": "<your-qa-highend-slug>",
14
+ "security": "<your-security-highend-slug>",
15
+ "release": "<your-release-highend-slug>"
16
+ },
17
+ "notes": "Role-based high-end preset (US-0102 / DEC-0087). See ai_modell_auslegung_cursor_highend.md for non-normative role recommendations. Enable with MODEL_RESOLVE=role_catalog."
18
+ }
@@ -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`.
@@ -321,3 +321,58 @@ CAVEMAN_MODE=0
321
321
  CAVEMAN_LEVEL=
322
322
  CAVEMAN_COMPRESS_INPUT=0
323
323
  CAVEMAN_FILE_SCOPE=
324
+
325
+ #
326
+ # ## Per-phase model tier selection (US-0101 / DEC-0086)
327
+ # MODEL_TIER selects LLM model strength (which model runs).
328
+ # MODEL_TIER ≠ TOKEN_PROFILE ≠ DELIVERY_MODE — these are independent axes;
329
+ # none substitutes for the other (DEC-0062 / US-0080 / US-0096).
330
+ # - MODEL_TIER_DEFAULT: cheap|balanced|strong (default balanced)
331
+ # - MODEL_TIER_<PHASE>: cheap|balanced|strong (per-phase override; PHASE = canonical phase id)
332
+ # Default matrix (architecture-locked):
333
+ # cheap — ask, refresh-context, memory-audit, status-reconcile, pause
334
+ # balanced — intake, discovery, research, release, plan-verify
335
+ # strong — architecture, execute, quick, qa, verify-work, security-review
336
+ # (inherit parent) — auto (orchestrator always inherits parent model)
337
+ # - MODEL_CATALOG: path to local slug catalog (default .cursor/model-catalog.local.json)
338
+ # - MODEL_RESOLVE: alias_only|local_catalog|role_catalog (default alias_only)
339
+ # - MODEL_FALLBACK: fallback when catalog lookup fails (default inherit)
340
+ # - MODEL_PROVIDER_MODE: cursor|api (default cursor)
341
+ # cursor = all subagents route through Cursor-managed infrastructure
342
+ # api = operator uses BYOK via Cursor Settings → Models → API Key
343
+ # Known limitation: subagents do NOT inherit custom API keys/base URLs.
344
+ #
345
+ # ## Direct per-phase model slug override (US-0102 / DEC-0087) — set in this local file only
346
+ # Precedence: MODEL_<PHASE> > MODEL_TIER_<PHASE> > MODEL_TIER_DEFAULT > Cursor alias
347
+ # - MODEL_<PHASE>: direct vendor slug (e.g. MODEL_EXECUTE=<your-vendor-slug>, MODEL_ASK=<your-vendor-slug>)
348
+ # - MODEL_RESOLVE=role_catalog enables phase→role→catalog slug lookup (requires v2 catalog with roles section)
349
+ MODEL_TIER_DEFAULT=balanced
350
+ MODEL_CATALOG=.cursor/model-catalog.local.json
351
+ MODEL_RESOLVE=alias_only
352
+ MODEL_FALLBACK=inherit
353
+ MODEL_PROVIDER_MODE=cursor
354
+
355
+ # Per-phase tier overrides for this project (uncomment and adjust as needed):
356
+ #MODEL_TIER_INTAKE=balanced
357
+ #MODEL_TIER_DISCOVERY=cheap
358
+ #MODEL_TIER_RESEARCH=balanced
359
+ #MODEL_TIER_ARCHITECTURE=strong
360
+ #MODEL_TIER_SPRINT-PLAN=strong
361
+ #MODEL_TIER_PLAN-VERIFY=balanced
362
+ #MODEL_TIER_EXECUTE=cheap
363
+ #MODEL_TIER_QA=strong
364
+ #MODEL_TIER_VERIFY-WORK=strong
365
+ #MODEL_TIER_RELEASE=balanced
366
+ #MODEL_TIER_REFRESH-CONTEXT=cheap
367
+
368
+ # Direct per-phase slug overrides (US-0102 — uncomment and set vendor slugs):
369
+ #MODEL_ASK=<your-vendor-slug>
370
+ #MODEL_EXECUTE=<your-vendor-slug>
371
+ #MODEL_QA=<your-vendor-slug>
372
+
373
+ # Use a vendor catalog instead of Cursor aliases:
374
+ # cp .cursor/model-catalog.local.example.level-2-complex.json .cursor/model-catalog.local.json
375
+ #MODEL_RESOLVE=local_catalog
376
+ # Role-based catalog preset (US-0102):
377
+ # cp .cursor/model-catalog.local.example.role-based-balanced.json .cursor/model-catalog.local.json
378
+ #MODEL_RESOLVE=role_catalog