sessioncost 1.2.1__tar.gz → 1.2.3__tar.gz

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 (93) hide show
  1. {sessioncost-1.2.1/sessioncost.egg-info → sessioncost-1.2.3}/PKG-INFO +4 -1
  2. {sessioncost-1.2.1 → sessioncost-1.2.3}/README.md +3 -0
  3. {sessioncost-1.2.1 → sessioncost-1.2.3}/pyproject.toml +1 -1
  4. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/__init__.py +1 -1
  5. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/cli.py +10 -3
  6. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixer.py +56 -33
  7. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixer_store.py +41 -7
  8. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/guard.py +119 -159
  9. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/guard_agents.py +36 -0
  10. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/guard_auto.py +15 -0
  11. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/guard_checks.py +109 -51
  12. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/guard_decide.py +68 -26
  13. sessioncost-1.2.3/sessioncost/guard_fresh.py +177 -0
  14. sessioncost-1.2.3/sessioncost/guard_owasp.py +225 -0
  15. sessioncost-1.2.3/sessioncost/guard_post.py +153 -0
  16. sessioncost-1.2.3/sessioncost/guard_quiet.py +159 -0
  17. sessioncost-1.2.3/sessioncost/guard_scan.py +106 -0
  18. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/guard_setup.py +10 -4
  19. sessioncost-1.2.3/sessioncost/guard_waste.py +81 -0
  20. sessioncost-1.2.3/sessioncost/help_menu.py +52 -0
  21. sessioncost-1.2.3/sessioncost/opener.py +48 -0
  22. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/report_board.html +1 -1
  23. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/risk_patterns.py +26 -6
  24. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/risk_shell.py +69 -2
  25. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/risks.py +26 -16
  26. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/sarif.py +6 -0
  27. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/skill/SKILL.md +16 -3
  28. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/skill/liveguard.md +1 -1
  29. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/textflags.py +29 -6
  30. {sessioncost-1.2.1 → sessioncost-1.2.3/sessioncost.egg-info}/PKG-INFO +4 -1
  31. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost.egg-info/SOURCES.txt +8 -0
  32. {sessioncost-1.2.1 → sessioncost-1.2.3}/LICENSE +0 -0
  33. {sessioncost-1.2.1 → sessioncost-1.2.3}/MANIFEST.in +0 -0
  34. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/__main__.py +0 -0
  35. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/analyse.py +0 -0
  36. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/analyse_calls.py +0 -0
  37. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/analyse_lists.py +0 -0
  38. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/cli_setup.py +0 -0
  39. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/editor.py +0 -0
  40. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixer_plan.py +0 -0
  41. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/__init__.py +0 -0
  42. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/big_results.py +0 -0
  43. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/cache_break.py +0 -0
  44. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/common.py +0 -0
  45. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/confirm_turns.py +0 -0
  46. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/error_loop.py +0 -0
  47. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/helper_polling.py +0 -0
  48. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/helper_rereads.py +0 -0
  49. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/images.py +0 -0
  50. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/long_chat.py +0 -0
  51. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/long_output.py +0 -0
  52. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/model_choice.py +0 -0
  53. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/overlap.py +0 -0
  54. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/repeated_reads.py +0 -0
  55. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/repeated_writes.py +0 -0
  56. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/reruns.py +0 -0
  57. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/stale_context.py +0 -0
  58. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/startup_bloat.py +0 -0
  59. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/unused_builtins.py +0 -0
  60. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/fixes/unused_tools.py +0 -0
  61. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/guard_inventory.py +0 -0
  62. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/guard_report.py +0 -0
  63. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/guard_store.py +0 -0
  64. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/locate.py +0 -0
  65. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/model.py +0 -0
  66. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/names.py +0 -0
  67. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/practices.py +0 -0
  68. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/prices.json +0 -0
  69. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/prices.py +0 -0
  70. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/prices_cmd.py +0 -0
  71. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/readers/__init__.py +0 -0
  72. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/readers/_pb.py +0 -0
  73. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/readers/_util.py +0 -0
  74. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/readers/antigravity.py +0 -0
  75. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/readers/claude.py +0 -0
  76. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/readers/claude_text.py +0 -0
  77. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/readers/codex.py +0 -0
  78. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/readers/copilot.py +0 -0
  79. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/readers/cursor.py +0 -0
  80. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/readers/cursor_steps.py +0 -0
  81. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/readers/cursor_usage.py +0 -0
  82. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/readers/vscode_chat.py +0 -0
  83. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/report.py +0 -0
  84. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/risk_bypass.py +0 -0
  85. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/rules.py +0 -0
  86. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/serve.py +0 -0
  87. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/status.py +0 -0
  88. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/update.py +0 -0
  89. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost/zfile.py +0 -0
  90. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost.egg-info/dependency_links.txt +0 -0
  91. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost.egg-info/entry_points.txt +0 -0
  92. {sessioncost-1.2.1 → sessioncost-1.2.3}/sessioncost.egg-info/top_level.txt +0 -0
  93. {sessioncost-1.2.1 → sessioncost-1.2.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sessioncost
3
- Version: 1.2.1
3
+ Version: 1.2.3
4
4
  Summary: See how many tokens each turn of your coding-agent chat sends, why, and what to cut. Cost goes down with it.
5
5
  Author: kish21
6
6
  License-Expression: MIT
@@ -91,6 +91,9 @@ Terminal commands, report options and the guard's settings:
91
91
 
92
92
  - Reads your agent's log on your computer. No AI model is called.
93
93
  - Nothing is sent anywhere: the report is one file on your computer.
94
+ - One exception, in the guard: when the agent installs a package, the guard sends that package's name to its registry
95
+ (pypi.org or registry.npmjs.org) to check how new that version is. Nothing else. To stop it:
96
+ `sessioncost guard fresh-releases off`.
94
97
 
95
98
  More: **[Privacy and security](https://kish21.github.io/sessioncost-help/reference/privacy/)**.
96
99
 
@@ -76,6 +76,9 @@ Terminal commands, report options and the guard's settings:
76
76
 
77
77
  - Reads your agent's log on your computer. No AI model is called.
78
78
  - Nothing is sent anywhere: the report is one file on your computer.
79
+ - One exception, in the guard: when the agent installs a package, the guard sends that package's name to its registry
80
+ (pypi.org or registry.npmjs.org) to check how new that version is. Nothing else. To stop it:
81
+ `sessioncost guard fresh-releases off`.
79
82
 
80
83
  More: **[Privacy and security](https://kish21.github.io/sessioncost-help/reference/privacy/)**.
81
84
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sessioncost"
7
- version = "1.2.1"
7
+ version = "1.2.3"
8
8
  description = "See how many tokens each turn of your coding-agent chat sends, why, and what to cut. Cost goes down with it."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -1,2 +1,2 @@
1
1
  """SessionCost: see where every token of your agent session went, turn by turn, and what to fix."""
2
- __version__ = "1.2.1"
2
+ __version__ = "1.2.3"
@@ -5,7 +5,6 @@ import argparse
5
5
  import json
6
6
  import os
7
7
  import sys
8
- import webbrowser
9
8
  from pathlib import Path
10
9
 
11
10
  from . import __version__, locate, prices as pricemod, readers, report, zfile
@@ -281,7 +280,7 @@ def cmd_fix(argv: list[str]) -> int:
281
280
  if argv[:1] == ["long-chat"]: # when a chat counts as long: the handover offer
282
281
  if len(argv) < 2:
283
282
  print(f"SessionCost fix: a chat over {fixer._tok(fixer.long_chat())} tokens gets the handover offer. "
284
- 'To change it, say "warn me at 150k tokens" (or type `sessioncost fix long-chat 150k`).')
283
+ 'To change it, say "warn me at 1m tokens" (or type `sessioncost fix long-chat 1m`).')
285
284
  return 0
286
285
  code, msg = fixer.set_long_chat(argv[1])
287
286
  print(msg)
@@ -396,6 +395,9 @@ def main(argv: list[str] | None = None) -> int:
396
395
  return 0
397
396
  if argv[:1] == ["fix"]: # `sessioncost fix ...`: its own options (see cmd_fix)
398
397
  return cmd_fix(argv[1:])
398
+ if argv[:1] == ["help"]: # what you can say in the chat, and the guide's address (help_menu.py)
399
+ from . import help_menu
400
+ return help_menu.main(argv[1:])
399
401
  if argv[:1] == ["editor"]: # the editor extension's status bar: one short JSON answer (editor.py)
400
402
  from . import editor
401
403
  return editor.main(argv[1:])
@@ -446,6 +448,10 @@ def main(argv: list[str] | None = None) -> int:
446
448
  except (readers.NotSupported, ValueError) as e:
447
449
  print(f"sessioncost: {e}")
448
450
  return 2
451
+ except PermissionError as e: # an agent's sandbox (Codex) refused the write: one line, no retries (2026-11-18)
452
+ print(f"sessioncost: could not write to {REPORTS.parent} ({e.strerror or e}). If your agent runs commands in "
453
+ "a sandbox (Codex does), allow it to write to that folder and run this again.", flush=True)
454
+ return 3
449
455
  if args.live: # after an answer, in the background: the to-do list for the next reply
450
456
  from . import fixer
451
457
  if fixer.auto_on():
@@ -466,7 +472,8 @@ def main(argv: list[str] | None = None) -> int:
466
472
  if gone:
467
473
  print(f"Old reports: deleted {gone} ({size(freed)}); the newest {KEEP_REPORTS} are kept.")
468
474
  if out and not args.no_open:
469
- webbrowser.open(out.resolve().as_uri())
475
+ from .opener import open_report # returns at once: the agent is not kept waiting on the browser
476
+ open_report(out)
470
477
  return 0
471
478
 
472
479
 
@@ -23,13 +23,17 @@ from pathlib import Path
23
23
 
24
24
  from . import practices
25
25
  from .fixer_plan import Plan, plan
26
- from .fixer_store import (ASKED_FIX, BIG_TIP_TOKENS, CHAT_KEEP_S, HANDOVER_ASK, HEAD, KEEP_SEEN, MIN_TIP_TOKENS,
26
+ from .fixer_store import (ASKED_FIX, BIG_TIP_TOKENS, CHAT_KEEP_S, HANDOVER_END, HANDOVER_NAME, HEAD, KEEP_SEEN, MIN_TIP_TOKENS,
27
27
  NOTE_MAX_AGE_S, OFFER_QUIET_S, RULE_OF, SAY_FIX, SAY_HANDOVER, SETTINGS, _load, _norm, _now, _save, _sha, _size, _tok, _ts, _usd,
28
- auto_on, backups_dir, base, chat_file, find_handover, fixes_file, handover_file, known,
29
- live_file, offered_file, project_key, project_path, start_folder)
28
+ asks_handover, auto_on, backups_dir, base, chat_file, find_handover, fixes_file, handover_file, known,
29
+ live_file, newest_lines, offered_file, project_key, project_path, start_folder)
30
30
  # Names other modules and tests use as fixer.<name>; they live in fixer_store.py and fixer_plan.py.
31
31
  from .fixer_plan import for_report, render # noqa: F401
32
- from .fixer_store import LONG_CHAT, auto_text, budget_text, budget_usd, learn, learned, long_chat, set_auto, set_budget, set_long_chat # noqa: F401
32
+ from .fixer_store import HANDOVER_AT, LONG_CHAT, auto_text, handover_hint_once, budget_text, budget_usd, learn, learned, long_chat, set_auto, set_budget, set_long_chat # noqa: F401
33
+
34
+ # a user may keep their own notes in the handover file: the newest handover goes first, nothing is lost (owner, 2026-11-17)
35
+ ON_TOP = ("keep everything already in the file below it, and end the new handover with this line, as written, so a "
36
+ f"new chat reads only the newest one: {HANDOVER_END}")
33
37
 
34
38
 
35
39
  def apply(p: Plan) -> tuple[int, str]:
@@ -98,7 +102,8 @@ def apply(p: Plan) -> tuple[int, str]:
98
102
  + "\n".join(" " + x for x in i.steps.splitlines()))
99
103
  if any(i.kind == "handover" for i in p.items):
100
104
  h = handover_file(p.project)
101
- out.append(f"Handover: write it now in {h.as_posix()} (replace what is there): the goal, what is done, files "
105
+ out.append(f"Handover: write it now at the top of {h.as_posix()} under a heading with today's date (a new "
106
+ f"file if there is none; {ON_TOP}): the goal, what is done, files "
102
107
  "changed, tests run, what is next. Show it in your reply, then tell the user to start a new chat "
103
108
  "and say \"continue from handover\" there.")
104
109
  out.append("In the same handover, add a short section \"Other token waste in this chat\": what cost tokens in "
@@ -298,7 +303,7 @@ def _quiet(note: dict, chat: str, cwd: str, st: dict) -> list[dict]:
298
303
  return out
299
304
 
300
305
 
301
- def _one_line(items: list[dict], same: bool) -> str:
306
+ def _one_line(items: list[dict], same: bool, hint: str = "") -> str:
302
307
  waste = [i for i in items if i.get("id") != "long-chat" and i.get("kind") != "learned"]
303
308
  learnt = [i for i in items if i.get("kind") == "learned"]
304
309
  long = next((i for i in items if i.get("id") == "long-chat"), None)
@@ -315,13 +320,14 @@ def _one_line(items: list[dict], same: bool) -> str:
315
320
  # its own words, never "Shall I ...?": the agent may have asked its own question higher up the reply, and a bare
316
321
  # "yes" would answer either (owner, 2026-11-11). The command is named too, for those who prefer to type it.
317
322
  typed = "(or type /sessioncost fix)"
318
- line = f"💡 SessionCost: {'. Also '.join(parts)}." if parts else ""
323
+ line = f'💡 SessionCost: {". Also ".join(parts)}. Say "{SAY_FIX}" {typed} to fix these.' if parts else ""
319
324
  if not long:
320
- return f'{line} Say "{SAY_FIX}" {typed} to fix these.' if line else ""
321
- line = (line + " " if line else "💡 SessionCost: ") + long.get("line", "")
322
- if parts:
323
- return f'{line} Say "{SAY_FIX}" {typed} to fix these and write a handover, so you can start a fresh chat.'
324
- return f'{line} Say "{SAY_HANDOVER}" {typed} so you can start a fresh chat.'
325
+ return line
326
+ # the agent writes the handover in the same reply, unasked (owner, 2026-11-17): the line says where it goes. It
327
+ # says what the agent does, not that the file is there: a blocked write made "is in" untrue (a Codex chat, 2026-11-18)
328
+ return ((line + " " if line else "💡 SessionCost: ") + long.get("line", "") + hint
329
+ + f' Your agent writes a handover to {HANDOVER_NAME}: once it is there, start a fresh chat and say '
330
+ '"continue from handover".')
325
331
 
326
332
 
327
333
  def _same_agent(hook_agent: str, note_agent: str) -> bool:
@@ -347,9 +353,12 @@ def tip(chat: str, cwd: str, prompt: str = "", start: bool = False, turn: str |
347
353
  "(keep only the ids they chose) and show the lines it prints. Otherwise ignore this.")
348
354
  st["pending"] = ""
349
355
  h = find_handover(cwd) if cwd else None
350
- if h and prompt and HANDOVER_ASK.search(prompt):
351
- out.append(f"The user wants to continue from the handover of an earlier chat: read "
352
- f"{h.as_posix()} first, then carry on from its \"what is next\".")
356
+ if h and prompt and asks_handover(prompt):
357
+ n = newest_lines(h) # the newest handover only: older ones below it would cost tokens for nothing
358
+ what = (f"read only lines 1-{n} of {h.as_posix()} (the newest handover; do not read the older notes below "
359
+ "it unless the user asks)" if n else f"read {h.as_posix()} first")
360
+ out.append(f"The user wants to continue from the handover of an earlier chat: {what}, then carry on from its "
361
+ "\"what is next\".")
353
362
  elif h and start and time.time() - h.stat().st_mtime < CHAT_KEEP_S:
354
363
  out.append(f"A handover from an earlier chat in this project is at {h.as_posix()}. Read it "
355
364
  "only if the user asks to continue from it.")
@@ -365,32 +374,46 @@ def tip(chat: str, cwd: str, prompt: str = "", start: bool = False, turn: str |
365
374
  _seen(st, [i["id"] for i in items], note.get("context"))
366
375
  items, dirty = [], True
367
376
  if items:
368
- ids = ",".join(i["id"] for i in items)
369
377
  where = _q(Path(cwd).as_posix())
370
378
  of = f"{_q(str(note['chat']))} " if note.get("chat") else "" # the chat the list came from
371
- cmd = f"{run_cmd()} fix -y {of}--only {ids} --project {where}"
372
- look = f"{run_cmd()} fix --preview {of}--only {ids} --project {where}"
379
+ long = any(i["id"] == "long-chat" for i in items)
380
+ one = _one_line(items, note.get("chat") == chat, handover_hint_once() if long else "")
381
+ ids =",".join(i["id"] for i in items if i["id"] != "long-chat")
382
+ cmd = f"{run_cmd()} fix -y {of}--only {ids} --project {where}" if ids else ""
373
383
  # chat-start text stays in the agent's context for the whole chat (Copilot, Cursor): said once, or the
374
384
  # agent ends every reply with it, even after the fix ran (owner, 2026-11-12)
375
385
  when = ("put this one line only at the end of your first reply in this chat and never repeat it in a "
376
386
  "later reply (also not after the fix ran or the user said no); in that first reply put it "
377
387
  if start else "end your reply with this one line, ")
378
- out.append(
379
- "SessionCost (fix auto is on) found token waste. Answer the user's message as usual first; when "
380
- f"all your work for it is done, {when}as written, as a quote block "
381
- "(begin it with \"> \"), as the very last thing in the reply, so the user sees it where the chat "
382
- f"stops:\n{_one_line(items, note.get('chat') == chat)}\n"
383
- "Put nothing after that line. Do not end that reply with a question of your own: the user answers this one first. "
384
- f"If the user asks what these are, run `{look}` and show what it prints. Only if the user says "
385
- f"\"{SAY_FIX}\" or \"{SAY_HANDOVER}\" (or \"fix these\", \"fix all\", \"fix the first one\": all, "
386
- f"or some), run `{cmd}` "
387
- "(keep only the ids they chose) and show the lines it prints. A bare \"yes\" answers your own "
388
- "question, not this line: do not run it then. If "
389
- "it asks you to write a handover, do it. If running it is blocked or refused (auto mode, for "
390
- "example), do not try another way: tell the user to type /sessioncost fix and answer yes there. "
391
- "If they say no, or say nothing about it, drop it. Never run it without their yes.")
388
+ say = [f"SessionCost (fix auto is on) found token waste. Answer the user's message as usual first; when "
389
+ f"all your work for it is done, {when}as written, as a quote block "
390
+ "(begin it with \"> \"), as the very last thing in the reply, so the user sees it where the chat "
391
+ f"stops:\n{one}\n"
392
+ "Put nothing after that line."]
393
+ if long: # a long chat: the handover is written at once, no yes needed (owner, 2026-11-17)
394
+ say.append(f"This chat is long, so write a handover now, without waiting for the user's yes: "
395
+ "after your work for the user's message and before that last line, run "
396
+ f"`{run_cmd()} fix -y {of}--only long-chat --project {where}` and do what it prints. "
397
+ "If running it is blocked or refused, write the handover yourself at the top of "
398
+ f"{handover_file(cwd).as_posix()} ({ON_TOP}): the goal, what is done, files "
399
+ "changed, tests run, what is next. Write it with your own file-edit tool, not a script "
400
+ "(a script that writes files can be blocked). If the handover could not be written at "
401
+ "all, end that last line with \"The handover could not be written: \" and the reason in "
402
+ "a few words, instead of its sentence about the handover.")
403
+ if cmd:
404
+ look = f"{run_cmd()} fix --preview {of}--only {ids} --project {where}"
405
+ say.append(
406
+ "Do not end that reply with a question of your own: the user answers this one first. "
407
+ f"If the user asks what these are, run `{look}` and show what it prints. Only if the user says "
408
+ f"\"{SAY_FIX}\" (or \"fix these\", \"fix all\", \"fix the first one\": all, or some), run "
409
+ f"`{cmd}` (keep only the ids they chose) and show the lines it prints. A bare \"yes\" answers "
410
+ "your own question, not this line: do not run it then. If running it is blocked or refused "
411
+ "(auto mode, for example), do not try another way: tell the user to type /sessioncost fix and "
412
+ "answer yes there. If they say no, or say nothing about it, drop it. Never run it without "
413
+ "their yes.")
414
+ out.append(" ".join(say))
392
415
  _seen(st, [i["id"] for i in items], note.get("context"))
393
- st["last_tip"] = {"at": time.time(), "line": _one_line(items, note.get("chat") == chat)} # status.py
416
+ st["last_tip"] = {"at": time.time(), "line": one} # status.py
394
417
  st["lists"] = int(st.get("lists") or 0) + 1
395
418
  st["pending"] = cmd if turn is not None else ""
396
419
  dirty = True
@@ -15,7 +15,8 @@ from . import rules
15
15
 
16
16
 
17
17
 
18
- LONG_CHAT = fixmod.LONG_CHAT # one number for "this chat is long": the long-chat fix's
18
+ LONG_CHAT = fixmod.LONG_CHAT # the report's long-chat check (a long chat carried on after a break)
19
+ HANDOVER_AT = 200_000 # the handover offer, unless the user set their own (owner 2026-11-20: 100k came too soon)
19
20
  HEAD = "## SessionCost rules (fewer tokens)"
20
21
  SETTINGS = Path(".claude") / "settings.local.json" # Claude Code's personal project settings: never committed
21
22
  BUILTIN_SETTING = {"Artifact": ("enableArtifact", False), "Workflow": ("disableWorkflows", True)}
@@ -45,6 +46,13 @@ ASKED_FIX = re.compile(r"^\s*[/$](?:sessioncost:)?sessioncost\b|\bsessioncost fi
45
46
  SAY_FIX = "fix it" # what the user says to the live tip: its own words, not a bare "yes" (owner, 2026-11-11)
46
47
  SAY_HANDOVER = "write a handover" # ... to the long-chat tip
47
48
  HANDOVER_ASK = re.compile(r"\b(?:continue|carry on|resume|pick up)\b.{0,40}\bhand-?over\b", re.I | re.S)
49
+ # words just before the ask that make it a mention, not a request: 'instead of saying continue from handover'
50
+ _MENTION = re.compile(r"(?:\bsay(?:s|ing)?|\bsaid|\btypes?|\btyping|\bwords?|[\"'“‘`])\s*$", re.I)
51
+
52
+
53
+ def asks_handover(prompt: str) -> bool:
54
+ """The user asks to continue from the handover (and does not only talk about those words)."""
55
+ return any(not _MENTION.search(prompt[:m.start()]) for m in HANDOVER_ASK.finditer(prompt or ""))
48
56
 
49
57
 
50
58
  # ---- where things are kept ----
@@ -86,6 +94,20 @@ def backups_dir(project) -> Path:
86
94
 
87
95
 
88
96
  HANDOVER_NAME = "NEXT-SESSION.md" # in the project, where the user can find it (owner, 2026-11-12)
97
+ # the last line of each handover: "continue from handover" reads up to the first one only (owner, 2026-11-18)
98
+ HANDOVER_END = "<!-- End of the newest handover. Older notes below: do not read further unless asked. -->"
99
+
100
+
101
+ def newest_lines(f: Path) -> int:
102
+ """How many lines the newest handover takes (up to and with the first end line); 0 when the file has none."""
103
+ try:
104
+ with f.open(encoding="utf-8", errors="replace") as fh:
105
+ for n, line in enumerate(fh, 1):
106
+ if line.strip() == HANDOVER_END:
107
+ return n
108
+ except OSError:
109
+ pass
110
+ return 0
89
111
 
90
112
 
91
113
  def handover_file(project) -> Path:
@@ -211,16 +233,28 @@ def set_auto(on: bool) -> str:
211
233
  return ("SessionCost fix auto: on for every chat, every day. After each answer SessionCost looks for new token "
212
234
  "waste; your agent names it in the last line of its next reply and changes nothing until you say "
213
235
  f'"{SAY_FIX}". A chat over {_tok(long_chat())} tokens gets a handover offer: to change that, say "warn '
214
- 'me at 150k tokens" (or type `sessioncost fix long-chat 150k`). To stop the tips, say "turn token tips '
236
+ 'me at 1m tokens" (or type `sessioncost fix long-chat 1m`). To stop the tips, say "turn token tips '
215
237
  'off" (or type `sessioncost fix auto off`).')
216
238
  return ('SessionCost fix auto: off. To start the tips again, say "turn token tips on" (or type `sessioncost fix '
217
239
  'auto on`). Say "fix my token waste" (or type `sessioncost fix`) for the to-do list whenever you want.')
218
240
 
219
241
 
220
242
  def long_chat() -> int:
221
- """The developer's own "this chat is long" (`sessioncost fix long-chat 150k`), else LONG_CHAT."""
243
+ """When a chat gets the handover offer: the developer's own number (`sessioncost fix long-chat 1m`), else HANDOVER_AT."""
222
244
  v = _load(_config(), {}).get("long_chat")
223
- return int(v) if isinstance(v, int) and not isinstance(v, bool) and v >= 10_000 else LONG_CHAT
245
+ return int(v) if isinstance(v, int) and not isinstance(v, bool) and v >= 10_000 else HANDOVER_AT
246
+
247
+
248
+ def handover_hint_once() -> str:
249
+ """The first handover offer on this computer says the number can change: without the help site nobody would know.
250
+ Said once, never again; not said at all to someone who already set their own number (owner 2026-11-20)."""
251
+ cfg = _config()
252
+ have = _load(cfg, {})
253
+ if "long_chat" in have or have.get("long_chat_hint"):
254
+ return ""
255
+ _save(cfg, {**have, "long_chat_hint": True})
256
+ return (f' (The handover comes at {_tok(HANDOVER_AT)} tokens; to change that, say "warn me at 1m tokens" with your '
257
+ "own number.)")
224
258
 
225
259
 
226
260
  def parse_tokens(text: str) -> int | None:
@@ -237,9 +271,9 @@ def set_long_chat(text: str) -> tuple[int, str]:
237
271
  return 2, "sessioncost fix long-chat: give the tokens, 10k or more (for example 150k, or 1m)."
238
272
  cfg = _config()
239
273
  _save(cfg, {**_load(cfg, {}), "long_chat": n})
240
- return 0, (f"SessionCost fix: a chat over {_tok(n)} tokens now gets the handover offer (it was {_tok(LONG_CHAT)} by "
241
- 'default). To change it, say "warn me at 150k tokens" with your own number (or type `sessioncost fix '
242
- "long-chat 150k`).")
274
+ return 0, (f"SessionCost fix: a chat over {_tok(n)} tokens now gets the handover offer (it was {_tok(HANDOVER_AT)} by "
275
+ 'default). To change it, say "warn me at 1m tokens" with your own number (or type `sessioncost fix '
276
+ "long-chat 1m`).")
243
277
 
244
278
 
245
279
  def budget_usd() -> float | None: