@alexgreensh/token-optimizer 5.13.75 → 5.13.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/hooks/module_runner.py +1 -1
  4. package/hooks/posttooluse_runner.py +7 -9
  5. package/hooks/run.py +5 -1
  6. package/hooks/stop_runner.py +15 -56
  7. package/hooks/userpromptsubmit_runner.py +29 -4
  8. package/package.json +1 -1
  9. package/skills/token-optimizer/assets/dashboard.html +30 -14
  10. package/skills/token-optimizer/assets/savings_story.js +103 -27
  11. package/skills/token-optimizer/references/agent-prompts.md +2 -0
  12. package/skills/token-optimizer/references/implementation-playbook.md +1 -0
  13. package/skills/token-optimizer/scripts/_measure/__init__.py +1 -1
  14. package/skills/token-optimizer/scripts/_measure/apply_safe.py +512 -0
  15. package/skills/token-optimizer/scripts/_measure/audit.py +9 -20
  16. package/skills/token-optimizer/scripts/_measure/autocompact_advice.py +455 -0
  17. package/skills/token-optimizer/scripts/_measure/cache_policy.py +82 -127
  18. package/skills/token-optimizer/scripts/_measure/cli.py +10 -24
  19. package/skills/token-optimizer/scripts/_measure/cold_guard.py +777 -0
  20. package/skills/token-optimizer/scripts/_measure/continuity.py +45 -4
  21. package/skills/token-optimizer/scripts/_measure/counted_closes.py +398 -0
  22. package/skills/token-optimizer/scripts/_measure/counted_headline.py +112 -0
  23. package/skills/token-optimizer/scripts/_measure/dashboard.py +14 -6
  24. package/skills/token-optimizer/scripts/_measure/feature_health.py +6 -0
  25. package/skills/token-optimizer/scripts/_measure/keepwarm_auto.py +452 -0
  26. package/skills/token-optimizer/scripts/_measure/keepwarm_economics.py +8 -4
  27. package/skills/token-optimizer/scripts/_measure/keepwarm_safety.py +548 -24
  28. package/skills/token-optimizer/scripts/_measure/limit_units.py +463 -0
  29. package/skills/token-optimizer/scripts/_measure/local_adapt.py +192 -0
  30. package/skills/token-optimizer/scripts/_measure/mod_action_booking.py +71 -14
  31. package/skills/token-optimizer/scripts/_measure/next_actions.py +420 -0
  32. package/skills/token-optimizer/scripts/_measure/poc_commands.py +44 -0
  33. package/skills/token-optimizer/scripts/_measure/prefix_cost.py +215 -0
  34. package/skills/token-optimizer/scripts/_measure/pt_resume_cues.py +46 -0
  35. package/skills/token-optimizer/scripts/_measure/quality_archive.py +7 -10
  36. package/skills/token-optimizer/scripts/_measure/savings.py +75 -81
  37. package/skills/token-optimizer/scripts/_measure/savings_headline.py +17 -21
  38. package/skills/token-optimizer/scripts/_measure/savings_story.py +8 -1
  39. package/skills/token-optimizer/scripts/_measure/session_store_spool.py +119 -78
  40. package/skills/token-optimizer/scripts/_measure/status_bar_refresh.py +38 -3
  41. package/skills/token-optimizer/scripts/_measure/structural_ledger.py +1 -1
  42. package/skills/token-optimizer/scripts/_measure/subscription_audits.py +725 -0
  43. package/skills/token-optimizer/scripts/_measure/transcript_backfill.py +1 -1
  44. package/skills/token-optimizer/scripts/_measure/transcript_stream.py +8 -2
  45. package/skills/token-optimizer/scripts/antigravity_install.py +3 -0
  46. package/skills/token-optimizer/scripts/archive_result.py +16 -28
  47. package/skills/token-optimizer/scripts/archive_verify.py +1 -1
  48. package/skills/token-optimizer/scripts/bash_compress.py +156 -176
  49. package/skills/token-optimizer/scripts/bash_compress_hook.py +218 -174
  50. package/skills/token-optimizer/scripts/bash_search_results.py +189 -9
  51. package/skills/token-optimizer/scripts/bash_whitelist.py +6 -1
  52. package/skills/token-optimizer/scripts/benchmark.py +11 -13
  53. package/skills/token-optimizer/scripts/big_noncode_read.py +998 -0
  54. package/skills/token-optimizer/scripts/build_output_compress.py +103 -8
  55. package/skills/token-optimizer/scripts/builtin_tool_compress.py +716 -0
  56. package/skills/token-optimizer/scripts/cloud_kit.py +1 -1
  57. package/skills/token-optimizer/scripts/codex_doctor.py +1 -1
  58. package/skills/token-optimizer/scripts/command_compress_extra.py +955 -0
  59. package/skills/token-optimizer/scripts/compact_markers.py +129 -0
  60. package/skills/token-optimizer/scripts/copilot_install.py +3 -0
  61. package/skills/token-optimizer/scripts/cursor_install.py +7 -0
  62. package/skills/token-optimizer/scripts/devin_source.py +5 -5
  63. package/skills/token-optimizer/scripts/emit_safety_gate.py +518 -0
  64. package/skills/token-optimizer/scripts/fixtures/b2_more_commands.json +142 -0
  65. package/skills/token-optimizer/scripts/fixtures/b5_more_savings.json +26 -0
  66. package/skills/token-optimizer/scripts/fixtures/builtin_tools.json +103 -0
  67. package/skills/token-optimizer/scripts/fixtures/c7_review_ratchet.json +52 -0
  68. package/skills/token-optimizer/scripts/fixtures/large_output_policy.json +55 -0
  69. package/skills/token-optimizer/scripts/go_cargo_test_compress.py +493 -0
  70. package/skills/token-optimizer/scripts/grok_install.py +3 -0
  71. package/skills/token-optimizer/scripts/hermes_doctor.py +4 -1
  72. package/skills/token-optimizer/scripts/hermes_install.py +10 -1
  73. package/skills/token-optimizer/scripts/hook_fastpath.py +94 -0
  74. package/skills/token-optimizer/scripts/hook_runtime.py +6 -2
  75. package/skills/token-optimizer/scripts/large_output_policy.py +431 -0
  76. package/skills/token-optimizer/scripts/measure.py +10 -12
  77. package/skills/token-optimizer/scripts/pipe_file_compress.py +900 -0
  78. package/skills/token-optimizer/scripts/pipeline_analyzer.py +15 -1
  79. package/skills/token-optimizer/scripts/post_run_classify.py +2 -2
  80. package/skills/token-optimizer/scripts/preserved_reinject.py +20 -3
  81. package/skills/token-optimizer/scripts/process_identity.py +66 -0
  82. package/skills/token-optimizer/scripts/read_cache.py +51 -60
  83. package/skills/token-optimizer/scripts/statusline.js +21 -3
  84. package/skills/token-optimizer/scripts/visibility_rule.py +536 -0
