@tangle-network/harness-sessions 1.0.6 → 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.
Files changed (51) hide show
  1. package/dist/builder.d.ts +0 -13
  2. package/dist/builder.js +0 -17
  3. package/dist/capture.d.ts +0 -8
  4. package/dist/capture.js +3 -14
  5. package/dist/catalog.d.ts +16 -18
  6. package/dist/catalog.js +6 -20
  7. package/dist/cli.js +0 -1
  8. package/dist/formats/claude-code.d.ts +0 -1
  9. package/dist/formats/claude-code.js +2 -25
  10. package/dist/formats/claude-records.d.ts +0 -8
  11. package/dist/formats/claude-records.js +0 -6
  12. package/dist/formats/codex.js +2 -45
  13. package/dist/formats/factory.js +2 -19
  14. package/dist/formats/fold.d.ts +6 -2
  15. package/dist/formats/fold.js +16 -0
  16. package/dist/formats/grok.js +29 -30
  17. package/dist/formats/head.d.ts +0 -1
  18. package/dist/formats/head.js +0 -4
  19. package/dist/formats/hermes.d.ts +3 -0
  20. package/dist/formats/hermes.js +89 -0
  21. package/dist/formats/kimi.d.ts +0 -1
  22. package/dist/formats/kimi.js +2 -22
  23. package/dist/formats/nanoclaw.js +17 -27
  24. package/dist/formats/openclaw.d.ts +3 -0
  25. package/dist/formats/openclaw.js +98 -0
  26. package/dist/formats/opencode.d.ts +0 -1
  27. package/dist/formats/opencode.js +12 -31
  28. package/dist/formats/pi.d.ts +1 -1
  29. package/dist/formats/pi.js +5 -25
  30. package/dist/formats/prime.d.ts +2 -0
  31. package/dist/formats/prime.js +30 -0
  32. package/dist/formats/sandbox-events.d.ts +12 -0
  33. package/dist/formats/sandbox-events.js +69 -0
  34. package/dist/index.d.ts +4 -1
  35. package/dist/index.js +4 -0
  36. package/dist/input.d.ts +0 -6
  37. package/dist/input.js +0 -2
  38. package/dist/projections/chat.d.ts +0 -4
  39. package/dist/projections/chat.js +0 -1
  40. package/dist/projections/otlp.d.ts +0 -2
  41. package/dist/projections/otlp.js +0 -1
  42. package/dist/projections/turns.d.ts +0 -14
  43. package/dist/projections/turns.js +0 -3
  44. package/dist/registry.d.ts +0 -5
  45. package/dist/registry.js +4 -6
  46. package/dist/schema.d.ts +0 -39
  47. package/dist/source.d.ts +0 -11
  48. package/dist/source.js +0 -19
  49. package/dist/stores.d.ts +0 -4
  50. package/dist/stores.js +0 -5
  51. package/package.json +1 -1
