@alexgreensh/token-optimizer 5.13.65 → 5.13.67

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.
Files changed (44) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/hooks/hooks.json +0 -10
  4. package/hooks/module_runner.py +62 -13
  5. package/hooks/userpromptsubmit_runner.py +13 -1
  6. package/package.json +1 -1
  7. package/skills/token-optimizer/examples/hooks-starter.json +0 -10
  8. package/skills/token-optimizer/scripts/_measure/__init__.py +16 -0
  9. package/skills/token-optimizer/scripts/_measure/_compat.py +200 -0
  10. package/skills/token-optimizer/scripts/_measure/_vendor/README.md +9 -0
  11. package/skills/token-optimizer/scripts/_measure/_vendor/__init__.py +23 -0
  12. package/skills/token-optimizer/scripts/_measure/_vendor/tomli/LICENSE +21 -0
  13. package/skills/token-optimizer/scripts/_measure/_vendor/tomli/__init__.py +8 -0
  14. package/skills/token-optimizer/scripts/_measure/_vendor/tomli/_parser.py +770 -0
  15. package/skills/token-optimizer/scripts/_measure/_vendor/tomli/_re.py +112 -0
  16. package/skills/token-optimizer/scripts/_measure/_vendor/tomli/_types.py +10 -0
  17. package/skills/token-optimizer/scripts/_measure/_vendor/tomli/py.typed +1 -0
  18. package/skills/token-optimizer/scripts/_measure/audit.py +6949 -0
  19. package/skills/token-optimizer/scripts/_measure/cache_policy.py +7050 -0
  20. package/skills/token-optimizer/scripts/_measure/cli.py +2722 -0
  21. package/skills/token-optimizer/scripts/_measure/continuity.py +4630 -0
  22. package/skills/token-optimizer/scripts/_measure/daemon.py +6773 -0
  23. package/skills/token-optimizer/scripts/_measure/dashboard.py +4358 -0
  24. package/skills/token-optimizer/scripts/_measure/lifecycle.py +6145 -0
  25. package/skills/token-optimizer/scripts/_measure/pricing.py +2101 -0
  26. package/skills/token-optimizer/scripts/_measure/quality_archive.py +7138 -0
  27. package/skills/token-optimizer/scripts/_measure/runtime.py +1231 -0
  28. package/skills/token-optimizer/scripts/_measure/savings.py +7702 -0
  29. package/skills/token-optimizer/scripts/_measure/sessions.py +4784 -0
  30. package/skills/token-optimizer/scripts/_measure/trends.py +2432 -0
  31. package/skills/token-optimizer/scripts/antigravity_hook_bridge.py +11 -3
  32. package/skills/token-optimizer/scripts/bash_compress.py +3 -3
  33. package/skills/token-optimizer/scripts/bash_compress_hook.py +6 -7
  34. package/skills/token-optimizer/scripts/cloud_kit.py +7 -8
  35. package/skills/token-optimizer/scripts/codex_compact_prompt.py +2 -2
  36. package/skills/token-optimizer/scripts/codex_doctor.py +14 -0
  37. package/skills/token-optimizer/scripts/command_filters.py +630 -19
  38. package/skills/token-optimizer/scripts/devin_source.py +2 -1
  39. package/skills/token-optimizer/scripts/hermes_doctor.py +13 -0
  40. package/skills/token-optimizer/scripts/hermes_install.py +11 -0
  41. package/skills/token-optimizer/scripts/measure.py +2430 -60930
  42. package/skills/token-optimizer/scripts/read_cache.py +20 -21
  43. package/skills/token-optimizer/scripts/reset_epoch.py +177 -0
  44. package/skills/token-optimizer/scripts/session_store.py +11 -48
@@ -399,13 +399,15 @@ def _rollup_lease_held(home: Path) -> bool:
399
399
  return False
400
400
 
401
401
 
402
- def _touch_rollup_lease(home: Path) -> None:
402
+ def _touch_rollup_lease(home: Path) -> bool:
403
+ """Touch the rollup lease; False when the write failed (degraded dir)."""
403
404
  lease = _to_dir(home) / "rollup.lease"
404
405
  try:
405
406
  lease.parent.mkdir(parents=True, exist_ok=True)
406
407
  lease.touch()
408
+ return True
407
409
  except OSError:
408
- pass
410
+ return False
409
411
 
410
412
 
411
413
  def handle_stop(payload: dict) -> dict:
