@tangle-network/harness-sessions 1.0.6 → 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.
- package/dist/builder.d.ts +0 -13
- package/dist/builder.js +0 -17
- package/dist/capture.d.ts +0 -8
- package/dist/capture.js +3 -14
- package/dist/catalog.d.ts +3 -17
- package/dist/catalog.js +3 -20
- package/dist/cli.js +0 -1
- package/dist/formats/claude-code.d.ts +0 -1
- package/dist/formats/claude-code.js +0 -9
- package/dist/formats/claude-records.d.ts +0 -8
- package/dist/formats/claude-records.js +0 -6
- package/dist/formats/codex.js +0 -29
- package/dist/formats/factory.js +0 -3
- package/dist/formats/fold.d.ts +0 -1
- package/dist/formats/grok.js +12 -3
- package/dist/formats/head.d.ts +0 -1
- package/dist/formats/head.js +0 -4
- package/dist/formats/hermes.d.ts +3 -0
- package/dist/formats/hermes.js +93 -0
- package/dist/formats/kimi.d.ts +0 -1
- package/dist/formats/kimi.js +0 -6
- package/dist/formats/nanoclaw.js +0 -1
- package/dist/formats/openclaw.d.ts +3 -0
- package/dist/formats/openclaw.js +102 -0
- package/dist/formats/opencode.d.ts +0 -1
- package/dist/formats/opencode.js +0 -6
- package/dist/formats/pi.d.ts +1 -1
- package/dist/formats/pi.js +3 -9
- package/dist/formats/prime.d.ts +2 -0
- package/dist/formats/prime.js +35 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -0
- package/dist/input.d.ts +0 -6
- package/dist/input.js +0 -2
- package/dist/projections/chat.d.ts +0 -4
- package/dist/projections/chat.js +0 -1
- package/dist/projections/otlp.d.ts +0 -2
- package/dist/projections/otlp.js +0 -1
- package/dist/projections/turns.d.ts +0 -14
- package/dist/projections/turns.js +0 -3
- package/dist/registry.d.ts +0 -5
- package/dist/registry.js +4 -6
- package/dist/schema.d.ts +0 -39
- package/dist/source.d.ts +0 -11
- package/dist/source.js +0 -19
- package/dist/stores.d.ts +0 -4
- package/dist/stores.js +0 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** One normalized reader for each coding-agent harness session store. */
|
|
2
1
|
export type { HarnessSession, HarnessSessionReader, LocateOptions, ModelCall, NativeSessionCopy, NativeSessionStore, Part, RawEvidenceArchiveManifestV2, ReadOptions, SessionEnding, SessionError, SessionEvidenceSources, SessionFormatId, SessionIntegrity, SessionMessage, SessionRef, SessionSummary, SessionToolCall, TokenUsage, } from './schema.js';
|
|
3
2
|
export { HARNESS_SESSION_SCHEMA } from './schema.js';
|
|
4
3
|
export { CODEX_HOME_RULE, EVIDENCE, SESSION_FORMAT_IDS, STORES, assertStoreRoot, isCodexHome, storeGlob, withinPath } from './catalog.js';
|
|
@@ -13,6 +12,9 @@ export { kimiReader, kimiRefForFile } from './formats/kimi.js';
|
|
|
13
12
|
export { factoryReader, factoryRefForFile } from './formats/factory.js';
|
|
14
13
|
export { grokReader, grokRefForFile } from './formats/grok.js';
|
|
15
14
|
export { nanoclawReader, nanoclawRefForFile } from './formats/nanoclaw.js';
|
|
15
|
+
export { hermesReader, hermesSessionsInStore } from './formats/hermes.js';
|
|
16
|
+
export { primeReader } from './formats/prime.js';
|
|
17
|
+
export { openclawReader } from './formats/openclaw.js';
|
|
16
18
|
export { listCapture, readCapture, RETENTION_MANIFEST_KIND, RETENTION_SESSIONS, type CaptureListing, type CapturedSessionRef, } from './capture.js';
|
|
17
19
|
export { SessionParseError } from './source.js';
|
|
18
20
|
export { servedModelKey } from './builder.js';
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,9 @@ export { kimiReader, kimiRefForFile } from './formats/kimi.js';
|
|
|
11
11
|
export { factoryReader, factoryRefForFile } from './formats/factory.js';
|
|
12
12
|
export { grokReader, grokRefForFile } from './formats/grok.js';
|
|
13
13
|
export { nanoclawReader, nanoclawRefForFile } from './formats/nanoclaw.js';
|
|
14
|
+
export { hermesReader, hermesSessionsInStore } from './formats/hermes.js';
|
|
15
|
+
export { primeReader } from './formats/prime.js';
|
|
16
|
+
export { openclawReader } from './formats/openclaw.js';
|
|
14
17
|
export { listCapture, readCapture, RETENTION_MANIFEST_KIND, RETENTION_SESSIONS, } from './capture.js';
|
|
15
18
|
export { SessionParseError } from './source.js';
|
|
16
19
|
export { servedModelKey } from './builder.js';
|
package/dist/input.d.ts
CHANGED
|
@@ -5,16 +5,10 @@ export type SessionInput = {
|
|
|
5
5
|
records: readonly unknown[];
|
|
6
6
|
};
|
|
7
7
|
export interface SessionInputInit {
|
|
8
|
-
/** The native session id when the caller knows it; JSONL formats also read it from their records. */
|
|
9
8
|
nativeSessionId?: string;
|
|
10
|
-
/** Set for a subagent's own transcript; its records are the subagent's, not sidechain noise. */
|
|
11
9
|
parentNativeSessionId?: string | null;
|
|
12
|
-
/** Names the source in integrity records (a path, a blob ref). */
|
|
13
10
|
label?: string;
|
|
14
|
-
/** The file line `input` starts on, when it continues a longer file (records appended since a previous read). A record without an id of its own is named by its line, so the same record gets the same id whichever way the file is read. Default 1. */
|
|
15
11
|
firstLine?: number;
|
|
16
12
|
}
|
|
17
|
-
/** Read a JSONL-format session (Claude Code, Codex, Pi, Kimi) from text or parsed records, synchronously. */
|
|
18
13
|
export declare function readSessionInput(harness: string, input: SessionInput, init?: SessionInputInit, options?: Pick<ReadOptions, 'corruption'>): HarnessSession;
|
|
19
|
-
/** Summarize a JSONL-format session from text or parsed records, synchronously. */
|
|
20
14
|
export declare function summarizeSessionInput(harness: string, input: SessionInput, init?: SessionInputInit, options?: Pick<ReadOptions, 'corruption'>): SessionSummary;
|
package/dist/input.js
CHANGED
|
@@ -39,11 +39,9 @@ function foldInput(harness, input, init, mode, options) {
|
|
|
39
39
|
fold.observe(record);
|
|
40
40
|
return fold.finish();
|
|
41
41
|
}
|
|
42
|
-
/** Read a JSONL-format session (Claude Code, Codex, Pi, Kimi) from text or parsed records, synchronously. */
|
|
43
42
|
export function readSessionInput(harness, input, init = {}, options = {}) {
|
|
44
43
|
return foldInput(harness, input, init, 'full', options).build();
|
|
45
44
|
}
|
|
46
|
-
/** Summarize a JSONL-format session from text or parsed records, synchronously. */
|
|
47
45
|
export function summarizeSessionInput(harness, input, init = {}, options = {}) {
|
|
48
46
|
return foldInput(harness, input, init, 'summary', options).summary();
|
|
49
47
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { HarnessSession } from '../schema.js';
|
|
2
|
-
/** agent-eval's chat-with-tools message (`src/rollout/schema.ts`), declared here structurally. */
|
|
3
2
|
export interface ChatToolCall {
|
|
4
3
|
id: string;
|
|
5
4
|
type: 'function';
|
|
@@ -18,10 +17,7 @@ export interface ChatMessage {
|
|
|
18
17
|
is_copied_context?: boolean;
|
|
19
18
|
}
|
|
20
19
|
export interface ChatProjectionOptions {
|
|
21
|
-
/** Keep messages the harness injected (environment context, instructions). Default true. */
|
|
22
20
|
injected?: boolean;
|
|
23
|
-
/** Keep `system` messages. Default true. */
|
|
24
21
|
system?: boolean;
|
|
25
22
|
}
|
|
26
|
-
/** The session as chat-with-tools messages: each assistant message carries its text, reasoning and tool calls; each tool result is a `tool` message answering its call. Content is complete; a projection that needs less trims it itself. */
|
|
27
23
|
export declare function toChatMessages(session: HarnessSession, options?: ChatProjectionOptions): ChatMessage[];
|
package/dist/projections/chat.js
CHANGED
|
@@ -14,7 +14,6 @@ function resultContent(output, text) {
|
|
|
14
14
|
return '';
|
|
15
15
|
return JSON.stringify(output);
|
|
16
16
|
}
|
|
17
|
-
/** The session as chat-with-tools messages: each assistant message carries its text, reasoning and tool calls; each tool result is a `tool` message answering its call. Content is complete; a projection that needs less trims it itself. */
|
|
18
17
|
export function toChatMessages(session, options = {}) {
|
|
19
18
|
const keepInjected = options.injected !== false;
|
|
20
19
|
const keepSystem = options.system !== false;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { type ContractSpan } from '@tangle-network/agent-trace-contract';
|
|
2
2
|
import type { HarnessSession } from '../schema.js';
|
|
3
3
|
export interface OtlpProjectionOptions {
|
|
4
|
-
/** Characters of message text kept per span attribute. Default 8000; 0 keeps none. */
|
|
5
4
|
contentChars?: number;
|
|
6
5
|
}
|
|
7
|
-
/** The session as contract spans: one AGENT span for the session, one LLM span per model call (served model, tokens, cost, error status) and one TOOL span per tool call under the model call that made it. Ids derive from the native session id, so two exports of one session join. */
|
|
8
6
|
export declare function toOtlpSpans(session: HarnessSession, options?: OtlpProjectionOptions): ContractSpan[];
|
package/dist/projections/otlp.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { contractSpan, deriveHexId, llmSpan, toolSpan, } from '@tangle-network/agent-trace-contract';
|
|
2
2
|
const cap = (text, n) => (text.length <= n ? text : `${text.slice(0, n)}…`);
|
|
3
|
-
/** The session as contract spans: one AGENT span for the session, one LLM span per model call (served model, tokens, cost, error status) and one TOOL span per tool call under the model call that made it. Ids derive from the native session id, so two exports of one session join. */
|
|
4
3
|
export function toOtlpSpans(session, options = {}) {
|
|
5
4
|
const chars = options.contentChars ?? 8000;
|
|
6
5
|
const traceId = deriveHexId(`${session.harness}:${session.nativeSessionId}`, 16);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { HarnessSession, SessionError, SessionToolCall, TokenUsage } from '../schema.js';
|
|
2
|
-
/** One tool invocation in a turn, previewed for storage beside a post. */
|
|
3
2
|
export interface TurnToolCall {
|
|
4
3
|
name: string;
|
|
5
4
|
input_preview?: string;
|
|
@@ -7,7 +6,6 @@ export interface TurnToolCall {
|
|
|
7
6
|
result_preview?: string;
|
|
8
7
|
is_error?: boolean;
|
|
9
8
|
}
|
|
10
|
-
/** One turn of agent activity, the blog's trace unit (drewstone.github.io tools/harness/types.ts). */
|
|
11
9
|
export interface Turn {
|
|
12
10
|
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
13
11
|
seq?: number;
|
|
@@ -18,30 +16,18 @@ export interface Turn {
|
|
|
18
16
|
tool_call_details?: TurnToolCall[];
|
|
19
17
|
files_touched?: string[];
|
|
20
18
|
had_thinking?: boolean;
|
|
21
|
-
/** The model that answered this turn, as the session recorded it. */
|
|
22
19
|
model?: string;
|
|
23
20
|
usage?: TokenUsage;
|
|
24
|
-
/** The error the model call ended with, when it failed. */
|
|
25
21
|
error?: SessionError;
|
|
26
22
|
ts: string;
|
|
27
23
|
}
|
|
28
24
|
export interface TurnOptions {
|
|
29
|
-
/** Working directory to make touched paths relative to. Defaults to the session cwd. */
|
|
30
25
|
cwd?: string | null;
|
|
31
|
-
/** Characters kept in `text`. Default 8000. */
|
|
32
26
|
textChars?: number;
|
|
33
|
-
/** Characters kept in `text_summary`. Default 280. */
|
|
34
27
|
summaryChars?: number;
|
|
35
|
-
/** Characters kept in a tool input or result preview. Default 600. */
|
|
36
28
|
previewChars?: number;
|
|
37
|
-
/**
|
|
38
|
-
* The files a tool call touched. Defaults to the path of an edit or write tool and the files a
|
|
39
|
-
* patch names; a caller with its own notion (paths mentioned anywhere in the input) passes it.
|
|
40
|
-
*/
|
|
41
29
|
filesOf?: (call: SessionToolCall) => string[];
|
|
42
30
|
}
|
|
43
31
|
export declare function summarizeText(text: string, n: number): string;
|
|
44
|
-
/** The session as the blog's turns: one turn per human message and per assistant message, with the tool calls an assistant message made, the files they touched, the model that answered, its usage and the error it ended with. */
|
|
45
32
|
export declare function toTurns(session: HarnessSession, options?: TurnOptions): Turn[];
|
|
46
|
-
/** The model a session was answered by most often, or null when it recorded none. */
|
|
47
33
|
export declare function primaryModel(session: Pick<HarnessSession, 'modelCalls'>): string | null;
|
|
@@ -12,7 +12,6 @@ function stringField(input, ...keys) {
|
|
|
12
12
|
return input[key];
|
|
13
13
|
return undefined;
|
|
14
14
|
}
|
|
15
|
-
/** Paths a patch touches, from `*** Update File:` / `*** Add File:` / `*** Delete File:` headers. */
|
|
16
15
|
function patchPaths(text) {
|
|
17
16
|
return [...text.matchAll(/^\*\*\* (?:Update|Add|Delete) File: (.+)$/gmu)].map((m) => m[1].trim());
|
|
18
17
|
}
|
|
@@ -60,7 +59,6 @@ function inputPreview(call) {
|
|
|
60
59
|
function text(message, type) {
|
|
61
60
|
return message.parts.filter((p) => p.type === type).map((p) => p.text).join('\n');
|
|
62
61
|
}
|
|
63
|
-
/** The session as the blog's turns: one turn per human message and per assistant message, with the tool calls an assistant message made, the files they touched, the model that answered, its usage and the error it ended with. */
|
|
64
62
|
export function toTurns(session, options = {}) {
|
|
65
63
|
const textChars = options.textChars ?? 8000;
|
|
66
64
|
const summaryChars = options.summaryChars ?? 280;
|
|
@@ -117,7 +115,6 @@ export function toTurns(session, options = {}) {
|
|
|
117
115
|
}
|
|
118
116
|
return turns;
|
|
119
117
|
}
|
|
120
|
-
/** The model a session was answered by most often, or null when it recorded none. */
|
|
121
118
|
export function primaryModel(session) {
|
|
122
119
|
const counts = new Map();
|
|
123
120
|
for (const call of session.modelCalls)
|
package/dist/registry.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type { HarnessSessionReader, SessionFormatId } from './schema.js';
|
|
2
|
-
/** Every reader this package ships. */
|
|
3
2
|
export declare function listReaders(): readonly HarnessSessionReader[];
|
|
4
|
-
/** Harness ids and aliases that resolve to a reader. */
|
|
5
3
|
export declare function knownHarnesses(): string[];
|
|
6
|
-
/** The reader for a harness id or alias. Throws for a harness with no reader. */
|
|
7
4
|
export declare function readerFor(harnessOrAlias: string): HarnessSessionReader;
|
|
8
|
-
/** The reader for a harness, or undefined when none exists. */
|
|
9
5
|
export declare function maybeReaderFor(harnessOrAlias: string): HarnessSessionReader | undefined;
|
|
10
|
-
/** The reader that owns a session format. */
|
|
11
6
|
export declare function readerForFormat(format: SessionFormatId): HarnessSessionReader;
|
package/dist/registry.js
CHANGED
|
@@ -3,36 +3,34 @@ import { codexReader } from './formats/codex.js';
|
|
|
3
3
|
import { kimiReader } from './formats/kimi.js';
|
|
4
4
|
import { factoryReader } from './formats/factory.js';
|
|
5
5
|
import { grokReader } from './formats/grok.js';
|
|
6
|
+
import { hermesReader } from './formats/hermes.js';
|
|
6
7
|
import { nanoclawReader } from './formats/nanoclaw.js';
|
|
8
|
+
import { openclawReader } from './formats/openclaw.js';
|
|
9
|
+
import { primeReader } from './formats/prime.js';
|
|
7
10
|
import { opencodeReader } from './formats/opencode.js';
|
|
8
11
|
import { piReader } from './formats/pi.js';
|
|
9
|
-
const READERS = [claudeCodeReader, codexReader, opencodeReader, piReader, kimiReader, factoryReader, grokReader, nanoclawReader];
|
|
12
|
+
const READERS = [claudeCodeReader, codexReader, opencodeReader, piReader, kimiReader, factoryReader, grokReader, nanoclawReader, hermesReader, primeReader, openclawReader];
|
|
10
13
|
const BY_NAME = new Map();
|
|
11
14
|
for (const reader of READERS) {
|
|
12
15
|
BY_NAME.set(reader.harness, reader);
|
|
13
16
|
for (const alias of reader.aliases)
|
|
14
17
|
BY_NAME.set(alias, reader);
|
|
15
18
|
}
|
|
16
|
-
/** Every reader this package ships. */
|
|
17
19
|
export function listReaders() {
|
|
18
20
|
return READERS;
|
|
19
21
|
}
|
|
20
|
-
/** Harness ids and aliases that resolve to a reader. */
|
|
21
22
|
export function knownHarnesses() {
|
|
22
23
|
return [...BY_NAME.keys()].sort();
|
|
23
24
|
}
|
|
24
|
-
/** The reader for a harness id or alias. Throws for a harness with no reader. */
|
|
25
25
|
export function readerFor(harnessOrAlias) {
|
|
26
26
|
const reader = BY_NAME.get(harnessOrAlias) ?? BY_NAME.get(harnessOrAlias.toLowerCase());
|
|
27
27
|
if (!reader)
|
|
28
28
|
throw new Error(`no session reader for harness "${harnessOrAlias}"; known: ${knownHarnesses().join(', ')}`);
|
|
29
29
|
return reader;
|
|
30
30
|
}
|
|
31
|
-
/** The reader for a harness, or undefined when none exists. */
|
|
32
31
|
export function maybeReaderFor(harnessOrAlias) {
|
|
33
32
|
return BY_NAME.get(harnessOrAlias) ?? BY_NAME.get(harnessOrAlias.toLowerCase());
|
|
34
33
|
}
|
|
35
|
-
/** The reader that owns a session format. */
|
|
36
34
|
export function readerForFormat(format) {
|
|
37
35
|
const reader = READERS.find((r) => r.formats.includes(format));
|
|
38
36
|
if (!reader)
|
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;
|
package/dist/source.js
CHANGED
|
@@ -23,7 +23,6 @@ export class SessionParseError extends Error {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
const NEWLINE = 0x0a;
|
|
26
|
-
/** 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. */
|
|
27
26
|
export async function* readJsonlRecords(path, stats, options = {}) {
|
|
28
27
|
const hash = createHash('sha256');
|
|
29
28
|
let pending = [];
|
|
@@ -109,19 +108,16 @@ export async function* readJsonlRecords(path, stats, options = {}) {
|
|
|
109
108
|
export function newSourceStats(path) {
|
|
110
109
|
return { path, sha256: '', bytes: 0, unparsed: 0, tornTail: false, line: 0 };
|
|
111
110
|
}
|
|
112
|
-
/** The records of a JSONL file, streamed. */
|
|
113
111
|
export function fileRecords(path, options = {}) {
|
|
114
112
|
const stats = newSourceStats(path);
|
|
115
113
|
return { stats, records: readJsonlRecords(path, stats, options) };
|
|
116
114
|
}
|
|
117
|
-
/** Stats for bytes already in memory. */
|
|
118
115
|
export function memoryStats(label, text) {
|
|
119
116
|
if (text === undefined)
|
|
120
117
|
return { path: label, sha256: '', bytes: 0, unparsed: 0, tornTail: false, line: 0 };
|
|
121
118
|
const bytes = Buffer.from(text, 'utf8');
|
|
122
119
|
return { path: label, sha256: `sha256:${createHash('sha256').update(bytes).digest('hex')}`, bytes: bytes.length, unparsed: 0, tornTail: false, line: 0 };
|
|
123
120
|
}
|
|
124
|
-
/** JSONL text already in memory. `firstLine` numbers its first line when the text continues a longer file. */
|
|
125
121
|
export function* textRecordsSync(text, stats, options = {}) {
|
|
126
122
|
const lines = text.split('\n');
|
|
127
123
|
const first = options.firstLine ?? 1;
|
|
@@ -154,7 +150,6 @@ export function* textRecordsSync(text, stats, options = {}) {
|
|
|
154
150
|
yield value;
|
|
155
151
|
}
|
|
156
152
|
}
|
|
157
|
-
/** Records a caller already parsed (one per line, in order, the first on line `firstLine`). Non-objects count as unparsed. */
|
|
158
153
|
export function* arrayRecordsSync(values, stats, firstLine = 1) {
|
|
159
154
|
for (const [position, value] of values.entries()) {
|
|
160
155
|
const index = firstLine - 1 + position;
|
|
@@ -166,8 +161,6 @@ export function* arrayRecordsSync(values, stats, firstLine = 1) {
|
|
|
166
161
|
yield value;
|
|
167
162
|
}
|
|
168
163
|
}
|
|
169
|
-
// `node:sqlite` is loaded through `createRequire`: bundlers rewrite a dynamic `import()` of a
|
|
170
|
-
// `node:` builtin under some targets, and a require obtained this way is not analyzable by them.
|
|
171
164
|
function loadSqlite() {
|
|
172
165
|
const nodeRequire = createRequire(import.meta.url);
|
|
173
166
|
return nodeRequire('node:sqlite');
|
|
@@ -183,15 +176,12 @@ async function exists(path) {
|
|
|
183
176
|
throw error;
|
|
184
177
|
}
|
|
185
178
|
}
|
|
186
|
-
/** Open a SQLite store read-only in place. A WAL uses `mode=ro` (committed tail, coordinates through `-shm`, never writes or checkpoints). No log uses `immutable=1` (no live connection, no new `-wal`/`-shm`). Throws when SQLite cannot read it there. */
|
|
187
179
|
async function openSqlite(path) {
|
|
188
180
|
const mode = (await exists(`${path}-wal`)) ? 'mode=ro' : 'immutable=1';
|
|
189
181
|
const { DatabaseSync } = loadSqlite();
|
|
190
|
-
// `readOnly` as well: a Node that treated the URI as a file name would fail to open, not create it.
|
|
191
182
|
const db = new DatabaseSync(`${pathToFileURL(path).href}?${mode}`, { readOnly: true });
|
|
192
183
|
try {
|
|
193
184
|
db.exec('PRAGMA busy_timeout = 5000');
|
|
194
|
-
// The first read opens the log and its index, so a store SQLite cannot read in place fails here.
|
|
195
185
|
db.prepare('PRAGMA schema_version').get();
|
|
196
186
|
return db;
|
|
197
187
|
}
|
|
@@ -200,15 +190,11 @@ async function openSqlite(path) {
|
|
|
200
190
|
throw error;
|
|
201
191
|
}
|
|
202
192
|
}
|
|
203
|
-
/** SQLite's primary result code `SQLITE_CANTOPEN`, which `node:sqlite` errors carry in `errcode`. */
|
|
204
193
|
function cannotOpen(error) {
|
|
205
194
|
const code = error?.errcode;
|
|
206
195
|
return typeof code === 'number' && (code & 0xff) === 14;
|
|
207
196
|
}
|
|
208
|
-
/** 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. */
|
|
209
197
|
export async function withSqlite(path, use) {
|
|
210
|
-
// SQLite follows a symlinked store to its target and keeps the log there, so the log is looked
|
|
211
|
-
// for there too. A missing store throws ENOENT here, which callers read as "no sessions".
|
|
212
198
|
const store = await realpath(path);
|
|
213
199
|
const db = await openSqlite(store).catch((error) => {
|
|
214
200
|
if (cannotOpen(error))
|
|
@@ -224,9 +210,6 @@ export async function withSqlite(path, use) {
|
|
|
224
210
|
db.close();
|
|
225
211
|
}
|
|
226
212
|
}
|
|
227
|
-
// One private copy is kept per process: reading every session of a store SQLite cannot open in
|
|
228
|
-
// place copies it once, not once per session. It is replaced when a different store, or a store
|
|
229
|
-
// that changed, is read, and removed when the process exits.
|
|
230
213
|
let current = null;
|
|
231
214
|
function dropCopy() {
|
|
232
215
|
if (current === null)
|
|
@@ -235,7 +218,6 @@ function dropCopy() {
|
|
|
235
218
|
current.db.close();
|
|
236
219
|
}
|
|
237
220
|
catch {
|
|
238
|
-
// already closed
|
|
239
221
|
}
|
|
240
222
|
rmSync(current.dir, { recursive: true, force: true });
|
|
241
223
|
current = null;
|
|
@@ -256,7 +238,6 @@ async function storeKey(path) {
|
|
|
256
238
|
}
|
|
257
239
|
return `${path}|${parts.join('|')}`;
|
|
258
240
|
}
|
|
259
|
-
/** Run `use` on a private copy of the store and its `-wal`/`-shm`, opened writable so SQLite replays the log. `use` is synchronous. */
|
|
260
241
|
async function withSqliteCopy(path, use) {
|
|
261
242
|
const key = await storeKey(path);
|
|
262
243
|
if (current?.key !== key) {
|
package/dist/stores.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
export { assertStoreRoot, CODEX_HOME_RULE, EVIDENCE, isCodexHome, SESSION_FORMAT_IDS, STORES, storeGlob, withinPath } from './catalog.js';
|
|
2
|
-
/** Regular files under `dir`; an optional matcher refuses selected unsafe entries before descent. */
|
|
3
2
|
export declare function walkFiles(dir: string, signal?: AbortSignal, matches?: (path: string) => boolean): Promise<string[]>;
|
|
4
|
-
/** Session files a locate reads at once: a store holds thousands, and each read waits on the disk. */
|
|
5
3
|
export declare const LOCATE_READS = 32;
|
|
6
|
-
/** `fn` over `items`, at most `limit` at a time, with the results in the order of `items`. */
|
|
7
4
|
export declare function mapLimit<T, R>(items: readonly T[], limit: number, fn: (item: T) => Promise<R>): Promise<R[]>;
|
|
8
5
|
export declare function mtimeMs(path: string): Promise<number>;
|
|
9
|
-
/** Every Codex home under `home`, by `CODEX_HOME_RULE`: `home` itself when it is one (a fleet seat's `codex` passed as a store root), `.codex` and each `.codex-<name>` in it, and each acct account home. `$CODEX_HOME` and `$ACCT_CONFIG` describe this process's own HOME, so they apply only when `home` is that HOME; another HOME (a store root, a capture) is read by its layout alone. Homes that resolve to one directory, such as an account home linked to `~/.codex`, count once. */
|
|
10
6
|
export declare function codexHomes(home: string): Promise<string[]>;
|
package/dist/stores.js
CHANGED
|
@@ -4,7 +4,6 @@ import { join, relative, resolve, sep } from 'node:path';
|
|
|
4
4
|
import { CODEX_HOME_RULE, isCodexHome } from './catalog.js';
|
|
5
5
|
import { isMissing } from './source.js';
|
|
6
6
|
export { assertStoreRoot, CODEX_HOME_RULE, EVIDENCE, isCodexHome, SESSION_FORMAT_IDS, STORES, storeGlob, withinPath } from './catalog.js';
|
|
7
|
-
/** Regular files under `dir`; an optional matcher refuses selected unsafe entries before descent. */
|
|
8
7
|
export async function walkFiles(dir, signal, matches) {
|
|
9
8
|
const out = [];
|
|
10
9
|
const visit = async (current) => {
|
|
@@ -33,9 +32,7 @@ export async function walkFiles(dir, signal, matches) {
|
|
|
33
32
|
await visit(dir);
|
|
34
33
|
return out.sort();
|
|
35
34
|
}
|
|
36
|
-
/** Session files a locate reads at once: a store holds thousands, and each read waits on the disk. */
|
|
37
35
|
export const LOCATE_READS = 32;
|
|
38
|
-
/** `fn` over `items`, at most `limit` at a time, with the results in the order of `items`. */
|
|
39
36
|
export async function mapLimit(items, limit, fn) {
|
|
40
37
|
const results = new Array(items.length);
|
|
41
38
|
let next = 0;
|
|
@@ -59,7 +56,6 @@ export async function mtimeMs(path) {
|
|
|
59
56
|
throw error;
|
|
60
57
|
}
|
|
61
58
|
}
|
|
62
|
-
/** Names of the directories (or links to them) directly in `dir`. A missing dir has none. */
|
|
63
59
|
async function childDirs(dir) {
|
|
64
60
|
try {
|
|
65
61
|
return (await readdir(dir, { withFileTypes: true })).filter((e) => e.isDirectory() || e.isSymbolicLink()).map((e) => e.name).sort();
|
|
@@ -70,7 +66,6 @@ async function childDirs(dir) {
|
|
|
70
66
|
throw error;
|
|
71
67
|
}
|
|
72
68
|
}
|
|
73
|
-
/** Every Codex home under `home`, by `CODEX_HOME_RULE`: `home` itself when it is one (a fleet seat's `codex` passed as a store root), `.codex` and each `.codex-<name>` in it, and each acct account home. `$CODEX_HOME` and `$ACCT_CONFIG` describe this process's own HOME, so they apply only when `home` is that HOME; another HOME (a store root, a capture) is read by its layout alone. Homes that resolve to one directory, such as an account home linked to `~/.codex`, count once. */
|
|
74
69
|
export async function codexHomes(home) {
|
|
75
70
|
const own = resolve(home) === resolve(process.env.HOME || homedir());
|
|
76
71
|
const candidates = isCodexHome(home) ? [home] : [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/harness-sessions",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "One reader for every coding-agent harness's native session (Claude Code, Codex, OpenCode, Pi): store layouts, a normalized session with messages, tool calls, served models, usage and ending errors, and projections to chat messages, OTLP spans and turns",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|