@punks/cli 3.2.1 → 3.3.0

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 (117) hide show
  1. package/AGENTS.md +2 -0
  2. package/dist/BASELINE_CHANGELOG.md +76 -0
  3. package/dist/CHANGELOG.md +46 -1
  4. package/dist/baseline/scaffold-baseline/baseline.json +5 -5
  5. package/dist/baseline/scaffold-baseline/data/catalog/lint-assets.json +4 -1
  6. package/dist/baseline/scaffold-baseline/data/catalog/packs.json +7 -3
  7. package/dist/baseline/scaffold-baseline/data/catalog/skills.json +32 -0
  8. package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/post-command-flow.md +25 -17
  9. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/rule-authoring/SKILL.md +18 -0
  10. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/rule-authoring/references/migration.md +10 -0
  11. package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/animate/LICENSE +21 -0
  12. package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/animate/RECIPES.md +333 -0
  13. package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/animate/SKILL.md +203 -0
  14. package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/animate/UPSTREAM.md +9 -0
  15. package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/review-animations/LICENSE +21 -0
  16. package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/review-animations/SKILL.md +112 -0
  17. package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/review-animations/STANDARDS.md +229 -0
  18. package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/review-animations/UPSTREAM.md +9 -0
  19. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/REFERENCE.md +5 -1
  20. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/SKILL.md +9 -7
  21. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/references/architecture-convergence.md +4 -3
  22. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/references/planner-task-graph.md +12 -7
  23. package/dist/baseline/scaffold-baseline/skills/agnostic/quality/tdd/SKILL.md +3 -2
  24. package/dist/baseline/scaffold-baseline/skills/agnostic/quality/tdd/high-signal-tests.md +17 -3
  25. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/domain-modeling/{CONTEXT-FORMAT.md → GLOSSARY-FORMAT.md} +9 -9
  26. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/domain-modeling/SKILL.md +12 -12
  27. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/SKILL.md +4 -1
  28. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +36 -3
  29. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/references/grilling-flow.md +18 -1
  30. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/EXAMPLES.md +1 -1
  31. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/REFERENCE.md +4 -3
  32. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/SKILL.md +2 -2
  33. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/concepts/backlog-model.md +6 -6
  34. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/providers/azure-devops-create-payload.md +7 -7
  35. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/providers/github-projects-create-payload.md +12 -12
  36. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/providers/linear-create-payload.md +9 -9
  37. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/providers/monday-create-payload.md +10 -10
  38. package/dist/baseline/scaffold-baseline/skills/frameworks/expo/animate-expo/LICENSE +21 -0
  39. package/dist/baseline/scaffold-baseline/skills/frameworks/expo/animate-expo/RECIPES.md +435 -0
  40. package/dist/baseline/scaffold-baseline/skills/frameworks/expo/animate-expo/SKILL.md +255 -0
  41. package/dist/baseline/scaffold-baseline/skills/frameworks/expo/animate-expo/UPSTREAM.md +9 -0
  42. package/dist/baseline/scaffold-baseline/skills/misc/wait-what/SKILL.md +1 -1
  43. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/SKILL.md +5 -7
  44. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/review.md +50 -25
  45. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/router.md +29 -21
  46. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/phase-handoff.md +28 -10
  47. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/AUTHORING-HANDOFF.md +14 -11
  48. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/prepare-review.md +1 -1
  49. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/retain-report.md +9 -2
  50. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/return-route.md +6 -8
  51. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/run-review.md +8 -5
  52. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/references/durable-report.md +29 -14
  53. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/references/state-graph.md +45 -32
  54. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/references/targets.md +2 -1
  55. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/scripts/review-contract.mjs +86 -12
  56. package/dist/baseline/scaffold-baseline.json +5 -5
  57. package/dist/baseline/scaffold-baseline.tgz +0 -0
  58. package/dist/data/AGENTS.md +2 -0
  59. package/dist/index.js +17 -17
  60. package/dist/skills/agnostic/cli/hi-cli/references/post-command-flow.md +10 -2
  61. package/dist/skills/agnostic/docs/rule-authoring/SKILL.md +18 -0
  62. package/dist/skills/agnostic/docs/rule-authoring/references/migration.md +10 -0
  63. package/dist/skills/agnostic/frontend/animate/LICENSE +21 -0
  64. package/dist/skills/agnostic/frontend/animate/RECIPES.md +324 -0
  65. package/dist/skills/agnostic/frontend/animate/SKILL.md +199 -0
  66. package/dist/skills/agnostic/frontend/animate/UPSTREAM.md +9 -0
  67. package/dist/skills/agnostic/frontend/review-animations/LICENSE +21 -0
  68. package/dist/skills/agnostic/frontend/review-animations/SKILL.md +112 -0
  69. package/dist/skills/agnostic/frontend/review-animations/STANDARDS.md +187 -0
  70. package/dist/skills/agnostic/frontend/review-animations/UPSTREAM.md +9 -0
  71. package/dist/skills/agnostic/planning/create-plan/REFERENCE.md +5 -1
  72. package/dist/skills/agnostic/planning/create-plan/SKILL.md +9 -7
  73. package/dist/skills/agnostic/planning/create-plan/references/architecture-convergence.md +4 -3
  74. package/dist/skills/agnostic/planning/create-plan/references/planner-task-graph.md +12 -7
  75. package/dist/skills/agnostic/quality/tdd/SKILL.md +3 -2
  76. package/dist/skills/agnostic/quality/tdd/high-signal-tests.md +17 -3
  77. package/dist/skills/agnostic/requirements/domain-modeling/{CONTEXT-FORMAT.md → GLOSSARY-FORMAT.md} +9 -9
  78. package/dist/skills/agnostic/requirements/domain-modeling/SKILL.md +12 -12
  79. package/dist/skills/agnostic/requirements/requirements-grill/SKILL.md +4 -1
  80. package/dist/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +33 -3
  81. package/dist/skills/agnostic/requirements/requirements-grill/references/grilling-flow.md +18 -1
  82. package/dist/skills/agnostic/requirements/write-backlog/EXAMPLES.md +1 -1
  83. package/dist/skills/agnostic/requirements/write-backlog/REFERENCE.md +4 -3
  84. package/dist/skills/agnostic/requirements/write-backlog/SKILL.md +2 -2
  85. package/dist/skills/agnostic/requirements/write-backlog/assets/concepts/backlog-model.md +6 -6
  86. package/dist/skills/agnostic/requirements/write-backlog/assets/providers/azure-devops-create-payload.md +7 -7
  87. package/dist/skills/agnostic/requirements/write-backlog/assets/providers/github-projects-create-payload.md +12 -12
  88. package/dist/skills/agnostic/requirements/write-backlog/assets/providers/linear-create-payload.md +9 -9
  89. package/dist/skills/agnostic/requirements/write-backlog/assets/providers/monday-create-payload.md +10 -10
  90. package/dist/skills/frameworks/expo/animate-expo/LICENSE +21 -0
  91. package/dist/skills/frameworks/expo/animate-expo/RECIPES.md +385 -0
  92. package/dist/skills/frameworks/expo/animate-expo/SKILL.md +255 -0
  93. package/dist/skills/frameworks/expo/animate-expo/UPSTREAM.md +9 -0
  94. package/dist/skills/misc/wait-what/SKILL.md +1 -1
  95. package/dist/skills/phases/delivery-phase/SKILL.md +5 -7
  96. package/dist/skills/phases/delivery-phase/phases/review.md +50 -25
  97. package/dist/skills/phases/delivery-phase/phases/router.md +27 -19
  98. package/dist/skills/phases/delivery-phase/references/phase-handoff.md +28 -10
  99. package/dist/skills/phases/review-phase/AUTHORING-HANDOFF.md +14 -11
  100. package/dist/skills/phases/review-phase/phases/prepare-review.md +1 -1
  101. package/dist/skills/phases/review-phase/phases/retain-report.md +9 -2
  102. package/dist/skills/phases/review-phase/phases/return-route.md +6 -8
  103. package/dist/skills/phases/review-phase/phases/run-review.md +8 -5
  104. package/dist/skills/phases/review-phase/references/durable-report.md +29 -14
  105. package/dist/skills/phases/review-phase/references/state-graph.md +19 -6
  106. package/dist/skills/phases/review-phase/references/targets.md +2 -1
  107. package/dist/skills/phases/review-phase/scripts/review-contract.mjs +91 -11
  108. package/package.json +4 -23
  109. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/adapters/claude.test.ts +0 -130
  110. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/adapters/codex.test.ts +0 -135
  111. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/adapters/cursor.test.ts +0 -138
  112. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/adapters/opencode.test.ts +0 -135
  113. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/contract.test.ts +0 -875
  114. package/dist/baseline/scaffold-baseline/data/scripts/sync-subagents.lifecycle.test.ts +0 -205
  115. package/dist/baseline/scaffold-baseline/data/scripts/sync-subagents.native.test.ts +0 -2765
  116. package/dist/baseline/scaffold-baseline/data/scripts/sync-subagents.test.ts +0 -2108
  117. package/dist/baseline/scaffold-baseline/data/subagents/manifest.test.ts +0 -116