@@ -421,7 +423,13 @@ def handle_stop(payload: dict) -> dict:
421
423
  if measure_py is None:
422
424
  return {}
423
425
 
424
- _touch_rollup_lease(home)
426
+ if not _touch_rollup_lease(home):
427
+ # Fail closed (the Cursor bridge's throttle-state rule, R12): on a
428
+ # read-only/full data dir the lease can never be observed held, so
429
+ # without this guard EVERY stop would spawn a detached
430
+ # rollup+dashboard pair - a process storm under exactly the degraded
431
+ # conditions the lease exists to contain.
432
+ return {}
425
433
 
426
434
  try:
427
435
  from spawn_utils import spawn_detached
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env python3
2
2
  """Token Optimizer v5: Bash Output Compression Wrapper.
3
3
 
4
- Invoked by bash_hook.py via PreToolUse command rewriting:
4
+ Shared PostToolUse and host-bridge compression; optional direct wrapper:
5
5
  bash_compress.py git status
6
6
  bash_compress.py pytest tests/
7
7
 
8
- Runs the command, captures output, applies pattern-matched compression.
9
- On ANY error, returns raw output unchanged (fail-open).
8
+ The legacy bash_hook.py no longer rewrites PreToolUse commands. Direct calls
9
+ capture and compress output; errors retain raw output unchanged (fail-open).
10
10
 
11
11
  Security:
12
12
  - shell=True is NEVER used
@@ -2,9 +2,8 @@
2
2
  """Token Optimizer v5.12: PostToolUse Bash Compression Hook.
3
3
 
4
4
  Compresses Bash tool output AFTER execution via Claude Code's
5
- ``updatedToolOutput`` mechanism. This is the UNIT B expansion: it handles
6
- pipeline and metachar-containing commands that PreToolUse bash_hook.py
7
- categorically rejects.
5
+ ``updatedToolOutput`` mechanism. Handles eligible simple commands and
6
+ pipelines after execution, without rewriting or approving the original call.
8
7
 
9
8
  Architecture:
10
9
  CC runs Bash tool → PostToolUse fires → this hook receives tool_response
@@ -13,11 +12,11 @@ Architecture:
13
12
  enforce the baseline-size invariant → updatedToolOutput replaces what
14
13
  Claude sees.
15
14
 
16
- The existing PreToolUse bash_hook.py continues to handle simple (metachar-free)
17
- commands. This hook handles everything else — pipes, &&, ||, ;, redirections,
18
- heredocs, and command substitutions.
15
+ The legacy PreToolUse bash_hook.py entry point is silent and is not registered.
16
+ PostToolUse compression covers read-only simple commands and supported pipelines,
17
+ including commands with pipes, &&, ||, ;, redirections, heredocs, and substitutions.
19
18
 
20
- Safety (same stack as bash_hook.py):
19
+ Safety:
21
20
  - Fail-open: any exception → exit 0 with no output → Claude sees raw result
22
21
  - Read-only only: pipeline_analyzer rejects any side-effecting stage
23
22
  - No double-execution: command already ran; we only compress captured output
@@ -37,9 +37,7 @@ Rules this module keeps:
37
37
  install-cloud.sh appends to install.log, and exit status 1), and the
38
38
  shell wrapper always exits 0, so a cloud session's setup never fails.
