# Review  -  Valven delivery-rule gate (Step 2c)

> Loaded by `review/SKILL.md` Step 2c. The SKILL keeps the not-measured rule and the NEEDS WORK rule; this file carries the Step 6 summary lines, the per-input gate arguments, the checkout-vs-diff-file choice, and the handling of every rule family. Rule definitions: `$HOME/.claude/multi-agent-refs/features/valven.md`.

```bash
VG_FILE="/tmp/multi-agent-review-${TASK_ID}-valven.json"
VG_ARGS=(--mode review --out "$VG_FILE")
case "$kind/$provider" in
  branch/local)
    VG_ARGS+=(--repo . --base origin/develop --head "$ref") ;;
  pr/github)
    node "$HOME/.claude/scripts/pr-timeline.mjs" --repo "$org_repo" --pr "$pr_number" \
      --out "/tmp/multi-agent-review-${TASK_ID}-pr.json"   # gh pr view + ready time + bot-typed reviews
    jq -r '.body // ""' "/tmp/multi-agent-review-${TASK_ID}-pr.json" > "/tmp/multi-agent-review-${TASK_ID}-body.md"
    jq -r '.commits[] | "\(.authoredDate)\t\(.messageHeadline)"' "/tmp/multi-agent-review-${TASK_ID}-pr.json" > "/tmp/multi-agent-review-${TASK_ID}-commits.txt"
    VG_ARGS+=(--branch "$(jq -r .headRefName "/tmp/multi-agent-review-${TASK_ID}-pr.json")"
              --pr-body-file "/tmp/multi-agent-review-${TASK_ID}-body.md"
              --commits-file "/tmp/multi-agent-review-${TASK_ID}-commits.txt"
              --pr-meta-file "/tmp/multi-agent-review-${TASK_ID}-pr.json") ;;
  pr/bitbucket-server)
    # Same credentials as Step 2. PR: fromRef.displayId + description; commits: values[].message.
    # Write the description to ...-body.md, one "<ISO authorTimestamp>\t<first message line>" per commit to ...-commits.txt,
    # and the timeline to ...-meta.json (features/valven.md, "Development Behaviors"). Then:
    VG_ARGS+=(--branch "$BB_FROM_REF" --pr-body-file "/tmp/multi-agent-review-${TASK_ID}-body.md"
              --commits-file "/tmp/multi-agent-review-${TASK_ID}-commits.txt"
              --pr-meta-file "/tmp/multi-agent-review-${TASK_ID}-meta.json") ;;
esac
```

For PR input: when the cwd is a checkout of the same repo, `git fetch origin "<headRef>"` (this moves no HEAD) and add `--repo . --base "origin/<baseRef>" --head FETCH_HEAD`, so sizes and the rework ratio come from history. Otherwise add `--diff-file "$DIFF_FILE"`; the rework rule then reports `not-measured`, which is stated in the summary rather than read as a pass.

```bash
node "$HOME/.claude/scripts/valven-gate.mjs" "${VG_ARGS[@]}" >/dev/null
VG_RC=$?   # 0 clean, 1 findings, 2 could not run
```

- Exit 2: print the stderr line and continue the review with `Valven: not measured (<reason>)` in the Step 6 summary. Never print it as passed.
- The gate's `findings[]` join the reviewer findings at Step 5 with `tag: valven`. They are measurements, so triage accepts them unless the task is exempt; an accepted `important` or `blocking` one makes the Step 7 decision NEEDS WORK.
- When `splitRequired` is true, run `node "$HOME/.claude/scripts/valven-split.mjs" --repo . --base "origin/<baseRef>" --head <head>` (plan only, no `--apply`) where a checkout exists, and append the slice table (branch, lines, files) to the `VLV-SIZE-01` finding's `fix`.
- When `VLV-AGE-01`, `VLV-BEHIND-01` or `VLV-TRACE-03` fires and a checkout exists, put the `valven-port.mjs` plan (same base and head, no `--apply`) in the finding's `fix` as `$HOME/.claude/multi-agent-refs/features/valven.md`, "Old work", lists it.
- The registry's judgement rules (`rules:` block: `VLV-SCOPE-02`, `VLV-PRDESC-02`) go into every reviewer prompt in Step 3, with the PR body when one exists. Each reviewer returns a verdict per ID.
- `VLV-CYCLE-01..03` are `suggestion` findings with a Valven score and never set NEEDS WORK alone; `VLV-PICKUP-01` is `important` for no reviewer, a `suggestion` for an old draft. Branch input reports them `not-measured`.

## Summary lines

Step 6 adds one line under the table: `Valven: <n> finding(s)  ·  <changedLines> lines / <fileCount> files  ·  split: <yes N slices|no>`, plus for a PR `Valven scores: churn · coding · pickup · review` from the report's `scores` (`-` where one is missing).
