@alexgreensh/token-optimizer 5.13.74 → 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.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/hooks/module_runner.py +1 -1
- package/hooks/posttooluse_runner.py +7 -9
- package/hooks/run.py +5 -1
- package/hooks/stop_runner.py +15 -56
- package/hooks/userpromptsubmit_runner.py +29 -4
- package/package.json +1 -1
- package/skills/token-optimizer/assets/dashboard.html +30 -14
- package/skills/token-optimizer/assets/savings_story.js +103 -27
- package/skills/token-optimizer/references/agent-prompts.md +2 -0
- package/skills/token-optimizer/references/implementation-playbook.md +1 -0
- package/skills/token-optimizer/scripts/_measure/__init__.py +1 -1
- package/skills/token-optimizer/scripts/_measure/apply_safe.py +512 -0
- package/skills/token-optimizer/scripts/_measure/audit.py +9 -20
- package/skills/token-optimizer/scripts/_measure/autocompact_advice.py +455 -0
- package/skills/token-optimizer/scripts/_measure/cache_policy.py +82 -127
- package/skills/token-optimizer/scripts/_measure/cli.py +10 -24
- package/skills/token-optimizer/scripts/_measure/cold_guard.py +777 -0
- package/skills/token-optimizer/scripts/_measure/continuity.py +45 -4
- package/skills/token-optimizer/scripts/_measure/counted_closes.py +398 -0
- package/skills/token-optimizer/scripts/_measure/counted_headline.py +112 -0
- package/skills/token-optimizer/scripts/_measure/dashboard.py +14 -6
- package/skills/token-optimizer/scripts/_measure/feature_health.py +6 -0
- package/skills/token-optimizer/scripts/_measure/keepwarm_auto.py +452 -0
- package/skills/token-optimizer/scripts/_measure/keepwarm_economics.py +8 -4
- package/skills/token-optimizer/scripts/_measure/keepwarm_safety.py +548 -24
- package/skills/token-optimizer/scripts/_measure/limit_units.py +463 -0
- package/skills/token-optimizer/scripts/_measure/local_adapt.py +192 -0
- package/skills/token-optimizer/scripts/_measure/mod_action_booking.py +71 -14
- package/skills/token-optimizer/scripts/_measure/next_actions.py +420 -0
- package/skills/token-optimizer/scripts/_measure/poc_commands.py +44 -0
- package/skills/token-optimizer/scripts/_measure/prefix_cost.py +215 -0
- package/skills/token-optimizer/scripts/_measure/pt_resume_cues.py +46 -0
- package/skills/token-optimizer/scripts/_measure/quality_archive.py +7 -10
- package/skills/token-optimizer/scripts/_measure/savings.py +80 -82
- package/skills/token-optimizer/scripts/_measure/savings_headline.py +17 -21
- package/skills/token-optimizer/scripts/_measure/savings_story.py +8 -1
- package/skills/token-optimizer/scripts/_measure/session_store_spool.py +119 -78
- package/skills/token-optimizer/scripts/_measure/status_bar_refresh.py +38 -3
- package/skills/token-optimizer/scripts/_measure/structural_ledger.py +1 -1
- package/skills/token-optimizer/scripts/_measure/subscription_audits.py +725 -0
- package/skills/token-optimizer/scripts/_measure/transcript_backfill.py +1 -1
- package/skills/token-optimizer/scripts/_measure/transcript_stream.py +8 -2
- package/skills/token-optimizer/scripts/antigravity_install.py +3 -0
- package/skills/token-optimizer/scripts/archive_result.py +16 -28
- package/skills/token-optimizer/scripts/archive_verify.py +1 -1
- package/skills/token-optimizer/scripts/bash_compress.py +156 -176
- package/skills/token-optimizer/scripts/bash_compress_hook.py +218 -174
- package/skills/token-optimizer/scripts/bash_search_results.py +189 -9
- package/skills/token-optimizer/scripts/bash_whitelist.py +6 -1
- package/skills/token-optimizer/scripts/benchmark.py +11 -13
- package/skills/token-optimizer/scripts/big_noncode_read.py +998 -0
- package/skills/token-optimizer/scripts/build_output_compress.py +103 -8
- package/skills/token-optimizer/scripts/builtin_tool_compress.py +716 -0
- package/skills/token-optimizer/scripts/cloud_kit.py +1 -1
- package/skills/token-optimizer/scripts/codex_doctor.py +1 -1
- package/skills/token-optimizer/scripts/command_compress_extra.py +955 -0
- package/skills/token-optimizer/scripts/compact_markers.py +129 -0
- package/skills/token-optimizer/scripts/copilot_install.py +3 -0
- package/skills/token-optimizer/scripts/cursor_install.py +7 -0
- package/skills/token-optimizer/scripts/devin_source.py +5 -5
- package/skills/token-optimizer/scripts/emit_safety_gate.py +518 -0
- package/skills/token-optimizer/scripts/fixtures/b2_more_commands.json +142 -0
- package/skills/token-optimizer/scripts/fixtures/b5_more_savings.json +26 -0
- package/skills/token-optimizer/scripts/fixtures/builtin_tools.json +103 -0
- package/skills/token-optimizer/scripts/fixtures/c7_review_ratchet.json +52 -0
- package/skills/token-optimizer/scripts/fixtures/large_output_policy.json +55 -0
- package/skills/token-optimizer/scripts/go_cargo_test_compress.py +493 -0
- package/skills/token-optimizer/scripts/grok_install.py +3 -0
- package/skills/token-optimizer/scripts/hermes_doctor.py +4 -1
- package/skills/token-optimizer/scripts/hermes_install.py +10 -1
- package/skills/token-optimizer/scripts/hook_fastpath.py +94 -0
- package/skills/token-optimizer/scripts/hook_runtime.py +6 -2
- package/skills/token-optimizer/scripts/large_output_policy.py +431 -0
- package/skills/token-optimizer/scripts/measure.py +10 -12
- package/skills/token-optimizer/scripts/pipe_file_compress.py +900 -0
- package/skills/token-optimizer/scripts/pipeline_analyzer.py +15 -1
- package/skills/token-optimizer/scripts/post_run_classify.py +2 -2
- package/skills/token-optimizer/scripts/preserved_reinject.py +20 -3
- package/skills/token-optimizer/scripts/process_identity.py +66 -0
- package/skills/token-optimizer/scripts/read_cache.py +51 -60
- package/skills/token-optimizer/scripts/statusline.js +21 -3
- package/skills/token-optimizer/scripts/visibility_rule.py +536 -0
|
@@ -101,8 +101,14 @@ _BUILD_TEST_COMMANDS: dict[str, frozenset[str] | None] = {
|
|
|
101
101
|
"tox": None, "nox": None,
|
|
102
102
|
# Ruby
|
|
103
103
|
"rspec": None, "rake": None,
|
|
104
|
-
# Python project/dependency
|
|
104
|
+
# Python project/dependency managers (pip install, uv run/sync/pip)
|
|
105
|
+
"pip": frozenset({"install", "wheel", "download"}),
|
|
106
|
+
"pip3": frozenset({"install", "wheel", "download"}),
|
|
105
107
|
"uv": frozenset({"run", "sync", "pip"}),
|
|
108
|
+
# Package managers / IaC
|
|
109
|
+
"brew": frozenset({"install", "upgrade", "reinstall", "update"}),
|
|
110
|
+
"terraform": frozenset({"plan", "apply", "init", "validate"}),
|
|
111
|
+
"tofu": frozenset({"plan", "apply", "init", "validate"}),
|
|
106
112
|
# Debuggers / instrumentation
|
|
107
113
|
"valgrind": None,
|
|
108
114
|
"gdb": frozenset({"-batch"}),
|
|
@@ -127,6 +133,7 @@ _SHAPE_FALLBACK_KEYWORDS = frozenset({
|
|
|
127
133
|
"npm", "yarn", "pnpm", "mvn", "gradle", "cmake", "ninja", "gcc",
|
|
128
134
|
"g++", "cc", "clang", "rustc", "dotnet", "swift", "rspec", "rake",
|
|
129
135
|
"tox", "nox", "webpack", "vite", "rollup", "esbuild", "next",
|
|
136
|
+
"pip", "pip3", "brew", "terraform", "tofu",
|
|
130
137
|
})
|
|
131
138
|
|
|
132
139
|
# ---------------------------------------------------------------------------
|
|
@@ -166,6 +173,9 @@ _SHAPE_MARKER_PATTERNS = [
|
|
|
166
173
|
re.compile(r"Successfully installed"), # pip
|
|
167
174
|
re.compile(r"added \d+ package"), # npm
|
|
168
175
|
re.compile(r"removed \d+ package"), # npm
|
|
176
|
+
re.compile(r"^=== RUN\s+", re.MULTILINE), # go test -v
|
|
177
|
+
re.compile(r"^--- (?:PASS|FAIL|SKIP):\s+", re.MULTILINE), # go test -v
|
|
178
|
+
re.compile(r"^test result:\s+", re.MULTILINE), # cargo test
|
|
169
179
|
]
|
|
170
180
|
|
|
171
181
|
# Combined shape-marker regex for the classify_by_shape fallback (single
|
|
@@ -207,6 +217,12 @@ _ERROR_LINE_PATTERNS = [
|
|
|
207
217
|
re.compile(r"help: ", re.I), # Rust help
|
|
208
218
|
re.compile(r"panicked at", re.I), # Rust panic
|
|
209
219
|
re.compile(r"thread '.*' panicked", re.I), # Rust panic
|
|
220
|
+
re.compile(r"^\s*--- FAIL:\s+", re.MULTILINE), # go test failure
|
|
221
|
+
re.compile(r"^FAIL\t\S+", re.MULTILINE), # go test package failure
|
|
222
|
+
re.compile(r"^\s+\S+_test\.go:\d+:", re.MULTILINE), # go test assertion line
|
|
223
|
+
re.compile(r"^test .+? \.\.\. FAILED\s*$", re.MULTILINE), # cargo test failure
|
|
224
|
+
re.compile(r"^\s*(?:✖|not ok \d+ -)\s+", re.MULTILINE), # node --test failure
|
|
225
|
+
re.compile(r"^test at \S+:\d+", re.MULTILINE), # node spec failure site
|
|
210
226
|
]
|
|
211
227
|
|
|
212
228
|
# F4: import foreign-language and localized error markers from bash_compress
|
|
@@ -266,6 +282,11 @@ _SUMMARY_LINE_PATTERNS = [
|
|
|
266
282
|
re.compile(r"===\s*FAILURES\s*===", re.I),
|
|
267
283
|
re.compile(r"===\s*ERRORS\s*===", re.I),
|
|
268
284
|
re.compile(r"---\s*FAILED\s+---", re.I),
|
|
285
|
+
re.compile(r"^ok\s+\S+\t"), # go test package pass
|
|
286
|
+
re.compile(r"^FAIL\t\S+"), # go test package fail
|
|
287
|
+
re.compile(r"^\?\s+\S+\t\[no test files\]"), # go test no test files
|
|
288
|
+
re.compile(r"^test result:\s+"), # cargo test summary
|
|
289
|
+
re.compile(r"^(?:#|ℹ)\s+(?:tests|pass|fail|skipped)\s+\d+"), # node --test summary
|
|
269
290
|
]
|
|
270
291
|
|
|
271
292
|
_COMBINED_SUMMARY_RE = re.compile(
|
|
@@ -312,6 +333,13 @@ _PROGRESS_NOISE_PATTERNS = [
|
|
|
312
333
|
re.compile(r"^#[\d.]+\s+"),
|
|
313
334
|
# npm install progress
|
|
314
335
|
re.compile(r"^\s*⸨\s*⸩\s*"), # npm spinner
|
|
336
|
+
# Go test verbose pass/run/skip progress
|
|
337
|
+
re.compile(r"^\s*=== (?:RUN|PAUSE|CONT)\s+"),
|
|
338
|
+
re.compile(r"^\s*--- (?:PASS|SKIP):\s+"),
|
|
339
|
+
# Cargo per-test pass/ignored progress
|
|
340
|
+
re.compile(r"^test .+? \.\.\. (?:ok|ignored)\s*$"),
|
|
341
|
+
# Node --test passing lines
|
|
342
|
+
re.compile(r"^\s*(?:✔|ok \d+ -)\s+"),
|
|
315
343
|
]
|
|
316
344
|
|
|
317
345
|
_COMBINED_PROGRESS_RE = re.compile(
|
|
@@ -370,6 +398,14 @@ def classify(command: str) -> bool:
|
|
|
370
398
|
return True
|
|
371
399
|
return False
|
|
372
400
|
|
|
401
|
+
# Node built-in test runner (`node --test ...`), never arbitrary `node script.js`
|
|
402
|
+
if cmd == "node":
|
|
403
|
+
return next(
|
|
404
|
+
(t == "--test" for t in tokens[cmd_start + 1:]
|
|
405
|
+
if t in ("--test", "--") or not t.startswith("-")),
|
|
406
|
+
False,
|
|
407
|
+
)
|
|
408
|
+
|
|
373
409
|
# Direct command match
|
|
374
410
|
if cmd in _BUILD_TEST_COMMANDS:
|
|
375
411
|
allowed_subs = _BUILD_TEST_COMMANDS[cmd]
|
|
@@ -466,7 +502,13 @@ def classify_by_shape(output: str, command: str = "") -> bool:
|
|
|
466
502
|
|
|
467
503
|
def _is_error_line(line: str) -> bool:
|
|
468
504
|
"""True if this line is a distinct error line that must be preserved."""
|
|
469
|
-
|
|
505
|
+
if _COMBINED_ERROR_RE.search(line):
|
|
506
|
+
return True
|
|
507
|
+
try:
|
|
508
|
+
from visibility_rule import is_error_or_failure_line
|
|
509
|
+
return is_error_or_failure_line(line, include_stack_frames=False)
|
|
510
|
+
except Exception:
|
|
511
|
+
return False
|
|
470
512
|
|
|
471
513
|
|
|
472
514
|
def _is_summary_line(line: str) -> bool:
|
|
@@ -538,7 +580,10 @@ def _collapse_near_identical_warnings(lines: list[str]) -> list[str]:
|
|
|
538
580
|
and _normalize(lines[i + run]) == norm_current):
|
|
539
581
|
run += 1
|
|
540
582
|
if run > 1:
|
|
541
|
-
result.append(
|
|
583
|
+
result.append(
|
|
584
|
+
f"{current} [+{run - 1} near-identical warnings "
|
|
585
|
+
f"({run - 1} lines collapsed in lines {i + 2}-{i + run})]"
|
|
586
|
+
)
|
|
542
587
|
else:
|
|
543
588
|
result.append(current)
|
|
544
589
|
i += run
|
|
@@ -655,6 +700,27 @@ def compress(command: str, output: str) -> str | None:
|
|
|
655
700
|
if len(lines) < _MIN_COMPRESS_LINES:
|
|
656
701
|
return None
|
|
657
702
|
|
|
703
|
+
# Structured fast-path for verbose package installers / terraform plan.
|
|
704
|
+
# Runs credential preservation so a secret-bearing line is never dropped.
|
|
705
|
+
try:
|
|
706
|
+
from command_compress_extra import compress_build_command
|
|
707
|
+
structured = compress_build_command(command, output)
|
|
708
|
+
if structured is not None and len(structured) < len(output):
|
|
709
|
+
if _CRED_PATTERNS:
|
|
710
|
+
s_lines = set(structured.splitlines())
|
|
711
|
+
missing_creds = [
|
|
712
|
+
ln for ln in lines
|
|
713
|
+
if _cred_prefilter(ln)
|
|
714
|
+
and any(p.search(ln) for p in _CRED_PATTERNS)
|
|
715
|
+
and ln not in s_lines
|
|
716
|
+
]
|
|
717
|
+
if missing_creds:
|
|
718
|
+
structured = structured + "\n" + "\n".join(missing_creds)
|
|
719
|
+
if len(structured) < len(output):
|
|
720
|
+
return structured
|
|
721
|
+
except Exception:
|
|
722
|
+
pass
|
|
723
|
+
|
|
658
724
|
# --- single O(n) pass: credential scan + noise drop + error/summary ---
|
|
659
725
|
# F1: credential scan runs FIRST, before the progress-noise drop. A
|
|
660
726
|
# line matching a credential pattern is always preserved and never
|
|
@@ -663,13 +729,15 @@ def compress(command: str, output: str) -> str | None:
|
|
|
663
729
|
# prefixes) instead of a hand-maintained 13-token list.
|
|
664
730
|
kept_lines: list[str] = []
|
|
665
731
|
noise_dropped = 0
|
|
732
|
+
noise_first = 0
|
|
733
|
+
noise_last = 0
|
|
666
734
|
distinct_errors: list[str] = []
|
|
667
735
|
_error_seen: set[str] = set()
|
|
668
736
|
summary_lines: list[str] = []
|
|
669
737
|
_summary_seen: set[str] = set()
|
|
670
738
|
preserved_lines: list[str] = []
|
|
671
739
|
|
|
672
|
-
for line in lines:
|
|
740
|
+
for idx, line in enumerate(lines, 1):
|
|
673
741
|
# F1: credential check FIRST — a credential-bearing line is
|
|
674
742
|
# never dropped, even if it also matches progress noise.
|
|
675
743
|
is_credential = False
|
|
@@ -685,7 +753,7 @@ def compress(command: str, output: str) -> str | None:
|
|
|
685
753
|
# "#10 0.317 ERROR: failed to solve") survives in
|
|
686
754
|
# distinct_errors even when the progress filter would drop it
|
|
687
755
|
# from kept_lines. It is re-injected later either way.
|
|
688
|
-
if
|
|
756
|
+
if _is_error_line(line):
|
|
689
757
|
if line not in _error_seen:
|
|
690
758
|
_error_seen.add(line)
|
|
691
759
|
distinct_errors.append(line)
|
|
@@ -693,6 +761,9 @@ def compress(command: str, output: str) -> str | None:
|
|
|
693
761
|
# Progress noise: drop immediately (cheapest check, most common).
|
|
694
762
|
# But never drop a credential-bearing line (F1).
|
|
695
763
|
if not is_credential and _COMBINED_PROGRESS_RE.search(line):
|
|
764
|
+
if noise_dropped == 0:
|
|
765
|
+
noise_first = idx
|
|
766
|
+
noise_last = idx
|
|
696
767
|
noise_dropped += 1
|
|
697
768
|
continue
|
|
698
769
|
kept_lines.append(line)
|
|
@@ -729,10 +800,14 @@ def compress(command: str, output: str) -> str | None:
|
|
|
729
800
|
# the input, which defeats the purpose of compression. Prefer
|
|
730
801
|
# the original (return None) in that case.
|
|
731
802
|
if result != output and len(result) < len(output):
|
|
732
|
-
|
|
803
|
+
if "identical lines collapsed]" in result and "(lines " not in result:
|
|
804
|
+
result = f"[build output: identical lines collapsed (lines 1-{len(lines)})]\n" + result
|
|
805
|
+
from emit_safety_gate import gate_or_none as _emit_gate
|
|
806
|
+
return _emit_gate(output, result, feature="build_output_compress", tool_name="Bash", command=command, require_expand=False)
|
|
733
807
|
return None
|
|
734
808
|
|
|
735
809
|
# --- assemble the compressed output ---
|
|
810
|
+
_omit_marker_idx: int | None = None
|
|
736
811
|
if len(collapsed) <= _HEAD_LINES + _TAIL_LINES:
|
|
737
812
|
parts = list(collapsed)
|
|
738
813
|
else:
|
|
@@ -741,7 +816,8 @@ def compress(command: str, output: str) -> str | None:
|
|
|
741
816
|
middle = collapsed[_HEAD_LINES:-_TAIL_LINES]
|
|
742
817
|
parts = list(head)
|
|
743
818
|
if len(middle) > 50:
|
|
744
|
-
|
|
819
|
+
_omit_marker_idx = len(parts)
|
|
820
|
+
parts.append("") # placeholder filled with exact omitted raw line count below
|
|
745
821
|
else:
|
|
746
822
|
parts.extend(middle)
|
|
747
823
|
parts.extend(tail)
|
|
@@ -765,12 +841,31 @@ def compress(command: str, output: str) -> str | None:
|
|
|
765
841
|
parts.append(p)
|
|
766
842
|
current_set.add(p)
|
|
767
843
|
|
|
844
|
+
if _omit_marker_idx is not None:
|
|
845
|
+
visible_set = {ln.strip() for ln in parts if ln}
|
|
846
|
+
hidden_nos = [
|
|
847
|
+
idx for idx, raw_ln in enumerate(lines, 1)
|
|
848
|
+
if raw_ln.strip() and raw_ln.strip() not in visible_set
|
|
849
|
+
]
|
|
850
|
+
omitted_cnt = len(hidden_nos) if hidden_nos else len(collapsed) - _HEAD_LINES - _TAIL_LINES
|
|
851
|
+
lo = hidden_nos[0] if hidden_nos else _HEAD_LINES + 1
|
|
852
|
+
hi = hidden_nos[-1] if hidden_nos else len(lines) - _TAIL_LINES
|
|
853
|
+
parts[_omit_marker_idx] = (
|
|
854
|
+
f"... [{omitted_cnt} more lines (lines {lo}-{hi}), repetition collapsed] ..."
|
|
855
|
+
)
|
|
856
|
+
|
|
857
|
+
if noise_dropped > 0:
|
|
858
|
+
parts.insert(0, f"[build output: {noise_dropped} progress lines collapsed (lines {noise_first}-{noise_last})]")
|
|
859
|
+
|
|
768
860
|
compressed = "\n".join(parts)
|
|
861
|
+
if "identical lines collapsed]" in compressed and "(lines " not in compressed:
|
|
862
|
+
compressed = f"[build output: identical lines collapsed (lines 1-{len(lines)})]\n" + compressed
|
|
769
863
|
|
|
770
864
|
# Only return if we actually shrank the output
|
|
771
865
|
if len(compressed) >= len(output):
|
|
772
866
|
return None
|
|
773
867
|
|
|
774
|
-
|
|
868
|
+
from emit_safety_gate import gate_or_none as _emit_gate
|
|
869
|
+
return _emit_gate(output, compressed, feature="build_output_compress", tool_name="Bash", command=command, require_expand=False)
|
|
775
870
|
except Exception:
|
|
776
871
|
return None
|