@alexgreensh/token-optimizer 5.13.67 → 5.13.69
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/package.json +1 -1
- package/skills/fleet-auditor/references/fleet-systems.md +38 -0
- package/skills/fleet-auditor/scripts/fleet.py +63 -92
- package/skills/fleet-auditor/scripts/fleet_base.py +106 -0
- package/skills/fleet-auditor/scripts/fleet_cursor_adapter.py +376 -0
- package/skills/token-coach/SKILL.md +21 -23
- package/skills/token-dashboard/SKILL.md +5 -4
- package/skills/token-optimizer/SKILL.md +1 -1
- package/skills/token-optimizer/assets/dashboard.html +101 -50
- package/skills/token-optimizer/references/cli-reference.md +1 -1
- package/skills/token-optimizer/references/cursor-workflow.md +1 -1
- package/skills/token-optimizer/references/phase0-setup.md +1 -1
- package/skills/token-optimizer/references/presentation-workflow.md +1 -1
- package/skills/token-optimizer/scripts/_measure/__init__.py +1 -1
- package/skills/token-optimizer/scripts/_measure/_vendor/README.md +8 -2
- package/skills/token-optimizer/scripts/_measure/_vendor/__init__.py +46 -6
- package/skills/token-optimizer/scripts/_measure/_vendor/tomli/__init__.py +34 -3
- package/skills/token-optimizer/scripts/_measure/audit.py +5 -21
- package/skills/token-optimizer/scripts/_measure/cli.py +86 -0
- package/skills/token-optimizer/scripts/_measure/daemon.py +34 -76
- package/skills/token-optimizer/scripts/_measure/dashboard.py +63 -37
- package/skills/token-optimizer/scripts/_measure/dashboard_history.py +79 -0
- package/skills/token-optimizer/scripts/_measure/lifecycle.py +88 -528
- package/skills/token-optimizer/scripts/_measure/savings.py +20 -70
- package/skills/token-optimizer/scripts/_measure/sessions.py +58 -20
- package/skills/token-optimizer/scripts/_measure/weekly_activity.py +69 -0
- package/skills/token-optimizer/scripts/{_measure/_vendor/tomli/_parser.py → _tomli.py} +156 -10
- package/skills/token-optimizer/scripts/antigravity_install.py +7 -0
- package/skills/token-optimizer/scripts/bash_compress.py +8 -40
- package/skills/token-optimizer/scripts/bash_compress_hook.py +6 -0
- package/skills/token-optimizer/scripts/bash_search_results.py +43 -0
- package/skills/token-optimizer/scripts/cloud_kit.py +22 -22
- package/skills/token-optimizer/scripts/codex_doctor.py +34 -8
- package/skills/token-optimizer/scripts/codex_hook_provenance.py +268 -0
- package/skills/token-optimizer/scripts/codex_install.py +33 -69
- package/skills/token-optimizer/scripts/command_filters.py +39 -309
- package/skills/token-optimizer/scripts/copilot_install.py +9 -0
- package/skills/token-optimizer/scripts/credential_patterns.py +4 -19
- package/skills/token-optimizer/scripts/credential_url_patterns.py +42 -0
- package/skills/token-optimizer/scripts/cursor_audit.py +723 -0
- package/skills/token-optimizer/scripts/cursor_bridge_checkpoint.py +213 -0
- package/skills/token-optimizer/scripts/cursor_bridge_payload.py +170 -0
- package/skills/token-optimizer/scripts/cursor_bridge_rewrite.py +106 -0
- package/skills/token-optimizer/scripts/cursor_bridge_rollup.py +115 -0
- package/skills/token-optimizer/scripts/cursor_coach.py +485 -0
- package/skills/token-optimizer/scripts/cursor_doctor.py +89 -9
- package/skills/token-optimizer/scripts/cursor_hook_bridge.py +393 -276
- package/skills/token-optimizer/scripts/cursor_install.py +111 -19
- package/skills/token-optimizer/scripts/cursor_quality.py +505 -0
- package/skills/token-optimizer/scripts/cursor_read_cache.py +597 -0
- package/skills/token-optimizer/scripts/cursor_session.py +26 -5
- package/skills/token-optimizer/scripts/cursor_state.py +8 -0
- package/skills/token-optimizer/scripts/cursor_statusline.py +372 -0
- package/skills/token-optimizer/scripts/cursor_thrash.py +78 -0
- package/skills/token-optimizer/scripts/cursor_transcript.py +223 -0
- package/skills/token-optimizer/scripts/devin_install.py +6 -12
- package/skills/token-optimizer/scripts/devin_source.py +17 -6
- package/skills/token-optimizer/scripts/devin_verify.py +17 -0
- package/skills/token-optimizer/scripts/grok_install.py +9 -0
- package/skills/token-optimizer/scripts/heal_report.py +92 -0
- package/skills/token-optimizer/scripts/hermes_doctor.py +4 -1
- package/skills/token-optimizer/scripts/hermes_install.py +4 -1
- package/skills/token-optimizer/scripts/hook_heal.py +138 -0
- package/skills/token-optimizer/scripts/hook_provenance.py +878 -0
- package/skills/token-optimizer/scripts/measure.py +2 -2
- package/skills/token-optimizer/scripts/owned_hooks.py +420 -0
- package/skills/token-optimizer/scripts/shipped_codex_hook_templates.json +5815 -0
- package/skills/token-optimizer/scripts/shipped_hook_templates.py +252 -0
- package/skills/token-optimizer/scripts/shipped_starter_hooks.py +55 -0
- package/skills/token-optimizer/scripts/thrash_guard.py +10 -5
- package/skills/token-optimizer/scripts/_measure/_vendor/tomli/_re.py +0 -112
- package/skills/token-optimizer/scripts/_measure/_vendor/tomli/_types.py +0 -10
|
@@ -45,12 +45,23 @@ HOOK_TIMEOUT_SEC = 10
|
|
|
45
45
|
# hook never depends on the repo checkout location.
|
|
46
46
|
_PAYLOAD_MODULES = (
|
|
47
47
|
"cursor_hook_bridge.py",
|
|
48
|
+
"cursor_read_cache.py",
|
|
49
|
+
"structure_map.py",
|
|
50
|
+
"structure_map_ts.py",
|
|
51
|
+
"read_cache.py",
|
|
48
52
|
"cursor_state.py",
|
|
49
53
|
"cursor_session.py",
|
|
54
|
+
"cursor_quality.py",
|
|
50
55
|
"bash_hook.py",
|
|
51
56
|
"bash_compress.py",
|
|
57
|
+
"bash_search_results.py",
|
|
52
58
|
# Dependency-free whitelist gate shared by bash_hook + bash_compress.
|
|
53
59
|
"bash_whitelist.py",
|
|
60
|
+
# command_filters + _tomli: user [filters.*] TOML config consulted by
|
|
61
|
+
# bash_compress/bash_whitelist; _tomli is the 3.9/3.10 parser it
|
|
62
|
+
# lazy-imports when tomllib is absent.
|
|
63
|
+
"command_filters.py",
|
|
64
|
+
"_tomli.py",
|
|
54
65
|
"hook_io.py",
|
|
55
66
|
"plugin_env.py",
|
|
56
67
|
"runtime_env.py",
|
|
@@ -70,6 +81,34 @@ _PAYLOAD_MODULES = (
|
|
|
70
81
|
# credential_patterns: bash_compress's credential-preservation patterns
|
|
71
82
|
# (the inline fallback misses e.g. ghp_/github_pat_ tokens, #171).
|
|
72
83
|
"credential_patterns.py",
|
|
84
|
+
# credential_url_patterns: credential_patterns imports it at module import
|
|
85
|
+
# time (URL pattern family split under the 1,000-line ratchet) — without it
|
|
86
|
+
# EVERY payload consumer of credential_patterns breaks at import.
|
|
87
|
+
"credential_url_patterns.py",
|
|
88
|
+
# cursor_bridge_*: cursor_hook_bridge's helper modules (payload decode,
|
|
89
|
+
# rewrite staging, rollup spawn, checkpoint I/O) split under the ratchet.
|
|
90
|
+
# The bridge degrades to a no-op without them.
|
|
91
|
+
"cursor_bridge_payload.py",
|
|
92
|
+
"cursor_bridge_rewrite.py",
|
|
93
|
+
"cursor_bridge_rollup.py",
|
|
94
|
+
"cursor_bridge_checkpoint.py",
|
|
95
|
+
# cursor_thrash powers the Shell thrash nudge in postToolUse; its runtime
|
|
96
|
+
# dependency closure (empirically traced over the identical-output, burn
|
|
97
|
+
# and inline-script nudge paths) is thrash_guard -> session_store,
|
|
98
|
+
# delta_diff, archive_result -> recovery_output, refetch_fingerprint,
|
|
99
|
+
# reset_epoch, token_estimate. Without ANY of these the nudge silently
|
|
100
|
+
# no-ops in a real install (fail-open). cursor_transcript powers the
|
|
101
|
+
# transcript translation in the compact-checkpoint capture.
|
|
102
|
+
"cursor_thrash.py",
|
|
103
|
+
"thrash_guard.py",
|
|
104
|
+
"session_store.py",
|
|
105
|
+
"delta_diff.py",
|
|
106
|
+
"archive_result.py",
|
|
107
|
+
"recovery_output.py",
|
|
108
|
+
"refetch_fingerprint.py",
|
|
109
|
+
"reset_epoch.py",
|
|
110
|
+
"token_estimate.py",
|
|
111
|
+
"cursor_transcript.py",
|
|
73
112
|
)
|
|
74
113
|
|
|
75
114
|
# One-line locator written next to the bridge, naming the canonical measure.py
|
|
@@ -163,13 +202,21 @@ def _hook_entries(bridge_path: Path) -> dict:
|
|
|
163
202
|
|
|
164
203
|
return {
|
|
165
204
|
"sessionStart": [entry("sessionStart")],
|
|
166
|
-
#
|
|
167
|
-
#
|
|
168
|
-
|
|
205
|
+
# Shell is rewritten; Read is intercepted by the U2 read cache
|
|
206
|
+
# (shadow by default, emitting nothing until explicitly armed).
|
|
207
|
+
# The matcher keeps every other tool out of the bridge's hot path
|
|
208
|
+
# (Cursor matchers are JS regex over tool name).
|
|
209
|
+
"preToolUse": [entry("preToolUse", matcher="Shell|Read")],
|
|
169
210
|
"postToolUse": [entry("postToolUse")],
|
|
170
211
|
"preCompact": [entry("preCompact")],
|
|
171
212
|
"stop": [entry("stop")],
|
|
172
213
|
"sessionEnd": [entry("sessionEnd")],
|
|
214
|
+
# U4 record-only events: accounting, failure/burn signals, corroboration.
|
|
215
|
+
"afterAgentResponse": [entry("afterAgentResponse")],
|
|
216
|
+
"postToolUseFailure": [entry("postToolUseFailure")],
|
|
217
|
+
"afterShellExecution": [entry("afterShellExecution")],
|
|
218
|
+
"subagentStart": [entry("subagentStart")],
|
|
219
|
+
"subagentStop": [entry("subagentStop")],
|
|
173
220
|
}
|
|
174
221
|
|
|
175
222
|
|
|
@@ -237,7 +284,10 @@ def _hooks_lock(hooks_path: Path):
|
|
|
237
284
|
# 120s lease: the critical section copies the payload and rewrites
|
|
238
285
|
# hooks.json; a 30s lease could lapse mid-RMW on a slow disk and let a
|
|
239
286
|
# concurrent installer reclaim it, reintroducing the clobber.
|
|
240
|
-
|
|
287
|
+
# reclaim_released: a cleanly FINISHED install (release marker written)
|
|
288
|
+
# must not block a fast re-run (git pull + reinstall) for the rest of the
|
|
289
|
+
# lease window; a crashed install's tombstone still holds until expiry.
|
|
290
|
+
with lease_lock(lock_path, acquire_timeout=5.0, lease_seconds=120.0, reclaim_released=True) as acquired:
|
|
241
291
|
if not acquired:
|
|
242
292
|
raise RuntimeError(
|
|
243
293
|
"another Cursor install/uninstall is in progress "
|
|
@@ -269,9 +319,28 @@ def _copy_no_follow(src: Path, dest: Path) -> None:
|
|
|
269
319
|
raise
|
|
270
320
|
|
|
271
321
|
|
|
322
|
+
def _resolved_root(home):
|
|
323
|
+
if home is None:
|
|
324
|
+
return cursor_home()
|
|
325
|
+
raw = str(home)
|
|
326
|
+
if not raw or raw.startswith("-"):
|
|
327
|
+
raise ValueError("--home requires a directory path")
|
|
328
|
+
path = home.expanduser() if isinstance(home, Path) else Path(raw).expanduser()
|
|
329
|
+
if path.is_symlink():
|
|
330
|
+
raise ValueError("--home must not be a symlink")
|
|
331
|
+
root = path.resolve()
|
|
332
|
+
try:
|
|
333
|
+
different = root != cursor_home().resolve()
|
|
334
|
+
except (OSError, ValueError, NotImplementedError):
|
|
335
|
+
different = True
|
|
336
|
+
if different:
|
|
337
|
+
print("Warning: set TOKEN_OPTIMIZER_CURSOR_HOME to this home for Cursor hooks and doctor.", file=sys.stderr)
|
|
338
|
+
return root
|
|
339
|
+
|
|
340
|
+
|
|
272
341
|
def install(*, dry_run: bool = False, home: Path = None) -> dict:
|
|
273
342
|
"""Install the adapter. Returns a summary dict of actions taken."""
|
|
274
|
-
root = home
|
|
343
|
+
root = _resolved_root(home)
|
|
275
344
|
actions = {"copied": [], "hook_file": None, "skipped": [], "dry_run": dry_run}
|
|
276
345
|
plugin_dir = _plugin_dir(root)
|
|
277
346
|
|
|
@@ -317,12 +386,24 @@ def install(*, dry_run: bool = False, home: Path = None) -> dict:
|
|
|
317
386
|
with _hooks_lock(hooks_path):
|
|
318
387
|
existing = _read_hooks(hooks_path)
|
|
319
388
|
hooks = existing.get("hooks")
|
|
320
|
-
if
|
|
389
|
+
if hooks is None:
|
|
321
390
|
hooks = {}
|
|
391
|
+
elif not isinstance(hooks, dict):
|
|
392
|
+
# Fail closed like the non-object root: replacing a malformed
|
|
393
|
+
# member would silently destroy foreign configuration (G4).
|
|
394
|
+
raise RuntimeError(
|
|
395
|
+
f"{hooks_path} has a non-object 'hooks' member "
|
|
396
|
+
f"({type(hooks).__name__}); refusing to replace it. "
|
|
397
|
+
"Fix or remove the member and re-run."
|
|
398
|
+
)
|
|
322
399
|
for event, new_entries in _hook_entries(bridge_path).items():
|
|
323
400
|
old = hooks.get(event, [])
|
|
324
401
|
if not isinstance(old, list):
|
|
325
|
-
|
|
402
|
+
raise RuntimeError(
|
|
403
|
+
f"{hooks_path} event {event!r} is not a list "
|
|
404
|
+
f"({type(old).__name__}); refusing to replace it. "
|
|
405
|
+
"Fix or remove the entry and re-run."
|
|
406
|
+
)
|
|
326
407
|
hooks[event] = [e for e in old if not _is_ours(e, bridge_path)] + new_entries
|
|
327
408
|
existing["hooks"] = hooks
|
|
328
409
|
existing.setdefault("version", 1)
|
|
@@ -337,13 +418,8 @@ def install(*, dry_run: bool = False, home: Path = None) -> dict:
|
|
|
337
418
|
|
|
338
419
|
|
|
339
420
|
def uninstall(*, dry_run: bool = False, home: Path = None) -> dict:
|
|
340
|
-
"""Remove
|
|
341
|
-
|
|
342
|
-
Session data (``<cursor_home>/token-optimizer/sessions``,
|
|
343
|
-
``restore-context``, ``observed-events.jsonl``) and trends are left in place
|
|
344
|
-
for the user to purge manually, matching the Copilot uninstall contract.
|
|
345
|
-
"""
|
|
346
|
-
root = home if home is not None else cursor_home()
|
|
421
|
+
"""Remove our hooks, payload and derived caches; retain session history."""
|
|
422
|
+
root = _resolved_root(home)
|
|
347
423
|
actions = {"removed": [], "dry_run": dry_run}
|
|
348
424
|
|
|
349
425
|
bridge_path = _plugin_dir(root) / "cursor_hook_bridge.py"
|
|
@@ -371,17 +447,27 @@ def uninstall(*, dry_run: bool = False, home: Path = None) -> dict:
|
|
|
371
447
|
raise RuntimeError(f"failed writing {hooks_path}: {exc}") from exc
|
|
372
448
|
actions["removed"].append(f"{hooks_path} (Cursor entries)")
|
|
373
449
|
|
|
374
|
-
|
|
375
|
-
if
|
|
450
|
+
data_dir = root / "token-optimizer"
|
|
451
|
+
if data_dir.is_symlink() or (data_dir / "snapshot").is_symlink():
|
|
452
|
+
raise RuntimeError("refusing to remove caches through a symlinked data directory")
|
|
453
|
+
for plugin_dir in (_plugin_dir(root), data_dir / "read-fingerprints",
|
|
454
|
+
data_dir / "checkpoints", data_dir / "restore-context",
|
|
455
|
+
data_dir / "snapshot" / "checkpoints"):
|
|
456
|
+
if not plugin_dir.exists() and not plugin_dir.is_symlink():
|
|
457
|
+
continue
|
|
376
458
|
if not dry_run:
|
|
377
459
|
try:
|
|
378
|
-
|
|
460
|
+
if plugin_dir.is_symlink():
|
|
461
|
+
plugin_dir.unlink()
|
|
462
|
+
else:
|
|
463
|
+
shutil.rmtree(plugin_dir)
|
|
379
464
|
except OSError as exc:
|
|
380
465
|
# main() only surfaces RuntimeError; a raw OSError would escape
|
|
381
466
|
# as a traceback and leave a half-uninstalled state unexplained.
|
|
382
467
|
raise RuntimeError(f"failed removing {plugin_dir}: {exc}") from exc
|
|
383
468
|
actions["removed"].append(str(plugin_dir))
|
|
384
469
|
|
|
470
|
+
actions["kept"] = ["session tallies, observed events, trends and other session data"]
|
|
385
471
|
return actions
|
|
386
472
|
|
|
387
473
|
|
|
@@ -389,6 +475,10 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
389
475
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
390
476
|
parser.add_argument("action", choices=("install", "uninstall"))
|
|
391
477
|
parser.add_argument("--dry-run", action="store_true")
|
|
478
|
+
# --home overrides the resolved Cursor home (install.sh forwards the
|
|
479
|
+
# WSL-aware resolved path so the install and its banner agree, mirroring
|
|
480
|
+
# grok_install --home / copilot_install --home).
|
|
481
|
+
parser.add_argument("--home", type=Path, default=None)
|
|
392
482
|
return parser
|
|
393
483
|
|
|
394
484
|
|
|
@@ -396,7 +486,7 @@ def main(argv=None) -> int:
|
|
|
396
486
|
args = build_parser().parse_args(argv)
|
|
397
487
|
try:
|
|
398
488
|
if args.action == "install":
|
|
399
|
-
result = install(dry_run=args.dry_run)
|
|
489
|
+
result = install(dry_run=args.dry_run, home=args.home)
|
|
400
490
|
verb = "Would install" if args.dry_run else "Installed"
|
|
401
491
|
print(f"{verb} Token Optimizer for Cursor.")
|
|
402
492
|
print(f" Hooks merged into: {result['hook_file']}")
|
|
@@ -404,10 +494,12 @@ def main(argv=None) -> int:
|
|
|
404
494
|
+ (f", {len(result['skipped'])} missing: {result['skipped']}" if result["skipped"] else ""))
|
|
405
495
|
print(_hint(" Run `python3 measure.py cursor-doctor` to verify readiness."))
|
|
406
496
|
else:
|
|
407
|
-
result = uninstall(dry_run=args.dry_run)
|
|
497
|
+
result = uninstall(dry_run=args.dry_run, home=args.home)
|
|
408
498
|
verb = "Would remove" if args.dry_run else "Removed"
|
|
409
499
|
for item in result["removed"] or ["(nothing installed)"]:
|
|
410
500
|
print(f"{verb}: {item}")
|
|
501
|
+
for item in result["kept"]:
|
|
502
|
+
print(f"Kept: {item}")
|
|
411
503
|
return 0
|
|
412
504
|
except RuntimeError as exc:
|
|
413
505
|
print(f"[Token Optimizer] {exc}", file=sys.stderr)
|