@tangle-network/harness-sessions 1.0.7 → 1.0.8
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/dist/catalog.d.ts +13 -1
- package/dist/catalog.js +3 -0
- package/dist/formats/claude-code.js +2 -16
- package/dist/formats/codex.js +2 -16
- package/dist/formats/factory.js +2 -16
- package/dist/formats/fold.d.ts +6 -1
- package/dist/formats/fold.js +16 -0
- package/dist/formats/grok.js +17 -27
- package/dist/formats/hermes.js +15 -19
- package/dist/formats/kimi.js +2 -16
- package/dist/formats/nanoclaw.js +17 -26
- package/dist/formats/openclaw.js +14 -18
- package/dist/formats/opencode.js +12 -25
- package/dist/formats/pi.js +2 -16
- package/dist/formats/prime.js +17 -22
- package/dist/formats/sandbox-events.d.ts +12 -0
- package/dist/formats/sandbox-events.js +69 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/dist/catalog.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const SESSION_FORMAT_IDS: readonly ["claude-code.projects-jsonl", "codex.rollout-jsonl", "opencode.sqlite", "pi.session-jsonl", "kimi.session-dir", "factory.session-jsonl", "gemini.chat-json", "amp.thread-json", "forge.sqlite", "hermes.state-sqlite", "prime.session-jsonl", "openclaw.session-jsonl", "grok.acp-session-dir", "nanoclaw.session-sqlite"];
|
|
1
|
+
export declare const SESSION_FORMAT_IDS: readonly ["claude-code.projects-jsonl", "codex.rollout-jsonl", "opencode.sqlite", "pi.session-jsonl", "kimi.session-dir", "factory.session-jsonl", "gemini.chat-json", "amp.thread-json", "forge.sqlite", "hermes.state-sqlite", "prime.session-jsonl", "openclaw.session-jsonl", "grok.acp-session-dir", "nanoclaw.session-sqlite", "sandbox.events"];
|
|
2
2
|
export declare const STORES: {
|
|
3
3
|
readonly 'claude-code.projects-jsonl': {
|
|
4
4
|
format: "claude-code.projects-jsonl";
|
|
@@ -91,6 +91,13 @@ export declare const STORES: {
|
|
|
91
91
|
write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
|
|
92
92
|
shared: boolean;
|
|
93
93
|
};
|
|
94
|
+
readonly 'sandbox.events': {
|
|
95
|
+
format: "sandbox.events";
|
|
96
|
+
root: string;
|
|
97
|
+
files: readonly ["{id}/*.jsonl"];
|
|
98
|
+
write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
|
|
99
|
+
shared: boolean;
|
|
100
|
+
};
|
|
94
101
|
readonly 'nanoclaw.session-sqlite': {
|
|
95
102
|
format: "nanoclaw.session-sqlite";
|
|
96
103
|
root: string;
|
|
@@ -186,6 +193,11 @@ export declare const EVIDENCE: {
|
|
|
186
193
|
readonly usage: "per-response";
|
|
187
194
|
readonly endingError: "none";
|
|
188
195
|
};
|
|
196
|
+
readonly 'sandbox.events': {
|
|
197
|
+
readonly servedModel: "none";
|
|
198
|
+
readonly usage: "per-response";
|
|
199
|
+
readonly endingError: "none";
|
|
200
|
+
};
|
|
189
201
|
};
|
|
190
202
|
export declare const CODEX_HOME_RULE: {
|
|
191
203
|
readonly siblings: RegExp;
|
package/dist/catalog.js
CHANGED
|
@@ -13,6 +13,7 @@ export const SESSION_FORMAT_IDS = [
|
|
|
13
13
|
'openclaw.session-jsonl',
|
|
14
14
|
'grok.acp-session-dir',
|
|
15
15
|
'nanoclaw.session-sqlite',
|
|
16
|
+
'sandbox.events',
|
|
16
17
|
];
|
|
17
18
|
function store(format, root, files, write = 'jsonl-append', shared = write === 'sqlite-wal') {
|
|
18
19
|
return { format, root, files, write, shared };
|
|
@@ -37,6 +38,7 @@ export const STORES = {
|
|
|
37
38
|
'prime.session-jsonl': store('prime.session-jsonl', '.prime-provider/prime-agent-dirs', ['**/sessions/*.jsonl']),
|
|
38
39
|
'openclaw.session-jsonl': store('openclaw.session-jsonl', '.openclaw', ['agents/main/agent/openclaw-agent.sqlite', 'agents/main/agent/openclaw-agent.sqlite-wal', 'agents/main/agent/openclaw-agent.sqlite-shm'], 'sqlite-wal'),
|
|
39
40
|
'grok.acp-session-dir': store('grok.acp-session-dir', '.grok/sessions', ['*/{id}/updates.jsonl', '*/{id}/chat_history.jsonl', '*/{id}/summary.json', '*/{id}/signals.json']),
|
|
41
|
+
'sandbox.events': store('sandbox.events', 'evidence/live-stream', ['{id}/*.jsonl']),
|
|
40
42
|
'nanoclaw.session-sqlite': store('nanoclaw.session-sqlite', '.nanoclaw/data/v2-sessions', ['*/{id}/outbound.db', '*/{id}/inbound.db'], 'sqlite-wal', false),
|
|
41
43
|
};
|
|
42
44
|
export const KIMI_STORES = [
|
|
@@ -58,6 +60,7 @@ export const EVIDENCE = {
|
|
|
58
60
|
'openclaw.session-jsonl': { servedModel: 'session-record', usage: 'per-response', endingError: 'none' },
|
|
59
61
|
'grok.acp-session-dir': { servedModel: 'session-record', usage: 'session-total', endingError: 'none' },
|
|
60
62
|
'nanoclaw.session-sqlite': { servedModel: 'none', usage: 'per-response', endingError: 'none' },
|
|
63
|
+
'sandbox.events': { servedModel: 'none', usage: 'per-response', endingError: 'none' },
|
|
61
64
|
};
|
|
62
65
|
export const CODEX_HOME_RULE = {
|
|
63
66
|
siblings: /^\.codex(?:-.+)?$/u,
|
|
@@ -2,7 +2,7 @@ import { isRecord } from '@tangle-network/agent-core';
|
|
|
2
2
|
import { basename, join } from 'node:path';
|
|
3
3
|
import { SessionBuilder, count, sessionError, str, textOf, usageOrNull } from '../builder.js';
|
|
4
4
|
import { fileRecords } from '../source.js';
|
|
5
|
-
import { runFold } from './fold.js';
|
|
5
|
+
import { foldedReader, runFold } from './fold.js';
|
|
6
6
|
import { EVIDENCE, LOCATE_READS, STORES, mapLimit, mtimeMs, storeGlob, walkFiles, withinPath } from '../stores.js';
|
|
7
7
|
import { headRecord } from './head.js';
|
|
8
8
|
import { claudeRecordIsMachine, claudeTypedPromptText } from './claude-records.js';
|
|
@@ -258,21 +258,7 @@ async function locate(home, opts) {
|
|
|
258
258
|
});
|
|
259
259
|
return sessions.flat().sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
260
260
|
}
|
|
261
|
-
export const claudeCodeReader = {
|
|
262
|
-
harness: HARNESS,
|
|
263
|
-
aliases: ['claude', 'claude-code-acp', 'claudish'],
|
|
264
|
-
formats: [FORMAT],
|
|
265
|
-
stores: [STORE],
|
|
266
|
-
globs: { session: STORE.files[0], children: STORE.files[1] },
|
|
267
|
-
evidence: EVIDENCE[FORMAT],
|
|
268
|
-
locate: (home, opts = {}) => locate(home, opts),
|
|
269
|
-
async read(ref, opts = {}) {
|
|
270
|
-
return (await fold(ref, 'full', opts)).build();
|
|
271
|
-
},
|
|
272
|
-
async summarize(ref, opts = {}) {
|
|
273
|
-
return (await fold(ref, 'summary', opts)).summary();
|
|
274
|
-
},
|
|
275
|
-
};
|
|
261
|
+
export const claudeCodeReader = foldedReader({ harness: HARNESS, aliases: ['claude', 'claude-code-acp', 'claudish'], format: FORMAT, globs: { session: STORE.files[0], children: STORE.files[1] } }, locate, fold);
|
|
276
262
|
export function claudeCodeRefForFile(path, parentNativeSessionId = null) {
|
|
277
263
|
const name = basename(path, '.jsonl');
|
|
278
264
|
return {
|
package/dist/formats/codex.js
CHANGED
|
@@ -2,7 +2,7 @@ import { isRecord } from '@tangle-network/agent-core';
|
|
|
2
2
|
import { basename } from 'node:path';
|
|
3
3
|
import { SessionBuilder, argumentsOf, count, sessionError, str, textOf, usageOrNull, } from '../builder.js';
|
|
4
4
|
import { fileRecords, isMissing } from '../source.js';
|
|
5
|
-
import { runFold } from './fold.js';
|
|
5
|
+
import { foldedReader, runFold } from './fold.js';
|
|
6
6
|
import { CODEX_HOME_RULE, EVIDENCE, LOCATE_READS, STORES, codexHomes, mapLimit, storeGlob, walkFiles, withinPath } from '../stores.js';
|
|
7
7
|
import { headRecord } from './head.js';
|
|
8
8
|
import { stat } from 'node:fs/promises';
|
|
@@ -407,21 +407,7 @@ async function locate(home, opts) {
|
|
|
407
407
|
}
|
|
408
408
|
return [...largest.values()].map((c) => c.ref).sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
409
409
|
}
|
|
410
|
-
export const codexReader = {
|
|
411
|
-
harness: HARNESS,
|
|
412
|
-
aliases: ['codex-acp', 'codex-cli'],
|
|
413
|
-
formats: [FORMAT],
|
|
414
|
-
stores: [STORE],
|
|
415
|
-
globs: { session: STORE.files[0] },
|
|
416
|
-
evidence: EVIDENCE[FORMAT],
|
|
417
|
-
locate: (home, opts = {}) => locate(home, opts),
|
|
418
|
-
async read(ref, opts = {}) {
|
|
419
|
-
return (await fold(ref, 'full', opts)).build();
|
|
420
|
-
},
|
|
421
|
-
async summarize(ref, opts = {}) {
|
|
422
|
-
return (await fold(ref, 'summary', opts)).summary();
|
|
423
|
-
},
|
|
424
|
-
};
|
|
410
|
+
export const codexReader = foldedReader({ harness: HARNESS, aliases: ['codex-acp', 'codex-cli'], format: FORMAT }, locate, fold);
|
|
425
411
|
export function codexRefForFile(path) {
|
|
426
412
|
return {
|
|
427
413
|
harness: HARNESS,
|
package/dist/formats/factory.js
CHANGED
|
@@ -4,7 +4,7 @@ import { basename, join } from 'node:path';
|
|
|
4
4
|
import { SessionBuilder, count, str, textOf, usageOrNull } from '../builder.js';
|
|
5
5
|
import { fileRecords, isMissing } from '../source.js';
|
|
6
6
|
import { EVIDENCE, STORES, mtimeMs, storeGlob, walkFiles, withinPath } from '../stores.js';
|
|
7
|
-
import { runFold } from './fold.js';
|
|
7
|
+
import { foldedReader, runFold } from './fold.js';
|
|
8
8
|
import { headRecord } from './head.js';
|
|
9
9
|
const FORMAT = 'factory.session-jsonl';
|
|
10
10
|
const STORE = STORES[FORMAT];
|
|
@@ -133,21 +133,7 @@ async function locate(home, opts) {
|
|
|
133
133
|
}
|
|
134
134
|
return filtered.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
135
135
|
}
|
|
136
|
-
export const factoryReader = {
|
|
137
|
-
harness: HARNESS,
|
|
138
|
-
aliases: ['factory', 'droid'],
|
|
139
|
-
formats: [FORMAT],
|
|
140
|
-
stores: [STORE],
|
|
141
|
-
globs: { session: STORE.files[0] },
|
|
142
|
-
evidence: EVIDENCE[FORMAT],
|
|
143
|
-
locate: (home, opts = {}) => locate(home, opts),
|
|
144
|
-
async read(ref, opts = {}) {
|
|
145
|
-
return (await fold(ref, 'full', opts)).build();
|
|
146
|
-
},
|
|
147
|
-
async summarize(ref, opts = {}) {
|
|
148
|
-
return (await fold(ref, 'summary', opts)).summary();
|
|
149
|
-
},
|
|
150
|
-
};
|
|
136
|
+
export const factoryReader = foldedReader({ harness: HARNESS, aliases: ['factory', 'droid'], format: FORMAT }, locate, fold);
|
|
151
137
|
export function factoryRefForFile(path) {
|
|
152
138
|
return { harness: HARNESS, format: FORMAT, nativeSessionId: basename(path, '.jsonl'), path, files: [path], home: null, cwd: null, mtimeMs: 0, parentNativeSessionId: null };
|
|
153
139
|
}
|
package/dist/formats/fold.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { SessionBuilder } from '../builder.js';
|
|
1
|
+
import type { BuildMode, SessionBuilder } from '../builder.js';
|
|
2
|
+
import type { HarnessSessionReader, LocateOptions, ReadOptions, SessionFormatId, SessionRef } from '../schema.js';
|
|
2
3
|
import type { RecordSource } from '../source.js';
|
|
3
4
|
export interface SessionFold {
|
|
4
5
|
builder: SessionBuilder;
|
|
@@ -6,3 +7,7 @@ export interface SessionFold {
|
|
|
6
7
|
finish(): SessionBuilder;
|
|
7
8
|
}
|
|
8
9
|
export declare function runFold(fold: SessionFold, source: RecordSource): Promise<SessionBuilder>;
|
|
10
|
+
/** A reader: what differs between harnesses is how a session is found and folded. */
|
|
11
|
+
export declare function foldedReader(reader: Pick<HarnessSessionReader, 'harness' | 'aliases'> & Partial<Pick<HarnessSessionReader, 'stores' | 'globs'>> & {
|
|
12
|
+
format: SessionFormatId;
|
|
13
|
+
}, locate: (home: string, opts: LocateOptions) => Promise<SessionRef[]>, fold: (ref: SessionRef, mode: BuildMode, opts: ReadOptions) => Promise<SessionBuilder>): HarnessSessionReader;
|
package/dist/formats/fold.js
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
|
+
import { EVIDENCE, STORES } from '../stores.js';
|
|
1
2
|
export async function runFold(fold, source) {
|
|
2
3
|
for await (const record of source.records)
|
|
3
4
|
fold.observe(record);
|
|
4
5
|
return fold.finish();
|
|
5
6
|
}
|
|
7
|
+
/** A reader: what differs between harnesses is how a session is found and folded. */
|
|
8
|
+
export function foldedReader(reader, locate, fold) {
|
|
9
|
+
const store = STORES[reader.format];
|
|
10
|
+
return {
|
|
11
|
+
harness: reader.harness,
|
|
12
|
+
aliases: reader.aliases,
|
|
13
|
+
formats: [reader.format],
|
|
14
|
+
stores: reader.stores ?? [store],
|
|
15
|
+
globs: reader.globs ?? { session: store.files[0] },
|
|
16
|
+
evidence: EVIDENCE[reader.format],
|
|
17
|
+
locate: (home, opts = {}) => locate(home, opts),
|
|
18
|
+
read: async (ref, opts = {}) => (await fold(ref, 'full', opts)).build(),
|
|
19
|
+
summarize: async (ref, opts = {}) => (await fold(ref, 'summary', opts)).summary(),
|
|
20
|
+
};
|
|
21
|
+
}
|
package/dist/formats/grok.js
CHANGED
|
@@ -4,7 +4,7 @@ import { basename, dirname, join } from 'node:path';
|
|
|
4
4
|
import { SessionBuilder, count, str, textOf, usageOrNull } from '../builder.js';
|
|
5
5
|
import { fileRecords, isMissing } from '../source.js';
|
|
6
6
|
import { EVIDENCE, STORES, mtimeMs, storeGlob, walkFiles } from '../stores.js';
|
|
7
|
-
import { runFold } from './fold.js';
|
|
7
|
+
import { foldedReader, runFold } from './fold.js';
|
|
8
8
|
const FORMAT = 'grok.acp-session-dir';
|
|
9
9
|
const STORE = STORES[FORMAT];
|
|
10
10
|
const HARNESS = 'grok';
|
|
@@ -109,32 +109,22 @@ async function fold(ref, mode, options) {
|
|
|
109
109
|
const model = isRecord(summary) ? str(summary.current_model_id) : null;
|
|
110
110
|
return runFold(createFold(ref, mode, records.stats, model, usageOf(await markedJson(ref, 'signals.json', 'primaryModelId'))), records);
|
|
111
111
|
}
|
|
112
|
-
export const grokReader = {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const id = basename(dirname(rel));
|
|
129
|
-
if ((opts.sinceMs && mtime < opts.sinceMs) || (opts.nativeSessionId && id !== opts.nativeSessionId))
|
|
130
|
-
continue;
|
|
131
|
-
refs.push({ harness: HARNESS, format: FORMAT, nativeSessionId: id, path, files: [path], home, cwd: null, mtimeMs: mtime, parentNativeSessionId: null });
|
|
132
|
-
}
|
|
133
|
-
return refs.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
134
|
-
},
|
|
135
|
-
async read(ref, opts = {}) { return (await fold(ref, 'full', opts)).build(); },
|
|
136
|
-
async summarize(ref, opts = {}) { return (await fold(ref, 'summary', opts)).summary(); },
|
|
137
|
-
};
|
|
112
|
+
export const grokReader = foldedReader({ harness: HARNESS, aliases: ['grok-build'], format: FORMAT }, async (home, opts) => {
|
|
113
|
+
const root = join(home, STORE.root);
|
|
114
|
+
const pattern = storeGlob(STORE.files[0], opts.nativeSessionId);
|
|
115
|
+
const refs = [];
|
|
116
|
+
for (const rel of await walkFiles(root)) {
|
|
117
|
+
if (!pattern.test(rel))
|
|
118
|
+
continue;
|
|
119
|
+
const path = join(root, rel);
|
|
120
|
+
const mtime = await mtimeMs(path);
|
|
121
|
+
const id = basename(dirname(rel));
|
|
122
|
+
if ((opts.sinceMs && mtime < opts.sinceMs) || (opts.nativeSessionId && id !== opts.nativeSessionId))
|
|
123
|
+
continue;
|
|
124
|
+
refs.push({ harness: HARNESS, format: FORMAT, nativeSessionId: id, path, files: [path], home, cwd: null, mtimeMs: mtime, parentNativeSessionId: null });
|
|
125
|
+
}
|
|
126
|
+
return refs.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
127
|
+
}, fold);
|
|
138
128
|
export function grokRefForFile(path) {
|
|
139
129
|
return { harness: HARNESS, format: FORMAT, nativeSessionId: basename(dirname(path)), path, files: [path], home: null, cwd: null, mtimeMs: 0, parentNativeSessionId: null };
|
|
140
130
|
}
|
package/dist/formats/hermes.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { foldedReader } from './fold.js';
|
|
1
2
|
import { basename, join } from 'node:path';
|
|
2
3
|
import { SessionBuilder, count, str, usageOrNull } from '../builder.js';
|
|
3
4
|
import { withSqlite } from '../source.js';
|
|
@@ -70,24 +71,19 @@ export async function hermesSessionsInStore(path) {
|
|
|
70
71
|
}).catch(() => undefined);
|
|
71
72
|
return refs;
|
|
72
73
|
}
|
|
73
|
-
export const hermesReader = {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
export const hermesReader = foldedReader({ harness: HARNESS, aliases: [], format: FORMAT }, async (home, opts) => {
|
|
75
|
+
const root = join(home, STORE.root);
|
|
76
|
+
const refs = [];
|
|
77
|
+
for (const rel of await walkFiles(root)) {
|
|
78
|
+
if (basename(rel) !== 'state.db')
|
|
79
|
+
continue;
|
|
80
|
+
const path = join(root, rel);
|
|
81
|
+
const mtime = await mtimeMs(path);
|
|
82
|
+
for (const ref of await hermesSessionsInStore(path)) {
|
|
83
|
+
if (opts.nativeSessionId && ref.nativeSessionId !== opts.nativeSessionId)
|
|
80
84
|
continue;
|
|
81
|
-
|
|
82
|
-
const mtime = await mtimeMs(path);
|
|
83
|
-
for (const ref of await hermesSessionsInStore(path)) {
|
|
84
|
-
if (opts.nativeSessionId && ref.nativeSessionId !== opts.nativeSessionId)
|
|
85
|
-
continue;
|
|
86
|
-
refs.push({ ...ref, home, mtimeMs: mtime });
|
|
87
|
-
}
|
|
85
|
+
refs.push({ ...ref, home, mtimeMs: mtime });
|
|
88
86
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
async summarize(ref, _opts = {}) { return (await fold(ref, 'summary')).summary(); },
|
|
93
|
-
};
|
|
87
|
+
}
|
|
88
|
+
return refs;
|
|
89
|
+
}, fold);
|
package/dist/formats/kimi.js
CHANGED
|
@@ -4,7 +4,7 @@ import { SessionBuilder, count, sessionError, str, textOf, usageOrNull } from '.
|
|
|
4
4
|
import { fileRecords } from '../source.js';
|
|
5
5
|
import { KIMI_STORES } from '../catalog.js';
|
|
6
6
|
import { EVIDENCE, mtimeMs, storeGlob, walkFiles, withinPath } from '../stores.js';
|
|
7
|
-
import { runFold } from './fold.js';
|
|
7
|
+
import { foldedReader, runFold } from './fold.js';
|
|
8
8
|
const FORMAT = 'kimi.session-dir';
|
|
9
9
|
const HARNESS = 'kimi-code';
|
|
10
10
|
const WIRE = '*/{id}/wire.jsonl';
|
|
@@ -234,21 +234,7 @@ async function locate(home, opts) {
|
|
|
234
234
|
}
|
|
235
235
|
return refs.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
236
236
|
}
|
|
237
|
-
export const kimiReader = {
|
|
238
|
-
harness: HARNESS,
|
|
239
|
-
aliases: ['kimi', 'kimi-cli'],
|
|
240
|
-
formats: [FORMAT],
|
|
241
|
-
stores: KIMI_STORES,
|
|
242
|
-
globs: { session: WIRE, children: CHILD_WIRE },
|
|
243
|
-
evidence: EVIDENCE[FORMAT],
|
|
244
|
-
locate: (home, opts = {}) => locate(home, opts),
|
|
245
|
-
async read(ref, opts = {}) {
|
|
246
|
-
return (await fold(ref, 'full', opts)).build();
|
|
247
|
-
},
|
|
248
|
-
async summarize(ref, opts = {}) {
|
|
249
|
-
return (await fold(ref, 'summary', opts)).summary();
|
|
250
|
-
},
|
|
251
|
-
};
|
|
237
|
+
export const kimiReader = foldedReader({ harness: HARNESS, aliases: ['kimi', 'kimi-cli'], format: FORMAT, globs: { session: WIRE, children: CHILD_WIRE }, stores: KIMI_STORES }, locate, fold);
|
|
252
238
|
export function kimiRefForFile(path) {
|
|
253
239
|
const { id, parent } = sessionIdentity(path);
|
|
254
240
|
return { harness: HARNESS, format: FORMAT, nativeSessionId: id, path, files: [path], home: null, cwd: null, mtimeMs: 0, parentNativeSessionId: parent };
|
package/dist/formats/nanoclaw.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { foldedReader } from './fold.js';
|
|
1
2
|
import { basename, dirname, join } from 'node:path';
|
|
2
3
|
import { SessionBuilder } from '../builder.js';
|
|
3
4
|
import { withSqlite } from '../source.js';
|
|
@@ -34,32 +35,22 @@ async function fold(ref, mode) {
|
|
|
34
35
|
builder.inferEnding();
|
|
35
36
|
return builder;
|
|
36
37
|
}
|
|
37
|
-
export const nanoclawReader = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const mtime = await mtimeMs(path);
|
|
54
|
-
if ((opts.sinceMs && mtime < opts.sinceMs) || (opts.nativeSessionId && id !== opts.nativeSessionId))
|
|
55
|
-
continue;
|
|
56
|
-
refs.push({ harness: HARNESS, format: FORMAT, nativeSessionId: id, path, files: [path, join(dirname(path), 'inbound.db')], home, cwd: null, mtimeMs: mtime, parentNativeSessionId: null });
|
|
57
|
-
}
|
|
58
|
-
return refs.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
59
|
-
},
|
|
60
|
-
async read(ref, _opts = {}) { return (await fold(ref, 'full')).build(); },
|
|
61
|
-
async summarize(ref, _opts = {}) { return (await fold(ref, 'summary')).summary(); },
|
|
62
|
-
};
|
|
38
|
+
export const nanoclawReader = foldedReader({ harness: HARNESS, aliases: [], format: FORMAT }, async (home, opts) => {
|
|
39
|
+
const root = join(home, STORE.root);
|
|
40
|
+
const pattern = storeGlob(STORE.files[0], opts.nativeSessionId);
|
|
41
|
+
const refs = [];
|
|
42
|
+
for (const rel of await walkFiles(root)) {
|
|
43
|
+
if (!pattern.test(rel))
|
|
44
|
+
continue;
|
|
45
|
+
const path = join(root, rel);
|
|
46
|
+
const id = basename(dirname(rel));
|
|
47
|
+
const mtime = await mtimeMs(path);
|
|
48
|
+
if ((opts.sinceMs && mtime < opts.sinceMs) || (opts.nativeSessionId && id !== opts.nativeSessionId))
|
|
49
|
+
continue;
|
|
50
|
+
refs.push({ harness: HARNESS, format: FORMAT, nativeSessionId: id, path, files: [path, join(dirname(path), 'inbound.db')], home, cwd: null, mtimeMs: mtime, parentNativeSessionId: null });
|
|
51
|
+
}
|
|
52
|
+
return refs.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
53
|
+
}, fold);
|
|
63
54
|
export function nanoclawRefForFile(path) {
|
|
64
55
|
return { harness: HARNESS, format: FORMAT, nativeSessionId: basename(dirname(path)), path, files: [path], home: null, cwd: null, mtimeMs: 0, parentNativeSessionId: null };
|
|
65
56
|
}
|
package/dist/formats/openclaw.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { foldedReader } from './fold.js';
|
|
1
2
|
import { zstdDecompressSync } from 'node:zlib';
|
|
2
3
|
import { join } from 'node:path';
|
|
3
4
|
import { isRecord } from '@tangle-network/agent-core';
|
|
@@ -80,23 +81,18 @@ async function fold(ref, mode) {
|
|
|
80
81
|
builder.inferEnding();
|
|
81
82
|
return builder;
|
|
82
83
|
}
|
|
83
|
-
export const openclawReader = {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
export const openclawReader = foldedReader({ harness: HARNESS, aliases: [], format: FORMAT }, async (home, opts) => {
|
|
85
|
+
const refs = [];
|
|
86
|
+
for (const rel of await walkFiles(join(home, STORE.root))) {
|
|
87
|
+
if (!rel.endsWith('openclaw-agent.sqlite'))
|
|
88
|
+
continue;
|
|
89
|
+
const path = join(home, STORE.root, rel);
|
|
90
|
+
const mtime = await mtimeMs(path);
|
|
91
|
+
for (const ref of await openclawSessionsInStore(path)) {
|
|
92
|
+
if (opts.nativeSessionId && ref.nativeSessionId !== opts.nativeSessionId)
|
|
89
93
|
continue;
|
|
90
|
-
|
|
91
|
-
const mtime = await mtimeMs(path);
|
|
92
|
-
for (const ref of await openclawSessionsInStore(path)) {
|
|
93
|
-
if (opts.nativeSessionId && ref.nativeSessionId !== opts.nativeSessionId)
|
|
94
|
-
continue;
|
|
95
|
-
refs.push({ ...ref, home, mtimeMs: mtime });
|
|
96
|
-
}
|
|
94
|
+
refs.push({ ...ref, home, mtimeMs: mtime });
|
|
97
95
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
async summarize(ref, _opts = {}) { return (await fold(ref, 'summary')).summary(); },
|
|
102
|
-
};
|
|
96
|
+
}
|
|
97
|
+
return refs.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
98
|
+
}, fold);
|
package/dist/formats/opencode.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { foldedReader } from './fold.js';
|
|
1
2
|
import { isRecord } from '@tangle-network/agent-core';
|
|
2
3
|
import { createHash } from 'node:crypto';
|
|
3
4
|
import { join } from 'node:path';
|
|
@@ -208,28 +209,14 @@ export async function opencodeSessionsInStore(path, home, opts = {}) {
|
|
|
208
209
|
.map((row) => ({ harness: HARNESS, format: FORMAT, nativeSessionId: row.id, path, files, home, cwd: row.directory, mtimeMs: row.time_updated || mtime, parentNativeSessionId: row.parent_id }));
|
|
209
210
|
});
|
|
210
211
|
}
|
|
211
|
-
export const opencodeReader = {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
if (isMissing(error))
|
|
225
|
-
return [];
|
|
226
|
-
throw error;
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
async read(ref, opts = {}) {
|
|
230
|
-
return (await fold(ref, 'full', opts)).build();
|
|
231
|
-
},
|
|
232
|
-
async summarize(ref, opts = {}) {
|
|
233
|
-
return (await fold(ref, 'summary', opts)).summary();
|
|
234
|
-
},
|
|
235
|
-
};
|
|
212
|
+
export const opencodeReader = foldedReader({ harness: HARNESS, aliases: ['opencode-acp', 'opencode-cli'], format: FORMAT }, async (home, opts) => {
|
|
213
|
+
const path = join(home, STORE.root, STORE.files[0]);
|
|
214
|
+
try {
|
|
215
|
+
return await opencodeSessionsInStore(path, home, opts);
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
if (isMissing(error))
|
|
219
|
+
return [];
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
}, fold);
|
package/dist/formats/pi.js
CHANGED
|
@@ -2,7 +2,7 @@ import { isRecord } from '@tangle-network/agent-core';
|
|
|
2
2
|
import { basename, join } from 'node:path';
|
|
3
3
|
import { SessionBuilder, count, sessionError, str, textOf, usageOrNull } from '../builder.js';
|
|
4
4
|
import { fileRecords } from '../source.js';
|
|
5
|
-
import { runFold } from './fold.js';
|
|
5
|
+
import { foldedReader, runFold } from './fold.js';
|
|
6
6
|
import { EVIDENCE, STORES, mtimeMs, storeGlob, walkFiles, withinPath } from '../stores.js';
|
|
7
7
|
import { headRecord } from './head.js';
|
|
8
8
|
const FORMAT = 'pi.session-jsonl';
|
|
@@ -167,21 +167,7 @@ async function locate(home, opts) {
|
|
|
167
167
|
}
|
|
168
168
|
return refs.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
169
169
|
}
|
|
170
|
-
export const piReader = {
|
|
171
|
-
harness: HARNESS,
|
|
172
|
-
aliases: ['pi-coding-agent', 'pi-agent'],
|
|
173
|
-
formats: [FORMAT],
|
|
174
|
-
stores: [STORE],
|
|
175
|
-
globs: { session: STORE.files[0] },
|
|
176
|
-
evidence: EVIDENCE[FORMAT],
|
|
177
|
-
locate: (home, opts = {}) => locate(home, opts),
|
|
178
|
-
async read(ref, opts = {}) {
|
|
179
|
-
return (await fold(ref, 'full', opts)).build();
|
|
180
|
-
},
|
|
181
|
-
async summarize(ref, opts = {}) {
|
|
182
|
-
return (await fold(ref, 'summary', opts)).summary();
|
|
183
|
-
},
|
|
184
|
-
};
|
|
170
|
+
export const piReader = foldedReader({ harness: HARNESS, aliases: ['pi-coding-agent', 'pi-agent'], format: FORMAT }, locate, fold);
|
|
185
171
|
export function piRefForFile(path) {
|
|
186
172
|
return { harness: HARNESS, format: FORMAT, nativeSessionId: idFromName(path), path, files: [path], home: null, cwd: null, mtimeMs: 0, parentNativeSessionId: null };
|
|
187
173
|
}
|
package/dist/formats/prime.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { basename, join } from 'node:path';
|
|
2
2
|
import { fileRecords } from '../source.js';
|
|
3
|
-
import {
|
|
4
|
-
import { runFold } from './fold.js';
|
|
3
|
+
import { STORES, mtimeMs, storeGlob, walkFiles } from '../stores.js';
|
|
4
|
+
import { foldedReader, runFold } from './fold.js';
|
|
5
5
|
import { createFold } from './pi.js';
|
|
6
6
|
const FORMAT = 'prime.session-jsonl';
|
|
7
7
|
const STORE = STORES[FORMAT];
|
|
@@ -13,23 +13,18 @@ async function fold(ref, mode, opts) {
|
|
|
13
13
|
const records = fileRecords(ref.path, { strict: opts.corruption === 'strict', signal: opts.signal });
|
|
14
14
|
return runFold(createFold(ref, mode, records.stats, HARNESS, FORMAT), records);
|
|
15
15
|
}
|
|
16
|
-
export const primeReader = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return refs.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
32
|
-
},
|
|
33
|
-
async read(ref, opts = {}) { return (await fold(ref, 'full', opts)).build(); },
|
|
34
|
-
async summarize(ref, opts = {}) { return (await fold(ref, 'summary', opts)).summary(); },
|
|
35
|
-
};
|
|
16
|
+
export const primeReader = foldedReader({ harness: HARNESS, aliases: [], format: FORMAT }, async (home, opts) => {
|
|
17
|
+
const root = join(home, STORE.root);
|
|
18
|
+
const pattern = storeGlob(STORE.files[0], opts.nativeSessionId);
|
|
19
|
+
const refs = [];
|
|
20
|
+
for (const rel of await walkFiles(root)) {
|
|
21
|
+
if (!pattern.test(rel))
|
|
22
|
+
continue;
|
|
23
|
+
const path = join(root, rel);
|
|
24
|
+
const id = idFromName(rel);
|
|
25
|
+
if (opts.nativeSessionId && id !== opts.nativeSessionId)
|
|
26
|
+
continue;
|
|
27
|
+
refs.push({ harness: HARNESS, format: FORMAT, nativeSessionId: id, path, files: [path], home, cwd: null, mtimeMs: await mtimeMs(path), parentNativeSessionId: null });
|
|
28
|
+
}
|
|
29
|
+
return refs.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
30
|
+
}, fold);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { HarnessSession } from '../schema.js';
|
|
2
|
+
export interface SandboxEventsRun {
|
|
3
|
+
harness: string;
|
|
4
|
+
nativeSessionId: string;
|
|
5
|
+
/** The task the agent was given; the stream never repeats it. */
|
|
6
|
+
task: string;
|
|
7
|
+
/** The settled final answer; a stream can stop before its last text part lands. */
|
|
8
|
+
answer: string;
|
|
9
|
+
events: readonly unknown[];
|
|
10
|
+
}
|
|
11
|
+
/** One agent's run as the Sandbox streamed it: every harness reaches this stream as the same parts. */
|
|
12
|
+
export declare function sandboxEventsSession(run: SandboxEventsRun): HarnessSession;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { isRecord } from '@tangle-network/agent-core';
|
|
2
|
+
import { SessionBuilder, str } from '../builder.js';
|
|
3
|
+
import { EVIDENCE } from '../stores.js';
|
|
4
|
+
const FORMAT = 'sandbox.events';
|
|
5
|
+
/**
|
|
6
|
+
* The newest copy of each part, in first-seen order. A part is re-sent whole as it grows, and a
|
|
7
|
+
* reasoning or text part can keep its id across messages while its text accumulates, so a later
|
|
8
|
+
* message holds only what it added.
|
|
9
|
+
*/
|
|
10
|
+
function partsOf(events) {
|
|
11
|
+
const parts = new Map();
|
|
12
|
+
const newest = new Map();
|
|
13
|
+
const carried = new Map();
|
|
14
|
+
for (const event of events) {
|
|
15
|
+
if (!isRecord(event) || event.type !== 'message.part.updated' || !isRecord(event.data))
|
|
16
|
+
continue;
|
|
17
|
+
const part = event.data.part;
|
|
18
|
+
if (!isRecord(part) || typeof part.id !== 'string')
|
|
19
|
+
continue;
|
|
20
|
+
const seen = newest.get(part.id);
|
|
21
|
+
if (typeof seen?.text === 'string' && seen.message !== part.messageID)
|
|
22
|
+
carried.set(part.id, seen.text);
|
|
23
|
+
newest.set(part.id, { message: part.messageID, text: part.text });
|
|
24
|
+
const prior = carried.get(part.id) ?? '';
|
|
25
|
+
const added = typeof part.text === 'string' && part.text.startsWith(prior) ? part.text.slice(prior.length).trim() : part.text;
|
|
26
|
+
parts.set(`${str(part.messageID)}:${part.id}`, { ...part, text: added });
|
|
27
|
+
}
|
|
28
|
+
return [...parts.values()];
|
|
29
|
+
}
|
|
30
|
+
/** One agent's run as the Sandbox streamed it: every harness reaches this stream as the same parts. */
|
|
31
|
+
export function sandboxEventsSession(run) {
|
|
32
|
+
const { nativeSessionId: id } = run;
|
|
33
|
+
const builder = new SessionBuilder(run.harness, FORMAT, EVIDENCE[FORMAT].servedModel, 'full', id);
|
|
34
|
+
builder.message({ id: `${id}:task`, role: 'user', actor: 'subagent-spawn', at: null, modelCallId: null, parts: [{ type: 'text', text: run.task }] });
|
|
35
|
+
let turn = null;
|
|
36
|
+
let turns = 0;
|
|
37
|
+
let said = '';
|
|
38
|
+
const assistant = () => {
|
|
39
|
+
turn ??= builder.message({ id: `${id}:turn:${(turns += 1)}`, role: 'assistant', actor: 'agent', at: null, modelCallId: null, parts: [] }).id;
|
|
40
|
+
return turn;
|
|
41
|
+
};
|
|
42
|
+
for (const part of partsOf(run.events)) {
|
|
43
|
+
if (part.type === 'tool') {
|
|
44
|
+
const state = isRecord(part.state) ? part.state : {};
|
|
45
|
+
const time = isRecord(state.time) ? state.time : {};
|
|
46
|
+
const call = `${str(part.messageID)}:${str(part.callID) ?? str(part.id)}`;
|
|
47
|
+
const messageId = assistant();
|
|
48
|
+
builder.appendParts(messageId, [{ type: 'tool-call', toolCallId: call }]);
|
|
49
|
+
builder.toolCall({ id: call, name: str(part.tool) ?? 'unknown', input: state.input ?? null, inputText: null, at: builder.seen(time.start), messageId });
|
|
50
|
+
turn = null;
|
|
51
|
+
if (state.status !== 'completed' && state.status !== 'failed' && state.status !== 'error')
|
|
52
|
+
continue;
|
|
53
|
+
const isError = state.status !== 'completed';
|
|
54
|
+
const output = isError ? (state.error ?? null) : (state.output ?? null);
|
|
55
|
+
const at = builder.seen(time.end);
|
|
56
|
+
builder.message({ id: `${call}:result`, role: 'tool', actor: 'tool-result', at, modelCallId: null, parts: [{ type: 'tool-result', toolCallId: call }] });
|
|
57
|
+
builder.toolResult(call, { output, text: typeof output === 'string' ? output : null, isError, at, messageId: `${call}:result` });
|
|
58
|
+
}
|
|
59
|
+
else if ((part.type === 'text' || part.type === 'reasoning') && typeof part.text === 'string' && part.text.length > 0) {
|
|
60
|
+
builder.appendParts(assistant(), [part.type === 'text' ? { type: 'text', text: part.text } : { type: 'reasoning', text: part.text, redacted: false }]);
|
|
61
|
+
if (part.type === 'text')
|
|
62
|
+
said = part.text;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!said.trim().endsWith(run.answer.trim()))
|
|
66
|
+
builder.appendParts(assistant(), [{ type: 'text', text: run.answer }]);
|
|
67
|
+
builder.end({ status: 'completed', error: null, at: null });
|
|
68
|
+
return builder.build();
|
|
69
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export { grokReader, grokRefForFile } from './formats/grok.js';
|
|
|
14
14
|
export { nanoclawReader, nanoclawRefForFile } from './formats/nanoclaw.js';
|
|
15
15
|
export { hermesReader, hermesSessionsInStore } from './formats/hermes.js';
|
|
16
16
|
export { primeReader } from './formats/prime.js';
|
|
17
|
+
export { sandboxEventsSession, type SandboxEventsRun } from './formats/sandbox-events.js';
|
|
17
18
|
export { openclawReader } from './formats/openclaw.js';
|
|
18
19
|
export { listCapture, readCapture, RETENTION_MANIFEST_KIND, RETENTION_SESSIONS, type CaptureListing, type CapturedSessionRef, } from './capture.js';
|
|
19
20
|
export { SessionParseError } from './source.js';
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export { grokReader, grokRefForFile } from './formats/grok.js';
|
|
|
13
13
|
export { nanoclawReader, nanoclawRefForFile } from './formats/nanoclaw.js';
|
|
14
14
|
export { hermesReader, hermesSessionsInStore } from './formats/hermes.js';
|
|
15
15
|
export { primeReader } from './formats/prime.js';
|
|
16
|
+
export { sandboxEventsSession } from './formats/sandbox-events.js';
|
|
16
17
|
export { openclawReader } from './formats/openclaw.js';
|
|
17
18
|
export { listCapture, readCapture, RETENTION_MANIFEST_KIND, RETENTION_SESSIONS, } from './capture.js';
|
|
18
19
|
export { SessionParseError } from './source.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/harness-sessions",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "One reader for every coding-agent harness's native session (Claude Code, Codex, OpenCode, Pi): store layouts, a normalized session with messages, tool calls, served models, usage and ending errors, and projections to chat messages, OTLP spans and turns",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|