@liberseek/boft-cli-win32-arm64 0.6.2 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/desktop-controller.mjs +4 -1
- package/app/host-runtime.mjs +223 -29
- package/app/plugins/antigravity/plugin.mjs +6 -1
- package/app/plugins/claude-code/plugin.mjs +528 -49
- package/app/plugins/deepseek-harness/plugin.mjs +11 -1
- package/app/plugins/enabled.json +4 -1
- package/app/plugins/grok/plugin.mjs +925 -86
- package/app/plugins/hermes/manifest.json +11 -0
- package/app/plugins/hermes/plugin.mjs +21491 -0
- package/app/plugins/kiro-cli/assets/icon.svg +5 -0
- package/app/plugins/kiro-cli/manifest.json +12 -0
- package/app/plugins/kiro-cli/plugin.mjs +23353 -0
- package/app/plugins/muse/assets/icon.svg +4 -0
- package/app/plugins/muse/manifest.json +12 -0
- package/app/plugins/muse/plugin.mjs +18151 -0
- package/app/plugins/omp/plugin.mjs +11 -1
- package/app/plugins/opencode/plugin.mjs +11 -1
- package/app/plugins/pi/plugin.mjs +11 -1
- package/app/renderer-extension.js +1130 -157
- 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
|
@@ -18710,6 +18710,8 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
18710
18710
|
reasoningOutputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
18711
18711
|
totalTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
18712
18712
|
totalCostUsd: finiteNonNegativeNumberSchema.optional(),
|
|
18713
|
+
totalCredits: finiteNonNegativeNumberSchema.optional(),
|
|
18714
|
+
contextUsagePercent: finiteNonNegativeNumberSchema.optional(),
|
|
18713
18715
|
cacheHitRatePercent: cacheHitRatePercentSchema.optional(),
|
|
18714
18716
|
contextWindowTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
18715
18717
|
contextUsedTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
@@ -19665,7 +19667,9 @@ var usageFields = /* @__PURE__ */ new Set([
|
|
|
19665
19667
|
...tokenFields,
|
|
19666
19668
|
...safeIntegerFields,
|
|
19667
19669
|
...percentFields,
|
|
19668
|
-
"totalCostUsd"
|
|
19670
|
+
"totalCostUsd",
|
|
19671
|
+
"totalCredits",
|
|
19672
|
+
"contextUsagePercent"
|
|
19669
19673
|
]);
|
|
19670
19674
|
function isRecord2(value) {
|
|
19671
19675
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -19699,6 +19703,12 @@ function parseHostUsage(value) {
|
|
|
19699
19703
|
if (value.totalCostUsd !== void 0 && (typeof value.totalCostUsd !== "number" || !Number.isFinite(value.totalCostUsd) || value.totalCostUsd < 0)) {
|
|
19700
19704
|
throw new Error("Harness Usage 'totalCostUsd' must be a finite non-negative number");
|
|
19701
19705
|
}
|
|
19706
|
+
for (const field of ["totalCredits", "contextUsagePercent"]) {
|
|
19707
|
+
const candidate = value[field];
|
|
19708
|
+
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
|
|
19709
|
+
throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
|
|
19710
|
+
}
|
|
19711
|
+
}
|
|
19702
19712
|
for (const field of percentFields) {
|
|
19703
19713
|
const candidate = value[field];
|
|
19704
19714
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0 || candidate > 100)) {
|
|
@@ -20980,6 +20990,309 @@ function hasGrokToolProjection(projection) {
|
|
|
20980
20990
|
return projection.output !== void 0 || projection.exitCode !== void 0;
|
|
20981
20991
|
}
|
|
20982
20992
|
|
|
20993
|
+
// dist/grok-subagent.js
|
|
20994
|
+
var SPAWN_TOOL_NAMES = /* @__PURE__ */ new Set(["spawn_subagent", "spawn_agent", "task"]);
|
|
20995
|
+
var SEND_TOOL_NAMES = /* @__PURE__ */ new Set(["send_subagent_message"]);
|
|
20996
|
+
var WAIT_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
20997
|
+
"get_command_or_subagent_output",
|
|
20998
|
+
"get_task_output",
|
|
20999
|
+
"wait_tasks"
|
|
21000
|
+
]);
|
|
21001
|
+
var KILL_TOOL_NAMES = /* @__PURE__ */ new Set(["kill_command_or_subagent", "kill_task"]);
|
|
21002
|
+
var DESCRIPTION_LIMIT = 500;
|
|
21003
|
+
var SUMMARY_LIMIT = 2e3;
|
|
21004
|
+
function isRecord5(value) {
|
|
21005
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21006
|
+
}
|
|
21007
|
+
function idField(value, key) {
|
|
21008
|
+
if (!isRecord5(value))
|
|
21009
|
+
return void 0;
|
|
21010
|
+
const field = value[key];
|
|
21011
|
+
if (typeof field === "string") {
|
|
21012
|
+
const trimmed = field.trim();
|
|
21013
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
21014
|
+
}
|
|
21015
|
+
if (typeof field === "number" && Number.isFinite(field))
|
|
21016
|
+
return String(field);
|
|
21017
|
+
return void 0;
|
|
21018
|
+
}
|
|
21019
|
+
function stringField2(value, key) {
|
|
21020
|
+
if (!isRecord5(value) || typeof value[key] !== "string")
|
|
21021
|
+
return void 0;
|
|
21022
|
+
const trimmed = value[key].trim();
|
|
21023
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
21024
|
+
}
|
|
21025
|
+
function bounded(value, limit) {
|
|
21026
|
+
if (!value)
|
|
21027
|
+
return void 0;
|
|
21028
|
+
return value.slice(0, limit);
|
|
21029
|
+
}
|
|
21030
|
+
function toolId(name, title) {
|
|
21031
|
+
return grokToolName(name, title).toLowerCase();
|
|
21032
|
+
}
|
|
21033
|
+
function collectIds(value) {
|
|
21034
|
+
const ids = [];
|
|
21035
|
+
const push = (entry) => {
|
|
21036
|
+
if (typeof entry === "string" && entry.trim().length > 0)
|
|
21037
|
+
ids.push(entry.trim());
|
|
21038
|
+
else if (typeof entry === "number" && Number.isFinite(entry))
|
|
21039
|
+
ids.push(String(entry));
|
|
21040
|
+
};
|
|
21041
|
+
push(idField(value, "task_id"));
|
|
21042
|
+
push(idField(value, "subagent_id"));
|
|
21043
|
+
if (isRecord5(value)) {
|
|
21044
|
+
const list = value.task_ids ?? value.subagent_ids;
|
|
21045
|
+
if (Array.isArray(list)) {
|
|
21046
|
+
for (const entry of list)
|
|
21047
|
+
push(entry);
|
|
21048
|
+
} else {
|
|
21049
|
+
push(list);
|
|
21050
|
+
}
|
|
21051
|
+
}
|
|
21052
|
+
return [...new Set(ids)];
|
|
21053
|
+
}
|
|
21054
|
+
function grokSubagentOperation(name, title, rawInput) {
|
|
21055
|
+
const id = toolId(name, title);
|
|
21056
|
+
if (WAIT_TOOL_NAMES.has(id) || KILL_TOOL_NAMES.has(id))
|
|
21057
|
+
return null;
|
|
21058
|
+
if (SEND_TOOL_NAMES.has(id))
|
|
21059
|
+
return "send";
|
|
21060
|
+
if (SPAWN_TOOL_NAMES.has(id))
|
|
21061
|
+
return "spawn";
|
|
21062
|
+
if (isRecord5(rawInput) && rawInput.variant === "Task")
|
|
21063
|
+
return "spawn";
|
|
21064
|
+
return null;
|
|
21065
|
+
}
|
|
21066
|
+
function grokSubagentWaitIds(name, title, rawInput) {
|
|
21067
|
+
if (!WAIT_TOOL_NAMES.has(toolId(name, title)) && !KILL_TOOL_NAMES.has(toolId(name, title))) {
|
|
21068
|
+
return [];
|
|
21069
|
+
}
|
|
21070
|
+
return collectIds(rawInput);
|
|
21071
|
+
}
|
|
21072
|
+
function grokSubagentKill(name, title) {
|
|
21073
|
+
return KILL_TOOL_NAMES.has(toolId(name, title));
|
|
21074
|
+
}
|
|
21075
|
+
function grokSubagentDescription(rawInput, title, fallback = "Grok Subagent") {
|
|
21076
|
+
return bounded(stringField2(rawInput, "description"), DESCRIPTION_LIMIT) ?? bounded(stringField2(rawInput, "name"), DESCRIPTION_LIMIT) ?? (title && !SPAWN_TOOL_NAMES.has(title.toLowerCase()) && !SEND_TOOL_NAMES.has(title.toLowerCase()) ? bounded(title, DESCRIPTION_LIMIT) : void 0) ?? fallback;
|
|
21077
|
+
}
|
|
21078
|
+
function grokSubagentPrompt(rawInput) {
|
|
21079
|
+
return bounded(stringField2(rawInput, "prompt") ?? stringField2(rawInput, "message"), SUMMARY_LIMIT);
|
|
21080
|
+
}
|
|
21081
|
+
function grokSubagentRole(rawInput) {
|
|
21082
|
+
return bounded(stringField2(rawInput, "subagent_type") ?? stringField2(rawInput, "agent_type") ?? stringField2(rawInput, "type"), DESCRIPTION_LIMIT);
|
|
21083
|
+
}
|
|
21084
|
+
function grokSubagentBackground(rawInput) {
|
|
21085
|
+
if (!isRecord5(rawInput))
|
|
21086
|
+
return true;
|
|
21087
|
+
if (rawInput.background === false || rawInput.run_in_background === false)
|
|
21088
|
+
return false;
|
|
21089
|
+
return true;
|
|
21090
|
+
}
|
|
21091
|
+
function grokSubagentModel(rawInput) {
|
|
21092
|
+
return bounded(stringField2(rawInput, "model"), DESCRIPTION_LIMIT);
|
|
21093
|
+
}
|
|
21094
|
+
function grokNativeSubagentId(...candidates) {
|
|
21095
|
+
const fromKey = (key) => {
|
|
21096
|
+
for (const candidate of candidates) {
|
|
21097
|
+
const value = idField(candidate, key);
|
|
21098
|
+
if (value)
|
|
21099
|
+
return value;
|
|
21100
|
+
}
|
|
21101
|
+
return void 0;
|
|
21102
|
+
};
|
|
21103
|
+
const fromText = (pattern) => {
|
|
21104
|
+
for (const candidate of candidates) {
|
|
21105
|
+
const text = extractText(candidate);
|
|
21106
|
+
const match = text?.match(pattern);
|
|
21107
|
+
if (match?.[1])
|
|
21108
|
+
return match[1].trim();
|
|
21109
|
+
}
|
|
21110
|
+
return void 0;
|
|
21111
|
+
};
|
|
21112
|
+
return fromKey("subagent_id") ?? fromText(/subagent_id:\s*([^\s]+)/i) ?? fromKey("task_id") ?? fromKey("id") ?? fromText(/task_id:\s*([^\s]+)/i) ?? fromText(/task_ids=\["([^"]+)"\]/);
|
|
21113
|
+
}
|
|
21114
|
+
function grokSubagentResultSummary(...candidates) {
|
|
21115
|
+
for (const candidate of candidates) {
|
|
21116
|
+
const text = extractText(candidate);
|
|
21117
|
+
if (text)
|
|
21118
|
+
return bounded(text, SUMMARY_LIMIT);
|
|
21119
|
+
}
|
|
21120
|
+
return void 0;
|
|
21121
|
+
}
|
|
21122
|
+
function grokSubagentEventFromUpdate(update) {
|
|
21123
|
+
if (!isRecord5(update) || typeof update.sessionUpdate !== "string")
|
|
21124
|
+
return null;
|
|
21125
|
+
const nativeSubagentId = idField(update, "subagent_id") ?? idField(update, "child_session_id");
|
|
21126
|
+
if (!nativeSubagentId)
|
|
21127
|
+
return null;
|
|
21128
|
+
if (update.sessionUpdate === "subagent_spawned") {
|
|
21129
|
+
const description = bounded(stringField2(update, "description"), DESCRIPTION_LIMIT);
|
|
21130
|
+
const role = bounded(stringField2(update, "subagent_type") ?? stringField2(update, "role"), DESCRIPTION_LIMIT);
|
|
21131
|
+
const model = bounded(stringField2(update, "model"), DESCRIPTION_LIMIT);
|
|
21132
|
+
return {
|
|
21133
|
+
type: "subagent.spawned",
|
|
21134
|
+
nativeSubagentId,
|
|
21135
|
+
...description ? { description } : {},
|
|
21136
|
+
...role ? { role } : {},
|
|
21137
|
+
...model ? { model } : {}
|
|
21138
|
+
};
|
|
21139
|
+
}
|
|
21140
|
+
if (update.sessionUpdate === "subagent_finished") {
|
|
21141
|
+
const mapped = mapTaskStatus(typeof update.status === "string" ? update.status : void 0);
|
|
21142
|
+
if (!mapped || mapped === "running" || mapped === "pending")
|
|
21143
|
+
return null;
|
|
21144
|
+
const status = mapped === "failed" ? "failed" : mapped === "interrupted" ? "interrupted" : "completed";
|
|
21145
|
+
const resultSummary = bounded(typeof update.output === "string" ? update.output.trim() : void 0, SUMMARY_LIMIT);
|
|
21146
|
+
return {
|
|
21147
|
+
type: "subagent.finished",
|
|
21148
|
+
nativeSubagentId,
|
|
21149
|
+
status,
|
|
21150
|
+
...resultSummary ? { resultSummary } : {}
|
|
21151
|
+
};
|
|
21152
|
+
}
|
|
21153
|
+
return null;
|
|
21154
|
+
}
|
|
21155
|
+
function grokSubagentWaitSettlements(input) {
|
|
21156
|
+
const ids = grokSubagentWaitIds(input.name, input.title, input.rawInput);
|
|
21157
|
+
if (grokSubagentKill(input.name, input.title)) {
|
|
21158
|
+
return ids.map((id) => ({ id, status: "interrupted" }));
|
|
21159
|
+
}
|
|
21160
|
+
if (ids.length === 0)
|
|
21161
|
+
return [];
|
|
21162
|
+
const resultEntries = taskOutputResults(input.rawOutput);
|
|
21163
|
+
if (resultEntries.length > 0) {
|
|
21164
|
+
const settled = [];
|
|
21165
|
+
for (const result of resultEntries) {
|
|
21166
|
+
const id = idField(result, "task_id") ?? idField(result, "subagent_id");
|
|
21167
|
+
const status = mapTaskStatus(typeof result.status === "string" ? result.status : void 0);
|
|
21168
|
+
if (!id || !status || status === "running" || status === "pending")
|
|
21169
|
+
continue;
|
|
21170
|
+
const resultSummary = bounded(typeof result.output === "string" ? result.output.trim() : void 0, SUMMARY_LIMIT);
|
|
21171
|
+
settled.push({ id, status, ...resultSummary ? { resultSummary } : {} });
|
|
21172
|
+
}
|
|
21173
|
+
return settled;
|
|
21174
|
+
}
|
|
21175
|
+
const fromText = taskOutputTextSettlements(input.rawOutput, input.content, ids);
|
|
21176
|
+
if (fromText.length > 0)
|
|
21177
|
+
return fromText;
|
|
21178
|
+
const overall = mapTaskStatus(taskOutputStatus(input.rawOutput, input.content));
|
|
21179
|
+
if (!overall || overall === "running" || overall === "pending")
|
|
21180
|
+
return [];
|
|
21181
|
+
return ids.map((id) => ({ id, status: overall }));
|
|
21182
|
+
}
|
|
21183
|
+
function taskOutputResults(rawOutput) {
|
|
21184
|
+
if (!isRecord5(rawOutput))
|
|
21185
|
+
return [];
|
|
21186
|
+
if (Array.isArray(rawOutput.results)) {
|
|
21187
|
+
return rawOutput.results.filter(isRecord5);
|
|
21188
|
+
}
|
|
21189
|
+
const nested = firstRecord(rawOutput.MultiResult, rawOutput.multiResult, rawOutput.multi_result);
|
|
21190
|
+
if (nested && Array.isArray(nested.results)) {
|
|
21191
|
+
return nested.results.filter(isRecord5);
|
|
21192
|
+
}
|
|
21193
|
+
const single = firstRecord(rawOutput.Result, rawOutput.result);
|
|
21194
|
+
if (single)
|
|
21195
|
+
return [single];
|
|
21196
|
+
if (typeof rawOutput.status === "string")
|
|
21197
|
+
return [rawOutput];
|
|
21198
|
+
return [];
|
|
21199
|
+
}
|
|
21200
|
+
function firstRecord(...values) {
|
|
21201
|
+
for (const value of values) {
|
|
21202
|
+
if (isRecord5(value))
|
|
21203
|
+
return value;
|
|
21204
|
+
}
|
|
21205
|
+
return void 0;
|
|
21206
|
+
}
|
|
21207
|
+
function taskOutputTextSettlements(rawOutput, content, ids) {
|
|
21208
|
+
const text = extractText(content) ?? extractText(rawOutput);
|
|
21209
|
+
if (!text)
|
|
21210
|
+
return [];
|
|
21211
|
+
const settled = [];
|
|
21212
|
+
const pattern = /---\s*Task\s+(\S+)\s+\[(completed|failed|interrupted|cancelled|canceled)\]\s*---/gi;
|
|
21213
|
+
for (const match of text.matchAll(pattern)) {
|
|
21214
|
+
const id = match[1]?.trim();
|
|
21215
|
+
const status = mapTaskStatus(match[2]);
|
|
21216
|
+
if (!id || !status || status === "running" || status === "pending")
|
|
21217
|
+
continue;
|
|
21218
|
+
if (!ids.includes(id))
|
|
21219
|
+
continue;
|
|
21220
|
+
settled.push({ id, status });
|
|
21221
|
+
}
|
|
21222
|
+
return settled;
|
|
21223
|
+
}
|
|
21224
|
+
function taskOutputStatus(rawOutput, content) {
|
|
21225
|
+
if (isRecord5(rawOutput) && typeof rawOutput.status === "string")
|
|
21226
|
+
return rawOutput.status;
|
|
21227
|
+
const text = extractText(content) ?? extractText(rawOutput);
|
|
21228
|
+
if (!text)
|
|
21229
|
+
return void 0;
|
|
21230
|
+
if (/<subagent_meta>|<subagent_result>/i.test(text))
|
|
21231
|
+
return "completed";
|
|
21232
|
+
if (/\bstatus["']?\s*[:=]\s*["']?completed/i.test(text))
|
|
21233
|
+
return "completed";
|
|
21234
|
+
if (/\bstatus["']?\s*[:=]\s*["']?failed/i.test(text))
|
|
21235
|
+
return "failed";
|
|
21236
|
+
if (/\bstatus["']?\s*[:=]\s*["']?(cancelled|canceled|interrupted)/i.test(text)) {
|
|
21237
|
+
return "interrupted";
|
|
21238
|
+
}
|
|
21239
|
+
if (/\bstill running\b|\bstatus["']?\s*[:=]\s*["']?(running|pending|in_progress)/i.test(text)) {
|
|
21240
|
+
return "running";
|
|
21241
|
+
}
|
|
21242
|
+
return void 0;
|
|
21243
|
+
}
|
|
21244
|
+
function mapTaskStatus(status) {
|
|
21245
|
+
if (!status)
|
|
21246
|
+
return void 0;
|
|
21247
|
+
switch (status.toLowerCase()) {
|
|
21248
|
+
case "completed":
|
|
21249
|
+
case "succeeded":
|
|
21250
|
+
case "success":
|
|
21251
|
+
return "completed";
|
|
21252
|
+
case "failed":
|
|
21253
|
+
case "error":
|
|
21254
|
+
case "errored":
|
|
21255
|
+
return "failed";
|
|
21256
|
+
case "cancelled":
|
|
21257
|
+
case "canceled":
|
|
21258
|
+
case "interrupted":
|
|
21259
|
+
return "interrupted";
|
|
21260
|
+
case "running":
|
|
21261
|
+
case "pending":
|
|
21262
|
+
case "in_progress":
|
|
21263
|
+
case "inprogress":
|
|
21264
|
+
return "running";
|
|
21265
|
+
default:
|
|
21266
|
+
return void 0;
|
|
21267
|
+
}
|
|
21268
|
+
}
|
|
21269
|
+
function extractText(value, depth = 0) {
|
|
21270
|
+
if (depth > 6)
|
|
21271
|
+
return void 0;
|
|
21272
|
+
if (typeof value === "string") {
|
|
21273
|
+
const trimmed = value.trim();
|
|
21274
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
21275
|
+
}
|
|
21276
|
+
if (Array.isArray(value)) {
|
|
21277
|
+
const parts = value.flatMap((entry) => {
|
|
21278
|
+
const text = extractText(entry, depth + 1);
|
|
21279
|
+
return text ? [text] : [];
|
|
21280
|
+
});
|
|
21281
|
+
const joined = parts.join("\n").trim();
|
|
21282
|
+
return joined.length > 0 ? joined : void 0;
|
|
21283
|
+
}
|
|
21284
|
+
if (!isRecord5(value))
|
|
21285
|
+
return void 0;
|
|
21286
|
+
if (typeof value.text === "string" && value.text.trim().length > 0)
|
|
21287
|
+
return value.text.trim();
|
|
21288
|
+
if (typeof value.output === "string" && value.output.trim().length > 0) {
|
|
21289
|
+
return value.output.trim();
|
|
21290
|
+
}
|
|
21291
|
+
if (value.content !== void 0)
|
|
21292
|
+
return extractText(value.content, depth + 1);
|
|
21293
|
+
return void 0;
|
|
21294
|
+
}
|
|
21295
|
+
|
|
20983
21296
|
// dist/grok-history.js
|
|
20984
21297
|
function stableId(kind, turn, index) {
|
|
20985
21298
|
return hostItemIdSchema.parse(`grok-history-${kind}-${turn}-${index}`);
|
|
@@ -21042,6 +21355,90 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
21042
21355
|
let reasoning = null;
|
|
21043
21356
|
const tools = /* @__PURE__ */ new Map();
|
|
21044
21357
|
const mediaRoots = grokMediaResolveRoots(cwd, sessionDirectory);
|
|
21358
|
+
const subagents = /* @__PURE__ */ new Map();
|
|
21359
|
+
const subagentAliases = /* @__PURE__ */ new Map();
|
|
21360
|
+
const rememberSubagentAlias = (callId, nativeId) => {
|
|
21361
|
+
subagentAliases.set(callId, callId);
|
|
21362
|
+
if (nativeId)
|
|
21363
|
+
subagentAliases.set(nativeId, callId);
|
|
21364
|
+
};
|
|
21365
|
+
const completeHistorySubagent = (callId, status, content, rawOutput, rawInput) => {
|
|
21366
|
+
const current = subagents.get(callId);
|
|
21367
|
+
const currentAgent = current?.subagents[0];
|
|
21368
|
+
if (!current || !currentAgent)
|
|
21369
|
+
return;
|
|
21370
|
+
const nativeSubagentId = grokNativeSubagentId(rawInput, rawOutput, content) ?? currentAgent.nativeSubagentId;
|
|
21371
|
+
rememberSubagentAlias(callId, nativeSubagentId);
|
|
21372
|
+
const summary = grokSubagentResultSummary(content, rawOutput);
|
|
21373
|
+
const failed = status === "failed";
|
|
21374
|
+
const keepRunning = !failed && (currentAgent.background === true || current.operation === "send");
|
|
21375
|
+
const item = {
|
|
21376
|
+
...current,
|
|
21377
|
+
subagents: [
|
|
21378
|
+
{
|
|
21379
|
+
...currentAgent,
|
|
21380
|
+
status: failed ? "failed" : keepRunning ? "running" : "completed",
|
|
21381
|
+
...nativeSubagentId ? { nativeSubagentId, subagentId: nativeSubagentId } : {},
|
|
21382
|
+
...summary ? { resultSummary: summary } : {}
|
|
21383
|
+
}
|
|
21384
|
+
]
|
|
21385
|
+
};
|
|
21386
|
+
if (keepRunning) {
|
|
21387
|
+
subagents.set(callId, item);
|
|
21388
|
+
return;
|
|
21389
|
+
}
|
|
21390
|
+
subagents.delete(callId);
|
|
21391
|
+
items.push({
|
|
21392
|
+
item,
|
|
21393
|
+
outcome: failed ? {
|
|
21394
|
+
status: "failed",
|
|
21395
|
+
error: {
|
|
21396
|
+
code: "nativeFailure",
|
|
21397
|
+
message: "Grok Subagent delegation failed",
|
|
21398
|
+
retryable: false
|
|
21399
|
+
}
|
|
21400
|
+
} : { status: "succeeded" }
|
|
21401
|
+
});
|
|
21402
|
+
};
|
|
21403
|
+
const settleWatchedSubagents = (name, rawInput, content, rawOutput) => {
|
|
21404
|
+
const summary = grokSubagentResultSummary(content, rawOutput);
|
|
21405
|
+
for (const settlement of grokSubagentWaitSettlements({
|
|
21406
|
+
...name ? { name, title: name } : {},
|
|
21407
|
+
rawInput,
|
|
21408
|
+
content,
|
|
21409
|
+
rawOutput
|
|
21410
|
+
})) {
|
|
21411
|
+
const spawnId = subagentAliases.get(settlement.id);
|
|
21412
|
+
const item = spawnId ? subagents.get(spawnId) : void 0;
|
|
21413
|
+
if (!item?.subagents[0])
|
|
21414
|
+
continue;
|
|
21415
|
+
if (spawnId)
|
|
21416
|
+
subagents.delete(spawnId);
|
|
21417
|
+
const resultSummary = settlement.resultSummary ?? summary;
|
|
21418
|
+
items.push({
|
|
21419
|
+
item: {
|
|
21420
|
+
...item,
|
|
21421
|
+
subagents: [
|
|
21422
|
+
{
|
|
21423
|
+
...item.subagents[0],
|
|
21424
|
+
status: settlement.status,
|
|
21425
|
+
nativeSubagentId: item.subagents[0].nativeSubagentId ?? settlement.id,
|
|
21426
|
+
subagentId: item.subagents[0].nativeSubagentId ?? settlement.id,
|
|
21427
|
+
...resultSummary ? { resultSummary } : {}
|
|
21428
|
+
}
|
|
21429
|
+
]
|
|
21430
|
+
},
|
|
21431
|
+
outcome: settlement.status === "failed" ? {
|
|
21432
|
+
status: "failed",
|
|
21433
|
+
error: {
|
|
21434
|
+
code: "nativeFailure",
|
|
21435
|
+
message: "Grok Subagent delegation failed",
|
|
21436
|
+
retryable: false
|
|
21437
|
+
}
|
|
21438
|
+
} : settlement.status === "interrupted" ? { status: "cancelled", reason: "Cancelled by user" } : { status: "succeeded" }
|
|
21439
|
+
});
|
|
21440
|
+
}
|
|
21441
|
+
};
|
|
21045
21442
|
const completeAgent = () => {
|
|
21046
21443
|
if (!agent || agent.text.length === 0)
|
|
21047
21444
|
return;
|
|
@@ -21062,6 +21459,10 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
21062
21459
|
items.push({ item: tool, outcome: { status: "succeeded" } });
|
|
21063
21460
|
}
|
|
21064
21461
|
tools.clear();
|
|
21462
|
+
for (const item of subagents.values()) {
|
|
21463
|
+
items.push({ item, outcome: { status: "succeeded" } });
|
|
21464
|
+
}
|
|
21465
|
+
subagents.clear();
|
|
21065
21466
|
};
|
|
21066
21467
|
const applyToolProjection = (callId, content, rawOutput) => {
|
|
21067
21468
|
const tool = tools.get(callId);
|
|
@@ -21086,6 +21487,7 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
21086
21487
|
retryable: false
|
|
21087
21488
|
}
|
|
21088
21489
|
} : { status: "succeeded" };
|
|
21490
|
+
settleWatchedSubagents(tool.type === "toolExecution" ? tool.toolName : tool.command, tool.type === "toolExecution" ? tool.arguments : void 0, content, rawOutput);
|
|
21089
21491
|
items.push({ item: tool, outcome });
|
|
21090
21492
|
if (status !== "completed")
|
|
21091
21493
|
return;
|
|
@@ -21153,6 +21555,8 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
21153
21555
|
agent = null;
|
|
21154
21556
|
reasoning = null;
|
|
21155
21557
|
tools.clear();
|
|
21558
|
+
subagents.clear();
|
|
21559
|
+
subagentAliases.clear();
|
|
21156
21560
|
continue;
|
|
21157
21561
|
}
|
|
21158
21562
|
if (event.type === "user.text") {
|
|
@@ -21227,23 +21631,99 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
21227
21631
|
} else if (event.type === "tool.call") {
|
|
21228
21632
|
completeReasoning();
|
|
21229
21633
|
completeAgent();
|
|
21230
|
-
|
|
21231
|
-
|
|
21232
|
-
|
|
21233
|
-
|
|
21234
|
-
|
|
21235
|
-
|
|
21236
|
-
|
|
21237
|
-
|
|
21238
|
-
|
|
21239
|
-
|
|
21240
|
-
|
|
21634
|
+
const operation = grokSubagentOperation(event.name, event.title, event.rawInput);
|
|
21635
|
+
if (operation) {
|
|
21636
|
+
const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content);
|
|
21637
|
+
rememberSubagentAlias(event.callId, nativeSubagentId);
|
|
21638
|
+
const prompt = grokSubagentPrompt(event.rawInput);
|
|
21639
|
+
const role = grokSubagentRole(event.rawInput);
|
|
21640
|
+
const model = grokSubagentModel(event.rawInput);
|
|
21641
|
+
subagents.set(event.callId, {
|
|
21642
|
+
type: "subagentDelegation",
|
|
21643
|
+
itemId: stableId("subagent", turnIndex, ++messageIndex),
|
|
21644
|
+
operation,
|
|
21645
|
+
...prompt ? { prompt } : {},
|
|
21646
|
+
subagents: [
|
|
21647
|
+
{
|
|
21648
|
+
subagentId: nativeSubagentId ?? event.callId,
|
|
21649
|
+
...nativeSubagentId ? { nativeSubagentId } : {},
|
|
21650
|
+
description: grokSubagentDescription(event.rawInput, event.title),
|
|
21651
|
+
...role ? { role } : {},
|
|
21652
|
+
...model ? { model } : {},
|
|
21653
|
+
background: grokSubagentBackground(event.rawInput),
|
|
21654
|
+
status: "running"
|
|
21655
|
+
}
|
|
21656
|
+
]
|
|
21657
|
+
});
|
|
21658
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
21659
|
+
completeHistorySubagent(event.callId, event.status, event.content, event.rawOutput, event.rawInput);
|
|
21660
|
+
}
|
|
21661
|
+
} else {
|
|
21662
|
+
tools.set(event.callId, startGrokToolItem({
|
|
21663
|
+
itemId: stableId("tool", turnIndex, ++messageIndex),
|
|
21664
|
+
name: event.name,
|
|
21665
|
+
title: event.title,
|
|
21666
|
+
kind: event.kind,
|
|
21667
|
+
rawInput: event.rawInput,
|
|
21668
|
+
cwd
|
|
21669
|
+
}));
|
|
21670
|
+
applyToolProjection(event.callId, event.content, event.rawOutput);
|
|
21671
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
21672
|
+
completeTool(event.callId, event.status, event.content, event.rawOutput);
|
|
21673
|
+
}
|
|
21241
21674
|
}
|
|
21242
21675
|
} else if (event.type === "tool.update") {
|
|
21243
|
-
|
|
21244
|
-
|
|
21245
|
-
|
|
21676
|
+
if (subagents.has(event.callId)) {
|
|
21677
|
+
const current = subagents.get(event.callId);
|
|
21678
|
+
if (current?.subagents[0]) {
|
|
21679
|
+
const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content) ?? current.subagents[0].nativeSubagentId;
|
|
21680
|
+
rememberSubagentAlias(event.callId, nativeSubagentId);
|
|
21681
|
+
subagents.set(event.callId, {
|
|
21682
|
+
...current,
|
|
21683
|
+
subagents: [
|
|
21684
|
+
{
|
|
21685
|
+
...current.subagents[0],
|
|
21686
|
+
description: grokSubagentDescription(event.rawInput, event.title, current.subagents[0].description),
|
|
21687
|
+
...nativeSubagentId ? { nativeSubagentId, subagentId: nativeSubagentId } : {}
|
|
21688
|
+
}
|
|
21689
|
+
]
|
|
21690
|
+
});
|
|
21691
|
+
}
|
|
21692
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
21693
|
+
completeHistorySubagent(event.callId, event.status, event.content, event.rawOutput, event.rawInput);
|
|
21694
|
+
}
|
|
21695
|
+
} else {
|
|
21696
|
+
applyToolProjection(event.callId, event.content, event.rawOutput);
|
|
21697
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
21698
|
+
completeTool(event.callId, event.status, event.content, event.rawOutput);
|
|
21699
|
+
}
|
|
21700
|
+
}
|
|
21701
|
+
} else if (event.type === "subagent.spawned") {
|
|
21702
|
+
for (const [callId, current] of subagents) {
|
|
21703
|
+
const agent2 = current.subagents[0];
|
|
21704
|
+
if (!agent2)
|
|
21705
|
+
continue;
|
|
21706
|
+
const matchesId = agent2.nativeSubagentId === event.nativeSubagentId;
|
|
21707
|
+
const matchesDescription = !agent2.nativeSubagentId && event.description !== void 0 && agent2.description === event.description;
|
|
21708
|
+
if (!matchesId && !matchesDescription)
|
|
21709
|
+
continue;
|
|
21710
|
+
rememberSubagentAlias(callId, event.nativeSubagentId);
|
|
21711
|
+
subagents.set(callId, {
|
|
21712
|
+
...current,
|
|
21713
|
+
subagents: [
|
|
21714
|
+
{
|
|
21715
|
+
...agent2,
|
|
21716
|
+
nativeSubagentId: event.nativeSubagentId,
|
|
21717
|
+
subagentId: event.nativeSubagentId,
|
|
21718
|
+
...event.role ? { role: event.role } : {},
|
|
21719
|
+
...event.model ? { model: event.model } : {}
|
|
21720
|
+
}
|
|
21721
|
+
]
|
|
21722
|
+
});
|
|
21723
|
+
break;
|
|
21246
21724
|
}
|
|
21725
|
+
} else if (event.type === "subagent.finished") {
|
|
21726
|
+
settleWatchedSubagents("get_command_or_subagent_output", { task_ids: [event.nativeSubagentId] }, event.resultSummary ? [event.resultSummary] : void 0, { task_id: event.nativeSubagentId, status: event.status, output: event.resultSummary });
|
|
21247
21727
|
}
|
|
21248
21728
|
}
|
|
21249
21729
|
completeTurn({ status: "unknown", reason: "Grok Native history has no terminal signal" });
|
|
@@ -21268,11 +21748,11 @@ var GROK_SESSION_DELETE_METHOD = "_x.ai/session/delete";
|
|
|
21268
21748
|
function error51(code, message, retryable = false) {
|
|
21269
21749
|
return { code, message, retryable };
|
|
21270
21750
|
}
|
|
21271
|
-
function
|
|
21751
|
+
function isRecord6(value) {
|
|
21272
21752
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21273
21753
|
}
|
|
21274
21754
|
function isGrokMethodNotFound(error53) {
|
|
21275
|
-
if (
|
|
21755
|
+
if (isRecord6(error53) && error53.code === -32601)
|
|
21276
21756
|
return true;
|
|
21277
21757
|
const message = error53 instanceof Error ? error53.message : String(error53);
|
|
21278
21758
|
return /method not found/iu.test(message);
|
|
@@ -21290,10 +21770,10 @@ function buildGrokForkParams(input) {
|
|
|
21290
21770
|
};
|
|
21291
21771
|
}
|
|
21292
21772
|
function parseGrokForkResponse(value) {
|
|
21293
|
-
if (!
|
|
21773
|
+
if (!isRecord6(value) || value.error !== void 0)
|
|
21294
21774
|
return null;
|
|
21295
|
-
const payload = typeof value.newSessionId !== "string" &&
|
|
21296
|
-
if (!
|
|
21775
|
+
const payload = typeof value.newSessionId !== "string" && isRecord6(value.result) ? value.result : value;
|
|
21776
|
+
if (!isRecord6(payload) || payload.error !== void 0)
|
|
21297
21777
|
return null;
|
|
21298
21778
|
if (typeof payload.newSessionId !== "string" || payload.newSessionId.length === 0)
|
|
21299
21779
|
return null;
|
|
@@ -21456,7 +21936,7 @@ var GROK_SESSION_UPDATE_EXTENSION_METHODS = [
|
|
|
21456
21936
|
"_x.ai/session/update",
|
|
21457
21937
|
"x.ai/session_notification"
|
|
21458
21938
|
];
|
|
21459
|
-
function
|
|
21939
|
+
function isRecord7(value) {
|
|
21460
21940
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21461
21941
|
}
|
|
21462
21942
|
function optionalNonNegativeInt(value) {
|
|
@@ -21477,7 +21957,7 @@ function isGrokExtensionSessionUpdateMethod(method) {
|
|
|
21477
21957
|
return GROK_SESSION_UPDATE_EXTENSION_METHODS.includes(method);
|
|
21478
21958
|
}
|
|
21479
21959
|
function grokCompactionEventFromUpdate(update) {
|
|
21480
|
-
if (!
|
|
21960
|
+
if (!isRecord7(update) || typeof update.sessionUpdate !== "string")
|
|
21481
21961
|
return null;
|
|
21482
21962
|
const tokensUsed = optionalNonNegativeInt(firstPresent(update, ["tokensUsed", "tokens_used"]));
|
|
21483
21963
|
const contextWindowTokens = optionalNonNegativeInt(firstPresent(update, ["contextWindowTokens", "contextWindow", "context_window"]));
|
|
@@ -21516,7 +21996,7 @@ function grokCompactionEventFromUpdate(update) {
|
|
|
21516
21996
|
// dist/grok-manual-compaction.js
|
|
21517
21997
|
var GROK_COMPACT_CONVERSATION_METHOD = "x.ai/compact_conversation";
|
|
21518
21998
|
var GROK_COMPACT_CONVERSATION_FALLBACK_METHOD = "_x.ai/compact_conversation";
|
|
21519
|
-
function
|
|
21999
|
+
function isRecord8(value) {
|
|
21520
22000
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21521
22001
|
}
|
|
21522
22002
|
function optionalNonNegativeInt2(value) {
|
|
@@ -21528,7 +22008,7 @@ function optionalErrorMessage2(value) {
|
|
|
21528
22008
|
function parseGrokCompactResult(value, cancelled = false) {
|
|
21529
22009
|
if (cancelled)
|
|
21530
22010
|
return { outcome: "cancelled" };
|
|
21531
|
-
if (!
|
|
22011
|
+
if (!isRecord8(value))
|
|
21532
22012
|
return { outcome: "succeeded" };
|
|
21533
22013
|
const tokensBefore = optionalNonNegativeInt2(value.tokensBefore ?? value.tokens_before);
|
|
21534
22014
|
const tokensAfter = optionalNonNegativeInt2(value.tokensAfter ?? value.tokens_after);
|
|
@@ -21566,7 +22046,7 @@ var GROK_REWIND_EXECUTE_METHOD = "_x.ai/rewind/execute";
|
|
|
21566
22046
|
function error52(code, message, retryable = false) {
|
|
21567
22047
|
return { code, message, retryable };
|
|
21568
22048
|
}
|
|
21569
|
-
function
|
|
22049
|
+
function isRecord9(value) {
|
|
21570
22050
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21571
22051
|
}
|
|
21572
22052
|
function buildGrokRewindParams(input) {
|
|
@@ -21578,10 +22058,10 @@ function buildGrokRewindParams(input) {
|
|
|
21578
22058
|
};
|
|
21579
22059
|
}
|
|
21580
22060
|
function parseGrokRewindResponse(value) {
|
|
21581
|
-
if (!
|
|
22061
|
+
if (!isRecord9(value))
|
|
21582
22062
|
return null;
|
|
21583
|
-
const payload = typeof value.success !== "boolean" &&
|
|
21584
|
-
if (!
|
|
22063
|
+
const payload = typeof value.success !== "boolean" && isRecord9(value.result) ? value.result : value;
|
|
22064
|
+
if (!isRecord9(payload) || typeof payload.success !== "boolean")
|
|
21585
22065
|
return null;
|
|
21586
22066
|
return rewindPayload(payload);
|
|
21587
22067
|
}
|
|
@@ -21691,10 +22171,10 @@ async function rewindGrokLastTurn(input) {
|
|
|
21691
22171
|
|
|
21692
22172
|
// dist/grok-plan-review.js
|
|
21693
22173
|
var GROK_PLAN_DECISION_ID = "plan-decision";
|
|
21694
|
-
function
|
|
22174
|
+
function isRecord10(value) {
|
|
21695
22175
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21696
22176
|
}
|
|
21697
|
-
function
|
|
22177
|
+
function stringField3(value, ...keys) {
|
|
21698
22178
|
for (const key of keys) {
|
|
21699
22179
|
const field = value[key];
|
|
21700
22180
|
if (typeof field === "string" && field.length > 0)
|
|
@@ -21703,12 +22183,12 @@ function stringField2(value, ...keys) {
|
|
|
21703
22183
|
return void 0;
|
|
21704
22184
|
}
|
|
21705
22185
|
function parseGrokExitPlanModeParams(params) {
|
|
21706
|
-
if (!
|
|
22186
|
+
if (!isRecord10(params))
|
|
21707
22187
|
return null;
|
|
21708
|
-
const nested =
|
|
21709
|
-
const plan =
|
|
21710
|
-
const planFilePath =
|
|
21711
|
-
const sessionId =
|
|
22188
|
+
const nested = isRecord10(params.input) ? params.input : params;
|
|
22189
|
+
const plan = stringField3(nested, "planContent", "plan_content", "plan") ?? stringField3(params, "planContent", "plan_content", "plan") ?? null;
|
|
22190
|
+
const planFilePath = stringField3(nested, "planFilePath", "plan_file_path") ?? stringField3(params, "planFilePath", "plan_file_path");
|
|
22191
|
+
const sessionId = stringField3(params, "sessionId", "session_id");
|
|
21712
22192
|
return {
|
|
21713
22193
|
plan,
|
|
21714
22194
|
...sessionId ? { sessionId } : {},
|
|
@@ -21772,10 +22252,10 @@ var GROK_ACP_CLIENT_CAPABILITIES = {
|
|
|
21772
22252
|
"x.ai/exit_plan_mode": true
|
|
21773
22253
|
}
|
|
21774
22254
|
};
|
|
21775
|
-
function
|
|
22255
|
+
function isRecord11(value) {
|
|
21776
22256
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21777
22257
|
}
|
|
21778
|
-
function
|
|
22258
|
+
function stringField4(value, ...keys) {
|
|
21779
22259
|
for (const key of keys) {
|
|
21780
22260
|
const field = value[key];
|
|
21781
22261
|
if (typeof field === "string" && field.length > 0)
|
|
@@ -21801,22 +22281,22 @@ function isGrokExitPlanModeMethod(method) {
|
|
|
21801
22281
|
function questionsPayload(params) {
|
|
21802
22282
|
if (Array.isArray(params.questions))
|
|
21803
22283
|
return params.questions;
|
|
21804
|
-
if (
|
|
22284
|
+
if (isRecord11(params.input) && Array.isArray(params.input.questions))
|
|
21805
22285
|
return params.input.questions;
|
|
21806
|
-
if (
|
|
22286
|
+
if (isRecord11(params.askUserQuestion) && Array.isArray(params.askUserQuestion.questions)) {
|
|
21807
22287
|
return params.askUserQuestion.questions;
|
|
21808
22288
|
}
|
|
21809
22289
|
return void 0;
|
|
21810
22290
|
}
|
|
21811
22291
|
function parseOption(value, labels) {
|
|
21812
|
-
if (!
|
|
22292
|
+
if (!isRecord11(value))
|
|
21813
22293
|
return null;
|
|
21814
|
-
const label =
|
|
22294
|
+
const label = stringField4(value, "label");
|
|
21815
22295
|
if (!label || labels.has(label))
|
|
21816
22296
|
return null;
|
|
21817
22297
|
labels.add(label);
|
|
21818
|
-
const description =
|
|
21819
|
-
const preview =
|
|
22298
|
+
const description = stringField4(value, "description");
|
|
22299
|
+
const preview = stringField4(value, "preview");
|
|
21820
22300
|
const combined = [description, preview].filter((part) => part !== void 0);
|
|
21821
22301
|
return {
|
|
21822
22302
|
label,
|
|
@@ -21824,9 +22304,9 @@ function parseOption(value, labels) {
|
|
|
21824
22304
|
};
|
|
21825
22305
|
}
|
|
21826
22306
|
function parseQuestion(value, questions) {
|
|
21827
|
-
if (!
|
|
22307
|
+
if (!isRecord11(value))
|
|
21828
22308
|
return null;
|
|
21829
|
-
const question =
|
|
22309
|
+
const question = stringField4(value, "question");
|
|
21830
22310
|
if (!question || questions.has(question))
|
|
21831
22311
|
return null;
|
|
21832
22312
|
if (!Array.isArray(value.options) || value.options.length === 0)
|
|
@@ -21840,7 +22320,7 @@ function parseQuestion(value, questions) {
|
|
|
21840
22320
|
options.push(parsed);
|
|
21841
22321
|
}
|
|
21842
22322
|
questions.add(question);
|
|
21843
|
-
const header =
|
|
22323
|
+
const header = stringField4(value, "header");
|
|
21844
22324
|
return {
|
|
21845
22325
|
question,
|
|
21846
22326
|
...header ? { header } : {},
|
|
@@ -21849,7 +22329,7 @@ function parseQuestion(value, questions) {
|
|
|
21849
22329
|
};
|
|
21850
22330
|
}
|
|
21851
22331
|
function parseGrokAskUserQuestionParams(params) {
|
|
21852
|
-
if (!
|
|
22332
|
+
if (!isRecord11(params))
|
|
21853
22333
|
return null;
|
|
21854
22334
|
const rawQuestions = questionsPayload(params);
|
|
21855
22335
|
if (!Array.isArray(rawQuestions) || rawQuestions.length === 0)
|
|
@@ -21862,7 +22342,7 @@ function parseGrokAskUserQuestionParams(params) {
|
|
|
21862
22342
|
return null;
|
|
21863
22343
|
questions.push(parsed);
|
|
21864
22344
|
}
|
|
21865
|
-
const sessionId =
|
|
22345
|
+
const sessionId = stringField4(params, "sessionId", "session_id");
|
|
21866
22346
|
const timeoutMs = optionalTimeoutMs(params);
|
|
21867
22347
|
return {
|
|
21868
22348
|
questions,
|
|
@@ -21964,9 +22444,18 @@ var GrokTransportError = class extends Error {
|
|
|
21964
22444
|
this.name = "GrokTransportError";
|
|
21965
22445
|
}
|
|
21966
22446
|
};
|
|
21967
|
-
function
|
|
22447
|
+
function isRecord12(value) {
|
|
21968
22448
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21969
22449
|
}
|
|
22450
|
+
function acpToolName(update, metadata) {
|
|
22451
|
+
if (!isRecord12(update))
|
|
22452
|
+
return void 0;
|
|
22453
|
+
if (typeof update.name === "string" && update.name.length > 0)
|
|
22454
|
+
return update.name;
|
|
22455
|
+
const meta3 = isRecord12(update._meta) ? update._meta : metadata;
|
|
22456
|
+
const tool = meta3 && isRecord12(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
|
|
22457
|
+
return tool && typeof tool.name === "string" && tool.name.length > 0 ? tool.name : void 0;
|
|
22458
|
+
}
|
|
21970
22459
|
function errorText(error53) {
|
|
21971
22460
|
return error53 instanceof Error ? error53.message : String(error53);
|
|
21972
22461
|
}
|
|
@@ -22020,7 +22509,7 @@ function signalProcessTree(child, signal) {
|
|
|
22020
22509
|
try {
|
|
22021
22510
|
process.kill(-child.pid, signal);
|
|
22022
22511
|
} catch (error53) {
|
|
22023
|
-
if (!
|
|
22512
|
+
if (!isRecord12(error53) || error53.code !== "ESRCH")
|
|
22024
22513
|
throw error53;
|
|
22025
22514
|
}
|
|
22026
22515
|
}
|
|
@@ -22045,6 +22534,9 @@ function transportEvent(update, metadata) {
|
|
|
22045
22534
|
const compaction = grokCompactionEventFromUpdate(extension);
|
|
22046
22535
|
if (compaction)
|
|
22047
22536
|
return compaction;
|
|
22537
|
+
const subagent = grokSubagentEventFromUpdate(extension);
|
|
22538
|
+
if (subagent)
|
|
22539
|
+
return subagent;
|
|
22048
22540
|
switch (update.sessionUpdate) {
|
|
22049
22541
|
case "user_message_chunk":
|
|
22050
22542
|
case "agent_message_chunk":
|
|
@@ -22056,30 +22548,34 @@ function transportEvent(update, metadata) {
|
|
|
22056
22548
|
text: update.content.text,
|
|
22057
22549
|
...update.messageId ? { messageId: update.messageId } : {}
|
|
22058
22550
|
};
|
|
22059
|
-
case "tool_call":
|
|
22551
|
+
case "tool_call": {
|
|
22552
|
+
const name = acpToolName(update, metadata);
|
|
22060
22553
|
return {
|
|
22061
22554
|
type: "tool.call",
|
|
22062
22555
|
callId: update.toolCallId,
|
|
22063
22556
|
title: update.title,
|
|
22064
|
-
...
|
|
22557
|
+
...name ? { name } : {},
|
|
22065
22558
|
...update.kind ? { kind: update.kind } : {},
|
|
22066
22559
|
...update.status ? { status: update.status } : {},
|
|
22067
22560
|
...update.rawInput !== void 0 ? { rawInput: update.rawInput } : {},
|
|
22068
22561
|
...update.rawOutput !== void 0 ? { rawOutput: update.rawOutput } : {},
|
|
22069
22562
|
...update.content ? { content: update.content } : {}
|
|
22070
22563
|
};
|
|
22071
|
-
|
|
22564
|
+
}
|
|
22565
|
+
case "tool_call_update": {
|
|
22566
|
+
const name = acpToolName(update, metadata);
|
|
22072
22567
|
return {
|
|
22073
22568
|
type: "tool.update",
|
|
22074
22569
|
callId: update.toolCallId,
|
|
22075
22570
|
...update.title !== void 0 ? { title: update.title } : {},
|
|
22076
|
-
...
|
|
22571
|
+
...name ? { name } : {},
|
|
22077
22572
|
...update.kind !== void 0 ? { kind: update.kind } : {},
|
|
22078
22573
|
...update.status !== void 0 ? { status: update.status } : {},
|
|
22079
22574
|
...update.rawInput !== void 0 ? { rawInput: update.rawInput } : {},
|
|
22080
22575
|
...update.rawOutput !== void 0 ? { rawOutput: update.rawOutput } : {},
|
|
22081
22576
|
...update.content !== void 0 ? { content: update.content } : {}
|
|
22082
22577
|
};
|
|
22578
|
+
}
|
|
22083
22579
|
case "usage_update":
|
|
22084
22580
|
return { type: "usage", update, ...metadata ? { metadata } : {} };
|
|
22085
22581
|
default:
|
|
@@ -22108,7 +22604,7 @@ async function readNativeSignals(options, sessionId) {
|
|
|
22108
22604
|
}
|
|
22109
22605
|
}
|
|
22110
22606
|
function isMissingFile(error53) {
|
|
22111
|
-
return
|
|
22607
|
+
return isRecord12(error53) && error53.code === "ENOENT";
|
|
22112
22608
|
}
|
|
22113
22609
|
async function locateGrokNativeSession(options, sessionId) {
|
|
22114
22610
|
if (sessionId.length === 0)
|
|
@@ -22131,7 +22627,7 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
22131
22627
|
try {
|
|
22132
22628
|
summaryRaw = await readFile(path8.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
|
|
22133
22629
|
} catch (error53) {
|
|
22134
|
-
if (isMissingFile(error53) ||
|
|
22630
|
+
if (isMissingFile(error53) || isRecord12(error53) && error53.code === "ENOTDIR")
|
|
22135
22631
|
continue;
|
|
22136
22632
|
throw new GrokTransportError("unavailable", "Grok Native Session metadata could not be read", {
|
|
22137
22633
|
cause: error53
|
|
@@ -22143,10 +22639,10 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
22143
22639
|
} catch {
|
|
22144
22640
|
continue;
|
|
22145
22641
|
}
|
|
22146
|
-
if (!
|
|
22642
|
+
if (!isRecord12(parsed))
|
|
22147
22643
|
continue;
|
|
22148
22644
|
const info = parsed.info;
|
|
22149
|
-
const cwd =
|
|
22645
|
+
const cwd = isRecord12(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path8.resolve(info.cwd) : path8.resolve(decodeURIComponent(entry.name));
|
|
22150
22646
|
const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path8.resolve(parsed.source_workspace_dir) : void 0;
|
|
22151
22647
|
matches.push({
|
|
22152
22648
|
cwd,
|
|
@@ -22179,12 +22675,12 @@ function parseNativeHistory(contents, sessionId) {
|
|
|
22179
22675
|
} catch {
|
|
22180
22676
|
throw new GrokTransportError("protocolError", "Grok Native history contains invalid JSON");
|
|
22181
22677
|
}
|
|
22182
|
-
if (!
|
|
22678
|
+
if (!isRecord12(record2) || !isRecord12(record2.params))
|
|
22183
22679
|
continue;
|
|
22184
22680
|
const params = record2.params;
|
|
22185
|
-
if (params.sessionId !== sessionId || !
|
|
22681
|
+
if (params.sessionId !== sessionId || !isRecord12(params.update))
|
|
22186
22682
|
continue;
|
|
22187
|
-
const metadata =
|
|
22683
|
+
const metadata = isRecord12(params._meta) ? params._meta : void 0;
|
|
22188
22684
|
const event = transportEvent(params.update, metadata);
|
|
22189
22685
|
if (event)
|
|
22190
22686
|
events.push(metadata ? { ...event, metadata } : event);
|
|
@@ -22487,7 +22983,7 @@ var GrokAcpTransport = class {
|
|
|
22487
22983
|
modelId,
|
|
22488
22984
|
...reasoningEffort ? { reasoningEffort } : {}
|
|
22489
22985
|
});
|
|
22490
|
-
if (!
|
|
22986
|
+
if (!isRecord12(response) || !isRecord12(response._meta) || !isRecord12(response._meta.model)) {
|
|
22491
22987
|
throw new GrokTransportError("protocolError", "Grok rejected Model configuration");
|
|
22492
22988
|
}
|
|
22493
22989
|
const selected = response._meta.model.Ok;
|
|
@@ -22530,7 +23026,7 @@ var GrokAcpTransport = class {
|
|
|
22530
23026
|
#handleUpdate(notification) {
|
|
22531
23027
|
if (this.#sessionId && notification.sessionId !== this.#sessionId)
|
|
22532
23028
|
return;
|
|
22533
|
-
const metadata =
|
|
23029
|
+
const metadata = isRecord12(notification._meta) ? notification._meta : void 0;
|
|
22534
23030
|
const event = transportEvent(notification.update, metadata);
|
|
22535
23031
|
if (!event)
|
|
22536
23032
|
return;
|
|
@@ -22545,7 +23041,7 @@ var GrokAcpTransport = class {
|
|
|
22545
23041
|
#handleExtensionNotification(method, params) {
|
|
22546
23042
|
if (!isGrokExtensionSessionUpdateMethod(method))
|
|
22547
23043
|
return;
|
|
22548
|
-
if (typeof params.sessionId !== "string" || !
|
|
23044
|
+
if (typeof params.sessionId !== "string" || !isRecord12(params.update))
|
|
22549
23045
|
return;
|
|
22550
23046
|
this.#handleUpdate(params);
|
|
22551
23047
|
}
|
|
@@ -22572,8 +23068,200 @@ var GrokAcpTransport = class {
|
|
|
22572
23068
|
}
|
|
22573
23069
|
};
|
|
22574
23070
|
|
|
23071
|
+
// dist/grok-subagent-lifecycle.js
|
|
23072
|
+
function subagentFailure() {
|
|
23073
|
+
return {
|
|
23074
|
+
code: "nativeFailure",
|
|
23075
|
+
message: "Grok Subagent delegation failed",
|
|
23076
|
+
retryable: false
|
|
23077
|
+
};
|
|
23078
|
+
}
|
|
23079
|
+
var GrokSubagentLifecycle = class {
|
|
23080
|
+
#emit;
|
|
23081
|
+
#newItemId;
|
|
23082
|
+
#delegations = /* @__PURE__ */ new Map();
|
|
23083
|
+
#callIdByNativeId = /* @__PURE__ */ new Map();
|
|
23084
|
+
constructor(options) {
|
|
23085
|
+
this.#emit = options.emit;
|
|
23086
|
+
this.#newItemId = options.newItemId;
|
|
23087
|
+
}
|
|
23088
|
+
get size() {
|
|
23089
|
+
return this.#delegations.size;
|
|
23090
|
+
}
|
|
23091
|
+
has(callId) {
|
|
23092
|
+
return this.#delegations.has(callId);
|
|
23093
|
+
}
|
|
23094
|
+
nativeSubagentId(callId) {
|
|
23095
|
+
return this.#delegations.get(callId)?.item.subagents[0]?.nativeSubagentId;
|
|
23096
|
+
}
|
|
23097
|
+
start(turnId, input) {
|
|
23098
|
+
if (this.#delegations.has(input.callId)) {
|
|
23099
|
+
throw new Error("Grok Subagent delegation started more than once");
|
|
23100
|
+
}
|
|
23101
|
+
this.#callIdByNativeId.set(input.callId, input.callId);
|
|
23102
|
+
if (input.nativeSubagentId)
|
|
23103
|
+
this.#callIdByNativeId.set(input.nativeSubagentId, input.callId);
|
|
23104
|
+
const subagent = {
|
|
23105
|
+
subagentId: input.nativeSubagentId ?? input.callId,
|
|
23106
|
+
...input.nativeSubagentId ? { nativeSubagentId: input.nativeSubagentId } : {},
|
|
23107
|
+
description: input.description,
|
|
23108
|
+
...input.role ? { role: input.role } : {},
|
|
23109
|
+
...input.model ? { model: input.model } : {},
|
|
23110
|
+
...input.reasoningEffort ? { reasoningEffort: input.reasoningEffort } : {},
|
|
23111
|
+
background: input.background,
|
|
23112
|
+
status: "running"
|
|
23113
|
+
};
|
|
23114
|
+
const item = {
|
|
23115
|
+
type: "subagentDelegation",
|
|
23116
|
+
itemId: this.#newItemId(),
|
|
23117
|
+
operation: input.operation,
|
|
23118
|
+
...input.prompt ? { prompt: input.prompt } : {},
|
|
23119
|
+
subagents: [subagent]
|
|
23120
|
+
};
|
|
23121
|
+
this.#delegations.set(input.callId, { callId: input.callId, item });
|
|
23122
|
+
this.#emit({ type: "item.started", turnId, item });
|
|
23123
|
+
this.#emitState(subagent);
|
|
23124
|
+
return subagent;
|
|
23125
|
+
}
|
|
23126
|
+
bindNativeId(turnId, input) {
|
|
23127
|
+
for (const [callId, active] of this.#delegations) {
|
|
23128
|
+
const current = active.item.subagents[0];
|
|
23129
|
+
if (!current)
|
|
23130
|
+
continue;
|
|
23131
|
+
if (current.nativeSubagentId === input.nativeSubagentId) {
|
|
23132
|
+
return this.update(turnId, callId, input);
|
|
23133
|
+
}
|
|
23134
|
+
}
|
|
23135
|
+
for (const [callId, active] of this.#delegations) {
|
|
23136
|
+
const current = active.item.subagents[0];
|
|
23137
|
+
if (!current || current.nativeSubagentId)
|
|
23138
|
+
continue;
|
|
23139
|
+
if (input.description && current.description === input.description) {
|
|
23140
|
+
return this.update(turnId, callId, input);
|
|
23141
|
+
}
|
|
23142
|
+
}
|
|
23143
|
+
return void 0;
|
|
23144
|
+
}
|
|
23145
|
+
update(turnId, callId, patch) {
|
|
23146
|
+
const active = this.#delegations.get(callId);
|
|
23147
|
+
if (!active)
|
|
23148
|
+
return void 0;
|
|
23149
|
+
const current = active.item.subagents[0];
|
|
23150
|
+
if (!current)
|
|
23151
|
+
throw new Error("Grok Subagent delegation has no Agent state");
|
|
23152
|
+
if (patch.nativeSubagentId)
|
|
23153
|
+
this.#callIdByNativeId.set(patch.nativeSubagentId, callId);
|
|
23154
|
+
const nativeSubagentId = patch.nativeSubagentId ?? current.nativeSubagentId;
|
|
23155
|
+
const subagent = {
|
|
23156
|
+
...current,
|
|
23157
|
+
...nativeSubagentId ? { nativeSubagentId, subagentId: nativeSubagentId } : {},
|
|
23158
|
+
...patch.description ? { description: patch.description } : {},
|
|
23159
|
+
...patch.role ? { role: patch.role } : {},
|
|
23160
|
+
...patch.model ? { model: patch.model } : {},
|
|
23161
|
+
...patch.reasoningEffort ? { reasoningEffort: patch.reasoningEffort } : {},
|
|
23162
|
+
...patch.resultSummary ? { resultSummary: patch.resultSummary } : {},
|
|
23163
|
+
...patch.status ? { status: patch.status } : {}
|
|
23164
|
+
};
|
|
23165
|
+
active.item = { ...active.item, subagents: [subagent] };
|
|
23166
|
+
this.#emit({
|
|
23167
|
+
type: "item.updated",
|
|
23168
|
+
turnId,
|
|
23169
|
+
itemId: active.item.itemId,
|
|
23170
|
+
update: { type: "subagents.replace", subagents: active.item.subagents }
|
|
23171
|
+
});
|
|
23172
|
+
this.#emitState(subagent);
|
|
23173
|
+
return subagent;
|
|
23174
|
+
}
|
|
23175
|
+
completeSpawn(turnId, callId, input) {
|
|
23176
|
+
const active = this.#delegations.get(callId);
|
|
23177
|
+
const background = input.background ?? active?.item.subagents[0]?.background ?? true;
|
|
23178
|
+
const keepRunning = !input.failed && !input.cancellationRequested && (background || active?.item.operation === "send");
|
|
23179
|
+
if (keepRunning) {
|
|
23180
|
+
return this.update(turnId, callId, {
|
|
23181
|
+
status: "running",
|
|
23182
|
+
...input.nativeSubagentId ? { nativeSubagentId: input.nativeSubagentId } : {},
|
|
23183
|
+
...input.resultSummary ? { resultSummary: input.resultSummary } : {}
|
|
23184
|
+
});
|
|
23185
|
+
}
|
|
23186
|
+
return this.complete(turnId, callId, { ...input, keepRunning: false });
|
|
23187
|
+
}
|
|
23188
|
+
completeByNativeId(turnId, nativeSubagentId, input) {
|
|
23189
|
+
const callId = this.#callIdByNativeId.get(nativeSubagentId) ?? this.#callIdForNative(nativeSubagentId);
|
|
23190
|
+
if (callId && this.#delegations.has(callId)) {
|
|
23191
|
+
return this.complete(turnId, callId, { ...input, nativeSubagentId });
|
|
23192
|
+
}
|
|
23193
|
+
const status = input.status ?? (input.cancellationRequested ? "interrupted" : input.failed ? "failed" : "completed");
|
|
23194
|
+
this.#emit({
|
|
23195
|
+
type: "subagent.state.changed",
|
|
23196
|
+
nativeSubagentId,
|
|
23197
|
+
status,
|
|
23198
|
+
...input.resultSummary ? { resultSummary: input.resultSummary } : {}
|
|
23199
|
+
});
|
|
23200
|
+
return void 0;
|
|
23201
|
+
}
|
|
23202
|
+
complete(turnId, callId, input) {
|
|
23203
|
+
const active = this.#delegations.get(callId);
|
|
23204
|
+
if (!active)
|
|
23205
|
+
return void 0;
|
|
23206
|
+
this.#delegations.delete(callId);
|
|
23207
|
+
const current = active.item.subagents[0];
|
|
23208
|
+
if (!current)
|
|
23209
|
+
throw new Error("Grok Subagent delegation has no Agent state");
|
|
23210
|
+
const status = input.status ?? (input.cancellationRequested ? "interrupted" : input.failed ? "failed" : input.keepRunning ? "running" : "completed");
|
|
23211
|
+
const nativeSubagentId = input.nativeSubagentId ?? current.nativeSubagentId;
|
|
23212
|
+
if (nativeSubagentId)
|
|
23213
|
+
this.#callIdByNativeId.set(nativeSubagentId, callId);
|
|
23214
|
+
const subagent = {
|
|
23215
|
+
...current,
|
|
23216
|
+
status,
|
|
23217
|
+
...nativeSubagentId ? { nativeSubagentId, subagentId: nativeSubagentId } : {},
|
|
23218
|
+
...input.resultSummary ? { resultSummary: input.resultSummary } : {}
|
|
23219
|
+
};
|
|
23220
|
+
const item = { ...active.item, subagents: [subagent] };
|
|
23221
|
+
this.#emit({
|
|
23222
|
+
type: "item.updated",
|
|
23223
|
+
turnId,
|
|
23224
|
+
itemId: item.itemId,
|
|
23225
|
+
update: { type: "subagents.replace", subagents: item.subagents }
|
|
23226
|
+
});
|
|
23227
|
+
const outcome = input.cancellationRequested ? { status: "cancelled", reason: "Cancelled by user" } : input.failed ? { status: "failed", error: subagentFailure() } : { status: "succeeded" };
|
|
23228
|
+
this.#emit({ type: "item.completed", turnId, snapshot: { item, outcome } });
|
|
23229
|
+
this.#emitState(subagent);
|
|
23230
|
+
return subagent;
|
|
23231
|
+
}
|
|
23232
|
+
finalize(turnId, outcome) {
|
|
23233
|
+
for (const [callId, active] of this.#delegations) {
|
|
23234
|
+
this.#delegations.delete(callId);
|
|
23235
|
+
const current = active.item.subagents[0];
|
|
23236
|
+
if (!current)
|
|
23237
|
+
continue;
|
|
23238
|
+
const status = outcome.status === "succeeded" ? current.status : outcome.status === "cancelled" ? "interrupted" : "failed";
|
|
23239
|
+
const item = { ...active.item, subagents: [{ ...current, status }] };
|
|
23240
|
+
this.#emit({ type: "item.completed", turnId, snapshot: { item, outcome } });
|
|
23241
|
+
this.#emitState({ ...current, status });
|
|
23242
|
+
}
|
|
23243
|
+
}
|
|
23244
|
+
#callIdForNative(nativeSubagentId) {
|
|
23245
|
+
for (const [callId, active] of this.#delegations) {
|
|
23246
|
+
if (active.item.subagents[0]?.nativeSubagentId === nativeSubagentId)
|
|
23247
|
+
return callId;
|
|
23248
|
+
}
|
|
23249
|
+
return void 0;
|
|
23250
|
+
}
|
|
23251
|
+
#emitState(subagent) {
|
|
23252
|
+
if (!subagent.nativeSubagentId)
|
|
23253
|
+
return;
|
|
23254
|
+
this.#emit({
|
|
23255
|
+
type: "subagent.state.changed",
|
|
23256
|
+
nativeSubagentId: subagent.nativeSubagentId,
|
|
23257
|
+
status: subagent.status,
|
|
23258
|
+
...subagent.resultSummary ? { resultSummary: subagent.resultSummary } : {}
|
|
23259
|
+
});
|
|
23260
|
+
}
|
|
23261
|
+
};
|
|
23262
|
+
|
|
22575
23263
|
// dist/grok-models.js
|
|
22576
|
-
function
|
|
23264
|
+
function isRecord13(value) {
|
|
22577
23265
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22578
23266
|
}
|
|
22579
23267
|
function nonBlank(value) {
|
|
@@ -22585,7 +23273,7 @@ function thinkingOptions(value) {
|
|
|
22585
23273
|
const seen = /* @__PURE__ */ new Set();
|
|
22586
23274
|
const options = [];
|
|
22587
23275
|
for (const candidate of value) {
|
|
22588
|
-
if (!
|
|
23276
|
+
if (!isRecord13(candidate) || !nonBlank(candidate.label))
|
|
22589
23277
|
continue;
|
|
22590
23278
|
const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
|
|
22591
23279
|
if (!id.success || seen.has(id.data))
|
|
@@ -22596,7 +23284,7 @@ function thinkingOptions(value) {
|
|
|
22596
23284
|
return options;
|
|
22597
23285
|
}
|
|
22598
23286
|
function parseGrokModelState(value) {
|
|
22599
|
-
if (!
|
|
23287
|
+
if (!isRecord13(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
|
|
22600
23288
|
return null;
|
|
22601
23289
|
}
|
|
22602
23290
|
const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
|
|
@@ -22607,12 +23295,12 @@ function parseGrokModelState(value) {
|
|
|
22607
23295
|
const models = [];
|
|
22608
23296
|
let currentThinkingOptionId;
|
|
22609
23297
|
for (const candidate of value.availableModels) {
|
|
22610
|
-
if (!
|
|
23298
|
+
if (!isRecord13(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
|
|
22611
23299
|
continue;
|
|
22612
23300
|
const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
|
|
22613
23301
|
if (!ref.success)
|
|
22614
23302
|
continue;
|
|
22615
|
-
const metadata =
|
|
23303
|
+
const metadata = isRecord13(candidate._meta) ? candidate._meta : {};
|
|
22616
23304
|
const options2 = thinkingOptions(metadata.reasoningEfforts);
|
|
22617
23305
|
if (typeof metadata.totalContextTokens === "number" && Number.isSafeInteger(metadata.totalContextTokens) && metadata.totalContextTokens > 0) {
|
|
22618
23306
|
contextWindowTokensByModel.set(ref.data.id, metadata.totalContextTokens);
|
|
@@ -22647,10 +23335,10 @@ function parseGrokModelState(value) {
|
|
|
22647
23335
|
};
|
|
22648
23336
|
}
|
|
22649
23337
|
function modelStateFromInitialize(response) {
|
|
22650
|
-
return parseGrokModelState(
|
|
23338
|
+
return parseGrokModelState(isRecord13(response._meta) ? response._meta.modelState : void 0);
|
|
22651
23339
|
}
|
|
22652
23340
|
function modelStateFromSessionResponse(response) {
|
|
22653
|
-
return parseGrokModelState(
|
|
23341
|
+
return parseGrokModelState(isRecord13(response) ? response.models : void 0);
|
|
22654
23342
|
}
|
|
22655
23343
|
function stateForGrokModel(modelState, nativeState, model = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
|
|
22656
23344
|
const selectedModel = model;
|
|
@@ -22674,7 +23362,7 @@ import os4 from "node:os";
|
|
|
22674
23362
|
import path9 from "node:path";
|
|
22675
23363
|
var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
22676
23364
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
22677
|
-
function
|
|
23365
|
+
function isRecord14(value) {
|
|
22678
23366
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22679
23367
|
}
|
|
22680
23368
|
function finitePercent(value) {
|
|
@@ -22704,7 +23392,7 @@ function productUsageFrom(value) {
|
|
|
22704
23392
|
if (!Array.isArray(value))
|
|
22705
23393
|
return void 0;
|
|
22706
23394
|
const products = value.flatMap((entry) => {
|
|
22707
|
-
if (!
|
|
23395
|
+
if (!isRecord14(entry) || typeof entry.product !== "string")
|
|
22708
23396
|
return [];
|
|
22709
23397
|
const usagePercent = finitePercent(entry.usagePercent);
|
|
22710
23398
|
return usagePercent === void 0 ? [] : [{ product: entry.product, usagePercent }];
|
|
@@ -22712,13 +23400,13 @@ function productUsageFrom(value) {
|
|
|
22712
23400
|
return products.length > 0 ? products : void 0;
|
|
22713
23401
|
}
|
|
22714
23402
|
function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
22715
|
-
if (!
|
|
23403
|
+
if (!isRecord14(value) || !isRecord14(value.config))
|
|
22716
23404
|
return null;
|
|
22717
23405
|
const config2 = value.config;
|
|
22718
|
-
const period =
|
|
23406
|
+
const period = isRecord14(config2.currentPeriod) ? config2.currentPeriod : void 0;
|
|
22719
23407
|
const resetsAt = (typeof period?.end === "string" && period.end.length > 0 ? period.end : void 0) ?? (typeof config2.billingPeriodEnd === "string" && config2.billingPeriodEnd.length > 0 ? config2.billingPeriodEnd : void 0);
|
|
22720
|
-
const onDemandCap =
|
|
22721
|
-
const onDemandUsed =
|
|
23408
|
+
const onDemandCap = isRecord14(config2.onDemandCap) ? nonNegativeNumber(config2.onDemandCap.val) : void 0;
|
|
23409
|
+
const onDemandUsed = isRecord14(config2.onDemandUsed) ? nonNegativeNumber(config2.onDemandUsed.val) : void 0;
|
|
22722
23410
|
const usedPercent = finitePercent(config2.creditUsagePercent) ?? (onDemandCap !== void 0 && onDemandCap > 0 && onDemandUsed !== void 0 ? Math.min(100, Math.max(0, onDemandUsed / onDemandCap * 100)) : void 0);
|
|
22723
23411
|
if (usedPercent === void 0)
|
|
22724
23412
|
return null;
|
|
@@ -22732,11 +23420,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
|
|
|
22732
23420
|
};
|
|
22733
23421
|
}
|
|
22734
23422
|
function selectAccessToken(auth, now) {
|
|
22735
|
-
if (!
|
|
23423
|
+
if (!isRecord14(auth))
|
|
22736
23424
|
return null;
|
|
22737
|
-
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) &&
|
|
23425
|
+
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) && isRecord14(value) && typeof value.key === "string" && value.key.length > 0).sort(([left], [right]) => Number(right.startsWith("https://auth.x.ai")) - Number(left.startsWith("https://auth.x.ai")));
|
|
22738
23426
|
for (const [, value] of entries) {
|
|
22739
|
-
if (!
|
|
23427
|
+
if (!isRecord14(value) || typeof value.key !== "string")
|
|
22740
23428
|
continue;
|
|
22741
23429
|
if (typeof value.expires_at === "string") {
|
|
22742
23430
|
const expiresAt = Date.parse(value.expires_at);
|
|
@@ -22808,7 +23496,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
22808
23496
|
|
|
22809
23497
|
// dist/grok-usage.js
|
|
22810
23498
|
var USD_TICKS_PER_DOLLAR = 1e10;
|
|
22811
|
-
function
|
|
23499
|
+
function isRecord15(value) {
|
|
22812
23500
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22813
23501
|
}
|
|
22814
23502
|
function optionalToken(value) {
|
|
@@ -22825,7 +23513,7 @@ function combineUsage(base, next) {
|
|
|
22825
23513
|
return base === null ? next : parseHostUsage({ ...base, ...next });
|
|
22826
23514
|
}
|
|
22827
23515
|
function usageFromNative(value) {
|
|
22828
|
-
if (!
|
|
23516
|
+
if (!isRecord15(value))
|
|
22829
23517
|
return null;
|
|
22830
23518
|
const nativeInputTokens = optionalToken(value.inputTokens);
|
|
22831
23519
|
const cachedRead = optionalToken(value.cachedReadTokens);
|
|
@@ -22854,7 +23542,7 @@ function usageFromPrompt(response) {
|
|
|
22854
23542
|
return response.usage ? usageFromNative(response.usage) : null;
|
|
22855
23543
|
}
|
|
22856
23544
|
function usageFromSignals(value) {
|
|
22857
|
-
if (!
|
|
23545
|
+
if (!isRecord15(value))
|
|
22858
23546
|
return null;
|
|
22859
23547
|
try {
|
|
22860
23548
|
return parseHostUsage({
|
|
@@ -22874,7 +23562,7 @@ var summedUsageFields = [
|
|
|
22874
23562
|
"totalTokens"
|
|
22875
23563
|
];
|
|
22876
23564
|
function nativeCostTicks(value) {
|
|
22877
|
-
if (!
|
|
23565
|
+
if (!isRecord15(value))
|
|
22878
23566
|
return void 0;
|
|
22879
23567
|
const ticks = value.costUsdTicks;
|
|
22880
23568
|
if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
|
|
@@ -22951,7 +23639,7 @@ function usageFromCompact(tokensAfter, contextWindowTokens) {
|
|
|
22951
23639
|
function usageFromUpdate(update, metadata, contextWindowTokens) {
|
|
22952
23640
|
try {
|
|
22953
23641
|
if (update?.sessionUpdate === "usage_update") {
|
|
22954
|
-
const cost =
|
|
23642
|
+
const cost = isRecord15(update.cost) ? update.cost : null;
|
|
22955
23643
|
return parseHostUsage({
|
|
22956
23644
|
contextUsedTokens: update.used,
|
|
22957
23645
|
contextWindowTokens: update.size,
|
|
@@ -22992,7 +23680,8 @@ function capabilitiesForModels(modelState) {
|
|
|
22992
23680
|
selectPermissionMode: true,
|
|
22993
23681
|
permissionModeScope: "atCreate"
|
|
22994
23682
|
},
|
|
22995
|
-
history: { fork: true, forkAcrossCwd: true, rollbackLastTurn: true }
|
|
23683
|
+
history: { fork: true, forkAcrossCwd: true, rollbackLastTurn: true },
|
|
23684
|
+
subagents: { observe: true, readTranscript: true }
|
|
22996
23685
|
};
|
|
22997
23686
|
}
|
|
22998
23687
|
var DEFAULT_CLOSE_TIMEOUT_MS = 2e3;
|
|
@@ -23193,6 +23882,7 @@ var GrokHarnessSession = class {
|
|
|
23193
23882
|
compactionContextWindow: void 0,
|
|
23194
23883
|
compactionTerminal: null,
|
|
23195
23884
|
tools: /* @__PURE__ */ new Map(),
|
|
23885
|
+
subagents: this.#createSubagents(),
|
|
23196
23886
|
completedItems: [],
|
|
23197
23887
|
approvals: /* @__PURE__ */ new Map(),
|
|
23198
23888
|
questions: /* @__PURE__ */ new Map(),
|
|
@@ -23268,6 +23958,7 @@ var GrokHarnessSession = class {
|
|
|
23268
23958
|
compactionContextWindow: void 0,
|
|
23269
23959
|
compactionTerminal: null,
|
|
23270
23960
|
tools: /* @__PURE__ */ new Map(),
|
|
23961
|
+
subagents: this.#createSubagents(),
|
|
23271
23962
|
completedItems: [],
|
|
23272
23963
|
approvals: /* @__PURE__ */ new Map(),
|
|
23273
23964
|
questions: /* @__PURE__ */ new Map(),
|
|
@@ -23597,6 +24288,10 @@ var GrokHarnessSession = class {
|
|
|
23597
24288
|
this.#startTool(active, event);
|
|
23598
24289
|
else if (event.type === "tool.update")
|
|
23599
24290
|
this.#updateTool(active, event);
|
|
24291
|
+
else if (event.type === "subagent.spawned")
|
|
24292
|
+
this.#bindSpawnedSubagent(active, event);
|
|
24293
|
+
else if (event.type === "subagent.finished")
|
|
24294
|
+
this.#finishNativeSubagent(active, event);
|
|
23600
24295
|
else if (event.type === "compaction.started")
|
|
23601
24296
|
this.#startCompaction(active, event);
|
|
23602
24297
|
else if (event.type === "compaction.completed") {
|
|
@@ -23703,9 +24398,44 @@ var GrokHarnessSession = class {
|
|
|
23703
24398
|
update: { type: "text.append", text }
|
|
23704
24399
|
});
|
|
23705
24400
|
}
|
|
24401
|
+
#createSubagents() {
|
|
24402
|
+
return new GrokSubagentLifecycle({
|
|
24403
|
+
newItemId: () => hostItemIdSchema.parse(this.#randomUUID()),
|
|
24404
|
+
emit: (event) => this.#event(event)
|
|
24405
|
+
});
|
|
24406
|
+
}
|
|
24407
|
+
#subagentModelLabel(modelId) {
|
|
24408
|
+
const id = modelId ?? this.#state.effectiveModel?.id;
|
|
24409
|
+
if (!id)
|
|
24410
|
+
return void 0;
|
|
24411
|
+
return this.#modelState.catalog.models.find((model) => model.ref.id === id)?.label ?? id;
|
|
24412
|
+
}
|
|
23706
24413
|
#startTool(active, event) {
|
|
23707
24414
|
this.#completeReasoning(active, { status: "succeeded" });
|
|
23708
24415
|
this.#completeAgent(active, { status: "succeeded" });
|
|
24416
|
+
const operation = grokSubagentOperation(event.name, event.title, event.rawInput);
|
|
24417
|
+
if (operation) {
|
|
24418
|
+
const prompt = grokSubagentPrompt(event.rawInput);
|
|
24419
|
+
const role = grokSubagentRole(event.rawInput);
|
|
24420
|
+
const nativeSubagentId = grokNativeSubagentId(event.rawInput);
|
|
24421
|
+
const model = this.#subagentModelLabel(grokSubagentModel(event.rawInput));
|
|
24422
|
+
const reasoningEffort = this.#state.effectiveThinkingOptionId;
|
|
24423
|
+
active.subagents.start(active.command.turnId, {
|
|
24424
|
+
callId: event.callId,
|
|
24425
|
+
operation,
|
|
24426
|
+
description: grokSubagentDescription(event.rawInput, event.title),
|
|
24427
|
+
...prompt ? { prompt } : {},
|
|
24428
|
+
...role ? { role } : {},
|
|
24429
|
+
...model ? { model } : {},
|
|
24430
|
+
...reasoningEffort ? { reasoningEffort } : {},
|
|
24431
|
+
background: grokSubagentBackground(event.rawInput),
|
|
24432
|
+
...nativeSubagentId ? { nativeSubagentId } : {}
|
|
24433
|
+
});
|
|
24434
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
24435
|
+
this.#completeSubagentTool(active, event.callId, event.status, event);
|
|
24436
|
+
}
|
|
24437
|
+
return;
|
|
24438
|
+
}
|
|
23709
24439
|
let item = startGrokToolItem({
|
|
23710
24440
|
itemId: hostItemIdSchema.parse(this.#randomUUID()),
|
|
23711
24441
|
name: event.name,
|
|
@@ -23724,6 +24454,34 @@ var GrokHarnessSession = class {
|
|
|
23724
24454
|
}
|
|
23725
24455
|
}
|
|
23726
24456
|
#updateTool(active, event) {
|
|
24457
|
+
if (!active.subagents.has(event.callId) && !active.tools.has(event.callId) && grokSubagentOperation(event.name, event.title, event.rawInput)) {
|
|
24458
|
+
this.#startTool(active, {
|
|
24459
|
+
type: "tool.call",
|
|
24460
|
+
callId: event.callId,
|
|
24461
|
+
title: event.title ?? "Grok Subagent",
|
|
24462
|
+
...event.name ? { name: event.name } : {},
|
|
24463
|
+
...event.kind ? { kind: event.kind } : {},
|
|
24464
|
+
...event.status ? { status: event.status } : {},
|
|
24465
|
+
...event.rawInput !== void 0 ? { rawInput: event.rawInput } : {},
|
|
24466
|
+
...event.rawOutput !== void 0 ? { rawOutput: event.rawOutput } : {},
|
|
24467
|
+
...event.content ? { content: event.content } : {}
|
|
24468
|
+
});
|
|
24469
|
+
return;
|
|
24470
|
+
}
|
|
24471
|
+
if (active.subagents.has(event.callId)) {
|
|
24472
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
24473
|
+
this.#completeSubagentTool(active, event.callId, event.status, event);
|
|
24474
|
+
return;
|
|
24475
|
+
}
|
|
24476
|
+
const role = grokSubagentRole(event.rawInput);
|
|
24477
|
+
const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content);
|
|
24478
|
+
active.subagents.update(active.command.turnId, event.callId, {
|
|
24479
|
+
...event.title ? { description: grokSubagentDescription(event.rawInput, event.title) } : {},
|
|
24480
|
+
...role ? { role } : {},
|
|
24481
|
+
...nativeSubagentId ? { nativeSubagentId } : {}
|
|
24482
|
+
});
|
|
24483
|
+
return;
|
|
24484
|
+
}
|
|
23727
24485
|
const tool = active.tools.get(event.callId);
|
|
23728
24486
|
if (!tool)
|
|
23729
24487
|
return;
|
|
@@ -23777,6 +24535,7 @@ var GrokHarnessSession = class {
|
|
|
23777
24535
|
}
|
|
23778
24536
|
} : { status: "succeeded" };
|
|
23779
24537
|
this.#completeItem(active, tool.item, outcome);
|
|
24538
|
+
this.#completeWatchedSubagents(active, tool.item, content, rawOutput);
|
|
23780
24539
|
if (status !== "completed")
|
|
23781
24540
|
return;
|
|
23782
24541
|
const changes = projectGrokFileChanges(content, this.#cwd);
|
|
@@ -23790,6 +24549,52 @@ var GrokHarnessSession = class {
|
|
|
23790
24549
|
this.#event({ type: "item.started", turnId: active.command.turnId, item: fileItem });
|
|
23791
24550
|
this.#completeItem(active, fileItem, { status: "succeeded" });
|
|
23792
24551
|
}
|
|
24552
|
+
#completeSubagentTool(active, callId, status, event) {
|
|
24553
|
+
const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content);
|
|
24554
|
+
const resultSummary = grokSubagentResultSummary(event.content, event.rawOutput);
|
|
24555
|
+
active.subagents.completeSpawn(active.command.turnId, callId, {
|
|
24556
|
+
failed: status === "failed",
|
|
24557
|
+
cancellationRequested: active.cancellationRequested,
|
|
24558
|
+
...nativeSubagentId ? { nativeSubagentId } : {},
|
|
24559
|
+
...resultSummary ? { resultSummary } : {}
|
|
24560
|
+
});
|
|
24561
|
+
}
|
|
24562
|
+
#completeWatchedSubagents(active, item, content, rawOutput) {
|
|
24563
|
+
const name = item.type === "toolExecution" ? item.toolName : item.command;
|
|
24564
|
+
const rawInput = item.type === "toolExecution" ? item.arguments : void 0;
|
|
24565
|
+
const resultSummary = grokSubagentResultSummary(content, rawOutput);
|
|
24566
|
+
for (const settlement of grokSubagentWaitSettlements({
|
|
24567
|
+
name,
|
|
24568
|
+
title: name,
|
|
24569
|
+
rawInput,
|
|
24570
|
+
content,
|
|
24571
|
+
rawOutput
|
|
24572
|
+
})) {
|
|
24573
|
+
active.subagents.completeByNativeId(active.command.turnId, settlement.id, {
|
|
24574
|
+
failed: settlement.status === "failed",
|
|
24575
|
+
cancellationRequested: active.cancellationRequested || settlement.status === "interrupted",
|
|
24576
|
+
status: settlement.status,
|
|
24577
|
+
...settlement.resultSummary ? { resultSummary: settlement.resultSummary } : resultSummary ? { resultSummary } : {}
|
|
24578
|
+
});
|
|
24579
|
+
}
|
|
24580
|
+
}
|
|
24581
|
+
#bindSpawnedSubagent(active, event) {
|
|
24582
|
+
const model = event.model ? this.#subagentModelLabel(event.model) : void 0;
|
|
24583
|
+
active.subagents.bindNativeId(active.command.turnId, {
|
|
24584
|
+
nativeSubagentId: event.nativeSubagentId,
|
|
24585
|
+
...event.description ? { description: event.description } : {},
|
|
24586
|
+
...event.role ? { role: event.role } : {},
|
|
24587
|
+
...model ? { model } : {}
|
|
24588
|
+
});
|
|
24589
|
+
}
|
|
24590
|
+
#finishNativeSubagent(active, event) {
|
|
24591
|
+
active.subagents.completeByNativeId(active.command.turnId, event.nativeSubagentId, {
|
|
24592
|
+
failed: event.status === "failed",
|
|
24593
|
+
cancellationRequested: active.cancellationRequested || event.status === "interrupted",
|
|
24594
|
+
status: event.status,
|
|
24595
|
+
...event.resultSummary ? { resultSummary: event.resultSummary } : {}
|
|
24596
|
+
});
|
|
24597
|
+
}
|
|
23793
24598
|
#completeAgent(active, outcome) {
|
|
23794
24599
|
const item = active.agent;
|
|
23795
24600
|
if (item && active.rawAgentText.length > 0) {
|
|
@@ -23853,6 +24658,7 @@ var GrokHarnessSession = class {
|
|
|
23853
24658
|
const itemOutcome = outcome;
|
|
23854
24659
|
this.#completeReasoning(active, itemOutcome);
|
|
23855
24660
|
this.#completeAgent(active, itemOutcome);
|
|
24661
|
+
active.subagents.finalize(active.command.turnId, itemOutcome);
|
|
23856
24662
|
if (active.compactionItem) {
|
|
23857
24663
|
this.#completeItem(active, active.compactionItem, itemOutcome);
|
|
23858
24664
|
active.compactionItem = null;
|
|
@@ -23930,6 +24736,39 @@ var GrokHarnessSession = class {
|
|
|
23930
24736
|
var GrokAdapter = class {
|
|
23931
24737
|
commandCatalog = grokCommandCatalog;
|
|
23932
24738
|
harnessId = grokHarnessId;
|
|
24739
|
+
subagents = {
|
|
24740
|
+
readSnapshot: async (input) => {
|
|
24741
|
+
if (input.parent.harnessId !== this.harnessId || input.nativeSubagentId.trim().length === 0) {
|
|
24742
|
+
return {
|
|
24743
|
+
ok: false,
|
|
24744
|
+
error: {
|
|
24745
|
+
code: "invalidRequest",
|
|
24746
|
+
message: "Grok Subagent reference is invalid",
|
|
24747
|
+
retryable: false
|
|
24748
|
+
}
|
|
24749
|
+
};
|
|
24750
|
+
}
|
|
24751
|
+
try {
|
|
24752
|
+
const location = await locateGrokNativeSession(this.#environment ? { environment: this.#environment } : {}, input.nativeSubagentId);
|
|
24753
|
+
const cwd = location?.cwd ?? input.cwd;
|
|
24754
|
+
const history = await readGrokNativeHistory(this.#environment ? { cwd, environment: this.#environment } : { cwd }, input.nativeSubagentId);
|
|
24755
|
+
return {
|
|
24756
|
+
ok: true,
|
|
24757
|
+
value: mapGrokReplay(
|
|
24758
|
+
history,
|
|
24759
|
+
this.harnessId,
|
|
24760
|
+
// Host Subagent records keep the parent Native Session identity.
|
|
24761
|
+
input.parent.nativeSessionId,
|
|
24762
|
+
cwd,
|
|
24763
|
+
[],
|
|
24764
|
+
this.#toolOutputLimit
|
|
24765
|
+
)
|
|
24766
|
+
};
|
|
24767
|
+
} catch (error53) {
|
|
24768
|
+
return { ok: false, error: normalizeError(error53, "protocolError") };
|
|
24769
|
+
}
|
|
24770
|
+
}
|
|
24771
|
+
};
|
|
23933
24772
|
#closeTimeoutMs;
|
|
23934
24773
|
#dependencies;
|
|
23935
24774
|
#environment;
|