autotel-agents 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Jag Reehal 2025
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # autotel-agents
2
+
3
+ Browser-safe domain layer for **observing coding agents** — Claude Code, opencode, and (soon) Codex — from the OpenTelemetry **metrics and log events** they emit.
4
+
5
+ It turns a stream of decoded OTLP records into a session-centric model you can render: who did what, which tools and MCP servers were used, how many tokens/dollars, accept vs reject.
6
+
7
+ > This package does **no I/O**. The [`autotel-devtools`](../autotel-devtools) server decodes OTLP (JSON/protobuf), feeds plain objects in, and the devtools widget renders the resulting sessions. Nothing here imports `node:*`, `protobufjs`, or `ws` — enforced by an ESLint browser-safety guard — so the same code runs in the browser and on the server.
8
+
9
+ ## Why this exists
10
+
11
+ Coding agents don't emit traces — they emit **metrics** (`*.token.usage`, `*.cost.usage`, `*.lines_of_code.count`, …) and **log events** (`api_request`, `tool_result`, `tool_decision`, `user_prompt`, `api_error`). opencode deliberately mirrors Claude Code's contract under an `opencode.` prefix, so one adapter shape covers many agents.
12
+
13
+ ## Model
14
+
15
+ ```
16
+ OtelMetricRecord ─┐
17
+ ├─ adapter registry (by scope + name prefix) ─→ AgentSession
18
+ AgentRawEvent ─┘ ├─ rollup (kept forever)
19
+ └─ timeline (ring-buffered)
20
+ ```
21
+
22
+ - **Events are authoritative** for the timeline and for cost/token totals (per-request, cache-accurate).
23
+ - **Metrics fill metric-only gaps** (lines of code, commits, PRs, active time) by `session.id`.
24
+ - `token.usage` / `cost.usage` **metrics are recognized but never summed** — they overlap `api_request` events, so summing both would double-count.
25
+
26
+ ## Usage (server side)
27
+
28
+ ```ts
29
+ import { ingestEventRecord, ingestMetricRecord, summarizeSessions } from 'autotel-agents';
30
+ import type { AgentSessionStore } from 'autotel-agents';
31
+
32
+ const store: AgentSessionStore = new Map();
33
+
34
+ // after decoding an OTLP log record / metric:
35
+ ingestEventRecord(store, decodedLogRecord); // { eventName, timestamp, attributes, resource, scope }
36
+ ingestMetricRecord(store, decodedMetric); // { name, dataPoints, resource, scope }
37
+
38
+ const sessions = [...store.values()]; // broadcast to the widget
39
+ const aggregate = summarizeSessions(sessions); // cost, models, MCP servers across sessions
40
+ ```
41
+
42
+ ## MCP visibility
43
+
44
+ Claude Code names MCP tools `mcp__<server>__<tool>`, and those names flow through `tool_result` / `tool_decision`. `parseToolName` splits them so you can break usage down by MCP server:
45
+
46
+ ```ts
47
+ parseToolName('mcp__github__create_issue');
48
+ // → { name, isMcp: true, mcpServer: 'github', mcpTool: 'create_issue' }
49
+ ```
50
+
51
+ ## Adding an agent
52
+
53
+ ```ts
54
+ import { createPrefixAdapter } from 'autotel-agents';
55
+
56
+ export const codexAdapter = createPrefixAdapter({
57
+ kind: 'codex',
58
+ prefix: 'codex.',
59
+ scopeHint: 'codex',
60
+ });
61
+ ```
62
+
63
+ Register it in `src/adapters/registry.ts`. No reducer or UI changes.
64
+
65
+ ## License
66
+
67
+ MIT