@tangle-network/harness-sessions 1.0.5 → 1.0.7

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 (49) hide show
  1. package/dist/builder.d.ts +0 -24
  2. package/dist/builder.js +0 -28
  3. package/dist/capture.d.ts +0 -11
  4. package/dist/capture.js +3 -21
  5. package/dist/catalog.d.ts +16 -22
  6. package/dist/catalog.js +8 -26
  7. package/dist/cli.js +0 -8
  8. package/dist/formats/claude-code.d.ts +0 -1
  9. package/dist/formats/claude-code.js +0 -9
  10. package/dist/formats/claude-records.d.ts +0 -12
  11. package/dist/formats/claude-records.js +0 -10
  12. package/dist/formats/codex.js +0 -34
  13. package/dist/formats/factory.js +0 -3
  14. package/dist/formats/fold.d.ts +0 -5
  15. package/dist/formats/grok.js +12 -3
  16. package/dist/formats/head.d.ts +0 -7
  17. package/dist/formats/head.js +0 -10
  18. package/dist/formats/hermes.d.ts +3 -0
  19. package/dist/formats/hermes.js +93 -0
  20. package/dist/formats/kimi.d.ts +0 -1
  21. package/dist/formats/kimi.js +0 -6
  22. package/dist/formats/nanoclaw.d.ts +3 -0
  23. package/dist/formats/nanoclaw.js +65 -0
  24. package/dist/formats/openclaw.d.ts +3 -0
  25. package/dist/formats/openclaw.js +102 -0
  26. package/dist/formats/opencode.d.ts +0 -1
  27. package/dist/formats/opencode.js +0 -6
  28. package/dist/formats/pi.d.ts +1 -1
  29. package/dist/formats/pi.js +3 -9
  30. package/dist/formats/prime.d.ts +2 -0
  31. package/dist/formats/prime.js +35 -0
  32. package/dist/index.d.ts +4 -1
  33. package/dist/index.js +4 -0
  34. package/dist/input.d.ts +0 -10
  35. package/dist/input.js +0 -2
  36. package/dist/projections/chat.d.ts +0 -8
  37. package/dist/projections/chat.js +0 -5
  38. package/dist/projections/otlp.d.ts +0 -6
  39. package/dist/projections/otlp.js +0 -5
  40. package/dist/projections/turns.d.ts +0 -18
  41. package/dist/projections/turns.js +0 -7
  42. package/dist/registry.d.ts +0 -5
  43. package/dist/registry.js +5 -6
  44. package/dist/schema.d.ts +0 -39
  45. package/dist/source.d.ts +0 -11
  46. package/dist/source.js +0 -19
  47. package/dist/stores.d.ts +0 -10
  48. package/dist/stores.js +0 -11
  49. package/package.json +1 -1