@@ -3,6 +3,10 @@
3
3
  This is the graph-authoring record. It is separate from review runtime
4
4
  handoffs, retained reports, and delivery handoffs.
5
5
 
6
+ Test references below are source-repository provenance. The installed package
7
+ omits the source repository test files; reproduce a claim from the immutable
8
+ source commit with its named command and contract seam.
9
+
6
10
  ## Router Selection
7
11
 
8
12
  Phase: router
@@ -362,8 +366,8 @@ Artifacts:
362
366
  Validation:
363
367
 
364
368
  - Disclosure completion was durable.
365
- - The focused route contract was observed RED at 16/23: seven assertions still
366
- addressed deleted or relocated authority.
369
+ - The focused route contract was observed RED against deleted or relocated
370
+ authority.
367
371
  - The nine authoring route predictions and runtime storage/no-write cases were
368
372
  not yet executable or recorded, so `test-routes.md` was the single route.
369
373
 
@@ -410,8 +414,8 @@ Validation:
410
414
  - All nine predictions matched derivation; no runtime contract mismatch required
411
415
  repair.
412
416
  - Stale, out-of-scope, and invalid artifact subcases resolve separately.
413
- - The focused suite moved from observed RED 16/23 to GREEN 25/25 after replacing
414
- deleted-root assertions and adding two runtime graph contracts.
417
+ - The focused source contract moved from observed RED to GREEN after replacing
418
+ deleted-root assertions and adding runtime graph contracts.
415
419
  - Router priorities 1-12 cover terminal, checkpoint, blocked, and all four gate
416
420
  outputs. Delivery and standalone storage, conflict, and every declared
417
421
  authoritative no-write class are executable assertions.
@@ -441,7 +445,7 @@ storage modes, no-write outcomes, conflicts, and router classes were tested.
441
445
 
442
446
  Artifacts:
443
447
 
444
- - `tests/review-phase-graph.contract.test.mjs`: 25 focused graph contracts.
448
+ - The canonical source review-graph contract and its named Node command.
445
449
  - `Test Routes Outcome`: nine frozen predictions with nine matching derived
446
450
  routes and zero graph repairs.
447
451
 
@@ -474,8 +478,7 @@ Artifacts:
474
478
 
475
479
  - `SKILL.md`, `agents/openai.yaml`, `phases/router.md`, four flat gate files,
476
480
  four references, and `scripts/review-contract.mjs`.
477
- - `tests/review-phase-graph.contract.test.mjs` and all eight shared
478
- `tests/*.test.mjs` files.
481
+ - The canonical source review-graph contract and shared source contract command.
479
482
 
480
483
  Validation:
481
484
 
@@ -498,7 +501,7 @@ Validation:
498
501
  - The no-op test required zero deletions: each remaining instruction changes
499
502
  invocation, routing, evidence, validation, persistence, or stop behavior.
500
503
  - `SKILL.md` and `agents/openai.yaml` consistently disable implicit invocation.
501
- - Focused tests pass 25/25; all eight shared test files pass 94/94. Both Node
504
+ - The focused and shared source contract commands pass. Both Node
502
505
  files pass syntax checks, and the scoped diff passes `git diff --check`.
503
506
  - The requested literal `python` command is unavailable. The same validator
504
507
  executed through `uv run --with pyyaml python` and failed because
@@ -582,8 +585,8 @@ Artifacts:
582
585
 
583
586
  - `SKILL.md`, `agents/openai.yaml`, `phases/router.md`, four flat gate files,
584
587
  four references, and `scripts/review-contract.mjs`.
585
- - `tests/review-phase-graph.contract.test.mjs`, all eight shared test files,
586
- and the applicable `skills` packaging validator output.
588
+ - The canonical source review-graph and shared contract commands, plus the
589
+ applicable `skills` packaging validator output.
587
590
 