@@ -0,0 +1,98 @@
1
+ import { foldedReader } from './fold.js';
2
+ import { zstdDecompressSync } from 'node:zlib';
3
+ import { join } from 'node:path';
4
+ import { isRecord } from '@tangle-network/agent-core';
5
+ import { SessionBuilder, count, str, textOf, usageOrNull } from '../builder.js';
6
+ import { withSqlite } from '../source.js';
7
+ import { EVIDENCE, STORES, mtimeMs, walkFiles } from '../stores.js';
8
+ const FORMAT = 'openclaw.session-jsonl';
9
+ const STORE = STORES[FORMAT];
10
+ const HARNESS = 'openclaw';
11
+ const TOOL_CALL = new Set(['toolCall', 'toolUse', 'functionCall']);
12
+ function usageOf(value) {
13
+ if (!isRecord(value))
14
+ return null;
15
+ return usageOrNull({ input: count(value.input), output: count(value.output), reasoning: count(value.reasoning), cacheRead: count(value.cacheRead), cacheWrite: count(value.cacheWrite) });
16
+ }
17
+ function decode(json, zstd) {
18
+ const text = typeof json === 'string' && json ? json : zstd instanceof Uint8Array ? zstdDecompressSync(zstd).toString('utf8') : null;
19
+ if (!text)
20
+ return null;
21
+ try {
22
+ const value = JSON.parse(text);
23
+ return isRecord(value) ? value : null;
24
+ }
25
+ catch {
26
+ return null;
27
+ }
28
+ }
29
+ function readDb(db, sessionId, builder) {
30
+ const rows = db.prepare('SELECT event_json, event_zstd FROM transcript_events WHERE session_id = ? ORDER BY seq').all(sessionId);
31
+ let calls = 0;
32
+ for (const row of rows) {
33
+ const event = decode(row.event_json, row.event_zstd);
34
+ if (!event || event.type !== 'message' || !isRecord(event.message))
35
+ continue;
36
+ const message = event.message;
37
+ const role = str(message.role);
38
+ const at = builder.seen(event.timestamp);
39
+ const id = str(event.id) ?? `${sessionId}:${calls}`;
40
+ const text = textOf(message.content) ?? str(message.content);
41
+ if (role === 'user' && text) {
42
+ builder.message({ id, role: 'user', actor: 'human', at, modelCallId: null, parts: [{ type: 'text', text }] });
43
+ continue;
44
+ }
45
+ if (role === 'toolResult') {
46
+ const callId = str(message.toolCallId) ?? str(message.toolUseId) ?? id;
47
+ builder.toolResult(callId, { output: message.content ?? null, text, isError: message.isError === true, at, messageId: id });
48
+ builder.message({ id, role: 'tool', actor: 'tool-result', at, modelCallId: null, parts: [{ type: 'tool-result', toolCallId: callId }] });
49
+ continue;
50
+ }
51
+ if (role !== 'assistant')
52
+ continue;
53
+ const model = str(message.responseModel) ?? str(message.model);
54
+ const modelCallId = `${sessionId}:${calls}`;
55
+ builder.modelCall({ id: modelCallId, at, provider: str(message.provider), servedModel: model, requestedModel: str(message.model), usage: usageOf(message.usage), costUsd: null, stopReason: str(message.stopReason), error: null });
56
+ calls += 1;
57
+ const parts = text ? [{ type: 'text', text }] : [];
58
+ if (Array.isArray(message.content))
59
+ for (const block of message.content) {
60
+ if (!isRecord(block) || typeof block.type !== 'string' || !TOOL_CALL.has(block.type))
61
+ continue;
62
+ const callId = str(block.id) ?? `${modelCallId}:call`;
63
+ const input = block.arguments ?? block.input ?? null;
64
+ parts.push({ type: 'tool-call', toolCallId: callId });
65
+ builder.toolCall({ id: callId, name: str(block.name) ?? 'tool', input, inputText: typeof input === 'string' ? input : null, at, messageId: id });
66
+ }
67
+ builder.message({ id, role: 'assistant', actor: 'agent', at, modelCallId, parts });
68
+ }
69
+ }
70
+ export async function openclawSessionsInStore(path) {
71
+ const refs = [];
72
+ await withSqlite(path, (db) => {
73
+ for (const row of db.prepare('SELECT session_id FROM session_windows').all())
74
+ refs.push({ harness: HARNESS, format: FORMAT, nativeSessionId: row.session_id, path, files: [path], home: null, cwd: null, mtimeMs: 0, parentNativeSessionId: null });
75
+ }).catch(() => undefined);
76
+ return refs;
77
+ }
78
+ async function fold(ref, mode) {
79
+ const builder = new SessionBuilder(HARNESS, FORMAT, EVIDENCE[FORMAT].servedModel, mode, ref.nativeSessionId, ref.parentNativeSessionId);
80
+ await withSqlite(ref.path, (db) => readDb(db, ref.nativeSessionId, builder));
81
+ builder.inferEnding();
82
+ return builder;
83
+ }
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)
93
+ continue;
94
+ refs.push({ ...ref, home, mtimeMs: mtime });
95
+ }
96
+ }
97
+ return refs.sort((a, b) => b.mtimeMs - a.mtimeMs);
98
+ }, fold);
@@ -1,4 +1,3 @@
1
1
  import type { HarnessSessionReader, LocateOptions, SessionRef } from '../schema.js';
2
- /** Every session in one store file, read in place without writing it. */
3
2
  export declare function opencodeSessionsInStore(path: string, home: string | null, opts?: LocateOptions): Promise<SessionRef[]>;
4
3
  export declare const opencodeReader: HarnessSessionReader;
