Plan: a plain bash line whose every command is cleared is allowed without the judge

Closes: #888. Relates to: #884 (the audit that ruled it), #205 (why a rule allow is never taken from a compound line), #122 (the workspace-read stage this mirrors), #901 (the decision pipeline, planned after this). Depends on: #923 (see Prerequisite). Branch: feat/plain-line-allow. Status: Done (2026-11-24) — on in auto and plan: the field count cleared 24.7 % (pi), 24.2 % (canopy), 16.3 % (craig) of main-session bash calls, past the 15 % rule

Context

The mode rules allow a bash line only when it is one command (evaluateLine, packages/pi-modes/mode-policy.ts, #205). Real lines are not: measured on luchs over 57,699 bash calls in three projects' sessions, a single command is 0.5 % to 1.4 % of lines, and the 106 shipped allow patterns decided 19 lines. The judge decided the rest: 70,837 calls, $484, 1.5 s median over three weeks (pi-win, #884).

The operator ruled on #888: allow a line when every part matches an allow pattern. Measured, that alone clears 0.5 % to 0.8 % of lines, because the patterns name builds, tests and a few git reads, while lines are chains of grep, sed -n, head, cat. On 2026-11-23 the operator chose the wider form: the allow table plus read-only commands with argument checks. A sizing script (a text splitter, not the real parser) put that at 24.7 % (pi), 39.3 % (canopy) and 41.4 % (craig) of bash lines.

The judge’s corpus (packages/pi-modes/eval/corpus.json) says where the line is. Its critical denies include cat .env.local, grep -r TOKEN . and cat /proc/self/environ piped on: a reader is only safe when the files it reads are known and are not secrets.

Design

What a plain line is (pi-bash)

New file packages/pi-bash/plain.ts exports one synchronous function, re-exported from packages/pi-bash/index.ts:

export type WordQuoting = "bare" | "quoted" | "mixed";
export interface PlainWord { text: string; quoting: WordQuoting }
export interface PlainCommand {
  /** The command's source text, trimmed: what a rule pattern matches. */
  text: string;
  /** Its words as bash passes them, the name first. */
  words: PlainWord[];
  /** It is a stage of a pipeline. */
  inPipeline: boolean;
}
export function plainCommands(line: string): PlainCommand[] | undefined;

It parses with currentParser() (parser.ts) and returns undefined when the parser is cold, the parse throws, the root has an error, the line holds no command, or the tree holds anything outside an allowlist. The allowlist is the whole safety argument of this view, so it is closed:

  • Named nodes: program, list, pipeline, redirected_statement, command, command_name, word, number, string, string_content, raw_string, concatenation, file_redirect, file_descriptor, comment. Exported as PLAIN_NODE_TYPES.

  • Unnamed tokens: text &&, ||, ;, a single pipe, a double quote, or blank (a newline). A redirect’s operator is judged with its redirect.

  • Redirects: a file_redirect is allowed only as a descriptor duplication (operator >&, destination all digits) or a write to /dev/null (operator >, >>, &> or &>>, destination exactly /dev/null). Its descriptor, when present, is all digits, and it holds exactly one destination.

So a plain line has no substitution, expansion, subshell, brace group, control flow, function, heredoc, here-string, input redirect, file-writing redirect, background &, negation, test command ([ ], [[ ]]), assignment (a prefix or a statement), export or declare. It writes no file through the shell by construction.

Words come from commandArgv(node) and strayWords(node) (structure.ts, both exported; plain.ts imports them from ./structure.ts, as line.ts does). A word whose literal is null makes the line not plain. So does any stray word, and lost.

One assumption, by reading and not run: tree-sitter-bash reads ~/code/x as one word node. cd ~/…​ opens 96 % of real lines, so plain.test.ts pins it, and the field tool’s share would show it at once if it were wrong (every such line would be not-plain). commandArgv gains a quoting: WordQuoting[] beside argv: bare for a word or number node, quoted for string or raw_string, mixed for concatenation. For the command’s name the node is `command_name’s first child. No other caller reads the new field.

Which commands are cleared (pi-modes)

New file packages/pi-modes/plain-line.ts holds the roster and one pure function. It touches no file system: the caller supplies the two facts that need one.

export type PlainLineRefusal =
  | "not-plain" | "command" | "option" | "operand" | "glob" | "path" | "cd" | "tree-search";
export type PlainLineVerdict =
  | { cleared: true; byRoster: number; byRule: number }
  | { cleared: false; why: PlainLineRefusal; head?: string };
export interface PlainLineInput {
  commands: readonly PlainCommand[] | undefined;
  /** The session's directory: where the line starts. */
  cwd: string;
  home: string;
  /** Whether the mode's own rules allow this one command's text. */
  allowedByRule(text: string): boolean;
  /** Whether `path`, read from directory `dir`, is a file this session may read without the judge. */
  readable(path: string, dir: string): boolean;
  /** Whether `path`, entered from `dir`, is a directory inside the workspace or temp; its resolved path when so. */
  enterable(path: string, dir: string): string | undefined;
}
export function plainLineVerdict(input: PlainLineInput): PlainLineVerdict;

commands undefined or empty is not-plain. Otherwise every command must be cleared, in order, and the first that is not gives the refusal, with head its first word.

A command whose first word is in the roster is decided by the roster’s proof alone: a failed proof refuses the line and the rule table is not consulted for it. Any other command is cleared only by allowedByRule(command.text), else command.

Three rules hold for every roster command:

  • No expansion in an operand. An operand (a word after the name that does not start with -) that is bare or mixed and holds *, ?, [ or an opening brace refuses with glob. A quoted word is literal. An option word is exempt: its value is checked by the option table.

  • Tilde. A bare operand that is ~ or starts with ~/ is read under home. Any other operand starting with ~ that is not quoted refuses with path.

  • Directories. The line starts in cwd. Each cleared cd adds the directory it enters to the set of directories later commands may run in; it never replaces the set, because a failed cd followed by ; leaves the shell where it was. A path operand must be readable from every directory in the set. A set larger than 8 refuses with cd.

The roster, 22 names. Erratum (2026-11-24): 23; the list below names 23, egrep and fgrep beside grep. "Options" means every option word must parse against the list: letters may cluster, a value-taking letter takes the rest of its word or the next word, anything else refuses with option. "Paths" means every operand must be readable; a lone - is standard input.

  • cd: exactly two words, the second not starting with - (so cd - and a bare cd refuse), not inPipeline; enterable from every directory in the set, else cd.

  • pwd, true, false, :, echo, printf, test, tr: any words. They read no file’s content. Erratum (2026-11-24): test has a proof of its own: the operand of each file operator (-e, -f, -s and the like) and both sides of -nt, -ot and -ef must be readable, since test -s /etc/shadow tells something about a file outside the workspace.

  • exit: no operand, or one of digits only. sleep: one operand, digits with an optional fraction. Else operand.

  • cat: options nAbsETv; paths.

  • head, tail: options qv, valued nc, and a dash followed by digits; paths.

  • wc: options lcmwL; paths.

  • cut: options s, valued cfdb, long --complement; paths.

  • sort: options rnuhVfb, valued kt; paths.

  • uniq: options cdui, valued fsw; no operand at all (uniq IN OUT writes), else operand.

  • ls: options laAdtrRh1SF; paths.

  • sed: exactly sed -n SCRIPT then paths, where SCRIPT is one or more print commands joined by ;, each a line number or a range ending in a number or $, then p. Any other form refuses with option.

  • grep, egrep, fgrep: options nivEFPowxhHIsclLqrR, valued eABCm, long valued --include, --exclude, --exclude-dir, long --color with or without a value. The first operand is the pattern unless -e was given; the rest are paths. A recursive search (r or R) refuses with tree-search unless it prints no file content (l, L, c or q): it prints lines from files the command never names, which is the corpus’s critical case.

Left out on purpose, each a top blocker in the sizing run and each needing a proof of its own: awk, find, rg, jq, xargs, timeout and every other wrapper, date, git beyond what the mode’s rules allow.

The stage (authorize.ts)

A new stage, plainLineAllow, runs in authorizeAsk’s `settled chain right after ruleAllow and before scratchWriteAllow. It is split in two so the field tool can read the reason:

export type PlainLineOutcome = PlainLineVerdict | { cleared: false; why: "off" | "rule" | "helper" | "remote" | "no-cwd" | "valve" };
export async function plainLineOutcome(
  deps: AuthorizeDeps, details: AskDetails, mode: ModeDescriptor,
  line: { rule: RuleMatch | undefined; units: string[] },
): Promise<PlainLineOutcome>;

plainLineOutcome answers, in this order:

  1. off unless mode.plainLines === "allow".

  2. not-plain unless bashLineOf(details) gives a line (mode-policy.ts, exported by this plan; today private).

  3. rule when line.rule !== undefined: a deny has already refused, an ask rule on any command keeps the line the judge’s, and a single command’s own allow was `ruleAllow’s to take or to decline.

  4. helper when details.forwarded === true: a helper’s directory is not this session’s.

  5. remote when deps.workspace?.isRemote === true; no-cwd when deps.cwd === undefined.

  6. valve when mode.judge !== undefined and hitsSafetyValve(mode.judge, { …​details, units }) (judge.ts) names a pattern, with units as ruleAllow takes them (details.units ?? line.units).

  7. Erratum (2026-11-24): secret when the line holds a secret-shaped value (holdsSecretShaped), as #923, merged after this plan, made every rule allow stand back for one.

  8. Otherwise plainLineVerdict over plainCommands(line), with cwd: deps.cwd, home: homedir(), and:

    • allowedByRule: commandAllow(mode.permission, details, text) !== undefined. commandAllow is new in mode-policy.ts: bestMatch(rules, surfacesOf(details), [text]), returned only when its action is allow. A refining deny still outranks an allow there, as for a single command.

    • readable and enterable: readAtHome(path, dir, deps.cwd, deps.shell ?? "git-bash"), new in authorize.ts beside writesAtHome and built from the same parts. The path is placed with shellTarget(path, process.platform, tempDir(), shell) and walked with realLocation(placed, dir). It must land inside realPath(cwd) or one of tempRoots(process.platform, tempDir()). readable also refuses a credential-shaped name, by credentialShaped on the basename of both the word and the real location. A path that does not exist yet is judged where its deepest existing parent really is, as a write is; a dangling link is refused.

plainLineAllow calls it. When cleared it writes the review-log event gadhs_plain_line.allow (mode, ask cut to 160 characters, byRoster, byRule) and returns { kind: "allow", source: "rule", pattern: "plain-line" }. Otherwise it returns undefined and the ask goes on as today.

The high-consequence list, the registry check and the pending queue have all run before it, as they run before ruleAllow.

The mode key

ModeDescriptor gains plainLines?: "allow" | "ask" (config.ts: the interface, MODE_KEYS, and a check.oneOf line beside workspaceReads). modes.json sets "plainLines": "allow" on auto and plan. manual and yolo do not set it: in manual the human answers whatever the rules do not decide, and widening that is a separate decision; yolo allows everything already. An overlay replaces the key like any other mode field (mergeModesConfig).

What changes for a rule allow

An allow pattern, shipped or the operator’s own, now also clears its command inside a plain line whose other commands are cleared. cd /tmp && glab api --method PUT …/merge runs by rule once the operator has a standing approval for that exact merge command. The valve and the high-consequence list still come first. A standing approval is still written only from a single command (standing-approval.test.ts, "refuses what a rule cannot allow", which matches the words "several commands" and so still passes); standingRefusal’s reason becomes: `a standing approval is one command’s rule, and this is a line of several commands (or one that cannot be read); approve it once.

Measured before it ships: the field tool

node tools/task.mjs plain-line-field <sessions dir> [--mode auto|plan] (new tools/lib/plain-line-field.mjs) replays every bash call of the session files under a directory through the real gate, offline. It awaits warmBashParser() once and stops with an error if the load fails. For each call it builds the ask { toolName: "bash", surface: "bash", command: line, fullCommand: line } and calls authorizeAsk with the loaded config (loadModesConfig), the named mode (default auto), registry: undefined, a fresh DenialTracker and cwd from the session file’s first record. With no registry the gate returns before any model. For a call not allowed it reads the reason from plainLineOutcome, given the same ask and evaluateLine(mode.permission, ask)’s `verdict and units. The package sources are loaded with a dynamic import() of the .ts files, as tools/model-battery/drivers/judge.mjs loads eval/run.ts. A session file with no cwd in its first record is skipped and counted as such.

It prints counts only, never a command: per group (files directly under the directory are main sessions; files under a tasks directory are helpers) the bash calls, those allowed by plain-line, those allowed by another rule or stage, those a rule denied, the rest, the refusals by reason, and the 20 most common head words of refused lines, a head holding a slash shown as (path). It says in its output that it reads today’s files and each session’s starting directory, so it is an estimate.

bashCalls and sessionFiles are exported from tools/lib/shell-field.mjs for it.

Prediction on file: 20 % to 35 % of main-session bash calls allowed by plain-line in each of pi, canopy and craig on luchs. Decision rule, fixed here: the key ships on when at least two of the three reach 15 %. Otherwise modes.json is left without the key, everything else ships, and the numbers go to the operator. The numbers are recorded in the MR either way.

Prerequisite (#923, merged first)

By reading, a shipped allow already passes two things as a single command: git show HEAD:.env.local (the corpus’s critical deny cred-git-show-env-file) and git’s --output=FILE, which writes a file in plan mode. Both are pre-existing, so they are one fix: issue with its own branch.

Its fix: two ask rules on the bash surface of auto, plan and manual in modes.json: git show : (a file’s content at a revision is the judge’s, as cat of it is) and git*--output*. Each is more specific than the allow it narrows (specificity, mode-policy.ts), so evaluateLine reports ask for the single command and for the command inside a line alike. Its regression test is packages/pi-modes/test/eval-rules.test.ts, described under Tests, created there without the plain-line assertion; any other case that test exposes on main is fixed in that issue too. This plan needs nothing more from it than step 3 above.

Not in this plan

  • A helper’s asks and a remote (SSH) session’s asks. Both stay with the judge. An issue is filed for each once the field tool shows their share.

  • A workspace reached under two mount paths (luchs’s ~/code is also /data/code): a path spelled the other way lands outside by realLocation and stays with the judge. @gadhs/pi-workspace’s `canonicalOf knows both spellings but is asynchronous; an issue is filed if the field tool shows the cost.

  • More roster names. Each is added on the field tool’s evidence, with its own proof and tests.

  • #901’s single decision pipeline.

Scope

  • New: packages/pi-bash/plain.ts, packages/pi-bash/test/plain.test.ts.

  • packages/pi-bash/structure.ts: commandArgv returns quoting; WordQuoting exported. packages/pi-bash/index.ts: exports plainCommands, PLAIN_NODE_TYPES, PlainCommand, PlainWord, WordQuoting. packages/pi-bash/test/differential.test.ts: a third reading.

  • New: packages/pi-modes/plain-line.ts, packages/pi-modes/test/plain-line.test.ts. Extended: packages/pi-modes/test/eval-rules.test.ts (created by the prerequisite).

  • packages/pi-modes/mode-policy.ts: export bashLineOf; add commandAllow; the header comment.

  • packages/pi-modes/authorize.ts: readAtHome, plainLineOutcome, plainLineAllow, the chain, the header’s order list.

  • packages/pi-modes/config.ts, packages/pi-modes/modes.json: the key.

  • packages/pi-modes/standing-approval.ts: the reason text and the header comment.

  • packages/pi-modes/test/authorize.test.ts: new cases, and two existing ones changed (Tests).

  • New: tools/lib/plain-line-field.mjs, tools/lib/test/plain-line-field.test.mjs. tools/lib/shell-field.mjs: two exports. tools/task.mjs: the verb. tools/consumer-sim.mjs: one live row.

  • Docs and CHANGELOG (Delivery).

Checked by search, and unaffected: every other test that puts a bash ask through the gate either gives it no cwd (deps() in authorize.test.ts), or asks a line the stage does not clear (pending-wiring.test.ts, job-tools.test.ts, monitor-tools.test.ts), or accepts any verdict (judge-wiring-callback.test.ts, the adversarial shapes). The battery’s judge task (tools/model-battery/drivers/judge.mjs) and task eval (packages/pi-modes/eval/run.ts) call runJudge directly, not authorizeAsk, so their numbers do not move.

Risks

  • A roster command has a writing or executing option the list lets through. Fail-open. Options are allowlisted per command and an unknown one refuses; commands with an output-file positional (uniq) take no operand; the proof table in plain-line.test.ts holds one refused case per excluded option family.

  • The parser reads a line differently from bash. Fail-open. The node allowlist is closed, any stray word refuses, and differential.test.ts compares the words plainCommands reports with what real bash ran.

  • A path lands somewhere else at run time. Fail-open. Directories accumulate and never narrow, links are followed by realLocation, and a plain line writes nothing, so the line itself cannot move what it reads. Another process swapping a link between the check and the run is accepted, as it is for the workspace-write stage.

  • A secret in a file whose name is not credential-shaped is printed by a cleared cat. Fail-open, and equal to what the read tool’s workspace-read stage already allows. The name list is the shared one; a tree-wide content search is refused.

  • An operator’s allow rule now applies inside a plain line. Fail-open against what tuning.adoc says today. The valve and the high-consequence list still come first; the page and the #475 contract test change with it.

  • The stage cannot decide. Fail-closed: a cold parser, a helper’s ask, a remote session, no directory, any unknown construct all leave the line with the judge, at today’s cost.

  • The field tool misestimates. Silent. It says it reads today’s files; the decision rule leaves a margin under the prediction; after release the share is read from real ask.verdict records.

  • A path is mapped wrongly on Windows. Fail-closed in the cases reasoned through (an unmapped path lands outside and refuses). pi-win runs the suites and the field tool there before the merge.

Tests

Unit (packages/pi-bash/test/plain.test.ts):

  • A plain line yields its commands: text, words, quoting of each kind, inPipeline. cd ~/code/x && ls is plain, its second word ~/code/x, bare.

  • Never plain, one case each: command substitution, backticks, a variable, arithmetic, a subshell, a brace group, if, for, while, case, a function, a heredoc, a here-string, an input redirect, a write to a file, an append to a file, &> to a file, a background &, a negation, [ ], [[ ]], an assignment prefix, an assignment statement, export, a word after a redirect’s destination, a syntax error, an empty line, a cold parser.

  • PLAIN_NODE_TYPES equals the fifteen names above, so a new one is a reviewed change.

Property (packages/pi-bash/test/differential.test.ts): wherever plainCommands answers for a generated line, its words are the argvs real bash ran. The count compared is asserted greater than zero.

Unit (packages/pi-modes/test/plain-line.test.ts): one cleared and one refused case per roster name, each refusal by its reason; the three shared rules; a non-roster command cleared only by allowedByRule; a roster command never rescued by allowedByRule. For the directory set: in cd sub; cat x, readable is asked about x from both the starting directory and sub, and the line is refused when either answer is no.

Property (plain-line.test.ts, fast-check): a line holding any command that is neither cleared by its proof nor allowed by rule is never cleared, wherever it sits; appending such a command to a cleared line always refuses it.

Regression, the gate (packages/pi-modes/test/authorize.test.ts), in a real temporary workspace with a registry that throws when asked:

  • cd . && grep -n x a.ts | head -5 is { kind: "allow", source: "rule", pattern: "plain-line" }, in auto and in plan.

  • Not allowed by rule, with a registry that records being reached: a helper’s ask; a remote workspace; no cwd; a cold parser; a credential-shaped file; a path outside the workspace; a link inside the tree pointing out (skipped visibly without symlink privilege); cd /etc && cat passwd; grep -rn x .. In manual the same first line defers with source mode.

  • A valve pattern on a cleared command defers by the valve; a high-consequence pattern defers before the stage.

  • Changed: "two rule-allowed commands together are still the judge’s" gains a cwd and asserts the plain-line allow, and keeps a second assertion that without a cwd the judge is reached.

  • Changed, contract (#475): the standing approval’s exact command after cd /tmp && is allowed when a cwd is given; with an extra argument, or another project, it still reaches the judge.

Regression, the corpus (packages/pi-modes/test/eval-rules.test.ts): every case of corpus.json is put through authorizeAsk in its mode, built by detailsFor (eval/run.ts), in a real temporary workspace, with a registry that records being reached. Whenever the gate allows without reaching it, the case’s expected set contains allow. This plan adds: at least two cases are allowed with pattern plain-line (by reading, the corpus’s names-only and count-only tree searches), so the stage is exercised by it. It pins that the stage allows nothing the corpus says must not be allowed.

Unit (tools/lib/test/plain-line-field.test.mjs): a fixture directory with a main session (one cleared line, one refused for tree-search, one the judge would get) and a helper file under tasks gives exactly those counts per group, the third line under "the rest" since the tool passes no registry, and no command text appears in the output.

Contract, live (tools/consumer-sim.mjs): on the installed distribution, pi -a --model vertex-anthropic/claude-haiku-4-5 -p in the scratch repo, as the READY row runs it, with GADHS_PI_DIAGNOSTICS naming a file of its own. The prompt tells the model to run exactly cd . && ls | head -3. The row passes when that file holds an ask.verdict record whose pattern is plain-line; a run with none is repeated once, then fails. Skipped under --no-model.

Delivery

  1. #923 is fixed and merged.

  2. This branch: the pi-bash view, then the decision and the stage, then the field tool. Run the field tool on luchs for the three projects; pi-win runs the suites and the tool on Windows. Apply the decision rule.

  3. Docs, with the change: modes.adoc is the canonical page (the rules table’s two rows that say a compound line is always the judge’s, the paragraph on how a line is matched, and a plainLines row beside workspaceReads, with the roster). Also judge.adoc and tuning.adoc (the standing-approval bullets), diagnostics.adoc (gadhs_plain_line.allow), local-dev.adoc (the task verb), public-surface.adoc (pi-bash’s stable names).

  4. CHANGELOG.adoc, == Unreleased, Changed, with the measured share.

  5. MR with Closes #888; after the merge, the merge SHA on the issue, with the two deferred issues named.

Edit this page · latest