39
39
  """
40
-
41
40
  from __future__ import annotations
42
-
43
41
  import base64
44
42
  import compileall
45
43
  import hashlib
@@ -53,7 +51,6 @@ import tempfile
53
51
  import urllib.parse
54
52
  import urllib.request
55
53
  from pathlib import Path
56
-
57
54
  PACKAGE = "@alexgreensh/token-optimizer"
58
55
  REGISTRY = "https://registry.npmjs.org"
59
56
  CACHE_DIRNAME = "token-optimizer-cloud"
@@ -61,15 +58,11 @@ RUNNER_NAME = "token-optimizer-cloud-run.sh"
61
58
  # Every hook command we write contains this (whatever the cache dir is); it is
62
59
  # how we, and measure.py's self-heal, recognize our entries and only ours.
63
60
  MARKER = "/" + RUNNER_NAME
64
-
65
61
  SCRIPTS_DIR = Path(__file__).resolve().parent
66
62
  PLUGIN_ROOT = SCRIPTS_DIR.parents[2]
67
-
68
63
  # Semver with an optional prerelease tag (5.13.50-rc.1). The charset stays
69
64
  # shell-safe because the version is rendered into the setup script.
70
65
  _VERSION_RE = re.compile(r"^\d+\.\d+\.\d+(?:-[0-9A-Za-z]+(?:\.[0-9A-Za-z]+)*)?$")
71
-
72
-
73
66
  def _version_key(v: str):
74
67
  """Sort key: releases after their prereleases, numeric parts numerically."""
75
68
  core, _, pre = v.partition("-")
@@ -491,7 +484,13 @@ def render_run_sh(root: Path, pycache: Path, version: str) -> str:
491
484
  # extracted tarball (package.json, README, LICENSE files) is copied too; this
492
485
  # list is what must exist for a usable install.
493
486
  _REQUIRED = ("hooks/hooks.json", "hooks/python-launcher.sh", "hooks/run.py",
494
- "skills/token-optimizer/scripts/measure.py")
487
+ "skills/token-optimizer/scripts/measure.py") + tuple(
488
+ "skills/token-optimizer/scripts/_measure/" + name for name in (
489
+ '__init__.py', '_compat.py', 'runtime.py', 'pricing.py', 'audit.py',
490
+ 'dashboard.py', 'lifecycle.py', 'sessions.py', 'trends.py', 'cache_policy.py',
491
+ 'daemon.py', 'quality_archive.py', 'continuity.py', 'savings.py', 'cli.py',
492
+ )
493
+ )
495
494
 
496
495
 
497
496
  # Written into the cache dir on install. Uninstall only removes the shared
@@ -102,11 +102,11 @@ _TABLE_HEADER_RE = re.compile(r"(?m)^[ \t]*\[\[?[^\[\]\n]+\]\]?[ \t]*(?:#.*)?$")
102
102
 
103
103
  def _toml_root_value(config_text: str):
104
104
  """Return (state, root value of the setting). state is "ok", "invalid"
105
- (the text does not parse) or "unavailable" (no TOML parser, Python < 3.11)."""
105
+ (the text does not parse). Both readers support TOML 1.0."""
106
106
  try:
107
107
  import tomllib # Python 3.11+
108
108
  except ImportError:
109
- return "unavailable", None
109
+ from _measure._vendor import tomli as tomllib
110
110
  try:
111
111
  data = tomllib.loads(config_text)
112
112
  except Exception:
@@ -57,6 +57,16 @@ SKILL_INSTALL_FILES = (
57
57
  )
58
58
 
59
59
 
60
+ # Completeness is separate from the legacy healthy-output counts.
61
+ _MEASURE_PACKAGE_FILES = (
62
+ "_measure/__init__.py", "_measure/_compat.py", "_measure/runtime.py",
63
+ "_measure/pricing.py", "_measure/audit.py", "_measure/dashboard.py",
64
+ "_measure/lifecycle.py", "_measure/sessions.py", "_measure/trends.py",
65
+ "_measure/cache_policy.py", "_measure/daemon.py", "_measure/quality_archive.py",
66
+ "_measure/continuity.py", "_measure/savings.py", "_measure/cli.py",
67
+ )
68
+
69
+
60
70
  def _repo_root() -> Path:
61
71
  return Path(__file__).resolve().parents[3]
62
72
 
@@ -207,6 +217,8 @@ def _command_mentions_missing_path(root: Path, command: str) -> bool:
207
217
 
208
218
  def _required_file_checks(root: Path) -> list[dict[str, str]]:
209
219
  missing = [rel for rel in REQUIRED_FILES if not (root / rel).exists()]
220
+ missing += ['skills/token-optimizer/scripts/' + rel for rel in _MEASURE_PACKAGE_FILES
221
+ if not (root / 'skills/token-optimizer/scripts' / rel).is_file()]
210
222
  if missing:
211
223
  return [_check("FAIL", "Required files", ", ".join(missing))]
212
224
  return [_check("OK", "Required files", f"{len(REQUIRED_FILES)} present")]
@@ -215,6 +227,8 @@ def _required_file_checks(root: Path) -> list[dict[str, str]]:
215
227
  def _skill_install_checks() -> list[dict[str, str]]:
216
228
  root = _skill_root()
217
229
  missing = [rel for rel in SKILL_INSTALL_FILES if not (root / rel).exists()]
230
+ missing += ['scripts/' + rel for rel in _MEASURE_PACKAGE_FILES
231
+ if not (root / 'scripts' / rel).is_file()]
218
232
  if missing:
219
233
  return [_check("FAIL", "Installed skill files", ", ".join(missing))]
220
234
  return [