@punks/cli 3.1.10 → 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 (38) hide show
  1. package/dist/BASELINE_CHANGELOG.md +33 -0
  2. package/dist/CHANGELOG.md +30 -0
  3. package/dist/data/subagents/manifest.mjs +11 -6
  4. package/dist/index.js +29 -29
  5. package/dist/skills/agnostic/cli/hi-cli/references/post-command-flow.md +5 -0
  6. package/dist/skills/agnostic/planning/create-plan/REFERENCE.md +1 -1
  7. package/dist/skills/agnostic/planning/create-plan/SKILL.md +19 -7
  8. package/dist/skills/agnostic/planning/create-plan/references/plan-schema.md +19 -0
  9. package/dist/skills/agnostic/planning/create-plan/references/planner-task-graph.md +27 -10
  10. package/dist/skills/agnostic/planning/implement-spec/SKILL.md +6 -2
  11. package/dist/skills/agnostic/planning/implement-spec/assets/IMPLEMENTATION-NOTES-TEMPLATE.md +22 -6
  12. package/dist/skills/agnostic/planning/implement-spec/references/lifecycle.md +12 -0
  13. package/dist/skills/agnostic/planning/implement-spec/references/parallel-orchestration.md +10 -2
  14. package/dist/skills/agnostic/planning/implement-spec/references/parallel-worker-brief.md +10 -1
  15. package/dist/skills/agnostic/planning/implement-spec/references/parallel.md +2 -0
  16. package/dist/skills/agnostic/quality/autoreview/SKILL.md +11 -2
  17. package/dist/skills/agnostic/quality/review/SKILL.md +16 -11
  18. package/dist/skills/languages/python/python-backend-structure/SKILL.md +91 -0
  19. package/dist/skills/languages/python/python-backend-structure/agents/openai.yaml +4 -0
  20. package/dist/skills/languages/python/python-design-patterns/SKILL.md +93 -69
  21. package/dist/skills/languages/python/python-project-structure/SKILL.md +4 -247
  22. package/dist/skills/phases/delivery-phase/SKILL.md +13 -4
  23. package/dist/skills/phases/delivery-phase/phases/closeout.md +3 -0
  24. package/dist/skills/phases/delivery-phase/phases/debug.md +8 -1
  25. package/dist/skills/phases/delivery-phase/phases/implement.md +11 -2
  26. package/dist/skills/phases/delivery-phase/phases/review.md +50 -29
  27. package/dist/skills/phases/delivery-phase/phases/router.md +56 -36
  28. package/dist/skills/phases/delivery-phase/references/artifact-state.md +8 -2
  29. package/dist/skills/phases/delivery-phase/references/phase-handoff.md +60 -10
  30. package/dist/skills/phases/finder-phase/references/root-routing.md +6 -1
  31. package/dist/skills/phases/review-phase/REFERENCE.md +83 -145
  32. package/dist/skills/phases/review-phase/SKILL.md +41 -45
  33. package/dist/skills/phases/review-phase/agents/openai.yaml +2 -0
  34. package/dist/skills/phases/review-phase/references/durable-report.md +172 -0
  35. package/dist/skills/phases/review-phase/references/state-graph.md +69 -0
  36. package/dist/skills/phases/review-phase/references/targets.md +156 -0
  37. package/dist/skills/phases/review-phase/scripts/review-contract.mjs +819 -0
  38. package/package.json +9 -9
