@punks/cli 3.1.9 → 3.1.11

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 (44) hide show
  1. package/dist/BASELINE_CHANGELOG.md +67 -0
  2. package/dist/CHANGELOG.md +48 -0
  3. package/dist/data/subagents/manifest.mjs +11 -6
  4. package/dist/index.js +32 -29
  5. package/dist/skills/agnostic/cli/hi-cli/references/post-command-flow.md +5 -0
  6. package/dist/skills/agnostic/docs/writing-great-skills/GLOSSARY.md +69 -0
  7. package/dist/skills/agnostic/docs/writing-great-skills/SKILL.md +63 -0
  8. package/dist/skills/agnostic/planning/create-plan/REFERENCE.md +1 -1
  9. package/dist/skills/agnostic/planning/create-plan/SKILL.md +19 -7
  10. package/dist/skills/agnostic/planning/create-plan/references/plan-schema.md +19 -0
  11. package/dist/skills/agnostic/planning/create-plan/references/planner-task-graph.md +27 -10
  12. package/dist/skills/agnostic/planning/implement-spec/SKILL.md +6 -2
  13. package/dist/skills/agnostic/planning/implement-spec/assets/IMPLEMENTATION-NOTES-TEMPLATE.md +22 -6
  14. package/dist/skills/agnostic/planning/implement-spec/references/lifecycle.md +12 -0
  15. package/dist/skills/agnostic/planning/implement-spec/references/parallel-orchestration.md +10 -2
  16. package/dist/skills/agnostic/planning/implement-spec/references/parallel-worker-brief.md +10 -1
  17. package/dist/skills/agnostic/planning/implement-spec/references/parallel.md +2 -0
  18. package/dist/skills/agnostic/quality/autoreview/SKILL.md +11 -2
  19. package/dist/skills/agnostic/quality/review/SKILL.md +16 -11
  20. package/dist/skills/frameworks/effect/effect-service-design/LICENSE +21 -0
  21. package/dist/skills/frameworks/effect/effect-service-design/SKILL.md +124 -0
  22. package/dist/skills/frameworks/effect/effect-service-design/references/AUDIT.md +98 -0
  23. package/dist/skills/frameworks/nestjs/nestjs-best-practices/.gitignore +29 -0
  24. package/dist/skills/languages/python/python-backend-structure/SKILL.md +91 -0
  25. package/dist/skills/languages/python/python-backend-structure/agents/openai.yaml +4 -0
  26. package/dist/skills/languages/python/python-design-patterns/SKILL.md +93 -69
  27. package/dist/skills/languages/python/python-project-structure/SKILL.md +4 -247
  28. package/dist/skills/phases/delivery-phase/SKILL.md +13 -4
  29. package/dist/skills/phases/delivery-phase/phases/closeout.md +3 -0
  30. package/dist/skills/phases/delivery-phase/phases/debug.md +8 -1
  31. package/dist/skills/phases/delivery-phase/phases/implement.md +11 -2
  32. package/dist/skills/phases/delivery-phase/phases/review.md +50 -29
  33. package/dist/skills/phases/delivery-phase/phases/router.md +56 -36
  34. package/dist/skills/phases/delivery-phase/references/artifact-state.md +8 -2
  35. package/dist/skills/phases/delivery-phase/references/phase-handoff.md +60 -10
  36. package/dist/skills/phases/finder-phase/references/root-routing.md +6 -1
  37. package/dist/skills/phases/review-phase/REFERENCE.md +83 -145
  38. package/dist/skills/phases/review-phase/SKILL.md +41 -45
  39. package/dist/skills/phases/review-phase/agents/openai.yaml +2 -0
  40. package/dist/skills/phases/review-phase/references/durable-report.md +172 -0
  41. package/dist/skills/phases/review-phase/references/state-graph.md +69 -0
  42. package/dist/skills/phases/review-phase/references/targets.md +156 -0
  43. package/dist/skills/phases/review-phase/scripts/review-contract.mjs +819 -0
  44. package/package.json +9 -63