588
591
  Validation:
589
592
 
@@ -601,7 +604,7 @@ Validation:
601
604
  form the progressive-disclosure trace.
602
605
  - The no-op test required zero deletions. Root frontmatter and
603
606
  `agents/openai.yaml` consistently enforce explicit-only invocation.
604
- - Focused tests pass 25/25; all eight shared test files pass 94/94. Both Node
607
+ - The focused and shared source contract commands pass. Both Node
605
608
  files pass syntax checks, and the scoped diff passes `git diff --check`.
606
609
  - The applicable packaging validator exits zero, validates the local path,
607
610
  discovers 106 skills, and lists `review-phase` with the exact source
@@ -3,7 +3,7 @@
3
3
  ## Entry Guard
4
4
 
5
5
  The router selected this gate from fresh `review_due` evidence supplied by an
6
- explicit operator invocation. The review mode is `delivery` or `standalone`,
6
+ authorized full-delivery or explicit-operator invocation. The review mode is `delivery` or `standalone`,
7
7
  and no valid later-state evidence already owns the run.
8
8
 
9
9
  ## Inputs
@@ -11,6 +11,8 @@ returns the zero-write `review_budget_exhausted` terminal.
11
11
  ## Inputs
12
12
 
13
13
  - exact local report path and bytes
14
+ - exact bytes resolved from `reportCommitSha:reportPath` for every retained
15
+ candidate, supplied to the validator as `resolvedReportBytes`
14
16
  - primitive accepted-bounds, normalized-target, and governing-source evidence
15
17
  - review mode, lineage, run ID, and delivery ordinal when applicable
16
18
  - expected report SHA-256 and allowed navigation/wiki-log envelope paths
@@ -51,8 +53,11 @@ review_run_id)` independently. Reuse one unique valid candidate, including
51
53
  the report and allowed envelope, then push or use the approved ref. Preserve
52
54
  the report bytes exactly.
53
55
  6. Verify that the retained ref contains the exact report commit and that the
54
- commit changed only approved envelope paths. Run the complete retained-pass
55
- validator again against the retained blob and current primitive evidence.
56
+ commit changed only approved envelope paths. Resolve
57
+ `reportCommitSha:reportPath` from that commit, pass those exact committed
58
+ bytes to the retained-pass validator, and require exact equality with the
59
+ local report bytes. A local digest or caller assertion cannot replace this
60
+ commit-tree read.
56
61
  7. Only a unique valid retained delivery report establishes its ordinal.
57
62
  Reconcile the delivery `review_count` projection from the highest unique
58
63
  valid retained ordinal. Standalone retention changes no delivery counter.
@@ -81,6 +86,8 @@ review_run_id)` independently. Reuse one unique valid candidate, including
81
86
  - same-run candidate inventory and uniqueness decision
82
87
  - report commit SHA and its exact changed-path set
83
88
  - approved retained ref and proof that it contains the report commit
89
+ - exact `reportCommitSha:reportPath` resolution and committed/local byte
90
+ equality
84
91
  - delivery ordinal and reconciled counter projection, or standalone mode
85
92
 
86
93
  ## Declared Exits
@@ -31,13 +31,11 @@ debug, debt, documentation, or closeout work.
31
31
  1. Revalidate the retained blob, canonical identities, approved commit paths,
32
32
  same-run uniqueness, ref containment, and current freshness. Reuse only the
33
33
  immutable authority block inside those retained bytes.
34
- 2. Derive the primary route from retained findings in this order:
35
- - any finding with runtime-failure evidence -> `debugging`
36
- - otherwise, any in-scope non-runtime blocking finding -> `implementation`
37
- - otherwise, any broad architecture-debt finding -> `debt_follow_up`
38
- - otherwise, incomplete required documentation -> `docs_ingest`
39
- - otherwise -> `closeout`
40
- 3. Set `secondary_architecture_follow_up` only when a broad architecture-debt
34
+ 2. Pass the complete retained finding set to the public `deriveReviewRouting`
35
+ helper. Each non-empty finding already carries one validated `return_route`.
36
+ The helper applies `debugging` > `implementation` > `debt_follow_up` >
37
+ `docs_ingest`; an empty set returns `closeout`.
38
+ 3. Accept `secondary_architecture_follow_up` only when a `debt_follow_up`
41
39
  finding accompanies a higher-priority debugging or implementation route.
42
40
  4. Require the derived result to equal the retained report's `routing` object.
43
41
  A mismatch is invalid retained routing evidence and routes to
@@ -63,7 +61,7 @@ debug, debt, documentation, or closeout work.
63
61
 
64
62
  - valid retained-pass result and final freshness result
65
63
  - retained report path, SHA-256, commit, and containing ref
66
- - stable finding IDs used by each route class
64
+ - stable finding IDs and their explicit `return_route` classifications
67
65
  - deterministic precedence result and exact match to report `routing`
68
66
  - returned mode-specific state and routing-evidence artifact
69
67
 
@@ -51,7 +51,8 @@ scope; the parent rejects stale, expanded, duplicated, or unverified output.
51
51
  6. Parent-verify every advisory and lens candidate against the frozen target and
52
52
  adjacent evidence. Only verified candidates become findings. Give each
53
53
  accepted finding a stable identifier, lens, severity, location, impact,
54
- evidence, and action.
54
+ evidence, action, and one explicit `return_route`: `debugging`,
55
+ `implementation`, `debt_follow_up`, or `docs_ingest`.
55
56
  7. Run only the smallest safe readonly validation needed to verify candidates or
56
57
  governing acceptance evidence. Broader checks require explicit accepted spec
57
58
  or plan authority. Record missing required RED/GREEN evidence as a finding;
@@ -61,10 +62,11 @@ scope; the parent rejects stale, expanded, duplicated, or unverified output.
61
62
  caches, generated files, snapshots, lockfiles, or state run in a disposable
62
63
  checkout or snapshot rooted at the frozen revision. Reconcile exact commands,
63
64
  isolation mode, hashes, output, skipped checks, and residual risk.
64
- 9. Derive the report route from verified findings: runtime evidence first,
65
- otherwise an in-scope non-runtime blocker, otherwise broad architecture debt,
66
- otherwise documentation ingest or closeout by documentation completeness.
67
- Architecture debt may remain a secondary follow-up.
65
+ 9. Pass the complete verified finding set to `deriveReviewRouting` in
66
+ [`review-contract.mjs`](../scripts/review-contract.mjs). Store its result
67
+ unchanged. The helper uses only `return_route`, applies canonical precedence,
68
+ and preserves debt as a secondary follow-up beside debugging or
69
+ implementation. Finding prose never selects or reranks a route.
68
70
  10. Assemble exactly one complete local report using
