Skip to content

Follow or refuse the folder a line moves to (#163, part 1) - #182

Merged
paureis merged 8 commits into
mainfrom
fix/163-folder
Nov 5, 2026
Merged

paureis merged 8 commits into
mainfrom
fix/163-folder

Conversation

@paureis

@paureis paureis commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Part of #163 (PR 1 of 5, the folder family). Design: docs/superpowers/specs/2026-11-04-fail-closed-design.md, which this adds with the owner's decisions.

The bug. cd sub && gh ... was read correctly, but cd -- sub, cd -P sub, pushd sub, Set-Location sub and others were read as staying put, so the call was checked against the wrong pin file, for every CLI.

The fix: follow or refuse.

  • Followed in bash: cd -P/-L/-e/--, pushd, popd, cd -, bare cd, ~, builtin cd, command cd, a variable set on the line, and one from the hook's environment.
  • Followed in PowerShell, any case: cd, chdir, sl, Set-Location, pushd, Push-Location, popd, Pop-Location, with -Path, -LiteralPath, -PSPath.
  • Refused as "can't tell", naming no value: $(...), backticks, an unset variable, a glob or brace, cd a b, stack numbers, CDPATH set, PowerShell's bare cd, provider paths and blocks that move the folder. Exempt calls still pass.
  • Only with a pin file in sight (owner decision): an unknown folder stops a call only when a pin file is found from the last folder the line knew. With none, cloudpin does nothing, as DESIGN.md promises. So cd "$REPO" && az ... from a folder with no pin file in sight passes, and THREAT_MODEL.md says so.
  • Also fixed: Git Bash's /c/x was read as C:\c\x.

Argument parsing state moved to src/line-state.ts first, in a commit of its own with a move proof, because shellwords.ts was over the size cap.

Also: CHANGELOG.md moves 1.2.0 to docs/changelog-1.0-1.2.md to stay under its limit, and ROADMAP lists #163, #168, #180 and #181 with 1.4.0's date.

Evidence

  • npm run typecheck exit 0; npx vitest run: 3465 passed, 19 skipped.
  • 131 mutations: 130 killed, 1 equivalent survivor.
  • Compared with real shells using printers named like a CLI: Git Bash 57 same, 19 refused, 0 different; PowerShell 5.1 74 same, 28 refused, 0 different. The same forms on main's parser differ on 128, so the check can fail.
  • The built hook, end to end: a followed form with a wrong pin denies, an unknown folder with a pin in sight denies, the same line with no pin in sight passes, an exempt call passes.
  • On 31,046 of the owner's real commands (counts only): 0 new stops, but almost no pin files exist there. 11 lines would stop in projects that had pin files.

Not tested

pwsh (not installed; PowerShell 7 differs on bare cd and cd -, so those stay refused), macOS and Linux shells. Other agents use the same parser but were not run.

Limits

A conditional cd is read as if it ran (test -d a && cd a; gh). cd missing; gh is read as moved. iex $c or a bare $c could move the folder unseen; that is PR 3's family.

🤖 Generated with Claude Code

paureis and others added 8 commits November 4, 2026 20:22
A pure move, to make room for the folder family: shellwords.ts is at its size cap. Dialect, State,
variables, child and assign go to line-state.ts, unchanged but for `export`. Checked with a script that
every removed line is in the new file and every added line is an import or a re-export, with a control
that reports a mutated line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cd -- x, cd -P x, pushd x, Set-Location x, sl x, cd -Path x and friends passed with no objection, so the wrong
pin file and the wrong link applied, for every CLI. folder.ts now reads each spelling as real Git Bash and
PowerShell 5.1 do, a folder set by a variable on the line, and one from the hook's environment (owner's
decision 4). Anything else makes the call's cwd UNKNOWN_FOLDER, and guard stops it as "can't tell" unless it is
exempt, whether or not a pin file is in sight, since the folder it goes to may have one.

Also read now: a command either shell rejects leaves the folder where it was; bash's pipe sides and background
jobs keep their folder; Invoke-Expression runs in the session; a PowerShell block or ( ) that moves the folder
makes what follows unknown; /c/x in Git Bash on Windows is C:/x, which used to read as C:\c\x, and /tmp is %TEMP%;
env -C, sudo -D, pnpm -C, yarn --cwd and Start-Process -WorkingDirectory with a folder only known when it runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#163)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#163)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner's decision. A line that moves to a folder cloudpin can't read stops a later non-exempt call as "can't tell"
only if findConfig finds a pin file from the last folder the line knew. A pin file it can't read counts as in
sight. With none in sight cloudpin does nothing, as DESIGN.md promises for a folder with no pin file: on 30 days
of real commands every stop was of that kind.

The last known folder travels in its own field, knownCwd, so UNKNOWN_FOLDER never reaches a path lookup and a
request without it stops. cloudpin switch still asks and names no pins, and explain says why it lets the line run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CHANGELOG.md was at its 20,000-byte cap. 1.2.0 moves, byte for byte, and docs/changelog-1.0-1.1.md is renamed
docs/changelog-1.0-1.2.md, newest first. 1.2.1 stays: test/release-docs.test.ts wants the current version's entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@paureis
paureis merged commit aab07df into main Nov 5, 2026
4 checks passed
@paureis
paureis deleted the fix/163-folder branch November 5, 2026 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant