@tangle-network/harness-sessions 1.0.13 → 1.0.15

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 CHANGED
@@ -32,6 +32,7 @@ export declare class SessionBuilder {
32
32
  private toolCallCount;
33
33
  private replies;
34
34
  readonly modelCalls: ModelCall[];
35
+ private readonly turnReceipts;
35
36
  private readonly modelCallById;
36
37
  private readonly toolDefinitionSnapshots;
37
38
  private readonly children;
@@ -78,6 +79,7 @@ export declare class SessionBuilder {
78
79
  unparsedLines?: number[];
79
80
  }): void;
80
81
  markTruncated(reason: string): void;
82
+ closeNativeTurn(id: string, firstModelCall: number, ending: SessionEnding): void;
81
83
  setSessionUsage(usage: TokenUsage | null): void;
82
84
  end(ending: SessionEnding): void;
83
85
  inferEnding(aborted?: {
package/dist/builder.js CHANGED
@@ -42,8 +42,9 @@ export function httpStatusIn(text) {
42
42
  const match = /\b(?:status(?: code)?|HTTP)[^\d]{0,4}([1-5]\d\d)\b/iu.exec(text) ?? /^([45]\d\d)\b/u.exec(text.trim());
43
43
  return match ? Number(match[1]) : null;
44
44
  }
45
+ const usageKeys = ['input', 'output', 'reasoning', 'cacheRead', 'cacheWrite'];
45
46
  function addUsage(total, usage) {
46
- for (const key of ['input', 'output', 'reasoning', 'cacheRead', 'cacheWrite']) {
47
+ for (const key of usageKeys) {
47
48
  const value = usage[key];
48
49
  if (value !== null)
49
50
  total[key] = (total[key] ?? 0) + value;
@@ -80,6 +81,7 @@ export class SessionBuilder {
80
81
  toolCallCount = 0;
81
82
  replies = 0;
82
83
  modelCalls = [];
84
+ turnReceipts = [];
83
85
  modelCallById = new Map();
84
86
  toolDefinitionSnapshots = [];
85
87
  children = [];
@@ -207,6 +209,26 @@ export class SessionBuilder {
207
209
  this.truncated = true;
208
210
  this.gap(reason);
209
211
  }
212
+ closeNativeTurn(id, firstModelCall, ending) {
213
+ const calls = this.modelCalls.slice(firstModelCall);
214
+ const total = { input: null, output: null, reasoning: null, cacheRead: null, cacheWrite: null };
215
+ // A missing step counter stays unknown even if another step reported that class.
216
+ for (const key of usageKeys) {
217
+ if (!calls.length)
218
+ continue;
219
+ let sum = 0;
220
+ for (const call of calls) {
221
+ const value = call.usage?.[key];
222
+ if (value == null) {
223
+ sum = null;
224
+ break;
225
+ }
226
+ sum += value;
227
+ }
228
+ total[key] = sum;
229
+ }
230
+ this.turnReceipts.push({ id, firstModelCall, endModelCall: this.modelCalls.length, ending, usage: usageOrNull(total) });
231
+ }
210
232
  setSessionUsage(usage) {
211
233
  this.sessionUsage = usage;
212
234
  }
@@ -274,6 +296,7 @@ export class SessionBuilder {
274
296
  modelSource: this.modelSource,
275
297
  usage: this.usage(),
276
298
  ending: this.ending,
299
+ ...(this.turnReceipts.length ? { turnReceipts: this.turnReceipts } : {}),
277
300
  children: this.children,
278
301
  integrity: {
279
302
  sourceFiles: this.sources,
@@ -297,6 +320,7 @@ export class SessionBuilder {
297
320
  modelSource: this.modelSource,
298
321
  usage: this.usage(),
299
322
  ending: this.ending,
323
+ ...(this.turnReceipts.length ? { turnReceipts: this.turnReceipts } : {}),
300
324
  unparsedRecords: this.unparsed,
301
325
  bytes: this.sources.reduce((sum, s) => sum + s.bytes, 0),
302
326
  truncated: this.truncated,
package/dist/capture.js CHANGED
@@ -6,6 +6,7 @@ import { str } from './builder.js';
6
6
  import { opencodeSessionsInStore } from './formats/opencode.js';
7
7
  import { hermesSessionsInStore } from './formats/hermes.js';
8
8
  import { openclawSessionsInStore } from './formats/openclaw.js';
9
+ import { kimiRefForFile, linkKimiFamily } from './formats/kimi.js';
9
10
  import { maybeReaderFor, readerFor, readerForFormat } from './registry.js';
10
11
  import { isMissing } from './source.js';
11
12
  import { storeGlob } from './stores.js';
@@ -121,13 +122,29 @@ async function fromV2(archiveDir, manifest, listing) {
121
122
  continue;
122
123
  }
123
124
  const mainPath = join(archiveDir, mainFile.path);
124
- const nestedFiles = copy.files.filter((f) => { const rel = inStore(storePathOf(f)); return rel !== null && nested.some((n) => n.test(rel)); }).map((f) => join(archiveDir, f.path));
125
+ const nestedCopies = [...new Map(copy.files.filter((f) => {
126
+ const rel = inStore(storePathOf(f));
127
+ return rel !== null && !main.test(rel) && nested.some((n) => n.test(rel));
128
+ }).map((f) => [storePathOf(f), f])).values()];
129
+ const nestedFiles = nestedCopies.map((f) => join(archiveDir, f.path));
125
130
  const declared = store.files.map((pattern) => storeGlob(pattern, copy.nativeSessionId));
126
131
  const files = [...new Set([mainPath, ...nestedFiles, ...copy.files.filter((f) => { const rel = inStore(storePathOf(f)); return rel !== null && declared.some((pattern) => pattern.test(rel)); }).map((f) => join(archiveDir, f.path))])];
127
- listing.sessions.push(captured({ harness: reader.harness, format: store.format, nativeSessionId: copy.nativeSessionId, path: mainPath, files, home: null, cwd: null, mtimeMs: Date.parse(copy.capturedAt) || 0, parentNativeSessionId: null, truncated: mainFile.truncated }, copy, true, archiveDir, mainPath));
128
- for (const file of nestedFiles) {
129
- const child = file.split('/').pop().replace(/\.jsonl$/u, '').replace(/^agent-/u, '');
130
- listing.sessions.push(captured({ harness: reader.harness, format: store.format, nativeSessionId: child, path: file, files: [file], home: null, cwd: null, mtimeMs: Date.parse(copy.capturedAt) || 0, parentNativeSessionId: copy.nativeSessionId, truncated }, copy, false, archiveDir, file));
132
+ const family = [{ harness: reader.harness, format: store.format, nativeSessionId: copy.nativeSessionId, path: mainPath, files, home: null, cwd: null, mtimeMs: Date.parse(copy.capturedAt) || 0, parentNativeSessionId: null, truncated: mainFile.truncated }];
133
+ for (const file of nestedCopies) {
134
+ const path = join(archiveDir, file.path);
135
+ const child = path.split('/').pop().replace(/\.jsonl$/u, '').replace(/^agent-/u, '');
136
+ const identity = reader.harness === 'kimi-code'
137
+ ? kimiRefForFile(path, storePathOf(file))
138
+ : { harness: reader.harness, format: store.format, nativeSessionId: child, parentNativeSessionId: copy.nativeSessionId };
139
+ family.push({ ...identity, path, files: [path], home: null, cwd: null, mtimeMs: Date.parse(copy.capturedAt) || 0, truncated: reader.harness === 'kimi-code' ? file.truncated : truncated });
140
+ }
141
+ if (reader.harness === 'kimi-code' && nestedFiles.length) {
142
+ const state = storeGlob('wd_*/{id}/state.json', copy.nativeSessionId);
143
+ const index = copy.files.find(file => state.test(inStore(storePathOf(file)) ?? ''));
144
+ await linkKimiFamily(family, index && !index.truncated ? join(archiveDir, index.path) : undefined);
145
+ }
146
+ for (const ref of family) {
147
+ listing.sessions.push(captured(ref, copy, ref.path === mainPath, archiveDir, ref.path));
131
148
  }
132
149
  }
133
150
  }
package/dist/catalog.d.ts CHANGED
@@ -111,6 +111,7 @@ export declare const KIMI_STORES: readonly [{
111
111
  readonly files: readonly ["wd_*/{id}/**"];
112
112
  readonly globs: {
113
113
  readonly session: "wd_*/{id}/agents/main/wire.jsonl";
114
+ readonly children: "wd_*/{id}/agents/*/wire.jsonl";
114
115
  };
115
116
  readonly format: "kimi.session-dir";
116
117
  readonly write: "jsonl-append" | "json-rewrite" | "sqlite-wal";
package/dist/catalog.js CHANGED
@@ -42,7 +42,7 @@ export const STORES = {
42
42
  'nanoclaw.session-sqlite': store('nanoclaw.session-sqlite', '.nanoclaw/data/v2-sessions', ['*/{id}/outbound.db', '*/{id}/inbound.db'], 'sqlite-wal', false),
43
43
  };
44
44
  export const KIMI_STORES = [
45
- { ...STORES['kimi.session-dir'], root: '.kimi-code/sessions', files: ['wd_*/{id}/**'], globs: { session: 'wd_*/{id}/agents/main/wire.jsonl' } },
45
+ { ...STORES['kimi.session-dir'], root: '.kimi-code/sessions', files: ['wd_*/{id}/**'], globs: { session: 'wd_*/{id}/agents/main/wire.jsonl', children: 'wd_*/{id}/agents/*/wire.jsonl' } },
46
46
  STORES['kimi.session-dir'],
47
47
  ];
48
48
  /** Every root the pinned CLIs write transcripts to: the classic home layout and the XDG config layout (#553). */
@@ -4,5 +4,7 @@ import { type RecordSource, type SourceStats } from '../source.js';
4
4
  import { type SessionFold } from './fold.js';
5
5
  export declare function createFold(ref: SessionRef, mode: BuildMode, stats: SourceStats): SessionFold;
6
6
  export declare function fold(ref: SessionRef, mode: BuildMode, options: ReadOptions, source?: RecordSource): Promise<SessionBuilder>;
7
+ /** Recover the originating call's owner only for a requested family missing its native index. */
8
+ export declare function linkKimiFamily(refs: SessionRef[], statePath?: string, options?: ReadOptions): Promise<void>;
7
9
  export declare const kimiReader: HarnessSessionReader;
8
- export declare function kimiRefForFile(path: string): SessionRef;
10
+ export declare function kimiRefForFile(path: string, storePath?: string): SessionRef;
@@ -1,20 +1,55 @@
1
1
  import { isRecord } from '@tangle-network/agent-core';
2
- import { basename, dirname, join } from 'node:path';
2
+ import { readFileSync } from 'node:fs';
3
+ import { readdir } from 'node:fs/promises';
4
+ import { basename, dirname, isAbsolute, join } from 'node:path';
3
5
  import { SessionBuilder, count, sessionError, str, textOf, usageOrNull } from '../builder.js';
4
- import { fileRecords } from '../source.js';
6
+ import { fileRecords, isMissing } from '../source.js';
5
7
  import { KIMI_STORES } from '../catalog.js';
6
8
  import { EVIDENCE, mtimeMs, storeGlob, walkFiles, withinPath } from '../stores.js';
7
9
  import { foldedReader, runFold } from './fold.js';
8
10
  const FORMAT = 'kimi.session-dir';
9
11
  const HARNESS = 'kimi-code';
10
12
  const WIRE = '*/{id}/wire.jsonl';
11
- const CHILD_WIRE = '*/*/subagents/{id}/wire.jsonl';
13
+ const CHILD_WIRE = '*/{id}/subagents/*/wire.jsonl';
14
+ function scopedAgent(root, agent) {
15
+ return agent === 'main' ? root : `${root}/${agent}`;
16
+ }
12
17
  function sessionIdentity(path) {
13
18
  const directory = dirname(path);
14
19
  const container = dirname(directory);
15
- if (basename(container) === 'agents' && basename(directory) === 'main')
16
- return { id: basename(dirname(container)), parent: null };
17
- return { id: basename(directory), parent: basename(container) === 'subagents' ? basename(dirname(container)) : null };
20
+ const agent = basename(directory);
21
+ if (basename(container) === 'agents') {
22
+ const root = basename(dirname(container));
23
+ return { id: scopedAgent(root, agent), parent: null, root };
24
+ }
25
+ return { id: agent, parent: basename(container) === 'subagents' ? basename(dirname(container)) : null, root: null };
26
+ }
27
+ /** In 2.x every agent has a sibling directory. The small native index names its actual parent. */
28
+ function stateParents(path) {
29
+ let state;
30
+ try {
31
+ state = JSON.parse(readFileSync(path, 'utf8'));
32
+ }
33
+ catch (error) {
34
+ if (isMissing(error) || error instanceof SyntaxError)
35
+ return new Map();
36
+ throw error;
37
+ }
38
+ const parents = new Map();
39
+ if (isRecord(state) && typeof state.id === 'string' && isRecord(state.agents)) {
40
+ for (const [agent, row] of Object.entries(state.agents)) {
41
+ if (isRecord(row) && typeof row.parentAgentId === 'string')
42
+ parents.set(scopedAgent(state.id, agent), scopedAgent(state.id, row.parentAgentId));
43
+ }
44
+ }
45
+ return parents;
46
+ }
47
+ function spawnEdge(ref, payload) {
48
+ const [root, agent = 'main'] = ref.nativeSessionId.split('/');
49
+ const child = str(payload.subagentId);
50
+ if (!root || !child || child === 'main' || payload.parentAgentId !== agent || payload.callerAgentId !== agent)
51
+ return null;
52
+ return { id: scopedAgent(root, child), tool: str(payload.parentToolCallId) };
18
53
  }
19
54
  function usageOf(value) {
20
55
  if (!isRecord(value))
@@ -30,6 +65,7 @@ function usageOf(value) {
30
65
  export function createFold(ref, mode, stats) {
31
66
  const builder = new SessionBuilder(HARNESS, FORMAT, EVIDENCE[FORMAT].servedModel, mode, ref.nativeSessionId, ref.parentNativeSessionId);
32
67
  let turn = 0;
68
+ let openTurn = null;
33
69
  let step = null;
34
70
  let lastToolCall = null;
35
71
  let aborted = null;
@@ -70,6 +106,9 @@ export function createFold(ref, mode, stats) {
70
106
  case 'turn.prompt':
71
107
  case 'TurnBegin': {
72
108
  turn += 1;
109
+ openTurn = type === 'turn.prompt' && (typeof payload.turnId === 'string' || Number.isSafeInteger(payload.turnId))
110
+ ? { id: String(payload.turnId), firstModelCall: builder.modelCalls.length }
111
+ : null;
73
112
  step = null;
74
113
  aborted = null;
75
114
  promptId = str(payload.promptId);
@@ -168,6 +207,10 @@ export function createFold(ref, mode, stats) {
168
207
  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;
169
208
  nativeEnding = { status, error, at: status === 'open' ? null : endedAt };
170
209
  nativeReason = reason;
210
+ if (type === 'turn.ended' && status !== 'open' && openTurn?.id === String(payload.turnId)) {
211
+ builder.closeNativeTurn(openTurn.id, openTurn.firstModelCall, nativeEnding);
212
+ openTurn = null;
213
+ }
171
214
  if (status === 'open')
172
215
  builder.gap('Native ending reason is unknown');
173
216
  break;
@@ -175,6 +218,12 @@ export function createFold(ref, mode, stats) {
175
218
  case 'CompactionBegin':
176
219
  compactions += 1;
177
220
  break;
221
+ case 'subagent.spawned': {
222
+ const child = spawnEdge(ref, payload);
223
+ if (child)
224
+ builder.child(child.id, child.tool);
225
+ break;
226
+ }
178
227
  case 'SubagentEvent': {
179
228
  subagentEvents += 1;
180
229
  const agent = str(payload.agent_id);
@@ -204,38 +253,118 @@ export function createFold(ref, mode, stats) {
204
253
  return { builder, observe, finish };
205
254
  }
206
255
  export async function fold(ref, mode, options, source = fileRecords(ref.path, { strict: options.corruption === 'strict', signal: options.signal })) {
256
+ const { root } = sessionIdentity(ref.path);
257
+ if (ref.parentNativeSessionId === null && root && ref.nativeSessionId !== root) {
258
+ // A direct file read may have only the retained wires, without the session index.
259
+ const agents = dirname(dirname(ref.path));
260
+ ref = { ...ref };
261
+ const family = [ref];
262
+ for (const entry of await readdir(agents, { withFileTypes: true })) {
263
+ const path = join(agents, entry.name, 'wire.jsonl');
264
+ if (entry.isDirectory() && path !== ref.path && await mtimeMs(path))
265
+ family.push(refForWire(path, path));
266
+ }
267
+ await linkKimiFamily(family, undefined, options);
268
+ }
207
269
  return runFold(createFold(ref, mode, source.stats), source);
208
270
  }
271
+ /** Recover the originating call's owner only for a requested family missing its native index. */
272
+ export async function linkKimiFamily(refs, statePath, options = {}) {
273
+ const indexed = statePath ? stateParents(statePath) : new Map();
274
+ const missing = new Map();
275
+ for (const ref of refs) {
276
+ ref.parentNativeSessionId ??= indexed.get(ref.nativeSessionId) ?? null;
277
+ if (ref.parentNativeSessionId === null && ref.nativeSessionId.includes('/'))
278
+ missing.set(ref.nativeSessionId, ref);
279
+ }
280
+ if (!missing.size)
281
+ return;
282
+ // A root normally records the first spawn long before it finishes. Stop at that record.
283
+ const parents = [...refs].sort((a, b) => Number(a.nativeSessionId.includes('/')) - Number(b.nativeSessionId.includes('/')));
284
+ for (const parent of parents) {
285
+ if (missing.size === 1 && missing.has(parent.nativeSessionId))
286
+ continue;
287
+ for await (const row of fileRecords(parent.path, { signal: options.signal, strict: options.corruption === 'strict' }).records) {
288
+ if (row.type !== 'subagent.spawned')
289
+ continue;
290
+ const edge = spawnEdge(parent, row);
291
+ const child = edge && missing.get(edge.id);
292
+ if (child) {
293
+ child.parentNativeSessionId = parent.nativeSessionId;
294
+ missing.delete(child.nativeSessionId);
295
+ if (!missing.size)
296
+ return;
297
+ }
298
+ }
299
+ }
300
+ }
209
301
  async function locate(home, opts) {
210
- const refs = [];
302
+ const found = [];
303
+ const indices = new Map();
211
304
  for (const store of KIMI_STORES) {
212
305
  const root = join(home, store.root);
213
306
  const pattern = storeGlob('globs' in store ? store.globs.session : WIRE);
214
- const children = storeGlob(CHILD_WIRE);
307
+ const children = storeGlob('globs' in store && store.globs.children ? store.globs.children : CHILD_WIRE);
215
308
  const matches = (rel) => {
216
- const { id, parent } = sessionIdentity(rel);
217
- return (pattern.test(rel) || children.test(rel)) && (!opts.nativeSessionId || id === opts.nativeSessionId || parent === opts.nativeSessionId);
309
+ if (!pattern.test(rel) && !children.test(rel))
310
+ return false;
311
+ if (!opts.nativeSessionId)
312
+ return true;
313
+ const { id, parent, root: sessionRoot } = sessionIdentity(rel);
314
+ return sessionRoot !== null
315
+ ? sessionRoot === opts.nativeSessionId.split('/')[0]
316
+ : id === opts.nativeSessionId || parent === opts.nativeSessionId;
218
317
  };
219
318
  for (const rel of await walkFiles(root, undefined, matches)) {
220
319
  const path = join(root, rel);
221
- const mtime = await mtimeMs(path);
222
- if (opts.sinceMs && mtime < opts.sinceMs)
223
- continue;
224
320
  const context = join(dirname(path), 'context.jsonl');
225
321
  const files = (await mtimeMs(context)) > 0 ? [path, context] : [path];
226
- const ref = { ...kimiRefForFile(path), files, home, mtimeMs: mtime };
227
- if (opts.cwd) {
228
- ref.cwd = (await fold(ref, 'summary', {})).cwd;
229
- if (ref.cwd === null || !withinPath(ref.cwd, opts.cwd))
230
- continue;
231
- }
232
- refs.push(ref);
322
+ found.push({ ...refForWire(path, path, indices), files, home, mtimeMs: await mtimeMs(path) });
233
323
  }
234
324
  }
235
- return refs.sort((a, b) => b.mtimeMs - a.mtimeMs);
325
+ const refs = found.filter(ref => !opts.sinceMs || ref.mtimeMs >= opts.sinceMs);
326
+ // Inventory stays a metadata operation. An explicit family read can recover a missing parent from its own wires.
327
+ if (opts.nativeSessionId && refs.some(ref => ref.nativeSessionId.includes('/') && ref.parentNativeSessionId === null))
328
+ await linkKimiFamily(found);
329
+ const byId = new Map(found.map((ref) => [ref.nativeSessionId, ref]));
330
+ const selected = (ref) => {
331
+ if (!opts.nativeSessionId || ref.nativeSessionId.split('/')[0] === opts.nativeSessionId)
332
+ return true;
333
+ let id = ref.nativeSessionId;
334
+ const seen = new Set();
335
+ while (id !== null && !seen.has(id)) {
336
+ if (id === opts.nativeSessionId)
337
+ return true;
338
+ seen.add(id);
339
+ id = byId.get(id)?.parentNativeSessionId ?? null;
340
+ }
341
+ return false;
342
+ };
343
+ const selectedRefs = [];
344
+ for (const ref of refs) {
345
+ if (!selected(ref))
346
+ continue;
347
+ if (opts.cwd) {
348
+ ref.cwd = (await fold(ref, 'summary', {})).cwd;
349
+ if (ref.cwd === null || !withinPath(ref.cwd, opts.cwd))
350
+ continue;
351
+ }
352
+ selectedRefs.push(ref);
353
+ }
354
+ return selectedRefs.sort((a, b) => b.mtimeMs - a.mtimeMs);
236
355
  }
237
356
  export const kimiReader = foldedReader({ harness: HARNESS, aliases: ['kimi', 'kimi-cli'], format: FORMAT, globs: { session: WIRE, children: CHILD_WIRE }, stores: KIMI_STORES }, locate, fold);
238
- export function kimiRefForFile(path) {
239
- const { id, parent } = sessionIdentity(path);
240
- return { harness: HARNESS, format: FORMAT, nativeSessionId: id, path, files: [path], home: null, cwd: null, mtimeMs: 0, parentNativeSessionId: parent };
357
+ function refForWire(path, storePath, indices) {
358
+ const { id, parent, root } = sessionIdentity(storePath);
359
+ let owner = parent;
360
+ if (root && id !== root && path === storePath && isAbsolute(path)) {
361
+ const state = join(dirname(dirname(dirname(path))), 'state.json');
362
+ const parents = indices?.get(state) ?? stateParents(state);
363
+ indices?.set(state, parents);
364
+ owner = parents.get(id) ?? null;
365
+ }
366
+ return { harness: HARNESS, format: FORMAT, nativeSessionId: id, path, files: [path], home: null, cwd: null, mtimeMs: 0, parentNativeSessionId: owner };
367
+ }
368
+ export function kimiRefForFile(path, storePath = path) {
369
+ return refForWire(path, storePath);
241
370
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { HarnessSession, HarnessSessionReader, LocateOptions, ModelCall, NativeSessionCopy, NativeSessionStore, Part, RawEvidenceArchiveManifestV2, ReadOptions, SessionEnding, SessionError, SessionEvidenceSources, SessionFormatId, SessionIntegrity, SessionMessage, SessionRef, SessionSummary, SessionToolCall, SessionToolDefinition, SessionToolDefinitionSnapshot, TokenUsage, } from './schema.js';
1
+ export type { HarnessSession, HarnessSessionReader, LocateOptions, ModelCall, NativeSessionCopy, NativeSessionStore, NativeTurnReceipt, Part, RawEvidenceArchiveManifestV2, ReadOptions, SessionEnding, SessionError, SessionEvidenceSources, SessionFormatId, SessionIntegrity, SessionMessage, SessionRef, SessionSummary, SessionToolCall, SessionToolDefinition, SessionToolDefinitionSnapshot, TokenUsage, } from './schema.js';
2
2
  export { HARNESS_SESSION_SCHEMA } from './schema.js';
3
3
  export { CLAUDE_CODE_STORES, CODEX_HOME_RULE, CODEX_STORES, EVIDENCE, KIMI_STORES, SESSION_FORMAT_IDS, STORES, assertStoreRoot, isCodexHome, storeGlob, withinPath } from './catalog.js';
4
4
  export { codexHomes } from './stores.js';
package/dist/schema.d.ts CHANGED
@@ -115,6 +115,15 @@ export interface SessionIntegrity {
115
115
  truncated: boolean;
116
116
  gaps: string[];
117
117
  }
118
+ /** One explicitly closed native turn. The model-call interval is half-open. */
119
+ export interface NativeTurnReceipt {
120
+ id: string;
121
+ firstModelCall: number;
122
+ endModelCall: number;
123
+ ending: SessionEnding;
124
+ /** Totals over this closed turn. Each incomplete token class stays null. */
125
+ usage: TokenUsage | null;
126
+ }
118
127
  export interface HarnessSession {
119
128
  schema: 'tangle.harness-session.v1';
120
129
  harness: string;
@@ -133,6 +142,7 @@ export interface HarnessSession {
133
142
  modelSource: SessionEvidenceSources['servedModel'];
134
143
  usage: TokenUsage | null;
135
144
  ending: SessionEnding;
145
+ turnReceipts?: NativeTurnReceipt[];
136
146
  children: Array<{
137
147
  nativeSessionId: string;
138
148
  toolCallId: string | null;
@@ -152,6 +162,7 @@ export interface SessionSummary {
152
162
  modelSource: HarnessSession['modelSource'];
153
163
  usage: TokenUsage | null;
154
164
  ending: SessionEnding;
165
+ turnReceipts?: NativeTurnReceipt[];
155
166
  unparsedRecords: number;
156
167
  bytes: number;
157
168
  truncated: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/harness-sessions",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
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,