69
71
  [`../references/durable-report.md`](../references/durable-report.md). Record
70
72
  an explicit outcome for every lens. After its final bytes are written, treat
@@ -95,6 +97,7 @@ The run is complete only when one local report contains:
95
97
  and mode-specific delivery identities
96
98
  - explicit Standards, skill-adherence, architecture, simplify, and Spec outcomes
97
99
  - every verified stable finding and no unverified advisory candidate
100
+ - one validated `return_route` on each accepted finding
98
101
  - evidence-cardinality results for all applicable skill guidance and notes
99
102
  - exact validation commands, isolation, before/after hashes, outcomes, skipped
100
103
  checks, and residual risk
@@ -45,9 +45,14 @@ the fixed wiki values are `review-report`, `project`, and `internal`. Its title
45
45
  uses the derived filename slug; created and updated equal the date in
46
46
  `reviewed_at`. Its lineage, run, mode, timestamp, accepted-bounds identity/hash,
47
47
  and snapshot hash must agree with the JSON authority and recomputed evidence.
48
+ Prototype-sensitive frontmatter keys are malformed and are rejected before any
49
+ assignment. `reviewed_at` must name a real UTC calendar instant. Delivery
50
+ normalization requires a non-empty inclusive scope and delivery-goal identity;
51
+ governing-source normalization requires a non-empty source set.
48
52
 
49
53
  The parsed JSON object is report authority. Detached objects, sidecars, and
50
- caller-supplied derived identities are never trusted. It contains exactly these fields:
54
+ caller-supplied derived identities are never trusted. It contains exactly these
55
+ fields:
51
56
 
52
57
  - `review_lineage_id`
53
58
  - `review_run_id`
@@ -60,8 +65,8 @@ caller-supplied derived identities are never trusted. It contains exactly these
60
65
  - canonical `source_set_hash`
61
66
  - an explicit outcome for Standards, skill adherence and scoped skills,
62
67
  architecture, simplify, and Spec
63
- - stable finding identifiers with severity, location, impact, evidence, and
64
- action
68
+ - stable finding identifiers with severity, location, impact, evidence,
69
+ action, and one `return_route`
65
70
  - routing and validation
66
71
 
67
72
  Delivery mode also records delivery-goal identity, review ordinal, and preceding
@@ -70,16 +75,23 @@ as null or not applicable.
70
75
 
71
76
  `lens_outcomes` has exactly `standards`, `skill_adherence`, `architecture`,
72
77
  `simplify`, and `spec`; each value is `clean` or `findings`. Every finding has
73
- exactly stable `id`, `lens`, `severity`, `location`, `impact`, `evidence`, and
74
- `action`. Finding IDs are unique, severity is `critical`, `high`, `medium`, or
75
- `low`, and each lens outcome agrees with whether that lens has a finding.
78
+ exactly the fields `id`, `lens`, `severity`, `location`, `impact`, `evidence`,
79
+ `action`, and `return_route`. Finding IDs are unique, severity is `critical`,
80
+ `high`, `medium`, or `low`, and each lens outcome agrees with whether that lens
81
+ has a finding. Each finding's `return_route` is exactly `debugging`,
82
+ `implementation`, `debt_follow_up`, or `docs_ingest`.
76
83
 
77
84
  `routing` has exactly `primary` and `secondary_architecture_follow_up`.
78
85
  `primary` is `debugging`, `implementation`, `debt_follow_up`, `docs_ingest`, or
79
- `closeout`; the secondary flag is boolean. `validation` is an array of records
80
- with exactly command, isolation mode, before/after frozen hashes, outcome, and
81
- evidence. Isolation is proven no-write, disposable checkout, or disposable
82
- snapshot. Retained validation records require equal before/after hashes.
86
+ `closeout`; the secondary flag is boolean. Aggregate routing is derived by the
87
+ public `deriveReviewRouting` helper from the complete finding set. Precedence is
88
+ `debugging` > `implementation` > `debt_follow_up` > `docs_ingest`; an empty set
89
+ derives `closeout`, and debt is secondary only beside debugging or
90
+ implementation. A supplied aggregate mismatch is invalid. `validation` is an
91
+ array of records with exactly command, isolation mode, before/after frozen
92
+ hashes, outcome, and evidence. Isolation is proven no-write, disposable
93
+ checkout, or disposable snapshot. Retained validation records require equal
94
+ before/after hashes.
83
95
 
84
96
  Delivery ordinals are 1 through 3. Review 1 has null preceding-repair ordinal;
85
97
  review 2 or 3 records respectively 1 or 2. Standalone delivery-goal identity,
@@ -117,12 +129,15 @@ evidence. A candidate is a valid retained pass only when every predicate holds:
117
129
  snapshot hash, source-set hash, and deterministic report path equal values
118
130
  recomputed from the canonical identity algorithm;
119
131
  3. the outside-envelope report SHA-256 equals the exact retained report blob;
120
- 4. current accepted-bounds, normalized-target, and governing-source hashes still
132
+ 4. bytes resolved from `reportCommitSha:reportPath` are exactly equal to the
133
+ local report bytes; the caller supplies them as `resolvedReportBytes`;
134
+ 5. current accepted-bounds, normalized-target, and governing-source hashes still
121
135
  equal the report values;
122
- 5. the report commit changed the report path and only repository-approved
136
+ 6. the report commit changed the report path and only repository-approved
123
137
  report, navigation, and wiki-log envelope paths;
124
- 6. the approved retained ref contains that exact report commit;
125
- 7. delivery ordinal is an integer from 1 through 3; standalone delivery-only
138
+ 7. the approved retained ref contains that exact report commit with boolean
139
+ `true` containment evidence;
140
+ 8. delivery ordinal is an integer from 1 through 3; standalone delivery-only
126
141
  fields are null.
127
142
 
128
143
  A malformed report, wrong lineage or run id, wrong blob or freshness hash,
@@ -4,38 +4,44 @@ Review owns normalization, frozen inspection, report retention, routing output,
4
4
  and termination. Delivery owns debugging, implementation, debt, docs, closeout,
5
5
  and clean handoff.
6
6
 
