Plan: brush is pi’s shell on Windows - pinned, checksummed, behind the bash tool, with Git Bash as the fallback

Closes: #652. Relates to: #650. Branch: feat/brush-windows-shell. Status: N/A

Erratum (2026-11-24): brush was removed by #907.

Erratum (2026-11-11): the pin is not an upstream release. It is this repository’s own build of upstream 0b6a4acc with two carried patches and coreutils inside (#772), opt-in through PI_WINDOWS_SHELL=brush, and Git for Windows' tools are no longer on its PATH. The gate ran as that plan’s D9; the spike-corpus re-read of this plan’s gate was not repeated, since the tools it compared against are now refused by name.

Erratum (2026-11-02): a pinned brush not yet kept is fetched in the background; that session runs Git Bash and the next brush, so the shell is fixed for a process and the guards' path mapping never changes mid-session (Design said "or verifies now").

Erratum (2026-11-02): pi-workflow’s commit-message.ts (shellPathFor) and git-guard.ts (commitTargetsElsewhere) also map paths by Git Bash’s rules for the commit guard, so they take the kind too; short-names.ts keeps its /c/ mapping, which only restricts. The kind is read as bashShellKind(pi.events) where each consumer is wired (pi-modes' judge deps and recap, pi-workflow’s commit pause), not by one session-start query.

Erratum (2026-11-02): the shared download and verification is its own module, packages/pi-workspace/pinned-binary.ts, beside windows-shell.ts rather than inside it.

TL;DR

The spike (#650) measured, on panther at 85-100% CPU: Git Bash 4.2 s to start and 193 of 400 real agent commands past the 20 s limit; brush 29 ms to start, 5 timeouts, and the same output as Git Bash on 195 of the 206 commands both finished once MSYS=noglob is set. The byte capture showed why the rest differ: brush parses the line right, and the msys runtime of Git’s own tools re-parses the native command line brush builds. The operator’s decision: brush on Windows first, pinned and checksummed, behind pi’s bash tool, gated on the differential test pi-dev landed (packages/pi-bash/test/differential.test.ts and bash-oracle.ts, whose brush oracle reads PI_BRUSH; on main at 835903db6, ahead of the checkout this plan was written in).

Two facts found while planning shape the design:

  • The gate already fails brush 0.4.0. At PI_BASH_DIFF_RUNS=3000, with a heredoc pending on the line, brush drops a number before a spaced redirect (a <<E && a 1 >o.txt: bash runs a 1, brush runs a). The guards read a 1 there. A shell that runs less than the guards read is a safety gap, so no 0.4.0 pin. The pin is the first upstream release that passes a deep run, and upstream has no Windows release asset yet (v0.4.0 ships six targets, none Windows; canary Windows builds follow each push to main; a tagged Windows asset is "planned"). So this plan builds every pi-side piece now against a locally built brush, and the switch is a one-line pin bump.

  • The spike’s corpus excluded every absolute path by construction, and in this box’s own sessions 87% of bash commands carry a /d/…​ path (78% begin cd /d/code/pi). brush does not resolve msys drive paths (upstream #1142), so cd /d/code/pi fails under it. The operator’s read: that form is a habit learned from Git Bash’s output, and the model adapts to the shell’s errors. The plan treats it so: a one-line hint in the bash tool’s description on Windows, a clear error, and a field count after the switch that shows the adaptation happened.

Phase 1 switches the bash tool only. Monitors and jobs keep Git Bash: their stop and stuck logic reads Git Bash’s msys process group (#553, #626), and a native shell needs its own, which is a later plan. The ! user shell stays upstream’s resolution. Linux and macOS follow once Windows has run on brush and the differential holds (the operator’s sequencing), as their own plan.

Design

Where brush comes from, and how it is trusted

Three sources were compared:

Source For Against

Upstream tagged release asset, with its .sha256 sidecar and GitHub attestation

The provenance pi already accepts for rg and fd (packages/pi-ssh/remote-tools.ts, PINNED); one artifact for every box; the sidecar is the pin

None exists for Windows today; the timing is upstream’s

cargo install --locked brush-shell@<ver> on each box

Works today (panther’s spike binary was built so); the crate’s own Cargo.lock pins every dependency

Needs a Rust toolchain on every Windows box; a Rust build is not bit-identical across boxes, so a repo-committed checksum cannot verify it - a per-box hash is tamper detection, not provenance

MSYS2’s mingw-w64-*-brush package

Signed packages, a package manager

Needs MSYS2 on every box; the version follows MSYS2’s cadence; still a native build with the same msys-argument gap

Decision: the upstream release asset, by the rg/fd pattern. A PINNED record in a new packages/pi-workspace/windows-shell.ts names the brush version, the Windows x86_64 asset URL and its sha256 (and aarch64 when upstream ships it). On first use the extension downloads it to <agentDir>/gadhs-pi-shell/brush-<ver>-win32-<arch>/brush.exe, verifies the sha256 before anything runs it, and refuses on mismatch or with PI_OFFLINE set, exactly as remote-tools.ts does. Until a Windows asset exists the record is empty, and only the developer path below reaches brush. The pin bump is one record and one CHANGELOG line.

Developer path: PI_BRUSH=<path> names a brush binary and skips the download: the variable the differential’s brush oracle reads (bash-oracle.ts lines 17-21 on main: BRUSH, BRUSH_PRESENT). It exists so panther can build and test everything in this plan against the locally built 0.4.0 and, later, a canary. It is the box’s environment, which no project can write, so it needs no trust gate; the recap says when a session ran on it.

How the bash tool picks brush

The bash tool is registered by pi-ssh (extension.ts localBash) or, without it, by pi-workflow (batch-order.ts sequentialBash), both through withCommandFile(shellOptions(settings), LOCAL_SHELL) in packages/pi-workspace/bash.ts and command-file.ts. That is the seam. A new windowsShell(settings, env, platform) in windows-shell.ts answers, on win32, which shell runs the bash tool:

  1. PI_BRUSH, when set and the file exists (trusted project only).

  2. The pinned, verified brush under the agent dir, when PINNED names one and the download has verified (or verifies now).

  3. Otherwise Git Bash, exactly as today: upstream’s getShellConfig with the shellPath setting.

withCommandFile takes the answer. For brush it builds the operations on brush’s path with -c, keeps the command-file transport (brush sources . 'C:/Users/…​/pi-bash-<hex>.sh' as Git Bash does; the file removes the msys -c halving #450 solved, and keeps one transport), and gives the child MSYS=noglob in its env. The variable is set on that spawn only: never on pi’s own process, so monitors, jobs and the ! shell see nothing of it. Upstream’s shellPath setting is left alone: it is shared by monitors and jobs, which stay on Git Bash in phase 1.

The escape: PI_WINDOWS_SHELL=git-bash in the box’s environment forces Git Bash for the bash tool; brush is the default and the only other value. An unknown value is refused at registration with its reason, and the tool runs Git Bash, never a silent guess. It sits beside PI_BRUSH and PI_OFFLINE because it is the box’s setting, not a project’s: there is no per-project override of the shell a tool runs in.

What the guards must know

The guards decide from tree-sitter-bash’s parse, and two places read the running shell’s path conventions:

  • authorize.ts shellTarget maps a redirect target through gitBashPath on win32 (/tmp/x is the user’s Temp; /c/…​ a drive). Under brush, /tmp/x is <cwd drive>:\tmp\x and /c/…​ is no path at all. The mapping takes the shell: brushPath maps a leading / as brush does (the cwd’s drive) and ~ as brush’s $HOME (Windows form). A target the shell cannot resolve is not scratch, so it is judged, never rule-allowed: the safe direction.

  • short-names.ts reads GIT_BASH_DRIVE forms. Under brush a /c/ spelling reaches no file, so the long spelling check keeps it as it is: an 8.3 name in C:/ form is still expanded.

The shell in force is one value, ShellKind = "git-bash" | "brush", decided once beside the bash tool’s registration. It crosses packages as the owner of bash already does: bash.ts answers bashOwner() over the extension event bus (claimBash, BASH_OWNER_CHANNEL), and a bashShellKind(events) query beside it answers the kind. pi-modes asks once where it asks the owner, at session start, and hands the answer to the authorizer’s deps; no guard re-derives it from the environment.

The tool’s description, and the field count

On win32 under brush the bash tool’s description gains one sentence: "Paths are Windows paths (D:/code/pi); /d/code/pi is not a path here." The session recap records the shell kind. A new task.mjs report, shell-field <sessions dir>, counts per session the bash calls that failed with brush’s cd: …​ not found on a /x/ path and how many turns until the form changed. It reads session logs as tools/shell-spike/extract.mjs does and prints counts only. Its number after a week on panther goes on #652; the hypothesis is one or two failures per session, then none.

The gate, and what is documented

The pin bump lands only when, on the pinned version:

  1. pi-dev’s differential passes a deep run on Linux and on panther: PI_BASH_DIFF_RUNS=20000 PI_BRUSH=<pinned> vitest run packages/pi-bash/test/differential.test.ts (suite "pi-bash reads a line’s argvs as brush runs them (#650, #652)").

  2. The spike’s corpus under brush with MSYS=noglob matches Git Bash on every command whose difference is not an embedded " to an msys tool (195 of 206 on 0.4.0; the number is re-read on the pinned version).

  3. task validate on panther with the bash tool on brush.

The embedded-quote gap is documented, not gated: a pattern holding a literal " passed to one of Git’s msys tools arrives changed, so a grep can report nothing where there are matches. Its fix is upstream PR #1295, which the operator posts with the heredoc and glob-order reports. Until it lands, the docs say so and name the workaround: ripgrep (rg), a native program, reads its arguments by native rules.

Scope

In

  1. Rebase first. The branch starts from main at or after 835903db6, where the brush oracle lives; this plan was written in a checkout behind it.

  2. packages/pi-workspace/windows-shell.ts: PINNED, the download and sha256 verification (lifted from remote-tools.ts into pi-workspace, and remote-tools.ts imports it back: one copy), the PI_BRUSH path, PI_WINDOWS_SHELL, windowsShell(), ShellKind, and the MSYS=noglob env. Tests (contract, the shell faked): a wrong sha256 is refused and the file removed; PI_OFFLINE refuses the download with its reason; the three-way choice; PI_BRUSH naming no file falls back to Git Bash; an unknown PI_WINDOWS_SHELL is refused with its reason and Git Bash runs; MSYS=noglob is on the brush spawn’s env and absent from Git Bash’s and from process.env.

  3. packages/pi-workspace/bash.ts, command-file.ts: withCommandFile takes the shell choice; bashShellKind() beside bashOwner(). Tests (contract): the sourced file reaches brush as a Windows path in single quotes; the kind query answers what the registration claimed; with PINNED empty and no PI_BRUSH, the operations are upstream’s (regression: nothing changes on any box).

  4. packages/pi-ssh/extension.ts, packages/pi-workflow/batch-order.ts: the registration claims the kind and adds the Windows sentence to the tool’s description. Tests (contract): the description carries the sentence only on win32 under brush; the claim is made by whichever extension registers bash.

  5. packages/pi-modes/authorize.ts, short-names.ts, session wiring: the kind asked at session start and handed to the deps; shellTarget and the short-name forms by kind. Tests (regression): /tmp/x under brush is not scratch and is judged; ~/x under brush maps to the Windows home; every Git Bash case unchanged; the recap names the kind.

  6. tools/task.mjs shell-field with its test on a synthetic session log (contract: the counts for a known log).

  7. Verification on panther (PI_BRUSH at the local 0.4.0, then the pinned version): the spike corpus re-read, one tools/shell-spike/run.mjs invocation naming Git Bash and brush with MSYS=noglob in the environment; task validate with the bash tool on brush; and a day of this session’s own work on brush before the pin bump MR.

  8. Delivery. Two MRs. The pi-side MR (Relates to #652) lands with PINNED empty: dormant on every box. The pin bump MR (Closes #652) carries the gate’s numbers; #650 is closed by the operator when the upstream reports are posted.

  9. Docs: modes.adoc (the Windows shell paragraph at the workflow guards, and the "Both commands are bash" resolution order; the #650 PowerShell note rewritten: brush is the fast path), ssh.adoc "From a Windows machine", packages.adoc (the pinned binary), security.adoc ASI04 (one more pinned, checksummed binary; the embedded-quote gap in the residual column), tuning.adoc (PI_WINDOWS_SHELL, PI_BRUSH), testing.adoc (the brush differential and its deep run). CHANGELOG under Unreleased.

Out

  • Monitors and jobs on brush (their msys stop and stuck logic; #553, #626): a later plan, after the bash tool has run on brush.

  • The ! user shell: upstream’s resolution, unchanged.

  • Linux and macOS: their own plan, per the operator’s sequencing.

  • Rewriting any part of an agent’s command (paths, quotes) before it runs: never; the guards must read what runs.

  • An upstream contribution for #1142, #1295, the heredoc bug or the glob order: the operator posts the reports; a patch is its own decision.

  • A Windows CI runner: the pi-side units are unit-tested on every platform with the shell faked; the real-shell checks run on panther.

Risks

Risk Response

Upstream ships no Windows asset for months (fail-closed: Git Bash runs)

The pi side is complete and dormant (PINNED empty); panther runs the developer path. The decision to build our own artifact (a CI job with a Rust toolchain publishing to the project’s generic package registry) is the operator’s, taken then, not now.

The pinned version passes the deep differential on Linux but a Windows-only divergence hides in the spawn boundary (silent)

The differential also runs on panther before the pin bump, and the corpus re-read is Windows-only by construction.

The model keeps writing /d/ paths and each session loses turns (fail-closed: an error, never a wrong run)

The tool description sentence, brush’s clear error, and the shell-field count after a week; if the count stays high, PI_WINDOWS_SHELL=git-bash is the one-line escape, and a cd shim becomes a decision with data.

A silent empty grep misleads a session (the embedded-quote gap; silent)

Documented with the rg workaround; the recap records the shell kind so a wrong conclusion can be traced; upstream #1295 closes it.

Two copies of the download-and-verify code drift (fail-open: a weaker copy could accept a bad binary)

One copy, in pi-workspace, imported by pi-ssh’s remote-tools.ts.

MSYS=noglob leaks to a child that needed msys globbing (fail-closed: a glob stays literal, so a command sees fewer files, never more)

Set on the bash tool’s spawn only; the spike’s 400 commands ran under it with no such case; a command that needs msys globbing from a native parent is one the plan’s docs name as the escape’s reason.

Acceptance

  • With PINNED empty and no PI_BRUSH, nothing changes on any box: the Windows bash tool runs Git Bash as today (a test asserts the operations are upstream’s).

  • With PI_BRUSH on panther: the bash tool runs brush with MSYS=noglob; task validate passes; /tmp/x redirects are judged, not rule-allowed; the recap names the shell.

  • The pin bump MR carries the deep differential’s numbers on both boxes, the corpus re-read, and the first shell-field count.

Edit this page · latest