@tangle-network/harness-sessions 0.3.0 → 1.0.0
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/README.md +8 -3
- package/dist/capture.js +5 -3
- package/dist/catalog.d.ts +78 -61
- package/dist/catalog.js +28 -85
- package/dist/cli.js +1 -1
- package/dist/formats/kimi.js +111 -53
- package/dist/schema.d.ts +11 -6
- package/dist/source.js +42 -32
- package/dist/stores.d.ts +2 -5
- package/dist/stores.js +9 -11
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ npm install @tangle-network/harness-sessions
|
|
|
12
12
|
|
|
13
13
|
## Where this fits
|
|
14
14
|
|
|
15
|
-
- The sidecar's harness session contract (agent-container `packages/cli-agent-registry`)
|
|
15
|
+
- The catalog serves `STORES` and `SessionFormatId` for capture consumers. The sidecar's harness session contract (agent-container `packages/cli-agent-registry`) currently mirrors these declarations; its native-version adoption remains a separate consumer change.
|
|
16
16
|
- The capture path reads captures through `listCapture` / `readCapture`.
|
|
17
17
|
- Discovery's trace gate, agent-eval, agent-record and the blog read sessions only through this package.
|
|
18
18
|
- Its dependencies are `@tangle-network/agent-core`, `@tangle-network/agent-trace-contract` and Node built-ins (`node:sqlite` for OpenCode).
|
|
@@ -25,7 +25,7 @@ npm install @tangle-network/harness-sessions
|
|
|
25
25
|
| `codex` | `codex.rollout-jsonl` | `rollout-*-{id}.jsonl` under `sessions/` and `archived_sessions/` of every Codex home (below) | turn context (the configured model) | per response (`last_token_usage`); session total from `total_token_usage` |
|
|
26
26
|
| `opencode` | `opencode.sqlite` | `.local/share/opencode/opencode.db` (shared by every session) | session record (`providerID/modelID`) | per step (`step-finish`) |
|
|
27
27
|
| `pi` | `pi.session-jsonl` | `.pi/agent/sessions/**/*_{id}.jsonl` | session record (`provider/model`) | per assistant message |
|
|
28
|
-
| `kimi-code` | `kimi.session-dir` | `.kimi/sessions
|
|
28
|
+
| `kimi-code` | `kimi.session-dir` | `.kimi-code/sessions/wd_<hash>/{id}/agents/main/wire.jsonl`; retained `.kimi/sessions/*/{id}/wire.jsonl` and child wires | requested model recorded separately; served identity unknown | per step, excluding mirrored and wrapped child events |
|
|
29
29
|
| `factory-droids` | `factory.session-jsonl` | `.factory/sessions/*/{id}.jsonl` plus settings | configured model in settings (`turn-context`) | session total in settings |
|
|
30
30
|
|
|
31
31
|
A HOME can hold several Codex homes, and `codexReader.locate` reads all of them (`codexHomes(home)` lists them):
|
|
@@ -39,6 +39,10 @@ Homes that resolve to one directory count once. A session copied into several ho
|
|
|
39
39
|
|
|
40
40
|
`listReaders()` and the exported catalog own the complete installed format inventory.
|
|
41
41
|
|
|
42
|
+
Kimi uses the full `session_<uuid>` directory as its native ID, not the agent directory `main`. `kimiReader.stores` (also `KIMI_STORES` from the catalog entry) declares both layouts; the existing `STORES['kimi.session-dir']` remains the legacy declaration for consumers that still run that producer. A store's optional `globs` overrides the reader's default file globs, including when reading a v2 capture whose payload names are flat. No state or configuration sidecar is needed to read the current wire.
|
|
43
|
+
|
|
44
|
+
The current flat wire records prompts and loop steps alongside appended message snapshots, usage mirrors and a token-counting context summary. The fold takes prompt input and loop content/tools/step usage once; it preserves separately recorded injected user context. `llm.request` supplies `requestedModel`, without promoting configured or usage labels into served identity. Explicit native endings map completed to completed, cancelled/prompt-aborted to aborted, and failed/blocked to error; an assistant-looking prefix stays open. A later matching prompt ending preserves the turn's structured error. Unknown ending reasons stay open with an integrity gap. Recorded step counters of zero remain zero, while absent usage remains unknown. The retained fixture proves the completed and prefix cases; failure/abort mappings follow the official producer schema and await real failure captures. Nonzero accounting and new-format child-agent discovery remain unproved.
|
|
45
|
+
|
|
42
46
|
## Child execution evidence
|
|
43
47
|
|
|
44
48
|
Kimi records a child `agent_id` and `parent_tool_call_id` on each wrapped `SubagentEvent`, and writes the child's own wire under the parent's `subagents/<agent_id>/` directory. `kimiReader.locate(home, { nativeSessionId: parentId })` returns the parent and these child refs. A child-ID lookup selects that child. The reader keeps wrapped child events out of the parent's messages and usage; read each returned child ref for its own recorded work. `kimiRefForFile` preserves the same parent binding when a child wire is read directly. A missing child wire remains missing execution evidence, even when its ID appears in the parent.
|
|
@@ -82,10 +86,11 @@ harness-sessions read <file|home|capture> [--harness h] [--session id] [--summar
|
|
|
82
86
|
- A session with zero model calls is not the trace of a turn.
|
|
83
87
|
- `locate(home, { cwd })` keeps a session whose recorded cwd is `cwd` or lies under it on a path boundary (`withinPath`): `/w/agent` matches `/w/agent/sub`, never `/w/agent-dev-container`. Every store is resolved against the `home` given; only the Codex environment overrides above depend on the process.
|
|
84
88
|
- An unparsable record is counted in `integrity.unparsedRecords` and never stops a read (`corruption: 'strict'` throws instead). A record cut off at the end of a live copy is reported as a torn tail, not as corruption.
|
|
89
|
+
- Kimi discovery refuses a selected wire path that is a symlink, directory or special file; an unrelated native ID remains absent. JSONL reads recheck the opened descriptor as a regular file with `O_NOFOLLOW` and `O_NONBLOCK`, including after a located path is replaced. Platforms without these flags refuse the read. This protects the final file component, not ancestor-directory confinement; existing Codex home-directory aliases and SQLite's separate symlink policy remain unchanged. Kimi refs retain recorded context companion inventory.
|
|
85
90
|
- `ending.status` is `completed`, `error`, `aborted` or `open`. `open` means the records stop mid-turn: the turn was still running or the process died.
|
|
86
91
|
- An OpenCode store is opened read-only where it lies, with no copy: SQLite never writes the store or its write-ahead log. With a log present it reads the log's committed rows and keeps only its own shared-memory index (`-shm`) current; without one the store is opened immutable and nothing is created beside it. A store SQLite cannot open in place (a log with no `-shm` in a directory it cannot write, such as a capture on read-only storage, or any store under Node before 22.15, whose `node:sqlite` takes no URI file names) is read from a private copy. `integrity.sourceFiles` names the session as `<store>#session=<id>` with a digest of the rows read for it.
|
|
87
92
|
|
|
88
93
|
## Tests
|
|
89
94
|
|
|
90
|
-
The baseline fixtures are sessions that the real harness CLIs wrote while talking to the trace-proof scripted model; the tests assert that script. The Kimi child fixture retains complete existing parent and child wire records with all content removed, IDs pseudonymized, and source hashes, record counts, redaction version and token counters recorded in `test/fixtures/kimi/provenance.json`. Its integration test exercises discovery, full/summary reads, in-memory input and contract-span projection, preserving parent and child usage separately.
|
|
95
|
+
The baseline fixtures are sessions that the real harness CLIs wrote while talking to the trace-proof scripted model; the tests assert that script. The Kimi child fixture retains complete existing parent and child wire records with all content removed, IDs pseudonymized, and source hashes, record counts, redaction version and token counters recorded in `test/fixtures/kimi/provenance.json`. Its integration test exercises discovery, full/summary reads, in-memory input and contract-span projection, preserving parent and child usage separately. The current Kimi fixture in `test/fixtures/kimi2/` retains all 33 actual records through agent-eval's share pipeline and content minimization, with provenance alongside it. Its real-file integration covers both store layouts, direct-file CLI identity, v2 capture joins, projections, and incomplete prefixes without invoking a native harness or model.
|
|
91
96
|
The proof against the readers this package replaces is a comparison over stored sessions, recorded with each release.
|
package/dist/capture.js
CHANGED
|
@@ -47,7 +47,8 @@ async function fromV2(archiveDir, manifest, listing) {
|
|
|
47
47
|
listing.missing.push({ sandboxSessionId: null, harness: copy.harness, reason: 'no_reader_for_harness', nativeSessionId: copy.nativeSessionId });
|
|
48
48
|
continue;
|
|
49
49
|
}
|
|
50
|
-
const
|
|
50
|
+
const stores = reader.stores.filter((s) => s.format === copy.format);
|
|
51
|
+
const store = stores.find((s) => copy.files.some((f) => storePathOf(f).includes(`${s.root}/`))) ?? stores[0] ?? reader.stores[0];
|
|
51
52
|
const inStore = (path) => {
|
|
52
53
|
const marker = `${store.root}/`;
|
|
53
54
|
const index = path.indexOf(marker);
|
|
@@ -75,8 +76,9 @@ async function fromV2(archiveDir, manifest, listing) {
|
|
|
75
76
|
}
|
|
76
77
|
continue;
|
|
77
78
|
}
|
|
78
|
-
const
|
|
79
|
-
const
|
|
79
|
+
const globs = store.globs ?? reader.globs;
|
|
80
|
+
const main = storeGlob(globs.session, copy.nativeSessionId);
|
|
81
|
+
const nested = globs.children ? [storeGlob(globs.children, copy.nativeSessionId)] : [];
|
|
80
82
|
const mainFile = copy.files.find((f) => { const rel = inStore(storePathOf(f)); return rel !== null && main.test(rel); });
|
|
81
83
|
if (!mainFile) {
|
|
82
84
|
listing.missing.push({ sandboxSessionId: null, harness: copy.harness, reason: 'native_session_file_missing', nativeSessionId: copy.nativeSessionId });
|
package/dist/catalog.d.ts
CHANGED
|
@@ -2,94 +2,111 @@ export declare const SESSION_FORMAT_IDS: readonly ["claude-code.projects-jsonl",
|
|
|
2
2
|
/** Store layouts, relative to the HOME a harness ran with. */
|
|
3
3
|
export declare const STORES: {
|
|
4
4
|
readonly 'claude-code.projects-jsonl': {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
readonly
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
format: "claude-code.projects-jsonl";
|
|
6
|
+
root: string;
|
|
7
|
+
files: readonly ["*/{id}.jsonl", "*/{id}/subagents/**/*.jsonl"];
|
|
8
|
+
write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
|
|
9
|
+
shared: boolean;
|
|
10
10
|
};
|
|
11
11
|
readonly 'codex.rollout-jsonl': {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
readonly
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
format: "codex.rollout-jsonl";
|
|
13
|
+
root: string;
|
|
14
|
+
files: readonly ["*/*/*/rollout-*-{id}.jsonl"];
|
|
15
|
+
write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
|
|
16
|
+
shared: boolean;
|
|
17
17
|
};
|
|
18
18
|
readonly 'opencode.sqlite': {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
readonly
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
format: "opencode.sqlite";
|
|
20
|
+
root: string;
|
|
21
|
+
files: readonly ["opencode.db", "opencode.db-wal", "opencode.db-shm"];
|
|
22
|
+
write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
|
|
23
|
+
shared: boolean;
|
|
24
24
|
};
|
|
25
25
|
readonly 'pi.session-jsonl': {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
readonly
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
format: "pi.session-jsonl";
|
|
27
|
+
root: string;
|
|
28
|
+
files: readonly ["**/*_{id}.jsonl"];
|
|
29
|
+
write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
|
|
30
|
+
shared: boolean;
|
|
31
31
|
};
|
|
32
32
|
readonly 'kimi.session-dir': {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
readonly
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
format: "kimi.session-dir";
|
|
34
|
+
root: string;
|
|
35
|
+
files: readonly ["*/{id}/**", "*/{id}.jsonl"];
|
|
36
|
+
write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
|
|
37
|
+
shared: boolean;
|
|
38
38
|
};
|
|
39
39
|
readonly 'factory.session-jsonl': {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
readonly
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
format: "factory.session-jsonl";
|
|
41
|
+
root: string;
|
|
42
|
+
files: readonly ["*/{id}.jsonl", "*/{id}.settings.json"];
|
|
43
|
+
write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
|
|
44
|
+
shared: boolean;
|
|
45
45
|
};
|
|
46
46
|
readonly 'gemini.chat-json': {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
readonly
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
format: "gemini.chat-json";
|
|
48
|
+
root: string;
|
|
49
|
+
files: readonly ["*/chats/session-*{id}*.json"];
|
|
50
|
+
write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
|
|
51
|
+
shared: boolean;
|
|
52
52
|
};
|
|
53
53
|
readonly 'amp.thread-json': {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
readonly
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
format: "amp.thread-json";
|
|
55
|
+
root: string;
|
|
56
|
+
files: readonly ["{id}.json"];
|
|
57
|
+
write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
|
|
58
|
+
shared: boolean;
|
|
59
59
|
};
|
|
60
60
|
readonly 'forge.sqlite': {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
readonly
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
format: "forge.sqlite";
|
|
62
|
+
root: string;
|
|
63
|
+
files: readonly [".forge.db", ".forge.db-wal", ".forge.db-shm"];
|
|
64
|
+
write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
|
|
65
|
+
shared: boolean;
|
|
66
66
|
};
|
|
67
67
|
readonly 'hermes.state-sqlite': {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
readonly
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
format: "hermes.state-sqlite";
|
|
69
|
+
root: string;
|
|
70
|
+
files: readonly ["state.db", "state.db-wal", "state.db-shm"];
|
|
71
|
+
write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
|
|
72
|
+
shared: boolean;
|
|
73
73
|
};
|
|
74
74
|
readonly 'prime.session-jsonl': {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
readonly
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
format: "prime.session-jsonl";
|
|
76
|
+
root: string;
|
|
77
|
+
files: readonly ["**/*_{id}.jsonl"];
|
|
78
|
+
write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
|
|
79
|
+
shared: boolean;
|
|
80
80
|
};
|
|
81
81
|
readonly 'openclaw.session-jsonl': {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
readonly
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
format: "openclaw.session-jsonl";
|
|
83
|
+
root: string;
|
|
84
|
+
files: readonly ["**/{id}.jsonl"];
|
|
85
|
+
write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
|
|
86
|
+
shared: boolean;
|
|
87
87
|
};
|
|
88
88
|
};
|
|
89
|
+
/** Kimi Code's current and retained legacy layouts; the legacy catalog entry stays stable. */
|
|
90
|
+
export declare const KIMI_STORES: readonly [{
|
|
91
|
+
readonly root: ".kimi-code/sessions";
|
|
92
|
+
readonly files: readonly ["wd_*/{id}/**"];
|
|
93
|
+
readonly globs: {
|
|
94
|
+
readonly session: "wd_*/{id}/agents/main/wire.jsonl";
|
|
95
|
+
};
|
|
96
|
+
readonly format: "kimi.session-dir";
|
|
97
|
+
readonly write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
|
|
98
|
+
readonly shared: boolean;
|
|
99
|
+
}, {
|
|
100
|
+
format: "kimi.session-dir";
|
|
101
|
+
root: string;
|
|
102
|
+
files: readonly ["*/{id}/**", "*/{id}.jsonl"];
|
|
103
|
+
write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
|
|
104
|
+
shared: boolean;
|
|
105
|
+
}];
|
|
89
106
|
/**
|
|
90
107
|
* Where each format's served model, usage and ending error come from. `turn-context` means the
|
|
91
108
|
* model the harness was configured or asked for (Codex `turn_context`, OpenCode's message
|
|
92
|
-
* `modelID`, Factory's settings); `none` means
|
|
109
|
+
* `modelID`, Factory's settings); `none` means no served identity is proven by the records.
|
|
93
110
|
*/
|
|
94
111
|
export declare const EVIDENCE: {
|
|
95
112
|
readonly 'claude-code.projects-jsonl': {
|
package/dist/catalog.js
CHANGED
|
@@ -12,99 +12,42 @@ export const SESSION_FORMAT_IDS = [
|
|
|
12
12
|
'prime.session-jsonl',
|
|
13
13
|
'openclaw.session-jsonl',
|
|
14
14
|
];
|
|
15
|
+
/** One catalog declaration owns append-only defaults and shared SQLite copy semantics. */
|
|
16
|
+
function store(format, root, files, write = 'jsonl-append') {
|
|
17
|
+
return { format, root, files, write, shared: write === 'sqlite-wal' };
|
|
18
|
+
}
|
|
15
19
|
/** Store layouts, relative to the HOME a harness ran with. */
|
|
16
20
|
export const STORES = {
|
|
17
|
-
'claude-code.projects-jsonl':
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
'
|
|
25
|
-
root: '.codex/sessions',
|
|
26
|
-
files: ['*/*/*/rollout-*-{id}.jsonl'],
|
|
27
|
-
write: 'jsonl-append',
|
|
28
|
-
shared: false,
|
|
29
|
-
format: 'codex.rollout-jsonl',
|
|
30
|
-
},
|
|
31
|
-
'opencode.sqlite': {
|
|
32
|
-
root: '.local/share/opencode',
|
|
33
|
-
files: ['opencode.db', 'opencode.db-wal', 'opencode.db-shm'],
|
|
34
|
-
write: 'sqlite-wal',
|
|
35
|
-
shared: true,
|
|
36
|
-
format: 'opencode.sqlite',
|
|
37
|
-
},
|
|
38
|
-
'pi.session-jsonl': {
|
|
39
|
-
root: '.pi/agent/sessions',
|
|
40
|
-
files: ['**/*_{id}.jsonl'],
|
|
41
|
-
write: 'jsonl-append',
|
|
42
|
-
shared: false,
|
|
43
|
-
format: 'pi.session-jsonl',
|
|
44
|
-
},
|
|
21
|
+
'claude-code.projects-jsonl': store('claude-code.projects-jsonl', '.claude/projects', [
|
|
22
|
+
'*/{id}.jsonl', '*/{id}/subagents/**/*.jsonl',
|
|
23
|
+
]),
|
|
24
|
+
'codex.rollout-jsonl': store('codex.rollout-jsonl', '.codex/sessions', ['*/*/*/rollout-*-{id}.jsonl']),
|
|
25
|
+
'opencode.sqlite': store('opencode.sqlite', '.local/share/opencode', [
|
|
26
|
+
'opencode.db', 'opencode.db-wal', 'opencode.db-shm',
|
|
27
|
+
], 'sqlite-wal'),
|
|
28
|
+
'pi.session-jsonl': store('pi.session-jsonl', '.pi/agent/sessions', ['**/*_{id}.jsonl']),
|
|
45
29
|
// A session directory: wire.jsonl (the event stream read here), context.jsonl and its rotated
|
|
46
30
|
// context_N.jsonl copies, and state.json.
|
|
47
|
-
'kimi.session-dir': {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
'
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
write: 'jsonl-append',
|
|
58
|
-
shared: false,
|
|
59
|
-
format: 'factory.session-jsonl',
|
|
60
|
-
},
|
|
61
|
-
'gemini.chat-json': {
|
|
62
|
-
root: '.gemini/tmp',
|
|
63
|
-
files: ['*/chats/session-*{id}*.json'],
|
|
64
|
-
write: 'json-rewrite',
|
|
65
|
-
shared: false,
|
|
66
|
-
format: 'gemini.chat-json',
|
|
67
|
-
},
|
|
68
|
-
'amp.thread-json': {
|
|
69
|
-
root: '.local/share/amp/threads',
|
|
70
|
-
files: ['{id}.json'],
|
|
71
|
-
write: 'json-rewrite',
|
|
72
|
-
shared: false,
|
|
73
|
-
format: 'amp.thread-json',
|
|
74
|
-
},
|
|
75
|
-
'forge.sqlite': {
|
|
76
|
-
root: '.forge',
|
|
77
|
-
files: ['.forge.db', '.forge.db-wal', '.forge.db-shm'],
|
|
78
|
-
write: 'sqlite-wal',
|
|
79
|
-
shared: true,
|
|
80
|
-
format: 'forge.sqlite',
|
|
81
|
-
},
|
|
82
|
-
'hermes.state-sqlite': {
|
|
83
|
-
root: '.hermes',
|
|
84
|
-
files: ['state.db', 'state.db-wal', 'state.db-shm'],
|
|
85
|
-
write: 'sqlite-wal',
|
|
86
|
-
shared: true,
|
|
87
|
-
format: 'hermes.state-sqlite',
|
|
88
|
-
},
|
|
89
|
-
'prime.session-jsonl': {
|
|
90
|
-
root: '.prime-provider/prime-agent-dirs',
|
|
91
|
-
files: ['**/*_{id}.jsonl'],
|
|
92
|
-
write: 'jsonl-append',
|
|
93
|
-
shared: false,
|
|
94
|
-
format: 'prime.session-jsonl',
|
|
95
|
-
},
|
|
96
|
-
'openclaw.session-jsonl': {
|
|
97
|
-
root: '.openclaw/agents',
|
|
98
|
-
files: ['**/{id}.jsonl'],
|
|
99
|
-
write: 'jsonl-append',
|
|
100
|
-
shared: false,
|
|
101
|
-
format: 'openclaw.session-jsonl',
|
|
102
|
-
},
|
|
31
|
+
'kimi.session-dir': store('kimi.session-dir', '.kimi/sessions', ['*/{id}/**', '*/{id}.jsonl']),
|
|
32
|
+
'factory.session-jsonl': store('factory.session-jsonl', '.factory/sessions', [
|
|
33
|
+
'*/{id}.jsonl', '*/{id}.settings.json',
|
|
34
|
+
]),
|
|
35
|
+
'gemini.chat-json': store('gemini.chat-json', '.gemini/tmp', ['*/chats/session-*{id}*.json'], 'json-rewrite'),
|
|
36
|
+
'amp.thread-json': store('amp.thread-json', '.local/share/amp/threads', ['{id}.json'], 'json-rewrite'),
|
|
37
|
+
'forge.sqlite': store('forge.sqlite', '.forge', ['.forge.db', '.forge.db-wal', '.forge.db-shm'], 'sqlite-wal'),
|
|
38
|
+
'hermes.state-sqlite': store('hermes.state-sqlite', '.hermes', ['state.db', 'state.db-wal', 'state.db-shm'], 'sqlite-wal'),
|
|
39
|
+
'prime.session-jsonl': store('prime.session-jsonl', '.prime-provider/prime-agent-dirs', ['**/*_{id}.jsonl']),
|
|
40
|
+
'openclaw.session-jsonl': store('openclaw.session-jsonl', '.openclaw/agents', ['**/{id}.jsonl']),
|
|
103
41
|
};
|
|
42
|
+
/** Kimi Code's current and retained legacy layouts; the legacy catalog entry stays stable. */
|
|
43
|
+
export const KIMI_STORES = [
|
|
44
|
+
{ ...STORES['kimi.session-dir'], root: '.kimi-code/sessions', files: ['wd_*/{id}/**'], globs: { session: 'wd_*/{id}/agents/main/wire.jsonl' } },
|
|
45
|
+
STORES['kimi.session-dir'],
|
|
46
|
+
];
|
|
104
47
|
/**
|
|
105
48
|
* Where each format's served model, usage and ending error come from. `turn-context` means the
|
|
106
49
|
* model the harness was configured or asked for (Codex `turn_context`, OpenCode's message
|
|
107
|
-
* `modelID`, Factory's settings); `none` means
|
|
50
|
+
* `modelID`, Factory's settings); `none` means no served identity is proven by the records.
|
|
108
51
|
*/
|
|
109
52
|
export const EVIDENCE = {
|
|
110
53
|
'claude-code.projects-jsonl': { servedModel: 'provider-response', usage: 'per-response', endingError: 'session-record' },
|
package/dist/cli.js
CHANGED
|
@@ -38,7 +38,7 @@ function harnessOfFile(path) {
|
|
|
38
38
|
return 'codex';
|
|
39
39
|
if (/(^|\/)\.pi\/agent\/sessions\//u.test(path))
|
|
40
40
|
return 'pi';
|
|
41
|
-
if (/(^|\/)\.kimi
|
|
41
|
+
if (/(^|\/)\.kimi(?:-code)?\/sessions\/.+\/wire\.jsonl$/u.test(path))
|
|
42
42
|
return 'kimi-code';
|
|
43
43
|
if (/(^|\/)\.factory\/sessions\//u.test(path))
|
|
44
44
|
return 'factory-droids';
|
package/dist/formats/kimi.js
CHANGED
|
@@ -9,50 +9,58 @@ import { isRecord } from '@tangle-network/agent-core';
|
|
|
9
9
|
* (`token_usage`: `input_other`, `output`, `input_cache_read`, `input_cache_creation`, disjoint,
|
|
10
10
|
* and the provider's `message_id`) follow. `ToolResult` answers a call. `StepRetry` is a failed
|
|
11
11
|
* attempt with the provider's status code; `StepInterrupted` ends a step without an answer. A
|
|
12
|
-
* subagent's events arrive wrapped in `SubagentEvent`. The wire records no model.
|
|
12
|
+
* subagent's events arrive wrapped in `SubagentEvent`. The legacy wire records no model.
|
|
13
|
+
* Current `.kimi-code/sessions/wd_<hash>/session_<uuid>/agents/main/wire.jsonl` records are flat:
|
|
14
|
+
* turn prompts and loop events own messages, tools and step usage. Appended message snapshots,
|
|
15
|
+
* usage records and token-counting totals mirror that work, so are not counted again. Request
|
|
16
|
+
* metadata names the requested model; a completed native turn is required to prove completion.
|
|
13
17
|
*/
|
|
14
18
|
import { basename, dirname, join } from 'node:path';
|
|
15
19
|
import { SessionBuilder, count, sessionError, str, textOf, usageOrNull } from '../builder.js';
|
|
16
20
|
import { fileRecords } from '../source.js';
|
|
17
|
-
import {
|
|
21
|
+
import { KIMI_STORES } from '../catalog.js';
|
|
22
|
+
import { EVIDENCE, mtimeMs, storeGlob, walkFiles, withinPath } from '../stores.js';
|
|
18
23
|
import { runFold } from './fold.js';
|
|
19
24
|
const FORMAT = 'kimi.session-dir';
|
|
20
|
-
const STORE = STORES[FORMAT];
|
|
21
25
|
const HARNESS = 'kimi-code';
|
|
22
26
|
/** The event stream this reader folds; the store also holds context.jsonl and state.json. */
|
|
23
27
|
const WIRE = '*/{id}/wire.jsonl';
|
|
24
28
|
const CHILD_WIRE = '*/*/subagents/{id}/wire.jsonl';
|
|
25
|
-
/**
|
|
29
|
+
/** Current main agents belong to session_<uuid>; legacy child wires retain their own agent IDs. */
|
|
26
30
|
function sessionIdentity(path) {
|
|
27
31
|
const directory = dirname(path);
|
|
28
32
|
const container = dirname(directory);
|
|
33
|
+
if (basename(container) === 'agents' && basename(directory) === 'main')
|
|
34
|
+
return { id: basename(dirname(container)), parent: null };
|
|
29
35
|
return { id: basename(directory), parent: basename(container) === 'subagents' ? basename(dirname(container)) : null };
|
|
30
36
|
}
|
|
31
37
|
function usageOf(value) {
|
|
32
38
|
if (!isRecord(value))
|
|
33
39
|
return null;
|
|
34
40
|
return usageOrNull({
|
|
35
|
-
input: count(value.input_other),
|
|
41
|
+
input: count(value.input_other ?? value.inputOther),
|
|
36
42
|
output: count(value.output),
|
|
37
43
|
reasoning: null,
|
|
38
|
-
cacheRead: count(value.input_cache_read),
|
|
39
|
-
cacheWrite: count(value.input_cache_creation),
|
|
44
|
+
cacheRead: count(value.input_cache_read ?? value.inputCacheRead),
|
|
45
|
+
cacheWrite: count(value.input_cache_creation ?? value.inputCacheCreation),
|
|
40
46
|
});
|
|
41
47
|
}
|
|
42
48
|
export function createFold(ref, mode, stats) {
|
|
43
49
|
const builder = new SessionBuilder(HARNESS, FORMAT, EVIDENCE[FORMAT].servedModel, mode, ref.nativeSessionId, ref.parentNativeSessionId);
|
|
44
50
|
let turn = 0;
|
|
45
|
-
let calls = 0;
|
|
46
51
|
let step = null;
|
|
47
52
|
let lastToolCall = null;
|
|
48
53
|
let aborted = null;
|
|
49
54
|
let compactions = 0;
|
|
50
55
|
let subagentEvents = 0;
|
|
56
|
+
let flat = false;
|
|
57
|
+
let promptId = null;
|
|
58
|
+
let nativeEnding = { status: 'open', error: null, at: null };
|
|
59
|
+
let nativeReason = null;
|
|
51
60
|
const openStep = (at) => {
|
|
52
61
|
if (step)
|
|
53
62
|
return step;
|
|
54
|
-
|
|
55
|
-
const id = `${builder.nativeSessionId}:turn:${turn}:step:${calls}`;
|
|
63
|
+
const id = `${builder.nativeSessionId}:turn:${turn}:step:${builder.modelCalls.length + 1}`;
|
|
56
64
|
const call = builder.modelCall({ id, at, provider: null, servedModel: null, requestedModel: null, usage: null, costUsd: null, stopReason: null, error: null });
|
|
57
65
|
builder.message({ id: `${id}:message`, role: 'assistant', actor: 'agent', at, modelCallId: id, parts: [] });
|
|
58
66
|
step = { call, messageId: `${id}:message` };
|
|
@@ -64,42 +72,68 @@ export function createFold(ref, mode, stats) {
|
|
|
64
72
|
lastToolCall = null;
|
|
65
73
|
};
|
|
66
74
|
const observe = (record) => {
|
|
67
|
-
const message = isRecord(record.message) ? record.message :
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const payload = isRecord(message.payload) ? message.payload : {};
|
|
72
|
-
const
|
|
75
|
+
const message = isRecord(record.message) ? record.message : {};
|
|
76
|
+
const outer = str(record.type);
|
|
77
|
+
// Both protocols have metadata; only flat payload events use namespaced discriminators.
|
|
78
|
+
flat ||= outer?.includes('.') === true;
|
|
79
|
+
const payload = outer === 'context.append_loop_event' && isRecord(record.event) ? record.event : outer ? record : isRecord(message.payload) ? message.payload : {};
|
|
80
|
+
const type = outer === 'context.append_loop_event' ? str(payload.type) : outer ?? str(message.type);
|
|
81
|
+
const at = builder.seen(record.time ?? record.timestamp ?? record.created_at);
|
|
73
82
|
if (type !== 'ToolCallPart')
|
|
74
83
|
flushToolArguments();
|
|
75
84
|
switch (type) {
|
|
85
|
+
case 'profile.bind':
|
|
86
|
+
if (isRecord(payload.environmentDisclosure))
|
|
87
|
+
builder.cwd = str(payload.environmentDisclosure.cwd);
|
|
88
|
+
break;
|
|
89
|
+
case 'turn.prompt':
|
|
76
90
|
case 'TurnBegin': {
|
|
77
91
|
turn += 1;
|
|
78
92
|
step = null;
|
|
79
93
|
aborted = null;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
94
|
+
promptId = str(payload.promptId);
|
|
95
|
+
nativeEnding = { status: 'open', error: null, at: null };
|
|
96
|
+
nativeReason = null;
|
|
97
|
+
const text = textOf(payload.user_input ?? payload.input);
|
|
98
|
+
const parts = text === null ? [] : [{ type: 'text', text }];
|
|
84
99
|
builder.message({ id: `${builder.nativeSessionId}:turn:${turn}:input`, role: 'user', actor: ref.parentNativeSessionId ? 'subagent-spawn' : 'human', at, modelCallId: null, parts });
|
|
85
100
|
break;
|
|
86
101
|
}
|
|
102
|
+
case 'context.append_message': {
|
|
103
|
+
const value = isRecord(payload.message) ? payload.message : {};
|
|
104
|
+
if (value.role !== 'user' || (promptId !== null && value.id === promptId))
|
|
105
|
+
break;
|
|
106
|
+
const origin = isRecord(value.origin) ? value.origin : {};
|
|
107
|
+
const text = textOf(value.content);
|
|
108
|
+
builder.message({ id: str(value.id) ?? `${builder.nativeSessionId}:context:${stats.line}`, role: 'user', actor: origin.kind === 'user' ? 'human' : 'injected', at, modelCallId: null, parts: text === null ? [] : [{ type: 'text', text }] });
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case 'llm.request': {
|
|
112
|
+
const current = openStep(at);
|
|
113
|
+
current.call.requestedModel = str(payload.model);
|
|
114
|
+
current.call.provider = str(payload.provider);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
case 'step.begin':
|
|
87
118
|
case 'StepBegin':
|
|
88
119
|
step = null;
|
|
89
120
|
openStep(at);
|
|
90
121
|
break;
|
|
122
|
+
case 'content.part':
|
|
91
123
|
case 'ContentPart': {
|
|
92
124
|
const current = openStep(at);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
125
|
+
const part = isRecord(payload.part) ? payload.part : payload;
|
|
126
|
+
if (part.type === 'think')
|
|
127
|
+
builder.appendParts(current.messageId, [{ type: 'reasoning', text: str(part.think) ?? '', redacted: part.encrypted != null && !part.think }]);
|
|
128
|
+
else if (typeof part.text === 'string')
|
|
129
|
+
builder.appendParts(current.messageId, [{ type: 'text', text: part.text }]);
|
|
97
130
|
break;
|
|
98
131
|
}
|
|
132
|
+
case 'tool.call':
|
|
99
133
|
case 'ToolCall': {
|
|
100
134
|
const current = openStep(at);
|
|
101
|
-
const fn = isRecord(payload.function) ? payload.function : {};
|
|
102
|
-
const id = str(payload.id) ?? `${builder.nativeSessionId}:call:${stats.line}`;
|
|
135
|
+
const fn = isRecord(payload.function) ? payload.function : { name: payload.name, arguments: payload.args };
|
|
136
|
+
const id = str(payload.id) ?? str(payload.toolCallId) ?? `${builder.nativeSessionId}:call:${stats.line}`;
|
|
103
137
|
const text = typeof fn.arguments === 'string' ? fn.arguments : JSON.stringify(fn.arguments ?? {});
|
|
104
138
|
builder.appendParts(current.messageId, [{ type: 'tool-call', toolCallId: id }]);
|
|
105
139
|
builder.toolCall({ id, name: str(fn.name) ?? 'unknown', input: null, inputText: text, at, messageId: current.messageId });
|
|
@@ -110,27 +144,30 @@ export function createFold(ref, mode, stats) {
|
|
|
110
144
|
if (lastToolCall && typeof payload.arguments_part === 'string')
|
|
111
145
|
lastToolCall.text += payload.arguments_part;
|
|
112
146
|
break;
|
|
147
|
+
case 'tool.result':
|
|
113
148
|
case 'ToolResult': {
|
|
114
|
-
const id = str(payload.tool_call_id) ?? '';
|
|
115
|
-
const value = isRecord(payload.return_value) ? payload.return_value : {};
|
|
149
|
+
const id = str(payload.tool_call_id) ?? str(payload.toolCallId) ?? '';
|
|
150
|
+
const value = isRecord(payload.return_value) ? payload.return_value : isRecord(payload.result) ? payload.result : {};
|
|
116
151
|
const resultId = `${id}:result`;
|
|
117
152
|
builder.message({ id: resultId, role: 'tool', actor: 'tool-result', at, modelCallId: null, parts: [{ type: 'tool-result', toolCallId: id }] });
|
|
118
153
|
builder.toolResult(id, { output: value.output ?? null, text: typeof value.output === 'string' ? value.output : textOf(value.output), isError: value.is_error === true, at, messageId: resultId, details: value });
|
|
119
154
|
break;
|
|
120
155
|
}
|
|
156
|
+
case 'step.end':
|
|
121
157
|
case 'StatusUpdate': {
|
|
122
|
-
const usage = usageOf(payload.token_usage);
|
|
158
|
+
const usage = usageOf(payload.token_usage ?? payload.usage);
|
|
123
159
|
if (usage === null)
|
|
124
160
|
break;
|
|
125
161
|
const current = openStep(at);
|
|
126
162
|
current.call.usage = usage;
|
|
163
|
+
if (type === 'step.end')
|
|
164
|
+
current.call.stopReason = str(payload.finishReason);
|
|
127
165
|
break;
|
|
128
166
|
}
|
|
129
167
|
case 'StepRetry': {
|
|
130
168
|
// A failed attempt Kimi retried: a model call that returned no answer.
|
|
131
|
-
calls += 1;
|
|
132
169
|
builder.modelCall({
|
|
133
|
-
id: `${builder.nativeSessionId}:turn:${turn}:retry:${
|
|
170
|
+
id: `${builder.nativeSessionId}:turn:${turn}:retry:${builder.modelCalls.length + 1}`, at, provider: null, servedModel: null, requestedModel: null, usage: null, costUsd: null, stopReason: null,
|
|
134
171
|
error: sessionError(str(payload.error_type) ?? 'retry', `${str(payload.error_type) ?? 'error'}${payload.status_code ? ` (status ${String(payload.status_code)})` : ''}`, at, count(payload.status_code)),
|
|
135
172
|
});
|
|
136
173
|
break;
|
|
@@ -142,6 +179,19 @@ export function createFold(ref, mode, stats) {
|
|
|
142
179
|
case 'TurnEnd':
|
|
143
180
|
step = null;
|
|
144
181
|
break;
|
|
182
|
+
case 'turn.ended':
|
|
183
|
+
case 'prompt.completed':
|
|
184
|
+
case 'prompt.aborted': {
|
|
185
|
+
const reason = type === 'prompt.aborted' ? 'cancelled' : str(payload.reason);
|
|
186
|
+
const status = reason === 'completed' ? 'completed' : reason === 'cancelled' ? 'aborted' : reason === 'failed' || reason === 'blocked' ? 'error' : 'open';
|
|
187
|
+
const endedAt = builder.seen(payload.abortedAt ?? payload.finishedAt) ?? at;
|
|
188
|
+
const error = isRecord(payload.error) && typeof payload.error.code === 'string' && typeof payload.error.message === 'string' ? { kind: payload.error.code, message: payload.error.message, httpStatus: null, at: endedAt } : reason === nativeReason ? nativeEnding.error : null;
|
|
189
|
+
nativeEnding = { status, error, at: status === 'open' ? null : endedAt };
|
|
190
|
+
nativeReason = reason;
|
|
191
|
+
if (status === 'open')
|
|
192
|
+
builder.gap('Native ending reason is unknown');
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
145
195
|
case 'CompactionBegin':
|
|
146
196
|
compactions += 1;
|
|
147
197
|
break;
|
|
@@ -159,11 +209,16 @@ export function createFold(ref, mode, stats) {
|
|
|
159
209
|
const finish = () => {
|
|
160
210
|
flushToolArguments();
|
|
161
211
|
builder.source(stats);
|
|
212
|
+
if (ref.truncated)
|
|
213
|
+
builder.markTruncated(`${ref.path}: the session copy was cut short`);
|
|
162
214
|
if (compactions > 0)
|
|
163
215
|
builder.gap(`${compactions} compactions replaced earlier context`);
|
|
164
216
|
if (subagentEvents > 0)
|
|
165
217
|
builder.gap(`${subagentEvents} wrapped subagent events were excluded from this session's own messages and usage; separate child wires must be read for child execution`);
|
|
166
|
-
|
|
218
|
+
if (flat)
|
|
219
|
+
builder.end(nativeEnding);
|
|
220
|
+
else
|
|
221
|
+
builder.inferEnding(aborted ? { at: aborted.at, error: null } : undefined);
|
|
167
222
|
return builder;
|
|
168
223
|
};
|
|
169
224
|
return { builder, observe, finish };
|
|
@@ -172,27 +227,30 @@ export async function fold(ref, mode, options, source = fileRecords(ref.path, {
|
|
|
172
227
|
return runFold(createFold(ref, mode, source.stats), source);
|
|
173
228
|
}
|
|
174
229
|
async function locate(home, opts) {
|
|
175
|
-
const root = join(home, STORE.root);
|
|
176
|
-
const pattern = storeGlob(WIRE);
|
|
177
|
-
const children = storeGlob(CHILD_WIRE);
|
|
178
230
|
const refs = [];
|
|
179
|
-
for (const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
231
|
+
for (const store of KIMI_STORES) {
|
|
232
|
+
const root = join(home, store.root);
|
|
233
|
+
const pattern = storeGlob('globs' in store ? store.globs.session : WIRE);
|
|
234
|
+
const children = storeGlob(CHILD_WIRE);
|
|
235
|
+
const matches = (rel) => {
|
|
236
|
+
const { id, parent } = sessionIdentity(rel);
|
|
237
|
+
return (pattern.test(rel) || children.test(rel)) && (!opts.nativeSessionId || id === opts.nativeSessionId || parent === opts.nativeSessionId);
|
|
238
|
+
};
|
|
239
|
+
for (const rel of await walkFiles(root, undefined, matches)) {
|
|
240
|
+
const path = join(root, rel);
|
|
241
|
+
const mtime = await mtimeMs(path);
|
|
242
|
+
if (opts.sinceMs && mtime < opts.sinceMs)
|
|
243
|
+
continue;
|
|
244
|
+
const context = join(dirname(path), 'context.jsonl');
|
|
245
|
+
const files = (await mtimeMs(context)) > 0 ? [path, context] : [path];
|
|
246
|
+
const ref = { ...kimiRefForFile(path), files, home, mtimeMs: mtime };
|
|
247
|
+
if (opts.cwd) {
|
|
248
|
+
ref.cwd = (await fold(ref, 'summary', {})).cwd;
|
|
249
|
+
if (ref.cwd === null || !withinPath(ref.cwd, opts.cwd))
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
refs.push(ref);
|
|
253
|
+
}
|
|
196
254
|
}
|
|
197
255
|
return refs.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
198
256
|
}
|
|
@@ -200,7 +258,7 @@ export const kimiReader = {
|
|
|
200
258
|
harness: HARNESS,
|
|
201
259
|
aliases: ['kimi', 'kimi-cli'],
|
|
202
260
|
formats: [FORMAT],
|
|
203
|
-
stores:
|
|
261
|
+
stores: KIMI_STORES,
|
|
204
262
|
globs: { session: WIRE, children: CHILD_WIRE },
|
|
205
263
|
evidence: EVIDENCE[FORMAT],
|
|
206
264
|
locate: (home, opts = {}) => locate(home, opts),
|
package/dist/schema.d.ts
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
* blog.
|
|
9
9
|
*/
|
|
10
10
|
/** One native session format. The id names the harness family and the on-disk layout. */
|
|
11
|
-
export type SessionFormatId =
|
|
11
|
+
export type SessionFormatId = (typeof import('./catalog.js').SESSION_FORMAT_IDS)[number];
|
|
12
12
|
/**
|
|
13
|
-
* Where a harness keeps its sessions, relative to the HOME it ran with.
|
|
14
|
-
*
|
|
13
|
+
* Where a harness keeps its sessions, relative to the HOME it ran with. Capture consumers can
|
|
14
|
+
* share these declarations; consumer adoption of a producer layout is a separate change.
|
|
15
15
|
*/
|
|
16
16
|
export interface NativeSessionStore {
|
|
17
17
|
/** Relative to the execution's private runtime HOME. Normalized, never absolute, never `..`. */
|
|
@@ -23,10 +23,15 @@ export interface NativeSessionStore {
|
|
|
23
23
|
/** True when one store holds every session in the HOME (opencode.db). Readers select by id. */
|
|
24
24
|
shared: boolean;
|
|
25
25
|
format: SessionFormatId;
|
|
26
|
+
/** Reader files when this layout differs from the harness's default globs. */
|
|
27
|
+
globs?: {
|
|
28
|
+
session: string;
|
|
29
|
+
children?: string;
|
|
30
|
+
};
|
|
26
31
|
}
|
|
27
32
|
/** Where a format's served-model, usage and ending-error evidence comes from. */
|
|
28
33
|
export interface SessionEvidenceSources {
|
|
29
|
-
/** `none`:
|
|
34
|
+
/** `none`: no proven served identity (including Kimi request labels); served models stay empty. */
|
|
30
35
|
servedModel: 'provider-response' | 'session-record' | 'turn-context' | 'none';
|
|
31
36
|
usage: 'per-response' | 'cumulative' | 'session-total';
|
|
32
37
|
endingError: 'session-record' | 'none';
|
|
@@ -217,8 +222,8 @@ export interface HarnessSessionReader {
|
|
|
217
222
|
formats: readonly SessionFormatId[];
|
|
218
223
|
stores: readonly NativeSessionStore[];
|
|
219
224
|
/**
|
|
220
|
-
*
|
|
221
|
-
* harness
|
|
225
|
+
* Default globs under each store's root, unless that store supplies its own globs: the session
|
|
226
|
+
* file and, when the harness writes subagent transcripts separately, those files.
|
|
222
227
|
*/
|
|
223
228
|
globs: {
|
|
224
229
|
session: string;
|
package/dist/source.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import {
|
|
3
|
-
import { copyFile, mkdtemp, realpath, stat } from 'node:fs/promises';
|
|
2
|
+
import { constants, rmSync } from 'node:fs';
|
|
3
|
+
import { copyFile, mkdtemp, open, realpath, stat } from 'node:fs/promises';
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
5
|
import { tmpdir } from 'node:os';
|
|
6
6
|
import { join } from 'node:path';
|
|
@@ -61,45 +61,55 @@ export async function* readJsonlRecords(path, stats, options = {}) {
|
|
|
61
61
|
}
|
|
62
62
|
return value;
|
|
63
63
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
64
|
+
if (typeof constants.O_NOFOLLOW !== 'number' || typeof constants.O_NONBLOCK !== 'number')
|
|
65
|
+
throw new Error('Safe native JSONL reads require O_NOFOLLOW and O_NONBLOCK');
|
|
66
|
+
const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
67
|
+
try {
|
|
68
|
+
if (!(await file.stat()).isFile())
|
|
69
|
+
throw new Error(`${path}: native session must be a regular file`);
|
|
70
|
+
const stream = file.createReadStream({ highWaterMark: 1 << 20, signal: options.signal, autoClose: false });
|
|
71
|
+
for await (const chunk of stream) {
|
|
72
|
+
hash.update(chunk);
|
|
73
|
+
stats.bytes += chunk.length;
|
|
74
|
+
let start = 0;
|
|
75
|
+
for (;;) {
|
|
76
|
+
const index = chunk.indexOf(NEWLINE, start);
|
|
77
|
+
if (index === -1)
|
|
78
|
+
break;
|
|
79
|
+
let line;
|
|
80
|
+
if (pendingBytes > 0) {
|
|
81
|
+
pending.push(chunk.subarray(start, index));
|
|
82
|
+
line = Buffer.concat(pending);
|
|
83
|
+
pending = [];
|
|
84
|
+
pendingBytes = 0;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
line = chunk.subarray(start, index);
|
|
88
|
+
}
|
|
89
|
+
const record = parse(line, true);
|
|
90
|
+
if (record !== undefined) {
|
|
91
|
+
stats.line = lineNumber;
|
|
92
|
+
yield record;
|
|
93
|
+
}
|
|
94
|
+
start = index + 1;
|
|
79
95
|
}
|
|
80
|
-
|
|
81
|
-
|
|
96
|
+
if (start < chunk.length) {
|
|
97
|
+
pending.push(chunk.subarray(start));
|
|
98
|
+
pendingBytes += chunk.length - start;
|
|
82
99
|
}
|
|
83
|
-
|
|
100
|
+
}
|
|
101
|
+
if (pendingBytes > 0) {
|
|
102
|
+
const record = parse(Buffer.concat(pending), false);
|
|
84
103
|
if (record !== undefined) {
|
|
85
104
|
stats.line = lineNumber;
|
|
86
105
|
yield record;
|
|
87
106
|
}
|
|
88
|
-
start = index + 1;
|
|
89
|
-
}
|
|
90
|
-
if (start < chunk.length) {
|
|
91
|
-
pending.push(chunk.subarray(start));
|
|
92
|
-
pendingBytes += chunk.length - start;
|
|
93
107
|
}
|
|
108
|
+
stats.sha256 = `sha256:${hash.digest('hex')}`;
|
|
94
109
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (record !== undefined) {
|
|
98
|
-
stats.line = lineNumber;
|
|
99
|
-
yield record;
|
|
100
|
-
}
|
|
110
|
+
finally {
|
|
111
|
+
await file.close();
|
|
101
112
|
}
|
|
102
|
-
stats.sha256 = `sha256:${hash.digest('hex')}`;
|
|
103
113
|
}
|
|
104
114
|
export function newSourceStats(path) {
|
|
105
115
|
return { path, sha256: '', bytes: 0, unparsed: 0, tornTail: false, line: 0 };
|
package/dist/stores.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import type { NativeSessionStore } from './schema.js';
|
|
2
1
|
export { assertStoreRoot, CODEX_HOME_RULE, EVIDENCE, isCodexHome, SESSION_FORMAT_IDS, STORES, storeGlob, withinPath } from './catalog.js';
|
|
3
|
-
/**
|
|
4
|
-
export declare function walkFiles(dir: string, signal?: AbortSignal): Promise<string[]>;
|
|
2
|
+
/** Regular files under `dir`; an optional matcher refuses selected unsafe entries before descent. */
|
|
3
|
+
export declare function walkFiles(dir: string, signal?: AbortSignal, matches?: (path: string) => boolean): Promise<string[]>;
|
|
5
4
|
/** Session files a locate reads at once: a store holds thousands, and each read waits on the disk. */
|
|
6
5
|
export declare const LOCATE_READS = 32;
|
|
7
6
|
/** `fn` over `items`, at most `limit` at a time, with the results in the order of `items`. */
|
|
8
7
|
export declare function mapLimit<T, R>(items: readonly T[], limit: number, fn: (item: T) => Promise<R>): Promise<R[]>;
|
|
9
|
-
/** Files under `home` that one store glob matches, as absolute paths. */
|
|
10
|
-
export declare function storeFiles(home: string, store: NativeSessionStore, glob: string, nativeSessionId?: string): Promise<string[]>;
|
|
11
8
|
export declare function mtimeMs(path: string): Promise<number>;
|
|
12
9
|
/**
|
|
13
10
|
* Every Codex home under `home`, by `CODEX_HOME_RULE`: `home` itself when it is one (a fleet seat's
|
package/dist/stores.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { readdir, realpath, stat } from 'node:fs/promises';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { join, relative, resolve, sep } from 'node:path';
|
|
4
|
-
import { CODEX_HOME_RULE, isCodexHome
|
|
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
|
-
/**
|
|
8
|
-
export async function walkFiles(dir, signal) {
|
|
7
|
+
/** Regular files under `dir`; an optional matcher refuses selected unsafe entries before descent. */
|
|
8
|
+
export async function walkFiles(dir, signal, matches) {
|
|
9
9
|
const out = [];
|
|
10
10
|
const visit = async (current) => {
|
|
11
11
|
signal?.throwIfAborted();
|
|
@@ -20,10 +20,14 @@ export async function walkFiles(dir, signal) {
|
|
|
20
20
|
}
|
|
21
21
|
for (const entry of entries) {
|
|
22
22
|
const path = join(current, entry.name);
|
|
23
|
+
const rel = relative(dir, path).split(sep).join('/');
|
|
24
|
+
const matched = matches?.(rel);
|
|
25
|
+
if (matched && !entry.isFile())
|
|
26
|
+
throw new Error(`${path}: native session must be a regular file, not a directory, link or special file`);
|
|
23
27
|
if (entry.isDirectory())
|
|
24
28
|
await visit(path);
|
|
25
|
-
else if (entry.isFile())
|
|
26
|
-
out.push(
|
|
29
|
+
else if (entry.isFile() && matched !== false)
|
|
30
|
+
out.push(rel);
|
|
27
31
|
}
|
|
28
32
|
};
|
|
29
33
|
await visit(dir);
|
|
@@ -45,12 +49,6 @@ export async function mapLimit(items, limit, fn) {
|
|
|
45
49
|
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
46
50
|
return results;
|
|
47
51
|
}
|
|
48
|
-
/** Files under `home` that one store glob matches, as absolute paths. */
|
|
49
|
-
export async function storeFiles(home, store, glob, nativeSessionId) {
|
|
50
|
-
const root = join(home, store.root);
|
|
51
|
-
const pattern = storeGlob(glob, nativeSessionId);
|
|
52
|
-
return (await walkFiles(root)).filter((path) => pattern.test(path)).map((path) => join(root, path));
|
|
53
|
-
}
|
|
54
52
|
export async function mtimeMs(path) {
|
|
55
53
|
try {
|
|
56
54
|
return (await stat(path)).mtimeMs;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/harness-sessions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
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,
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"LICENSE"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@tangle-network/agent-core": "^0.
|
|
44
|
-
"@tangle-network/agent-trace-contract": "^2.
|
|
43
|
+
"@tangle-network/agent-core": "^0.15.0",
|
|
44
|
+
"@tangle-network/agent-trace-contract": "^2.2.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/node": "26.6.5",
|