7
- | State | Event | Guard | Owner | Next state | Counter effect | Required evidence |
8
- | --------------------------------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------- | ----------------- | --------------------------------- | ------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- |
9
- | Current delivery state | Review considered | Unsupported target | Delivery caller | Return `review_failed` | None; zero handoff or status writes | Exact target failure; no report |
10
- | Current delivery state | Review considered | Invalid accepted bounds | Delivery caller | Return `review_failed` | None; zero handoff or status writes | Exact bounds failure; no report |
11
- | `review_due` | Explicit review invocation | Delivery; accepted bounds and target valid; recovered `review_count < 3` | Delivery caller | `review_running` | Preallocate ordinal `review_count + 1`; no completed-pass change | Lineage, run id, ordinal, bounds identity/hash, normalized target |
12
- | `review_due` | Explicit review invocation | Standalone; accepted bounds and target valid | Standalone caller | `review_running` | None | Lineage, run id, bounds identity/hash, normalized target |
13
- | Current delivery state | Review considered | Delivery; in-memory accepted bounds and target valid; recovered `review_count >= 3` | Delivery caller | Return `review_budget_exhausted` | None; zero handoff or status writes | Exact current route, lineage, counters; no report or status mutation |
14
- | `review_running` | All lenses and parent verification complete | One frozen snapshot; complete local report exists | `review-phase` | `report_retention_pending` | None; no completed-pass change | Complete report and fresh target/source hashes |
15
- | `review_running` | Validation mutation detected | Frozen-target hash differs after validation | `review-phase` | `review_due` | None | Before/after hashes, command, mutation evidence; no report or pass |
16
- | `review_running` | Retryable infrastructure failure or partial run | No immutable report | `review-phase` | `review_due` | None | Exact retryable evidence; unchanged counters |
17
- | `review_running` | Non-retryable contract or infrastructure failure | No immutable report | `review-phase` | `review_failed` | None | Exact terminal evidence; no report; unchanged counters |
18
- | `report_retention_pending` | Retention verified | Delivery; valid retained-pass predicate; ordinal at most 3; hashes fresh | Report writer | `review_routed` | Unique retained commit establishes authoritative ordinal; reconcile projection | Path, SHA-256, commit, retained ref, ordinal, run id |
19
- | `report_retention_pending` | Retention rejected | Delivery; ordinal is greater than 3 | Report writer | `review_budget_exhausted` | None | Exact ordinal rejection/current route; no authoritative pass |
20
- | `report_retention_pending` | Retention verified | Standalone; valid retained-pass predicate; hashes fresh | Report writer | `review_routed` | None | Path, SHA-256, commit, retained ref |
21
- | `report_retention_pending` | Idempotent retention recovery | Same lineage/run has identical valid path, report blob SHA-256, and commit | Report writer | `review_routed` | Reuse existing pass; project its ordinal at most once | Existing unique authority and containment evidence |
22
- | `report_retention_pending` | Same-run conflict | Same lineage/run has two valid candidates with different path, blob, or commit | Report writer | `review_failed` | None | `same_run_conflict`, both authorities; no pass or counter change |
23
- | `report_retention_pending` | Retained-pass validation rejected | Active candidate is malformed or has wrong derived identity, hash, paths, containment, or ordinal | Report writer | `review_failed` | None | Exact failed predicate; no pass or counter change |
24
- | `report_retention_pending` | Retryable retention failure | Hashes fresh | Report writer | `report_retention_pending` | None | Exact retryable evidence; no authoritative pass |
25
- | `report_retention_pending` | Non-retryable retention failure | Retry cannot succeed | Report writer | `review_failed` | None | Exact terminal evidence; no authoritative pass |
26
- | `report_retention_pending` | Freshness changed | Target or source hash changed | `review-phase` | `review_due` | None | Stale local report; unchanged counters |
27
- | `review_routed` | Readonly return | Standalone | Standalone caller | `review_complete` | None | Retained report output and route |
28
- | `review_routed` | Resume debug route | Handoff already records run id, debug route, and `debug_active` | `delivery-phase` | `debug_active` | None | Existing atomic handoff; no guard fallthrough |
29
- | `review_routed` | Resume implementation route | Handoff already records run id, implementation route, and `repair_active` | `delivery-phase` | `repair_active` | None | Existing atomic handoff; no guard fallthrough |
30
- | `review_routed` | Mixed or single finding route | Runtime evidence exists; run id unrecorded | `delivery-phase` | `debug_active` | Atomic handoff opens corresponding repair | Primary debug route, stable findings, atomic handoff, optional architecture follow-up |
31
- | `review_routed` | Mixed or single finding route | No runtime evidence; in-scope non-runtime blocker exists; run id unrecorded | `delivery-phase` | `repair_active` | Atomic handoff opens corresponding repair | Primary implementation route, stable findings, atomic handoff, optional architecture follow-up |
32
- | `review_routed` | Finding route | No higher blocker; broad architecture debt exists | `delivery-phase` | `debt_follow_up` | None | Debt route and stable findings |
33
- | `review_routed` | No-blocker route | Required documentation remains | `delivery-phase` | `docs_ingest` | None | Report and docs route |
34
- | `review_routed` | No-blocker route | Documentation complete | `delivery-phase` | `closeout` | None | Report and closeout route |
35
- | `repair_active` or `debug_active` | Ordinary repair completes | `review_count < 3` | `delivery-phase` | `review_due` | None | Stale prior report, changed target identity, preserved counters |
36
- | `repair_active` or `debug_active` | Fix 3 completes | `review_count = 3` and `repair_count = 3` | `delivery-phase` | `focused_validation` | None | Fix-3 changes and required focused validation |
37
- | `focused_validation` | Focused validation fails | Repair epoch 3 remains open | `delivery-phase` | `repair_active` or `debug_active` | None; unchanged counters | Failed validation and recorded owning route |
38
- | `focused_validation` | Focused validation passes | Repair epoch 3 complete | `delivery-phase` | `clean_handoff` | None | Passing validation, final changes, report-3 link, clean status |
7
+ | State | Event | Guard | Owner | Next state | Counter effect | Required evidence |
8
+ | --------------------------------- | ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- | --------------------------------- | ------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------- |
9
+ | Current delivery state | Review considered | Unsupported target | Delivery caller | Return `review_failed` | None; zero handoff or status writes | Exact target failure; no report |
10
+ | Current delivery state | Review considered | Invalid accepted bounds | Delivery caller | Return `review_failed` | None; zero handoff or status writes | Exact bounds failure; no report |
11
+ | `review_due` | Authorized review invocation | Delivery; accepted bounds and target valid; recovered `review_count < 3` | Delivery caller | `review_running` | Preallocate ordinal `review_count + 1`; no completed-pass change | Lineage, run id, ordinal, bounds identity/hash, normalized target |
12
+ | `review_due` | Explicit review invocation | Standalone; accepted bounds and target valid | Standalone caller | `review_running` | None | Lineage, run id, bounds identity/hash, normalized target |
13
+ | Current delivery state | Review considered | Delivery; in-memory accepted bounds and target valid; recovered `review_count >= 3` | Delivery caller | Return `review_budget_exhausted` | None; zero handoff or status writes | Exact current route, lineage, counters; no report or status mutation |
14
+ | `review_running` | All lenses and parent verification complete | One frozen snapshot; complete local report exists | `review-phase` | `report_retention_pending` | None; no completed-pass change | Complete report and fresh target/source hashes |
15
+ | `review_running` | Validation mutation detected | Frozen-target hash differs after validation | `review-phase` | `review_due` | None | Before/after hashes, command, mutation evidence; no report or pass |
16
+ | `review_running` | Retryable infrastructure failure or partial run | No immutable report | `review-phase` | `review_due` | None | Exact retryable evidence; unchanged counters |
17
+ | `review_running` | Non-retryable contract or infrastructure failure | No immutable report | `review-phase` | `review_failed` | None | Exact terminal evidence; no report; unchanged counters |
18
+ | `report_retention_pending` | Retention verified | Delivery; valid retained-pass predicate; ordinal at most 3; hashes fresh | Report writer | `review_routed` | Unique retained commit establishes authoritative ordinal; reconcile projection | Path, SHA-256, commit, retained ref, ordinal, run id |
19
+ | `report_retention_pending` | Retention rejected | Delivery; ordinal is greater than 3 | Report writer | `review_budget_exhausted` | None | Exact ordinal rejection/current route; no authoritative pass |
20
+ | `report_retention_pending` | Retention verified | Standalone; valid retained-pass predicate; hashes fresh | Report writer | `review_routed` | None | Path, SHA-256, commit, retained ref |
21
+ | `report_retention_pending` | Idempotent retention recovery | Same lineage/run has identical valid path, report blob SHA-256, and commit | Report writer | `review_routed` | Reuse existing pass; project its ordinal at most once | Existing unique authority and containment evidence |
22
+ | `report_retention_pending` | Same-run conflict | Same lineage/run has two valid candidates with different path, blob, or commit | Report writer | `review_failed` | None | `same_run_conflict`, both authorities; no pass or counter change |
23
+ | `report_retention_pending` | Retained-pass validation rejected | Active candidate is malformed or has wrong derived identity, hash, paths, containment, or ordinal | Report writer | `review_failed` | None | Exact failed predicate; no pass or counter change |
24
+ | `report_retention_pending` | Retryable retention failure | Hashes fresh | Report writer | `report_retention_pending` | None | Exact retryable evidence; no authoritative pass |
25
+ | `report_retention_pending` | Non-retryable retention failure | Retry cannot succeed | Report writer | `review_failed` | None | Exact terminal evidence; no authoritative pass |
26
+ | `report_retention_pending` | Freshness changed | Target or source hash changed | `review-phase` | `review_due` | None | Stale local report; unchanged counters |
27
+ | `review_routed` | Readonly return | Standalone | Standalone caller | `review_complete` | None | Retained report output and route |
28
+ | `review_routed` | Resume debug route | Handoff already records run id, debug route, and `debug_active` | `delivery-phase` | `debug_active` | None | Existing atomic handoff; no guard fallthrough |
29
+ | `review_routed` | Resume implementation route | Handoff already records run id, implementation route, and `repair_active` | `delivery-phase` | `repair_active` | None | Existing atomic handoff; no guard fallthrough |
30
+ | `review_routed` | Resume debt follow-up | Handoff already records run id, retained report, stable finding IDs, and `debt_follow_up` | Delivery review handoff | `debt_follow_up` | None | Existing debt keys and artifact; no duplicate capture |
31
+ | `review_routed` | Mixed finding route | Runtime evidence exists; derived primary route is `debugging`; secondary architecture follow-up is true; run id unrecorded | `delivery-phase` | `debt_follow_up` | None | Explicit finding routes, stable findings, post-debt route `debugging` |
32
+ | `review_routed` | Mixed finding route | No runtime evidence; derived primary route is `implementation`; secondary architecture follow-up is true; run id unrecorded | `delivery-phase` | `debt_follow_up` | None | Explicit finding routes, stable findings, post-debt route `implementation` |
33
+ | `review_routed` | Single repair route | Runtime evidence exists; derived primary route is `debugging`; no debt follow-up; run id unrecorded | `delivery-phase` | `debug_active` | Atomic handoff opens corresponding repair | Explicit finding routes, stable findings, atomic handoff |
34
+ | `review_routed` | Single repair route | No runtime evidence; in-scope non-runtime blocker exists; derived primary route is `implementation`; no debt follow-up; run id unrecorded | `delivery-phase` | `repair_active` | Atomic handoff opens corresponding repair | Explicit finding routes, stable findings, atomic handoff |
35
+ | `review_routed` | Finding route | Derived primary route is `debt_follow_up` | `delivery-phase` | `debt_follow_up` | None | Explicit debt routes, stable findings, post-debt route `docs_ingest` or `closeout` |
36
+ | `debt_follow_up` | Debt captured | Every debt key is present; `post_debt_route` is `debugging` | Delivery review handoff | `debug_active` | Open repair after capture exactly once | Retained report commit/path, stable finding IDs, artifact path, captured keys |
37
+ | `debt_follow_up` | Debt captured | Every debt key is present; `post_debt_route` is `implementation` | Delivery review handoff | `repair_active` | Open repair after capture exactly once | Retained report commit/path, stable finding IDs, artifact path, captured keys |
38
+ | `debt_follow_up` | Debt captured | Every debt key is present; `post_debt_route` is `docs_ingest` or `closeout` | Delivery review handoff | `docs_ingest` or `closeout` | None | Retained report commit/path, stable finding IDs, artifact path, captured keys |
39
+ | `review_routed` | Documentation-only findings | Derived primary route is `docs_ingest` | `delivery-phase` | `docs_ingest` | None | Explicit docs routes and stable findings |
40
+ | `review_routed` | Finding-free route | Finding set is empty | `delivery-phase` | `closeout` | None | Report and derived closeout route |
41
+ | `repair_active` or `debug_active` | Ordinary repair completes | `review_count < 3` | `delivery-phase` | `review_due` | None | Stale prior report, changed target identity, preserved counters |
42
+ | `repair_active` or `debug_active` | Fix 3 completes | `review_count = 3` and `repair_count = 3` | `delivery-phase` | `focused_validation` | None | Fix-3 changes and required focused validation |
43
+ | `focused_validation` | Focused validation fails | Repair epoch 3 remains open | `delivery-phase` | `repair_active` or `debug_active` | None; unchanged counters | Failed validation and recorded owning route |
44
+ | `focused_validation` | Focused validation passes | Repair epoch 3 complete | `delivery-phase` | `clean_handoff` | None | Passing validation, final changes, report-3 link, clean status |
39
45
 
