Plan: one bash parser, in one package
Closes: #206. Branch: refactor/pi-bash. Status: Done (2026-09-26) — pi-bash 0.1.0; a release follows
TL;DR
Two copies exist because ADR-004 (2026-08-31) split policy (pi-modes) from
workflow enforcement (pi-workflow), forbade one importing the other, and
preferred copies held equal by test. pi-workflow’s bash-structure.ts
(2026-09-01, #14) came first, for the commit guard. pi-modes needed a
parser on 2026-09-25 for the compound-line fix (#205) and copied it as
bash-line.ts. The ADR did not foresee a shared parser; for pi-modes'
trace and status helpers it said a shared package would be "a new
decision, not this one". This is such a decision, for the parser.
Neither copy is strictly better. bash-structure is the deeper view (argv
with unknowable tokens marked, redirects, wrapper chains, spans, which
heredoc bodies are inert). bash-line has three things it lacks
(pipelines, "is this one statement", a text split for PowerShell). The
library keeps the deeper parser and adds the three.
Design
The package
packages/pi-bash, @gadhs/pi-bash, a library: no pi field, no
extension, no loader in the meta package (the meta’s loader test holds one
loader per dependency, and this has nothing to load). It follows
pi-guidance’s manifest shape otherwise: type: module, files of *.ts
(not vitest.config.ts), README.md, LICENSE; exports "." to
./index.ts; the repository’s publishConfig. tools/ci-publish.mjs
discovers publishable packages by publishConfig and orders them by name,
meta last, so pi-bash publishes before pi-modes and pi-workflow with
no CI change.
Dependencies move, they don’t multiply: tree-sitter-bash ^0.25.1 and
web-tree-sitter ^0.26.9 leave both consumers' dependencies and become
pi-bash’s. Each consumer takes "@gadhs/pi-bash": "workspace:*" as a
regular dependency, which publishing pins to the exact version, as the
meta’s members are. A regular dependency, not a peer: the parser is a
private tool of each consumer, like tree-sitter was, and if npm ever
resolved two copies each would simply warm its own, as the two copies do
today.
The modules
|
|
|
|
|
|
|
ONE table, |
|
Re-exports the four. |
The consumers
-
pi-workflow: delete
bash-structure.ts;git-guard.ts,structural-guards.ts,commit-pause.ts,index.tsimport from@gadhs/pi-bash;warmBashStructurebecomeswarmBashParser;TEXT_WRAPPERSgoes (it was an alias ofWRAPPER_NAMES), andstripWrappersstays ingit-guard.tsreading the library’s table. Its commit guard now unwrapssetsid,ioniceandexec. Regression tests, ingit-guard.test.ts:findCommitsfinds the commit insetsid git commit -m x,exec git commit -m xandionice -c 3 git commit -m x, warm and cold, andguardGitCommitrefusessetsid git commit --no-verify -m x. -
pi-modes: delete
bash-line.ts;mode-policy.ts,judge-wiring.ts,judge.tsimport from@gadhs/pi-bash;warmBashLinebecomeswarmBashParser. Its effective commands now seeenv -S. Regression test, in pi-bash’s line tests:effectiveCommand("env -S 'CI=1' pnpm publish")ispnpm publish. The existingcommand -v npmpin stays and still holds. -
Tests move with their modules:
bash-structure.test.tsandbash-line.test.tsbecome pi-bash’s, under its own vitest config with the repository’s coverage bar. The two parity tests that read the other package’spackage.jsonfor tree-sitter ranges collapse into one in pi-bash that reads the engine’s (@gotgenes/pi-permission-system) asbash-structure.test.tsdoes today. Consumer tests that callresetBashLine/resetBashStructurecallresetBashParser. -
git-guard-chaos.test.ts’s parity pin between `TEXT_WRAPPERSandWRAPPER_NAMESis deleted: the two are one value. -
packages/pi/test/shipped-imports.test.tschecks a package’s relative imports against itsfileslist; a bare@gadhs/pi-bashimport is outside its concern. What makes the import resolve on a consumer’s box is thedependenciesentry, which the consumer simulation exercises.
The installed layout
The consumer simulation (tools/consumer-sim.mjs) checks pi-remote’s wasm
loads from the installed root (#142) and never checked the bash parser’s.
Moving the parser is the moment to: a check that imports @gadhs/pi-bash
from the installed root, awaits warmBashParser, and asserts
analyze("git commit -m x").commands[0].argv[0] === "git". A cold parser
fails closed and quietly today; this makes it loud where it would first
appear.
ADR-004, amended
A dated amendment: a library is a package species beside the extension packages. It ships no extension and needs no loader; the enforcement packages import it by name as a regular dependency. The criteria from the ADR apply (its change cadence is the parser’s, its review posture is enforcement, it is coupled to neither mode nor workflow). The mirror-constant preference stands for constants; it failed for a parser and its tables (#62, and the 2026-09-26 drift).
Docs and release note
-
packages.adoc: the package table gains pi-bash; the count of packages wherever a page states it (grepseven). -
CHANGELOG.adoc== Unreleased, under Changed: the new package, the merged table, and the two behaviour changes it brings (the commit guard unwrapssetsid,ionice,exec; pi-modes' effective commands seeenv -S). -
Versions at release: pi-bash 0.1.0; pi-modes and pi-workflow minor.
Order of work
-
The package, with the moved modules and tests, green on its own.
-
pi-workflow switched over, its parity pin deleted, green.
-
pi-modes switched over, green.
-
The consumer-sim check, ADR amendment, docs, changelog.
-
validate; the pack test inpackages/pi; then the release. -
Close #206 with the merge SHA.
One MR. The ledger stays one parser at every step: a consumer is switched whole, never half.
Risks
| Change | Direction | Why it is safe |
|---|---|---|
The commit guard unwraps three more wrappers |
Fail-closed |
More lines read as commits, never fewer. A wrapper form the walk misreads
leaves the unit unrecognised, and the raw-string |
One warm state for two consumers |
Fail-closed |
Cold or failed is |
The wasm loads from a new package location |
Fail-closed, and today silent |
A load failure is logged and the session runs cold. The consumer-sim check turns that into a red run at the one place it would first show. |
npm resolves two copies of pi-bash |
None |
Each copy warms its own parser, as the two copies do today. Publishing pins exact versions, so this needs two consumers on different pi-bash versions, which one release never produces. |
|
Fail-closed |
One more candidate for the restricting checks; an allow is never taken from a unit. |
Nothing here is silent: a cold parser is logged (bash_line.load_failed
today, one event name after the merge), and every refusal is traced.
Scope
In: packages/pi-bash/*; in pi-workflow bash-structure.ts (deleted),
git-guard.ts, structural-guards.ts, commit-pause.ts, index.ts,
package.json, its tests; in pi-modes bash-line.ts (deleted),
mode-policy.ts, judge-wiring.ts, judge.ts, package.json, its
tests; tools/consumer-sim.mjs; adr-004-package-boundaries.adoc,
packages.adoc, CHANGELOG.adoc.
Out:
-
Any change to what either parser reports beyond the table union. The structure view and the line view stay two functions over one tree; making them one view is a later simplification if anyone wants it.
-
The meta package: no loader, no dependency; pi-bash reaches consumers through pi-modes and pi-workflow.
-
pi-modes'
textUnitsfor PowerShell stays text-only; a PowerShell parser is not this.