@@ -0,0 +1,493 @@
1
+ #!/usr/bin/env python3
2
+ """Structured test-output compressors for Go, Cargo, and Node (`node --test`).
3
+
4
+ Stdlib-only helper called by ``bash_compress._compress_pytest`` for test
5
+ runners whose verbose output formats do not match pytest's ``N passed`` /
6
+ ``=== FAILURES ===`` layout:
7
+
8
+ - ``go test -v ./...`` (``=== RUN``, ``--- PASS:``, ``--- SKIP:``,
9
+ ``--- FAIL:``, ``ok \\tpkg\\t0.1s``, ``FAIL\\tpkg\\t0.1s``)
10
+ - ``cargo test`` across single-crate and multi-crate workspaces
11
+ (``running N tests``, ``test name ... ok/ignored/FAILED``,
12
+ ``failures:``, ``test result: ...``)
13
+ - ``node --test`` TAP and spec output (``ok N -`` / ``not ok N -``,
14
+ ``✔`` / ``✖``, ``# tests`` / ``ℹ tests`` summary lines)
15
+
16
+ Safety invariants:
17
+ - Never touches short outputs (< 15 lines).
18
+ - Drops ONLY known pass noise (passing/skipped test markers and passing
19
+ ``t.Log`` lines). Unrecognised lines, diagnostics, compile errors, panic
20
+ stack frames, ``Example`` ``got:``/``want:``, data-race warnings,
21
+ benchmarks, Cargo aborts/``Caused by:``/``SIGABRT``/``--nocapture``
22
+ output, and Node ``test at file:line`` locations are preserved verbatim.
23
+ - Only sniffs the format of the detected runner when dispatched from a
24
+ command, so pytest output is never misparsed as Go/Cargo/Node.
25
+ - Returns ``None`` when the output does not match a known format or does not
26
+ shrink, so the caller falls through cleanly.
27
+ """
28
+ from __future__ import annotations
29
+
30
+ import re
31
+ import shlex
32
+
33
+ _MIN_LINES = 15
34
+
35
+ # --- Go test patterns ---
36
+ _GO_RUN_RE = re.compile(r"^\s*=== (?:RUN|PAUSE|CONT)\s+")
37
+ _GO_PASS_RE = re.compile(r"^\s*--- PASS:\s+")
38
+ _GO_SKIP_RE = re.compile(r"^\s*--- SKIP:\s+")
39
+ _GO_FAIL_RE = re.compile(r"^\s*--- FAIL:\s+")
40
+ _GO_PKG_OK_RE = re.compile(r"^ok\s+\S+\t")
41
+ _GO_PKG_FAIL_RE = re.compile(r"^FAIL\t\S+")
42
+ _GO_PKG_NOTEST_RE = re.compile(r"^\?\s+\S+\t\[no test files\]")
43
+ _GO_TEST_FILE_LINE_RE = re.compile(r"^\s+\S+_test\.go:\d+:")
44
+ _GO_FAILURE_SIGNAL_RE = re.compile(
45
+ r"(?:^panic:|^fatal error:|^goroutine \d+|WARNING:\s*DATA RACE|\[build failed\]|\[setup failed\])"
46
+ )
47
+
48
+ # --- Cargo test patterns ---
49
+ _CARGO_RUNNING_RE = re.compile(r"^running \d+ tests?\s*$")
50
+ _CARGO_TEST_OK_RE = re.compile(r"^test .+? \.\.\. ok(?:\s+\(compile fail\))?\s*$")
51
+ _CARGO_TEST_IGNORED_RE = re.compile(r"^test .+? \.\.\. ignored(?:,\s*.*)?\s*$")
52
+ _CARGO_TEST_FAILED_RE = re.compile(r"^test .+? \.\.\. FAILED\s*$")
53
+ _CARGO_RESULT_RE = re.compile(r"^test result:\s+")
54
+ _CARGO_DOC_HEADER_RE = re.compile(r"^\s*Doc-tests\s+\S+")
55
+ _CARGO_RUNNING_BIN_RE = re.compile(r"^\s*Running\s+(?:unittests|tests/|`?target)")
56
+ _CARGO_ERROR_SIGNAL_RE = re.compile(
57
+ r"(?:^error(?:\[E\d+\])?:|^Caused by:|panicked at|fatal runtime error:|SIGABRT|SIGSEGV|SIGKILL|test result:\s*FAILED)"
58
+ )
59
+
60
+ # --- Node --test patterns ---
61
+ _NODE_TAP_VERSION_RE = re.compile(r"^TAP version \d+\s*$")
62
+ _NODE_TAP_PLAN_RE = re.compile(r"^\s*1\.\.\d+\s*$")
63
+ _NODE_TAP_SUBTEST_RE = re.compile(r"^\s*# Subtest:\s+")
64
+ _NODE_TAP_OK_RE = re.compile(r"^\s*ok \d+\s+-\s+")
65
+ _NODE_TAP_FAIL_RE = re.compile(r"^\s*not ok \d+\s+-\s+")
66
+ _NODE_SPEC_OK_RE = re.compile(r"^\s*[✔✓]\s+")
67
+ _NODE_SPEC_FAIL_RE = re.compile(r"^\s*[✖✗]\s+")
68
+ _NODE_SPEC_SUITE_RE = re.compile(r"^\s*▶\s+")
69
+ _NODE_SUMMARY_RE = re.compile(
70
+ r"^(?:#|ℹ)\s+(?:tests|suites|pass|fail|cancelled|skipped|todo|duration_ms)\s+\S+"
71
+ )
72
+ _NODE_YAML_PASS_KEY_RE = re.compile(r"^\s+(?:duration_ms|type):\s+")
73
+
74
+ _SHELL_SPLIT_TOKENS = frozenset({"|", "&&", "||", ";"})
75
+
76
+
77
+ def is_node_test_args(args: list[str]) -> bool:
78
+ """Return True iff ``--test`` appears in ``node`` options before the first non-option token."""
79
+ for tok in args:
80
+ if tok == "--":
81
+ return False
82
+ if tok == "--test":
83
+ return True
84
+ if not tok.startswith("-"):
85
+ return False
86
+ return False
87
+
88
+
89
+ def detect_runner(command_str: str) -> str | None:
90
+ """Return ``'go'``, ``'cargo'``, or ``'node'`` for supported test commands, else ``None``."""
91
+ if not command_str or not command_str.strip():
92
+ return None
93
+ try:
94
+ tokens = shlex.split(command_str)
95
+ except ValueError:
96
+ return None
97
+ if not tokens:
98
+ return None
99
+
100
+ # Inspect the primary command segment before any pipe/operator.
101
+ stage: list[str] = []
102
+ for tok in tokens:
103
+ if tok in _SHELL_SPLIT_TOKENS:
104
+ break
105
+ stage.append(tok)
106
+ if not stage:
107
+ return None
108
+
109
+ idx = 0
110
+ if stage[idx] == "env":
111
+ idx += 1
112
+ while idx < len(stage) and "=" in stage[idx] and not stage[idx].startswith("-"):
113
+ idx += 1
114
+ if idx >= len(stage):
115
+ return None
116
+
117
+ cmd = stage[idx].rsplit("/", 1)[-1]
118
+ subcmd = stage[idx + 1] if idx + 1 < len(stage) else ""
119
+
120
+ if cmd == "go" and subcmd == "test":
121
+ return "go"
122
+ if cmd == "cargo" and subcmd == "test":
123
+ return "cargo"
124
+ if cmd == "node" and is_node_test_args(stage[idx + 1:]):
125
+ return "node"
126
+ return None
127
+
128
+
129
+ def compress_go_test(output: str) -> str | None:
130
+ """Compress verbose ``go test`` output while keeping all non-pass lines and summaries."""
131
+ lines = output.strip().splitlines()
132
+ if len(lines) < _MIN_LINES:
133
+ return None
134
+
135
+ has_go_marker = any(
136
+ _GO_RUN_RE.match(ln)
137
+ or _GO_PASS_RE.match(ln)
138
+ or _GO_FAIL_RE.match(ln)
139
+ or _GO_PKG_OK_RE.match(ln)
140
+ or _GO_PKG_FAIL_RE.match(ln)
141
+ for ln in lines
142
+ )
143
+ if not has_go_marker:
144
+ return None
145
+
146
+ passed = 0
147
+ skipped = 0
148
+ failed = 0
149
+ pkg_summaries: list[str] = []
150
+ kept_lines: list[str] = []
151
+
152
+ # Buffer `=== RUN` and indented `*_test.go:line:` t.Log lines until we see
153
+ # whether the test passes/skips (drop its t.Log) or fails/panics (keep all).
154
+ pending_run: str | None = None
155
+ pending_logs: list[str] = []
156
+ in_test_log = False
157
+
158
+ def _flush_pending(include_run: bool = True) -> None:
159
+ nonlocal pending_run, pending_logs, in_test_log
160
+ if include_run and pending_run is not None:
161
+ kept_lines.append(pending_run)
162
+ if pending_logs:
163
+ kept_lines.extend(pending_logs)
164
+ pending_run = None
165
+ pending_logs = []
166
+ in_test_log = False
167
+
168
+ for ln in lines:
169
+ if _GO_RUN_RE.match(ln):
170
+ # Previous pending_logs without a PASS/SKIP belong to an unfinished
171
+ # or parallel test; never drop them silently.
172
+ if pending_logs:
173
+ _flush_pending(include_run=True)
174
+ pending_run = ln
175
+ in_test_log = False
176
+ continue
177
+
178
+ if _GO_PASS_RE.match(ln):
179
+ passed += 1
180
+ pending_run = None
181
+ pending_logs = []
182
+ in_test_log = False
183
+ continue
184
+
185
+ if _GO_SKIP_RE.match(ln):
186
+ skipped += 1
187
+ pending_run = None
188
+ pending_logs = []
189
+ in_test_log = False
190
+ continue
191
+
192
+ if _GO_FAIL_RE.match(ln):
193
+ failed += 1
194
+ # --- FAIL: already names the test; flush any buffered diagnostics.
195
+ _flush_pending(include_run=False)
196
+ kept_lines.append(ln)
197
+ continue
198
+
199
+ if _GO_PKG_OK_RE.match(ln) or _GO_PKG_FAIL_RE.match(ln) or _GO_PKG_NOTEST_RE.match(ln):
200
+ if pending_logs:
201
+ _flush_pending(include_run=True)
202
+ else:
203
+ pending_run = None
204
+ in_test_log = False
205
+ pkg_summaries.append(ln)
206
+ continue
207
+
208
+ if ln.strip() == "PASS":
209
+ if pending_logs:
210
+ _flush_pending(include_run=True)
211
+ else:
212
+ pending_run = None
213
+ in_test_log = False
214
+ continue
215
+
216
+ if ln.strip() == "FAIL":
217
+ if pending_logs:
218
+ _flush_pending(include_run=True)
219
+ else:
220
+ pending_run = None
221
+ in_test_log = False
222
+ continue
223
+
224
+ # Buffer clean `*_test.go:line:` t.Log lines (and indented continuations)
225
+ # while inside a test so passing/skipped test logs don't leak into output.
226
+ if (
227
+ pending_run is not None
228
+ and not _GO_FAILURE_SIGNAL_RE.search(ln)
229
+ and (
230
+ _GO_TEST_FILE_LINE_RE.match(ln)
231
+ or (in_test_log and ln.startswith((" ", "\t")) and ln.strip())
232
+ )
233
+ ):
234
+ pending_logs.append(ln)
235
+ in_test_log = True
236
+ continue
237
+
238
+ # Everything else (compile errors, panic frames, Example got/want,
239
+ # helper.go diagnostics, log lines, WARNING: DATA RACE, benchmarks)
240
+ # is NOT known pass noise: keep it verbatim.
241
+ _flush_pending(include_run=True)
242
+ kept_lines.append(ln)
243
+
244
+ if pending_logs:
245
+ _flush_pending(include_run=True)
246
+
247
+ # If no passing/skipped tests were collapsed, there is nothing to compress
248
+ # (e.g. pure `go test -bench=.` or pure compile-error output).
249
+ if passed == 0 and skipped == 0:
250
+ return None
251
+
252
+ header_parts = []
253
+ if passed:
254
+ header_parts.append(f"{passed} passed")
255
+ if failed:
256
+ header_parts.append(f"{failed} failed")
257
+ if skipped:
258
+ header_parts.append(f"{skipped} skipped")
259
+
260
+ out_parts: list[str] = []
261
+ if header_parts:
262
+ out_parts.append(f"go test: {', '.join(header_parts)}")
263
+ if kept_lines:
264
+ out_parts.append("\n".join(kept_lines))
265
+ if pkg_summaries:
266
+ out_parts.append("\n".join(pkg_summaries))
267
+
268
+ result = "\n\n".join(out_parts)
269
+ if not result or len(result) >= len(output):
270
+ return None
271
+ return result
272
+
273
+
274
+ def compress_cargo_test(output: str) -> str | None:
275
+ """Compress verbose ``cargo test`` output across single or multi-crate runs."""
276
+ lines = output.strip().splitlines()
277
+ if len(lines) < _MIN_LINES:
278
+ return None
279
+
280
+ has_cargo_marker = any(_CARGO_RESULT_RE.match(ln) for ln in lines) and any(
281
+ _CARGO_RUNNING_RE.match(ln)
282
+ or _CARGO_TEST_OK_RE.match(ln)
283
+ or _CARGO_TEST_FAILED_RE.match(ln)
284
+ for ln in lines
285
+ )
286
+ if not has_cargo_marker:
287
+ return None
288
+
289
+ ok_count = 0
290
+ ignored_count = 0
291
+ failed_tests: list[str] = []
292
+ result_lines: list[str] = []
293
+ kept_lines: list[str] = []
294
+ has_error_signal = False
295
+
296
+ in_failures = False
297
+ current_suite = ""
298
+ suite_emitted_result = True
299
+
300
+ for ln in lines:
301
+ if not in_failures and (_CARGO_RUNNING_BIN_RE.match(ln) or _CARGO_DOC_HEADER_RE.match(ln)):
302
+ current_suite = ln.strip()
303
+ suite_emitted_result = False
304
+ continue
305
+ if not in_failures and _CARGO_RUNNING_RE.match(ln):
306
+ continue
307
+ if not in_failures and _CARGO_TEST_OK_RE.match(ln):
308
+ ok_count += 1
309
+ continue
310
+ if not in_failures and _CARGO_TEST_IGNORED_RE.match(ln):
311
+ ignored_count += 1
312
+ continue
313
+ if _CARGO_TEST_FAILED_RE.match(ln):
314
+ failed_tests.append(ln)
315
+ has_error_signal = True
316
+ continue
317
+ if ln.strip() == "failures:":
318
+ in_failures = True
319
+ has_error_signal = True
320
+ kept_lines.append(ln)
321
+ continue
322
+ if _CARGO_RESULT_RE.match(ln):
323
+ in_failures = False
324
+ suite_emitted_result = True
325
+ if "FAILED" in ln:
326
+ has_error_signal = True
327
+ label = f"[{current_suite}] {ln}" if current_suite else ln
328
+ result_lines.append(label)
329
+ continue
330
+ if in_failures:
331
+ kept_lines.append(ln)
332
+ continue
333
+ if not ln.strip():
334
+ continue
335
+
336
+ # Any other non-empty line (abort/SIGABRT, `error: test failed`,
337
+ # `Caused by:`, `--nocapture` inline panics, `to rerun pass`, compiler
338
+ # warnings/errors) is NOT known pass noise: keep it verbatim.
339
+ if _CARGO_ERROR_SIGNAL_RE.search(ln):
340
+ has_error_signal = True
341
+ if current_suite and not suite_emitted_result:
342
+ kept_lines.append(f"[{current_suite}]")
343
+ suite_emitted_result = True
344
+ kept_lines.append(ln)
345
+
346
+ if ok_count == 0 and ignored_count == 0:
347
+ return None
348
+ if not result_lines and not failed_tests and not kept_lines:
349
+ return None
350
+
351
+ out_parts: list[str] = []
352
+ note = f"cargo test: {ok_count} ok"
353
+ if ignored_count:
354
+ note += f", {ignored_count} ignored"
355
+ if failed_tests:
356
+ note += f", {len(failed_tests)} FAILED"
357
+ elif has_error_signal:
358
+ note += " (errors/abort)"
359
+ out_parts.append(note)
360
+
361
+ if failed_tests:
362
+ out_parts.append("\n".join(failed_tests))
363
+ if kept_lines:
364
+ out_parts.append("\n".join(kept_lines))
365
+ if result_lines:
366
+ out_parts.append("\n".join(result_lines))
367
+
368
+ result = "\n\n".join(out_parts)
369
+ if not result or len(result) >= len(output):
370
+ return None
371
+ return result
372
+
373
+
374
+ def compress_node_test(output: str) -> str | None:
375
+ """Compress verbose ``node --test`` TAP or spec output."""
376
+ lines = output.strip().splitlines()
377
+ if len(lines) < _MIN_LINES:
378
+ return None
379
+
380
+ summary_lines = [ln for ln in lines if _NODE_SUMMARY_RE.match(ln)]
381
+ if len(summary_lines) < 2:
382
+ return None
383
+
384
+ has_any_failure = any(
385
+ _NODE_TAP_FAIL_RE.match(ln) or _NODE_SPEC_FAIL_RE.match(ln)
386
+ for ln in lines
387
+ )
388
+
389
+ passed = 0
390
+ kept_lines: list[str] = []
391
+ i = 0
392
+ n = len(lines)
393
+
394
+ while i < n:
395
+ ln = lines[i]
396
+ if _NODE_SUMMARY_RE.match(ln):
397
+ i += 1
398
+ continue
399
+ if _NODE_TAP_OK_RE.match(ln):
400
+ passed += 1
401
+ i += 1
402
+ # Drop optional duration-only YAML metadata block on passing TAP tests.
403
+ if i < n and lines[i].strip() == "---":
404
+ j = i + 1
405
+ yaml_only_pass = True
406
+ while j < n and lines[j].strip() != "...":
407
+ if not _NODE_YAML_PASS_KEY_RE.match(lines[j]):
408
+ yaml_only_pass = False
409
+ break
410
+ j += 1
411
+ if yaml_only_pass and j < n and lines[j].strip() == "...":
412
+ i = j + 1
413
+ continue
414
+ if _NODE_SPEC_OK_RE.match(ln):
415
+ passed += 1
416
+ i += 1
417
+ continue
418
+ if not has_any_failure and (
419
+ _NODE_TAP_VERSION_RE.match(ln)
420
+ or _NODE_TAP_PLAN_RE.match(ln)
421
+ or _NODE_TAP_SUBTEST_RE.match(ln)
422
+ or _NODE_SPEC_SUITE_RE.match(ln)
423
+ ):
424
+ i += 1
425
+ continue
426
+ if has_any_failure and (
427
+ _NODE_TAP_VERSION_RE.match(ln)
428
+ or _NODE_TAP_PLAN_RE.match(ln)
429
+ ):
430
+ i += 1
431
+ continue
432
+ if has_any_failure and _NODE_TAP_SUBTEST_RE.match(ln):
433
+ # Drop `# Subtest:` only if the immediately following line is a passing `ok`.
434
+ if i + 1 < n and _NODE_TAP_OK_RE.match(lines[i + 1]):
435
+ i += 1
436
+ continue
437
+ if not ln.strip():
438
+ # Keep single blank lines inside failure sections for readability.
439
+ if kept_lines and kept_lines[-1] != "":
440
+ kept_lines.append("")
441
+ i += 1
442
+ continue
443
+
444
+ # Everything else (not ok, ✖, `test at file:line`, YAML error blocks,
445
+ # AssertionError, diffs, stack traces) is NOT known pass noise: keep it.
446
+ kept_lines.append(ln)
447
+ i += 1
448
+
449
+ while kept_lines and kept_lines[-1] == "":
450
+ kept_lines.pop()
451
+
452
+ if passed == 0:
453
+ return None
454
+
455
+ out_parts: list[str] = []
456
+ if kept_lines:
457
+ out_parts.append("\n".join(kept_lines))
458
+ out_parts.append("\n".join(summary_lines))
459
+
460
+ result = "\n\n".join(out_parts)
461
+ if not result or len(result) >= len(output):
462
+ return None
463
+ return result
464
+
465
+
466
+ def compress_structured_test_output(output: str, runner: str | None = None) -> str | None:
467
+ """Compress Go, Cargo, or Node test output.
468
+
469
+ When ``runner`` is given (``'go'``, ``'cargo'``, ``'node'``), only that
470
+ runner's compressor is invoked so one runner's output is never misparsed
471
+ as another. Unknown explicit runners return ``None``.
472
+ """
473
+ dispatch = {
474
+ "go": compress_go_test,
475
+ "cargo": compress_cargo_test,
476
+ "node": compress_node_test,
477
+ }
478
+ if runner is not None:
479
+ fn = dispatch.get(runner)
480
+ return fn(output) if fn is not None else None
481
+ for fn in (compress_go_test, compress_cargo_test, compress_node_test):
482
+ res = fn(output)
483
+ if res is not None:
484
+ return res
485
+ return None
486
+
487
+
488
+ def compress_for_command(output: str, command_str: str) -> str | None:
489
+ """Detect the runner from ``command_str`` and compress only that runner's format."""
490
+ runner = detect_runner(command_str)
491
+ if runner is None:
492
+ return None
493
+ return compress_structured_test_output(output, runner=runner)
@@ -59,6 +59,9 @@ _PAYLOAD_MODULES = (
59
59
  "post_run_classify.py",
60
60
  "preserved_reinject.py",
61
61
  "bash_search_results.py",
62
+ "command_compress_extra.py",
63
+ "visibility_rule.py",
64
+ "emit_safety_gate.py",
62
65
  # Dependency-free whitelist gate shared by bash_hook + bash_compress.
63
66
  # Without it, `import bash_hook` fails in the installed path, the bridge
64
67
  # sets _bash_hook = None, and the entire PreToolUse bash compression
@@ -76,9 +76,12 @@ REQUIRED_ENGINE_SCRIPTS = (
76
76
  "hermes_tool_hooks.py",
77
77
  "bash_compress_hook.py",
78
78
  "archive_result.py",
79
+ "builtin_tool_compress.py",
79
80
  "archive_verify.py",
80
81
  "context_intel.py",
81
82
  "read_cache.py",
83
+ "compact_markers.py",
84
+ "process_identity.py",
82
85
  "session_store.py",
83
86
  "session_store_guard.py",
84
87
  "refetch_guard.py",
@@ -354,7 +357,7 @@ def _registration_checks() -> list[dict[str, str]]:
354
357
 
355
358
 
356
359
  # Completeness is separate from the legacy healthy-output counts.
357
- _MEASURE_PACKAGE_FILES = ('_measure/__init__.py', '_measure/_compat.py', '_measure/runtime.py', '_measure/pricing.py', '_measure/audit.py', '_measure/dashboard.py', '_measure/lifecycle.py', '_measure/sessions.py', '_measure/trends.py', '_measure/cache_policy.py', '_measure/daemon.py', '_measure/quality_archive.py', '_measure/continuity.py', '_measure/savings.py', '_measure/cli.py', '_measure/dashboard_history.py', '_measure/weekly_activity.py', '_measure/headline.py', '_measure/counted_position.py', '_measure/counted_pricing_v5.py', '_measure/transcript_backfill.py', '_measure/counted_subagents.py', '_measure/lean_resume_threshold.py', '_measure/output_reread.py', '_measure/session_effect.py', '_measure/structural_ledger.py', '_measure/structural_archives.py', '_measure/structural_listing.py', '_measure/structural_report.py', '_measure/structural_seed.py', '_measure/structural_value.py', '_measure/rework_metrics.py', '_measure/session_best.py', '_measure/savings_story.py', '_measure/savings_headline.py', '_measure/counted_orphans.py', '_measure/counted_cap.py', '_measure/archive_void_evidence.py', '_measure/cost_per_message_trend.py', '_measure/lean_resume_receivers.py', '_measure/routing_period.py', '_measure/fixture_context.py', '_measure/transcript_product.py', '_measure/periphery_exposure.py', '_measure/structure_funnel.py', '_measure/setup_attachment_counter.py', '_measure/first_read_outcomes.py', '_measure/setup_budget_monitor.py', '_measure/setup_connector_ledger.py', '_measure/first_call_context.py', '_measure/timestamp_cache.py', '_measure/token_type_split.py', '_measure/evidence_parallel.py', '_measure/ttl_period.py', '_measure/first_read_revive.py', '_measure/mcp_archive_tripwire.py', '_measure/compaction_survival.py', '_measure/archive_void_codex.py', '_measure/compression_fixture_void.py', '_measure/feature_health.py', '_measure/archive_health.py', '_measure/coverage_report.py', '_measure/file_refetch.py', '_measure/holdout_report.py', '_measure/structural_dedupe.py', '_measure/setup_step.py', '_measure/baseline_provenance.py', '_measure/own_price_card.py', '_measure/transcript_stream.py', '_measure/checkpoint_direction.py', '_measure/checkpoint_retention.py', '_measure/keepwarm_safety.py', '_measure/keepwarm_economics.py', '_measure/keepwarm_linux.py', '_measure/mod_action_booking.py', '_measure/mod_action_diagnostics.py', '_measure/mod_action_selftest.py', '_measure/install_baseline.py', '_measure/routing_credit.py', '_measure/mod_compaction_booking.py', '_measure/mod_fresh_booking.py', '_measure/quality_continuity.py', '_measure/quality_checkpoint.py', '_measure/codex_quality.py', '_measure/lease_candidate_cleanup.py', '_measure/session_store_spool.py', '_measure/upgrade_drain_control.py', '_measure/compression_scan_checkpoint.py', '_measure/status_bar_lock.py', '_measure/session_flush_lock.py', '_measure/context_reset_marker.py', '_measure/holdout_fallback.py', '_measure/dashboard_heal_claim.py', '_measure/config_cache.py', '_measure/setup_observation_cache.py', '_measure/status_bar_refresh.py', '_measure/routing_default.py', '_measure/pilot_report.py', '_measure/nudge_followthrough.py', '_measure/runway_all_in.py', '_measure/session_activity.py', '_measure/routing_savings.py')
360
+ _MEASURE_PACKAGE_FILES = ('_measure/__init__.py', '_measure/_compat.py', '_measure/runtime.py', '_measure/pricing.py', '_measure/audit.py', '_measure/dashboard.py', '_measure/lifecycle.py', '_measure/sessions.py', '_measure/trends.py', '_measure/cache_policy.py', '_measure/daemon.py', '_measure/quality_archive.py', '_measure/continuity.py', '_measure/savings.py', '_measure/cli.py', '_measure/dashboard_history.py', '_measure/weekly_activity.py', '_measure/headline.py', '_measure/counted_position.py', '_measure/counted_pricing_v5.py', '_measure/transcript_backfill.py', '_measure/counted_subagents.py', '_measure/lean_resume_threshold.py', '_measure/output_reread.py', '_measure/session_effect.py', '_measure/structural_ledger.py', '_measure/structural_archives.py', '_measure/structural_listing.py', '_measure/structural_report.py', '_measure/structural_seed.py', '_measure/structural_value.py', '_measure/rework_metrics.py', '_measure/session_best.py', '_measure/savings_story.py', '_measure/savings_headline.py', '_measure/counted_orphans.py', '_measure/counted_cap.py', '_measure/archive_void_evidence.py', '_measure/cost_per_message_trend.py', '_measure/lean_resume_receivers.py', '_measure/routing_period.py', '_measure/fixture_context.py', '_measure/transcript_product.py', '_measure/periphery_exposure.py', '_measure/structure_funnel.py', '_measure/setup_attachment_counter.py', '_measure/first_read_outcomes.py', '_measure/setup_budget_monitor.py', '_measure/setup_connector_ledger.py', '_measure/first_call_context.py', '_measure/timestamp_cache.py', '_measure/token_type_split.py', '_measure/evidence_parallel.py', '_measure/ttl_period.py', '_measure/first_read_revive.py', '_measure/mcp_archive_tripwire.py', '_measure/compaction_survival.py', '_measure/archive_void_codex.py', '_measure/compression_fixture_void.py', '_measure/feature_health.py', '_measure/archive_health.py', '_measure/coverage_report.py', '_measure/file_refetch.py', '_measure/holdout_report.py', '_measure/structural_dedupe.py', '_measure/setup_step.py', '_measure/baseline_provenance.py', '_measure/own_price_card.py', '_measure/transcript_stream.py', '_measure/checkpoint_direction.py', '_measure/checkpoint_retention.py', '_measure/keepwarm_safety.py', '_measure/keepwarm_economics.py', '_measure/keepwarm_linux.py', '_measure/mod_action_booking.py', '_measure/mod_action_diagnostics.py', '_measure/mod_action_selftest.py', '_measure/install_baseline.py', '_measure/routing_credit.py', '_measure/mod_compaction_booking.py', '_measure/mod_fresh_booking.py', '_measure/quality_continuity.py', '_measure/quality_checkpoint.py', '_measure/codex_quality.py', '_measure/lease_candidate_cleanup.py', '_measure/session_store_spool.py', '_measure/upgrade_drain_control.py', '_measure/compression_scan_checkpoint.py', '_measure/status_bar_lock.py', '_measure/session_flush_lock.py', '_measure/context_reset_marker.py', '_measure/holdout_fallback.py', '_measure/dashboard_heal_claim.py', '_measure/config_cache.py', '_measure/setup_observation_cache.py', '_measure/status_bar_refresh.py', '_measure/routing_default.py', '_measure/pilot_report.py', '_measure/nudge_followthrough.py', '_measure/runway_all_in.py', '_measure/session_activity.py', '_measure/routing_savings.py', '_measure/pt_resume_cues.py', '_measure/subscription_audits.py', '_measure/limit_units.py', '_measure/local_adapt.py', '_measure/prefix_cost.py', '_measure/poc_commands.py', '_measure/counted_closes.py', '_measure/counted_headline.py', '_measure/apply_safe.py', '_measure/autocompact_advice.py', '_measure/cold_guard.py', '_measure/keepwarm_auto.py', '_measure/next_actions.py')
358
361
 
359
362
 
360
363
  def _engine_checks() -> list[dict[str, str]]:
@@ -68,10 +68,19 @@ _RUNTIME_MODULES = (
68
68
  _ENGINE_SCRIPTS = (
69
69
  "hermes_tool_hooks.py",
70
70
  "bash_compress_hook.py",
71
+ "command_compress_extra.py",
72
+ "visibility_rule.py",
73
+ "emit_safety_gate.py",
74
+ "pipe_file_compress.py",
75
+ "large_output_policy.py",
71
76
  "archive_result.py",
77
+ "builtin_tool_compress.py",
72
78
  "archive_verify.py",
73
79
  "context_intel.py",
74
80
  "read_cache.py",
81
+ "big_noncode_read.py",
82
+ "compact_markers.py",
83
+ "process_identity.py",
75
84
  "session_store.py",
76
85
  "session_store_guard.py",
77
86
  "refetch_guard.py",
@@ -97,7 +106,7 @@ _ENABLE_SNIPPET = "plugins:\n enabled:\n - token-optimizer\n"
97
106
 
98
107
 
99
108
  # Completeness is separate from the legacy healthy-output counts.
100
- _MEASURE_PACKAGE_FILES = ('_measure/__init__.py', '_measure/_compat.py', '_measure/runtime.py', '_measure/pricing.py', '_measure/audit.py', '_measure/dashboard.py', '_measure/lifecycle.py', '_measure/sessions.py', '_measure/trends.py', '_measure/cache_policy.py', '_measure/daemon.py', '_measure/quality_archive.py', '_measure/continuity.py', '_measure/savings.py', '_measure/cli.py', '_measure/dashboard_history.py', '_measure/weekly_activity.py', '_measure/headline.py', '_measure/counted_position.py', '_measure/counted_pricing_v5.py', '_measure/transcript_backfill.py', '_measure/counted_subagents.py', '_measure/lean_resume_threshold.py', '_measure/output_reread.py', '_measure/session_effect.py', '_measure/structural_ledger.py', '_measure/structural_archives.py', '_measure/structural_listing.py', '_measure/structural_report.py', '_measure/structural_seed.py', '_measure/structural_value.py', '_measure/rework_metrics.py', '_measure/session_best.py', '_measure/savings_story.py', '_measure/savings_headline.py', '_measure/counted_orphans.py', '_measure/counted_cap.py', '_measure/archive_void_evidence.py', '_measure/cost_per_message_trend.py', '_measure/lean_resume_receivers.py', '_measure/routing_period.py', '_measure/fixture_context.py', '_measure/transcript_product.py', '_measure/periphery_exposure.py', '_measure/structure_funnel.py', '_measure/setup_attachment_counter.py', '_measure/first_read_outcomes.py', '_measure/setup_budget_monitor.py', '_measure/setup_connector_ledger.py', '_measure/first_call_context.py', '_measure/timestamp_cache.py', '_measure/token_type_split.py', '_measure/evidence_parallel.py', '_measure/ttl_period.py', '_measure/first_read_revive.py', '_measure/mcp_archive_tripwire.py', '_measure/compaction_survival.py', '_measure/archive_void_codex.py', '_measure/compression_fixture_void.py', '_measure/feature_health.py', '_measure/archive_health.py', '_measure/coverage_report.py', '_measure/file_refetch.py', '_measure/holdout_report.py', '_measure/structural_dedupe.py', '_measure/setup_step.py', '_measure/baseline_provenance.py', '_measure/own_price_card.py', '_measure/transcript_stream.py', '_measure/checkpoint_direction.py', '_measure/checkpoint_retention.py', '_measure/keepwarm_safety.py', '_measure/keepwarm_economics.py', '_measure/keepwarm_linux.py', '_measure/mod_action_booking.py', '_measure/mod_action_diagnostics.py', '_measure/mod_action_selftest.py', '_measure/install_baseline.py', '_measure/routing_credit.py', '_measure/mod_compaction_booking.py', '_measure/mod_fresh_booking.py', '_measure/quality_continuity.py', '_measure/quality_checkpoint.py', '_measure/codex_quality.py', '_measure/lease_candidate_cleanup.py', '_measure/session_store_spool.py', '_measure/upgrade_drain_control.py', '_measure/compression_scan_checkpoint.py', '_measure/status_bar_lock.py', '_measure/session_flush_lock.py', '_measure/context_reset_marker.py', '_measure/holdout_fallback.py', '_measure/dashboard_heal_claim.py', '_measure/config_cache.py', '_measure/setup_observation_cache.py', '_measure/status_bar_refresh.py', '_measure/routing_default.py', '_measure/pilot_report.py', '_measure/nudge_followthrough.py', '_measure/runway_all_in.py', '_measure/session_activity.py', '_measure/routing_savings.py')
109
+ _MEASURE_PACKAGE_FILES = ('_measure/__init__.py', '_measure/_compat.py', '_measure/runtime.py', '_measure/pricing.py', '_measure/audit.py', '_measure/dashboard.py', '_measure/lifecycle.py', '_measure/sessions.py', '_measure/trends.py', '_measure/cache_policy.py', '_measure/daemon.py', '_measure/quality_archive.py', '_measure/continuity.py', '_measure/savings.py', '_measure/cli.py', '_measure/dashboard_history.py', '_measure/weekly_activity.py', '_measure/headline.py', '_measure/counted_position.py', '_measure/counted_pricing_v5.py', '_measure/transcript_backfill.py', '_measure/counted_subagents.py', '_measure/lean_resume_threshold.py', '_measure/output_reread.py', '_measure/session_effect.py', '_measure/structural_ledger.py', '_measure/structural_archives.py', '_measure/structural_listing.py', '_measure/structural_report.py', '_measure/structural_seed.py', '_measure/structural_value.py', '_measure/rework_metrics.py', '_measure/session_best.py', '_measure/savings_story.py', '_measure/savings_headline.py', '_measure/counted_orphans.py', '_measure/counted_cap.py', '_measure/archive_void_evidence.py', '_measure/cost_per_message_trend.py', '_measure/lean_resume_receivers.py', '_measure/routing_period.py', '_measure/fixture_context.py', '_measure/transcript_product.py', '_measure/periphery_exposure.py', '_measure/structure_funnel.py', '_measure/setup_attachment_counter.py', '_measure/first_read_outcomes.py', '_measure/setup_budget_monitor.py', '_measure/setup_connector_ledger.py', '_measure/first_call_context.py', '_measure/timestamp_cache.py', '_measure/token_type_split.py', '_measure/evidence_parallel.py', '_measure/ttl_period.py', '_measure/first_read_revive.py', '_measure/mcp_archive_tripwire.py', '_measure/compaction_survival.py', '_measure/archive_void_codex.py', '_measure/compression_fixture_void.py', '_measure/feature_health.py', '_measure/archive_health.py', '_measure/coverage_report.py', '_measure/file_refetch.py', '_measure/holdout_report.py', '_measure/structural_dedupe.py', '_measure/setup_step.py', '_measure/baseline_provenance.py', '_measure/own_price_card.py', '_measure/transcript_stream.py', '_measure/checkpoint_direction.py', '_measure/checkpoint_retention.py', '_measure/keepwarm_safety.py', '_measure/keepwarm_economics.py', '_measure/keepwarm_linux.py', '_measure/mod_action_booking.py', '_measure/mod_action_diagnostics.py', '_measure/mod_action_selftest.py', '_measure/install_baseline.py', '_measure/routing_credit.py', '_measure/mod_compaction_booking.py', '_measure/mod_fresh_booking.py', '_measure/quality_continuity.py', '_measure/quality_checkpoint.py', '_measure/codex_quality.py', '_measure/lease_candidate_cleanup.py', '_measure/session_store_spool.py', '_measure/upgrade_drain_control.py', '_measure/compression_scan_checkpoint.py', '_measure/status_bar_lock.py', '_measure/session_flush_lock.py', '_measure/context_reset_marker.py', '_measure/holdout_fallback.py', '_measure/dashboard_heal_claim.py', '_measure/config_cache.py', '_measure/setup_observation_cache.py', '_measure/status_bar_refresh.py', '_measure/routing_default.py', '_measure/pilot_report.py', '_measure/nudge_followthrough.py', '_measure/runway_all_in.py', '_measure/session_activity.py', '_measure/routing_savings.py', '_measure/pt_resume_cues.py', '_measure/subscription_audits.py', '_measure/limit_units.py', '_measure/local_adapt.py', '_measure/prefix_cost.py', '_measure/poc_commands.py', '_measure/counted_closes.py', '_measure/counted_headline.py', '_measure/apply_safe.py', '_measure/autocompact_advice.py', '_measure/cold_guard.py', '_measure/keepwarm_auto.py', '_measure/next_actions.py')
101
110
 
102
111
 
103
112
  def _scripts_dir() -> Path:
@@ -0,0 +1,94 @@
1
+ """Hook fast-path early-exit and monotonic time box (SPEC-hook-fastpath).
2
+
3
+ Pure stdlib (os, time, pathlib) so importing this module costs <1 ms and never
4
+ pulls in sqlite3, session_store, archive_result, or bash_compress.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ import os
9
+ import time
10
+ from pathlib import Path
11
+
12
+ DEFAULT_COMPRESSION_BUDGET_S = 1.5
13
+ _QUALITY_THROTTLE_S = 120.0
14
+
15
+
16
+ class BudgetExceeded(Exception):
17
+ """Raised when in-process compression or verification exceeds its time box."""
18
+
19
+
20
+ class MonotonicBudget:
21
+ """In-process monotonic deadline checked at line-batch granularity."""
22
+
23
+ __slots__ = ("deadline",)
24
+
25
+ def __init__(self, seconds: float = DEFAULT_COMPRESSION_BUDGET_S) -> None:
26
+ self.deadline = time.monotonic() + max(0.01, float(seconds))
27
+
28
+ def check(self, index: int = 0, stride: int = 64) -> None:
29
+ if stride <= 1 or (index % stride) == 0:
30
+ if time.monotonic() > self.deadline:
31
+ raise BudgetExceeded("compression time box exceeded")
32
+
33
+
34
+ def _quality_throttle_due(session_id: str, snapshot_dir: Path | None) -> bool:
35
+ """True if quality-cache file exists and is older than _QUALITY_THROTTLE_S.
36
+
37
+ If no cache file exists yet, throttle-only mode is a guaranteed no-op
38
+ (see test_throttle_only_cache_miss_never_parses_transcript), so return False.
39
+ """
40
+ if not snapshot_dir or not session_id:
41
+ return False
42
+ try:
43
+ qfile = snapshot_dir / f"quality-cache-{session_id}.json"
44
+ if not qfile.is_file():
45
+ return False
46
+ age = time.time() - qfile.stat().st_mtime
47
+ return age >= _QUALITY_THROTTLE_S
48
+ except OSError:
49
+ return False
50
+
51
+
52
+ def _resolve_snapshot_dir() -> Path | None:
53
+ env_dir = os.environ.get("TOKEN_OPTIMIZER_SNAPSHOT_DIR", "").strip()
54
+ if env_dir:
55
+ return Path(env_dir)
56
+ pdata = os.environ.get("CLAUDE_PLUGIN_DATA", "").strip() or os.environ.get("TOKEN_OPTIMIZER_PLUGIN_DATA", "").strip()
57
+ if pdata:
58
+ return Path(pdata)
59
+ return Path.home() / ".claude" / "token-optimizer"
60
+
61
+
62
+ def can_early_exit_posttooluse(
63
+ hook_input: dict,
64
+ snapshot_dir: Path | None = None,
65
+ *,
66
+ only_throttle_matches: bool = False,
67
+ ) -> bool:
68
+ """Return True only when PostToolUse is provably a no-op.
69
+
70
+ The runner's sole proven no-op is a tool whose only matching handler is the
71
+ quality-cache throttle tick, with no tick due. Every tool that matches
72
+ context_intel (Bash, Edit, Write, Read, ...) always records an activity row,
73
+ and Edit-family tools always invalidate the read cache, so neither may skip.
74
+ The caller states the matcher result via ``only_throttle_matches``; without
75
+ it this returns False.
76
+ """
77
+ if not only_throttle_matches or not isinstance(hook_input, dict):
78
+ return False
79
+ if hook_input.get("hook_event_name") == "PostToolUseFailure":
80
+ return False
81
+ if os.environ.get("TOKEN_OPTIMIZER_COVERAGE_FUNNEL", "").strip() == "1":
82
+ return False
83
+ session_id = str(hook_input.get("session_id") or "")
84
+ sdir = snapshot_dir if snapshot_dir is not None else _resolve_snapshot_dir()
85
+ return not _quality_throttle_due(session_id, sdir)
86
+
87
+
88
+ def skip_posttooluse(pending_names: list[str], hook_input: dict) -> bool:
89
+ """Runner entry: skip ONLY when the quality-throttle tick is the sole
90
+ matching handler and it is provably not due. Any tool that reaches
91
+ context_intel, archive, compression or invalidation always does real work."""
92
+ if list(pending_names) != ["quality-cache --throttle-only"]:
93
+ return False
94
+ return can_early_exit_posttooluse(hook_input, only_throttle_matches=True)