40
46
  ## Durable Budget
41
47
 
@@ -52,6 +58,13 @@ already-consumed ordinals. Complete the transition only after the write. An
52
58
  already recorded run ID resumes its active state without another increment and
53
59
  cannot fall through to an unrecorded guard.
54
60
 
61
+ Debt capture is also idempotent. The retained report commit, report path, and
62
+ stable finding ID form one key in the goal/spec-linked debt artifact. Resume
63
+ reuses recorded keys, adds only missing keys, and follows durable
64
+ `post_debt_route` without implementing unaccepted debt. Secondary debt records
65
+ `debugging` or `implementation`; primary debt records `docs_ingest` or
66
+ `closeout`. Capture completes before the recorded route opens.
67
+
55
68
  Review 1 may open fix 1, review 2 fix 2, and review 3 fix 3. Fix 3 never opens
56
69
  review 4. A failed focused validation stays in repair epoch 3 until that same
57
70
  validation passes.
@@ -6,7 +6,8 @@ composition, report, routing, and freshness contracts.
6
6
 
7
7
  ## Scope
8
8
 
9
- Record the smallest certain inclusive scope. Full-repository expansion requires
9
+ Record a non-empty, smallest certain inclusive scope in every review mode. A
10
+ zero-artifact bundle is not a review target. Full-repository expansion requires
10
11
  an explicit caller request. Unsupported targets or invalid accepted bounds enter
