Skip to content

fix(guard-bash): resolve path arguments through one resolver (closes #3988) - #3997

Merged
apmantza merged 8 commits into
apmantza:masterfrom
drakeo338:claude/3988-fix
Oct 7, 2026
Merged

apmantza merged 8 commits into
apmantza:masterfrom
drakeo338:claude/3988-fix

Conversation

@drakeo338

@drakeo338 drakeo338 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Why

A git worktree remove path spelled with ~, $HOME, $VAR, a relative path after cd/git -C, a .. through a symlink, or $(...) no longer slips past the #3173 shared-node_modules guard, and no command substitution beside a rule word hides a command master denied.

Notes for the reviewer

  • Contributor commit 821e37d (drakeo338: ~/$HOME/${HOME} on the remove path) is kept with its authorship; maintainer rounds sit on top. Round 4 is one commit, fix(guard-bash): two substitution readings (#3988), after a merge of origin/master.
  • Round 4 is the fourth round on this lexer/resolver seam. The state-space table (section "Round 4") was posted to this body before the first code edit; its r4 column is now measured on this head: 133 of 133 cells give the expected rule.
  • Decision for the orchestrator (unchanged from round 2): an unresolvable path fails closed for git worktree remove only. The tmp-checkout hygiene rules stay fail-open on it.
  • Decision for the orchestrator (new, bash semantics): git's path words are expanded without the command's inline VAR=val prefix, because bash expands the words first (measured: TMPDIR=/home/dev/scratch printf %s "$TMPDIR/foo" prints the shell's value). So TMPDIR=/tmp git worktree add $TMPDIR/x now allows when the ambient TMPDIR is off /tmp, where master denied: the tree really lands under the ambient TMPDIR. In the differential fuzz below this family is the only master deny that becomes an allow, and only with an off-/tmp ambient TMPDIR (0 with TMPDIR unset, the CI shape). The TMPDIR= row in the test file is re-pinned in both shapes.
  • Visible cost (unchanged): historical orchestrator commands that remove worktrees through a loop variable or glob deny with worktreeUnresolved (66 expected corpus denies, as pinned in round 3). The sanctioned bulk removal is node scripts/prune-agent-worktrees.mjs.

Change outline

- classifyPayload scripts/hooks/guard-bash.mjs
  - findDeny scripts/hooks/guard-bash.mjs:2609
    + two readings of a command holding a substitution: mark kept (unknown), then marks removed (empty)
    - classifySegment scripts/hooks/guard-bash.mjs:2155
      - commandBasename(stripSubstitutionMark(rest[0])) -> commandBasename(rest[0])
      + classifyGit(args, cwd, effectiveEnv, sharedEnv)   (was a sharedEnv copy plus the __PI_LENS_INLINE_HOME sentinel)
      - classifyGit scripts/hooks/guard-bash.mjs:1429
        - args.map(stripSubstitutionMark) / rawArgs
        + expansionEnv parameter for path words; env (inline prefix included) for classifyHookBypass
        + gitCwd: the -C walk computed once (gitInvocationCwd deleted)
        - resolveShellPath scripts/hooks/guard-bash.mjs:1234
          + realpathSync.native for every non-cd path (kernel resolution); logical flag for cd
          - realpathSync(path) !== path guard (inert)
          - expandShellWord scripts/hooks/guard-bash.mjs:1178
            - identifier-valued pre-loop and the two chain-bound reasons
            + tilde step after the last hop; cap restored to 8
            - lookupShellVariable: __PI_LENS_INLINE_HOME branch
    - cwdAfterSegment scripts/hooks/guard-bash.mjs:2665
      + resolveShellPath(target, cwd, env, true)
    - stripCommandGroupAndRunnerPrefixes: three stripSubstitutionMark calls
- deleted: stripSubstitutionMark, gitInvocationCwd (49 top-level functions, as on master)

Summary

Closes #3988. Every acceptance criterion holds after this round:

  • ~, $HOME, ${HOME} and relative paths resolve against the command's effective cwd before the check; an unresolvable path fails closed with the named rule worktreeUnresolved (rows "fails closed (named rule) on an unresolvable path", "round 4 remove cell").
  • Red-first rows for each spelling run through the real hook entry, with mutations on the expansion (rounds 2 and 4 below).
  • Every guard-bash rule that tests a path argument uses the one resolver (member list in "Class sweep"; rm has no rule).

Root cause of the round-3 regressions: c0184f1 kept the substitution mark in word text and stripped it at three call sites. Stripping turned a whole-word substitution into "", which skipped the remove check (H2), and the other word consumers (checkUngated, mktemp flags, a split word) still saw the mark. The inline-HOME fix handed classifyGit an env without the inline prefix, so the hook-bypass check lost HUSKY=0 (H1). The .. guard compared the lexically normalized path with its own realpath, which is never the kernel's path (H3).

The rule (derived from the table; full text in "Round 4"): a substitution's output is unknown, so findDeny reads a command that holds one twice, first with the mark as opaque word text, then with the marks removed, and denies if either reading denies.

scripts/hooks/guard-bash.mjs:2609

export function findDeny(commandText, cwd) {
	const unknownReading = scannableRegions(commandText);

Git's own env and its path words' env are now separate parameters:

scripts/hooks/guard-bash.mjs:2190

	if (cmd === "git") return classifyGit(args, cwd, effectiveEnv, sharedEnv);

A path a program hands the kernel resolves physically; a cd target stays logical:

scripts/hooks/guard-bash.mjs:1242

			path = realpathSync.native(isAbsolute(text) ? text : `${anchor}/${text}`);

Type of change

  • Bug fix
  • New feature (net-new capability)
  • Enhancement (improvement to existing capability)
  • Documentation

Area

  • area:lsp
  • area:dispatch
  • area:installer
  • area:diagnostics
  • area:read-guard
  • area:project-intelligence
  • area:perf
  • area:observability
  • area:session
  • area:config
  • area:security
  • area:tests

Checklist

  • I have read CONTRIBUTING.md and AGENTS.md
  • The change has tests (happy path, edge cases, regression test for bugs)
  • Targeted test files for the touched seams pass locally after npm run build; the full suite is CI's job.
  • Every NEW regression test is proven RED on pre-fix code; the red output is quoted in this PR
  • New guards/branches/filters/caps/fallbacks have compile-valid hand-mutation proof (AGENTS.md, one PR mutation layer)
  • PR title carries the conventional prefix and the issue ref
  • npm run lint passes
  • npm run build:dist succeeds if I changed code under clients/, commands/, tools/, or index.ts
  • package-lock.json is in sync with package.json (regenerate with the exact npm pin in package.json's packageManager field)
  • AGENTS.md is updated if this PR changes behavior, commands, conventions, or invariants documented there
  • .changelog/<branch-or-slug>-<short-desc>.md has one valid entry in this PR for any user-facing change (Added/Changed/Deprecated/Removed/Fixed/Security), with audience: user or audience: internal — see .changelog/README.md; internal-only test/refactor PRs may skip it
  • Commit subject includes the issue number: (closes #NNN) or (refs #NNN)

Tests

Round 4, tests/scripts/guard-bash-hook.test.ts, all through runHook (stdin JSON, exit code, stderr compared with RULE_MESSAGES):

  • New ROUND4_REMOVE_ROWS in the describe "path-argument resolver (guard-bash: #3173 shared-node_modules worktree-remove guard misses ~/ and $HOME/ path spellings #3988)": H2 (whole-word $(...)/backticks, --force/-- then "$(...)", a $(...) word before the path, unquoted git -C $(pwd)), H3 (symlink then ..: relative, $PWD, after git -C, as the -C directory, after cd; plus the allow row "a cd target stays logical"), F4 (HOME= inline), F5 (8-variable chain resolves, 9-variable chain fails closed, identifier-valued variable is a literal word). The fixture gains HOME/away/lnk -> ../scratch/wt; no new git spawn.
  • New describe "substitution next to a rule word (fix(guard-bash): resolve path arguments through one resolver (closes #3988) #3997)": 12 deny rows (the split-word family, checkUngated, mktemp, worktree add, clone, and H1 with a substitution) and 3 allow rows (git commit -m "$(cat msg.txt)", echo $(git rev-parse HEAD), git -C "$(...)" status).
  • Edited: "an inline TMPDIR= does not move a $TMPDIR-shaped destination: bash expands the word first" replaces the row that read the runner's ambient TMPDIR (green on the lane, red in CI); it now pins both ambient shapes explicitly.
  • Edited: "fails closed for the reviewed resolver blind spots (fix(guard-bash): resolve path arguments through one resolver (closes #3988) #3997 F3-F6)" loses its HOME= and fake-chain rows (moved, with bash-correct verdicts, to ROUND4_REMOVE_ROWS); "keeps a substitution mark from fusing into the surrounding rule word (fix(guard-bash): resolve path arguments through one resolver (closes #3988) #3997 F1)" loses its splitWords line, which asserted the mark's own placement and passed on the pre-round source.
  • tests/config/agents-governance.test.ts: the shape-count pin moves 60 -> 61 for the new numbered shape 61.

Red on c0184f1 (the round-4 test file against c0184f1's hook; -t "round 4|#3997|3778|hook bypass|inline TMPDIR|whole path from a quoted"):

     × round 4 remove cell: H2 unquoted $(...) as the whole path
     × round 4 remove cell: H3 a relative path through a symlink, t…
     × round 4 remove cell: F4 an inline HOME= does not change what…
     × round 4 remove cell: F5 an 8-variable $ chain ending in ~ re…
     × round 4 remove cell: F5 an identifier-valued variable is a l…
     × denies git $(:) stash
     × denies npm$(:) run lint; git$(:) commit -m x
     × denies HUSKY=0 git $(:) commit -m x
     × denies "HUSKY=0 git commit -m x" through the real hook entry
AssertionError: expected '' to be 'git worktree remove on a path this ho…' // Object.is equality
AssertionError: expected '' to be 'git stash is forbidden (CLAUDE.md non…' // Object.is equality
AssertionError: expected +0 to be 2 // Object.is equality
      Tests  32 failed | 107 passed | 853 skipped (992)

Not red on c0184f1, kept as pins: "H2 an unquoted $(...) as the git -C directory", "H3 a cd target stays logical", "F5 a 9-variable $ chain fails closed at the bound", the three allow rows, and the re-pinned TMPDIR row (c0184f1's verdict there is ambient-dependent: tmpCheckout with TMPDIR /tmp or unset, null with an off-/tmp TMPDIR, measured through findDeny on c0184f1's hook).

Green on this head: tests/scripts/guard-bash-hook.test.ts Tests 992 passed (992), Duration 148.99s; corpus line guard-bash transcript corpus: 1122 rows, 66 expected denies, 88332ms (cap 180 000 ms). The TMPDIR row passes with TMPDIR unset and with the lane TMPDIR. Governance batch (ls tests/clients/*{sweep,ratchet,conformance,coverage,gate,governance,silence,hermeticity,invariant,contract}*.test.ts plus tests/config/*.test.ts, 134 files) through npm run test:targeted: Test Files 134 passed (134), Tests 1871 passed | 1 skipped (1872). tests/scripts/stryker-diff.test.ts and tests/scripts/pr-worktree.test.ts: 165 passed. npm run lint (pre-commit), npx oxfmt --check on every touched file, npm run astgrep:self-scan (clean: 0 finding(s)), node scripts/check-changelog-fragments.mjs (changelog fragments OK) all pass.

Mutations (compile-valid, scripts/hooks/guard-bash.mjs mutated in place and restored with git checkout HEAD --; filter: the whole file minus the corpus, baseline 991 passed | 1 skipped):

Mutation Result
M0 the verify's remedy alone: mark zero-width in splitWords, one reading 12 failed: $(...) inside the path, whole path from a quoted $(...), relative path after cd $(...), every H2 row
M1 unknown reading off (empty only) 16 failed: M0's 12 rows plus the 4 $(printf C)/backtick coproc label rows
M2 empty reading off (unknown only) 13 failed: all 12 "substitution next to a rule word" deny rows and the F1 row
M3 hook-bypass check reads the shell env 8 failed: the six #3778 inline-env rows and the two H1-with-substitution rows
M4 git path words expanded with the inline prefix 2 failed: F4 inline HOME, the TMPDIR row
M5 physical resolution off (lexical) 5 failed: every H3 deny row
M6 cd target resolved physically 1 failed: "H3 a cd target stays logical"
M7 last-hop tilde not expanded 1 failed: "F5 an 8-variable $ chain ending in ~ resolves"
M8 leftover-$ reason off 8 failed, including "F5 a 9-variable $ chain fails closed at the bound"
M9 git -C walk off 10 failed (the -C deny, unresolved and tmp-checkout rows)
M10 mark not recorded as a dynamic expansion (#3949 coproc) 4 failed: the $(printf C)/backtick coproc label rows
M11 prior-round spot check (b950180 M21: subshell cwd stack off) 1 failed: "a subshell's cd does not leak out"

One guard was mutation-inert and was deleted: the .. condition on the physical step (forcing a realpath on every non-cd path changed no verdict in the file or the corpus), so every path git or mktemp hands the kernel resolves physically.

Differential fuzz against origin/master (in-process findDeny, 34 seeds, $(:), backticks, $(printf x), "$(:)" inserted at every word boundary, every character position and every word end; 3586 variants, payload cwd off /tmp):

ambient TMPDIR off /tmp: masterDenies=3010 bothDeny=2855 masterDeny&candAllow=155 candDeny&masterAllow=306
ambient TMPDIR unset:    masterDenies=3052 bothDeny=3052 masterDeny&candAllow=0   candDeny&masterAllow=306
c0184f1, TMPDIR off:     masterDenies=3010 bothDeny=2019 masterDeny&candAllow=991 candDeny&masterAllow=138

All 155 are the TMPDIR=/tmp git worktree add $TMPDIR/x family (decision note above). The 306 added denies are 303 tmpCheckout from the TMPDIR=/tmp mktemp -d $TMPDIR/x.XXXX family (Residuals) and 3 contrived coproc $(:) C { … } rows.

Test assessment

tests/scripts/guard-bash-hook.test.ts pins the hook's decisions through the real entry. Removed: the splitWords assertion on the mark's own placement (vacuous: it passed on the pre-round source and pinned the implementation), and the two F3-F6 rows that asserted non-bash verdicts (an inline HOME= is not the expansion HOME; A=B; … $A is the literal word B); their shapes survive in ROUND4_REMOVE_ROWS, where M4 and the F5 rows red. tests/config/agents-governance.test.ts: count pin only.

Blast radius

scripts/hooks/guard-bash.mjs only, plus tests, AGENTS.md (numbered shape 61 and one line in "Git guard and host adapters"), one changelog fragment (the round-3 second fragment is deleted). Callers above: run -> classifyPayload -> findDeny; findDeny -> classifySegment -> classifyGit, classifyMktemp, classifyNode; findDeny -> cwdAfterSegment. Callees below: resolveShellPath (callers: the -C walk, remove, add, clone in classifyGit; classifyMktemp; cwdAfterSegment), expandShellWord (resolveShellPath, classifyMktemp, classifyNode), lookupShellVariable. Not a hot path: one short-lived process per Bash call; a command holding a substitution is scanned twice, and one realpath runs per path argument. The corpus of 1122 real commands keeps its 66 expected denies. module_report blastRadius does not index this bare-Node hook script.

Observability

none: the guard is a PreToolUse hook whose only observable output is its deny message on stderr and its exit code, asserted row by row through the real hook entry in tests/scripts/guard-bash-hook.test.ts; it keeps no degradation ledger or session record, and every new branch is a deny or an allow, not a swallowed failure.

Class sweep

Shape: AGENTS.md shape 61 (new), "Stand-in for unknown text stripped per consumer", next to shape 43. Population: every guard-bash consumer of split words, grepped for splitWords( (5 call sites: classifySegment, classifyCheckOrWrite, findPipedCiVerdictStatusRead twice, cwdAfterSegment) and for every rule word they feed: classifyGit (subcommand, flags, hook-bypass env, paths), argv0 and prefix stripping, classifyNode, classifyMktemp, classifyPkillKillall, the checkUngated chain scan, the ci-verdict pipe rule (M = 7, as the verify counted). c0184f1 stripped the mark in 3 of 7. Verdict: fold at the one seam that sees every consumer, findDeny; no consumer reads the mark specially except the path resolver (expandShellWord) and the coproc label check (canFormCoprocIdentifier via WORD_EXPANSIONS). The three call-site strips and stripSubstitutionMark are deleted.

Path-argument members (every guard-bash rule that takes a path, grepped for resolve(, isAbsolute(, process.cwd(), realpathSync(, existsSync(, readlinkSync():

Member Verdict
git worktree remove <path> resolveShellPath, physical, fail closed
git worktree add <path>, git clone <repo> <dir> resolveShellPath, physical, fail open
git -C <dir> the one gitCwd walk in classifyGit, physical
mktemp -d template, -p/--tmpdir= expandShellWord on the template, resolveShellPath on the directory
cd/pushd/popd cwdAfterSegment, logical
node <file> expandShellWord; repository identity stays (#3680)
rm targets no rule exists
pkill -f pattern a regex, not a path
node_modules link target a filesystem link, not a shell word

Consolidation verdict: one resolver; deleting it would put an expander back into six callers.

Residuals

  • mktemp and node words still expand with the command's inline prefix, as on master, so TMPDIR=/tmp mktemp -d $TMPDIR/x.XXXX denies although bash creates it under the ambient TMPDIR (a false deny, the safe direction), and TMPDIR=/off mktemp -d $TMPDIR/x.XXXX allows with an ambient /tmp TMPDIR (a hygiene false allow). Flipping them needs separate program and word envs inside classifyMktemp; not folded, because it turns master denies into allows. Not filed (this lane has no issue grant): orchestrator decision.
  • cd -P lnk/.. is tracked logically (documented in cwdAfterSegment).
  • guard-bash: guarded commands built from substitution output bypass the hook #4025 (a guarded word built from substitution output, git $(printf stash)) stays out of scope; it allows on master and here.

Round 4 (state space first, written before any edit)

Fourth round on the guard-bash lexer/resolver seam, so this section was posted before the first code edit. Every cell below ran through the real hook entry (node scripts/hooks/guard-bash.mjs, PreToolUse JSON on stdin) against a fixture: FX is a git repo and the payload cwd and HOME; FX/linked is a linked worktree whose node_modules is a symlink outside it; FX/clean has a real node_modules; FX/scratch/lnk -> ../linked. Columns master (01b525fb5) and c0184f1 were measured before the first edit and expected was written then; the r4 column is this head, measured after the change (133 of 133 cells give the expected rule).

Measured before the table, to set the expectations:

  • git worktree remove --force scratch/lnk/../linked (from FX) removed FX/linked: git resolves the raw path physically, so the kernel follows lnk before ...
  • Node's fs.realpathSync("FX/scratch/lnk/../linked") throws ENOENT (it normalizes .. lexically first); fs.realpathSync.native returns FX/linked. This is why c0184f1's realpathSync(path) !== path guard is inert.
  • cd scratch/lnk/.. && pwd prints FX/scratch: bash's cd is logical, so cd targets stay lexical.
  • TMPDIR=/home/dev/scratch printf %s "$TMPDIR/foo" prints the shell's TMPDIR, not the inline value: bash expands every word before the command's inline assignments take effect.

The rule

A command substitution's output is not known statically. The hook reads each region twice and denies when either reading denies:

  1. Unknown reading: the substitution is one opaque piece of word text (the U+E000 mark lexRegions leaves). No rule word matches it, and a path that holds it cannot be resolved (worktreeUnresolved for git worktree remove).
  2. Empty reading: the substitution printed nothing. The mark is removed, which is exactly the text master scanned; an unquoted word made only of substitutions then vanishes, as bash drops an empty unquoted expansion.

The two other axes follow bash too. A git path word is expanded with the shell's variables (earlier export and standalone assignments, then the hook's ambient env), never with the same command's inline VAR=val prefix; the program's own reads (the hook-bypass env check) see the prefix. A path git hands to the kernel is judged where the kernel puts it: with a .. segment, the unnormalized path is resolved physically. A cd target stays logical.

The verify's remedy (strip the mark in splitWords to a zero-width WORD_EXPANSIONS entry) is the empty reading alone. Measured as mutation M0 (Tests section): it leaves 12 reds, among them git worktree remove $(echo linked) loses its only positional, and git -C $(pwd) worktree remove linked reads worktree as -C's value, so both allow; and the expansion table does not survive the prefix slices between splitWords and classifyGit. The two-reading rule keeps the remedy's deletions (the three call-site strips and stripSubstitutionMark) without those gaps.

Findings (review-3997-r2)

Id Disposition
H1 inline HUSKY=0/PI_LENS_SKIP_HOOKS= allowed fixed: classifyGit reads git's env for the bypass check, the shell variables for path words; the sentinel is gone (M3, M4)
H2 whole-word substitution as the remove path fixed by the unknown reading (rows H2, M0, M1)
H3 symlink .. fixed: physical resolution for every path git or mktemp hands the kernel, logical for cd (M5, M6)
split-word family (a substitution split from, fused into, or before a rule word) fixed by the empty reading: the deny rows in "substitution next to a rule word (#3997)" (M2)
M4 mechanism (strip per call site) replaced: the three strips and stripSubstitutionMark deleted; the remedy alone measured as M0
M5/F5 no real chain test fixed: 8- and 9-variable $ chains through the real hook; the non-bash identifier pre-loop deleted (M7, M8)
M6/F7 helper count fixed: 49 top-level functions, as on master (stripSubstitutionMark, gitInvocationCwd deleted)
M7 CI: second changelog fragment fixed: one fragment
M7 CI: TMPDIR row fixed: re-pinned in both ambient shapes
L8 records fixed: title, body and commit say closes; commit body uses real newlines; AGENTS.md shape is numbered 61 beside shape 43, with the mechanism findDeny implements

Table

cell command master c0184f1 r4 expected
A command word / none git stash stash stash stash stash
A command word / $(…) own word $(printf x) git stash stash allow stash stash
A command word / backtick fused git`:` stash stash stash stash stash
A command word / empty $(:) fused git$(:) stash stash stash stash stash
A command word / empty $(:) own word $(:) git stash stash allow stash stash
A command word / split gi$(:)t stash stash stash stash stash
A git subcommand / none git stash stash stash stash stash
A git subcommand / $(…) own word git $(printf x) stash stash allow stash stash
A git subcommand / backtick fused git stash`:` stash stash stash stash
A git subcommand / empty $(:) fused git stash$(:) stash stash stash stash
A git subcommand / empty $(:) own word git $(:) stash stash allow stash stash
A git subcommand / split git st$(:)ash stash stash stash stash
A flag suffix / none git commit --no-verify -m x hookBypass hookBypass hookBypass hookBypass
A flag suffix / $(…) own word git commit $(printf x) --no-verify -m x hookBypass hookBypass hookBypass hookBypass
A flag suffix / backtick fused git commit --no-verify`:` -m x hookBypass hookBypass hookBypass hookBypass
A flag suffix / empty $(:) fused git commit --no-verify$(:) -m x hookBypass hookBypass hookBypass hookBypass
A flag suffix / empty $(:) own word git commit $(:) --no-verify -m x hookBypass hookBypass hookBypass hookBypass
A flag suffix / split git commit --$(:)no-verify -m x hookBypass hookBypass hookBypass hookBypass
B HUSKY=0 / subcommand / none HUSKY=0 git commit -m x hookBypass allow hookBypass hookBypass
B HUSKY=0 / subcommand / $(…) own word HUSKY=0 git $(printf x) commit -m x hookBypass allow hookBypass hookBypass
B HUSKY=0 / subcommand / backtick fused HUSKY=0 git commit`:` -m x hookBypass allow hookBypass hookBypass
B HUSKY=0 / subcommand / empty $(:) fused HUSKY=0 git commit$(:) -m x hookBypass allow hookBypass hookBypass
B HUSKY=0 / subcommand / empty $(:) own word HUSKY=0 git $(:) commit -m x hookBypass allow hookBypass hookBypass
B HUSKY=0 / subcommand / split HUSKY=0 git co$(:)mmit -m x hookBypass allow hookBypass hookBypass
B PI_LENS_SKIP_HOOKS=1 / subcommand / none PI_LENS_SKIP_HOOKS=1 git commit -m x hookBypass allow hookBypass hookBypass
B PI_LENS_SKIP_HOOKS=1 / subcommand / $(…) own word PI_LENS_SKIP_HOOKS=1 git $(printf x) commit -m x hookBypass allow hookBypass hookBypass
B PI_LENS_SKIP_HOOKS=1 / subcommand / backtick fused PI_LENS_SKIP_HOOKS=1 git commit`:` -m x hookBypass allow hookBypass hookBypass
B PI_LENS_SKIP_HOOKS=1 / subcommand / empty $(:) fused PI_LENS_SKIP_HOOKS=1 git commit$(:) -m x hookBypass allow hookBypass hookBypass
B PI_LENS_SKIP_HOOKS=1 / subcommand / empty $(:) own word PI_LENS_SKIP_HOOKS=1 git $(:) commit -m x hookBypass allow hookBypass hookBypass
B PI_LENS_SKIP_HOOKS=1 / subcommand / split PI_LENS_SKIP_HOOKS=1 git co$(:)mmit -m x hookBypass allow hookBypass hookBypass
B env HUSKY=0 runner env HUSKY=0 git commit -m x hookBypass allow hookBypass hookBypass
B export HUSKY=0 export HUSKY=0; git commit -m x hookBypass hookBypass hookBypass hookBypass
B HUSKY=1 (not a bypass) HUSKY=1 git commit -m x allow allow allow allow
C no env / literal / none git worktree remove FX/linked worktreeSymlink worktreeSymlink worktreeSymlink worktreeSymlink
C no env / literal / $(…) git worktree remove "$(echo FX/linked)" allow allow worktreeUnresolved worktreeUnresolved
C no env / literal / backtick git worktree remove `echo FX/linked` allow allow worktreeUnresolved worktreeUnresolved
C no env / literal / empty $(:) fused git worktree remove FX/linked$(:) worktreeSymlink worktreeUnresolved worktreeUnresolved worktreeUnresolved
C no env / literal / split git worktree remove FX/lin$(:)ked worktreeSymlink worktreeUnresolved worktreeUnresolved worktreeUnresolved
C no env / tilde / none git worktree remove ~/linked allow worktreeSymlink worktreeSymlink worktreeSymlink
C no env / tilde / $(…) git worktree remove "$(echo ~/linked)" allow allow worktreeUnresolved worktreeUnresolved
C no env / tilde / backtick git worktree remove `echo ~/linked` allow allow worktreeUnresolved worktreeUnresolved
C no env / tilde / empty $(:) fused git worktree remove ~/linked$(:) allow worktreeUnresolved worktreeUnresolved worktreeUnresolved
C no env / tilde / split git worktree remove ~/lin$(:)ked allow worktreeUnresolved worktreeUnresolved worktreeUnresolved
C no env / home / none git worktree remove $HOME/linked allow worktreeSymlink worktreeSymlink worktreeSymlink
C no env / home / $(…) git worktree remove "$(echo $HOME/linked)" allow allow worktreeUnresolved worktreeUnresolved
C no env / home / backtick git worktree remove `echo $HOME/linked` allow allow worktreeUnresolved worktreeUnresolved
C no env / home / empty $(:) fused git worktree remove $HOME/linked$(:) allow worktreeUnresolved worktreeUnresolved worktreeUnresolved
C no env / home / split git worktree remove $HOME/lin$(:)ked allow worktreeUnresolved worktreeUnresolved worktreeUnresolved
C no env / relative / none git worktree remove linked worktreeSymlink worktreeSymlink worktreeSymlink worktreeSymlink
C no env / relative / $(…) git worktree remove "$(echo linked)" allow allow worktreeUnresolved worktreeUnresolved
C no env / relative / backtick git worktree remove `echo linked` allow allow worktreeUnresolved worktreeUnresolved
C no env / relative / empty $(:) fused git worktree remove linked$(:) worktreeSymlink worktreeUnresolved worktreeUnresolved worktreeUnresolved
C no env / relative / split git worktree remove lin$(:)ked worktreeSymlink worktreeUnresolved worktreeUnresolved worktreeUnresolved
C no env / symlink-.. / none git worktree remove scratch/lnk/../linked allow allow worktreeSymlink worktreeSymlink
C no env / symlink-.. / $(…) git worktree remove "$(echo scratch/lnk/../linked)" allow allow worktreeUnresolved worktreeUnresolved
C no env / symlink-.. / backtick git worktree remove `echo scratch/lnk/../linked` allow allow worktreeUnresolved worktreeUnresolved
C no env / symlink-.. / empty $(:) fused git worktree remove scratch/lnk/../linked$(:) allow worktreeUnresolved worktreeUnresolved worktreeUnresolved
C no env / symlink-.. / split git worktree remove scratch/lnk/../lin$(:)ked allow worktreeUnresolved worktreeUnresolved worktreeUnresolved
C HUSKY=0 / literal / none HUSKY=0 git worktree remove FX/linked worktreeSymlink worktreeSymlink worktreeSymlink worktreeSymlink
C HUSKY=0 / literal / $(…) HUSKY=0 git worktree remove "$(echo FX/linked)" allow allow worktreeUnresolved worktreeUnresolved
C HUSKY=0 / literal / backtick HUSKY=0 git worktree remove `echo FX/linked` allow allow worktreeUnresolved worktreeUnresolved
C HUSKY=0 / literal / empty $(:) fused HUSKY=0 git worktree remove FX/linked$(:) worktreeSymlink worktreeUnresolved worktreeUnresolved worktreeUnresolved
C HUSKY=0 / literal / split HUSKY=0 git worktree remove FX/lin$(:)ked worktreeSymlink worktreeUnresolved worktreeUnresolved worktreeUnresolved
C HUSKY=0 / tilde / none HUSKY=0 git worktree remove ~/linked allow worktreeSymlink worktreeSymlink worktreeSymlink
C HUSKY=0 / tilde / $(…) HUSKY=0 git worktree remove "$(echo ~/linked)" allow allow worktreeUnresolved worktreeUnresolved
C HUSKY=0 / tilde / backtick HUSKY=0 git worktree remove `echo ~/linked` allow allow worktreeUnresolved worktreeUnresolved
C HUSKY=0 / tilde / empty $(:) fused HUSKY=0 git worktree remove ~/linked$(:) allow worktreeUnresolved worktreeUnresolved worktreeUnresolved
C HUSKY=0 / tilde / split HUSKY=0 git worktree remove ~/lin$(:)ked allow worktreeUnresolved worktreeUnresolved worktreeUnresolved
C HUSKY=0 / home / none HUSKY=0 git worktree remove $HOME/linked allow worktreeSymlink worktreeSymlink worktreeSymlink
C HUSKY=0 / home / $(…) HUSKY=0 git worktree remove "$(echo $HOME/linked)" allow allow worktreeUnresolved worktreeUnresolved
C HUSKY=0 / home / backtick HUSKY=0 git worktree remove `echo $HOME/linked` allow allow worktreeUnresolved worktreeUnresolved
C HUSKY=0 / home / empty $(:) fused HUSKY=0 git worktree remove $HOME/linked$(:) allow worktreeUnresolved worktreeUnresolved worktreeUnresolved
C HUSKY=0 / home / split HUSKY=0 git worktree remove $HOME/lin$(:)ked allow worktreeUnresolved worktreeUnresolved worktreeUnresolved
C HUSKY=0 / relative / none HUSKY=0 git worktree remove linked worktreeSymlink worktreeSymlink worktreeSymlink worktreeSymlink
C HUSKY=0 / relative / $(…) HUSKY=0 git worktree remove "$(echo linked)" allow allow worktreeUnresolved worktreeUnresolved
C HUSKY=0 / relative / backtick HUSKY=0 git worktree remove `echo linked` allow allow worktreeUnresolved worktreeUnresolved
C HUSKY=0 / relative / empty $(:) fused HUSKY=0 git worktree remove linked$(:) worktreeSymlink worktreeUnresolved worktreeUnresolved worktreeUnresolved
C HUSKY=0 / relative / split HUSKY=0 git worktree remove lin$(:)ked worktreeSymlink worktreeUnresolved worktreeUnresolved worktreeUnresolved
C HUSKY=0 / symlink-.. / none HUSKY=0 git worktree remove scratch/lnk/../linked allow allow worktreeSymlink worktreeSymlink
C HUSKY=0 / symlink-.. / $(…) HUSKY=0 git worktree remove "$(echo scratch/lnk/../linked)" allow allow worktreeUnresolved worktreeUnresolved
C HUSKY=0 / symlink-.. / backtick HUSKY=0 git worktree remove `echo scratch/lnk/../linked` allow allow worktreeUnresolved worktreeUnresolved
C HUSKY=0 / symlink-.. / empty $(:) fused HUSKY=0 git worktree remove scratch/lnk/../linked$(:) allow worktreeUnresolved worktreeUnresolved worktreeUnresolved
C HUSKY=0 / symlink-.. / split HUSKY=0 git worktree remove scratch/lnk/../lin$(:)ked allow worktreeUnresolved worktreeUnresolved worktreeUnresolved
D git $(:) stash stash allow stash stash
D $(:) git stash stash allow stash stash
D sudo $(:) git stash stash allow stash stash
D env $(:) git stash stash allow stash stash
D git -C . $(:) stash stash allow stash stash
D git `:` stash stash allow stash stash
D npm$(:) run lint; git$(:) commit -m x checkUngated allow checkUngated checkUngated
D mktemp $(:)-d /tmp/x.XXXX tmpCheckout allow tmpCheckout tmpCheckout
D git worktree add /tm$(:)p/wt tmpCheckout allow tmpCheckout tmpCheckout
D git clone r /tm$(:)p/x tmpCheckout allow tmpCheckout tmpCheckout
D git stash$(true) stash stash stash stash
D git reset --hard$(:) reset reset reset reset
D git push --force$(:) origin x forcePush forcePush forcePush forcePush
D git worktree remove "$(cat f)" allow allow worktreeUnresolved worktreeUnresolved
D git worktree remove $(echo linked) allow allow worktreeUnresolved worktreeUnresolved
D git worktree remove --force "$(echo linked)" allow allow worktreeUnresolved worktreeUnresolved
D git worktree remove -- "$(echo linked)" allow allow worktreeUnresolved worktreeUnresolved
D git worktree remove $(echo -f) linked worktreeSymlink allow worktreeUnresolved worktreeUnresolved
D git worktree remove $(true)linked worktreeSymlink worktreeUnresolved worktreeUnresolved worktreeUnresolved
D git -C $(pwd) worktree remove linked allow worktreeUnresolved worktreeUnresolved worktreeUnresolved
D git -C "$(pwd)" worktree remove linked worktreeSymlink worktreeUnresolved worktreeUnresolved worktreeUnresolved
D cd $(pwd) && git worktree remove linked worktreeSymlink worktreeUnresolved worktreeUnresolved worktreeUnresolved
D cd $(pwd) && git worktree remove FX/linked worktreeSymlink worktreeSymlink worktreeSymlink worktreeSymlink
D A=$(pwd); git worktree remove $A/linked allow worktreeUnresolved worktreeUnresolved worktreeUnresolved
D git worktree remove FX/scratch/lnk/../linked allow allow worktreeSymlink worktreeSymlink
D git worktree remove $PWD/scratch/lnk/../linked allow allow worktreeSymlink worktreeSymlink
D git -C scratch worktree remove lnk/../linked worktreeSymlink allow worktreeSymlink worktreeSymlink
D cd scratch; git worktree remove lnk/../linked allow allow worktreeSymlink worktreeSymlink
D git worktree remove scratch/lnk/.. allow allow allow allow
D cd scratch/lnk/.. && git worktree remove linked allow allow allow allow
D HOME=/x git worktree remove ~/linked allow worktreeUnresolved worktreeSymlink worktreeSymlink
D HOME=/x git worktree remove /x/linked allow allow allow allow
D export HOME=/x; git worktree remove ~/linked allow allow allow allow
D G=~/linked; F=$G; E=$F; D=$E; C=$D; B=$C; A=$B; git worktree remove $A allow worktreeUnresolved worktreeSymlink worktreeSymlink
D H=~/linked; G=$H; F=$G; E=$F; D=$E; C=$D; B=$C; A=$B; git worktree remove $A allow worktreeUnresolved worktreeSymlink worktreeSymlink
D I=~/linked; H=$I; G=$H; F=$G; E=$F; D=$E; C=$D; B=$C; A=$B; git worktree remove $A allow worktreeUnresolved worktreeUnresolved worktreeUnresolved
D A=B; B=C; C=D; D=E; E=F; F=G; G=H; H=~/linked; git worktree remove $A allow worktreeUnresolved allow allow
D TMPDIR=/home/dev/scratch git worktree add "$TMPDIR/foo" (ambient TMPDIR=unset) allow tmpCheckout tmpCheckout tmpCheckout
D TMPDIR=/home/dev/scratch git worktree add "$TMPDIR/foo" (ambient TMPDIR=/home/dev/elsewhere) allow allow allow allow
D coproc C$(:) { git stash; } stash stash stash stash
D coproc $(printf C) { git stash; } stash stash stash stash
D coproc `printf C`9 { git stash; } stash stash stash stash
D git worktree remove clean allow allow allow allow
D git worktree remove FX/clean allow allow allow allow
D git status allow allow allow allow
D echo $(git rev-parse HEAD) allow allow allow allow
D git commit -m "$(cat f)" allow allow allow allow
D git -C "$(git rev-parse --show-toplevel)" status allow allow allow allow
D git worktree add "$UNSET_WT" allow allow allow allow
D git $(printf stash) allow allow allow allow

rows: 133
master: 52 allow/deny mismatches vs expected
c0184f1: 59 allow/deny mismatches vs expected
r4: 0 allow/deny mismatches vs expected

🤖 Generated with Claude Code

apmantza#3988)

The `git worktree remove` rule resolved its path argument without the
shell expansion bash applies first, so `~/wt`, `$HOME/wt` and `${HOME}/wt`
were treated as paths relative to cwd, looksLikeGitWorktree failed, and a
worktree whose node_modules symlinks outside it was removed unchecked.

Expand a leading `~`, `$HOME` or `${HOME}` from the hook's HOME before the
absolute/relative resolution. The expansion is a separate helper so the
$TMPDIR substitution for `git worktree add` keeps its own variable lookup.
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Thanks for your first pull request! A maintainer will review it soon. Please make sure CI passes and the PR template is filled out.

@github-actions github-actions Bot added the red-ci Retired merge-train warden (#4105) - a required check was failing on the head label Oct 7, 2026
@apmantza

apmantza commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Thanks, this is the #3988 fix we filed this session. A maintainer round will push to this branch (maintainer edits are allowed):

  1. CI: the new test's mkdtemp prefix is outside the pi-lens- namespace, so tests/config/tmp-fixture-hygiene.test.ts reds in every shard. oxfmt also fails.
  2. The rest of guard-bash: #3173 shared-node_modules worktree-remove guard misses ~/ and $HOME/ path spellings #3988 (same seam): resolve relative git worktree remove paths against the command's effective cwd (including a preceding cd and git -C); fail closed with a named reason on a path that can't be resolved statically ($VAR/…, $(…), ~user); and route every guard-bash rule that tests a path argument through the one resolver, with a member list.
  3. Tests: red-first rows for each spelling through the real hook entry, with mutations on the resolver.

Open PR #3949 changes the same file for the coproc-label class. The two rounds will be kept compatible.

wastedC and others added 3 commits October 7, 2026 09:09
The apmantza#3173 node_modules-symlink guard resolved a `git worktree remove`
path literally, so `~/wt`, `$HOME/wt`, a relative path after `cd`/`git
-C`, and any `$VAR` or `$(...)` spelling failed open. The tmp-checkout,
mktemp and node-probe rules each carried a partial expander of their
own with the same hole.

One resolver now serves them all: expandShellWord expands `~`, `$VAR`,
`${VAR}` and `$PWD` as bash would, resolveShellPath anchors the result
on the command's effective cwd (a preceding cd/pushd, every `git -C`,
else the payload cwd; a subshell's cd does not leak). expandHomePrefix,
expandShellHome, substituteTempDirPrefix and pathResolvesUnderTmp are
deleted. lexRegions leaves a placeholder where it drops a `$(...)` or
backtick span so a word that held one is not read as a shorter path.

A `git worktree remove` path that cannot be resolved statically now
fails closed with `worktreeUnresolved`; the tmp-checkout hygiene rules
stay fail-open on it. Six historical orchestrator loop-variable removes
in the transcript corpus are now expected denies.

Closes apmantza#3988.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
oxfmt had rewritten the "" escape to the raw private-use
character, an invisible byte sequence in the source. Build it with
String.fromCharCode(0xe000) so the formatter leaves it readable (apmantza#3988).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@apmantza apmantza changed the title fix(guard-bash): expand ~ and $HOME in git worktree remove path (Refs #3988) fix(guard-bash): resolve path arguments through one resolver (Refs #3988) Oct 7, 2026
@apmantza

apmantza commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Maintainer round pushed to this branch (head b950180; contributor commit 821e37d kept, authorship preserved).

  • CI: the new test's mkdtemp prefix is gone with the rewritten table, tmp-fixture-hygiene and oxfmt are green locally. tests/config (96 files), the 37 tests/clients governance suites and guard-bash-hook.test.ts pass (134 files, 2572 passed) after merging origin/master.
  • guard-bash: #3173 shared-node_modules worktree-remove guard misses ~/ and $HOME/ path spellings #3988 folded in: ~, $HOME, ${HOME}, $VAR, $PWD and relative paths now resolve through one resolver (expandShellWord/resolveShellPath) against the command's effective cwd (cd/pushd, every git -C, a subshell's cd does not leak). git worktree remove on a path it cannot resolve statically fails closed with the new worktreeUnresolved rule. The tmp-checkout, mktemp, node probe and cd tracking rules route through the same seam; the body has the case table, the member list and the 26 mutation reds.
  • Red first: 40 of the 75 new and pinned rows fail on the pre-fix hook, all pass now.
  • One visible cost: six historical orchestrator commands that remove worktrees through a loop variable or glob now deny. Use node scripts/prune-agent-worktrees.mjs or a literal path.
  • Overlap with fix(guard-bash): skip keywords, git globals (#3787) #3949 is textual (four lexRegions hunks plus the header); noted in the body.

CI on this head is still running (ci-verdict: exit 3 (pending) at the time of writing).

@apmantza

apmantza commented Oct 7, 2026

Copy link
Copy Markdown
Owner

thanks @drakeo338. appreciate the PR. done some extra work on it, hope that's OK. merging soon.

@apmantza

apmantza commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Review (on the real hook, plus a combined tree with #3949): needs changes. Thanks for the fix; the path resolver itself is the right seam. The findings below come from probes through the real hook entry, with a logging bash/git stub.

Regressions introduced by the U+E000 substitution mark:

Fail-open cases:

  • F3: A=$(pwd); git worktree remove $A/wt is allowed (also with export, backticks, and cd $A).
  • F4: ambient $_ and $OLDPWD are trusted ($OLDPWD is a regression), and HOME=/x git worktree remove ~/wt is allowed because bash expands ~ before the inline assignment.
  • F5: an 8-hop variable chain ending in ~/wt is allowed, so the deleted chain-cap guard was load-bearing.
  • F6 (pre-existing, folded since it is the same resolver): brace expansion {-q,/path/wt}, and lexical .. through a symlinked directory.
  • F7: the helper count is net +1.

Plan (orchestrator): #3949 merges first. Then one maintainer round here, pushed to this branch, opening with a state-space table: keep the mark out of rule-matched word text (F1), register it as a dynamic expansion in splitWords and delete #3949's now-redundant coproc-label helper and its four lines (F2), and fold F3–F7. The transcript corpus expectation will deny 16 more real prune-loop commands (for w in …; do git worktree remove --force …/$w), which we accept as unresolvable paths. The corpus test will be kept under its time cap.

@apmantza

apmantza commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Status: this is waiting on #3949, which merges first. After that, one maintainer round here, as posted above. It resolves the overlap the review found by subsuming the U+E000 mark into #3949's coproc-label handling, and folds F1–F7. Your resolver design stays; the round fixes the fail-open cases and re-pins the transcript corpus.

# Conflicts:
#	scripts/hooks/guard-bash.mjs
Treat lexer substitution marks as dynamic expansions so rule words remain matchable and coproc labels remain scannable. Fail closed for indirect substitutions, volatile ambient paths, bounded chains, brace expansion, and symlink-sensitive parent traversal.\n\nRefs apmantza#3997. Closes apmantza#3988.
@apmantza

apmantza commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Maintainer status (2026-10-07): the round-2 verify found regressions in c0184f1: inline-env hook bypass, worktree remove "$(…)" and symlink-.. are allowed. They are reproduced through the real hook. Round 4 is in progress: a state-space table first, one derived rule (strip the substitution mark at the splitWords seam), the regressions fixed red-first, and the split-word family (git $(:) stash and its siblings) folded in by maintainer decision. The PR stays not-ready until a fresh verify.

A command substitution's output is not statically known. findDeny now
scans a command that holds one twice and denies if either reading does:
with the U+E000 mark kept as opaque word text (no rule word matches it,
no path resolves through it), then with the marks removed (the text
master scanned, where bash drops an empty unquoted word). This replaces
the three call-site strips and stripSubstitutionMark, which left `git
$(:) stash`, `npm$(:) run lint; git$(:) commit`, `mktemp $(:)-d` and the
whole-word `git worktree remove "$(cat f)"` open.

classifyGit takes git's env (inline prefix included, so HUSKY=0 and
PI_LENS_SKIP_HOOKS deny again) and, separately, the shell variables its
path words were expanded with; the __PI_LENS_INLINE_HOME sentinel is
gone. A path git or mktemp hands the kernel resolves physically
(measured: git removed the tree `lnk` pointed at for `lnk/../wt`); a cd
target stays logical, as bash resolves it. The chain expander drops the
identifier-valued pre-loop, restores the cap of 8 and expands a tilde
surfaced by the last hop. The -C walk is computed once in classifyGit
(gitInvocationCwd deleted): 49 top-level functions, as on master.
AGENTS.md gains numbered shape 61 (the shape-count pin in
agents-governance moves to 61), and the two changelog fragments fold
into one.

Refs apmantza#3997. Closes apmantza#3988.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@apmantza apmantza changed the title fix(guard-bash): resolve path arguments through one resolver (Refs #3988) fix(guard-bash): resolve path arguments through one resolver (closes #3988) Oct 7, 2026
@sonarqubecloud

sonarqubecloud Bot commented Oct 7, 2026

Copy link
Copy Markdown

@apmantza

apmantza commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Maintainer decisions on round 4 (head 6384cac, 2026-10-07):

  1. Accept the bash-semantics allow for TMPDIR=/tmp git worktree add $TMPDIR/x when the ambient TMPDIR is off /tmp. Bash expands $TMPDIR before the inline assignment takes effect, so the tree really lands off /tmp.
  2. The pre-existing residual is filed separately: mktemp and node words still expand with the inline prefix, unchanged from master.
  3. A fresh verify follows, since this round adds mechanism (the two-reading rule).

@apmantza
apmantza merged commit 1465da7 into apmantza:master Oct 7, 2026
49 of 52 checks passed
apmantza pushed a commit that referenced this pull request Oct 7, 2026
Round 3 of #4044 after #3997 merged. An unknown cwd (a cd the scan could
not resolve) is judged as the payload cwd; delete operands and --prefix
go through resolveShellPath in logical mode; find -L/-follow descent,
unlisted npm value flags, the unlink wording and the typos aliases.
Refs #4044

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Nyarlathoteppppp added a commit to Nyarlathoteppppp/pi-lens that referenced this pull request Oct 24, 2026
apmantza#4057)

Since the prefix stopped expanding mktemp's typed words, a `-p` or
`--tmpdir=` value that is one variable the shell does not have stayed
unexpanded and resolved under the cwd, so `D=/tmp/lane mktemp -d -p $D
y.XXXXXX` allowed. Master denied it by expanding the prefix's `D`.
Bash expands that word to nothing, and GNU mktemp reads an empty `-p`
or `--tmpdir=` value as its own `$TMPDIR`, else /tmp. A template word
that vanishes leaves no template, which defaults there too.

classifyMktemp now reads such a word twice, as findDeny reads a
substitution since apmantza#3997: as written, and as empty, where it judges
mktemp's `$TMPDIR` sentinel with mktemp's own env. The first reading
that lands under /tmp denies. Quotes are gone by then, so `-p "$D"`
and `-p $D` read alike.

Eight rows pin the empty readings, seven of them red at the previous
head. Two more rows give `-t` and bundled `-dt` their missing
direction. The remaining mktemp-default comments say GNU mktemp.
apmantza pushed a commit that referenced this pull request Oct 25, 2026
#4057)

Bash expands a command's words before an inline `VAR=val` prefix
reaches the program, so `TMPDIR=/x mktemp -d $TMPDIR/y` expands
`$TMPDIR` from the shell's own value. Since #3997 git's path words use
the shell's variables (`sharedEnv`), but mktemp and node still read
the prefixed env for their path words.

Pass `sharedEnv` to classifyMktemp and classifyNode as `expansionEnv`,
the same seam classifyGit uses. Typed words now expand from it: a
mktemp template, a `-p` or `--tmpdir=` value, and node's file
argument. Values the program reads from its own env keep the prefix:
mktemp's `$TMPDIR` default (no template, `-t` with a relative
template, bare `--tmpdir`) and node's `PI_LENS_HOME`. Each `-p` or
`--tmpdir` value records the env it expands with, so the last one
given still wins.

The new rows run the real hook with an explicit ambient TMPDIR, HOME
or variable, in both directions. Fourteen are red on master. The
controls for the default directory and PI_LENS_HOME pass on both.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

red-ci Retired merge-train warden (#4105) - a required check was failing on the head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

guard-bash: #3173 shared-node_modules worktree-remove guard misses ~/ and $HOME/ path spellings

3 participants