@liberseek/boft-cli-win32-arm64 0.6.3 → 0.6.4

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.
@@ -20990,6 +20990,309 @@ function hasGrokToolProjection(projection) {
20990
20990
  return projection.output !== void 0 || projection.exitCode !== void 0;
20991
20991
  }
20992
20992
 
20993
+ // dist/grok-subagent.js
20994
+ var SPAWN_TOOL_NAMES = /* @__PURE__ */ new Set(["spawn_subagent", "spawn_agent", "task"]);
20995
+ var SEND_TOOL_NAMES = /* @__PURE__ */ new Set(["send_subagent_message"]);
20996
+ var WAIT_TOOL_NAMES = /* @__PURE__ */ new Set([
20997
+ "get_command_or_subagent_output",
20998
+ "get_task_output",
20999
+ "wait_tasks"
21000
+ ]);
21001
+ var KILL_TOOL_NAMES = /* @__PURE__ */ new Set(["kill_command_or_subagent", "kill_task"]);
21002
+ var DESCRIPTION_LIMIT = 500;
21003
+ var SUMMARY_LIMIT = 2e3;
21004
+ function isRecord5(value) {
21005
+ return typeof value === "object" && value !== null && !Array.isArray(value);
21006
+ }
21007
+ function idField(value, key) {
21008
+ if (!isRecord5(value))
21009
+ return void 0;
21010
+ const field = value[key];
21011
+ if (typeof field === "string") {
21012
+ const trimmed = field.trim();
21013
+ return trimmed.length > 0 ? trimmed : void 0;
21014
+ }
21015
+ if (typeof field === "number" && Number.isFinite(field))
21016
+ return String(field);
21017
+ return void 0;
21018
+ }
21019
+ function stringField2(value, key) {
21020
+ if (!isRecord5(value) || typeof value[key] !== "string")
21021
+ return void 0;
21022
+ const trimmed = value[key].trim();
21023
+ return trimmed.length > 0 ? trimmed : void 0;
21024
+ }
21025
+ function bounded(value, limit) {
21026
+ if (!value)
21027
+ return void 0;
21028
+ return value.slice(0, limit);
21029
+ }
21030
+ function toolId(name, title) {
21031
+ return grokToolName(name, title).toLowerCase();
21032
+ }
21033
+ function collectIds(value) {
21034
+ const ids = [];
21035
+ const push = (entry) => {
21036
+ if (typeof entry === "string" && entry.trim().length > 0)
21037
+ ids.push(entry.trim());
21038
+ else if (typeof entry === "number" && Number.isFinite(entry))
21039
+ ids.push(String(entry));
21040
+ };
21041
+ push(idField(value, "task_id"));
21042
+ push(idField(value, "subagent_id"));
21043
+ if (isRecord5(value)) {
21044
+ const list = value.task_ids ?? value.subagent_ids;
21045
+ if (Array.isArray(list)) {
21046
+ for (const entry of list)
21047
+ push(entry);
21048
+ } else {
21049
+ push(list);
21050
+ }
21051
+ }
21052
+ return [...new Set(ids)];
21053
+ }
21054
+ function grokSubagentOperation(name, title, rawInput) {
21055
+ const id = toolId(name, title);
21056
+ if (WAIT_TOOL_NAMES.has(id) || KILL_TOOL_NAMES.has(id))
21057
+ return null;
21058
+ if (SEND_TOOL_NAMES.has(id))
21059
+ return "send";
21060
+ if (SPAWN_TOOL_NAMES.has(id))
21061
+ return "spawn";
21062
+ if (isRecord5(rawInput) && rawInput.variant === "Task")
21063
+ return "spawn";
21064
+ return null;
21065
+ }
21066
+ function grokSubagentWaitIds(name, title, rawInput) {
21067
+ if (!WAIT_TOOL_NAMES.has(toolId(name, title)) && !KILL_TOOL_NAMES.has(toolId(name, title))) {
21068
+ return [];
21069
+ }
21070
+ return collectIds(rawInput);
21071
+ }
21072
+ function grokSubagentKill(name, title) {
21073
+ return KILL_TOOL_NAMES.has(toolId(name, title));
21074
+ }
21075
+ function grokSubagentDescription(rawInput, title, fallback = "Grok Subagent") {
21076
+ return bounded(stringField2(rawInput, "description"), DESCRIPTION_LIMIT) ?? bounded(stringField2(rawInput, "name"), DESCRIPTION_LIMIT) ?? (title && !SPAWN_TOOL_NAMES.has(title.toLowerCase()) && !SEND_TOOL_NAMES.has(title.toLowerCase()) ? bounded(title, DESCRIPTION_LIMIT) : void 0) ?? fallback;
21077
+ }
21078
+ function grokSubagentPrompt(rawInput) {
21079
+ return bounded(stringField2(rawInput, "prompt") ?? stringField2(rawInput, "message"), SUMMARY_LIMIT);
21080
+ }
21081
+ function grokSubagentRole(rawInput) {
21082
+ return bounded(stringField2(rawInput, "subagent_type") ?? stringField2(rawInput, "agent_type") ?? stringField2(rawInput, "type"), DESCRIPTION_LIMIT);
21083
+ }
21084
+ function grokSubagentBackground(rawInput) {
21085
+ if (!isRecord5(rawInput))
21086
+ return true;
21087
+ if (rawInput.background === false || rawInput.run_in_background === false)
21088
+ return false;
21089
+ return true;
21090
+ }
21091
+ function grokSubagentModel(rawInput) {
21092
+ return bounded(stringField2(rawInput, "model"), DESCRIPTION_LIMIT);
21093
+ }
21094
+ function grokNativeSubagentId(...candidates) {
21095
+ const fromKey = (key) => {
21096
+ for (const candidate of candidates) {
21097
+ const value = idField(candidate, key);
21098
+ if (value)
21099
+ return value;
21100
+ }
21101
+ return void 0;
21102
+ };
21103
+ const fromText = (pattern) => {
21104
+ for (const candidate of candidates) {
21105
+ const text = extractText(candidate);
21106
+ const match = text?.match(pattern);
21107
+ if (match?.[1])
21108
+ return match[1].trim();
21109
+ }
21110
+ return void 0;
21111
+ };
21112
+ return fromKey("subagent_id") ?? fromText(/subagent_id:\s*([^\s]+)/i) ?? fromKey("task_id") ?? fromKey("id") ?? fromText(/task_id:\s*([^\s]+)/i) ?? fromText(/task_ids=\["([^"]+)"\]/);
21113
+ }
21114
+ function grokSubagentResultSummary(...candidates) {
21115
+ for (const candidate of candidates) {
21116
+ const text = extractText(candidate);
21117
+ if (text)
21118
+ return bounded(text, SUMMARY_LIMIT);
21119
+ }
21120
+ return void 0;
21121
+ }
21122
+ function grokSubagentEventFromUpdate(update) {
21123
+ if (!isRecord5(update) || typeof update.sessionUpdate !== "string")
21124
+ return null;
21125
+ const nativeSubagentId = idField(update, "subagent_id") ?? idField(update, "child_session_id");
21126
+ if (!nativeSubagentId)
21127
+ return null;
21128
+ if (update.sessionUpdate === "subagent_spawned") {
21129
+ const description = bounded(stringField2(update, "description"), DESCRIPTION_LIMIT);
21130
+ const role = bounded(stringField2(update, "subagent_type") ?? stringField2(update, "role"), DESCRIPTION_LIMIT);
21131
+ const model = bounded(stringField2(update, "model"), DESCRIPTION_LIMIT);
21132
+ return {
21133
+ type: "subagent.spawned",
21134
+ nativeSubagentId,
21135
+ ...description ? { description } : {},
21136
+ ...role ? { role } : {},
21137
+ ...model ? { model } : {}
21138
+ };
21139
+ }
21140
+ if (update.sessionUpdate === "subagent_finished") {
21141
+ const mapped = mapTaskStatus(typeof update.status === "string" ? update.status : void 0);
21142
+ if (!mapped || mapped === "running" || mapped === "pending")
21143
+ return null;
21144
+ const status = mapped === "failed" ? "failed" : mapped === "interrupted" ? "interrupted" : "completed";
21145
+ const resultSummary = bounded(typeof update.output === "string" ? update.output.trim() : void 0, SUMMARY_LIMIT);
21146
+ return {
21147
+ type: "subagent.finished",
21148
+ nativeSubagentId,
21149
+ status,
21150
+ ...resultSummary ? { resultSummary } : {}
21151
+ };
21152
+ }
21153
+ return null;
21154
+ }
21155
+ function grokSubagentWaitSettlements(input) {
21156
+ const ids = grokSubagentWaitIds(input.name, input.title, input.rawInput);
21157
+ if (grokSubagentKill(input.name, input.title)) {
21158
+ return ids.map((id) => ({ id, status: "interrupted" }));
21159
+ }
21160
+ if (ids.length === 0)
21161
+ return [];
21162
+ const resultEntries = taskOutputResults(input.rawOutput);
21163
+ if (resultEntries.length > 0) {
21164
+ const settled = [];
21165
+ for (const result of resultEntries) {
21166
+ const id = idField(result, "task_id") ?? idField(result, "subagent_id");
21167
+ const status = mapTaskStatus(typeof result.status === "string" ? result.status : void 0);
21168
+ if (!id || !status || status === "running" || status === "pending")
21169
+ continue;
21170
+ const resultSummary = bounded(typeof result.output === "string" ? result.output.trim() : void 0, SUMMARY_LIMIT);
21171
+ settled.push({ id, status, ...resultSummary ? { resultSummary } : {} });
21172
+ }
21173
+ return settled;
21174
+ }
21175
+ const fromText = taskOutputTextSettlements(input.rawOutput, input.content, ids);
21176
+ if (fromText.length > 0)
21177
+ return fromText;
21178
+ const overall = mapTaskStatus(taskOutputStatus(input.rawOutput, input.content));
21179
+ if (!overall || overall === "running" || overall === "pending")
21180
+ return [];
21181
+ return ids.map((id) => ({ id, status: overall }));
21182
+ }
21183
+ function taskOutputResults(rawOutput) {
21184
+ if (!isRecord5(rawOutput))
21185
+ return [];
21186
+ if (Array.isArray(rawOutput.results)) {
21187
+ return rawOutput.results.filter(isRecord5);
21188
+ }
21189
+ const nested = firstRecord(rawOutput.MultiResult, rawOutput.multiResult, rawOutput.multi_result);
21190
+ if (nested && Array.isArray(nested.results)) {
21191
+ return nested.results.filter(isRecord5);
21192
+ }
21193
+ const single = firstRecord(rawOutput.Result, rawOutput.result);
21194
+ if (single)
21195
+ return [single];
21196
+ if (typeof rawOutput.status === "string")
21197
+ return [rawOutput];
21198
+ return [];
21199
+ }
21200
+ function firstRecord(...values) {
21201
+ for (const value of values) {
21202
+ if (isRecord5(value))
21203
+ return value;
21204
+ }
21205
+ return void 0;
21206
+ }
21207
+ function taskOutputTextSettlements(rawOutput, content, ids) {
21208
+ const text = extractText(content) ?? extractText(rawOutput);
21209
+ if (!text)
21210
+ return [];
21211
+ const settled = [];
21212
+ const pattern = /---\s*Task\s+(\S+)\s+\[(completed|failed|interrupted|cancelled|canceled)\]\s*---/gi;
21213
+ for (const match of text.matchAll(pattern)) {
21214
+ const id = match[1]?.trim();
21215
+ const status = mapTaskStatus(match[2]);
21216
+ if (!id || !status || status === "running" || status === "pending")
21217
+ continue;
21218
+ if (!ids.includes(id))
21219
+ continue;
21220
+ settled.push({ id, status });
21221
+ }
21222
+ return settled;
21223
+ }
21224
+ function taskOutputStatus(rawOutput, content) {
21225
+ if (isRecord5(rawOutput) && typeof rawOutput.status === "string")
21226
+ return rawOutput.status;
21227
+ const text = extractText(content) ?? extractText(rawOutput);
21228
+ if (!text)
21229
+ return void 0;
21230
+ if (/<subagent_meta>|<subagent_result>/i.test(text))
21231
+ return "completed";
21232
+ if (/\bstatus["']?\s*[:=]\s*["']?completed/i.test(text))
21233
+ return "completed";
21234
+ if (/\bstatus["']?\s*[:=]\s*["']?failed/i.test(text))
21235
+ return "failed";
21236
+ if (/\bstatus["']?\s*[:=]\s*["']?(cancelled|canceled|interrupted)/i.test(text)) {
21237
+ return "interrupted";
21238
+ }
21239
+ if (/\bstill running\b|\bstatus["']?\s*[:=]\s*["']?(running|pending|in_progress)/i.test(text)) {
21240
+ return "running";
21241
+ }
21242
+ return void 0;
21243
+ }
21244
+ function mapTaskStatus(status) {
21245
+ if (!status)
21246
+ return void 0;
21247
+ switch (status.toLowerCase()) {
21248
+ case "completed":
21249
+ case "succeeded":
21250
+ case "success":
21251
+ return "completed";
21252
+ case "failed":
21253
+ case "error":
21254
+ case "errored":
21255
+ return "failed";
21256
+ case "cancelled":
21257
+ case "canceled":
21258
+ case "interrupted":
21259
+ return "interrupted";
21260
+ case "running":
21261
+ case "pending":
21262
+ case "in_progress":
21263
+ case "inprogress":
21264
+ return "running";
21265
+ default:
21266
+ return void 0;
21267
+ }
21268
+ }
21269
+ function extractText(value, depth = 0) {
21270
+ if (depth > 6)
21271
+ return void 0;
21272
+ if (typeof value === "string") {
21273
+ const trimmed = value.trim();
21274
+ return trimmed.length > 0 ? trimmed : void 0;
21275
+ }
21276
+ if (Array.isArray(value)) {
21277
+ const parts = value.flatMap((entry) => {
21278
+ const text = extractText(entry, depth + 1);
21279
+ return text ? [text] : [];
21280
+ });
21281
+ const joined = parts.join("\n").trim();
21282
+ return joined.length > 0 ? joined : void 0;
21283
+ }
21284
+ if (!isRecord5(value))
21285
+ return void 0;
21286
+ if (typeof value.text === "string" && value.text.trim().length > 0)
21287
+ return value.text.trim();
21288
+ if (typeof value.output === "string" && value.output.trim().length > 0) {
21289
+ return value.output.trim();
21290
+ }
21291
+ if (value.content !== void 0)
21292
+ return extractText(value.content, depth + 1);
21293
+ return void 0;
21294
+ }
21295
+
20993
21296
  // dist/grok-history.js
20994
21297
  function stableId(kind, turn, index) {
20995
21298
  return hostItemIdSchema.parse(`grok-history-${kind}-${turn}-${index}`);
@@ -21052,6 +21355,90 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
21052
21355
  let reasoning = null;
21053
21356
  const tools = /* @__PURE__ */ new Map();
21054
21357
  const mediaRoots = grokMediaResolveRoots(cwd, sessionDirectory);
21358
+ const subagents = /* @__PURE__ */ new Map();
21359
+ const subagentAliases = /* @__PURE__ */ new Map();
21360
+ const rememberSubagentAlias = (callId, nativeId) => {
21361
+ subagentAliases.set(callId, callId);
21362
+ if (nativeId)
21363
+ subagentAliases.set(nativeId, callId);
21364
+ };
21365
+ const completeHistorySubagent = (callId, status, content, rawOutput, rawInput) => {
21366
+ const current = subagents.get(callId);
21367
+ const currentAgent = current?.subagents[0];
21368
+ if (!current || !currentAgent)
21369
+ return;
21370
+ const nativeSubagentId = grokNativeSubagentId(rawInput, rawOutput, content) ?? currentAgent.nativeSubagentId;
21371
+ rememberSubagentAlias(callId, nativeSubagentId);
21372
+ const summary = grokSubagentResultSummary(content, rawOutput);
21373
+ const failed = status === "failed";
21374
+ const keepRunning = !failed && (currentAgent.background === true || current.operation === "send");
21375
+ const item = {
21376
+ ...current,
21377
+ subagents: [
21378
+ {
21379
+ ...currentAgent,
21380
+ status: failed ? "failed" : keepRunning ? "running" : "completed",
21381
+ ...nativeSubagentId ? { nativeSubagentId, subagentId: nativeSubagentId } : {},
21382
+ ...summary ? { resultSummary: summary } : {}
21383
+ }
21384
+ ]
21385
+ };
21386
+ if (keepRunning) {
21387
+ subagents.set(callId, item);
21388
+ return;
21389
+ }
21390
+ subagents.delete(callId);
21391
+ items.push({
21392
+ item,
21393
+ outcome: failed ? {
21394
+ status: "failed",
21395
+ error: {
21396
+ code: "nativeFailure",
21397
+ message: "Grok Subagent delegation failed",
21398
+ retryable: false
21399
+ }
21400
+ } : { status: "succeeded" }
21401
+ });
21402
+ };
21403
+ const settleWatchedSubagents = (name, rawInput, content, rawOutput) => {
21404
+ const summary = grokSubagentResultSummary(content, rawOutput);
21405
+ for (const settlement of grokSubagentWaitSettlements({
21406
+ ...name ? { name, title: name } : {},
21407
+ rawInput,
21408
+ content,
21409
+ rawOutput
21410
+ })) {
21411
+ const spawnId = subagentAliases.get(settlement.id);
21412
+ const item = spawnId ? subagents.get(spawnId) : void 0;
21413
+ if (!item?.subagents[0])
21414
+ continue;
21415
+ if (spawnId)
21416
+ subagents.delete(spawnId);
21417
+ const resultSummary = settlement.resultSummary ?? summary;
21418
+ items.push({
21419
+ item: {
21420
+ ...item,
21421
+ subagents: [
21422
+ {
21423
+ ...item.subagents[0],
21424
+ status: settlement.status,
21425
+ nativeSubagentId: item.subagents[0].nativeSubagentId ?? settlement.id,
21426
+ subagentId: item.subagents[0].nativeSubagentId ?? settlement.id,
21427
+ ...resultSummary ? { resultSummary } : {}
21428
+ }
21429
+ ]
21430
+ },
21431
+ outcome: settlement.status === "failed" ? {
21432
+ status: "failed",
21433
+ error: {
21434
+ code: "nativeFailure",
21435
+ message: "Grok Subagent delegation failed",
21436
+ retryable: false
21437
+ }
21438
+ } : settlement.status === "interrupted" ? { status: "cancelled", reason: "Cancelled by user" } : { status: "succeeded" }
21439
+ });
21440
+ }
21441
+ };
21055
21442
  const completeAgent = () => {
21056
21443
  if (!agent || agent.text.length === 0)
21057
21444
  return;
@@ -21072,6 +21459,10 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
21072
21459
  items.push({ item: tool, outcome: { status: "succeeded" } });
21073
21460
  }
21074
21461
  tools.clear();
21462
+ for (const item of subagents.values()) {
21463
+ items.push({ item, outcome: { status: "succeeded" } });
21464
+ }
21465
+ subagents.clear();
21075
21466
  };
21076
21467
  const applyToolProjection = (callId, content, rawOutput) => {
21077
21468
  const tool = tools.get(callId);
@@ -21096,6 +21487,7 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
21096
21487
  retryable: false
21097
21488
  }
21098
21489
  } : { status: "succeeded" };
21490
+ settleWatchedSubagents(tool.type === "toolExecution" ? tool.toolName : tool.command, tool.type === "toolExecution" ? tool.arguments : void 0, content, rawOutput);
21099
21491
  items.push({ item: tool, outcome });
21100
21492
  if (status !== "completed")
21101
21493
  return;
@@ -21163,6 +21555,8 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
21163
21555
  agent = null;
21164
21556
  reasoning = null;
21165
21557
  tools.clear();
21558
+ subagents.clear();
21559
+ subagentAliases.clear();
21166
21560
  continue;
21167
21561
  }
21168
21562
  if (event.type === "user.text") {
@@ -21237,23 +21631,99 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
21237
21631
  } else if (event.type === "tool.call") {
21238
21632
  completeReasoning();
21239
21633
  completeAgent();
21240
- tools.set(event.callId, startGrokToolItem({
21241
- itemId: stableId("tool", turnIndex, ++messageIndex),
21242
- name: event.name,
21243
- title: event.title,
21244
- kind: event.kind,
21245
- rawInput: event.rawInput,
21246
- cwd
21247
- }));
21248
- applyToolProjection(event.callId, event.content, event.rawOutput);
21249
- if (event.status === "completed" || event.status === "failed") {
21250
- completeTool(event.callId, event.status, event.content, event.rawOutput);
21634
+ const operation = grokSubagentOperation(event.name, event.title, event.rawInput);
21635
+ if (operation) {
21636
+ const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content);
21637
+ rememberSubagentAlias(event.callId, nativeSubagentId);
21638
+ const prompt = grokSubagentPrompt(event.rawInput);
21639
+ const role = grokSubagentRole(event.rawInput);
21640
+ const model = grokSubagentModel(event.rawInput);
21641
+ subagents.set(event.callId, {
21642
+ type: "subagentDelegation",
21643
+ itemId: stableId("subagent", turnIndex, ++messageIndex),
21644
+ operation,
21645
+ ...prompt ? { prompt } : {},
21646
+ subagents: [
21647
+ {
21648
+ subagentId: nativeSubagentId ?? event.callId,
21649
+ ...nativeSubagentId ? { nativeSubagentId } : {},
21650
+ description: grokSubagentDescription(event.rawInput, event.title),
21651
+ ...role ? { role } : {},
21652
+ ...model ? { model } : {},
21653
+ background: grokSubagentBackground(event.rawInput),
21654
+ status: "running"
21655
+ }
21656
+ ]
21657
+ });
21658
+ if (event.status === "completed" || event.status === "failed") {
21659
+ completeHistorySubagent(event.callId, event.status, event.content, event.rawOutput, event.rawInput);
21660
+ }
21661
+ } else {
21662
+ tools.set(event.callId, startGrokToolItem({
21663
+ itemId: stableId("tool", turnIndex, ++messageIndex),
21664
+ name: event.name,
21665
+ title: event.title,
21666
+ kind: event.kind,
21667
+ rawInput: event.rawInput,
21668
+ cwd
21669
+ }));
21670
+ applyToolProjection(event.callId, event.content, event.rawOutput);
21671
+ if (event.status === "completed" || event.status === "failed") {
21672
+ completeTool(event.callId, event.status, event.content, event.rawOutput);
21673
+ }
21251
21674
  }
21252
21675
  } else if (event.type === "tool.update") {
21253
- applyToolProjection(event.callId, event.content, event.rawOutput);
21254
- if (event.status === "completed" || event.status === "failed") {
21255
- completeTool(event.callId, event.status, event.content, event.rawOutput);
21676
+ if (subagents.has(event.callId)) {
21677
+ const current = subagents.get(event.callId);
21678
+ if (current?.subagents[0]) {
21679
+ const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content) ?? current.subagents[0].nativeSubagentId;
21680
+ rememberSubagentAlias(event.callId, nativeSubagentId);
21681
+ subagents.set(event.callId, {
21682
+ ...current,
21683
+ subagents: [
21684
+ {
21685
+ ...current.subagents[0],
21686
+ description: grokSubagentDescription(event.rawInput, event.title, current.subagents[0].description),
21687
+ ...nativeSubagentId ? { nativeSubagentId, subagentId: nativeSubagentId } : {}
21688
+ }
21689
+ ]
21690
+ });
21691
+ }
21692
+ if (event.status === "completed" || event.status === "failed") {
21693
+ completeHistorySubagent(event.callId, event.status, event.content, event.rawOutput, event.rawInput);
21694
+ }
21695
+ } else {
21696
+ applyToolProjection(event.callId, event.content, event.rawOutput);
21697
+ if (event.status === "completed" || event.status === "failed") {
21698
+ completeTool(event.callId, event.status, event.content, event.rawOutput);
21699
+ }
21700
+ }
21701
+ } else if (event.type === "subagent.spawned") {
21702
+ for (const [callId, current] of subagents) {
21703
+ const agent2 = current.subagents[0];
21704
+ if (!agent2)
21705
+ continue;
21706
+ const matchesId = agent2.nativeSubagentId === event.nativeSubagentId;
21707
+ const matchesDescription = !agent2.nativeSubagentId && event.description !== void 0 && agent2.description === event.description;
21708
+ if (!matchesId && !matchesDescription)
21709
+ continue;
21710
+ rememberSubagentAlias(callId, event.nativeSubagentId);
21711
+ subagents.set(callId, {
21712
+ ...current,
21713
+ subagents: [
21714
+ {
21715
+ ...agent2,
21716
+ nativeSubagentId: event.nativeSubagentId,
21717
+ subagentId: event.nativeSubagentId,
21718
+ ...event.role ? { role: event.role } : {},
21719
+ ...event.model ? { model: event.model } : {}
21720
+ }
21721
+ ]
21722
+ });
21723
+ break;
21256
21724
  }
21725
+ } else if (event.type === "subagent.finished") {
21726
+ settleWatchedSubagents("get_command_or_subagent_output", { task_ids: [event.nativeSubagentId] }, event.resultSummary ? [event.resultSummary] : void 0, { task_id: event.nativeSubagentId, status: event.status, output: event.resultSummary });
21257
21727
  }
21258
21728
  }
21259
21729
  completeTurn({ status: "unknown", reason: "Grok Native history has no terminal signal" });
@@ -21278,11 +21748,11 @@ var GROK_SESSION_DELETE_METHOD = "_x.ai/session/delete";
21278
21748
  function error51(code, message, retryable = false) {
21279
21749
  return { code, message, retryable };
21280
21750
  }
21281
- function isRecord5(value) {
21751
+ function isRecord6(value) {
21282
21752
  return typeof value === "object" && value !== null && !Array.isArray(value);
21283
21753
  }
21284
21754
  function isGrokMethodNotFound(error53) {
21285
- if (isRecord5(error53) && error53.code === -32601)
21755
+ if (isRecord6(error53) && error53.code === -32601)
21286
21756
  return true;
21287
21757
  const message = error53 instanceof Error ? error53.message : String(error53);
21288
21758
  return /method not found/iu.test(message);
@@ -21300,10 +21770,10 @@ function buildGrokForkParams(input) {
21300
21770
  };
21301
21771
  }
21302
21772
  function parseGrokForkResponse(value) {
21303
- if (!isRecord5(value) || value.error !== void 0)
21773
+ if (!isRecord6(value) || value.error !== void 0)
21304
21774
  return null;
21305
- const payload = typeof value.newSessionId !== "string" && isRecord5(value.result) ? value.result : value;
21306
- if (!isRecord5(payload) || payload.error !== void 0)
21775
+ const payload = typeof value.newSessionId !== "string" && isRecord6(value.result) ? value.result : value;
21776
+ if (!isRecord6(payload) || payload.error !== void 0)
21307
21777
  return null;
21308
21778
  if (typeof payload.newSessionId !== "string" || payload.newSessionId.length === 0)
21309
21779
  return null;
@@ -21466,7 +21936,7 @@ var GROK_SESSION_UPDATE_EXTENSION_METHODS = [
21466
21936
  "_x.ai/session/update",
21467
21937
  "x.ai/session_notification"
21468
21938
  ];
21469
- function isRecord6(value) {
21939
+ function isRecord7(value) {
21470
21940
  return typeof value === "object" && value !== null && !Array.isArray(value);
21471
21941
  }
21472
21942
  function optionalNonNegativeInt(value) {
@@ -21487,7 +21957,7 @@ function isGrokExtensionSessionUpdateMethod(method) {
21487
21957
  return GROK_SESSION_UPDATE_EXTENSION_METHODS.includes(method);
21488
21958
  }
21489
21959
  function grokCompactionEventFromUpdate(update) {
21490
- if (!isRecord6(update) || typeof update.sessionUpdate !== "string")
21960
+ if (!isRecord7(update) || typeof update.sessionUpdate !== "string")
21491
21961
  return null;
21492
21962
  const tokensUsed = optionalNonNegativeInt(firstPresent(update, ["tokensUsed", "tokens_used"]));
21493
21963
  const contextWindowTokens = optionalNonNegativeInt(firstPresent(update, ["contextWindowTokens", "contextWindow", "context_window"]));
@@ -21526,7 +21996,7 @@ function grokCompactionEventFromUpdate(update) {
21526
21996
  // dist/grok-manual-compaction.js
21527
21997
  var GROK_COMPACT_CONVERSATION_METHOD = "x.ai/compact_conversation";
21528
21998
  var GROK_COMPACT_CONVERSATION_FALLBACK_METHOD = "_x.ai/compact_conversation";
21529
- function isRecord7(value) {
21999
+ function isRecord8(value) {
21530
22000
  return typeof value === "object" && value !== null && !Array.isArray(value);
21531
22001
  }
21532
22002
  function optionalNonNegativeInt2(value) {
@@ -21538,7 +22008,7 @@ function optionalErrorMessage2(value) {
21538
22008
  function parseGrokCompactResult(value, cancelled = false) {
21539
22009
  if (cancelled)
21540
22010
  return { outcome: "cancelled" };
21541
- if (!isRecord7(value))
22011
+ if (!isRecord8(value))
21542
22012
  return { outcome: "succeeded" };
21543
22013
  const tokensBefore = optionalNonNegativeInt2(value.tokensBefore ?? value.tokens_before);
21544
22014
  const tokensAfter = optionalNonNegativeInt2(value.tokensAfter ?? value.tokens_after);
@@ -21576,7 +22046,7 @@ var GROK_REWIND_EXECUTE_METHOD = "_x.ai/rewind/execute";
21576
22046
  function error52(code, message, retryable = false) {
21577
22047
  return { code, message, retryable };
21578
22048
  }
21579
- function isRecord8(value) {
22049
+ function isRecord9(value) {
21580
22050
  return typeof value === "object" && value !== null && !Array.isArray(value);
21581
22051
  }
21582
22052
  function buildGrokRewindParams(input) {
@@ -21588,10 +22058,10 @@ function buildGrokRewindParams(input) {
21588
22058
  };
21589
22059
  }
21590
22060
  function parseGrokRewindResponse(value) {
21591
- if (!isRecord8(value))
22061
+ if (!isRecord9(value))
21592
22062
  return null;
21593
- const payload = typeof value.success !== "boolean" && isRecord8(value.result) ? value.result : value;
21594
- if (!isRecord8(payload) || typeof payload.success !== "boolean")
22063
+ const payload = typeof value.success !== "boolean" && isRecord9(value.result) ? value.result : value;
22064
+ if (!isRecord9(payload) || typeof payload.success !== "boolean")
21595
22065
  return null;
21596
22066
  return rewindPayload(payload);
21597
22067
  }
@@ -21701,10 +22171,10 @@ async function rewindGrokLastTurn(input) {
21701
22171
 
21702
22172
  // dist/grok-plan-review.js
21703
22173
  var GROK_PLAN_DECISION_ID = "plan-decision";
21704
- function isRecord9(value) {
22174
+ function isRecord10(value) {
21705
22175
  return typeof value === "object" && value !== null && !Array.isArray(value);
21706
22176
  }
21707
- function stringField2(value, ...keys) {
22177
+ function stringField3(value, ...keys) {
21708
22178
  for (const key of keys) {
21709
22179
  const field = value[key];
21710
22180
  if (typeof field === "string" && field.length > 0)
@@ -21713,12 +22183,12 @@ function stringField2(value, ...keys) {
21713
22183
  return void 0;
21714
22184
  }
21715
22185
  function parseGrokExitPlanModeParams(params) {
21716
- if (!isRecord9(params))
22186
+ if (!isRecord10(params))
21717
22187
  return null;
21718
- const nested = isRecord9(params.input) ? params.input : params;
21719
- const plan = stringField2(nested, "planContent", "plan_content", "plan") ?? stringField2(params, "planContent", "plan_content", "plan") ?? null;
21720
- const planFilePath = stringField2(nested, "planFilePath", "plan_file_path") ?? stringField2(params, "planFilePath", "plan_file_path");
21721
- const sessionId = stringField2(params, "sessionId", "session_id");
22188
+ const nested = isRecord10(params.input) ? params.input : params;
22189
+ const plan = stringField3(nested, "planContent", "plan_content", "plan") ?? stringField3(params, "planContent", "plan_content", "plan") ?? null;
22190
+ const planFilePath = stringField3(nested, "planFilePath", "plan_file_path") ?? stringField3(params, "planFilePath", "plan_file_path");
22191
+ const sessionId = stringField3(params, "sessionId", "session_id");
21722
22192
  return {
21723
22193
  plan,
21724
22194
  ...sessionId ? { sessionId } : {},
@@ -21782,10 +22252,10 @@ var GROK_ACP_CLIENT_CAPABILITIES = {
21782
22252
  "x.ai/exit_plan_mode": true
21783
22253
  }
21784
22254
  };
21785
- function isRecord10(value) {
22255
+ function isRecord11(value) {
21786
22256
  return typeof value === "object" && value !== null && !Array.isArray(value);
21787
22257
  }
21788
- function stringField3(value, ...keys) {
22258
+ function stringField4(value, ...keys) {
21789
22259
  for (const key of keys) {
21790
22260
  const field = value[key];
21791
22261
  if (typeof field === "string" && field.length > 0)
@@ -21811,22 +22281,22 @@ function isGrokExitPlanModeMethod(method) {
21811
22281
  function questionsPayload(params) {
21812
22282
  if (Array.isArray(params.questions))
21813
22283
  return params.questions;
21814
- if (isRecord10(params.input) && Array.isArray(params.input.questions))
22284
+ if (isRecord11(params.input) && Array.isArray(params.input.questions))
21815
22285
  return params.input.questions;
21816
- if (isRecord10(params.askUserQuestion) && Array.isArray(params.askUserQuestion.questions)) {
22286
+ if (isRecord11(params.askUserQuestion) && Array.isArray(params.askUserQuestion.questions)) {
21817
22287
  return params.askUserQuestion.questions;
21818
22288
  }
21819
22289
  return void 0;
21820
22290
  }
21821
22291
  function parseOption(value, labels) {
21822
- if (!isRecord10(value))
22292
+ if (!isRecord11(value))
21823
22293
  return null;
21824
- const label = stringField3(value, "label");
22294
+ const label = stringField4(value, "label");
21825
22295
  if (!label || labels.has(label))
21826
22296
  return null;
21827
22297
  labels.add(label);
21828
- const description = stringField3(value, "description");
21829
- const preview = stringField3(value, "preview");
22298
+ const description = stringField4(value, "description");
22299
+ const preview = stringField4(value, "preview");
21830
22300
  const combined = [description, preview].filter((part) => part !== void 0);
21831
22301
  return {
21832
22302
  label,
@@ -21834,9 +22304,9 @@ function parseOption(value, labels) {
21834
22304
  };
21835
22305
  }
21836
22306
  function parseQuestion(value, questions) {
21837
- if (!isRecord10(value))
22307
+ if (!isRecord11(value))
21838
22308
  return null;
21839
- const question = stringField3(value, "question");
22309
+ const question = stringField4(value, "question");
21840
22310
  if (!question || questions.has(question))
21841
22311
  return null;
21842
22312
  if (!Array.isArray(value.options) || value.options.length === 0)
@@ -21850,7 +22320,7 @@ function parseQuestion(value, questions) {
21850
22320
  options.push(parsed);
21851
22321
  }
21852
22322
  questions.add(question);
21853
- const header = stringField3(value, "header");
22323
+ const header = stringField4(value, "header");
21854
22324
  return {
21855
22325
  question,
21856
22326
  ...header ? { header } : {},
@@ -21859,7 +22329,7 @@ function parseQuestion(value, questions) {
21859
22329
  };
21860
22330
  }
21861
22331
  function parseGrokAskUserQuestionParams(params) {
21862
- if (!isRecord10(params))
22332
+ if (!isRecord11(params))
21863
22333
  return null;
21864
22334
  const rawQuestions = questionsPayload(params);
21865
22335
  if (!Array.isArray(rawQuestions) || rawQuestions.length === 0)
@@ -21872,7 +22342,7 @@ function parseGrokAskUserQuestionParams(params) {
21872
22342
  return null;
21873
22343
  questions.push(parsed);
21874
22344
  }
21875
- const sessionId = stringField3(params, "sessionId", "session_id");
22345
+ const sessionId = stringField4(params, "sessionId", "session_id");
21876
22346
  const timeoutMs = optionalTimeoutMs(params);
21877
22347
  return {
21878
22348
  questions,
@@ -21974,9 +22444,18 @@ var GrokTransportError = class extends Error {
21974
22444
  this.name = "GrokTransportError";
21975
22445
  }
21976
22446
  };
21977
- function isRecord11(value) {
22447
+ function isRecord12(value) {
21978
22448
  return typeof value === "object" && value !== null && !Array.isArray(value);
21979
22449
  }
22450
+ function acpToolName(update, metadata) {
22451
+ if (!isRecord12(update))
22452
+ return void 0;
22453
+ if (typeof update.name === "string" && update.name.length > 0)
22454
+ return update.name;
22455
+ const meta3 = isRecord12(update._meta) ? update._meta : metadata;
22456
+ const tool = meta3 && isRecord12(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
22457
+ return tool && typeof tool.name === "string" && tool.name.length > 0 ? tool.name : void 0;
22458
+ }
21980
22459
  function errorText(error53) {
21981
22460
  return error53 instanceof Error ? error53.message : String(error53);
21982
22461
  }
@@ -22030,7 +22509,7 @@ function signalProcessTree(child, signal) {
22030
22509
  try {
22031
22510
  process.kill(-child.pid, signal);
22032
22511
  } catch (error53) {
22033
- if (!isRecord11(error53) || error53.code !== "ESRCH")
22512
+ if (!isRecord12(error53) || error53.code !== "ESRCH")
22034
22513
  throw error53;
22035
22514
  }
22036
22515
  }
@@ -22055,6 +22534,9 @@ function transportEvent(update, metadata) {
22055
22534
  const compaction = grokCompactionEventFromUpdate(extension);
22056
22535
  if (compaction)
22057
22536
  return compaction;
22537
+ const subagent = grokSubagentEventFromUpdate(extension);
22538
+ if (subagent)
22539
+ return subagent;
22058
22540
  switch (update.sessionUpdate) {
22059
22541
  case "user_message_chunk":
22060
22542
  case "agent_message_chunk":
@@ -22066,30 +22548,34 @@ function transportEvent(update, metadata) {
22066
22548
  text: update.content.text,
22067
22549
  ...update.messageId ? { messageId: update.messageId } : {}
22068
22550
  };
22069
- case "tool_call":
22551
+ case "tool_call": {
22552
+ const name = acpToolName(update, metadata);
22070
22553
  return {
22071
22554
  type: "tool.call",
22072
22555
  callId: update.toolCallId,
22073
22556
  title: update.title,
22074
- ...update.name ? { name: update.name } : {},
22557
+ ...name ? { name } : {},
22075
22558
  ...update.kind ? { kind: update.kind } : {},
22076
22559
  ...update.status ? { status: update.status } : {},
22077
22560
  ...update.rawInput !== void 0 ? { rawInput: update.rawInput } : {},
22078
22561
  ...update.rawOutput !== void 0 ? { rawOutput: update.rawOutput } : {},
22079
22562
  ...update.content ? { content: update.content } : {}
22080
22563
  };
22081
- case "tool_call_update":
22564
+ }
22565
+ case "tool_call_update": {
22566
+ const name = acpToolName(update, metadata);
22082
22567
  return {
22083
22568
  type: "tool.update",
22084
22569
  callId: update.toolCallId,
22085
22570
  ...update.title !== void 0 ? { title: update.title } : {},
22086
- ...update.name !== void 0 ? { name: update.name } : {},
22571
+ ...name ? { name } : {},
22087
22572
  ...update.kind !== void 0 ? { kind: update.kind } : {},
22088
22573
  ...update.status !== void 0 ? { status: update.status } : {},
22089
22574
  ...update.rawInput !== void 0 ? { rawInput: update.rawInput } : {},
22090
22575
  ...update.rawOutput !== void 0 ? { rawOutput: update.rawOutput } : {},
22091
22576
  ...update.content !== void 0 ? { content: update.content } : {}
22092
22577
  };
22578
+ }
22093
22579
  case "usage_update":
22094
22580
  return { type: "usage", update, ...metadata ? { metadata } : {} };
22095
22581
  default:
@@ -22118,7 +22604,7 @@ async function readNativeSignals(options, sessionId) {
22118
22604
  }
22119
22605
  }
22120
22606
  function isMissingFile(error53) {
22121
- return isRecord11(error53) && error53.code === "ENOENT";
22607
+ return isRecord12(error53) && error53.code === "ENOENT";
22122
22608
  }
22123
22609
  async function locateGrokNativeSession(options, sessionId) {
22124
22610
  if (sessionId.length === 0)
@@ -22141,7 +22627,7 @@ async function locateGrokNativeSession(options, sessionId) {
22141
22627
  try {
22142
22628
  summaryRaw = await readFile(path8.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
22143
22629
  } catch (error53) {
22144
- if (isMissingFile(error53) || isRecord11(error53) && error53.code === "ENOTDIR")
22630
+ if (isMissingFile(error53) || isRecord12(error53) && error53.code === "ENOTDIR")
22145
22631
  continue;
22146
22632
  throw new GrokTransportError("unavailable", "Grok Native Session metadata could not be read", {
22147
22633
  cause: error53
@@ -22153,10 +22639,10 @@ async function locateGrokNativeSession(options, sessionId) {
22153
22639
  } catch {
22154
22640
  continue;
22155
22641
  }
22156
- if (!isRecord11(parsed))
22642
+ if (!isRecord12(parsed))
22157
22643
  continue;
22158
22644
  const info = parsed.info;
22159
- const cwd = isRecord11(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path8.resolve(info.cwd) : path8.resolve(decodeURIComponent(entry.name));
22645
+ const cwd = isRecord12(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path8.resolve(info.cwd) : path8.resolve(decodeURIComponent(entry.name));
22160
22646
  const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path8.resolve(parsed.source_workspace_dir) : void 0;
22161
22647
  matches.push({
22162
22648
  cwd,
@@ -22189,12 +22675,12 @@ function parseNativeHistory(contents, sessionId) {
22189
22675
  } catch {
22190
22676
  throw new GrokTransportError("protocolError", "Grok Native history contains invalid JSON");
22191
22677
  }
22192
- if (!isRecord11(record2) || !isRecord11(record2.params))
22678
+ if (!isRecord12(record2) || !isRecord12(record2.params))
22193
22679
  continue;
22194
22680
  const params = record2.params;
22195
- if (params.sessionId !== sessionId || !isRecord11(params.update))
22681
+ if (params.sessionId !== sessionId || !isRecord12(params.update))
22196
22682
  continue;
22197
- const metadata = isRecord11(params._meta) ? params._meta : void 0;
22683
+ const metadata = isRecord12(params._meta) ? params._meta : void 0;
22198
22684
  const event = transportEvent(params.update, metadata);
22199
22685
  if (event)
22200
22686
  events.push(metadata ? { ...event, metadata } : event);
@@ -22497,7 +22983,7 @@ var GrokAcpTransport = class {
22497
22983
  modelId,
22498
22984
  ...reasoningEffort ? { reasoningEffort } : {}
22499
22985
  });
22500
- if (!isRecord11(response) || !isRecord11(response._meta) || !isRecord11(response._meta.model)) {
22986
+ if (!isRecord12(response) || !isRecord12(response._meta) || !isRecord12(response._meta.model)) {
22501
22987
  throw new GrokTransportError("protocolError", "Grok rejected Model configuration");
22502
22988
  }
22503
22989
  const selected = response._meta.model.Ok;
@@ -22540,7 +23026,7 @@ var GrokAcpTransport = class {
22540
23026
  #handleUpdate(notification) {
22541
23027
  if (this.#sessionId && notification.sessionId !== this.#sessionId)
22542
23028
  return;
22543
- const metadata = isRecord11(notification._meta) ? notification._meta : void 0;
23029
+ const metadata = isRecord12(notification._meta) ? notification._meta : void 0;
22544
23030
  const event = transportEvent(notification.update, metadata);
22545
23031
  if (!event)
22546
23032
  return;
@@ -22555,7 +23041,7 @@ var GrokAcpTransport = class {
22555
23041
  #handleExtensionNotification(method, params) {
22556
23042
  if (!isGrokExtensionSessionUpdateMethod(method))
22557
23043
  return;
22558
- if (typeof params.sessionId !== "string" || !isRecord11(params.update))
23044
+ if (typeof params.sessionId !== "string" || !isRecord12(params.update))
22559
23045
  return;
22560
23046
  this.#handleUpdate(params);
22561
23047
  }
@@ -22582,8 +23068,200 @@ var GrokAcpTransport = class {
22582
23068
  }
22583
23069
  };
22584
23070
 
23071
+ // dist/grok-subagent-lifecycle.js
23072
+ function subagentFailure() {
23073
+ return {
23074
+ code: "nativeFailure",
23075
+ message: "Grok Subagent delegation failed",
23076
+ retryable: false
23077
+ };
23078
+ }
23079
+ var GrokSubagentLifecycle = class {
23080
+ #emit;
23081
+ #newItemId;
23082
+ #delegations = /* @__PURE__ */ new Map();
23083
+ #callIdByNativeId = /* @__PURE__ */ new Map();
23084
+ constructor(options) {
23085
+ this.#emit = options.emit;
23086
+ this.#newItemId = options.newItemId;
23087
+ }
23088
+ get size() {
23089
+ return this.#delegations.size;
23090
+ }
23091
+ has(callId) {
23092
+ return this.#delegations.has(callId);
23093
+ }
23094
+ nativeSubagentId(callId) {
23095
+ return this.#delegations.get(callId)?.item.subagents[0]?.nativeSubagentId;
23096
+ }
23097
+ start(turnId, input) {
23098
+ if (this.#delegations.has(input.callId)) {
23099
+ throw new Error("Grok Subagent delegation started more than once");
23100
+ }
23101
+ this.#callIdByNativeId.set(input.callId, input.callId);
23102
+ if (input.nativeSubagentId)
23103
+ this.#callIdByNativeId.set(input.nativeSubagentId, input.callId);
23104
+ const subagent = {
23105
+ subagentId: input.nativeSubagentId ?? input.callId,
23106
+ ...input.nativeSubagentId ? { nativeSubagentId: input.nativeSubagentId } : {},
23107
+ description: input.description,
23108
+ ...input.role ? { role: input.role } : {},
23109
+ ...input.model ? { model: input.model } : {},
23110
+ ...input.reasoningEffort ? { reasoningEffort: input.reasoningEffort } : {},
23111
+ background: input.background,
23112
+ status: "running"
23113
+ };
23114
+ const item = {
23115
+ type: "subagentDelegation",
23116
+ itemId: this.#newItemId(),
23117
+ operation: input.operation,
23118
+ ...input.prompt ? { prompt: input.prompt } : {},
23119
+ subagents: [subagent]
23120
+ };
23121
+ this.#delegations.set(input.callId, { callId: input.callId, item });
23122
+ this.#emit({ type: "item.started", turnId, item });
23123
+ this.#emitState(subagent);
23124
+ return subagent;
23125
+ }
23126
+ bindNativeId(turnId, input) {
23127
+ for (const [callId, active] of this.#delegations) {
23128
+ const current = active.item.subagents[0];
23129
+ if (!current)
23130
+ continue;
23131
+ if (current.nativeSubagentId === input.nativeSubagentId) {
23132
+ return this.update(turnId, callId, input);
23133
+ }
23134
+ }
23135
+ for (const [callId, active] of this.#delegations) {
23136
+ const current = active.item.subagents[0];
23137
+ if (!current || current.nativeSubagentId)
23138
+ continue;
23139
+ if (input.description && current.description === input.description) {
23140
+ return this.update(turnId, callId, input);
23141
+ }
23142
+ }
23143
+ return void 0;
23144
+ }
23145
+ update(turnId, callId, patch) {
23146
+ const active = this.#delegations.get(callId);
23147
+ if (!active)
23148
+ return void 0;
23149
+ const current = active.item.subagents[0];
23150
+ if (!current)
23151
+ throw new Error("Grok Subagent delegation has no Agent state");
23152
+ if (patch.nativeSubagentId)
23153
+ this.#callIdByNativeId.set(patch.nativeSubagentId, callId);
23154
+ const nativeSubagentId = patch.nativeSubagentId ?? current.nativeSubagentId;
23155
+ const subagent = {
23156
+ ...current,
23157
+ ...nativeSubagentId ? { nativeSubagentId, subagentId: nativeSubagentId } : {},
23158
+ ...patch.description ? { description: patch.description } : {},
23159
+ ...patch.role ? { role: patch.role } : {},
23160
+ ...patch.model ? { model: patch.model } : {},
23161
+ ...patch.reasoningEffort ? { reasoningEffort: patch.reasoningEffort } : {},
23162
+ ...patch.resultSummary ? { resultSummary: patch.resultSummary } : {},
23163
+ ...patch.status ? { status: patch.status } : {}
23164
+ };
23165
+ active.item = { ...active.item, subagents: [subagent] };
23166
+ this.#emit({
23167
+ type: "item.updated",
23168
+ turnId,
23169
+ itemId: active.item.itemId,
23170
+ update: { type: "subagents.replace", subagents: active.item.subagents }
23171
+ });
23172
+ this.#emitState(subagent);
23173
+ return subagent;
23174
+ }
23175
+ completeSpawn(turnId, callId, input) {
23176
+ const active = this.#delegations.get(callId);
23177
+ const background = input.background ?? active?.item.subagents[0]?.background ?? true;
23178
+ const keepRunning = !input.failed && !input.cancellationRequested && (background || active?.item.operation === "send");
23179
+ if (keepRunning) {
23180
+ return this.update(turnId, callId, {
23181
+ status: "running",
23182
+ ...input.nativeSubagentId ? { nativeSubagentId: input.nativeSubagentId } : {},
23183
+ ...input.resultSummary ? { resultSummary: input.resultSummary } : {}
23184
+ });
23185
+ }
23186
+ return this.complete(turnId, callId, { ...input, keepRunning: false });
23187
+ }
23188
+ completeByNativeId(turnId, nativeSubagentId, input) {
23189
+ const callId = this.#callIdByNativeId.get(nativeSubagentId) ?? this.#callIdForNative(nativeSubagentId);
23190
+ if (callId && this.#delegations.has(callId)) {
23191
+ return this.complete(turnId, callId, { ...input, nativeSubagentId });
23192
+ }
23193
+ const status = input.status ?? (input.cancellationRequested ? "interrupted" : input.failed ? "failed" : "completed");
23194
+ this.#emit({
23195
+ type: "subagent.state.changed",
23196
+ nativeSubagentId,
23197
+ status,
23198
+ ...input.resultSummary ? { resultSummary: input.resultSummary } : {}
23199
+ });
23200
+ return void 0;
23201
+ }
23202
+ complete(turnId, callId, input) {
23203
+ const active = this.#delegations.get(callId);
23204
+ if (!active)
23205
+ return void 0;
23206
+ this.#delegations.delete(callId);
23207
+ const current = active.item.subagents[0];
23208
+ if (!current)
23209
+ throw new Error("Grok Subagent delegation has no Agent state");
23210
+ const status = input.status ?? (input.cancellationRequested ? "interrupted" : input.failed ? "failed" : input.keepRunning ? "running" : "completed");
23211
+ const nativeSubagentId = input.nativeSubagentId ?? current.nativeSubagentId;
23212
+ if (nativeSubagentId)
23213
+ this.#callIdByNativeId.set(nativeSubagentId, callId);
23214
+ const subagent = {
23215
+ ...current,
23216
+ status,
23217
+ ...nativeSubagentId ? { nativeSubagentId, subagentId: nativeSubagentId } : {},
23218
+ ...input.resultSummary ? { resultSummary: input.resultSummary } : {}
23219
+ };
23220
+ const item = { ...active.item, subagents: [subagent] };
23221
+ this.#emit({
23222
+ type: "item.updated",
23223
+ turnId,
23224
+ itemId: item.itemId,
23225
+ update: { type: "subagents.replace", subagents: item.subagents }
23226
+ });
23227
+ const outcome = input.cancellationRequested ? { status: "cancelled", reason: "Cancelled by user" } : input.failed ? { status: "failed", error: subagentFailure() } : { status: "succeeded" };
23228
+ this.#emit({ type: "item.completed", turnId, snapshot: { item, outcome } });
23229
+ this.#emitState(subagent);
23230
+ return subagent;
23231
+ }
23232
+ finalize(turnId, outcome) {
23233
+ for (const [callId, active] of this.#delegations) {
23234
+ this.#delegations.delete(callId);
23235
+ const current = active.item.subagents[0];
23236
+ if (!current)
23237
+ continue;
23238
+ const status = outcome.status === "succeeded" ? current.status : outcome.status === "cancelled" ? "interrupted" : "failed";
23239
+ const item = { ...active.item, subagents: [{ ...current, status }] };
23240
+ this.#emit({ type: "item.completed", turnId, snapshot: { item, outcome } });
23241
+ this.#emitState({ ...current, status });
23242
+ }
23243
+ }
23244
+ #callIdForNative(nativeSubagentId) {
23245
+ for (const [callId, active] of this.#delegations) {
23246
+ if (active.item.subagents[0]?.nativeSubagentId === nativeSubagentId)
23247
+ return callId;
23248
+ }
23249
+ return void 0;
23250
+ }
23251
+ #emitState(subagent) {
23252
+ if (!subagent.nativeSubagentId)
23253
+ return;
23254
+ this.#emit({
23255
+ type: "subagent.state.changed",
23256
+ nativeSubagentId: subagent.nativeSubagentId,
23257
+ status: subagent.status,
23258
+ ...subagent.resultSummary ? { resultSummary: subagent.resultSummary } : {}
23259
+ });
23260
+ }
23261
+ };
23262
+
22585
23263
  // dist/grok-models.js
22586
- function isRecord12(value) {
23264
+ function isRecord13(value) {
22587
23265
  return typeof value === "object" && value !== null && !Array.isArray(value);
22588
23266
  }
22589
23267
  function nonBlank(value) {
@@ -22595,7 +23273,7 @@ function thinkingOptions(value) {
22595
23273
  const seen = /* @__PURE__ */ new Set();
22596
23274
  const options = [];
22597
23275
  for (const candidate of value) {
22598
- if (!isRecord12(candidate) || !nonBlank(candidate.label))
23276
+ if (!isRecord13(candidate) || !nonBlank(candidate.label))
22599
23277
  continue;
22600
23278
  const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
22601
23279
  if (!id.success || seen.has(id.data))
@@ -22606,7 +23284,7 @@ function thinkingOptions(value) {
22606
23284
  return options;
22607
23285
  }
22608
23286
  function parseGrokModelState(value) {
22609
- if (!isRecord12(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
23287
+ if (!isRecord13(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
22610
23288
  return null;
22611
23289
  }
22612
23290
  const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
@@ -22617,12 +23295,12 @@ function parseGrokModelState(value) {
22617
23295
  const models = [];
22618
23296
  let currentThinkingOptionId;
22619
23297
  for (const candidate of value.availableModels) {
22620
- if (!isRecord12(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
23298
+ if (!isRecord13(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
22621
23299
  continue;
22622
23300
  const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
22623
23301
  if (!ref.success)
22624
23302
  continue;
22625
- const metadata = isRecord12(candidate._meta) ? candidate._meta : {};
23303
+ const metadata = isRecord13(candidate._meta) ? candidate._meta : {};
22626
23304
  const options2 = thinkingOptions(metadata.reasoningEfforts);
22627
23305
  if (typeof metadata.totalContextTokens === "number" && Number.isSafeInteger(metadata.totalContextTokens) && metadata.totalContextTokens > 0) {
22628
23306
  contextWindowTokensByModel.set(ref.data.id, metadata.totalContextTokens);
@@ -22657,10 +23335,10 @@ function parseGrokModelState(value) {
22657
23335
  };
22658
23336
  }
22659
23337
  function modelStateFromInitialize(response) {
22660
- return parseGrokModelState(isRecord12(response._meta) ? response._meta.modelState : void 0);
23338
+ return parseGrokModelState(isRecord13(response._meta) ? response._meta.modelState : void 0);
22661
23339
  }
22662
23340
  function modelStateFromSessionResponse(response) {
22663
- return parseGrokModelState(isRecord12(response) ? response.models : void 0);
23341
+ return parseGrokModelState(isRecord13(response) ? response.models : void 0);
22664
23342
  }
22665
23343
  function stateForGrokModel(modelState, nativeState, model = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
22666
23344
  const selectedModel = model;
@@ -22684,7 +23362,7 @@ import os4 from "node:os";
22684
23362
  import path9 from "node:path";
22685
23363
  var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
22686
23364
  var REQUEST_TIMEOUT_MS = 15e3;
22687
- function isRecord13(value) {
23365
+ function isRecord14(value) {
22688
23366
  return typeof value === "object" && value !== null && !Array.isArray(value);
22689
23367
  }
22690
23368
  function finitePercent(value) {
@@ -22714,7 +23392,7 @@ function productUsageFrom(value) {
22714
23392
  if (!Array.isArray(value))
22715
23393
  return void 0;
22716
23394
  const products = value.flatMap((entry) => {
22717
- if (!isRecord13(entry) || typeof entry.product !== "string")
23395
+ if (!isRecord14(entry) || typeof entry.product !== "string")
22718
23396
  return [];
22719
23397
  const usagePercent = finitePercent(entry.usagePercent);
22720
23398
  return usagePercent === void 0 ? [] : [{ product: entry.product, usagePercent }];
@@ -22722,13 +23400,13 @@ function productUsageFrom(value) {
22722
23400
  return products.length > 0 ? products : void 0;
22723
23401
  }
22724
23402
  function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
22725
- if (!isRecord13(value) || !isRecord13(value.config))
23403
+ if (!isRecord14(value) || !isRecord14(value.config))
22726
23404
  return null;
22727
23405
  const config2 = value.config;
22728
- const period = isRecord13(config2.currentPeriod) ? config2.currentPeriod : void 0;
23406
+ const period = isRecord14(config2.currentPeriod) ? config2.currentPeriod : void 0;
22729
23407
  const resetsAt = (typeof period?.end === "string" && period.end.length > 0 ? period.end : void 0) ?? (typeof config2.billingPeriodEnd === "string" && config2.billingPeriodEnd.length > 0 ? config2.billingPeriodEnd : void 0);
22730
- const onDemandCap = isRecord13(config2.onDemandCap) ? nonNegativeNumber(config2.onDemandCap.val) : void 0;
22731
- const onDemandUsed = isRecord13(config2.onDemandUsed) ? nonNegativeNumber(config2.onDemandUsed.val) : void 0;
23408
+ const onDemandCap = isRecord14(config2.onDemandCap) ? nonNegativeNumber(config2.onDemandCap.val) : void 0;
23409
+ const onDemandUsed = isRecord14(config2.onDemandUsed) ? nonNegativeNumber(config2.onDemandUsed.val) : void 0;
22732
23410
  const usedPercent = finitePercent(config2.creditUsagePercent) ?? (onDemandCap !== void 0 && onDemandCap > 0 && onDemandUsed !== void 0 ? Math.min(100, Math.max(0, onDemandUsed / onDemandCap * 100)) : void 0);
22733
23411
  if (usedPercent === void 0)
22734
23412
  return null;
@@ -22742,11 +23420,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
22742
23420
  };
22743
23421
  }
22744
23422
  function selectAccessToken(auth, now) {
22745
- if (!isRecord13(auth))
23423
+ if (!isRecord14(auth))
22746
23424
  return null;
22747
- const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) && isRecord13(value) && typeof value.key === "string" && value.key.length > 0).sort(([left], [right]) => Number(right.startsWith("https://auth.x.ai")) - Number(left.startsWith("https://auth.x.ai")));
23425
+ const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) && isRecord14(value) && typeof value.key === "string" && value.key.length > 0).sort(([left], [right]) => Number(right.startsWith("https://auth.x.ai")) - Number(left.startsWith("https://auth.x.ai")));
22748
23426
  for (const [, value] of entries) {
22749
- if (!isRecord13(value) || typeof value.key !== "string")
23427
+ if (!isRecord14(value) || typeof value.key !== "string")
22750
23428
  continue;
22751
23429
  if (typeof value.expires_at === "string") {
22752
23430
  const expiresAt = Date.parse(value.expires_at);
@@ -22818,7 +23496,7 @@ async function fetchGrokCredits(input = {}) {
22818
23496
 
22819
23497
  // dist/grok-usage.js
22820
23498
  var USD_TICKS_PER_DOLLAR = 1e10;
22821
- function isRecord14(value) {
23499
+ function isRecord15(value) {
22822
23500
  return typeof value === "object" && value !== null && !Array.isArray(value);
22823
23501
  }
22824
23502
  function optionalToken(value) {
@@ -22835,7 +23513,7 @@ function combineUsage(base, next) {
22835
23513
  return base === null ? next : parseHostUsage({ ...base, ...next });
22836
23514
  }
22837
23515
  function usageFromNative(value) {
22838
- if (!isRecord14(value))
23516
+ if (!isRecord15(value))
22839
23517
  return null;
22840
23518
  const nativeInputTokens = optionalToken(value.inputTokens);
22841
23519
  const cachedRead = optionalToken(value.cachedReadTokens);
@@ -22864,7 +23542,7 @@ function usageFromPrompt(response) {
22864
23542
  return response.usage ? usageFromNative(response.usage) : null;
22865
23543
  }
22866
23544
  function usageFromSignals(value) {
22867
- if (!isRecord14(value))
23545
+ if (!isRecord15(value))
22868
23546
  return null;
22869
23547
  try {
22870
23548
  return parseHostUsage({
@@ -22884,7 +23562,7 @@ var summedUsageFields = [
22884
23562
  "totalTokens"
22885
23563
  ];
22886
23564
  function nativeCostTicks(value) {
22887
- if (!isRecord14(value))
23565
+ if (!isRecord15(value))
22888
23566
  return void 0;
22889
23567
  const ticks = value.costUsdTicks;
22890
23568
  if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
@@ -22961,7 +23639,7 @@ function usageFromCompact(tokensAfter, contextWindowTokens) {
22961
23639
  function usageFromUpdate(update, metadata, contextWindowTokens) {
22962
23640
  try {
22963
23641
  if (update?.sessionUpdate === "usage_update") {
22964
- const cost = isRecord14(update.cost) ? update.cost : null;
23642
+ const cost = isRecord15(update.cost) ? update.cost : null;
22965
23643
  return parseHostUsage({
22966
23644
  contextUsedTokens: update.used,
22967
23645
  contextWindowTokens: update.size,
@@ -23002,7 +23680,8 @@ function capabilitiesForModels(modelState) {
23002
23680
  selectPermissionMode: true,
23003
23681
  permissionModeScope: "atCreate"
23004
23682
  },
23005
- history: { fork: true, forkAcrossCwd: true, rollbackLastTurn: true }
23683
+ history: { fork: true, forkAcrossCwd: true, rollbackLastTurn: true },
23684
+ subagents: { observe: true, readTranscript: true }
23006
23685
  };
23007
23686
  }
23008
23687
  var DEFAULT_CLOSE_TIMEOUT_MS = 2e3;
@@ -23203,6 +23882,7 @@ var GrokHarnessSession = class {
23203
23882
  compactionContextWindow: void 0,
23204
23883
  compactionTerminal: null,
23205
23884
  tools: /* @__PURE__ */ new Map(),
23885
+ subagents: this.#createSubagents(),
23206
23886
  completedItems: [],
23207
23887
  approvals: /* @__PURE__ */ new Map(),
23208
23888
  questions: /* @__PURE__ */ new Map(),
@@ -23278,6 +23958,7 @@ var GrokHarnessSession = class {
23278
23958
  compactionContextWindow: void 0,
23279
23959
  compactionTerminal: null,
23280
23960
  tools: /* @__PURE__ */ new Map(),
23961
+ subagents: this.#createSubagents(),
23281
23962
  completedItems: [],
23282
23963
  approvals: /* @__PURE__ */ new Map(),
23283
23964
  questions: /* @__PURE__ */ new Map(),
@@ -23607,6 +24288,10 @@ var GrokHarnessSession = class {
23607
24288
  this.#startTool(active, event);
23608
24289
  else if (event.type === "tool.update")
23609
24290
  this.#updateTool(active, event);
24291
+ else if (event.type === "subagent.spawned")
24292
+ this.#bindSpawnedSubagent(active, event);
24293
+ else if (event.type === "subagent.finished")
24294
+ this.#finishNativeSubagent(active, event);
23610
24295
  else if (event.type === "compaction.started")
23611
24296
  this.#startCompaction(active, event);
23612
24297
  else if (event.type === "compaction.completed") {
@@ -23713,9 +24398,44 @@ var GrokHarnessSession = class {
23713
24398
  update: { type: "text.append", text }
23714
24399
  });
23715
24400
  }
24401
+ #createSubagents() {
24402
+ return new GrokSubagentLifecycle({
24403
+ newItemId: () => hostItemIdSchema.parse(this.#randomUUID()),
24404
+ emit: (event) => this.#event(event)
24405
+ });
24406
+ }
24407
+ #subagentModelLabel(modelId) {
24408
+ const id = modelId ?? this.#state.effectiveModel?.id;
24409
+ if (!id)
24410
+ return void 0;
24411
+ return this.#modelState.catalog.models.find((model) => model.ref.id === id)?.label ?? id;
24412
+ }
23716
24413
  #startTool(active, event) {
23717
24414
  this.#completeReasoning(active, { status: "succeeded" });
23718
24415
  this.#completeAgent(active, { status: "succeeded" });
24416
+ const operation = grokSubagentOperation(event.name, event.title, event.rawInput);
24417
+ if (operation) {
24418
+ const prompt = grokSubagentPrompt(event.rawInput);
24419
+ const role = grokSubagentRole(event.rawInput);
24420
+ const nativeSubagentId = grokNativeSubagentId(event.rawInput);
24421
+ const model = this.#subagentModelLabel(grokSubagentModel(event.rawInput));
24422
+ const reasoningEffort = this.#state.effectiveThinkingOptionId;
24423
+ active.subagents.start(active.command.turnId, {
24424
+ callId: event.callId,
24425
+ operation,
24426
+ description: grokSubagentDescription(event.rawInput, event.title),
24427
+ ...prompt ? { prompt } : {},
24428
+ ...role ? { role } : {},
24429
+ ...model ? { model } : {},
24430
+ ...reasoningEffort ? { reasoningEffort } : {},
24431
+ background: grokSubagentBackground(event.rawInput),
24432
+ ...nativeSubagentId ? { nativeSubagentId } : {}
24433
+ });
24434
+ if (event.status === "completed" || event.status === "failed") {
24435
+ this.#completeSubagentTool(active, event.callId, event.status, event);
24436
+ }
24437
+ return;
24438
+ }
23719
24439
  let item = startGrokToolItem({
23720
24440
  itemId: hostItemIdSchema.parse(this.#randomUUID()),
23721
24441
  name: event.name,
@@ -23734,6 +24454,34 @@ var GrokHarnessSession = class {
23734
24454
  }
23735
24455
  }
23736
24456
  #updateTool(active, event) {
24457
+ if (!active.subagents.has(event.callId) && !active.tools.has(event.callId) && grokSubagentOperation(event.name, event.title, event.rawInput)) {
24458
+ this.#startTool(active, {
24459
+ type: "tool.call",
24460
+ callId: event.callId,
24461
+ title: event.title ?? "Grok Subagent",
24462
+ ...event.name ? { name: event.name } : {},
24463
+ ...event.kind ? { kind: event.kind } : {},
24464
+ ...event.status ? { status: event.status } : {},
24465
+ ...event.rawInput !== void 0 ? { rawInput: event.rawInput } : {},
24466
+ ...event.rawOutput !== void 0 ? { rawOutput: event.rawOutput } : {},
24467
+ ...event.content ? { content: event.content } : {}
24468
+ });
24469
+ return;
24470
+ }
24471
+ if (active.subagents.has(event.callId)) {
24472
+ if (event.status === "completed" || event.status === "failed") {
24473
+ this.#completeSubagentTool(active, event.callId, event.status, event);
24474
+ return;
24475
+ }
24476
+ const role = grokSubagentRole(event.rawInput);
24477
+ const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content);
24478
+ active.subagents.update(active.command.turnId, event.callId, {
24479
+ ...event.title ? { description: grokSubagentDescription(event.rawInput, event.title) } : {},
24480
+ ...role ? { role } : {},
24481
+ ...nativeSubagentId ? { nativeSubagentId } : {}
24482
+ });
24483
+ return;
24484
+ }
23737
24485
  const tool = active.tools.get(event.callId);
23738
24486
  if (!tool)
23739
24487
  return;
@@ -23787,6 +24535,7 @@ var GrokHarnessSession = class {
23787
24535
  }
23788
24536
  } : { status: "succeeded" };
23789
24537
  this.#completeItem(active, tool.item, outcome);
24538
+ this.#completeWatchedSubagents(active, tool.item, content, rawOutput);
23790
24539
  if (status !== "completed")
23791
24540
  return;
23792
24541
  const changes = projectGrokFileChanges(content, this.#cwd);
@@ -23800,6 +24549,52 @@ var GrokHarnessSession = class {
23800
24549
  this.#event({ type: "item.started", turnId: active.command.turnId, item: fileItem });
23801
24550
  this.#completeItem(active, fileItem, { status: "succeeded" });
23802
24551
  }
24552
+ #completeSubagentTool(active, callId, status, event) {
24553
+ const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content);
24554
+ const resultSummary = grokSubagentResultSummary(event.content, event.rawOutput);
24555
+ active.subagents.completeSpawn(active.command.turnId, callId, {
24556
+ failed: status === "failed",
24557
+ cancellationRequested: active.cancellationRequested,
24558
+ ...nativeSubagentId ? { nativeSubagentId } : {},
24559
+ ...resultSummary ? { resultSummary } : {}
24560
+ });
24561
+ }
24562
+ #completeWatchedSubagents(active, item, content, rawOutput) {
24563
+ const name = item.type === "toolExecution" ? item.toolName : item.command;
24564
+ const rawInput = item.type === "toolExecution" ? item.arguments : void 0;
24565
+ const resultSummary = grokSubagentResultSummary(content, rawOutput);
24566
+ for (const settlement of grokSubagentWaitSettlements({
24567
+ name,
24568
+ title: name,
24569
+ rawInput,
24570
+ content,
24571
+ rawOutput
24572
+ })) {
24573
+ active.subagents.completeByNativeId(active.command.turnId, settlement.id, {
24574
+ failed: settlement.status === "failed",
24575
+ cancellationRequested: active.cancellationRequested || settlement.status === "interrupted",
24576
+ status: settlement.status,
24577
+ ...settlement.resultSummary ? { resultSummary: settlement.resultSummary } : resultSummary ? { resultSummary } : {}
24578
+ });
24579
+ }
24580
+ }
24581
+ #bindSpawnedSubagent(active, event) {
24582
+ const model = event.model ? this.#subagentModelLabel(event.model) : void 0;
24583
+ active.subagents.bindNativeId(active.command.turnId, {
24584
+ nativeSubagentId: event.nativeSubagentId,
24585
+ ...event.description ? { description: event.description } : {},
24586
+ ...event.role ? { role: event.role } : {},
24587
+ ...model ? { model } : {}
24588
+ });
24589
+ }
24590
+ #finishNativeSubagent(active, event) {
24591
+ active.subagents.completeByNativeId(active.command.turnId, event.nativeSubagentId, {
24592
+ failed: event.status === "failed",
24593
+ cancellationRequested: active.cancellationRequested || event.status === "interrupted",
24594
+ status: event.status,
24595
+ ...event.resultSummary ? { resultSummary: event.resultSummary } : {}
24596
+ });
24597
+ }
23803
24598
  #completeAgent(active, outcome) {
23804
24599
  const item = active.agent;
23805
24600
  if (item && active.rawAgentText.length > 0) {
@@ -23863,6 +24658,7 @@ var GrokHarnessSession = class {
23863
24658
  const itemOutcome = outcome;
23864
24659
  this.#completeReasoning(active, itemOutcome);
23865
24660
  this.#completeAgent(active, itemOutcome);
24661
+ active.subagents.finalize(active.command.turnId, itemOutcome);
23866
24662
  if (active.compactionItem) {
23867
24663
  this.#completeItem(active, active.compactionItem, itemOutcome);
23868
24664
  active.compactionItem = null;
@@ -23940,6 +24736,39 @@ var GrokHarnessSession = class {
23940
24736
  var GrokAdapter = class {
23941
24737
  commandCatalog = grokCommandCatalog;
23942
24738
  harnessId = grokHarnessId;
24739
+ subagents = {
24740
+ readSnapshot: async (input) => {
24741
+ if (input.parent.harnessId !== this.harnessId || input.nativeSubagentId.trim().length === 0) {
24742
+ return {
24743
+ ok: false,
24744
+ error: {
24745
+ code: "invalidRequest",
24746
+ message: "Grok Subagent reference is invalid",
24747
+ retryable: false
24748
+ }
24749
+ };
24750
+ }
24751
+ try {
24752
+ const location = await locateGrokNativeSession(this.#environment ? { environment: this.#environment } : {}, input.nativeSubagentId);
24753
+ const cwd = location?.cwd ?? input.cwd;
24754
+ const history = await readGrokNativeHistory(this.#environment ? { cwd, environment: this.#environment } : { cwd }, input.nativeSubagentId);
24755
+ return {
24756
+ ok: true,
24757
+ value: mapGrokReplay(
24758
+ history,
24759
+ this.harnessId,
24760
+ // Host Subagent records keep the parent Native Session identity.
24761
+ input.parent.nativeSessionId,
24762
+ cwd,
24763
+ [],
24764
+ this.#toolOutputLimit
24765
+ )
24766
+ };
24767
+ } catch (error53) {
24768
+ return { ok: false, error: normalizeError(error53, "protocolError") };
24769
+ }
24770
+ }
24771
+ };
23943
24772
  #closeTimeoutMs;
23944
24773
  #dependencies;
23945
24774
  #environment;