Skip to content

skill contract: Bash writes to repo files count as edits for check_after_last_edit (GST-1633) - #4078

Merged
capy-ai[bot] merged 2 commits into
mainfrom
capy/gst-1633-bash-writes
Nov 6, 2026
Merged

capy-ai[bot] merged 2 commits into
mainfrom
capy/gst-1633-bash-writes

Conversation

@garrytan

@garrytan garrytan commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner
{
  "schema_version": 1,
  "pr": 4078,
  "head": "f6e6b507b989f80e211a3c98f342f278f5ef4a7b",
  "version": "1.96.0.0",
  "base": "main",
  "gate": {
    "targeted": {
      "pass": 52,
      "fail": 0,
      "skip": 0
    },
    "free": {
      "pass": 1610,
      "fail": 0,
      "skip": 0
    }
  },
  "ci_carried": [
    {
      "lane": "free",
      "run": 42242441792,
      "attempt": 1,
      "tree": "5fbd032127ed007a8168e88f8753ecb793dd4a22"
    }
  ],
  "session_kind": "unattended",
  "head_tree": "5fbd032127ed007a8168e88f8753ecb793dd4a22",
  "product_patch_id": "d738e3c2ec43ba475162b25e1c99a2ab073e031a",
  "gstack_version": "1.96.0.0",
  "review_depth": {
    "depth": "full",
    "class": "code",
    "runtime_lines": 373,
    "rules": "70895942bb8a8ee2",
    "base": "274fb34537edc2d90e021a27d91a0a7bc61125f8",
    "registry": "274fb34537edc2d90e021a27d91a0a7bc61125f8",
    "gate_scan": {
      "tagged": 0,
      "head": "f6e6b507b989f80e211a3c98f342f278f5ef4a7b"
    },
    "reasons": [
      "risk:policy",
      "runtime=373"
    ],
    "risk": [
      "policy"
    ],
    "mode": "panel",
    "declared": [
      "policy"
    ],
    "detected": []
  },
  "pregate": "requires-remote cleared @5fbd032127ed (7 checks, current for f6e6b507b989)",
  "requires_remote": [
    "free-tests.yml/cso-macos-launcher: https://github.com/garrytan/gstack/actions/runs/42242441792/attempts/1",
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/42242441792/attempts/1",
    "pregate.json/remote_gate: remote-gate tree=5fbd032127ed tests=35936 skipped=69 runs=42242441792/1 profiles=ci-reuse/free-tests heads=f6e6b507b989 verified=2026-11-06T15:32:50.549Z"
  ],
  "issues": {
    "fixes": [],
    "refs": [],
    "flakes": []
  },
  "docs": {
    "status": "current",
    "scope": "docs/, README.md, AGENTS.md, CLAUDE.md, CONTRIBUTING.md against main...HEAD (5 files)"
  },
  "review_loop": {
    "passes": 2,
    "blocking_found": 1,
    "deferred": 0,
    "noted": 1,
    "fixed": 1,
    "scope": "frozen",
    "rounds": 2,
    "est_input_tokens": 21881,
    "ledgers_read": 3,
    "dispatches": {
      "specialist-batched": 2,
      "red-team": 2
    }
  }
}

What changed

A fix written through a Bash heredoc after the last test now reads missing instead of met

A fix written through a Bash heredoc after the last test now reads missing instead of met.

Before/after as text: A fix written through a Bash heredoc after the last test now reads missing instead of met
--- Before · before.txt · captured output
+++ After · after.txt · captured output
 $ gstack-skill-contract check  # Edit, bun test, then a heredoc python fix, no test after
+  missing check-after-last-edit: no test or repro command after the last Bash write (src/auth.ts)
-  met     check-after-last-edit: ran "bun test test/auth.test.ts" after the last edit
 

/investigate's check_after_last_edit contract item now treats a Bash command that writes a file inside the session directory as an edit. Before, only Edit, Write, MultiEdit and NotebookEdit counted, so a run that tested, then fixed the code through the shell and never tested again read met. The new parser, lib/shell-writes.ts, reports the files written by >/>>/&> redirects, tee, sed -i/perl -i, patch, git apply, and inline or heredoc python, node, ruby, bun or deno code that opens a literal path for writing. A target counts only when it resolves inside the session directory (the transcript's first cwd). A check later in the same Bash command counts, and so does the command whose output a redirect or tee captures (bun test > out.log). The miss detail names the write: no test or repro command after the last Bash write (src/auth.ts).

