@tangle-network/harness-sessions 1.0.14 → 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 +2 -0
- package/dist/builder.js +25 -1
- package/dist/formats/kimi.js +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/schema.d.ts +11 -0
- package/package.json +1 -1
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
|
|
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/formats/kimi.js
CHANGED
|
@@ -65,6 +65,7 @@ function usageOf(value) {
|
|
|
65
65
|
export function createFold(ref, mode, stats) {
|
|
66
66
|
const builder = new SessionBuilder(HARNESS, FORMAT, EVIDENCE[FORMAT].servedModel, mode, ref.nativeSessionId, ref.parentNativeSessionId);
|
|
67
67
|
let turn = 0;
|
|
68
|
+
let openTurn = null;
|
|
68
69
|
let step = null;
|
|
69
70
|
let lastToolCall = null;
|
|
70
71
|
let aborted = null;
|
|
@@ -105,6 +106,9 @@ export function createFold(ref, mode, stats) {
|
|
|
105
106
|
case 'turn.prompt':
|
|
106
107
|
case 'TurnBegin': {
|
|
107
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;
|
|
108
112
|
step = null;
|
|
109
113
|
aborted = null;
|
|
110
114
|
promptId = str(payload.promptId);
|
|
@@ -203,6 +207,10 @@ export function createFold(ref, mode, stats) {
|
|
|
203
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;
|
|
204
208
|
nativeEnding = { status, error, at: status === 'open' ? null : endedAt };
|
|
205
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
|
+
}
|
|
206
214
|
if (status === 'open')
|
|
207
215
|
builder.gap('Native ending reason is unknown');
|
|
208
216
|
break;
|
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.
|
|
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,
|