Validate pr

From ianjamesburke/PLEXI · View interactive version

Validate pr is an AI agent skill from the GitHub repository ianjamesburke/PLEXI. Phase 3 of the PLEXI ship pipeline. Installs a PR build, generates test instructions, handles user pass/fail/modify responses, and manages the retry loop (max 3 soft rejects before escalating to hard reject). Input: PR number. Output: approved PR number or hard-reject.

How to use this skill

Skill file

Validate PR

Phase 3 of the ship pipeline. Manages the test loop and all rejection paths.

Entry:

Outcomes:

Reads ## Ship Log in the issue body to determine current attempt count. Never trust an argument alone — always verify against the log.

Testing notification routing: If the env var PM_PANE_ID is set (injected by PM when it dispatches this skill), route the --choice "Talk to Claude" action to that pane so the user replies in the PM pane. Otherwise default to $PLEXI_PANE_ID.

Labels are live state — never the Ship Log. Pane: plexi${PLEXI_CHANNEL:+-$PLEXI_CHANNEL} pane name "#<n> · <state>" — no digit in status (PM census uses grep -oE '[0-9]+'). States: validate, needs-you, fixing, blocked. Source .agents/skills/_lib/pipeline-slots.sh; call pipeline_slots_set validate "$ISSUE_NUMBER" "$PR_NUMBER" <status> <summary> <error> at every status change.


Step 0 — Read Context

gh pr view <pr-number> --json title,headRefName,number,baseRefName,state

Extract:

Stint-first mode means the PR is backed by one or more .stint/ tasks rather than a GitHub issue. A feature/stint-<id>[-<id>...]-<slug> branch identifies the stint ids; it does not identify a GitHub issue: .stint/ is authoritative and issues are optional. Do not read a digit run out of that branch as an issue number — 0469 is a stint id, and gh issue view 469 returns an unrelated issue. In this mode, for the whole skill:

Read current attempt count from the Ship Log (issue body, or PR body in stint-first mode). Count **Validate attempt entries; ATTEMPT_COUNT = that number (0 if no log yet).

# issue-first
ATTEMPT_COUNT=$(gh issue view $ISSUE_NUMBER --json body --jq '.body' \
  | grep -cE '^\*\*Validate attempt [0-9]+:' || true)
# stint-first
ATTEMPT_COUNT=$(gh pr view $PR_NUMBER --json body --jq '.body' \
  | grep -cE '^\*\*Validate attempt [0-9]+:' || true)

Mark issue as actively in this phase and update pane status. /open-pr already set pipeline:validate when it chained in here, so this is a no-op on the inline path — it exists so a standalone /validate-pr <PR> on an issue still sitting at pipeline:open-pr lands in the right phase. Do not add in progress: /open-pr deliberately removes it in favor of ready, and re-adding it here just thrashes the label back and forth.

gh issue edit $ISSUE_NUMBER \
  --remove-label "pipeline:open-pr" \
  --add-label "pipeline:validate" 2>/dev/null || true
plexi${PLEXI_CHANNEL:+-$PLEXI_CHANNEL} pane name "#<n> · validate"
pipeline_slots_set validate "$ISSUE_NUMBER" "$PR_NUMBER" working "" ""

Step 0b — Resume Guard After User Reply

Run this before handling any pass, fail, or modify reply, especially after context compaction. A reply to a [TESTING] block is part of PR validation by default; do not treat it as a fresh alpha bug report unless the user explicitly says to leave the PR flow.

Rehydrate the PR and force all subsequent reads, edits, tests, commits, pushes, and PR installs into the feature worktree:

if [ -z "${PR_NUMBER:-}" ]; then
  VALIDATION_STATE="/tmp/plexi-validate-${PLEXI_PANE_ID:-unknown}.env"
  test -f "$VALIDATION_STATE" || { echo "Missing PR_NUMBER and validation state: $VALIDATION_STATE"; exit 1; }
  . "$VALIDATION_STATE"
