@alexgreensh/token-optimizer 5.13.62 → 5.13.64
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/sessionstart_runner.py +25 -4
- package/package.json +1 -1
- package/skills/fleet-auditor/SKILL.md +1 -1
- package/skills/fleet-auditor/scripts/fleet.py +4 -1
- package/skills/fleet-auditor/scripts/shared.py +31 -14
- package/skills/token-coach/SKILL.md +49 -40
- package/skills/token-coach/references/deterministic-stages.md +1 -1
- package/skills/token-coach/references/keepwarm-consent.md +7 -7
- package/skills/token-dashboard/SKILL.md +30 -6
- package/skills/token-optimizer/SKILL.md +42 -44
- package/skills/token-optimizer/assets/dashboard.html +571 -106
- package/skills/token-optimizer/references/agent-prompts.md +4 -1
- package/skills/token-optimizer/references/codex-workflow.md +30 -12
- package/skills/token-optimizer/references/cursor-workflow.md +9 -7
- package/skills/token-optimizer/references/implementation-playbook.md +4 -4
- package/skills/token-optimizer/references/keepwarm-consent.md +7 -7
- package/skills/token-optimizer/references/opencode-workflow.md +4 -2
- package/skills/token-optimizer/references/optimization-checklist.md +9 -9
- package/skills/token-optimizer/references/phase0-setup.md +9 -9
- package/skills/token-optimizer/references/presentation-workflow.md +3 -3
- package/skills/token-optimizer/references/session-continuity.md +1 -1
- package/skills/token-optimizer/references/token-flow-architecture.md +2 -1
- package/skills/token-optimizer/scripts/adapter_hook_command.py +94 -0
- package/skills/token-optimizer/scripts/antigravity_doctor.py +12 -0
- package/skills/token-optimizer/scripts/antigravity_hook_bridge.py +4 -0
- package/skills/token-optimizer/scripts/antigravity_install.py +9 -18
- package/skills/token-optimizer/scripts/antigravity_session.py +31 -6
- package/skills/token-optimizer/scripts/archive_result.py +6 -1
- package/skills/token-optimizer/scripts/archive_window.py +274 -0
- package/skills/token-optimizer/scripts/checkpoint_state.py +385 -0
- package/skills/token-optimizer/scripts/codex_install.py +5 -3
- package/skills/token-optimizer/scripts/codex_session.py +149 -1
- package/skills/token-optimizer/scripts/cursor_doctor.py +12 -27
- package/skills/token-optimizer/scripts/cursor_install.py +11 -19
- package/skills/token-optimizer/scripts/devin_source.py +3 -3
- package/skills/token-optimizer/scripts/grok_doctor.py +12 -24
- package/skills/token-optimizer/scripts/grok_install.py +9 -16
- package/skills/token-optimizer/scripts/measure.py +7300 -1642
- package/skills/token-optimizer/scripts/read_cache.py +52 -27
- package/skills/token-optimizer/scripts/recovery_output.py +67 -18
- package/skills/token-optimizer/scripts/refetch_guard.py +9 -3
- package/skills/token-optimizer/scripts/session_activity.py +169 -0
- package/skills/token-optimizer/scripts/session_store.py +127 -9
- package/skills/token-optimizer/scripts/statusline.js +4 -6
|
@@ -25,7 +25,6 @@ from __future__ import annotations
|
|
|
25
25
|
import argparse
|
|
26
26
|
import json
|
|
27
27
|
import os
|
|
28
|
-
import shlex
|
|
29
28
|
import shutil
|
|
30
29
|
import subprocess
|
|
31
30
|
import sys
|
|
@@ -35,6 +34,7 @@ from pathlib import Path
|
|
|
35
34
|
_SCRIPT_DIR = Path(__file__).resolve().parent
|
|
36
35
|
sys.path.insert(0, str(_SCRIPT_DIR))
|
|
37
36
|
|
|
37
|
+
import adapter_hook_command # noqa: E402
|
|
38
38
|
from runtime_env import cursor_home, measure_cli as _measure_cli, with_measure_cli as _hint # noqa: E402
|
|
39
39
|
from cursor_install import _py_path_is_trusted # noqa: E402
|
|
40
40
|
|
|
@@ -420,10 +420,11 @@ def _installed_commands() -> dict:
|
|
|
420
420
|
# own (the installed plugin copy, or the sibling checkout bridge in dev)
|
|
421
421
|
# qualify, so a corrupted entry pointing at /tmp/evil/cursor_hook_bridge.py
|
|
422
422
|
# is never replayed by --probe.
|
|
423
|
-
ours =
|
|
424
|
-
str(
|
|
425
|
-
|
|
426
|
-
|
|
423
|
+
ours = set().union(*(
|
|
424
|
+
adapter_hook_command.path_spellings(str(p)) for p in (
|
|
425
|
+
cursor_home() / "token-optimizer" / "plugin" / "cursor_hook_bridge.py",
|
|
426
|
+
_SCRIPT_DIR / "cursor_hook_bridge.py",
|
|
427
|
+
)))
|
|
427
428
|
out = {}
|
|
428
429
|
for event in _WIRED_EVENTS:
|
|
429
430
|
for cmd in commands.get(event, []):
|
|
@@ -435,30 +436,14 @@ def _installed_commands() -> dict:
|
|
|
435
436
|
|
|
436
437
|
|
|
437
438
|
def _parse_hook_command(command: str) -> list | None:
|
|
438
|
-
"""Parse a persisted
|
|
439
|
+
"""Parse a persisted hook command into ``[python, bridge, event]``, or None.
|
|
439
440
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
become an injection vector for a corrupted or malicious entry.
|
|
441
|
+
Only the exact shape the installer writes is accepted (see
|
|
442
|
+
adapter_hook_command): runtime pin on POSIX, absolute python and bridge, a
|
|
443
|
+
wired event. Anything else is rejected rather than executed, so --probe
|
|
444
|
+
never becomes an injection vector for a corrupted or foreign entry.
|
|
445
445
|
"""
|
|
446
|
-
|
|
447
|
-
# posix=False on Windows: shlex's POSIX mode eats backslashes, so
|
|
448
|
-
# C:\Python314\python.exe would parse as "C:Python314python.exe".
|
|
449
|
-
tokens = shlex.split(command, posix=(os.name != "nt"))
|
|
450
|
-
except ValueError:
|
|
451
|
-
return None
|
|
452
|
-
if len(tokens) != 4:
|
|
453
|
-
return None
|
|
454
|
-
runtime, py, bridge, event = tokens
|
|
455
|
-
if runtime != "TOKEN_OPTIMIZER_RUNTIME=cursor":
|
|
456
|
-
return None
|
|
457
|
-
if not os.path.isabs(py) or not os.path.isabs(bridge):
|
|
458
|
-
return None
|
|
459
|
-
if event not in _WIRED_EVENTS:
|
|
460
|
-
return None
|
|
461
|
-
return tokens[1:]
|
|
446
|
+
return adapter_hook_command.parse(command, runtime="cursor", events=_WIRED_EVENTS)
|
|
462
447
|
|
|
463
448
|
|
|
464
449
|
def _run_probe_command(command: str, payload: dict, probe_home: Path) -> dict:
|
|
@@ -9,9 +9,9 @@ Wires Token Optimizer into Cursor's shared user hooks file:
|
|
|
9
9
|
tools are preserved verbatim; only entries whose ``command`` points at our
|
|
10
10
|
bridge path are replaced. Cursor has one shared hooks.json (no per-plugin
|
|
11
11
|
file like Copilot), so clobbering it would destroy other people's hooks.
|
|
12
|
-
3.
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
3. Writes a hook command each platform's shell parses: POSIX-quoted on
|
|
13
|
+
macOS/Linux, a form PowerShell and cmd.exe both run on native Windows
|
|
14
|
+
(see adapter_hook_command).
|
|
15
15
|
|
|
16
16
|
Idempotent: re-running refreshes the payload and replaces only OUR entries.
|
|
17
17
|
Uninstall removes only OUR entries and the payload dir; session data stays.
|
|
@@ -26,7 +26,6 @@ from __future__ import annotations
|
|
|
26
26
|
import argparse
|
|
27
27
|
import json
|
|
28
28
|
import os
|
|
29
|
-
import shlex
|
|
30
29
|
import shutil
|
|
31
30
|
import stat as _stat
|
|
32
31
|
import sys
|
|
@@ -36,6 +35,7 @@ from pathlib import Path
|
|
|
36
35
|
_SCRIPT_DIR = Path(__file__).resolve().parent
|
|
37
36
|
sys.path.insert(0, str(_SCRIPT_DIR))
|
|
38
37
|
|
|
38
|
+
import adapter_hook_command # noqa: E402
|
|
39
39
|
from py_trust import py_path_is_trusted, py_trust_reason # noqa: E402
|
|
40
40
|
from runtime_env import cursor_home, measure_cli as _measure_cli, with_measure_cli as _hint # noqa: E402
|
|
41
41
|
|
|
@@ -145,16 +145,15 @@ def _hook_entries(bridge_path: Path) -> dict:
|
|
|
145
145
|
"""The hook entries TO appends to ~/.cursor/hooks.json.
|
|
146
146
|
|
|
147
147
|
Cursor's per-hook schema is ``{command, type, matcher?, timeout,
|
|
148
|
-
failClosed?, loop_limit?}`` (verified 2026-09-01). ``command``
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
failClosed?, loop_limit?}`` (verified 2026-09-01). ``command`` runs through
|
|
149
|
+
the platform shell (see adapter_hook_command); the runtime is pinned so the
|
|
150
|
+
bridge never process-scans on the hot path.
|
|
151
151
|
"""
|
|
152
|
-
|
|
153
|
-
bridge_q = shlex.quote(str(bridge_path))
|
|
152
|
+
py = _resolve_safe_python()
|
|
154
153
|
|
|
155
154
|
def entry(event: str, *, matcher: str | None = None) -> dict:
|
|
156
155
|
e = {
|
|
157
|
-
"command":
|
|
156
|
+
"command": adapter_hook_command.build(py, str(bridge_path), event, runtime="cursor"),
|
|
158
157
|
"type": "command",
|
|
159
158
|
"timeout": HOOK_TIMEOUT_SEC,
|
|
160
159
|
}
|
|
@@ -178,7 +177,8 @@ def _is_ours(entry, bridge_path: Path) -> bool:
|
|
|
178
177
|
if not isinstance(entry, dict):
|
|
179
178
|
return False
|
|
180
179
|
cmd = entry.get("command")
|
|
181
|
-
return isinstance(cmd, str) and
|
|
180
|
+
return isinstance(cmd, str) and any(
|
|
181
|
+
spelling in cmd for spelling in adapter_hook_command.path_spellings(str(bridge_path)))
|
|
182
182
|
|
|
183
183
|
|
|
184
184
|
def _read_hooks(path: Path) -> dict:
|
|
@@ -271,14 +271,6 @@ def _copy_no_follow(src: Path, dest: Path) -> None:
|
|
|
271
271
|
|
|
272
272
|
def install(*, dry_run: bool = False, home: Path = None) -> dict:
|
|
273
273
|
"""Install the adapter. Returns a summary dict of actions taken."""
|
|
274
|
-
# Windows refusal (deferred quoting: cmd.exe would not parse shlex.quote).
|
|
275
|
-
if os.name == "nt":
|
|
276
|
-
raise RuntimeError(
|
|
277
|
-
"Cursor install on native Windows is not supported yet: the persisted "
|
|
278
|
-
"hook command is POSIX-shell quoted and cmd.exe would not parse it. "
|
|
279
|
-
"Install from a POSIX shell or WSL."
|
|
280
|
-
)
|
|
281
|
-
|
|
282
274
|
root = home if home is not None else cursor_home()
|
|
283
275
|
actions = {"copied": [], "hook_file": None, "skipped": [], "dry_run": dry_run}
|
|
284
276
|
plugin_dir = _plugin_dir(root)
|
|
@@ -16,7 +16,7 @@ ALLOWED_MODULES = frozenset(Path(name).stem for name in PAYLOAD)
|
|
|
16
16
|
|
|
17
17
|
# Repo names outside the installed closure must never fall back to sys.path.
|
|
18
18
|
REPO_MODULES = frozenset((
|
|
19
|
-
'activity_tracker', 'antigravity_doctor', 'antigravity_hook_bridge', 'antigravity_install',
|
|
19
|
+
'activity_tracker', 'adapter_hook_command', 'antigravity_doctor', 'antigravity_hook_bridge', 'antigravity_install',
|
|
20
20
|
'antigravity_proto', 'antigravity_session', 'antigravity_state', 'archive_result',
|
|
21
21
|
'bash_compress', 'bash_compress_hook', 'bash_hook', 'bash_whitelist', 'benchmark', 'cloud_kit',
|
|
22
22
|
'build_output_compress', 'codex_command_compress', 'codex_compact_prompt', 'codex_doctor',
|
|
@@ -33,8 +33,8 @@ REPO_MODULES = frozenset((
|
|
|
33
33
|
'hermes_state', 'hermes_tool_hooks', 'hook_io', 'hook_runtime', 'injection', 'install_reconcile', 'measure',
|
|
34
34
|
'outline', 'pipeline_analyzer', 'plugin_env', 'py_trust', 'quality_cache_gate',
|
|
35
35
|
'read_cache', 'recovery_output', 'refetch_fingerprint', 'refetch_guard', 'routing_advisor',
|
|
36
|
-
'runtime_env', 'session_store', 'spawn_utils', 'structure_map', 'structure_map_ts',
|
|
37
|
-
'structure_replay', 'thrash_guard', 'token_estimate', 'tool_search_diagnostic', 'utf8_io',
|
|
36
|
+
'runtime_env', 'session_activity', 'session_store', 'spawn_utils', 'structure_map', 'structure_map_ts',
|
|
37
|
+
'structure_replay', 'thrash_guard', 'token_estimate', 'tool_search_diagnostic', 'utf8_io', 'archive_window', 'checkpoint_state',
|
|
38
38
|
))
|
|
39
39
|
|
|
40
40
|
class SourceOnly(importlib.abc.MetaPathFinder, importlib.abc.Loader):
|
|
@@ -30,7 +30,6 @@ from __future__ import annotations
|
|
|
30
30
|
import argparse
|
|
31
31
|
import json
|
|
32
32
|
import os
|
|
33
|
-
import shlex
|
|
34
33
|
import shutil
|
|
35
34
|
import subprocess
|
|
36
35
|
import sys
|
|
@@ -40,6 +39,7 @@ from pathlib import Path
|
|
|
40
39
|
_SCRIPT_DIR = Path(__file__).resolve().parent
|
|
41
40
|
sys.path.insert(0, str(_SCRIPT_DIR))
|
|
42
41
|
|
|
42
|
+
import adapter_hook_command # noqa: E402
|
|
43
43
|
from runtime_env import grok_home, measure_cli as _measure_cli, with_measure_cli as _hint # noqa: E402
|
|
44
44
|
from py_trust import py_path_is_trusted # noqa: E402
|
|
45
45
|
|
|
@@ -383,10 +383,11 @@ def _installed_commands() -> dict:
|
|
|
383
383
|
# Identity, not substring: only entries whose bridge token is a bridge we
|
|
384
384
|
# own qualify, so a corrupted entry pointing at /tmp/evil/grok_hook_bridge.py
|
|
385
385
|
# is never replayed by --probe.
|
|
386
|
-
ours =
|
|
387
|
-
str(
|
|
388
|
-
|
|
389
|
-
|
|
386
|
+
ours = set().union(*(
|
|
387
|
+
adapter_hook_command.path_spellings(str(p)) for p in (
|
|
388
|
+
grok_home() / "token-optimizer" / "plugin" / "grok_hook_bridge.py",
|
|
389
|
+
_SCRIPT_DIR / "grok_hook_bridge.py",
|
|
390
|
+
)))
|
|
390
391
|
out = {}
|
|
391
392
|
by_event = {event: [c for e, c in _iter_commands(config) if e == event]
|
|
392
393
|
for event in _WIRED_EVENTS}
|
|
@@ -400,27 +401,14 @@ def _installed_commands() -> dict:
|
|
|
400
401
|
|
|
401
402
|
|
|
402
403
|
def _parse_hook_command(command: str) -> list | None:
|
|
403
|
-
"""Parse a persisted hook command into
|
|
404
|
+
"""Parse a persisted hook command into ``[python, bridge, event]``, or None.
|
|
404
405
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
vector for a corrupted or
|
|
406
|
+
Only the exact shape the installer writes is accepted (see
|
|
407
|
+
adapter_hook_command): runtime pin on POSIX, absolute python and bridge, a
|
|
408
|
+
wired event. Anything else is rejected rather than executed, so --probe
|
|
409
|
+
never becomes an injection vector for a corrupted or foreign entry.
|
|
409
410
|
"""
|
|
410
|
-
|
|
411
|
-
tokens = shlex.split(command, posix=(os.name != "nt"))
|
|
412
|
-
except ValueError:
|
|
413
|
-
return None
|
|
414
|
-
if len(tokens) != 4:
|
|
415
|
-
return None
|
|
416
|
-
runtime, py, bridge, event = tokens
|
|
417
|
-
if runtime != "TOKEN_OPTIMIZER_RUNTIME=grok":
|
|
418
|
-
return None
|
|
419
|
-
if not os.path.isabs(py) or not os.path.isabs(bridge):
|
|
420
|
-
return None
|
|
421
|
-
if event not in _WIRED_EVENTS:
|
|
422
|
-
return None
|
|
423
|
-
return tokens[1:]
|
|
411
|
+
return adapter_hook_command.parse(command, runtime="grok", events=_WIRED_EVENTS)
|
|
424
412
|
|
|
425
413
|
|
|
426
414
|
def _run_probe_command(command: str, payload: dict, probe_home: Path) -> dict:
|
|
@@ -9,8 +9,9 @@ Wires Token Optimizer into Grok Build's hooks system:
|
|
|
9
9
|
(Grok scans ``~/.grok/hooks/*.json`` as a DIRECTORY of files — unlike
|
|
10
10
|
Cursor's single shared hooks.json — so TO owns its file outright and never
|
|
11
11
|
merges with, or clobbers, another tool's hooks).
|
|
12
|
-
3.
|
|
13
|
-
|
|
12
|
+
3. Writes a hook command each platform's shell parses: POSIX-quoted on
|
|
13
|
+
macOS/Linux, a form PowerShell and cmd.exe both run on native Windows
|
|
14
|
+
(see adapter_hook_command).
|
|
14
15
|
|
|
15
16
|
The hooks JSON format is Grok's documented shape (10-hooks.md "The Hook JSON
|
|
16
17
|
Format"): ``{"hooks": {<Event>: [{matcher?, hooks: [{type, command, timeout}]}]}}``.
|
|
@@ -28,7 +29,6 @@ from __future__ import annotations
|
|
|
28
29
|
import argparse
|
|
29
30
|
import json
|
|
30
31
|
import os
|
|
31
|
-
import shlex
|
|
32
32
|
import shutil
|
|
33
33
|
import sys
|
|
34
34
|
from contextlib import contextmanager
|
|
@@ -37,6 +37,7 @@ from pathlib import Path
|
|
|
37
37
|
_SCRIPT_DIR = Path(__file__).resolve().parent
|
|
38
38
|
sys.path.insert(0, str(_SCRIPT_DIR))
|
|
39
39
|
|
|
40
|
+
import adapter_hook_command # noqa: E402
|
|
40
41
|
from py_trust import py_path_is_trusted, py_trust_reason # noqa: E402
|
|
41
42
|
from runtime_env import grok_home, measure_cli as _measure_cli, with_measure_cli as _hint # noqa: E402
|
|
42
43
|
|
|
@@ -134,17 +135,16 @@ def _resolve_safe_python() -> str:
|
|
|
134
135
|
def _hook_entries(bridge_path: Path) -> dict:
|
|
135
136
|
"""The hook entries TO writes to $GROK_HOME/hooks/token-optimizer.json.
|
|
136
137
|
|
|
137
|
-
Format is Grok's documented 10-hooks.md shape. ``command``
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
Format is Grok's documented 10-hooks.md shape. ``command`` runs through the
|
|
139
|
+
platform shell (see adapter_hook_command); the runtime is pinned so the
|
|
140
|
+
bridge never process-scans on the hot path.
|
|
140
141
|
"""
|
|
141
|
-
|
|
142
|
-
bridge_q = shlex.quote(str(bridge_path))
|
|
142
|
+
py = _resolve_safe_python()
|
|
143
143
|
|
|
144
144
|
def handler(event: str, timeout: int) -> dict:
|
|
145
145
|
return {
|
|
146
146
|
"type": "command",
|
|
147
|
-
"command":
|
|
147
|
+
"command": adapter_hook_command.build(py, str(bridge_path), event, runtime="grok"),
|
|
148
148
|
"timeout": timeout,
|
|
149
149
|
}
|
|
150
150
|
|
|
@@ -274,13 +274,6 @@ def _copy_no_follow(src: Path, dest: Path) -> None:
|
|
|
274
274
|
|
|
275
275
|
def install(*, dry_run: bool = False, home: Path | None = None) -> dict:
|
|
276
276
|
"""Install the adapter. Returns a summary dict of actions taken."""
|
|
277
|
-
if os.name == "nt":
|
|
278
|
-
raise RuntimeError(
|
|
279
|
-
"Grok install on native Windows is not supported yet: the persisted "
|
|
280
|
-
"hook command is POSIX-shell quoted and cmd.exe would not parse it. "
|
|
281
|
-
"Install from a POSIX shell or WSL."
|
|
282
|
-
)
|
|
283
|
-
|
|
284
277
|
root = home if home is not None else grok_home()
|
|
285
278
|
actions = {"copied": [], "hook_file": None, "skipped": [], "dry_run": dry_run}
|
|
286
279
|
plugin_dir = _plugin_dir(root)
|