11
12
  `review_failed` with exact evidence, no report, and no counter change, including
12
13
  when a delivery counter is already 3.
@@ -36,8 +36,12 @@ export const inclusiveScopeHash = (entries) => hashRecord("inclusive-scope", sor
36
36
  export const acceptedBoundsHash = (identity, scopeEntries) =>
37
37
  hashRecord("accepted-bounds", [identity, inclusiveScopeHash(scopeEntries)]);
38
38
 
39
- export const deliveryLineageId = (deliveryGoalIdentity) =>
40
- hashRecord("delivery-lineage", [deliveryGoalIdentity]);
39
+ export const deliveryLineageId = (deliveryGoalIdentity) => {
40
+ if (typeof deliveryGoalIdentity !== "string" || deliveryGoalIdentity.length === 0) {
41
+ throw new TypeError("delivery goal identity must be a non-empty string");
42
+ }
43
+ return hashRecord("delivery-lineage", [deliveryGoalIdentity]);
44
+ };
41
45
 
42
46
  export const standaloneLineageId = (locator, boundsHash) =>
43
47
  hashRecord("standalone-lineage", [locator, boundsHash]);
@@ -118,10 +122,21 @@ export const sourceSetHash = (sources) =>
118
122
  .flatMap(({ path, hash }) => [path, hash]),
119
123
  );
120
124
 
