@alexgreensh/token-optimizer 5.13.51 → 5.13.52

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.
@@ -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.51",
16
+ "version": "5.13.52",
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.51",
58
+ "version": "5.13.52",
59
59
  "author": {
60
60
  "name": "Alex Greenshpun",
61
61
  "url": "https://linkedin.com/in/alexgreensh"
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "homepage": "https://github.com/alexgreensh/token-optimizer",
9
9
  "repository": "https://github.com/alexgreensh/token-optimizer",
10
- "version": "5.13.51",
10
+ "version": "5.13.52",
11
11
  "license": "PolyForm-Noncommercial-1.0.0",
12
12
  "keywords": [
13
13
  "token",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexgreensh/token-optimizer",
3
- "version": "5.13.51",
3
+ "version": "5.13.52",
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,6 +1,6 @@
1
1
  ---
2
2
  name: token-dashboard
3
- description: Answers what a past session cost ("the Navina session yesterday", a session id) with a priced number, and opens the Token Optimizer dashboard when asked to see it.
3
+ description: Answers what a past session cost ("the Garden session yesterday", a session id) with a priced number, and opens the Token Optimizer dashboard when asked to see it.
4
4
  ---
5
5
 
6
6
  # Token Optimizer Dashboard
@@ -62,11 +62,11 @@ if [ -z "$MEASURE_PY" ]; then echo "[Error] measure.py not found. Is Token Optim
62
62
  export TOKEN_OPTIMIZER_RUNTIME="$RUNTIME"
63
63
  ```
64
64
 
65
- 2. **A cost question** ("what did the Navina session yesterday cost?", "how much were my TR sync sessions?", "cost of session <id>"): run this instead of steps 3-4.
65
+ 2. **A cost question** ("what did the Garden session yesterday cost?", "how much were my TR sync sessions?", "cost of session <id>"): run this instead of steps 3-4.
66
66
  ```bash
67
67
  python3 "$MEASURE_PY" session-cost <the user's words> --json
68
68
  ```
69
- - Pass the user's own words (`navina yesterday`, `tr sync`, an id or its first 8 characters). Names match topic, slug and project, case-insensitively, and all of them must match; `today`, `yesterday` and `YYYY-MM-DD` set the day. Add `--days N` for "this week" (default 30), `--limit N` to list more.
69
+ - Pass the user's own words (`garden yesterday`, `tr sync`, an id or its first 8 characters). Names match topic, slug and project, case-insensitively, and all of them must match; `today`, `yesterday` and `YYYY-MM-DD` set the day. Add `--days N` for "this week" (default 30), `--limit N` to list more.
70
70
  - Answer from `sessions[]`: date, topic, `cost_usd.total`, the main-thread and subagent split when subagents ran, `cost_usd.on_date` when a day was asked and the session ran over several days, and `partial_reason` when set. Several matches: give `total_cost_usd` and list them, asking which one only when it changes the answer.
71
71
  - State `basis` in one line: API list prices, so on a subscription it is what the work would have cost, not a bill.
72
72
  - No match: say so, show `closest[]`, and pass on `note` (a session is collected when it ends).
@@ -25956,7 +25956,7 @@ def _price_session_row(sr, pricing_tier):
25956
25956
 
25957
25957
 
25958
25958
  # ---------------------------------------------------------------------------
25959
- # session-cost: "what did the Navina session yesterday cost?" answered from
25959
+ # session-cost: "what did the Garden session yesterday cost?" answered from
25960
25960
  # trends.db, priced by _price_session_row (the dashboard's own number). Strictly
25961
25961
  # read-only: the DB is opened mode=ro (WAL readers never block a writer) and,
25962
25962
  # only if that open fails, immutable=1. Nothing here creates, migrates or
@@ -37268,7 +37268,8 @@ def compute_quality_score(quality_data, session_id=None):
37268
37268
  elif _worst_key == "context_fill_degradation":
37269
37269
  top_drag = {
37270
37270
  "key": "context_fill",
37271
- "label": f"{round(fill_pct * 100)}% context fill",
37271
+ "label": (f"{round(model_fill * 100)}% context fill ({round(fill_pct * 100)}% of the way to auto-compact)"
37272
+ if compact_window_reduced else f"{round(fill_pct * 100)}% context fill"),
37272
37273
  "points": round(_worst_pts, 1),
37273
37274
  }
37274
37275
  elif _worst_key == "compaction_depth":
@@ -37319,8 +37320,8 @@ def compute_quality_score(quality_data, session_id=None):
37319
37320
  _cfd_detail = f"{round(fill_pct * 100)}% fill, {band_name.lower()} ({curve_name})"
37320
37321
  if compact_window_reduced:
37321
37322
  _cfd_detail = (
37322
- f"{round(fill_pct * 100)}% of compact window "
37323
- f"({round(model_fill * 100)}% of model window), "
37323
+ f"{round(model_fill * 100)}% of model window "
37324
+ f"({round(fill_pct * 100)}% of the way to auto-compact), "
37324
37325
  f"{band_name.lower()} ({curve_name})"
37325
37326
  )
37326
37327
 
@@ -40859,7 +40860,7 @@ def compact_capture(transcript_path=None, session_id=None, trigger="auto", cwd=N
40859
40860
  lines.append("## Context Quality")
40860
40861
  lines.append(
40861
40862
  f"- Score: {quality_summary.get('grade', '?')} ({quality_summary.get('score', '?')}/100)"
40862
- f" | Fill: {cfd.get('fill_pct', '?')}%"
40863
+ f" | Fill: {_format_context_fill(cfd.get('fill_pct'), cfd)}"
40863
40864
  f" | Model: {cfd.get('model') or quality_summary.get('model') or 'unknown'}"
40864
40865
  )
40865
40866
  if cfd.get("quality_curve"):
@@ -43015,7 +43016,7 @@ def _continuity_prompt_hint(prompt_text="", session_id=None, cwd=None, max_age_m
43015
43016
  if quality:
43016
43017
  lines.append(
43017
43018
  f"- Prior context quality: {quality.get('grade', '?')} "
43018
- f"({quality.get('score', '?')}/100), fill {quality.get('breakdown', {}).get('context_fill_degradation', {}).get('fill_pct', '?')}%"
43019
+ f"({quality.get('score', '?')}/100), fill {_format_context_fill(quality.get('breakdown', {}).get('context_fill_degradation', {}).get('fill_pct'), quality.get('breakdown', {}).get('context_fill_degradation', {}))}"
43019
43020
  )
43020
43021
  # Per-item relevance filter: a checkpoint that passed the
43021
43022
  # same-project gate may still carry session-wide Key Decisions / Files that
@@ -43694,7 +43695,7 @@ def checkpoint_trigger(milestone=None, session_id=None, transcript_path=None, qu
43694
43695
  transcript_path=str(filepath),
43695
43696
  session_id=session_id,
43696
43697
  trigger=trigger,
43697
- fill_pct=result.get("fill_pct"),
43698
+ fill_pct=_model_window_fill(result),
43698
43699
  quality_score=result.get("score"),
43699
43700
  )
43700
43701
  if not cp_path:
@@ -45868,8 +45869,11 @@ def _maybe_fresh_session_nudge(result, cache_path, quality_data, quiet=False):
45868
45869
  saved_str = f"~{saved // 1000}K" if saved >= 1000 else f"~{saved}"
45869
45870
  usd = _fresh_session_savings_usd(saved, session_id)
45870
45871
  cost_str = f" (~${usd:.2f})" if usd >= 0.01 else ""
45872
+ # Share of the model window: what the user's meter shows (see _format_context_fill).
45873
+ shown = _model_window_fill(result)
45874
+ shown = shown if isinstance(shown, (int, float)) else fill_pct
45871
45875
  return (
45872
- f"[Token Optimizer] {int(fill_pct)}% full, quality {score}. "
45876
+ f"[Token Optimizer] {int(shown)}% full, quality {score}. "
45873
45877
  f"Fresh session reclaims {saved_str}{cost_str}. "
45874
45878
  f"Checkpoint saved, say \"continue this\"."
45875
45879
  )
@@ -56533,6 +56537,43 @@ def _format_reduced_window_note(cached, model_window, model_size):
56533
56537
  return f" (of {_format_window_size(compact)} compact window, {share}{model_size} model window{origin})"
56534
56538
 
56535
56539
 
56540
+ def _format_context_fill(fill_pct, cached):
56541
+ """The fill phrase every model-facing message uses, e.g. "38% of 1M window".
56542
+
56543
+ Leads with the share of the MODEL window: the number the user's own context
56544
+ meter shows. With a reduced compact window the compact share follows as
56545
+ distance to auto-compact. Models quote the first number they read; leading
56546
+ with the compact share made sessions report "76% full" and offer handovers
56547
+ at 38% real fill.
56548
+ """
56549
+ cached = cached or {}
56550
+ try:
56551
+ model_window = int(cached.get("model_context_window") or 0)
56552
+ compact = int(cached.get("compact_window") or 0)
56553
+ except (TypeError, ValueError, OverflowError):
56554
+ model_window = compact = 0
56555
+ model_fill = cached.get("model_fill_pct")
56556
+ if (cached.get("compact_window_reduced") and 0 < compact < model_window
56557
+ and isinstance(fill_pct, (int, float))):
56558
+ if not isinstance(model_fill, (int, float)):
56559
+ model_fill = fill_pct * compact / model_window
56560
+ source = _safe_note_text(cached.get("compact_window_source"), extra="=.[]'", limit=64)
56561
+ origin = f", source: {source}" if source else ""
56562
+ return (f"{model_fill:.0f}% of {_format_window_size(model_window)} window "
56563
+ f"(auto-compact at {_format_window_size(compact)}, {fill_pct:.0f}% of the way there{origin})")
56564
+ if not isinstance(fill_pct, (int, float)):
56565
+ return "?%"
56566
+ return f"{fill_pct:.0f}%{_format_window_note(cached)}"
56567
+
56568
+
56569
+ def _model_window_fill(result):
56570
+ """Share of the model window for display; fill_pct when no reduction applies."""
56571
+ result = result or {}
56572
+ if result.get("compact_window_reduced") and isinstance(result.get("model_fill_pct"), (int, float)):
56573
+ return result["model_fill_pct"]
56574
+ return result.get("fill_pct")
56575
+
56576
+
56536
56577
  def _format_window_note(cached):
56537
56578
  """Render the denominator and its origin, e.g. " (1M window, source: default 1M)".
56538
56579
 
@@ -56865,7 +56906,7 @@ def run_verbosity_steer(transcript_path=None, quiet=True, session_id=None):
56865
56906
  if fill_pct >= 90:
56866
56907
  if not quiet:
56867
56908
  sys.stderr.write(
56868
- f"[Token Optimizer] Context at {fill_pct:.0f}%{window_note} — consider /compact or /clear. "
56909
+ f"[Token Optimizer] Context at {_format_context_fill(fill_pct, cached)} — consider /compact or /clear. "
56869
56910
  f"Verbosity nudge suppressed to avoid adding tokens.\n"
56870
56911
  )
56871
56912
  return ""
@@ -56894,7 +56935,7 @@ def run_verbosity_steer(transcript_path=None, quiet=True, session_id=None):
56894
56935
  # the Sonnet figure as the product number.
56895
56936
  if fill_pct >= 75:
56896
56937
  nudge = (
56897
- f"[Token Optimizer] Context {fill_pct:.0f}%{window_note}, resource health {score:.0f}/100. "
56938
+ f"[Token Optimizer] Context {_format_context_fill(fill_pct, cached)}, resource health {score:.0f}/100. "
56898
56939
  "Answer in a focused and spartan way, as if the user has ADHD. Cut everything "
56899
56940
  "that is not the answer itself. Think as long as you need, and size code, "
56900
56941
  "diffs and file contents to the task."
@@ -56902,7 +56943,7 @@ def run_verbosity_steer(transcript_path=None, quiet=True, session_id=None):
56902
56943
  elif (fill_pct >= _VERBOSITY_NUDGE_MIN_FILL
56903
56944
  and session_efficiency < _VERBOSITY_NUDGE_EFFICIENCY_THRESHOLD):
56904
56945
  nudge = (
56905
- f"[Token Optimizer] Context {fill_pct:.0f}%{window_note}, "
56946
+ f"[Token Optimizer] Context {_format_context_fill(fill_pct, cached)}, "
56906
56947
  f"session efficiency {session_efficiency:.0f}/100. "
56907
56948
  "Answer in a focused and spartan way, as if the user has ADHD. "
56908
56949
  "Think as long as you need, and size code, diffs and file contents to the task."
@@ -59324,7 +59365,7 @@ if __name__ == "__main__":
59324
59365
  quiet = "--quiet" in args or "-q" in args
59325
59366
  archive_result(quiet=quiet)
59326
59367
  elif args[0] == "session-cost":
59327
- # "What did the Navina session yesterday cost?" Read-only; see session_cost_main.
59368
+ # "What did the Garden session yesterday cost?" Read-only; see session_cost_main.
59328
59369
  sys.exit(session_cost_main(args[1:]))
59329
59370
  elif args[0] == "expand":
59330
59371
  # Retrieve archived tool result
@@ -59507,7 +59548,7 @@ if __name__ == "__main__":
59507
59548
  print(" python3 measure.py attention-optimize --apply # Apply reordering (backup + write)")
59508
59549
  print(" python3 measure.py archive-result # PostToolUse hook: archive large tool results")
59509
59550
  print(" python3 measure.py archive-result --quiet # Silent mode (suppress stderr)")
59510
- print(" python3 measure.py session-cost navina --date yesterday # What a session cost, in your words (read-only)")
59551
+ print(" python3 measure.py session-cost garden --date yesterday # What a session cost, in your words (read-only)")
59511
59552
  print(" python3 measure.py session-cost --id UUID --json # One session by id, machine-readable")
59512
59553
  print(" python3 measure.py expand TOOL_USE_ID # Retrieve archived tool result")
59513
59554
  print(" python3 measure.py expand TOOL_USE_ID --session SID # Retrieve from specific session")