@@ -15,7 +15,8 @@ Keep root prompt guidance short:
15
15
  - Unclear requirements inside a bounded topic route to `requirements-phase`.
16
16
  - Accepted specs, issues, or plans route to `delivery-phase`.
17
17
  - Runtime failures route to `debugging-phase`.
18
- - Reviews route to `review-phase`.
18
+ - Review requests persist the bounded target and accepted-bounds context, then
19
+ point the operator to the exact explicit `$review-phase` invocation.
19
20
  - Docs learning after proven changes routes to `docs-ingest-phase`.
20
21
 
21
22
  ## Boundary
@@ -28,3 +29,7 @@ Keep root prompt guidance short:
28
29
  - `create-spec`, `create-plan`, or `delivery-phase` after implementation scope is accepted.
29
30
 
30
31
  It chooses the route and updates the frontier handoff.
32
+
33
+ `finder-phase`, root routing, and `delivery-phase` never invoke, delegate to, or
34
+ model-select `review-phase`. They may only persist its input context, return the
35
+ exact explicit `$review-phase` instruction, and stop.
@@ -1,147 +1,85 @@
1
1
  # Review Phase Reference
2
2
 
3
- ## Use And Stop Rules
4
-
5
- Use for review-only goals, audits, PR review, suspicious code, external edits,
6
- merged or rebased branches, and `delivery-phase` review gates.
7
-
8
- Do not use when the user asks for immediate implementation, pure planning,
9
- requirements grilling, docs writing with no artifact to review, or an undefined
10
- target that cannot be inferred from branch, diff, issue, PR, or prompt.
11
-
12
- Standalone mode is readonly and stops after findings. Delivery mode may return
13
- findings to delivery for fixes, debugging, docs, or validation because delivery
14
- owns completion.
15
-
16
- ## Scope Policy
17
-
18
- Default to the smallest certain target:
19
-
20
- - open PR changes
21
- - highlighted diff
22
- - supplied code portions
23
- - branch range
24
- - named files, paths, packages, apps, domains, or features
25
-
26
- Use a full-codebase scan only when no PR is open and no certain domain, portion,
27
- or path is provided, or when the user explicitly asks for a full-codebase
28
- review.
29
-
30
- Pass the bounded target into every inner review step: `autoreview`,
31
- ClawPatch-backed review, delegated readonly checks, and lens prompts. Do not run
32
- review tooling against the full codebase when a bounded target exists.
33
-
34
- For PR review, use the actual PR base branch. Do not assume trunk.
35
-
36
- ## Runtime And Lenses
37
-
38
- Start review flow with `review`. It pins the fixed point, discovers
39
- Spec and Standards sources, carries baseline code smells, and keeps Standards
40
- findings separate from Spec findings. Use that frame for delegated review
41
- prompts, `autoreview` context, and final aggregation.
42
-
43
- `autoreview` remains the core structured review runtime. Capture the exact
44
- command and manually verify accepted findings against source, docs, scoped
45
- skills, and dependency contracts.
46
-
47
- Mandatory lenses:
48
-
49
- - `review`: two-axis Standards versus Spec wrapper, fixed diff, and
50
- separate aggregation.
51
- - `simplify`: clarity, avoidable complexity, unnecessary abstraction, derivable
52
- state, naming, and scope creep.
53
- - `improve-codebase-architecture`: boundary friction, shallow modules, module
54
- depth, and follow-up RFC candidates.
55
- - Scoped local guidance: nearest relevant `AGENTS.md`, stack skills, runbooks,
56
- ownership rules, and skills named by those instructions.
57
-
58
- Conditional lens:
59
-
60
- - `parallel-research`: split independent readonly checks by subsystem, risk, or
61
- hypothesis. Synthesize evidence; do not vote-count disagreements.
62
-
63
- ## Evidence And Validation
64
-
65
- Prefer primary artifacts over tracker summaries. Record exact files and
66
- commands consulted. Include stack status or prior delivery stack evidence when
67
- stack metadata is relevant.
68
-
69
- Safe readonly validation may include focused tests, typecheck, lint, build,
70
- docs link checks, or smoke commands. If a check cannot run, state why and the
71
- residual risk.
72
-
73
- For behavior-changing implementation plans or specs, missing RED/GREEN proof is
74
- a blocking finding unless the task has an explicit valid `reason_not_testable`.
75
- Reject `reason_not_testable` when the only reason is forgotten RED; the delivery
76
- owner must recover with public-result RED and GREEN evidence.
77
-
78
- ## Requirements Grill Wrapper Review
79
-
80
- When reviewed spec, plan, phase, or wrapper claims to use
81
- `requirements-grill` or design-phase grill, review shared interview behavior
82
- against `$grilling` and durable behavior against the `requirements-grill`
83
- inner flow, not just its outer handoff.
84
-
85
- Check:
86
-
87
- - Serious grill sessions pair `references/grilling-flow.md` with
88
- `references/artifact-output.md`.
89
- - Before each round is yielded, it is persisted with stable question ids,
90
- prerequisites, and the current frontier, with a stable mapping between live
91
- questions and the routed log/status artifacts.
92
- - Each response set is processed answer by answer; partially answered rounds
93
- preserve omitted questions as unanswered and carry them forward.
94
- - Status is updated after each response set, and branch percentages agree with
95
- the unanswered-question and shared-understanding confirmation fields.
96
- - Routed grill log/status artifacts are created or updated when grilling
97
- decisions, branches, parked scope, percentages, glossary, axioms, or
98
- ambiguities change.
99
- - Glossary, axiom, and status updates preserve current meaning while the
100
- log records accepted decisions and superseded decisions.
101
- - Added or renamed wiki grill artifacts update routed metadata/bookkeeping:
102
- `content/docs/project/grilling/meta.json`, section index when missing,
103
- and wiki `log.md` when the repo maintains one.
104
- - After `$grilling` completes, downstream handoff evidence exists as
105
- applicable: wiki synthesis, backlog/user stories, spec, or phase handoff
106
- carrying accepted decisions and recorded scope state.
107
-
108
- Missing inner-flow or durable-artifact evidence is a review finding when
109
- the wrapper promised grill behavior.
110
-
111
- ## Findings Policy
112
-
113
- Prioritize bugs, regressions, broken contracts, missing validation, unsafe
114
- assumptions, and user-facing risks. Include file and line references when
115
- available. Separate blocking findings from improvements and optional cleanup.
116
-
117
- Do not edit code in standalone mode unless the user explicitly asks after
118
- seeing the review scope. Do not use `simplify` as permission to refactor.
119
-
120
- Do not flatten scoped `AGENTS.md` guidance into generic advice; cite the
121
- concrete constraint. Do not skip scoped skills from `AGENTS.md` prompts.
122
-
123
- Do not run mutating stack commands in review. `review-phase` reports stack
124
- evidence only; delivery owns `stack sync`.
125
-
126
- ## Output Checklist
127
-
128
- Lead with findings, ordered by severity. For each finding include:
129
-
130
- - severity
131
- - file/line or artifact reference
132
- - issue and impact
133
- - evidence
134
- - recommended action
135
-
136
- Then include:
137
-
138
- - open questions or assumptions
139
- - validation run and result
140
- - exact `autoreview` command and clean/accepted-findings result
141
- - fixed point, Spec source or skipped reason, Standards sources
142
- - scoped `AGENTS.md` files and mandatory scoped skills checked
143
- - short summary after findings
144
- - mode: standalone readonly review or delivery-owned review
145
-
146
- If there are no findings, say so clearly and still report validation coverage
147
- and residual risk.
3
+ Load [references/targets.md](references/targets.md) for target normalization,
4
+ identity, or resume. Load
5
+ [references/state-graph.md](references/state-graph.md) for delivery budget,
6
+ failure, retention, routing, repair, or final-fix behavior. Load
7
+ [references/durable-report.md](references/durable-report.md) before writing or
8
+ retaining a report.
9
+
10
+ ## One All-Lens Run
11
+
12
+ Evaluate exactly one frozen bounded snapshot per completed invocation.
13
+
14
+ 1. Run `autoreview` exactly once as advisory candidate generation. A ClawPatch
15
+ helper, when present, stays inside that call and consumes no additional pass.
16
+ 2. The parent verifies all advisory candidates against the frozen target and
17
+ adjacent evidence. Only verified candidates become findings.
18
+ 3. Dispatch independent lenses against the same snapshot in parallel:
19
+ - Standards
20
+ - skill adherence and scoped skills
21
+ - architecture
22
+ - simplify
23
+ - Spec
24
+ 4. Record an explicit outcome for every lens. Standards and skill adherence,
25
+ architecture, simplify, then Spec controls presentation and triage order
26
+ only. Parallel execution is unchanged. Standards and Spec stay distinct
27
+ report sections without cross-axis merging or reranking.
28
+
29
+ The `review` skill supplies separate Standards and Spec checks. Apply
30
+ `improve-codebase-architecture`, `simplify`, the nearest `AGENTS.md`, and every
31
+ named scoped skill as their own bounded lenses.
32
+
33
+ ## Skill-Adherence Lens
34
+
35
+ Treat `assigned_skills` as planning provenance. For every implementation task:
36
+
37
+ 1. Match every implementation-applicable `assigned_skills` item to exactly one
38
+ `implementation_skill_guidance` entry.
39
+ 2. Match every guidance entry to exactly one `IMPLEMENTATION-NOTES.md` evidence
40
+ record.
41
+ 3. Check evidence cardinality and every record, including `not_applicable`,
42
+ against frozen changed artifacts and the cited how/where location.
43
+ 4. Report missing, extra, or contradicted claims as a skill-adherence finding.
44
+
45
+ When a requirements or design wrapper claims grilling behavior, verify its
46
+ named guidance, routed log/status artifacts, stable question mapping, carried
47
+ unanswered questions, and downstream synthesis evidence instead of accepting
48
+ the wrapper claim alone.
49
+
50
+ ## Validation Boundary
51
+
52
+ Run the smallest safe readonly validation needed to verify candidates or
53
+ governing acceptance evidence. Broader checks run only when the accepted spec
54
+ or plan explicitly requires them. Missing required RED/GREEN evidence becomes
55
+ a reported and routed finding; review never creates that evidence.
56
+
57
+ Before every validation command, record the frozen-target hash. A command may
58
+ run against the reviewed checkout only when its no-write mode is proven. Run any
59
+ command that may write caches, generated files, snapshots, lockfiles, or other
60
+ state in a disposable checkout or snapshot rooted at the frozen revision.
61
+
62
+ Always recompute and compare the frozen-target hash after validation. A mismatch
63
+ invalidates the run and any local report, returns `review_due` with exact
64
+ mutation evidence, and consumes no pass. Record exact commands, isolation mode,
65
+ before/after hashes, sources, skipped checks, and residual risk. Keep this
66
+ validation bounded; isolation is a safety boundary, not permission to broaden
67
+ the test surface.
68
+
69
+ Use the executable before/after decision in
70
+ [`scripts/review-contract.mjs`](scripts/review-contract.mjs); mutation returns
71
+ `review_due` and consumes no pass.
72
+
73
+ ## Finding And Route Output
74
+
75
+ Every stable finding records severity, location, impact, evidence, and action.
76
+ Determine route precedence from verified evidence:
77
+
78
+ 1. runtime evidence: debugging
79
+ 2. otherwise, an in-scope non-runtime blocker: implementation
80
+ 3. otherwise, broad architecture debt: debt follow-up
81
+ 4. otherwise: documentation ingest or closeout by documentation completeness
82
+
83
+ Broad architecture debt may accompany debugging or implementation as a
84
+ secondary follow-up. Review returns this routing output and stops. Delivery
85
+ owns route mutation and repairs.
@@ -1,53 +1,49 @@
1
1
  ---
2
2
  name: review-phase
3
3
  description: >-
4
- Findings-first readonly review with explicit entry gates, delegated lenses,
5
- artifacts, and validation.
4
+ Explicit readonly review of one frozen delivery diff or standalone artifact
5
+ bundle, ending with one retained all-lens report and routing output.
6
6
  disable-model-invocation: true
7
7
  ---
8
8
 
9
9
  # Review Phase
10
10
 
11
- Readonly findings-first review. Standalone mode reports findings only; delivery
12
- mode hands findings back to the owning phase for fixes.
13
-
14
- Load [REFERENCE.md](REFERENCE.md) before running review tools. Start with
15
- `review` to frame fixed-point diff, Standards axis, and Spec axis.
16
-
17
- ## Contract
18
-
19
- - Target must be a diff, PR, branch range, files, spec, plan, docs, or runtime
20
- evidence.
21
- - Default scope is PR changes, highlighted diffs, supplied code portions, or
22
- certain paths/domains. Full-codebase scan only when no PR is open and no
23
- certain scope exists, or when the user explicitly asks.
24
- - Pass bounded scope to inner `autoreview`, ClawPatch-backed review, and
25
- delegated readonly checks.
26
- - Apply relevant `AGENTS.md` guidance and scoped skills for reviewed paths.
27
- - Use `review` as the review-flow wrapper; keep axes separate.
28
- - Use `autoreview` as the core structured review runtime.
29
- - If target claims `requirements-grill` or design-phase grill, inspect shared
30
- interview behavior against `$grilling` and durable-artifact evidence against
31
- the `requirements-grill` inner flow.
32
-
33
- ## Steps
34
-
35
- 1. Identify target, scope, base/head when relevant, and readonly posture.
36
- 2. If scope is ambiguous, ask one clarifying question.
37
- 3. Gather evidence: status, diff/range/PR metadata, tests, docs, local guidance,
38
- and exact files/commands consulted.
39
- 4. Apply `review`: pin fixed point, find Spec and Standards sources,
40
- and prepare separate Standards/Spec review prompts.
41
- 5. Run `autoreview` on the bounded target and manually verify accepted findings.
42
- 6. Apply mandatory lenses: `simplify`, `improve-codebase-architecture`, and
43
- applicable scoped skills, claimed grill-wrapper checks.
44
- 7. Run safe readonly validation that matches the target.
45
- 8. Report findings-first; standalone mode stops, delivery mode returns findings
46
- to the owning phase.
47
-
48
- ## Output
49
-
50
- Lead with findings by severity. Include references, impact, evidence,
51
- recommended action, validation, exact review command, fixed point, Spec source
52
- or skipped reason, Standards sources, scoped guidance checked, residual risk,
53
- and mode.
11
+ Review one frozen target through every normative lens. The reviewed target
12
+ remains readonly. One designated writer may change only the report, navigation,
13
+ and wiki-log retention envelope.
14
+
15
+ This phase owns normalization, inspection, report retention, and routing output.
16
+ It does not plan work, classify implementation stages, assign implementation
17
+ skills, create implementation-stage evidence, or repair findings.
18
+
19
+ ## Run
20
+
21
+ 1. Read [REFERENCE.md](REFERENCE.md), then load only the mode references it
22
+ points to. Completion: the explicit operator invocation has a valid
23
+ `review_due` context or a fresh `report_retention_pending` resume context.
24
+ 2. For `review_due`, apply the mode budget guard. Completion: delivery has
25
+ preallocated ordinal `review_count + 1` and fixed `review_run_id`, or
26
+ standalone has fixed its target-derived run identity, and the invocation has
27
+ entered `review_running`. For a fresh retention resume, continue at step 6
28
+ without rerunning lenses.
29
+ 3. Freeze the target and governing sources. Completion: one immutable bounded
30
+ snapshot and its target, bounds, and source hashes exist.
31
+ 4. Run the all-lens composition once. Completion: every lens has an explicit
32
+ outcome and every accepted finding was verified against the frozen evidence.
33
+ 5. Write the unique local report and enter `report_retention_pending` without a
34
+ counter change. Completion: the report satisfies the durable schema.
35
+ 6. Retain the allowed envelope and verify the retained ref contains its commit.
36
+ Completion: report path, report SHA-256, report commit SHA, and verified
37
+ retained ref exist outside the immutable report.
38
+ 7. Return the report evidence and route. Then terminate without entering a
39
+ repair state; delivery or the standalone caller owns every next action.
40
+
41
+ ## Boundaries
42
+
43
+ - Normalize the smallest certain inclusive scope. Expand to the full repository
44
+ only when the caller explicitly requests it.
45
+ - Use the smallest safe readonly validation. Missing required RED/GREEN proof is
46
+ a finding; review does not create implementation evidence or repairs.
47
+ - Stop on the graph outcome: `review_complete`, `review_due`,
48
+ `report_retention_pending`, `review_failed`, or `review_budget_exhausted`.
49
+ - External GitHub and Codex PR reviewer integration is outside this capability.
@@ -0,0 +1,2 @@
1
+ policy:
2
+ allow_implicit_invocation: false
@@ -0,0 +1,172 @@
1
+ # Durable Review Report
2
+
3
+ Every completed run creates one unique immutable report:
4
+
5
+ `apps/wiki/content/docs/project/reviews/<review-scope-slug>-<YYYYMMDDTHHMMSSZ>-<snapshot12>-review-report.md`
6
+
7
+ The report filename slug derives from `review_lineage_id`. Its content never
8
+ changes after creation.
9
+
10
+ ## Required Report Fields
11
+
12
+ The report bytes start with the wiki-required YAML frontmatter, followed
13
+ immediately by exactly one fenced authority block. Optional human prose may
14
+ follow its closing fence. Missing, malformed, extra, or duplicate frontmatter
15
+ or authority blocks are invalid.
16
+
17
+ ````text
18
+ ---
19
+ title: "<review-scope-slug> review report"
20
+ domain: "<domain>"
21
+ type: "review-report"
22
+ surface: "project"
23
+ permission: "internal"
24
+ links: []
25
+ review_lineage_id: "<stable lineage>"
26
+ review_run_id: "<mode-specific run identity>"
27
+ review_mode: "delivery | standalone"
28
+ reviewed_at: "YYYYMMDDTHHMMSSZ"
29
+ accepted_bounds_identity: "<identity>"
30
+ accepted_bounds_hash: "<sha256>"
31
+ snapshot_hash: "<sha256>"
32
+ created: "YYYY-MM-DD"
33
+ updated: "YYYY-MM-DD"
34
+ ---
35
+
36
+ ```review-report-json
37
+ {"review_lineage_id":"...", "...":"..."}
38
+ ```
39
+ Optional human prose.
40
+ ````
41
+
42
+ The parser reads both structures from retained bytes. Frontmatter has exactly
43
+ the typed fields above: every scalar is a string, `links` is an empty array, and
44
+ the fixed wiki values are `review-report`, `project`, and `internal`. Its title
45
+ uses the derived filename slug; created and updated equal the date in
46
+ `reviewed_at`. Its lineage, run, mode, timestamp, accepted-bounds identity/hash,
47
+ and snapshot hash must agree with the JSON authority and recomputed evidence.
48
+
49
+ The parsed JSON object is report authority. Detached objects, sidecars, and
50
+ caller-supplied derived identities are never trusted. It contains exactly these fields:
51
+
52
+ - `review_lineage_id`
53
+ - `review_run_id`
54
+ - accepted-bounds identity and hash
55
+ - `reviewed_at` and mode
56
+ - normalized target
57
+ - snapshot hash and narrow excluded envelope
58
+ - source paths and hashes for Spec, Standards, scoped guidance, and every named
59
+ skill
60
+ - canonical `source_set_hash`
61
+ - an explicit outcome for Standards, skill adherence and scoped skills,
62
+ architecture, simplify, and Spec
63
+ - stable finding identifiers with severity, location, impact, evidence, and
64
+ action
65
+ - routing and validation
66
+
67
+ Delivery mode also records delivery-goal identity, review ordinal, and preceding
68
+ repair ordinal when present. Standalone mode records those delivery-only fields
69
+ as null or not applicable.
70
+
71
+ `lens_outcomes` has exactly `standards`, `skill_adherence`, `architecture`,
72
+ `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.
76
+
77
+ `routing` has exactly `primary` and `secondary_architecture_follow_up`.
78
+ `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.
83
+
84
+ Delivery ordinals are 1 through 3. Review 1 has null preceding-repair ordinal;
85
+ review 2 or 3 records respectively 1 or 2. Standalone delivery-goal identity,
86
+ review ordinal, and preceding-repair ordinal are all null.
87
+
88
+ The snapshot hash excludes only the report itself, navigation metadata, and the
89
+ wiki log envelope. Navigation ordering does not affect freshness. The report and
90
+ normalized target omit raw selected bytes.
91
+
92
+ ## Retention
93
+
94
+ A complete local report enters `report_retention_pending` with no counter
95
+ change. One designated writer:
96
+
97
+ 1. rejects a delivery ordinal greater than 3 without an authoritative pass or
98
+ counter change;
99
+ 2. confirms target and governing source hashes remain fresh;
100
+ 3. commits only the report, navigation, and wiki-log envelope;
101
+ 4. pushes or uses a repository-approved retained ref;
102
+ 5. verifies that the retained ref contains the report commit.
103
+
104
+ Delivery uses its current delivery branch or another approved ref. Standalone
105
+ uses deterministic `review/<review-scope-slug>-<snapshot12>` or another approved
106
+ ref.
107
+
108
+ Return report path, report SHA-256, report commit SHA, and verified retained ref
109
+ outside the immutable report. A verified retained delivery report is the
110
+ authoritative completed ordinal; only then reconcile the handoff `review_count`
111
+ projection. Standalone retention changes no delivery counter.
112
+
113
+ ## Valid Retained Pass
114
+
115
+ [`../scripts/review-contract.mjs`](../scripts/review-contract.mjs) is the
116
+ executable encoder, byte parser, identity implementation, and validator. It
117
+ recomputes the normalized target, scope/bounds/source/snapshot hashes, lineage,
118
+ run ID, snapshot12, slug, path, and ordinal relationships from primitive current
119
+ evidence. A candidate is a valid retained pass only when every predicate holds:
120
+
121
+ 1. the immutable bytes contain valid wiki frontmatter and one authority block,
122
+ both satisfying every exact schema, agreement, and semantic rule above;
123
+ 2. mode, lineage, run id, delivery ordinal, accepted-bounds identity/hash,
124
+ snapshot hash, source-set hash, and deterministic report path equal values
125
+ recomputed from the canonical identity algorithm;
126
+ 3. the outside-envelope report SHA-256 equals the exact retained report blob;
127
+ 4. current accepted-bounds, normalized-target, and governing-source hashes still
128
+ equal the report values;
129
+ 5. the report commit changed the report path and only repository-approved
130
+ report, navigation, and wiki-log envelope paths;
131
+ 6. the approved retained ref contains that exact report commit;
132
+ 7. delivery ordinal is an integer from 1 through 3; standalone delivery-only
133
+ fields are null.
134
+
135
+ A malformed report, wrong lineage or run id, wrong blob or freshness hash,
136
+ outside-envelope commit path, missing ref containment, or invalid ordinal is not
137
+ a pass and cannot affect a counter.
138
+
139
+ ## Same-Run Uniqueness
140
+
141
+ Index retained candidates by `(review_lineage_id, review_run_id)`. Validate each
142
+ candidate independently before comparison.
143
+
144
+ - No valid candidate: no pass.
145
+ - One valid candidate: unique authoritative pass.
146
+ - Repeated discovery of the same path, report blob SHA-256, and report commit:
147
+ reuse that already-retained pass; create no new pass and project its ordinal
148
+ at most once.
149
+ - Two valid candidates for the same run with different path, blob SHA-256, or
150
+ report commit: `same_run_conflict`; reject the run with exact evidence, no
151
+ authoritative pass, and no counter change.
152
+
153
+ Recovery uses only unique or identical-reuse valid passes. Any same-run conflict
154
+ blocks recovery from that run rather than choosing one candidate. Delivery
155
+ projects the highest uniquely authoritative recovered ordinal.
156
+
157
+ ## Retention Failure
158
+
159
+ - A retryable retention failure stays `report_retention_pending`, returns exact
160
+ evidence, and establishes no pass. While target and source hashes remain
161
+ fresh, reuse the local report without rerunning lenses.
162
+ - A non-retryable contract or infrastructure failure enters `review_failed`
163
+ with exact evidence, no pass, and no counter change.
164
+ - A malformed active retention candidate or `same_run_conflict` enters
165
+ `review_failed` with exact evidence, no new pass, and no counter change.
166
+ - If target or source hash changes before retention, mark the local report stale
167
+ and return to `review_due` without consuming a pass.
168
+
169
+ The review report is the frozen-snapshot handoff. After fix 3, the delivery
170
+ handoff is final clean-state authority and links report 3, final changes,
171
+ focused validation, and clean status. Report 3 remains immutable pre-fix
172
+ evidence.
@@ -0,0 +1,69 @@
1
+ # Review And Repair State Graph
2
+
3
+ Review owns normalization, frozen inspection, report retention, routing output,
4
+ and termination. Delivery owns debugging, implementation, debt, docs, closeout,
5
+ and clean handoff.
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 |
39
+
40
+ ## Durable Budget
41
+
42
+ Only a unique valid retained report commit is an authoritative pass record.
43
+ Identical rediscovery reuses it. A conflicting same-run candidate supplies no
44
+ authority. Recover `review_count` from unique valid retained ordinals for the
45
+ lineage, using the highest valid retained ordinal; the handoff counter is a projection reconciled after interrupted
46
+ updates.
47
+
48
+ Repair opening is one atomic durable handoff write containing active state,
49
+ primary route, `repair_count = review_count`, and idempotency `review_run_id`.
50
+ This enforces the corresponding numbered repair and rejects mismatched or
51
+ already-consumed ordinals. Complete the transition only after the write. An
52
+ already recorded run ID resumes its active state without another increment and
53
+ cannot fall through to an unrecorded guard.
54
+
55
+ Review 1 may open fix 1, review 2 fix 2, and review 3 fix 3. Fix 3 never opens
56
+ review 4. A failed focused validation stays in repair epoch 3 until that same
57
+ validation passes.
58
+
59
+ Same-goal bounds revisions preserve delivery lineage and counters. Resume,
60
+ rebase, new commit, process retry, and handoff preserve them. Only an explicitly
61
+ new delivery goal with materially changed accepted bounds creates a new lineage
62
+ and resets counters.
63
+
64
+ `review_budget_exhausted` is a terminal no-op for the route evaluation: exact
65
+ current route evidence, no handoff write, report, counter or status change, and no block on clean
66
+ continuation. `review_failed` is only a non-retryable invocation-level contract
67
+ or infrastructure failure and consumes no counter.
68
+
69
+ External GitHub and Codex PR reviewer integration is excluded.