121
- export const reviewReportPath = ({ lineageId, reviewedAt, snapshotHash }) => {
122
- if (!/^\d{8}T\d{6}Z$/u.test(reviewedAt)) {
123
- throw new TypeError("reviewedAt must use YYYYMMDDTHHMMSSZ UTC format");
125
+ const assertReviewedAt = (reviewedAt, field) => {
126
+ const match = /^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z$/u.exec(reviewedAt);
127
+ if (!match) {
128
+ throw new TypeError(`${field} must use YYYYMMDDTHHMMSSZ UTC format`);
129
+ }
130
+ const [, year, month, day, hour, minute, second] = match;
131
+ const iso = `${year}-${month}-${day}T${hour}:${minute}:${second}.000Z`;
132
+ const instant = new Date(iso);
133
+ if (Number.isNaN(instant.valueOf()) || instant.toISOString() !== iso) {
134
+ throw new TypeError(`${field} must name a real UTC instant`);
124
135
  }
136
+ };
137
+
138
+ export const reviewReportPath = ({ lineageId, reviewedAt, snapshotHash }) => {
139
+ assertReviewedAt(reviewedAt, "reviewedAt");
125
140
  return `apps/wiki/content/docs/project/reviews/${reviewScopeSlug(lineageId)}-${reviewedAt}-${snapshot12(snapshotHash)}-review-report.md`;
126
141
  };
127
142
 
@@ -147,6 +162,29 @@ const FRONTMATTER_KEYS = [
147
162
  const HEX_64 = /^[0-9a-f]{64}$/u;
148
163
  const COMMIT_SHA = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/u;
149
164
  const LENS_KEYS = ["standards", "skill_adherence", "architecture", "simplify", "spec"];
165
+ const PROTOTYPE_KEYS = new Set(["__proto__", "constructor", "prototype"]);
166
+ const FINDING_ROUTES = ["debugging", "implementation", "debt_follow_up", "docs_ingest"];
167
+
168
+ export const deriveReviewRouting = (findings) => {
169
+ if (
170
+ !Array.isArray(findings) ||
171
+ findings.some(
172
+ (finding) =>
173
+ finding === null ||
174
+ typeof finding !== "object" ||
175
+ !FINDING_ROUTES.includes(finding.return_route),
176
+ )
177
+ ) {
178
+ throw new TypeError("invalid finding return route");
179
+ }
180
+ const routes = new Set(findings.map(({ return_route: route }) => route));
181
+ const primary = FINDING_ROUTES.find((route) => routes.has(route)) ?? "closeout";
182
+ return {
183
+ primary,
184
+ secondary_architecture_follow_up:
185
+ routes.has("debt_follow_up") && (primary === "debugging" || primary === "implementation"),
186
+ };
187
+ };
150
188
 
151
189
  const exactKeys = (value, keys) =>
152
190
  value !== null &&
@@ -163,9 +201,7 @@ const sortedUniqueStrings = (values) =>
163
201
  isDeepStrictEqual(values, sortUtf8(values));
164
202
 
165
203
  const reportDate = (reviewedAt) => {
166
- if (!/^\d{8}T\d{6}Z$/u.test(reviewedAt)) {
167
- throw new TypeError("reviewed_at must use YYYYMMDDTHHMMSSZ");
168
- }
204
+ assertReviewedAt(reviewedAt, "reviewed_at");
169
205
  return `${reviewedAt.slice(0, 4)}-${reviewedAt.slice(4, 6)}-${reviewedAt.slice(6, 8)}`;
170
206
  };
171
207
 
@@ -218,11 +254,14 @@ const parseFrontmatter = (text) => {
218
254
  if (!text.startsWith("---\n")) throw new TypeError("missing frontmatter");
219
255
  const close = text.indexOf("\n---\n", 4);
220
256
  if (close < 0) throw new TypeError("unclosed frontmatter");
221
- const frontmatter = {};
257
+ const frontmatter = Object.create(null);
222
258
  for (const line of text.slice(4, close).split("\n")) {
223
259
  const separator = line.indexOf(": ");
224
260
  if (separator < 1) throw new TypeError("malformed frontmatter line");
225
261
  const key = line.slice(0, separator);
262
+ if (PROTOTYPE_KEYS.has(key)) {
263
+ throw new TypeError("prototype-sensitive frontmatter key");
264
+ }
226
265
  if (Object.hasOwn(frontmatter, key)) throw new TypeError("duplicate frontmatter key");
227
266
  const raw = line.slice(separator + 2);
228
267
  frontmatter[key] = raw === "[]" ? [] : JSON.parse(raw);
@@ -264,6 +303,8 @@ export const normalizeReviewTarget = (mode, evidence) => {
264
303
  !nonemptyString(evidence.actualBaseRef) ||
265
304
  !COMMIT_SHA.test(evidence.fixedPointSha) ||
266
305
  !nonemptyString(evidence.headIdentity) ||
306
+ !Array.isArray(evidence.scopeEntries) ||
307
+ evidence.scopeEntries.length === 0 ||
267
308
  !sortedUniqueStrings(sortUtf8(evidence.scopeEntries)) ||
268
309
  !Buffer.isBuffer(evidence.canonicalPatchBytes)
269
310
  ) {
@@ -280,11 +321,15 @@ export const normalizeReviewTarget = (mode, evidence) => {
280
321
  };
281
322
  }
282
323
  if (mode === "standalone") {
324
+ if (!Array.isArray(evidence.scopeEntries) || evidence.scopeEntries.length === 0) {
325
+ throw new TypeError("invalid standalone target evidence");
326
+ }
283
327
  const files = orderedFiles(evidence.files);
284
328
  const identities = files.map(({ identity }) => identity);
285
329
  const scope = sortUtf8(evidence.scopeEntries);
286
330
  if (
287
331
  !nonemptyString(evidence.locator) ||
332
+ identities.length === 0 ||
288
333
  !sortedUniqueStrings(identities) ||
289
334
  !files.every(({ bytes }) => Buffer.isBuffer(bytes)) ||
290
335
  !isDeepStrictEqual(scope, identities)
@@ -306,6 +351,7 @@ export const normalizeReviewTarget = (mode, evidence) => {
306
351
  export const normalizeReviewSources = (sources) => {
307
352
  if (
308
353
  !Array.isArray(sources) ||
354
+ sources.length === 0 ||
309
355
  sources.some(({ path, bytes }) => !nonemptyString(path) || !Buffer.isBuffer(bytes)) ||
310
356
  new Set(sources.map(({ path }) => path)).size !== sources.length
311
357
  ) {
@@ -393,7 +439,12 @@ const validateTargetSchema = (target, mode, errors) => {
393
439
  errors.push("malformed:normalized_target_schema");
394
440
  return;
395
441
  }
396
- if (!nonemptyString(target.locator) || !sortedUniqueStrings(target.inclusive_scope)) {
442
+ if (
443
+ !nonemptyString(target.locator) ||
444
+ !Array.isArray(target.inclusive_scope) ||
445
+ target.inclusive_scope.length === 0 ||
446
+ !sortedUniqueStrings(target.inclusive_scope)
447
+ ) {
397
448
  errors.push("malformed:normalized_target_common_fields");
398
449
  }
399
450
  if (mode === "delivery") {
@@ -435,7 +486,16 @@ const validateReportSemantics = (report, errors) => {
435
486
  if (!Array.isArray(report.findings)) {
436
487
  errors.push("malformed:findings");
437
488
  } else {
438
- const findingKeys = ["id", "lens", "severity", "location", "impact", "evidence", "action"];
489
+ const findingKeys = [
490
+ "id",
491
+ "lens",
492
+ "severity",
493
+ "location",
494
+ "impact",
495
+ "evidence",
496
+ "action",
497
+ "return_route",
498
+ ];
439
499
  const ids = new Set();
440
500
  const findingLenses = new Set();
441
501
  for (const finding of report.findings) {
@@ -471,6 +531,14 @@ const validateReportSemantics = (report, errors) => {
471
531
  typeof report.routing?.secondary_architecture_follow_up !== "boolean"
472
532
  ) {
473
533
  errors.push("malformed:routing");
534
+ } else {
535
+ try {
536
+ if (!isDeepStrictEqual(report.routing, deriveReviewRouting(report.findings))) {
537
+ errors.push("mismatch:routing");
538
+ }
539
+ } catch {
540
+ errors.push("malformed:finding_return_route");
541
+ }
474
542
  }
475
543
 
476
544
  const validationKeys = [
@@ -655,7 +723,13 @@ const inspectRetainedPass = (candidate, expected) => {
655
723
  ) {
656
724
  errors.push("mismatch:report_sha256");
657
725
  }
658
- if (!candidate.refContainsCommit) errors.push("ref_missing_commit");
726
+ if (
727
+ !Buffer.isBuffer(candidate.resolvedReportBytes) ||
728
+ !candidate.reportBytes.equals(candidate.resolvedReportBytes)
729
+ ) {
730
+ errors.push("mismatch:resolved_report_bytes");
731
+ }
732
+ if (candidate.refContainsCommit !== true) errors.push("ref_missing_commit");
659
733
  if (!COMMIT_SHA.test(candidate.reportCommitSha)) {
660
734
  errors.push("invalid:report_commit_sha");
661
735
  }