/ship's review found one blocker, fixed in f6e6b50: perl and sed option clusters were scanned for i through attached values, so perl -Ilib t/basic.t (a standard Perl test run) counted as an in-place write of the whole repo and could never satisfy the item. Clusters now stop at the first option that takes an attached value (perl -I -M -m -C -d -D -F -x, sed -e -f).

Why

In GEVA-2's L1 run, 5 of 7 probe-I fixes were heredoc writes, and every one of them read met with no test after the fix. A contract that says "run the test after your last edit" has to see every edit, or it rewards the shell route it was meant to police.

Tests

Failing-first: the two new check_after_last_edit tests in test/skill-contract.test.ts failed on main (the heredoc python write read met; sed -i without a transcript cwd read met) and pass now. They cover 12 write forms (heredoc python with a variable path, sed -i, tee, >>, cat > file <<EOF, git apply heredoc, patch -p1 <, cd && perl -pi, python -c with Path.write_text, node -e writeFileSync to an absolute repo path, a script written to /tmp then run, xargs sed -i), each as missing alone, met with a later test call, met with a test later in the same call, and missing with the test earlier in the same call; plus 25 negative controls and a unit test of lastBashWrite.

Blast radius

Only the skill contract checker (the Stop hook and gstack-skill-contract) calls lastBashWrite, and check_after_last_edit is its one consumer (lib/skill-contract.ts:389, read). parseTranscript's new cwd fields are optional, so existing callers and hand-built transcripts parse unchanged; the full free suite passed at this tree (run 42242441792).

Approvals

No approvals recorded for branch capy/gst-1633-bash-writes.

Summary

The Stop hook let a fix written through the shell pass as tested. It now counts in-repo Bash writes as edits, with a conservative parser that ignores reads, stdout, /tmp, home and variable targets. Review hardened the perl and sed option parsing so ordinary Perl test runs are not mistaken for writes.

Test Coverage

Coverage: deterministic (each of 2 changed runtime files has a changed test naming it; no audit reader).

Regression proof: the perl/sed case in test/skill-contract.test.ts (lastBashWrite test) failed on ce10db3 (perl -Ilib t/basic.t returned {files:['.']}) and passes after f6e6b50.

Tests ran: targeted 52
Tests ran: free 1610 (files, carried from CI run 42242441792)

Pre-Landing Review

Pass 1 (full depth, policy risk declared): Pre-Landing Review: 3 issues — 1 auto-fixed, 2 asked (0 fixed, 2 skipped), 0 deferred, 0 noted. The two skips were taken unattended on the run's recommendation under the crew blocking floor; both are listed under Open notes below.
Pass 2 (range ce10db3..f6e6b50): Pre-Landing Review: 1 issue — 0 auto-fixed, 0 asked (0 fixed, 0 skipped), 0 deferred, 1 noted

REVIEW_LOOP: passes=2 blocking_found=1 deferred=0 noted=1 fixed=1 scope=frozen ledgers_read=3 dispatches=4 est_input_tokens=21881

Gate edits: none detected (2 listed, 0 read; patterns: RH-1,RH-3,RH-4,RH-12,RH-13,RH-14,RH-15,RH-16; unlisted idioms: none)

Outside review: Codex CLI is not installed on this machine, so the outside voice ran as a separate Claude subagent (same model family); it completed with 5 findings, none blocking. Cross-family outside coverage is unavailable.

Review notes

