agent-decoder 0.3.2__py3-none-any.whl → 0.3.6__py3-none-any.whl
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.
- {clau_decode → agent_decoder}/__init__.py +2 -2
- agent_decoder/__main__.py +11 -0
- {clau_decode → agent_decoder}/_auth_env.py +4 -6
- {clau_decode → agent_decoder}/_pty_preexec.py +1 -1
- agent_decoder/_tmux_capture.py +23 -0
- agent_decoder/_tmux_exec.py +16 -0
- agent_decoder/agent_runs.py +266 -0
- {clau_decode → agent_decoder}/analytics/aggregator.py +1 -1
- {clau_decode → agent_decoder}/analytics/extractor.py +1 -1
- {clau_decode → agent_decoder}/analytics/fast.py +1 -1
- {clau_decode → agent_decoder}/analytics/pricing.py +29 -9
- {clau_decode → agent_decoder}/analytics/prompt.py +1 -1
- {clau_decode → agent_decoder}/analytics/service.py +1 -1
- {clau_decode → agent_decoder}/analytics/stats.py +1 -1
- {clau_decode → agent_decoder}/analytics/tips.py +1 -1
- {clau_decode → agent_decoder}/cli.py +13 -13
- {clau_decode → agent_decoder}/config.py +31 -12
- {clau_decode → agent_decoder}/db.py +361 -228
- {clau_decode → agent_decoder}/driver_manager.py +53 -78
- {clau_decode → agent_decoder}/drivers/base.py +16 -4
- {clau_decode → agent_decoder}/drivers/registry.py +4 -5
- {clau_decode → agent_decoder}/drivers/tmux_driver.py +27 -11
- {clau_decode → agent_decoder}/editor.py +2 -2
- agent_decoder/execution_manager.py +414 -0
- {clau_decode → agent_decoder}/locks.py +3 -3
- {clau_decode → agent_decoder}/migrate.py +12 -15
- {clau_decode → agent_decoder}/models.py +6 -0
- {clau_decode → agent_decoder}/parser.py +16 -2
- {clau_decode → agent_decoder}/providers/__init__.py +1 -1
- {clau_decode → agent_decoder}/providers/base.py +6 -2
- {clau_decode → agent_decoder}/providers/claude.py +4 -2
- {clau_decode → agent_decoder}/providers/codex.py +8 -2
- {clau_decode → agent_decoder}/providers/registry.py +2 -2
- {clau_decode → agent_decoder}/pty_runner.py +155 -17
- agent_decoder/query_parser.py +127 -0
- {clau_decode → agent_decoder}/scanner.py +28 -2
- {clau_decode → agent_decoder}/server.py +249 -90
- agent_decoder/static/assets/ArtifactsPanel-D-CqWycU.js +1 -0
- clau_decode/static/assets/ChatView-BBVXuITs.js → agent_decoder/static/assets/ChatView-CFunVM15.js +39 -39
- agent_decoder/static/assets/Dashboard-CBe8ZXJ-.js +1 -0
- agent_decoder/static/assets/FileViewer-CVtveC8R.js +1 -0
- clau_decode/static/assets/HelpPopup-CPtECjYw.js → agent_decoder/static/assets/HelpPopup-BYhBIvA6.js +1 -1
- agent_decoder/static/assets/Runs-DvLUpR9O.js +1 -0
- agent_decoder/static/assets/Runs-Y8oF-gxW.css +1 -0
- clau_decode/static/assets/ScrollContainer-BT_Dzxah.js → agent_decoder/static/assets/ScrollContainer-CA7-aYqv.js +1 -1
- agent_decoder/static/assets/SearchOverlay-CF4dXG6x.js +1 -0
- agent_decoder/static/assets/SessionItem-BUejVuL5.js +1 -0
- agent_decoder/static/assets/SettingsModal-DWSMRQmn.js +1 -0
- agent_decoder/static/assets/ShortcutsPopup-Df9bhfs6.js +1 -0
- agent_decoder/static/assets/Sidebar-CJcwJziw.js +1 -0
- agent_decoder/static/assets/fileType-BHvAriyJ.js +1 -0
- agent_decoder/static/assets/formatRelative-CavTjOcy.js +1 -0
- agent_decoder/static/assets/hljs-CvdnYs1C.js +35 -0
- clau_decode/static/assets/index-BHdCOIkq.css → agent_decoder/static/assets/index-Bo2bFwpv.css +1 -1
- agent_decoder/static/assets/index-XPrlVfCr.js +5 -0
- clau_decode/static/assets/react-Bi_azaFt.js → agent_decoder/static/assets/react-CCIEwYL0.js +4 -4
- agent_decoder/static/assets/renderSnippet-CcNMfZRd.js +1 -0
- agent_decoder/static/assets/sessionCache-Cj3FsbQ4.js +1 -0
- clau_decode/static/assets/shared-DdVGprvF.js → agent_decoder/static/assets/shared-CAVcrZag.js +1 -1
- agent_decoder/static/assets/ui-BVMZ0uWi.js +1 -0
- agent_decoder/static/assets/useDebounce-CRtjXm0i.js +1 -0
- agent_decoder/static/assets/useSessionDetail-D4HneaxZ.js +1 -0
- {clau_decode → agent_decoder}/static/index.html +5 -6
- agent_decoder/static/site.webmanifest +1 -0
- agent_decoder/tmux_terminal.py +297 -0
- {clau_decode → agent_decoder}/update_check.py +5 -4
- {agent_decoder-0.3.2.dist-info → agent_decoder-0.3.6.dist-info}/METADATA +56 -44
- agent_decoder-0.3.6.dist-info/RECORD +101 -0
- {agent_decoder-0.3.2.dist-info → agent_decoder-0.3.6.dist-info}/WHEEL +1 -1
- agent_decoder-0.3.6.dist-info/entry_points.txt +2 -0
- {agent_decoder-0.3.2.dist-info → agent_decoder-0.3.6.dist-info}/licenses/LICENSE +1 -1
- agent_decoder-0.3.2.dist-info/RECORD +0 -89
- agent_decoder-0.3.2.dist-info/entry_points.txt +0 -2
- clau_decode/__main__.py +0 -11
- clau_decode/static/assets/Dashboard-3CYO4HQw.js +0 -1
- clau_decode/static/assets/FileViewer-BwbDc3ky.js +0 -1
- clau_decode/static/assets/SearchOverlay-DqI7aZaC.js +0 -1
- clau_decode/static/assets/SessionItem-DlyKg80u.js +0 -1
- clau_decode/static/assets/SettingsModal-CZBfMqx7.js +0 -1
- clau_decode/static/assets/ShortcutsPopup-W7CPdCzW.js +0 -1
- clau_decode/static/assets/Sidebar-BBswhEua.js +0 -1
- clau_decode/static/assets/client-DTSXvAb8.js +0 -1
- clau_decode/static/assets/formatRelative-j86webkr.js +0 -1
- clau_decode/static/assets/hljs-B3O74O7Z.js +0 -35
- clau_decode/static/assets/index-DfKltZ6z.js +0 -5
- clau_decode/static/assets/renderSnippet-CqpQQugH.js +0 -1
- clau_decode/static/assets/ui-BcGPjpYn.js +0 -1
- clau_decode/static/site.webmanifest +0 -1
- {clau_decode → agent_decoder}/analytics/__init__.py +0 -0
- {clau_decode → agent_decoder}/analytics/cost.py +0 -0
- {clau_decode → agent_decoder}/analytics/models.py +0 -0
- {clau_decode → agent_decoder}/btw_capture.py +0 -0
- {clau_decode → agent_decoder}/drivers/__init__.py +0 -0
- {clau_decode → agent_decoder}/events_bus.py +0 -0
- {clau_decode → agent_decoder}/pty_native.py +0 -0
- {clau_decode → agent_decoder}/pty_screen_state.py +0 -0
- {clau_decode → agent_decoder}/recap_runner.py +0 -0
- {clau_decode → agent_decoder}/reporter.py +0 -0
- {clau_decode → agent_decoder}/static/android-chrome-192x192.png +0 -0
- {clau_decode → agent_decoder}/static/android-chrome-512x512.png +0 -0
- {clau_decode → agent_decoder}/static/app-icon.png +0 -0
- {clau_decode → agent_decoder}/static/apple-touch-icon.png +0 -0
- {clau_decode → agent_decoder}/static/assets/ChatView-BrP-ENHg.css +0 -0
- {clau_decode → agent_decoder}/static/assets/fira-code-DGosTW8U.woff2 +0 -0
- {clau_decode → agent_decoder}/static/assets/ioskeley-mono-C7VR2-sL.woff2 +0 -0
- {clau_decode → agent_decoder}/static/assets/jetbrains-mono-V6pRDFza.woff2 +0 -0
- {clau_decode → agent_decoder}/static/assets/julia-mono-Cbvba6sW.woff2 +0 -0
- {clau_decode → agent_decoder}/static/assets/libertinus-mono-Coz17E-O.woff2 +0 -0
- {clau_decode → agent_decoder}/static/assets/monaspace-argon-RS-2TGNg.woff2 +0 -0
- /clau_decode/static/assets/nativePtyFonts-BaXKtUsn.js → /agent_decoder/static/assets/nativePtyFonts-BxhRYj2G.js +0 -0
- /clau_decode/static/assets/rolldown-runtime-S-ySWqyJ.js → /agent_decoder/static/assets/rolldown-runtime-QTnfLwEv.js +0 -0
- {clau_decode → agent_decoder}/static/assets/source-code-pro-DEXWLoHG.woff2 +0 -0
- {clau_decode → agent_decoder}/static/assets/spline-sans-mono-mUpA6Mve.woff2 +0 -0
- {clau_decode → agent_decoder}/static/assets/xanh-mono-Dsg19vWS.woff2 +0 -0
- {clau_decode → agent_decoder}/static/favicon-16x16.png +0 -0
- {clau_decode → agent_decoder}/static/favicon-32x32.png +0 -0
- {clau_decode → agent_decoder}/static/favicon.ico +0 -0
- {clau_decode → agent_decoder}/watcher.py +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# THE single source of truth for
|
|
1
|
+
# THE single source of truth for Agent Decoder's version. Edit it here and
|
|
2
2
|
# nowhere else — every other place derives from this one string:
|
|
3
3
|
# * Python packaging — pyproject's [tool.hatch.version] reads this file.
|
|
4
4
|
# * CLI `--version` — cli.py imports __version__.
|
|
5
5
|
# * HTTP API — /api/host-info returns it.
|
|
6
6
|
# * Settings ▸ About — the frontend fetches it from that API (no copy in JS).
|
|
7
7
|
# Bump this on every release (and tag the commit `vX.Y.Z` to match).
|
|
8
|
-
__version__ = "0.3.
|
|
8
|
+
__version__ = "0.3.6"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""Module entry point so ``python -m agent_decoder`` runs the app.
|
|
2
|
+
|
|
3
|
+
Mirrors the ``ring`` console script (``agent_decoder.cli:main``). Handy for
|
|
4
|
+
running straight from a checkout (``uv run python -m agent_decoder``) without a
|
|
5
|
+
global install.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .cli import main
|
|
9
|
+
|
|
10
|
+
if __name__ == "__main__":
|
|
11
|
+
main()
|
|
@@ -37,11 +37,11 @@ _SUBSCRIPTION_BLOCKED_ENV: Final = frozenset(
|
|
|
37
37
|
|
|
38
38
|
# Session-identity vars the `claude` CLI sets on itself so a nested/child
|
|
39
39
|
# invocation can detect it's not a top-level session (e.g. it disables
|
|
40
|
-
# transcript saving). If
|
|
40
|
+
# transcript saving). If agent-decoder's own server process was launched from
|
|
41
41
|
# inside a Claude Code session, these leak into ``os.environ`` and — because
|
|
42
42
|
# spawn_env otherwise starts from a raw copy of it — get inherited by every
|
|
43
|
-
# native PTY
|
|
44
|
-
# session falsely believe it's a child of another one. Every PTY
|
|
43
|
+
# native PTY agent-decoder spawns, making an unrelated top-level `claude`
|
|
44
|
+
# session falsely believe it's a child of another one. Every PTY ring
|
|
45
45
|
# spawns is its own top-level session, so these must never survive the copy.
|
|
46
46
|
_SESSION_IDENTITY_BLOCKED_ENV: Final = frozenset({"CLAUDE_CODE_CHILD_SESSION"})
|
|
47
47
|
|
|
@@ -62,9 +62,7 @@ def _subscription_env() -> dict[str, str]:
|
|
|
62
62
|
outside tests should prefer ``spawn_env(bin_name)`` so the strip is
|
|
63
63
|
gated by the binary's actual auth method.
|
|
64
64
|
"""
|
|
65
|
-
env = {
|
|
66
|
-
k: v for k, v in os.environ.items() if k not in _SUBSCRIPTION_BLOCKED_ENV
|
|
67
|
-
}
|
|
65
|
+
env = {k: v for k, v in os.environ.items() if k not in _SUBSCRIPTION_BLOCKED_ENV}
|
|
68
66
|
return _strip_session_identity_env(env)
|
|
69
67
|
|
|
70
68
|
|
|
@@ -12,7 +12,7 @@ the real target binary. From here on the child is fully detached and runs
|
|
|
12
12
|
under its own session with the slave as its controlling TTY.
|
|
13
13
|
|
|
14
14
|
Usage:
|
|
15
|
-
python3 -m
|
|
15
|
+
python3 -m agent_decoder._pty_preexec <bin_name> [args...]
|
|
16
16
|
|
|
17
17
|
The first argv after the module name is the target binary; remaining args
|
|
18
18
|
are forwarded.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Drain tmux pipe-pane without ever waiting for the application receiver.
|
|
2
|
+
|
|
3
|
+
Datagrams are bounded and sequenced. A stopped/full receiver drops data rather
|
|
4
|
+
than blocking the provider; the reader rejects incomplete ephemeral captures.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import socket
|
|
9
|
+
import struct
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
sink = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
|
13
|
+
sink.setblocking(False)
|
|
14
|
+
sequence = 0
|
|
15
|
+
while True:
|
|
16
|
+
chunk = os.read(0, 1024)
|
|
17
|
+
if not chunk:
|
|
18
|
+
break
|
|
19
|
+
sequence += 1
|
|
20
|
+
try:
|
|
21
|
+
sink.sendto(struct.pack("!Q", sequence) + chunk, sys.argv[1])
|
|
22
|
+
except OSError:
|
|
23
|
+
pass
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Consume a private environment handoff then exec a persistent harness.
|
|
2
|
+
|
|
3
|
+
Environment values never appear in tmux's argv or durable session metadata.
|
|
4
|
+
The handoff lives in a mode-0700 temporary directory and is unlinked before
|
|
5
|
+
executing the provider. This process becomes the pane PID via exec.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
with open(sys.argv[1]) as handoff:
|
|
13
|
+
payload = json.load(handoff)
|
|
14
|
+
os.unlink(sys.argv[1])
|
|
15
|
+
os.rmdir(os.path.dirname(sys.argv[1]))
|
|
16
|
+
os.execvpe(payload["argv"][0], payload["argv"], payload["env"])
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"""Durable managed execution attempts, independent of the session index.
|
|
2
|
+
|
|
3
|
+
A run is one managed process attempt, not a turn or a task. No screen or exit
|
|
4
|
+
code establishes successful completion. Detached attempts retain their identity.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import asyncio
|
|
10
|
+
from datetime import datetime, timezone
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Literal
|
|
13
|
+
from uuid import uuid4
|
|
14
|
+
|
|
15
|
+
import aiosqlite
|
|
16
|
+
from pydantic import BaseModel
|
|
17
|
+
|
|
18
|
+
RunState = Literal[
|
|
19
|
+
"queued",
|
|
20
|
+
"starting",
|
|
21
|
+
"running",
|
|
22
|
+
"awaiting_input",
|
|
23
|
+
"blocked",
|
|
24
|
+
"completed",
|
|
25
|
+
"failed",
|
|
26
|
+
"canceled",
|
|
27
|
+
]
|
|
28
|
+
TERMINAL = ("completed", "failed", "canceled")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
RUN_SCHEMA = """
|
|
32
|
+
CREATE TABLE IF NOT EXISTS agent_runs (
|
|
33
|
+
id TEXT PRIMARY KEY, provider TEXT NOT NULL,
|
|
34
|
+
native_session_id TEXT NOT NULL, model TEXT, project_id TEXT,
|
|
35
|
+
cwd TEXT, git_branch TEXT, is_worktree INTEGER NOT NULL DEFAULT 0,
|
|
36
|
+
task_id TEXT, parent_run_id TEXT, state TEXT NOT NULL CHECK(state IN ('queued','starting','running','awaiting_input','blocked','completed','failed','canceled')),
|
|
37
|
+
reason TEXT NOT NULL, provenance TEXT NOT NULL,
|
|
38
|
+
created_at TEXT NOT NULL, updated_at TEXT NOT NULL,
|
|
39
|
+
last_observed_at TEXT, ended_at TEXT);
|
|
40
|
+
CREATE UNIQUE INDEX IF NOT EXISTS agent_runs_active
|
|
41
|
+
ON agent_runs(provider, native_session_id)
|
|
42
|
+
WHERE ended_at IS NULL;
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def now() -> str:
|
|
47
|
+
return datetime.now(timezone.utc).isoformat()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class AgentRun(BaseModel):
|
|
51
|
+
id: str
|
|
52
|
+
provider: str
|
|
53
|
+
native_session_id: str
|
|
54
|
+
model: str | None = None
|
|
55
|
+
project_id: str | None = None
|
|
56
|
+
cwd: str | None = None
|
|
57
|
+
git_branch: str | None = None
|
|
58
|
+
is_worktree: bool = False
|
|
59
|
+
task_id: str | None = None
|
|
60
|
+
parent_run_id: str | None = None
|
|
61
|
+
state: RunState
|
|
62
|
+
reason: str
|
|
63
|
+
provenance: str
|
|
64
|
+
created_at: str
|
|
65
|
+
updated_at: str
|
|
66
|
+
last_observed_at: str | None = None
|
|
67
|
+
ended_at: str | None = None
|
|
68
|
+
source_available: bool = False
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class RunStore:
|
|
72
|
+
def __init__(self, path: Path | None, bus=None):
|
|
73
|
+
self.path, self.bus = path, bus
|
|
74
|
+
self.lock = asyncio.Lock()
|
|
75
|
+
|
|
76
|
+
async def initialize(self):
|
|
77
|
+
if self.path is None:
|
|
78
|
+
return
|
|
79
|
+
async with aiosqlite.connect(self.path) as db:
|
|
80
|
+
await db.executescript(RUN_SCHEMA)
|
|
81
|
+
await db.execute(
|
|
82
|
+
"UPDATE agent_runs SET state='blocked', reason='Server restarted; process not yet reobserved', provenance='server_restart', updated_at=? WHERE ended_at IS NULL",
|
|
83
|
+
(now(),),
|
|
84
|
+
)
|
|
85
|
+
await db.commit()
|
|
86
|
+
|
|
87
|
+
async def list(
|
|
88
|
+
self,
|
|
89
|
+
*,
|
|
90
|
+
limit: int = 200,
|
|
91
|
+
offset: int = 0,
|
|
92
|
+
active_only: bool = False,
|
|
93
|
+
session_id: str | None = None,
|
|
94
|
+
run_id: str | None = None,
|
|
95
|
+
provider: str | None = None,
|
|
96
|
+
state: str | None = None,
|
|
97
|
+
project: str | None = None,
|
|
98
|
+
q: str = "",
|
|
99
|
+
) -> list[AgentRun]:
|
|
100
|
+
if self.path is None:
|
|
101
|
+
return []
|
|
102
|
+
async with aiosqlite.connect(self.path) as db:
|
|
103
|
+
db.row_factory = aiosqlite.Row
|
|
104
|
+
clauses, params = [], []
|
|
105
|
+
if active_only:
|
|
106
|
+
clauses.append("r.ended_at IS NULL")
|
|
107
|
+
if session_id is not None:
|
|
108
|
+
clauses.append("r.native_session_id=?")
|
|
109
|
+
params.append(session_id)
|
|
110
|
+
if run_id is not None:
|
|
111
|
+
clauses.append("r.id=?")
|
|
112
|
+
params.append(run_id)
|
|
113
|
+
for column, value in (
|
|
114
|
+
("provider", provider),
|
|
115
|
+
("state", state),
|
|
116
|
+
("project_id", project),
|
|
117
|
+
):
|
|
118
|
+
if value:
|
|
119
|
+
clauses.append(f"r.{column}=?")
|
|
120
|
+
params.append(value)
|
|
121
|
+
if q:
|
|
122
|
+
clauses.append(
|
|
123
|
+
"lower(coalesce(r.cwd,'') || ' ' || coalesce(r.project_id,'') || ' ' || coalesce(r.model,'') || ' ' || coalesce(r.git_branch,'') || ' ' || r.native_session_id || ' ' || r.id) LIKE ?"
|
|
124
|
+
)
|
|
125
|
+
params.append("%" + q.lower() + "%")
|
|
126
|
+
where = (" WHERE " + " AND ".join(clauses)) if clauses else ""
|
|
127
|
+
rows = await db.execute(
|
|
128
|
+
"""SELECT r.id, r.provider, r.native_session_id,
|
|
129
|
+
coalesce(r.model,s.model) AS model, coalesce(r.project_id,s.project_id) AS project_id,
|
|
130
|
+
coalesce(r.cwd,s.cwd) AS cwd, coalesce(r.git_branch,s.git_branch) AS git_branch,
|
|
131
|
+
CASE WHEN r.project_id IS NULL THEN coalesce(s.is_worktree,r.is_worktree) ELSE r.is_worktree END AS is_worktree,
|
|
132
|
+
r.task_id,r.parent_run_id,r.state,r.reason,r.provenance,r.created_at,r.updated_at,
|
|
133
|
+
r.last_observed_at,r.ended_at,(s.id IS NOT NULL) AS source_available
|
|
134
|
+
FROM agent_runs r LEFT JOIN sessions s ON s.id=r.native_session_id"""
|
|
135
|
+
+ where
|
|
136
|
+
+ " ORDER BY created_at DESC LIMIT ? OFFSET ?",
|
|
137
|
+
(*params, limit, offset),
|
|
138
|
+
)
|
|
139
|
+
return [AgentRun(**dict(row)) for row in await rows.fetchall()]
|
|
140
|
+
|
|
141
|
+
async def active(self, session_id: str, provider: str | None = None):
|
|
142
|
+
return next(
|
|
143
|
+
iter(
|
|
144
|
+
await self.list(
|
|
145
|
+
active_only=True, session_id=session_id, provider=provider, limit=1
|
|
146
|
+
)
|
|
147
|
+
),
|
|
148
|
+
None,
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
async def begin(self, session_id: str, provider: str, **metadata):
|
|
152
|
+
if self.path is None:
|
|
153
|
+
return None
|
|
154
|
+
async with self.lock:
|
|
155
|
+
stamp = now()
|
|
156
|
+
async with aiosqlite.connect(self.path) as db:
|
|
157
|
+
await db.execute("BEGIN IMMEDIATE")
|
|
158
|
+
cursor = await db.execute(
|
|
159
|
+
"SELECT id FROM agent_runs WHERE provider=? AND native_session_id=? AND ended_at IS NULL",
|
|
160
|
+
(provider, session_id),
|
|
161
|
+
)
|
|
162
|
+
if await cursor.fetchone():
|
|
163
|
+
await db.rollback()
|
|
164
|
+
return await self.active(session_id, provider)
|
|
165
|
+
db.row_factory = aiosqlite.Row
|
|
166
|
+
cursor = await db.execute(
|
|
167
|
+
"SELECT model, project_id, cwd, git_branch, is_worktree FROM sessions WHERE id=?",
|
|
168
|
+
(session_id,),
|
|
169
|
+
)
|
|
170
|
+
row = await cursor.fetchone()
|
|
171
|
+
values = dict(row) if row else {}
|
|
172
|
+
for key in ("model", "cwd"):
|
|
173
|
+
if metadata.get(key) is not None:
|
|
174
|
+
values[key] = metadata[key]
|
|
175
|
+
run = AgentRun(
|
|
176
|
+
id=str(uuid4()),
|
|
177
|
+
provider=provider,
|
|
178
|
+
native_session_id=session_id,
|
|
179
|
+
state="starting",
|
|
180
|
+
reason="Managed launch or attachment requested",
|
|
181
|
+
provenance="execution_manager",
|
|
182
|
+
created_at=stamp,
|
|
183
|
+
updated_at=stamp,
|
|
184
|
+
**values,
|
|
185
|
+
)
|
|
186
|
+
data = run.model_dump(exclude={"source_available"})
|
|
187
|
+
await db.execute(
|
|
188
|
+
f"INSERT INTO agent_runs ({','.join(data)}) VALUES ({','.join('?' for _ in data)})",
|
|
189
|
+
tuple(data.values()),
|
|
190
|
+
)
|
|
191
|
+
await db.commit()
|
|
192
|
+
self.changed()
|
|
193
|
+
return run
|
|
194
|
+
|
|
195
|
+
def changed(self):
|
|
196
|
+
if self.bus:
|
|
197
|
+
self.bus.publish({"type": "runs_changed"})
|
|
198
|
+
|
|
199
|
+
async def update(
|
|
200
|
+
self,
|
|
201
|
+
session_id: str,
|
|
202
|
+
state: RunState,
|
|
203
|
+
reason: str,
|
|
204
|
+
provenance: str,
|
|
205
|
+
*,
|
|
206
|
+
observed=False,
|
|
207
|
+
close_unknown=False,
|
|
208
|
+
observation_at: str | None = None,
|
|
209
|
+
):
|
|
210
|
+
async with self.lock:
|
|
211
|
+
run = await self.active(session_id)
|
|
212
|
+
if not run:
|
|
213
|
+
return
|
|
214
|
+
stamp = now()
|
|
215
|
+
async with aiosqlite.connect(self.path) as db:
|
|
216
|
+
await db.execute(
|
|
217
|
+
"UPDATE agent_runs SET model=?,project_id=?,cwd=?,git_branch=?,is_worktree=? WHERE id=?",
|
|
218
|
+
(
|
|
219
|
+
run.model,
|
|
220
|
+
run.project_id,
|
|
221
|
+
run.cwd,
|
|
222
|
+
run.git_branch,
|
|
223
|
+
run.is_worktree,
|
|
224
|
+
run.id,
|
|
225
|
+
),
|
|
226
|
+
)
|
|
227
|
+
await db.execute(
|
|
228
|
+
"""UPDATE agent_runs SET state=?,reason=?,provenance=?,updated_at=?,
|
|
229
|
+
last_observed_at=?,ended_at=? WHERE id=? AND ended_at IS NULL""",
|
|
230
|
+
(
|
|
231
|
+
state,
|
|
232
|
+
reason,
|
|
233
|
+
provenance,
|
|
234
|
+
stamp,
|
|
235
|
+
(observation_at or stamp) if observed else run.last_observed_at,
|
|
236
|
+
stamp if state in TERMINAL or close_unknown else None,
|
|
237
|
+
run.id,
|
|
238
|
+
),
|
|
239
|
+
)
|
|
240
|
+
await db.commit()
|
|
241
|
+
self.changed()
|
|
242
|
+
|
|
243
|
+
async def rekey(self, old: str, new: str):
|
|
244
|
+
if self.path is None:
|
|
245
|
+
return
|
|
246
|
+
async with self.lock:
|
|
247
|
+
async with aiosqlite.connect(self.path) as db:
|
|
248
|
+
await db.execute(
|
|
249
|
+
"UPDATE agent_runs SET native_session_id=?,updated_at=? WHERE native_session_id=? AND ended_at IS NULL",
|
|
250
|
+
(new, now(), old),
|
|
251
|
+
)
|
|
252
|
+
cursor = await db.execute(
|
|
253
|
+
"SELECT model,project_id,cwd,git_branch,is_worktree FROM sessions WHERE id=?",
|
|
254
|
+
(new,),
|
|
255
|
+
)
|
|
256
|
+
source = await cursor.fetchone()
|
|
257
|
+
if source:
|
|
258
|
+
await db.execute(
|
|
259
|
+
"""UPDATE agent_runs SET model=coalesce(model,?),project_id=coalesce(project_id,?),
|
|
260
|
+
cwd=coalesce(cwd,?),git_branch=coalesce(git_branch,?),
|
|
261
|
+
is_worktree=CASE WHEN project_id IS NULL THEN ? ELSE is_worktree END
|
|
262
|
+
WHERE native_session_id=? AND ended_at IS NULL""",
|
|
263
|
+
(*source, new),
|
|
264
|
+
)
|
|
265
|
+
await db.commit()
|
|
266
|
+
self.changed()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
from datetime import date, timezone
|
|
3
|
-
from
|
|
3
|
+
from agent_decoder.models import Message
|
|
4
4
|
from .extractor import DeduplicatingExtractor, TokenExtractor
|
|
5
5
|
from .models import DailyBucket, TokenBreakdown
|
|
6
6
|
|
|
@@ -23,7 +23,7 @@ from __future__ import annotations
|
|
|
23
23
|
|
|
24
24
|
from typing import Any
|
|
25
25
|
|
|
26
|
-
from
|
|
26
|
+
from agent_decoder.models import Message, TokenUsage, ToolResultBlock, ToolUseBlock
|
|
27
27
|
|
|
28
28
|
from .stats import compute_stats
|
|
29
29
|
from .tips import (
|
|
@@ -14,7 +14,8 @@ _LITELLM_URL = (
|
|
|
14
14
|
"model_prices_and_context_window.json"
|
|
15
15
|
)
|
|
16
16
|
|
|
17
|
-
# API pricing as of
|
|
17
|
+
# API pricing as of 2026-07-19 (USD per million tokens), covering the
|
|
18
|
+
# Claude Fable 5 / Opus 4.8 / Sonnet 5 lineup.
|
|
18
19
|
# Keys are model name prefixes for flexible matching.
|
|
19
20
|
_HARDCODED_RATES: dict[str, "ModelPricing"] = {}
|
|
20
21
|
|
|
@@ -39,11 +40,30 @@ class ModelPricing:
|
|
|
39
40
|
|
|
40
41
|
|
|
41
42
|
_HARDCODED_RATES = {
|
|
43
|
+
"claude-fable-5": ModelPricing(
|
|
44
|
+
input_per_mtok=Decimal("10.00"),
|
|
45
|
+
output_per_mtok=Decimal("50.00"),
|
|
46
|
+
cache_write_per_mtok=Decimal("12.50"),
|
|
47
|
+
cache_read_per_mtok=Decimal("1.00"),
|
|
48
|
+
),
|
|
49
|
+
"claude-opus-4-8": ModelPricing(
|
|
50
|
+
input_per_mtok=Decimal("5.00"),
|
|
51
|
+
output_per_mtok=Decimal("25.00"),
|
|
52
|
+
cache_write_per_mtok=Decimal("6.25"),
|
|
53
|
+
cache_read_per_mtok=Decimal("0.50"),
|
|
54
|
+
),
|
|
42
55
|
"claude-opus-4-7": ModelPricing(
|
|
43
|
-
input_per_mtok=Decimal("
|
|
44
|
-
output_per_mtok=Decimal("
|
|
45
|
-
cache_write_per_mtok=Decimal("
|
|
46
|
-
cache_read_per_mtok=Decimal("
|
|
56
|
+
input_per_mtok=Decimal("5.00"),
|
|
57
|
+
output_per_mtok=Decimal("25.00"),
|
|
58
|
+
cache_write_per_mtok=Decimal("6.25"),
|
|
59
|
+
cache_read_per_mtok=Decimal("0.50"),
|
|
60
|
+
),
|
|
61
|
+
# Standard rates; intro pricing $2/$10 per 1M applied through 2026-08-31.
|
|
62
|
+
"claude-sonnet-5": ModelPricing(
|
|
63
|
+
input_per_mtok=Decimal("3.00"),
|
|
64
|
+
output_per_mtok=Decimal("15.00"),
|
|
65
|
+
cache_write_per_mtok=Decimal("3.75"),
|
|
66
|
+
cache_read_per_mtok=Decimal("0.30"),
|
|
47
67
|
),
|
|
48
68
|
"claude-sonnet-4-6": ModelPricing(
|
|
49
69
|
input_per_mtok=Decimal("3.00"),
|
|
@@ -52,10 +72,10 @@ _HARDCODED_RATES = {
|
|
|
52
72
|
cache_read_per_mtok=Decimal("0.30"),
|
|
53
73
|
),
|
|
54
74
|
"claude-haiku-4-5": ModelPricing(
|
|
55
|
-
input_per_mtok=Decimal("
|
|
56
|
-
output_per_mtok=Decimal("
|
|
57
|
-
cache_write_per_mtok=Decimal("1.
|
|
58
|
-
cache_read_per_mtok=Decimal("0.
|
|
75
|
+
input_per_mtok=Decimal("1.00"),
|
|
76
|
+
output_per_mtok=Decimal("5.00"),
|
|
77
|
+
cache_write_per_mtok=Decimal("1.25"),
|
|
78
|
+
cache_read_per_mtok=Decimal("0.10"),
|
|
59
79
|
),
|
|
60
80
|
"claude-3-5-sonnet": ModelPricing(
|
|
61
81
|
input_per_mtok=Decimal("3.00"),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
|
-
from
|
|
2
|
+
from agent_decoder.models import Message
|
|
3
3
|
from .aggregator import DailyAggregator, SessionAggregator
|
|
4
4
|
from .extractor import TokenExtractor
|
|
5
5
|
from .models import DailyBucket, PromptCost, TokenBreakdown
|
|
@@ -3,7 +3,7 @@ import statistics
|
|
|
3
3
|
from collections import Counter, defaultdict
|
|
4
4
|
from typing import Any
|
|
5
5
|
|
|
6
|
-
from
|
|
6
|
+
from agent_decoder.models import Message, ToolUseBlock
|
|
7
7
|
from .extractor import TokenExtractor
|
|
8
8
|
from .prompt import PromptIterator
|
|
9
9
|
|
|
@@ -3,7 +3,7 @@ from collections import defaultdict
|
|
|
3
3
|
from dataclasses import dataclass, field
|
|
4
4
|
from typing import Literal, Protocol
|
|
5
5
|
|
|
6
|
-
from
|
|
6
|
+
from agent_decoder.models import Message, ToolResultBlock, ToolUseBlock
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
_SEVERITY_ORDER = {"error": 0, "warning": 1, "info": 2}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""CLI entry point — `
|
|
1
|
+
"""CLI entry point — `ring [options] <command>`.
|
|
2
2
|
|
|
3
3
|
Commands:
|
|
4
4
|
dashboard Launch the web UI (default when no command given)
|
|
@@ -41,7 +41,7 @@ from .server import create_app
|
|
|
41
41
|
|
|
42
42
|
def _build_parser() -> argparse.ArgumentParser:
|
|
43
43
|
parser = argparse.ArgumentParser(
|
|
44
|
-
prog="
|
|
44
|
+
prog="ring",
|
|
45
45
|
description="Local web viewer and analytics for AI coding assistant chat history",
|
|
46
46
|
)
|
|
47
47
|
parser.add_argument(
|
|
@@ -77,7 +77,7 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
77
77
|
parser.add_argument(
|
|
78
78
|
"--version",
|
|
79
79
|
action="version",
|
|
80
|
-
version=f"
|
|
80
|
+
version=f"agent-decoder {__version__}",
|
|
81
81
|
)
|
|
82
82
|
parser.add_argument(
|
|
83
83
|
"--enable-edit",
|
|
@@ -101,7 +101,7 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
101
101
|
"--log-level",
|
|
102
102
|
choices=("debug", "info", "warning", "error"),
|
|
103
103
|
default="info",
|
|
104
|
-
help="Verbosity for
|
|
104
|
+
help="Verbosity for agent_decoder loggers (independent of uvicorn). "
|
|
105
105
|
"Default 'info' surfaces operational signals (PTY runner warnings, "
|
|
106
106
|
"/btw finalize/timeout, ephemeral persistence). Use 'debug' when "
|
|
107
107
|
"diagnosing a live issue.",
|
|
@@ -168,8 +168,8 @@ def _resolve_host(args: argparse.Namespace, config=None) -> str:
|
|
|
168
168
|
return "127.0.0.1"
|
|
169
169
|
|
|
170
170
|
|
|
171
|
-
def
|
|
172
|
-
"""Attach an explicit stderr handler to the ``
|
|
171
|
+
def _configure_agent_decoder_logging(level_name: str) -> None:
|
|
172
|
+
"""Attach an explicit stderr handler to the ``agent_decoder`` logger.
|
|
173
173
|
|
|
174
174
|
Uvicorn's default ``log_config`` reconfigures Python logging when
|
|
175
175
|
``uvicorn.run`` is invoked, which drops the implicit ``lastResort``
|
|
@@ -195,28 +195,28 @@ def _configure_clau_decode_logging(level_name: str) -> None:
|
|
|
195
195
|
except Exception:
|
|
196
196
|
pass
|
|
197
197
|
level = getattr(_logging, level_name.upper(), _logging.INFO)
|
|
198
|
-
logger = _logging.getLogger("
|
|
198
|
+
logger = _logging.getLogger("agent_decoder")
|
|
199
199
|
logger.setLevel(level)
|
|
200
200
|
if not any(
|
|
201
201
|
isinstance(h, _logging.StreamHandler)
|
|
202
|
-
and getattr(h, "
|
|
202
|
+
and getattr(h, "_agent_decoder_attached", False)
|
|
203
203
|
for h in logger.handlers
|
|
204
204
|
):
|
|
205
205
|
handler = _logging.StreamHandler(sys.stderr)
|
|
206
206
|
handler.setFormatter(
|
|
207
207
|
_logging.Formatter("%(asctime)s %(name)s %(levelname)s %(message)s")
|
|
208
208
|
)
|
|
209
|
-
handler.
|
|
209
|
+
handler._agent_decoder_attached = True # type: ignore[attr-defined]
|
|
210
210
|
logger.addHandler(handler)
|
|
211
211
|
logger.propagate = False
|
|
212
212
|
|
|
213
213
|
|
|
214
214
|
def _run_dashboard(args: argparse.Namespace, config) -> None:
|
|
215
215
|
"""Launch the web UI with uvicorn."""
|
|
216
|
-
|
|
216
|
+
_configure_agent_decoder_logging(args.log_level)
|
|
217
217
|
import logging as _logging
|
|
218
218
|
|
|
219
|
-
_logging.getLogger("
|
|
219
|
+
_logging.getLogger("agent_decoder").info(
|
|
220
220
|
"logger configured (level=%s)", args.log_level
|
|
221
221
|
)
|
|
222
222
|
host = _resolve_host(args, config)
|
|
@@ -246,7 +246,7 @@ def _run_dashboard(args: argparse.Namespace, config) -> None:
|
|
|
246
246
|
|
|
247
247
|
threading.Thread(target=_open_browser, daemon=True).start()
|
|
248
248
|
|
|
249
|
-
print(f"
|
|
249
|
+
print(f"Agent Decoder running at http://{host}:{config.port}", flush=True)
|
|
250
250
|
uvicorn.run(app, host=host, port=config.port, log_level="warning")
|
|
251
251
|
|
|
252
252
|
|
|
@@ -500,5 +500,5 @@ def main() -> None:
|
|
|
500
500
|
|
|
501
501
|
|
|
502
502
|
def _run_migrate(args, config) -> None:
|
|
503
|
-
"""``
|
|
503
|
+
"""``ring migrate`` -- filesystem merge tool; ignores app config."""
|
|
504
504
|
raise SystemExit(migrate.run(args))
|