@@ -1,5 +1,5 @@
1
+ import { foldedReader } from './fold.js';
1
2
  import { isRecord } from '@tangle-network/agent-core';
2
- /** OpenCode sqlite at ~/.local/share/opencode/opencode.db. Opened read-only, including the wal. */
3
3
  import { createHash } from 'node:crypto';
4
4
  import { join } from 'node:path';
5
5
  import { SessionBuilder, count, isoTime, sessionError, str, usageOrNull } from '../builder.js';
@@ -47,8 +47,6 @@ function foldSession(db, ref, mode, builder) {
47
47
  builder.cwd = session.directory;
48
48
  builder.parentNativeSessionId = session.parent_id ?? null;
49
49
  builder.seen(session.time_created);
50
- // The session's source is the rows this fold reads, not the whole store: a digest of the store
51
- // file would read every other session in it and change whenever any of them did.
52
50
  const digest = createHash('sha256').update(JSON.stringify(session));
53
51
  let bytes = 0;
54
52
  const note = (row) => {
@@ -159,7 +157,6 @@ function foldSession(db, ref, mode, builder) {
159
157
  break;
160
158
  }
161
159
  case 'retry': {
162
- // A failed request OpenCode retried: a model call that returned no answer.
163
160
  builder.modelCall({ id: `${row.id}:retry:${partId}`, at: isoTime(partTime.created) ?? partAt, provider, servedModel: null, requestedModel: model, usage: null, costUsd: null, stopReason: null, error: errorOf(part.error, partAt) ?? sessionError('retry', 'retried request', partAt) });
164
161
  break;
165
162
  }
@@ -168,7 +165,6 @@ function foldSession(db, ref, mode, builder) {
168
165
  }
169
166
  }
170
167
  if (steps === 0) {
171
- // No response step was recorded: the request failed or the process stopped first.
172
168
  builder.modelCall({ id: `${row.id}:request`, at, provider: messageError ? null : provider, servedModel: messageError ? null : model, requestedModel: model, usage: usageOf(data.tokens), costUsd: count(data.cost), stopReason: str(data.finish), error: messageError });
173
169
  if (messageError)
174
170
  builder.message({ id: row.id, role: 'assistant', actor: 'injected', at, modelCallId: `${row.id}:request`, parts: [{ type: 'text', text: messageError.message }] });
@@ -198,7 +194,6 @@ async function fold(ref, mode, options) {
198
194
  builder.markTruncated(`${ref.path}: the store copy was cut short`);
199
195
  return builder;
200
196
  }
201
- /** Every session in one store file, read in place without writing it. */
202
197
  export async function opencodeSessionsInStore(path, home, opts = {}) {
203
198
  const mtime = await mtimeMs(path);
204
199
  const files = [path];
@@ -214,28 +209,14 @@ export async function opencodeSessionsInStore(path, home, opts = {}) {
214
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 }));
215
210
  });
216
211
  }
217
- export const opencodeReader = {
218
- harness: HARNESS,
219
- aliases: ['opencode-acp', 'opencode-cli'],
220
- formats: [FORMAT],
221
- stores: [STORE],
222
- globs: { session: STORE.files[0] },
223
- evidence: EVIDENCE[FORMAT],
224
- async locate(home, opts = {}) {
225
- const path = join(home, STORE.root, STORE.files[0]);
226
- try {
227
- return await opencodeSessionsInStore(path, home, opts);
228
- }
229
- catch (error) {
230
- if (isMissing(error))
231
- return [];
232
- throw error;
233
- }
234
- },
235
- async read(ref, opts = {}) {
236
- return (await fold(ref, 'full', opts)).build();
237
- },
238
- async summarize(ref, opts = {}) {
239
- return (await fold(ref, 'summary', opts)).summary();
240
- },
241
- };
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);
@@ -2,7 +2,7 @@ import { SessionBuilder, type BuildMode } from '../builder.js';
2
2
  import type { HarnessSessionReader, ReadOptions, SessionRef } from '../schema.js';
3
3
  import { type RecordSource, type SourceStats } from '../source.js';
4
4
  import { type SessionFold } from './fold.js';
5
- export declare function createFold(ref: SessionRef, mode: BuildMode, stats: SourceStats): SessionFold;
5
+ export declare function createFold(ref: SessionRef, mode: BuildMode, stats: SourceStats, harness?: string, format?: 'pi.session-jsonl' | 'prime.session-jsonl'): SessionFold;
6
6
  export declare function fold(ref: SessionRef, mode: BuildMode, options: ReadOptions, source?: RecordSource): Promise<SessionBuilder>;
7
7
  export declare const piReader: HarnessSessionReader;
8
8
  export declare function piRefForFile(path: string): SessionRef;
@@ -1,9 +1,8 @@
1
1
  import { isRecord } from '@tangle-network/agent-core';
2
- /** Pi jsonl under ~/.pi/agent/sessions. Session header, then message entries. Usage fields are disjoint. */
3
2
  import { basename, join } from 'node:path';
4
3
  import { SessionBuilder, count, sessionError, str, textOf, usageOrNull } from '../builder.js';
5
4
  import { fileRecords } from '../source.js';
6
- import { runFold } from './fold.js';
5
+ import { foldedReader, runFold } from './fold.js';
7
6
  import { EVIDENCE, STORES, mtimeMs, storeGlob, walkFiles, withinPath } from '../stores.js';
8
7
  import { headRecord } from './head.js';
9
8
  const FORMAT = 'pi.session-jsonl';
@@ -42,12 +41,11 @@ function contentParts(content, ref) {
42
41
  }
43
42
  return parts;
44
43
  }
45
- /** Session ids are the part of the file name after the timestamp: `<timestamp>_<id>.jsonl`. */
46
44
  function idFromName(path) {
47
45
  return basename(path, '.jsonl').replace(/^[\dTZ.:-]+_/u, '');
48
46
  }
