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
@@ -322,3 +322,206 @@ CAVEMAN_MODE=1
322
322
  CAVEMAN_LEVEL=full
323
323
  CAVEMAN_COMPRESS_INPUT=0
324
324
  CAVEMAN_FILE_SCOPE=
325
+
326
+ #
327
+ # ## Per-phase model tier selection (US-0101 / DEC-0086)
328
+ # MODEL_TIER selects LLM model strength (which model runs).
329
+ # MODEL_TIER ≠ TOKEN_PROFILE ≠ DELIVERY_MODE — these are independent axes;
330
+ # none substitutes for the other (DEC-0062 / US-0080 / US-0096).
331
+ # - MODEL_TIER_DEFAULT: cheap|balanced|strong (default balanced)
332
+ # - MODEL_TIER_<PHASE>: cheap|balanced|strong (per-phase override; PHASE = canonical phase id)
333
+ # Examples: MODEL_TIER_EXECUTE=cheap, MODEL_TIER_QA=strong, MODEL_TIER_RESEARCH=balanced
334
+ # Set in .cursor/scratchpad.local.md to override per phase without touching committed defaults.
335
+ # Default matrix (architecture-locked):
336
+ # cheap — ask, refresh-context, memory-audit, status-reconcile, pause
337
+ # balanced — intake, discovery, research, release, plan-verify
338
+ # strong — architecture, execute, quick, qa, verify-work, security-review
339
+ # (inherit parent) — auto (orchestrator always inherits parent model)
340
+ # - MODEL_CATALOG: path to local slug catalog (default .cursor/model-catalog.local.json)
341
+ # - MODEL_RESOLVE: alias_only|local_catalog|role_catalog (default alias_only)
342
+ # alias_only = use Cursor-stable aliases (cheap->fast, balanced->inherit, strong->omit model:)
343
+ # local_catalog = look up vendor model slugs from MODEL_CATALOG; requires valid JSON catalog
344
+ # role_catalog = opt-in phase→role→catalog slug lookup (US-0102 / DEC-0087); falls through on miss
345
+ # - MODEL_FALLBACK: fallback when catalog lookup fails (default inherit)
346
+ # - MODEL_PROVIDER_MODE: cursor|api (default cursor)
347
+ # cursor = all subagents route through Cursor-managed infrastructure
348
+ # api = operator uses BYOK via Cursor Settings → Models → API Key
349
+ # Known limitation: subagents do NOT inherit custom API keys/base URLs.
350
+ #
351
+ # Example catalogs for 4 software-complexity levels + a Cursor-only variant:
352
+ # .cursor/model-catalog.local.example.json — minimal placeholder template
353
+ # .cursor/model-catalog.local.example.cursor-only.json — only Cursor-integrated Composer models
354
+ # .cursor/model-catalog.local.example.level-1-easy.json — small/simple apps
355
+ # .cursor/model-catalog.local.example.level-2-complex.json — complex multi-service apps
356
+ # .cursor/model-catalog.local.example.level-3-mega.json — mega-complex / modular monoliths
357
+ # .cursor/model-catalog.local.example.level-4-super.json — super-high-sophisticated / mission-critical
358
+ # .cursor/model-catalog.local.example.role-based-balanced.json — v2 role preset (balanced)
359
+ # .cursor/model-catalog.local.example.role-based-highend.json — v2 role preset (high-end)
360
+ # Copy one to .cursor/model-catalog.local.json and set MODEL_RESOLVE=local_catalog or role_catalog to activate.
361
+ MODEL_TIER_DEFAULT=balanced
362
+ MODEL_CATALOG=.cursor/model-catalog.local.json
363
+ MODEL_RESOLVE=alias_only
364
+ MODEL_FALLBACK=inherit
365
+ MODEL_PROVIDER_MODE=cursor
366
+ #
367
+ # ## Direct per-phase model slug override + role catalog (US-0102 / DEC-0087)
368
+ # Composes on US-0101 / DEC-0086 — tier baseline unchanged; overlays are optional.
369
+ # Precedence chain (deterministic, per canonical phase_id):
370
+ # 1. MODEL_<PHASE> — direct vendor slug override (highest priority)
371
+ # 2. MODEL_TIER_<PHASE> — DEC-0086 tier→alias / local_catalog chain
372
+ # 3. role_catalog lookup — only when MODEL_RESOLVE=role_catalog; miss falls through
373
+ # 4. MODEL_TIER_DEFAULT — DEC-0086 tier chain
374
+ # 5. Cursor stable alias — DEC-0086 built-in mapping (fast / inherit / omit)
375
+ # Scratchpad merge precedence for all MODEL_* keys: MODEL_<PHASE> > MODEL_TIER_<PHASE> > MODEL_TIER_DEFAULT
376
+ # - MODEL_<PHASE>: direct vendor slug; <PHASE> = canonical phase id (same list as MODEL_TIER_<PHASE>)
377
+ # Set in .cursor/scratchpad.local.md only — use <your-vendor-slug> placeholders in committed files.
378
+ # Canonical phase ids: ask, refresh-context, memory-audit, status-reconcile, pause,
379
+ # intake, discovery, research, release, plan-verify, architecture, execute, quick,
380
+ # qa, verify-work, security-review, auto
381
+ # Examples (placeholders — replace in scratchpad.local.md):
382
+ # MODEL_ASK=<your-vendor-slug>
383
+ # MODEL_EXECUTE=<your-vendor-slug>
384
+ # MODEL_QA=<your-vendor-slug>
385
+ # MODEL_REFRESH-CONTEXT=<your-vendor-slug>
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
@@ -0,0 +1,279 @@
1
+ # DEC-0104: Cross-Model Adversarial Critic (US-0104)
2
+
3
+ - **Date**: 2026-06-28
4
+ - **Status**: Accepted
5
+ - **Story**: `US-0104`
6
+ - **Composes on**: **US-0048** (per-phase isolation evidence), **US-0069** (phase role enforcement), **US-0023** (fresh-context semantics), **US-0110** (convergence conjunct 3) — **do not amend**; US-0104 **populates** `handoffs/sovereign_critic_findings.jsonl` and sets **`cross_model_reviewed`** on **US-0103** ledger entries
7
+ - **Related**: `R-0092` (research anchor), **US-0101** / **US-0102** (model resolution — read-only consumer), **US-0103** (ledger `cross_model_reviewed` field), **US-0108** (anti-slop score consumer), **US-0045** (status authority)
8
+ - **Supersedes**: none
9
+ - **Default-off**: `CROSS_MODEL_REVIEW=0` — zero overhead when off
10
+
11
+ ## Context
12
+
13
+ Sovereign-loop quality gate (US-0103..US-0110). After each producer phase completes, an optional critic subagent using a **different model** evaluates phase artifacts through three fixed lenses (Challenger / Architect / Subtractor). Findings reconcile via parallel-jury agreement; anti-slop scoring triggers bounded producer rework. **US-0048 / US-0069 / US-0023 / US-0110 are UNCHANGED** — US-0104 writes findings JSONL and optional ledger patches only.
14
+
15
+ Research basis: `R-0092` Q1–Q7 closed.
16
+
17
+ ## Decision
18
+
19
+ ### §1 — Scratchpad keys (AC-1)
20
+
21
+ | Key | Values | Default | Notes |
22
+ |-----|--------|---------|-------|
23
+ | **`CROSS_MODEL_REVIEW`** | **`0`** \| **`1`** | **`0`** | When `0`, no critic spawn, no findings writes, no anti-slop gate — **zero overhead**. |
24
+ | **`CROSS_MODEL_ANTISLOP_THRESHOLD`** | int **0–10** | **`6`** | Aggregate below threshold → rework loop. |
25
+ | **`CROSS_MODEL_REWORK_MAX`** | int ≥ **0** | **`2`** | Max producer re-spawns per `(orchestrator_run_id, phase_id)` before decision gate. |
26
+
27
+ Published in **`.cursor/scratchpad.md`** (+ **`template/.cursor/scratchpad.md`** byte-parity per **US-0017**).
28
+
29
+ **Rejected**: always-on critic (**rejected** — latency/token cost; default-off discipline).
30
+ **Rejected**: per-lens threshold keys (**rejected** — single aggregate `min(lens_scores)` sufficient for v1; **US-0108** depends on stable aggregate).
31
+
32
+ ### §2 — Findings JSONL schema v1 (AC-4, AC-5)
33
+
34
+ **Canonical path**: **`handoffs/sovereign_critic_findings.jsonl`** (repo root under `handoffs/`; matches **US-0110** `sovereign_convergence_lib.CRITIC_PATH`). Append-only; one file per repo (not per run).
35
+
36
+ | Field | Type | Required | Notes |
37
+ |-------|------|----------|-------|
38
+ | **`ts`** | ISO 8601 UTC string | yes | `YYYY-MM-DDTHH:MM:SS.mmmZ` |
39
+ | **`orchestrator_run_id`** | non-empty string | yes | Partition key for rework counter |
40
+ | **`phase_id`** | string | yes | **DEC-0086** canonical phase id |
41
+ | **`role`** | string | yes | Producer logical role (`po`, `tech-lead`, `dev`, `qa`, …) |
42
+ | **`producer_model_id`** | non-empty string | yes | Resolved slug or stable alias (`fast`, `inherit`, vendor slug) |
43
+ | **`critic_model_id`** | non-empty string | yes | Same vocabulary as producer |
44
+ | **`lens`** | enum | yes | `challenger` \| `architect` \| `subtractor` |
45
+ | **`finding_id`** | UUIDv4 | yes | Globally unique per finding line |
46
+ | **`severity`** | enum | yes | `low` \| `medium` \| `high` \| `critical` |
47
+ | **`confidence`** | enum | yes | `high` \| `medium` \| `low` — set by reconciliation |
48
+ | **`anti_slop_score`** | int **0–10** | yes | Per-lens score after rubric validation |
49
+ | **`finding_text`** | non-empty string | yes | Operator-auditable prose |
50
+ | **`status`** | enum | yes | `open` \| `resolved` \| `waived` |
51
+ | **`blocking`** | bool | yes | `true` when finding blocks convergence / rework exit |
52
+ | **`degraded_mode`** | bool | yes | `true` when single-model-multi-lens fallback active |
53
+
54
+ **Optional v1 fields** (allowed, not required): **`issue_key`** (normalized dedup key), **`single_finder`** (bool), **`rework_generation`** (int ≥ 0).
55
+
56
+ **Invariant**: `schema_version: 1` implicit via field inventory. Future bumps → `schema_version: 2`.
57
+
58
+ ### §3 — Three lenses + parallel jury (AC-3)
59
+
60
+ | Lens | Evaluation focus |
61
+ |------|------------------|
62
+ | **`challenger`** | Edge cases, race conditions, failure modes, boundary violations |
63
+ | **`architect`** | Coupling, layering, boundaries, dependency direction |
64
+ | **`subtractor`** | Over-engineering, premature abstraction, YAGNI, scope creep |
65
+
66
+ v1 runs **all three lenses** per critic invocation. Lens prompt templates live in **`.cursor/commands/sovereign-critic.md`** + runbook — no runtime lens invention.
67
+
68
+ **Reconciliation rule** (`reconcile_findings`):
69
+ 1. Compute **`issue_key`** per raw finding via **`compute_issue_key(finding_text)`** (§4).
70
+ 2. Group by `issue_key` across lenses.
71
+ 3. **≥2 lenses** share `issue_key` → `confidence=high`, `single_finder=false`.
72
+ 4. **Exactly 1 lens** → `confidence=medium`, `single_finder=true`.
73
+ 5. Emit merged finding rows with reconciled confidence; preserve per-lens `anti_slop_score`.
74
+
75
+ ### §4 — Issue normalization key v1 (R-0092 Q2)
76
+
77
+ Deterministic **`compute_issue_key(finding_text) -> str`**:
78
+
79
+ 1. Lowercase `finding_text`.
80
+ 2. Remove punctuation (`string.punctuation`).
81
+ 3. Collapse whitespace to single spaces; strip.
82
+ 4. Truncate to **80** characters on word boundary.
83
+ 5. SHA-256 hex digest; return first **16** hex chars prefixed `ik_`.
84
+
85
+ **Rejected**: semantic embedding cluster (**rejected** — non-deterministic, no stdlib embedding in v1).
86
+ **Rejected**: exact string match only (**rejected** — too brittle across lens phrasing).
87
+
88
+ ### §5 — `select_critic_model` algorithm (AC-2, AC-7)
89
+
90
+ `select_critic_model(producer_model_id, scratchpad, phase_id) -> SelectCriticResult`:
91
+
92
+ 1. If `producer_model_id` empty: resolve via **`model_tier_lib.resolve_model_for_phase(phase_id, scratchpad)`** → slug or alias.
93
+ 2. Map producer to tier:
94
+ - alias `fast` → **`cheap`**
95
+ - alias `inherit` or empty/omitted → **`balanced`**
96
+ - explicit slug: lookup catalog tier when `MODEL_RESOLVE=local_catalog`; else infer **`strong`** for non-alias slugs.
97
+ 3. Pick critic tier (opposition table):
98
+ | Producer tier | Critic tier |
99
+ |---------------|-------------|
100
+ | `strong` | `cheap` |
101
+ | `balanced` | `cheap` |
102
+ | `cheap` | `strong` |
103
+ 4. Resolve critic slug via **`model_tier_lib`** tier chain for synthetic phase **`sovereign-critic`** (fixed **`cheap`** tier in `DEFAULT_PHASE_TIER_MATRIX` override) **OR** direct tier→slug from catalog.
104
+ 5. Normalize comparison: aliases `fast`≠`inherit`≠vendor slug; if normalized critic slug **equals** producer slug → **`degraded=True`**, reason **`CROSS_MODEL_DEGRADED_MODE`**.
105
+ 6. Catalog miss / only one slug → **`degraded=True`**, reason **`CROSS_MODEL_CRITIC_MODEL_UNAVAILABLE`** or **`CROSS_MODEL_MODEL_COLLISION`**.
106
+
107
+ **R-0088 limitations** (documented, not blocked): Cursor Task tool `model` param may override subagent frontmatter; BYOK keys not inherited by subagents; `inherit` unreliable on some billing plans. Framework records **`degraded_mode=true`** and continues single-model-multi-lens — not a hard stop.
108
+
109
+ **Degraded fallback (L8)**: three sequential fresh subagent spawns (same `model_id`, different lens prompts); all findings record `degraded_mode=true`.
110
+
111
+ ### §6 — Anti-slop rubric + rework (AC-6)
112
+
113
+ **Per-lens deterministic checklist** (agent reports hits; lib validates floor):
114
+
115
+ | Lens | Checks (2.5 pts each, max 10) |
116
+ |------|-------------------------------|
117
+ | challenger | edge case cited; failure mode named; concurrency/race considered; input boundary tested |
118
+ | architect | coupling named; layer boundary stated; dependency direction explicit; interface contract mentioned |
119
+ | subtractor | unnecessary abstraction flagged; YAGNI applied; premature generalization challenged; scope creep identified |
120
+
121
+ `score_lens_antislop(lens, checklist_hits: dict[str, bool]) -> int` — count `True` × 2.5, round to int, clamp 0–10. Agent-reported score must be ≤ rubric ceiling or lib clamps down.
122
+
123
+ **Aggregate**: **`compute_anti_slop_aggregate(lens_scores) -> min(lens_scores)`** — stable for **US-0108**.
124
+
125
+ **Rework orchestration** (`/auto` post-phase hook):
126
+ 1. After `/sovereign-critic`, compute aggregate.
127
+ 2. If aggregate **< `CROSS_MODEL_ANTISLOP_THRESHOLD`** and `blocking` findings exist:
128
+ - Increment `rework_generation` for `(orchestrator_run_id, phase_id)`.
129
+ - If `rework_generation < CROSS_MODEL_REWORK_MAX`: re-spawn producer phase (fresh context per **US-0023**); pass critic summary as read-only input → reason **`CROSS_MODEL_ANTISLOP_FAIL`** (rework, not terminal).
130
+ - Else → **`CROSS_MODEL_REWORK_CAP_EXHAUSTED`** decision gate (operator waive or abort).
131
+
132
+ **`dev_to_qa.md` evidence tuple extension** (additive when `CROSS_MODEL_REVIEW=1`):
133
+
134
+ ```json
135
+ {
136
+ "critic_evidence": {
137
+ "producer_model_id": "...",
138
+ "critic_model_id": "...",
139
+ "anti_slop_aggregate": 7,
140
+ "rework_generation": 0,
141
+ "degraded_mode": false,
142
+ "findings_path": "handoffs/sovereign_critic_findings.jsonl"
143
+ }
144
+ }
145
+ ```
146
+
147
+ ### §7 — Isolation evidence `model_id` v2 extension (AC-4)
148
+
149
+ **Additive** field on **US-0048** evidence tuple (base five fields unchanged):
150
+
151
+ | Field | When required |
152
+ |-------|---------------|
153
+ | **`model_id`** | Required on **both** producer and critic isolation entries when `CROSS_MODEL_REVIEW=1`; omitted when `0` |
154
+
155
+ Fail-closed **`ISOLATION_EVIDENCE_MODEL_ID_MISSING`** when critic enabled and `model_id` absent on any in-scope isolation row for the phase pair.
156
+
157
+ Regression: **`test_us0104_us0048_compose_no_base_schema_change`** — US-0048 base schema literals unchanged.
158
+
159
+ ### §8 — Helper library contract (AC-5)
160
+
161
+ **Script**: **`scripts/sovereign_critic_lib.py`** (+ **`template/scripts/`** mirror).
162
+
163
+ | Function | Purpose |
164
+ |----------|---------|
165
+ | **`is_cross_model_review_enabled(scratchpad) -> bool`** | `CROSS_MODEL_REVIEW=1` |
166
+ | **`select_critic_model(producer_model_id, scratchpad, phase_id) -> SelectCriticResult`** | §5 algorithm |
167
+ | **`compute_issue_key(finding_text) -> str`** | §4 normalization |
168
+ | **`reconcile_findings(raw_findings) -> ReconciliationResult`** | §3 jury merge |
169
+ | **`compute_anti_slop_aggregate(lens_scores) -> int`** | `min(lens_scores)` |
170
+ | **`score_lens_antislop(lens, checklist_hits) -> int`** | §6 rubric |
171
+ | **`append_finding(path, entry) -> (bool, reason_code\|None)`** | Append-only JSONL + fsync |
172
+ | **`read_open_blocking(repo) -> list[dict]`** | Open `blocking=true` findings |
173
+ | **`resolve_finding(path, finding_id, status) -> bool`** | Patch status to `resolved`/`waived` |
174
+ | **`build_qa_cross_reviewer_block(repo) -> dict`** | `cross_reviewer_findings` for `qa-findings.md` |
175
+ | **`patch_ledger_cross_model_reviewed(...)`** | **US-0103** `build_new_entry(..., cross_model_reviewed=True)` when ledger enabled |
176
+ | **`schema_check(entry) -> (bool, error\|None)`** | 15-field v1 validation |
177
+ | **`self_test() -> bool`** | `[SOVEREIGN_CRITIC_SELF_TEST_OK]` |
178
+
179
+ Research stub ships schemas + self-test; full spawn orchestration deferred to execute tranche C.
180
+
181
+ ### §9 — Validator CLI contract (AC-8)
182
+
183
+ **Script**: **`scripts/sovereign_critic_validate.py`** (+ template mirror).
184
+
185
+ | CLI flag | Purpose |
186
+ |----------|---------|
187
+ | **`--file <path>`** | Validate single JSONL file |
188
+ | **`--repo <root>`** | Validate `handoffs/sovereign_critic_findings.jsonl` if present |
189
+ | **`--self-test`** | Library contract self-test |
190
+ | **`--enforce`** | Non-zero exit on fail-closed code |
191
+ | **`--open-blocking`** | List open blocking findings (stdout JSON) |
192
+
193
+ Output on success: **`[SOVEREIGN_CRITIC_VALIDATION_OK]`**.
194
+
195
+ ### §10 — `/sovereign-critic` command (AC-2)
196
+
197
+ **Path**: **`.cursor/commands/sovereign-critic.md`** (+ template mirror).
198
+
199
+ Invoked by **`/auto`** orchestrator **after** producer phase when `CROSS_MODEL_REVIEW=1`. Spawns fresh critic subagent per **US-0048** / **US-0023**. Inputs: `phase_id`, `role`, `evidence_ref`, `producer_model_id`, artifact digest. Outputs: append findings JSONL + optional `cross_reviewer_findings` in sprint `qa-findings.md`.
200
+
201
+ ### §11 — Reason code inventory (AC-8)
202
+
203
+ | Code | Blocking? | Surface |
204
+ |------|-----------|---------|
205
+ | **`CROSS_MODEL_REVIEW_DISABLED`** | no (info) | scratchpad gate off |
206
+ | **`CROSS_MODEL_CRITIC_SPAWN_FAILED`** | yes | orchestrator hook |
207
+ | **`CROSS_MODEL_MODEL_COLLISION`** | no → degraded | same slug resolved |
208
+ | **`CROSS_MODEL_ANTISLOP_FAIL`** | yes (rework) | score below threshold |
209
+ | **`CROSS_MODEL_REWORK_CAP_EXHAUSTED`** | yes (gate) | rework max hit |
210
+ | **`CROSS_MODEL_FINDINGS_INVALID`** | yes | schema validation |
211
+ | **`CROSS_MODEL_RECONCILE_FAILED`** | yes | jury merge error |
212
+ | **`CROSS_MODEL_DEGRADED_MODE`** | no (info) | single-model fallback |
213
+ | **`CROSS_MODEL_CRITIC_MODEL_UNAVAILABLE`** | yes → degraded | catalog miss |
214
+ | **`ISOLATION_EVIDENCE_MODEL_ID_MISSING`** | yes | critic enabled, evidence incomplete |
215
+
216
+ ### §12 — Contract tests + parity (AC-8)
217
+
218
+ Eight **`test_us0104_*`** markers in **`tests/us0104_contract_test.py`**:
219
+
220
+ 1. `test_us0104_scratchpad_keys_literals`
221
+ 2. `test_us0104_sovereign_critic_command_literals`
222
+ 3. `test_us0104_three_lens_enum_contract`
223
+ 4. `test_us0104_findings_jsonl_schema_contract`
224
+ 5. `test_us0104_reconciliation_agreement_branches`
225
+ 6. `test_us0104_model_id_isolation_evidence_extension`
226
+ 7. `test_us0104_antislop_rework_cap_literals`
227
+ 8. `test_us0104_degraded_fallback_zero_overhead`
228
+
229
+ Compose regression guards:
230
+ - `test_us0104_us0048_compose_no_base_schema_change`
231
+ - `test_us0104_us0110_critic_path_unchanged`
232
+
233
+ **`SOVEREIGN_CRITIC_PAIRS`** for `check_intake_template_parity.py --scope=sovereign-critic`:
234
+ - `scripts/sovereign_critic_lib.py` ↔ `template/scripts/sovereign_critic_lib.py`
235
+ - `scripts/sovereign_critic_validate.py` ↔ `template/scripts/sovereign_critic_validate.py`
236
+ - `.cursor/commands/sovereign-critic.md` ↔ `template/.cursor/commands/sovereign-critic.md`
237
+ - `.cursor/scratchpad.md` ↔ `template/.cursor/scratchpad.md` (`CROSS_MODEL_*` block)
238
+ - `decisions/DEC-0104.md` ↔ `template/decisions/DEC-0104.md`
239
+
240
+ ### §13 — Composition rules
241
+
242
+ | Story | Compose rule |
243
+ |-------|--------------|
244
+ | **US-0048** | Base isolation tuple unchanged; `model_id` additive v2 only. |
245
+ | **US-0069** | Phase→role matrix unchanged; critic spawned by orchestrator command, not new canonical phase role. |
246
+ | **US-0023** | Fresh-context semantics unchanged; rework re-spawn uses fresh marker. |
247
+ | **US-0110** | `CRITIC_PATH` / conjunct-3 degrade matrix unchanged; US-0104 populates artifact. |
248
+ | **US-0103** | `cross_model_reviewed` field already in 12-field v1; no ledger schema change. |
249
+ | **US-0101** / **US-0102** | Model resolution read-only via `model_tier_lib`; no precedence chain amendment. |
250
+ | **US-0108** | Consumes stable `min(lens_scores)` aggregate — do not change formula without coordinated DEC. |
251
+ | **US-0045** | US-0104 remains **OPEN** until release closure. |
252
+
253
+ ### §14 — Risks
254
+
255
+ | Risk | Mitigation |
256
+ |------|------------|
257
+ | **R1** Model routing unreliable (**R-0088**) | Deterministic degraded fallback §5 |
258
+ | **R2** Phase latency / token cost | Default-off `CROSS_MODEL_REVIEW=0` |
259
+ | **R3** Rework oscillation | `CROSS_MODEL_REWORK_MAX` + decision gate §6 |
260
+ | **R4** Anti-slop subjectivity | Deterministic checklist rubric §6 |
261
+ | **R5** Jury dedup drift | Stable `issue_key` algorithm §4 |
262
+ | **R6** **US-0108** aggregate coupling | Frozen `min(lens_scores)` formula |
263
+
264
+ ### §15 — Implementation tranche order
265
+
266
+ 1. **Tranche A** — scratchpad keys + reason codes + `DEC-0104` template mirror
267
+ 2. **Tranche B** — **`scripts/sovereign_critic_lib.py`** full API + self-test
268
+ 3. **Tranche C** — **`scripts/sovereign_critic_validate.py`** + `/sovereign-critic` command
269
+ 4. **Tranche D** — `/auto` post-phase hook + rework loop + `dev_to_qa.md` tuple
270
+ 5. **Tranche E** — isolation `model_id` v2 + ledger hook + eight `test_us0104_*` + parity + architecture `# US-0104`
271
+
272
+ ## References
273
+
274
+ - `docs/engineering/research.md` — **`R-0092`**
275
+ - `docs/product/backlog.md` — **`## US-0104`**
276
+ - `handoffs/intake_evidence/intake-sovereign-20260627-01.json`
277
+ - `scripts/sovereign_convergence_lib.py` — **`CRITIC_PATH`**
278
+ - `scripts/decision_ledger_lib.py` — **`cross_model_reviewed`**
279
+ - `scripts/model_tier_lib.py` — model resolution (read-only)