@alexgreensh/token-optimizer 5.13.75 → 5.13.76
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/hooks/posttooluse_runner.py +7 -9
- package/hooks/run.py +5 -1
- package/hooks/stop_runner.py +15 -56
- package/hooks/userpromptsubmit_runner.py +29 -4
- package/package.json +1 -1
- package/skills/token-optimizer/assets/dashboard.html +30 -14
- package/skills/token-optimizer/assets/savings_story.js +103 -27
- package/skills/token-optimizer/references/agent-prompts.md +2 -0
- package/skills/token-optimizer/references/implementation-playbook.md +1 -0
- package/skills/token-optimizer/scripts/_measure/__init__.py +1 -1
- package/skills/token-optimizer/scripts/_measure/apply_safe.py +512 -0
- package/skills/token-optimizer/scripts/_measure/audit.py +9 -20
- package/skills/token-optimizer/scripts/_measure/autocompact_advice.py +455 -0
- package/skills/token-optimizer/scripts/_measure/cache_policy.py +82 -127
- package/skills/token-optimizer/scripts/_measure/cli.py +10 -24
- package/skills/token-optimizer/scripts/_measure/cold_guard.py +777 -0
- package/skills/token-optimizer/scripts/_measure/continuity.py +45 -4
- package/skills/token-optimizer/scripts/_measure/counted_closes.py +398 -0
- package/skills/token-optimizer/scripts/_measure/counted_headline.py +112 -0
- package/skills/token-optimizer/scripts/_measure/dashboard.py +14 -6
- package/skills/token-optimizer/scripts/_measure/feature_health.py +6 -0
- package/skills/token-optimizer/scripts/_measure/keepwarm_auto.py +452 -0
- package/skills/token-optimizer/scripts/_measure/keepwarm_economics.py +8 -4
- package/skills/token-optimizer/scripts/_measure/keepwarm_safety.py +548 -24
- package/skills/token-optimizer/scripts/_measure/limit_units.py +463 -0
- package/skills/token-optimizer/scripts/_measure/local_adapt.py +192 -0
- package/skills/token-optimizer/scripts/_measure/mod_action_booking.py +71 -14
- package/skills/token-optimizer/scripts/_measure/next_actions.py +420 -0
- package/skills/token-optimizer/scripts/_measure/poc_commands.py +44 -0
- package/skills/token-optimizer/scripts/_measure/prefix_cost.py +215 -0
- package/skills/token-optimizer/scripts/_measure/pt_resume_cues.py +46 -0
- package/skills/token-optimizer/scripts/_measure/quality_archive.py +7 -10
- package/skills/token-optimizer/scripts/_measure/savings.py +75 -81
- package/skills/token-optimizer/scripts/_measure/savings_headline.py +17 -21
- package/skills/token-optimizer/scripts/_measure/savings_story.py +8 -1
- package/skills/token-optimizer/scripts/_measure/session_store_spool.py +119 -78
- package/skills/token-optimizer/scripts/_measure/status_bar_refresh.py +38 -3
- package/skills/token-optimizer/scripts/_measure/structural_ledger.py +1 -1
- package/skills/token-optimizer/scripts/_measure/subscription_audits.py +725 -0
- package/skills/token-optimizer/scripts/_measure/transcript_backfill.py +1 -1
- package/skills/token-optimizer/scripts/_measure/transcript_stream.py +8 -2
- package/skills/token-optimizer/scripts/antigravity_install.py +3 -0
- package/skills/token-optimizer/scripts/archive_result.py +16 -28
- package/skills/token-optimizer/scripts/archive_verify.py +1 -1
- package/skills/token-optimizer/scripts/bash_compress.py +156 -176
- package/skills/token-optimizer/scripts/bash_compress_hook.py +218 -174
- package/skills/token-optimizer/scripts/bash_search_results.py +189 -9
- package/skills/token-optimizer/scripts/bash_whitelist.py +6 -1
- package/skills/token-optimizer/scripts/benchmark.py +11 -13
- package/skills/token-optimizer/scripts/big_noncode_read.py +998 -0
- package/skills/token-optimizer/scripts/build_output_compress.py +103 -8
- package/skills/token-optimizer/scripts/builtin_tool_compress.py +716 -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/command_compress_extra.py +955 -0
- package/skills/token-optimizer/scripts/compact_markers.py +129 -0
- package/skills/token-optimizer/scripts/copilot_install.py +3 -0
- package/skills/token-optimizer/scripts/cursor_install.py +7 -0
- package/skills/token-optimizer/scripts/devin_source.py +5 -5
- package/skills/token-optimizer/scripts/emit_safety_gate.py +518 -0
- package/skills/token-optimizer/scripts/fixtures/b2_more_commands.json +142 -0
- package/skills/token-optimizer/scripts/fixtures/b5_more_savings.json +26 -0
- package/skills/token-optimizer/scripts/fixtures/builtin_tools.json +103 -0
- package/skills/token-optimizer/scripts/fixtures/c7_review_ratchet.json +52 -0
- package/skills/token-optimizer/scripts/fixtures/large_output_policy.json +55 -0
- package/skills/token-optimizer/scripts/go_cargo_test_compress.py +493 -0
- package/skills/token-optimizer/scripts/grok_install.py +3 -0
- package/skills/token-optimizer/scripts/hermes_doctor.py +4 -1
- package/skills/token-optimizer/scripts/hermes_install.py +10 -1
- package/skills/token-optimizer/scripts/hook_fastpath.py +94 -0
- package/skills/token-optimizer/scripts/hook_runtime.py +6 -2
- package/skills/token-optimizer/scripts/large_output_policy.py +431 -0
- package/skills/token-optimizer/scripts/measure.py +10 -12
- package/skills/token-optimizer/scripts/pipe_file_compress.py +900 -0
- package/skills/token-optimizer/scripts/pipeline_analyzer.py +15 -1
- package/skills/token-optimizer/scripts/post_run_classify.py +2 -2
- package/skills/token-optimizer/scripts/preserved_reinject.py +20 -3
- package/skills/token-optimizer/scripts/process_identity.py +66 -0
- package/skills/token-optimizer/scripts/read_cache.py +51 -60
- package/skills/token-optimizer/scripts/statusline.js +21 -3
- package/skills/token-optimizer/scripts/visibility_rule.py +536 -0
|
@@ -244,7 +244,7 @@ def _split_stages(tokens: list[str]) -> list[list[str]]:
|
|
|
244
244
|
_READ_ONLY_SINGLE = frozenset({
|
|
245
245
|
# === From bash_hook._WHITELIST_SINGLE ===
|
|
246
246
|
"git", "pytest", "py.test", "jest", "vitest", "rspec", "ls", "find",
|
|
247
|
-
"eslint", "flake8", "pylint", "shellcheck", "rubocop",
|
|
247
|
+
"eslint", "flake8", "pylint", "shellcheck", "rubocop", "mypy",
|
|
248
248
|
"tail", "journalctl", "tree",
|
|
249
249
|
"tsc", "webpack", "esbuild",
|
|
250
250
|
"mocha", "karma", "tox", "nox", "ava", "gradle", "gradlew", "mvn",
|
|
@@ -330,6 +330,14 @@ _READ_ONLY_COMPOUND = frozenset({
|
|
|
330
330
|
("terraform", "plan"),
|
|
331
331
|
("terraform", "show"),
|
|
332
332
|
("terraform", "output"),
|
|
333
|
+
("tofu", "plan"),
|
|
334
|
+
("tofu", "show"),
|
|
335
|
+
("tofu", "output"),
|
|
336
|
+
("gh", "run"),
|
|
337
|
+
("gh", "pr"),
|
|
338
|
+
("gh", "issue"),
|
|
339
|
+
("gh", "workflow"),
|
|
340
|
+
("gh", "release"),
|
|
333
341
|
("yarn", "test"),
|
|
334
342
|
("make", "-n"),
|
|
335
343
|
("cargo", "check"),
|
|
@@ -544,6 +552,12 @@ def _is_stage_read_only(tokens: list[str]) -> tuple[bool, str]:
|
|
|
544
552
|
if subsub in ("up", "down", "build", "run", "exec", "pull", "push", "restart", "start", "stop", "rm"):
|
|
545
553
|
return False, "docker-compose-side-effect"
|
|
546
554
|
return False, "docker-compose-unknown"
|
|
555
|
+
# gh: strict read-only sub-subcommand allow-list (view/list/checks/diff/status).
|
|
556
|
+
if cmd == "gh":
|
|
557
|
+
subsub = tokens[cmd_start + 2] if cmd_start + 2 < len(tokens) else ""
|
|
558
|
+
if subsub in ("view", "list", "checks", "diff", "status"):
|
|
559
|
+
return True, "gh-read-only"
|
|
560
|
+
return False, f"gh-forbidden-action:{subsub}"
|
|
547
561
|
return True, "compound-whitelist"
|
|
548
562
|
|
|
549
563
|
# -------------------------------------------------------------------
|
|
@@ -38,7 +38,7 @@ _DEFAULT_MODE = "on"
|
|
|
38
38
|
|
|
39
39
|
ALLOWED_PATTERNS = frozenset({
|
|
40
40
|
"git_diff", "search_results", "disk_stats", "pytest", "sqlite3", "ls",
|
|
41
|
-
"git_status",
|
|
41
|
+
"git_status", "git_ls", "gh_run_log", "gh_list", "terraform_plan", "mypy",
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
_ASSIGN_RE = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*=")
|
|
@@ -271,7 +271,7 @@ _CANDIDATE_HEADS = frozenset({
|
|
|
271
271
|
"pytest", "py.test", "python", "python3", "rspec", "mocha", "karma",
|
|
272
272
|
"cypress", "playwright", "npx", "go", "cargo", "tox", "nox",
|
|
273
273
|
"nox-sessions", "gradle", "gradlew", "./gradlew", "mvn", "deno", "bun",
|
|
274
|
-
"ava", "npm", "jest", "vitest",
|
|
274
|
+
"ava", "npm", "jest", "vitest", "gh", "terraform", "tofu", "mypy",
|
|
275
275
|
})
|
|
276
276
|
|
|
277
277
|
|
|
@@ -14,11 +14,28 @@ import re
|
|
|
14
14
|
WARNING_LINE_RE = re.compile(r"(?i)\bwarn(?:ing)?s?\b|\b[A-Za-z]+Warning\b")
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
def find_priority_lines(text, error_patterns):
|
|
18
|
-
"""Indices of error and warning lines.
|
|
17
|
+
def find_priority_lines(text, error_patterns, *, is_search=False):
|
|
18
|
+
"""Indices of error and warning lines.
|
|
19
|
+
|
|
20
|
+
When ``is_search`` is True, structured ``file:line:content`` grep/rg matches
|
|
21
|
+
of literal words like ``error`` or ``ValueError`` are ordinary search hits
|
|
22
|
+
and are not treated as runtime failures; non-match tool/diagnostic errors
|
|
23
|
+
still stay visible verbatim.
|
|
24
|
+
"""
|
|
25
|
+
try:
|
|
26
|
+
from visibility_rule import is_error_or_failure_line, is_search_match_line
|
|
27
|
+
except Exception:
|
|
28
|
+
is_error_or_failure_line = None
|
|
29
|
+
is_search_match_line = None
|
|
19
30
|
out = set()
|
|
20
31
|
for i, line in enumerate(text.splitlines()):
|
|
21
|
-
if
|
|
32
|
+
if is_search and is_search_match_line is not None and is_search_match_line(line):
|
|
33
|
+
continue
|
|
34
|
+
if (
|
|
35
|
+
WARNING_LINE_RE.search(line)
|
|
36
|
+
or any(p.search(line) for p in error_patterns)
|
|
37
|
+
or (is_error_or_failure_line is not None and is_error_or_failure_line(line))
|
|
38
|
+
):
|
|
22
39
|
out.add(i)
|
|
23
40
|
return out
|
|
24
41
|
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Read a process creation stamp without launching a command."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def process_start(pid):
|
|
8
|
+
"""Return a comparable stamp for this PID's current process, or None."""
|
|
9
|
+
try:
|
|
10
|
+
pid = int(pid)
|
|
11
|
+
if not 0 < pid < 2**31:
|
|
12
|
+
return None
|
|
13
|
+
if sys.platform.startswith("linux"):
|
|
14
|
+
stat = Path(f"/proc/{pid}/stat").read_text()
|
|
15
|
+
# The executable name can itself contain spaces and parentheses.
|
|
16
|
+
return stat.rsplit(")", 1)[1].split()[19]
|
|
17
|
+
if sys.platform == "darwin":
|
|
18
|
+
return _darwin_start(pid)
|
|
19
|
+
if sys.platform == "win32":
|
|
20
|
+
return _windows_start(pid)
|
|
21
|
+
except (OSError, ValueError, TypeError, IndexError):
|
|
22
|
+
return None
|
|
23
|
+
return None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _darwin_start(pid):
|
|
27
|
+
import ctypes
|
|
28
|
+
|
|
29
|
+
class ProcBSDInfo(ctypes.Structure):
|
|
30
|
+
# sys/proc_info.h: the fixed-width fields preceding the start timeval.
|
|
31
|
+
_fields_ = [("prefix", ctypes.c_byte * 120),
|
|
32
|
+
("start_seconds", ctypes.c_uint64), ("start_microseconds", ctypes.c_uint64)]
|
|
33
|
+
|
|
34
|
+
proc_pidinfo = ctypes.CDLL("/usr/lib/libproc.dylib").proc_pidinfo
|
|
35
|
+
proc_pidinfo.argtypes = (ctypes.c_int, ctypes.c_int, ctypes.c_uint64, ctypes.c_void_p, ctypes.c_int)
|
|
36
|
+
info = ProcBSDInfo()
|
|
37
|
+
size = ctypes.sizeof(info)
|
|
38
|
+
if proc_pidinfo(pid, 3, 0, ctypes.byref(info), size) == size: # PROC_PIDTBSDINFO
|
|
39
|
+
return f"{info.start_seconds}:{info.start_microseconds}"
|
|
40
|
+
return None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _windows_start(pid):
|
|
44
|
+
import ctypes
|
|
45
|
+
from ctypes import wintypes
|
|
46
|
+
|
|
47
|
+
kernel = ctypes.WinDLL("kernel32")
|
|
48
|
+
kernel.OpenProcess.argtypes = (wintypes.DWORD, wintypes.BOOL, wintypes.DWORD)
|
|
49
|
+
kernel.OpenProcess.restype = wintypes.HANDLE
|
|
50
|
+
kernel.CloseHandle.argtypes = (wintypes.HANDLE,)
|
|
51
|
+
kernel.WaitForSingleObject.argtypes = (wintypes.HANDLE, wintypes.DWORD)
|
|
52
|
+
kernel.WaitForSingleObject.restype = wintypes.DWORD
|
|
53
|
+
kernel.GetProcessTimes.argtypes = (wintypes.HANDLE,) + (ctypes.POINTER(wintypes.FILETIME),) * 4
|
|
54
|
+
# PROCESS_QUERY_LIMITED_INFORMATION | SYNCHRONIZE
|
|
55
|
+
handle = kernel.OpenProcess(0x1000 | 0x100000, False, pid)
|
|
56
|
+
if not handle:
|
|
57
|
+
return None
|
|
58
|
+
try:
|
|
59
|
+
times = [wintypes.FILETIME() for _ in range(4)]
|
|
60
|
+
if (kernel.GetProcessTimes(handle, *(ctypes.byref(stamp) for stamp in times))
|
|
61
|
+
and kernel.WaitForSingleObject(handle, 0) == 258): # WAIT_TIMEOUT: still running
|
|
62
|
+
created = times[0]
|
|
63
|
+
return str((created.dwHighDateTime << 32) | created.dwLowDateTime)
|
|
64
|
+
finally:
|
|
65
|
+
kernel.CloseHandle(handle)
|
|
66
|
+
return None
|
|
@@ -453,49 +453,29 @@ def _make_store(
|
|
|
453
453
|
_COMPACT_SCAN_META_KEY = "compact_scan_cursor"
|
|
454
454
|
_COMPACT_SCAN_MAX_PATHS = 32
|
|
455
455
|
_COMPACT_SCAN_MAX_SEEN = 256
|
|
456
|
-
|
|
456
|
+
from compact_markers import (
|
|
457
|
+
COMPACT_MARKERS as _COMPACT_MARKERS,
|
|
458
|
+
compact_boundary_id as _compact_boundary_id,
|
|
459
|
+
should_invalidate_for_id as _should_invalidate_for_id,
|
|
460
|
+
)
|
|
457
461
|
_COMPACT_SCAN_CHUNK = 1 << 20 # 1 MiB
|
|
458
462
|
_COMPACT_SCAN_MAX_SECONDS = 0.25
|
|
459
463
|
|
|
460
464
|
|
|
461
|
-
def _compact_boundary_id(line: bytes, where: str = ""):
|
|
462
|
-
"""Stable id of a real compaction row (its uuid, else a hash of the row and
|
|
463
|
-
``where`` it sits: path + byte offset, so two identical uuid-less rows stay
|
|
464
|
-
distinct), or None when the line is not one: a tool result that merely
|
|
465
|
-
quotes the marker text (reading TO's own source would otherwise trip it)
|
|
466
|
-
is not."""
|
|
467
|
-
if not any(m in line for m in _COMPACT_MARKERS):
|
|
468
|
-
return None
|
|
469
|
-
try:
|
|
470
|
-
row = json.loads(line.decode("utf-8", errors="replace"))
|
|
471
|
-
except (ValueError, UnicodeDecodeError):
|
|
472
|
-
return None
|
|
473
|
-
if not isinstance(row, dict):
|
|
474
|
-
return None
|
|
475
|
-
if not ((row.get("type") == "system" and row.get("subtype") == "compact_boundary")
|
|
476
|
-
or row.get("isCompactSummary") is True):
|
|
477
|
-
return None
|
|
478
|
-
uuid = row.get("uuid")
|
|
479
|
-
if isinstance(uuid, str) and uuid:
|
|
480
|
-
return "u:" + uuid[:80]
|
|
481
|
-
import hashlib
|
|
482
|
-
return "h:" + hashlib.sha1(where.encode("utf-8", "replace") + b"\0" + line.strip()).hexdigest()[:20]
|
|
483
|
-
|
|
484
|
-
|
|
485
465
|
def _is_compact_boundary_row(line: bytes) -> bool:
|
|
486
466
|
return _compact_boundary_id(line) is not None
|
|
487
467
|
|
|
488
468
|
|
|
489
469
|
def _load_compact_cursor(store: Any) -> tuple:
|
|
490
|
-
"""(paths: {path: offset}, seen: [boundary ids]
|
|
491
|
-
the pre-map single-slot shape too. Never raises."""
|
|
470
|
+
"""(paths: {path: offset}, seen: [boundary ids], cm: {path: [c, u, t]})
|
|
471
|
+
from session_meta. Reads the pre-map single-slot shape too. Never raises."""
|
|
492
472
|
try:
|
|
493
473
|
raw = store.get_meta(_COMPACT_SCAN_META_KEY)
|
|
494
474
|
cur = json.loads(raw) if raw else None
|
|
495
475
|
except Exception:
|
|
496
476
|
cur = None
|
|
497
477
|
if not isinstance(cur, dict):
|
|
498
|
-
return {}, []
|
|
478
|
+
return {}, [], {}
|
|
499
479
|
paths: dict = {}
|
|
500
480
|
if isinstance(cur.get("paths"), dict):
|
|
501
481
|
for k, v in cur["paths"].items():
|
|
@@ -509,7 +489,15 @@ def _load_compact_cursor(store: Any) -> tuple:
|
|
|
509
489
|
except (TypeError, ValueError):
|
|
510
490
|
pass
|
|
511
491
|
seen = [x for x in cur.get("seen") or [] if isinstance(x, str)]
|
|
512
|
-
|
|
492
|
+
cm: dict = {}
|
|
493
|
+
if isinstance(cur.get("cm"), dict):
|
|
494
|
+
for k, v in cur["cm"].items():
|
|
495
|
+
if isinstance(v, list) and len(v) == 3:
|
|
496
|
+
try:
|
|
497
|
+
cm[str(k)] = [max(0, int(v[0])), max(0, int(v[1])), max(0, int(v[2]))]
|
|
498
|
+
except (TypeError, ValueError):
|
|
499
|
+
continue
|
|
500
|
+
return paths, seen, cm
|
|
513
501
|
|
|
514
502
|
|
|
515
503
|
def _scan_for_compaction(store: Any, transcript_path: Any) -> bool:
|
|
@@ -532,7 +520,7 @@ def _scan_for_compaction(store: Any, transcript_path: Any) -> bool:
|
|
|
532
520
|
if not stat_module.S_ISREG(st.st_mode):
|
|
533
521
|
return False
|
|
534
522
|
size = st.st_size
|
|
535
|
-
paths, seen = _load_compact_cursor(store)
|
|
523
|
+
paths, seen, cm = _load_compact_cursor(store)
|
|
536
524
|
offset = paths.get(path, 0)
|
|
537
525
|
if offset > size:
|
|
538
526
|
offset = 0 # rewritten / truncated transcript: rescan
|
|
@@ -540,6 +528,8 @@ def _scan_for_compaction(store: Any, transcript_path: Any) -> bool:
|
|
|
540
528
|
return False
|
|
541
529
|
found = False
|
|
542
530
|
new_ids: list = []
|
|
531
|
+
cm_wm = list(cm.get(path, [0, 0, 0]))
|
|
532
|
+
orig_cm_wm = list(cm_wm)
|
|
543
533
|
start = time.monotonic()
|
|
544
534
|
pos = offset
|
|
545
535
|
with open(path, "rb") as fh:
|
|
@@ -562,21 +552,28 @@ def _scan_for_compaction(store: Any, transcript_path: Any) -> bool:
|
|
|
562
552
|
for line in complete.split(b"\n"):
|
|
563
553
|
bid = _compact_boundary_id(line, "%s@%d" % (path, line_at)) if line else None
|
|
564
554
|
line_at += len(line) + 1
|
|
565
|
-
if bid and bid
|
|
566
|
-
new_ids.append(bid)
|
|
555
|
+
if bid and _should_invalidate_for_id(bid, seen, new_ids, cm_wm):
|
|
567
556
|
found = True
|
|
568
557
|
pos += len(complete)
|
|
569
558
|
if time.monotonic() - start > _COMPACT_SCAN_MAX_SECONDS:
|
|
570
559
|
break
|
|
571
|
-
if pos != offset or new_ids:
|
|
560
|
+
if pos != offset or new_ids or cm_wm != orig_cm_wm:
|
|
572
561
|
paths.pop(path, None)
|
|
573
562
|
paths[path] = pos # most recent last; the oldest paths drop first
|
|
563
|
+
if any(cm_wm):
|
|
564
|
+
cm[path] = cm_wm
|
|
565
|
+
else:
|
|
566
|
+
cm.pop(path, None)
|
|
574
567
|
while len(paths) > _COMPACT_SCAN_MAX_PATHS:
|
|
575
|
-
|
|
568
|
+
evicted = next(iter(paths))
|
|
569
|
+
paths.pop(evicted)
|
|
570
|
+
cm.pop(evicted, None)
|
|
576
571
|
seen = (seen + new_ids)[-_COMPACT_SCAN_MAX_SEEN:]
|
|
577
572
|
try:
|
|
578
|
-
|
|
579
|
-
|
|
573
|
+
payload = {"v": 2, "paths": paths, "seen": seen}
|
|
574
|
+
if cm:
|
|
575
|
+
payload["cm"] = cm
|
|
576
|
+
store.set_meta(_COMPACT_SCAN_META_KEY, json.dumps(payload))
|
|
580
577
|
except Exception:
|
|
581
578
|
pass
|
|
582
579
|
return found
|
|
@@ -701,6 +698,14 @@ def _codemap(fn: str, *args: Any, **kwargs: Any) -> Any:
|
|
|
701
698
|
return None
|
|
702
699
|
|
|
703
700
|
|
|
701
|
+
def _try_big_noncode_read(file_path: str, stat: os.stat_result, offset: int, limit: int, session_id: str, store: Any, mode: str, entry: dict[str, Any], cached_content: Optional[str], reset_epoch: Any, save_hook_context_enabled: bool, quiet: bool) -> bool:
|
|
702
|
+
try:
|
|
703
|
+
from big_noncode_read import try_big_noncode_read
|
|
704
|
+
return try_big_noncode_read(file_path, stat, offset, limit, session_id, store, mode, entry, cached_content=cached_content, reset_epoch=reset_epoch, save_hook_context_enabled=save_hook_context_enabled, quiet=quiet, emit_fn=_emit_pretool_response, log_decision_fn=_log_decision, log_savings_fn=_log_savings_event)
|
|
705
|
+
except Exception:
|
|
706
|
+
return False
|
|
707
|
+
|
|
708
|
+
|
|
704
709
|
def _log_unexpected_tool(tool_name: str, quiet: bool = False) -> None:
|
|
705
710
|
"""Log when the hook is invoked for a non-Read tool (matcher bypass)."""
|
|
706
711
|
log_dir = SNAPSHOT_DIR / "diagnostics"
|
|
@@ -1541,32 +1546,18 @@ def _handle_read_impl(hook_input: dict[str, Any], mode: str, quiet: bool, funnel
|
|
|
1541
1546
|
pass
|
|
1542
1547
|
_reset_replacement_state(entry)
|
|
1543
1548
|
store.upsert_file_entry(file_path, entry, expected_reset_epoch=reset_epoch)
|
|
1544
|
-
|
|
1545
|
-
if
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
save_hook_context_enabled=save_hook_context_enabled,
|
|
1549
|
-
quiet=quiet, tool_use_id=current_tool_use_id, parent_session_id=str(hook_input.get("session_id") or ""),
|
|
1550
|
-
):
|
|
1549
|
+
_fr_content = entry.get("cached_content") or delta_content
|
|
1550
|
+
if _try_big_noncode_read(file_path, stat, offset, limit, session_id, store, mode, entry, _fr_content, reset_epoch, save_hook_context_enabled, quiet):
|
|
1551
|
+
return
|
|
1552
|
+
if _first_read_compress(file_path, stat, offset, limit, language, session_id, store, mode, cached_content=_fr_content, save_hook_context_enabled=save_hook_context_enabled, quiet=quiet, tool_use_id=current_tool_use_id, parent_session_id=str(hook_input.get("session_id") or "")):
|
|
1551
1553
|
return
|
|
1552
1554
|
_log_decision(
|
|
1553
|
-
"allow",
|
|
1554
|
-
|
|
1555
|
-
"first_read",
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
eligible=False,
|
|
1560
|
-
language=language,
|
|
1561
|
-
reason_code="first_read",
|
|
1562
|
-
offset=offset,
|
|
1563
|
-
limit=limit,
|
|
1564
|
-
replacement_type=None,
|
|
1565
|
-
file_tokens_est=tokens_est,
|
|
1566
|
-
replacement_tokens_est=0,
|
|
1567
|
-
net_saved_tokens_est=0,
|
|
1568
|
-
replacement_fingerprint=None,
|
|
1569
|
-
repeat_replacement_count=0,
|
|
1555
|
+
"allow", file_path, "first_read", session_id, mode=mode,
|
|
1556
|
+
actual_substitution=False, eligible=False, language=language,
|
|
1557
|
+
reason_code="first_read", offset=offset, limit=limit,
|
|
1558
|
+
replacement_type=None, file_tokens_est=tokens_est,
|
|
1559
|
+
replacement_tokens_est=0, net_saved_tokens_est=0,
|
|
1560
|
+
replacement_fingerprint=None, repeat_replacement_count=0,
|
|
1570
1561
|
save_hook_additional_context_enabled=save_hook_context_enabled,
|
|
1571
1562
|
)
|
|
1572
1563
|
return
|
|
@@ -212,7 +212,7 @@ function _statusBarCacheFiles(dir, key) {
|
|
|
212
212
|
// Freshness is decided on computed_at across all candidate files BEFORE
|
|
213
213
|
// reading display, so a newer "below threshold" cache correctly hides an
|
|
214
214
|
// older number that no longer applies.
|
|
215
|
-
function
|
|
215
|
+
function _statusBarFreshestCache(sessionId) {
|
|
216
216
|
try {
|
|
217
217
|
const key = _statusBarSessionKey(sessionId);
|
|
218
218
|
let best = null, bestTs = -1;
|
|
@@ -228,7 +228,17 @@ function _statusBarHeadlineDisplay(sessionId) {
|
|
|
228
228
|
best = data;
|
|
229
229
|
} catch (e) {}
|
|
230
230
|
}
|
|
231
|
-
|
|
231
|
+
return best;
|
|
232
|
+
} catch (e) {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function _statusBarHeadlineDisplay(sessionId, cache) {
|
|
238
|
+
try {
|
|
239
|
+
const best = cache || _statusBarFreshestCache(sessionId);
|
|
240
|
+
const headline = (best && best.counted_headline && best.counted_headline.display != null)
|
|
241
|
+
? best.counted_headline : best && best.savings && best.savings.savings_headline;
|
|
232
242
|
const display = headline && headline.display;
|
|
233
243
|
if (display && typeof display === 'object' &&
|
|
234
244
|
typeof display.short === 'string' && display.short) {
|
|
@@ -615,7 +625,8 @@ process.stdin.on('end', () => {
|
|
|
615
625
|
// cache (never a Python spawn) and is omitted entirely when the shared
|
|
616
626
|
// headline's display is null.
|
|
617
627
|
const row2Parts = [];
|
|
618
|
-
const
|
|
628
|
+
const statusCache = _statusBarFreshestCache(sessionId);
|
|
629
|
+
const savingsDisplay = _statusBarHeadlineDisplay(sessionId, statusCache);
|
|
619
630
|
let savingsSeg = null;
|
|
620
631
|
if (savingsDisplay) {
|
|
621
632
|
const label = `${savingsDisplay.short} ↗`;
|
|
@@ -626,6 +637,13 @@ process.stdin.on('end', () => {
|
|
|
626
637
|
: `\x1b[32m${label}${RESET}`;
|
|
627
638
|
row2Parts.push(savingsSeg);
|
|
628
639
|
}
|
|
640
|
+
const nextShort = statusCache && statusCache.next_action && statusCache.next_action.short;
|
|
641
|
+
if (typeof nextShort === 'string') {
|
|
642
|
+
const clean = nextShort.replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g, '')
|
|
643
|
+
.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, '').replace(/[\x00-\x1f\x7f-\x9f]/g, '');
|
|
644
|
+
const short = Array.from(clean).slice(0, 40).join('');
|
|
645
|
+
if (short) row2Parts.push(`\x1b[33m${short}${RESET}`);
|
|
646
|
+
}
|
|
629
647
|
|
|
630
648
|
// U3: near-zero-cost "resumable checkpoint" existence signal.
|
|
631
649
|
// When the SessionStart pointer fired (a relevance-cleared checkpoint
|