mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-25 17:41:35 +01:00
When /ship stops at a pull request's review round cap, a grant naming that stop now buys one scoped review of the fix, in the same run or the next, instead of another read-only full review. Before, a grant recorded after the read-only review, or between /ship runs, bought nothing, so teams paid for extra full reviews or second grants (ghome#40: $8.78 against about $3). Nothing to do: /ship prints the grant command when it stops. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=security Review-Finding: p1/specialist-batched#2 reader=state-machines Review-Finding: p1/specialist-batched#3 reader=testing Review-Finding: p1/red-team#1 reader=red-team Review-Finding: p1/red-team#2 reader=red-team Review-Finding: p1/red-team#3 reader=red-team
286 lines
20 KiB
Cheetah
286 lines
20 KiB
Cheetah
## Step 9: Pre-Landing Review
|
||
|
||
Set CYCLES to 0 on first entry only, with PASS set to 1,
|
||
`REVIEW_SINCE=$(date -u +%Y-%m-%dT%H:%M:%SZ)` saved and the `ship: review_scope`
|
||
policy line (Step 3) kept. Every entry saves `PASS_HEAD=$(git rev-parse HEAD)`; from pass 2 on,
|
||
`RANGE_BASE` is the previous pass's PASS_HEAD. Every entry also runs
|
||
`mkdir -p .gstack/tmp && rm -f .gstack/tmp/targeted.json && _EX=$(git rev-parse --git-path info/exclude) && mkdir -p "$(dirname "$_EX")" && { grep -qxF '/.gstack/tmp/' "$_EX" 2>/dev/null || printf '\n/.gstack/tmp/\n' >> "$_EX"; }`
|
||
(a pass without the targeted reader leaves no record, and the record never reads as an uncommitted edit). Keep existing approvals; changed
|
||
finding scope needs a new decision. Order: checklist/design, specialists (9.1),
|
||
Red Team (9.2), QA (9.2.1), dedup (9.3), scope, fixes and logging (9.4).
|
||
Gated/unsupported specialists skip only their dispatch, never QA or Step 11.
|
||
Steps 10–11 queue findings without editing; include those findings in this pass.
|
||
Every repeat starts before the checklist read and captures a fresh REVIEW_START.
|
||
Finish the complete review and QA before applying any fix in Step 9.4.
|
||
|
||
**Review plan.** Pass 1 runs `~/.claude/skills/gstack/bin/gstack-review-plan
|
||
--base <base>`, plus `--depth-floor <d>` on every plan run when the /ship prompt
|
||
gave `--depth-floor <d>` (it only raises), and Step 1's `PR_REVIEW_FLAGS:` on every plan run (the PR's
|
||
earlier rounds and a round grant; past two the plan is one read-only full review, and `PR_ROUND_CAP` stops for the lane, never the owner).
|
||
When they name `--round-grant <id>`, run `gstack-ship-receipt claim --pr <n> --run <SESSION_ID> --grant <id>` before the first
|
||
dispatch (`GRANT_SPENT` stops the run). With `--stop <head>` too, the grant buys that stop's fix round: Step 9 is only decision
|
||
3.5's fix-check of the PR's own change since `<head>`, for the grant's findings, Step 11.5 saves `<head>`'s tree, and the receipt's
|
||
`review_loop_exception` names the grant. Add `--declare-risk <classes>` when the diff touches a risk
|
||
class the plan's `REVIEW_DEPTH:` misses (spend it reserves or binds: `money`), and give Step 16's
|
||
receipt write the same flag; a repeat uses the plan run that picked it.
|
||
A `scoped` repeat is a full pass on the range: its `fix-check` is decision 3.5's
|
||
reviewer and prompt with `git diff $RANGE_BASE` as the hunks, inside this pass.
|
||
Save its `REVIEW_PLAN:` line and fingerprint, `REVIEW_DEPTH:` (depth,
|
||
`runtime_lines`, `rules`) and `GATE_SCAN:`. Dispatch exactly its `DISPATCH:` lines
|
||
(specialists, Red Team, Step 11's voices), each at its `effort=` on the same model
|
||
family (`full` is the lane's reasoning, `medium` reasoning medium, `light` low; a
|
||
host that cannot set it runs its default) and reading its `DIFF_CMD:`, in place of 9.1's and 9.2's own selection rules;
|
||
`specialist batched` is one subagent reading every checklist its
|
||
`checklists=` names (light adds Red Team), tagging each finding with its checklist.
|
||
`NEXT: platform` runs no reader: log item 6's row with `"depth":"platform"` and the
|
||
`PLATFORM_REVIEW:` id (Step 16's receipt write takes `--platform-review <id>`; Step 11.5 selects no Step 11
|
||
record), then go to Step 10.
|
||
A `SKIP:` reviewer logs `{"dispatched":false,"reason":"scope"}`. Audits run at
|
||
`AUDIT_EFFORT:`. The core checklist, gate scan and QA always run. Item 6's row adds
|
||
`"dispatches":[{"role":R,"prompt_bytes":N,"diff_bytes":N}]`, `"depth"`,
|
||
`"runtime_lines"`, `"depth_rules"` (the `rules` hash) and
|
||
`"gate_scan":{"tagged":N|null,"head":"<sha>"}` from those lines.
|
||
|
||
**Pass 2+ reads the range, not the tree** (`review_scope frozen`): the core read
|
||
in item 2 becomes `git diff $RANGE_BASE`, and every dispatched prompt (specialists,
|
||
Red Team, the Step 11 reviewers) carries a literal sha you write in:
|
||
`DIFF_BASE=<diff-base>`, the merge base on pass 1 and `RANGE_BASE` from pass 2 on.
|
||
A reviewer never sees your shell's `RANGE_BASE`; a variable left in a prompt
|
||
re-reads the whole branch. An outside backend receives the range `RANGE_BASE..HEAD`.
|
||
Under `review_scope all` every pass reads the full diff. The gate scan (2.5) and
|
||
the QA probes keep the whole candidate:
|
||
they are tools, not reviewers. `NO FINDINGS` is the expected result for a clean range.
|
||
|
||
{{CONFIDENCE_CALIBRATION}}
|
||
|
||
### Core checklist
|
||
|
||
This pass is static; defer product probes to Step 9.2.1.
|
||
|
||
1. Read `~/.claude/skills/gstack/review/checklist.md`. If the file cannot be read, **STOP** and report the error.
|
||
|
||
2. Before reading the diff, run `~/.claude/skills/gstack/bin/gstack-review-log --start review` and save its token as REVIEW_START (under a token cap, first reserve this pass's dispatch batch with `gstack-ship-budget check` and add `--reservation <id>`). Then run `git diff origin/<base>` (`git diff $RANGE_BASE` from pass 2 on). Read non-ignored untracked source files too (`git ls-files --others --exclude-standard`); the snapshot includes them.
|
||
|
||
Every pass captures a full token (no `--fix-range`), so the record binds the
|
||
whole tree even when reviewers read only the range.
|
||
|
||
2.5. **Gate scan.** Before applying the checklist, run the gate scan on the same candidate:
|
||
|
||
{{GATE_SCAN_BLOCK}}
|
||
|
||
Save the `GATE_SUMMARY:` line and the read-level listing for the checklist's Gate
|
||
Integrity category, Step 9.4's record, Step 16 stage 5 and the PR body. Carry any
|
||
gate hunks Step 7's rescan already flagged into the same category.
|
||
|
||
3. Apply the review checklist in two passes:
|
||
- **Pass 1 (CRITICAL):** the checklist's Pass 1 categories, including Gate Integrity
|
||
over item 2.5's listing (three levels; only findings reach a question)
|
||
- **Pass 2 (INFORMATIONAL):** All remaining categories
|
||
|
||
### Design-lite checklist
|
||
|
||
Its numbering is local. `/ship` attempts this design check automatically when frontend
|
||
review applies; `enabled` is that choice, not a user question. Step 11 has its own
|
||
outside-review switch and required native pass.
|
||
|
||
{{DESIGN_REVIEW_LITE}}
|
||
|
||
Design-lite (parent) and the Design specialist are independent reads. Before counting
|
||
and Fix-First, merge one evidenced design defect at the same path/line into one item
|
||
with both sources and the stricter ASK. Keep actual specialist stats and distinct defects.
|
||
|
||
{{REVIEW_ARMY}}
|
||
|
||
{{QA_REVIEW}}
|
||
|
||
{{CROSS_REVIEW_DEDUP}}
|
||
|
||
## Step 9.4: Fix-First and persistence
|
||
|
||
Before edits, inspect every dispatched reader/writer's handle. Wait for return
|
||
or confirm termination; otherwise log incomplete through items 5–6 and STOP
|
||
without edits. After terminal failure, independent evidence may support fixes,
|
||
but missing dispatched output still blocks continuation, even with a QA exception.
|
||
|
||
0. **Scope the findings.** Write the unmatched or reopened findings from Step 9.3
|
||
(all sources, queued Steps 10–11 included) as a JSON array to
|
||
`.gstack/tmp/review-findings-p$PASS.json` with your file-write tool, each with
|
||
`raised_by` (`core`, `qa`, a specialist, `red-team`, `adversarial-native`,
|
||
`outside-voice` or `fix-check`) and, for a dispatched reader's finding, `ledger_id`
|
||
(`<pass dir>/<its merged.jsonl id>`, e.g. `p2/adversarial-native#3`), then:
|
||
`~/.claude/skills/gstack/bin/gstack-review-scope classify --base <base> --pass $PASS --range-base $RANGE_BASE --findings .gstack/tmp/review-findings-p$PASS.json --json > .gstack/tmp/review-classified-p$PASS.json`
|
||
(omit `--range-base` on pass 1). Every Step 9.4 scratch file lives under
|
||
`.gstack/tmp/` (gitignored): `<classified>` below is this pass's classified
|
||
file and `<deferred.json>` is `.gstack/tmp/review-deferred.json`. Each finding comes back with `locus` (`diff`,
|
||
`fix-range`, `outside`), `kind`, `blocking` (a CRITICAL defect: a test that would
|
||
fail, a production break, a security or data-loss defect) and `scope`: `fix`,
|
||
`defer` or `note`. Under `frozen`, pass 1 fixes the diff and defers blocking
|
||
findings in code the PR did not change; later passes fix only blocking findings
|
||
in the range or the diff. Below the floor is never fixed after pass 1 and never
|
||
triggers a pass. Under `diff-plus-blocking` a blocking finding in unchanged
|
||
code is `fix`, never `defer`; under `all` everything is `fix`. Save the `REVIEW_SCOPE:` line.
|
||
A `REVIEW_SCOPE_INPUT` or `REVIEW_SCOPE_RANGE` refusal is a STOP until repaired.
|
||
Three words cover every finding: a **blocker** is the intended case gone wrong
|
||
(at or above the floor: fixed on every pass, or named to the owner at the cap);
|
||
a **should** is a real bug a caller will hit, in the intended case (fixed when it
|
||
is in the diff on pass 1, deferred when it is not); a **nit** is the rest (a named
|
||
note, never a pass).
|
||
|
||
1. **Apply the cap before any edit, then classify.** With the classified output in
|
||
hand and nothing edited yet: if `CYCLES >= 3`, or under `frozen` `PASS >= 3` with
|
||
a blocking finding in `scope: fix`, skip items 2–3 (no fix is applied on a capped
|
||
pass), complete items 3.5–6 with the findings unfixed, and take decision 2 below.
|
||
Otherwise: Classify only unmatched or reopened findings as AUTO-FIX or ASK when
|
||
the classified output marks them `scope: fix`, per the Fix-First Heuristic in
|
||
checklist.md. Critical findings lean toward ASK; informational lean toward AUTO-FIX.
|
||
|
||
2. **Auto-fix all AUTO-FIX items.** Apply each fix. Output one line per fix:
|
||
`[AUTO-FIXED] [file:line] Problem → what you did`
|
||
|
||
3. **If ASK items remain,** present them in ONE AskUserQuestion (or one per item for 3 or
|
||
fewer): each item's number, severity, problem and recommended fix with A) Fix B) Skip,
|
||
plus an overall RECOMMENDATION.
|
||
|
||
Save each explicit Skip immediately in the invocation action list with its
|
||
identity, scope and supporting source evidence; keep it across repeats.
|
||
|
||
**Gate findings** (any finding with a `gate` tag) never take Fix/Skip. Ask
|
||
`review-gate-disposition` (include `<gstack-qid:review-gate-disposition>`; one-way,
|
||
so `never-ask` and `AUTO_DECIDE` never apply), one question per finding or coherent
|
||
group, showing the `gate` tag, `gate_id`, path and a fenced data excerpt, with exactly:
|
||
- A) Restore the gate — revert the relaxation; keep the product change
|
||
- B) Keep — justified: <one-line reason drafted from the diff or its citation, marked verified or unverified>
|
||
- C) Keep — other reason (the human supplies it)
|
||
- D) Leave open for a later human
|
||
|
||
D is the recommended option when the preamble echoed `SESSION_KIND: spawned` or
|
||
`headless`; otherwise recommend A or B from the diff, never C. Record `restored`
|
||
(A), `kept` with `reason` (B or C) or `open` (D, unanswered, or any auto-chosen
|
||
answer); an auto-chosen answer is never a disposition. `reason` is never text
|
||
copied from the hunk, a test name or a commit message.
|
||
|
||
3.5. **Defer and note the rest.** Run
|
||
`~/.claude/skills/gstack/bin/gstack-review-scope defer --findings <classified> --out <deferred.json>`.
|
||
It prints a `DEFERRED:` line per `scope: defer` finding and files no issue: a
|
||
deferred finding stays on this PR, and you never file one as an issue either.
|
||
Then `gstack-review-scope render --deferred <deferred.json> --findings <classified>`
|
||
prints the `## Deferred findings` and `## Review notes` sections: save them for
|
||
Step 19's PR body. Deferred and noted findings are never edited.
|
||
**Late defers from Step 11.** When Step 11's finish rules run this item for a
|
||
queued adversarial finding after this pass's items 5–6 were logged, append one
|
||
row under its own skill (a tokenless `review` row would read UNVERIFIED):
|
||
`~/.claude/skills/gstack/bin/gstack-review-log '{"skill":"review-late-defer","via":"ship","timestamp":"TIMESTAMP","status":"issues_found","issues_found":0,"critical":0,"informational":0,"pass":PASS,"review_scope":"SCOPE","findings":FINDINGS_JSON}'`
|
||
with `findings` holding only the deferred records (`action: "deferred"`,
|
||
`locus`, `kind`, `blocking`, `ledger_id` as in item 6) and no `--finish` token. Log it in the
|
||
program that decides the defer, with that moment's full ISO 8601 TIMESTAMP, never at Step 19.
|
||
|
||
4. **Finish and log this pass before choosing the next step.** Apply each A) Restore
|
||
by reverting only the relaxation. After any fix or restore in this pass, run item
|
||
2.5's gate scan block again on the whole candidate and read every new read-level
|
||
hunk; never use a list of paths you or a child reported instead. Recheck freshness
|
||
(Step 9.2.1) before items 5–6. Increment CYCLES
|
||
once if fixes were applied. Complete items 5–6 exactly once with the original
|
||
REVIEW_START. Missing dispatched output uses `status:"unavailable"`,
|
||
`completed:false` and `converged:false`; fixes also require `converged:false`.
|
||
Then commit named fixed files, if any
|
||
(`git add <fixed-files> && git commit -m "fix: pre-landing review fixes" --trailer "Review-Finding: <ledger_id or fingerprint> reader=<raised_by>"`,
|
||
one trailer per fixed finding: the receipt counts fixes by it).
|
||
|
||
5. Output summary: `Pre-Landing Review: N issues — M auto-fixed, K asked (J fixed, L skipped), D deferred, O noted`
|
||
|
||
If coverage is incomplete: `Pre-Landing Review: INCOMPLETE — <missing reviewers>`.
|
||
Otherwise, if no issues found: `Pre-Landing Review: No issues found.`
|
||
|
||
Then one `Gate edits:` line from the latest `GATE_SUMMARY:` and the gate answers:
|
||
`Gate edits: none detected (N listed, M read; patterns: <coverage>; unlisted idioms: <languages_unlisted>)`,
|
||
`Gate edits: N listed, M read, K findings — J kept (reasons below), R restored, O open`,
|
||
`Gate edits: partial (K of M eligible read)` plus the counts for the read hunks, or
|
||
`Gate edits: UNAVAILABLE — <GATE_ERROR line or helper exit>` (missing coverage,
|
||
never `none detected`). List each kept finding's `gate`, path and `reason` under it.
|
||
|
||
6. Persist the review result to the review log:
|
||
```bash
|
||
~/.claude/skills/gstack/bin/gstack-review-log '{"skill":"review","timestamp":"TIMESTAMP","status":"STATUS","issues_found":N,"critical":N,"informational":N,"quality_score":SCORE,"specialists":SPECIALISTS_JSON,"findings":FINDINGS_JSON,"commit":"'"$(git rev-parse --short HEAD)"'","via":"ship","completed":COMPLETED,"converged":CONVERGED,"cycles":CYCLES,"pass":PASS,"review_scope":"SCOPE","range_base":RANGE_BASE_OR_NULL}' --finish REVIEW_START
|
||
```
|
||
- `TIMESTAMP`: ISO 8601. `STATUS`: `unavailable` for missing dispatched reviewer output,
|
||
else `clean` only for completed coverage with no unresolved non-advisory defects,
|
||
else `issues_found`. N counts unresolved defects now, not original totals; missing
|
||
coverage, deferred and noted findings are not defects. `SCOPE` is the policy
|
||
(`frozen`, `diff-plus-blocking` or `all`); `RANGE_BASE_OR_NULL` is `"<sha>"` from pass 2, else `null`.
|
||
- A `scoped` pass adds `"scope":"scoped"`; it is a full-pass row and counts toward the cap.
|
||
- `REVIEW_START`: this pass's Step 9 token captured before reading the diff;
|
||
never recapture at persistence to certify unreviewed fixes.
|
||
- `COMPLETED`: checklist and dispatched specialists/Red Team finish, and all required probes pass.
|
||
Failed, blocked, inconclusive or not-run required probes mean false, never clean.
|
||
Record accepted untested risk separately, not as passing verification.
|
||
Undispatched host-unsupported/gated specialists do not block; retain their labels.
|
||
- `CONVERGED`: completed with zero fixes. `CYCLES`: fix cycles performed, initially 0.
|
||
- `quality_score`: Step 9.2's score, or `10.0` when specialists were skipped/unsupported.
|
||
- `specialists`: `{}` for a small-diff skip; otherwise every considered specialist's Step 9.2 stats:
|
||
`{"dispatched":true,"findings":N,"critical":N,"informational":N}` or
|
||
`{"dispatched":false,"reason":"scope|gated"}`.
|
||
- `findings`: checklist, specialist, exploratory QA and queued Steps 10–11 records with
|
||
`{"fingerprint":"path:line:category","severity":"CRITICAL|INFORMATIONAL","action":"ACTION"}`.
|
||
ACTION: `"auto-fixed"`, `"fixed"` (approved), `"skipped"` (explicit Skip),
|
||
`"deferred"` or `"noted"`. Copy
|
||
`locus`, `kind`, `blocking`, `raised_by` and `ledger_id` from the classified output onto every finding.
|
||
Merge revalidated invocation decisions by identity and advisory/defect kind;
|
||
preserve `advisory`, `evidence_paths` and `helper_target`.
|
||
Gate findings add `gate` (RH tag), `gate_id` (the tool's hunk identity), `reason`
|
||
(for `kept`) and ACTION `"kept"`, `"restored"` or `"open"`; never store hunk text.
|
||
`open` counts in `issues_found` and by severity. The logger stamps `actor` from
|
||
`gstack-session-kind` (a supplied `actor` is discarded) and forces `"open"` on
|
||
gate findings in a non-interactive session.
|
||
Save the review output and `Gate edits:` line for Step 19's PR body; an `open` gate
|
||
finding makes that PR a draft.
|
||
|
||
### Decide whether to repeat Step 9
|
||
|
||
After persistence, record missing output, CYCLES and fixes in the invocation record. With a PR open, run
|
||
`gstack-review-scope summary --since "$REVIEW_SINCE" --no-ledger --out .gstack/tmp/review-loop.json && gstack-ship-receipt stub --pr <n> --run <SESSION_ID> --review-loop @.gstack/tmp/review-loop.json`
|
||
so a run that stops still counts its rounds (Step 19's write, same `--run`, replaces it). On `NEXT: stop` with a PR open, also
|
||
run `gstack-ship-receipt stop --pr <n> --run <SESSION_ID> --since "$REVIEW_SINCE"` and report its `NEXT:` line with the stop.
|
||
Decision 1 always applies first. Then, under `frozen`, run `gstack-review-plan --base <base> --pass $PASS --last full`
|
||
with each flag that holds (`--fixed-blocking`, `--fixed-below`, `--blocking-open`,
|
||
`--touched-gate` for a fix to an item 2.5 path, `--critical-found` when this pass
|
||
logged a CRITICAL, `--adversarial-ran` once Step 11's native pass ran, `--reviewed-numbers <fp>`,
|
||
`--depth-floor <d>` when given, `--fix-checks <n>` after a fix-check, `--grant <approval id>` once the owner's grant of one scoped fix-check is
|
||
in `gstack-approvals` naming `review_loop_grant` and the stop head), `--range-base $PASS_HEAD` and `--pass1-depth <pass 1's REVIEW_DEPTH>`;
|
||
its `NEXT:` alone picks the next decision: `stop` 2, `full` 3, `fix-check` 3.5, `done` 4, `platform` 4. `voices` 4: Step 11 runs before the stop.
|
||
`scoped` is 3 too. A full pass 1 always gets a full pass 2.
|
||
Other scopes apply decisions 2–4 in order.
|
||
|
||
1. **Dispatched reviewer output missing:** STOP and name each failed specialist or
|
||
Red Team. Retain queued fixes and restore coverage. If this pass made edits,
|
||
resume at the next decision; otherwise run a fresh complete Step 9. A successful
|
||
peer or a QA exception cannot replace missing dispatched coverage.
|
||
2. **Third fixing cycle reached (`CYCLES >= 3`):** STOP and report recurring findings with
|
||
`converged:false`; do not run a fourth fixing cycle. Name each blocking finding (path,
|
||
severity, problem) for the owner, unfixed. The cap is a stop, not an approval. A capped
|
||
pass whose remaining findings are all deferred or noted applied no edits: decision 4.
|
||
3. **Fixes applied below the cap:** Insert Step 5, affected Steps 6–8 and all of
|
||
Step 9 before the pending Step 10 in the work list. If the fixes grew the diff
|
||
past what the request needs (a helper, a guard, a case nothing takes), cut that
|
||
growth before anything else; the repeat reviews the cut as part of the range. Tests must pass or retain approval for the same verified pre-existing
|
||
failures and scope. Keep CYCLES and scoped approvals across this repeat; PASS increments on entry.
|
||
3.5. **One fix-check.** Take a `gstack-review-log --start review-fix-check` token (`--reservation <id>` under a cap); write the
|
||
fix list, touched hunks (`git diff $PASS_HEAD`), callers of changed symbols and
|
||
test results to `.gstack/tmp/fix-check-*.txt`; dispatch one full-effort reviewer
|
||
on `gstack-review-plan --fix-check-prompt --fix-list <f> --hunks <f> --tests <f>
|
||
--callers <f>`, plus the outside voice only if the plan lists it. Log item 6's
|
||
row as `"skill":"review-fix-check"` with `--finish <token>`; not a pass. A
|
||
CRITICAL goes to decision 2; otherwise decision 4.
|
||
4. **No edits in this pass:** Resolve the required-probe gate below. Only after it
|
||
clears may you continue to Step 10. A pass whose only findings were deferred or
|
||
noted applied no edits and continues here: the loop converges below the floor.
|
||
|
||
**Required-probe parent gate:** With completed checklist and dispatched reviewers,
|
||
failed/unavailable required probes block continuation.
|
||
Use AskUserQuestion: stop for repair (recommended), or explicitly accept each
|
||
named probe's concrete risk. Skipping a fix is not risk acceptance or a passing
|
||
probe. Keep actual outcomes and incomplete flags; VERIFY_RESULT stays fail for
|
||
plan-check exceptions. This cannot waive missing reviewer output, recurring fixes
|
||
or independent test/security gates.
|
||
|
||
---
|