@codexhost/cli-darwin-x64 0.6.1 → 0.7.0
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/THIRD_PARTY_NOTICES.txt +4 -0
- package/app/codexhost-distribution.json +1 -1
- package/app/desktop-controller.mjs +3 -1
- package/app/host-runtime.mjs +1000 -472
- package/app/plugins/antigravity/plugin.mjs +54 -205
- package/app/plugins/claude-code/plugin.mjs +223 -49
- package/app/plugins/codebuddy/assets/icon.svg +1 -0
- package/app/plugins/codebuddy/manifest.json +13 -0
- package/app/plugins/codebuddy/plugin.mjs +23045 -0
- package/app/plugins/cursor-cli/assets/icon.svg +1 -0
- package/app/plugins/cursor-cli/manifest.json +13 -0
- package/app/plugins/cursor-cli/plugin.mjs +22579 -0
- package/app/plugins/deepseek-harness/plugin.mjs +7695 -10516
- package/app/plugins/enabled.json +3 -1
- package/app/plugins/grok/plugin.mjs +921 -74
- package/app/plugins/kiro-cli/plugin.mjs +29 -6
- package/app/plugins/pi/plugin.mjs +0 -12
- package/app/renderer-extension.js +746 -344
- package/bin/codexhost +0 -0
- package/libexec/codexhost-shim +0 -0
- package/libexec/codexhost-updater +0 -0
- package/licenses/Agent-Client-Protocol-SDK-LICENSE.txt +191 -0
- package/package.json +1 -1
|
@@ -19938,8 +19938,13 @@ function resolveGrokExecutable(input = {}) {
|
|
|
19938
19938
|
throw new GrokExecutableError("Grok CLI is not installed");
|
|
19939
19939
|
return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable : path3.resolve(resolution.executable);
|
|
19940
19940
|
}
|
|
19941
|
-
function grokInvocation(command, platform = process.platform) {
|
|
19942
|
-
|
|
19941
|
+
function grokInvocation(command, platform = process.platform, modelId) {
|
|
19942
|
+
const arguments_ = ["agent", "--no-leader"];
|
|
19943
|
+
const trimmed = modelId?.trim();
|
|
19944
|
+
if (trimmed)
|
|
19945
|
+
arguments_.push("--model", trimmed);
|
|
19946
|
+
arguments_.push("stdio");
|
|
19947
|
+
return commandInvocation(command, arguments_, process.env, platform);
|
|
19943
19948
|
}
|
|
19944
19949
|
|
|
19945
19950
|
// dist/grok-fork.js
|
|
@@ -20930,6 +20935,309 @@ function hasGrokToolProjection(projection) {
|
|
|
20930
20935
|
return projection.output !== void 0 || projection.exitCode !== void 0;
|
|
20931
20936
|
}
|
|
20932
20937
|
|
|
20938
|
+
// dist/grok-subagent.js
|
|
20939
|
+
var SPAWN_TOOL_NAMES = /* @__PURE__ */ new Set(["spawn_subagent", "spawn_agent", "task"]);
|
|
20940
|
+
var SEND_TOOL_NAMES = /* @__PURE__ */ new Set(["send_subagent_message"]);
|
|
20941
|
+
var WAIT_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
20942
|
+
"get_command_or_subagent_output",
|
|
20943
|
+
"get_task_output",
|
|
20944
|
+
"wait_tasks"
|
|
20945
|
+
]);
|
|
20946
|
+
var KILL_TOOL_NAMES = /* @__PURE__ */ new Set(["kill_command_or_subagent", "kill_task"]);
|
|
20947
|
+
var DESCRIPTION_LIMIT = 500;
|
|
20948
|
+
var SUMMARY_LIMIT = 2e3;
|
|
20949
|
+
function isRecord5(value) {
|
|
20950
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20951
|
+
}
|
|
20952
|
+
function idField(value, key) {
|
|
20953
|
+
if (!isRecord5(value))
|
|
20954
|
+
return void 0;
|
|
20955
|
+
const field = value[key];
|
|
20956
|
+
if (typeof field === "string") {
|
|
20957
|
+
const trimmed = field.trim();
|
|
20958
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
20959
|
+
}
|
|
20960
|
+
if (typeof field === "number" && Number.isFinite(field))
|
|
20961
|
+
return String(field);
|
|
20962
|
+
return void 0;
|
|
20963
|
+
}
|
|
20964
|
+
function stringField2(value, key) {
|
|
20965
|
+
if (!isRecord5(value) || typeof value[key] !== "string")
|
|
20966
|
+
return void 0;
|
|
20967
|
+
const trimmed = value[key].trim();
|
|
20968
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
20969
|
+
}
|
|
20970
|
+
function bounded(value, limit) {
|
|
20971
|
+
if (!value)
|
|
20972
|
+
return void 0;
|
|
20973
|
+
return value.slice(0, limit);
|
|
20974
|
+
}
|
|
20975
|
+
function toolId(name, title) {
|
|
20976
|
+
return grokToolName(name, title).toLowerCase();
|
|
20977
|
+
}
|
|
20978
|
+
function collectIds(value) {
|
|
20979
|
+
const ids = [];
|
|
20980
|
+
const push = (entry) => {
|
|
20981
|
+
if (typeof entry === "string" && entry.trim().length > 0)
|
|
20982
|
+
ids.push(entry.trim());
|
|
20983
|
+
else if (typeof entry === "number" && Number.isFinite(entry))
|
|
20984
|
+
ids.push(String(entry));
|
|
20985
|
+
};
|
|
20986
|
+
push(idField(value, "task_id"));
|
|
20987
|
+
push(idField(value, "subagent_id"));
|
|
20988
|
+
if (isRecord5(value)) {
|
|
20989
|
+
const list = value.task_ids ?? value.subagent_ids;
|
|
20990
|
+
if (Array.isArray(list)) {
|
|
20991
|
+
for (const entry of list)
|
|
20992
|
+
push(entry);
|
|
20993
|
+
} else {
|
|
20994
|
+
push(list);
|
|
20995
|
+
}
|
|
20996
|
+
}
|
|
20997
|
+
return [...new Set(ids)];
|
|
20998
|
+
}
|
|
20999
|
+
function grokSubagentOperation(name, title, rawInput) {
|
|
21000
|
+
const id = toolId(name, title);
|
|
21001
|
+
if (WAIT_TOOL_NAMES.has(id) || KILL_TOOL_NAMES.has(id))
|
|
21002
|
+
return null;
|
|
21003
|
+
if (SEND_TOOL_NAMES.has(id))
|
|
21004
|
+
return "send";
|
|
21005
|
+
if (SPAWN_TOOL_NAMES.has(id))
|
|
21006
|
+
return "spawn";
|
|
21007
|
+
if (isRecord5(rawInput) && rawInput.variant === "Task")
|
|
21008
|
+
return "spawn";
|
|
21009
|
+
return null;
|
|
21010
|
+
}
|
|
21011
|
+
function grokSubagentWaitIds(name, title, rawInput) {
|
|
21012
|
+
if (!WAIT_TOOL_NAMES.has(toolId(name, title)) && !KILL_TOOL_NAMES.has(toolId(name, title))) {
|
|
21013
|
+
return [];
|
|
21014
|
+
}
|
|
21015
|
+
return collectIds(rawInput);
|
|
21016
|
+
}
|
|
21017
|
+
function grokSubagentKill(name, title) {
|
|
21018
|
+
return KILL_TOOL_NAMES.has(toolId(name, title));
|
|
21019
|
+
}
|
|
21020
|
+
function grokSubagentDescription(rawInput, title, fallback = "Grok Subagent") {
|
|
21021
|
+
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;
|
|
21022
|
+
}
|
|
21023
|
+
function grokSubagentPrompt(rawInput) {
|
|
21024
|
+
return bounded(stringField2(rawInput, "prompt") ?? stringField2(rawInput, "message"), SUMMARY_LIMIT);
|
|
21025
|
+
}
|
|
21026
|
+
function grokSubagentRole(rawInput) {
|
|
21027
|
+
return bounded(stringField2(rawInput, "subagent_type") ?? stringField2(rawInput, "agent_type") ?? stringField2(rawInput, "type"), DESCRIPTION_LIMIT);
|
|
21028
|
+
}
|
|
21029
|
+
function grokSubagentBackground(rawInput) {
|
|
21030
|
+
if (!isRecord5(rawInput))
|
|
21031
|
+
return true;
|
|
21032
|
+
if (rawInput.background === false || rawInput.run_in_background === false)
|
|
21033
|
+
return false;
|
|
21034
|
+
return true;
|
|
21035
|
+
}
|
|
21036
|
+
function grokSubagentModel(rawInput) {
|
|
21037
|
+
return bounded(stringField2(rawInput, "model"), DESCRIPTION_LIMIT);
|
|
21038
|
+
}
|
|
21039
|
+
function grokNativeSubagentId(...candidates) {
|
|
21040
|
+
const fromKey = (key) => {
|
|
21041
|
+
for (const candidate of candidates) {
|
|
21042
|
+
const value = idField(candidate, key);
|
|
21043
|
+
if (value)
|
|
21044
|
+
return value;
|
|
21045
|
+
}
|
|
21046
|
+
return void 0;
|
|
21047
|
+
};
|
|
21048
|
+
const fromText = (pattern) => {
|
|
21049
|
+
for (const candidate of candidates) {
|
|
21050
|
+
const text = extractText(candidate);
|
|
21051
|
+
const match = text?.match(pattern);
|
|
21052
|
+
if (match?.[1])
|
|
21053
|
+
return match[1].trim();
|
|
21054
|
+
}
|
|
21055
|
+
return void 0;
|
|
21056
|
+
};
|
|
21057
|
+
return fromKey("subagent_id") ?? fromText(/subagent_id:\s*([^\s]+)/i) ?? fromKey("task_id") ?? fromKey("id") ?? fromText(/task_id:\s*([^\s]+)/i) ?? fromText(/task_ids=\["([^"]+)"\]/);
|
|
21058
|
+
}
|
|
21059
|
+
function grokSubagentResultSummary(...candidates) {
|
|
21060
|
+
for (const candidate of candidates) {
|
|
21061
|
+
const text = extractText(candidate);
|
|
21062
|
+
if (text)
|
|
21063
|
+
return bounded(text, SUMMARY_LIMIT);
|
|
21064
|
+
}
|
|
21065
|
+
return void 0;
|
|
21066
|
+
}
|
|
21067
|
+
function grokSubagentEventFromUpdate(update) {
|
|
21068
|
+
if (!isRecord5(update) || typeof update.sessionUpdate !== "string")
|
|
21069
|
+
return null;
|
|
21070
|
+
const nativeSubagentId = idField(update, "subagent_id") ?? idField(update, "child_session_id");
|
|
21071
|
+
if (!nativeSubagentId)
|
|
21072
|
+
return null;
|
|
21073
|
+
if (update.sessionUpdate === "subagent_spawned") {
|
|
21074
|
+
const description = bounded(stringField2(update, "description"), DESCRIPTION_LIMIT);
|
|
21075
|
+
const role = bounded(stringField2(update, "subagent_type") ?? stringField2(update, "role"), DESCRIPTION_LIMIT);
|
|
21076
|
+
const model = bounded(stringField2(update, "model"), DESCRIPTION_LIMIT);
|
|
21077
|
+
return {
|
|
21078
|
+
type: "subagent.spawned",
|
|
21079
|
+
nativeSubagentId,
|
|
21080
|
+
...description ? { description } : {},
|
|
21081
|
+
...role ? { role } : {},
|
|
21082
|
+
...model ? { model } : {}
|
|
21083
|
+
};
|
|
21084
|
+
}
|
|
21085
|
+
if (update.sessionUpdate === "subagent_finished") {
|
|
21086
|
+
const mapped = mapTaskStatus(typeof update.status === "string" ? update.status : void 0);
|
|
21087
|
+
if (!mapped || mapped === "running" || mapped === "pending")
|
|
21088
|
+
return null;
|
|
21089
|
+
const status = mapped === "failed" ? "failed" : mapped === "interrupted" ? "interrupted" : "completed";
|
|
21090
|
+
const resultSummary = bounded(typeof update.output === "string" ? update.output.trim() : void 0, SUMMARY_LIMIT);
|
|
21091
|
+
return {
|
|
21092
|
+
type: "subagent.finished",
|
|
21093
|
+
nativeSubagentId,
|
|
21094
|
+
status,
|
|
21095
|
+
...resultSummary ? { resultSummary } : {}
|
|
21096
|
+
};
|
|
21097
|
+
}
|
|
21098
|
+
return null;
|
|
21099
|
+
}
|
|
21100
|
+
function grokSubagentWaitSettlements(input) {
|
|
21101
|
+
const ids = grokSubagentWaitIds(input.name, input.title, input.rawInput);
|
|
21102
|
+
if (grokSubagentKill(input.name, input.title)) {
|
|
21103
|
+
return ids.map((id) => ({ id, status: "interrupted" }));
|
|
21104
|
+
}
|
|
21105
|
+
if (ids.length === 0)
|
|
21106
|
+
return [];
|
|
21107
|
+
const resultEntries = taskOutputResults(input.rawOutput);
|
|
21108
|
+
if (resultEntries.length > 0) {
|
|
21109
|
+
const settled = [];
|
|
21110
|
+
for (const result of resultEntries) {
|
|
21111
|
+
const id = idField(result, "task_id") ?? idField(result, "subagent_id");
|
|
21112
|
+
const status = mapTaskStatus(typeof result.status === "string" ? result.status : void 0);
|
|
21113
|
+
if (!id || !status || status === "running" || status === "pending")
|
|
21114
|
+
continue;
|
|
21115
|
+
const resultSummary = bounded(typeof result.output === "string" ? result.output.trim() : void 0, SUMMARY_LIMIT);
|
|
21116
|
+
settled.push({ id, status, ...resultSummary ? { resultSummary } : {} });
|
|
21117
|
+
}
|
|
21118
|
+
return settled;
|
|
21119
|
+
}
|
|
21120
|
+
const fromText = taskOutputTextSettlements(input.rawOutput, input.content, ids);
|
|
21121
|
+
if (fromText.length > 0)
|
|
21122
|
+
return fromText;
|
|
21123
|
+
const overall = mapTaskStatus(taskOutputStatus(input.rawOutput, input.content));
|
|
21124
|
+
if (!overall || overall === "running" || overall === "pending")
|
|
21125
|
+
return [];
|
|
21126
|
+
return ids.map((id) => ({ id, status: overall }));
|
|
21127
|
+
}
|
|
21128
|
+
function taskOutputResults(rawOutput) {
|
|
21129
|
+
if (!isRecord5(rawOutput))
|
|
21130
|
+
return [];
|
|
21131
|
+
if (Array.isArray(rawOutput.results)) {
|
|
21132
|
+
return rawOutput.results.filter(isRecord5);
|
|
21133
|
+
}
|
|
21134
|
+
const nested = firstRecord(rawOutput.MultiResult, rawOutput.multiResult, rawOutput.multi_result);
|
|
21135
|
+
if (nested && Array.isArray(nested.results)) {
|
|
21136
|
+
return nested.results.filter(isRecord5);
|
|
21137
|
+
}
|
|
21138
|
+
const single = firstRecord(rawOutput.Result, rawOutput.result);
|
|
21139
|
+
if (single)
|
|
21140
|
+
return [single];
|
|
21141
|
+
if (typeof rawOutput.status === "string")
|
|
21142
|
+
return [rawOutput];
|
|
21143
|
+
return [];
|
|
21144
|
+
}
|
|
21145
|
+
function firstRecord(...values) {
|
|
21146
|
+
for (const value of values) {
|
|
21147
|
+
if (isRecord5(value))
|
|
21148
|
+
return value;
|
|
21149
|
+
}
|
|
21150
|
+
return void 0;
|
|
21151
|
+
}
|
|
21152
|
+
function taskOutputTextSettlements(rawOutput, content, ids) {
|
|
21153
|
+
const text = extractText(content) ?? extractText(rawOutput);
|
|
21154
|
+
if (!text)
|
|
21155
|
+
return [];
|
|
21156
|
+
const settled = [];
|
|
21157
|
+
const pattern = /---\s*Task\s+(\S+)\s+\[(completed|failed|interrupted|cancelled|canceled)\]\s*---/gi;
|
|
21158
|
+
for (const match of text.matchAll(pattern)) {
|
|
21159
|
+
const id = match[1]?.trim();
|
|
21160
|
+
const status = mapTaskStatus(match[2]);
|
|
21161
|
+
if (!id || !status || status === "running" || status === "pending")
|
|
21162
|
+
continue;
|
|
21163
|
+
if (!ids.includes(id))
|
|
21164
|
+
continue;
|
|
21165
|
+
settled.push({ id, status });
|
|
21166
|
+
}
|
|
21167
|
+
return settled;
|
|
21168
|
+
}
|
|
21169
|
+
function taskOutputStatus(rawOutput, content) {
|
|
21170
|
+
if (isRecord5(rawOutput) && typeof rawOutput.status === "string")
|
|
21171
|
+
return rawOutput.status;
|
|
21172
|
+
const text = extractText(content) ?? extractText(rawOutput);
|
|
21173
|
+
if (!text)
|
|
21174
|
+
return void 0;
|
|
21175
|
+
if (/<subagent_meta>|<subagent_result>/i.test(text))
|
|
21176
|
+
return "completed";
|
|
21177
|
+
if (/\bstatus["']?\s*[:=]\s*["']?completed/i.test(text))
|
|
21178
|
+
return "completed";
|
|
21179
|
+
if (/\bstatus["']?\s*[:=]\s*["']?failed/i.test(text))
|
|
21180
|
+
return "failed";
|
|
21181
|
+
if (/\bstatus["']?\s*[:=]\s*["']?(cancelled|canceled|interrupted)/i.test(text)) {
|
|
21182
|
+
return "interrupted";
|
|
21183
|
+
}
|
|
21184
|
+
if (/\bstill running\b|\bstatus["']?\s*[:=]\s*["']?(running|pending|in_progress)/i.test(text)) {
|
|
21185
|
+
return "running";
|
|
21186
|
+
}
|
|
21187
|
+
return void 0;
|
|
21188
|
+
}
|
|
21189
|
+
function mapTaskStatus(status) {
|
|
21190
|
+
if (!status)
|
|
21191
|
+
return void 0;
|
|
21192
|
+
switch (status.toLowerCase()) {
|
|
21193
|
+
case "completed":
|
|
21194
|
+
case "succeeded":
|
|
21195
|
+
case "success":
|
|
21196
|
+
return "completed";
|
|
21197
|
+
case "failed":
|
|
21198
|
+
case "error":
|
|
21199
|
+
case "errored":
|
|
21200
|
+
return "failed";
|
|
21201
|
+
case "cancelled":
|
|
21202
|
+
case "canceled":
|
|
21203
|
+
case "interrupted":
|
|
21204
|
+
return "interrupted";
|
|
21205
|
+
case "running":
|
|
21206
|
+
case "pending":
|
|
21207
|
+
case "in_progress":
|
|
21208
|
+
case "inprogress":
|
|
21209
|
+
return "running";
|
|
21210
|
+
default:
|
|
21211
|
+
return void 0;
|
|
21212
|
+
}
|
|
21213
|
+
}
|
|
21214
|
+
function extractText(value, depth = 0) {
|
|
21215
|
+
if (depth > 6)
|
|
21216
|
+
return void 0;
|
|
21217
|
+
if (typeof value === "string") {
|
|
21218
|
+
const trimmed = value.trim();
|
|
21219
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
21220
|
+
}
|
|
21221
|
+
if (Array.isArray(value)) {
|
|
21222
|
+
const parts = value.flatMap((entry) => {
|
|
21223
|
+
const text = extractText(entry, depth + 1);
|
|
21224
|
+
return text ? [text] : [];
|
|
21225
|
+
});
|
|
21226
|
+
const joined = parts.join("\n").trim();
|
|
21227
|
+
return joined.length > 0 ? joined : void 0;
|
|
21228
|
+
}
|
|
21229
|
+
if (!isRecord5(value))
|
|
21230
|
+
return void 0;
|
|
21231
|
+
if (typeof value.text === "string" && value.text.trim().length > 0)
|
|
21232
|
+
return value.text.trim();
|
|
21233
|
+
if (typeof value.output === "string" && value.output.trim().length > 0) {
|
|
21234
|
+
return value.output.trim();
|
|
21235
|
+
}
|
|
21236
|
+
if (value.content !== void 0)
|
|
21237
|
+
return extractText(value.content, depth + 1);
|
|
21238
|
+
return void 0;
|
|
21239
|
+
}
|
|
21240
|
+
|
|
20933
21241
|
// dist/grok-history.js
|
|
20934
21242
|
function stableId(kind, turn, index) {
|
|
20935
21243
|
return hostItemIdSchema.parse(`grok-history-${kind}-${turn}-${index}`);
|
|
@@ -20992,6 +21300,90 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
20992
21300
|
let reasoning = null;
|
|
20993
21301
|
const tools = /* @__PURE__ */ new Map();
|
|
20994
21302
|
const mediaRoots = grokMediaResolveRoots(cwd, sessionDirectory);
|
|
21303
|
+
const subagents = /* @__PURE__ */ new Map();
|
|
21304
|
+
const subagentAliases = /* @__PURE__ */ new Map();
|
|
21305
|
+
const rememberSubagentAlias = (callId, nativeId) => {
|
|
21306
|
+
subagentAliases.set(callId, callId);
|
|
21307
|
+
if (nativeId)
|
|
21308
|
+
subagentAliases.set(nativeId, callId);
|
|
21309
|
+
};
|
|
21310
|
+
const completeHistorySubagent = (callId, status, content, rawOutput, rawInput) => {
|
|
21311
|
+
const current = subagents.get(callId);
|
|
21312
|
+
const currentAgent = current?.subagents[0];
|
|
21313
|
+
if (!current || !currentAgent)
|
|
21314
|
+
return;
|
|
21315
|
+
const nativeSubagentId = grokNativeSubagentId(rawInput, rawOutput, content) ?? currentAgent.nativeSubagentId;
|
|
21316
|
+
rememberSubagentAlias(callId, nativeSubagentId);
|
|
21317
|
+
const summary = grokSubagentResultSummary(content, rawOutput);
|
|
21318
|
+
const failed = status === "failed";
|
|
21319
|
+
const keepRunning = !failed && (currentAgent.background === true || current.operation === "send");
|
|
21320
|
+
const item = {
|
|
21321
|
+
...current,
|
|
21322
|
+
subagents: [
|
|
21323
|
+
{
|
|
21324
|
+
...currentAgent,
|
|
21325
|
+
status: failed ? "failed" : keepRunning ? "running" : "completed",
|
|
21326
|
+
...nativeSubagentId ? { nativeSubagentId, subagentId: nativeSubagentId } : {},
|
|
21327
|
+
...summary ? { resultSummary: summary } : {}
|
|
21328
|
+
}
|
|
21329
|
+
]
|
|
21330
|
+
};
|
|
21331
|
+
if (keepRunning) {
|
|
21332
|
+
subagents.set(callId, item);
|
|
21333
|
+
return;
|
|
21334
|
+
}
|
|
21335
|
+
subagents.delete(callId);
|
|
21336
|
+
items.push({
|
|
21337
|
+
item,
|
|
21338
|
+
outcome: failed ? {
|
|
21339
|
+
status: "failed",
|
|
21340
|
+
error: {
|
|
21341
|
+
code: "nativeFailure",
|
|
21342
|
+
message: "Grok Subagent delegation failed",
|
|
21343
|
+
retryable: false
|
|
21344
|
+
}
|
|
21345
|
+
} : { status: "succeeded" }
|
|
21346
|
+
});
|
|
21347
|
+
};
|
|
21348
|
+
const settleWatchedSubagents = (name, rawInput, content, rawOutput) => {
|
|
21349
|
+
const summary = grokSubagentResultSummary(content, rawOutput);
|
|
21350
|
+
for (const settlement of grokSubagentWaitSettlements({
|
|
21351
|
+
...name ? { name, title: name } : {},
|
|
21352
|
+
rawInput,
|
|
21353
|
+
content,
|
|
21354
|
+
rawOutput
|
|
21355
|
+
})) {
|
|
21356
|
+
const spawnId = subagentAliases.get(settlement.id);
|
|
21357
|
+
const item = spawnId ? subagents.get(spawnId) : void 0;
|
|
21358
|
+
if (!item?.subagents[0])
|
|
21359
|
+
continue;
|
|
21360
|
+
if (spawnId)
|
|
21361
|
+
subagents.delete(spawnId);
|
|
21362
|
+
const resultSummary = settlement.resultSummary ?? summary;
|
|
21363
|
+
items.push({
|
|
21364
|
+
item: {
|
|
21365
|
+
...item,
|
|
21366
|
+
subagents: [
|
|
21367
|
+
{
|
|
21368
|
+
...item.subagents[0],
|
|
21369
|
+
status: settlement.status,
|
|
21370
|
+
nativeSubagentId: item.subagents[0].nativeSubagentId ?? settlement.id,
|
|
21371
|
+
subagentId: item.subagents[0].nativeSubagentId ?? settlement.id,
|
|
21372
|
+
...resultSummary ? { resultSummary } : {}
|
|
21373
|
+
}
|
|
21374
|
+
]
|
|
21375
|
+
},
|
|
21376
|
+
outcome: settlement.status === "failed" ? {
|
|
21377
|
+
status: "failed",
|
|
21378
|
+
error: {
|
|
21379
|
+
code: "nativeFailure",
|
|
21380
|
+
message: "Grok Subagent delegation failed",
|
|
21381
|
+
retryable: false
|
|
21382
|
+
}
|
|
21383
|
+
} : settlement.status === "interrupted" ? { status: "cancelled", reason: "Cancelled by user" } : { status: "succeeded" }
|
|
21384
|
+
});
|
|
21385
|
+
}
|
|
21386
|
+
};
|
|
20995
21387
|
const completeAgent = () => {
|
|
20996
21388
|
if (!agent || agent.text.length === 0)
|
|
20997
21389
|
return;
|
|
@@ -21012,6 +21404,10 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
21012
21404
|
items.push({ item: tool, outcome: { status: "succeeded" } });
|
|
21013
21405
|
}
|
|
21014
21406
|
tools.clear();
|
|
21407
|
+
for (const item of subagents.values()) {
|
|
21408
|
+
items.push({ item, outcome: { status: "succeeded" } });
|
|
21409
|
+
}
|
|
21410
|
+
subagents.clear();
|
|
21015
21411
|
};
|
|
21016
21412
|
const applyToolProjection = (callId, content, rawOutput) => {
|
|
21017
21413
|
const tool = tools.get(callId);
|
|
@@ -21036,6 +21432,9 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
21036
21432
|
retryable: false
|
|
21037
21433
|
}
|
|
21038
21434
|
} : { status: "succeeded" };
|
|
21435
|
+
if (status === "completed") {
|
|
21436
|
+
settleWatchedSubagents(tool.type === "toolExecution" ? tool.toolName : tool.command, tool.type === "toolExecution" ? tool.arguments : void 0, content, rawOutput);
|
|
21437
|
+
}
|
|
21039
21438
|
items.push({ item: tool, outcome });
|
|
21040
21439
|
if (status !== "completed")
|
|
21041
21440
|
return;
|
|
@@ -21103,6 +21502,8 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
21103
21502
|
agent = null;
|
|
21104
21503
|
reasoning = null;
|
|
21105
21504
|
tools.clear();
|
|
21505
|
+
subagents.clear();
|
|
21506
|
+
subagentAliases.clear();
|
|
21106
21507
|
continue;
|
|
21107
21508
|
}
|
|
21108
21509
|
if (event.type === "user.text") {
|
|
@@ -21177,23 +21578,99 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
21177
21578
|
} else if (event.type === "tool.call") {
|
|
21178
21579
|
completeReasoning();
|
|
21179
21580
|
completeAgent();
|
|
21180
|
-
|
|
21181
|
-
|
|
21182
|
-
|
|
21183
|
-
|
|
21184
|
-
|
|
21185
|
-
|
|
21186
|
-
|
|
21187
|
-
|
|
21188
|
-
|
|
21189
|
-
|
|
21190
|
-
|
|
21581
|
+
const operation = grokSubagentOperation(event.name, event.title, event.rawInput);
|
|
21582
|
+
if (operation) {
|
|
21583
|
+
const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content);
|
|
21584
|
+
rememberSubagentAlias(event.callId, nativeSubagentId);
|
|
21585
|
+
const prompt = grokSubagentPrompt(event.rawInput);
|
|
21586
|
+
const role = grokSubagentRole(event.rawInput);
|
|
21587
|
+
const model = grokSubagentModel(event.rawInput);
|
|
21588
|
+
subagents.set(event.callId, {
|
|
21589
|
+
type: "subagentDelegation",
|
|
21590
|
+
itemId: stableId("subagent", turnIndex, ++messageIndex),
|
|
21591
|
+
operation,
|
|
21592
|
+
...prompt ? { prompt } : {},
|
|
21593
|
+
subagents: [
|
|
21594
|
+
{
|
|
21595
|
+
subagentId: nativeSubagentId ?? event.callId,
|
|
21596
|
+
...nativeSubagentId ? { nativeSubagentId } : {},
|
|
21597
|
+
description: grokSubagentDescription(event.rawInput, event.title),
|
|
21598
|
+
...role ? { role } : {},
|
|
21599
|
+
...model ? { model } : {},
|
|
21600
|
+
background: grokSubagentBackground(event.rawInput),
|
|
21601
|
+
status: "running"
|
|
21602
|
+
}
|
|
21603
|
+
]
|
|
21604
|
+
});
|
|
21605
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
21606
|
+
completeHistorySubagent(event.callId, event.status, event.content, event.rawOutput, event.rawInput);
|
|
21607
|
+
}
|
|
21608
|
+
} else {
|
|
21609
|
+
tools.set(event.callId, startGrokToolItem({
|
|
21610
|
+
itemId: stableId("tool", turnIndex, ++messageIndex),
|
|
21611
|
+
name: event.name,
|
|
21612
|
+
title: event.title,
|
|
21613
|
+
kind: event.kind,
|
|
21614
|
+
rawInput: event.rawInput,
|
|
21615
|
+
cwd
|
|
21616
|
+
}));
|
|
21617
|
+
applyToolProjection(event.callId, event.content, event.rawOutput);
|
|
21618
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
21619
|
+
completeTool(event.callId, event.status, event.content, event.rawOutput);
|
|
21620
|
+
}
|
|
21191
21621
|
}
|
|
21192
21622
|
} else if (event.type === "tool.update") {
|
|
21193
|
-
|
|
21194
|
-
|
|
21195
|
-
|
|
21623
|
+
if (subagents.has(event.callId)) {
|
|
21624
|
+
const current = subagents.get(event.callId);
|
|
21625
|
+
if (current?.subagents[0]) {
|
|
21626
|
+
const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content) ?? current.subagents[0].nativeSubagentId;
|
|
21627
|
+
rememberSubagentAlias(event.callId, nativeSubagentId);
|
|
21628
|
+
subagents.set(event.callId, {
|
|
21629
|
+
...current,
|
|
21630
|
+
subagents: [
|
|
21631
|
+
{
|
|
21632
|
+
...current.subagents[0],
|
|
21633
|
+
description: grokSubagentDescription(event.rawInput, event.title, current.subagents[0].description),
|
|
21634
|
+
...nativeSubagentId ? { nativeSubagentId, subagentId: nativeSubagentId } : {}
|
|
21635
|
+
}
|
|
21636
|
+
]
|
|
21637
|
+
});
|
|
21638
|
+
}
|
|
21639
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
21640
|
+
completeHistorySubagent(event.callId, event.status, event.content, event.rawOutput, event.rawInput);
|
|
21641
|
+
}
|
|
21642
|
+
} else {
|
|
21643
|
+
applyToolProjection(event.callId, event.content, event.rawOutput);
|
|
21644
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
21645
|
+
completeTool(event.callId, event.status, event.content, event.rawOutput);
|
|
21646
|
+
}
|
|
21647
|
+
}
|
|
21648
|
+
} else if (event.type === "subagent.spawned") {
|
|
21649
|
+
for (const [callId, current] of subagents) {
|
|
21650
|
+
const agent2 = current.subagents[0];
|
|
21651
|
+
if (!agent2)
|
|
21652
|
+
continue;
|
|
21653
|
+
const matchesId = agent2.nativeSubagentId === event.nativeSubagentId;
|
|
21654
|
+
const matchesDescription = !agent2.nativeSubagentId && event.description !== void 0 && agent2.description === event.description;
|
|
21655
|
+
if (!matchesId && !matchesDescription)
|
|
21656
|
+
continue;
|
|
21657
|
+
rememberSubagentAlias(callId, event.nativeSubagentId);
|
|
21658
|
+
subagents.set(callId, {
|
|
21659
|
+
...current,
|
|
21660
|
+
subagents: [
|
|
21661
|
+
{
|
|
21662
|
+
...agent2,
|
|
21663
|
+
nativeSubagentId: event.nativeSubagentId,
|
|
21664
|
+
subagentId: event.nativeSubagentId,
|
|
21665
|
+
...event.role ? { role: event.role } : {},
|
|
21666
|
+
...event.model ? { model: event.model } : {}
|
|
21667
|
+
}
|
|
21668
|
+
]
|
|
21669
|
+
});
|
|
21670
|
+
break;
|
|
21196
21671
|
}
|
|
21672
|
+
} else if (event.type === "subagent.finished") {
|
|
21673
|
+
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 });
|
|
21197
21674
|
}
|
|
21198
21675
|
}
|
|
21199
21676
|
completeTurn({ status: "unknown", reason: "Grok Native history has no terminal signal" });
|
|
@@ -21218,11 +21695,11 @@ var GROK_SESSION_DELETE_METHOD = "_x.ai/session/delete";
|
|
|
21218
21695
|
function error51(code, message, retryable = false) {
|
|
21219
21696
|
return { code, message, retryable };
|
|
21220
21697
|
}
|
|
21221
|
-
function
|
|
21698
|
+
function isRecord6(value) {
|
|
21222
21699
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21223
21700
|
}
|
|
21224
21701
|
function isGrokMethodNotFound(error53) {
|
|
21225
|
-
if (
|
|
21702
|
+
if (isRecord6(error53) && error53.code === -32601)
|
|
21226
21703
|
return true;
|
|
21227
21704
|
const message = error53 instanceof Error ? error53.message : String(error53);
|
|
21228
21705
|
return /method not found/iu.test(message);
|
|
@@ -21240,10 +21717,10 @@ function buildGrokForkParams(input) {
|
|
|
21240
21717
|
};
|
|
21241
21718
|
}
|
|
21242
21719
|
function parseGrokForkResponse(value) {
|
|
21243
|
-
if (!
|
|
21720
|
+
if (!isRecord6(value) || value.error !== void 0)
|
|
21244
21721
|
return null;
|
|
21245
|
-
const payload = typeof value.newSessionId !== "string" &&
|
|
21246
|
-
if (!
|
|
21722
|
+
const payload = typeof value.newSessionId !== "string" && isRecord6(value.result) ? value.result : value;
|
|
21723
|
+
if (!isRecord6(payload) || payload.error !== void 0)
|
|
21247
21724
|
return null;
|
|
21248
21725
|
if (typeof payload.newSessionId !== "string" || payload.newSessionId.length === 0)
|
|
21249
21726
|
return null;
|
|
@@ -21406,7 +21883,7 @@ var GROK_SESSION_UPDATE_EXTENSION_METHODS = [
|
|
|
21406
21883
|
"_x.ai/session/update",
|
|
21407
21884
|
"x.ai/session_notification"
|
|
21408
21885
|
];
|
|
21409
|
-
function
|
|
21886
|
+
function isRecord7(value) {
|
|
21410
21887
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21411
21888
|
}
|
|
21412
21889
|
function optionalNonNegativeInt(value) {
|
|
@@ -21427,7 +21904,7 @@ function isGrokExtensionSessionUpdateMethod(method) {
|
|
|
21427
21904
|
return GROK_SESSION_UPDATE_EXTENSION_METHODS.includes(method);
|
|
21428
21905
|
}
|
|
21429
21906
|
function grokCompactionEventFromUpdate(update) {
|
|
21430
|
-
if (!
|
|
21907
|
+
if (!isRecord7(update) || typeof update.sessionUpdate !== "string")
|
|
21431
21908
|
return null;
|
|
21432
21909
|
const tokensUsed = optionalNonNegativeInt(firstPresent(update, ["tokensUsed", "tokens_used"]));
|
|
21433
21910
|
const contextWindowTokens = optionalNonNegativeInt(firstPresent(update, ["contextWindowTokens", "contextWindow", "context_window"]));
|
|
@@ -21466,7 +21943,7 @@ function grokCompactionEventFromUpdate(update) {
|
|
|
21466
21943
|
// dist/grok-manual-compaction.js
|
|
21467
21944
|
var GROK_COMPACT_CONVERSATION_METHOD = "x.ai/compact_conversation";
|
|
21468
21945
|
var GROK_COMPACT_CONVERSATION_FALLBACK_METHOD = "_x.ai/compact_conversation";
|
|
21469
|
-
function
|
|
21946
|
+
function isRecord8(value) {
|
|
21470
21947
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21471
21948
|
}
|
|
21472
21949
|
function optionalNonNegativeInt2(value) {
|
|
@@ -21478,7 +21955,7 @@ function optionalErrorMessage2(value) {
|
|
|
21478
21955
|
function parseGrokCompactResult(value, cancelled = false) {
|
|
21479
21956
|
if (cancelled)
|
|
21480
21957
|
return { outcome: "cancelled" };
|
|
21481
|
-
if (!
|
|
21958
|
+
if (!isRecord8(value))
|
|
21482
21959
|
return { outcome: "succeeded" };
|
|
21483
21960
|
const tokensBefore = optionalNonNegativeInt2(value.tokensBefore ?? value.tokens_before);
|
|
21484
21961
|
const tokensAfter = optionalNonNegativeInt2(value.tokensAfter ?? value.tokens_after);
|
|
@@ -21516,7 +21993,7 @@ var GROK_REWIND_EXECUTE_METHOD = "_x.ai/rewind/execute";
|
|
|
21516
21993
|
function error52(code, message, retryable = false) {
|
|
21517
21994
|
return { code, message, retryable };
|
|
21518
21995
|
}
|
|
21519
|
-
function
|
|
21996
|
+
function isRecord9(value) {
|
|
21520
21997
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21521
21998
|
}
|
|
21522
21999
|
function buildGrokRewindParams(input) {
|
|
@@ -21528,10 +22005,10 @@ function buildGrokRewindParams(input) {
|
|
|
21528
22005
|
};
|
|
21529
22006
|
}
|
|
21530
22007
|
function parseGrokRewindResponse(value) {
|
|
21531
|
-
if (!
|
|
22008
|
+
if (!isRecord9(value))
|
|
21532
22009
|
return null;
|
|
21533
|
-
const payload = typeof value.success !== "boolean" &&
|
|
21534
|
-
if (!
|
|
22010
|
+
const payload = typeof value.success !== "boolean" && isRecord9(value.result) ? value.result : value;
|
|
22011
|
+
if (!isRecord9(payload) || typeof payload.success !== "boolean")
|
|
21535
22012
|
return null;
|
|
21536
22013
|
return rewindPayload(payload);
|
|
21537
22014
|
}
|
|
@@ -21688,9 +22165,18 @@ var GrokTransportError = class extends Error {
|
|
|
21688
22165
|
this.name = "GrokTransportError";
|
|
21689
22166
|
}
|
|
21690
22167
|
};
|
|
21691
|
-
function
|
|
22168
|
+
function isRecord10(value) {
|
|
21692
22169
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21693
22170
|
}
|
|
22171
|
+
function acpToolName(update, metadata) {
|
|
22172
|
+
if (!isRecord10(update))
|
|
22173
|
+
return void 0;
|
|
22174
|
+
if (typeof update.name === "string" && update.name.length > 0)
|
|
22175
|
+
return update.name;
|
|
22176
|
+
const meta3 = isRecord10(update._meta) ? update._meta : metadata;
|
|
22177
|
+
const tool = meta3 && isRecord10(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
|
|
22178
|
+
return tool && typeof tool.name === "string" && tool.name.length > 0 ? tool.name : void 0;
|
|
22179
|
+
}
|
|
21694
22180
|
function errorText(error53) {
|
|
21695
22181
|
return error53 instanceof Error ? error53.message : String(error53);
|
|
21696
22182
|
}
|
|
@@ -21744,7 +22230,7 @@ function signalProcessTree(child, signal) {
|
|
|
21744
22230
|
try {
|
|
21745
22231
|
process.kill(-child.pid, signal);
|
|
21746
22232
|
} catch (error53) {
|
|
21747
|
-
if (!
|
|
22233
|
+
if (!isRecord10(error53) || error53.code !== "ESRCH")
|
|
21748
22234
|
throw error53;
|
|
21749
22235
|
}
|
|
21750
22236
|
}
|
|
@@ -21769,6 +22255,9 @@ function transportEvent(update, metadata) {
|
|
|
21769
22255
|
const compaction = grokCompactionEventFromUpdate(extension);
|
|
21770
22256
|
if (compaction)
|
|
21771
22257
|
return compaction;
|
|
22258
|
+
const subagent = grokSubagentEventFromUpdate(extension);
|
|
22259
|
+
if (subagent)
|
|
22260
|
+
return subagent;
|
|
21772
22261
|
switch (update.sessionUpdate) {
|
|
21773
22262
|
case "user_message_chunk":
|
|
21774
22263
|
case "agent_message_chunk":
|
|
@@ -21780,30 +22269,34 @@ function transportEvent(update, metadata) {
|
|
|
21780
22269
|
text: update.content.text,
|
|
21781
22270
|
...update.messageId ? { messageId: update.messageId } : {}
|
|
21782
22271
|
};
|
|
21783
|
-
case "tool_call":
|
|
22272
|
+
case "tool_call": {
|
|
22273
|
+
const name = acpToolName(update, metadata);
|
|
21784
22274
|
return {
|
|
21785
22275
|
type: "tool.call",
|
|
21786
22276
|
callId: update.toolCallId,
|
|
21787
22277
|
title: update.title,
|
|
21788
|
-
...
|
|
22278
|
+
...name ? { name } : {},
|
|
21789
22279
|
...update.kind ? { kind: update.kind } : {},
|
|
21790
22280
|
...update.status ? { status: update.status } : {},
|
|
21791
22281
|
...update.rawInput !== void 0 ? { rawInput: update.rawInput } : {},
|
|
21792
22282
|
...update.rawOutput !== void 0 ? { rawOutput: update.rawOutput } : {},
|
|
21793
22283
|
...update.content ? { content: update.content } : {}
|
|
21794
22284
|
};
|
|
21795
|
-
|
|
22285
|
+
}
|
|
22286
|
+
case "tool_call_update": {
|
|
22287
|
+
const name = acpToolName(update, metadata);
|
|
21796
22288
|
return {
|
|
21797
22289
|
type: "tool.update",
|
|
21798
22290
|
callId: update.toolCallId,
|
|
21799
22291
|
...update.title !== void 0 ? { title: update.title } : {},
|
|
21800
|
-
...
|
|
22292
|
+
...name ? { name } : {},
|
|
21801
22293
|
...update.kind !== void 0 ? { kind: update.kind } : {},
|
|
21802
22294
|
...update.status !== void 0 ? { status: update.status } : {},
|
|
21803
22295
|
...update.rawInput !== void 0 ? { rawInput: update.rawInput } : {},
|
|
21804
22296
|
...update.rawOutput !== void 0 ? { rawOutput: update.rawOutput } : {},
|
|
21805
22297
|
...update.content !== void 0 ? { content: update.content } : {}
|
|
21806
22298
|
};
|
|
22299
|
+
}
|
|
21807
22300
|
case "usage_update":
|
|
21808
22301
|
return { type: "usage", update, ...metadata ? { metadata } : {} };
|
|
21809
22302
|
default:
|
|
@@ -21832,7 +22325,7 @@ async function readNativeSignals(options, sessionId) {
|
|
|
21832
22325
|
}
|
|
21833
22326
|
}
|
|
21834
22327
|
function isMissingFile(error53) {
|
|
21835
|
-
return
|
|
22328
|
+
return isRecord10(error53) && error53.code === "ENOENT";
|
|
21836
22329
|
}
|
|
21837
22330
|
async function locateGrokNativeSession(options, sessionId) {
|
|
21838
22331
|
if (sessionId.length === 0)
|
|
@@ -21855,7 +22348,7 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
21855
22348
|
try {
|
|
21856
22349
|
summaryRaw = await readFile(path8.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
|
|
21857
22350
|
} catch (error53) {
|
|
21858
|
-
if (isMissingFile(error53) ||
|
|
22351
|
+
if (isMissingFile(error53) || isRecord10(error53) && error53.code === "ENOTDIR")
|
|
21859
22352
|
continue;
|
|
21860
22353
|
throw new GrokTransportError("unavailable", "Grok Native Session metadata could not be read", {
|
|
21861
22354
|
cause: error53
|
|
@@ -21867,10 +22360,10 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
21867
22360
|
} catch {
|
|
21868
22361
|
continue;
|
|
21869
22362
|
}
|
|
21870
|
-
if (!
|
|
22363
|
+
if (!isRecord10(parsed))
|
|
21871
22364
|
continue;
|
|
21872
22365
|
const info = parsed.info;
|
|
21873
|
-
const cwd =
|
|
22366
|
+
const cwd = isRecord10(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path8.resolve(info.cwd) : path8.resolve(decodeURIComponent(entry.name));
|
|
21874
22367
|
const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path8.resolve(parsed.source_workspace_dir) : void 0;
|
|
21875
22368
|
matches.push({
|
|
21876
22369
|
cwd,
|
|
@@ -21903,12 +22396,12 @@ function parseNativeHistory(contents, sessionId) {
|
|
|
21903
22396
|
} catch {
|
|
21904
22397
|
throw new GrokTransportError("protocolError", "Grok Native history contains invalid JSON");
|
|
21905
22398
|
}
|
|
21906
|
-
if (!
|
|
22399
|
+
if (!isRecord10(record2) || !isRecord10(record2.params))
|
|
21907
22400
|
continue;
|
|
21908
22401
|
const params = record2.params;
|
|
21909
|
-
if (params.sessionId !== sessionId || !
|
|
22402
|
+
if (params.sessionId !== sessionId || !isRecord10(params.update))
|
|
21910
22403
|
continue;
|
|
21911
|
-
const metadata =
|
|
22404
|
+
const metadata = isRecord10(params._meta) ? params._meta : void 0;
|
|
21912
22405
|
const event = transportEvent(params.update, metadata);
|
|
21913
22406
|
if (event)
|
|
21914
22407
|
events.push(metadata ? { ...event, metadata } : event);
|
|
@@ -21926,6 +22419,7 @@ var GrokAcpTransport = class {
|
|
|
21926
22419
|
#initialize = null;
|
|
21927
22420
|
#replay = null;
|
|
21928
22421
|
#sessionId = null;
|
|
22422
|
+
#startupModelId;
|
|
21929
22423
|
#stderrTail = "";
|
|
21930
22424
|
constructor(options) {
|
|
21931
22425
|
this.#options = {
|
|
@@ -21982,6 +22476,8 @@ var GrokAcpTransport = class {
|
|
|
21982
22476
|
if (this.#sessionId || this.#closed)
|
|
21983
22477
|
throw new Error("Grok ACP Transport cannot be opened twice");
|
|
21984
22478
|
try {
|
|
22479
|
+
if (input.kind === "create")
|
|
22480
|
+
this.#startupModelId = input.modelId;
|
|
21985
22481
|
const initialize = await this.#ensureInitialized();
|
|
21986
22482
|
const connection = this.#connection;
|
|
21987
22483
|
if (!connection)
|
|
@@ -22107,7 +22603,7 @@ var GrokAcpTransport = class {
|
|
|
22107
22603
|
...this.#options.command ? { command: this.#options.command } : {},
|
|
22108
22604
|
environment: this.#options.environment ?? process.env
|
|
22109
22605
|
});
|
|
22110
|
-
const invocation = grokInvocation(executable);
|
|
22606
|
+
const invocation = grokInvocation(executable, process.platform, this.#startupModelId);
|
|
22111
22607
|
const child = spawn(invocation.command, invocation.arguments, {
|
|
22112
22608
|
cwd: this.#options.cwd,
|
|
22113
22609
|
env: { ...process.env, ...this.#options.environment },
|
|
@@ -22210,7 +22706,7 @@ var GrokAcpTransport = class {
|
|
|
22210
22706
|
modelId,
|
|
22211
22707
|
...reasoningEffort ? { reasoningEffort } : {}
|
|
22212
22708
|
});
|
|
22213
|
-
if (!
|
|
22709
|
+
if (!isRecord10(response) || !isRecord10(response._meta) || !isRecord10(response._meta.model)) {
|
|
22214
22710
|
throw new GrokTransportError("protocolError", "Grok rejected Model configuration");
|
|
22215
22711
|
}
|
|
22216
22712
|
const selected = response._meta.model.Ok;
|
|
@@ -22253,7 +22749,7 @@ var GrokAcpTransport = class {
|
|
|
22253
22749
|
#handleUpdate(notification) {
|
|
22254
22750
|
if (this.#sessionId && notification.sessionId !== this.#sessionId)
|
|
22255
22751
|
return;
|
|
22256
|
-
const metadata =
|
|
22752
|
+
const metadata = isRecord10(notification._meta) ? notification._meta : void 0;
|
|
22257
22753
|
const event = transportEvent(notification.update, metadata);
|
|
22258
22754
|
if (!event)
|
|
22259
22755
|
return;
|
|
@@ -22268,7 +22764,7 @@ var GrokAcpTransport = class {
|
|
|
22268
22764
|
#handleExtensionNotification(method, params) {
|
|
22269
22765
|
if (!isGrokExtensionSessionUpdateMethod(method))
|
|
22270
22766
|
return;
|
|
22271
|
-
if (typeof params.sessionId !== "string" || !
|
|
22767
|
+
if (typeof params.sessionId !== "string" || !isRecord10(params.update))
|
|
22272
22768
|
return;
|
|
22273
22769
|
this.#handleUpdate(params);
|
|
22274
22770
|
}
|
|
@@ -22285,8 +22781,200 @@ var GrokAcpTransport = class {
|
|
|
22285
22781
|
}
|
|
22286
22782
|
};
|
|
22287
22783
|
|
|
22784
|
+
// dist/grok-subagent-lifecycle.js
|
|
22785
|
+
function subagentFailure() {
|
|
22786
|
+
return {
|
|
22787
|
+
code: "nativeFailure",
|
|
22788
|
+
message: "Grok Subagent delegation failed",
|
|
22789
|
+
retryable: false
|
|
22790
|
+
};
|
|
22791
|
+
}
|
|
22792
|
+
var GrokSubagentLifecycle = class {
|
|
22793
|
+
#emit;
|
|
22794
|
+
#newItemId;
|
|
22795
|
+
#delegations = /* @__PURE__ */ new Map();
|
|
22796
|
+
#callIdByNativeId = /* @__PURE__ */ new Map();
|
|
22797
|
+
constructor(options) {
|
|
22798
|
+
this.#emit = options.emit;
|
|
22799
|
+
this.#newItemId = options.newItemId;
|
|
22800
|
+
}
|
|
22801
|
+
get size() {
|
|
22802
|
+
return this.#delegations.size;
|
|
22803
|
+
}
|
|
22804
|
+
has(callId) {
|
|
22805
|
+
return this.#delegations.has(callId);
|
|
22806
|
+
}
|
|
22807
|
+
nativeSubagentId(callId) {
|
|
22808
|
+
return this.#delegations.get(callId)?.item.subagents[0]?.nativeSubagentId;
|
|
22809
|
+
}
|
|
22810
|
+
start(turnId, input) {
|
|
22811
|
+
if (this.#delegations.has(input.callId)) {
|
|
22812
|
+
throw new Error("Grok Subagent delegation started more than once");
|
|
22813
|
+
}
|
|
22814
|
+
this.#callIdByNativeId.set(input.callId, input.callId);
|
|
22815
|
+
if (input.nativeSubagentId)
|
|
22816
|
+
this.#callIdByNativeId.set(input.nativeSubagentId, input.callId);
|
|
22817
|
+
const subagent = {
|
|
22818
|
+
subagentId: input.nativeSubagentId ?? input.callId,
|
|
22819
|
+
...input.nativeSubagentId ? { nativeSubagentId: input.nativeSubagentId } : {},
|
|
22820
|
+
description: input.description,
|
|
22821
|
+
...input.role ? { role: input.role } : {},
|
|
22822
|
+
...input.model ? { model: input.model } : {},
|
|
22823
|
+
...input.reasoningEffort ? { reasoningEffort: input.reasoningEffort } : {},
|
|
22824
|
+
background: input.background,
|
|
22825
|
+
status: "running"
|
|
22826
|
+
};
|
|
22827
|
+
const item = {
|
|
22828
|
+
type: "subagentDelegation",
|
|
22829
|
+
itemId: this.#newItemId(),
|
|
22830
|
+
operation: input.operation,
|
|
22831
|
+
...input.prompt ? { prompt: input.prompt } : {},
|
|
22832
|
+
subagents: [subagent]
|
|
22833
|
+
};
|
|
22834
|
+
this.#delegations.set(input.callId, { callId: input.callId, item });
|
|
22835
|
+
this.#emit({ type: "item.started", turnId, item });
|
|
22836
|
+
this.#emitState(subagent);
|
|
22837
|
+
return subagent;
|
|
22838
|
+
}
|
|
22839
|
+
bindNativeId(turnId, input) {
|
|
22840
|
+
for (const [callId, active] of this.#delegations) {
|
|
22841
|
+
const current = active.item.subagents[0];
|
|
22842
|
+
if (!current)
|
|
22843
|
+
continue;
|
|
22844
|
+
if (current.nativeSubagentId === input.nativeSubagentId) {
|
|
22845
|
+
return this.update(turnId, callId, input);
|
|
22846
|
+
}
|
|
22847
|
+
}
|
|
22848
|
+
for (const [callId, active] of this.#delegations) {
|
|
22849
|
+
const current = active.item.subagents[0];
|
|
22850
|
+
if (!current || current.nativeSubagentId)
|
|
22851
|
+
continue;
|
|
22852
|
+
if (input.description && current.description === input.description) {
|
|
22853
|
+
return this.update(turnId, callId, input);
|
|
22854
|
+
}
|
|
22855
|
+
}
|
|
22856
|
+
return void 0;
|
|
22857
|
+
}
|
|
22858
|
+
update(turnId, callId, patch) {
|
|
22859
|
+
const active = this.#delegations.get(callId);
|
|
22860
|
+
if (!active)
|
|
22861
|
+
return void 0;
|
|
22862
|
+
const current = active.item.subagents[0];
|
|
22863
|
+
if (!current)
|
|
22864
|
+
throw new Error("Grok Subagent delegation has no Agent state");
|
|
22865
|
+
if (patch.nativeSubagentId)
|
|
22866
|
+
this.#callIdByNativeId.set(patch.nativeSubagentId, callId);
|
|
22867
|
+
const nativeSubagentId = patch.nativeSubagentId ?? current.nativeSubagentId;
|
|
22868
|
+
const subagent = {
|
|
22869
|
+
...current,
|
|
22870
|
+
...nativeSubagentId ? { nativeSubagentId, subagentId: nativeSubagentId } : {},
|
|
22871
|
+
...patch.description ? { description: patch.description } : {},
|
|
22872
|
+
...patch.role ? { role: patch.role } : {},
|
|
22873
|
+
...patch.model ? { model: patch.model } : {},
|
|
22874
|
+
...patch.reasoningEffort ? { reasoningEffort: patch.reasoningEffort } : {},
|
|
22875
|
+
...patch.resultSummary ? { resultSummary: patch.resultSummary } : {},
|
|
22876
|
+
...patch.status ? { status: patch.status } : {}
|
|
22877
|
+
};
|
|
22878
|
+
active.item = { ...active.item, subagents: [subagent] };
|
|
22879
|
+
this.#emit({
|
|
22880
|
+
type: "item.updated",
|
|
22881
|
+
turnId,
|
|
22882
|
+
itemId: active.item.itemId,
|
|
22883
|
+
update: { type: "subagents.replace", subagents: active.item.subagents }
|
|
22884
|
+
});
|
|
22885
|
+
this.#emitState(subagent);
|
|
22886
|
+
return subagent;
|
|
22887
|
+
}
|
|
22888
|
+
completeSpawn(turnId, callId, input) {
|
|
22889
|
+
const active = this.#delegations.get(callId);
|
|
22890
|
+
const background = input.background ?? active?.item.subagents[0]?.background ?? true;
|
|
22891
|
+
const keepRunning = !input.failed && !input.cancellationRequested && (background || active?.item.operation === "send");
|
|
22892
|
+
if (keepRunning) {
|
|
22893
|
+
return this.update(turnId, callId, {
|
|
22894
|
+
status: "running",
|
|
22895
|
+
...input.nativeSubagentId ? { nativeSubagentId: input.nativeSubagentId } : {},
|
|
22896
|
+
...input.resultSummary ? { resultSummary: input.resultSummary } : {}
|
|
22897
|
+
});
|
|
22898
|
+
}
|
|
22899
|
+
return this.complete(turnId, callId, { ...input, keepRunning: false });
|
|
22900
|
+
}
|
|
22901
|
+
completeByNativeId(turnId, nativeSubagentId, input) {
|
|
22902
|
+
const callId = this.#callIdByNativeId.get(nativeSubagentId) ?? this.#callIdForNative(nativeSubagentId);
|
|
22903
|
+
if (callId && this.#delegations.has(callId)) {
|
|
22904
|
+
return this.complete(turnId, callId, { ...input, nativeSubagentId });
|
|
22905
|
+
}
|
|
22906
|
+
const status = input.status ?? (input.cancellationRequested ? "interrupted" : input.failed ? "failed" : "completed");
|
|
22907
|
+
this.#emit({
|
|
22908
|
+
type: "subagent.state.changed",
|
|
22909
|
+
nativeSubagentId,
|
|
22910
|
+
status,
|
|
22911
|
+
...input.resultSummary ? { resultSummary: input.resultSummary } : {}
|
|
22912
|
+
});
|
|
22913
|
+
return void 0;
|
|
22914
|
+
}
|
|
22915
|
+
complete(turnId, callId, input) {
|
|
22916
|
+
const active = this.#delegations.get(callId);
|
|
22917
|
+
if (!active)
|
|
22918
|
+
return void 0;
|
|
22919
|
+
this.#delegations.delete(callId);
|
|
22920
|
+
const current = active.item.subagents[0];
|
|
22921
|
+
if (!current)
|
|
22922
|
+
throw new Error("Grok Subagent delegation has no Agent state");
|
|
22923
|
+
const status = input.status ?? (input.cancellationRequested ? "interrupted" : input.failed ? "failed" : input.keepRunning ? "running" : "completed");
|
|
22924
|
+
const nativeSubagentId = input.nativeSubagentId ?? current.nativeSubagentId;
|
|
22925
|
+
if (nativeSubagentId)
|
|
22926
|
+
this.#callIdByNativeId.set(nativeSubagentId, callId);
|
|
22927
|
+
const subagent = {
|
|
22928
|
+
...current,
|
|
22929
|
+
status,
|
|
22930
|
+
...nativeSubagentId ? { nativeSubagentId, subagentId: nativeSubagentId } : {},
|
|
22931
|
+
...input.resultSummary ? { resultSummary: input.resultSummary } : {}
|
|
22932
|
+
};
|
|
22933
|
+
const item = { ...active.item, subagents: [subagent] };
|
|
22934
|
+
this.#emit({
|
|
22935
|
+
type: "item.updated",
|
|
22936
|
+
turnId,
|
|
22937
|
+
itemId: item.itemId,
|
|
22938
|
+
update: { type: "subagents.replace", subagents: item.subagents }
|
|
22939
|
+
});
|
|
22940
|
+
const outcome = input.cancellationRequested ? { status: "cancelled", reason: "Cancelled by user" } : input.failed ? { status: "failed", error: subagentFailure() } : { status: "succeeded" };
|
|
22941
|
+
this.#emit({ type: "item.completed", turnId, snapshot: { item, outcome } });
|
|
22942
|
+
this.#emitState(subagent);
|
|
22943
|
+
return subagent;
|
|
22944
|
+
}
|
|
22945
|
+
finalize(turnId, outcome) {
|
|
22946
|
+
for (const [callId, active] of this.#delegations) {
|
|
22947
|
+
this.#delegations.delete(callId);
|
|
22948
|
+
const current = active.item.subagents[0];
|
|
22949
|
+
if (!current)
|
|
22950
|
+
continue;
|
|
22951
|
+
const status = outcome.status === "succeeded" ? current.status : outcome.status === "cancelled" ? "interrupted" : "failed";
|
|
22952
|
+
const item = { ...active.item, subagents: [{ ...current, status }] };
|
|
22953
|
+
this.#emit({ type: "item.completed", turnId, snapshot: { item, outcome } });
|
|
22954
|
+
this.#emitState({ ...current, status });
|
|
22955
|
+
}
|
|
22956
|
+
}
|
|
22957
|
+
#callIdForNative(nativeSubagentId) {
|
|
22958
|
+
for (const [callId, active] of this.#delegations) {
|
|
22959
|
+
if (active.item.subagents[0]?.nativeSubagentId === nativeSubagentId)
|
|
22960
|
+
return callId;
|
|
22961
|
+
}
|
|
22962
|
+
return void 0;
|
|
22963
|
+
}
|
|
22964
|
+
#emitState(subagent) {
|
|
22965
|
+
if (!subagent.nativeSubagentId)
|
|
22966
|
+
return;
|
|
22967
|
+
this.#emit({
|
|
22968
|
+
type: "subagent.state.changed",
|
|
22969
|
+
nativeSubagentId: subagent.nativeSubagentId,
|
|
22970
|
+
status: subagent.status,
|
|
22971
|
+
...subagent.resultSummary ? { resultSummary: subagent.resultSummary } : {}
|
|
22972
|
+
});
|
|
22973
|
+
}
|
|
22974
|
+
};
|
|
22975
|
+
|
|
22288
22976
|
// dist/grok-models.js
|
|
22289
|
-
function
|
|
22977
|
+
function isRecord11(value) {
|
|
22290
22978
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22291
22979
|
}
|
|
22292
22980
|
function nonBlank(value) {
|
|
@@ -22298,7 +22986,7 @@ function thinkingOptions(value) {
|
|
|
22298
22986
|
const seen = /* @__PURE__ */ new Set();
|
|
22299
22987
|
const options = [];
|
|
22300
22988
|
for (const candidate of value) {
|
|
22301
|
-
if (!
|
|
22989
|
+
if (!isRecord11(candidate) || !nonBlank(candidate.label))
|
|
22302
22990
|
continue;
|
|
22303
22991
|
const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
|
|
22304
22992
|
if (!id.success || seen.has(id.data))
|
|
@@ -22309,7 +22997,7 @@ function thinkingOptions(value) {
|
|
|
22309
22997
|
return options;
|
|
22310
22998
|
}
|
|
22311
22999
|
function parseGrokModelState(value) {
|
|
22312
|
-
if (!
|
|
23000
|
+
if (!isRecord11(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
|
|
22313
23001
|
return null;
|
|
22314
23002
|
}
|
|
22315
23003
|
const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
|
|
@@ -22320,12 +23008,12 @@ function parseGrokModelState(value) {
|
|
|
22320
23008
|
const models = [];
|
|
22321
23009
|
let currentThinkingOptionId;
|
|
22322
23010
|
for (const candidate of value.availableModels) {
|
|
22323
|
-
if (!
|
|
23011
|
+
if (!isRecord11(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
|
|
22324
23012
|
continue;
|
|
22325
23013
|
const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
|
|
22326
23014
|
if (!ref.success)
|
|
22327
23015
|
continue;
|
|
22328
|
-
const metadata =
|
|
23016
|
+
const metadata = isRecord11(candidate._meta) ? candidate._meta : {};
|
|
22329
23017
|
const options2 = thinkingOptions(metadata.reasoningEfforts);
|
|
22330
23018
|
if (typeof metadata.totalContextTokens === "number" && Number.isSafeInteger(metadata.totalContextTokens) && metadata.totalContextTokens > 0) {
|
|
22331
23019
|
contextWindowTokensByModel.set(ref.data.id, metadata.totalContextTokens);
|
|
@@ -22360,10 +23048,10 @@ function parseGrokModelState(value) {
|
|
|
22360
23048
|
};
|
|
22361
23049
|
}
|
|
22362
23050
|
function modelStateFromInitialize(response) {
|
|
22363
|
-
return parseGrokModelState(
|
|
23051
|
+
return parseGrokModelState(isRecord11(response._meta) ? response._meta.modelState : void 0);
|
|
22364
23052
|
}
|
|
22365
23053
|
function modelStateFromSessionResponse(response) {
|
|
22366
|
-
return parseGrokModelState(
|
|
23054
|
+
return parseGrokModelState(isRecord11(response) ? response.models : void 0);
|
|
22367
23055
|
}
|
|
22368
23056
|
function stateForGrokModel(modelState, nativeState, model = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
|
|
22369
23057
|
const selectedModel = model;
|
|
@@ -22387,7 +23075,7 @@ import os4 from "node:os";
|
|
|
22387
23075
|
import path9 from "node:path";
|
|
22388
23076
|
var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
22389
23077
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
22390
|
-
function
|
|
23078
|
+
function isRecord12(value) {
|
|
22391
23079
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22392
23080
|
}
|
|
22393
23081
|
function finitePercent(value) {
|
|
@@ -22395,10 +23083,13 @@ function finitePercent(value) {
|
|
|
22395
23083
|
return void 0;
|
|
22396
23084
|
return Math.min(100, Math.max(0, value));
|
|
22397
23085
|
}
|
|
22398
|
-
function
|
|
22399
|
-
if (
|
|
23086
|
+
function nonNegativeCentValue(value) {
|
|
23087
|
+
if (!isRecord12(value))
|
|
22400
23088
|
return void 0;
|
|
22401
|
-
|
|
23089
|
+
const amount = value.val === void 0 ? 0 : value.val;
|
|
23090
|
+
if (typeof amount !== "number" || !Number.isFinite(amount) || amount < 0)
|
|
23091
|
+
return void 0;
|
|
23092
|
+
return amount;
|
|
22402
23093
|
}
|
|
22403
23094
|
function grokHome(environment) {
|
|
22404
23095
|
return environment.GROK_HOME ?? path9.join(environment.HOME ?? environment.USERPROFILE ?? os4.homedir(), ".grok");
|
|
@@ -22417,7 +23108,7 @@ function productUsageFrom(value) {
|
|
|
22417
23108
|
if (!Array.isArray(value))
|
|
22418
23109
|
return void 0;
|
|
22419
23110
|
const products = value.flatMap((entry) => {
|
|
22420
|
-
if (!
|
|
23111
|
+
if (!isRecord12(entry) || typeof entry.product !== "string")
|
|
22421
23112
|
return [];
|
|
22422
23113
|
const usagePercent = finitePercent(entry.usagePercent);
|
|
22423
23114
|
return usagePercent === void 0 ? [] : [{ product: entry.product, usagePercent }];
|
|
@@ -22425,31 +23116,41 @@ function productUsageFrom(value) {
|
|
|
22425
23116
|
return products.length > 0 ? products : void 0;
|
|
22426
23117
|
}
|
|
22427
23118
|
function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
22428
|
-
if (!
|
|
23119
|
+
if (!isRecord12(value) || !isRecord12(value.config))
|
|
22429
23120
|
return null;
|
|
22430
23121
|
const config2 = value.config;
|
|
22431
|
-
const period =
|
|
23122
|
+
const period = isRecord12(config2.currentPeriod) ? config2.currentPeriod : void 0;
|
|
23123
|
+
const periodType = periodTypeFrom(period?.type);
|
|
22432
23124
|
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);
|
|
22433
|
-
|
|
22434
|
-
|
|
22435
|
-
|
|
23125
|
+
let usedPercent = finitePercent(config2.creditUsagePercent);
|
|
23126
|
+
if (config2.creditUsagePercent === void 0) {
|
|
23127
|
+
const monthlyLimit = nonNegativeCentValue(config2.monthlyLimit);
|
|
23128
|
+
const used = nonNegativeCentValue(config2.used);
|
|
23129
|
+
if (config2.monthlyLimit !== void 0 && monthlyLimit === void 0 || config2.used !== void 0 && used === void 0)
|
|
23130
|
+
return null;
|
|
23131
|
+
if (monthlyLimit !== void 0 && monthlyLimit > 0) {
|
|
23132
|
+
usedPercent = Math.min(100, (used ?? 0) / monthlyLimit * 100);
|
|
23133
|
+
} else if (periodType !== "unknown" && resetsAt !== void 0 && Number.isFinite(Date.parse(resetsAt))) {
|
|
23134
|
+
usedPercent = 0;
|
|
23135
|
+
}
|
|
23136
|
+
}
|
|
22436
23137
|
if (usedPercent === void 0)
|
|
22437
23138
|
return null;
|
|
22438
23139
|
const productUsage = productUsageFrom(config2.productUsage);
|
|
22439
23140
|
return {
|
|
22440
23141
|
usedPercent,
|
|
22441
|
-
periodType
|
|
23142
|
+
periodType,
|
|
22442
23143
|
fetchedAt,
|
|
22443
23144
|
...resetsAt ? { resetsAt } : {},
|
|
22444
23145
|
...productUsage ? { productUsage } : {}
|
|
22445
23146
|
};
|
|
22446
23147
|
}
|
|
22447
23148
|
function selectAccessToken(auth, now) {
|
|
22448
|
-
if (!
|
|
23149
|
+
if (!isRecord12(auth))
|
|
22449
23150
|
return null;
|
|
22450
|
-
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) &&
|
|
23151
|
+
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) && isRecord12(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")));
|
|
22451
23152
|
for (const [, value] of entries) {
|
|
22452
|
-
if (!
|
|
23153
|
+
if (!isRecord12(value) || typeof value.key !== "string")
|
|
22453
23154
|
continue;
|
|
22454
23155
|
if (typeof value.expires_at === "string") {
|
|
22455
23156
|
const expiresAt = Date.parse(value.expires_at);
|
|
@@ -22520,7 +23221,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
22520
23221
|
|
|
22521
23222
|
// dist/grok-usage.js
|
|
22522
23223
|
var USD_TICKS_PER_DOLLAR = 1e10;
|
|
22523
|
-
function
|
|
23224
|
+
function isRecord13(value) {
|
|
22524
23225
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22525
23226
|
}
|
|
22526
23227
|
function optionalToken(value) {
|
|
@@ -22537,7 +23238,7 @@ function combineUsage(base, next) {
|
|
|
22537
23238
|
return base === null ? next : parseHostUsage({ ...base, ...next });
|
|
22538
23239
|
}
|
|
22539
23240
|
function usageFromNative(value) {
|
|
22540
|
-
if (!
|
|
23241
|
+
if (!isRecord13(value))
|
|
22541
23242
|
return null;
|
|
22542
23243
|
const inputTokens = optionalToken(value.inputTokens);
|
|
22543
23244
|
const cachedRead = optionalToken(value.cachedReadTokens);
|
|
@@ -22564,7 +23265,7 @@ function usageFromPrompt(response) {
|
|
|
22564
23265
|
return response.usage ? usageFromNative(response.usage) : null;
|
|
22565
23266
|
}
|
|
22566
23267
|
function usageFromSignals(value) {
|
|
22567
|
-
if (!
|
|
23268
|
+
if (!isRecord13(value))
|
|
22568
23269
|
return null;
|
|
22569
23270
|
try {
|
|
22570
23271
|
return parseHostUsage({
|
|
@@ -22584,7 +23285,7 @@ var summedUsageFields = [
|
|
|
22584
23285
|
"totalTokens"
|
|
22585
23286
|
];
|
|
22586
23287
|
function nativeCostTicks(value) {
|
|
22587
|
-
if (!
|
|
23288
|
+
if (!isRecord13(value))
|
|
22588
23289
|
return void 0;
|
|
22589
23290
|
const ticks = value.costUsdTicks;
|
|
22590
23291
|
if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
|
|
@@ -22661,7 +23362,7 @@ function usageFromCompact(tokensAfter, contextWindowTokens) {
|
|
|
22661
23362
|
function usageFromUpdate(update, metadata, contextWindowTokens) {
|
|
22662
23363
|
try {
|
|
22663
23364
|
if (update?.sessionUpdate === "usage_update") {
|
|
22664
|
-
const cost =
|
|
23365
|
+
const cost = isRecord13(update.cost) ? update.cost : null;
|
|
22665
23366
|
return parseHostUsage({
|
|
22666
23367
|
contextUsedTokens: update.used,
|
|
22667
23368
|
contextWindowTokens: update.size,
|
|
@@ -22702,7 +23403,8 @@ function capabilitiesForModels(modelState) {
|
|
|
22702
23403
|
selectPermissionMode: true,
|
|
22703
23404
|
permissionModeScope: "atCreate"
|
|
22704
23405
|
},
|
|
22705
|
-
history: { fork: true, forkAcrossCwd: true, rollbackLastTurn: true }
|
|
23406
|
+
history: { fork: true, forkAcrossCwd: true, rollbackLastTurn: true },
|
|
23407
|
+
subagents: { observe: true, readTranscript: true }
|
|
22706
23408
|
};
|
|
22707
23409
|
}
|
|
22708
23410
|
var DEFAULT_CLOSE_TIMEOUT_MS = 2e3;
|
|
@@ -22902,6 +23604,7 @@ var GrokHarnessSession = class {
|
|
|
22902
23604
|
compactionContextWindow: void 0,
|
|
22903
23605
|
compactionTerminal: null,
|
|
22904
23606
|
tools: /* @__PURE__ */ new Map(),
|
|
23607
|
+
subagents: this.#createSubagents(),
|
|
22905
23608
|
completedItems: [],
|
|
22906
23609
|
approvals: /* @__PURE__ */ new Map(),
|
|
22907
23610
|
cancellationRequested: false,
|
|
@@ -22976,6 +23679,7 @@ var GrokHarnessSession = class {
|
|
|
22976
23679
|
compactionContextWindow: void 0,
|
|
22977
23680
|
compactionTerminal: null,
|
|
22978
23681
|
tools: /* @__PURE__ */ new Map(),
|
|
23682
|
+
subagents: this.#createSubagents(),
|
|
22979
23683
|
completedItems: [],
|
|
22980
23684
|
approvals: /* @__PURE__ */ new Map(),
|
|
22981
23685
|
cancellationRequested: false,
|
|
@@ -23204,6 +23908,10 @@ var GrokHarnessSession = class {
|
|
|
23204
23908
|
this.#startTool(active, event);
|
|
23205
23909
|
else if (event.type === "tool.update")
|
|
23206
23910
|
this.#updateTool(active, event);
|
|
23911
|
+
else if (event.type === "subagent.spawned")
|
|
23912
|
+
this.#bindSpawnedSubagent(active, event);
|
|
23913
|
+
else if (event.type === "subagent.finished")
|
|
23914
|
+
this.#finishNativeSubagent(active, event);
|
|
23207
23915
|
else if (event.type === "compaction.started")
|
|
23208
23916
|
this.#startCompaction(active, event);
|
|
23209
23917
|
else if (event.type === "compaction.completed") {
|
|
@@ -23310,9 +24018,36 @@ var GrokHarnessSession = class {
|
|
|
23310
24018
|
update: { type: "text.append", text }
|
|
23311
24019
|
});
|
|
23312
24020
|
}
|
|
24021
|
+
#createSubagents() {
|
|
24022
|
+
return new GrokSubagentLifecycle({
|
|
24023
|
+
newItemId: () => hostItemIdSchema.parse(this.#randomUUID()),
|
|
24024
|
+
emit: (event) => this.#event(event)
|
|
24025
|
+
});
|
|
24026
|
+
}
|
|
23313
24027
|
#startTool(active, event) {
|
|
23314
24028
|
this.#completeReasoning(active, { status: "succeeded" });
|
|
23315
24029
|
this.#completeAgent(active, { status: "succeeded" });
|
|
24030
|
+
const operation = grokSubagentOperation(event.name, event.title, event.rawInput);
|
|
24031
|
+
if (operation) {
|
|
24032
|
+
const prompt = grokSubagentPrompt(event.rawInput);
|
|
24033
|
+
const role = grokSubagentRole(event.rawInput);
|
|
24034
|
+
const nativeSubagentId = grokNativeSubagentId(event.rawInput);
|
|
24035
|
+
const model = grokSubagentModel(event.rawInput);
|
|
24036
|
+
active.subagents.start(active.command.turnId, {
|
|
24037
|
+
callId: event.callId,
|
|
24038
|
+
operation,
|
|
24039
|
+
description: grokSubagentDescription(event.rawInput, event.title),
|
|
24040
|
+
...prompt ? { prompt } : {},
|
|
24041
|
+
...role ? { role } : {},
|
|
24042
|
+
...model ? { model } : {},
|
|
24043
|
+
background: grokSubagentBackground(event.rawInput),
|
|
24044
|
+
...nativeSubagentId ? { nativeSubagentId } : {}
|
|
24045
|
+
});
|
|
24046
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
24047
|
+
this.#completeSubagentTool(active, event.callId, event.status, event);
|
|
24048
|
+
}
|
|
24049
|
+
return;
|
|
24050
|
+
}
|
|
23316
24051
|
let item = startGrokToolItem({
|
|
23317
24052
|
itemId: hostItemIdSchema.parse(this.#randomUUID()),
|
|
23318
24053
|
name: event.name,
|
|
@@ -23331,6 +24066,34 @@ var GrokHarnessSession = class {
|
|
|
23331
24066
|
}
|
|
23332
24067
|
}
|
|
23333
24068
|
#updateTool(active, event) {
|
|
24069
|
+
if (!active.subagents.has(event.callId) && !active.tools.has(event.callId) && grokSubagentOperation(event.name, event.title, event.rawInput)) {
|
|
24070
|
+
this.#startTool(active, {
|
|
24071
|
+
type: "tool.call",
|
|
24072
|
+
callId: event.callId,
|
|
24073
|
+
title: event.title ?? "Grok Subagent",
|
|
24074
|
+
...event.name ? { name: event.name } : {},
|
|
24075
|
+
...event.kind ? { kind: event.kind } : {},
|
|
24076
|
+
...event.status ? { status: event.status } : {},
|
|
24077
|
+
...event.rawInput !== void 0 ? { rawInput: event.rawInput } : {},
|
|
24078
|
+
...event.rawOutput !== void 0 ? { rawOutput: event.rawOutput } : {},
|
|
24079
|
+
...event.content ? { content: event.content } : {}
|
|
24080
|
+
});
|
|
24081
|
+
return;
|
|
24082
|
+
}
|
|
24083
|
+
if (active.subagents.has(event.callId)) {
|
|
24084
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
24085
|
+
this.#completeSubagentTool(active, event.callId, event.status, event);
|
|
24086
|
+
return;
|
|
24087
|
+
}
|
|
24088
|
+
const role = grokSubagentRole(event.rawInput);
|
|
24089
|
+
const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content);
|
|
24090
|
+
active.subagents.update(active.command.turnId, event.callId, {
|
|
24091
|
+
...event.title ? { description: grokSubagentDescription(event.rawInput, event.title) } : {},
|
|
24092
|
+
...role ? { role } : {},
|
|
24093
|
+
...nativeSubagentId ? { nativeSubagentId } : {}
|
|
24094
|
+
});
|
|
24095
|
+
return;
|
|
24096
|
+
}
|
|
23334
24097
|
const tool = active.tools.get(event.callId);
|
|
23335
24098
|
if (!tool)
|
|
23336
24099
|
return;
|
|
@@ -23386,6 +24149,7 @@ var GrokHarnessSession = class {
|
|
|
23386
24149
|
this.#completeItem(active, tool.item, outcome);
|
|
23387
24150
|
if (status !== "completed")
|
|
23388
24151
|
return;
|
|
24152
|
+
this.#completeWatchedSubagents(active, tool.item, content, rawOutput);
|
|
23389
24153
|
const changes = projectGrokFileChanges(content, this.#cwd);
|
|
23390
24154
|
if (!changes)
|
|
23391
24155
|
return;
|
|
@@ -23397,6 +24161,51 @@ var GrokHarnessSession = class {
|
|
|
23397
24161
|
this.#event({ type: "item.started", turnId: active.command.turnId, item: fileItem });
|
|
23398
24162
|
this.#completeItem(active, fileItem, { status: "succeeded" });
|
|
23399
24163
|
}
|
|
24164
|
+
#completeSubagentTool(active, callId, status, event) {
|
|
24165
|
+
const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content);
|
|
24166
|
+
const resultSummary = grokSubagentResultSummary(event.content, event.rawOutput);
|
|
24167
|
+
active.subagents.completeSpawn(active.command.turnId, callId, {
|
|
24168
|
+
failed: status === "failed",
|
|
24169
|
+
cancellationRequested: active.cancellationRequested,
|
|
24170
|
+
...nativeSubagentId ? { nativeSubagentId } : {},
|
|
24171
|
+
...resultSummary ? { resultSummary } : {}
|
|
24172
|
+
});
|
|
24173
|
+
}
|
|
24174
|
+
#completeWatchedSubagents(active, item, content, rawOutput) {
|
|
24175
|
+
const name = item.type === "toolExecution" ? item.toolName : item.command;
|
|
24176
|
+
const rawInput = item.type === "toolExecution" ? item.arguments : void 0;
|
|
24177
|
+
const resultSummary = grokSubagentResultSummary(content, rawOutput);
|
|
24178
|
+
for (const settlement of grokSubagentWaitSettlements({
|
|
24179
|
+
name,
|
|
24180
|
+
title: name,
|
|
24181
|
+
rawInput,
|
|
24182
|
+
content,
|
|
24183
|
+
rawOutput
|
|
24184
|
+
})) {
|
|
24185
|
+
active.subagents.completeByNativeId(active.command.turnId, settlement.id, {
|
|
24186
|
+
failed: settlement.status === "failed",
|
|
24187
|
+
cancellationRequested: active.cancellationRequested || settlement.status === "interrupted",
|
|
24188
|
+
status: settlement.status,
|
|
24189
|
+
...settlement.resultSummary ? { resultSummary: settlement.resultSummary } : resultSummary ? { resultSummary } : {}
|
|
24190
|
+
});
|
|
24191
|
+
}
|
|
24192
|
+
}
|
|
24193
|
+
#bindSpawnedSubagent(active, event) {
|
|
24194
|
+
active.subagents.bindNativeId(active.command.turnId, {
|
|
24195
|
+
nativeSubagentId: event.nativeSubagentId,
|
|
24196
|
+
...event.description ? { description: event.description } : {},
|
|
24197
|
+
...event.role ? { role: event.role } : {},
|
|
24198
|
+
...event.model ? { model: event.model } : {}
|
|
24199
|
+
});
|
|
24200
|
+
}
|
|
24201
|
+
#finishNativeSubagent(active, event) {
|
|
24202
|
+
active.subagents.completeByNativeId(active.command.turnId, event.nativeSubagentId, {
|
|
24203
|
+
failed: event.status === "failed",
|
|
24204
|
+
cancellationRequested: active.cancellationRequested || event.status === "interrupted",
|
|
24205
|
+
status: event.status,
|
|
24206
|
+
...event.resultSummary ? { resultSummary: event.resultSummary } : {}
|
|
24207
|
+
});
|
|
24208
|
+
}
|
|
23400
24209
|
#completeAgent(active, outcome) {
|
|
23401
24210
|
const item = active.agent;
|
|
23402
24211
|
if (item && active.rawAgentText.length > 0) {
|
|
@@ -23463,6 +24272,7 @@ var GrokHarnessSession = class {
|
|
|
23463
24272
|
const itemOutcome = outcome;
|
|
23464
24273
|
this.#completeReasoning(active, itemOutcome);
|
|
23465
24274
|
this.#completeAgent(active, itemOutcome);
|
|
24275
|
+
active.subagents.finalize(active.command.turnId, itemOutcome);
|
|
23466
24276
|
if (active.compactionItem) {
|
|
23467
24277
|
this.#completeItem(active, active.compactionItem, itemOutcome);
|
|
23468
24278
|
active.compactionItem = null;
|
|
@@ -23545,6 +24355,39 @@ var GrokHarnessSession = class {
|
|
|
23545
24355
|
var GrokAdapter = class {
|
|
23546
24356
|
commandCatalog = grokCommandCatalog;
|
|
23547
24357
|
harnessId = grokHarnessId;
|
|
24358
|
+
subagents = {
|
|
24359
|
+
readSnapshot: async (input) => {
|
|
24360
|
+
if (input.parent.harnessId !== this.harnessId || input.nativeSubagentId.trim().length === 0) {
|
|
24361
|
+
return {
|
|
24362
|
+
ok: false,
|
|
24363
|
+
error: {
|
|
24364
|
+
code: "invalidRequest",
|
|
24365
|
+
message: "Grok Subagent reference is invalid",
|
|
24366
|
+
retryable: false
|
|
24367
|
+
}
|
|
24368
|
+
};
|
|
24369
|
+
}
|
|
24370
|
+
try {
|
|
24371
|
+
const location = await locateGrokNativeSession(this.#environment ? { environment: this.#environment } : {}, input.nativeSubagentId);
|
|
24372
|
+
const cwd = location?.cwd ?? input.cwd;
|
|
24373
|
+
const history = await readGrokNativeHistory(this.#environment ? { cwd, environment: this.#environment } : { cwd }, input.nativeSubagentId);
|
|
24374
|
+
return {
|
|
24375
|
+
ok: true,
|
|
24376
|
+
value: mapGrokReplay(
|
|
24377
|
+
history,
|
|
24378
|
+
this.harnessId,
|
|
24379
|
+
// Host Subagent records keep the parent Native Session identity.
|
|
24380
|
+
input.parent.nativeSessionId,
|
|
24381
|
+
cwd,
|
|
24382
|
+
[],
|
|
24383
|
+
this.#toolOutputLimit
|
|
24384
|
+
)
|
|
24385
|
+
};
|
|
24386
|
+
} catch (error53) {
|
|
24387
|
+
return { ok: false, error: normalizeError(error53, "protocolError") };
|
|
24388
|
+
}
|
|
24389
|
+
}
|
|
24390
|
+
};
|
|
23548
24391
|
#closeTimeoutMs;
|
|
23549
24392
|
#dependencies;
|
|
23550
24393
|
#environment;
|
|
@@ -23748,7 +24591,11 @@ var GrokAdapter = class {
|
|
|
23748
24591
|
kind: "resume",
|
|
23749
24592
|
sessionId: parsedRef.data.nativeSessionId,
|
|
23750
24593
|
permissionModeId: requestedPermissionModeId
|
|
23751
|
-
} : {
|
|
24594
|
+
} : {
|
|
24595
|
+
kind: "create",
|
|
24596
|
+
permissionModeId: requestedPermissionModeId,
|
|
24597
|
+
...input.kind === "create" && input.model ? { modelId: input.model.id } : {}
|
|
24598
|
+
});
|
|
23752
24599
|
}
|
|
23753
24600
|
if (!opened) {
|
|
23754
24601
|
await transport.close().catch(() => void 0);
|