llmtop 0.0.0-stage → 0.1.1
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 +21 -0
- package/README.md +114 -2
- package/bin/llmtop.mjs +101 -0
- package/dashboard/dist/apple-touch-icon.png +0 -0
- package/dashboard/dist/assets/index-BVbAwMVB.js +9 -0
- package/dashboard/dist/assets/index-Cp7Swcz5.css +1 -0
- package/dashboard/dist/assets/llmtop-lockup-DtFPJmhv.svg +1 -0
- package/dashboard/dist/assets/llmtop-lockup-reversed-D9OmQIVU.svg +1 -0
- package/dashboard/dist/favicon.ico +0 -0
- package/dashboard/dist/favicon.svg +1 -0
- package/dashboard/dist/index.html +19 -0
- package/dashboard/dist/llmtop-mark-192.png +0 -0
- package/dashboard/dist/llmtop-mark-512.png +0 -0
- package/dashboard/dist/site.webmanifest +11 -0
- package/dashboard/src/App.tsx +213 -0
- package/dashboard/src/controls/DateRange.tsx +108 -0
- package/dashboard/src/controls/Disclosure.tsx +15 -0
- package/dashboard/src/controls/Search.tsx +18 -0
- package/dashboard/src/controls/Select.tsx +48 -0
- package/dashboard/src/controls/popover.tsx +31 -0
- package/dashboard/src/dash.ts +23 -0
- package/dashboard/src/extra.test.ts +9 -0
- package/dashboard/src/extra.ts +16 -0
- package/dashboard/src/format.ts +29 -0
- package/dashboard/src/i18n.tsx +52 -0
- package/dashboard/src/index.ts +7 -0
- package/dashboard/src/main.tsx +7 -0
- package/dashboard/src/model.test.ts +110 -0
- package/dashboard/src/model.ts +255 -0
- package/dashboard/src/state.test.ts +48 -0
- package/dashboard/src/state.ts +61 -0
- package/dashboard/src/styles.css +401 -0
- package/dashboard/src/tip.ts +51 -0
- package/dashboard/src/treemap.test.ts +23 -0
- package/dashboard/src/treemap.ts +30 -0
- package/dashboard/src/ui.tsx +327 -0
- package/dashboard/src/views/Activity.tsx +177 -0
- package/dashboard/src/views/Context.tsx +183 -0
- package/dashboard/src/views/Models.tsx +155 -0
- package/dashboard/src/views/Overview.tsx +83 -0
- package/dashboard/src/views/Projects.tsx +116 -0
- package/dashboard/src/views/Sessions.tsx +54 -0
- package/dashboard/src/views/Subagents.tsx +102 -0
- package/docs/brand/README.md +91 -0
- package/docs/brand/brand.json +67 -0
- package/docs/brand/favicon.ico +0 -0
- package/docs/brand/png/apple-touch-icon.png +0 -0
- package/docs/brand/png/favicon-16.png +0 -0
- package/docs/brand/png/favicon-32.png +0 -0
- package/docs/brand/png/favicon-48.png +0 -0
- package/docs/brand/png/llmtop-lockup-reversed@2x.png +0 -0
- package/docs/brand/png/llmtop-lockup@2x.png +0 -0
- package/docs/brand/png/llmtop-mark-1024.png +0 -0
- package/docs/brand/png/llmtop-mark-192.png +0 -0
- package/docs/brand/png/llmtop-mark-512.png +0 -0
- package/docs/brand/png/llmtop-wordmark@2x.png +0 -0
- package/docs/brand/source/build_brand.py +173 -0
- package/docs/brand/svg/favicon.svg +1 -0
- package/docs/brand/svg/llmtop-glyph.svg +1 -0
- package/docs/brand/svg/llmtop-lockup-reversed.svg +1 -0
- package/docs/brand/svg/llmtop-lockup.svg +1 -0
- package/docs/brand/svg/llmtop-mark-light.svg +1 -0
- package/docs/brand/svg/llmtop-mark.svg +1 -0
- package/docs/brand/svg/llmtop-wordmark-reversed.svg +1 -0
- package/docs/brand/svg/llmtop-wordmark.svg +1 -0
- package/llmtop.config.example.json +10 -0
- package/package.json +73 -4
- package/prices.md +27 -0
- package/src/api.mjs +53 -0
- package/src/archive.mjs +142 -0
- package/src/config.mjs +55 -0
- package/src/context.mjs +151 -0
- package/src/dashboard.mjs +61 -0
- package/src/db.mjs +102 -0
- package/src/derive.mjs +346 -0
- package/src/effort.mjs +18 -0
- package/src/format.mjs +19 -0
- package/src/paths.mjs +82 -0
- package/src/prices-command.mjs +25 -0
- package/src/prices.mjs +146 -0
- package/src/providers/agy.mjs +438 -0
- package/src/providers/claude.mjs +274 -0
- package/src/providers/codex.mjs +589 -0
- package/src/providers/index.mjs +25 -0
- package/src/rebuilds.mjs +85 -0
- package/src/scan.mjs +214 -0
- package/src/serve.mjs +44 -0
- package/src/show.mjs +20 -0
- package/src/usage-command.mjs +110 -0
- package/src/usage.mjs +388 -0
- package/src/zone.mjs +15 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// Everything that knows the Claude Code transcript format: where transcripts sit in the projects folder,
|
|
2
|
+
// the shapes of their records, and the subagent meta files. Tool output is never stored.
|
|
3
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { join, relative, sep } from "node:path";
|
|
6
|
+
import { createPathTracker, extractCommandDirs } from "../paths.mjs";
|
|
7
|
+
import { zoner } from "../zone.mjs";
|
|
8
|
+
|
|
9
|
+
const isDir = (p) => {
|
|
10
|
+
try {
|
|
11
|
+
return statSync(p).isDirectory();
|
|
12
|
+
} catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const list = (p) => (isDir(p) ? readdirSync(p, { withFileTypes: true }) : []);
|
|
17
|
+
|
|
18
|
+
// Describe a transcript by its path relative to the projects folder:
|
|
19
|
+
// <slug>/<session>.jsonl (main) or <slug>/<session>/subagents/agent-<id>.jsonl (sub).
|
|
20
|
+
export function describe(rel) {
|
|
21
|
+
const parts = rel.split(sep);
|
|
22
|
+
if (parts.length === 2 && parts[1].endsWith(".jsonl")) return { rel, kind: "main", slug: parts[0], sessionId: parts[1].slice(0, -6), agentId: null };
|
|
23
|
+
if (parts.length === 4 && parts[2] === "subagents" && /^agent-.+\.jsonl$/.test(parts[3]))
|
|
24
|
+
return { rel, kind: "sub", slug: parts[0], sessionId: parts[1], agentId: parts[3].slice(6, -6) };
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Transcripts and other session-folder files under a projects folder.
|
|
29
|
+
export function listHost(root) {
|
|
30
|
+
const transcripts = [];
|
|
31
|
+
const others = [];
|
|
32
|
+
for (const slug of list(root)) {
|
|
33
|
+
if (!slug.isDirectory()) continue;
|
|
34
|
+
const slugDir = join(root, slug.name);
|
|
35
|
+
for (const entry of list(slugDir)) {
|
|
36
|
+
if (entry.isFile() && entry.name.endsWith(".jsonl")) transcripts.push(describe(join(slug.name, entry.name)));
|
|
37
|
+
if (!entry.isDirectory() || !/^[0-9a-f-]{36}$/.test(entry.name)) continue;
|
|
38
|
+
const walk = (dir) => {
|
|
39
|
+
for (const e of list(dir)) {
|
|
40
|
+
const abs = join(dir, e.name);
|
|
41
|
+
if (e.isDirectory()) walk(abs);
|
|
42
|
+
else if (e.isFile()) {
|
|
43
|
+
const d = describe(relative(root, abs));
|
|
44
|
+
if (d) transcripts.push(d);
|
|
45
|
+
else others.push(relative(root, abs));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
walk(join(slugDir, entry.name));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return { transcripts, others };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const FAMILIES = ["opus", "sonnet", "haiku", "fable"];
|
|
56
|
+
export const defaultPath = "~/.claude/projects";
|
|
57
|
+
export const label = "Claude";
|
|
58
|
+
const FAMILY_NAMES = { opus: "Opus", sonnet: "Sonnet", haiku: "Haiku", fable: "Fable" };
|
|
59
|
+
export const familyOf = (model) => FAMILIES.find((f) => model.includes(f)) ?? model;
|
|
60
|
+
export const displayModel = (family) => FAMILY_NAMES[family] ?? family;
|
|
61
|
+
|
|
62
|
+
// Text blocks that are not the owner's words even when they sit in a user record.
|
|
63
|
+
const NOT_OWNER = ["<system-reminder>", "<task-notification>", "<local-command", "<bash-", "Caveat:", "This session is being continued", "[Request interrupted"];
|
|
64
|
+
|
|
65
|
+
// The owner's typed text in a user record, or null. A slash command keeps its name and arguments.
|
|
66
|
+
export function ownerText(rec) {
|
|
67
|
+
if (rec.type !== "user" || rec.isMeta || rec.isSidechain || rec.isCompactSummary || rec.toolUseResult) return null;
|
|
68
|
+
// Turns started by another session, an SDK call or a task notification are not typed by the owner.
|
|
69
|
+
if (rec.turnOrigin && rec.turnOrigin !== "human") return null;
|
|
70
|
+
if (rec.origin?.kind && rec.origin.kind !== "human") return null;
|
|
71
|
+
const content = rec.message?.content;
|
|
72
|
+
const blocks = typeof content === "string" ? [content] : Array.isArray(content) ? content.filter((b) => b.type === "text").map((b) => b.text ?? "") : [];
|
|
73
|
+
if (Array.isArray(content) && content.some((b) => b.type === "tool_result")) return null;
|
|
74
|
+
const kept = [];
|
|
75
|
+
for (const raw of blocks) {
|
|
76
|
+
const text = raw.trim();
|
|
77
|
+
if (!text) continue;
|
|
78
|
+
const command = text.match(/<command-name>([^<]*)<\/command-name>/);
|
|
79
|
+
if (command) {
|
|
80
|
+
const args = text.match(/<command-args>([\s\S]*?)<\/command-args>/)?.[1].trim();
|
|
81
|
+
kept.push(args ? `${command[1]} ${args}` : command[1]);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (text.startsWith("<command-message>") || NOT_OWNER.some((p) => text.startsWith(p))) continue;
|
|
85
|
+
kept.push(text);
|
|
86
|
+
}
|
|
87
|
+
return kept.length ? kept.join("\n\n") : null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Where a skill was loaded from, by the folder the host names when it loads one: the host's own bundled skills,
|
|
91
|
+
// a plugin's, the user's own under ~/.claude/skills, or a project's .claude/skills.
|
|
92
|
+
export function skillSource(dir, home = homedir()) {
|
|
93
|
+
if (dir.includes("/bundled-skills/")) return "builtin";
|
|
94
|
+
if (dir.includes("/skills-plugin/") || dir.includes("/.claude/plugins/")) return "plugin";
|
|
95
|
+
if (dir.startsWith(join(home, ".claude", "skills") + sep)) return "personal";
|
|
96
|
+
if (dir.includes(`${sep}.claude${sep}skills${sep}`)) return "project";
|
|
97
|
+
return "other";
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const textOf = (content) => (typeof content === "string" ? content : Array.isArray(content) ? content.filter((b) => b?.type === "text").map((b) => b.text ?? "").join("\n") : "");
|
|
101
|
+
|
|
102
|
+
// hasFile(sessionId): whether a main transcript of that session is known; its records are left to it.
|
|
103
|
+
export function createIngester(db, timeZone, hasFile = () => false) {
|
|
104
|
+
const zone = zoner(timeZone);
|
|
105
|
+
const q = {
|
|
106
|
+
record: db.prepare("INSERT OR IGNORE INTO records(uuid, file_id, line, type, ts) VALUES (?, ?, ?, ?, ?)"),
|
|
107
|
+
repeat: db.prepare("INSERT OR IGNORE INTO repeats(file_id, message_id) VALUES (?, ?)"),
|
|
108
|
+
request: db.prepare(`INSERT OR IGNORE INTO requests(message_id, file_id, line, session_id, agent_id, ts, day, hour, model, family,
|
|
109
|
+
effort, is_sub, input, output, thinking, cache_read, cache_write, cache_write_1h) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`),
|
|
110
|
+
owner: db.prepare("INSERT OR IGNORE INTO owner_messages(uuid, file_id, line, session_id, ts, kind, text) VALUES (?, ?, ?, ?, ?, ?, ?)"),
|
|
111
|
+
call: db.prepare("INSERT OR IGNORE INTO tool_calls(id, file_id, line, session_id, agent_id, ts, name, model, is_error) VALUES (?, ?, ?, ?, ?, ?, ?, ?, NULL)"),
|
|
112
|
+
result: db.prepare("UPDATE tool_calls SET is_error = ? WHERE id = ?"),
|
|
113
|
+
skill: db.prepare("INSERT OR IGNORE INTO skills(id, file_id, line, session_id, ts, name, via, source) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"),
|
|
114
|
+
skillResult: db.prepare("UPDATE skills SET is_error = ? WHERE id = ?"),
|
|
115
|
+
skillSource: db.prepare("UPDATE skills SET source = ? WHERE id = ?"),
|
|
116
|
+
compaction: db.prepare(`INSERT OR IGNORE INTO compactions(uuid, file_id, line, session_id, agent_id, ts, trigger, pre_tokens, post_tokens, duration_ms)
|
|
117
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`),
|
|
118
|
+
boundaryBefore: db.prepare("SELECT 1 FROM compactions WHERE file_id = ? AND line BETWEEN ? AND ? AND trigger IS NOT NULL LIMIT 1"),
|
|
119
|
+
cost: db.prepare(`INSERT OR REPLACE INTO cost_states(file_id, line, session_id, start_ms, cost, incomplete, api_ms, tool_ms,
|
|
120
|
+
lines_added, lines_removed, model_usage) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`),
|
|
121
|
+
title: db.prepare("INSERT OR REPLACE INTO titles(file_id, line, session_id, kind, title) VALUES (?, ?, ?, ?, ?)"),
|
|
122
|
+
getTargetPaths: db.prepare("SELECT target_paths FROM file_meta WHERE file_id = ?"),
|
|
123
|
+
upsertTargetPaths: db.prepare(`INSERT INTO file_meta(file_id, target_paths) VALUES (?, ?)
|
|
124
|
+
ON CONFLICT(file_id) DO UPDATE SET target_paths = excluded.target_paths`),
|
|
125
|
+
};
|
|
126
|
+
const stateByFile = new Map();
|
|
127
|
+
const CLAUDE_WRITE_TOOLS = new Set(["Edit", "Write", "MultiEdit", "NotebookEdit"]);
|
|
128
|
+
const CLAUDE_READ_TOOLS = new Set(["Read", "Grep", "Glob"]);
|
|
129
|
+
|
|
130
|
+
// file: { id, kind, session_id, agent_id }. Returns how many records were added, and the line's cwd and timestamp.
|
|
131
|
+
return function ingestLine(file, line, text) {
|
|
132
|
+
let rec;
|
|
133
|
+
try {
|
|
134
|
+
rec = JSON.parse(text);
|
|
135
|
+
} catch {
|
|
136
|
+
return { added: 0 };
|
|
137
|
+
}
|
|
138
|
+
if (!rec || typeof rec !== "object" || rec.type === "session-owner") return { added: 0 };
|
|
139
|
+
const session = file.session_id;
|
|
140
|
+
const agent = file.agent_id;
|
|
141
|
+
// A line copied into a continuation or fork keeps the id of the session that wrote it.
|
|
142
|
+
const foreign = Boolean(rec.sessionId) && rec.sessionId !== session;
|
|
143
|
+
const seen = { cwd: rec.cwd, ts: rec.timestamp, own: rec.sessionId === session };
|
|
144
|
+
let st = stateByFile.get(file.id);
|
|
145
|
+
if (!st) {
|
|
146
|
+
const prev = file.lines > 0 ? q.getTargetPaths.get(file.id) : null;
|
|
147
|
+
st = { launchCwd: file.cwd ?? null, cwd: file.cwd ?? null, paths: createPathTracker(prev?.target_paths ?? null) };
|
|
148
|
+
stateByFile.set(file.id, st);
|
|
149
|
+
}
|
|
150
|
+
let pathsDirty = false;
|
|
151
|
+
if (!foreign && rec.cwd) {
|
|
152
|
+
st.launchCwd ??= rec.cwd;
|
|
153
|
+
st.cwd = rec.cwd;
|
|
154
|
+
if (rec.cwd !== st.launchCwd && st.paths.add(rec.cwd, { write: false })) pathsDirty = true;
|
|
155
|
+
}
|
|
156
|
+
const flushPaths = () => {
|
|
157
|
+
if (!pathsDirty) return;
|
|
158
|
+
const json = st.paths.toJSON();
|
|
159
|
+
if (json) q.upsertTargetPaths.run(file.id, json);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
if (rec.type === "cost-state") {
|
|
163
|
+
// Per model: the host's cost and the tokens it priced; `split` tells whether 5m and 1h cache writes are told apart.
|
|
164
|
+
const models = Object.fromEntries(Object.entries(rec.modelUsage ?? {}).map(([m, u]) => [m, {
|
|
165
|
+
cost: u?.costUSD ?? null, input: u?.inputTokens ?? 0, output: u?.outputTokens ?? 0, read: u?.cacheReadInputTokens ?? 0,
|
|
166
|
+
write: u?.cacheCreationInputTokens ?? 0, w5: u?.cacheCreationEphemeral5mInputTokens ?? 0, w1: u?.cacheCreationEphemeral1hInputTokens ?? 0,
|
|
167
|
+
split: u?.cacheCreationEphemeral5mInputTokens !== undefined || u?.cacheCreationEphemeral1hInputTokens !== undefined, web: u?.webSearchRequests ?? 0,
|
|
168
|
+
}]));
|
|
169
|
+
q.cost.run(file.id, line, session, rec.startTime ?? null, rec.totalCostUSD ?? null, rec.hasUnknownModelCost ? 1 : 0,
|
|
170
|
+
rec.totalAPIDuration ?? null, rec.totalToolDuration ?? null, rec.totalLinesAdded ?? null, rec.totalLinesRemoved ?? null, JSON.stringify(models));
|
|
171
|
+
flushPaths();
|
|
172
|
+
return { added: 1, ...seen };
|
|
173
|
+
}
|
|
174
|
+
if (rec.type === "custom-title" && rec.customTitle) {
|
|
175
|
+
q.title.run(file.id, line, session, "custom", rec.customTitle);
|
|
176
|
+
flushPaths();
|
|
177
|
+
return { added: 1, ...seen };
|
|
178
|
+
}
|
|
179
|
+
if (rec.type === "ai-title" && rec.aiTitle) {
|
|
180
|
+
q.title.run(file.id, line, session, "ai", rec.aiTitle);
|
|
181
|
+
flushPaths();
|
|
182
|
+
return { added: 1, ...seen };
|
|
183
|
+
}
|
|
184
|
+
if (!rec.uuid) { flushPaths(); return { added: 0, ...seen }; }
|
|
185
|
+
|
|
186
|
+
// A copied record belongs to the file of the session that wrote it, whichever file is read first;
|
|
187
|
+
// here only note which requests it repeats. A copy whose original file is gone is kept here.
|
|
188
|
+
if ((foreign && hasFile(rec.sessionId)) || q.record.run(rec.uuid, file.id, line, rec.type, rec.timestamp ?? null).changes === 0) {
|
|
189
|
+
if (rec.type === "assistant" && rec.message?.id) q.repeat.run(file.id, rec.message.id);
|
|
190
|
+
return { added: 0, ...seen, own: false };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (rec.type === "system" && rec.subtype === "compact_boundary") {
|
|
194
|
+
// The boundary carries what the compaction did; the summary record after it names it as the anchor of what was kept,
|
|
195
|
+
// so both resolve to one row keyed by the summary.
|
|
196
|
+
const m = rec.compactMetadata ?? {};
|
|
197
|
+
const key = m.preservedSegment?.anchorUuid ?? m.preservedMessages?.anchorUuid ?? rec.uuid;
|
|
198
|
+
q.compaction.run(key, file.id, line, session, agent, rec.timestamp ?? null, m.trigger ?? null, m.preTokens ?? null, m.postTokens ?? null, m.durationMs ?? null);
|
|
199
|
+
} else if (rec.type === "assistant") {
|
|
200
|
+
const msg = rec.message ?? {};
|
|
201
|
+
const u = msg.usage;
|
|
202
|
+
if (msg.id && u && msg.model !== "<synthetic>" && rec.timestamp) {
|
|
203
|
+
const { day, hour } = zone(rec.timestamp);
|
|
204
|
+
q.request.run(msg.id, file.id, line, session, agent, rec.timestamp, day, hour, msg.model ?? "unknown", familyOf(msg.model ?? "unknown"),
|
|
205
|
+
rec.effort ?? null, file.kind === "sub" ? 1 : 0, u.input_tokens ?? 0, u.output_tokens ?? 0,
|
|
206
|
+
u.output_tokens_details?.thinking_tokens ?? 0, u.cache_read_input_tokens ?? 0, u.cache_creation_input_tokens ?? 0,
|
|
207
|
+
u.cache_creation?.ephemeral_1h_input_tokens ?? null);
|
|
208
|
+
}
|
|
209
|
+
for (const b of Array.isArray(msg.content) ? msg.content : []) {
|
|
210
|
+
if (b?.type === "tool_use" && b.id) {
|
|
211
|
+
q.call.run(b.id, file.id, line, session, agent, rec.timestamp ?? null, b.name ?? "unknown", msg.model ?? null);
|
|
212
|
+
if (CLAUDE_WRITE_TOOLS.has(b.name)) {
|
|
213
|
+
const fp = b.input?.file_path ?? b.input?.notebook_path;
|
|
214
|
+
if (st.paths.add(fp, { isFile: true, write: true, baseCwd: st.cwd })) pathsDirty = true;
|
|
215
|
+
} else if (CLAUDE_READ_TOOLS.has(b.name)) {
|
|
216
|
+
if (b.input?.file_path && st.paths.add(b.input.file_path, { isFile: true, write: false, baseCwd: st.cwd })) pathsDirty = true;
|
|
217
|
+
if (b.input?.path && st.paths.add(b.input.path, { isFile: false, write: false, baseCwd: st.cwd })) pathsDirty = true;
|
|
218
|
+
} else if (b.name === "Bash" && typeof b.input?.command === "string") {
|
|
219
|
+
for (const dir of extractCommandDirs(b.input.command, st.cwd)) {
|
|
220
|
+
if (st.paths.add(dir, { write: false })) pathsDirty = true;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// A skill the agent called; a plugin's skill is named plugin:skill. Its folder, when the host loads it, follows.
|
|
225
|
+
if (b?.type === "tool_use" && b.id && b.name === "Skill") {
|
|
226
|
+
const name = String(b.input?.skill ?? "unknown").replace(/^\//, "");
|
|
227
|
+
q.skill.run(b.id, file.id, line, session, rec.timestamp ?? null, name, "agent", name.includes(":") ? "plugin" : null);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
} else if (rec.type === "user") {
|
|
231
|
+
const content = rec.message?.content;
|
|
232
|
+
for (const b of Array.isArray(content) ? content : []) {
|
|
233
|
+
if (b?.type === "tool_result" && b.tool_use_id) {
|
|
234
|
+
q.result.run(b.is_error ? 1 : 0, b.tool_use_id);
|
|
235
|
+
q.skillResult.run(b.is_error ? 1 : 0, b.tool_use_id);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const body = textOf(content);
|
|
239
|
+
// The host loads a skill with a record naming its folder, tied to the agent's call or to the typed command before it.
|
|
240
|
+
const loaded = rec.isMeta && body.match(/^Base directory for this skill: (.+)/);
|
|
241
|
+
if (loaded) q.skillSource.run(skillSource(loaded[1].trim()), rec.sourceToolUseID ?? rec.parentUuid ?? "");
|
|
242
|
+
// A typed slash command; it counts as a skill once the host loads one for it, which a built-in command never does.
|
|
243
|
+
const command = file.kind === "main" && !rec.isMeta && !rec.isSidechain && body.match(/<command-name>\/?([^<]+)<\/command-name>/);
|
|
244
|
+
if (command) q.skill.run(rec.uuid, file.id, line, session, rec.timestamp ?? null, command[1].trim(), "command", null);
|
|
245
|
+
// A summary with no boundary just before it (older hosts) still counts, without the boundary's figures.
|
|
246
|
+
if (rec.isCompactSummary && !q.boundaryBefore.get(file.id, line - 50, line)) q.compaction.run(rec.uuid, file.id, line, session, agent, rec.timestamp ?? null, null, null, null, null);
|
|
247
|
+
if (file.kind === "main") {
|
|
248
|
+
const typed = ownerText(rec);
|
|
249
|
+
if (typed) q.owner.run(rec.uuid, file.id, line, session, rec.timestamp ?? null, "typed", typed);
|
|
250
|
+
const answers = rec.toolUseResult?.answers;
|
|
251
|
+
if (answers && typeof answers === "object" && !rec.isSidechain) {
|
|
252
|
+
Object.values(answers).forEach((a, i) => {
|
|
253
|
+
if (typeof a === "string" && a.trim()) q.owner.run(`${rec.uuid}#${i}`, file.id, line, session, rec.timestamp ?? null, "popup", a.trim());
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
flushPaths();
|
|
259
|
+
return { added: 1, ...seen };
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// The type and parent tool call of a subagent, from the meta file archived beside its transcript.
|
|
264
|
+
export function subagentMeta(archiveDir, d) {
|
|
265
|
+
try {
|
|
266
|
+
const m = JSON.parse(readFileSync(join(archiveDir, d.rel.replace(/\.jsonl$/, ".meta.json")), "utf8"));
|
|
267
|
+
return { type: m.agentType ?? null, toolUseId: m.toolUseId ?? null };
|
|
268
|
+
} catch {
|
|
269
|
+
// No readable meta file: the subagent has no recorded type.
|
|
270
|
+
return { type: null, toolUseId: null };
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export const claude = { name: "claude", label, defaultPath, describe, listHost, createIngester, subagentMeta, familyOf, displayModel };
|