@tangle-network/harness-sessions 1.0.8 → 1.0.9
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/formats/claude-code.js +24 -52
- package/dist/schema.d.ts +2 -0
- package/package.json +1 -1
|
@@ -42,7 +42,7 @@ export function createFold(ref, mode, stats) {
|
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
const type = record.type;
|
|
45
|
-
if (type !== 'user' && type !== 'assistant' && type !== 'system')
|
|
45
|
+
if (type !== 'user' && type !== 'assistant' && type !== 'system' && type !== 'attachment')
|
|
46
46
|
return;
|
|
47
47
|
if (typeof record.uuid === 'string') {
|
|
48
48
|
if (seenUuids.has(record.uuid))
|
|
@@ -64,22 +64,29 @@ export function createFold(ref, mode, stats) {
|
|
|
64
64
|
}
|
|
65
65
|
const uuid = str(record.uuid) ?? `${builder.nativeSessionId}:${stats.line}`;
|
|
66
66
|
const machine = (text) => claudeRecordIsMachine({ text, isMeta: record.isMeta === true, isCompactSummary: record.isCompactSummary === true, entrypoint: str(record.entrypoint) ?? undefined });
|
|
67
|
+
if (type === 'attachment') {
|
|
68
|
+
// What Claude Code put in the model's context: `rendered` is its exact text, a prompt snapshot the system prompt.
|
|
69
|
+
// A queued command is a message sent while the turn ran, so it is a prompt.
|
|
70
|
+
const attachment = isRecord(record.attachment) ? record.attachment : {};
|
|
71
|
+
const kind = str(attachment.type) ?? 'attachment';
|
|
72
|
+
const queued = kind === 'queued_command' ? textOf(attachment.prompt) : null;
|
|
73
|
+
if (queued !== null) {
|
|
74
|
+
const typed = attachment.commandMode === 'prompt' && !machine(queued);
|
|
75
|
+
builder.message({ id: uuid, role: 'user', actor: !typed ? 'injected' : subagent ? 'subagent-spawn' : 'human', at, modelCallId: null, parts: [{ type: 'text', text: typed ? claudeTypedPromptText(queued) : queued }] });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const parts = Array.isArray(record.rendered) ? record.rendered : kind === 'prompt_snapshot' && Array.isArray(attachment.systemPrompt) ? attachment.systemPrompt : [];
|
|
79
|
+
const text = parts.map((part) => (typeof part === 'string' ? part : isRecord(part) ? str(part.content) ?? '' : '')).join('\n');
|
|
80
|
+
if (text)
|
|
81
|
+
builder.message({ id: uuid, role: 'system', actor: 'injected', at, modelCallId: null, source: kind, parts: [{ type: 'text', text }] });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
67
84
|
if (type === 'system') {
|
|
68
85
|
if (record.subtype !== 'api_error')
|
|
69
86
|
return;
|
|
70
87
|
const error = isRecord(record.error) ? record.error : {};
|
|
71
88
|
const message = str(error.formatted) ?? str(error.message) ?? str(record.content) ?? 'API error';
|
|
72
|
-
builder.modelCall({
|
|
73
|
-
id: uuid,
|
|
74
|
-
at,
|
|
75
|
-
provider: null,
|
|
76
|
-
servedModel: null,
|
|
77
|
-
requestedModel: null,
|
|
78
|
-
usage: null,
|
|
79
|
-
costUsd: null,
|
|
80
|
-
stopReason: null,
|
|
81
|
-
error: sessionError('api_error', message, at, count(error.status)),
|
|
82
|
-
});
|
|
89
|
+
builder.modelCall({ id: uuid, at, provider: null, servedModel: null, requestedModel: null, usage: null, costUsd: null, stopReason: null, error: sessionError('api_error', message, at, count(error.status)) });
|
|
83
90
|
errors += 1;
|
|
84
91
|
return;
|
|
85
92
|
}
|
|
@@ -94,14 +101,7 @@ export function createFold(ref, mode, stats) {
|
|
|
94
101
|
if (typeof content === 'string') {
|
|
95
102
|
if (INTERRUPTED.test(content))
|
|
96
103
|
aborted = { at };
|
|
97
|
-
builder.message({
|
|
98
|
-
id: uuid,
|
|
99
|
-
role: 'user',
|
|
100
|
-
actor: machine(content) ? 'injected' : subagent ? 'subagent-spawn' : 'human',
|
|
101
|
-
at,
|
|
102
|
-
modelCallId: null,
|
|
103
|
-
parts: [{ type: 'text', text: machine(content) ? content : claudeTypedPromptText(content) }],
|
|
104
|
-
});
|
|
104
|
+
builder.message({ id: uuid, role: 'user', actor: machine(content) ? 'injected' : subagent ? 'subagent-spawn' : 'human', at, modelCallId: null, parts: [{ type: 'text', text: machine(content) ? content : claudeTypedPromptText(content) }] });
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
107
|
if (!Array.isArray(content))
|
|
@@ -139,16 +139,8 @@ export function createFold(ref, mode, stats) {
|
|
|
139
139
|
}
|
|
140
140
|
if (toolParts.length > 0)
|
|
141
141
|
builder.message({ id: `${uuid}:tool`, role: 'tool', actor: 'tool-result', at, modelCallId: null, parts: toolParts });
|
|
142
|
-
if (userParts.length > 0)
|
|
143
|
-
builder.message({
|
|
144
|
-
id: uuid,
|
|
145
|
-
role: 'user',
|
|
146
|
-
actor: machine(firstText(userParts)) ? 'injected' : subagent ? 'subagent-spawn' : 'human',
|
|
147
|
-
at,
|
|
148
|
-
modelCallId: null,
|
|
149
|
-
parts: userParts,
|
|
150
|
-
});
|
|
151
|
-
}
|
|
142
|
+
if (userParts.length > 0)
|
|
143
|
+
builder.message({ id: uuid, role: 'user', actor: machine(firstText(userParts)) ? 'injected' : subagent ? 'subagent-spawn' : 'human', at, modelCallId: null, parts: userParts });
|
|
152
144
|
return;
|
|
153
145
|
}
|
|
154
146
|
aborted = null;
|
|
@@ -156,17 +148,7 @@ export function createFold(ref, mode, stats) {
|
|
|
156
148
|
const content = Array.isArray(message.content) ? message.content : [];
|
|
157
149
|
if (record.isApiErrorMessage === true || model === '<synthetic>') {
|
|
158
150
|
const text = textOf(content) ?? 'API error';
|
|
159
|
-
const call = builder.modelCall({
|
|
160
|
-
id: uuid,
|
|
161
|
-
at,
|
|
162
|
-
provider: null,
|
|
163
|
-
servedModel: null,
|
|
164
|
-
requestedModel: null,
|
|
165
|
-
usage: null,
|
|
166
|
-
costUsd: null,
|
|
167
|
-
stopReason: str(message.stop_reason),
|
|
168
|
-
error: sessionError(str(record.error) ?? 'api-error', text, at),
|
|
169
|
-
});
|
|
151
|
+
const call = builder.modelCall({ id: uuid, at, provider: null, servedModel: null, requestedModel: null, usage: null, costUsd: null, stopReason: str(message.stop_reason), error: sessionError(str(record.error) ?? 'api-error', text, at) });
|
|
170
152
|
builder.message({ id: uuid, role: 'assistant', actor: 'injected', at, modelCallId: call.id, parts: [{ type: 'text', text }] });
|
|
171
153
|
errors += 1;
|
|
172
154
|
return;
|
|
@@ -198,17 +180,7 @@ export function createFold(ref, mode, stats) {
|
|
|
198
180
|
builder.appendParts(apiId, parts);
|
|
199
181
|
return;
|
|
200
182
|
}
|
|
201
|
-
builder.modelCall({
|
|
202
|
-
id: apiId,
|
|
203
|
-
at,
|
|
204
|
-
provider: null,
|
|
205
|
-
servedModel: model,
|
|
206
|
-
requestedModel: null,
|
|
207
|
-
usage: usageOf(message.usage),
|
|
208
|
-
costUsd: null,
|
|
209
|
-
stopReason: str(message.stop_reason),
|
|
210
|
-
error: null,
|
|
211
|
-
});
|
|
183
|
+
builder.modelCall({ id: apiId, at, provider: null, servedModel: model, requestedModel: null, usage: usageOf(message.usage), costUsd: null, stopReason: str(message.stop_reason), error: null });
|
|
212
184
|
builder.message({ id: apiId, role: 'assistant', actor: 'agent', at, modelCallId: apiId, parts });
|
|
213
185
|
};
|
|
214
186
|
const finish = () => {
|
package/dist/schema.d.ts
CHANGED
|
@@ -53,6 +53,8 @@ export interface SessionMessage {
|
|
|
53
53
|
at: string | null;
|
|
54
54
|
modelCallId: string | null;
|
|
55
55
|
parts: Part[];
|
|
56
|
+
/** What a harness-injected system message is, in the harness's words: Claude Code's attachment type, such as `instructions`. */
|
|
57
|
+
source?: string;
|
|
56
58
|
}
|
|
57
59
|
export interface SessionToolCall {
|
|
58
60
|
id: string;
|
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.9",
|
|
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,
|