claude-code-rust 0.14.3 → 0.14.5
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 +3 -4
- package/agent-sdk/dist/bridge/account_metadata.js +6 -2
- package/agent-sdk/dist/bridge/agents.js +9 -3
- package/agent-sdk/dist/bridge/available_commands.js +13 -3
- package/agent-sdk/dist/bridge/command_lifecycle.js +79 -4
- package/agent-sdk/dist/bridge/command_scheduler.js +7 -2
- package/agent-sdk/dist/bridge/command_session_control.js +5 -1
- package/agent-sdk/dist/bridge/command_session_data.js +225 -10
- package/agent-sdk/dist/bridge/commands.js +48 -11
- package/agent-sdk/dist/bridge/error_classification.js +6 -1
- package/agent-sdk/dist/bridge/events.js +45 -7
- package/agent-sdk/dist/bridge/history.js +34 -10
- package/agent-sdk/dist/bridge/logger.js +19 -3
- package/agent-sdk/dist/bridge/mcp.js +7 -2
- package/agent-sdk/dist/bridge/mcp_auth_adapter.js +4 -2
- package/agent-sdk/dist/bridge/mcp_metadata.js +113 -39
- package/agent-sdk/dist/bridge/mcp_monitor.js +6 -1
- package/agent-sdk/dist/bridge/message_handlers.js +324 -66
- package/agent-sdk/dist/bridge/model_metadata.js +19 -6
- package/agent-sdk/dist/bridge/permissions.js +32 -8
- package/agent-sdk/dist/bridge/session_lifecycle.js +234 -52
- package/agent-sdk/dist/bridge/state_parsing.js +23 -8
- package/agent-sdk/dist/bridge/tasks.js +63 -22
- package/agent-sdk/dist/bridge/tool_calls.js +82 -25
- package/agent-sdk/dist/bridge/tooling.js +311 -88
- package/agent-sdk/dist/bridge/user_interaction.js +45 -13
- package/agent-sdk/dist/bridge.js +200 -104
- package/package.json +8 -8
|
@@ -72,7 +72,9 @@ function jsonRecord(value) {
|
|
|
72
72
|
: undefined;
|
|
73
73
|
}
|
|
74
74
|
function nonEmptyString(value) {
|
|
75
|
-
return typeof value === "string" && value.trim().length > 0
|
|
75
|
+
return typeof value === "string" && value.trim().length > 0
|
|
76
|
+
? value
|
|
77
|
+
: undefined;
|
|
76
78
|
}
|
|
77
79
|
function stringArray(value) {
|
|
78
80
|
if (!Array.isArray(value)) {
|
|
@@ -200,7 +202,9 @@ function humanizeFieldLabel(key) {
|
|
|
200
202
|
if (word === "id") {
|
|
201
203
|
return "ID";
|
|
202
204
|
}
|
|
203
|
-
return index === 0
|
|
205
|
+
return index === 0
|
|
206
|
+
? `${word.charAt(0).toUpperCase()}${word.slice(1)}`
|
|
207
|
+
: word;
|
|
204
208
|
})
|
|
205
209
|
.join(" ");
|
|
206
210
|
}
|
|
@@ -210,7 +214,9 @@ function displayScalarValue(value) {
|
|
|
210
214
|
if (!trimmed) {
|
|
211
215
|
return undefined;
|
|
212
216
|
}
|
|
213
|
-
return /^[a-z][a-z0-9]*(?:_[a-z0-9]+)+$/u.test(trimmed)
|
|
217
|
+
return /^[a-z][a-z0-9]*(?:_[a-z0-9]+)+$/u.test(trimmed)
|
|
218
|
+
? trimmed.replace(/_/g, " ")
|
|
219
|
+
: trimmed;
|
|
214
220
|
}
|
|
215
221
|
if (typeof value === "boolean") {
|
|
216
222
|
return value ? "yes" : "no";
|
|
@@ -224,13 +230,17 @@ function decodeXmlText(value) {
|
|
|
224
230
|
return value.replace(/&(?:#(\d+)|#x([0-9a-fA-F]+)|amp|lt|gt|quot|apos);/g, (match, dec, hex) => {
|
|
225
231
|
if (typeof dec === "string" && dec.length > 0) {
|
|
226
232
|
const codePoint = Number.parseInt(dec, 10);
|
|
227
|
-
return Number.isInteger(codePoint) &&
|
|
233
|
+
return Number.isInteger(codePoint) &&
|
|
234
|
+
codePoint >= 0 &&
|
|
235
|
+
codePoint <= 0x10ffff
|
|
228
236
|
? String.fromCodePoint(codePoint)
|
|
229
237
|
: match;
|
|
230
238
|
}
|
|
231
239
|
if (typeof hex === "string" && hex.length > 0) {
|
|
232
240
|
const codePoint = Number.parseInt(hex, 16);
|
|
233
|
-
return Number.isInteger(codePoint) &&
|
|
241
|
+
return Number.isInteger(codePoint) &&
|
|
242
|
+
codePoint >= 0 &&
|
|
243
|
+
codePoint <= 0x10ffff
|
|
234
244
|
? String.fromCodePoint(codePoint)
|
|
235
245
|
: match;
|
|
236
246
|
}
|
|
@@ -242,7 +252,7 @@ function decodeXmlText(value) {
|
|
|
242
252
|
case ">":
|
|
243
253
|
return ">";
|
|
244
254
|
case """:
|
|
245
|
-
return "
|
|
255
|
+
return '"';
|
|
246
256
|
case "'":
|
|
247
257
|
return "'";
|
|
248
258
|
default:
|
|
@@ -261,7 +271,9 @@ function xmlLeafFields(text) {
|
|
|
261
271
|
break;
|
|
262
272
|
}
|
|
263
273
|
const [, key, rawValue] = match;
|
|
264
|
-
if (!key ||
|
|
274
|
+
if (!key ||
|
|
275
|
+
rawValue === undefined ||
|
|
276
|
+
/<[A-Za-z][\w.-]{0,79}[\s>]/u.test(rawValue)) {
|
|
265
277
|
continue;
|
|
266
278
|
}
|
|
267
279
|
const value = decodeXmlText(rawValue).trim();
|
|
@@ -277,7 +289,8 @@ function firstTaskRecord(candidates) {
|
|
|
277
289
|
if (nestedTask && typeof nestedTask.id === "string") {
|
|
278
290
|
return nestedTask;
|
|
279
291
|
}
|
|
280
|
-
if (typeof candidate.id === "string" &&
|
|
292
|
+
if (typeof candidate.id === "string" &&
|
|
293
|
+
typeof candidate.subject === "string") {
|
|
281
294
|
return candidate;
|
|
282
295
|
}
|
|
283
296
|
}
|
|
@@ -287,7 +300,8 @@ function firstRecordWithTaskProperty(candidates) {
|
|
|
287
300
|
return candidates.find((candidate) => Object.hasOwn(candidate, "task"));
|
|
288
301
|
}
|
|
289
302
|
function firstTaskUpdateOutput(candidates) {
|
|
290
|
-
return candidates.find((candidate) => typeof candidate.success === "boolean" &&
|
|
303
|
+
return candidates.find((candidate) => typeof candidate.success === "boolean" &&
|
|
304
|
+
typeof candidate.taskId === "string");
|
|
291
305
|
}
|
|
292
306
|
function firstTaskListOutput(candidates) {
|
|
293
307
|
return candidates.find((candidate) => Array.isArray(candidate.tasks));
|
|
@@ -449,7 +463,9 @@ function taskCreatePatch(taskRecord, input, toolUseId) {
|
|
|
449
463
|
const metadata = jsonValue(input.metadata);
|
|
450
464
|
return {
|
|
451
465
|
task_id: taskId,
|
|
452
|
-
subject: nonEmptyString(taskRecord.subject) ??
|
|
466
|
+
subject: nonEmptyString(taskRecord.subject) ??
|
|
467
|
+
nonEmptyString(input.subject) ??
|
|
468
|
+
taskId,
|
|
453
469
|
description: nonEmptyString(input.description),
|
|
454
470
|
active_form: nonEmptyString(input.activeForm),
|
|
455
471
|
status: "pending",
|
|
@@ -462,7 +478,8 @@ function taskCreatePatch(taskRecord, input, toolUseId) {
|
|
|
462
478
|
function taskUpdatePatch(session, taskId, input, output) {
|
|
463
479
|
const existing = session.tasksById.get(taskId);
|
|
464
480
|
const metadata = mergeMetadata(existing?.metadata, jsonRecord(input.metadata));
|
|
465
|
-
const status = normalizeTaskStatus(input.status) ??
|
|
481
|
+
const status = normalizeTaskStatus(input.status) ??
|
|
482
|
+
normalizeTaskStatus(asRecordOrNull(output.statusChange)?.to);
|
|
466
483
|
const addBlocks = stringArray(input.addBlocks);
|
|
467
484
|
const addBlockedBy = stringArray(input.addBlockedBy);
|
|
468
485
|
const patch = {
|
|
@@ -472,7 +489,9 @@ function taskUpdatePatch(session, taskId, input, output) {
|
|
|
472
489
|
active_form: nonEmptyString(input.activeForm),
|
|
473
490
|
status,
|
|
474
491
|
owner: nonEmptyString(input.owner),
|
|
475
|
-
blocks: addBlocks.length > 0
|
|
492
|
+
blocks: addBlocks.length > 0
|
|
493
|
+
? uniqueStrings([...(existing?.blocks ?? []), ...addBlocks])
|
|
494
|
+
: undefined,
|
|
476
495
|
blocked_by: addBlockedBy.length > 0
|
|
477
496
|
? uniqueStrings([...(existing?.blocked_by ?? []), ...addBlockedBy])
|
|
478
497
|
: undefined,
|
|
@@ -573,7 +592,9 @@ function taskStatusMarker(status) {
|
|
|
573
592
|
}
|
|
574
593
|
}
|
|
575
594
|
function taskRecordLine(record) {
|
|
576
|
-
const subject = typeof record.subject === "string" && record.subject.trim()
|
|
595
|
+
const subject = typeof record.subject === "string" && record.subject.trim()
|
|
596
|
+
? record.subject
|
|
597
|
+
: "Task";
|
|
577
598
|
return `${taskStatusMarker(record.status)} ${subject}`;
|
|
578
599
|
}
|
|
579
600
|
function taskListWindow(lines) {
|
|
@@ -604,7 +625,9 @@ export function taskToolResultText(toolName, rawResult, rawContent, rawInput) {
|
|
|
604
625
|
return "";
|
|
605
626
|
}
|
|
606
627
|
if (output.success !== true) {
|
|
607
|
-
const error = typeof output.error === "string" && output.error.trim()
|
|
628
|
+
const error = typeof output.error === "string" && output.error.trim()
|
|
629
|
+
? output.error
|
|
630
|
+
: "Task update failed";
|
|
608
631
|
return error;
|
|
609
632
|
}
|
|
610
633
|
return "";
|
|
@@ -663,7 +686,8 @@ export function taskToolResultText(toolName, rawResult, rawContent, rawInput) {
|
|
|
663
686
|
return "";
|
|
664
687
|
}
|
|
665
688
|
export function taskUpdateSucceeded(rawResult, rawContent) {
|
|
666
|
-
return firstTaskUpdateOutput(resultCandidates(rawResult, rawContent))
|
|
689
|
+
return firstTaskUpdateOutput(resultCandidates(rawResult, rawContent))
|
|
690
|
+
?.success;
|
|
667
691
|
}
|
|
668
692
|
export function applyTaskToolResult(session, toolUseId, isError, rawContent, rawResult) {
|
|
669
693
|
if (isError) {
|
|
@@ -678,7 +702,9 @@ export function applyTaskToolResult(session, toolUseId, isError, rawContent, raw
|
|
|
678
702
|
const candidates = resultCandidates(rawResult, rawContent);
|
|
679
703
|
if (toolName === "TaskCreate") {
|
|
680
704
|
const taskRecord = firstTaskRecord(candidates);
|
|
681
|
-
const patch = taskRecord
|
|
705
|
+
const patch = taskRecord
|
|
706
|
+
? taskCreatePatch(taskRecord, input, toolUseId)
|
|
707
|
+
: undefined;
|
|
682
708
|
if (!patch) {
|
|
683
709
|
return;
|
|
684
710
|
}
|
|
@@ -730,7 +756,9 @@ export function applyTaskToolResult(session, toolUseId, isError, rawContent, raw
|
|
|
730
756
|
.map((entry) => {
|
|
731
757
|
const record = asRecordOrNull(entry);
|
|
732
758
|
const taskId = nonEmptyString(record?.id);
|
|
733
|
-
return record
|
|
759
|
+
return record
|
|
760
|
+
? taskListPatch(record, taskId ? session.tasksById.get(taskId) : undefined)
|
|
761
|
+
: undefined;
|
|
734
762
|
})
|
|
735
763
|
.filter((patch) => Boolean(patch));
|
|
736
764
|
const snapshot = replaceTaskSnapshot(session, patches);
|
|
@@ -757,12 +785,17 @@ export function applyTaskToolResult(session, toolUseId, isError, rawContent, raw
|
|
|
757
785
|
const metadata = mergeMetadata(existing?.metadata, {
|
|
758
786
|
terminal_status: "stopped",
|
|
759
787
|
task_type: output.task_type,
|
|
760
|
-
...(typeof output.command === "string"
|
|
788
|
+
...(typeof output.command === "string"
|
|
789
|
+
? { command: output.command }
|
|
790
|
+
: {}),
|
|
761
791
|
});
|
|
762
792
|
emitTaskStateUpdate(session, "task_lifecycle", [
|
|
763
793
|
upsertTask(session, {
|
|
764
794
|
task_id: taskId,
|
|
765
|
-
subject: existing?.subject ??
|
|
795
|
+
subject: existing?.subject ??
|
|
796
|
+
nonEmptyString(output.command) ??
|
|
797
|
+
nonEmptyString(output.task_type) ??
|
|
798
|
+
taskId,
|
|
766
799
|
status: "completed",
|
|
767
800
|
metadata,
|
|
768
801
|
source_tool_call_id: sourceToolCallId,
|
|
@@ -773,7 +806,8 @@ export function applyTaskToolResult(session, toolUseId, isError, rawContent, raw
|
|
|
773
806
|
}
|
|
774
807
|
function lifecycleTaskStatus(subtype, msg) {
|
|
775
808
|
const patch = asRecordOrNull(msg.patch);
|
|
776
|
-
const explicit = normalizeLifecycleTaskStatus(msg.status) ??
|
|
809
|
+
const explicit = normalizeLifecycleTaskStatus(msg.status) ??
|
|
810
|
+
normalizeLifecycleTaskStatus(patch?.status);
|
|
777
811
|
if (explicit) {
|
|
778
812
|
return explicit;
|
|
779
813
|
}
|
|
@@ -797,6 +831,7 @@ function lifecycleMetadata(msg) {
|
|
|
797
831
|
for (const key of [
|
|
798
832
|
"error",
|
|
799
833
|
"is_backgrounded",
|
|
834
|
+
"spawn_depth",
|
|
800
835
|
"request_id",
|
|
801
836
|
"subagent_type",
|
|
802
837
|
"task_description",
|
|
@@ -834,7 +869,9 @@ export function applyTaskLifecycleState(session, subtype, msg) {
|
|
|
834
869
|
}
|
|
835
870
|
const existing = session.tasksById.get(taskId);
|
|
836
871
|
const status = lifecycleTaskStatus(subtype, msg);
|
|
837
|
-
const description = nonEmptyString(patch?.description) ??
|
|
872
|
+
const description = nonEmptyString(patch?.description) ??
|
|
873
|
+
nonEmptyString(msg.description) ??
|
|
874
|
+
nonEmptyString(msg.summary);
|
|
838
875
|
const activeForm = nonEmptyString(patch?.activeForm);
|
|
839
876
|
const subject = nonEmptyString(patch?.subject) ??
|
|
840
877
|
nonEmptyString(msg.subject) ??
|
|
@@ -845,7 +882,11 @@ export function applyTaskLifecycleState(session, subtype, msg) {
|
|
|
845
882
|
taskId;
|
|
846
883
|
const metadata = mergeMetadata(existing?.metadata, lifecycleMetadata(msg));
|
|
847
884
|
const sourceToolCallId = session.taskToolUseIds.get(taskId);
|
|
848
|
-
if (!status &&
|
|
885
|
+
if (!status &&
|
|
886
|
+
!description &&
|
|
887
|
+
!activeForm &&
|
|
888
|
+
metadata === existing?.metadata &&
|
|
889
|
+
!sourceToolCallId) {
|
|
849
890
|
return;
|
|
850
891
|
}
|
|
851
892
|
emitTaskStateUpdate(session, "task_lifecycle", [
|
|
@@ -2,10 +2,21 @@ import { emitSessionUpdate } from "./events.js";
|
|
|
2
2
|
import { bridgeLogger, LOG_TARGETS } from "./logger.js";
|
|
3
3
|
import { asRecordOrNull } from "./shared.js";
|
|
4
4
|
import { applyTaskToolResult } from "./tasks.js";
|
|
5
|
-
import { activeTaskIdForToolUse, linkTaskToolUse, unlinkTaskToolUse } from "./task_links.js";
|
|
5
|
+
import { activeTaskIdForToolUse, linkTaskToolUse, unlinkTaskToolUse, } from "./task_links.js";
|
|
6
6
|
import { applyToolNonExecutionMetadata, backgroundToolLaunchTaskIdFromResult, buildToolResultFields, createToolCall, } from "./tooling.js";
|
|
7
|
-
const TOOL_SUMMARY_TOOL_NAMES = new Set([
|
|
8
|
-
|
|
7
|
+
const TOOL_SUMMARY_TOOL_NAMES = new Set([
|
|
8
|
+
"Agent",
|
|
9
|
+
"Task",
|
|
10
|
+
"WebSearch",
|
|
11
|
+
"WebFetch",
|
|
12
|
+
"ExitPlanMode",
|
|
13
|
+
]);
|
|
14
|
+
const TASK_LIFECYCLE_TOOL_NAMES = new Set([
|
|
15
|
+
"Agent",
|
|
16
|
+
"Task",
|
|
17
|
+
"Monitor",
|
|
18
|
+
"Workflow",
|
|
19
|
+
]);
|
|
9
20
|
function jsonSize(value) {
|
|
10
21
|
if (value === undefined) {
|
|
11
22
|
return undefined;
|
|
@@ -21,8 +32,16 @@ function toolNameFromMeta(meta) {
|
|
|
21
32
|
if (!meta || typeof meta !== "object") {
|
|
22
33
|
return undefined;
|
|
23
34
|
}
|
|
24
|
-
const claudeCode = "claudeCode" in meta &&
|
|
25
|
-
|
|
35
|
+
const claudeCode = "claudeCode" in meta &&
|
|
36
|
+
meta.claudeCode &&
|
|
37
|
+
typeof meta.claudeCode === "object"
|
|
38
|
+
? meta.claudeCode
|
|
39
|
+
: undefined;
|
|
40
|
+
const toolName = claudeCode &&
|
|
41
|
+
"toolName" in claudeCode &&
|
|
42
|
+
typeof claudeCode.toolName === "string"
|
|
43
|
+
? claudeCode.toolName
|
|
44
|
+
: "";
|
|
26
45
|
return toolName || undefined;
|
|
27
46
|
}
|
|
28
47
|
function toolName(base, fields) {
|
|
@@ -82,20 +101,32 @@ function parentToolUseIdFromMeta(meta) {
|
|
|
82
101
|
if (!meta || typeof meta !== "object") {
|
|
83
102
|
return null;
|
|
84
103
|
}
|
|
85
|
-
const claudeCode = "claudeCode" in meta &&
|
|
86
|
-
|
|
104
|
+
const claudeCode = "claudeCode" in meta &&
|
|
105
|
+
meta.claudeCode &&
|
|
106
|
+
typeof meta.claudeCode === "object"
|
|
107
|
+
? meta.claudeCode
|
|
108
|
+
: undefined;
|
|
109
|
+
const parentToolUseId = claudeCode &&
|
|
110
|
+
"parentToolUseId" in claudeCode &&
|
|
111
|
+
typeof claudeCode.parentToolUseId === "string"
|
|
87
112
|
? claudeCode.parentToolUseId
|
|
88
113
|
: null;
|
|
89
114
|
return parentToolUseId;
|
|
90
115
|
}
|
|
91
116
|
function applyToolCorrelationMetadata(toolCall, metadata) {
|
|
92
|
-
if (!metadata?.requestId &&
|
|
117
|
+
if (!metadata?.requestId &&
|
|
118
|
+
!metadata?.subagentType &&
|
|
119
|
+
!metadata?.taskDescription) {
|
|
93
120
|
return;
|
|
94
121
|
}
|
|
95
|
-
const meta = toolCall.meta &&
|
|
122
|
+
const meta = toolCall.meta &&
|
|
123
|
+
typeof toolCall.meta === "object" &&
|
|
124
|
+
!Array.isArray(toolCall.meta)
|
|
96
125
|
? toolCall.meta
|
|
97
126
|
: {};
|
|
98
|
-
const claudeCode = meta.claudeCode &&
|
|
127
|
+
const claudeCode = meta.claudeCode &&
|
|
128
|
+
typeof meta.claudeCode === "object" &&
|
|
129
|
+
!Array.isArray(meta.claudeCode)
|
|
99
130
|
? meta.claudeCode
|
|
100
131
|
: {};
|
|
101
132
|
toolCall.meta = {
|
|
@@ -104,7 +135,9 @@ function applyToolCorrelationMetadata(toolCall, metadata) {
|
|
|
104
135
|
...claudeCode,
|
|
105
136
|
...(metadata.requestId ? { requestId: metadata.requestId } : {}),
|
|
106
137
|
...(metadata.subagentType ? { subagentType: metadata.subagentType } : {}),
|
|
107
|
-
...(metadata.taskDescription
|
|
138
|
+
...(metadata.taskDescription
|
|
139
|
+
? { taskDescription: metadata.taskDescription }
|
|
140
|
+
: {}),
|
|
108
141
|
},
|
|
109
142
|
};
|
|
110
143
|
}
|
|
@@ -176,7 +209,9 @@ function logToolCallSubmitted(sessionId, toolCall, updateKind) {
|
|
|
176
209
|
}
|
|
177
210
|
function logToolCallUpdateEmitted(sessionId, toolUseId, fields, base, updateKind) {
|
|
178
211
|
const nextStatus = fields.status ?? base?.status;
|
|
179
|
-
const rawOutput = typeof fields.raw_output === "string"
|
|
212
|
+
const rawOutput = typeof fields.raw_output === "string"
|
|
213
|
+
? fields.raw_output
|
|
214
|
+
: base?.raw_output;
|
|
180
215
|
const failureKind = nextStatus === "failed" ? classifyFailureKind(rawOutput) : undefined;
|
|
181
216
|
const commonEvent = {
|
|
182
217
|
target: LOG_TARGETS.APP_TOOL,
|
|
@@ -195,7 +230,8 @@ function logToolCallUpdateEmitted(sessionId, toolUseId, fields, base, updateKind
|
|
|
195
230
|
content_block_count: fields.content?.length,
|
|
196
231
|
location_count: fields.locations?.length,
|
|
197
232
|
raw_output_chars: rawOutput?.length,
|
|
198
|
-
has_output_metadata: fields.output_metadata !== undefined ||
|
|
233
|
+
has_output_metadata: fields.output_metadata !== undefined ||
|
|
234
|
+
base?.output_metadata !== undefined,
|
|
199
235
|
has_task_metadata: fields.task_metadata !== undefined || base?.task_metadata !== undefined,
|
|
200
236
|
failure_kind: failureKind,
|
|
201
237
|
},
|
|
@@ -217,7 +253,10 @@ function logToolCallUpdateEmitted(sessionId, toolUseId, fields, base, updateKind
|
|
|
217
253
|
function emitInitialToolCall(session, toolCall, updateKind = "initial") {
|
|
218
254
|
session.toolCalls.set(toolCall.tool_call_id, toolCall);
|
|
219
255
|
logToolCallSubmitted(session.sessionId, toolCall, updateKind);
|
|
220
|
-
emitSessionUpdate(session.sessionId, {
|
|
256
|
+
emitSessionUpdate(session.sessionId, {
|
|
257
|
+
type: "tool_call",
|
|
258
|
+
tool_call: toolCall,
|
|
259
|
+
});
|
|
221
260
|
}
|
|
222
261
|
function taskTitleContext(session, name, input) {
|
|
223
262
|
const taskId = name === "TaskUpdate"
|
|
@@ -242,7 +281,9 @@ function taskTitleContext(session, name, input) {
|
|
|
242
281
|
export function emitToolCallUpdate(session, toolUseId, fields, updateKind, sourceMessageUuid) {
|
|
243
282
|
const base = session.toolCalls.get(toolUseId);
|
|
244
283
|
const nextStatus = fields.status ?? base?.status;
|
|
245
|
-
const terminal = nextStatus === "completed" ||
|
|
284
|
+
const terminal = nextStatus === "completed" ||
|
|
285
|
+
nextStatus === "failed" ||
|
|
286
|
+
nextStatus === "killed";
|
|
246
287
|
const hasActiveRetry = base?.task_metadata?.subagent_retry?.state === "waiting" ||
|
|
247
288
|
fields.task_metadata?.subagent_retry?.state === "waiting";
|
|
248
289
|
if (terminal && hasActiveRetry) {
|
|
@@ -333,7 +374,8 @@ export function finalizeOpenToolCalls(session, status) {
|
|
|
333
374
|
if (toolCall.status !== "pending" && toolCall.status !== "in_progress") {
|
|
334
375
|
continue;
|
|
335
376
|
}
|
|
336
|
-
if (toolAcceptsTaskLifecycle(toolCall) &&
|
|
377
|
+
if (toolAcceptsTaskLifecycle(toolCall) &&
|
|
378
|
+
activeTaskIdForToolUse(session, toolUseId)) {
|
|
337
379
|
continue;
|
|
338
380
|
}
|
|
339
381
|
emitToolCallUpdate(session, toolUseId, { status }, "finalize");
|
|
@@ -360,7 +402,8 @@ export function emitToolProgressUpdate(session, toolUseId, progress = {}) {
|
|
|
360
402
|
existing.task_metadata?.subagent_retry?.state === "waiting") {
|
|
361
403
|
taskMetadata.subagent_retry = progress.subagentRetry;
|
|
362
404
|
}
|
|
363
|
-
if (progress.subagentType &&
|
|
405
|
+
if (progress.subagentType &&
|
|
406
|
+
progress.subagentType !== existing.task_metadata?.subagent_type) {
|
|
364
407
|
taskMetadata.subagent_type = progress.subagentType;
|
|
365
408
|
}
|
|
366
409
|
const fields = {};
|
|
@@ -383,7 +426,9 @@ export function emitToolSummaryUpdate(session, toolUseId, summary) {
|
|
|
383
426
|
return;
|
|
384
427
|
}
|
|
385
428
|
const fields = {
|
|
386
|
-
status: base.status === "failed" || base.status === "killed"
|
|
429
|
+
status: base.status === "failed" || base.status === "killed"
|
|
430
|
+
? base.status
|
|
431
|
+
: "completed",
|
|
387
432
|
raw_output: summary,
|
|
388
433
|
content: [{ type: "content", content: { type: "text", text: summary } }],
|
|
389
434
|
};
|
|
@@ -397,7 +442,9 @@ export function setToolCallStatus(session, toolUseId, status, message) {
|
|
|
397
442
|
const fields = { status };
|
|
398
443
|
if (message && message.length > 0) {
|
|
399
444
|
fields.raw_output = message;
|
|
400
|
-
fields.content = [
|
|
445
|
+
fields.content = [
|
|
446
|
+
{ type: "content", content: { type: "text", text: message } },
|
|
447
|
+
];
|
|
401
448
|
}
|
|
402
449
|
emitToolCallUpdate(session, toolUseId, fields, "status");
|
|
403
450
|
}
|
|
@@ -448,7 +495,9 @@ function buildTaskMetadata(patch) {
|
|
|
448
495
|
if (typeof patch.is_backgrounded === "boolean") {
|
|
449
496
|
taskMetadata.is_backgrounded = patch.is_backgrounded;
|
|
450
497
|
}
|
|
451
|
-
if (typeof patch.end_time === "number" &&
|
|
498
|
+
if (typeof patch.end_time === "number" &&
|
|
499
|
+
Number.isFinite(patch.end_time) &&
|
|
500
|
+
patch.end_time >= 0) {
|
|
452
501
|
taskMetadata.end_time = Math.trunc(patch.end_time);
|
|
453
502
|
}
|
|
454
503
|
if (typeof patch.total_paused_ms === "number" &&
|
|
@@ -456,19 +505,23 @@ function buildTaskMetadata(patch) {
|
|
|
456
505
|
patch.total_paused_ms >= 0) {
|
|
457
506
|
taskMetadata.total_paused_ms = Math.trunc(patch.total_paused_ms);
|
|
458
507
|
}
|
|
459
|
-
if (typeof patch.status === "string" &&
|
|
508
|
+
if (typeof patch.status === "string" &&
|
|
509
|
+
["completed", "failed", "killed"].includes(patch.status)) {
|
|
460
510
|
taskMetadata.terminal_status = patch.status;
|
|
461
511
|
}
|
|
462
512
|
if (typeof patch.blocked === "boolean") {
|
|
463
513
|
taskMetadata.blocked = patch.blocked;
|
|
464
514
|
}
|
|
465
|
-
if (typeof patch.parent_agent_id === "string" &&
|
|
515
|
+
if (typeof patch.parent_agent_id === "string" &&
|
|
516
|
+
patch.parent_agent_id.length > 0) {
|
|
466
517
|
taskMetadata.parent_agent_id = patch.parent_agent_id;
|
|
467
518
|
}
|
|
468
519
|
return Object.keys(taskMetadata).length > 0 ? taskMetadata : undefined;
|
|
469
520
|
}
|
|
470
521
|
export function taskUpdatedFields(msg) {
|
|
471
|
-
const patch = msg.patch && typeof msg.patch === "object"
|
|
522
|
+
const patch = msg.patch && typeof msg.patch === "object"
|
|
523
|
+
? msg.patch
|
|
524
|
+
: {};
|
|
472
525
|
const fields = {};
|
|
473
526
|
const status = taskPatchStatus(patch.status);
|
|
474
527
|
const description = typeof patch.description === "string" ? patch.description : "";
|
|
@@ -478,11 +531,15 @@ export function taskUpdatedFields(msg) {
|
|
|
478
531
|
}
|
|
479
532
|
if (description) {
|
|
480
533
|
fields.raw_output = description;
|
|
481
|
-
fields.content = [
|
|
534
|
+
fields.content = [
|
|
535
|
+
{ type: "content", content: { type: "text", text: description } },
|
|
536
|
+
];
|
|
482
537
|
}
|
|
483
538
|
else if ((status === "failed" || status === "killed") && error) {
|
|
484
539
|
fields.raw_output = error;
|
|
485
|
-
fields.content = [
|
|
540
|
+
fields.content = [
|
|
541
|
+
{ type: "content", content: { type: "text", text: error } },
|
|
542
|
+
];
|
|
486
543
|
}
|
|
487
544
|
const taskMetadata = buildTaskMetadata(patch);
|
|
488
545
|
if (taskMetadata) {
|