Skip to content

Treat newlines as command separators in bash command parsing - #1930

Open
goranai wants to merge 1 commit into
getagentseal:mainfrom
goranai:fix/bash-newline-separator
Open

goranai wants to merge 1 commit into
getagentseal:mainfrom
goranai:fix/bash-newline-separator

Conversation

@goranai

@goranai goranai commented Nov 11, 2026 •

Copy link
Copy Markdown

Summary

  • extractBashCommands and isReadShapedBashCommand split only on &&, ; and |. A newline also ends a shell command, so git status\nnpm test gave ["git"], cd /tmp\nnpm test\nls gave [], and ls\nrm -rf dist was judged read-only, which the read-edit-ratio and retry detectors then trusted (Bash-heavy workflows are misread: shell reads uncounted, retries overcounted #941). Closes Bash parsing ignores newlines, so later lines of a multi-line command are dropped #1929.
  • A new maskForSplitting scans a multi-line command once: quoted text, # comments and heredoc bodies (<<, <<-, quoted or escaped delimiters, several heredocs on one line) are blanked, and an unquoted newline becomes ;. A newline after an odd run of backslashes (also before \r\n) is a line continuation. <<< is not a heredoc. The mask keeps the input's length, as the separator slicing needs.
  • A single-line command takes the old path (stripQuotedStrings) unchanged, so its output is identical to main.
  • FACTS_VERSION goes 3 to 4 and the digest in tests/scan-facts-version.test.ts is recorded, with maskForSplitting and HEREDOC_START added to the pinned rules, because isReadShapedBashCommand feeds stored scan facts. Stored Optimize facts are rebuilt once after the update.

Behavior changes besides the bug case (multi-line commands only):

  • Commands on later lines now appear in the shell command breakdown. Shell keywords on their own lines (do, done, then, fi) and a line that is only ) are counted as names, the same way for/do already were on one line.
  • A multi-line call with a write on any line is no longer a read, so read-edit ratio and retry counting change for such calls.
  • # comments are skipped in multi-line commands, so a comment line no longer counts as a # command or makes a read-only call non-read. Single-line commands keep the old handling (for example ls # x; rm y still gives ["ls", "rm"]).
  • Session data already cached keeps its old command lists until it is parsed again (no cache version bump, as in fix(bash): attribute wrapped commands to the real tool, not the wrapper #658). Only the scan facts are versioned.

Known limits, unchanged from main: $((1<<2)) on a line is still read as a heredoc start, and a backslash before a quote (\') is not treated as an escape, as in stripQuotedStrings.

Testing / Verification

  • I have tested this locally against real data (not just unit tests)
  • npm test passes
  • npm run build succeeds
  • Not a UI change
  • UI change: before and after screenshots attached below

Run on Windows 11, Node 24, branch = main 40d5880 + this diff, 2026-11-11:

  • New tests: the 5 new cases in tests/bash-commands.test.ts fail with src/bash-utils.ts from main and pass with the fix. npx vitest run tests/bash-commands.test.ts tests/scan-facts-version.test.ts tests/classifier.test.ts tests/optimize.test.ts tests/guard: 258 passed (7 files).
  • npx tsc --noEmit: exit 0.
  • npm test -- --maxWorkers=2 on this branch: 5681 passed, 14 failed, 34 skipped (5729). On main: 5675 passed, 15 failed, 34 skipped (5724). All 14 failures on the branch also fail on main (Windows path and process tests: launcher-homes, plugin-signing, plugin-tar-security, quota-providers, serve-stdio and others). The branch adds no new failure. I left the npm test passes box unticked because the suite is not green on Windows.
  • npm run build: the tsup CLI step succeeds. The chained build:dash step (npm ci --silent in dash/) exits 1 on this Windows machine on main too; run on its own, npm ci and npm run build in dash/ succeed. Left unticked for CI to confirm.
  • Differential fuzz (fast-check, not added to the repo): 130000 newline-free inputs give identical output on main and branch for both functions; 100000 inputs with newlines never throw, and for plain input a newline gives the same result as ; and as parsing each line alone; 20000 generated multi-line scripts with comments, heredocs (with apostrophes in the body) and CRLF match the expected command list. 20000-character inputs finish in under 10 ms.

AI disclosure: Validated with Claude Opus 5.5. The owner directs and reviews the work.

extractBashCommands and isReadShapedBashCommand split only on &&, ; and |,
so every line after the first was read as arguments of the first command.
Multi-line commands are now scanned once: quotes, comments and heredoc
bodies are blanked and an unquoted newline separates commands.
Single-line commands are parsed exactly as before.

Closes getagentseal#1929
@goranai
goranai requested a review from iamtoruk as a code owner November 11, 2026 15:38

This branch has not been deployed

No deployments
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.

Bash parsing ignores newlines, so later lines of a multi-line command are dropped

1 participant