49
- export function createFold(ref, mode, stats) {
50
- const builder = new SessionBuilder(HARNESS, FORMAT, EVIDENCE[FORMAT].servedModel, mode, ref.nativeSessionId, ref.parentNativeSessionId);
47
+ export function createFold(ref, mode, stats, harness = HARNESS, format = FORMAT) {
48
+ const builder = new SessionBuilder(harness, format, EVIDENCE[format].servedModel, mode, ref.nativeSessionId, ref.parentNativeSessionId);
51
49
  let previousId = null;
52
50
  let branches = 0;
53
51
  let compactions = 0;
@@ -57,7 +55,7 @@ export function createFold(ref, mode, stats) {
57
55
  const id = str(entry.id) ?? `${builder.nativeSessionId}:${stats.line}`;
58
56
  const parentId = str(entry.parentId);
59
57
  if (entry.type === 'session') {
60
- if (typeof entry.id === 'string')
58
+ if (typeof entry.id === 'string' && harness !== 'prime')
61
59
  builder.nativeSessionId = entry.id;
62
60
  builder.cwd = str(entry.cwd);
63
61
  previousId = null;
@@ -104,13 +102,10 @@ export function createFold(ref, mode, stats) {
104
102
  const errorText = str(message.errorMessage);
105
103
  const failed = stopReason === 'error';
106
104
  const { usage, cost } = usageOf(message.usage);
107
- // A failed request returned no response, so no model served it; the model it was sent to
108
- // stays in the profile and the request, not here.
109
105
  builder.modelCall({
110
106
  id,
111
107
  at,
112
108
  provider: failed ? null : str(message.provider),
113
- // Pi 0.85 records the provider's own answer as responseModel; model is what it asked for.
114
109
  servedModel: failed ? null : (str(message.responseModel) ?? str(message.model)),
115
110
  requestedModel: str(message.model),
116
111
  usage,
@@ -132,7 +127,6 @@ export function createFold(ref, mode, stats) {
132
127
  aborted = stopReason === 'aborted' ? { at, message: errorText } : null;
133
128
  return;
134
129
  }
135
- // Harness-injected messages (system prompts, extension messages, shell executions).
136
130
  if (role === 'system' || role === 'custom' || role === 'bashExecution') {
137
131
  builder.message({ id, role: role === 'system' ? 'system' : 'user', actor: 'injected', at, modelCallId: null, parts: contentParts(message.content ?? message.output, id) });
138
132
  }
@@ -173,21 +167,7 @@ async function locate(home, opts) {
173
167
  }
174
168
  return refs.sort((a, b) => b.mtimeMs - a.mtimeMs);
175
169
  }
176
- export const piReader = {
177
- harness: HARNESS,
178
- aliases: ['pi-coding-agent', 'pi-agent'],
179
- formats: [FORMAT],
180
- stores: [STORE],
181
- globs: { session: STORE.files[0] },
182
- evidence: EVIDENCE[FORMAT],
183
- locate: (home, opts = {}) => locate(home, opts),
184
- async read(ref, opts = {}) {
185
- return (await fold(ref, 'full', opts)).build();
186
- },
187
- async summarize(ref, opts = {}) {
188
- return (await fold(ref, 'summary', opts)).summary();
189
- },
190
- };
170
+ export const piReader = foldedReader({ harness: HARNESS, aliases: ['pi-coding-agent', 'pi-agent'], format: FORMAT }, locate, fold);
191
171
  export function piRefForFile(path) {
192
172
  return { harness: HARNESS, format: FORMAT, nativeSessionId: idFromName(path), path, files: [path], home: null, cwd: null, mtimeMs: 0, parentNativeSessionId: null };
193
173
  }
@@ -0,0 +1,2 @@
1
+ import type { HarnessSessionReader } from '../schema.js';
2
+ export declare const primeReader: HarnessSessionReader;
@@ -0,0 +1,30 @@
1
+ import { basename, join } from 'node:path';
2
+ import { fileRecords } from '../source.js';
3
+ import { STORES, mtimeMs, storeGlob, walkFiles } from '../stores.js';
4
+ import { foldedReader, runFold } from './fold.js';
5
+ import { createFold } from './pi.js';
6
+ const FORMAT = 'prime.session-jsonl';
7
+ const STORE = STORES[FORMAT];
8
+ const HARNESS = 'prime';
9
+ function idFromName(path) {
10
+ return basename(path, '.jsonl').replace(/^[\dTZ.:-]+_/u, '');
11
+ }
12
+ async function fold(ref, mode, opts) {
13
+ const records = fileRecords(ref.path, { strict: opts.corruption === 'strict', signal: opts.signal });
14
+ return runFold(createFold(ref, mode, records.stats, HARNESS, FORMAT), records);
15
+ }
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
@@ -1,4 +1,3 @@
1
- /** One normalized reader for each coding-agent harness session store. */
2
1
  export type { HarnessSession, HarnessSessionReader, LocateOptions, ModelCall, NativeSessionCopy, NativeSessionStore, Part, RawEvidenceArchiveManifestV2, ReadOptions, SessionEnding, SessionError, SessionEvidenceSources, SessionFormatId, SessionIntegrity, SessionMessage, SessionRef, SessionSummary, SessionToolCall, TokenUsage, } from './schema.js';
3
2
  export { HARNESS_SESSION_SCHEMA } from './schema.js';
4
3
  export { CODEX_HOME_RULE, EVIDENCE, SESSION_FORMAT_IDS, STORES, assertStoreRoot, isCodexHome, storeGlob, withinPath } from './catalog.js';
@@ -13,6 +12,10 @@ export { kimiReader, kimiRefForFile } from './formats/kimi.js';
13
12
  export { factoryReader, factoryRefForFile } from './formats/factory.js';
14
13
  export { grokReader, grokRefForFile } from './formats/grok.js';
15
14
  export { nanoclawReader, nanoclawRefForFile } from './formats/nanoclaw.js';
15
+ export { hermesReader, hermesSessionsInStore } from './formats/hermes.js';
16
+ export { primeReader } from './formats/prime.js';
17
+ export { sandboxEventsSession, type SandboxEventsRun } from './formats/sandbox-events.js';
18
+ export { openclawReader } from './formats/openclaw.js';
16
19
  export { listCapture, readCapture, RETENTION_MANIFEST_KIND, RETENTION_SESSIONS, type CaptureListing, type CapturedSessionRef, } from './capture.js';
17
20
  export { SessionParseError } from './source.js';
18
21
  export { servedModelKey } from './builder.js';
package/dist/index.js CHANGED
@@ -11,6 +11,10 @@ export { kimiReader, kimiRefForFile } from './formats/kimi.js';
11
11
  export { factoryReader, factoryRefForFile } from './formats/factory.js';
12
12
  export { grokReader, grokRefForFile } from './formats/grok.js';
13
13
  export { nanoclawReader, nanoclawRefForFile } from './formats/nanoclaw.js';
14
+ export { hermesReader, hermesSessionsInStore } from './formats/hermes.js';
15
+ export { primeReader } from './formats/prime.js';
16
+ export { sandboxEventsSession } from './formats/sandbox-events.js';
17
+ export { openclawReader } from './formats/openclaw.js';
14
18
  export { listCapture, readCapture, RETENTION_MANIFEST_KIND, RETENTION_SESSIONS, } from './capture.js';
15
19
  export { SessionParseError } from './source.js';
16
20
  export { servedModelKey } from './builder.js';
package/dist/input.d.ts CHANGED
@@ -5,16 +5,10 @@ export type SessionInput = {
5
5
  records: readonly unknown[];
6
6
  };
7
7
  export interface SessionInputInit {
8
- /** The native session id when the caller knows it; JSONL formats also read it from their records. */
9
8
  nativeSessionId?: string;
10
- /** Set for a subagent's own transcript; its records are the subagent's, not sidechain noise. */
11
9
  parentNativeSessionId?: string | null;
12
- /** Names the source in integrity records (a path, a blob ref). */
13
10
  label?: string;
14
- /** The file line `input` starts on, when it continues a longer file (records appended since a previous read). A record without an id of its own is named by its line, so the same record gets the same id whichever way the file is read. Default 1. */
15
11
  firstLine?: number;
16
12
  }
17
- /** Read a JSONL-format session (Claude Code, Codex, Pi, Kimi) from text or parsed records, synchronously. */
18
13
  export declare function readSessionInput(harness: string, input: SessionInput, init?: SessionInputInit, options?: Pick<ReadOptions, 'corruption'>): HarnessSession;
19
- /** Summarize a JSONL-format session from text or parsed records, synchronously. */
20
14
  export declare function summarizeSessionInput(harness: string, input: SessionInput, init?: SessionInputInit, options?: Pick<ReadOptions, 'corruption'>): SessionSummary;
package/dist/input.js CHANGED
@@ -39,11 +39,9 @@ function foldInput(harness, input, init, mode, options) {
39
39
  fold.observe(record);
40
40
  return fold.finish();
41
41
  }
42
- /** Read a JSONL-format session (Claude Code, Codex, Pi, Kimi) from text or parsed records, synchronously. */
43
42
  export function readSessionInput(harness, input, init = {}, options = {}) {
44
43
  return foldInput(harness, input, init, 'full', options).build();
45
44
  }
46
- /** Summarize a JSONL-format session from text or parsed records, synchronously. */
47
45
  export function summarizeSessionInput(harness, input, init = {}, options = {}) {
48
46
  return foldInput(harness, input, init, 'summary', options).summary();
49
47
  }
@@ -1,5 +1,4 @@
1
1
  import type { HarnessSession } from '../schema.js';
2
- /** agent-eval's chat-with-tools message (`src/rollout/schema.ts`), declared here structurally. */
3
2
  export interface ChatToolCall {
4
3
  id: string;
5
4
  type: 'function';
@@ -18,10 +17,7 @@ export interface ChatMessage {
18
17
  is_copied_context?: boolean;
19
18
  }
20
19
  export interface ChatProjectionOptions {
21
- /** Keep messages the harness injected (environment context, instructions). Default true. */
22
20
  injected?: boolean;
23
- /** Keep `system` messages. Default true. */
24
21
  system?: boolean;
25
22
  }
26
- /** The session as chat-with-tools messages: each assistant message carries its text, reasoning and tool calls; each tool result is a `tool` message answering its call. Content is complete; a projection that needs less trims it itself. */
27
23
  export declare function toChatMessages(session: HarnessSession, options?: ChatProjectionOptions): ChatMessage[];
@@ -14,7 +14,6 @@ function resultContent(output, text) {
14
14
  return '';
15
15
  return JSON.stringify(output);
16
16
  }
17
- /** The session as chat-with-tools messages: each assistant message carries its text, reasoning and tool calls; each tool result is a `tool` message answering its call. Content is complete; a projection that needs less trims it itself. */
18
17
  export function toChatMessages(session, options = {}) {
19
18
  const keepInjected = options.injected !== false;
20
19
  const keepSystem = options.system !== false;
@@ -1,8 +1,6 @@
1
1
  import { type ContractSpan } from '@tangle-network/agent-trace-contract';
2
2
  import type { HarnessSession } from '../schema.js';
3
3
  export interface OtlpProjectionOptions {
4
- /** Characters of message text kept per span attribute. Default 8000; 0 keeps none. */
5
4
  contentChars?: number;
6
5
  }
7
- /** The session as contract spans: one AGENT span for the session, one LLM span per model call (served model, tokens, cost, error status) and one TOOL span per tool call under the model call that made it. Ids derive from the native session id, so two exports of one session join. */
8
6
  export declare function toOtlpSpans(session: HarnessSession, options?: OtlpProjectionOptions): ContractSpan[];
@@ -1,6 +1,5 @@
1
1
  import { contractSpan, deriveHexId, llmSpan, toolSpan, } from '@tangle-network/agent-trace-contract';
2
2
  const cap = (text, n) => (text.length <= n ? text : `${text.slice(0, n)}…`);
3
- /** The session as contract spans: one AGENT span for the session, one LLM span per model call (served model, tokens, cost, error status) and one TOOL span per tool call under the model call that made it. Ids derive from the native session id, so two exports of one session join. */
4
3
  export function toOtlpSpans(session, options = {}) {
5
4
  const chars = options.contentChars ?? 8000;
6
5
  const traceId = deriveHexId(`${session.harness}:${session.nativeSessionId}`, 16);
@@ -1,5 +1,4 @@
1
1
  import type { HarnessSession, SessionError, SessionToolCall, TokenUsage } from '../schema.js';
2
- /** One tool invocation in a turn, previewed for storage beside a post. */
3
2
  export interface TurnToolCall {
4
3
  name: string;
5
4
  input_preview?: string;
@@ -7,7 +6,6 @@ export interface TurnToolCall {
7
6
  result_preview?: string;
8
7
  is_error?: boolean;
9
8
  }
10
- /** One turn of agent activity, the blog's trace unit (drewstone.github.io tools/harness/types.ts). */
11
9
  export interface Turn {
12
10
  role: 'user' | 'assistant' | 'system' | 'tool';
13
11
  seq?: number;
@@ -18,30 +16,18 @@ export interface Turn {
18
16
  tool_call_details?: TurnToolCall[];
19
17
  files_touched?: string[];
20
18
  had_thinking?: boolean;
21
- /** The model that answered this turn, as the session recorded it. */
22
19
  model?: string;
23
20
  usage?: TokenUsage;
24
- /** The error the model call ended with, when it failed. */
25
21
  error?: SessionError;
26
22
  ts: string;
27
23
  }
28
24
  export interface TurnOptions {
29
- /** Working directory to make touched paths relative to. Defaults to the session cwd. */
30
25
  cwd?: string | null;
31
- /** Characters kept in `text`. Default 8000. */
32
26
  textChars?: number;
33
- /** Characters kept in `text_summary`. Default 280. */
34
27
  summaryChars?: number;
35
- /** Characters kept in a tool input or result preview. Default 600. */
36
28
  previewChars?: number;
37
- /**
38
- * The files a tool call touched. Defaults to the path of an edit or write tool and the files a
39
- * patch names; a caller with its own notion (paths mentioned anywhere in the input) passes it.
40
- */
41
29
  filesOf?: (call: SessionToolCall) => string[];
42
30
  }
43
31
  export declare function summarizeText(text: string, n: number): string;
44
- /** The session as the blog's turns: one turn per human message and per assistant message, with the tool calls an assistant message made, the files they touched, the model that answered, its usage and the error it ended with. */
45
32
  export declare function toTurns(session: HarnessSession, options?: TurnOptions): Turn[];
46
- /** The model a session was answered by most often, or null when it recorded none. */
47
33
  export declare function primaryModel(session: Pick<HarnessSession, 'modelCalls'>): string | null;
@@ -12,7 +12,6 @@ function stringField(input, ...keys) {
12
12
  return input[key];
13
13
  return undefined;
14
14
  }
15
- /** Paths a patch touches, from `*** Update File:` / `*** Add File:` / `*** Delete File:` headers. */
16
15
  function patchPaths(text) {
17
16
  return [...text.matchAll(/^\*\*\* (?:Update|Add|Delete) File: (.+)$/gmu)].map((m) => m[1].trim());
18
17
  }
@@ -60,7 +59,6 @@ function inputPreview(call) {
60
59
  function text(message, type) {
61
60
  return message.parts.filter((p) => p.type === type).map((p) => p.text).join('\n');
62
61
  }
63
- /** The session as the blog's turns: one turn per human message and per assistant message, with the tool calls an assistant message made, the files they touched, the model that answered, its usage and the error it ended with. */
64
62
  export function toTurns(session, options = {}) {
65
63
  const textChars = options.textChars ?? 8000;
66
64
  const summaryChars = options.summaryChars ?? 280;
@@ -117,7 +115,6 @@ export function toTurns(session, options = {}) {
117
115
  }
118
116
  return turns;
119
117
  }
120
- /** The model a session was answered by most often, or null when it recorded none. */
121
118
  export function primaryModel(session) {
122
119
  const counts = new Map();
123
120
  for (const call of session.modelCalls)
@@ -1,11 +1,6 @@
1
1
  import type { HarnessSessionReader, SessionFormatId } from './schema.js';
2
- /** Every reader this package ships. */
3
2
  export declare function listReaders(): readonly HarnessSessionReader[];
4
- /** Harness ids and aliases that resolve to a reader. */
5
3
  export declare function knownHarnesses(): string[];
6
- /** The reader for a harness id or alias. Throws for a harness with no reader. */
7
4
  export declare function readerFor(harnessOrAlias: string): HarnessSessionReader;
8
- /** The reader for a harness, or undefined when none exists. */
9
5
  export declare function maybeReaderFor(harnessOrAlias: string): HarnessSessionReader | undefined;
10
- /** The reader that owns a session format. */
11
6
  export declare function readerForFormat(format: SessionFormatId): HarnessSessionReader;
package/dist/registry.js CHANGED
@@ -3,36 +3,34 @@ import { codexReader } from './formats/codex.js';
3
3
  import { kimiReader } from './formats/kimi.js';
4
4
  import { factoryReader } from './formats/factory.js';
5
5
  import { grokReader } from './formats/grok.js';
6
+ import { hermesReader } from './formats/hermes.js';
6
7
  import { nanoclawReader } from './formats/nanoclaw.js';
8
+ import { openclawReader } from './formats/openclaw.js';
9
+ import { primeReader } from './formats/prime.js';
7
10
  import { opencodeReader } from './formats/opencode.js';
8
11
  import { piReader } from './formats/pi.js';
9
- const READERS = [claudeCodeReader, codexReader, opencodeReader, piReader, kimiReader, factoryReader, grokReader, nanoclawReader];
12
+ const READERS = [claudeCodeReader, codexReader, opencodeReader, piReader, kimiReader, factoryReader, grokReader, nanoclawReader, hermesReader, primeReader, openclawReader];
10
13
  const BY_NAME = new Map();
11
14
  for (const reader of READERS) {
12
15
  BY_NAME.set(reader.harness, reader);
13
16
  for (const alias of reader.aliases)
14
17
  BY_NAME.set(alias, reader);
15
18
  }
16
- /** Every reader this package ships. */
17
19
  export function listReaders() {
18
20
  return READERS;
19
21
  }
20
- /** Harness ids and aliases that resolve to a reader. */
21
22
  export function knownHarnesses() {
22
23
  return [...BY_NAME.keys()].sort();
23
24
  }
24
- /** The reader for a harness id or alias. Throws for a harness with no reader. */
25
25
  export function readerFor(harnessOrAlias) {
26
26
  const reader = BY_NAME.get(harnessOrAlias) ?? BY_NAME.get(harnessOrAlias.toLowerCase());
27
27
  if (!reader)
28
28
  throw new Error(`no session reader for harness "${harnessOrAlias}"; known: ${knownHarnesses().join(', ')}`);
29
29
  return reader;
30
30
  }
31
- /** The reader for a harness, or undefined when none exists. */
32
31
  export function maybeReaderFor(harnessOrAlias) {
33
32
  return BY_NAME.get(harnessOrAlias) ?? BY_NAME.get(harnessOrAlias.toLowerCase());
34
33
  }
35
- /** The reader that owns a session format. */
36
34
  export function readerForFormat(format) {
37
35
  const reader = READERS.find((r) => r.formats.includes(format));
38
36
  if (!reader)