@silverprotocol/claude-agent-sdk 0.11.0 → 0.12.1
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/index.d.ts +7 -7
- package/dist/index.js +56 -56
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
- package/src/index.ts +66 -66
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `@silverprotocol/claude-agent-sdk` — the LIVE-path normalizer (stateful facet).
|
|
3
3
|
*
|
|
4
|
-
* Translates the public Claude Agent SDK `SDKMessage` union (the
|
|
5
|
-
*
|
|
4
|
+
* Translates the public Claude Agent SDK `SDKMessage` union (the frames a host's
|
|
5
|
+
* run seam yields from `query()`) into
|
|
6
6
|
* AgJSON events (`AgEvent[]`, spec §4) by driving a shared {@link StreamAssembler}
|
|
7
7
|
* via primitive calls. Claude's assistant turn is a COMPLETE-message structure —
|
|
8
8
|
* `message.content[]` is the whole turn's content, not a stream of deltas — so the
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* block, then tool_use block), so the message lifecycle is keyed on `message.id`
|
|
13
13
|
* and its seal is deferred across contiguous same-id frames: one
|
|
14
14
|
* `message.start`/`message.end` pair per id, never a re-open of a sealed id
|
|
15
|
-
* (INV-MSG — see `PendingMessage` in `createClaudeNormalizer
|
|
15
|
+
* (INV-MSG — see `PendingMessage` in `createClaudeNormalizer`).
|
|
16
16
|
*
|
|
17
17
|
* With `includePartialMessages: true` (workspace#7) the seam ALSO interleaves
|
|
18
18
|
* `stream_event` frames — the raw Anthropic streaming vocabulary — before each
|
|
@@ -53,8 +53,8 @@ export interface ClaudeNormalizerOptions {
|
|
|
53
53
|
* tool_result frame that carries none, the turn's own id), a placeholder in
|
|
54
54
|
* the same spirit as the openai/vercel facets' fixed labels. That placeholder is fine for
|
|
55
55
|
* self-contained streams but LEAKS into any consumer that persists
|
|
56
|
-
* events verbatim under its own thread identity (
|
|
57
|
-
* events carried the session id while the runtime's session records
|
|
56
|
+
* events verbatim under its own thread identity (in a reference host,
|
|
57
|
+
* mid-stream events carried the session id while the runtime's session records
|
|
58
58
|
* carried the real thread id). A runtime that owns the real thread
|
|
59
59
|
* identity should always pass it here — one id everywhere, stamped at
|
|
60
60
|
* construction.
|
|
@@ -66,8 +66,8 @@ export interface ClaudeNormalizerOptions {
|
|
|
66
66
|
* whose frame carries no usable message id or uuid (the normal path names a
|
|
67
67
|
* turn by its SDK message id or frame uuid, unique by construction). A host
|
|
68
68
|
* folds every invoke of a conversation into ONE Reducer, so a stem that
|
|
69
|
-
* restarted with each invoke repeated those ids across invokes (
|
|
70
|
-
*
|
|
69
|
+
* restarted with each invoke repeated those ids across invokes (§8.0 "Ids
|
|
70
|
+
* across invokes"). Absent, each normalizer draws a random
|
|
71
71
|
* `claude_<16 hex>` stem at most once, lazily (only when a fallback id is
|
|
72
72
|
* first needed, so the common path draws no randomness), and holds it
|
|
73
73
|
* OUTSIDE the atomic-push rebuild, so a rebuild reproduces it. Pass a fixed
|
package/dist/index.js
CHANGED
|
@@ -345,7 +345,7 @@ function readNonExecutionKinds(frame) {
|
|
|
345
345
|
}
|
|
346
346
|
return out;
|
|
347
347
|
}
|
|
348
|
-
//
|
|
348
|
+
// Ruled 2026-09-24 (no neutral remedy field; fix the carries): each `tool_result_meta`
|
|
349
349
|
// entry, keyed by its `id` (the tool_use_id), verbatim: {id, non_execution_kind?,
|
|
350
350
|
// user_feedback?, remedy?} per the CLI's schema ("@internal Display metadata for
|
|
351
351
|
// this message's tool_result blocks"). Read through the JSON boundary; an entry
|
|
@@ -374,8 +374,8 @@ function readToolResultMetaEntries(frame) {
|
|
|
374
374
|
function isDenialKind(kind) {
|
|
375
375
|
return kind === "user-rejected" || kind === "permission-rule" || (kind !== undefined && kind.startsWith("automode-"));
|
|
376
376
|
}
|
|
377
|
-
// Which assistant `error` codes are transient (retriable).
|
|
378
|
-
// top-level close and a nested frame's non-terminal `error` share it.
|
|
377
|
+
// Which assistant `error` codes are transient (retriable). An API-error turn's
|
|
378
|
+
// stashed top-level close and a nested frame's non-terminal `error` share it.
|
|
379
379
|
// Finding #2 (minor): `overloaded` (transient capacity error, a first
|
|
380
380
|
// cousin of rate_limit/server_error) joins the retriable set.
|
|
381
381
|
// `model_not_found` (a permanent misconfiguration — e.g. a stale/
|
|
@@ -663,7 +663,7 @@ const CARRIED_SYSTEM_SUBTYPES = new Set([
|
|
|
663
663
|
// system/status ping — status:'compacting'|'requesting'|null (+ optional
|
|
664
664
|
// compact_result/compact_error). GENUINE consumer-facing agent-state signal
|
|
665
665
|
// (exactly the ready/thinking/responding vocabulary chat surfaces render —
|
|
666
|
-
//
|
|
666
|
+
// a reference host's status-states request) with no AgJSON home; previously
|
|
667
667
|
// router-plane'd. Carried whole-frame, which also closes the manifest's
|
|
668
668
|
// disclosed `compact_error` residual gap.
|
|
669
669
|
"status",
|
|
@@ -732,7 +732,7 @@ function anthropicFrameKind(msg) {
|
|
|
732
732
|
// A COPY, never the frame's own array: the value is emitted unparsed
|
|
733
733
|
// (result-meta, message.metadata), core's StreamAssembler does not copy, and
|
|
734
734
|
// push() hands a JSON frame through by reference, so returning `v` would let an
|
|
735
|
-
// emitted event share the host's live array (
|
|
735
|
+
// emitted event share the host's live array (found by an aliasing audit).
|
|
736
736
|
function readUserMessageUuids(v) {
|
|
737
737
|
return Array.isArray(v) && v.every((s) => typeof s === "string") ? [...v] : undefined;
|
|
738
738
|
}
|
|
@@ -746,7 +746,7 @@ const HOST_ONLY_WRAPPER_KEYS = new Set([
|
|
|
746
746
|
"api_error",
|
|
747
747
|
"api_error_params",
|
|
748
748
|
"api_error_code",
|
|
749
|
-
//
|
|
749
|
+
// Ruled 2026-09-24 (defer the field, fix the carries): three more @internal
|
|
750
750
|
// CLI assistant-wrapper strings, carried where the host can read them.
|
|
751
751
|
"error_details",
|
|
752
752
|
"advisor_model",
|
|
@@ -799,7 +799,7 @@ function readNarrationBlockIndexes(v) {
|
|
|
799
799
|
function carryVerbatim(v) {
|
|
800
800
|
return withoutCreditTokens(JsonValue.parse(v));
|
|
801
801
|
}
|
|
802
|
-
//
|
|
802
|
+
// SPEC §13.10: a provider credit or bearer token is never
|
|
803
803
|
// emitted. Anthropic's refusal `stop_details` can hold `fallback_credit_token`
|
|
804
804
|
// (top level and per fallback), so every key of that name is deleted at any
|
|
805
805
|
// depth; everything else is kept verbatim.
|
|
@@ -830,7 +830,7 @@ function toolResultText(content) {
|
|
|
830
830
|
return joined !== "" ? joined : undefined;
|
|
831
831
|
}
|
|
832
832
|
// The namespace of the facet's own harness keys on a tool.done `_meta` (the
|
|
833
|
-
// subagent report's "anthropic/agentOutput",
|
|
833
|
+
// subagent report's "anthropic/agentOutput", the CLI's "anthropic/toolResultMeta",
|
|
834
834
|
// and since draft.5 the two host records below). SPEC §2.1 *Host records*: a
|
|
835
835
|
// producer carries such a record under a key in a namespace it owns.
|
|
836
836
|
const HARNESS_META_PREFIX = "anthropic/";
|
|
@@ -848,7 +848,7 @@ const PERMISSION_DENIED_META_KEY = `${HARNESS_META_PREFIX}permissionDenied`;
|
|
|
848
848
|
// written, so a tool (a malicious MCP server) can never present a forged
|
|
849
849
|
// harness fact, such as an agent report or a remedy pointing a host at its URL,
|
|
850
850
|
// even for a call the facet writes no harness key for (a review of the
|
|
851
|
-
//
|
|
851
|
+
// tool_result_meta carry; the CLI itself strips its own reserved `com.anthropic/` prefix
|
|
852
852
|
// from server `_meta`). Every other sibling key is kept verbatim. undefined
|
|
853
853
|
// when nothing remains.
|
|
854
854
|
function mergeHarnessMeta(sibling, harness) {
|
|
@@ -1209,10 +1209,10 @@ function mintInvokeNonce() {
|
|
|
1209
1209
|
*/
|
|
1210
1210
|
function createInnerClaudeNormalizer(options, invokeStem) {
|
|
1211
1211
|
const a = new StreamAssembler();
|
|
1212
|
-
//
|
|
1212
|
+
// A reference host's fold-identity check: the wire-visible `parentTurnId`
|
|
1213
1213
|
// label passed to subagent.start/.done (`turn_${parent_tool_use_id}`) is a
|
|
1214
1214
|
// synthetic cross-ref that was never opened as a real turn — it must stay on
|
|
1215
|
-
// the wire (
|
|
1215
|
+
// the wire (a reference host asserts `parentTurnId === 'turn_<toolCallId>'`)
|
|
1216
1216
|
// but must NOT be reused to route an INNER tool_result's turnId. Track the
|
|
1217
1217
|
// REAL subagent turnId per spawning parent_tool_use_id, derived from the
|
|
1218
1218
|
// sub-session's own assistant arm at subagent.start time, so a later inner
|
|
@@ -1237,7 +1237,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
1237
1237
|
// message id opens its turn under its own frame uuid instead;
|
|
1238
1238
|
// - `isSDKMessage` validates only discriminants, so a missing or non-string
|
|
1239
1239
|
// id/uuid falls back to a positional `turn_<stem>_frame_<n>` rather than a
|
|
1240
|
-
// shared `turn_undefined`. The stem is per invoke (
|
|
1240
|
+
// shared `turn_undefined`. The stem is per invoke (§8.0 ids across invokes: a bare
|
|
1241
1241
|
// `turn_frame_<n>` repeated across the invokes one Reducer folds), and the
|
|
1242
1242
|
// counter is deterministic from the wire, so an atomic-push rebuild
|
|
1243
1243
|
// reproduces every delivered id.
|
|
@@ -1280,7 +1280,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
1280
1280
|
}
|
|
1281
1281
|
// The result frame closes the open turn (or, for a result-only turn, the one
|
|
1282
1282
|
// it opens itself) and clears it. A RESULT-ONLY turn (no assistant frame,
|
|
1283
|
-
// notice or stream opened it: the
|
|
1283
|
+
// notice or stream opened it: the result-only API-error path, a
|
|
1284
1284
|
// startup-failure result, a local-command result) is OPENED here with an
|
|
1285
1285
|
// explicit turn.start before anything else the result emits (INV-TURN,
|
|
1286
1286
|
// SPEC:743: every turn is opened by exactly one turn.start and closed by
|
|
@@ -1306,7 +1306,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
1306
1306
|
// session into one nested turn (and, if a subagent's frames carry the
|
|
1307
1307
|
// parent's session_id, collided with the top-level turn itself). It must
|
|
1308
1308
|
// never equal the synthetic `parentTurnId` label `turn_${parent_tool_use_id}`
|
|
1309
|
-
// (
|
|
1309
|
+
// (a reference host's fold-identity check), and a message id never does.
|
|
1310
1310
|
function nestedTurnId(parentToolUseId, firstMessageId, frameUuid) {
|
|
1311
1311
|
const known = subagentTurnByParentToolUseId.get(parentToolUseId);
|
|
1312
1312
|
if (known !== undefined && !closedRuns.has(parentToolUseId))
|
|
@@ -1387,12 +1387,12 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
1387
1387
|
// Every toolCallId that already got its FINAL tool.done in this invoke. The
|
|
1388
1388
|
// result's permission_denials aggregate skips these: re-emitting tool.start +
|
|
1389
1389
|
// tool.done{denied} for a call already closed is a duplicate start and a second
|
|
1390
|
-
// final tool.done (INV-BLOCK
|
|
1390
|
+
// final tool.done (INV-BLOCK: the reducer parks it as a double fold).
|
|
1391
1391
|
const closedToolCallIds = new Set();
|
|
1392
1392
|
// SDK message id → the `diagnostics` value already carried for it (see the
|
|
1393
1393
|
// assistant branch): one carry per response, not one per frame.
|
|
1394
1394
|
const diagnosticsCarried = new Map();
|
|
1395
|
-
//
|
|
1395
|
+
// Top-level turnId → the closing response's non-null stop_details (credit
|
|
1396
1396
|
// tokens stripped) and the message it describes, emitted on that turn's turn.done.
|
|
1397
1397
|
const stopDetailsByTurn = new Map();
|
|
1398
1398
|
// The live denial's diagnostic fields, camelCased — the record under
|
|
@@ -1415,7 +1415,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
1415
1415
|
};
|
|
1416
1416
|
}
|
|
1417
1417
|
const stashedTurnErrors = new Map();
|
|
1418
|
-
/** Remove and return the stashed error close for `turnId`, if any
|
|
1418
|
+
/** Remove and return the stashed error close for `turnId`, if any. */
|
|
1419
1419
|
function takeStashedTurnError(turnId) {
|
|
1420
1420
|
const stashed = stashedTurnErrors.get(turnId);
|
|
1421
1421
|
stashedTurnErrors.delete(turnId);
|
|
@@ -1586,7 +1586,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
1586
1586
|
}
|
|
1587
1587
|
// The stream arm proper. Partials map onto the SAME lifecycles the complete
|
|
1588
1588
|
// arm produces: message_start opens the SAME PendingMessage the complete
|
|
1589
|
-
// frame later joins (
|
|
1589
|
+
// frame later joins (the split-frame continuation test), and block ids reuse the
|
|
1590
1590
|
// stream's own content `index` — which equals the complete arm's cross-frame
|
|
1591
1591
|
// `blockIndex` arithmetic, so ids are identical either way.
|
|
1592
1592
|
function driveStreamEvent(msg) {
|
|
@@ -1658,7 +1658,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
1658
1658
|
return;
|
|
1659
1659
|
}
|
|
1660
1660
|
if (ev.type === "message_stop") {
|
|
1661
|
-
// The seal stays DEFERRED (
|
|
1661
|
+
// The seal stays DEFERRED (INV-MSG) while the lifecycle is
|
|
1662
1662
|
// open: the complete assistant frame for this id follows and joins it,
|
|
1663
1663
|
// and tool_results may still bind. And when the lifecycle is ALREADY
|
|
1664
1664
|
// sealed — the live wire delivers the tool_result BEFORE the tool-round
|
|
@@ -1812,7 +1812,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
1812
1812
|
// on start events, so the estimate is now LIVE-ONLY (it used to fold
|
|
1813
1813
|
// last-value-wins onto the reasoning block) — the same standing as its
|
|
1814
1814
|
// `system/thinking_tokens` twin, which rides `ext.anthropic.frame`. No
|
|
1815
|
-
// consumer read the folded value (
|
|
1815
|
+
// consumer read the folded value (both reference consumers checked).
|
|
1816
1816
|
// `reasoningDelta`'s sugar has no `_meta` option; `a.emit()` is the base
|
|
1817
1817
|
// primitive (the reasoning.start precedent in `emitAssistantBlock`), and
|
|
1818
1818
|
// the sugar's only extra step, de-cumulation, is a pass-through for a
|
|
@@ -1992,7 +1992,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
1992
1992
|
? nestedTurnId(msg.parent_tool_use_id, m.id, msg.uuid)
|
|
1993
1993
|
: topTurnId(m.id, msg.uuid);
|
|
1994
1994
|
const parentTurnId = msg.parent_tool_use_id !== null ? `turn_${msg.parent_tool_use_id}` : undefined;
|
|
1995
|
-
//
|
|
1995
|
+
// INV-MSG: does this frame CONTINUE the message left open by the previous
|
|
1996
1996
|
// frame? Same SDK message id, same turn, same nesting — anything else is a
|
|
1997
1997
|
// new message and seals the open one first (unchanged emission order).
|
|
1998
1998
|
const continued = pending !== undefined &&
|
|
@@ -2136,7 +2136,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2136
2136
|
if (assistantApiErrorCode !== undefined) {
|
|
2137
2137
|
wrapperMetaRaw["api_error_code"] = assistantApiErrorCode;
|
|
2138
2138
|
}
|
|
2139
|
-
//
|
|
2139
|
+
// Ruled 2026-09-24 (defer the neutral remedy field, fix the
|
|
2140
2140
|
// vendor carries; a 0.7.0 carry with zero golden moves). Three more
|
|
2141
2141
|
// @internal CLI 2.1.280 assistant-wrapper strings, UNDECLARED in sdk.d.ts
|
|
2142
2142
|
// 0.3.280 (so read through the JSON boundary), carried verbatim under their
|
|
@@ -2164,7 +2164,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2164
2164
|
// A non-null parent_tool_use_id ⇒ this assistant message belongs to a
|
|
2165
2165
|
// NESTED turn (subagent run). subagent.start is the SOLE nested-turn opener
|
|
2166
2166
|
// (spec §4/§5), emitted once per run by `openRun`, and seeds the turn so
|
|
2167
|
-
// openMessage does NOT synthesize a duplicate turn.start.
|
|
2167
|
+
// openMessage does NOT synthesize a duplicate turn.start. INV-MSG: a
|
|
2168
2168
|
// CONTINUATION frame joins the message the previous frame opened — no
|
|
2169
2169
|
// second message.start.
|
|
2170
2170
|
let open;
|
|
@@ -2210,7 +2210,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2210
2210
|
});
|
|
2211
2211
|
}
|
|
2212
2212
|
const messageId = open.emittedId;
|
|
2213
|
-
//
|
|
2213
|
+
// A NON-NULL `stop_details` on a response (e.g. a refusal's
|
|
2214
2214
|
// {type: "refusal", category, explanation}, the shape @anthropic-ai/sdk
|
|
2215
2215
|
// 0.93.0 declares; any further member is kept too) is carried verbatim on its
|
|
2216
2216
|
// turn's closing turn.done.messageMetadata, which folds onto the message it
|
|
@@ -2283,9 +2283,9 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2283
2283
|
// `message.metadata` event after the block (the streamed path already
|
|
2284
2284
|
// carries the turn-binding family there).
|
|
2285
2285
|
//
|
|
2286
|
-
// Consumer check (2026-09-23):
|
|
2287
|
-
//
|
|
2288
|
-
// the native frame.
|
|
2286
|
+
// Consumer check (2026-09-23): a reference client has none of these
|
|
2287
|
+
// names; a reference host reads no `providerMetadata`, and its scrub keys
|
|
2288
|
+
// on the native frame. That host asked that the triad move as ONE unit; the
|
|
2289
2289
|
// result frame's `apiErrorCode` stays on `ext.anthropic.result-meta`.
|
|
2290
2290
|
const replayRaw = {};
|
|
2291
2291
|
const hostRaw = {};
|
|
@@ -2314,7 +2314,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2314
2314
|
const narrationIndexes = new Set(narrationBlockIndexes ?? []);
|
|
2315
2315
|
if (suppressed && narrationIndexes.size > 0) {
|
|
2316
2316
|
// STREAMED: the complete frame precedes its blocks' content_block_stop
|
|
2317
|
-
// (
|
|
2317
|
+
// (thinking-fable51 frames [62] signature → [63] frame → [64]
|
|
2318
2318
|
// stop), so each listed frame-local index names stream block
|
|
2319
2319
|
// `framedThrough + idx` (the frame covers the next blocks after those
|
|
2320
2320
|
// earlier frames covered). It is marked only while it is still OPEN;
|
|
@@ -2330,7 +2330,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2330
2330
|
}
|
|
2331
2331
|
if (suppressed) {
|
|
2332
2332
|
// STREAMED: record each open tool block's `wire_tool_inputs` entry (the
|
|
2333
|
-
// complete frame precedes the block's content_block_stop
|
|
2333
|
+
// complete frame precedes the block's content_block_stop); its
|
|
2334
2334
|
// tool.args.assembled carries it only if it differs from the streamed input.
|
|
2335
2335
|
for (let i = 0; i < m.content.length; i++) {
|
|
2336
2336
|
const frameBlock = m.content[i];
|
|
@@ -2400,7 +2400,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2400
2400
|
a.emit({ type: "message.metadata", messageId, metadata: unanchored });
|
|
2401
2401
|
}
|
|
2402
2402
|
}
|
|
2403
|
-
// The seal is DEFERRED (
|
|
2403
|
+
// The seal is DEFERRED (INV-MSG) — the next frame may continue this same
|
|
2404
2404
|
// message id. Usage is message-level and repeated per frame, so the newest
|
|
2405
2405
|
// frame's copy is the one that rides the eventual `message.end` — field by
|
|
2406
2406
|
// field: `mapMessageUsage` names every field it maps explicitly (absent ⇒
|
|
@@ -2414,7 +2414,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2414
2414
|
open.rawInput = nativeInput(open.rawInput, m.usage);
|
|
2415
2415
|
// If the assistant turn carries an error signal (rate_limit, billing_error, etc.),
|
|
2416
2416
|
// the turn ends as a turn.error so consumers see the error rather than a
|
|
2417
|
-
// silent empty turn.
|
|
2417
|
+
// silent empty turn. The close is STASHED, not emitted here — the
|
|
2418
2418
|
// turn's result frame (which carries the turn's usage) emits it, or
|
|
2419
2419
|
// `flush()` does if no result ever arrives (see `stashedTurnErrors`).
|
|
2420
2420
|
if (msg.error !== undefined) {
|
|
@@ -2446,12 +2446,12 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2446
2446
|
}
|
|
2447
2447
|
else if (!stashedTurnErrors.has(turnId)) {
|
|
2448
2448
|
// First error frame wins: a turn already carrying a stashed close keeps
|
|
2449
|
-
// it (before
|
|
2449
|
+
// it (through 0.6.2, before the stash, the first error frame closed the turn).
|
|
2450
2450
|
stashedTurnErrors.set(turnId, { message: errCode, code: errCode, retriable });
|
|
2451
2451
|
}
|
|
2452
2452
|
}
|
|
2453
2453
|
// `subagent.done` is NOT emitted here: it brackets the RUN (see `openRun`),
|
|
2454
|
-
// and this message's seal is deferred (
|
|
2454
|
+
// and this message's seal is deferred (INV-MSG) until nothing can continue it.
|
|
2455
2455
|
// Record this frame's own uuid → the messageId it produced, so a LATER
|
|
2456
2456
|
// retraction naming this uuid can translate it (Finding #1). The EMITTED
|
|
2457
2457
|
// id, so a retraction still names the message that actually exists on the
|
|
@@ -2483,7 +2483,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2483
2483
|
// sibling, read here for live frames, is no longer read on replays.
|
|
2484
2484
|
if ("isReplay" in msg && msg.isReplay === true)
|
|
2485
2485
|
return;
|
|
2486
|
-
//
|
|
2486
|
+
// INV-MSG: a tool_result binds to the fold, and a COMPLETE-mode message
|
|
2487
2487
|
// is sealed first, exactly as the per-frame close used to. A STREAMED
|
|
2488
2488
|
// message is never sealed by a live user frame: its native boundary is its
|
|
2489
2489
|
// own stream (message_stop, with the complete assistant frames that join
|
|
@@ -2599,11 +2599,11 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2599
2599
|
// started mid-run: a background agent spanning invokes, a resume):
|
|
2600
2600
|
// open a fresh run named by this frame, so its tool.done lands in a
|
|
2601
2601
|
// turn that subagent.start opened (INV-TURN) and B-strict closes.
|
|
2602
|
-
// Through 0.7.0
|
|
2603
|
-
//
|
|
2604
|
-
// loudly"): a turn
|
|
2605
|
-
//
|
|
2606
|
-
//
|
|
2602
|
+
// Through 0.7.0 (whose cross-invoke fix covered the fallback stem
|
|
2603
|
+
// only) the never-opened case named the synthetic
|
|
2604
|
+
// `turn_<parent_tool_use_id>` label instead ("park loudly"): a turn
|
|
2605
|
+
// nobody opened, whose id REPEATED across the invokes one Reducer
|
|
2606
|
+
// folds (§8.0 "Ids across invokes"), and it parked.
|
|
2607
2607
|
toolTurnId = nestedTurnId(parentToolUseId, undefined, msg.uuid);
|
|
2608
2608
|
openRun(parentToolUseId, toolTurnId, `turn_${parentToolUseId}`);
|
|
2609
2609
|
}
|
|
@@ -2611,7 +2611,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2611
2611
|
else {
|
|
2612
2612
|
toolTurnId = openTopTurnId;
|
|
2613
2613
|
}
|
|
2614
|
-
// tool_use_result sibling (SDK-injected rich MCP result
|
|
2614
|
+
// tool_use_result sibling (SDK-injected rich MCP result): carries
|
|
2615
2615
|
// structuredContent (incl. render-cache markers) + _meta.ui the block-level
|
|
2616
2616
|
// arm never sees. Applies only when the message has exactly ONE tool_result
|
|
2617
2617
|
// block (the sibling is message-level; multi-result attribution is ambiguous —
|
|
@@ -2716,10 +2716,10 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2716
2716
|
outcome,
|
|
2717
2717
|
...(denied ? {} : { isError: block.is_error === true }),
|
|
2718
2718
|
turnId: toolTurnId,
|
|
2719
|
-
// SPEC §5 tool.done adoption
|
|
2719
|
+
// SPEC §5 tool.done adoption: the Claude SDK
|
|
2720
2720
|
// closes the assistant message (message.end) BEFORE this tool_result
|
|
2721
2721
|
// arrives, so a messageId-less toolDone here has no open message to
|
|
2722
|
-
// attach to and parks the fold (
|
|
2722
|
+
// attach to and parks the fold (a reference host's fold-identity check caught
|
|
2723
2723
|
// this on a real claude tool conversation). A stable derived
|
|
2724
2724
|
// messageId engages the reducer's adoption path instead: the result
|
|
2725
2725
|
// lands in its OWN dedicated role:"tool" message.
|
|
@@ -2740,7 +2740,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2740
2740
|
// The facet's harness keys ride the same `_meta`, MERGED into the MCP
|
|
2741
2741
|
// sibling's `_meta` (never replacing it), so they fold with the
|
|
2742
2742
|
// tool-result block: the Agent run report ("anthropic/agentOutput"),
|
|
2743
|
-
//
|
|
2743
|
+
// the CLI's `tool_result_meta` entry ("anthropic/toolResultMeta"),
|
|
2744
2744
|
// and the draft.5 host records, the MCP `resourceLinks` list and the
|
|
2745
2745
|
// live denial's context. The "anthropic/" namespace is the
|
|
2746
2746
|
// harness's own: see `mergeHarnessMeta`. This tool.done carries no
|
|
@@ -2767,14 +2767,14 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2767
2767
|
return;
|
|
2768
2768
|
}
|
|
2769
2769
|
if (msg.type === "result" && msg.subtype === "success") {
|
|
2770
|
-
//
|
|
2770
|
+
// INV-MSG: the turn is closing — seal the open assistant message first
|
|
2771
2771
|
// (message.end has always preceded the turn close).
|
|
2772
2772
|
closePendingMessage();
|
|
2773
2773
|
// B-strict: a subagent run still open (a background or unreported sub-run)
|
|
2774
2774
|
// is NOT closed by its parent's result; it closes when the framework
|
|
2775
2775
|
// reports it, or at flush.
|
|
2776
2776
|
const turnId = closingTopTurnId(msg.uuid, msg.session_id, msg.user_message_uuid);
|
|
2777
|
-
//
|
|
2777
|
+
// Since 0.6.3 (claude-agent-sdk 0.3.280): `subtype: "success"` does NOT mean the turn
|
|
2778
2778
|
// succeeded. Upstream's SDKResultMessage doc: "subtype "success" carries
|
|
2779
2779
|
// the final assistant text in result — or, with is_error true, the error
|
|
2780
2780
|
// text when the turn ended on an API error". The CLI sets is_error from
|
|
@@ -2802,14 +2802,14 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2802
2802
|
const structuredOutput = msg.structured_output !== undefined ? JsonValue.parse(msg.structured_output) : undefined;
|
|
2803
2803
|
// Emit permission_denials as tool.start + tool.done denied pairs, inside a
|
|
2804
2804
|
// dedicated carrier message: the assistant message is already sealed, and
|
|
2805
|
-
// INV-MSG
|
|
2806
|
-
//
|
|
2805
|
+
// INV-MSG forbids attaching to sealed messages / closed turns.
|
|
2806
|
+
// An API-error turn's denials take this same carrier, at the same
|
|
2807
2807
|
// point — its close is deferred to this frame (below), so the turn is
|
|
2808
2808
|
// still open here, like every other turn.
|
|
2809
2809
|
emitDenialsCarrier(turnId, msg.permission_denials, msg.session_id);
|
|
2810
2810
|
// 0.3.220: fast_mode_disabled_reason + per-model canonicalModel/provider
|
|
2811
2811
|
// ride `ext.anthropic.result-meta` before the close (no core home on
|
|
2812
|
-
// turn.done — see resultMetaPayload's doc).
|
|
2812
|
+
// turn.done — see resultMetaPayload's doc). It is emitted on an
|
|
2813
2813
|
// API-error turn too, before its close like on every other turn.
|
|
2814
2814
|
const resultMeta = resultMetaPayload(msg, stashedError !== undefined || apiErrorTurn);
|
|
2815
2815
|
if (resultMeta !== undefined) {
|
|
@@ -2866,7 +2866,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2866
2866
|
// exactly what "paused" names). The result-meta deferredToolUse carry stays.
|
|
2867
2867
|
// A later invoke that resumes the call opens its own turn, minted from its
|
|
2868
2868
|
// own frames (INV-XINV). Never keyed on terminal_reason. An is_error result
|
|
2869
|
-
// never reaches here: it closed above as turn.error
|
|
2869
|
+
// never reaches here: it closed above as turn.error, and so did a
|
|
2870
2870
|
// turn an API-error frame decided; the deferred tool found unavailable on
|
|
2871
2871
|
// resume ("tool_deferred_unavailable") is such an is_error close.
|
|
2872
2872
|
const deferredCall = readDeferredCall(msg);
|
|
@@ -2900,10 +2900,10 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2900
2900
|
}
|
|
2901
2901
|
if (msg.type === "result") {
|
|
2902
2902
|
// At this point msg.subtype can only be an error variant (success handled above).
|
|
2903
|
-
//
|
|
2903
|
+
// INV-MSG: seal the open assistant message before the turn close.
|
|
2904
2904
|
closePendingMessage();
|
|
2905
2905
|
const turnId = closingTopTurnId(msg.uuid, msg.session_id);
|
|
2906
|
-
//
|
|
2906
|
+
// Consume any stashed assistant-error close for this turnId — this
|
|
2907
2907
|
// frame emits it (below). Each turn has its own id now, so an entry can
|
|
2908
2908
|
// only ever be this turn's.
|
|
2909
2909
|
const stashedError = takeStashedTurnError(turnId);
|
|
@@ -2913,7 +2913,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2913
2913
|
// not throw (Tenet 6: graceful, never throws).
|
|
2914
2914
|
const errors = Array.isArray(msg.errors) ? msg.errors : [];
|
|
2915
2915
|
const subtype = typeof msg.subtype === "string" ? msg.subtype : "error_unknown";
|
|
2916
|
-
//
|
|
2916
|
+
// Since claude-agent-sdk 0.3.274: a known startup failure says why the CLI refused to
|
|
2917
2917
|
// start, and upstream frames it as "offer the fix instead of a retry" —
|
|
2918
2918
|
// so a PRESENT reason decides retriable (false, except the values upstream
|
|
2919
2919
|
// itself calls retriable; see `startupFailureRetriable`). An ABSENT reason
|
|
@@ -2940,7 +2940,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2940
2940
|
a.emitExt("anthropic", "result-meta", resultMeta);
|
|
2941
2941
|
}
|
|
2942
2942
|
if (stashedError !== undefined) {
|
|
2943
|
-
//
|
|
2943
|
+
// An assistant error frame already decided this turn's close —
|
|
2944
2944
|
// emit THAT one (the first error that ended the turn), once, never a
|
|
2945
2945
|
// second turn.error for the same turnId (INV-TURN), with this frame's
|
|
2946
2946
|
// usage (the success arm's mapping). This arm is only
|
|
@@ -2995,7 +2995,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
2995
2995
|
// `retractUuids`'s doc); also the ONLY retraction path when a consumer
|
|
2996
2996
|
// never observed (or a normalizer instance never processed) the
|
|
2997
2997
|
// superseding assistant frame's own `supersedes` field directly.
|
|
2998
|
-
//
|
|
2998
|
+
// INV-MSG: a retraction can name the still-open message — seal it first so
|
|
2999
2999
|
// `message.end` never trails its own `message.remove`.
|
|
3000
3000
|
closePendingMessage();
|
|
3001
3001
|
const uuids = Array.isArray(msg.retracted_message_uuids) ? msg.retracted_message_uuids : [];
|
|
@@ -3129,7 +3129,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
3129
3129
|
return a.drain();
|
|
3130
3130
|
},
|
|
3131
3131
|
flush() {
|
|
3132
|
-
//
|
|
3132
|
+
// INV-MSG: nothing can continue the deferred message now — seal it with
|
|
3133
3133
|
// its real usage rather than leaving INV-FLUSH to synthesize a bare
|
|
3134
3134
|
// `message.end`. At flush: no content is minted (INV-FLUSH (3), C1).
|
|
3135
3135
|
closePendingMessage(true);
|
|
@@ -3137,7 +3137,7 @@ function createInnerClaudeNormalizer(options, invokeStem) {
|
|
|
3137
3137
|
// terminal (turn.abort{stream-truncated}, or its stashed API error) and
|
|
3138
3138
|
// its subagent.done, innermost first.
|
|
3139
3139
|
abortOpenRuns();
|
|
3140
|
-
//
|
|
3140
|
+
// A turn whose assistant error frame stashed its close but whose
|
|
3141
3141
|
// result frame never arrived still closes as that turn.error (no usage:
|
|
3142
3142
|
// only a result carries the turn's), never as INV-FLUSH's synthesized
|
|
3143
3143
|
// turn.abort — the outcome the frame's own close used to produce.
|