@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.
- 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 +75 -81
- 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
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""Transcript boundary markers that invalidate cached Read context.
|
|
2
|
+
|
|
3
|
+
Recognizes both full compaction rows (``compact_boundary`` / ``isCompactSummary``)
|
|
4
|
+
and silent tool-result eviction that does not fire PreCompact:
|
|
5
|
+
- Claude Code microcompaction (``type="system"``, ``subtype="microcompact_boundary"``)
|
|
6
|
+
- Client-side tool-use cuts (``message.context_management.client_cut_tool_uses > 0``)
|
|
7
|
+
- Anthropic Context Editing API (``message.context_management.applied_edits`` with a
|
|
8
|
+
``clear_tool_uses*`` edit that cleared at least one tool use or input token).
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import hashlib
|
|
14
|
+
import json
|
|
15
|
+
|
|
16
|
+
COMPACT_MARKERS = (
|
|
17
|
+
b"compact_boundary",
|
|
18
|
+
b"isCompactSummary",
|
|
19
|
+
b"microcompact_boundary",
|
|
20
|
+
b"clear_tool_uses",
|
|
21
|
+
b"client_cut_tool_uses",
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _nonneg_int(val: object) -> int:
|
|
26
|
+
if val is None or isinstance(val, bool):
|
|
27
|
+
return 0
|
|
28
|
+
try:
|
|
29
|
+
n = int(val)
|
|
30
|
+
except (TypeError, ValueError):
|
|
31
|
+
return 0
|
|
32
|
+
return n if n > 0 else 0
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def context_management_totals(row: dict) -> tuple[int, int, int]:
|
|
36
|
+
"""Return ``(client_cut_tool_uses, cleared_tool_uses, cleared_input_tokens)``
|
|
37
|
+
from ``row["message"]["context_management"]`` (all >= 0).
|
|
38
|
+
"""
|
|
39
|
+
msg = row.get("message")
|
|
40
|
+
if not isinstance(msg, dict):
|
|
41
|
+
return (0, 0, 0)
|
|
42
|
+
cm = msg.get("context_management")
|
|
43
|
+
if not isinstance(cm, dict):
|
|
44
|
+
return (0, 0, 0)
|
|
45
|
+
client_cut = _nonneg_int(cm.get("client_cut_tool_uses"))
|
|
46
|
+
cleared_uses = 0
|
|
47
|
+
cleared_tokens = 0
|
|
48
|
+
edits = cm.get("applied_edits")
|
|
49
|
+
if isinstance(edits, list):
|
|
50
|
+
for edit in edits:
|
|
51
|
+
if not isinstance(edit, dict):
|
|
52
|
+
continue
|
|
53
|
+
etype = str(edit.get("type") or "")
|
|
54
|
+
if not etype.startswith("clear_tool_uses"):
|
|
55
|
+
continue
|
|
56
|
+
cleared_uses += _nonneg_int(edit.get("cleared_tool_uses"))
|
|
57
|
+
cleared_tokens += _nonneg_int(edit.get("cleared_input_tokens"))
|
|
58
|
+
return (client_cut, cleared_uses, cleared_tokens)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def compact_boundary_id(line: bytes, where: str = ""):
|
|
62
|
+
"""Stable id of a real compaction or tool-eviction row, or None.
|
|
63
|
+
|
|
64
|
+
A tool result that merely quotes marker text (for example reading this
|
|
65
|
+
module's source) returns None because we parse JSON and inspect structured
|
|
66
|
+
fields.
|
|
67
|
+
|
|
68
|
+
Context-management evictions return ``cm:<client_cut>:<uses>:<tokens>`` so
|
|
69
|
+
callers can compare against a per-path high-water mark and avoid wiping the
|
|
70
|
+
cache on every turn if the API re-reports the same ``applied_edits`` on
|
|
71
|
+
subsequent assistant responses.
|
|
72
|
+
"""
|
|
73
|
+
if not any(m in line for m in COMPACT_MARKERS):
|
|
74
|
+
return None
|
|
75
|
+
try:
|
|
76
|
+
row = json.loads(line.decode("utf-8", errors="replace"))
|
|
77
|
+
except (ValueError, UnicodeDecodeError):
|
|
78
|
+
return None
|
|
79
|
+
if not isinstance(row, dict):
|
|
80
|
+
return None
|
|
81
|
+
is_system_boundary = (
|
|
82
|
+
row.get("type") == "system"
|
|
83
|
+
and row.get("subtype") in ("compact_boundary", "microcompact_boundary")
|
|
84
|
+
)
|
|
85
|
+
if is_system_boundary or row.get("isCompactSummary") is True:
|
|
86
|
+
uuid = row.get("uuid")
|
|
87
|
+
if isinstance(uuid, str) and uuid:
|
|
88
|
+
return "u:" + uuid[:80]
|
|
89
|
+
return "h:" + hashlib.sha1(where.encode("utf-8", "replace") + b"\0" + line.strip()).hexdigest()[:20]
|
|
90
|
+
client_cut, cleared_uses, cleared_tokens = context_management_totals(row)
|
|
91
|
+
if client_cut > 0 or cleared_uses > 0 or cleared_tokens > 0:
|
|
92
|
+
return f"cm:{client_cut}:{cleared_uses}:{cleared_tokens}"
|
|
93
|
+
return None
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def should_invalidate_for_id(
|
|
97
|
+
bid: str,
|
|
98
|
+
seen: list[str],
|
|
99
|
+
new_ids: list[str],
|
|
100
|
+
cm_watermark: list[int],
|
|
101
|
+
) -> bool:
|
|
102
|
+
"""Decide whether ``bid`` represents a new invalidation event and update state.
|
|
103
|
+
|
|
104
|
+
- ``cm:<client_cut>:<uses>:<tokens>`` invalidates only when at least one
|
|
105
|
+
cumulative total strictly exceeds ``cm_watermark``.
|
|
106
|
+
- ``u:*`` / ``h:*`` invalidates once per distinct boundary id and resets
|
|
107
|
+
``cm_watermark`` so post-compaction tool evictions start fresh.
|
|
108
|
+
"""
|
|
109
|
+
if bid.startswith("cm:"):
|
|
110
|
+
parts = bid.split(":")
|
|
111
|
+
if len(parts) != 4:
|
|
112
|
+
return False
|
|
113
|
+
try:
|
|
114
|
+
c, u, t = int(parts[1]), int(parts[2]), int(parts[3])
|
|
115
|
+
except ValueError:
|
|
116
|
+
return False
|
|
117
|
+
if c > cm_watermark[0] or u > cm_watermark[1] or t > cm_watermark[2]:
|
|
118
|
+
cm_watermark[0] = max(cm_watermark[0], c)
|
|
119
|
+
cm_watermark[1] = max(cm_watermark[1], u)
|
|
120
|
+
cm_watermark[2] = max(cm_watermark[2], t)
|
|
121
|
+
return True
|
|
122
|
+
return False
|
|
123
|
+
if bid not in seen and bid not in new_ids:
|
|
124
|
+
new_ids.append(bid)
|
|
125
|
+
cm_watermark[0] = 0
|
|
126
|
+
cm_watermark[1] = 0
|
|
127
|
+
cm_watermark[2] = 0
|
|
128
|
+
return True
|
|
129
|
+
return False
|
|
@@ -51,6 +51,9 @@ _PAYLOAD_MODULES = (
|
|
|
51
51
|
"post_run_classify.py",
|
|
52
52
|
"preserved_reinject.py",
|
|
53
53
|
"bash_search_results.py",
|
|
54
|
+
"command_compress_extra.py",
|
|
55
|
+
"visibility_rule.py",
|
|
56
|
+
"emit_safety_gate.py",
|
|
54
57
|
# Dependency-free whitelist gate shared by bash_hook + bash_compress.
|
|
55
58
|
"bash_whitelist.py",
|
|
56
59
|
# command_filters + _tomli: user [filters.*] TOML config consulted by
|
|
@@ -49,6 +49,9 @@ _PAYLOAD_MODULES = (
|
|
|
49
49
|
"structure_map.py",
|
|
50
50
|
"structure_map_ts.py",
|
|
51
51
|
"read_cache.py",
|
|
52
|
+
"big_noncode_read.py",
|
|
53
|
+
"compact_markers.py",
|
|
54
|
+
"process_identity.py",
|
|
52
55
|
"cursor_state.py",
|
|
53
56
|
"cursor_session.py",
|
|
54
57
|
"cursor_quality.py",
|
|
@@ -57,6 +60,9 @@ _PAYLOAD_MODULES = (
|
|
|
57
60
|
"post_run_classify.py",
|
|
58
61
|
"preserved_reinject.py",
|
|
59
62
|
"bash_search_results.py",
|
|
63
|
+
"visibility_rule.py",
|
|
64
|
+
"emit_safety_gate.py",
|
|
65
|
+
"command_compress_extra.py",
|
|
60
66
|
# Dependency-free whitelist gate shared by bash_hook + bash_compress.
|
|
61
67
|
"bash_whitelist.py",
|
|
62
68
|
# command_filters + _tomli: user [filters.*] TOML config consulted by
|
|
@@ -108,6 +114,7 @@ _PAYLOAD_MODULES = (
|
|
|
108
114
|
"hint_paths.py", # session_store imports it at module load
|
|
109
115
|
"delta_diff.py",
|
|
110
116
|
"archive_result.py",
|
|
117
|
+
"builtin_tool_compress.py",
|
|
111
118
|
"recovery_output.py",
|
|
112
119
|
"refetch_fingerprint.py",
|
|
113
120
|
"reset_epoch.py",
|
|
@@ -20,8 +20,8 @@ REPO_MODULES = frozenset((
|
|
|
20
20
|
'_measure', '_tomli', 'hook_skip_log', 'lean_resume_carry', 'structural',
|
|
21
21
|
'activity_tracker', 'adapter_hook_command', 'antigravity_doctor', 'antigravity_hook_bridge', 'antigravity_install',
|
|
22
22
|
'antigravity_proto', 'antigravity_session', 'antigravity_state', 'archive_result',
|
|
23
|
-
'bash_compress', 'bash_search_results', 'bash_compress_hook', 'bash_hook', 'bash_whitelist', 'benchmark', 'cloud_kit',
|
|
24
|
-
'build_output_compress', 'codex_command_compress', 'codex_compact_prompt', 'codex_doctor',
|
|
23
|
+
'bash_compress', 'bash_search_results', 'bash_compress_hook', 'bash_hook', 'bash_whitelist', 'benchmark', 'big_noncode_read', 'cloud_kit',
|
|
24
|
+
'build_output_compress', 'compact_markers', 'process_identity', 'codex_command_compress', 'codex_compact_prompt', 'codex_doctor',
|
|
25
25
|
'codex_hook_bridge', 'codex_hook_provenance', 'codex_install', 'codex_io', 'codex_log_index', 'codex_models',
|
|
26
26
|
'codex_session', 'codex_state', 'codex_statusline', 'command_filters',
|
|
27
27
|
'compression_backfill', 'compression_log', 'context_intel', 'context_pressure',
|
|
@@ -31,7 +31,7 @@ REPO_MODULES = frozenset((
|
|
|
31
31
|
'shipped_hook_templates', 'shipped_starter_hooks', 'cursor_doctor', 'cursor_hook_bridge', 'cursor_install',
|
|
32
32
|
'cursor_session', 'cursor_state', 'dashboard_assets', 'delta_diff', 'detectors', 'deterministic_candidates',
|
|
33
33
|
'devin_compress', 'devin_doctor', 'devin_hooks', 'devin_install', 'devin_source', 'devin_state',
|
|
34
|
-
'devin_verify', 'grok_doctor', 'grok_hook_bridge', 'grok_install', 'grok_session',
|
|
34
|
+
'devin_verify', 'go_cargo_test_compress', 'command_compress_extra', 'grok_doctor', 'grok_hook_bridge', 'grok_install', 'grok_session',
|
|
35
35
|
'grok_state', 'hermes_doctor', 'hermes_hook_bridge', 'hermes_install', 'hermes_session',
|
|
36
36
|
'hermes_state', 'hermes_tool_hooks', 'hook_io', 'hook_runtime', 'injection', 'install_reconcile', 'measure',
|
|
37
37
|
'outline', 'pipeline_analyzer', 'plugin_env', 'py_trust', 'quality_cache_gate',
|
|
@@ -50,8 +50,8 @@ REPO_MODULES = frozenset((
|
|
|
50
50
|
# Added by the 5.13.69 merges (pristine, codemap, quiet, coverage).
|
|
51
51
|
'archive_verify', 'codemap', 'codemap_hint', 'codemap_index', 'codemap_ledger', 'codemap_reread',
|
|
52
52
|
'coverage_funnel', 'hint_paths', 'holdout', 'post_run_classify', 'large_transcripts', 'preserved_reinject', 'session_store_guard',
|
|
53
|
-
# Added by 5.13.70 (settings
|
|
54
|
-
'settings_backup',
|
|
53
|
+
# Added by 5.13.70+ (settings backup + builtin tools + pipe/file compress + visibility rule + emit safety gate + benchmark fixtures dir).
|
|
54
|
+
'settings_backup', 'builtin_tool_compress', 'pipe_file_compress', 'visibility_rule', 'emit_safety_gate', 'fixtures', 'large_output_policy', 'hook_fastpath',
|
|
55
55
|
))
|
|
56
56
|
|
|
57
57
|
class SourceOnly(importlib.abc.MetaPathFinder, importlib.abc.Loader):
|