Repository navigation
Tools: per-command shell output filters with tee-on-failure (RTK-inspired) - #189
Merged
Merged
Conversation
shell_exec is the loudest tool in the registry. A typical
session burns kilobytes on the success path of git status,
cargo test, pytest, npm test, recursive greps, and recursive
listings -- mostly noise the model rarely reads in full. New
PasClaw.Tools.Shell.Filters condenses the success path while
leaving failures untouched.
Filters (always success-path; failures pass through verbatim):
git status branch + grouped counts + first 8 files per group
git diff file-level summary with +/- counts when diff
exceeds 60 lines (passthrough below)
git log newest 20 commit hash + subject lines
npm/yarn/pnpm/cargo test, pytest
pass count + every failure with context
grep / findstr / Select-String
aggregate by file, first 3 matches per file
ls -R / find / dir /s / Get-ChildItem -Recurse
cap at 40 entries + "(+N elided)"
Tee-on-failure: ApplyShellFilter short-circuits when ExitCode
<> 0 and returns RawOut unchanged. A failing test or compile
needs the full stack to debug -- a condensed failure would be
worse than no filter at all. Inspired by rtk-ai/rtk's same
contract.
Cross-shell normalisation so the same filter fires regardless
of host shell:
PowerShell aliases gci/Get-ChildItem -> ls
sls/Select-String -> grep
gc/Get-Content -> cat
cmd.exe builtins dir / findstr / type
Shell wrappers powershell -Command "..."
pwsh -c "..."
cmd /c ...
bash -c "..." (peeled before dispatch)
Two-word commands git/npm/yarn/pnpm/cargo/mvn carry the
subcommand as part of the dispatch key.
Unknown commands always pass through -- a bespoke incantation
the model invented never comes back mangled.
Process-lifetime counters (ShellFilterCalls, ShellFilterBytesSaved)
surface in the TUI /stats overlay next to the OutputCache numbers,
so operators can see the impact accumulating session-by-session.
Tests: shell_filters_tests covers canonicalisation (PowerShell +
cmd + shell wrappers), tee-on-failure, unknown-command passthrough,
each filter, and counter accumulation.
This was referenced Jun 9, 2026
khongten001
pushed a commit
to khongten001/PasClaw
that referenced
this pull request
Jul 13, 2026
PR FMXExpress#189 introduced PasClaw.Tools.Shell.Filters using TStringArray as the SplitTokens return type. FPC's SysUtils declares TStringArray; Delphi's RTL doesn't, so dcc64 errors out on the function signature and every downstream LowerCase(Tokens[i]) call cascades into E2008 / E2250 noise: PasClaw.Tools.Shell.Filters.pas(89): E2003 Undeclared identifier: 'TStringArray' PasClaw.Tools.Shell.Filters.pas(98): E2008 Incompatible types PasClaw.Tools.Shell.Filters.pas(133): E2008 Incompatible types PasClaw.Tools.Shell.Filters.pas(156): E2007 Constant or type identifier expected ... (15 more downstream cascades) Same fix shape PasClaw uses in PasClaw.Tools.Registry: declare TStringArray locally under {\$IFNDEF FPC} so the Delphi build has a definition without conflicting with FPC's SysUtils declaration. One-block change at the top of the implementation section, no functional changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
shell_execis the loudest tool in the registry. A typical session burns kilobytes on the success path ofgit status,cargo test,pytest,npm test, recursive greps, and recursive listings — mostly noise the model rarely reads in full. NewPasClaw.Tools.Shell.Filterscondenses the success path while leaving failures untouched. Concept borrowed from rtk-ai/rtk.A — per-command filters
Filters fire only on the success path. Implemented in this PR:
git statusgit diff+X -Ycountsgit log<hash> <subject>npm/yarn/pnpm/cargo test,pytestgrep/findstr/Select-Stringls -R/find/dir /s/Get-ChildItem -Recurse(+N elided — narrow the path)Unknown commands pass through unchanged — a bespoke incantation the model invented never comes back mangled.
B — tee-on-failure
ApplyShellFiltershort-circuits whenExitCode <> 0and returns the raw output verbatim. A failing test or compile needs the full stack trace to debug; a condensed failure would be worse than no filter at all. The same contractrtk-ai/rtk's tee pattern is built around.Cross-shell normalisation (Windows!)
The dispatcher canonicalises Windows aliases so the same filter fires regardless of host shell. The model doesn't have to remember whether it's talking to bash, PowerShell, or
cmd.exe:Counters in
/statsProcess-lifetime
ShellFilterCallsandShellFilterBytesSavedaccumulate across the session and surface in the TUI/statsoverlay alongside the existing OutputCache numbers — operators can watch the savings climb. Reset on TUI startup.Tests
shell_filters_tests(10 cases):ExitCode = 1returns raw, counters don't bumpgit status(clean + with changes),git diff(passthrough + summary),pytest(failures surfaced with context),grep(alias-dispatched viaSelect-String)Test plan
makerebuilds cleanlymake test— all 14 suites green (smoke + 12 existing + newshell_filters_tests)pasclaw agent, asks it to "run the tests" — confirmpytest/cargo testoutput is condensed, failures still visible. Check/statsshows non-zeroshellline.powershell -Command "git status"invocation — confirm the wrapper peeling lands on thegit statusfilter, the alias-dispatchedSelect-Stringfilter matches agrep -rfilter.cargo testagainst a known-broken test) — confirm the full failure context comes through, no truncation.Generated by Claude Code