package/dist/builder.d.ts CHANGED
@@ -1,28 +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
- /**
21
- * Folds one session's records into a {@link HarnessSession}. Every format reader drives this
22
- * builder, and `read` and `summarize` share the same fold: in summary mode the builder keeps the
23
- * counts, the model calls and the ending, and drops message and tool-call content, so a 700 MB
24
- * rollout is summarized without holding its outputs.
25
- */
26
15
  export declare class SessionBuilder {
27
16
  readonly harness: string;
28
17
  readonly format: SessionFormatId;
@@ -52,15 +41,11 @@ export declare class SessionBuilder {
52
41
  private sessionUsage;
53
42
  private ending;
54
43
  constructor(harness: string, format: SessionFormatId, modelSource: HarnessSession['modelSource'], mode: BuildMode, nativeSessionId: string, parentNativeSessionId?: string | null);
55
- /** Record an instant the session was active. Returns the normalized instant. */
56
44
  seen(value: unknown): string | null;
57
45
  message(message: SessionMessage): SessionMessage;
58
- /** Add parts to a message already recorded (one API response written over several records). */
59
46
  appendParts(messageId: string, parts: Part[]): void;
60
- /** Replace a tool call's arguments (a harness that streams them in parts). */
61
47
  setToolInput(id: string, inputText: string): void;
62
48
  hasMessage(messageId: string): boolean;
63
- /** A tool call the agent made. Its part is added to `messageId` when the message is held. */
64
49
  toolCall(call: {
65
50
  id: string;
66
51
  name: string;
@@ -69,7 +54,6 @@ export declare class SessionBuilder {
69
54
  at: string | null;
70
55
  messageId: string;
71
56
  }): void;
72
- /** The result of a tool call. A result whose call was not recorded becomes a call of its own. */
73
57
  toolResult(id: string, result: {
74
58
  output: unknown;
75
59
  text: string | null;
@@ -92,16 +76,8 @@ export declare class SessionBuilder {
92
76
  unparsedLines?: number[];
93
77
  }): void;
94
78
  markTruncated(reason: string): void;
95
- /** The harness's own session total, when it records one; it wins over the per-call sum. */
96
79
  setSessionUsage(usage: TokenUsage | null): void;
97
80
  end(ending: SessionEnding): void;
98
- /**
99
- * The ending every format shares, from what the session holds when the records run out:
100
- * `aborted` when the harness recorded an abort last; `error` when the last model call failed
101
- * and no new input followed it; `completed` when the last model call succeeded, every tool call
102
- * has its result and the agent spoke last; `open` otherwise (the turn was still running, or the
103
- * process died mid-turn).
104
- */
105
81
  inferEnding(aborted?: {
106
82
  at: string | null;
107
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,18 +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
- /**
70
- * Folds one session's records into a {@link HarnessSession}. Every format reader drives this
71
- * builder, and `read` and `summarize` share the same fold: in summary mode the builder keeps the
72
- * counts, the model calls and the ending, and drops message and tool-call content, so a 700 MB
73
- * rollout is summarized without holding its outputs.
74
- */
75
63
  export class SessionBuilder {
76
64
  harness;
77
65
  format;
@@ -108,7 +96,6 @@ export class SessionBuilder {
108
96
  this.nativeSessionId = nativeSessionId;
109
97
  this.parentNativeSessionId = parentNativeSessionId;
110
98
  }
111
- /** Record an instant the session was active. Returns the normalized instant. */
112
99
  seen(value) {
113
100
  const at = isoTime(value);
114
101
  if (at === null)
@@ -122,8 +109,6 @@ export class SessionBuilder {
122
109
  message(message) {
123
110
  if (message.role === 'assistant' && message.actor === 'agent')
124
111
  this.replies += 1;
125
- // Only new input re-opens a turn: harness bookkeeping (a compaction summary, environment
126
- // context) after a failed call does not.
127
112
  if (message.role === 'user' && (message.actor === 'human' || message.actor === 'subagent-spawn'))
128
113
  this.inputsSinceLastCall += 1;
129
114
  this.lastRole = message.role;
@@ -133,7 +118,6 @@ export class SessionBuilder {
133
118
  }
134
119
  return message;
135
120
  }
136
- /** Add parts to a message already recorded (one API response written over several records). */
137
121
  appendParts(messageId, parts) {
138
122
  if (!this.full)
139
123
  return;
@@ -141,7 +125,6 @@ export class SessionBuilder {
141
125
  if (message)
142
126
  message.parts.push(...parts);
143
127
  }
144
- /** Replace a tool call's arguments (a harness that streams them in parts). */
145
128
  setToolInput(id, inputText) {
146
129
  const call = this.toolCalls.get(id);
147
130
  if (!call)
@@ -152,7 +135,6 @@ export class SessionBuilder {
152
135
  hasMessage(messageId) {
153
136
  return this.messageById.has(messageId);
154
137
  }
155
- /** A tool call the agent made. Its part is added to `messageId` when the message is held. */
156
138
  toolCall(call) {
157
139
  if (this.toolCallIds.has(call.id))
158
140
  return;
@@ -173,7 +155,6 @@ export class SessionBuilder {
173
155
  messageId: call.messageId,
174
156
  });
175
157
  }
176
- /** The result of a tool call. A result whose call was not recorded becomes a call of its own. */
177
158
  toolResult(id, result) {
178
159
  if (!this.toolCallIds.has(id)) {
179
160
  this.toolCall({ id, name: result.name ?? 'unknown', input: null, inputText: null, at: result.at, messageId: result.messageId });
@@ -204,7 +185,6 @@ export class SessionBuilder {
204
185
  this.children.push({ nativeSessionId, toolCallId });
205
186
  }
206
187
  gap(text) {
207
- // Keep the first occurrences; a damaged file can produce one gap per record.
208
188
  if (this.gaps.length < 200)
209
189
  this.gaps.push(text);
210
190
  }
@@ -222,20 +202,12 @@ export class SessionBuilder {
222
202
  this.truncated = true;
223
203
  this.gap(reason);
224
204
  }
225
- /** The harness's own session total, when it records one; it wins over the per-call sum. */
226
205
  setSessionUsage(usage) {
227
206
  this.sessionUsage = usage;
228
207
  }
229
208
  end(ending) {
230
209
  this.ending = ending;
231
210
  }
232
- /**
233
- * The ending every format shares, from what the session holds when the records run out:
234
- * `aborted` when the harness recorded an abort last; `error` when the last model call failed
235
- * and no new input followed it; `completed` when the last model call succeeded, every tool call
236
- * has its result and the agent spoke last; `open` otherwise (the turn was still running, or the
237
- * process died mid-turn).
238
- */
239
211
  inferEnding(aborted) {
240
212
  if (aborted) {
241
213
  const error = aborted.error ?? this.modelCalls.at(-1)?.error ?? null;
package/dist/capture.d.ts CHANGED
@@ -1,44 +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
- /**
35
- * Every native session in a capture: from `manifest.nativeSessions` when a v2 manifest is given
36
- * (files relative to `dir`), otherwise from the retention layout under `dir`.
37
- */
38
28
  export declare function listCapture(dir: string, manifest?: RawEvidenceArchiveManifestV2 | null, options?: {
39
29
  harness?: string;
40
30
  }): Promise<CaptureListing>;
41
- /** Every native session in a capture, read in full. */
42
31
  export declare function readCapture(dir: string, manifest?: RawEvidenceArchiveManifestV2 | null, options?: {
43
32
  harness?: string;
44
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,11 +91,6 @@ async function fromV2(archiveDir, manifest, listing) {
94
91
  }
95
92
  }
96
93
  }
97
- /**
98
- * The file's path relative to the runtime HOME, which the store globs match. The sidecar's archive
99
- * stores payloads under flat member names (`path`) and names the HOME path in `storePath`; a
100
- * capture laid out like the HOME carries it in `path` itself.
101
- */
102
94
  function storePathOf(file) {
103
95
  return file.storePath ?? file.path;
104
96
  }
@@ -124,7 +116,6 @@ function captured(ref, copy, recordedId, archiveDir, path) {
124
116
  rootScope: null,
125
117
  };
126
118
  }
127
- /** Sessions in provider-tangle's retention layout, found through each reader's declared stores. */
128
119
  async function fromRetention(captureDir, listing, fallbackHarness) {
129
120
  const sessionsDir = join(captureDir, RETENTION_SESSIONS);
130
121
  for (const sandboxSessionId of await dirs(sessionsDir)) {
@@ -135,8 +126,6 @@ async function fromRetention(captureDir, listing, fallbackHarness) {
135
126
  await fromV2(dir, manifest, listing);
136
127
  continue;
137
128
  }
138
- // The manifest names the harness; a capture whose manifest does not falls back to the
139
- // harness the caller ran (the profile's), never to guessing from paths.
140
129
  const harness = (source ? str(source.backendType) : null) ?? fallbackHarness;
141
130
  const reader = harness ? maybeReaderFor(harness) : undefined;
142
131
  if (!reader) {
@@ -156,7 +145,6 @@ async function fromRetention(captureDir, listing, fallbackHarness) {
156
145
  }
157
146
  const lastAttempt = attempts[attempts.length - 1];
158
147
  const found = new Set();
159
- // native/<source id>/<root scope>/ is one execution's runtime HOME (or its workspace).
160
148
  for (const sourceId of await dirs(join(dir, 'native'))) {
161
149
  for (const rootScope of await dirs(join(dir, 'native', sourceId))) {
162
150
  const home = join(dir, 'native', sourceId, rootScope);
@@ -165,7 +153,6 @@ async function fromRetention(captureDir, listing, fallbackHarness) {
165
153
  refs = await reader.locate(home);
166
154
  }
167
155
  catch (error) {
168
- // A store that cannot be opened (a corrupt SQLite file) proves nothing about the turn.
169
156
  const store = reader.stores[0];
170
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) });
171
158
  continue;
@@ -194,10 +181,6 @@ async function fromRetention(captureDir, listing, fallbackHarness) {
194
181
  }
195
182
  }
196
183
  }
197
- /**
198
- * Every native session in a capture: from `manifest.nativeSessions` when a v2 manifest is given
199
- * (files relative to `dir`), otherwise from the retention layout under `dir`.
200
- */
201
184
  export async function listCapture(dir, manifest, options = {}) {
202
185
  const listing = { sessions: [], missing: [] };
203
186
  if (manifest && Array.isArray(manifest.nativeSessions))
@@ -206,7 +189,6 @@ export async function listCapture(dir, manifest, options = {}) {
206
189
  await fromRetention(dir, listing, options.harness ?? null);
207
190
  return listing;
208
191
  }
209
- /** Every native session in a capture, read in full. */
210
192
  export async function* readCapture(dir, manifest, options = {}) {
211
193
  const listing = await listCapture(dir, manifest, options);
212
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"];
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"];
3
2
  export declare const STORES: {
4
3
  readonly 'claude-code.projects-jsonl': {
5
4
  format: "claude-code.projects-jsonl";
@@ -74,26 +73,32 @@ 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 'nanoclaw.session-sqlite': {
95
+ format: "nanoclaw.session-sqlite";
96
+ root: string;
97
+ files: readonly ["*/{id}/outbound.db", "*/{id}/inbound.db"];
92
98
  write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
93
99
  shared: boolean;
94
100
  };
95
101
  };
96
- /** Kimi Code's current and retained legacy layouts; the legacy catalog entry stays stable. */
97
102
  export declare const KIMI_STORES: readonly [{
98
103
  readonly root: ".kimi-code/sessions";
99
104
  readonly files: readonly ["wd_*/{id}/**"];
@@ -176,31 +181,20 @@ export declare const EVIDENCE: {
176
181
  readonly usage: "session-total";
177
182
  readonly endingError: "none";
178
183
  };
184
+ readonly 'nanoclaw.session-sqlite': {
185
+ readonly servedModel: "none";
186
+ readonly usage: "per-response";
187
+ readonly endingError: "none";
188
+ };
179
189
  };
180
- /** Codex homes: `.codex`, `.codex-*`, acct homes, and a fleet seat's `codex` directory. */
181
190
  export declare const CODEX_HOME_RULE: {
182
- /** Directory names directly under HOME that are Codex homes: `.codex` and `.codex-<name>`. */
183
191
  readonly siblings: RegExp;
184
- /** Under HOME, unless `$ACCT_CONFIG` names it: each child is one account's Codex home. */
185
192
  readonly accounts: ".config/agent-accounts/codex";
186
193
  readonly sessionDirs: readonly ["sessions", "archived_sessions"];
187
- /** A rollout's file name, at any depth under a session dir (`sessions/` nests by date). */
188
194
  readonly rollout: "rollout-*.jsonl";
189
- /** The name Codex gives a rollout, ending in its thread id. */
190
195
  readonly named: "rollout-*-{id}.jsonl";
191
196
  };
192
- /**
193
- * True when `dir` is itself a Codex home by its path: `.codex`, `.codex-<name>`, an acct account
194
- * home (`agent-accounts/codex/<account>`), or a fleet seat's `codex` directory.
195
- */
196
197
  export declare function isCodexHome(dir: string): boolean;
197
- /** True when `path` is `root` or lies under it on a path boundary: `/x/agent` is not under `/x/age`. */
198
198
  export declare function withinPath(path: string, root: string): boolean;
199
- /**
200
- * Compile one store glob. `*` matches within a path segment, `**` matches any number of
201
- * segments, and `{id}` matches the native session id: the literal id when one is given, any
202
- * segment text otherwise (the reader then takes the id from the session's own header).
203
- */
204
199
  export declare function storeGlob(glob: string, nativeSessionId?: string): RegExp;
205
- /** A store root must be a normalized path relative to HOME: not absolute, no `.`/`..` segments. */
206
200
  export declare function assertStoreRoot(root: string): void;
package/dist/catalog.js CHANGED
@@ -12,12 +12,11 @@ export const SESSION_FORMAT_IDS = [
12
12
  'prime.session-jsonl',
13
13
  'openclaw.session-jsonl',
14
14
  'grok.acp-session-dir',
15
+ 'nanoclaw.session-sqlite',
15
16
  ];
16
- /** One catalog declaration owns append-only defaults and shared SQLite copy semantics. */
17
- function store(format, root, files, write = 'jsonl-append') {
18
- return { format, root, files, write, shared: write === 'sqlite-wal' };
17
+ function store(format, root, files, write = 'jsonl-append', shared = write === 'sqlite-wal') {
18
+ return { format, root, files, write, shared };
19
19
  }
20
- /** Store layouts, relative to the HOME a harness ran with. */
21
20
  export const STORES = {
22
21
  'claude-code.projects-jsonl': store('claude-code.projects-jsonl', '.claude/projects', [
23
22
  '*/{id}.jsonl', '*/{id}/subagents/**/*.jsonl',
@@ -27,8 +26,6 @@ export const STORES = {
27
26
  'opencode.db', 'opencode.db-wal', 'opencode.db-shm',
28
27
  ], 'sqlite-wal'),
29
28
  'pi.session-jsonl': store('pi.session-jsonl', '.pi/agent/sessions', ['**/*_{id}.jsonl']),
30
- // A session directory: wire.jsonl (the event stream read here), context.jsonl and its rotated
31
- // context_N.jsonl copies, and state.json.
32
29
  'kimi.session-dir': store('kimi.session-dir', '.kimi/sessions', ['*/{id}/**', '*/{id}.jsonl']),
33
30
  'factory.session-jsonl': store('factory.session-jsonl', '.factory/sessions', [
34
31
  '*/{id}.jsonl', '*/{id}.settings.json',
@@ -37,11 +34,11 @@ export const STORES = {
37
34
  'amp.thread-json': store('amp.thread-json', '.local/share/amp/threads', ['{id}.json'], 'json-rewrite'),
38
35
  'forge.sqlite': store('forge.sqlite', '.forge', ['.forge.db', '.forge.db-wal', '.forge.db-shm'], 'sqlite-wal'),
39
36
  'hermes.state-sqlite': store('hermes.state-sqlite', '.hermes', ['state.db', 'state.db-wal', 'state.db-shm'], 'sqlite-wal'),
40
- 'prime.session-jsonl': store('prime.session-jsonl', '.prime-provider/prime-agent-dirs', ['**/*_{id}.jsonl']),
41
- 'openclaw.session-jsonl': store('openclaw.session-jsonl', '.openclaw/agents', ['**/{id}.jsonl']),
42
- 'grok.acp-session-dir': store('grok.acp-session-dir', '.grok/sessions', ['*/{id}/updates.jsonl']),
37
+ 'prime.session-jsonl': store('prime.session-jsonl', '.prime-provider/prime-agent-dirs', ['**/sessions/*.jsonl']),
38
+ '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
+ 'grok.acp-session-dir': store('grok.acp-session-dir', '.grok/sessions', ['*/{id}/updates.jsonl', '*/{id}/chat_history.jsonl', '*/{id}/summary.json', '*/{id}/signals.json']),
40
+ 'nanoclaw.session-sqlite': store('nanoclaw.session-sqlite', '.nanoclaw/data/v2-sessions', ['*/{id}/outbound.db', '*/{id}/inbound.db'], 'sqlite-wal', false),
43
41
  };
44
- /** Kimi Code's current and retained legacy layouts; the legacy catalog entry stays stable. */
45
42
  export const KIMI_STORES = [
46
43
  { ...STORES['kimi.session-dir'], root: '.kimi-code/sessions', files: ['wd_*/{id}/**'], globs: { session: 'wd_*/{id}/agents/main/wire.jsonl' } },
47
44
  STORES['kimi.session-dir'],
@@ -60,23 +57,15 @@ export const EVIDENCE = {
60
57
  'prime.session-jsonl': { servedModel: 'session-record', usage: 'per-response', endingError: 'session-record' },
61
58
  'openclaw.session-jsonl': { servedModel: 'session-record', usage: 'per-response', endingError: 'none' },
62
59
  'grok.acp-session-dir': { servedModel: 'session-record', usage: 'session-total', endingError: 'none' },
60
+ 'nanoclaw.session-sqlite': { servedModel: 'none', usage: 'per-response', endingError: 'none' },
63
61
  };
64
- /** Codex homes: `.codex`, `.codex-*`, acct homes, and a fleet seat's `codex` directory. */
65
62
  export const CODEX_HOME_RULE = {
66
- /** Directory names directly under HOME that are Codex homes: `.codex` and `.codex-<name>`. */
67
63
  siblings: /^\.codex(?:-.+)?$/u,
68
- /** Under HOME, unless `$ACCT_CONFIG` names it: each child is one account's Codex home. */
69
64
  accounts: '.config/agent-accounts/codex',
70
65
  sessionDirs: ['sessions', 'archived_sessions'],
71
- /** A rollout's file name, at any depth under a session dir (`sessions/` nests by date). */
72
66
  rollout: 'rollout-*.jsonl',
73
- /** The name Codex gives a rollout, ending in its thread id. */
74
67
  named: 'rollout-*-{id}.jsonl',
75
68
  };
76
- /**
77
- * True when `dir` is itself a Codex home by its path: `.codex`, `.codex-<name>`, an acct account
78
- * home (`agent-accounts/codex/<account>`), or a fleet seat's `codex` directory.
79
- */
80
69
  export function isCodexHome(dir) {
81
70
  const parts = dir.replace(/\/+$/u, '').split('/');
82
71
  const [name, parent, grandparent] = [parts.at(-1) ?? '', parts.at(-2) ?? '', parts.at(-3) ?? ''];
@@ -86,18 +75,12 @@ export function isCodexHome(dir) {
86
75
  return true;
87
76
  return name === 'codex' && parent !== 'agent-accounts';
88
77
  }
89
- /** True when `path` is `root` or lies under it on a path boundary: `/x/agent` is not under `/x/age`. */
90
78
  export function withinPath(path, root) {
91
79
  const p = path.replace(/\/+$/u, '');
92
80
  const r = root.replace(/\/+$/u, '');
93
81
  return p === r || p.startsWith(`${r}/`);
94
82
  }
95
83
  const REGEX_SPECIALS = /[.+^$()|[\]\\]/gu;
96
- /**
97
- * Compile one store glob. `*` matches within a path segment, `**` matches any number of
98
- * segments, and `{id}` matches the native session id: the literal id when one is given, any
99
- * segment text otherwise (the reader then takes the id from the session's own header).
100
- */
101
84
  export function storeGlob(glob, nativeSessionId) {
102
85
  let pattern = '';
103
86
  for (let i = 0; i < glob.length; i += 1) {
@@ -126,7 +109,6 @@ export function storeGlob(glob, nativeSessionId) {
126
109
  }
127
110
  return new RegExp(`^${pattern}$`, 'u');
128
111
  }
129
- /** A store root must be a normalized path relative to HOME: not absolute, no `.`/`..` segments. */
130
112
  export function assertStoreRoot(root) {
131
113
  const segments = root.split('/');
132
114
  if (root.startsWith('/') || segments.some((s) => s === '' || s === '.' || s === '..')) {
package/dist/cli.js CHANGED
@@ -1,12 +1,4 @@
1
1
  #!/usr/bin/env node
2
- /**
3
- * harness-sessions read <file|home|capture> [--harness h] [--session id] [--cwd dir] [--summary] [--json]
4
- *
5
- * Reads native harness sessions into the normalized form, for callers that are not JavaScript.
6
- * A file is one session file (or an OpenCode store); a directory is a capture when it holds
7
- * `__retention__/sessions`, otherwise a HOME searched through every reader's store layout.
8
- * `--json` prints one JSON document per session, one per line.
9
- */
10
2
  import { stat } from 'node:fs/promises';
11
3
  import { join } from 'node:path';
12
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,5 +1,4 @@
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';
@@ -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))
@@ -281,7 +273,6 @@ export const claudeCodeReader = {
281
273
  return (await fold(ref, 'summary', opts)).summary();
282
274
  },
283
275
  };
284
- /** A reader for one transcript file outside a HOME layout (the CLI, a retained copy). */
285
276
  export function claudeCodeRefForFile(path, parentNativeSessionId = null) {
286
277
  const name = basename(path, '.jsonl');
287
278
  return {
@@ -1,20 +1,8 @@
1
- /**
2
- * Which Claude Code `user` records a person typed and which the harness wrote. Claude Code stores
3
- * both as `type: "user"`; the markers below are the only difference. This is the one owner of the
4
- * rule, so every reader of a Claude Code transcript (traces, agent-eval) classifies turns alike.
5
- */
6
1
  export interface ClaudeRecordFacts {
7
- /** The record's text (the first text part for block content). */
8
2
  text: string;
9
3
  isMeta?: boolean | undefined;
10
4
  isCompactSummary?: boolean | undefined;
11
- /** The record's `entrypoint`; `sdk-cli` is a programmatic caller, not a person. */
12
5
  entrypoint?: string | undefined;
13
6
  }
14
- /** True when the harness, not a person, wrote this user record. */
15
7
  export declare function claudeRecordIsMachine(facts: ClaudeRecordFacts): boolean;
16
- /**
17
- * What a person typed. A slash command is stored as a `<command-name>` wrapper; this returns the
18
- * command and its arguments (`/effort`, `/model opus`). Text without a wrapper is unchanged.
19
- */
20
8
  export declare function claudeTypedPromptText(text: string): string;
@@ -1,8 +1,3 @@
1
- /**
2
- * Which Claude Code `user` records a person typed and which the harness wrote. Claude Code stores
3
- * both as `type: "user"`; the markers below are the only difference. This is the one owner of the
4
- * rule, so every reader of a Claude Code transcript (traces, agent-eval) classifies turns alike.
5
- */
6
1
  const MACHINE_TEXT_PREFIXES = [
7
2
  '<local-command-caveat>',
8
3
  '<local-command-stdout>',
@@ -14,17 +9,12 @@ const MACHINE_TEXT_PREFIXES = [
14
9
  '<user-prompt-submit-hook>',
15
10
  '[Request interrupted by user',
16
11
  ];
17
- /** True when the harness, not a person, wrote this user record. */
18
12
  export function claudeRecordIsMachine(facts) {
19
13
  if (facts.isMeta === true || facts.isCompactSummary === true || facts.entrypoint === 'sdk-cli')
20
14
  return true;
21
15
  const head = facts.text.trimStart();
22
16
  return MACHINE_TEXT_PREFIXES.some((prefix) => head.startsWith(prefix));
23
17
  }
24
- /**
25
- * What a person typed. A slash command is stored as a `<command-name>` wrapper; this returns the
26
- * command and its arguments (`/effort`, `/model opus`). Text without a wrapper is unchanged.
27
- */
28
18
  export function claudeTypedPromptText(text) {
29
19
  const name = /<command-name>([\s\S]*?)<\/command-name>/u.exec(text)?.[1]?.trim();
30
20
  if (!name)