@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
@@ -1,5 +1,4 @@
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';
@@ -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
  }
@@ -0,0 +1,2 @@
1
+ import type { HarnessSessionReader } from '../schema.js';
2
+ export declare const primeReader: HarnessSessionReader;
@@ -0,0 +1,35 @@
1
+ import { basename, join } from 'node:path';
2
+ import { fileRecords } from '../source.js';
3
+ import { EVIDENCE, STORES, mtimeMs, storeGlob, walkFiles } from '../stores.js';
4
+ import { 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 = {
17
+ harness: HARNESS, aliases: [], formats: [FORMAT], stores: [STORE], globs: { session: STORE.files[0] }, evidence: EVIDENCE[FORMAT],
18
+ async locate(home, opts = {}) {
19
+ const root = join(home, STORE.root);
20
+ const pattern = storeGlob(STORE.files[0], opts.nativeSessionId);
21
+ const refs = [];
22
+ for (const rel of await walkFiles(root)) {
23
+ if (!pattern.test(rel))
24
+ continue;
25
+ const path = join(root, rel);
26
+ const id = idFromName(rel);
27
+ if (opts.nativeSessionId && id !== opts.nativeSessionId)
28
+ continue;
29
+ refs.push({ harness: HARNESS, format: FORMAT, nativeSessionId: id, path, files: [path], home, cwd: null, mtimeMs: await mtimeMs(path), parentNativeSessionId: null });
30
+ }
31
+ return refs.sort((a, b) => b.mtimeMs - a.mtimeMs);
32
+ },
33
+ async read(ref, opts = {}) { return (await fold(ref, 'full', opts)).build(); },
34
+ async summarize(ref, opts = {}) { return (await fold(ref, 'summary', opts)).summary(); },
35
+ };
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';
@@ -12,6 +11,10 @@ export { piReader, piRefForFile } from './formats/pi.js';
12
11
  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';
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 { openclawReader } from './formats/openclaw.js';
15
18
  export { listCapture, readCapture, RETENTION_MANIFEST_KIND, RETENTION_SESSIONS, type CaptureListing, type CapturedSessionRef, } from './capture.js';
16
19
  export { SessionParseError } from './source.js';
17
20
  export { servedModelKey } from './builder.js';
package/dist/index.js CHANGED
@@ -10,6 +10,10 @@ export { piReader, piRefForFile } from './formats/pi.js';
10
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
+ export { nanoclawReader, nanoclawRefForFile } from './formats/nanoclaw.js';
14
+ export { hermesReader, hermesSessionsInStore } from './formats/hermes.js';
15
+ export { primeReader } from './formats/prime.js';
16
+ export { openclawReader } from './formats/openclaw.js';
13
17
  export { listCapture, readCapture, RETENTION_MANIFEST_KIND, RETENTION_SESSIONS, } from './capture.js';
14
18
  export { SessionParseError } from './source.js';
15
19
  export { servedModelKey } from './builder.js';
package/dist/input.d.ts CHANGED
@@ -5,20 +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
- /**
15
- * The file line `input` starts on, when it continues a longer file (records appended since a
16
- * previous read). A record without an id of its own is named by its line, so the same record
17
- * gets the same id whichever way the file is read. Default 1.
18
- */
19
11
  firstLine?: number;
20
12
  }
21
- /** Read a JSONL-format session (Claude Code, Codex, Pi, Kimi) from text or parsed records, synchronously. */
22
13
  export declare function readSessionInput(harness: string, input: SessionInput, init?: SessionInputInit, options?: Pick<ReadOptions, 'corruption'>): HarnessSession;
23
- /** Summarize a JSONL-format session from text or parsed records, synchronously. */
24
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,14 +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
- /**
27
- * The session as chat-with-tools messages: each assistant message carries its text, reasoning
28
- * and tool calls; each tool result is a `tool` message answering its call. Content is complete;
29
- * a projection that needs less trims it itself.
30
- */
31
23
  export declare function toChatMessages(session: HarnessSession, options?: ChatProjectionOptions): ChatMessage[];
@@ -14,11 +14,6 @@ function resultContent(output, text) {
14
14
  return '';
15
15
  return JSON.stringify(output);
16
16
  }
17
- /**
18
- * The session as chat-with-tools messages: each assistant message carries its text, reasoning
19
- * and tool calls; each tool result is a `tool` message answering its call. Content is complete;
20
- * a projection that needs less trims it itself.
21
- */
22
17
  export function toChatMessages(session, options = {}) {
23
18
  const keepInjected = options.injected !== false;
24
19
  const keepSystem = options.system !== false;
@@ -1,12 +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
- /**
8
- * The session as contract spans: one AGENT span for the session, one LLM span per model call
9
- * (served model, tokens, cost, error status) and one TOOL span per tool call under the model call
10
- * that made it. Ids derive from the native session id, so two exports of one session join.
11
- */
12
6
  export declare function toOtlpSpans(session: HarnessSession, options?: OtlpProjectionOptions): ContractSpan[];
@@ -1,10 +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
- /**
4
- * The session as contract spans: one AGENT span for the session, one LLM span per model call
5
- * (served model, tokens, cost, error status) and one TOOL span per tool call under the model call
6
- * that made it. Ids derive from the native session id, so two exports of one session join.
7
- */
8
3
  export function toOtlpSpans(session, options = {}) {
9
4
  const chars = options.contentChars ?? 8000;
10
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,34 +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
- /**
45
- * The session as the blog's turns: one turn per human message and per assistant message, with
46
- * the tool calls an assistant message made, the files they touched, the model that answered,
47
- * its usage and the error it ended with.
48
- */
49
32
  export declare function toTurns(session: HarnessSession, options?: TurnOptions): Turn[];
50
- /** The model a session was answered by most often, or null when it recorded none. */
51
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,11 +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
- /**
64
- * The session as the blog's turns: one turn per human message and per assistant message, with
65
- * the tool calls an assistant message made, the files they touched, the model that answered,
66
- * its usage and the error it ended with.
67
- */
68
62
  export function toTurns(session, options = {}) {
69
63
  const textChars = options.textChars ?? 8000;
70
64
  const summaryChars = options.summaryChars ?? 280;
@@ -121,7 +115,6 @@ export function toTurns(session, options = {}) {
121
115
  }
122
116
  return turns;
123
117
  }
124
- /** The model a session was answered by most often, or null when it recorded none. */
125
118
  export function primaryModel(session) {
126
119
  const counts = new Map();
127
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,35 +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';
7
+ import { nanoclawReader } from './formats/nanoclaw.js';
8
+ import { openclawReader } from './formats/openclaw.js';
9
+ import { primeReader } from './formats/prime.js';
6
10
  import { opencodeReader } from './formats/opencode.js';
7
11
  import { piReader } from './formats/pi.js';
8
- const READERS = [claudeCodeReader, codexReader, opencodeReader, piReader, kimiReader, factoryReader, grokReader];
12
+ const READERS = [claudeCodeReader, codexReader, opencodeReader, piReader, kimiReader, factoryReader, grokReader, nanoclawReader, hermesReader, primeReader, openclawReader];
9
13
  const BY_NAME = new Map();
10
14
  for (const reader of READERS) {
11
15
  BY_NAME.set(reader.harness, reader);
12
16
  for (const alias of reader.aliases)
13
17
  BY_NAME.set(alias, reader);
14
18
  }
15
- /** Every reader this package ships. */
16
19
  export function listReaders() {
17
20
  return READERS;
18
21
  }
19
- /** Harness ids and aliases that resolve to a reader. */
20
22
  export function knownHarnesses() {
21
23
  return [...BY_NAME.keys()].sort();
22
24
  }
23
- /** The reader for a harness id or alias. Throws for a harness with no reader. */
24
25
  export function readerFor(harnessOrAlias) {
25
26
  const reader = BY_NAME.get(harnessOrAlias) ?? BY_NAME.get(harnessOrAlias.toLowerCase());
26
27
  if (!reader)
27
28
  throw new Error(`no session reader for harness "${harnessOrAlias}"; known: ${knownHarnesses().join(', ')}`);
28
29
  return reader;
29
30
  }
30
- /** The reader for a harness, or undefined when none exists. */
31
31
  export function maybeReaderFor(harnessOrAlias) {
32
32
  return BY_NAME.get(harnessOrAlias) ?? BY_NAME.get(harnessOrAlias.toLowerCase());
33
33
  }
34
- /** The reader that owns a session format. */
35
34
  export function readerForFormat(format) {
36
35
  const reader = READERS.find((r) => r.formats.includes(format));
37
36
  if (!reader)
package/dist/schema.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /** One native session format. The id names the harness family and the on-disk layout. */
2
1
  export type SessionFormatId = (typeof import('./catalog.js').SESSION_FORMAT_IDS)[number];
3
2
  export interface NativeSessionStore {
4
3
  root: string;
@@ -24,10 +23,8 @@ export interface TokenUsage {
24
23
  cacheWrite: number | null;
25
24
  }
26
25
  export interface SessionError {
27
- /** The harness's own classification: `api-error`, `stream_error`, a provider error name. */
28
26
  kind: string;
29
27
  message: string;
30
- /** The provider's HTTP status when the harness recorded it. */
31
28
  httpStatus: number | null;
32
29
  at: string | null;
33
30
  }
@@ -54,23 +51,19 @@ export interface SessionMessage {
54
51
  role: 'system' | 'user' | 'assistant' | 'tool';
55
52
  actor: 'human' | 'agent' | 'subagent-spawn' | 'injected' | 'tool-result';
56
53
  at: string | null;
57
- /** The model call that produced an assistant message; null for every other message. */
58
54
  modelCallId: string | null;
59
55
  parts: Part[];
60
56
  }
61
57
  export interface SessionToolCall {
62
58
  id: string;
63
59
  name: string;
64
- /** The arguments as structured data when the harness recorded JSON, otherwise the raw text. */
65
60
  input: unknown;
66
- /** The arguments exactly as the harness recorded them when it recorded text. */
67
61
  inputText: string | null;
68
62
  result: {
69
63
  output: unknown;
70
64
  text: string | null;
71
65
  isError: boolean;
72
66
  at: string | null;
73
- /** The harness's own structured result (Claude Code `toolUseResult`, Pi `details`, OpenCode `metadata`). */
74
67
  details: unknown;
75
68
  } | null;
76
69
  status: 'completed' | 'error' | 'pending' | 'interrupted';
@@ -82,12 +75,7 @@ export interface ModelCall {
82
75
  id: string;
83
76
  at: string | null;
84
77
  provider: string | null;
85
- /** The model that answered, from the provider response or the session record. Never the request. */
86
78
  servedModel: string | null;
87
- /**
88
- * The model the harness sent the request to, when the session records it. A failed request has
89
- * no served model; this says which model it was meant for. Never counted as served.
90
- */
91
79
  requestedModel: string | null;
92
80
  usage: TokenUsage | null;
93
81
  costUsd: number | null;
@@ -105,9 +93,7 @@ export interface SessionIntegrity {
105
93
  sha256: string;
106
94
  bytes: number;
107
95
  }>;
108
- /** Records the reader could not parse. Never fatal in recover mode. */
109
96
  unparsedRecords: number;
110
- /** True when a source copy was cut short (a bounded capture kept only a prefix). */
111
97
  truncated: boolean;
112
98
  gaps: string[];
113
99
  }
@@ -123,10 +109,8 @@ export interface HarnessSession {
123
109
  messages: SessionMessage[];
124
110
  toolCalls: SessionToolCall[];
125
111
  modelCalls: ModelCall[];
126
- /** `provider/model` (or the bare model when no provider is recorded) -> calls it answered. */
127
112
  servedModels: Record<string, number>;
128
113
  modelSource: SessionEvidenceSources['servedModel'];
129
- /** Null when the harness recorded no usage at all. Never reported as zero. */
130
114
  usage: TokenUsage | null;
131
115
  ending: SessionEnding;
132
116
  children: Array<{
@@ -135,18 +119,15 @@ export interface HarnessSession {
135
119
  }>;
136
120
  integrity: SessionIntegrity;
137
121
  }
138
- /** What `summarize` keeps: counts and the facts a gate needs, in constant memory. */
139
122
  export interface SessionSummary {
140
123
  harness: string;
141
124
  format: SessionFormatId;
142
125
  nativeSessionId: string;
143
126
  parentNativeSessionId: string | null;
144
127
  modelCalls: number;
145
- /** Assistant messages the agent produced. */
146
128
  replies: number;
147
129
  toolCalls: number;
148
130
  servedModels: Record<string, number>;
149
- /** The served-model key (`provider/model`) of the last model call that a model answered. */
150
131
  lastServedModel: string | null;
151
132
  modelSource: HarnessSession['modelSource'];
152
133
  usage: TokenUsage | null;
@@ -157,33 +138,25 @@ export interface SessionSummary {
157
138
  startedAt: string | null;
158
139
  endedAt: string | null;
159
140
  }
160
- /** One discovered session, before it is read. */
161
141
  export interface SessionRef {
162
142
  harness: string;
163
143
  format: SessionFormatId;
164
144
  nativeSessionId: string;
165
- /** The session's primary file (the JSONL, or the SQLite store for a shared store). */
166
145
  path: string;
167
- /** Every file whose bytes the read depends on, including subagent files and SQLite siblings. */
168
146
  files: readonly string[];
169
- /** The HOME the session was found under, when it was located through a store. */
170
147
  home: string | null;
171
148
  cwd: string | null;
172
149
  mtimeMs: number;
173
150
  parentNativeSessionId: string | null;
174
- /** True when the copy this ref points at is a bounded prefix of the session. */
175
151
  truncated?: boolean;
176
152
  }
177
153
  export interface LocateOptions {
178
154
  nativeSessionId?: string;
179
- /** Sessions whose recorded cwd is this path or lies under it on a path boundary (`/x/agent` excludes `/x/agent-dev-container`). */
180
155
  cwd?: string;
181
- /** Sessions modified at or after this epoch ms. */
182
156
  sinceMs?: number;
183
157
  }
184
158
  export interface ReadOptions {
185
159
  signal?: AbortSignal;
186
- /** `recover` (default) counts unparsable records; `strict` throws on the first one. */
187
160
  corruption?: 'recover' | 'strict';
188
161
  }
189
162
  export interface HarnessSessionReader {
@@ -191,10 +164,6 @@ export interface HarnessSessionReader {
191
164
  aliases: readonly string[];
192
165
  formats: readonly SessionFormatId[];
193
166
  stores: readonly NativeSessionStore[];
194
- /**
195
- * Default globs under each store's root, unless that store supplies its own globs: the session
196
- * file and, when the harness writes subagent transcripts separately, those files.
197
- */
198
167
  globs: {
199
168
  session: string;
200
169
  children?: string;
@@ -202,20 +171,16 @@ export interface HarnessSessionReader {
202
171
  evidence: SessionEvidenceSources;
203
172
  locate(home: string, opts?: LocateOptions): Promise<SessionRef[]>;
204
173
  read(ref: SessionRef, opts?: ReadOptions): Promise<HarnessSession>;
205
- /** Streams the session in constant memory with respect to message and tool-output size. */
206
174
  summarize(ref: SessionRef, opts?: Pick<ReadOptions, 'signal'>): Promise<SessionSummary>;
207
175
  }
208
- /** One copy of a native session that the sidecar captured for an execution. */
209
176
  export interface NativeSessionCopy {
210
177
  harness: string;
211
178
  format: SessionFormatId;
212
179
  executionId: string;
213
180
  attempt: number;
214
181
  nativeSessionId: string;
215
- /** `snapshot`: taken while the harness ran. `settled`: taken after it exited, however it ended. */
216
182
  copy: 'snapshot' | 'settled';
217
183
  capturedAt: string;
218
- /** Null where the sidecar did not observe the value at the copy point. */
219
184
  process: {
220
185
  pid: number | null;
221
186
  exitedAt: string | null;
@@ -223,11 +188,8 @@ export interface NativeSessionCopy {
223
188
  signal: string | null;
224
189
  };
225
190
  files: Array<{
226
- /** Path inside the archive, relative to the archive root. */
227
191
  path: string;
228
- /** The store root the file belongs to, relative to the runtime HOME. */
229
192
  store: string;
230
- /** The file's own path relative to the runtime HOME; the sidecar archive's payload names are flat. */
231
193
  storePath?: string;
232
194
  sizeBytes: number;
233
195
  sha256: string;
@@ -237,7 +199,6 @@ export interface NativeSessionCopy {
237
199
  complete: boolean;
238
200
  missingReasons: string[];
239
201
  }
240
- /** The part of the sidecar's raw-evidence archive manifest this package reads. */
241
202
  export interface RawEvidenceArchiveManifestV2 {
242
203
  schema: 'tangle.raw-evidence-archive.v2';
243
204
  nativeSessions: NativeSessionCopy[];
package/dist/source.d.ts CHANGED
@@ -1,18 +1,13 @@
1
1
  import type { DatabaseSync } from 'node:sqlite';
2
- /** What one source file contributed to a read: its identity and what could not be parsed. */
3
2
  export interface SourceStats {
4
3
  path: string;
5
4
  sha256: string;
6
5
  bytes: number;
7
6
  unparsed: number;
8
- /** The file ended without a newline and its last bytes were not a complete record. */
9
7
  tornTail: boolean;
10
- /** The line number (1-based) of the record most recently yielded. */
11
8
  line: number;
12
- /** Line numbers of the first unparsable lines (at most 50), for the gaps a reader reports. */
13
9
  unparsedLines?: number[];
14
10
  }
15
- /** Records to fold, with the stats of the bytes they came from. */
16
11
  export interface RecordSource {
17
12
  stats: SourceStats;
18
13
  records: AsyncIterable<Record<string, unknown>>;
@@ -22,26 +17,20 @@ export declare class SessionParseError extends Error {
22
17
  readonly line: number;
23
18
  constructor(path: string, line: number, reason: string);
24
19
  }
25
- /** Stream one JSONL file in order and hash it. Unparsable lines count, or throw in strict mode. A torn tail is an unfinished last line, not corruption. */
26
20
  export declare function readJsonlRecords(path: string, stats: SourceStats, options?: {
27
21
  strict?: boolean;
28
22
  signal?: AbortSignal;
29
23
  }): AsyncGenerator<Record<string, unknown>>;
30
24
  export declare function newSourceStats(path: string): SourceStats;
31
- /** The records of a JSONL file, streamed. */
32
25
  export declare function fileRecords(path: string, options?: {
33
26
  strict?: boolean;
34
27
  signal?: AbortSignal;
35
28
  }): RecordSource;
36
- /** Stats for bytes already in memory. */
37
29
  export declare function memoryStats(label: string, text?: string): SourceStats;
38
- /** JSONL text already in memory. `firstLine` numbers its first line when the text continues a longer file. */
39
30
  export declare function textRecordsSync(text: string, stats: SourceStats, options?: {
40
31
  strict?: boolean;
41
32
  firstLine?: number;
42
33
  }): Generator<Record<string, unknown>>;
43
- /** Records a caller already parsed (one per line, in order, the first on line `firstLine`). Non-objects count as unparsed. */
44
34
  export declare function arrayRecordsSync(values: readonly unknown[], stats: SourceStats, firstLine?: number): Generator<Record<string, unknown>>;
45
- /** Run `use` on a store opened read-only in place. If SQLite cannot, read a private copy: a WAL with no `-shm` on read-only storage, or Node before 22.15 without URI file names. */
46
35
  export declare function withSqlite<T>(path: string, use: (db: DatabaseSync) => T): Promise<T>;
47
36
  export declare function isMissing(error: unknown): boolean;