Skip to content

Reject reader options that run programs or write files (T186) - #87

Merged
erickb336 merged 1 commit into
mainfrom
codex/t186-reader-options
Oct 8, 2026
Merged

erickb336 merged 1 commit into
mainfrom
codex/t186-reader-options

Conversation

@erickb336

@erickb336 erickb336 commented Oct 8, 2026 •

Copy link
Copy Markdown
Owner

Closes #58
Sage task T186

Commands that name Sage's logbook no longer pass as plain reads when their options launch a program or write a file. Plain reads, option values and words after -- retain their existing behavior.

The hook now checks rg preprocessing, compressed-file search and hostname programs; file magic compilation and external decompression; and diff pagination through pr. It also checks the overlapping state-tool reader exceptions and gh alias-file write checks. Resolved command evidence covers wrappers and function bodies while excluding literal arguments to known shell functions. The existing command-array normalization also applies before these checks.

This follows merged #86. Changes are in packages/sage-claude/hooks/sage-hook.mjs and scripts/sage-hook.test.mjs; the build regenerates the Claude plugin. The shared command reader and Codex runtime are unchanged. Claude-owned work can rebase onto these localized hook changes.

Validation

All test runs put inert ps, pgrep and kill programs first on PATH, unset NODE_TEST_CONTEXT, and use caffeinate. No submitted command strings reach a shell.

npm run build
built 212 files

npm run check
✓ all checks pass (1 timing bound carries "// timing-ok:")

node --test --test-reporter=spec --test-name-pattern='T186:' scripts/sage-hook.test.mjs
tests 6; pass 6; fail 0; skipped 0

node --test --test-reporter=spec --test-name-pattern='T186|T197|T83|programsRun|shared command reader|shared command extraction|R454|R466|R467' scripts/sage-hook.test.mjs scripts/providers.test.mjs
tests 126; pass 126; fail 0; skipped 0

npm test
tests 706; pass 706; fail 0; skipped 0

The six new behavior groups fail with assertion errors on detached main at 5282918. The copied test file matches the branch. They cover each of the three affected readers, resolved dispatches, state-tool reader exceptions and command arrays.

git worktree add --detach <temporary-worktree> origin/main
# Copy only the final scripts/sage-hook.test.mjs into that worktree.
node --test --test-reporter=spec --test-name-pattern='T186:' scripts/sage-hook.test.mjs
tests 6; pass 0; fail 6; skipped 0

Each failure is ERR_ASSERTION for a missing refusal; none is an infrastructure failure. Existing test assertions are unchanged. Independent code/security and QA reviews are clean on the final source. Review found and fixed a known-function false refusal and a command-array bypass before publication. Final independent checks include 60 option cases, 6 function ownership cases, 106 input cases, 32 array cases and 8 extra function controls.

GitHub CI passed on 0779831f0d0006fbd0d0301a3e347cf712c46367. The PR is ready for owner review and merge.

Reader audit

Readers Coverage and result
rg Version 15.2 help: --pre, --pre-glob, -z/--search-zip and --hostname-bin select a run. The issue explicitly includes standalone --pre-glob.
file Manual, FILE5_46 option parser and decompressor source: -C/--compile writes; -z/-Z and their long forms can run decompressors.
diff Manual, GNU diffutils 3.12 and Apple option tables: -l/--paginate runs pr. Apple also accepts --p and --pa. --to-file names an input.
cat, head, tail, cut, wc, ls, stat, echo, printf Apple manuals and GNU coreutils source at c3709a88: no additional program-launch or separate-output-file option found. tail -f remains a read.
grep, egrep, fgrep Apple decoder source and GNU grep 3.12: option handlers read inputs and print output; Apple's compressed reads use libraries.
jq, cd, pushd; shell echo/printf jq CLI/module/test-runner source and Bash/zsh manuals: no additional launch or separate-output option in the inspected paths.

Primary source references: file option table, GNU diffutils 3.12 source archive, GNU coreutils snapshot, GNU grep 3.12 source archive, and Apple grep source.

Option parsing preserves required values, attached values, short clusters, case and --. file and diff support long-option abbreviations. The check conservatively treats an observed launch/write option as active; it does not simulate later cancellation flags or input-dependent execution.

Limits and seen, not fixed

No test command payload, preprocessor, decompressor or pager ran. Tests send text to the hook. This is a command-policy change, not an operating-system sandbox or a live Codex lifecycle test.

The audit does not certify custom binaries, future versions, all library internals, configured shell hooks or special-device inputs. file --preserve-date restores access-time metadata; GNU tail --pid probes process existence; libxo can load an in-process encoder; zsh directory changes can call configured hooks. These are distinct from this issue's launch/separate-output option changes.

The owner reviews and merges this PR. No product decision is pending.

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.

T186: Hook treats rg --pre and file -C as a run and a write, not a read

1 participant