@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
package/dist/builder.d.ts CHANGED
@@ -1,23 +1,17 @@
1
1
  import type { HarnessSession, ModelCall, Part, SessionEnding, SessionError, SessionFormatId, SessionMessage, SessionSummary, TokenUsage } from './schema.js';
2
2
  import type { SourceStats } from './source.js';
3
3
  export type BuildMode = 'full' | 'summary';
4
- /** An ISO-8601 instant from an ISO string, epoch milliseconds or epoch seconds; null otherwise. */
5
4
  export declare function isoTime(value: unknown): string | null;
6
5
  export declare const str: (value: unknown) => string | null;
7
6
  export declare function count(value: unknown): number | null;
8
- /** Parse tool arguments recorded as text; keep the text when it is not JSON. */
9
7
  export declare function argumentsOf(raw: unknown): {
10
8
  input: unknown;
11
9
  inputText: string | null;
12
10
  };
13
- /** The text of an output that is text, or of the text blocks in a content-block array. */
14
11
  export declare function textOf(value: unknown): string | null;
15
- /** The HTTP status in a provider error message such as `unexpected status 500 Internal Server Error`. */
16
12
  export declare function httpStatusIn(text: string | null | undefined): number | null;
17
13
  export declare function usageOrNull(usage: TokenUsage): TokenUsage | null;
18
- /** The key a served model is counted under: `provider/model`, or the bare model with no provider. */
19
14
  export declare function servedModelKey(call: Pick<ModelCall, 'provider' | 'servedModel'>): string | null;
20
- /** Folds one session's records into a {@link HarnessSession}. Every format reader drives this builder, and `read` and `summarize` share the same fold: in summary mode the builder keeps the counts, the model calls and the ending, and drops message and tool-call content, so a 700 MB rollout is summarized without holding its outputs. */
21
15
  export declare class SessionBuilder {
22
16
  readonly harness: string;
23
17
  readonly format: SessionFormatId;
@@ -47,15 +41,11 @@ export declare class SessionBuilder {
47
41
  private sessionUsage;
48
42
  private ending;
49
43
  constructor(harness: string, format: SessionFormatId, modelSource: HarnessSession['modelSource'], mode: BuildMode, nativeSessionId: string, parentNativeSessionId?: string | null);
50
- /** Record an instant the session was active. Returns the normalized instant. */
51
44
  seen(value: unknown): string | null;
52
45
  message(message: SessionMessage): SessionMessage;
53
- /** Add parts to a message already recorded (one API response written over several records). */
54
46
  appendParts(messageId: string, parts: Part[]): void;
55
- /** Replace a tool call's arguments (a harness that streams them in parts). */
56
47
  setToolInput(id: string, inputText: string): void;
57
48
  hasMessage(messageId: string): boolean;
58
- /** A tool call the agent made. Its part is added to `messageId` when the message is held. */
59
49
  toolCall(call: {
60
50
  id: string;
61
51
  name: string;
@@ -64,7 +54,6 @@ export declare class SessionBuilder {
64
54
  at: string | null;
65
55
  messageId: string;
66
56
  }): void;
67
- /** The result of a tool call. A result whose call was not recorded becomes a call of its own. */
68
57
  toolResult(id: string, result: {
69
58
  output: unknown;
70
59
  text: string | null;
@@ -87,10 +76,8 @@ export declare class SessionBuilder {
87
76
  unparsedLines?: number[];
88
77
  }): void;
89
78
  markTruncated(reason: string): void;
90
- /** The harness's own session total, when it records one; it wins over the per-call sum. */
91
79
  setSessionUsage(usage: TokenUsage | null): void;
92
80
  end(ending: SessionEnding): void;
93
- /** The ending every format shares, from what the session holds when the records run out: `aborted` when the harness recorded an abort last; `error` when the last model call failed and no new input followed it; `completed` when the last model call succeeded, every tool call has its result and the agent spoke last; `open` otherwise (the turn was still running, or the process died mid-turn). */
94
81
  inferEnding(aborted?: {
95
82
  at: string | null;
96
83
  error: SessionError | null;
package/dist/builder.js CHANGED
@@ -1,13 +1,11 @@
1
1
  import { isRecord } from '@tangle-network/agent-core';
2
2
  import { HARNESS_SESSION_SCHEMA } from './schema.js';
3
- /** An ISO-8601 instant from an ISO string, epoch milliseconds or epoch seconds; null otherwise. */
4
3
  export function isoTime(value) {
5
4
  if (typeof value === 'string' && value.length > 0) {
6
5
  const ms = Date.parse(value);
7
6
  return Number.isNaN(ms) ? null : new Date(ms).toISOString();
8
7
  }
9
8
  if (typeof value === 'number' && Number.isFinite(value) && value > 0) {
10
- // Seconds before 2001-09-09 in milliseconds are below 1e12; nothing here predates that.
11
9
  return new Date(value < 1e12 ? value * 1000 : value).toISOString();
12
10
  }
13
11
  return null;
@@ -16,7 +14,6 @@ export const str = (value) => (typeof value === 'string' ? value : null);
16
14
  export function count(value) {
17
15
  return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : null;
18
16
  }
19
- /** Parse tool arguments recorded as text; keep the text when it is not JSON. */
20
17
  export function argumentsOf(raw) {
21
18
  if (typeof raw !== 'string')
22
19
  return { input: raw ?? null, inputText: null };
@@ -27,7 +24,6 @@ export function argumentsOf(raw) {
27
24
  return { input: raw, inputText: raw };
28
25
  }
29
26
  }
30
- /** The text of an output that is text, or of the text blocks in a content-block array. */
31
27
  export function textOf(value) {
32
28
  if (typeof value === 'string')
33
29
  return value;
@@ -40,7 +36,6 @@ export function textOf(value) {
40
36
  }
41
37
  return texts.length > 0 ? texts.join('\n') : null;
42
38
  }
43
- /** The HTTP status in a provider error message such as `unexpected status 500 Internal Server Error`. */
44
39
  export function httpStatusIn(text) {
45
40
  if (!text)
46
41
  return null;
@@ -60,13 +55,11 @@ export function usageOrNull(usage) {
60
55
  ? null
61
56
  : usage;
62
57
  }
63
- /** The key a served model is counted under: `provider/model`, or the bare model with no provider. */
64
58
  export function servedModelKey(call) {
65
59
  if (call.servedModel === null)
66
60
  return null;
67
61
  return call.provider === null ? call.servedModel : `${call.provider}/${call.servedModel}`;
68
62
  }
69
- /** Folds one session's records into a {@link HarnessSession}. Every format reader drives this builder, and `read` and `summarize` share the same fold: in summary mode the builder keeps the counts, the model calls and the ending, and drops message and tool-call content, so a 700 MB rollout is summarized without holding its outputs. */
70
63
  export class SessionBuilder {
71
64
  harness;
72
65
  format;
@@ -103,7 +96,6 @@ export class SessionBuilder {
103
96
  this.nativeSessionId = nativeSessionId;
104
97
  this.parentNativeSessionId = parentNativeSessionId;
105
98
  }
106
- /** Record an instant the session was active. Returns the normalized instant. */
107
99
  seen(value) {
108
100
  const at = isoTime(value);
109
101
  if (at === null)
@@ -117,8 +109,6 @@ export class SessionBuilder {
117
109
  message(message) {
118
110
  if (message.role === 'assistant' && message.actor === 'agent')
119
111
  this.replies += 1;
120
- // Only new input re-opens a turn: harness bookkeeping (a compaction summary, environment
121
- // context) after a failed call does not.
122
112
  if (message.role === 'user' && (message.actor === 'human' || message.actor === 'subagent-spawn'))
123
113
  this.inputsSinceLastCall += 1;
124
114
  this.lastRole = message.role;
@@ -128,7 +118,6 @@ export class SessionBuilder {
128
118
  }
129
119
  return message;
130
120
  }
131
- /** Add parts to a message already recorded (one API response written over several records). */
132
121
  appendParts(messageId, parts) {
133
122
  if (!this.full)
134
123
  return;
@@ -136,7 +125,6 @@ export class SessionBuilder {
136
125
  if (message)
137
126
  message.parts.push(...parts);
138
127
  }
139
- /** Replace a tool call's arguments (a harness that streams them in parts). */
140
128
  setToolInput(id, inputText) {
141
129
  const call = this.toolCalls.get(id);
142
130
  if (!call)
@@ -147,7 +135,6 @@ export class SessionBuilder {
147
135
  hasMessage(messageId) {
148
136
  return this.messageById.has(messageId);
149
137
  }
150
- /** A tool call the agent made. Its part is added to `messageId` when the message is held. */
151
138
  toolCall(call) {
152
139
  if (this.toolCallIds.has(call.id))
153
140
  return;
@@ -168,7 +155,6 @@ export class SessionBuilder {
168
155
  messageId: call.messageId,
169
156
  });
170
157
  }
171
- /** The result of a tool call. A result whose call was not recorded becomes a call of its own. */
172
158
  toolResult(id, result) {
173
159
  if (!this.toolCallIds.has(id)) {
174
160
  this.toolCall({ id, name: result.name ?? 'unknown', input: null, inputText: null, at: result.at, messageId: result.messageId });
@@ -199,7 +185,6 @@ export class SessionBuilder {
199
185
  this.children.push({ nativeSessionId, toolCallId });
200
186
  }
201
187
  gap(text) {
202
- // Keep the first occurrences; a damaged file can produce one gap per record.
203
188
  if (this.gaps.length < 200)
204
189
  this.gaps.push(text);
205
190
  }
@@ -217,14 +202,12 @@ export class SessionBuilder {
217
202
  this.truncated = true;
218
203
  this.gap(reason);
219
204
  }
220
- /** The harness's own session total, when it records one; it wins over the per-call sum. */
221
205
  setSessionUsage(usage) {
222
206
  this.sessionUsage = usage;
223
207
  }
224
208
  end(ending) {
225
209
  this.ending = ending;
226
210
  }
227
- /** The ending every format shares, from what the session holds when the records run out: `aborted` when the harness recorded an abort last; `error` when the last model call failed and no new input followed it; `completed` when the last model call succeeded, every tool call has its result and the agent spoke last; `open` otherwise (the turn was still running, or the process died mid-turn). */
228
211
  inferEnding(aborted) {
229
212
  if (aborted) {
230
213
  const error = aborted.error ?? this.modelCalls.at(-1)?.error ?? null;
package/dist/capture.d.ts CHANGED
@@ -1,41 +1,33 @@
1
1
  import type { HarnessSession, NativeSessionCopy, RawEvidenceArchiveManifestV2, SessionRef } from './schema.js';
2
2
  export declare const RETENTION_SESSIONS: string;
3
3
  export declare const RETENTION_MANIFEST_KIND = "tangle-native-session-evidence.v1";
4
- /** One native session found in a capture, with the ids that join it to its execution. */
5
4
  export interface CapturedSessionRef {
6
5
  ref: SessionRef;
7
6
  harness: string;
8
- /** The sandbox (provider) session the capture belongs to. */
9
7
  sandboxSessionId: string | null;
10
8
  executionId: string | null;
11
9
  attempt: number | null;
12
10
  copy: NativeSessionCopy['copy'] | 'retained';
13
- /** True when the sidecar recorded this native session id for the execution. */
14
11
  recordedId: boolean;
15
- /** The capture's native root the session was found in, relative to the capture directory. */
16
12
  root: string;
17
13
  sourceId: string | null;
18
14
  rootScope: string | null;
19
15
  }
20
16
  export interface CaptureListing {
21
17
  sessions: CapturedSessionRef[];
22
- /** Executions whose harness has no reader, and ids recorded but not found in the copy. */
23
18
  missing: Array<{
24
19
  sandboxSessionId: string | null;
25
20
  harness: string | null;
26
21
  reason: string;
27
22
  nativeSessionId?: string;
28
- /** The capture root (relative to the capture directory) and store file a reason refers to. */
29
23
  root?: string;
30
24
  path?: string;
31
25
  detail?: string;
32
26
  }>;
33
27
  }
34
- /** Every native session in a capture: from `manifest.nativeSessions` when a v2 manifest is given (files relative to `dir`), otherwise from the retention layout under `dir`. */
35
28
  export declare function listCapture(dir: string, manifest?: RawEvidenceArchiveManifestV2 | null, options?: {
36
29
  harness?: string;
37
30
  }): Promise<CaptureListing>;
38
- /** Every native session in a capture, read in full. */
39
31
  export declare function readCapture(dir: string, manifest?: RawEvidenceArchiveManifestV2 | null, options?: {
40
32
  harness?: string;
41
33
  }): AsyncIterable<HarnessSession>;
package/dist/capture.js CHANGED
@@ -1,11 +1,10 @@
1
1
  import { isRecord } from '@tangle-network/agent-core';
2
- /** Read sidecar v2 native copies and historical provider retention through their
3
- * declared stores, preserving recorded execution identities and native families.
4
- */
5
2
  import { readdir, readFile } from 'node:fs/promises';
6
3
  import { join } from 'node:path';
7
4
  import { str } from './builder.js';
8
5
  import { opencodeSessionsInStore } from './formats/opencode.js';
6
+ import { hermesSessionsInStore } from './formats/hermes.js';
7
+ import { openclawSessionsInStore } from './formats/openclaw.js';
9
8
  import { maybeReaderFor, readerFor, readerForFormat } from './registry.js';
10
9
  import { isMissing } from './source.js';
11
10
  import { storeGlob } from './stores.js';
@@ -31,7 +30,6 @@ async function dirs(path) {
31
30
  throw error;
32
31
  }
33
32
  }
34
- /** Sessions listed by a v2 archive manifest. Files are resolved against `archiveDir`. */
35
33
  async function fromV2(archiveDir, manifest, listing) {
36
34
  for (const copy of manifest.nativeSessions) {
37
35
  const reader = maybeReaderFor(copy.harness) ?? readerForFormatSafe(copy.format);
@@ -54,7 +52,7 @@ async function fromV2(archiveDir, manifest, listing) {
54
52
  continue;
55
53
  }
56
54
  const path = join(archiveDir, db.path);
57
- const refs = await opencodeSessionsInStore(path, null, {});
55
+ const refs = store.format === 'hermes.state-sqlite' ? await hermesSessionsInStore(path) : store.format === 'openclaw.session-jsonl' ? await openclawSessionsInStore(path) : await opencodeSessionsInStore(path, null, {});
58
56
  const children = new Map();
59
57
  for (const ref of refs)
60
58
  if (ref.parentNativeSessionId) {
@@ -63,7 +61,6 @@ async function fromV2(archiveDir, manifest, listing) {
63
61
  children.set(ref.parentNativeSessionId, group);
64
62
  }
65
63
  const ids = new Set([copy.nativeSessionId]);
66
- // Set iteration visits newly added children once, independent of store order.
67
64
  for (const id of ids)
68
65
  for (const child of children.get(id) ?? [])
69
66
  ids.add(child);
@@ -94,7 +91,6 @@ async function fromV2(archiveDir, manifest, listing) {
94
91
  }
95
92
  }
96
93
  }
97
- /** The file's path relative to the runtime HOME, which the store globs match. The sidecar's archive stores payloads under flat member names (`path`) and names the HOME path in `storePath`; a capture laid out like the HOME carries it in `path` itself. */
98
94
  function storePathOf(file) {
99
95
  return file.storePath ?? file.path;
100
96
  }
@@ -120,7 +116,6 @@ function captured(ref, copy, recordedId, archiveDir, path) {
120
116
  rootScope: null,
121
117
  };
122
118
  }
123
- /** Sessions in provider-tangle's retention layout, found through each reader's declared stores. */
124
119
  async function fromRetention(captureDir, listing, fallbackHarness) {
125
120
  const sessionsDir = join(captureDir, RETENTION_SESSIONS);
126
121
  for (const sandboxSessionId of await dirs(sessionsDir)) {
@@ -131,8 +126,6 @@ async function fromRetention(captureDir, listing, fallbackHarness) {
131
126
  await fromV2(dir, manifest, listing);
132
127
  continue;
133
128
  }
134
- // The manifest names the harness; a capture whose manifest does not falls back to the
135
- // harness the caller ran (the profile's), never to guessing from paths.
136
129
  const harness = (source ? str(source.backendType) : null) ?? fallbackHarness;
137
130
  const reader = harness ? maybeReaderFor(harness) : undefined;
138
131
  if (!reader) {
@@ -152,7 +145,6 @@ async function fromRetention(captureDir, listing, fallbackHarness) {
152
145
  }
153
146
  const lastAttempt = attempts[attempts.length - 1];
154
147
  const found = new Set();
155
- // native/<source id>/<root scope>/ is one execution's runtime HOME (or its workspace).
156
148
  for (const sourceId of await dirs(join(dir, 'native'))) {
157
149
  for (const rootScope of await dirs(join(dir, 'native', sourceId))) {
158
150
  const home = join(dir, 'native', sourceId, rootScope);
@@ -161,7 +153,6 @@ async function fromRetention(captureDir, listing, fallbackHarness) {
161
153
  refs = await reader.locate(home);
162
154
  }
163
155
  catch (error) {
164
- // A store that cannot be opened (a corrupt SQLite file) proves nothing about the turn.
165
156
  const store = reader.stores[0];
166
157
  listing.missing.push({ sandboxSessionId, harness: reader.harness, reason: 'store_unreadable', root: home.slice(captureDir.length + 1), path: store.shared ? `${store.root}/${store.files[0]}` : store.root, detail: error instanceof Error ? error.message : String(error) });
167
158
  continue;
@@ -190,7 +181,6 @@ async function fromRetention(captureDir, listing, fallbackHarness) {
190
181
  }
191
182
  }
192
183
  }
193
- /** Every native session in a capture: from `manifest.nativeSessions` when a v2 manifest is given (files relative to `dir`), otherwise from the retention layout under `dir`. */
194
184
  export async function listCapture(dir, manifest, options = {}) {
195
185
  const listing = { sessions: [], missing: [] };
196
186
  if (manifest && Array.isArray(manifest.nativeSessions))
@@ -199,7 +189,6 @@ export async function listCapture(dir, manifest, options = {}) {
199
189
  await fromRetention(dir, listing, options.harness ?? null);
200
190
  return listing;
201
191
  }
202
- /** Every native session in a capture, read in full. */
203
192
  export async function* readCapture(dir, manifest, options = {}) {
204
193
  const listing = await listCapture(dir, manifest, options);
205
194
  for (const session of listing.sessions)
package/dist/catalog.d.ts CHANGED
@@ -1,5 +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"];
2
- /** Store layouts, relative to the HOME a harness ran with. */
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"];
3
2
  export declare const STORES: {
4
3
  readonly 'claude-code.projects-jsonl': {
5
4
  format: "claude-code.projects-jsonl";
@@ -74,21 +73,28 @@ export declare const STORES: {
74
73
  readonly 'prime.session-jsonl': {
75
74
  format: "prime.session-jsonl";
76
75
  root: string;
77
- files: readonly ["**/*_{id}.jsonl"];
76
+ files: readonly ["**/sessions/*.jsonl"];
78
77
  write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
79
78
  shared: boolean;
80
79
  };
81
80
  readonly 'openclaw.session-jsonl': {
82
81
  format: "openclaw.session-jsonl";
83
82
  root: string;
84
- files: readonly ["**/{id}.jsonl"];
83
+ files: readonly ["agents/main/agent/openclaw-agent.sqlite", "agents/main/agent/openclaw-agent.sqlite-wal", "agents/main/agent/openclaw-agent.sqlite-shm"];
85
84
  write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
86
85
  shared: boolean;
87
86
  };
88
87
  readonly 'grok.acp-session-dir': {
89
88
  format: "grok.acp-session-dir";
90
89
  root: string;
91
- files: readonly ["*/{id}/updates.jsonl"];
90
+ files: readonly ["*/{id}/updates.jsonl", "*/{id}/chat_history.jsonl", "*/{id}/summary.json", "*/{id}/signals.json"];
91
+ write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
92
+ shared: boolean;
93
+ };
94
+ readonly 'sandbox.events': {
95
+ format: "sandbox.events";
96
+ root: string;
97
+ files: readonly ["{id}/*.jsonl"];
92
98
  write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
93
99
  shared: boolean;
94
100
  };
@@ -100,7 +106,6 @@ export declare const STORES: {
100
106
  shared: boolean;
101
107
  };
102
108
  };
103
- /** Kimi Code's current and retained legacy layouts; the legacy catalog entry stays stable. */
104
109
  export declare const KIMI_STORES: readonly [{
105
110
  readonly root: ".kimi-code/sessions";
106
111
  readonly files: readonly ["wd_*/{id}/**"];
@@ -188,27 +193,20 @@ export declare const EVIDENCE: {
188
193
  readonly usage: "per-response";
189
194
  readonly endingError: "none";
190
195
  };
196
+ readonly 'sandbox.events': {
197
+ readonly servedModel: "none";
198
+ readonly usage: "per-response";
199
+ readonly endingError: "none";
200
+ };
191
201
  };
192
- /** Codex homes: `.codex`, `.codex-*`, acct homes, and a fleet seat's `codex` directory. */
193
202
  export declare const CODEX_HOME_RULE: {
194
- /** Directory names directly under HOME that are Codex homes: `.codex` and `.codex-<name>`. */
195
203
  readonly siblings: RegExp;
196
- /** Under HOME, unless `$ACCT_CONFIG` names it: each child is one account's Codex home. */
197
204
  readonly accounts: ".config/agent-accounts/codex";
198
205
  readonly sessionDirs: readonly ["sessions", "archived_sessions"];
199
- /** A rollout's file name, at any depth under a session dir (`sessions/` nests by date). */
200
206
  readonly rollout: "rollout-*.jsonl";
201
- /** The name Codex gives a rollout, ending in its thread id. */
202
207
  readonly named: "rollout-*-{id}.jsonl";
203
208
  };
204
- /**
205
- * True when `dir` is itself a Codex home by its path: `.codex`, `.codex-<name>`, an acct account
206
- * home (`agent-accounts/codex/<account>`), or a fleet seat's `codex` directory.
207
- */
208
209
  export declare function isCodexHome(dir: string): boolean;
209
- /** True when `path` is `root` or lies under it on a path boundary: `/x/agent` is not under `/x/age`. */
210
210
  export declare function withinPath(path: string, root: string): boolean;
211
- /** Compile one store glob. `*` matches within a path segment, `**` matches any number of segments, and `{id}` matches the native session id: the literal id when one is given, any segment text otherwise (the reader then takes the id from the session's own header). */
212
211
  export declare function storeGlob(glob: string, nativeSessionId?: string): RegExp;
213
- /** A store root must be a normalized path relative to HOME: not absolute, no `.`/`..` segments. */
214
212
  export declare function assertStoreRoot(root: string): void;
package/dist/catalog.js CHANGED
@@ -13,12 +13,11 @@ 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
- /** One catalog declaration owns append-only defaults and shared SQLite copy semantics. */
18
18
  function store(format, root, files, write = 'jsonl-append', shared = write === 'sqlite-wal') {
19
19
  return { format, root, files, write, shared };
20
20
  }
21
- /** Store layouts, relative to the HOME a harness ran with. */
22
21
  export const STORES = {
23
22
  'claude-code.projects-jsonl': store('claude-code.projects-jsonl', '.claude/projects', [
24
23
  '*/{id}.jsonl', '*/{id}/subagents/**/*.jsonl',
@@ -28,8 +27,6 @@ export const STORES = {
28
27
  'opencode.db', 'opencode.db-wal', 'opencode.db-shm',
29
28
  ], 'sqlite-wal'),
30
29
  'pi.session-jsonl': store('pi.session-jsonl', '.pi/agent/sessions', ['**/*_{id}.jsonl']),
31
- // A session directory: wire.jsonl (the event stream read here), context.jsonl and its rotated
32
- // context_N.jsonl copies, and state.json.
33
30
  'kimi.session-dir': store('kimi.session-dir', '.kimi/sessions', ['*/{id}/**', '*/{id}.jsonl']),
34
31
  'factory.session-jsonl': store('factory.session-jsonl', '.factory/sessions', [
35
32
  '*/{id}.jsonl', '*/{id}.settings.json',
@@ -38,12 +35,12 @@ export const STORES = {
38
35
  'amp.thread-json': store('amp.thread-json', '.local/share/amp/threads', ['{id}.json'], 'json-rewrite'),
39
36
  'forge.sqlite': store('forge.sqlite', '.forge', ['.forge.db', '.forge.db-wal', '.forge.db-shm'], 'sqlite-wal'),
40
37
  'hermes.state-sqlite': store('hermes.state-sqlite', '.hermes', ['state.db', 'state.db-wal', 'state.db-shm'], 'sqlite-wal'),
41
- 'prime.session-jsonl': store('prime.session-jsonl', '.prime-provider/prime-agent-dirs', ['**/*_{id}.jsonl']),
42
- 'openclaw.session-jsonl': store('openclaw.session-jsonl', '.openclaw/agents', ['**/{id}.jsonl']),
43
- 'grok.acp-session-dir': store('grok.acp-session-dir', '.grok/sessions', ['*/{id}/updates.jsonl']),
38
+ 'prime.session-jsonl': store('prime.session-jsonl', '.prime-provider/prime-agent-dirs', ['**/sessions/*.jsonl']),
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'),
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']),
44
42
  'nanoclaw.session-sqlite': store('nanoclaw.session-sqlite', '.nanoclaw/data/v2-sessions', ['*/{id}/outbound.db', '*/{id}/inbound.db'], 'sqlite-wal', false),
45
43
  };
46
- /** Kimi Code's current and retained legacy layouts; the legacy catalog entry stays stable. */
47
44
  export const KIMI_STORES = [
48
45
  { ...STORES['kimi.session-dir'], root: '.kimi-code/sessions', files: ['wd_*/{id}/**'], globs: { session: 'wd_*/{id}/agents/main/wire.jsonl' } },
49
46
  STORES['kimi.session-dir'],
@@ -63,23 +60,15 @@ export const EVIDENCE = {
63
60
  'openclaw.session-jsonl': { servedModel: 'session-record', usage: 'per-response', endingError: 'none' },
64
61
  'grok.acp-session-dir': { servedModel: 'session-record', usage: 'session-total', endingError: 'none' },
65
62
  'nanoclaw.session-sqlite': { servedModel: 'none', usage: 'per-response', endingError: 'none' },
63
+ 'sandbox.events': { servedModel: 'none', usage: 'per-response', endingError: 'none' },
66
64
  };
67
- /** Codex homes: `.codex`, `.codex-*`, acct homes, and a fleet seat's `codex` directory. */
68
65
  export const CODEX_HOME_RULE = {
69
- /** Directory names directly under HOME that are Codex homes: `.codex` and `.codex-<name>`. */
70
66
  siblings: /^\.codex(?:-.+)?$/u,
71
- /** Under HOME, unless `$ACCT_CONFIG` names it: each child is one account's Codex home. */
72
67
  accounts: '.config/agent-accounts/codex',
73
68
  sessionDirs: ['sessions', 'archived_sessions'],
74
- /** A rollout's file name, at any depth under a session dir (`sessions/` nests by date). */
75
69
  rollout: 'rollout-*.jsonl',
76
- /** The name Codex gives a rollout, ending in its thread id. */
77
70
  named: 'rollout-*-{id}.jsonl',
78
71
  };
79
- /**
80
- * True when `dir` is itself a Codex home by its path: `.codex`, `.codex-<name>`, an acct account
81
- * home (`agent-accounts/codex/<account>`), or a fleet seat's `codex` directory.
82
- */
83
72
  export function isCodexHome(dir) {
84
73
  const parts = dir.replace(/\/+$/u, '').split('/');
85
74
  const [name, parent, grandparent] = [parts.at(-1) ?? '', parts.at(-2) ?? '', parts.at(-3) ?? ''];
@@ -89,14 +78,12 @@ export function isCodexHome(dir) {
89
78
  return true;
90
79
  return name === 'codex' && parent !== 'agent-accounts';
91
80
  }
92
- /** True when `path` is `root` or lies under it on a path boundary: `/x/agent` is not under `/x/age`. */
93
81
  export function withinPath(path, root) {
94
82
  const p = path.replace(/\/+$/u, '');
95
83
  const r = root.replace(/\/+$/u, '');
96
84
  return p === r || p.startsWith(`${r}/`);
97
85
  }
98
86
  const REGEX_SPECIALS = /[.+^$()|[\]\\]/gu;
99
- /** Compile one store glob. `*` matches within a path segment, `**` matches any number of segments, and `{id}` matches the native session id: the literal id when one is given, any segment text otherwise (the reader then takes the id from the session's own header). */
100
87
  export function storeGlob(glob, nativeSessionId) {
101
88
  let pattern = '';
102
89
  for (let i = 0; i < glob.length; i += 1) {
@@ -125,7 +112,6 @@ export function storeGlob(glob, nativeSessionId) {
125
112
  }
126
113
  return new RegExp(`^${pattern}$`, 'u');
127
114
  }
128
- /** A store root must be a normalized path relative to HOME: not absolute, no `.`/`..` segments. */
129
115
  export function assertStoreRoot(root) {
130
116
  const segments = root.split('/');
131
117
  if (root.startsWith('/') || segments.some((s) => s === '' || s === '.' || s === '..')) {
package/dist/cli.js CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
- /** harness-sessions read <file|home|capture> [--harness h] [--session id] [--cwd dir] [--summary] [--json] Reads native harness sessions into the normalized form, for callers that are not JavaScript. A file is one session file (or an OpenCode store); a directory is a capture when it holds `__retention__/sessions`, otherwise a HOME searched through every reader's store layout. `--json` prints one JSON document per session, one per line. */
3
2
  import { stat } from 'node:fs/promises';
4
3
  import { join } from 'node:path';
5
4
  import { listCapture, RETENTION_SESSIONS } from './capture.js';
@@ -5,5 +5,4 @@ import { type SessionFold } from './fold.js';
5
5
  export declare function createFold(ref: SessionRef, mode: BuildMode, stats: SourceStats): SessionFold;
6
6
  export declare function fold(ref: SessionRef, mode: BuildMode, options: ReadOptions, source?: RecordSource): Promise<SessionBuilder>;
7
7
  export declare const claudeCodeReader: HarnessSessionReader;
8
- /** A reader for one transcript file outside a HOME layout (the CLI, a retained copy). */
9
8
  export declare function claudeCodeRefForFile(path: string, parentNativeSessionId?: string | null): SessionRef;
@@ -1,9 +1,8 @@
1
1
  import { isRecord } from '@tangle-network/agent-core';
2
- /** Claude Code jsonl under ~/.claude/projects. One assistant record per content block; message.model is served. */
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, LOCATE_READS, STORES, mapLimit, mtimeMs, storeGlob, walkFiles, withinPath } from '../stores.js';
8
7
  import { headRecord } from './head.js';
9
8
  import { claudeRecordIsMachine, claudeTypedPromptText } from './claude-records.js';
@@ -36,7 +35,6 @@ export function createFold(ref, mode, stats) {
36
35
  let aborted = null;
37
36
  let errors = 0;
38
37
  let identified = false;
39
- // A resumed agent's file writes its earlier records again, each with the uuid it had.
40
38
  const seenUuids = new Set();
41
39
  const observe = (record) => {
42
40
  if (!subagent && record.isSidechain === true) {
@@ -55,7 +53,6 @@ export function createFold(ref, mode, stats) {
55
53
  if (builder.cwd === null && typeof record.cwd === 'string')
56
54
  builder.cwd = record.cwd;
57
55
  if (!identified && typeof record.sessionId === 'string') {
58
- // The records name the session; a subagent's records name its parent and its agent id.
59
56
  identified = true;
60
57
  if (subagent && typeof record.agentId === 'string') {
61
58
  builder.nativeSessionId = record.agentId;
@@ -70,8 +67,6 @@ export function createFold(ref, mode, stats) {
70
67
  if (type === 'system') {
71
68
  if (record.subtype !== 'api_error')
72
69
  return;
73
- // A failed API request that Claude Code retried (or gave up on). It is a model call that
74
- // returned no answer; a later success supersedes it in the ending.
75
70
  const error = isRecord(record.error) ? record.error : {};
76
71
  const message = str(error.formatted) ?? str(error.message) ?? str(record.content) ?? 'API error';
77
72
  builder.modelCall({
@@ -125,7 +120,6 @@ export function createFold(ref, mode, stats) {
125
120
  isError: block.is_error === true,
126
121
  at,
127
122
  messageId: `${uuid}:tool`,
128
- // The record's structured result belongs to its tool result when it carries one.
129
123
  details: results === 1 ? (record.toolUseResult ?? null) : null,
130
124
  });
131
125
  const result = isRecord(record.toolUseResult) ? record.toolUseResult : null;
@@ -157,7 +151,6 @@ export function createFold(ref, mode, stats) {
157
151
  }
158
152
  return;
159
153
  }
160
- // assistant
161
154
  aborted = null;
162
155
  const model = str(message.model);
163
156
  const content = Array.isArray(message.content) ? message.content : [];
@@ -199,7 +192,6 @@ export function createFold(ref, mode, stats) {
199
192
  }
200
193
  const existing = builder.getModelCall(apiId);
201
194
  if (existing) {
202
- // A later block of the same response: its usage is the response's final usage so far.
203
195
  existing.usage = usageOf(message.usage) ?? existing.usage;
204
196
  existing.stopReason = str(message.stop_reason) ?? existing.stopReason;
205
197
  if (builder.hasMessage(apiId))
@@ -266,22 +258,7 @@ async function locate(home, opts) {
266
258
  });
267
259
  return sessions.flat().sort((a, b) => b.mtimeMs - a.mtimeMs);
268
260
  }
269
- export const claudeCodeReader = {
270
- harness: HARNESS,
271
- aliases: ['claude', 'claude-code-acp', 'claudish'],
272
- formats: [FORMAT],
273
- stores: [STORE],
274
- globs: { session: STORE.files[0], children: STORE.files[1] },
275
- evidence: EVIDENCE[FORMAT],
276
- locate: (home, opts = {}) => locate(home, opts),
277
- async read(ref, opts = {}) {
278
- return (await fold(ref, 'full', opts)).build();
279
- },
280
- async summarize(ref, opts = {}) {
281
- return (await fold(ref, 'summary', opts)).summary();
282
- },
283
- };
284
- /** A reader for one transcript file outside a HOME layout (the CLI, a retained copy). */
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);
285
262
  export function claudeCodeRefForFile(path, parentNativeSessionId = null) {
286
263
  const name = basename(path, '.jsonl');
287
264
  return {
@@ -1,16 +1,8 @@
1
- /** Which Claude Code `user` records a person typed and which the harness wrote. Claude Code stores both as `type: "user"`; the markers below are the only difference. This is the one owner of the rule, so every reader of a Claude Code transcript (traces, agent-eval) classifies turns alike. */
2
1
  export interface ClaudeRecordFacts {
3
- /** The record's text (the first text part for block content). */
4
2
  text: string;
5
3
  isMeta?: boolean | undefined;
6
4
  isCompactSummary?: boolean | undefined;
7
- /** The record's `entrypoint`; `sdk-cli` is a programmatic caller, not a person. */
8
5
  entrypoint?: string | undefined;
9
6
  }
10
- /** True when the harness, not a person, wrote this user record. */
11
7
  export declare function claudeRecordIsMachine(facts: ClaudeRecordFacts): boolean;
12
- /**
13
- * What a person typed. A slash command is stored as a `<command-name>` wrapper; this returns the
14
- * command and its arguments (`/effort`, `/model opus`). Text without a wrapper is unchanged.
15
- */
16
8
  export declare function claudeTypedPromptText(text: string): string;
@@ -1,4 +1,3 @@
1
- /** Which Claude Code `user` records a person typed and which the harness wrote. Claude Code stores both as `type: "user"`; the markers below are the only difference. This is the one owner of the rule, so every reader of a Claude Code transcript (traces, agent-eval) classifies turns alike. */
2
1
  const MACHINE_TEXT_PREFIXES = [
3
2
  '<local-command-caveat>',
4
3
  '<local-command-stdout>',
@@ -10,17 +9,12 @@ const MACHINE_TEXT_PREFIXES = [
10
9
  '<user-prompt-submit-hook>',
11
10
  '[Request interrupted by user',
12
11
  ];
13
- /** True when the harness, not a person, wrote this user record. */
14
12
  export function claudeRecordIsMachine(facts) {
15
13
  if (facts.isMeta === true || facts.isCompactSummary === true || facts.entrypoint === 'sdk-cli')
16
14
  return true;
17
15
  const head = facts.text.trimStart();
18
16
  return MACHINE_TEXT_PREFIXES.some((prefix) => head.startsWith(prefix));
19
17
  }
20
- /**
21
- * What a person typed. A slash command is stored as a `<command-name>` wrapper; this returns the
22
- * command and its arguments (`/effort`, `/model opus`). Text without a wrapper is unchanged.
23
- */
24
18
  export function claudeTypedPromptText(text) {
25
19
  const name = /<command-name>([\s\S]*?)<\/command-name>/u.exec(text)?.[1]?.trim();
26
20
  if (!name)