@alexgreensh/token-optimizer 5.13.68 → 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/cli.py +86 -0
- package/skills/token-optimizer/scripts/_measure/daemon.py +13 -25
- 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 +6 -7
- 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/antigravity_install.py +4 -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 +1 -1
- package/skills/token-optimizer/scripts/codex_doctor.py +1 -1
- package/skills/token-optimizer/scripts/copilot_install.py +4 -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 +106 -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_source.py +12 -2
- package/skills/token-optimizer/scripts/devin_verify.py +7 -6
- package/skills/token-optimizer/scripts/grok_install.py +4 -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/measure.py +2 -2
- package/skills/token-optimizer/scripts/thrash_guard.py +10 -5
|
@@ -45,10 +45,16 @@ 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",
|
|
54
60
|
# command_filters + _tomli: user [filters.*] TOML config consulted by
|
|
@@ -75,6 +81,34 @@ _PAYLOAD_MODULES = (
|
|
|
75
81
|
# credential_patterns: bash_compress's credential-preservation patterns
|
|
76
82
|
# (the inline fallback misses e.g. ghp_/github_pat_ tokens, #171).
|
|
77
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",
|
|
78
112
|
)
|
|
79
113
|
|
|
80
114
|
# One-line locator written next to the bridge, naming the canonical measure.py
|
|
@@ -168,13 +202,21 @@ def _hook_entries(bridge_path: Path) -> dict:
|
|
|
168
202
|
|
|
169
203
|
return {
|
|
170
204
|
"sessionStart": [entry("sessionStart")],
|
|
171
|
-
#
|
|
172
|
-
#
|
|
173
|
-
|
|
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")],
|
|
174
210
|
"postToolUse": [entry("postToolUse")],
|
|
175
211
|
"preCompact": [entry("preCompact")],
|
|
176
212
|
"stop": [entry("stop")],
|
|
177
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")],
|
|
178
220
|
}
|
|
179
221
|
|
|
180
222
|
|
|
@@ -242,7 +284,10 @@ def _hooks_lock(hooks_path: Path):
|
|
|
242
284
|
# 120s lease: the critical section copies the payload and rewrites
|
|
243
285
|
# hooks.json; a 30s lease could lapse mid-RMW on a slow disk and let a
|
|
244
286
|
# concurrent installer reclaim it, reintroducing the clobber.
|
|
245
|
-
|
|
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:
|
|
246
291
|
if not acquired:
|
|
247
292
|
raise RuntimeError(
|
|
248
293
|
"another Cursor install/uninstall is in progress "
|
|
@@ -274,9 +319,28 @@ def _copy_no_follow(src: Path, dest: Path) -> None:
|
|
|
274
319
|
raise
|
|
275
320
|
|
|
276
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
|
+
|
|
277
341
|
def install(*, dry_run: bool = False, home: Path = None) -> dict:
|
|
278
342
|
"""Install the adapter. Returns a summary dict of actions taken."""
|
|
279
|
-
root = home
|
|
343
|
+
root = _resolved_root(home)
|
|
280
344
|
actions = {"copied": [], "hook_file": None, "skipped": [], "dry_run": dry_run}
|
|
281
345
|
plugin_dir = _plugin_dir(root)
|
|
282
346
|
|
|
@@ -322,12 +386,24 @@ def install(*, dry_run: bool = False, home: Path = None) -> dict:
|
|
|
322
386
|
with _hooks_lock(hooks_path):
|
|
323
387
|
existing = _read_hooks(hooks_path)
|
|
324
388
|
hooks = existing.get("hooks")
|
|
325
|
-
if
|
|
389
|
+
if hooks is None:
|
|
326
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
|
+
)
|
|
327
399
|
for event, new_entries in _hook_entries(bridge_path).items():
|
|
328
400
|
old = hooks.get(event, [])
|
|
329
401
|
if not isinstance(old, list):
|
|
330
|
-
|
|
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
|
+
)
|
|
331
407
|
hooks[event] = [e for e in old if not _is_ours(e, bridge_path)] + new_entries
|
|
332
408
|
existing["hooks"] = hooks
|
|
333
409
|
existing.setdefault("version", 1)
|
|
@@ -342,13 +418,8 @@ def install(*, dry_run: bool = False, home: Path = None) -> dict:
|
|
|
342
418
|
|
|
343
419
|
|
|
344
420
|
def uninstall(*, dry_run: bool = False, home: Path = None) -> dict:
|
|
345
|
-
"""Remove
|
|
346
|
-
|
|
347
|
-
Session data (``<cursor_home>/token-optimizer/sessions``,
|
|
348
|
-
``restore-context``, ``observed-events.jsonl``) and trends are left in place
|
|
349
|
-
for the user to purge manually, matching the Copilot uninstall contract.
|
|
350
|
-
"""
|
|
351
|
-
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)
|
|
352
423
|
actions = {"removed": [], "dry_run": dry_run}
|
|
353
424
|
|
|
354
425
|
bridge_path = _plugin_dir(root) / "cursor_hook_bridge.py"
|
|
@@ -376,17 +447,27 @@ def uninstall(*, dry_run: bool = False, home: Path = None) -> dict:
|
|
|
376
447
|
raise RuntimeError(f"failed writing {hooks_path}: {exc}") from exc
|
|
377
448
|
actions["removed"].append(f"{hooks_path} (Cursor entries)")
|
|
378
449
|
|
|
379
|
-
|
|
380
|
-
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
|
|
381
458
|
if not dry_run:
|
|
382
459
|
try:
|
|
383
|
-
|
|
460
|
+
if plugin_dir.is_symlink():
|
|
461
|
+
plugin_dir.unlink()
|
|
462
|
+
else:
|
|
463
|
+
shutil.rmtree(plugin_dir)
|
|
384
464
|
except OSError as exc:
|
|
385
465
|
# main() only surfaces RuntimeError; a raw OSError would escape
|
|
386
466
|
# as a traceback and leave a half-uninstalled state unexplained.
|
|
387
467
|
raise RuntimeError(f"failed removing {plugin_dir}: {exc}") from exc
|
|
388
468
|
actions["removed"].append(str(plugin_dir))
|
|
389
469
|
|
|
470
|
+
actions["kept"] = ["session tallies, observed events, trends and other session data"]
|
|
390
471
|
return actions
|
|
391
472
|
|
|
392
473
|
|
|
@@ -394,6 +475,10 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
394
475
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
395
476
|
parser.add_argument("action", choices=("install", "uninstall"))
|
|
396
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)
|
|
397
482
|
return parser
|
|
398
483
|
|
|
399
484
|
|
|
@@ -401,7 +486,7 @@ def main(argv=None) -> int:
|
|
|
401
486
|
args = build_parser().parse_args(argv)
|
|
402
487
|
try:
|
|
403
488
|
if args.action == "install":
|
|
404
|
-
result = install(dry_run=args.dry_run)
|
|
489
|
+
result = install(dry_run=args.dry_run, home=args.home)
|
|
405
490
|
verb = "Would install" if args.dry_run else "Installed"
|
|
406
491
|
print(f"{verb} Token Optimizer for Cursor.")
|
|
407
492
|
print(f" Hooks merged into: {result['hook_file']}")
|
|
@@ -409,10 +494,12 @@ def main(argv=None) -> int:
|
|
|
409
494
|
+ (f", {len(result['skipped'])} missing: {result['skipped']}" if result["skipped"] else ""))
|
|
410
495
|
print(_hint(" Run `python3 measure.py cursor-doctor` to verify readiness."))
|
|
411
496
|
else:
|
|
412
|
-
result = uninstall(dry_run=args.dry_run)
|
|
497
|
+
result = uninstall(dry_run=args.dry_run, home=args.home)
|
|
413
498
|
verb = "Would remove" if args.dry_run else "Removed"
|
|
414
499
|
for item in result["removed"] or ["(nothing installed)"]:
|
|
415
500
|
print(f"{verb}: {item}")
|
|
501
|
+
for item in result["kept"]:
|
|
502
|
+
print(f"Kept: {item}")
|
|
416
503
|
return 0
|
|
417
504
|
except RuntimeError as exc:
|
|
418
505
|
print(f"[Token Optimizer] {exc}", file=sys.stderr)
|