Skip to content

Command filters: skip calls with an unrecognised printing segment - #61

Merged
JayPokale merged 2 commits into
JayPokale:mainfrom
mccalpink:fix/57-filters-skip-unrecognised-segments
Nov 27, 2026
Merged

JayPokale merged 2 commits into
JayPokale:mainfrom
mccalpink:fix/57-filters-skip-unrecognised-segments

Conversation

@mccalpink

Copy link
Copy Markdown
Contributor

What & why

Command filters ran over the output of the whole call, so a segment they did not recognise was rewritten too: git status && cat m.py lost the blank lines of m.py. Now a call with an unrecognised segment that prints is not filtered at all.

Refs #57 (not Closes): this covers the five cases in the issue description. The follow-up git status && git diff still loses the diff's blank context lines, so the issue should stay open (or move to a new one).

Root cause

kindsFor() collected the kinds of the segments it recognised and silently ignored the rest. filterCommand() then applied those filters to the combined output. git diff; cat fix.patch lost the patch file's diff --git/index/---/+++ lines, npm test; cat old.tap lost its ok N lines, and so on, although the module header says "Only commands we recognise are touched".

Fix

  • kindsFor() returns null as soon as a segment that is not silent is not recognised, so no filter runs. Silent segments, which do not count: cd, export X=…, plain VAR=value, true and :. cd app && npm test is filtered as before.
  • This follows the fix proposed in the issue description, without the optional echo allowance. chisle-run.js is unaffected: its runner filters one wrapped segment at a time (wrappable()).
  • A backslash-newline now continues the command instead of starting a segment (pytest tests/ \⏎ -k foo, git log \⏎ -n 5 stay filtered), in kindsFor() and in the split in filterCommand().
  • The assignment branch of the silent check has no nested overlapping quantifiers, so a long a=a=a=… token cannot backtrack.

Total diff: hook, tests and one CHANGELOG entry, +67/-4.

Checklist

  • skills/chisle/SKILL.md is the source of truth, with no rule logic duplicated into hooks (SKILL.md is untouched; this is hook-side filtering only)
  • Regenerated rule copies + chart if behavior changed (npm run build:rules && npm run build:chart) (no rule or chart input changed; check:rules, check:chart and check:samples report in sync)
  • Hook changes preserve the flag-file security model (O_NOFOLLOW, 0600) (chisle-config.js is untouched)
  • npm test passes (276 tests, Node 22.23.5 and Node 20.20.2)
  • Added/updated a test for any hook logic change (tests/test_command_filters.js)

How I verified it

  • an unrecognised segment that prints disables filtering for the whole call fails on main (git status && cat m.py was filtered) and passes with the fix. It also pins || and piped segments: npm test || echo FAILED, cat f || true, npm i | grep WARN && git status are not filtered, git status | head -5 still is.
  • segments that print nothing keep filtering on covers cd, export, assignments, true, : and a trailing ;.
  • a backslash-newline continues the command… covers pytest, npm test and git log split over two lines.
  • SILENT matching is linear… runs a 5000-assignment token (< 200 ms; the earlier regex does not finish).
  • node --test tests/*.js: 276 pass, 0 fail, on Node 22.23.5 and Node 20.20.2.
  • npm run check:rules, check:chart, check:samples: all in sync. bash -n hooks/chisle-statusline.sh install.sh and the installer --list/--help smoke test pass.

Notes

  • Where filtering now turns off. Calls that mix a recognised command with any other printing or unknown segment go unfiltered, e.g. npm test || true, git add -A && git status, source .venv/bin/activate && pytest, . venv/bin/activate && pytest, set -e; npm test, mkdir -p out && npm test, sleep 2; git status, npm run build && npm test, a # comment line before the command, X=$(git rev-parse HEAD) && git log -3. This follows directly from the rule in the issue, and the behaviour is conservative: no output is altered. It does cost token savings on those calls. On Claude Code with the wrapper on, test/build/install segments are still filtered by chisle-run.js; git commands and harnesses without the wrapper do not get that.
  • true and : are counted as silent. set, source, ., git add and mkdir are not: some of them can print, and which ones to allow is your call.
  • Open question: git status && git diff. Both segments are recognised but shortStatus still runs over the diff's output. Applying only the kinds common to all printing segments would cover it, but it would also stop filtering npm ci && npm test (progress ∩ test = ∅), a design choice I left out. Also left out: echo with a fixed string as a silent segment, and a single & (git status & cat m.py) as a boundary.

This PR was prepared with AI assistance (Claude Code). I have reviewed the change and the test results.

kindsFor() now returns null when any segment of a compound command that
prints (not cd, export or an assignment) is not recognised, so filters no
longer rewrite the output of commands like `cat m.py` in the same call.
Rewrite the assignment branch of SILENT so it cannot backtrack
exponentially, treat backslash-newline as a continuation instead of a
segment boundary (in kindsFor and filterCommand), and count true and :
as silent. Tests cover ||, piped segments and the new cases.
@mccalpink
mccalpink requested a review from JayPokale as a code owner November 27, 2026 10:30
@vercel

vercel Bot commented Nov 27, 2026

Copy link
Copy Markdown

@mccalpink is attempting to deploy a commit to the jaypokale35gmailcom's projects Team on Vercel.

A member of the Team first needs to authorize it.

@JayPokale
JayPokale merged commit 4a724bd into JayPokale:main Nov 27, 2026
3 of 4 checks passed
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.

2 participants