sessioncost 1.2.4__tar.gz → 1.2.5__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.
- {sessioncost-1.2.4/sessioncost.egg-info → sessioncost-1.2.5}/PKG-INFO +1 -1
- {sessioncost-1.2.4 → sessioncost-1.2.5}/pyproject.toml +1 -1
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/__init__.py +1 -1
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/readers/cursor.py +9 -2
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/skill/SKILL.md +8 -2
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/zfile.py +79 -68
- {sessioncost-1.2.4 → sessioncost-1.2.5/sessioncost.egg-info}/PKG-INFO +1 -1
- {sessioncost-1.2.4 → sessioncost-1.2.5}/LICENSE +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/MANIFEST.in +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/README.md +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/__main__.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/analyse.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/analyse_calls.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/analyse_lists.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/cli.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/cli_setup.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/editor.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixer.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixer_plan.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixer_store.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/__init__.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/big_results.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/cache_break.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/common.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/confirm_turns.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/error_loop.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/helper_polling.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/helper_rereads.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/images.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/long_chat.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/long_output.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/model_choice.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/overlap.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/repeated_reads.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/repeated_writes.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/reruns.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/stale_context.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/startup_bloat.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/unused_builtins.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fixes/unused_tools.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/fresh_chat.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/guard.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/guard_agents.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/guard_auto.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/guard_checks.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/guard_decide.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/guard_fresh.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/guard_inventory.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/guard_owasp.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/guard_post.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/guard_quiet.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/guard_report.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/guard_scan.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/guard_setup.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/guard_store.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/guard_waste.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/help_menu.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/locate.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/model.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/names.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/opener.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/practices.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/prices.json +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/prices.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/prices_cmd.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/readers/__init__.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/readers/_pb.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/readers/_util.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/readers/antigravity.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/readers/claude.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/readers/claude_text.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/readers/codex.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/readers/copilot.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/readers/cursor_steps.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/readers/cursor_usage.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/readers/vscode_chat.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/report.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/report_board.html +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/risk_bypass.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/risk_patterns.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/risk_shell.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/risks.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/rules.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/sarif.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/serve.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/skill/liveguard.md +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/status.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/textflags.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/uninstall.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/unsafe_code.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost/update.py +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost.egg-info/SOURCES.txt +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost.egg-info/dependency_links.txt +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost.egg-info/entry_points.txt +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/sessioncost.egg-info/top_level.txt +0 -0
- {sessioncost-1.2.4 → sessioncost-1.2.5}/setup.cfg +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "sessioncost"
|
|
7
|
-
version = "1.2.
|
|
7
|
+
version = "1.2.5"
|
|
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.
|
|
2
|
+
__version__ = "1.2.5"
|
|
@@ -83,9 +83,16 @@ def _value(con: sqlite3.Connection, key: str) -> dict:
|
|
|
83
83
|
return v if isinstance(v, dict) else {}
|
|
84
84
|
|
|
85
85
|
|
|
86
|
+
def with_prefix(con: sqlite3.Connection, prefix: str, cols: str = "value"):
|
|
87
|
+
"""Rows whose key starts with `prefix`, through the key's index. `key like 'x%'` reads the whole store instead
|
|
88
|
+
(Cursor's is often hundreds of MB): seconds on a cold disk."""
|
|
89
|
+
end = prefix[:-1] + chr(ord(prefix[-1]) + 1)
|
|
90
|
+
return con.execute(f"select {cols} from cursorDiskKV where key >= ? and key < ?", (prefix, end))
|
|
91
|
+
|
|
92
|
+
|
|
86
93
|
def chats(con: sqlite3.Connection) -> list[dict]:
|
|
87
94
|
out = []
|
|
88
|
-
for (v,) in con
|
|
95
|
+
for (v,) in with_prefix(con, "composerData:"):
|
|
89
96
|
try:
|
|
90
97
|
d = json.loads(v) if v else None
|
|
91
98
|
except ValueError:
|
|
@@ -342,7 +349,7 @@ class CursorReader:
|
|
|
342
349
|
s = Session(agent=self.name, session_id=cid, source=f"{state_db()}#{cid}", cwd=workspace(d),
|
|
343
350
|
title=str(d.get("name") or ""), tokens_exact=False)
|
|
344
351
|
bubbles = {}
|
|
345
|
-
for k, v in con
|
|
352
|
+
for k, v in with_prefix(con, f"bubbleId:{cid}:", "key, value"):
|
|
346
353
|
try:
|
|
347
354
|
bubbles[k.removeprefix(f"bubbleId:{cid}:")] = json.loads(v) # ids can hold ':' (".../s:0", ".../t:call-...")
|
|
348
355
|
except (ValueError, TypeError):
|
|
@@ -21,8 +21,14 @@ Codex, Antigravity or Cursor) and writes an HTML report. It uses no AI model and
|
|
|
21
21
|
SessionCost is not installed and to install it from https://github.com/kish21/sessioncost#install, then stop. Do
|
|
22
22
|
not run an installer yourself.
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
Every SessionCost command writes to `~/.sessioncost` in the user's home folder. If your commands run in a sandbox
|
|
25
|
+
that cannot write there (Codex does), ask for permission to run outside it on the FIRST try of each command: a
|
|
26
|
+
try inside the sandbox only fails.
|
|
27
|
+
|
|
28
|
+
Run each command once. It finishes in seconds but can take up to a minute: if it is still running, wait for it and
|
|
29
|
+
read its output; never start it again, and never run it a second time to check. If it says it could not write to
|
|
30
|
+
its folder (`~/.sessioncost`), your sandbox stopped it: ask the user once for permission to write there and run
|
|
31
|
+
the same command again with it. Do not try other ways or other folders.
|
|
26
32
|
|
|
27
33
|
2. It prints a short "What SessionCost is doing:" block, then `Report: <path>`. Reply with only: that block exactly as
|
|
28
34
|
printed, in a code block; then "The full report: <path>" (the path as a clickable link, on its own
|
|
@@ -1,68 +1,79 @@
|
|
|
1
|
-
"""Open a log that may be zstd-compressed (Codex packs older threads as rollout-*.jsonl.zst).
|
|
2
|
-
|
|
3
|
-
No hard dependency: Python 3.14+ has `compression.zstd` built in; on older Python the optional `zstandard` package
|
|
4
|
-
(BSD-3-Clause) is used when installed. Without either, compressed files are skipped and `zstd_note` says so.
|
|
5
|
-
"""
|
|
6
|
-
from __future__ import annotations
|
|
7
|
-
|
|
8
|
-
import functools
|
|
9
|
-
import io
|
|
10
|
-
import sys
|
|
11
|
-
from pathlib import Path
|
|
12
|
-
from typing import IO
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
@functools.lru_cache(maxsize=1) # a failed import is slow; looked up once per run
|
|
16
|
-
def _module():
|
|
17
|
-
try:
|
|
18
|
-
from compression import zstd # Python 3.14+
|
|
19
|
-
return zstd
|
|
20
|
-
except ImportError:
|
|
21
|
-
pass
|
|
22
|
-
try:
|
|
23
|
-
import zstandard # optional: pip install zstandard
|
|
24
|
-
return zstandard
|
|
25
|
-
except ImportError:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return
|
|
68
|
-
|
|
1
|
+
"""Open a log that may be zstd-compressed (Codex packs older threads as rollout-*.jsonl.zst).
|
|
2
|
+
|
|
3
|
+
No hard dependency: Python 3.14+ has `compression.zstd` built in; on older Python the optional `zstandard` package
|
|
4
|
+
(BSD-3-Clause) is used when installed. Without either, compressed files are skipped and `zstd_note` says so.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import functools
|
|
9
|
+
import io
|
|
10
|
+
import sys
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import IO
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@functools.lru_cache(maxsize=1) # a failed import is slow; looked up once per run
|
|
16
|
+
def _module():
|
|
17
|
+
try:
|
|
18
|
+
from compression import zstd # Python 3.14+
|
|
19
|
+
return zstd
|
|
20
|
+
except ImportError:
|
|
21
|
+
pass
|
|
22
|
+
try:
|
|
23
|
+
import zstandard # optional: pip install zstandard
|
|
24
|
+
return zstandard
|
|
25
|
+
except ImportError:
|
|
26
|
+
pass
|
|
27
|
+
if sys.flags.no_site: # the plugin's starter runs Python with -S (fast start): add the package folders
|
|
28
|
+
import site # only, never site.main(): that runs the slow start-up add-ons after all
|
|
29
|
+
for d in [site.getusersitepackages(), *site.getsitepackages()]:
|
|
30
|
+
if d not in sys.path:
|
|
31
|
+
sys.path.append(d)
|
|
32
|
+
try:
|
|
33
|
+
import zstandard
|
|
34
|
+
return zstandard
|
|
35
|
+
except ImportError:
|
|
36
|
+
pass
|
|
37
|
+
return None
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def can_unpack() -> bool:
|
|
41
|
+
return _module() is not None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def is_zst(path: Path) -> bool:
|
|
45
|
+
return path.suffix == ".zst"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def open_text(path: Path) -> IO[str]:
|
|
49
|
+
"""The file as text, unpacked if it ends in .zst. Raises OSError when it cannot be unpacked."""
|
|
50
|
+
if not is_zst(path):
|
|
51
|
+
return path.open(encoding="utf-8", errors="replace")
|
|
52
|
+
m = _module()
|
|
53
|
+
if m is None:
|
|
54
|
+
raise OSError(f"{path.name} is compressed: {zstd_hint()}")
|
|
55
|
+
try:
|
|
56
|
+
if m.__name__ == "compression.zstd":
|
|
57
|
+
stream = m.open(path, "rb")
|
|
58
|
+
else:
|
|
59
|
+
stream = m.ZstdDecompressor().stream_reader(path.open("rb"), closefd=True, read_across_frames=True)
|
|
60
|
+
except Exception as e: # a broken file must not stop the others
|
|
61
|
+
raise OSError(f"{path.name}: {e}") from e
|
|
62
|
+
return io.TextIOWrapper(stream, encoding="utf-8", errors="replace")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def zstd_hint() -> str:
|
|
66
|
+
# the Python that runs SessionCost (installer and npm keep a private one): a bare "pip" may be another Python
|
|
67
|
+
return f'to read them, run "{sys.executable}" -m pip install zstandard (free), or use Python 3.14 or newer'
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def codex_note(before: str = "", after: str = "") -> str:
|
|
71
|
+
"""The `zstd_note` for this machine's Codex folder, wrapped in `before`/`after`; "" when nothing is left out."""
|
|
72
|
+
from .locate import codex_unreadable
|
|
73
|
+
note = zstd_note(codex_unreadable())
|
|
74
|
+
return f"{before}{note}{after}" if note else ""
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def zstd_note(skipped: int) -> str:
|
|
78
|
+
return (f"{skipped} older Codex chat{'s are' if skipped != 1 else ' is'} compressed and not shown: "
|
|
79
|
+
f"{zstd_hint()}.") if skipped else ""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|