@@ -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.
@@ -0,0 +1,156 @@
1
+ # Review Target And Identity Contract
2
+
3
+ Validate accepted bounds and normalize a supported target before mode-specific
4
+ budget evaluation. Both target forms then enter the same review graph, lens
5
+ composition, report, routing, and freshness contracts.
6
+
7
+ ## Scope
8
+
9
+ Record the smallest certain inclusive scope. Full-repository expansion requires
10
+ an explicit caller request. Unsupported targets or invalid accepted bounds enter
11
+ `review_failed` with exact evidence, no report, and no counter change, including
12
+ when a delivery counter is already 3.
13
+
14
+ ## Delivery Git/Diff Adapter
15
+
16
+ Freeze and record:
17
+
18
+ - locator
19
+ - actual base ref
20
+ - merge-base or fixed-point SHA
21
+ - head or dirty-worktree identity
22
+ - inclusive scope
23
+ - canonical patch hash
24
+
25
+ Use the actual PR base when a PR exists. Record the exact bounded diff command
26
+ and environment. `canonical_patch_hash` is SHA-256 of its unmodified output
27
+ bytes.
28
+
29
+ The normalized object has exactly these keys:
30
+
31
+ ```text
32
+ kind: delivery-git-diff
33
+ locator:
34
+ actual_base_ref:
35
+ fixed_point_sha:
36
+ head_identity:
37
+ inclusive_scope: [sorted unique paths]
38
+ canonical_patch_hash: <64 lowercase hex>
39
+ ```
40
+
41
+ The validator receives the same primitive locator/base/fixed-point/head/scope
42
+ evidence plus the canonical patch bytes, hashes those bytes itself, and rejects
43
+ any missing, extra, malformed, or inconsistent normalized field.
44
+
45
+ ## Standalone Artifact Adapter
46
+
47
+ Plans, specs, and documentation freeze exact selected file bytes into one
48
+ deterministic ordered bundle. Sort file identities by their UTF-8 bytes. Hash
49
+ each file's raw bytes, then hash alternating identity/content-hash fields with
50
+ the canonical record below. Record:
51
+
52
+ - locator
53
+ - ordered file identities
54
+ - inclusive scope
55
+ - ordered bundle content hash
56
+ - explicit absence of a Git fixed point
57
+
58
+ The normalized target does not embed raw selected bytes. Standalone mode never
59
+ reads, increments, resets, or persists delivery counters.
60
+
61
+ The normalized object has exactly these keys:
62
+
63
+ ```text
64
+ kind: standalone-artifact
65
+ locator:
66
+ ordered_file_identities: [sorted unique paths]
67
+ inclusive_scope: [the same sorted unique paths]
68
+ ordered_bundle_content_hash: <64 lowercase hex>
69
+ git_fixed_point: null
70
+ ```
71
+
72
+ The validator receives primitive file identities and bytes, recomputes the
73
+ ordered bundle, and rejects any missing, extra, malformed, or inconsistent
74
+ normalized field.
75
+
76
+ ## Canonical Hash Record
77
+
78
+ All identities use lowercase hexadecimal SHA-256. The executable reference is
79
+ [`../scripts/review-contract.mjs`](../scripts/review-contract.mjs).
80
+
81
+ `record(label, fields)` is this exact byte sequence:
82
+
83
+ 1. UTF-8 bytes `review-identity-v1\n`.
84
+ 2. `frame(label)`.
85
+ 3. One `frame(value)` for each field in the stated fixed order.
86
+
87
+ `frame(value)` is the ASCII decimal UTF-8 byte length with no leading zero,
88
+ then ASCII `:`, then the exact UTF-8 bytes. Inputs receive no JSON encoding,
89
+ Unicode normalization, case folding, or newline rewriting. Sort set-like path
90
+ lists by unsigned UTF-8 byte order before framing. Hash raw file or patch bytes
91
+ directly before placing their lowercase hash in a record.
92
+
93
+ ## Derived Identities
94
+
95
+ Use these labels and field orders exactly:
96
+
97
+ - `inclusive_scope_hash = hash(record("inclusive-scope", sorted scope entries))`
98
+ - `accepted_bounds_hash = hash(record("accepted-bounds", [accepted_bounds_identity, inclusive_scope_hash]))`
99
+ - `delivery_snapshot_hash = hash(record("delivery-snapshot", [locator, actual_base_ref, fixed_point_sha, head_identity, inclusive_scope_hash, canonical_patch_hash]))`
100
+ - `ordered_bundle_content_hash = hash(record("artifact-bundle", [file_1_identity, file_1_raw_sha256, ...]))`
101
+ - `ordered_file_identities_hash = hash(record("ordered-files", [file_1_identity, ...]))`
102
+ - `standalone_snapshot_hash = hash(record("standalone-snapshot", [locator, ordered_file_identities_hash, inclusive_scope_hash, ordered_bundle_content_hash, "no-git-fixed-point"]))`
103
+ - `source_set_hash = hash(record("source-set", [source_1_path, source_1_blob_sha256, ...]))`, with sources sorted by path bytes
104
+ - `delivery_review_lineage_id = hash(record("delivery-lineage", [delivery_goal_identity]))`
105
+ - `standalone_review_lineage_id = hash(record("standalone-lineage", [locator, accepted_bounds_hash]))`
106
+ - `delivery_review_run_id = hash(record("delivery-run", [review_lineage_id, decimal_ordinal]))`
107
+ - `standalone_review_run_id = hash(record("standalone-run", [review_lineage_id, snapshot12]))`
108
+
109
+ `snapshot12` is the first 12 lowercase hexadecimal characters of the mode's
110
+ 64-character snapshot hash. `review-scope-slug` is `review-` plus the first 20
111
+ characters of `review_lineage_id`. Report UTC uses `YYYYMMDDTHHMMSSZ`.
112
+
113
+ Delivery lineage derives only from stable delivery-goal identity. Accepted-
114
+ bounds identity and hash do not enter delivery lineage. Standalone lineage
115
+ derives from target locator plus accepted-bounds hash. Delivery run identity
116
+ derives from lineage plus decimal ordinal; standalone run identity derives from
117
+ lineage plus `snapshot12`; the filename slug derives from lineage. Delivery preallocates ordinal
118
+ `recovered review_count + 1` only on explicit entry to `review_running`.
119
+ Standalone mode has no delivery-budget guard.
120
+
121
+ ## Fixed Vectors
122
+
123
+ These values detect serialization drift:
124
+
125
+ - Delivery goal `goal:HI-104`, bounds identity `bounds:v1:HI-104`, scope
126
+ `apps/cli/src/a.ts` plus `apps/wiki/spec.md`:
127
+ - scope hash: `5fb7f4cd0577ad89de00916c8c18b122b264e50fb61df0c79249b88aba23a306`
128
+ - bounds hash: `90dddda98e886e9b2ef511790f32d1d359847af24f5950361d25aedfe729bd8a`
129
+ - lineage: `291c26957263b22b0cd5ad8a209415ff2992cc9a645f0018ed46ac4ba48de33b`
130
+ - With locator `repo:wearedevpunks/harness-intelligence`, base `origin/main`,
131
+ fixed point `1111111111111111111111111111111111111111`, head
132
+ `2222222222222222222222222222222222222222`, patch hash of 64 `a`
133
+ characters, and ordinal 2:
134
+ - snapshot: `f116049b650180523f8dd9ee48b900394f090a425ca8a1d7f369c56ca9d5998b`
135
+ - run id: `9b164c914a883778fd5d4a3e242aaa2d261a44ce7601df10d1530bd9dd777e32`
136
+ - slug: `review-291c26957263b22b0cd5`
137
+ - report suffix identity: `20260811T120000Z-f116049b6501`
138
+ - Standalone locator `artifact:spec-v1`, bounds identity
139
+ `bounds:v1:artifact`, files `docs/b.md` containing `beta\n` and `docs/a.md`
140
+ containing `alpha\n`:
141
+ - bundle hash: `107ee7c127b10e1826bf2d2899a36cc21291392ee6702af8d9e39b3e13553cb7`
142
+ - bounds hash: `8dfde7eafe7f68b6ee5f763d23d01310f414fd5b7fca6393d5e92e90d963aa7f`
143
+ - lineage: `ba4a5082445cac8ab133b533cfb090f936d69915266728bc9c6bd4b5b786f95a`
144
+ - snapshot: `d4c43491a0aef9aaeb604dc224792222d0fb6c85caec76d03ff763896563a58a`
145
+ - run id: `f165ab99100afe180bea68b41eb730fd2b61b2122347be0e50c91549140629d4`
146
+ - slug: `review-ba4a5082445cac8ab133`
147
+
148
+ ## Resume And Freshness
149
+
150
+ Delivery recovery keys on lineage and unique valid retained passes. Reconcile
151
+ the handoff projection from their highest ordinal. Separately recompute target,
152
+ accepted-bounds, and governing source hashes and select the highest fresh pass.
153
+
154
+ Standalone resume matches lineage, bounds, normalized target, and inclusive
155
+ scope; recomputes freshness; and selects the most recent unique valid report by
156
+ `reviewed_at`. It changes no delivery counter.