Skip to content

Commit bb24ee3

Browse files
committed
fix: route pnpm/yarn run through their own filters and fix doc drift
Two fixes: 1. Remove "run" from _TWO_TOKEN_PREFIXES["pnpm"] and ["yarn"]. Previously "pnpm run dev" was stripped to ["dev"], which matched no filter and left pnpm/yarn run output entirely uncompressed. PnpmFilter now handles "pnpm run <script>" via _compress_run; YarnFilter handles "yarn run <script>". pnpm exec/dlx still strip to the wrapped tool's filter (e.g. ESLintFilter for "pnpm exec eslint"). Four dispatch regression tests added. 2. compute_adaptive_budget docstring was missing the +15 web_history bonus from its formula; added it.
1 parent 4816f40 commit bb24ee3

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎src/token_goat/bash_compress.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,8 +1517,8 @@ def _positional_args(args: list[str]) -> list[str]:
15171517
"pdm": frozenset(["run"]),
15181518
"pipenv": frozenset(["run"]),
15191519
"npx": frozenset(), # npx <tool>, second token IS the binary
1520-
"pnpm": frozenset(["exec", "dlx", "run"]),
1521-
"yarn": frozenset(["run", "exec", "dlx"]),
1520+
"pnpm": frozenset(["exec", "dlx"]),
1521+
"yarn": frozenset(["exec", "dlx"]),
15221522
"bundle": frozenset(["exec"]),
15231523
"tox": frozenset(["-e"]),
15241524
"hatch": frozenset(["run"]),

‎src/token_goat/compact.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3630,6 +3630,7 @@ def compute_adaptive_budget(
36303630
+ min(200, edited_files_count × 50) [up to 4 files]
36313631
+ min(150, symbols_accessed_files × 30) [up to 5 files with symbols]
36323632
+ 20 tokens if bash_history has entries
3633+
+ 15 tokens if web_history has entries
36333634
+ 50 tokens if there are pending git changes (git diff --stat HEAD non-empty)
36343635
+ 10 tokens if there are uncommitted changes (git diff/status non-empty)
36353636
× tier multiplier (young=0.6, active=1.0, mature=1.4)

‎tests/test_bash_compress_pkgmgr.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,28 @@ def test_pnpm_dispatches_to_pnpm_filter(self) -> None:
565565
assert f is not None
566566
assert f.name == "pnpm"
567567

568+
def test_pnpm_run_dispatches_to_pnpm_filter(self) -> None:
569+
# "run" must NOT strip via _TWO_TOKEN_PREFIXES — PnpmFilter must handle it.
570+
f = bc.select_filter(["pnpm", "run", "dev"])
571+
assert f is not None
572+
assert f.name == "pnpm"
573+
574+
def test_pnpm_exec_wrapped_tool_dispatches_to_tool_filter(self) -> None:
575+
f = bc.select_filter(["pnpm", "exec", "eslint", "src/"])
576+
assert f is not None
577+
assert f.name == "eslint"
578+
568579
def test_yarn_dispatches_to_yarn_filter(self) -> None:
569580
f = bc.select_filter(["yarn", "install"])
570581
assert f is not None
571582
assert f.name == "yarn"
572583

584+
def test_yarn_run_dispatches_to_yarn_filter(self) -> None:
585+
# "run" must NOT strip via _TWO_TOKEN_PREFIXES — YarnFilter must handle it.
586+
f = bc.select_filter(["yarn", "run", "build"])
587+
assert f is not None
588+
assert f.name == "yarn"
589+
573590
def test_conda_dispatches_to_conda_filter(self) -> None:
574591
f = bc.select_filter(["conda", "install", "numpy"])
575592
assert f is not None

0 commit comments

Comments
 (0)