@alexgreensh/token-optimizer 5.13.67 → 5.13.68
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/package.json +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/daemon.py +21 -51
- package/skills/token-optimizer/scripts/_measure/lifecycle.py +82 -521
- package/skills/token-optimizer/scripts/{_measure/_vendor/tomli/_parser.py → _tomli.py} +156 -10
- package/skills/token-optimizer/scripts/antigravity_install.py +3 -0
- package/skills/token-optimizer/scripts/cloud_kit.py +21 -21
- package/skills/token-optimizer/scripts/codex_doctor.py +33 -7
- 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 +5 -0
- package/skills/token-optimizer/scripts/cursor_install.py +5 -0
- package/skills/token-optimizer/scripts/devin_install.py +6 -12
- package/skills/token-optimizer/scripts/devin_source.py +5 -4
- package/skills/token-optimizer/scripts/devin_verify.py +16 -0
- package/skills/token-optimizer/scripts/grok_install.py +5 -0
- package/skills/token-optimizer/scripts/heal_report.py +92 -0
- 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/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/_measure/_vendor/tomli/_re.py +0 -112
- package/skills/token-optimizer/scripts/_measure/_vendor/tomli/_types.py +0 -10
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"name": "token-optimizer",
|
|
14
14
|
"source": "./",
|
|
15
15
|
"description": "Audit, fix, and monitor Claude Code context window usage. Find the ghost tokens.",
|
|
16
|
-
"version": "5.13.
|
|
16
|
+
"version": "5.13.68",
|
|
17
17
|
"author": {
|
|
18
18
|
"name": "Alex Greenshpun",
|
|
19
19
|
"url": "https://linkedin.com/in/alexgreensh"
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"name": "token-optimizer-cowork",
|
|
56
56
|
"source": "./cowork/token-optimizer",
|
|
57
57
|
"description": "Token Optimizer for Claude Cowork \u2014 full skills + Cowork-native hooks (beta). Install THIS in Cowork; the standard token-optimizer entry is for desktop Claude Code.",
|
|
58
|
-
"version": "5.13.
|
|
58
|
+
"version": "5.13.68",
|
|
59
59
|
"author": {
|
|
60
60
|
"name": "Alex Greenshpun",
|
|
61
61
|
"url": "https://linkedin.com/in/alexgreensh"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexgreensh/token-optimizer",
|
|
3
|
-
"version": "5.13.
|
|
3
|
+
"version": "5.13.68",
|
|
4
4
|
"description": "Token Optimizer for Claude Code cloud sessions: the real plugin, installed by your cloud environment's setup script.",
|
|
5
5
|
"license": "PolyForm-Noncommercial-1.0.0",
|
|
6
6
|
"author": "Alex Greenshpun (https://linkedin.com/in/alexgreensh)",
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
# Vendored TOML reader
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The parser source is the flat `../../../_tomli.py` module (Tomli 2.2.1, MIT,
|
|
4
|
+
Taneli Hukkinen; SPDX headers in the file, full text in `tomli/LICENSE`).
|
|
5
|
+
It is the single copy: Devin's closed payload ships `_tomli.py` because it
|
|
6
|
+
forbids `_measure` imports, and `_measure._vendor.tomli` re-exports it so
|
|
7
|
+
repo code keeps one lazy entry point. Python 3.11+ uses stdlib `tomllib`.
|
|
4
8
|
|
|
5
9
|
Source: https://pypi.org/project/tomli/2.2.1/
|
|
6
10
|
Archive: https://files.pythonhosted.org/packages/18/87/302344fed471e44a87289cf4967697d07e532f2421fdaf868a303cbae4ff/tomli-2.2.1.tar.gz
|
|
7
11
|
Archive SHA256: `cd45e1dc79c835ce60f7404ec8119f2eb06d38b1deba146f07ced3bbc44505ff`
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
`tomli/__init__.py` is a compatibility shim over `_tomli`; `LICENSE` and
|
|
14
|
+
`py.typed` are kept from the upstream package. It is not an extraction
|
|
15
|
+
provider or public API.
|
|
@@ -1,18 +1,58 @@
|
|
|
1
1
|
"""Private, license-preserving runtime dependencies; no runtime installation."""
|
|
2
|
-
import importlib.util
|
|
2
|
+
import importlib.util
|
|
3
|
+
import os as _os
|
|
3
4
|
import sys as _sys
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
def _lazy(name):
|
|
7
|
-
"""Return module ``name``
|
|
8
|
+
"""Return module ``name`` deferred to first attribute access.
|
|
9
|
+
|
|
10
|
+
The module object is registered in sys.modules immediately, but its code
|
|
11
|
+
runs only on the first attribute miss. No lock is held across that exec:
|
|
12
|
+
the shim's own __getattr__ keeps resolving parser attributes lazily, and
|
|
13
|
+
a fork child detects the inherited in-flight exec by pid and binds the
|
|
14
|
+
parser module directly instead of re-entering dead import state.
|
|
15
|
+
"""
|
|
8
16
|
module = _sys.modules.get(name)
|
|
9
17
|
if module is not None:
|
|
10
18
|
return module
|
|
11
|
-
spec =
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
spec = importlib.util.find_spec(name)
|
|
20
|
+
module = importlib.util.module_from_spec(spec)
|
|
21
|
+
pid = _os.getpid()
|
|
22
|
+
|
|
23
|
+
def _getattr(attr):
|
|
24
|
+
if _os.getpid() == pid:
|
|
25
|
+
spec.loader.exec_module(module)
|
|
26
|
+
try:
|
|
27
|
+
return module.__dict__[attr]
|
|
28
|
+
except KeyError:
|
|
29
|
+
pass
|
|
30
|
+
# The shim installed its own lazy __getattr__ during exec; it
|
|
31
|
+
# resolves parser attributes on demand. Anything else missing is
|
|
32
|
+
# a genuine AttributeError from that resolver.
|
|
33
|
+
module_getattr = module.__dict__.get('__getattr__')
|
|
34
|
+
if module_getattr is not None and module_getattr is not _getattr:
|
|
35
|
+
return module_getattr(attr)
|
|
36
|
+
else:
|
|
37
|
+
# Fork child: the parent's first exec of ``name`` was in flight,
|
|
38
|
+
# so its import lock is inherited held by a thread that does not
|
|
39
|
+
# exist here and exec_module could never finish. Bind the parser
|
|
40
|
+
# module's public names directly; _tomli's own lock is free.
|
|
41
|
+
impl = importlib.import_module('_tomli')
|
|
42
|
+
for key in ('TOMLDecodeError', '__version__', 'load', 'loads', '__all__'):
|
|
43
|
+
try:
|
|
44
|
+
module.__dict__[key] = getattr(impl, key)
|
|
45
|
+
except AttributeError:
|
|
46
|
+
pass
|
|
47
|
+
module.__dict__.pop('__getattr__', None)
|
|
48
|
+
try:
|
|
49
|
+
return module.__dict__[attr]
|
|
50
|
+
except KeyError:
|
|
51
|
+
raise AttributeError(
|
|
52
|
+
"module {!r} has no attribute {!r}".format(name, attr)) from None
|
|
53
|
+
|
|
54
|
+
module.__dict__['__getattr__'] = _getattr
|
|
14
55
|
_sys.modules[name] = module
|
|
15
|
-
spec.loader.exec_module(module)
|
|
16
56
|
return module
|
|
17
57
|
|
|
18
58
|
|
|
@@ -2,7 +2,38 @@
|
|
|
2
2
|
# SPDX-FileCopyrightText: 2021 Taneli Hukkinen
|
|
3
3
|
# Licensed to PSF under a Contributor Agreement.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
# Compatibility shim: the canonical flat copy ships as the _tomli payload
|
|
6
|
+
# module so Devin's closed set can use it without _measure imports. This
|
|
7
|
+
# package exists only so `from _measure._vendor import tomli` keeps working;
|
|
8
|
+
# _vendor's lazy loader still defers the real parser to first TOML access.
|
|
9
|
+
import importlib as _importlib
|
|
10
|
+
|
|
11
|
+
_EXPORTS = ("TOMLDecodeError", "__version__", "load", "loads")
|
|
12
|
+
|
|
7
13
|
|
|
8
|
-
|
|
14
|
+
def __getattr__(attr):
|
|
15
|
+
if attr not in _EXPORTS:
|
|
16
|
+
raise AttributeError(
|
|
17
|
+
"module '_measure._vendor.tomli' has no attribute {!r}".format(attr))
|
|
18
|
+
mod = _importlib.import_module("_tomli")
|
|
19
|
+
try:
|
|
20
|
+
value = getattr(mod, attr)
|
|
21
|
+
except AttributeError:
|
|
22
|
+
# _tomli is still executing its own first import on this thread (an
|
|
23
|
+
# import-time callback re-entered the facade). Hand back a resolver
|
|
24
|
+
# that delegates once the parser module finishes; it is not cached,
|
|
25
|
+
# so the real attribute binds on the next access.
|
|
26
|
+
def value(*args, **kwargs):
|
|
27
|
+
target = getattr(_importlib.import_module("_tomli"), attr, None)
|
|
28
|
+
if target is None:
|
|
29
|
+
raise RuntimeError(
|
|
30
|
+
"_tomli is still executing its first import; "
|
|
31
|
+
"tomli.{}() cannot run re-entrantly".format(attr))
|
|
32
|
+
globals()[attr] = target
|
|
33
|
+
return target(*args, **kwargs)
|
|
34
|
+
return value
|
|
35
|
+
globals()[attr] = value
|
|
36
|
+
return value
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
__all__ = ("loads", "load", "TOMLDecodeError")
|
|
@@ -3110,28 +3110,12 @@ def doctor(as_json=None):
|
|
|
3110
3110
|
checks.append(("OK", "Dashboard daemon", "status unknown (probe failed)"))
|
|
3111
3111
|
score += 1
|
|
3112
3112
|
|
|
3113
|
-
# Settings self-heal history
|
|
3113
|
+
# Settings self-heal history, plus one line per hook the malformed-hook
|
|
3114
|
+
# healer left alone because Token Optimizer cannot prove it wrote it.
|
|
3115
|
+
# Informational rows: they never change the score (heal_report.py).
|
|
3114
3116
|
try:
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
_heal_entries = [
|
|
3118
|
-
_measure_facade.json.loads(l) for l in _heal_log.read_text(encoding="utf-8").strip().split("\n")
|
|
3119
|
-
if l.strip()
|
|
3120
|
-
]
|
|
3121
|
-
_restores = [e for e in _heal_entries if e.get("action") == "restore"]
|
|
3122
|
-
if _restores:
|
|
3123
|
-
_last = _restores[-1]
|
|
3124
|
-
_keys = ", ".join(_last.get("restored_keys", [])[:5])
|
|
3125
|
-
if len(_last.get("restored_keys", [])) > 5:
|
|
3126
|
-
_keys += f" (+{len(_last['restored_keys']) - 5} more)"
|
|
3127
|
-
checks.append((
|
|
3128
|
-
"OK", "Settings self-heal",
|
|
3129
|
-
f"{len(_restores)} restore(s), last: {_keys} at {_last.get('timestamp', '?')[:19]}",
|
|
3130
|
-
))
|
|
3131
|
-
else:
|
|
3132
|
-
checks.append(("OK", "Settings self-heal", "no restores needed"))
|
|
3133
|
-
else:
|
|
3134
|
-
checks.append(("OK", "Settings self-heal", "no heal history yet"))
|
|
3117
|
+
import heal_report
|
|
3118
|
+
checks.extend(heal_report.doctor_rows(_measure_facade))
|
|
3135
3119
|
except Exception:
|
|
3136
3120
|
pass # doctor must never fail on heal history
|
|
3137
3121
|
|
|
@@ -1734,18 +1734,13 @@ def session_health():
|
|
|
1734
1734
|
print("\nSession health check is not supported on this platform.")
|
|
1735
1735
|
return
|
|
1736
1736
|
|
|
1737
|
-
installed_version =
|
|
1738
|
-
|
|
1739
|
-
automated = health["automated"]
|
|
1740
|
-
recommendations = health["recommendations"]
|
|
1737
|
+
installed_version, running_sessions, automated, recommendations = (
|
|
1738
|
+
health[k] for k in ("installed_version", "running_sessions", "automated", "recommendations"))
|
|
1741
1739
|
|
|
1742
1740
|
print("\nSESSION HEALTH CHECK")
|
|
1743
1741
|
print("=" * 55)
|
|
1744
1742
|
|
|
1745
|
-
|
|
1746
|
-
print(f"\n Installed version: {installed_version}")
|
|
1747
|
-
else:
|
|
1748
|
-
print("\n Installed version: unknown (could not run 'claude --version')")
|
|
1743
|
+
print(f"\n Installed version: {installed_version or 'unknown (could not run ' + repr('claude --version') + ')'}")
|
|
1749
1744
|
|
|
1750
1745
|
if not running_sessions:
|
|
1751
1746
|
print("\n No running Claude Code CLI sessions found.")
|
|
@@ -1770,6 +1765,11 @@ def session_health():
|
|
|
1770
1765
|
print("\nAUTOMATED PROCESSES")
|
|
1771
1766
|
for proc in automated:
|
|
1772
1767
|
print(f" {proc}")
|
|
1768
|
+
try: # hooks the malformed-hook healer left alone (heal_report.py)
|
|
1769
|
+
for _line in __import__("heal_report").health_lines(_measure_facade):
|
|
1770
|
+
print(_line)
|
|
1771
|
+
except Exception:
|
|
1772
|
+
pass # health must never fail on this optional section
|
|
1773
1773
|
|
|
1774
1774
|
print()
|
|
1775
1775
|
|
|
@@ -5430,51 +5430,19 @@ def _backup_settings_file(dest_dir: Path) -> Path | None:
|
|
|
5430
5430
|
return None
|
|
5431
5431
|
|
|
5432
5432
|
|
|
5433
|
-
def _is_our_hook_entry(entry) -> bool:
|
|
5434
|
-
"""True when a settings.json hook entry is one
|
|
5433
|
+
def _is_our_hook_entry(entry, event="", group=None) -> bool:
|
|
5434
|
+
"""True when a settings.json hook entry is one Token Optimizer wrote (cleanup).
|
|
5435
5435
|
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
* it carries one of our distinctive subcommands (quality-cache,
|
|
5443
|
-
compact-capture, compact-restore, ensure-health, clear-compacted,
|
|
5444
|
-
session-end-flush, dynamic-compact-instructions).
|
|
5445
|
-
|
|
5446
|
-
Conservative by construction: unrecognized shapes are NOT ours, so a hook
|
|
5447
|
-
we cannot positively identify is left in place. The cost of a false
|
|
5448
|
-
negative is a dangling entry the user can delete; the cost of a false
|
|
5449
|
-
positive is silently deleting their automation.
|
|
5436
|
+
Proof only (owned_hooks.cleanup_owner): recorded in the provenance ledger,
|
|
5437
|
+
a shipped hooks.json entry for an install root, or byte-identical to a
|
|
5438
|
+
command setup_hook / setup_smart_compact / setup_quality_bar generated for
|
|
5439
|
+
an install's measure.py. A command that merely names our subcommands or
|
|
5440
|
+
scripts proves nothing and stays: a dangling entry the user can delete
|
|
5441
|
+
beats silently deleting their automation.
|
|
5450
5442
|
"""
|
|
5451
5443
|
_measure_facade = _compat.facade()
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
cmd = entry.get("command")
|
|
5455
|
-
if not isinstance(cmd, str) or not cmd:
|
|
5456
|
-
return False
|
|
5457
|
-
low = cmd.lower()
|
|
5458
|
-
our_subcommands = (
|
|
5459
|
-
"quality-cache", "compact-capture", "compact-restore", "ensure-health",
|
|
5460
|
-
"clear-compacted", "session-end-flush", "dynamic-compact-instructions",
|
|
5461
|
-
)
|
|
5462
|
-
if any(sub in low for sub in our_subcommands):
|
|
5463
|
-
return True
|
|
5464
|
-
our_scripts = (
|
|
5465
|
-
"measure.py", "read_cache.py", "statusline.js", "archive_result.py",
|
|
5466
|
-
"context_intel.py", "activity_tracker.py",
|
|
5467
|
-
# the UserPromptSubmit dispatcher. Without it a hook that
|
|
5468
|
-
# runs userpromptsubmit_runner.py (+ token-optimizer) is not recognised
|
|
5469
|
-
# as ours, so ownership-gated repair/reconciliation skips it. Whitelisting
|
|
5470
|
-
# the script name here is inert until the dispatcher ships (it is not yet
|
|
5471
|
-
# in this branch) and never matches a foreign hook (the token-optimizer
|
|
5472
|
-
# substring is still required alongside it).
|
|
5473
|
-
"userpromptsubmit_runner.py",
|
|
5474
|
-
)
|
|
5475
|
-
if "token-optimizer" in low and any(s in low for s in our_scripts):
|
|
5476
|
-
return True
|
|
5477
|
-
return False
|
|
5444
|
+
import owned_hooks
|
|
5445
|
+
return owned_hooks.cleanup_owner(_measure_facade)(event, {"hooks": [entry]} if group is None else group, entry)
|
|
5478
5446
|
|
|
5479
5447
|
|
|
5480
5448
|
def _remove_our_settings_entries(settings: dict) -> list[str]:
|
|
@@ -5522,6 +5490,8 @@ def _remove_our_settings_entries(settings: dict) -> list[str]:
|
|
|
5522
5490
|
# filtered with the same ownership predicate.
|
|
5523
5491
|
hooks = settings.get("hooks")
|
|
5524
5492
|
if isinstance(hooks, dict):
|
|
5493
|
+
import owned_hooks
|
|
5494
|
+
owns = owned_hooks.cleanup_owner(_measure_facade) # proof only, as _is_our_hook_entry
|
|
5525
5495
|
for event in list(hooks.keys()):
|
|
5526
5496
|
groups = hooks.get(event)
|
|
5527
5497
|
if not isinstance(groups, list):
|
|
@@ -5536,7 +5506,7 @@ def _remove_our_settings_entries(settings: dict) -> list[str]:
|
|
|
5536
5506
|
if not isinstance(entries, list):
|
|
5537
5507
|
new_groups.append(group)
|
|
5538
5508
|
continue
|
|
5539
|
-
kept = [h for h in entries if not
|
|
5509
|
+
kept = [h for h in entries if not owns(event, group, h)]
|
|
5540
5510
|
n_ours = len(entries) - len(kept)
|
|
5541
5511
|
if n_ours == 0:
|
|
5542
5512
|
# Nothing of ours here -- leave the group exactly as-is,
|