@karlorz/codexhost-cli-darwin-x64 0.13.3-0 → 0.13.3-3
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/console-web.js +64 -0
- package/app/host-runtime.mjs +100 -184
- package/app/plugins/grok/plugin.mjs +315 -181
- package/app/renderer-extension.js +211 -5
- package/bin/codexhost +0 -0
- package/libexec/codexhost-shim +0 -0
- package/libexec/codexhost-updater +0 -0
- package/package.json +1 -1
|
@@ -600,7 +600,7 @@ async function readGrokCredentials(environment) {
|
|
|
600
600
|
}
|
|
601
601
|
|
|
602
602
|
// dist/grok-adapter.js
|
|
603
|
-
import
|
|
603
|
+
import path16 from "node:path";
|
|
604
604
|
|
|
605
605
|
// ../../../node_modules/zod/v4/classic/external.js
|
|
606
606
|
var external_exports = {};
|
|
@@ -1368,10 +1368,10 @@ function mergeDefs(...defs) {
|
|
|
1368
1368
|
function cloneDef(schema) {
|
|
1369
1369
|
return mergeDefs(schema._zod.def);
|
|
1370
1370
|
}
|
|
1371
|
-
function getElementAtPath(obj,
|
|
1372
|
-
if (!
|
|
1371
|
+
function getElementAtPath(obj, path17) {
|
|
1372
|
+
if (!path17)
|
|
1373
1373
|
return obj;
|
|
1374
|
-
return
|
|
1374
|
+
return path17.reduce((acc, key) => acc?.[key], obj);
|
|
1375
1375
|
}
|
|
1376
1376
|
function promiseAllObject(promisesObj) {
|
|
1377
1377
|
const keys = Object.keys(promisesObj);
|
|
@@ -1780,11 +1780,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
1780
1780
|
}
|
|
1781
1781
|
return false;
|
|
1782
1782
|
}
|
|
1783
|
-
function prefixIssues(
|
|
1783
|
+
function prefixIssues(path17, issues) {
|
|
1784
1784
|
return issues.map((iss) => {
|
|
1785
1785
|
var _a3;
|
|
1786
1786
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
1787
|
-
iss.path.unshift(
|
|
1787
|
+
iss.path.unshift(path17);
|
|
1788
1788
|
return iss;
|
|
1789
1789
|
});
|
|
1790
1790
|
}
|
|
@@ -1931,16 +1931,16 @@ function flattenError(error53, mapper = (issue2) => issue2.message) {
|
|
|
1931
1931
|
}
|
|
1932
1932
|
function formatError(error53, mapper = (issue2) => issue2.message) {
|
|
1933
1933
|
const fieldErrors = { _errors: [] };
|
|
1934
|
-
const processError = (error54,
|
|
1934
|
+
const processError = (error54, path17 = []) => {
|
|
1935
1935
|
for (const issue2 of error54.issues) {
|
|
1936
1936
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1937
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1937
|
+
issue2.errors.map((issues) => processError({ issues }, [...path17, ...issue2.path]));
|
|
1938
1938
|
} else if (issue2.code === "invalid_key") {
|
|
1939
|
-
processError({ issues: issue2.issues }, [...
|
|
1939
|
+
processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
|
|
1940
1940
|
} else if (issue2.code === "invalid_element") {
|
|
1941
|
-
processError({ issues: issue2.issues }, [...
|
|
1941
|
+
processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
|
|
1942
1942
|
} else {
|
|
1943
|
-
const fullpath = [...
|
|
1943
|
+
const fullpath = [...path17, ...issue2.path];
|
|
1944
1944
|
if (fullpath.length === 0) {
|
|
1945
1945
|
fieldErrors._errors.push(mapper(issue2));
|
|
1946
1946
|
} else {
|
|
@@ -1967,17 +1967,17 @@ function formatError(error53, mapper = (issue2) => issue2.message) {
|
|
|
1967
1967
|
}
|
|
1968
1968
|
function treeifyError(error53, mapper = (issue2) => issue2.message) {
|
|
1969
1969
|
const result = { errors: [] };
|
|
1970
|
-
const processError = (error54,
|
|
1970
|
+
const processError = (error54, path17 = []) => {
|
|
1971
1971
|
var _a3, _b;
|
|
1972
1972
|
for (const issue2 of error54.issues) {
|
|
1973
1973
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1974
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1974
|
+
issue2.errors.map((issues) => processError({ issues }, [...path17, ...issue2.path]));
|
|
1975
1975
|
} else if (issue2.code === "invalid_key") {
|
|
1976
|
-
processError({ issues: issue2.issues }, [...
|
|
1976
|
+
processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
|
|
1977
1977
|
} else if (issue2.code === "invalid_element") {
|
|
1978
|
-
processError({ issues: issue2.issues }, [...
|
|
1978
|
+
processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
|
|
1979
1979
|
} else {
|
|
1980
|
-
const fullpath = [...
|
|
1980
|
+
const fullpath = [...path17, ...issue2.path];
|
|
1981
1981
|
if (fullpath.length === 0) {
|
|
1982
1982
|
result.errors.push(mapper(issue2));
|
|
1983
1983
|
continue;
|
|
@@ -2009,8 +2009,8 @@ function treeifyError(error53, mapper = (issue2) => issue2.message) {
|
|
|
2009
2009
|
}
|
|
2010
2010
|
function toDotPath(_path) {
|
|
2011
2011
|
const segs = [];
|
|
2012
|
-
const
|
|
2013
|
-
for (const seg of
|
|
2012
|
+
const path17 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
2013
|
+
for (const seg of path17) {
|
|
2014
2014
|
if (typeof seg === "number")
|
|
2015
2015
|
segs.push(`[${seg}]`);
|
|
2016
2016
|
else if (typeof seg === "symbol")
|
|
@@ -14702,13 +14702,13 @@ function resolveRef(ref, ctx) {
|
|
|
14702
14702
|
if (!ref.startsWith("#")) {
|
|
14703
14703
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14704
14704
|
}
|
|
14705
|
-
const
|
|
14706
|
-
if (
|
|
14705
|
+
const path17 = ref.slice(1).split("/").filter(Boolean);
|
|
14706
|
+
if (path17.length === 0) {
|
|
14707
14707
|
return ctx.rootSchema;
|
|
14708
14708
|
}
|
|
14709
14709
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14710
|
-
if (
|
|
14711
|
-
const key =
|
|
14710
|
+
if (path17[0] === defsKey) {
|
|
14711
|
+
const key = path17[1];
|
|
14712
14712
|
if (!key || !ctx.defs[key]) {
|
|
14713
14713
|
throw new Error(`Reference not found: ${ref}`);
|
|
14714
14714
|
}
|
|
@@ -16825,7 +16825,7 @@ function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
|
|
|
16825
16825
|
import { spawn, spawnSync } from "node:child_process";
|
|
16826
16826
|
import { readdir, readFile as readFile3 } from "node:fs/promises";
|
|
16827
16827
|
import os5 from "node:os";
|
|
16828
|
-
import
|
|
16828
|
+
import path13 from "node:path";
|
|
16829
16829
|
import { Readable, Writable } from "node:stream";
|
|
16830
16830
|
|
|
16831
16831
|
// ../../../node_modules/@agentclientprotocol/sdk/dist/schema/index.js
|
|
@@ -21013,8 +21013,8 @@ function parseGrokAvailableCommands(value) {
|
|
|
21013
21013
|
});
|
|
21014
21014
|
}
|
|
21015
21015
|
function isGrokSkill(command) {
|
|
21016
|
-
const
|
|
21017
|
-
return typeof
|
|
21016
|
+
const path17 = command.meta?.path;
|
|
21017
|
+
return typeof path17 === "string" && /(^|[\\/])SKILL\.md$/u.test(path17) || typeof command.meta?.qualifiedName === "string";
|
|
21018
21018
|
}
|
|
21019
21019
|
function grokLiveCommands(native) {
|
|
21020
21020
|
return native.map((command) => ({
|
|
@@ -21067,7 +21067,7 @@ function grokInvocation(command, platform = process.platform, modelId) {
|
|
|
21067
21067
|
|
|
21068
21068
|
// dist/grok-fork.js
|
|
21069
21069
|
import { isDeepStrictEqual } from "node:util";
|
|
21070
|
-
import
|
|
21070
|
+
import path11 from "node:path";
|
|
21071
21071
|
|
|
21072
21072
|
// dist/grok-file-change.js
|
|
21073
21073
|
import { Buffer as Buffer2 } from "node:buffer";
|
|
@@ -21173,16 +21173,16 @@ var Diff = class {
|
|
|
21173
21173
|
}
|
|
21174
21174
|
}
|
|
21175
21175
|
}
|
|
21176
|
-
addToPath(
|
|
21177
|
-
const last =
|
|
21176
|
+
addToPath(path17, added, removed, oldPosInc, options) {
|
|
21177
|
+
const last = path17.lastComponent;
|
|
21178
21178
|
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
21179
21179
|
return {
|
|
21180
|
-
oldPos:
|
|
21180
|
+
oldPos: path17.oldPos + oldPosInc,
|
|
21181
21181
|
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
21182
21182
|
};
|
|
21183
21183
|
} else {
|
|
21184
21184
|
return {
|
|
21185
|
-
oldPos:
|
|
21185
|
+
oldPos: path17.oldPos + oldPosInc,
|
|
21186
21186
|
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
21187
21187
|
};
|
|
21188
21188
|
}
|
|
@@ -21561,6 +21561,9 @@ function projectGrokFileChanges(content, cwd, textLimit = DEFAULT_GROK_FILE_CHAN
|
|
|
21561
21561
|
return changes;
|
|
21562
21562
|
}
|
|
21563
21563
|
|
|
21564
|
+
// dist/grok-generated-image.js
|
|
21565
|
+
import path10 from "node:path";
|
|
21566
|
+
|
|
21564
21567
|
// dist/local-media-markdown.js
|
|
21565
21568
|
import { existsSync, statSync } from "node:fs";
|
|
21566
21569
|
import os4 from "node:os";
|
|
@@ -21856,17 +21859,90 @@ function mediaFileExists(absolutePath) {
|
|
|
21856
21859
|
}
|
|
21857
21860
|
}
|
|
21858
21861
|
|
|
21859
|
-
// dist/grok-
|
|
21860
|
-
var
|
|
21861
|
-
var EXECUTE_TOOL_NAMES = /* @__PURE__ */ new Set(["bash", "run_terminal_command", "shell", "cursor_shell"]);
|
|
21862
|
+
// dist/grok-generated-image.js
|
|
21863
|
+
var GENERATED_IMAGE_TYPES = /* @__PURE__ */ new Set(["ImageGen", "ImageEdit"]);
|
|
21862
21864
|
function isRecord6(value) {
|
|
21863
21865
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21864
21866
|
}
|
|
21865
21867
|
function stringField(value, key) {
|
|
21866
21868
|
return isRecord6(value) && typeof value[key] === "string" && value[key].length > 0 ? value[key] : void 0;
|
|
21867
21869
|
}
|
|
21868
|
-
function
|
|
21870
|
+
function fromNativeRecord(value, exists) {
|
|
21869
21871
|
if (!isRecord6(value))
|
|
21872
|
+
return null;
|
|
21873
|
+
const type = stringField(value, "type");
|
|
21874
|
+
const sessionFolder = stringField(value, "session_folder");
|
|
21875
|
+
const typed = type !== void 0 && GENERATED_IMAGE_TYPES.has(type);
|
|
21876
|
+
const imageFolder = sessionFolder === "images";
|
|
21877
|
+
if (!typed && !imageFolder)
|
|
21878
|
+
return null;
|
|
21879
|
+
const savedPath = stringField(value, "path");
|
|
21880
|
+
if (!validAbsolutePath(savedPath))
|
|
21881
|
+
return null;
|
|
21882
|
+
const resolved = path10.resolve(savedPath);
|
|
21883
|
+
if (!exists(resolved))
|
|
21884
|
+
return null;
|
|
21885
|
+
const filename = stringField(value, "filename");
|
|
21886
|
+
return {
|
|
21887
|
+
savedPath: resolved,
|
|
21888
|
+
...filename ? { revisedPrompt: filename } : {}
|
|
21889
|
+
};
|
|
21890
|
+
}
|
|
21891
|
+
function parseJsonObject(text) {
|
|
21892
|
+
const trimmed = text.trim();
|
|
21893
|
+
if (!(trimmed.startsWith("{") && trimmed.endsWith("}")))
|
|
21894
|
+
return null;
|
|
21895
|
+
try {
|
|
21896
|
+
return JSON.parse(trimmed);
|
|
21897
|
+
} catch {
|
|
21898
|
+
return null;
|
|
21899
|
+
}
|
|
21900
|
+
}
|
|
21901
|
+
function projectGrokGeneratedImage(content, rawOutput, exists = mediaFileExists) {
|
|
21902
|
+
const fromRaw = fromNativeRecord(rawOutput, exists);
|
|
21903
|
+
if (fromRaw)
|
|
21904
|
+
return fromRaw;
|
|
21905
|
+
if (!Array.isArray(content))
|
|
21906
|
+
return null;
|
|
21907
|
+
for (const entry of content) {
|
|
21908
|
+
if (!isRecord6(entry))
|
|
21909
|
+
continue;
|
|
21910
|
+
const nested = entry.type === "content" && isRecord6(entry.content) ? entry.content : entry;
|
|
21911
|
+
if (isRecord6(nested) && nested.type === "text" && typeof nested.text === "string") {
|
|
21912
|
+
const parsed = fromNativeRecord(parseJsonObject(nested.text), exists);
|
|
21913
|
+
if (parsed)
|
|
21914
|
+
return parsed;
|
|
21915
|
+
}
|
|
21916
|
+
const direct = fromNativeRecord(nested, exists);
|
|
21917
|
+
if (direct)
|
|
21918
|
+
return direct;
|
|
21919
|
+
}
|
|
21920
|
+
return null;
|
|
21921
|
+
}
|
|
21922
|
+
function mergeGrokGeneratedImage(previous, next) {
|
|
21923
|
+
return next ?? previous;
|
|
21924
|
+
}
|
|
21925
|
+
function grokGeneratedImageItem(image, itemId, sourceItemId) {
|
|
21926
|
+
return {
|
|
21927
|
+
type: "generatedImage",
|
|
21928
|
+
itemId,
|
|
21929
|
+
savedPath: image.savedPath,
|
|
21930
|
+
sourceItemIds: [sourceItemId],
|
|
21931
|
+
...image.revisedPrompt ? { revisedPrompt: image.revisedPrompt } : {}
|
|
21932
|
+
};
|
|
21933
|
+
}
|
|
21934
|
+
|
|
21935
|
+
// dist/grok-tool-output.js
|
|
21936
|
+
var DEFAULT_GROK_TOOL_OUTPUT_LIMIT = 64e3;
|
|
21937
|
+
var EXECUTE_TOOL_NAMES = /* @__PURE__ */ new Set(["bash", "run_terminal_command", "shell", "cursor_shell"]);
|
|
21938
|
+
function isRecord7(value) {
|
|
21939
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21940
|
+
}
|
|
21941
|
+
function stringField2(value, key) {
|
|
21942
|
+
return isRecord7(value) && typeof value[key] === "string" && value[key].length > 0 ? value[key] : void 0;
|
|
21943
|
+
}
|
|
21944
|
+
function numberField(value, key) {
|
|
21945
|
+
if (!isRecord7(value))
|
|
21870
21946
|
return void 0;
|
|
21871
21947
|
const field = value[key];
|
|
21872
21948
|
if (field === null)
|
|
@@ -21889,8 +21965,8 @@ function firstReadableText(...candidates) {
|
|
|
21889
21965
|
for (const candidate of candidates) {
|
|
21890
21966
|
if (typeof candidate === "string" && candidate.length > 0)
|
|
21891
21967
|
return candidate;
|
|
21892
|
-
if (
|
|
21893
|
-
const nested =
|
|
21968
|
+
if (isRecord7(candidate)) {
|
|
21969
|
+
const nested = stringField2(candidate, "content") ?? stringField2(candidate, "text") ?? stringField2(candidate, "tool_result") ?? stringField2(candidate, "raw_output");
|
|
21894
21970
|
if (nested)
|
|
21895
21971
|
return nested;
|
|
21896
21972
|
}
|
|
@@ -21912,23 +21988,23 @@ function grokToolArguments(rawInput) {
|
|
|
21912
21988
|
if (!parsed.success)
|
|
21913
21989
|
return {};
|
|
21914
21990
|
const argumentsValue = parsed.data;
|
|
21915
|
-
if (!
|
|
21991
|
+
if (!isRecord7(argumentsValue) || stringField2(argumentsValue, "path"))
|
|
21916
21992
|
return argumentsValue;
|
|
21917
|
-
const targetFile =
|
|
21993
|
+
const targetFile = stringField2(argumentsValue, "target_file");
|
|
21918
21994
|
return targetFile ? { ...argumentsValue, path: targetFile } : argumentsValue;
|
|
21919
21995
|
}
|
|
21920
21996
|
function grokCommand(name, kind, rawInput) {
|
|
21921
|
-
const command =
|
|
21997
|
+
const command = stringField2(rawInput, "command");
|
|
21922
21998
|
if (!command)
|
|
21923
21999
|
return void 0;
|
|
21924
22000
|
if (kind === "execute")
|
|
21925
22001
|
return command;
|
|
21926
22002
|
if (name && EXECUTE_TOOL_NAMES.has(name))
|
|
21927
22003
|
return command;
|
|
21928
|
-
return
|
|
22004
|
+
return isRecord7(rawInput) && rawInput.variant === "Bash" ? command : void 0;
|
|
21929
22005
|
}
|
|
21930
22006
|
function grokCommandCwd(rawInput, fallback) {
|
|
21931
|
-
return
|
|
22007
|
+
return stringField2(rawInput, "cwd") ?? fallback;
|
|
21932
22008
|
}
|
|
21933
22009
|
function startGrokToolItem(input) {
|
|
21934
22010
|
const name = grokToolName(input.name, input.title);
|
|
@@ -21952,11 +22028,11 @@ function acpContentText(content) {
|
|
|
21952
22028
|
if (!Array.isArray(content))
|
|
21953
22029
|
return "";
|
|
21954
22030
|
return content.flatMap((entry) => {
|
|
21955
|
-
if (!
|
|
22031
|
+
if (!isRecord7(entry))
|
|
21956
22032
|
return [];
|
|
21957
22033
|
if (entry.type === "text" && typeof entry.text === "string")
|
|
21958
22034
|
return [entry.text];
|
|
21959
|
-
if (entry.type !== "content" || !
|
|
22035
|
+
if (entry.type !== "content" || !isRecord7(entry.content))
|
|
21960
22036
|
return [];
|
|
21961
22037
|
return entry.content.type === "text" && typeof entry.content.text === "string" ? [entry.content.text] : [];
|
|
21962
22038
|
}).join("\n");
|
|
@@ -21967,13 +22043,13 @@ function acpContentImages(content, remainingBytes) {
|
|
|
21967
22043
|
const images = [];
|
|
21968
22044
|
let remaining = remainingBytes;
|
|
21969
22045
|
for (const entry of content) {
|
|
21970
|
-
if (!
|
|
22046
|
+
if (!isRecord7(entry))
|
|
21971
22047
|
continue;
|
|
21972
22048
|
const image = entry.type === "image" ? entry : entry.type === "content" ? entry.content : null;
|
|
21973
|
-
if (!
|
|
22049
|
+
if (!isRecord7(image) || image.type !== "image")
|
|
21974
22050
|
continue;
|
|
21975
|
-
const mimeType =
|
|
21976
|
-
const data =
|
|
22051
|
+
const mimeType = stringField2(image, "mimeType") ?? stringField2(image, "mime_type");
|
|
22052
|
+
const data = stringField2(image, "data");
|
|
21977
22053
|
if (!mimeType || !data || data.length > remaining)
|
|
21978
22054
|
continue;
|
|
21979
22055
|
images.push({ type: "image", mimeType, base64Data: data });
|
|
@@ -21993,14 +22069,14 @@ function bashOutput(rawOutput) {
|
|
|
21993
22069
|
function rawOutputProjection(rawOutput) {
|
|
21994
22070
|
if (typeof rawOutput === "string")
|
|
21995
22071
|
return rawOutput.length > 0 ? { text: rawOutput } : {};
|
|
21996
|
-
if (!
|
|
22072
|
+
if (!isRecord7(rawOutput))
|
|
21997
22073
|
return {};
|
|
21998
22074
|
if (rawOutput.type === "Bash" || rawOutput.variant === "Bash" || numberField(rawOutput, "exit_code") !== void 0 || numberField(rawOutput, "exitCode") !== void 0) {
|
|
21999
22075
|
const bash = bashOutput(rawOutput);
|
|
22000
22076
|
if (bash.text !== void 0 || bash.exitCode !== void 0)
|
|
22001
22077
|
return bash;
|
|
22002
22078
|
}
|
|
22003
|
-
const text = firstReadableText(rawOutput.content, rawOutput.text, rawOutput.tool_result, rawOutput.raw_output,
|
|
22079
|
+
const text = firstReadableText(rawOutput.content, rawOutput.text, rawOutput.tool_result, rawOutput.raw_output, isRecord7(rawOutput.FileContent) ? rawOutput.FileContent : void 0, isRecord7(rawOutput.Content) ? rawOutput.Content : void 0);
|
|
22004
22080
|
if (text)
|
|
22005
22081
|
return { text };
|
|
22006
22082
|
if (typeof rawOutput.match_count === "number" && Number.isFinite(rawOutput.match_count)) {
|
|
@@ -22064,11 +22140,11 @@ var WAIT_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
|
22064
22140
|
var KILL_TOOL_NAMES = /* @__PURE__ */ new Set(["kill_command_or_subagent", "kill_task"]);
|
|
22065
22141
|
var DESCRIPTION_LIMIT = 500;
|
|
22066
22142
|
var SUMMARY_LIMIT = 2e3;
|
|
22067
|
-
function
|
|
22143
|
+
function isRecord8(value) {
|
|
22068
22144
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22069
22145
|
}
|
|
22070
22146
|
function idField(value, key) {
|
|
22071
|
-
if (!
|
|
22147
|
+
if (!isRecord8(value))
|
|
22072
22148
|
return void 0;
|
|
22073
22149
|
const field = value[key];
|
|
22074
22150
|
if (typeof field === "string") {
|
|
@@ -22079,8 +22155,8 @@ function idField(value, key) {
|
|
|
22079
22155
|
return String(field);
|
|
22080
22156
|
return void 0;
|
|
22081
22157
|
}
|
|
22082
|
-
function
|
|
22083
|
-
if (!
|
|
22158
|
+
function stringField3(value, key) {
|
|
22159
|
+
if (!isRecord8(value) || typeof value[key] !== "string")
|
|
22084
22160
|
return void 0;
|
|
22085
22161
|
const trimmed = value[key].trim();
|
|
22086
22162
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
@@ -22103,7 +22179,7 @@ function collectIds(value) {
|
|
|
22103
22179
|
};
|
|
22104
22180
|
push(idField(value, "task_id"));
|
|
22105
22181
|
push(idField(value, "subagent_id"));
|
|
22106
|
-
if (
|
|
22182
|
+
if (isRecord8(value)) {
|
|
22107
22183
|
const list = value.task_ids ?? value.subagent_ids;
|
|
22108
22184
|
if (Array.isArray(list)) {
|
|
22109
22185
|
for (const entry of list)
|
|
@@ -22122,7 +22198,7 @@ function grokSubagentOperation(name, title, rawInput) {
|
|
|
22122
22198
|
return "send";
|
|
22123
22199
|
if (SPAWN_TOOL_NAMES.has(id))
|
|
22124
22200
|
return "spawn";
|
|
22125
|
-
if (
|
|
22201
|
+
if (isRecord8(rawInput) && rawInput.variant === "Task")
|
|
22126
22202
|
return "spawn";
|
|
22127
22203
|
return null;
|
|
22128
22204
|
}
|
|
@@ -22136,23 +22212,23 @@ function grokSubagentKill(name, title) {
|
|
|
22136
22212
|
return KILL_TOOL_NAMES.has(toolId(name, title));
|
|
22137
22213
|
}
|
|
22138
22214
|
function grokSubagentDescription(rawInput, title, fallback = "Grok Subagent") {
|
|
22139
|
-
return bounded(
|
|
22215
|
+
return bounded(stringField3(rawInput, "description"), DESCRIPTION_LIMIT) ?? bounded(stringField3(rawInput, "name"), DESCRIPTION_LIMIT) ?? (title && !SPAWN_TOOL_NAMES.has(title.toLowerCase()) && !SEND_TOOL_NAMES.has(title.toLowerCase()) ? bounded(title, DESCRIPTION_LIMIT) : void 0) ?? fallback;
|
|
22140
22216
|
}
|
|
22141
22217
|
function grokSubagentPrompt(rawInput) {
|
|
22142
|
-
return bounded(
|
|
22218
|
+
return bounded(stringField3(rawInput, "prompt") ?? stringField3(rawInput, "message"), SUMMARY_LIMIT);
|
|
22143
22219
|
}
|
|
22144
22220
|
function grokSubagentRole(rawInput) {
|
|
22145
|
-
return bounded(
|
|
22221
|
+
return bounded(stringField3(rawInput, "subagent_type") ?? stringField3(rawInput, "agent_type") ?? stringField3(rawInput, "type"), DESCRIPTION_LIMIT);
|
|
22146
22222
|
}
|
|
22147
22223
|
function grokSubagentBackground(rawInput) {
|
|
22148
|
-
if (!
|
|
22224
|
+
if (!isRecord8(rawInput))
|
|
22149
22225
|
return true;
|
|
22150
22226
|
if (rawInput.background === false || rawInput.run_in_background === false)
|
|
22151
22227
|
return false;
|
|
22152
22228
|
return true;
|
|
22153
22229
|
}
|
|
22154
22230
|
function grokSubagentModel(rawInput) {
|
|
22155
|
-
return bounded(
|
|
22231
|
+
return bounded(stringField3(rawInput, "model"), DESCRIPTION_LIMIT);
|
|
22156
22232
|
}
|
|
22157
22233
|
function grokNativeSubagentId(...candidates) {
|
|
22158
22234
|
const fromKey = (key) => {
|
|
@@ -22183,15 +22259,15 @@ function grokSubagentResultSummary(...candidates) {
|
|
|
22183
22259
|
return void 0;
|
|
22184
22260
|
}
|
|
22185
22261
|
function grokSubagentEventFromUpdate(update) {
|
|
22186
|
-
if (!
|
|
22262
|
+
if (!isRecord8(update) || typeof update.sessionUpdate !== "string")
|
|
22187
22263
|
return null;
|
|
22188
22264
|
const nativeSubagentId = idField(update, "subagent_id") ?? idField(update, "child_session_id");
|
|
22189
22265
|
if (!nativeSubagentId)
|
|
22190
22266
|
return null;
|
|
22191
22267
|
if (update.sessionUpdate === "subagent_spawned") {
|
|
22192
|
-
const description = bounded(
|
|
22193
|
-
const role = bounded(
|
|
22194
|
-
const model2 = bounded(
|
|
22268
|
+
const description = bounded(stringField3(update, "description"), DESCRIPTION_LIMIT);
|
|
22269
|
+
const role = bounded(stringField3(update, "subagent_type") ?? stringField3(update, "role"), DESCRIPTION_LIMIT);
|
|
22270
|
+
const model2 = bounded(stringField3(update, "model"), DESCRIPTION_LIMIT);
|
|
22195
22271
|
return {
|
|
22196
22272
|
type: "subagent.spawned",
|
|
22197
22273
|
nativeSubagentId,
|
|
@@ -22244,14 +22320,14 @@ function grokSubagentWaitSettlements(input) {
|
|
|
22244
22320
|
return ids.map((id) => ({ id, status: overall }));
|
|
22245
22321
|
}
|
|
22246
22322
|
function taskOutputResults(rawOutput) {
|
|
22247
|
-
if (!
|
|
22323
|
+
if (!isRecord8(rawOutput))
|
|
22248
22324
|
return [];
|
|
22249
22325
|
if (Array.isArray(rawOutput.results)) {
|
|
22250
|
-
return rawOutput.results.filter(
|
|
22326
|
+
return rawOutput.results.filter(isRecord8);
|
|
22251
22327
|
}
|
|
22252
22328
|
const nested = firstRecord(rawOutput.MultiResult, rawOutput.multiResult, rawOutput.multi_result);
|
|
22253
22329
|
if (nested && Array.isArray(nested.results)) {
|
|
22254
|
-
return nested.results.filter(
|
|
22330
|
+
return nested.results.filter(isRecord8);
|
|
22255
22331
|
}
|
|
22256
22332
|
const single = firstRecord(rawOutput.Result, rawOutput.result);
|
|
22257
22333
|
if (single)
|
|
@@ -22262,7 +22338,7 @@ function taskOutputResults(rawOutput) {
|
|
|
22262
22338
|
}
|
|
22263
22339
|
function firstRecord(...values) {
|
|
22264
22340
|
for (const value of values) {
|
|
22265
|
-
if (
|
|
22341
|
+
if (isRecord8(value))
|
|
22266
22342
|
return value;
|
|
22267
22343
|
}
|
|
22268
22344
|
return void 0;
|
|
@@ -22285,7 +22361,7 @@ function taskOutputTextSettlements(rawOutput, content, ids) {
|
|
|
22285
22361
|
return settled;
|
|
22286
22362
|
}
|
|
22287
22363
|
function taskOutputStatus(rawOutput, content) {
|
|
22288
|
-
if (
|
|
22364
|
+
if (isRecord8(rawOutput) && typeof rawOutput.status === "string")
|
|
22289
22365
|
return rawOutput.status;
|
|
22290
22366
|
const text = extractText(content) ?? extractText(rawOutput);
|
|
22291
22367
|
if (!text)
|
|
@@ -22344,7 +22420,7 @@ function extractText(value, depth = 0) {
|
|
|
22344
22420
|
const joined = parts.join("\n").trim();
|
|
22345
22421
|
return joined.length > 0 ? joined : void 0;
|
|
22346
22422
|
}
|
|
22347
|
-
if (!
|
|
22423
|
+
if (!isRecord8(value))
|
|
22348
22424
|
return void 0;
|
|
22349
22425
|
if (typeof value.text === "string" && value.text.trim().length > 0)
|
|
22350
22426
|
return value.text.trim();
|
|
@@ -22417,6 +22493,7 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
22417
22493
|
let agent = null;
|
|
22418
22494
|
let reasoning = null;
|
|
22419
22495
|
const tools = /* @__PURE__ */ new Map();
|
|
22496
|
+
const generatedImages = /* @__PURE__ */ new Map();
|
|
22420
22497
|
const mediaRoots = grokMediaResolveRoots(cwd, sessionDirectory);
|
|
22421
22498
|
const subagents = /* @__PURE__ */ new Map();
|
|
22422
22499
|
const subagentAliases = /* @__PURE__ */ new Map();
|
|
@@ -22522,6 +22599,7 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
22522
22599
|
items.push({ item: tool, outcome: { status: "succeeded" } });
|
|
22523
22600
|
}
|
|
22524
22601
|
tools.clear();
|
|
22602
|
+
generatedImages.clear();
|
|
22525
22603
|
for (const item of subagents.values()) {
|
|
22526
22604
|
items.push({ item, outcome: { status: "succeeded" } });
|
|
22527
22605
|
}
|
|
@@ -22535,6 +22613,9 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
22535
22613
|
if (hasGrokToolProjection(projection)) {
|
|
22536
22614
|
tools.set(callId, applyGrokToolProjection(tool, projection));
|
|
22537
22615
|
}
|
|
22616
|
+
const image = mergeGrokGeneratedImage(generatedImages.get(callId), projectGrokGeneratedImage(content, rawOutput));
|
|
22617
|
+
if (image)
|
|
22618
|
+
generatedImages.set(callId, image);
|
|
22538
22619
|
};
|
|
22539
22620
|
const completeTool = (callId, status, content, rawOutput) => {
|
|
22540
22621
|
applyToolProjection(callId, content, rawOutput);
|
|
@@ -22542,6 +22623,8 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
22542
22623
|
if (!tool)
|
|
22543
22624
|
return;
|
|
22544
22625
|
tools.delete(callId);
|
|
22626
|
+
const generatedImage = generatedImages.get(callId);
|
|
22627
|
+
generatedImages.delete(callId);
|
|
22545
22628
|
const outcome = status === "failed" ? {
|
|
22546
22629
|
status: "failed",
|
|
22547
22630
|
error: {
|
|
@@ -22557,15 +22640,21 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
22557
22640
|
if (status !== "completed")
|
|
22558
22641
|
return;
|
|
22559
22642
|
const changes = projectGrokFileChanges(content, cwd);
|
|
22560
|
-
if (
|
|
22643
|
+
if (changes) {
|
|
22644
|
+
const fileItem = {
|
|
22645
|
+
type: "fileChange",
|
|
22646
|
+
itemId: stableId("file-change", turnIndex, ++messageIndex),
|
|
22647
|
+
sourceItemIds: [tool.itemId],
|
|
22648
|
+
changes
|
|
22649
|
+
};
|
|
22650
|
+
items.push({ item: fileItem, outcome: { status: "succeeded" } });
|
|
22651
|
+
}
|
|
22652
|
+
if (!generatedImage)
|
|
22561
22653
|
return;
|
|
22562
|
-
|
|
22563
|
-
|
|
22564
|
-
|
|
22565
|
-
|
|
22566
|
-
changes
|
|
22567
|
-
};
|
|
22568
|
-
items.push({ item: fileItem, outcome: { status: "succeeded" } });
|
|
22654
|
+
items.push({
|
|
22655
|
+
item: grokGeneratedImageItem(generatedImage, stableId("generated-image", turnIndex, ++messageIndex), tool.itemId),
|
|
22656
|
+
outcome: { status: "succeeded" }
|
|
22657
|
+
});
|
|
22569
22658
|
};
|
|
22570
22659
|
const completeTurn = (outcome, terminalKey) => {
|
|
22571
22660
|
if (input.length === 0)
|
|
@@ -22621,6 +22710,7 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
22621
22710
|
agent = null;
|
|
22622
22711
|
reasoning = null;
|
|
22623
22712
|
tools.clear();
|
|
22713
|
+
generatedImages.clear();
|
|
22624
22714
|
subagents.clear();
|
|
22625
22715
|
subagentAliases.clear();
|
|
22626
22716
|
continue;
|
|
@@ -22814,11 +22904,11 @@ var GROK_SESSION_DELETE_METHOD = "_x.ai/session/delete";
|
|
|
22814
22904
|
function error51(code, message, retryable = false) {
|
|
22815
22905
|
return { code, message, retryable };
|
|
22816
22906
|
}
|
|
22817
|
-
function
|
|
22907
|
+
function isRecord9(value) {
|
|
22818
22908
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22819
22909
|
}
|
|
22820
22910
|
function isGrokMethodNotFound(error53) {
|
|
22821
|
-
if (
|
|
22911
|
+
if (isRecord9(error53) && error53.code === -32601)
|
|
22822
22912
|
return true;
|
|
22823
22913
|
const message = error53 instanceof Error ? error53.message : String(error53);
|
|
22824
22914
|
return /method not found/iu.test(message);
|
|
@@ -22836,10 +22926,10 @@ function buildGrokForkParams(input) {
|
|
|
22836
22926
|
};
|
|
22837
22927
|
}
|
|
22838
22928
|
function parseGrokForkResponse(value) {
|
|
22839
|
-
if (!
|
|
22929
|
+
if (!isRecord9(value) || value.error !== void 0)
|
|
22840
22930
|
return null;
|
|
22841
|
-
const payload = typeof value.newSessionId !== "string" &&
|
|
22842
|
-
if (!
|
|
22931
|
+
const payload = typeof value.newSessionId !== "string" && isRecord9(value.result) ? value.result : value;
|
|
22932
|
+
if (!isRecord9(payload) || payload.error !== void 0)
|
|
22843
22933
|
return null;
|
|
22844
22934
|
if (typeof payload.newSessionId !== "string" || payload.newSessionId.length === 0)
|
|
22845
22935
|
return null;
|
|
@@ -22855,11 +22945,11 @@ function parseGrokForkResponse(value) {
|
|
|
22855
22945
|
}
|
|
22856
22946
|
function projectRelativePath(value, cwds) {
|
|
22857
22947
|
const normalized = value.replaceAll("\\", "/");
|
|
22858
|
-
if (!
|
|
22948
|
+
if (!path11.isAbsolute(value))
|
|
22859
22949
|
return normalized;
|
|
22860
22950
|
for (const cwd of cwds) {
|
|
22861
|
-
const relative =
|
|
22862
|
-
if (relative.length > 0 && relative !== ".." && !relative.startsWith(`..${
|
|
22951
|
+
const relative = path11.relative(path11.resolve(cwd), path11.resolve(value));
|
|
22952
|
+
if (relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path11.sep}`)) {
|
|
22863
22953
|
return relative.replaceAll("\\", "/");
|
|
22864
22954
|
}
|
|
22865
22955
|
}
|
|
@@ -22924,8 +23014,8 @@ async function forkGrokSession(input) {
|
|
|
22924
23014
|
error: error51("sessionNotFound", "Grok Native Session is unavailable")
|
|
22925
23015
|
};
|
|
22926
23016
|
}
|
|
22927
|
-
const sourceCwd =
|
|
22928
|
-
const targetCwd =
|
|
23017
|
+
const sourceCwd = path11.resolve(located.cwd);
|
|
23018
|
+
const targetCwd = path11.resolve(input.cwd);
|
|
22929
23019
|
const source = await readSnapshot({ ...input, cwd: sourceCwd }, sourceRef.data.nativeSessionId);
|
|
22930
23020
|
if (!source.ok)
|
|
22931
23021
|
return source;
|
|
@@ -23003,7 +23093,7 @@ var GROK_SESSION_UPDATE_EXTENSION_METHODS = [
|
|
|
23003
23093
|
"x.ai/session_notification",
|
|
23004
23094
|
"_x.ai/session_notification"
|
|
23005
23095
|
];
|
|
23006
|
-
function
|
|
23096
|
+
function isRecord10(value) {
|
|
23007
23097
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23008
23098
|
}
|
|
23009
23099
|
function optionalNonNegativeInt(value) {
|
|
@@ -23024,7 +23114,7 @@ function isGrokExtensionSessionUpdateMethod(method) {
|
|
|
23024
23114
|
return GROK_SESSION_UPDATE_EXTENSION_METHODS.includes(method);
|
|
23025
23115
|
}
|
|
23026
23116
|
function grokCompactionEventFromUpdate(update) {
|
|
23027
|
-
if (!
|
|
23117
|
+
if (!isRecord10(update) || typeof update.sessionUpdate !== "string")
|
|
23028
23118
|
return null;
|
|
23029
23119
|
const tokensUsed = optionalNonNegativeInt(firstPresent(update, ["tokensUsed", "tokens_used"]));
|
|
23030
23120
|
const contextWindowTokens = optionalNonNegativeInt(firstPresent(update, ["contextWindowTokens", "contextWindow", "context_window"]));
|
|
@@ -23063,7 +23153,7 @@ function grokCompactionEventFromUpdate(update) {
|
|
|
23063
23153
|
// dist/grok-manual-compaction.js
|
|
23064
23154
|
var GROK_COMPACT_CONVERSATION_METHOD = "x.ai/compact_conversation";
|
|
23065
23155
|
var GROK_COMPACT_CONVERSATION_FALLBACK_METHOD = "_x.ai/compact_conversation";
|
|
23066
|
-
function
|
|
23156
|
+
function isRecord11(value) {
|
|
23067
23157
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23068
23158
|
}
|
|
23069
23159
|
function optionalNonNegativeInt2(value) {
|
|
@@ -23075,7 +23165,7 @@ function optionalErrorMessage2(value) {
|
|
|
23075
23165
|
function parseGrokCompactResult(value, cancelled = false) {
|
|
23076
23166
|
if (cancelled)
|
|
23077
23167
|
return { outcome: "cancelled" };
|
|
23078
|
-
if (!
|
|
23168
|
+
if (!isRecord11(value))
|
|
23079
23169
|
return { outcome: "succeeded" };
|
|
23080
23170
|
const tokensBefore = optionalNonNegativeInt2(value.tokensBefore ?? value.tokens_before);
|
|
23081
23171
|
const tokensAfter = optionalNonNegativeInt2(value.tokensAfter ?? value.tokens_after);
|
|
@@ -23108,12 +23198,12 @@ function parseGrokCompactResult(value, cancelled = false) {
|
|
|
23108
23198
|
}
|
|
23109
23199
|
|
|
23110
23200
|
// dist/grok-rewind.js
|
|
23111
|
-
import
|
|
23201
|
+
import path12 from "node:path";
|
|
23112
23202
|
var GROK_REWIND_EXECUTE_METHOD = "_x.ai/rewind/execute";
|
|
23113
23203
|
function error52(code, message, retryable = false) {
|
|
23114
23204
|
return { code, message, retryable };
|
|
23115
23205
|
}
|
|
23116
|
-
function
|
|
23206
|
+
function isRecord12(value) {
|
|
23117
23207
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23118
23208
|
}
|
|
23119
23209
|
function buildGrokRewindParams(input) {
|
|
@@ -23125,10 +23215,10 @@ function buildGrokRewindParams(input) {
|
|
|
23125
23215
|
};
|
|
23126
23216
|
}
|
|
23127
23217
|
function parseGrokRewindResponse(value) {
|
|
23128
|
-
if (!
|
|
23218
|
+
if (!isRecord12(value))
|
|
23129
23219
|
return null;
|
|
23130
|
-
const payload = typeof value.success !== "boolean" &&
|
|
23131
|
-
if (!
|
|
23220
|
+
const payload = typeof value.success !== "boolean" && isRecord12(value.result) ? value.result : value;
|
|
23221
|
+
if (!isRecord12(payload) || typeof payload.success !== "boolean")
|
|
23132
23222
|
return null;
|
|
23133
23223
|
return rewindPayload(payload);
|
|
23134
23224
|
}
|
|
@@ -23181,8 +23271,8 @@ async function rewindGrokLastTurn(input) {
|
|
|
23181
23271
|
error: error52("sessionNotFound", "Grok Native Session is unavailable")
|
|
23182
23272
|
};
|
|
23183
23273
|
}
|
|
23184
|
-
const sourceCwd =
|
|
23185
|
-
const targetCwd =
|
|
23274
|
+
const sourceCwd = path12.resolve(located.cwd);
|
|
23275
|
+
const targetCwd = path12.resolve(input.cwd);
|
|
23186
23276
|
if (sourceCwd !== targetCwd) {
|
|
23187
23277
|
return {
|
|
23188
23278
|
ok: false,
|
|
@@ -23281,6 +23371,36 @@ function grokPermissionModeSessionMeta(permissionMode) {
|
|
|
23281
23371
|
};
|
|
23282
23372
|
}
|
|
23283
23373
|
|
|
23374
|
+
// dist/grok-codexhost-session-rules.js
|
|
23375
|
+
var GROK_CODEXHOST_SESSION_RULES = `# Codex Desktop / CodexHost
|
|
23376
|
+
|
|
23377
|
+
CodexHost started this Grok ACP session as an external Thread inside Codex Desktop.
|
|
23378
|
+
|
|
23379
|
+
Never print \`CODEXHOST_THREAD_ID\`, \`CODEXHOST_RUNTIME_TOKEN\`, \`CODEXHOST_RUNTIME_ENDPOINT\`, or other runtime descriptors.
|
|
23380
|
+
|
|
23381
|
+
## Session rules
|
|
23382
|
+
|
|
23383
|
+
1. **Model.** The Desktop composer Model is this Harness's Model. Pick that Harness's real Model before starting voice. For Grok, that is grok-4.6 or grok-4.7. \`flash-max\` is a Gemini Flash Model.
|
|
23384
|
+
|
|
23385
|
+
2. **Working directory.** Start the chat in the real repository (\`codex-host\` or the wiki). A Playground \`realtime-voice-chat*\` folder is a scratch cwd. Ask the user to start a new Thread in the real repo.
|
|
23386
|
+
|
|
23387
|
+
3. **Voice vs tools.** Desktop voice is gpt-live speech plus delegated Harness tasks on this same Thread. Do wiki, MCP, and file-heavy work as text in this Thread.
|
|
23388
|
+
|
|
23389
|
+
4. **Harness-owned tools.** This session's MCP servers and skills belong to this Harness. SkillWiki on Grok is Grok's config, not Claude, Pi, or Codex.
|
|
23390
|
+
|
|
23391
|
+
5. **Desktop chrome.** The window is Codex Desktop. Markdown View preview is a Codex file tab (View preview vs View source). \`file://\` browser tabs stay raw.
|
|
23392
|
+
|
|
23393
|
+
6. **Voice routes.** Official Codex live voice (New API/CPA) is a separate route from Host-owned external \`thread/realtime/*\`. This external Thread uses the Host-owned route.
|
|
23394
|
+
|
|
23395
|
+
Keep Grok Build tools, MCP, and rules inside the native session. An \`AGENT_TOOLS_AND_RULES.md\` dump in the cwd is unnecessary.
|
|
23396
|
+
`;
|
|
23397
|
+
function grokCodexhostSessionMeta(permissionMode) {
|
|
23398
|
+
return {
|
|
23399
|
+
...permissionMode ? grokPermissionModeSessionMeta(permissionMode) : {},
|
|
23400
|
+
rules: GROK_CODEXHOST_SESSION_RULES
|
|
23401
|
+
};
|
|
23402
|
+
}
|
|
23403
|
+
|
|
23284
23404
|
// dist/acp-transport.js
|
|
23285
23405
|
var GrokTransportError = class extends Error {
|
|
23286
23406
|
kind;
|
|
@@ -23292,16 +23412,16 @@ var GrokTransportError = class extends Error {
|
|
|
23292
23412
|
this.name = "GrokTransportError";
|
|
23293
23413
|
}
|
|
23294
23414
|
};
|
|
23295
|
-
function
|
|
23415
|
+
function isRecord13(value) {
|
|
23296
23416
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23297
23417
|
}
|
|
23298
23418
|
function acpToolName(update, metadata) {
|
|
23299
|
-
if (!
|
|
23419
|
+
if (!isRecord13(update))
|
|
23300
23420
|
return void 0;
|
|
23301
23421
|
if (typeof update.name === "string" && update.name.length > 0)
|
|
23302
23422
|
return update.name;
|
|
23303
|
-
const meta3 =
|
|
23304
|
-
const tool = meta3 &&
|
|
23423
|
+
const meta3 = isRecord13(update._meta) ? update._meta : metadata;
|
|
23424
|
+
const tool = meta3 && isRecord13(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
|
|
23305
23425
|
return tool && typeof tool.name === "string" && tool.name.length > 0 ? tool.name : void 0;
|
|
23306
23426
|
}
|
|
23307
23427
|
function errorText(error53) {
|
|
@@ -23357,7 +23477,7 @@ function signalProcessTree(child, signal) {
|
|
|
23357
23477
|
try {
|
|
23358
23478
|
process.kill(-child.pid, signal);
|
|
23359
23479
|
} catch (error53) {
|
|
23360
|
-
if (!
|
|
23480
|
+
if (!isRecord13(error53) || error53.code !== "ESRCH")
|
|
23361
23481
|
throw error53;
|
|
23362
23482
|
}
|
|
23363
23483
|
}
|
|
@@ -23448,13 +23568,13 @@ function transportEvent(update, metadata) {
|
|
|
23448
23568
|
function grokHomeDir(options) {
|
|
23449
23569
|
const environment = { ...process.env, ...options.environment };
|
|
23450
23570
|
const home = environment.HOME ?? environment.USERPROFILE ?? os5.homedir();
|
|
23451
|
-
return environment.GROK_HOME ??
|
|
23571
|
+
return environment.GROK_HOME ?? path13.join(home, ".grok");
|
|
23452
23572
|
}
|
|
23453
23573
|
function grokNativeSessionDirectory(options, sessionId) {
|
|
23454
|
-
return
|
|
23574
|
+
return path13.join(grokHomeDir(options), "sessions", encodeURIComponent(path13.resolve(options.cwd)), sessionId);
|
|
23455
23575
|
}
|
|
23456
23576
|
function nativeSessionFile(options, sessionId, fileName) {
|
|
23457
|
-
return
|
|
23577
|
+
return path13.join(grokNativeSessionDirectory(options, sessionId), fileName);
|
|
23458
23578
|
}
|
|
23459
23579
|
function nativeHistoryPath(options, sessionId) {
|
|
23460
23580
|
return nativeSessionFile(options, sessionId, "updates.jsonl");
|
|
@@ -23467,14 +23587,14 @@ async function readNativeSignals(options, sessionId) {
|
|
|
23467
23587
|
}
|
|
23468
23588
|
}
|
|
23469
23589
|
function isMissingFile(error53) {
|
|
23470
|
-
return
|
|
23590
|
+
return isRecord13(error53) && error53.code === "ENOENT";
|
|
23471
23591
|
}
|
|
23472
23592
|
async function locateGrokNativeSession(options, sessionId) {
|
|
23473
23593
|
if (sessionId.length === 0)
|
|
23474
23594
|
return null;
|
|
23475
23595
|
let entries;
|
|
23476
23596
|
try {
|
|
23477
|
-
entries = await readdir(
|
|
23597
|
+
entries = await readdir(path13.join(grokHomeDir(options), "sessions"), { withFileTypes: true });
|
|
23478
23598
|
} catch (error53) {
|
|
23479
23599
|
if (isMissingFile(error53))
|
|
23480
23600
|
return null;
|
|
@@ -23488,9 +23608,9 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
23488
23608
|
continue;
|
|
23489
23609
|
let summaryRaw;
|
|
23490
23610
|
try {
|
|
23491
|
-
summaryRaw = await readFile3(
|
|
23611
|
+
summaryRaw = await readFile3(path13.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
|
|
23492
23612
|
} catch (error53) {
|
|
23493
|
-
if (isMissingFile(error53) ||
|
|
23613
|
+
if (isMissingFile(error53) || isRecord13(error53) && error53.code === "ENOTDIR")
|
|
23494
23614
|
continue;
|
|
23495
23615
|
throw new GrokTransportError("unavailable", "Grok Native Session metadata could not be read", {
|
|
23496
23616
|
cause: error53
|
|
@@ -23502,11 +23622,11 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
23502
23622
|
} catch {
|
|
23503
23623
|
continue;
|
|
23504
23624
|
}
|
|
23505
|
-
if (!
|
|
23625
|
+
if (!isRecord13(parsed))
|
|
23506
23626
|
continue;
|
|
23507
23627
|
const info = parsed.info;
|
|
23508
|
-
const cwd =
|
|
23509
|
-
const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ?
|
|
23628
|
+
const cwd = isRecord13(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path13.resolve(info.cwd) : path13.resolve(decodeURIComponent(entry.name));
|
|
23629
|
+
const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path13.resolve(parsed.source_workspace_dir) : void 0;
|
|
23510
23630
|
matches.push({
|
|
23511
23631
|
cwd,
|
|
23512
23632
|
...sourceWorkspaceDir ? { sourceWorkspaceDir } : {}
|
|
@@ -23516,7 +23636,7 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
23516
23636
|
}
|
|
23517
23637
|
async function readGrokNativeHistory(options, sessionId) {
|
|
23518
23638
|
try {
|
|
23519
|
-
return parseNativeHistory(await readFile3(nativeHistoryPath({ ...options, cwd:
|
|
23639
|
+
return parseNativeHistory(await readFile3(nativeHistoryPath({ ...options, cwd: path13.resolve(options.cwd) }, sessionId), "utf8"), sessionId);
|
|
23520
23640
|
} catch (error53) {
|
|
23521
23641
|
if (isMissingFile(error53))
|
|
23522
23642
|
return [];
|
|
@@ -23538,12 +23658,12 @@ function parseNativeHistory(contents, sessionId) {
|
|
|
23538
23658
|
} catch {
|
|
23539
23659
|
throw new GrokTransportError("protocolError", "Grok Native history contains invalid JSON");
|
|
23540
23660
|
}
|
|
23541
|
-
if (!
|
|
23661
|
+
if (!isRecord13(record2) || !isRecord13(record2.params))
|
|
23542
23662
|
continue;
|
|
23543
23663
|
const params = record2.params;
|
|
23544
|
-
if (params.sessionId !== sessionId || !
|
|
23664
|
+
if (params.sessionId !== sessionId || !isRecord13(params.update))
|
|
23545
23665
|
continue;
|
|
23546
|
-
const metadata =
|
|
23666
|
+
const metadata = isRecord13(params._meta) ? params._meta : void 0;
|
|
23547
23667
|
const event = transportEvent(params.update, metadata);
|
|
23548
23668
|
if (event)
|
|
23549
23669
|
events.push(metadata ? { ...event, metadata } : event);
|
|
@@ -23605,7 +23725,7 @@ var GrokAcpTransport = class {
|
|
|
23605
23725
|
if (!this.#connection)
|
|
23606
23726
|
throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
|
|
23607
23727
|
const result = await withTimeout(this.#connection.request("_x.ai/session/usage", { sessionId: this.sessionId }), this.#options.commandTimeoutMs, "Grok Session usage");
|
|
23608
|
-
return
|
|
23728
|
+
return isRecord13(result) ? result.usage : void 0;
|
|
23609
23729
|
}
|
|
23610
23730
|
async readHistory(sessionId, cwd = this.#options.cwd) {
|
|
23611
23731
|
return readGrokNativeHistory({ ...this.#options, cwd }, sessionId);
|
|
@@ -23640,7 +23760,7 @@ var GrokAcpTransport = class {
|
|
|
23640
23760
|
const created = await withTimeout(connection.newSession({
|
|
23641
23761
|
cwd: this.#options.cwd,
|
|
23642
23762
|
mcpServers: [],
|
|
23643
|
-
_meta:
|
|
23763
|
+
_meta: grokCodexhostSessionMeta(permissionMode)
|
|
23644
23764
|
}), this.#options.commandTimeoutMs, "Grok Session creation");
|
|
23645
23765
|
session = created;
|
|
23646
23766
|
sessionId = created.sessionId;
|
|
@@ -23657,7 +23777,8 @@ var GrokAcpTransport = class {
|
|
|
23657
23777
|
session = await withTimeout(connection.loadSession({
|
|
23658
23778
|
cwd: this.#options.cwd,
|
|
23659
23779
|
mcpServers: [],
|
|
23660
|
-
sessionId: forked.newSessionId
|
|
23780
|
+
sessionId: forked.newSessionId,
|
|
23781
|
+
_meta: grokCodexhostSessionMeta()
|
|
23661
23782
|
}), this.#options.commandTimeoutMs, "Grok Session load");
|
|
23662
23783
|
} catch (error53) {
|
|
23663
23784
|
throw new GrokTransportError("unavailable", `Grok Fork succeeded as ${forked.newSessionId} but session/load failed`, { cause: error53 });
|
|
@@ -23669,7 +23790,7 @@ var GrokAcpTransport = class {
|
|
|
23669
23790
|
cwd: this.#options.cwd,
|
|
23670
23791
|
mcpServers: [],
|
|
23671
23792
|
sessionId: input.sessionId,
|
|
23672
|
-
|
|
23793
|
+
_meta: grokCodexhostSessionMeta(permissionMode)
|
|
23673
23794
|
}), this.#options.commandTimeoutMs, "Grok Session load");
|
|
23674
23795
|
sessionId = input.sessionId;
|
|
23675
23796
|
if (input.kind === "rewind") {
|
|
@@ -23858,7 +23979,7 @@ var GrokAcpTransport = class {
|
|
|
23858
23979
|
...reasoningEffort ? { reasoningEffort } : {},
|
|
23859
23980
|
...contextWindowTokens !== void 0 ? { _meta: { contextWindow: contextWindowTokens } } : {}
|
|
23860
23981
|
});
|
|
23861
|
-
if (!
|
|
23982
|
+
if (!isRecord13(response) || !isRecord13(response._meta) || !isRecord13(response._meta.model)) {
|
|
23862
23983
|
throw new GrokTransportError("protocolError", "Grok rejected Model configuration");
|
|
23863
23984
|
}
|
|
23864
23985
|
const selected = response._meta.model.Ok;
|
|
@@ -23910,7 +24031,7 @@ var GrokAcpTransport = class {
|
|
|
23910
24031
|
this.#availableCommands = parseGrokAvailableCommands(update.availableCommands);
|
|
23911
24032
|
return;
|
|
23912
24033
|
}
|
|
23913
|
-
const metadata =
|
|
24034
|
+
const metadata = isRecord13(notification._meta) ? notification._meta : void 0;
|
|
23914
24035
|
const event = transportEvent(notification.update, metadata);
|
|
23915
24036
|
if (!event)
|
|
23916
24037
|
return;
|
|
@@ -23925,7 +24046,7 @@ var GrokAcpTransport = class {
|
|
|
23925
24046
|
#handleExtensionNotification(method, params) {
|
|
23926
24047
|
if (!isGrokExtensionSessionUpdateMethod(method))
|
|
23927
24048
|
return;
|
|
23928
|
-
if (typeof params.sessionId !== "string" || !
|
|
24049
|
+
if (typeof params.sessionId !== "string" || !isRecord13(params.update))
|
|
23929
24050
|
return;
|
|
23930
24051
|
this.#handleUpdate(params);
|
|
23931
24052
|
}
|
|
@@ -23945,7 +24066,7 @@ var GrokAcpTransport = class {
|
|
|
23945
24066
|
// dist/session-import.js
|
|
23946
24067
|
import { createReadStream as createReadStream2 } from "node:fs";
|
|
23947
24068
|
import { opendir as opendir2, readFile as readFile4, stat } from "node:fs/promises";
|
|
23948
|
-
import
|
|
24069
|
+
import path14 from "node:path";
|
|
23949
24070
|
import { createInterface as createInterface2 } from "node:readline";
|
|
23950
24071
|
|
|
23951
24072
|
// ../../harness-adapter/dist/session-import.js
|
|
@@ -24066,7 +24187,7 @@ var SessionImportScope = class {
|
|
|
24066
24187
|
// dist/session-import.js
|
|
24067
24188
|
var MAX_METADATA_BYTES = 4 * 1024 * 1024;
|
|
24068
24189
|
var SUBAGENT_SESSION_KINDS = /* @__PURE__ */ new Set(["subagent", "subagent_resume"]);
|
|
24069
|
-
function
|
|
24190
|
+
function isRecord14(value) {
|
|
24070
24191
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24071
24192
|
}
|
|
24072
24193
|
async function readJson(file2, signal) {
|
|
@@ -24079,7 +24200,7 @@ function processAlive(pid) {
|
|
|
24079
24200
|
process.kill(pid, 0);
|
|
24080
24201
|
return true;
|
|
24081
24202
|
} catch (error53) {
|
|
24082
|
-
return
|
|
24203
|
+
return isRecord14(error53) && error53.code === "EPERM";
|
|
24083
24204
|
}
|
|
24084
24205
|
}
|
|
24085
24206
|
async function firstUserText(file2, signal) {
|
|
@@ -24096,10 +24217,10 @@ async function firstUserText(file2, signal) {
|
|
|
24096
24217
|
} catch {
|
|
24097
24218
|
continue;
|
|
24098
24219
|
}
|
|
24099
|
-
const update =
|
|
24100
|
-
if (!
|
|
24220
|
+
const update = isRecord14(entry) && isRecord14(entry.params) ? entry.params.update : null;
|
|
24221
|
+
if (!isRecord14(update) || update.sessionUpdate !== "user_message_chunk")
|
|
24101
24222
|
continue;
|
|
24102
|
-
const text =
|
|
24223
|
+
const text = isRecord14(update.content) ? update.content.text : null;
|
|
24103
24224
|
return typeof text === "string" ? text : "";
|
|
24104
24225
|
}
|
|
24105
24226
|
return null;
|
|
@@ -24166,7 +24287,7 @@ var GrokSessionImport = class {
|
|
|
24166
24287
|
const active = /* @__PURE__ */ new Set();
|
|
24167
24288
|
let entries;
|
|
24168
24289
|
try {
|
|
24169
|
-
entries = await readJson(
|
|
24290
|
+
entries = await readJson(path14.join(this.#home(), "active_sessions.json"), signal);
|
|
24170
24291
|
} catch (error53) {
|
|
24171
24292
|
signal.throwIfAborted();
|
|
24172
24293
|
if (isStorageAccessError(error53))
|
|
@@ -24176,14 +24297,14 @@ var GrokSessionImport = class {
|
|
|
24176
24297
|
if (!Array.isArray(entries))
|
|
24177
24298
|
return active;
|
|
24178
24299
|
for (const entry of entries) {
|
|
24179
|
-
if (
|
|
24300
|
+
if (isRecord14(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
|
|
24180
24301
|
active.add(entry.session_id);
|
|
24181
24302
|
}
|
|
24182
24303
|
return active;
|
|
24183
24304
|
}
|
|
24184
24305
|
/** Session ID to every directory claiming it. Enumerated links are not followed. */
|
|
24185
24306
|
async #sessionDirectories(signal) {
|
|
24186
|
-
const root =
|
|
24307
|
+
const root = path14.join(this.#home(), "sessions");
|
|
24187
24308
|
const found = /* @__PURE__ */ new Map();
|
|
24188
24309
|
const info = await optionalLstat(root);
|
|
24189
24310
|
if (!info)
|
|
@@ -24194,7 +24315,7 @@ var GrokSessionImport = class {
|
|
|
24194
24315
|
signal.throwIfAborted();
|
|
24195
24316
|
if (!workspace.isDirectory())
|
|
24196
24317
|
continue;
|
|
24197
|
-
const workspaceDirectory =
|
|
24318
|
+
const workspaceDirectory = path14.join(root, workspace.name);
|
|
24198
24319
|
const sessions = await opendir2(workspaceDirectory).catch((error53) => {
|
|
24199
24320
|
if (isMissingFileError(error53))
|
|
24200
24321
|
return null;
|
|
@@ -24207,7 +24328,7 @@ var GrokSessionImport = class {
|
|
|
24207
24328
|
if (!session.isDirectory())
|
|
24208
24329
|
continue;
|
|
24209
24330
|
const directories = found.get(session.name) ?? [];
|
|
24210
|
-
directories.push(
|
|
24331
|
+
directories.push(path14.join(workspaceDirectory, session.name));
|
|
24211
24332
|
found.set(session.name, directories);
|
|
24212
24333
|
}
|
|
24213
24334
|
}
|
|
@@ -24215,25 +24336,25 @@ var GrokSessionImport = class {
|
|
|
24215
24336
|
}
|
|
24216
24337
|
async #candidate(sessionDirectory, active, signal) {
|
|
24217
24338
|
signal.throwIfAborted();
|
|
24218
|
-
const nativeSessionId =
|
|
24339
|
+
const nativeSessionId = path14.basename(sessionDirectory);
|
|
24219
24340
|
const files = [
|
|
24220
|
-
|
|
24221
|
-
|
|
24341
|
+
path14.join(sessionDirectory, "summary.json"),
|
|
24342
|
+
path14.join(sessionDirectory, "updates.jsonl")
|
|
24222
24343
|
];
|
|
24223
24344
|
return readStableFiles(files, async ([summaryInfo, updates]) => {
|
|
24224
24345
|
if (!summaryInfo?.isFile() || !updates?.isFile() || summaryInfo.size > MAX_METADATA_BYTES)
|
|
24225
24346
|
return null;
|
|
24226
24347
|
try {
|
|
24227
24348
|
const summary = await readJson(files[0], signal);
|
|
24228
|
-
if (!
|
|
24349
|
+
if (!isRecord14(summary) || !isRecord14(summary.info) || summary.info.id !== nativeSessionId)
|
|
24229
24350
|
return null;
|
|
24230
24351
|
if (typeof summary.session_kind === "string" && SUBAGENT_SESSION_KINDS.has(summary.session_kind))
|
|
24231
24352
|
return null;
|
|
24232
24353
|
const nativeCwd = summary.info.cwd;
|
|
24233
|
-
if (typeof nativeCwd !== "string" || !
|
|
24354
|
+
if (typeof nativeCwd !== "string" || !path14.isAbsolute(nativeCwd) || nativeCwd.includes("\0"))
|
|
24234
24355
|
return null;
|
|
24235
|
-
const cwd =
|
|
24236
|
-
if (encodeURIComponent(cwd) !==
|
|
24356
|
+
const cwd = path14.resolve(nativeCwd);
|
|
24357
|
+
if (encodeURIComponent(cwd) !== path14.basename(path14.dirname(sessionDirectory)))
|
|
24237
24358
|
return null;
|
|
24238
24359
|
if (!(await stat(cwd)).isDirectory())
|
|
24239
24360
|
return null;
|
|
@@ -24452,7 +24573,7 @@ var GrokSubagentLifecycle = class {
|
|
|
24452
24573
|
};
|
|
24453
24574
|
|
|
24454
24575
|
// dist/grok-models.js
|
|
24455
|
-
function
|
|
24576
|
+
function isRecord15(value) {
|
|
24456
24577
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24457
24578
|
}
|
|
24458
24579
|
function nonBlank(value) {
|
|
@@ -24464,7 +24585,7 @@ function thinkingOptions(value) {
|
|
|
24464
24585
|
const seen = /* @__PURE__ */ new Set();
|
|
24465
24586
|
const options = [];
|
|
24466
24587
|
for (const candidate of value) {
|
|
24467
|
-
if (!
|
|
24588
|
+
if (!isRecord15(candidate) || !nonBlank(candidate.label))
|
|
24468
24589
|
continue;
|
|
24469
24590
|
const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
|
|
24470
24591
|
if (!id.success || seen.has(id.data))
|
|
@@ -24475,7 +24596,7 @@ function thinkingOptions(value) {
|
|
|
24475
24596
|
return options;
|
|
24476
24597
|
}
|
|
24477
24598
|
function parseGrokModelState(value) {
|
|
24478
|
-
if (!
|
|
24599
|
+
if (!isRecord15(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
|
|
24479
24600
|
return null;
|
|
24480
24601
|
}
|
|
24481
24602
|
const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
|
|
@@ -24487,12 +24608,12 @@ function parseGrokModelState(value) {
|
|
|
24487
24608
|
const models = [];
|
|
24488
24609
|
let currentThinkingOptionId;
|
|
24489
24610
|
for (const candidate of value.availableModels) {
|
|
24490
|
-
if (!
|
|
24611
|
+
if (!isRecord15(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
|
|
24491
24612
|
continue;
|
|
24492
24613
|
const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
|
|
24493
24614
|
if (!ref.success)
|
|
24494
24615
|
continue;
|
|
24495
|
-
const metadata =
|
|
24616
|
+
const metadata = isRecord15(candidate._meta) ? candidate._meta : {};
|
|
24496
24617
|
const options2 = thinkingOptions(metadata.reasoningEfforts);
|
|
24497
24618
|
if (Array.isArray(metadata.contextWindows) && metadata.contextWindows.includes(5e5)) {
|
|
24498
24619
|
defaultContextWindowTokensByModel.set(ref.data.id, 5e5);
|
|
@@ -24531,10 +24652,10 @@ function parseGrokModelState(value) {
|
|
|
24531
24652
|
};
|
|
24532
24653
|
}
|
|
24533
24654
|
function modelStateFromInitialize(response) {
|
|
24534
|
-
return parseGrokModelState(
|
|
24655
|
+
return parseGrokModelState(isRecord15(response._meta) ? response._meta.modelState : void 0);
|
|
24535
24656
|
}
|
|
24536
24657
|
function modelStateFromSessionResponse(response) {
|
|
24537
|
-
return parseGrokModelState(
|
|
24658
|
+
return parseGrokModelState(isRecord15(response) ? response.models : void 0);
|
|
24538
24659
|
}
|
|
24539
24660
|
function stateForGrokModel(modelState, nativeState, model2 = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
|
|
24540
24661
|
const selectedModel = model2;
|
|
@@ -24555,10 +24676,10 @@ function stateForGrokModel(modelState, nativeState, model2 = modelState.currentM
|
|
|
24555
24676
|
// dist/grok-credits.js
|
|
24556
24677
|
import { readFile as readFile5 } from "node:fs/promises";
|
|
24557
24678
|
import os6 from "node:os";
|
|
24558
|
-
import
|
|
24679
|
+
import path15 from "node:path";
|
|
24559
24680
|
var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
24560
24681
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
24561
|
-
function
|
|
24682
|
+
function isRecord16(value) {
|
|
24562
24683
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24563
24684
|
}
|
|
24564
24685
|
function finitePercent(value) {
|
|
@@ -24567,7 +24688,7 @@ function finitePercent(value) {
|
|
|
24567
24688
|
return Math.min(100, Math.max(0, value));
|
|
24568
24689
|
}
|
|
24569
24690
|
function nonNegativeCentValue(value) {
|
|
24570
|
-
if (!
|
|
24691
|
+
if (!isRecord16(value))
|
|
24571
24692
|
return void 0;
|
|
24572
24693
|
const amount = value.val === void 0 ? 0 : value.val;
|
|
24573
24694
|
if (typeof amount !== "number" || !Number.isFinite(amount) || amount < 0)
|
|
@@ -24575,7 +24696,7 @@ function nonNegativeCentValue(value) {
|
|
|
24575
24696
|
return amount;
|
|
24576
24697
|
}
|
|
24577
24698
|
function grokHome2(environment) {
|
|
24578
|
-
return environment.GROK_HOME ??
|
|
24699
|
+
return environment.GROK_HOME ?? path15.join(environment.HOME ?? environment.USERPROFILE ?? os6.homedir(), ".grok");
|
|
24579
24700
|
}
|
|
24580
24701
|
function periodTypeFrom(value) {
|
|
24581
24702
|
if (typeof value !== "string")
|
|
@@ -24591,7 +24712,7 @@ function productUsageFrom(value) {
|
|
|
24591
24712
|
if (!Array.isArray(value))
|
|
24592
24713
|
return void 0;
|
|
24593
24714
|
const products = value.flatMap((entry) => {
|
|
24594
|
-
if (!
|
|
24715
|
+
if (!isRecord16(entry) || typeof entry.product !== "string")
|
|
24595
24716
|
return [];
|
|
24596
24717
|
const usagePercent = finitePercent(entry.usagePercent);
|
|
24597
24718
|
const labels = {
|
|
@@ -24612,10 +24733,10 @@ function productUsageFrom(value) {
|
|
|
24612
24733
|
return products.length > 0 ? products : void 0;
|
|
24613
24734
|
}
|
|
24614
24735
|
function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
24615
|
-
if (!
|
|
24736
|
+
if (!isRecord16(value) || !isRecord16(value.config))
|
|
24616
24737
|
return null;
|
|
24617
24738
|
const config2 = value.config;
|
|
24618
|
-
const period =
|
|
24739
|
+
const period = isRecord16(config2.currentPeriod) ? config2.currentPeriod : void 0;
|
|
24619
24740
|
const periodType = periodTypeFrom(period?.type);
|
|
24620
24741
|
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);
|
|
24621
24742
|
let usedPercent = finitePercent(config2.creditUsagePercent);
|
|
@@ -24642,11 +24763,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
|
|
|
24642
24763
|
};
|
|
24643
24764
|
}
|
|
24644
24765
|
function selectAccessToken(auth, now) {
|
|
24645
|
-
if (!
|
|
24766
|
+
if (!isRecord16(auth))
|
|
24646
24767
|
return null;
|
|
24647
|
-
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) &&
|
|
24768
|
+
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) && isRecord16(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")));
|
|
24648
24769
|
for (const [, value] of entries) {
|
|
24649
|
-
if (!
|
|
24770
|
+
if (!isRecord16(value) || typeof value.key !== "string")
|
|
24650
24771
|
continue;
|
|
24651
24772
|
if (typeof value.expires_at === "string") {
|
|
24652
24773
|
const expiresAt = Date.parse(value.expires_at);
|
|
@@ -24667,7 +24788,7 @@ async function fetchGrokAccount(input = {}) {
|
|
|
24667
24788
|
if ([environment.XAI_API_KEY, environment.GROK_API_KEY, environment.GROK_TOKEN].some((value) => value?.trim()))
|
|
24668
24789
|
return null;
|
|
24669
24790
|
const now = input.now ?? /* @__PURE__ */ new Date();
|
|
24670
|
-
const authPath =
|
|
24791
|
+
const authPath = path15.join(grokHome2(environment), "auth.json");
|
|
24671
24792
|
const raw = input.readAuthFile ? await input.readAuthFile(authPath) : await readFile5(authPath, "utf8");
|
|
24672
24793
|
const token = selectAccessToken(JSON.parse(raw), now);
|
|
24673
24794
|
if (!token)
|
|
@@ -24717,7 +24838,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
24717
24838
|
|
|
24718
24839
|
// dist/grok-usage.js
|
|
24719
24840
|
var USD_TICKS_PER_DOLLAR = 1e10;
|
|
24720
|
-
function
|
|
24841
|
+
function isRecord17(value) {
|
|
24721
24842
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24722
24843
|
}
|
|
24723
24844
|
function optionalToken(value) {
|
|
@@ -24734,7 +24855,7 @@ function combineUsage(base, next) {
|
|
|
24734
24855
|
return base === null ? next : parseHostUsage({ ...base, ...next });
|
|
24735
24856
|
}
|
|
24736
24857
|
function usageFromNative(value) {
|
|
24737
|
-
if (!
|
|
24858
|
+
if (!isRecord17(value))
|
|
24738
24859
|
return null;
|
|
24739
24860
|
const inputTokens = optionalToken(value.inputTokens);
|
|
24740
24861
|
const cachedRead = optionalToken(value.cachedReadTokens);
|
|
@@ -24758,7 +24879,7 @@ function usageFromNative(value) {
|
|
|
24758
24879
|
}
|
|
24759
24880
|
}
|
|
24760
24881
|
function usageFromResponse(value) {
|
|
24761
|
-
if (!
|
|
24882
|
+
if (!isRecord17(value))
|
|
24762
24883
|
return null;
|
|
24763
24884
|
const buckets = [
|
|
24764
24885
|
value.input_tokens,
|
|
@@ -24858,7 +24979,7 @@ var GrokTurnUsage = class {
|
|
|
24858
24979
|
}
|
|
24859
24980
|
};
|
|
24860
24981
|
function usageFromSignals(value) {
|
|
24861
|
-
if (!
|
|
24982
|
+
if (!isRecord17(value))
|
|
24862
24983
|
return null;
|
|
24863
24984
|
try {
|
|
24864
24985
|
return parseHostUsage({
|
|
@@ -24878,7 +24999,7 @@ var summedUsageFields = [
|
|
|
24878
24999
|
"totalTokens"
|
|
24879
25000
|
];
|
|
24880
25001
|
function nativeCostTicks(value) {
|
|
24881
|
-
if (!
|
|
25002
|
+
if (!isRecord17(value))
|
|
24882
25003
|
return void 0;
|
|
24883
25004
|
const ticks = value.costUsdTicks;
|
|
24884
25005
|
if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
|
|
@@ -24886,7 +25007,7 @@ function nativeCostTicks(value) {
|
|
|
24886
25007
|
return ticks;
|
|
24887
25008
|
}
|
|
24888
25009
|
function sessionCostFromNative(value, initialCostUsd) {
|
|
24889
|
-
if (!
|
|
25010
|
+
if (!isRecord17(value))
|
|
24890
25011
|
return void 0;
|
|
24891
25012
|
if (value.costIsPartial !== void 0 && value.costIsPartial !== false)
|
|
24892
25013
|
return void 0;
|
|
@@ -24915,7 +25036,7 @@ function sessionUsageFromHistory(events) {
|
|
|
24915
25036
|
continue;
|
|
24916
25037
|
const usage = usageFromNative(event.usage);
|
|
24917
25038
|
const ticks2 = nativeCostTicks(event.usage);
|
|
24918
|
-
const complete =
|
|
25039
|
+
const complete = isRecord17(event.usage) && (event.usage.usageIsIncomplete === void 0 || event.usage.usageIsIncomplete === false) && usage?.inputTokens !== void 0 && usage.cachedInputTokens !== void 0 && usage.cachedInputTokens <= usage.inputTokens;
|
|
24919
25040
|
latestByKey.set(key, { usage, complete, ...ticks2 !== void 0 ? { ticks: ticks2 } : {} });
|
|
24920
25041
|
}
|
|
24921
25042
|
if (latestByKey.size === 0)
|
|
@@ -24969,7 +25090,7 @@ function usageFromCompact(tokensAfter, contextWindowTokens) {
|
|
|
24969
25090
|
function usageFromUpdate(update, metadata, contextWindowTokens) {
|
|
24970
25091
|
try {
|
|
24971
25092
|
if (update?.sessionUpdate === "usage_update") {
|
|
24972
|
-
const cost =
|
|
25093
|
+
const cost = isRecord17(update.cost) ? update.cost : null;
|
|
24973
25094
|
return parseHostUsage({
|
|
24974
25095
|
contextUsedTokens: update.used,
|
|
24975
25096
|
contextWindowTokens: update.size,
|
|
@@ -25712,7 +25833,12 @@ var GrokHarnessSession = class {
|
|
|
25712
25833
|
const projection = projectGrokToolOutput(event.content, event.rawOutput, this.#toolOutputLimit);
|
|
25713
25834
|
if (hasGrokToolProjection(projection))
|
|
25714
25835
|
item = applyGrokToolProjection(item, projection);
|
|
25715
|
-
|
|
25836
|
+
const generatedImage = projectGrokGeneratedImage(event.content, event.rawOutput);
|
|
25837
|
+
active.tools.set(event.callId, {
|
|
25838
|
+
item,
|
|
25839
|
+
...event.status ? { status: event.status } : {},
|
|
25840
|
+
...generatedImage ? { generatedImage } : {}
|
|
25841
|
+
});
|
|
25716
25842
|
this.#event({ type: "item.started", turnId: active.command.turnId, item });
|
|
25717
25843
|
if (event.status === "completed" || event.status === "failed") {
|
|
25718
25844
|
this.#completeTool(active, event.callId, event.status, event.content, event.rawOutput);
|
|
@@ -25778,6 +25904,9 @@ var GrokHarnessSession = class {
|
|
|
25778
25904
|
}
|
|
25779
25905
|
if (event.status)
|
|
25780
25906
|
tool.status = event.status;
|
|
25907
|
+
const generatedImage = mergeGrokGeneratedImage(tool.generatedImage, projectGrokGeneratedImage(event.content, event.rawOutput));
|
|
25908
|
+
if (generatedImage)
|
|
25909
|
+
tool.generatedImage = generatedImage;
|
|
25781
25910
|
if (event.status === "completed" || event.status === "failed") {
|
|
25782
25911
|
this.#completeTool(active, event.callId, event.status, event.content, event.rawOutput);
|
|
25783
25912
|
}
|
|
@@ -25804,16 +25933,21 @@ var GrokHarnessSession = class {
|
|
|
25804
25933
|
return;
|
|
25805
25934
|
this.#completeWatchedSubagents(active, tool.item, content, rawOutput);
|
|
25806
25935
|
const changes = projectGrokFileChanges(content, this.#cwd);
|
|
25807
|
-
if (
|
|
25936
|
+
if (changes) {
|
|
25937
|
+
const fileItem = {
|
|
25938
|
+
type: "fileChange",
|
|
25939
|
+
itemId: hostItemIdSchema.parse(this.#randomUUID()),
|
|
25940
|
+
sourceItemIds: [tool.item.itemId],
|
|
25941
|
+
changes
|
|
25942
|
+
};
|
|
25943
|
+
this.#event({ type: "item.started", turnId: active.command.turnId, item: fileItem });
|
|
25944
|
+
this.#completeItem(active, fileItem, { status: "succeeded" });
|
|
25945
|
+
}
|
|
25946
|
+
if (!tool.generatedImage)
|
|
25808
25947
|
return;
|
|
25809
|
-
const
|
|
25810
|
-
|
|
25811
|
-
|
|
25812
|
-
sourceItemIds: [tool.item.itemId],
|
|
25813
|
-
changes
|
|
25814
|
-
};
|
|
25815
|
-
this.#event({ type: "item.started", turnId: active.command.turnId, item: fileItem });
|
|
25816
|
-
this.#completeItem(active, fileItem, { status: "succeeded" });
|
|
25948
|
+
const imageItem = grokGeneratedImageItem(tool.generatedImage, hostItemIdSchema.parse(this.#randomUUID()), tool.item.itemId);
|
|
25949
|
+
this.#event({ type: "item.started", turnId: active.command.turnId, item: imageItem });
|
|
25950
|
+
this.#completeItem(active, imageItem, { status: "succeeded" });
|
|
25817
25951
|
}
|
|
25818
25952
|
#completeSubagentTool(active, callId, status, event) {
|
|
25819
25953
|
const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content);
|
|
@@ -26128,7 +26262,7 @@ var GrokAdapter = class {
|
|
|
26128
26262
|
async inspect(input = {}) {
|
|
26129
26263
|
if (this.#closePromise)
|
|
26130
26264
|
return { status: "unavailable", error: invalidState("Grok Adapter is closed") };
|
|
26131
|
-
const cwd =
|
|
26265
|
+
const cwd = path16.resolve(input.cwd ?? process.cwd());
|
|
26132
26266
|
if (!input.refresh) {
|
|
26133
26267
|
const cached2 = this.#inspectionCache.get(cwd);
|
|
26134
26268
|
if (cached2)
|
|
@@ -26190,7 +26324,7 @@ var GrokAdapter = class {
|
|
|
26190
26324
|
}
|
|
26191
26325
|
};
|
|
26192
26326
|
}
|
|
26193
|
-
const cwd =
|
|
26327
|
+
const cwd = path16.resolve(input.cwd);
|
|
26194
26328
|
const parsedRef = input.kind === "resume" ? nativeSessionRefSchema.safeParse(input.nativeRef) : null;
|
|
26195
26329
|
if (parsedRef && (!parsedRef.success || parsedRef.data.harnessId !== this.harnessId)) {
|
|
26196
26330
|
return {
|