Below the blocking floor (advisory, informational, test-gap or wording items); recorded here and not fixed in this PR.

  • INFORMATIONAL lib/shell-writes.ts:284 perl's -e detection still reads letters.endsWith('e'), so an attached -I/-M value ending in e (-I../include, -Mopen=locale) is taken as -e and swallows the next argument; perl -I../include -pi -e 's/a/b/' src/x.ts is a missed in-place write (a false met, no weaker than main, which saw no Bash writes)
  • INFORMATIONAL lib/shell-writes.ts:282 perl -E and -V: are not option-cluster stops and -E is not treated like -e, so perl -nE'print if /x/' src/a.pm, perl -E'print 1' and perl -V:libpth read as writes of '.' (pre-existing, also on ce10db3); a false missing after the last check
  • INFORMATIONAL lib/shell-writes.ts:282 C and d in the perl stop set hide perl -dpi -e ... src/a.pm (and -CSDpi, which perl itself rejects per outside-voice#5) as writes; a rare missed in-place edit, no weaker than main
  • INFORMATIONAL lib/shell-writes.ts:286 an attached sed -e/-f script (sed -i -es/a/b/ src/a.py src/b.py) is not marked as the script, so rest.slice(1) drops the first target or widens it to '.' (pre-existing over-approximation)
  • INFORMATIONAL lib/shell-writes.ts:284 letters.endsWith('e') treats an attached -M/-I value ending in e as -e, so perl -MTime::Piece -pi -e ... src/a.pm and perl -Ilib/site -pi -e ... now return null (found by ce10db3 by accident); a missed write and false met, no weaker than main. Same as p2/red-team#1

Open notes from pass 1 (skipped, below the blocking floor):

  • INFORMATIONAL lib/shell-writes.ts:306 An inline interpreter repro that also writes an output file inside the repo (open('out.json','w')) is the last edit and cannot count as its own check, so the item reads missing where main read met; the agent recovers by running any other check.
  • INFORMATIONAL lib/shell-writes.ts:338 A redirect is always the writer's own output, so python3 -c ... > src/app.py is credited as its own check; main read met for the same transcript, so the gate is no weaker than before, but this form of shell-written fix is not closed.

Exploratory QA

Target: bin/gstack-skill-contract check (the Stop hook's checker), functional CLI surface, synthetic transcripts under /home/user/.capy/work/gstack-1633/qa/t (root /repo). Smoke: 5 probes on ce10db3, then 5 revalidation captures after the perl/sed option fix.

Results

  • success: heredoc write then test in the same command reads met (001, revalidated 006: pass)
  • riskiest edge: heredoc fix after the last test reads missing (002, revalidated 007: pass)
  • red-team#1 replay: perl -Ilib t/basic.t after an Edit read missing on ce10db3 (003); after the fix it reads met (008: pass)
  • red-team#2 replay: python3 -c ... > src/app.py reads met (004, 009): documented behavior, noted design limit
  • specialist#1 replay: inline repro writing out.json reads missing (005, 010): documented behavior, noted design limit

Verdict: pass (gstack-qa-evidence materialize). Checkpoints: checkpoint 002 checkpoint 003 checkpoint 004 checkpoint 005 checkpoint 006 checkpoint 007 checkpoint 008 checkpoint 009 checkpoint 010

Limits

Captures 001-005 are superseded. The debug-report item fails in every fixture because the fixture's DEBUG REPORT predates the installed labels; only check-after-last-edit is under test.

Design Review

No frontend files changed — design review skipped.

Eval Results

No prompt-related files changed. The eval selector's PR profile names 120+ behavioral probes through derived references to lib/shell-writes.ts and lib/skill-contract.ts; the narrow PR screen (evals.yml run 42237202397) planned 0 of them and leaves them to the train gate's full census. No paid eval ran; $0 spent.

Review bot comments

No review bot comments.

Plan Completion

Plan completion audit: not run (no plan is bound to this branch and no docs/designs/ file matches). Fix: add "Plan: " to the PR body, or run /autoplan.

Issues

Refs p1/red-team#1

Verification Results

No Step 8.1 obligations (no plan bound). Exploratory QA: 10 captures, verdict pass.

TODOS

No TODO items completed in this PR.

Documentation

Scope: main...HEAD (5 files: lib/shell-writes.ts, lib/skill-contract.ts, test/skill-contract.test.ts, docs/skill-routing-and-contracts.md, changelog.d fragment); working tree clean.

Result: Current. The check_after_last_edit row in docs/skill-routing-and-contracts.md already says that Bash writes inside the session directory count as edits, and it matches the parser's behavior. The changelog.d fragment is accurate.

Debt: None found.

Test plan

  • bun test test/skill-contract.test.ts test/skill-contract-stop-hook.test.ts: 52 pass, 0 fail
  • bun run test (free suite): carried from Free Tests run 42242441792 at tree 5fbd032127ed, 1610 files green
  • bun run typecheck, module-size ratchet, conflict markers: pass

🤖 Generated with Claude Code

Open in Capy

…ter_last_edit (GST-1633)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@trunk-io

trunk-io Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

perl and sed option clusters stop at the first option that takes an attached value, so perl -Ilib t/basic.t, perl -MList::Util and sed -fscript.sed are no longer in-place writes (GST-1633).

Review-Finding: p1/red-team#1 reader=red-team
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai
capy-ai Bot merged commit 89e9a99 into main Nov 6, 2026
64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant