@cchistory/lite 0.8.3 → 0.9.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/INSTALL.md +1 -1
- package/apps/lite-cli/dist/version.d.ts +1 -1
- package/apps/lite-cli/dist/version.js +1 -1
- package/apps/lite-tui/dist/render.d.ts +1 -1
- package/apps/lite-tui/dist/version.d.ts +1 -1
- package/apps/lite-tui/dist/version.js +1 -1
- package/node_modules/@cchistory/canonical/dist/query.js +1 -1
- package/node_modules/@cchistory/canonical/dist/query.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/tool-call-summary.d.ts.map +1 -1
- package/node_modules/@cchistory/canonical/dist/tool-call-summary.js +10 -2
- package/node_modules/@cchistory/canonical/dist/tool-call-summary.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/usage-anomalies.d.ts.map +1 -1
- package/node_modules/@cchistory/canonical/dist/usage-anomalies.js +2 -0
- package/node_modules/@cchistory/canonical/dist/usage-anomalies.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/usage-call-evaluation.d.ts.map +1 -1
- package/node_modules/@cchistory/canonical/dist/usage-call-evaluation.js +4 -1
- package/node_modules/@cchistory/canonical/dist/usage-call-evaluation.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/usage-trace.d.ts.map +1 -1
- package/node_modules/@cchistory/canonical/dist/usage-trace.js +3 -1
- package/node_modules/@cchistory/canonical/dist/usage-trace.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/usage-trace.test.js +73 -0
- package/node_modules/@cchistory/canonical/dist/usage-trace.test.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/usage.d.ts +1 -0
- package/node_modules/@cchistory/canonical/dist/usage.d.ts.map +1 -1
- package/node_modules/@cchistory/canonical/dist/usage.js +23 -17
- package/node_modules/@cchistory/canonical/dist/usage.js.map +1 -1
- package/node_modules/@cchistory/canonical/package.json +1 -1
- package/node_modules/@cchistory/domain/dist/index.d.ts +3 -1
- package/node_modules/@cchistory/domain/dist/index.d.ts.map +1 -1
- package/node_modules/@cchistory/domain/dist/index.js.map +1 -1
- package/node_modules/@cchistory/domain/dist/index.test.js +10 -1
- package/node_modules/@cchistory/domain/dist/index.test.js.map +1 -1
- package/node_modules/@cchistory/domain/dist/token-evidence.d.ts.map +1 -1
- package/node_modules/@cchistory/domain/dist/token-evidence.js +3 -1
- package/node_modules/@cchistory/domain/dist/token-evidence.js.map +1 -1
- package/node_modules/@cchistory/domain/package.json +1 -1
- package/node_modules/@cchistory/live-runtime/dist/index.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/index.d.ts.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/index.js +1 -0
- package/node_modules/@cchistory/live-runtime/dist/index.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/index.test.js +266 -38
- package/node_modules/@cchistory/live-runtime/dist/index.test.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/package.json +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/conversation-seeds.d.ts +3 -0
- package/node_modules/@cchistory/source-adapters/dist/core/conversation-seeds.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/conversation-seeds.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/discovery.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/discovery.js +60 -4
- package/node_modules/@cchistory/source-adapters/dist/core/discovery.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/parser.js +198 -1
- package/node_modules/@cchistory/source-adapters/dist/core/parser.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/probe.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/probe.js +85 -5
- package/node_modules/@cchistory/source-adapters/dist/core/probe.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/registry.test.js +17 -1
- package/node_modules/@cchistory/source-adapters/dist/core/registry.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.js +44 -0
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/source-identity.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js +12 -0
- package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts +4 -0
- package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/index.test.js +4 -0
- package/node_modules/@cchistory/source-adapters/dist/index.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.test.js +2 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness/reader.d.ts +28 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness/reader.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness/reader.js +443 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness/reader.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness/runtime.d.ts +4 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness/runtime.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness/runtime.js +370 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness/runtime.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness.d.ts +3 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness.js +78 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness.test.d.ts +2 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness.test.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness.test.js +313 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness.test.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/generic/runtime.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/generic/runtime.js +14 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/generic/runtime.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/hermes/runtime.d.ts +4 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/hermes/runtime.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/hermes/runtime.js +306 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/hermes/runtime.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/hermes/sqlite.d.ts +8 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/hermes/sqlite.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/hermes/sqlite.js +499 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/hermes/sqlite.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/hermes.d.ts +9 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/hermes.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/hermes.js +53 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/hermes.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/hermes.test.d.ts +2 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/hermes.test.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/hermes.test.js +314 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/hermes.test.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/oh-my-pi.d.ts +9 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/oh-my-pi.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/oh-my-pi.js +84 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/oh-my-pi.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode/sqlite-records.d.ts +50 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode/sqlite-records.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode/sqlite-records.js +291 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode/sqlite-records.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode/sqlite.d.ts +8 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode/sqlite.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode/sqlite.js +321 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode/sqlite.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode-sqlite.test.d.ts +2 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode-sqlite.test.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode-sqlite.test.js +245 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode-sqlite.test.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.js +30 -7
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family/reader.d.ts +44 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family/reader.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family/reader.js +533 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family/reader.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family/runtime.d.ts +4 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family/runtime.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family/runtime.js +375 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family/runtime.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family.test.d.ts +2 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family.test.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family.test.js +346 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family.test.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/pi.d.ts +8 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/pi.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/pi.js +60 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/pi.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/registry.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/registry.js +8 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/registry.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/types.d.ts +3 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/types.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/types.js +5 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/types.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/package.json +1 -1
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildConversationEvidence, interpretSessionEvidence } from "@cchistory/canonical";
|
|
1
|
+
import { buildConversationEvidence, executeCanonicalQuery, interpretSessionEvidence } from "@cchistory/canonical";
|
|
2
2
|
import assert from "node:assert/strict";
|
|
3
3
|
import { access, appendFile, copyFile, mkdir, mkdtemp, readFile, rm, stat, symlink, utimes, writeFile } from "node:fs/promises";
|
|
4
4
|
import { DatabaseSync } from "node:sqlite";
|
|
@@ -8,7 +8,7 @@ import test from "node:test";
|
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
import { buildProjectDisplayList } from "@cchistory/canonical";
|
|
10
10
|
import { listPlatformAdapters, runSourceProbe } from "@cchistory/source-adapters";
|
|
11
|
-
import { assertLiteSourceRoot, buildLiveSnapshot, LiveHistorySnapshot, maskCompactPreview, resolveLiteSources, scanLiteHistory, } from "./index.js";
|
|
11
|
+
import { assertLiteSourceRoot, buildLiveSnapshot, compileSql, LiveHistorySnapshot, maskCompactPreview, resolveLiteSources, scanLiteHistory, } from "./index.js";
|
|
12
12
|
import { SAMPLE_RANK_CONCURRENCY, mapPool } from "./async-pool.js";
|
|
13
13
|
import { settleLauncherExit } from "./bootstrap.js";
|
|
14
14
|
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../..");
|
|
@@ -28,6 +28,10 @@ const fixtureRoots = {
|
|
|
28
28
|
cursor_agent: "fixtures/cursor-agent",
|
|
29
29
|
grok: "fixtures/grok-cli",
|
|
30
30
|
grok_bot: "fixtures/grok-bot",
|
|
31
|
+
deepseek_harness: ".deepseek-harness/sessions",
|
|
32
|
+
hermes: "fixtures/hermes",
|
|
33
|
+
pi: ".pi/agent/sessions",
|
|
34
|
+
oh_my_pi: ".omp/agent/sessions",
|
|
31
35
|
};
|
|
32
36
|
test("Codex accounting keeps text-less calls, compactions and call timestamps in every stats dimension", async () => {
|
|
33
37
|
const snapshot = await scanLiteHistory({
|
|
@@ -152,14 +156,14 @@ test("compact family I/O previews mask secrets before the 240-character cut", ()
|
|
|
152
156
|
test("Lite materializer resolves canonical history across the fixture-backed adapter matrix", async () => {
|
|
153
157
|
const tempStore = await mkdtemp(path.join(os.tmpdir(), "cchistory-lite-matrix-"));
|
|
154
158
|
try {
|
|
159
|
+
// SQL-backed sources (Hermes/ZCode) and profile trees need materialized
|
|
160
|
+
// roots; this matrix covers every registered adapter, not just file fixtures.
|
|
161
|
+
const matrixRoots = await prepareContextFixtureRoots(tempStore);
|
|
155
162
|
const sources = await resolveLiteSources({
|
|
156
163
|
homeDir: path.join(tempStore, "empty-home"),
|
|
157
164
|
hostname: "cchistory-lite-matrix-host",
|
|
158
|
-
sourceRefs: Object.keys(
|
|
159
|
-
sourceRoots: Object.entries(
|
|
160
|
-
sourceRef,
|
|
161
|
-
baseDir: path.join(mockDataRoot, relativePath),
|
|
162
|
-
})),
|
|
165
|
+
sourceRefs: Object.keys(matrixRoots),
|
|
166
|
+
sourceRoots: Object.entries(matrixRoots).map(([sourceRef, baseDir]) => ({ sourceRef, baseDir })),
|
|
163
167
|
});
|
|
164
168
|
const probe = await runSourceProbe(interpretSessionEvidence, { safe_mode: true }, sources);
|
|
165
169
|
const askPayload = probe.sources.find((payload) => payload.source.platform === "codex");
|
|
@@ -214,9 +218,12 @@ test("Lite materializer resolves canonical history across the fixture-backed ada
|
|
|
214
218
|
const lite = buildLiveSnapshot(probe);
|
|
215
219
|
assert.deepEqual(lite.projectionIssues, [], "the complete adapter matrix must satisfy the canonical projection contract");
|
|
216
220
|
// Every registered adapter in the matrix materializes into the live snapshot.
|
|
217
|
-
assert.deepEqual(sortById(lite.listSources()).map((source) => source.platform).sort(), Object.keys(
|
|
221
|
+
assert.deepEqual(sortById(lite.listSources()).map((source) => source.platform).sort(), Object.keys(matrixRoots).sort());
|
|
218
222
|
assert.ok(lite.listResolvedSessions().length > 0);
|
|
219
223
|
assert.ok(lite.listResolvedTurns().length > 0);
|
|
224
|
+
for (const sourceRef of Object.keys(matrixRoots)) {
|
|
225
|
+
assert.ok(lite.listResolvedSessions().some((session) => session.source_platform === sourceRef), `${sourceRef} must contribute a nonempty session to the fixture matrix`);
|
|
226
|
+
}
|
|
220
227
|
let previousMessageAt;
|
|
221
228
|
let reachedTurnlessSessions = false;
|
|
222
229
|
for (const session of lite.listResolvedSessions()) {
|
|
@@ -280,36 +287,42 @@ test("Lite materializer resolves canonical history across the fixture-backed ada
|
|
|
280
287
|
}
|
|
281
288
|
});
|
|
282
289
|
test("Lite targeted probes preserve one-session parity across the fixture adapter matrix", async () => {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
.
|
|
304
|
-
.
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
.filter((turn) => expectedSessionIds.has(turn.session_id))
|
|
311
|
-
|
|
312
|
-
|
|
290
|
+
const targetMatrixScratch = await mkdtemp(path.join(os.tmpdir(), "cchistory-lite-target-matrix-"));
|
|
291
|
+
try {
|
|
292
|
+
const targetRoots = await prepareContextFixtureRoots(targetMatrixScratch);
|
|
293
|
+
for (const [sourceRef, baseDir] of Object.entries(targetRoots)) {
|
|
294
|
+
const scanOptions = {
|
|
295
|
+
homeDir: path.join(mockDataRoot, "empty-home"),
|
|
296
|
+
hostname: `cchistory-lite-target-matrix-${sourceRef}`,
|
|
297
|
+
sourceRefs: [sourceRef],
|
|
298
|
+
sourceRoots: [{ sourceRef, baseDir }],
|
|
299
|
+
safeMode: true,
|
|
300
|
+
};
|
|
301
|
+
const full = await scanLiteHistory({ ...scanOptions, contextMode: "full" });
|
|
302
|
+
const target = full.listResolvedSessions().find((session) => session.source_session_id);
|
|
303
|
+
assert.ok(target?.source_session_id, `${sourceRef} needs an addressable session for targeted parity`);
|
|
304
|
+
const targeted = await scanLiteHistory({
|
|
305
|
+
...scanOptions,
|
|
306
|
+
contextMode: "full",
|
|
307
|
+
sessionRefs: [target.source_session_id],
|
|
308
|
+
});
|
|
309
|
+
const expectedSessionIds = new Set([
|
|
310
|
+
target.id,
|
|
311
|
+
...full.listDelegatedChildren(target.id)
|
|
312
|
+
.map((child) => child.child_session_ref)
|
|
313
|
+
.filter((id) => id !== undefined),
|
|
314
|
+
]);
|
|
315
|
+
assert.deepEqual(targeted.listResolvedSessions().map(targetSessionParityFields), full.listResolvedSessions().filter((session) => expectedSessionIds.has(session.id)).map(targetSessionParityFields), `${sourceRef} session parity`);
|
|
316
|
+
assert.equal(targeted.listTopLevelSessions().some((session) => session.id !== target.id && expectedSessionIds.has(session.id)), false, `${sourceRef} delegated children stay out of top-level collections`);
|
|
317
|
+
assert.deepEqual(targeted.listResolvedTurns().map(targetTurnParityFields), full.listResolvedTurns().filter((turn) => expectedSessionIds.has(turn.session_id)).map(targetTurnParityFields), `${sourceRef} turn parity`);
|
|
318
|
+
const targetTurnIds = new Set(full.listResolvedTurns()
|
|
319
|
+
.filter((turn) => expectedSessionIds.has(turn.session_id))
|
|
320
|
+
.map((turn) => turn.id));
|
|
321
|
+
assert.deepEqual(targeted.data.contexts.map(targetContextParityFields), full.data.contexts.filter((context) => targetTurnIds.has(context.turn_id)).map(targetContextParityFields), `${sourceRef} context parity`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
finally {
|
|
325
|
+
await rm(targetMatrixScratch, { recursive: true, force: true });
|
|
313
326
|
}
|
|
314
327
|
});
|
|
315
328
|
test("every logical-session projection boundary preserves source-wide canonical parity", async () => {
|
|
@@ -547,6 +560,7 @@ test("Lite scans explicit roots without creating or reading a Full store", async
|
|
|
547
560
|
}), /not a single project folder/);
|
|
548
561
|
const resolved = await resolveLiteSources({
|
|
549
562
|
homeDir: tempHome,
|
|
563
|
+
env: {},
|
|
550
564
|
sourceRoots: [
|
|
551
565
|
{ sourceRef: "codex", baseDir: path.join(mockDataRoot, ".codex", "sessions") },
|
|
552
566
|
],
|
|
@@ -992,6 +1006,15 @@ async function prepareContextFixtureRoots(scratch) {
|
|
|
992
1006
|
const kimiMain = path.join(kimiSession, "agents", "main");
|
|
993
1007
|
const zcode = path.join(scratch, ".zcode");
|
|
994
1008
|
const zcodeDb = path.join(zcode, "cli", "db");
|
|
1009
|
+
const hermes = path.join(scratch, "hermes");
|
|
1010
|
+
await mkdir(hermes, { recursive: true });
|
|
1011
|
+
const hermesDb = new DatabaseSync(path.join(hermes, "state.db"));
|
|
1012
|
+
try {
|
|
1013
|
+
hermesDb.exec(await readFile(path.join(mockDataRoot, "fixtures/hermes/state.sql"), "utf8"));
|
|
1014
|
+
}
|
|
1015
|
+
finally {
|
|
1016
|
+
hermesDb.close();
|
|
1017
|
+
}
|
|
995
1018
|
await mkdir(geminiChats, { recursive: true });
|
|
996
1019
|
await mkdir(kimiMain, { recursive: true });
|
|
997
1020
|
await mkdir(zcodeDb, { recursive: true });
|
|
@@ -1013,6 +1036,7 @@ async function prepareContextFixtureRoots(scratch) {
|
|
|
1013
1036
|
lobechat: path.join(fixtures, "lobechat"),
|
|
1014
1037
|
kimi,
|
|
1015
1038
|
zcode,
|
|
1039
|
+
hermes,
|
|
1016
1040
|
};
|
|
1017
1041
|
}
|
|
1018
1042
|
test("compact queries retain assistant usage and errors without expanding body search", async (t) => {
|
|
@@ -2100,5 +2124,209 @@ test("Codex inherited embedded usage stays on the parent while child calls remai
|
|
|
2100
2124
|
const child = snapshot.listResolvedSessions().find(session => session.source_session_id === "codex-delegation-child");
|
|
2101
2125
|
assert.equal(child.turn_count, 0);
|
|
2102
2126
|
assert.deepEqual(child.usage_events.map(event => [event.turn_id, event.token_usage.total_tokens]), [[null, 11]]);
|
|
2127
|
+
assert.equal(snapshot.getSessionTrace({ sessionRef: child.id, filters: { timezone: "UTC" } })?.usage_granularity, "call", "turn-less per-call delegated children must keep call granularity");
|
|
2128
|
+
});
|
|
2129
|
+
test("OpenCode SQLite stores project v1 and v2 sessions without projection issues", async () => {
|
|
2130
|
+
const root = await mkdtemp(path.join(os.tmpdir(), "cchistory-opencode-sqlite-"));
|
|
2131
|
+
try {
|
|
2132
|
+
const fixtureSql = await readFile(path.join(mockDataRoot, "fixtures/opencode-sqlite/v2.sql"), "utf8");
|
|
2133
|
+
const db = new DatabaseSync(path.join(root, "opencode.db"));
|
|
2134
|
+
try {
|
|
2135
|
+
db.exec(fixtureSql);
|
|
2136
|
+
}
|
|
2137
|
+
finally {
|
|
2138
|
+
db.close();
|
|
2139
|
+
}
|
|
2140
|
+
const snapshot = await scanLiteHistory({
|
|
2141
|
+
homeDir: path.join(mockDataRoot, "empty-home"),
|
|
2142
|
+
sourceRefs: ["opencode"],
|
|
2143
|
+
sourceRoots: [{ sourceRef: "opencode", baseDir: root }],
|
|
2144
|
+
contextMode: "none",
|
|
2145
|
+
});
|
|
2146
|
+
assert.deepEqual(snapshot.projectionIssues, []);
|
|
2147
|
+
assert.equal(snapshot.listResolvedSessions().length, 1);
|
|
2148
|
+
const turns = snapshot.listResolvedTurns();
|
|
2149
|
+
assert.equal(turns.length, 1);
|
|
2150
|
+
assert.equal(turns[0]?.canonical_text, "Compare the two OpenCode storage generations.");
|
|
2151
|
+
const overview = snapshot.getUsageOverview({ timezone: "UTC" });
|
|
2152
|
+
assert.equal(overview.total_tokens, 1_778);
|
|
2153
|
+
assert.equal(overview.usage_event_count, 2);
|
|
2154
|
+
const breakdown = snapshot.getUsageBreakdown({
|
|
2155
|
+
filters: { timezone: "UTC" },
|
|
2156
|
+
time_dimension: "day",
|
|
2157
|
+
matrix_dimensions: ["model", "day"],
|
|
2158
|
+
});
|
|
2159
|
+
assert.deepEqual(breakdown.by_model.rows.map((row) => [row.key, row.total_tokens]), [["mock-opencode-v2", 1_778]], "OpenCode SQLite usage_only events must retain their model rather than falling into unknown");
|
|
2160
|
+
const trace = snapshot.getSessionTrace({
|
|
2161
|
+
sessionRef: snapshot.listResolvedSessions()[0].id,
|
|
2162
|
+
filters: { timezone: "UTC" },
|
|
2163
|
+
});
|
|
2164
|
+
assert.equal(trace?.usage_granularity, "call");
|
|
2165
|
+
assert.equal(trace?.total_calls, 2);
|
|
2166
|
+
}
|
|
2167
|
+
finally {
|
|
2168
|
+
await rm(root, { recursive: true, force: true });
|
|
2169
|
+
}
|
|
2170
|
+
});
|
|
2171
|
+
test("Hermes delegated children stay in the parent family while compression continuations remain top-level", async () => {
|
|
2172
|
+
const root = await mkdtemp(path.join(os.tmpdir(), "cchistory-hermes-family-"));
|
|
2173
|
+
try {
|
|
2174
|
+
const db = new DatabaseSync(path.join(root, "state.db"));
|
|
2175
|
+
try {
|
|
2176
|
+
db.exec(await readFile(path.join(mockDataRoot, "fixtures/hermes/state.sql"), "utf8"));
|
|
2177
|
+
}
|
|
2178
|
+
finally {
|
|
2179
|
+
db.close();
|
|
2180
|
+
}
|
|
2181
|
+
const snapshot = await scanLiteHistory({
|
|
2182
|
+
homeDir: path.join(mockDataRoot, "empty-home"),
|
|
2183
|
+
sourceRefs: ["hermes"],
|
|
2184
|
+
sourceRoots: [{ sourceRef: "hermes", baseDir: root }],
|
|
2185
|
+
contextMode: "none",
|
|
2186
|
+
});
|
|
2187
|
+
assert.deepEqual(snapshot.projectionIssues, []);
|
|
2188
|
+
assert.deepEqual(snapshot.listTopLevelSessions().map((session) => session.source_session_id).sort(), ["sess_fixture_hermes_main", "sess_fixture_hermes_reset"], "the delegated child is addressable through its parent, not as a top-level session");
|
|
2189
|
+
const parent = snapshot.listResolvedSessions().find((session) => session.source_session_id === "sess_fixture_hermes_main");
|
|
2190
|
+
assert.ok(snapshot.listSessionRelatedWork(parent.id).some((entry) => entry.relation_kind === "delegated_session" && entry.child_session_ref?.includes("sess_fixture_hermes_child")));
|
|
2191
|
+
assert.equal(snapshot.getUsageOverview({ timezone: "UTC" }).total_tokens, 3_828);
|
|
2192
|
+
const breakdown = snapshot.getUsageBreakdown({
|
|
2193
|
+
filters: { timezone: "UTC" },
|
|
2194
|
+
time_dimension: "day",
|
|
2195
|
+
matrix_dimensions: ["model", "day"],
|
|
2196
|
+
});
|
|
2197
|
+
assert.deepEqual(breakdown.by_model.rows.map((row) => row.key).sort(), ["mock-hermes-1", "mock-hermes-2", "mock-hermes-mini"], "per-model session usage keeps every model row");
|
|
2198
|
+
const trace = snapshot.getSessionTrace({ sessionRef: parent.id, filters: { timezone: "UTC" } });
|
|
2199
|
+
assert.equal(trace?.usage_granularity, "session", "Hermes exposes session/model aggregates, not calls");
|
|
2200
|
+
assert.equal(snapshot.getReadStatus().loss_warning_count, 0);
|
|
2201
|
+
}
|
|
2202
|
+
finally {
|
|
2203
|
+
await rm(root, { recursive: true, force: true });
|
|
2204
|
+
}
|
|
2205
|
+
});
|
|
2206
|
+
test("OpenCode v1 and pre-split SQLite stores project without issues and keep delegated children resolvable", async () => {
|
|
2207
|
+
for (const fixture of ["v1.sql", "v2-presplit.sql"]) {
|
|
2208
|
+
const root = await mkdtemp(path.join(os.tmpdir(), `cchistory-opencode-${fixture}-`));
|
|
2209
|
+
try {
|
|
2210
|
+
const db = new DatabaseSync(path.join(root, "opencode.db"));
|
|
2211
|
+
try {
|
|
2212
|
+
db.exec(await readFile(path.join(mockDataRoot, "fixtures/opencode-sqlite", fixture), "utf8"));
|
|
2213
|
+
}
|
|
2214
|
+
finally {
|
|
2215
|
+
db.close();
|
|
2216
|
+
}
|
|
2217
|
+
const snapshot = await scanLiteHistory({
|
|
2218
|
+
homeDir: path.join(mockDataRoot, "empty-home"),
|
|
2219
|
+
sourceRefs: ["opencode"],
|
|
2220
|
+
sourceRoots: [{ sourceRef: "opencode", baseDir: root }],
|
|
2221
|
+
contextMode: "none",
|
|
2222
|
+
});
|
|
2223
|
+
assert.deepEqual(snapshot.projectionIssues, [], fixture);
|
|
2224
|
+
if (fixture === "v1.sql") {
|
|
2225
|
+
assert.equal(snapshot.listTopLevelSessions().length, 1, fixture);
|
|
2226
|
+
assert.equal(snapshot.listResolvedSessions().length, 2, fixture);
|
|
2227
|
+
assert.equal(snapshot.listResolvedTurns().length, 2, fixture);
|
|
2228
|
+
assert.equal(snapshot.getUsageOverview({ timezone: "UTC" }).total_tokens, 1_423, fixture);
|
|
2229
|
+
assert.deepEqual(snapshot.getUsageBreakdown({ filters: { timezone: "UTC" }, time_dimension: "day", matrix_dimensions: ["model", "day"] })
|
|
2230
|
+
.by_model.rows.map((row) => [row.key, row.total_tokens]), [["mock-opencode-v1", 1_423]], fixture);
|
|
2231
|
+
const parent = snapshot.listTopLevelSessions()[0];
|
|
2232
|
+
assert.ok(snapshot.listSessionRelatedWork(parent.id).some((entry) => entry.relation_kind === "delegated_session" && entry.child_session_ref?.includes("ses_fixture_v1_child")), fixture);
|
|
2233
|
+
}
|
|
2234
|
+
else {
|
|
2235
|
+
assert.equal(snapshot.listResolvedSessions().length, 1, fixture);
|
|
2236
|
+
assert.equal(snapshot.listResolvedTurns().length, 1, fixture);
|
|
2237
|
+
assert.equal(snapshot.getUsageOverview({ timezone: "UTC" }).total_tokens, 840, fixture);
|
|
2238
|
+
assert.deepEqual(snapshot.getUsageBreakdown({ filters: { timezone: "UTC" }, time_dimension: "day", matrix_dimensions: ["model", "day"] })
|
|
2239
|
+
.by_model.rows.map((row) => [row.key, row.total_tokens]), [["mock-opencode-presplit", 840]], fixture);
|
|
2240
|
+
assert.equal(snapshot.getReadStatus().loss_warning_count, 0, fixture);
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
finally {
|
|
2244
|
+
await rm(root, { recursive: true, force: true });
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
});
|
|
2248
|
+
test("Hermes per-model usage survives a final turn with no text reply", async () => {
|
|
2249
|
+
const root = await mkdtemp(path.join(os.tmpdir(), "cchistory-hermes-toolonly-"));
|
|
2250
|
+
try {
|
|
2251
|
+
const db = new DatabaseSync(path.join(root, "state.db"));
|
|
2252
|
+
try {
|
|
2253
|
+
db.exec(`
|
|
2254
|
+
CREATE TABLE sessions (id TEXT PRIMARY KEY, source TEXT NOT NULL, model TEXT, started_at REAL NOT NULL,
|
|
2255
|
+
input_tokens INTEGER DEFAULT 0, output_tokens INTEGER DEFAULT 0, cache_read_tokens INTEGER DEFAULT 0,
|
|
2256
|
+
cache_write_tokens INTEGER DEFAULT 0, reasoning_tokens INTEGER DEFAULT 0);
|
|
2257
|
+
CREATE TABLE messages (id INTEGER PRIMARY KEY AUTOINCREMENT, session_id TEXT NOT NULL, role TEXT NOT NULL,
|
|
2258
|
+
content TEXT, tool_calls TEXT, tool_call_id TEXT, tool_name TEXT, timestamp REAL NOT NULL,
|
|
2259
|
+
active INTEGER NOT NULL DEFAULT 1, display_kind TEXT, _compressed_summary INTEGER NOT NULL DEFAULT 0);
|
|
2260
|
+
CREATE TABLE session_model_usage (session_id TEXT NOT NULL, model TEXT NOT NULL,
|
|
2261
|
+
billing_provider TEXT NOT NULL DEFAULT '', task TEXT NOT NULL DEFAULT '', api_call_count INTEGER DEFAULT 0,
|
|
2262
|
+
input_tokens INTEGER DEFAULT 0, output_tokens INTEGER DEFAULT 0, cache_read_tokens INTEGER DEFAULT 0,
|
|
2263
|
+
cache_write_tokens INTEGER DEFAULT 0, reasoning_tokens INTEGER DEFAULT 0,
|
|
2264
|
+
estimated_cost_usd REAL DEFAULT 0, actual_cost_usd REAL DEFAULT 0);
|
|
2265
|
+
INSERT INTO sessions VALUES ('sess_tool_only', 'cli', 'hermes-model', 1771000000.0, 0, 0, 0, 0, 0);
|
|
2266
|
+
INSERT INTO messages (session_id, role, content, timestamp) VALUES
|
|
2267
|
+
('sess_tool_only', 'user', 'Run the audit tool.', 1771000001.0);
|
|
2268
|
+
INSERT INTO messages (session_id, role, content, tool_calls, timestamp) VALUES
|
|
2269
|
+
('sess_tool_only', 'assistant', NULL,
|
|
2270
|
+
'[{"id":"call_1","type":"function","function":{"name":"audit","arguments":"{}"}}]', 1771000002.0);
|
|
2271
|
+
INSERT INTO messages (session_id, role, content, tool_call_id, tool_name, timestamp) VALUES
|
|
2272
|
+
('sess_tool_only', 'tool', 'audit complete', 'call_1', 'audit', 1771000003.0);
|
|
2273
|
+
INSERT INTO session_model_usage VALUES ('sess_tool_only', 'hermes-model', 'mock', '', 1,
|
|
2274
|
+
100, 20, 0, 0, 5, 0, 0);
|
|
2275
|
+
`);
|
|
2276
|
+
}
|
|
2277
|
+
finally {
|
|
2278
|
+
db.close();
|
|
2279
|
+
}
|
|
2280
|
+
const snapshot = await scanLiteHistory({
|
|
2281
|
+
homeDir: path.join(mockDataRoot, "empty-home"),
|
|
2282
|
+
sourceRefs: ["hermes"],
|
|
2283
|
+
sourceRoots: [{ sourceRef: "hermes", baseDir: root }],
|
|
2284
|
+
contextMode: "none",
|
|
2285
|
+
});
|
|
2286
|
+
assert.deepEqual(snapshot.projectionIssues, []);
|
|
2287
|
+
assert.equal(snapshot.getUsageOverview({ timezone: "UTC" }).total_tokens, 120);
|
|
2288
|
+
assert.deepEqual(snapshot.getUsageBreakdown({ filters: { timezone: "UTC" }, time_dimension: "day", matrix_dimensions: ["model", "day"] })
|
|
2289
|
+
.by_model.rows.map((row) => row.key), ["hermes-model"]);
|
|
2290
|
+
const sqlQuery = await compileSql("SELECT granularity, high_context_tier, total_tokens FROM calls WHERE total_tokens > 0 LIMIT 10");
|
|
2291
|
+
const sqlResult = executeCanonicalQuery(snapshot.data, sqlQuery);
|
|
2292
|
+
assert.deepEqual(sqlResult.rows, [{ granularity: "session", high_context_tier: false, total_tokens: 120 }]);
|
|
2293
|
+
}
|
|
2294
|
+
finally {
|
|
2295
|
+
await rm(root, { recursive: true, force: true });
|
|
2296
|
+
}
|
|
2297
|
+
});
|
|
2298
|
+
test("Pi family projection keeps call-granularity usage and task-child lineage", async () => {
|
|
2299
|
+
const piSnapshot = await scanLiteHistory({
|
|
2300
|
+
homeDir: path.join(mockDataRoot, "empty-home"),
|
|
2301
|
+
sourceRefs: ["pi"],
|
|
2302
|
+
sourceRoots: [{ sourceRef: "pi", baseDir: path.join(mockDataRoot, ".pi/agent/sessions") }],
|
|
2303
|
+
contextMode: "none",
|
|
2304
|
+
});
|
|
2305
|
+
assert.deepEqual(piSnapshot.projectionIssues, []);
|
|
2306
|
+
assert.equal(piSnapshot.getUsageOverview({ timezone: "UTC" }).total_tokens, 4_466);
|
|
2307
|
+
const piSession = piSnapshot.listResolvedSessions()[0];
|
|
2308
|
+
assert.equal(piSnapshot.getSessionTrace({ sessionRef: piSession.id, filters: { timezone: "UTC" } })?.usage_granularity, "call");
|
|
2309
|
+
assert.ok(piSnapshot.listSessionTurns(piSession.id).every((turn) => !turn.canonical_text.includes("Abandoned branch")));
|
|
2310
|
+
const ompSnapshot = await scanLiteHistory({
|
|
2311
|
+
homeDir: path.join(mockDataRoot, "empty-home"),
|
|
2312
|
+
sourceRefs: ["oh_my_pi"],
|
|
2313
|
+
sourceRoots: [{ sourceRef: "oh_my_pi", baseDir: path.join(mockDataRoot, ".omp/agent/sessions") }],
|
|
2314
|
+
contextMode: "none",
|
|
2315
|
+
});
|
|
2316
|
+
assert.deepEqual(ompSnapshot.projectionIssues, []);
|
|
2317
|
+
assert.equal(ompSnapshot.getUsageOverview({ timezone: "UTC" }).total_tokens, 1_794);
|
|
2318
|
+
assert.deepEqual(ompSnapshot.listTopLevelSessions().map((session) => session.source_session_id).sort(), ["omp-fixture-fork", "omp-fixture-main"], "the task child is delegated; the ordinary fork stays top-level");
|
|
2319
|
+
const main = ompSnapshot.listTopLevelSessions().find((session) => session.source_session_id === "omp-fixture-main");
|
|
2320
|
+
assert.ok(ompSnapshot.listSessionRelatedWork(main.id).some((entry) => entry.relation_kind === "delegated_session" && entry.child_session_ref?.includes("omp-fixture-task")));
|
|
2321
|
+
// Targeted parent read must also include the delegated task child and related work.
|
|
2322
|
+
const ompTargeted = await scanLiteHistory({
|
|
2323
|
+
homeDir: path.join(mockDataRoot, "empty-home"),
|
|
2324
|
+
sourceRefs: ["oh_my_pi"],
|
|
2325
|
+
sourceRoots: [{ sourceRef: "oh_my_pi", baseDir: path.join(mockDataRoot, ".omp/agent/sessions") }],
|
|
2326
|
+
sessionRefs: [main.id],
|
|
2327
|
+
contextMode: "none",
|
|
2328
|
+
});
|
|
2329
|
+
assert.deepEqual(ompTargeted.projectionIssues, []);
|
|
2330
|
+
assert.ok(ompTargeted.listSessionRelatedWork(main.id).some((entry) => entry.relation_kind === "delegated_session" && entry.child_session_ref?.includes("omp-fixture-task")), "targeted OMP parent read keeps delegated task child resolvable");
|
|
2103
2331
|
});
|
|
2104
2332
|
//# sourceMappingURL=index.test.js.map
|