fi
PR_JSON=$(gh pr view $PR_NUMBER --json headRefName,baseRefName,state,isDraft)
BRANCH=$(printf '%s' "$PR_JSON" | jq -r '.headRefName')
PR_STATE=$(printf '%s' "$PR_JSON" | jq -r '.state')
test "$PR_STATE" = "OPEN" || { echo "PR #$PR_NUMBER is not open: $PR_STATE"; exit 1; }
ALPHA_ROOT=$(git worktree list --porcelain | awk '
  /^worktree / { path=$2 }
  /^branch refs\/heads\/alpha$/ { print path; exit }
')
test -n "$ALPHA_ROOT" || { echo "Could not resolve alpha worktree"; exit 1; }
WORKTREE="$ALPHA_ROOT/worktrees/$BRANCH"
test -d "$WORKTREE" || { echo "Missing PR worktree: $WORKTREE"; exit 1; }
CURRENT_BRANCH=$(git -C "$WORKTREE" branch --show-current)
test "$CURRENT_BRANCH" = "$BRANCH" || { echo "Wrong worktree branch: $CURRENT_BRANCH != $BRANCH"; exit 1; }
case "$CURRENT_BRANCH" in alpha|beta|main) echo "Refusing to validate from protected branch: $CURRENT_BRANCH"; exit 1 ;; esac
cd "$WORKTREE"
git status --short --branch

Hard stops:

While handling validation feedback, just install is banned. Reinstall only with just bs-validate-setup $PR_NUMBER.


Step 1 — Validation Mode Gate

Read the stint's Done-When and qualification, actual PR diff, current head and

worker evidence. Classify behavior and risk using TESTING.md — The Gate, not size or file paths alone.

Consume the /testing conclusion from the issue Ship Log or PR body in

stint-first mode. A missing, stale, incomplete or contradictory evidence block is

not a skip: request the missing evidence or use the applicable installed path.

Record the exact head, selected and skipped checks with reasons, screenshot

origin and durable link when applicable. A required missing capture is a failure.

The testing skill owns non-aggregate install-skip criteria; aggregate records

always require an installed-head record. plugins/, installed runtime, packaging,

PTY, and explicit installed acceptance can require installation regardless of

size. An independent tester must verify affected behavior; the worker's tests

are evidence, not an independent verdict. Avoid rerunning unrelated suites;

perform the minimum independent checks needed for the affected behavior.

If installation is not required, independently exercise the affected behavior

at the exact source head, document the skip and evidence, then proceed to Step 3.

If an installed check is required, the assigned tester owns pr-install so the

worker and tester do not both install the same head. After any head movement,

reassess the evidence and rerun the applicable head-dependent checks.


Step 2 — Install

The installer consumes a matching candidate artifact and successful pretest

receipt under the persistent slot lock as defined by TESTING.md. A mismatch

reruns the applicable work. Keep independent affected-behavior validation and

the installed SDK guard; cache reuse is not independent acceptance.

One recipe owns the mechanics — PR/branch/worktree resolution, the install, and provenance. just pr-install resolves and builds the PR's actual head itself (cwd-independent), so there is nothing to hand-derive here:

eval "$(just bs-validate-setup $PR_NUMBER | tee /dev/stderr | grep -E '^(BRANCH|WORKTREE|HEAD)=')"
PR_VERSION=$(grep '^version' "${WORKTREE:-.}/Cargo.toml" | head -1 | sed 's/.*= "//' | tr -d '"')

The recipe fails loudly (and publishes a validate:failed slot report) when the PR is not open or the install fails — stop and report; never hand-roll the install or fall back to just install. Provenance (PR, head sha, worktree) is appended to ~/.plexi-pr-<N>/install.log.

Wait for completion. The binary is now installed ($PR_VERSION). Move immediately to Step 3.

After installing, the independent tester exercises the affected behavior on the exact installed head using /drive-host when applicable. Record provenance and observable results; only ask Ian to act for a real human gate. Never present an install or a headless image as live behavior proof.


Independent review

