@liberseek/boft-cli-win32-arm64 0.6.3 → 0.6.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 +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/host-runtime.mjs +204 -131
- package/app/plugins/claude-code/plugin.mjs +664 -229
- package/app/plugins/deepseek-harness/plugin.mjs +82 -17
- package/app/plugins/grok/plugin.mjs +920 -85
- package/app/plugins/kiro-cli/plugin.mjs +77 -61
- package/app/plugins/omp/plugin.mjs +6 -0
- package/app/plugins/opencode/plugin.mjs +292 -142
- package/app/plugins/pi/plugin.mjs +1489 -1304
- package/app/renderer-extension.js +661 -31
- package/bin/codexhost.exe +0 -0
- package/libexec/codexhost-node-repl.exe +0 -0
- package/libexec/codexhost-shim.exe +0 -0
- package/libexec/codexhost-updater.exe +0 -0
- package/package.json +1 -1
|
@@ -19685,6 +19685,12 @@ function parseHostUsage(value) {
|
|
|
19685
19685
|
throw new Error(`Harness Usage contains unknown field '${key}'`);
|
|
19686
19686
|
}
|
|
19687
19687
|
}
|
|
19688
|
+
for (const field of ["totalCredits", "contextUsagePercent"]) {
|
|
19689
|
+
const candidate = value[field];
|
|
19690
|
+
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
|
|
19691
|
+
throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
|
|
19692
|
+
}
|
|
19693
|
+
}
|
|
19688
19694
|
for (const field of tokenFields) {
|
|
19689
19695
|
const candidate = value[field];
|
|
19690
19696
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
|
|
@@ -20990,6 +20996,309 @@ function hasGrokToolProjection(projection) {
|
|
|
20990
20996
|
return projection.output !== void 0 || projection.exitCode !== void 0;
|
|
20991
20997
|
}
|
|
20992
20998
|
|
|
20999
|
+
// dist/grok-subagent.js
|
|
21000
|
+
var SPAWN_TOOL_NAMES = /* @__PURE__ */ new Set(["spawn_subagent", "spawn_agent", "task"]);
|
|
21001
|
+
var SEND_TOOL_NAMES = /* @__PURE__ */ new Set(["send_subagent_message"]);
|
|
21002
|
+
var WAIT_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
21003
|
+
"get_command_or_subagent_output",
|
|
21004
|
+
"get_task_output",
|
|
21005
|
+
"wait_tasks"
|
|
21006
|
+
]);
|
|
21007
|
+
var KILL_TOOL_NAMES = /* @__PURE__ */ new Set(["kill_command_or_subagent", "kill_task"]);
|
|
21008
|
+
var DESCRIPTION_LIMIT = 500;
|
|
21009
|
+
var SUMMARY_LIMIT = 2e3;
|
|
21010
|
+
function isRecord5(value) {
|
|
21011
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21012
|
+
}
|
|
21013
|
+
function idField(value, key) {
|
|
21014
|
+
if (!isRecord5(value))
|
|
21015
|
+
return void 0;
|
|
21016
|
+
const field = value[key];
|
|
21017
|
+
if (typeof field === "string") {
|
|
21018
|
+
const trimmed = field.trim();
|
|
21019
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
21020
|
+
}
|
|
21021
|
+
if (typeof field === "number" && Number.isFinite(field))
|
|
21022
|
+
return String(field);
|
|
21023
|
+
return void 0;
|
|
21024
|
+
}
|
|
21025
|
+
function stringField2(value, key) {
|
|
21026
|
+
if (!isRecord5(value) || typeof value[key] !== "string")
|
|
21027
|
+
return void 0;
|
|
21028
|
+
const trimmed = value[key].trim();
|
|
21029
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
21030
|
+
}
|
|
21031
|
+
function bounded(value, limit) {
|
|
21032
|
+
if (!value)
|
|
21033
|
+
return void 0;
|
|
21034
|
+
return value.slice(0, limit);
|
|
21035
|
+
}
|
|
21036
|
+
function toolId(name, title) {
|
|
21037
|
+
return grokToolName(name, title).toLowerCase();
|
|
21038
|
+
}
|
|
21039
|
+
function collectIds(value) {
|
|
21040
|
+
const ids = [];
|
|
21041
|
+
const push = (entry) => {
|
|
21042
|
+
if (typeof entry === "string" && entry.trim().length > 0)
|
|
21043
|
+
ids.push(entry.trim());
|
|
21044
|
+
else if (typeof entry === "number" && Number.isFinite(entry))
|
|
21045
|
+
ids.push(String(entry));
|
|
21046
|
+
};
|
|
21047
|
+
push(idField(value, "task_id"));
|
|
21048
|
+
push(idField(value, "subagent_id"));
|
|
21049
|
+
if (isRecord5(value)) {
|
|
21050
|
+
const list = value.task_ids ?? value.subagent_ids;
|
|
21051
|
+
if (Array.isArray(list)) {
|
|
21052
|
+
for (const entry of list)
|
|
21053
|
+
push(entry);
|
|
21054
|
+
} else {
|
|
21055
|
+
push(list);
|
|
21056
|
+
}
|
|
21057
|
+
}
|
|
21058
|
+
return [...new Set(ids)];
|
|
21059
|
+
}
|
|
21060
|
+
function grokSubagentOperation(name, title, rawInput) {
|
|
21061
|
+
const id = toolId(name, title);
|
|
21062
|
+
if (WAIT_TOOL_NAMES.has(id) || KILL_TOOL_NAMES.has(id))
|
|
21063
|
+
return null;
|
|
21064
|
+
if (SEND_TOOL_NAMES.has(id))
|
|
21065
|
+
return "send";
|
|
21066
|
+
if (SPAWN_TOOL_NAMES.has(id))
|
|
21067
|
+
return "spawn";
|
|
21068
|
+
if (isRecord5(rawInput) && rawInput.variant === "Task")
|
|
21069
|
+
return "spawn";
|
|
21070
|
+
return null;
|
|
21071
|
+
}
|
|
21072
|
+
function grokSubagentWaitIds(name, title, rawInput) {
|
|
21073
|
+
if (!WAIT_TOOL_NAMES.has(toolId(name, title)) && !KILL_TOOL_NAMES.has(toolId(name, title))) {
|
|
21074
|
+
return [];
|
|
21075
|
+
}
|
|
21076
|
+
return collectIds(rawInput);
|
|
21077
|
+
}
|
|
21078
|
+
function grokSubagentKill(name, title) {
|
|
21079
|
+
return KILL_TOOL_NAMES.has(toolId(name, title));
|
|
21080
|
+
}
|
|
21081
|
+
function grokSubagentDescription(rawInput, title, fallback = "Grok Subagent") {
|
|
21082
|
+
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;
|
|
21083
|
+
}
|
|
21084
|
+
function grokSubagentPrompt(rawInput) {
|
|
21085
|
+
return bounded(stringField2(rawInput, "prompt") ?? stringField2(rawInput, "message"), SUMMARY_LIMIT);
|
|
21086
|
+
}
|
|
21087
|
+
function grokSubagentRole(rawInput) {
|
|
21088
|
+
return bounded(stringField2(rawInput, "subagent_type") ?? stringField2(rawInput, "agent_type") ?? stringField2(rawInput, "type"), DESCRIPTION_LIMIT);
|
|
21089
|
+
}
|
|
21090
|
+
function grokSubagentBackground(rawInput) {
|
|
21091
|
+
if (!isRecord5(rawInput))
|
|
21092
|
+
return true;
|
|
21093
|
+
if (rawInput.background === false || rawInput.run_in_background === false)
|
|
21094
|
+
return false;
|
|
21095
|
+
return true;
|
|
21096
|
+
}
|
|
21097
|
+
function grokSubagentModel(rawInput) {
|
|
21098
|
+
return bounded(stringField2(rawInput, "model"), DESCRIPTION_LIMIT);
|
|
21099
|
+
}
|
|
21100
|
+
function grokNativeSubagentId(...candidates) {
|
|
21101
|
+
const fromKey = (key) => {
|
|
21102
|
+
for (const candidate of candidates) {
|
|
21103
|
+
const value = idField(candidate, key);
|
|
21104
|
+
if (value)
|
|
21105
|
+
return value;
|
|
21106
|
+
}
|
|
21107
|
+
return void 0;
|
|
21108
|
+
};
|
|
21109
|
+
const fromText = (pattern) => {
|
|
21110
|
+
for (const candidate of candidates) {
|
|
21111
|
+
const text = extractText(candidate);
|
|
21112
|
+
const match = text?.match(pattern);
|
|
21113
|
+
if (match?.[1])
|
|
21114
|
+
return match[1].trim();
|
|
21115
|
+
}
|
|
21116
|
+
return void 0;
|
|
21117
|
+
};
|
|
21118
|
+
return fromKey("subagent_id") ?? fromText(/subagent_id:\s*([^\s]+)/i) ?? fromKey("task_id") ?? fromKey("id") ?? fromText(/task_id:\s*([^\s]+)/i) ?? fromText(/task_ids=\["([^"]+)"\]/);
|
|
21119
|
+
}
|
|
21120
|
+
function grokSubagentResultSummary(...candidates) {
|
|
21121
|
+
for (const candidate of candidates) {
|
|
21122
|
+
const text = extractText(candidate);
|
|
21123
|
+
if (text)
|
|
21124
|
+
return bounded(text, SUMMARY_LIMIT);
|
|
21125
|
+
}
|
|
21126
|
+
return void 0;
|
|
21127
|
+
}
|
|
21128
|
+
function grokSubagentEventFromUpdate(update) {
|
|
21129
|
+
if (!isRecord5(update) || typeof update.sessionUpdate !== "string")
|
|
21130
|
+
return null;
|
|
21131
|
+
const nativeSubagentId = idField(update, "subagent_id") ?? idField(update, "child_session_id");
|
|
21132
|
+
if (!nativeSubagentId)
|
|
21133
|
+
return null;
|
|
21134
|
+
if (update.sessionUpdate === "subagent_spawned") {
|
|
21135
|
+
const description = bounded(stringField2(update, "description"), DESCRIPTION_LIMIT);
|
|
21136
|
+
const role = bounded(stringField2(update, "subagent_type") ?? stringField2(update, "role"), DESCRIPTION_LIMIT);
|
|
21137
|
+
const model = bounded(stringField2(update, "model"), DESCRIPTION_LIMIT);
|
|
21138
|
+
return {
|
|
21139
|
+
type: "subagent.spawned",
|
|
21140
|
+
nativeSubagentId,
|
|
21141
|
+
...description ? { description } : {},
|
|
21142
|
+
...role ? { role } : {},
|
|
21143
|
+
...model ? { model } : {}
|
|
21144
|
+
};
|
|
21145
|
+
}
|
|
21146
|
+
if (update.sessionUpdate === "subagent_finished") {
|
|
21147
|
+
const mapped = mapTaskStatus(typeof update.status === "string" ? update.status : void 0);
|
|
21148
|
+
if (!mapped || mapped === "running" || mapped === "pending")
|
|
21149
|
+
return null;
|
|
21150
|
+
const status = mapped === "failed" ? "failed" : mapped === "interrupted" ? "interrupted" : "completed";
|
|
21151
|
+
const resultSummary = bounded(typeof update.output === "string" ? update.output.trim() : void 0, SUMMARY_LIMIT);
|
|
21152
|
+
return {
|
|
21153
|
+
type: "subagent.finished",
|
|
21154
|
+
nativeSubagentId,
|
|
21155
|
+
status,
|
|
21156
|
+
...resultSummary ? { resultSummary } : {}
|
|
21157
|
+
};
|
|
21158
|
+
}
|
|
21159
|
+
return null;
|
|
21160
|
+
}
|
|
21161
|
+
function grokSubagentWaitSettlements(input) {
|
|
21162
|
+
const ids = grokSubagentWaitIds(input.name, input.title, input.rawInput);
|
|
21163
|
+
if (grokSubagentKill(input.name, input.title)) {
|
|
21164
|
+
return ids.map((id) => ({ id, status: "interrupted" }));
|
|
21165
|
+
}
|
|
21166
|
+
if (ids.length === 0)
|
|
21167
|
+
return [];
|
|
21168
|
+
const resultEntries = taskOutputResults(input.rawOutput);
|
|
21169
|
+
if (resultEntries.length > 0) {
|
|
21170
|
+
const settled = [];
|
|
21171
|
+
for (const result of resultEntries) {
|
|
21172
|
+
const id = idField(result, "task_id") ?? idField(result, "subagent_id");
|
|
21173
|
+
const status = mapTaskStatus(typeof result.status === "string" ? result.status : void 0);
|
|
21174
|
+
if (!id || !status || status === "running" || status === "pending")
|
|
21175
|
+
continue;
|
|
21176
|
+
const resultSummary = bounded(typeof result.output === "string" ? result.output.trim() : void 0, SUMMARY_LIMIT);
|
|
21177
|
+
settled.push({ id, status, ...resultSummary ? { resultSummary } : {} });
|
|
21178
|
+
}
|
|
21179
|
+
return settled;
|
|
21180
|
+
}
|
|
21181
|
+
const fromText = taskOutputTextSettlements(input.rawOutput, input.content, ids);
|
|
21182
|
+
if (fromText.length > 0)
|
|
21183
|
+
return fromText;
|
|
21184
|
+
const overall = mapTaskStatus(taskOutputStatus(input.rawOutput, input.content));
|
|
21185
|
+
if (!overall || overall === "running" || overall === "pending")
|
|
21186
|
+
return [];
|
|
21187
|
+
return ids.map((id) => ({ id, status: overall }));
|
|
21188
|
+
}
|
|
21189
|
+
function taskOutputResults(rawOutput) {
|
|
21190
|
+
if (!isRecord5(rawOutput))
|
|
21191
|
+
return [];
|
|
21192
|
+
if (Array.isArray(rawOutput.results)) {
|
|
21193
|
+
return rawOutput.results.filter(isRecord5);
|
|
21194
|
+
}
|
|
21195
|
+
const nested = firstRecord(rawOutput.MultiResult, rawOutput.multiResult, rawOutput.multi_result);
|
|
21196
|
+
if (nested && Array.isArray(nested.results)) {
|
|
21197
|
+
return nested.results.filter(isRecord5);
|
|
21198
|
+
}
|
|
21199
|
+
const single = firstRecord(rawOutput.Result, rawOutput.result);
|
|
21200
|
+
if (single)
|
|
21201
|
+
return [single];
|
|
21202
|
+
if (typeof rawOutput.status === "string")
|
|
21203
|
+
return [rawOutput];
|
|
21204
|
+
return [];
|
|
21205
|
+
}
|
|
21206
|
+
function firstRecord(...values) {
|
|
21207
|
+
for (const value of values) {
|
|
21208
|
+
if (isRecord5(value))
|
|
21209
|
+
return value;
|
|
21210
|
+
}
|
|
21211
|
+
return void 0;
|
|
21212
|
+
}
|
|
21213
|
+
function taskOutputTextSettlements(rawOutput, content, ids) {
|
|
21214
|
+
const text = extractText(content) ?? extractText(rawOutput);
|
|
21215
|
+
if (!text)
|
|
21216
|
+
return [];
|
|
21217
|
+
const settled = [];
|
|
21218
|
+
const pattern = /---\s*Task\s+(\S+)\s+\[(completed|failed|interrupted|cancelled|canceled)\]\s*---/gi;
|
|
21219
|
+
for (const match of text.matchAll(pattern)) {
|
|
21220
|
+
const id = match[1]?.trim();
|
|
21221
|
+
const status = mapTaskStatus(match[2]);
|
|
21222
|
+
if (!id || !status || status === "running" || status === "pending")
|
|
21223
|
+
continue;
|
|
21224
|
+
if (!ids.includes(id))
|
|
21225
|
+
continue;
|
|
21226
|
+
settled.push({ id, status });
|
|
21227
|
+
}
|
|
21228
|
+
return settled;
|
|
21229
|
+
}
|
|
21230
|
+
function taskOutputStatus(rawOutput, content) {
|
|
21231
|
+
if (isRecord5(rawOutput) && typeof rawOutput.status === "string")
|
|
21232
|
+
return rawOutput.status;
|
|
21233
|
+
const text = extractText(content) ?? extractText(rawOutput);
|
|
21234
|
+
if (!text)
|
|
21235
|
+
return void 0;
|
|
21236
|
+
if (/<subagent_meta>|<subagent_result>/i.test(text))
|
|
21237
|
+
return "completed";
|
|
21238
|
+
if (/\bstatus["']?\s*[:=]\s*["']?completed/i.test(text))
|
|
21239
|
+
return "completed";
|
|
21240
|
+
if (/\bstatus["']?\s*[:=]\s*["']?failed/i.test(text))
|
|
21241
|
+
return "failed";
|
|
21242
|
+
if (/\bstatus["']?\s*[:=]\s*["']?(cancelled|canceled|interrupted)/i.test(text)) {
|
|
21243
|
+
return "interrupted";
|
|
21244
|
+
}
|
|
21245
|
+
if (/\bstill running\b|\bstatus["']?\s*[:=]\s*["']?(running|pending|in_progress)/i.test(text)) {
|
|
21246
|
+
return "running";
|
|
21247
|
+
}
|
|
21248
|
+
return void 0;
|
|
21249
|
+
}
|
|
21250
|
+
function mapTaskStatus(status) {
|
|
21251
|
+
if (!status)
|
|
21252
|
+
return void 0;
|
|
21253
|
+
switch (status.toLowerCase()) {
|
|
21254
|
+
case "completed":
|
|
21255
|
+
case "succeeded":
|
|
21256
|
+
case "success":
|
|
21257
|
+
return "completed";
|
|
21258
|
+
case "failed":
|
|
21259
|
+
case "error":
|
|
21260
|
+
case "errored":
|
|
21261
|
+
return "failed";
|
|
21262
|
+
case "cancelled":
|
|
21263
|
+
case "canceled":
|
|
21264
|
+
case "interrupted":
|
|
21265
|
+
return "interrupted";
|
|
21266
|
+
case "running":
|
|
21267
|
+
case "pending":
|
|
21268
|
+
case "in_progress":
|
|
21269
|
+
case "inprogress":
|
|
21270
|
+
return "running";
|
|
21271
|
+
default:
|
|
21272
|
+
return void 0;
|
|
21273
|
+
}
|
|
21274
|
+
}
|
|
21275
|
+
function extractText(value, depth = 0) {
|
|
21276
|
+
if (depth > 6)
|
|
21277
|
+
return void 0;
|
|
21278
|
+
if (typeof value === "string") {
|
|
21279
|
+
const trimmed = value.trim();
|
|
21280
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
21281
|
+
}
|
|
21282
|
+
if (Array.isArray(value)) {
|
|
21283
|
+
const parts = value.flatMap((entry) => {
|
|
21284
|
+
const text = extractText(entry, depth + 1);
|
|
21285
|
+
return text ? [text] : [];
|
|
21286
|
+
});
|
|
21287
|
+
const joined = parts.join("\n").trim();
|
|
21288
|
+
return joined.length > 0 ? joined : void 0;
|
|
21289
|
+
}
|
|
21290
|
+
if (!isRecord5(value))
|
|
21291
|
+
return void 0;
|
|
21292
|
+
if (typeof value.text === "string" && value.text.trim().length > 0)
|
|
21293
|
+
return value.text.trim();
|
|
21294
|
+
if (typeof value.output === "string" && value.output.trim().length > 0) {
|
|
21295
|
+
return value.output.trim();
|
|
21296
|
+
}
|
|
21297
|
+
if (value.content !== void 0)
|
|
21298
|
+
return extractText(value.content, depth + 1);
|
|
21299
|
+
return void 0;
|
|
21300
|
+
}
|
|
21301
|
+
|
|
20993
21302
|
// dist/grok-history.js
|
|
20994
21303
|
function stableId(kind, turn, index) {
|
|
20995
21304
|
return hostItemIdSchema.parse(`grok-history-${kind}-${turn}-${index}`);
|
|
@@ -21052,6 +21361,90 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
21052
21361
|
let reasoning = null;
|
|
21053
21362
|
const tools = /* @__PURE__ */ new Map();
|
|
21054
21363
|
const mediaRoots = grokMediaResolveRoots(cwd, sessionDirectory);
|
|
21364
|
+
const subagents = /* @__PURE__ */ new Map();
|
|
21365
|
+
const subagentAliases = /* @__PURE__ */ new Map();
|
|
21366
|
+
const rememberSubagentAlias = (callId, nativeId) => {
|
|
21367
|
+
subagentAliases.set(callId, callId);
|
|
21368
|
+
if (nativeId)
|
|
21369
|
+
subagentAliases.set(nativeId, callId);
|
|
21370
|
+
};
|
|
21371
|
+
const completeHistorySubagent = (callId, status, content, rawOutput, rawInput) => {
|
|
21372
|
+
const current = subagents.get(callId);
|
|
21373
|
+
const currentAgent = current?.subagents[0];
|
|
21374
|
+
if (!current || !currentAgent)
|
|
21375
|
+
return;
|
|
21376
|
+
const nativeSubagentId = grokNativeSubagentId(rawInput, rawOutput, content) ?? currentAgent.nativeSubagentId;
|
|
21377
|
+
rememberSubagentAlias(callId, nativeSubagentId);
|
|
21378
|
+
const summary = grokSubagentResultSummary(content, rawOutput);
|
|
21379
|
+
const failed = status === "failed";
|
|
21380
|
+
const keepRunning = !failed && (currentAgent.background === true || current.operation === "send");
|
|
21381
|
+
const item = {
|
|
21382
|
+
...current,
|
|
21383
|
+
subagents: [
|
|
21384
|
+
{
|
|
21385
|
+
...currentAgent,
|
|
21386
|
+
status: failed ? "failed" : keepRunning ? "running" : "completed",
|
|
21387
|
+
...nativeSubagentId ? { nativeSubagentId, subagentId: nativeSubagentId } : {},
|
|
21388
|
+
...summary ? { resultSummary: summary } : {}
|
|
21389
|
+
}
|
|
21390
|
+
]
|
|
21391
|
+
};
|
|
21392
|
+
if (keepRunning) {
|
|
21393
|
+
subagents.set(callId, item);
|
|
21394
|
+
return;
|
|
21395
|
+
}
|
|
21396
|
+
subagents.delete(callId);
|
|
21397
|
+
items.push({
|
|
21398
|
+
item,
|
|
21399
|
+
outcome: failed ? {
|
|
21400
|
+
status: "failed",
|
|
21401
|
+
error: {
|
|
21402
|
+
code: "nativeFailure",
|
|
21403
|
+
message: "Grok Subagent delegation failed",
|
|
21404
|
+
retryable: false
|
|
21405
|
+
}
|
|
21406
|
+
} : { status: "succeeded" }
|
|
21407
|
+
});
|
|
21408
|
+
};
|
|
21409
|
+
const settleWatchedSubagents = (name, rawInput, content, rawOutput) => {
|
|
21410
|
+
const summary = grokSubagentResultSummary(content, rawOutput);
|
|
21411
|
+
for (const settlement of grokSubagentWaitSettlements({
|
|
21412
|
+
...name ? { name, title: name } : {},
|
|
21413
|
+
rawInput,
|
|
21414
|
+
content,
|
|
21415
|
+
rawOutput
|
|
21416
|
+
})) {
|
|
21417
|
+
const spawnId = subagentAliases.get(settlement.id);
|
|
21418
|
+
const item = spawnId ? subagents.get(spawnId) : void 0;
|
|
21419
|
+
if (!item?.subagents[0])
|
|
21420
|
+
continue;
|
|
21421
|
+
if (spawnId)
|
|
21422
|
+
subagents.delete(spawnId);
|
|
21423
|
+
const resultSummary = settlement.resultSummary ?? summary;
|
|
21424
|
+
items.push({
|
|
21425
|
+
item: {
|
|
21426
|
+
...item,
|
|
21427
|
+
subagents: [
|
|
21428
|
+
{
|
|
21429
|
+
...item.subagents[0],
|
|
21430
|
+
status: settlement.status,
|
|
21431
|
+
nativeSubagentId: item.subagents[0].nativeSubagentId ?? settlement.id,
|
|
21432
|
+
subagentId: item.subagents[0].nativeSubagentId ?? settlement.id,
|
|
21433
|
+
...resultSummary ? { resultSummary } : {}
|
|
21434
|
+
}
|
|
21435
|
+
]
|
|
21436
|
+
},
|
|
21437
|
+
outcome: settlement.status === "failed" ? {
|
|
21438
|
+
status: "failed",
|
|
21439
|
+
error: {
|
|
21440
|
+
code: "nativeFailure",
|
|
21441
|
+
message: "Grok Subagent delegation failed",
|
|
21442
|
+
retryable: false
|
|
21443
|
+
}
|
|
21444
|
+
} : settlement.status === "interrupted" ? { status: "cancelled", reason: "Cancelled by user" } : { status: "succeeded" }
|
|
21445
|
+
});
|
|
21446
|
+
}
|
|
21447
|
+
};
|
|
21055
21448
|
const completeAgent = () => {
|
|
21056
21449
|
if (!agent || agent.text.length === 0)
|
|
21057
21450
|
return;
|
|
@@ -21072,6 +21465,10 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
21072
21465
|
items.push({ item: tool, outcome: { status: "succeeded" } });
|
|
21073
21466
|
}
|
|
21074
21467
|
tools.clear();
|
|
21468
|
+
for (const item of subagents.values()) {
|
|
21469
|
+
items.push({ item, outcome: { status: "succeeded" } });
|
|
21470
|
+
}
|
|
21471
|
+
subagents.clear();
|
|
21075
21472
|
};
|
|
21076
21473
|
const applyToolProjection = (callId, content, rawOutput) => {
|
|
21077
21474
|
const tool = tools.get(callId);
|
|
@@ -21096,6 +21493,7 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
21096
21493
|
retryable: false
|
|
21097
21494
|
}
|
|
21098
21495
|
} : { status: "succeeded" };
|
|
21496
|
+
settleWatchedSubagents(tool.type === "toolExecution" ? tool.toolName : tool.command, tool.type === "toolExecution" ? tool.arguments : void 0, content, rawOutput);
|
|
21099
21497
|
items.push({ item: tool, outcome });
|
|
21100
21498
|
if (status !== "completed")
|
|
21101
21499
|
return;
|
|
@@ -21163,6 +21561,8 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
21163
21561
|
agent = null;
|
|
21164
21562
|
reasoning = null;
|
|
21165
21563
|
tools.clear();
|
|
21564
|
+
subagents.clear();
|
|
21565
|
+
subagentAliases.clear();
|
|
21166
21566
|
continue;
|
|
21167
21567
|
}
|
|
21168
21568
|
if (event.type === "user.text") {
|
|
@@ -21237,23 +21637,99 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
21237
21637
|
} else if (event.type === "tool.call") {
|
|
21238
21638
|
completeReasoning();
|
|
21239
21639
|
completeAgent();
|
|
21240
|
-
|
|
21241
|
-
|
|
21242
|
-
|
|
21243
|
-
|
|
21244
|
-
|
|
21245
|
-
|
|
21246
|
-
|
|
21247
|
-
|
|
21248
|
-
|
|
21249
|
-
|
|
21250
|
-
|
|
21640
|
+
const operation = grokSubagentOperation(event.name, event.title, event.rawInput);
|
|
21641
|
+
if (operation) {
|
|
21642
|
+
const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content);
|
|
21643
|
+
rememberSubagentAlias(event.callId, nativeSubagentId);
|
|
21644
|
+
const prompt = grokSubagentPrompt(event.rawInput);
|
|
21645
|
+
const role = grokSubagentRole(event.rawInput);
|
|
21646
|
+
const model = grokSubagentModel(event.rawInput);
|
|
21647
|
+
subagents.set(event.callId, {
|
|
21648
|
+
type: "subagentDelegation",
|
|
21649
|
+
itemId: stableId("subagent", turnIndex, ++messageIndex),
|
|
21650
|
+
operation,
|
|
21651
|
+
...prompt ? { prompt } : {},
|
|
21652
|
+
subagents: [
|
|
21653
|
+
{
|
|
21654
|
+
subagentId: nativeSubagentId ?? event.callId,
|
|
21655
|
+
...nativeSubagentId ? { nativeSubagentId } : {},
|
|
21656
|
+
description: grokSubagentDescription(event.rawInput, event.title),
|
|
21657
|
+
...role ? { role } : {},
|
|
21658
|
+
...model ? { model } : {},
|
|
21659
|
+
background: grokSubagentBackground(event.rawInput),
|
|
21660
|
+
status: "running"
|
|
21661
|
+
}
|
|
21662
|
+
]
|
|
21663
|
+
});
|
|
21664
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
21665
|
+
completeHistorySubagent(event.callId, event.status, event.content, event.rawOutput, event.rawInput);
|
|
21666
|
+
}
|
|
21667
|
+
} else {
|
|
21668
|
+
tools.set(event.callId, startGrokToolItem({
|
|
21669
|
+
itemId: stableId("tool", turnIndex, ++messageIndex),
|
|
21670
|
+
name: event.name,
|
|
21671
|
+
title: event.title,
|
|
21672
|
+
kind: event.kind,
|
|
21673
|
+
rawInput: event.rawInput,
|
|
21674
|
+
cwd
|
|
21675
|
+
}));
|
|
21676
|
+
applyToolProjection(event.callId, event.content, event.rawOutput);
|
|
21677
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
21678
|
+
completeTool(event.callId, event.status, event.content, event.rawOutput);
|
|
21679
|
+
}
|
|
21251
21680
|
}
|
|
21252
21681
|
} else if (event.type === "tool.update") {
|
|
21253
|
-
|
|
21254
|
-
|
|
21255
|
-
|
|
21682
|
+
if (subagents.has(event.callId)) {
|
|
21683
|
+
const current = subagents.get(event.callId);
|
|
21684
|
+
if (current?.subagents[0]) {
|
|
21685
|
+
const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content) ?? current.subagents[0].nativeSubagentId;
|
|
21686
|
+
rememberSubagentAlias(event.callId, nativeSubagentId);
|
|
21687
|
+
subagents.set(event.callId, {
|
|
21688
|
+
...current,
|
|
21689
|
+
subagents: [
|
|
21690
|
+
{
|
|
21691
|
+
...current.subagents[0],
|
|
21692
|
+
description: grokSubagentDescription(event.rawInput, event.title, current.subagents[0].description),
|
|
21693
|
+
...nativeSubagentId ? { nativeSubagentId, subagentId: nativeSubagentId } : {}
|
|
21694
|
+
}
|
|
21695
|
+
]
|
|
21696
|
+
});
|
|
21697
|
+
}
|
|
21698
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
21699
|
+
completeHistorySubagent(event.callId, event.status, event.content, event.rawOutput, event.rawInput);
|
|
21700
|
+
}
|
|
21701
|
+
} else {
|
|
21702
|
+
applyToolProjection(event.callId, event.content, event.rawOutput);
|
|
21703
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
21704
|
+
completeTool(event.callId, event.status, event.content, event.rawOutput);
|
|
21705
|
+
}
|
|
21706
|
+
}
|
|
21707
|
+
} else if (event.type === "subagent.spawned") {
|
|
21708
|
+
for (const [callId, current] of subagents) {
|
|
21709
|
+
const agent2 = current.subagents[0];
|
|
21710
|
+
if (!agent2)
|
|
21711
|
+
continue;
|
|
21712
|
+
const matchesId = agent2.nativeSubagentId === event.nativeSubagentId;
|
|
21713
|
+
const matchesDescription = !agent2.nativeSubagentId && event.description !== void 0 && agent2.description === event.description;
|
|
21714
|
+
if (!matchesId && !matchesDescription)
|
|
21715
|
+
continue;
|
|
21716
|
+
rememberSubagentAlias(callId, event.nativeSubagentId);
|
|
21717
|
+
subagents.set(callId, {
|
|
21718
|
+
...current,
|
|
21719
|
+
subagents: [
|
|
21720
|
+
{
|
|
21721
|
+
...agent2,
|
|
21722
|
+
nativeSubagentId: event.nativeSubagentId,
|
|
21723
|
+
subagentId: event.nativeSubagentId,
|
|
21724
|
+
...event.role ? { role: event.role } : {},
|
|
21725
|
+
...event.model ? { model: event.model } : {}
|
|
21726
|
+
}
|
|
21727
|
+
]
|
|
21728
|
+
});
|
|
21729
|
+
break;
|
|
21256
21730
|
}
|
|
21731
|
+
} else if (event.type === "subagent.finished") {
|
|
21732
|
+
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
21733
|
}
|
|
21258
21734
|
}
|
|
21259
21735
|
completeTurn({ status: "unknown", reason: "Grok Native history has no terminal signal" });
|
|
@@ -21278,11 +21754,11 @@ var GROK_SESSION_DELETE_METHOD = "_x.ai/session/delete";
|
|
|
21278
21754
|
function error51(code, message, retryable = false) {
|
|
21279
21755
|
return { code, message, retryable };
|
|
21280
21756
|
}
|
|
21281
|
-
function
|
|
21757
|
+
function isRecord6(value) {
|
|
21282
21758
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21283
21759
|
}
|
|
21284
21760
|
function isGrokMethodNotFound(error53) {
|
|
21285
|
-
if (
|
|
21761
|
+
if (isRecord6(error53) && error53.code === -32601)
|
|
21286
21762
|
return true;
|
|
21287
21763
|
const message = error53 instanceof Error ? error53.message : String(error53);
|
|
21288
21764
|
return /method not found/iu.test(message);
|
|
@@ -21300,10 +21776,10 @@ function buildGrokForkParams(input) {
|
|
|
21300
21776
|
};
|
|
21301
21777
|
}
|
|
21302
21778
|
function parseGrokForkResponse(value) {
|
|
21303
|
-
if (!
|
|
21779
|
+
if (!isRecord6(value) || value.error !== void 0)
|
|
21304
21780
|
return null;
|
|
21305
|
-
const payload = typeof value.newSessionId !== "string" &&
|
|
21306
|
-
if (!
|
|
21781
|
+
const payload = typeof value.newSessionId !== "string" && isRecord6(value.result) ? value.result : value;
|
|
21782
|
+
if (!isRecord6(payload) || payload.error !== void 0)
|
|
21307
21783
|
return null;
|
|
21308
21784
|
if (typeof payload.newSessionId !== "string" || payload.newSessionId.length === 0)
|
|
21309
21785
|
return null;
|
|
@@ -21466,7 +21942,7 @@ var GROK_SESSION_UPDATE_EXTENSION_METHODS = [
|
|
|
21466
21942
|
"_x.ai/session/update",
|
|
21467
21943
|
"x.ai/session_notification"
|
|
21468
21944
|
];
|
|
21469
|
-
function
|
|
21945
|
+
function isRecord7(value) {
|
|
21470
21946
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21471
21947
|
}
|
|
21472
21948
|
function optionalNonNegativeInt(value) {
|
|
@@ -21487,7 +21963,7 @@ function isGrokExtensionSessionUpdateMethod(method) {
|
|
|
21487
21963
|
return GROK_SESSION_UPDATE_EXTENSION_METHODS.includes(method);
|
|
21488
21964
|
}
|
|
21489
21965
|
function grokCompactionEventFromUpdate(update) {
|
|
21490
|
-
if (!
|
|
21966
|
+
if (!isRecord7(update) || typeof update.sessionUpdate !== "string")
|
|
21491
21967
|
return null;
|
|
21492
21968
|
const tokensUsed = optionalNonNegativeInt(firstPresent(update, ["tokensUsed", "tokens_used"]));
|
|
21493
21969
|
const contextWindowTokens = optionalNonNegativeInt(firstPresent(update, ["contextWindowTokens", "contextWindow", "context_window"]));
|
|
@@ -21526,7 +22002,7 @@ function grokCompactionEventFromUpdate(update) {
|
|
|
21526
22002
|
// dist/grok-manual-compaction.js
|
|
21527
22003
|
var GROK_COMPACT_CONVERSATION_METHOD = "x.ai/compact_conversation";
|
|
21528
22004
|
var GROK_COMPACT_CONVERSATION_FALLBACK_METHOD = "_x.ai/compact_conversation";
|
|
21529
|
-
function
|
|
22005
|
+
function isRecord8(value) {
|
|
21530
22006
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21531
22007
|
}
|
|
21532
22008
|
function optionalNonNegativeInt2(value) {
|
|
@@ -21538,7 +22014,7 @@ function optionalErrorMessage2(value) {
|
|
|
21538
22014
|
function parseGrokCompactResult(value, cancelled = false) {
|
|
21539
22015
|
if (cancelled)
|
|
21540
22016
|
return { outcome: "cancelled" };
|
|
21541
|
-
if (!
|
|
22017
|
+
if (!isRecord8(value))
|
|
21542
22018
|
return { outcome: "succeeded" };
|
|
21543
22019
|
const tokensBefore = optionalNonNegativeInt2(value.tokensBefore ?? value.tokens_before);
|
|
21544
22020
|
const tokensAfter = optionalNonNegativeInt2(value.tokensAfter ?? value.tokens_after);
|
|
@@ -21576,7 +22052,7 @@ var GROK_REWIND_EXECUTE_METHOD = "_x.ai/rewind/execute";
|
|
|
21576
22052
|
function error52(code, message, retryable = false) {
|
|
21577
22053
|
return { code, message, retryable };
|
|
21578
22054
|
}
|
|
21579
|
-
function
|
|
22055
|
+
function isRecord9(value) {
|
|
21580
22056
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21581
22057
|
}
|
|
21582
22058
|
function buildGrokRewindParams(input) {
|
|
@@ -21588,10 +22064,10 @@ function buildGrokRewindParams(input) {
|
|
|
21588
22064
|
};
|
|
21589
22065
|
}
|
|
21590
22066
|
function parseGrokRewindResponse(value) {
|
|
21591
|
-
if (!
|
|
22067
|
+
if (!isRecord9(value))
|
|
21592
22068
|
return null;
|
|
21593
|
-
const payload = typeof value.success !== "boolean" &&
|
|
21594
|
-
if (!
|
|
22069
|
+
const payload = typeof value.success !== "boolean" && isRecord9(value.result) ? value.result : value;
|
|
22070
|
+
if (!isRecord9(payload) || typeof payload.success !== "boolean")
|
|
21595
22071
|
return null;
|
|
21596
22072
|
return rewindPayload(payload);
|
|
21597
22073
|
}
|
|
@@ -21701,10 +22177,10 @@ async function rewindGrokLastTurn(input) {
|
|
|
21701
22177
|
|
|
21702
22178
|
// dist/grok-plan-review.js
|
|
21703
22179
|
var GROK_PLAN_DECISION_ID = "plan-decision";
|
|
21704
|
-
function
|
|
22180
|
+
function isRecord10(value) {
|
|
21705
22181
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21706
22182
|
}
|
|
21707
|
-
function
|
|
22183
|
+
function stringField3(value, ...keys) {
|
|
21708
22184
|
for (const key of keys) {
|
|
21709
22185
|
const field = value[key];
|
|
21710
22186
|
if (typeof field === "string" && field.length > 0)
|
|
@@ -21713,12 +22189,12 @@ function stringField2(value, ...keys) {
|
|
|
21713
22189
|
return void 0;
|
|
21714
22190
|
}
|
|
21715
22191
|
function parseGrokExitPlanModeParams(params) {
|
|
21716
|
-
if (!
|
|
22192
|
+
if (!isRecord10(params))
|
|
21717
22193
|
return null;
|
|
21718
|
-
const nested =
|
|
21719
|
-
const plan =
|
|
21720
|
-
const planFilePath =
|
|
21721
|
-
const sessionId =
|
|
22194
|
+
const nested = isRecord10(params.input) ? params.input : params;
|
|
22195
|
+
const plan = stringField3(nested, "planContent", "plan_content", "plan") ?? stringField3(params, "planContent", "plan_content", "plan") ?? null;
|
|
22196
|
+
const planFilePath = stringField3(nested, "planFilePath", "plan_file_path") ?? stringField3(params, "planFilePath", "plan_file_path");
|
|
22197
|
+
const sessionId = stringField3(params, "sessionId", "session_id");
|
|
21722
22198
|
return {
|
|
21723
22199
|
plan,
|
|
21724
22200
|
...sessionId ? { sessionId } : {},
|
|
@@ -21782,10 +22258,10 @@ var GROK_ACP_CLIENT_CAPABILITIES = {
|
|
|
21782
22258
|
"x.ai/exit_plan_mode": true
|
|
21783
22259
|
}
|
|
21784
22260
|
};
|
|
21785
|
-
function
|
|
22261
|
+
function isRecord11(value) {
|
|
21786
22262
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21787
22263
|
}
|
|
21788
|
-
function
|
|
22264
|
+
function stringField4(value, ...keys) {
|
|
21789
22265
|
for (const key of keys) {
|
|
21790
22266
|
const field = value[key];
|
|
21791
22267
|
if (typeof field === "string" && field.length > 0)
|
|
@@ -21811,22 +22287,22 @@ function isGrokExitPlanModeMethod(method) {
|
|
|
21811
22287
|
function questionsPayload(params) {
|
|
21812
22288
|
if (Array.isArray(params.questions))
|
|
21813
22289
|
return params.questions;
|
|
21814
|
-
if (
|
|
22290
|
+
if (isRecord11(params.input) && Array.isArray(params.input.questions))
|
|
21815
22291
|
return params.input.questions;
|
|
21816
|
-
if (
|
|
22292
|
+
if (isRecord11(params.askUserQuestion) && Array.isArray(params.askUserQuestion.questions)) {
|
|
21817
22293
|
return params.askUserQuestion.questions;
|
|
21818
22294
|
}
|
|
21819
22295
|
return void 0;
|
|
21820
22296
|
}
|
|
21821
22297
|
function parseOption(value, labels) {
|
|
21822
|
-
if (!
|
|
22298
|
+
if (!isRecord11(value))
|
|
21823
22299
|
return null;
|
|
21824
|
-
const label =
|
|
22300
|
+
const label = stringField4(value, "label");
|
|
21825
22301
|
if (!label || labels.has(label))
|
|
21826
22302
|
return null;
|
|
21827
22303
|
labels.add(label);
|
|
21828
|
-
const description =
|
|
21829
|
-
const preview =
|
|
22304
|
+
const description = stringField4(value, "description");
|
|
22305
|
+
const preview = stringField4(value, "preview");
|
|
21830
22306
|
const combined = [description, preview].filter((part) => part !== void 0);
|
|
21831
22307
|
return {
|
|
21832
22308
|
label,
|
|
@@ -21834,9 +22310,9 @@ function parseOption(value, labels) {
|
|
|
21834
22310
|
};
|
|
21835
22311
|
}
|
|
21836
22312
|
function parseQuestion(value, questions) {
|
|
21837
|
-
if (!
|
|
22313
|
+
if (!isRecord11(value))
|
|
21838
22314
|
return null;
|
|
21839
|
-
const question =
|
|
22315
|
+
const question = stringField4(value, "question");
|
|
21840
22316
|
if (!question || questions.has(question))
|
|
21841
22317
|
return null;
|
|
21842
22318
|
if (!Array.isArray(value.options) || value.options.length === 0)
|
|
@@ -21850,7 +22326,7 @@ function parseQuestion(value, questions) {
|
|
|
21850
22326
|
options.push(parsed);
|
|
21851
22327
|
}
|
|
21852
22328
|
questions.add(question);
|
|
21853
|
-
const header =
|
|
22329
|
+
const header = stringField4(value, "header");
|
|
21854
22330
|
return {
|
|
21855
22331
|
question,
|
|
21856
22332
|
...header ? { header } : {},
|
|
@@ -21859,7 +22335,7 @@ function parseQuestion(value, questions) {
|
|
|
21859
22335
|
};
|
|
21860
22336
|
}
|
|
21861
22337
|
function parseGrokAskUserQuestionParams(params) {
|
|
21862
|
-
if (!
|
|
22338
|
+
if (!isRecord11(params))
|
|
21863
22339
|
return null;
|
|
21864
22340
|
const rawQuestions = questionsPayload(params);
|
|
21865
22341
|
if (!Array.isArray(rawQuestions) || rawQuestions.length === 0)
|
|
@@ -21872,7 +22348,7 @@ function parseGrokAskUserQuestionParams(params) {
|
|
|
21872
22348
|
return null;
|
|
21873
22349
|
questions.push(parsed);
|
|
21874
22350
|
}
|
|
21875
|
-
const sessionId =
|
|
22351
|
+
const sessionId = stringField4(params, "sessionId", "session_id");
|
|
21876
22352
|
const timeoutMs = optionalTimeoutMs(params);
|
|
21877
22353
|
return {
|
|
21878
22354
|
questions,
|
|
@@ -21974,9 +22450,18 @@ var GrokTransportError = class extends Error {
|
|
|
21974
22450
|
this.name = "GrokTransportError";
|
|
21975
22451
|
}
|
|
21976
22452
|
};
|
|
21977
|
-
function
|
|
22453
|
+
function isRecord12(value) {
|
|
21978
22454
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21979
22455
|
}
|
|
22456
|
+
function acpToolName(update, metadata) {
|
|
22457
|
+
if (!isRecord12(update))
|
|
22458
|
+
return void 0;
|
|
22459
|
+
if (typeof update.name === "string" && update.name.length > 0)
|
|
22460
|
+
return update.name;
|
|
22461
|
+
const meta3 = isRecord12(update._meta) ? update._meta : metadata;
|
|
22462
|
+
const tool = meta3 && isRecord12(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
|
|
22463
|
+
return tool && typeof tool.name === "string" && tool.name.length > 0 ? tool.name : void 0;
|
|
22464
|
+
}
|
|
21980
22465
|
function errorText(error53) {
|
|
21981
22466
|
return error53 instanceof Error ? error53.message : String(error53);
|
|
21982
22467
|
}
|
|
@@ -22030,7 +22515,7 @@ function signalProcessTree(child, signal) {
|
|
|
22030
22515
|
try {
|
|
22031
22516
|
process.kill(-child.pid, signal);
|
|
22032
22517
|
} catch (error53) {
|
|
22033
|
-
if (!
|
|
22518
|
+
if (!isRecord12(error53) || error53.code !== "ESRCH")
|
|
22034
22519
|
throw error53;
|
|
22035
22520
|
}
|
|
22036
22521
|
}
|
|
@@ -22055,6 +22540,9 @@ function transportEvent(update, metadata) {
|
|
|
22055
22540
|
const compaction = grokCompactionEventFromUpdate(extension);
|
|
22056
22541
|
if (compaction)
|
|
22057
22542
|
return compaction;
|
|
22543
|
+
const subagent = grokSubagentEventFromUpdate(extension);
|
|
22544
|
+
if (subagent)
|
|
22545
|
+
return subagent;
|
|
22058
22546
|
switch (update.sessionUpdate) {
|
|
22059
22547
|
case "user_message_chunk":
|
|
22060
22548
|
case "agent_message_chunk":
|
|
@@ -22066,30 +22554,34 @@ function transportEvent(update, metadata) {
|
|
|
22066
22554
|
text: update.content.text,
|
|
22067
22555
|
...update.messageId ? { messageId: update.messageId } : {}
|
|
22068
22556
|
};
|
|
22069
|
-
case "tool_call":
|
|
22557
|
+
case "tool_call": {
|
|
22558
|
+
const name = acpToolName(update, metadata);
|
|
22070
22559
|
return {
|
|
22071
22560
|
type: "tool.call",
|
|
22072
22561
|
callId: update.toolCallId,
|
|
22073
22562
|
title: update.title,
|
|
22074
|
-
...
|
|
22563
|
+
...name ? { name } : {},
|
|
22075
22564
|
...update.kind ? { kind: update.kind } : {},
|
|
22076
22565
|
...update.status ? { status: update.status } : {},
|
|
22077
22566
|
...update.rawInput !== void 0 ? { rawInput: update.rawInput } : {},
|
|
22078
22567
|
...update.rawOutput !== void 0 ? { rawOutput: update.rawOutput } : {},
|
|
22079
22568
|
...update.content ? { content: update.content } : {}
|
|
22080
22569
|
};
|
|
22081
|
-
|
|
22570
|
+
}
|
|
22571
|
+
case "tool_call_update": {
|
|
22572
|
+
const name = acpToolName(update, metadata);
|
|
22082
22573
|
return {
|
|
22083
22574
|
type: "tool.update",
|
|
22084
22575
|
callId: update.toolCallId,
|
|
22085
22576
|
...update.title !== void 0 ? { title: update.title } : {},
|
|
22086
|
-
...
|
|
22577
|
+
...name ? { name } : {},
|
|
22087
22578
|
...update.kind !== void 0 ? { kind: update.kind } : {},
|
|
22088
22579
|
...update.status !== void 0 ? { status: update.status } : {},
|
|
22089
22580
|
...update.rawInput !== void 0 ? { rawInput: update.rawInput } : {},
|
|
22090
22581
|
...update.rawOutput !== void 0 ? { rawOutput: update.rawOutput } : {},
|
|
22091
22582
|
...update.content !== void 0 ? { content: update.content } : {}
|
|
22092
22583
|
};
|
|
22584
|
+
}
|
|
22093
22585
|
case "usage_update":
|
|
22094
22586
|
return { type: "usage", update, ...metadata ? { metadata } : {} };
|
|
22095
22587
|
default:
|
|
@@ -22118,7 +22610,7 @@ async function readNativeSignals(options, sessionId) {
|
|
|
22118
22610
|
}
|
|
22119
22611
|
}
|
|
22120
22612
|
function isMissingFile(error53) {
|
|
22121
|
-
return
|
|
22613
|
+
return isRecord12(error53) && error53.code === "ENOENT";
|
|
22122
22614
|
}
|
|
22123
22615
|
async function locateGrokNativeSession(options, sessionId) {
|
|
22124
22616
|
if (sessionId.length === 0)
|
|
@@ -22141,7 +22633,7 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
22141
22633
|
try {
|
|
22142
22634
|
summaryRaw = await readFile(path8.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
|
|
22143
22635
|
} catch (error53) {
|
|
22144
|
-
if (isMissingFile(error53) ||
|
|
22636
|
+
if (isMissingFile(error53) || isRecord12(error53) && error53.code === "ENOTDIR")
|
|
22145
22637
|
continue;
|
|
22146
22638
|
throw new GrokTransportError("unavailable", "Grok Native Session metadata could not be read", {
|
|
22147
22639
|
cause: error53
|
|
@@ -22153,10 +22645,10 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
22153
22645
|
} catch {
|
|
22154
22646
|
continue;
|
|
22155
22647
|
}
|
|
22156
|
-
if (!
|
|
22648
|
+
if (!isRecord12(parsed))
|
|
22157
22649
|
continue;
|
|
22158
22650
|
const info = parsed.info;
|
|
22159
|
-
const cwd =
|
|
22651
|
+
const cwd = isRecord12(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path8.resolve(info.cwd) : path8.resolve(decodeURIComponent(entry.name));
|
|
22160
22652
|
const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path8.resolve(parsed.source_workspace_dir) : void 0;
|
|
22161
22653
|
matches.push({
|
|
22162
22654
|
cwd,
|
|
@@ -22189,12 +22681,12 @@ function parseNativeHistory(contents, sessionId) {
|
|
|
22189
22681
|
} catch {
|
|
22190
22682
|
throw new GrokTransportError("protocolError", "Grok Native history contains invalid JSON");
|
|
22191
22683
|
}
|
|
22192
|
-
if (!
|
|
22684
|
+
if (!isRecord12(record2) || !isRecord12(record2.params))
|
|
22193
22685
|
continue;
|
|
22194
22686
|
const params = record2.params;
|
|
22195
|
-
if (params.sessionId !== sessionId || !
|
|
22687
|
+
if (params.sessionId !== sessionId || !isRecord12(params.update))
|
|
22196
22688
|
continue;
|
|
22197
|
-
const metadata =
|
|
22689
|
+
const metadata = isRecord12(params._meta) ? params._meta : void 0;
|
|
22198
22690
|
const event = transportEvent(params.update, metadata);
|
|
22199
22691
|
if (event)
|
|
22200
22692
|
events.push(metadata ? { ...event, metadata } : event);
|
|
@@ -22497,7 +22989,7 @@ var GrokAcpTransport = class {
|
|
|
22497
22989
|
modelId,
|
|
22498
22990
|
...reasoningEffort ? { reasoningEffort } : {}
|
|
22499
22991
|
});
|
|
22500
|
-
if (!
|
|
22992
|
+
if (!isRecord12(response) || !isRecord12(response._meta) || !isRecord12(response._meta.model)) {
|
|
22501
22993
|
throw new GrokTransportError("protocolError", "Grok rejected Model configuration");
|
|
22502
22994
|
}
|
|
22503
22995
|
const selected = response._meta.model.Ok;
|
|
@@ -22540,7 +23032,7 @@ var GrokAcpTransport = class {
|
|
|
22540
23032
|
#handleUpdate(notification) {
|
|
22541
23033
|
if (this.#sessionId && notification.sessionId !== this.#sessionId)
|
|
22542
23034
|
return;
|
|
22543
|
-
const metadata =
|
|
23035
|
+
const metadata = isRecord12(notification._meta) ? notification._meta : void 0;
|
|
22544
23036
|
const event = transportEvent(notification.update, metadata);
|
|
22545
23037
|
if (!event)
|
|
22546
23038
|
return;
|
|
@@ -22555,7 +23047,7 @@ var GrokAcpTransport = class {
|
|
|
22555
23047
|
#handleExtensionNotification(method, params) {
|
|
22556
23048
|
if (!isGrokExtensionSessionUpdateMethod(method))
|
|
22557
23049
|
return;
|
|
22558
|
-
if (typeof params.sessionId !== "string" || !
|
|
23050
|
+
if (typeof params.sessionId !== "string" || !isRecord12(params.update))
|
|
22559
23051
|
return;
|
|
22560
23052
|
this.#handleUpdate(params);
|
|
22561
23053
|
}
|
|
@@ -22582,8 +23074,200 @@ var GrokAcpTransport = class {
|
|
|
22582
23074
|
}
|
|
22583
23075
|
};
|
|
22584
23076
|
|
|
23077
|
+
// dist/grok-subagent-lifecycle.js
|
|
23078
|
+
function subagentFailure() {
|
|
23079
|
+
return {
|
|
23080
|
+
code: "nativeFailure",
|
|
23081
|
+
message: "Grok Subagent delegation failed",
|
|
23082
|
+
retryable: false
|
|
23083
|
+
};
|
|
23084
|
+
}
|
|
23085
|
+
var GrokSubagentLifecycle = class {
|
|
23086
|
+
#emit;
|
|
23087
|
+
#newItemId;
|
|
23088
|
+
#delegations = /* @__PURE__ */ new Map();
|
|
23089
|
+
#callIdByNativeId = /* @__PURE__ */ new Map();
|
|
23090
|
+
constructor(options) {
|
|
23091
|
+
this.#emit = options.emit;
|
|
23092
|
+
this.#newItemId = options.newItemId;
|
|
23093
|
+
}
|
|
23094
|
+
get size() {
|
|
23095
|
+
return this.#delegations.size;
|
|
23096
|
+
}
|
|
23097
|
+
has(callId) {
|
|
23098
|
+
return this.#delegations.has(callId);
|
|
23099
|
+
}
|
|
23100
|
+
nativeSubagentId(callId) {
|
|
23101
|
+
return this.#delegations.get(callId)?.item.subagents[0]?.nativeSubagentId;
|
|
23102
|
+
}
|
|
23103
|
+
start(turnId, input) {
|
|
23104
|
+
if (this.#delegations.has(input.callId)) {
|
|
23105
|
+
throw new Error("Grok Subagent delegation started more than once");
|
|
23106
|
+
}
|
|
23107
|
+
this.#callIdByNativeId.set(input.callId, input.callId);
|
|
23108
|
+
if (input.nativeSubagentId)
|
|
23109
|
+
this.#callIdByNativeId.set(input.nativeSubagentId, input.callId);
|
|
23110
|
+
const subagent = {
|
|
23111
|
+
subagentId: input.nativeSubagentId ?? input.callId,
|
|
23112
|
+
...input.nativeSubagentId ? { nativeSubagentId: input.nativeSubagentId } : {},
|
|
23113
|
+
description: input.description,
|
|
23114
|
+
...input.role ? { role: input.role } : {},
|
|
23115
|
+
...input.model ? { model: input.model } : {},
|
|
23116
|
+
...input.reasoningEffort ? { reasoningEffort: input.reasoningEffort } : {},
|
|
23117
|
+
background: input.background,
|
|
23118
|
+
status: "running"
|
|
23119
|
+
};
|
|
23120
|
+
const item = {
|
|
23121
|
+
type: "subagentDelegation",
|
|
23122
|
+
itemId: this.#newItemId(),
|
|
23123
|
+
operation: input.operation,
|
|
23124
|
+
...input.prompt ? { prompt: input.prompt } : {},
|
|
23125
|
+
subagents: [subagent]
|
|
23126
|
+
};
|
|
23127
|
+
this.#delegations.set(input.callId, { callId: input.callId, item });
|
|
23128
|
+
this.#emit({ type: "item.started", turnId, item });
|
|
23129
|
+
this.#emitState(subagent);
|
|
23130
|
+
return subagent;
|
|
23131
|
+
}
|
|
23132
|
+
bindNativeId(turnId, input) {
|
|
23133
|
+
for (const [callId, active] of this.#delegations) {
|
|
23134
|
+
const current = active.item.subagents[0];
|
|
23135
|
+
if (!current)
|
|
23136
|
+
continue;
|
|
23137
|
+
if (current.nativeSubagentId === input.nativeSubagentId) {
|
|
23138
|
+
return this.update(turnId, callId, input);
|
|
23139
|
+
}
|
|
23140
|
+
}
|
|
23141
|
+
for (const [callId, active] of this.#delegations) {
|
|
23142
|
+
const current = active.item.subagents[0];
|
|
23143
|
+
if (!current || current.nativeSubagentId)
|
|
23144
|
+
continue;
|
|
23145
|
+
if (input.description && current.description === input.description) {
|
|
23146
|
+
return this.update(turnId, callId, input);
|
|
23147
|
+
}
|
|
23148
|
+
}
|
|
23149
|
+
return void 0;
|
|
23150
|
+
}
|
|
23151
|
+
update(turnId, callId, patch) {
|
|
23152
|
+
const active = this.#delegations.get(callId);
|
|
23153
|
+
if (!active)
|
|
23154
|
+
return void 0;
|
|
23155
|
+
const current = active.item.subagents[0];
|
|
23156
|
+
if (!current)
|
|
23157
|
+
throw new Error("Grok Subagent delegation has no Agent state");
|
|
23158
|
+
if (patch.nativeSubagentId)
|
|
23159
|
+
this.#callIdByNativeId.set(patch.nativeSubagentId, callId);
|
|
23160
|
+
const nativeSubagentId = patch.nativeSubagentId ?? current.nativeSubagentId;
|
|
23161
|
+
const subagent = {
|
|
23162
|
+
...current,
|
|
23163
|
+
...nativeSubagentId ? { nativeSubagentId, subagentId: nativeSubagentId } : {},
|
|
23164
|
+
...patch.description ? { description: patch.description } : {},
|
|
23165
|
+
...patch.role ? { role: patch.role } : {},
|
|
23166
|
+
...patch.model ? { model: patch.model } : {},
|
|
23167
|
+
...patch.reasoningEffort ? { reasoningEffort: patch.reasoningEffort } : {},
|
|
23168
|
+
...patch.resultSummary ? { resultSummary: patch.resultSummary } : {},
|
|
23169
|
+
...patch.status ? { status: patch.status } : {}
|
|
23170
|
+
};
|
|
23171
|
+
active.item = { ...active.item, subagents: [subagent] };
|
|
23172
|
+
this.#emit({
|
|
23173
|
+
type: "item.updated",
|
|
23174
|
+
turnId,
|
|
23175
|
+
itemId: active.item.itemId,
|
|
23176
|
+
update: { type: "subagents.replace", subagents: active.item.subagents }
|
|
23177
|
+
});
|
|
23178
|
+
this.#emitState(subagent);
|
|
23179
|
+
return subagent;
|
|
23180
|
+
}
|
|
23181
|
+
completeSpawn(turnId, callId, input) {
|
|
23182
|
+
const active = this.#delegations.get(callId);
|
|
23183
|
+
const background = input.background ?? active?.item.subagents[0]?.background ?? true;
|
|
23184
|
+
const keepRunning = !input.failed && !input.cancellationRequested && (background || active?.item.operation === "send");
|
|
23185
|
+
if (keepRunning) {
|
|
23186
|
+
return this.update(turnId, callId, {
|
|
23187
|
+
status: "running",
|
|
23188
|
+
...input.nativeSubagentId ? { nativeSubagentId: input.nativeSubagentId } : {},
|
|
23189
|
+
...input.resultSummary ? { resultSummary: input.resultSummary } : {}
|
|
23190
|
+
});
|
|
23191
|
+
}
|
|
23192
|
+
return this.complete(turnId, callId, { ...input, keepRunning: false });
|
|
23193
|
+
}
|
|
23194
|
+
completeByNativeId(turnId, nativeSubagentId, input) {
|
|
23195
|
+
const callId = this.#callIdByNativeId.get(nativeSubagentId) ?? this.#callIdForNative(nativeSubagentId);
|
|
23196
|
+
if (callId && this.#delegations.has(callId)) {
|
|
23197
|
+
return this.complete(turnId, callId, { ...input, nativeSubagentId });
|
|
23198
|
+
}
|
|
23199
|
+
const status = input.status ?? (input.cancellationRequested ? "interrupted" : input.failed ? "failed" : "completed");
|
|
23200
|
+
this.#emit({
|
|
23201
|
+
type: "subagent.state.changed",
|
|
23202
|
+
nativeSubagentId,
|
|
23203
|
+
status,
|
|
23204
|
+
...input.resultSummary ? { resultSummary: input.resultSummary } : {}
|
|
23205
|
+
});
|
|
23206
|
+
return void 0;
|
|
23207
|
+
}
|
|
23208
|
+
complete(turnId, callId, input) {
|
|
23209
|
+
const active = this.#delegations.get(callId);
|
|
23210
|
+
if (!active)
|
|
23211
|
+
return void 0;
|
|
23212
|
+
this.#delegations.delete(callId);
|
|
23213
|
+
const current = active.item.subagents[0];
|
|
23214
|
+
if (!current)
|
|
23215
|
+
throw new Error("Grok Subagent delegation has no Agent state");
|
|
23216
|
+
const status = input.status ?? (input.cancellationRequested ? "interrupted" : input.failed ? "failed" : input.keepRunning ? "running" : "completed");
|
|
23217
|
+
const nativeSubagentId = input.nativeSubagentId ?? current.nativeSubagentId;
|
|
23218
|
+
if (nativeSubagentId)
|
|
23219
|
+
this.#callIdByNativeId.set(nativeSubagentId, callId);
|
|
23220
|
+
const subagent = {
|
|
23221
|
+
...current,
|
|
23222
|
+
status,
|
|
23223
|
+
...nativeSubagentId ? { nativeSubagentId, subagentId: nativeSubagentId } : {},
|
|
23224
|
+
...input.resultSummary ? { resultSummary: input.resultSummary } : {}
|
|
23225
|
+
};
|
|
23226
|
+
const item = { ...active.item, subagents: [subagent] };
|
|
23227
|
+
this.#emit({
|
|
23228
|
+
type: "item.updated",
|
|
23229
|
+
turnId,
|
|
23230
|
+
itemId: item.itemId,
|
|
23231
|
+
update: { type: "subagents.replace", subagents: item.subagents }
|
|
23232
|
+
});
|
|
23233
|
+
const outcome = input.cancellationRequested ? { status: "cancelled", reason: "Cancelled by user" } : input.failed ? { status: "failed", error: subagentFailure() } : { status: "succeeded" };
|
|
23234
|
+
this.#emit({ type: "item.completed", turnId, snapshot: { item, outcome } });
|
|
23235
|
+
this.#emitState(subagent);
|
|
23236
|
+
return subagent;
|
|
23237
|
+
}
|
|
23238
|
+
finalize(turnId, outcome) {
|
|
23239
|
+
for (const [callId, active] of this.#delegations) {
|
|
23240
|
+
this.#delegations.delete(callId);
|
|
23241
|
+
const current = active.item.subagents[0];
|
|
23242
|
+
if (!current)
|
|
23243
|
+
continue;
|
|
23244
|
+
const status = outcome.status === "succeeded" ? current.status : outcome.status === "cancelled" ? "interrupted" : "failed";
|
|
23245
|
+
const item = { ...active.item, subagents: [{ ...current, status }] };
|
|
23246
|
+
this.#emit({ type: "item.completed", turnId, snapshot: { item, outcome } });
|
|
23247
|
+
this.#emitState({ ...current, status });
|
|
23248
|
+
}
|
|
23249
|
+
}
|
|
23250
|
+
#callIdForNative(nativeSubagentId) {
|
|
23251
|
+
for (const [callId, active] of this.#delegations) {
|
|
23252
|
+
if (active.item.subagents[0]?.nativeSubagentId === nativeSubagentId)
|
|
23253
|
+
return callId;
|
|
23254
|
+
}
|
|
23255
|
+
return void 0;
|
|
23256
|
+
}
|
|
23257
|
+
#emitState(subagent) {
|
|
23258
|
+
if (!subagent.nativeSubagentId)
|
|
23259
|
+
return;
|
|
23260
|
+
this.#emit({
|
|
23261
|
+
type: "subagent.state.changed",
|
|
23262
|
+
nativeSubagentId: subagent.nativeSubagentId,
|
|
23263
|
+
status: subagent.status,
|
|
23264
|
+
...subagent.resultSummary ? { resultSummary: subagent.resultSummary } : {}
|
|
23265
|
+
});
|
|
23266
|
+
}
|
|
23267
|
+
};
|
|
23268
|
+
|
|
22585
23269
|
// dist/grok-models.js
|
|
22586
|
-
function
|
|
23270
|
+
function isRecord13(value) {
|
|
22587
23271
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22588
23272
|
}
|
|
22589
23273
|
function nonBlank(value) {
|
|
@@ -22595,7 +23279,7 @@ function thinkingOptions(value) {
|
|
|
22595
23279
|
const seen = /* @__PURE__ */ new Set();
|
|
22596
23280
|
const options = [];
|
|
22597
23281
|
for (const candidate of value) {
|
|
22598
|
-
if (!
|
|
23282
|
+
if (!isRecord13(candidate) || !nonBlank(candidate.label))
|
|
22599
23283
|
continue;
|
|
22600
23284
|
const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
|
|
22601
23285
|
if (!id.success || seen.has(id.data))
|
|
@@ -22606,7 +23290,7 @@ function thinkingOptions(value) {
|
|
|
22606
23290
|
return options;
|
|
22607
23291
|
}
|
|
22608
23292
|
function parseGrokModelState(value) {
|
|
22609
|
-
if (!
|
|
23293
|
+
if (!isRecord13(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
|
|
22610
23294
|
return null;
|
|
22611
23295
|
}
|
|
22612
23296
|
const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
|
|
@@ -22617,12 +23301,12 @@ function parseGrokModelState(value) {
|
|
|
22617
23301
|
const models = [];
|
|
22618
23302
|
let currentThinkingOptionId;
|
|
22619
23303
|
for (const candidate of value.availableModels) {
|
|
22620
|
-
if (!
|
|
23304
|
+
if (!isRecord13(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
|
|
22621
23305
|
continue;
|
|
22622
23306
|
const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
|
|
22623
23307
|
if (!ref.success)
|
|
22624
23308
|
continue;
|
|
22625
|
-
const metadata =
|
|
23309
|
+
const metadata = isRecord13(candidate._meta) ? candidate._meta : {};
|
|
22626
23310
|
const options2 = thinkingOptions(metadata.reasoningEfforts);
|
|
22627
23311
|
if (typeof metadata.totalContextTokens === "number" && Number.isSafeInteger(metadata.totalContextTokens) && metadata.totalContextTokens > 0) {
|
|
22628
23312
|
contextWindowTokensByModel.set(ref.data.id, metadata.totalContextTokens);
|
|
@@ -22657,10 +23341,10 @@ function parseGrokModelState(value) {
|
|
|
22657
23341
|
};
|
|
22658
23342
|
}
|
|
22659
23343
|
function modelStateFromInitialize(response) {
|
|
22660
|
-
return parseGrokModelState(
|
|
23344
|
+
return parseGrokModelState(isRecord13(response._meta) ? response._meta.modelState : void 0);
|
|
22661
23345
|
}
|
|
22662
23346
|
function modelStateFromSessionResponse(response) {
|
|
22663
|
-
return parseGrokModelState(
|
|
23347
|
+
return parseGrokModelState(isRecord13(response) ? response.models : void 0);
|
|
22664
23348
|
}
|
|
22665
23349
|
function stateForGrokModel(modelState, nativeState, model = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
|
|
22666
23350
|
const selectedModel = model;
|
|
@@ -22684,7 +23368,7 @@ import os4 from "node:os";
|
|
|
22684
23368
|
import path9 from "node:path";
|
|
22685
23369
|
var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
22686
23370
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
22687
|
-
function
|
|
23371
|
+
function isRecord14(value) {
|
|
22688
23372
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22689
23373
|
}
|
|
22690
23374
|
function finitePercent(value) {
|
|
@@ -22714,7 +23398,7 @@ function productUsageFrom(value) {
|
|
|
22714
23398
|
if (!Array.isArray(value))
|
|
22715
23399
|
return void 0;
|
|
22716
23400
|
const products = value.flatMap((entry) => {
|
|
22717
|
-
if (!
|
|
23401
|
+
if (!isRecord14(entry) || typeof entry.product !== "string")
|
|
22718
23402
|
return [];
|
|
22719
23403
|
const usagePercent = finitePercent(entry.usagePercent);
|
|
22720
23404
|
return usagePercent === void 0 ? [] : [{ product: entry.product, usagePercent }];
|
|
@@ -22722,13 +23406,13 @@ function productUsageFrom(value) {
|
|
|
22722
23406
|
return products.length > 0 ? products : void 0;
|
|
22723
23407
|
}
|
|
22724
23408
|
function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
22725
|
-
if (!
|
|
23409
|
+
if (!isRecord14(value) || !isRecord14(value.config))
|
|
22726
23410
|
return null;
|
|
22727
23411
|
const config2 = value.config;
|
|
22728
|
-
const period =
|
|
23412
|
+
const period = isRecord14(config2.currentPeriod) ? config2.currentPeriod : void 0;
|
|
22729
23413
|
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 =
|
|
22731
|
-
const onDemandUsed =
|
|
23414
|
+
const onDemandCap = isRecord14(config2.onDemandCap) ? nonNegativeNumber(config2.onDemandCap.val) : void 0;
|
|
23415
|
+
const onDemandUsed = isRecord14(config2.onDemandUsed) ? nonNegativeNumber(config2.onDemandUsed.val) : void 0;
|
|
22732
23416
|
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
23417
|
if (usedPercent === void 0)
|
|
22734
23418
|
return null;
|
|
@@ -22742,11 +23426,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
|
|
|
22742
23426
|
};
|
|
22743
23427
|
}
|
|
22744
23428
|
function selectAccessToken(auth, now) {
|
|
22745
|
-
if (!
|
|
23429
|
+
if (!isRecord14(auth))
|
|
22746
23430
|
return null;
|
|
22747
|
-
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) &&
|
|
23431
|
+
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
23432
|
for (const [, value] of entries) {
|
|
22749
|
-
if (!
|
|
23433
|
+
if (!isRecord14(value) || typeof value.key !== "string")
|
|
22750
23434
|
continue;
|
|
22751
23435
|
if (typeof value.expires_at === "string") {
|
|
22752
23436
|
const expiresAt = Date.parse(value.expires_at);
|
|
@@ -22818,7 +23502,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
22818
23502
|
|
|
22819
23503
|
// dist/grok-usage.js
|
|
22820
23504
|
var USD_TICKS_PER_DOLLAR = 1e10;
|
|
22821
|
-
function
|
|
23505
|
+
function isRecord15(value) {
|
|
22822
23506
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22823
23507
|
}
|
|
22824
23508
|
function optionalToken(value) {
|
|
@@ -22835,7 +23519,7 @@ function combineUsage(base, next) {
|
|
|
22835
23519
|
return base === null ? next : parseHostUsage({ ...base, ...next });
|
|
22836
23520
|
}
|
|
22837
23521
|
function usageFromNative(value) {
|
|
22838
|
-
if (!
|
|
23522
|
+
if (!isRecord15(value))
|
|
22839
23523
|
return null;
|
|
22840
23524
|
const nativeInputTokens = optionalToken(value.inputTokens);
|
|
22841
23525
|
const cachedRead = optionalToken(value.cachedReadTokens);
|
|
@@ -22864,7 +23548,7 @@ function usageFromPrompt(response) {
|
|
|
22864
23548
|
return response.usage ? usageFromNative(response.usage) : null;
|
|
22865
23549
|
}
|
|
22866
23550
|
function usageFromSignals(value) {
|
|
22867
|
-
if (!
|
|
23551
|
+
if (!isRecord15(value))
|
|
22868
23552
|
return null;
|
|
22869
23553
|
try {
|
|
22870
23554
|
return parseHostUsage({
|
|
@@ -22884,7 +23568,7 @@ var summedUsageFields = [
|
|
|
22884
23568
|
"totalTokens"
|
|
22885
23569
|
];
|
|
22886
23570
|
function nativeCostTicks(value) {
|
|
22887
|
-
if (!
|
|
23571
|
+
if (!isRecord15(value))
|
|
22888
23572
|
return void 0;
|
|
22889
23573
|
const ticks = value.costUsdTicks;
|
|
22890
23574
|
if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
|
|
@@ -22961,7 +23645,7 @@ function usageFromCompact(tokensAfter, contextWindowTokens) {
|
|
|
22961
23645
|
function usageFromUpdate(update, metadata, contextWindowTokens) {
|
|
22962
23646
|
try {
|
|
22963
23647
|
if (update?.sessionUpdate === "usage_update") {
|
|
22964
|
-
const cost =
|
|
23648
|
+
const cost = isRecord15(update.cost) ? update.cost : null;
|
|
22965
23649
|
return parseHostUsage({
|
|
22966
23650
|
contextUsedTokens: update.used,
|
|
22967
23651
|
contextWindowTokens: update.size,
|
|
@@ -23002,7 +23686,8 @@ function capabilitiesForModels(modelState) {
|
|
|
23002
23686
|
selectPermissionMode: true,
|
|
23003
23687
|
permissionModeScope: "atCreate"
|
|
23004
23688
|
},
|
|
23005
|
-
history: { fork: true, forkAcrossCwd: true, rollbackLastTurn: true }
|
|
23689
|
+
history: { fork: true, forkAcrossCwd: true, rollbackLastTurn: true },
|
|
23690
|
+
subagents: { observe: true, readTranscript: true }
|
|
23006
23691
|
};
|
|
23007
23692
|
}
|
|
23008
23693
|
var DEFAULT_CLOSE_TIMEOUT_MS = 2e3;
|
|
@@ -23203,6 +23888,7 @@ var GrokHarnessSession = class {
|
|
|
23203
23888
|
compactionContextWindow: void 0,
|
|
23204
23889
|
compactionTerminal: null,
|
|
23205
23890
|
tools: /* @__PURE__ */ new Map(),
|
|
23891
|
+
subagents: this.#createSubagents(),
|
|
23206
23892
|
completedItems: [],
|
|
23207
23893
|
approvals: /* @__PURE__ */ new Map(),
|
|
23208
23894
|
questions: /* @__PURE__ */ new Map(),
|
|
@@ -23278,6 +23964,7 @@ var GrokHarnessSession = class {
|
|
|
23278
23964
|
compactionContextWindow: void 0,
|
|
23279
23965
|
compactionTerminal: null,
|
|
23280
23966
|
tools: /* @__PURE__ */ new Map(),
|
|
23967
|
+
subagents: this.#createSubagents(),
|
|
23281
23968
|
completedItems: [],
|
|
23282
23969
|
approvals: /* @__PURE__ */ new Map(),
|
|
23283
23970
|
questions: /* @__PURE__ */ new Map(),
|
|
@@ -23607,6 +24294,10 @@ var GrokHarnessSession = class {
|
|
|
23607
24294
|
this.#startTool(active, event);
|
|
23608
24295
|
else if (event.type === "tool.update")
|
|
23609
24296
|
this.#updateTool(active, event);
|
|
24297
|
+
else if (event.type === "subagent.spawned")
|
|
24298
|
+
this.#bindSpawnedSubagent(active, event);
|
|
24299
|
+
else if (event.type === "subagent.finished")
|
|
24300
|
+
this.#finishNativeSubagent(active, event);
|
|
23610
24301
|
else if (event.type === "compaction.started")
|
|
23611
24302
|
this.#startCompaction(active, event);
|
|
23612
24303
|
else if (event.type === "compaction.completed") {
|
|
@@ -23713,9 +24404,44 @@ var GrokHarnessSession = class {
|
|
|
23713
24404
|
update: { type: "text.append", text }
|
|
23714
24405
|
});
|
|
23715
24406
|
}
|
|
24407
|
+
#createSubagents() {
|
|
24408
|
+
return new GrokSubagentLifecycle({
|
|
24409
|
+
newItemId: () => hostItemIdSchema.parse(this.#randomUUID()),
|
|
24410
|
+
emit: (event) => this.#event(event)
|
|
24411
|
+
});
|
|
24412
|
+
}
|
|
24413
|
+
#subagentModelLabel(modelId) {
|
|
24414
|
+
const id = modelId ?? this.#state.effectiveModel?.id;
|
|
24415
|
+
if (!id)
|
|
24416
|
+
return void 0;
|
|
24417
|
+
return this.#modelState.catalog.models.find((model) => model.ref.id === id)?.label ?? id;
|
|
24418
|
+
}
|
|
23716
24419
|
#startTool(active, event) {
|
|
23717
24420
|
this.#completeReasoning(active, { status: "succeeded" });
|
|
23718
24421
|
this.#completeAgent(active, { status: "succeeded" });
|
|
24422
|
+
const operation = grokSubagentOperation(event.name, event.title, event.rawInput);
|
|
24423
|
+
if (operation) {
|
|
24424
|
+
const prompt = grokSubagentPrompt(event.rawInput);
|
|
24425
|
+
const role = grokSubagentRole(event.rawInput);
|
|
24426
|
+
const nativeSubagentId = grokNativeSubagentId(event.rawInput);
|
|
24427
|
+
const model = this.#subagentModelLabel(grokSubagentModel(event.rawInput));
|
|
24428
|
+
const reasoningEffort = this.#state.effectiveThinkingOptionId;
|
|
24429
|
+
active.subagents.start(active.command.turnId, {
|
|
24430
|
+
callId: event.callId,
|
|
24431
|
+
operation,
|
|
24432
|
+
description: grokSubagentDescription(event.rawInput, event.title),
|
|
24433
|
+
...prompt ? { prompt } : {},
|
|
24434
|
+
...role ? { role } : {},
|
|
24435
|
+
...model ? { model } : {},
|
|
24436
|
+
...reasoningEffort ? { reasoningEffort } : {},
|
|
24437
|
+
background: grokSubagentBackground(event.rawInput),
|
|
24438
|
+
...nativeSubagentId ? { nativeSubagentId } : {}
|
|
24439
|
+
});
|
|
24440
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
24441
|
+
this.#completeSubagentTool(active, event.callId, event.status, event);
|
|
24442
|
+
}
|
|
24443
|
+
return;
|
|
24444
|
+
}
|
|
23719
24445
|
let item = startGrokToolItem({
|
|
23720
24446
|
itemId: hostItemIdSchema.parse(this.#randomUUID()),
|
|
23721
24447
|
name: event.name,
|
|
@@ -23734,6 +24460,34 @@ var GrokHarnessSession = class {
|
|
|
23734
24460
|
}
|
|
23735
24461
|
}
|
|
23736
24462
|
#updateTool(active, event) {
|
|
24463
|
+
if (!active.subagents.has(event.callId) && !active.tools.has(event.callId) && grokSubagentOperation(event.name, event.title, event.rawInput)) {
|
|
24464
|
+
this.#startTool(active, {
|
|
24465
|
+
type: "tool.call",
|
|
24466
|
+
callId: event.callId,
|
|
24467
|
+
title: event.title ?? "Grok Subagent",
|
|
24468
|
+
...event.name ? { name: event.name } : {},
|
|
24469
|
+
...event.kind ? { kind: event.kind } : {},
|
|
24470
|
+
...event.status ? { status: event.status } : {},
|
|
24471
|
+
...event.rawInput !== void 0 ? { rawInput: event.rawInput } : {},
|
|
24472
|
+
...event.rawOutput !== void 0 ? { rawOutput: event.rawOutput } : {},
|
|
24473
|
+
...event.content ? { content: event.content } : {}
|
|
24474
|
+
});
|
|
24475
|
+
return;
|
|
24476
|
+
}
|
|
24477
|
+
if (active.subagents.has(event.callId)) {
|
|
24478
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
24479
|
+
this.#completeSubagentTool(active, event.callId, event.status, event);
|
|
24480
|
+
return;
|
|
24481
|
+
}
|
|
24482
|
+
const role = grokSubagentRole(event.rawInput);
|
|
24483
|
+
const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content);
|
|
24484
|
+
active.subagents.update(active.command.turnId, event.callId, {
|
|
24485
|
+
...event.title ? { description: grokSubagentDescription(event.rawInput, event.title) } : {},
|
|
24486
|
+
...role ? { role } : {},
|
|
24487
|
+
...nativeSubagentId ? { nativeSubagentId } : {}
|
|
24488
|
+
});
|
|
24489
|
+
return;
|
|
24490
|
+
}
|
|
23737
24491
|
const tool = active.tools.get(event.callId);
|
|
23738
24492
|
if (!tool)
|
|
23739
24493
|
return;
|
|
@@ -23787,6 +24541,7 @@ var GrokHarnessSession = class {
|
|
|
23787
24541
|
}
|
|
23788
24542
|
} : { status: "succeeded" };
|
|
23789
24543
|
this.#completeItem(active, tool.item, outcome);
|
|
24544
|
+
this.#completeWatchedSubagents(active, tool.item, content, rawOutput);
|
|
23790
24545
|
if (status !== "completed")
|
|
23791
24546
|
return;
|
|
23792
24547
|
const changes = projectGrokFileChanges(content, this.#cwd);
|
|
@@ -23800,6 +24555,52 @@ var GrokHarnessSession = class {
|
|
|
23800
24555
|
this.#event({ type: "item.started", turnId: active.command.turnId, item: fileItem });
|
|
23801
24556
|
this.#completeItem(active, fileItem, { status: "succeeded" });
|
|
23802
24557
|
}
|
|
24558
|
+
#completeSubagentTool(active, callId, status, event) {
|
|
24559
|
+
const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content);
|
|
24560
|
+
const resultSummary = grokSubagentResultSummary(event.content, event.rawOutput);
|
|
24561
|
+
active.subagents.completeSpawn(active.command.turnId, callId, {
|
|
24562
|
+
failed: status === "failed",
|
|
24563
|
+
cancellationRequested: active.cancellationRequested,
|
|
24564
|
+
...nativeSubagentId ? { nativeSubagentId } : {},
|
|
24565
|
+
...resultSummary ? { resultSummary } : {}
|
|
24566
|
+
});
|
|
24567
|
+
}
|
|
24568
|
+
#completeWatchedSubagents(active, item, content, rawOutput) {
|
|
24569
|
+
const name = item.type === "toolExecution" ? item.toolName : item.command;
|
|
24570
|
+
const rawInput = item.type === "toolExecution" ? item.arguments : void 0;
|
|
24571
|
+
const resultSummary = grokSubagentResultSummary(content, rawOutput);
|
|
24572
|
+
for (const settlement of grokSubagentWaitSettlements({
|
|
24573
|
+
name,
|
|
24574
|
+
title: name,
|
|
24575
|
+
rawInput,
|
|
24576
|
+
content,
|
|
24577
|
+
rawOutput
|
|
24578
|
+
})) {
|
|
24579
|
+
active.subagents.completeByNativeId(active.command.turnId, settlement.id, {
|
|
24580
|
+
failed: settlement.status === "failed",
|
|
24581
|
+
cancellationRequested: active.cancellationRequested || settlement.status === "interrupted",
|
|
24582
|
+
status: settlement.status,
|
|
24583
|
+
...settlement.resultSummary ? { resultSummary: settlement.resultSummary } : resultSummary ? { resultSummary } : {}
|
|
24584
|
+
});
|
|
24585
|
+
}
|
|
24586
|
+
}
|
|
24587
|
+
#bindSpawnedSubagent(active, event) {
|
|
24588
|
+
const model = event.model ? this.#subagentModelLabel(event.model) : void 0;
|
|
24589
|
+
active.subagents.bindNativeId(active.command.turnId, {
|
|
24590
|
+
nativeSubagentId: event.nativeSubagentId,
|
|
24591
|
+
...event.description ? { description: event.description } : {},
|
|
24592
|
+
...event.role ? { role: event.role } : {},
|
|
24593
|
+
...model ? { model } : {}
|
|
24594
|
+
});
|
|
24595
|
+
}
|
|
24596
|
+
#finishNativeSubagent(active, event) {
|
|
24597
|
+
active.subagents.completeByNativeId(active.command.turnId, event.nativeSubagentId, {
|
|
24598
|
+
failed: event.status === "failed",
|
|
24599
|
+
cancellationRequested: active.cancellationRequested || event.status === "interrupted",
|
|
24600
|
+
status: event.status,
|
|
24601
|
+
...event.resultSummary ? { resultSummary: event.resultSummary } : {}
|
|
24602
|
+
});
|
|
24603
|
+
}
|
|
23803
24604
|
#completeAgent(active, outcome) {
|
|
23804
24605
|
const item = active.agent;
|
|
23805
24606
|
if (item && active.rawAgentText.length > 0) {
|
|
@@ -23863,6 +24664,7 @@ var GrokHarnessSession = class {
|
|
|
23863
24664
|
const itemOutcome = outcome;
|
|
23864
24665
|
this.#completeReasoning(active, itemOutcome);
|
|
23865
24666
|
this.#completeAgent(active, itemOutcome);
|
|
24667
|
+
active.subagents.finalize(active.command.turnId, itemOutcome);
|
|
23866
24668
|
if (active.compactionItem) {
|
|
23867
24669
|
this.#completeItem(active, active.compactionItem, itemOutcome);
|
|
23868
24670
|
active.compactionItem = null;
|
|
@@ -23940,6 +24742,39 @@ var GrokHarnessSession = class {
|
|
|
23940
24742
|
var GrokAdapter = class {
|
|
23941
24743
|
commandCatalog = grokCommandCatalog;
|
|
23942
24744
|
harnessId = grokHarnessId;
|
|
24745
|
+
subagents = {
|
|
24746
|
+
readSnapshot: async (input) => {
|
|
24747
|
+
if (input.parent.harnessId !== this.harnessId || input.nativeSubagentId.trim().length === 0) {
|
|
24748
|
+
return {
|
|
24749
|
+
ok: false,
|
|
24750
|
+
error: {
|
|
24751
|
+
code: "invalidRequest",
|
|
24752
|
+
message: "Grok Subagent reference is invalid",
|
|
24753
|
+
retryable: false
|
|
24754
|
+
}
|
|
24755
|
+
};
|
|
24756
|
+
}
|
|
24757
|
+
try {
|
|
24758
|
+
const location = await locateGrokNativeSession(this.#environment ? { environment: this.#environment } : {}, input.nativeSubagentId);
|
|
24759
|
+
const cwd = location?.cwd ?? input.cwd;
|
|
24760
|
+
const history = await readGrokNativeHistory(this.#environment ? { cwd, environment: this.#environment } : { cwd }, input.nativeSubagentId);
|
|
24761
|
+
return {
|
|
24762
|
+
ok: true,
|
|
24763
|
+
value: mapGrokReplay(
|
|
24764
|
+
history,
|
|
24765
|
+
this.harnessId,
|
|
24766
|
+
// Host Subagent records keep the parent Native Session identity.
|
|
24767
|
+
input.parent.nativeSessionId,
|
|
24768
|
+
cwd,
|
|
24769
|
+
[],
|
|
24770
|
+
this.#toolOutputLimit
|
|
24771
|
+
)
|
|
24772
|
+
};
|
|
24773
|
+
} catch (error53) {
|
|
24774
|
+
return { ok: false, error: normalizeError(error53, "protocolError") };
|
|
24775
|
+
}
|
|
24776
|
+
}
|
|
24777
|
+
};
|
|
23943
24778
|
#closeTimeoutMs;
|
|
23944
24779
|
#dependencies;
|
|
23945
24780
|
#environment;
|