xtrium 0.1.0 → 0.2.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/README.md +5 -0
- package/dist/index.js +342 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,6 +48,11 @@ bundle again and refuses it if a secret is left.
|
|
|
48
48
|
skills and hooks (from `~/.claude` and each project's `.claude` folder; never their contents or commands).
|
|
49
49
|
- **Codex:** `~/.codex/sessions/**/rollout-*.jsonl` (or under `$CODEX_HOME`).
|
|
50
50
|
|
|
51
|
+
From each session it also keeps, as numbers and model ids only: the model and effort level of each response, how
|
|
52
|
+
many tokens of context it read and wrote, and when the conversation was compacted (with the token counts before and
|
|
53
|
+
after, where the tool records them). These show on the review page next to the rest and become facts such as your
|
|
54
|
+
largest context window and how often you compact.
|
|
55
|
+
|
|
51
56
|
Reading is local. `scan`, `review` and `card` send nothing anywhere; only `upload` and `card --share` do (when you are signed in, `card` also asks the server for your handle, for the footer). Damaged lines are skipped and counted, and files in a format the
|
|
52
57
|
CLI does not know are listed as unsupported instead of stopping the scan.
|
|
53
58
|
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { spinner } from "@clack/prompts";
|
|
|
9
9
|
// package.json
|
|
10
10
|
var package_default = {
|
|
11
11
|
name: "xtrium",
|
|
12
|
-
version: "0.
|
|
12
|
+
version: "0.2.0",
|
|
13
13
|
description: "Upload a redacted, reviewed record of how you work with AI coding tools to your Xtrium Atrium.",
|
|
14
14
|
homepage: "https://xtrium.co",
|
|
15
15
|
license: "MIT",
|
|
@@ -104,7 +104,7 @@ import { z as z2 } from "zod";
|
|
|
104
104
|
var AI_WORKFLOW_TOOLS = ["claude_code", "codex"];
|
|
105
105
|
var aiWorkflowToolSchema = z2.enum(AI_WORKFLOW_TOOLS);
|
|
106
106
|
var BUNDLE_FORMAT = "xtrium-ai-workflow";
|
|
107
|
-
var BUNDLE_VERSION =
|
|
107
|
+
var BUNDLE_VERSION = 2;
|
|
108
108
|
var MIB = 1024 * 1024;
|
|
109
109
|
var BUNDLE_MAX_BYTES = 64 * MIB;
|
|
110
110
|
var BUNDLE_MAX_UNCOMPRESSED_BYTES = 512 * MIB;
|
|
@@ -119,6 +119,18 @@ var sha256HexSchema = z2.string().regex(/^[0-9a-f]{64}$/);
|
|
|
119
119
|
var isoSchema = z2.iso.datetime({ offset: true });
|
|
120
120
|
var shortText = (max) => z2.string().max(max);
|
|
121
121
|
var eventBase = { at: isoSchema.optional() };
|
|
122
|
+
var modelIdSchema = z2.string().regex(/^[A-Za-z0-9][A-Za-z0-9._:/[\]-]{0,99}$/);
|
|
123
|
+
var AI_WORKFLOW_EFFORTS = [
|
|
124
|
+
"none",
|
|
125
|
+
"minimal",
|
|
126
|
+
"low",
|
|
127
|
+
"medium",
|
|
128
|
+
"high",
|
|
129
|
+
"xhigh",
|
|
130
|
+
"max"
|
|
131
|
+
];
|
|
132
|
+
var effortSchema = z2.enum(AI_WORKFLOW_EFFORTS);
|
|
133
|
+
var tokenCountSchema = z2.number().int().min(0).max(1e8);
|
|
122
134
|
var bundleEventSchema = z2.discriminatedUnion("kind", [
|
|
123
135
|
z2.object({ kind: z2.literal("user_prompt"), text: shortText(EVENT_TEXT_MAX + 64), ...eventBase }).strict(),
|
|
124
136
|
z2.object({
|
|
@@ -130,6 +142,8 @@ var bundleEventSchema = z2.discriminatedUnion("kind", [
|
|
|
130
142
|
kind: z2.literal("tool_call"),
|
|
131
143
|
name: shortText(200),
|
|
132
144
|
argsSummary: shortText(400),
|
|
145
|
+
/** The model a subagent call (`Agent`, `Task`) asked for, when it named one. */
|
|
146
|
+
model: modelIdSchema.optional(),
|
|
133
147
|
...eventBase
|
|
134
148
|
}).strict(),
|
|
135
149
|
z2.object({
|
|
@@ -144,13 +158,33 @@ var bundleEventSchema = z2.discriminatedUnion("kind", [
|
|
|
144
158
|
path: shortText(1100),
|
|
145
159
|
linesChanged: z2.number().int().min(0),
|
|
146
160
|
...eventBase
|
|
161
|
+
}).strict(),
|
|
162
|
+
/**
|
|
163
|
+
* One model response: the model and effort it ran with (null when not recorded), the context it read (input, cache
|
|
164
|
+
* read and cache creation tokens) and the tokens it wrote. Counts and ids only, never content.
|
|
165
|
+
*/
|
|
166
|
+
z2.object({
|
|
167
|
+
kind: z2.literal("model_turn"),
|
|
168
|
+
model: modelIdSchema.nullable(),
|
|
169
|
+
effort: effortSchema.nullable(),
|
|
170
|
+
contextTokens: tokenCountSchema,
|
|
171
|
+
outputTokens: tokenCountSchema,
|
|
172
|
+
...eventBase
|
|
173
|
+
}).strict(),
|
|
174
|
+
/** The tool compacted the conversation: how it was started and the context before and after, when recorded. */
|
|
175
|
+
z2.object({
|
|
176
|
+
kind: z2.literal("compaction"),
|
|
177
|
+
trigger: z2.enum(["manual", "auto"]).nullable(),
|
|
178
|
+
preTokens: tokenCountSchema.nullable(),
|
|
179
|
+
postTokens: tokenCountSchema.nullable(),
|
|
180
|
+
...eventBase
|
|
147
181
|
}).strict()
|
|
148
182
|
]);
|
|
149
183
|
var countSchema = z2.number().int().min(0);
|
|
150
184
|
var bundleHeaderSchema = z2.object({
|
|
151
185
|
type: z2.literal("header"),
|
|
152
186
|
format: z2.literal(BUNDLE_FORMAT),
|
|
153
|
-
version: z2.literal(
|
|
187
|
+
version: z2.union([z2.literal(1), z2.literal(2)]),
|
|
154
188
|
cliVersion: shortText(40).min(1),
|
|
155
189
|
createdAt: isoSchema,
|
|
156
190
|
tools: z2.array(
|
|
@@ -275,7 +309,8 @@ var uploadErrorSchema = z2.object({
|
|
|
275
309
|
"rate_limited",
|
|
276
310
|
"not_found",
|
|
277
311
|
"not_uploading",
|
|
278
|
-
"upload_incomplete"
|
|
312
|
+
"upload_incomplete",
|
|
313
|
+
"library_full"
|
|
279
314
|
]),
|
|
280
315
|
message: z2.string().max(300)
|
|
281
316
|
});
|
|
@@ -572,9 +607,10 @@ async function uploadFailure(response) {
|
|
|
572
607
|
value = await response.json();
|
|
573
608
|
} catch {
|
|
574
609
|
}
|
|
575
|
-
const parsed =
|
|
610
|
+
const parsed = uploadErrorMessageSchema.safeParse(value);
|
|
576
611
|
return parsed.success ? new CliError(parsed.data.message) : unexpected(response);
|
|
577
612
|
}
|
|
613
|
+
var uploadErrorMessageSchema = uploadErrorSchema.pick({ message: true });
|
|
578
614
|
|
|
579
615
|
// src/config.ts
|
|
580
616
|
import { homedir } from "os";
|
|
@@ -1013,7 +1049,150 @@ function sessionSignals(session) {
|
|
|
1013
1049
|
function skillName(args) {
|
|
1014
1050
|
return args.trim().split(/\s+/)[0]?.replace(/^\//, "").toLowerCase().slice(0, 120) ?? "";
|
|
1015
1051
|
}
|
|
1052
|
+
function sessionContext(session) {
|
|
1053
|
+
const out = {
|
|
1054
|
+
turns: 0,
|
|
1055
|
+
windowPeaks: [],
|
|
1056
|
+
compactions: [],
|
|
1057
|
+
models: /* @__PURE__ */ new Map(),
|
|
1058
|
+
efforts: /* @__PURE__ */ new Map(),
|
|
1059
|
+
subagentCalls: 0,
|
|
1060
|
+
subagentCallsOtherModel: 0
|
|
1061
|
+
};
|
|
1062
|
+
let peak = 0;
|
|
1063
|
+
let model = null;
|
|
1064
|
+
const close = (reported) => {
|
|
1065
|
+
const value = Math.max(peak, reported ?? 0);
|
|
1066
|
+
if (value > 0) out.windowPeaks.push(value);
|
|
1067
|
+
peak = 0;
|
|
1068
|
+
};
|
|
1069
|
+
for (const event of session.events) {
|
|
1070
|
+
if (event.kind === "model_turn") {
|
|
1071
|
+
out.turns += 1;
|
|
1072
|
+
peak = Math.max(peak, event.contextTokens);
|
|
1073
|
+
if (event.model !== null) {
|
|
1074
|
+
model = event.model;
|
|
1075
|
+
out.models.set(event.model, (out.models.get(event.model) ?? 0) + 1);
|
|
1076
|
+
}
|
|
1077
|
+
if (event.effort !== null) {
|
|
1078
|
+
out.efforts.set(event.effort, (out.efforts.get(event.effort) ?? 0) + 1);
|
|
1079
|
+
}
|
|
1080
|
+
} else if (event.kind === "compaction") {
|
|
1081
|
+
close(event.preTokens);
|
|
1082
|
+
const freed = event.preTokens !== null && event.postTokens !== null ? Math.max(0, event.preTokens - event.postTokens) : null;
|
|
1083
|
+
out.compactions.push({ trigger: event.trigger, freed });
|
|
1084
|
+
} else if (event.kind === "tool_call" && SUBAGENT_TOOLS.has(event.name)) {
|
|
1085
|
+
out.subagentCalls += 1;
|
|
1086
|
+
if (event.model !== void 0 && event.model !== model) out.subagentCallsOtherModel += 1;
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
close(null);
|
|
1090
|
+
return out;
|
|
1091
|
+
}
|
|
1092
|
+
function sessionKinds(session, signals) {
|
|
1093
|
+
const kinds = [];
|
|
1094
|
+
if (signals.planMode) kinds.push("plan_mode");
|
|
1095
|
+
if (signals.edited) kinds.push("edited_files");
|
|
1096
|
+
else if (session.events.some((event) => event.kind === "tool_call")) kinds.push("read_only");
|
|
1097
|
+
return kinds;
|
|
1098
|
+
}
|
|
1099
|
+
var MAX_MODELS = 10;
|
|
1100
|
+
var MAX_MODELS_PER_KIND = 5;
|
|
1101
|
+
function addAll(into, from) {
|
|
1102
|
+
for (const [key, n] of from) into.set(key, (into.get(key) ?? 0) + n);
|
|
1103
|
+
}
|
|
1104
|
+
function ranked(counts, max) {
|
|
1105
|
+
return [...counts.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, max);
|
|
1106
|
+
}
|
|
1107
|
+
var ContextCounter = class {
|
|
1108
|
+
sessions = 0;
|
|
1109
|
+
turns = 0;
|
|
1110
|
+
peaks = [];
|
|
1111
|
+
compactionsPerSession = [];
|
|
1112
|
+
triggers = { manual: 0, auto: 0, none: 0 };
|
|
1113
|
+
freed = [];
|
|
1114
|
+
models = /* @__PURE__ */ new Map();
|
|
1115
|
+
efforts = /* @__PURE__ */ new Map();
|
|
1116
|
+
changedModel = 0;
|
|
1117
|
+
changedEffort = 0;
|
|
1118
|
+
subagentCalls = 0;
|
|
1119
|
+
subagentCallsOtherModel = 0;
|
|
1120
|
+
kinds = /* @__PURE__ */ new Map();
|
|
1121
|
+
add(context, kinds) {
|
|
1122
|
+
if (context.turns === 0) return;
|
|
1123
|
+
this.sessions += 1;
|
|
1124
|
+
this.turns += context.turns;
|
|
1125
|
+
this.peaks.push(...context.windowPeaks);
|
|
1126
|
+
if (context.compactions.length > 0) this.compactionsPerSession.push(context.compactions.length);
|
|
1127
|
+
for (const compaction of context.compactions) {
|
|
1128
|
+
if (compaction.trigger === "manual") this.triggers.manual += 1;
|
|
1129
|
+
else if (compaction.trigger === "auto") this.triggers.auto += 1;
|
|
1130
|
+
else this.triggers.none += 1;
|
|
1131
|
+
if (compaction.freed !== null) this.freed.push(compaction.freed);
|
|
1132
|
+
}
|
|
1133
|
+
addAll(this.models, context.models);
|
|
1134
|
+
addAll(this.efforts, context.efforts);
|
|
1135
|
+
if (context.models.size > 1) this.changedModel += 1;
|
|
1136
|
+
if (context.efforts.size > 1) this.changedEffort += 1;
|
|
1137
|
+
this.subagentCalls += context.subagentCalls;
|
|
1138
|
+
this.subagentCallsOtherModel += context.subagentCallsOtherModel;
|
|
1139
|
+
for (const kind of kinds) {
|
|
1140
|
+
const entry = this.kinds.get(kind) ?? {
|
|
1141
|
+
sessions: 0,
|
|
1142
|
+
models: /* @__PURE__ */ new Map(),
|
|
1143
|
+
efforts: /* @__PURE__ */ new Map()
|
|
1144
|
+
};
|
|
1145
|
+
entry.sessions += 1;
|
|
1146
|
+
addAll(entry.models, context.models);
|
|
1147
|
+
addAll(entry.efforts, context.efforts);
|
|
1148
|
+
this.kinds.set(kind, entry);
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
finish() {
|
|
1152
|
+
if (this.sessions === 0) return void 0;
|
|
1153
|
+
const kindOrder = ["plan_mode", "edited_files", "read_only"];
|
|
1154
|
+
return {
|
|
1155
|
+
sessionsWithTurns: this.sessions,
|
|
1156
|
+
turns: this.turns,
|
|
1157
|
+
windows: this.peaks.length,
|
|
1158
|
+
windowPeakHighest: this.peaks.reduce((a, b) => Math.max(a, b), 0),
|
|
1159
|
+
windowPeakMedian: median(this.peaks) ?? 0,
|
|
1160
|
+
sessionsCompacted: this.compactionsPerSession.length,
|
|
1161
|
+
compactionsPerSessionMedian: median(this.compactionsPerSession) ?? 0,
|
|
1162
|
+
compactionsPerSessionMost: this.compactionsPerSession.reduce((a, b) => Math.max(a, b), 0),
|
|
1163
|
+
manualCompactions: this.triggers.manual,
|
|
1164
|
+
autoCompactions: this.triggers.auto,
|
|
1165
|
+
untriggeredCompactions: this.triggers.none,
|
|
1166
|
+
freedMedianTokens: median(this.freed),
|
|
1167
|
+
models: ranked(this.models, MAX_MODELS).map(([model, turns]) => ({ model, turns })),
|
|
1168
|
+
efforts: ranked(this.efforts, MAX_MODELS).map(([effort, turns]) => ({ effort, turns })),
|
|
1169
|
+
sessionsChangedModel: this.changedModel,
|
|
1170
|
+
sessionsChangedEffort: this.changedEffort,
|
|
1171
|
+
subagentCalls: this.subagentCalls,
|
|
1172
|
+
subagentCallsOtherModel: this.subagentCallsOtherModel,
|
|
1173
|
+
bySessionKind: kindOrder.flatMap((kind) => {
|
|
1174
|
+
const entry = this.kinds.get(kind);
|
|
1175
|
+
if (entry === void 0) return [];
|
|
1176
|
+
return [
|
|
1177
|
+
{
|
|
1178
|
+
kind,
|
|
1179
|
+
sessions: entry.sessions,
|
|
1180
|
+
models: ranked(entry.models, MAX_MODELS_PER_KIND).map(([model, turns]) => ({
|
|
1181
|
+
model,
|
|
1182
|
+
turns
|
|
1183
|
+
})),
|
|
1184
|
+
efforts: ranked(entry.efforts, MAX_MODELS).map(([effort, turns]) => ({
|
|
1185
|
+
effort,
|
|
1186
|
+
turns
|
|
1187
|
+
}))
|
|
1188
|
+
}
|
|
1189
|
+
];
|
|
1190
|
+
})
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1193
|
+
};
|
|
1016
1194
|
var StatsCounter = class {
|
|
1195
|
+
context = new ContextCounter();
|
|
1017
1196
|
sessions = 0;
|
|
1018
1197
|
projects = /* @__PURE__ */ new Set();
|
|
1019
1198
|
toolSessions = /* @__PURE__ */ new Map();
|
|
@@ -1039,6 +1218,7 @@ var StatsCounter = class {
|
|
|
1039
1218
|
this.projects.add(session.project);
|
|
1040
1219
|
this.toolSessions.set(session.tool, (this.toolSessions.get(session.tool) ?? 0) + 1);
|
|
1041
1220
|
const signals = sessionSignals(session);
|
|
1221
|
+
this.context.add(sessionContext(session), sessionKinds(session, signals));
|
|
1042
1222
|
if (signals.firstPromptChars !== null) this.firstPrompts.push(signals.firstPromptChars);
|
|
1043
1223
|
this.followUps += signals.followUps;
|
|
1044
1224
|
this.corrections.push(...signals.corrections);
|
|
@@ -1075,6 +1255,7 @@ var StatsCounter = class {
|
|
|
1075
1255
|
firstMonth: entry.first,
|
|
1076
1256
|
lastMonth: entry.last
|
|
1077
1257
|
})).sort((a, b) => b.sessions - a.sessions || a.topic.localeCompare(b.topic)).slice(0, MAX_TOPICS);
|
|
1258
|
+
const contextStats = this.context.finish();
|
|
1078
1259
|
return {
|
|
1079
1260
|
sessions: this.sessions,
|
|
1080
1261
|
projects: this.projects.size,
|
|
@@ -1096,7 +1277,8 @@ var StatsCounter = class {
|
|
|
1096
1277
|
corrections: this.corrections.length,
|
|
1097
1278
|
correctionMedianChars: median(this.corrections),
|
|
1098
1279
|
topics,
|
|
1099
|
-
secretsCaught: context.secretsCaught
|
|
1280
|
+
secretsCaught: context.secretsCaught,
|
|
1281
|
+
...contextStats === void 0 ? {} : { context: contextStats }
|
|
1100
1282
|
};
|
|
1101
1283
|
}
|
|
1102
1284
|
};
|
|
@@ -1398,6 +1580,21 @@ function isoOrUndefined(value) {
|
|
|
1398
1580
|
function withTime(event, at) {
|
|
1399
1581
|
return at === void 0 ? event : { ...event, at };
|
|
1400
1582
|
}
|
|
1583
|
+
function modelIdOrNull(value) {
|
|
1584
|
+
const parsed = modelIdSchema.safeParse(value);
|
|
1585
|
+
return parsed.success ? parsed.data : null;
|
|
1586
|
+
}
|
|
1587
|
+
function effortOrNull(value) {
|
|
1588
|
+
const parsed = effortSchema.safeParse(value);
|
|
1589
|
+
return parsed.success ? parsed.data : null;
|
|
1590
|
+
}
|
|
1591
|
+
var TOKENS_MAX = 1e8;
|
|
1592
|
+
function tokensOrNull(value) {
|
|
1593
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? Math.min(value, TOKENS_MAX) : null;
|
|
1594
|
+
}
|
|
1595
|
+
function tokens(value) {
|
|
1596
|
+
return tokensOrNull(value) ?? 0;
|
|
1597
|
+
}
|
|
1401
1598
|
|
|
1402
1599
|
// src/adapters/claude-setup.ts
|
|
1403
1600
|
import { readdir as readdir2, readFile as readFile3 } from "fs/promises";
|
|
@@ -1567,8 +1764,16 @@ var recordSchema = z7.looseObject({
|
|
|
1567
1764
|
isSidechain: z7.boolean().optional(),
|
|
1568
1765
|
isMeta: z7.boolean().optional(),
|
|
1569
1766
|
origin: z7.looseObject({ kind: z7.string() }).optional(),
|
|
1570
|
-
message: z7.looseObject({
|
|
1571
|
-
|
|
1767
|
+
message: z7.looseObject({
|
|
1768
|
+
content: z7.unknown(),
|
|
1769
|
+
id: z7.string().optional(),
|
|
1770
|
+
model: z7.unknown().optional(),
|
|
1771
|
+
usage: z7.looseObject({}).optional()
|
|
1772
|
+
}).optional(),
|
|
1773
|
+
toolUseResult: z7.unknown().optional(),
|
|
1774
|
+
effort: z7.unknown().optional(),
|
|
1775
|
+
subtype: z7.string().optional(),
|
|
1776
|
+
compactMetadata: z7.looseObject({}).optional()
|
|
1572
1777
|
});
|
|
1573
1778
|
var textBlockSchema = z7.looseObject({ type: z7.literal("text"), text: z7.string() });
|
|
1574
1779
|
var toolUseBlockSchema = z7.looseObject({
|
|
@@ -1619,6 +1824,7 @@ var claudeCodeAdapter = {
|
|
|
1619
1824
|
const events = [];
|
|
1620
1825
|
const versions = /* @__PURE__ */ new Set();
|
|
1621
1826
|
const toolNames = /* @__PURE__ */ new Map();
|
|
1827
|
+
const turns = /* @__PURE__ */ new Map();
|
|
1622
1828
|
let recognized = 0;
|
|
1623
1829
|
let project = null;
|
|
1624
1830
|
let first;
|
|
@@ -1638,7 +1844,24 @@ var claudeCodeAdapter = {
|
|
|
1638
1844
|
if (last === void 0 || at > last) last = at;
|
|
1639
1845
|
}
|
|
1640
1846
|
if (record.type === "user") readUser(record, at, toolNames, events);
|
|
1641
|
-
else if (record.type === "assistant")
|
|
1847
|
+
else if (record.type === "assistant") {
|
|
1848
|
+
readTurn(record, at, turns, events);
|
|
1849
|
+
readAssistant(record, at, toolNames, events);
|
|
1850
|
+
} else if (record.type === "system" && record.subtype === "compact_boundary") {
|
|
1851
|
+
const meta = record.compactMetadata ?? {};
|
|
1852
|
+
const trigger = meta.trigger === "manual" || meta.trigger === "auto" ? meta.trigger : null;
|
|
1853
|
+
events.push(
|
|
1854
|
+
withTime(
|
|
1855
|
+
{
|
|
1856
|
+
kind: "compaction",
|
|
1857
|
+
trigger,
|
|
1858
|
+
preTokens: tokensOrNull(meta.preTokens),
|
|
1859
|
+
postTokens: tokensOrNull(meta.postTokens)
|
|
1860
|
+
},
|
|
1861
|
+
at
|
|
1862
|
+
)
|
|
1863
|
+
);
|
|
1864
|
+
}
|
|
1642
1865
|
}
|
|
1643
1866
|
} catch {
|
|
1644
1867
|
return { status: "unsupported", file, bytes, reason: "the file could not be read" };
|
|
@@ -1733,6 +1956,33 @@ function readUser(record, at, toolNames, events) {
|
|
|
1733
1956
|
const text = promptText(texts.join("\n"));
|
|
1734
1957
|
if (text !== null) events.push(withTime({ kind: "user_prompt", text }, at));
|
|
1735
1958
|
}
|
|
1959
|
+
function readTurn(record, at, turns, events) {
|
|
1960
|
+
const message = record.message;
|
|
1961
|
+
if (message?.id === void 0 || message.usage === void 0) return;
|
|
1962
|
+
if (message.model === "<synthetic>") return;
|
|
1963
|
+
const usage = message.usage;
|
|
1964
|
+
const outputTokens = tokens(usage.output_tokens);
|
|
1965
|
+
const seen = turns.get(message.id);
|
|
1966
|
+
if (seen !== void 0) {
|
|
1967
|
+
seen.outputTokens = Math.max(seen.outputTokens, outputTokens);
|
|
1968
|
+
return;
|
|
1969
|
+
}
|
|
1970
|
+
const turn = withTime(
|
|
1971
|
+
{
|
|
1972
|
+
kind: "model_turn",
|
|
1973
|
+
model: modelIdOrNull(message.model),
|
|
1974
|
+
effort: effortOrNull(record.effort),
|
|
1975
|
+
contextTokens: Math.min(
|
|
1976
|
+
tokens(usage.input_tokens) + tokens(usage.cache_read_input_tokens) + tokens(usage.cache_creation_input_tokens),
|
|
1977
|
+
1e8
|
|
1978
|
+
),
|
|
1979
|
+
outputTokens
|
|
1980
|
+
},
|
|
1981
|
+
at
|
|
1982
|
+
);
|
|
1983
|
+
turns.set(message.id, turn);
|
|
1984
|
+
events.push(turn);
|
|
1985
|
+
}
|
|
1736
1986
|
function readAssistant(record, at, toolNames, events) {
|
|
1737
1987
|
const content = record.message?.content;
|
|
1738
1988
|
if (!Array.isArray(content)) return;
|
|
@@ -1747,15 +1997,26 @@ function readAssistant(record, at, toolNames, events) {
|
|
|
1747
1997
|
const call = toolUseBlockSchema.safeParse(block);
|
|
1748
1998
|
if (call.success) {
|
|
1749
1999
|
toolNames.set(call.data.id, call.data.name);
|
|
2000
|
+
const model = SUBAGENT_TOOLS2.has(call.data.name) ? subagentModel(call.data.input) : null;
|
|
1750
2001
|
events.push(
|
|
1751
2002
|
withTime(
|
|
1752
|
-
{
|
|
2003
|
+
{
|
|
2004
|
+
kind: "tool_call",
|
|
2005
|
+
name: call.data.name,
|
|
2006
|
+
argsSummary: summarizeArgs(call.data.input),
|
|
2007
|
+
...model === null ? {} : { model }
|
|
2008
|
+
},
|
|
1753
2009
|
at
|
|
1754
2010
|
)
|
|
1755
2011
|
);
|
|
1756
2012
|
}
|
|
1757
2013
|
}
|
|
1758
2014
|
}
|
|
2015
|
+
var SUBAGENT_TOOLS2 = /* @__PURE__ */ new Set(["Agent", "Task"]);
|
|
2016
|
+
function subagentModel(input) {
|
|
2017
|
+
if (typeof input !== "object" || input === null) return null;
|
|
2018
|
+
return modelIdOrNull(input.model);
|
|
2019
|
+
}
|
|
1759
2020
|
function promptText(content) {
|
|
1760
2021
|
const trimmed = content.trim();
|
|
1761
2022
|
if (trimmed === "") return null;
|
|
@@ -1795,6 +2056,17 @@ var recordSchema2 = z8.looseObject({
|
|
|
1795
2056
|
timestamp: z8.string().optional(),
|
|
1796
2057
|
payload: z8.looseObject({ type: z8.string().optional() })
|
|
1797
2058
|
});
|
|
2059
|
+
var turnContextSchema = z8.looseObject({
|
|
2060
|
+
model: z8.unknown().optional(),
|
|
2061
|
+
effort: z8.unknown().optional()
|
|
2062
|
+
});
|
|
2063
|
+
var usageSchema = z8.looseObject({ input_tokens: z8.unknown(), output_tokens: z8.unknown() });
|
|
2064
|
+
var tokenCountSchema2 = z8.looseObject({
|
|
2065
|
+
info: z8.looseObject({
|
|
2066
|
+
last_token_usage: usageSchema,
|
|
2067
|
+
total_token_usage: z8.looseObject({ total_tokens: z8.unknown() })
|
|
2068
|
+
})
|
|
2069
|
+
});
|
|
1798
2070
|
var sessionMetaSchema = z8.looseObject({
|
|
1799
2071
|
id: z8.string(),
|
|
1800
2072
|
cwd: z8.string(),
|
|
@@ -1846,6 +2118,7 @@ var codexAdapter = {
|
|
|
1846
2118
|
const stats = { skippedLines: 0, lines: 0 };
|
|
1847
2119
|
const events = [];
|
|
1848
2120
|
const exitCodes = /* @__PURE__ */ new Map();
|
|
2121
|
+
const turn = { model: null, effort: null, total: null };
|
|
1849
2122
|
let meta = null;
|
|
1850
2123
|
let first;
|
|
1851
2124
|
let last;
|
|
@@ -1862,8 +2135,19 @@ var codexAdapter = {
|
|
|
1862
2135
|
if (type === "session_meta") {
|
|
1863
2136
|
const value = sessionMetaSchema.safeParse(payload);
|
|
1864
2137
|
if (value.success && meta === null) meta = value.data;
|
|
2138
|
+
} else if (type === "turn_context") {
|
|
2139
|
+
const value = turnContextSchema.safeParse(payload);
|
|
2140
|
+
if (value.success) {
|
|
2141
|
+
turn.model = modelIdOrNull(value.data.model);
|
|
2142
|
+
turn.effort = effortOrNull(value.data.effort);
|
|
2143
|
+
}
|
|
2144
|
+
} else if (type === "compacted") {
|
|
2145
|
+
events.push(
|
|
2146
|
+
withTime({ kind: "compaction", trigger: null, preTokens: null, postTokens: null }, at)
|
|
2147
|
+
);
|
|
1865
2148
|
} else if (type === "event_msg") {
|
|
1866
|
-
|
|
2149
|
+
if (payload.type === "token_count") readTokenCount(payload, at, turn, events);
|
|
2150
|
+
else readEventMessage(payload, at, exitCodes, events);
|
|
1867
2151
|
} else if (type === "response_item") {
|
|
1868
2152
|
readResponseItem(payload, at, exitCodes, events);
|
|
1869
2153
|
}
|
|
@@ -1908,6 +2192,27 @@ var codexAdapter = {
|
|
|
1908
2192
|
return Promise.resolve(null);
|
|
1909
2193
|
}
|
|
1910
2194
|
};
|
|
2195
|
+
function readTokenCount(payload, at, turn, events) {
|
|
2196
|
+
const value = tokenCountSchema2.safeParse(payload);
|
|
2197
|
+
if (!value.success) return;
|
|
2198
|
+
const total = tokens(value.data.info.total_token_usage.total_tokens);
|
|
2199
|
+
if (total === turn.total) return;
|
|
2200
|
+
turn.total = total;
|
|
2201
|
+
const contextTokens = tokens(value.data.info.last_token_usage.input_tokens);
|
|
2202
|
+
if (contextTokens === 0) return;
|
|
2203
|
+
events.push(
|
|
2204
|
+
withTime(
|
|
2205
|
+
{
|
|
2206
|
+
kind: "model_turn",
|
|
2207
|
+
model: turn.model,
|
|
2208
|
+
effort: turn.effort,
|
|
2209
|
+
contextTokens,
|
|
2210
|
+
outputTokens: tokens(value.data.info.last_token_usage.output_tokens)
|
|
2211
|
+
},
|
|
2212
|
+
at
|
|
2213
|
+
)
|
|
2214
|
+
);
|
|
2215
|
+
}
|
|
1911
2216
|
function readEventMessage(payload, at, exitCodes, events) {
|
|
1912
2217
|
switch (payload.type) {
|
|
1913
2218
|
case "user_message": {
|
|
@@ -2838,6 +3143,10 @@ function outputLabel(lines, exitCode) {
|
|
|
2838
3143
|
const exit = exitCode === void 0 ? "" : `, exit ${String(exitCode)}`;
|
|
2839
3144
|
return `[tool output: ${lines.toLocaleString("en-US")} ${lines === 1 ? "line" : "lines"}${exit}]`;
|
|
2840
3145
|
}
|
|
3146
|
+
function keptModel(model, r, counts) {
|
|
3147
|
+
const out = r.text(model, 100, counts);
|
|
3148
|
+
return out.diff === null && out.text === model ? model : null;
|
|
3149
|
+
}
|
|
2841
3150
|
function redactEvent(event, r) {
|
|
2842
3151
|
const counts = {};
|
|
2843
3152
|
const at = event.at === void 0 ? {} : { at: event.at };
|
|
@@ -2855,8 +3164,15 @@ function redactEvent(event, r) {
|
|
|
2855
3164
|
case "tool_call": {
|
|
2856
3165
|
const name = r.text(event.name, 200, counts);
|
|
2857
3166
|
const args = r.text(event.argsSummary, 400, counts);
|
|
3167
|
+
const model = event.model === void 0 ? null : keptModel(event.model, r, counts);
|
|
2858
3168
|
return {
|
|
2859
|
-
event: {
|
|
3169
|
+
event: {
|
|
3170
|
+
kind: "tool_call",
|
|
3171
|
+
name: name.text,
|
|
3172
|
+
argsSummary: args.text,
|
|
3173
|
+
...model === null ? {} : { model },
|
|
3174
|
+
...at
|
|
3175
|
+
},
|
|
2860
3176
|
diff: args.diff ?? name.diff,
|
|
2861
3177
|
counts,
|
|
2862
3178
|
collapsed: false
|
|
@@ -2895,6 +3211,12 @@ function redactEvent(event, r) {
|
|
|
2895
3211
|
collapsed: false
|
|
2896
3212
|
};
|
|
2897
3213
|
}
|
|
3214
|
+
case "model_turn": {
|
|
3215
|
+
const model = event.model === null ? null : keptModel(event.model, r, counts);
|
|
3216
|
+
return { event: { ...event, model }, diff: null, counts, collapsed: false };
|
|
3217
|
+
}
|
|
3218
|
+
case "compaction":
|
|
3219
|
+
return { event: { ...event }, diff: null, counts, collapsed: false };
|
|
2898
3220
|
}
|
|
2899
3221
|
}
|
|
2900
3222
|
var sessionKey = (tool, id) => `session:${tool}:${id}`;
|
|
@@ -3167,14 +3489,20 @@ function diffNode(segments) {
|
|
|
3167
3489
|
function eventText(event) {
|
|
3168
3490
|
switch (event.kind) {
|
|
3169
3491
|
case "user_prompt": case "assistant_text": return event.text;
|
|
3170
|
-
case "tool_call": return event.name + ": " + event.argsSummary;
|
|
3492
|
+
case "tool_call": return event.name + ": " + event.argsSummary + (event.model ? " (model " + event.model + ")" : "");
|
|
3171
3493
|
case "tool_result": return event.summary + (event.exitCode === undefined ? "" : " (exit " + event.exitCode + ")");
|
|
3172
3494
|
case "file_edit": return event.path + " (" + event.linesChanged + " lines)";
|
|
3495
|
+
case "model_turn": return (event.model || "model not recorded") + (event.effort ? " \xB7 effort " + event.effort : "") +
|
|
3496
|
+
" \xB7 " + count(event.contextTokens) + " tokens of context, " + count(event.outputTokens) + " written";
|
|
3497
|
+
case "compaction": return (event.trigger ? event.trigger + " compaction" : "Compaction") +
|
|
3498
|
+
(event.preTokens === null ? "" : " \xB7 " + count(event.preTokens) + " tokens before") +
|
|
3499
|
+
(event.postTokens === null ? "" : ", " + count(event.postTokens) + " after");
|
|
3173
3500
|
}
|
|
3174
3501
|
return "";
|
|
3175
3502
|
}
|
|
3503
|
+
const count = (n) => n.toLocaleString("en-US");
|
|
3176
3504
|
const KIND_LABELS = { user_prompt: "You", assistant_text: "Assistant", tool_call: "Tool call",
|
|
3177
|
-
tool_result: "Tool result", file_edit: "File edit" };
|
|
3505
|
+
tool_result: "Tool result", file_edit: "File edit", model_turn: "Model turn", compaction: "Compaction" };
|
|
3178
3506
|
async function open(key) {
|
|
3179
3507
|
current = key;
|
|
3180
3508
|
renderList();
|