An independent tester verifies the Done-When and affected behavior. Do not invent

an implementation-phase AI verdict: if one exists, report it separately from

the independent result. Do not rerun a broad suite merely because it ran before;

run the focused checks needed to establish independent evidence and TESTING.md's

phase gate. The final combined candidate has its own full-suite requirement.


Step 3 — Write and Surface Testing Block

Spec gate: Re-read the Done When checklist (issue body, or the stint's ## Scope in stint-first mode) before writing. Pass criteria map 1:1 to checklist items. No extra criteria.

Fetch the brief:

# issue-first
ISSUE_TITLE=$(gh issue view $ISSUE_NUMBER --json title --jq '.title')
ISSUE_WHAT=$(gh issue view $ISSUE_NUMBER --json body --jq '.body' \
  | sed '/^---$/,/^---$/d' \
  | grep -v '^#' \
  | grep -v '^$' \
  | head -3)

# stint-first — same variables, sourced from stint
ISSUE_TITLE=$(stint show <id> | sed -n 's/^Title: *//p')
ISSUE_WHAT=$(stint show <id> \
  | sed '/^---$/,/^---$/d' \
  | grep -v '^#' \
  | grep -v '^$' \
  | head -3)

This is the one-line context shown at the top of every testing block so the reviewer knows exactly what they're evaluating. In stint-first mode the block's Issue row becomes | Stint | <id> — <ISSUE_TITLE> |.

Surface testing block format — binary install path:

[TESTING] PR #<n> — <title>

| | |
|---|---|
| PR | #<n> · attempt <attempt+1>/3 |
| Issue | #<issue-number> — <ISSUE_TITLE> |
| Install | done — v<PR_VERSION> |
| AI review | <one-line finding or "skipped — <reason>"> |
| Test evidence | <conclusion line, or "none"> |

What this ships: <ISSUE_WHAT — one line>

Pass: <concrete observable outcome(s), comma-separated or bullet if >2>
Fail: <concrete observable symptom(s)>

Reply: "pass" | "fail: <desc>" | "modify: <change>"

Surface testing block format — diff-review path:

[TESTING] PR #<n> — <title> (diff review only)

| | |
|---|---|
| PR | #<n> |
| Issue | #<issue-number> — <ISSUE_TITLE> |
| Install | skipped — <policy reason> |
| AI review | <one-line finding or "No issues found"> |
| Test evidence | <conclusion line, or "none"> |

What this ships: <ISSUE_WHAT — one line>

No binary install was run: <reason>. Independent affected-behavior checks: <commands and outcomes at head>.
AI findings: <AI_FINDINGS verbatim, or "No issues found.">

Reply: "pass" | "fail: <desc>" | "modify: <change>"

On the diff-review path, omit the Pass: / Fail: criteria entirely. The tester records the independent source-level verification and its limits. Only the install path asks the user to verify observable stop-check criteria.

AI_FINDINGS always shown verbatim when a pre-push review verdict exists; if none was recorded, say so in one line rather than leaving the row blank.

Your final response for this turn must be the testing block above. Do not replace it with a status recap. Do not keep working after it is surfaced.

After printing the testing block in the final response, send a best-effort notification. The notification is only an attention cue; the testing block is the source of truth.

Use a non-blocking choice notification so the user can focus the reply pane without leaving the agent process blocked on a response file:

# Persist enough state for a later user reply to survive context compaction.
ALPHA_ROOT=$(git worktree list --porcelain | awk '
  /^worktree / { path=$2 }
  /^branch refs\/heads\/alpha$/ { print path; exit }
')
VALIDATION_STATE="/tmp/plexi-validate-${PLEXI_PANE_ID:-unknown}.env"
{
  printf 'PR_NUMBER=%s\n' "$PR_NUMBER"
  printf 'ISSUE_NUMBER=%s\n' "$ISSUE_NUMBER"
  printf 'BRANCH=%s\n' "$BRANCH"
  printf 'WORKTREE=%s\n' "$ALPHA_ROOT/worktrees/$BRANCH"
} > "$VALIDATION_STATE"

# Flip pane status to needs-you so the PM surfaces this lane as awaiting the user
plexi${PLEXI_CHANNEL:+-$PLEXI_CHANNEL} pane name "#<n> · needs-you"
pipeline_slots_set validate "$ISSUE_NUMBER" "$PR_NUMBER" needs-you "Review the [TESTING] block, then reply pass/fail/modify." ""
# Route reply to PM pane if PM dispatched this skill, otherwise this pane
REPLY_PANE="${PM_PANE_ID:-$PLEXI_PANE_ID}"
PLEXI_SOCKET="$PLEXI_SOCKET" PLEXI_CHANNEL="$PLEXI_CHANNEL" \
  plexi${PLEXI_CHANNEL:+-$PLEXI_CHANNEL} notify --no-wait \
  --title "PR #<n> quality checks done (attempt $((ATTEMPT_COUNT+1))/3)" \
  --body "<title>. Review the [TESTING] block, then reply pass/fail/modify." \
  --choice "talk:Talk to Claude:pane_focus:$REPLY_PANE"

STOP. Wait for user reply.


Step 4 — Handle Response

Pass

Append to issue Ship Log and set pipeline state in one call:

CURRENT_BODY=$(gh issue view $ISSUE_NUMBER --json body --jq '.body')
gh issue edit $ISSUE_NUMBER \
  --body "$(printf '%s\n**Validate attempt %s:** PASS\n**Test date:** %s' "$CURRENT_BODY" "$((ATTEMPT_COUNT+1))" "$(date +%Y-%m-%d)")" \
  --add-label "pipeline:merge" \
  --add-label "ready" \
  --remove-label "pipeline:validate" \
  --remove-label "in progress"

Output:

[VALIDATED] PR #<n> — <title>
Attempt: <N>/3
Pipeline: pipeline:merge + ready set — invoking /merge-pr inline

Human-gate check before merging. If the stint/issue body contains a ## Human Gate section (or the PR carries a human-gate label), the PR needs Ian's hands before it merges — tester PASS is necessary but not sufficient:

```

Drive: <the 1-2 concrete things to do in the running build to judge it>

Judging: <what Ian is deciding>

Findings: (Ian appends here; any entry routes a fix round on this same PR, then re-validate)

```

Otherwise (no human gate — the common case): invoke /merge-pr <pr-number> inline in the same pane.

Modify

Valid only if pass criteria were not fully met. If criteria were met and user wants extras: "Pass criteria are met. Filing that as a separate issue." Create the issue, then treat as pass.

First run Step 0b — Resume Guard After User Reply. Do not inspect or edit production files until cd "$WORKTREE" has succeeded.

Fix the specific change on the feature branch, commit, push:

plexi${PLEXI_CHANNEL:+-$PLEXI_CHANNEL} pane name "#<n> · fixing"
pipeline_slots_set validate "$ISSUE_NUMBER" "$PR_NUMBER" fixing "" ""
git add <files>
git commit -m "fix: <description>"
git push

Reassess the new head and run the applicable TESTING.md gates; reinstall with just bs-validate-setup $PR_NUMBER when required. Never run just install during validation. Re-surface the testing block (which flips status back to needs-you). Do not expand scope.

Append to Ship Log:

**Validate attempt <N>:** MODIFY — <description of change>

Soft Reject (fail with description)

"fail" without a description: ask for it before taking any action.

Check attempt count — same marker as Step 0. ### Attempt counts implementation attempts (written by /implement-issue and /implement-stint-v2), not validation rounds; counting those here made the 3-strikes gate fire off a different number than Step 0 computed:

ATTEMPT_COUNT=$(gh issue view $ISSUE_NUMBER --json body --jq '.body' \
  | grep -cE '^\*\*Validate attempt [0-9]+:' || true)

If ATTEMPT_COUNT < 3 (soft reject — push a fix):

Read the PR build log first:

tail -100 ~/.plexi-pr-$PR_NUMBER/plexi.log

Report what the log shows. If the log alone can't reproduce the failure and you need to drive the live binary to confirm the fix, use the drive-host skill (boot → drive → observe → teardown) — do not hand-roll a launch.

First run Step 0b — Resume Guard After User Reply. Do not inspect or edit production files until cd "$WORKTREE" has succeeded.

Apply the targeted fix to the feature branch, commit, push:

plexi${PLEXI_CHANNEL:+-$PLEXI_CHANNEL} pane name "#<n> · fixing"
pipeline_slots_set validate "$ISSUE_NUMBER" "$PR_NUMBER" fixing "" "<failure description>"
git add <files>
git commit -m "fix: <description from failure>"
git push

Reassess the new head and run the applicable TESTING.md gates; reinstall with just bs-validate-setup $PR_NUMBER when required. Never run just install during validation.

Append to Ship Log:

**Validate attempt <N>:** FAIL — <verbatim user description>
**Fix applied:** <what was pushed> (commit <hash>)

Re-surface the testing block (attempt N+1/3) in your response first, then fire the notification again. STOP.

If ATTEMPT_COUNT >= 3 (escalate to hard reject):

Send notification:

RESULT=$(plexi notify \
  --title "PR #<n> failed 3 times — hard reject?" \
  --body "<title>. 3 attempts exhausted. Close and rewrite issue?" \
  --choice "a:Talk to Claude:pane_focus:$PLEXI_PANE_ID" \
  --choice "b:Hard reject — close PR" \
  --choice "c:Keep open — I'll review")

If b or user confirms in chat → proceed to Hard Reject.

If c → STOP. Leave PR open. Remove attempt limit — user owns it from here.


Hard Reject

  1. Mark the lane blocked and read the PR log:
plexi${PLEXI_CHANNEL:+-$PLEXI_CHANNEL} pane name "#<n> · blocked"
pipeline_slots_set validate "$ISSUE_NUMBER" "$PR_NUMBER" blocked "" "hard reject after failed validation"
tail -100 ~/.plexi-pr-$PR_NUMBER/plexi.log
  1. Close the PR:
gh pr close $PR_NUMBER --comment "Closing after 3 failed validate attempts. Full context in issue #$ISSUE_NUMBER body."
  1. Rewrite the issue body:

Fetch the current body and all Ship Log entries. Rewrite the body to include:

```markdown

## Prior Attempts

Attempt N: What was tried (branch, files changed, approach).

Why it failed: Root cause or observable symptom (from validate log and user description).

What to try next: Specific next investigation step.

```

One block per attempt, using the Ship Log entries as source.

```markdown

Hard reject: <YYYY-MM-DD> — PR #<pr-number> closed after <N> attempts.

```

gh issue edit $ISSUE_NUMBER --body "<rewritten body>"
  1. Re-label (remove all pipeline labels, reset to ready):
gh issue edit $ISSUE_NUMBER \
  --remove-label "in progress" \
  --remove-label "pipeline:implement" \
  --remove-label "pipeline:open-pr" \
  --remove-label "pipeline:validate" \
  --remove-label "pipeline:merge" \
  --add-label "ready"
  1. Clean up:
just channel-clean pr-$PR_NUMBER
wtp remove feature/<branch> --force
git push origin --delete feature/<branch>
  1. Output:
[HARD REJECT] PR #<n> closed
Issue #<issue-number> rewritten with Prior Attempts section
Branch feature/<branch> deleted
Issue re-labeled ready for next attempt

Diff-Review Testing Block

Surface the diff-review testing block format from Step 3. Key differences from the install path:

Flip pane status the same as the install path before notifying:

plexi${PLEXI_CHANNEL:+-$PLEXI_CHANNEL} pane name "#<n> · needs-you"
pipeline_slots_set validate "$ISSUE_NUMBER" "$PR_NUMBER" needs-you "Review the diff-review [TESTING] block, then reply pass/fail/modify." ""

Rules

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.