@karlorz/codexhost-cli-win32-arm64 0.13.3-1 → 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.
@@ -600,7 +600,7 @@ async function readGrokCredentials(environment) {
600
600
  }
601
601
 
602
602
  // dist/grok-adapter.js
603
- import path15 from "node:path";
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, path16) {
1372
- if (!path16)
1371
+ function getElementAtPath(obj, path17) {
1372
+ if (!path17)
1373
1373
  return obj;
1374
- return path16.reduce((acc, key) => acc?.[key], obj);
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(path16, issues) {
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(path16);
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, path16 = []) => {
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 }, [...path16, ...issue2.path]));
1937
+ issue2.errors.map((issues) => processError({ issues }, [...path17, ...issue2.path]));
1938
1938
  } else if (issue2.code === "invalid_key") {
1939
- processError({ issues: issue2.issues }, [...path16, ...issue2.path]);
1939
+ processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
1940
1940
  } else if (issue2.code === "invalid_element") {
1941
- processError({ issues: issue2.issues }, [...path16, ...issue2.path]);
1941
+ processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
1942
1942
  } else {
1943
- const fullpath = [...path16, ...issue2.path];
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, path16 = []) => {
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 }, [...path16, ...issue2.path]));
1974
+ issue2.errors.map((issues) => processError({ issues }, [...path17, ...issue2.path]));
1975
1975
  } else if (issue2.code === "invalid_key") {
1976
- processError({ issues: issue2.issues }, [...path16, ...issue2.path]);
1976
+ processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
1977
1977
  } else if (issue2.code === "invalid_element") {
1978
- processError({ issues: issue2.issues }, [...path16, ...issue2.path]);
1978
+ processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
1979
1979
  } else {
1980
- const fullpath = [...path16, ...issue2.path];
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 path16 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
2013
- for (const seg of path16) {
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 path16 = ref.slice(1).split("/").filter(Boolean);
14706
- if (path16.length === 0) {
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 (path16[0] === defsKey) {
14711
- const key = path16[1];
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 path12 from "node:path";
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 path16 = command.meta?.path;
21017
- return typeof path16 === "string" && /(^|[\\/])SKILL\.md$/u.test(path16) || typeof command.meta?.qualifiedName === "string";
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 path10 from "node:path";
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(path16, added, removed, oldPosInc, options) {
21177
- const last = path16.lastComponent;
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: path16.oldPos + oldPosInc,
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: path16.oldPos + oldPosInc,
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-tool-output.js
21860
- var DEFAULT_GROK_TOOL_OUTPUT_LIMIT = 64e3;
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 numberField(value, key) {
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 (isRecord6(candidate)) {
21893
- const nested = stringField(candidate, "content") ?? stringField(candidate, "text") ?? stringField(candidate, "tool_result") ?? stringField(candidate, "raw_output");
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 (!isRecord6(argumentsValue) || stringField(argumentsValue, "path"))
21991
+ if (!isRecord7(argumentsValue) || stringField2(argumentsValue, "path"))
21916
21992
  return argumentsValue;
21917
- const targetFile = stringField(argumentsValue, "target_file");
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 = stringField(rawInput, "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 isRecord6(rawInput) && rawInput.variant === "Bash" ? command : void 0;
22004
+ return isRecord7(rawInput) && rawInput.variant === "Bash" ? command : void 0;
21929
22005
  }
21930
22006
  function grokCommandCwd(rawInput, fallback) {
21931
- return stringField(rawInput, "cwd") ?? fallback;
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 (!isRecord6(entry))
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" || !isRecord6(entry.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 (!isRecord6(entry))
22046
+ if (!isRecord7(entry))
21971
22047
  continue;
21972
22048
  const image = entry.type === "image" ? entry : entry.type === "content" ? entry.content : null;
21973
- if (!isRecord6(image) || image.type !== "image")
22049
+ if (!isRecord7(image) || image.type !== "image")
21974
22050
  continue;
21975
- const mimeType = stringField(image, "mimeType") ?? stringField(image, "mime_type");
21976
- const data = stringField(image, "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 (!isRecord6(rawOutput))
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, isRecord6(rawOutput.FileContent) ? rawOutput.FileContent : void 0, isRecord6(rawOutput.Content) ? rawOutput.Content : void 0);
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 isRecord7(value) {
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 (!isRecord7(value))
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 stringField2(value, key) {
22083
- if (!isRecord7(value) || typeof value[key] !== "string")
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 (isRecord7(value)) {
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 (isRecord7(rawInput) && rawInput.variant === "Task")
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(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;
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(stringField2(rawInput, "prompt") ?? stringField2(rawInput, "message"), SUMMARY_LIMIT);
22218
+ return bounded(stringField3(rawInput, "prompt") ?? stringField3(rawInput, "message"), SUMMARY_LIMIT);
22143
22219
  }
22144
22220
  function grokSubagentRole(rawInput) {
22145
- return bounded(stringField2(rawInput, "subagent_type") ?? stringField2(rawInput, "agent_type") ?? stringField2(rawInput, "type"), DESCRIPTION_LIMIT);
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 (!isRecord7(rawInput))
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(stringField2(rawInput, "model"), DESCRIPTION_LIMIT);
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 (!isRecord7(update) || typeof update.sessionUpdate !== "string")
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(stringField2(update, "description"), DESCRIPTION_LIMIT);
22193
- const role = bounded(stringField2(update, "subagent_type") ?? stringField2(update, "role"), DESCRIPTION_LIMIT);
22194
- const model2 = bounded(stringField2(update, "model"), DESCRIPTION_LIMIT);
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 (!isRecord7(rawOutput))
22323
+ if (!isRecord8(rawOutput))
22248
22324
  return [];
22249
22325
  if (Array.isArray(rawOutput.results)) {
22250
- return rawOutput.results.filter(isRecord7);
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(isRecord7);
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 (isRecord7(value))
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 (isRecord7(rawOutput) && typeof rawOutput.status === "string")
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 (!isRecord7(value))
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 (!changes)
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
- const fileItem = {
22563
- type: "fileChange",
22564
- itemId: stableId("file-change", turnIndex, ++messageIndex),
22565
- sourceItemIds: [tool.itemId],
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 isRecord8(value) {
22907
+ function isRecord9(value) {
22818
22908
  return typeof value === "object" && value !== null && !Array.isArray(value);
22819
22909
  }
22820
22910
  function isGrokMethodNotFound(error53) {
22821
- if (isRecord8(error53) && error53.code === -32601)
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 (!isRecord8(value) || value.error !== void 0)
22929
+ if (!isRecord9(value) || value.error !== void 0)
22840
22930
  return null;
22841
- const payload = typeof value.newSessionId !== "string" && isRecord8(value.result) ? value.result : value;
22842
- if (!isRecord8(payload) || payload.error !== void 0)
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 (!path10.isAbsolute(value))
22948
+ if (!path11.isAbsolute(value))
22859
22949
  return normalized;
22860
22950
  for (const cwd of cwds) {
22861
- const relative = path10.relative(path10.resolve(cwd), path10.resolve(value));
22862
- if (relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path10.sep}`)) {
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 = path10.resolve(located.cwd);
22928
- const targetCwd = path10.resolve(input.cwd);
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 isRecord9(value) {
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 (!isRecord9(update) || typeof update.sessionUpdate !== "string")
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 isRecord10(value) {
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 (!isRecord10(value))
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 path11 from "node:path";
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 isRecord11(value) {
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 (!isRecord11(value))
23218
+ if (!isRecord12(value))
23129
23219
  return null;
23130
- const payload = typeof value.success !== "boolean" && isRecord11(value.result) ? value.result : value;
23131
- if (!isRecord11(payload) || typeof payload.success !== "boolean")
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 = path11.resolve(located.cwd);
23185
- const targetCwd = path11.resolve(input.cwd);
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,
@@ -23322,16 +23412,16 @@ var GrokTransportError = class extends Error {
23322
23412
  this.name = "GrokTransportError";
23323
23413
  }
23324
23414
  };
23325
- function isRecord12(value) {
23415
+ function isRecord13(value) {
23326
23416
  return typeof value === "object" && value !== null && !Array.isArray(value);
23327
23417
  }
23328
23418
  function acpToolName(update, metadata) {
23329
- if (!isRecord12(update))
23419
+ if (!isRecord13(update))
23330
23420
  return void 0;
23331
23421
  if (typeof update.name === "string" && update.name.length > 0)
23332
23422
  return update.name;
23333
- const meta3 = isRecord12(update._meta) ? update._meta : metadata;
23334
- const tool = meta3 && isRecord12(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
23423
+ const meta3 = isRecord13(update._meta) ? update._meta : metadata;
23424
+ const tool = meta3 && isRecord13(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
23335
23425
  return tool && typeof tool.name === "string" && tool.name.length > 0 ? tool.name : void 0;
23336
23426
  }
23337
23427
  function errorText(error53) {
@@ -23387,7 +23477,7 @@ function signalProcessTree(child, signal) {
23387
23477
  try {
23388
23478
  process.kill(-child.pid, signal);
23389
23479
  } catch (error53) {
23390
- if (!isRecord12(error53) || error53.code !== "ESRCH")
23480
+ if (!isRecord13(error53) || error53.code !== "ESRCH")
23391
23481
  throw error53;
23392
23482
  }
23393
23483
  }
@@ -23478,13 +23568,13 @@ function transportEvent(update, metadata) {
23478
23568
  function grokHomeDir(options) {
23479
23569
  const environment = { ...process.env, ...options.environment };
23480
23570
  const home = environment.HOME ?? environment.USERPROFILE ?? os5.homedir();
23481
- return environment.GROK_HOME ?? path12.join(home, ".grok");
23571
+ return environment.GROK_HOME ?? path13.join(home, ".grok");
23482
23572
  }
23483
23573
  function grokNativeSessionDirectory(options, sessionId) {
23484
- return path12.join(grokHomeDir(options), "sessions", encodeURIComponent(path12.resolve(options.cwd)), sessionId);
23574
+ return path13.join(grokHomeDir(options), "sessions", encodeURIComponent(path13.resolve(options.cwd)), sessionId);
23485
23575
  }
23486
23576
  function nativeSessionFile(options, sessionId, fileName) {
23487
- return path12.join(grokNativeSessionDirectory(options, sessionId), fileName);
23577
+ return path13.join(grokNativeSessionDirectory(options, sessionId), fileName);
23488
23578
  }
23489
23579
  function nativeHistoryPath(options, sessionId) {
23490
23580
  return nativeSessionFile(options, sessionId, "updates.jsonl");
@@ -23497,14 +23587,14 @@ async function readNativeSignals(options, sessionId) {
23497
23587
  }
23498
23588
  }
23499
23589
  function isMissingFile(error53) {
23500
- return isRecord12(error53) && error53.code === "ENOENT";
23590
+ return isRecord13(error53) && error53.code === "ENOENT";
23501
23591
  }
23502
23592
  async function locateGrokNativeSession(options, sessionId) {
23503
23593
  if (sessionId.length === 0)
23504
23594
  return null;
23505
23595
  let entries;
23506
23596
  try {
23507
- entries = await readdir(path12.join(grokHomeDir(options), "sessions"), { withFileTypes: true });
23597
+ entries = await readdir(path13.join(grokHomeDir(options), "sessions"), { withFileTypes: true });
23508
23598
  } catch (error53) {
23509
23599
  if (isMissingFile(error53))
23510
23600
  return null;
@@ -23518,9 +23608,9 @@ async function locateGrokNativeSession(options, sessionId) {
23518
23608
  continue;
23519
23609
  let summaryRaw;
23520
23610
  try {
23521
- summaryRaw = await readFile3(path12.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
23611
+ summaryRaw = await readFile3(path13.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
23522
23612
  } catch (error53) {
23523
- if (isMissingFile(error53) || isRecord12(error53) && error53.code === "ENOTDIR")
23613
+ if (isMissingFile(error53) || isRecord13(error53) && error53.code === "ENOTDIR")
23524
23614
  continue;
23525
23615
  throw new GrokTransportError("unavailable", "Grok Native Session metadata could not be read", {
23526
23616
  cause: error53
@@ -23532,11 +23622,11 @@ async function locateGrokNativeSession(options, sessionId) {
23532
23622
  } catch {
23533
23623
  continue;
23534
23624
  }
23535
- if (!isRecord12(parsed))
23625
+ if (!isRecord13(parsed))
23536
23626
  continue;
23537
23627
  const info = parsed.info;
23538
- const cwd = isRecord12(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path12.resolve(info.cwd) : path12.resolve(decodeURIComponent(entry.name));
23539
- const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path12.resolve(parsed.source_workspace_dir) : void 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;
23540
23630
  matches.push({
23541
23631
  cwd,
23542
23632
  ...sourceWorkspaceDir ? { sourceWorkspaceDir } : {}
@@ -23546,7 +23636,7 @@ async function locateGrokNativeSession(options, sessionId) {
23546
23636
  }
23547
23637
  async function readGrokNativeHistory(options, sessionId) {
23548
23638
  try {
23549
- return parseNativeHistory(await readFile3(nativeHistoryPath({ ...options, cwd: path12.resolve(options.cwd) }, sessionId), "utf8"), sessionId);
23639
+ return parseNativeHistory(await readFile3(nativeHistoryPath({ ...options, cwd: path13.resolve(options.cwd) }, sessionId), "utf8"), sessionId);
23550
23640
  } catch (error53) {
23551
23641
  if (isMissingFile(error53))
23552
23642
  return [];
@@ -23568,12 +23658,12 @@ function parseNativeHistory(contents, sessionId) {
23568
23658
  } catch {
23569
23659
  throw new GrokTransportError("protocolError", "Grok Native history contains invalid JSON");
23570
23660
  }
23571
- if (!isRecord12(record2) || !isRecord12(record2.params))
23661
+ if (!isRecord13(record2) || !isRecord13(record2.params))
23572
23662
  continue;
23573
23663
  const params = record2.params;
23574
- if (params.sessionId !== sessionId || !isRecord12(params.update))
23664
+ if (params.sessionId !== sessionId || !isRecord13(params.update))
23575
23665
  continue;
23576
- const metadata = isRecord12(params._meta) ? params._meta : void 0;
23666
+ const metadata = isRecord13(params._meta) ? params._meta : void 0;
23577
23667
  const event = transportEvent(params.update, metadata);
23578
23668
  if (event)
23579
23669
  events.push(metadata ? { ...event, metadata } : event);
@@ -23635,7 +23725,7 @@ var GrokAcpTransport = class {
23635
23725
  if (!this.#connection)
23636
23726
  throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
23637
23727
  const result = await withTimeout(this.#connection.request("_x.ai/session/usage", { sessionId: this.sessionId }), this.#options.commandTimeoutMs, "Grok Session usage");
23638
- return isRecord12(result) ? result.usage : void 0;
23728
+ return isRecord13(result) ? result.usage : void 0;
23639
23729
  }
23640
23730
  async readHistory(sessionId, cwd = this.#options.cwd) {
23641
23731
  return readGrokNativeHistory({ ...this.#options, cwd }, sessionId);
@@ -23889,7 +23979,7 @@ var GrokAcpTransport = class {
23889
23979
  ...reasoningEffort ? { reasoningEffort } : {},
23890
23980
  ...contextWindowTokens !== void 0 ? { _meta: { contextWindow: contextWindowTokens } } : {}
23891
23981
  });
23892
- if (!isRecord12(response) || !isRecord12(response._meta) || !isRecord12(response._meta.model)) {
23982
+ if (!isRecord13(response) || !isRecord13(response._meta) || !isRecord13(response._meta.model)) {
23893
23983
  throw new GrokTransportError("protocolError", "Grok rejected Model configuration");
23894
23984
  }
23895
23985
  const selected = response._meta.model.Ok;
@@ -23941,7 +24031,7 @@ var GrokAcpTransport = class {
23941
24031
  this.#availableCommands = parseGrokAvailableCommands(update.availableCommands);
23942
24032
  return;
23943
24033
  }
23944
- const metadata = isRecord12(notification._meta) ? notification._meta : void 0;
24034
+ const metadata = isRecord13(notification._meta) ? notification._meta : void 0;
23945
24035
  const event = transportEvent(notification.update, metadata);
23946
24036
  if (!event)
23947
24037
  return;
@@ -23956,7 +24046,7 @@ var GrokAcpTransport = class {
23956
24046
  #handleExtensionNotification(method, params) {
23957
24047
  if (!isGrokExtensionSessionUpdateMethod(method))
23958
24048
  return;
23959
- if (typeof params.sessionId !== "string" || !isRecord12(params.update))
24049
+ if (typeof params.sessionId !== "string" || !isRecord13(params.update))
23960
24050
  return;
23961
24051
  this.#handleUpdate(params);
23962
24052
  }
@@ -23976,7 +24066,7 @@ var GrokAcpTransport = class {
23976
24066
  // dist/session-import.js
23977
24067
  import { createReadStream as createReadStream2 } from "node:fs";
23978
24068
  import { opendir as opendir2, readFile as readFile4, stat } from "node:fs/promises";
23979
- import path13 from "node:path";
24069
+ import path14 from "node:path";
23980
24070
  import { createInterface as createInterface2 } from "node:readline";
23981
24071
 
23982
24072
  // ../../harness-adapter/dist/session-import.js
@@ -24097,7 +24187,7 @@ var SessionImportScope = class {
24097
24187
  // dist/session-import.js
24098
24188
  var MAX_METADATA_BYTES = 4 * 1024 * 1024;
24099
24189
  var SUBAGENT_SESSION_KINDS = /* @__PURE__ */ new Set(["subagent", "subagent_resume"]);
24100
- function isRecord13(value) {
24190
+ function isRecord14(value) {
24101
24191
  return typeof value === "object" && value !== null && !Array.isArray(value);
24102
24192
  }
24103
24193
  async function readJson(file2, signal) {
@@ -24110,7 +24200,7 @@ function processAlive(pid) {
24110
24200
  process.kill(pid, 0);
24111
24201
  return true;
24112
24202
  } catch (error53) {
24113
- return isRecord13(error53) && error53.code === "EPERM";
24203
+ return isRecord14(error53) && error53.code === "EPERM";
24114
24204
  }
24115
24205
  }
24116
24206
  async function firstUserText(file2, signal) {
@@ -24127,10 +24217,10 @@ async function firstUserText(file2, signal) {
24127
24217
  } catch {
24128
24218
  continue;
24129
24219
  }
24130
- const update = isRecord13(entry) && isRecord13(entry.params) ? entry.params.update : null;
24131
- if (!isRecord13(update) || update.sessionUpdate !== "user_message_chunk")
24220
+ const update = isRecord14(entry) && isRecord14(entry.params) ? entry.params.update : null;
24221
+ if (!isRecord14(update) || update.sessionUpdate !== "user_message_chunk")
24132
24222
  continue;
24133
- const text = isRecord13(update.content) ? update.content.text : null;
24223
+ const text = isRecord14(update.content) ? update.content.text : null;
24134
24224
  return typeof text === "string" ? text : "";
24135
24225
  }
24136
24226
  return null;
@@ -24197,7 +24287,7 @@ var GrokSessionImport = class {
24197
24287
  const active = /* @__PURE__ */ new Set();
24198
24288
  let entries;
24199
24289
  try {
24200
- entries = await readJson(path13.join(this.#home(), "active_sessions.json"), signal);
24290
+ entries = await readJson(path14.join(this.#home(), "active_sessions.json"), signal);
24201
24291
  } catch (error53) {
24202
24292
  signal.throwIfAborted();
24203
24293
  if (isStorageAccessError(error53))
@@ -24207,14 +24297,14 @@ var GrokSessionImport = class {
24207
24297
  if (!Array.isArray(entries))
24208
24298
  return active;
24209
24299
  for (const entry of entries) {
24210
- if (isRecord13(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
24300
+ if (isRecord14(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
24211
24301
  active.add(entry.session_id);
24212
24302
  }
24213
24303
  return active;
24214
24304
  }
24215
24305
  /** Session ID to every directory claiming it. Enumerated links are not followed. */
24216
24306
  async #sessionDirectories(signal) {
24217
- const root = path13.join(this.#home(), "sessions");
24307
+ const root = path14.join(this.#home(), "sessions");
24218
24308
  const found = /* @__PURE__ */ new Map();
24219
24309
  const info = await optionalLstat(root);
24220
24310
  if (!info)
@@ -24225,7 +24315,7 @@ var GrokSessionImport = class {
24225
24315
  signal.throwIfAborted();
24226
24316
  if (!workspace.isDirectory())
24227
24317
  continue;
24228
- const workspaceDirectory = path13.join(root, workspace.name);
24318
+ const workspaceDirectory = path14.join(root, workspace.name);
24229
24319
  const sessions = await opendir2(workspaceDirectory).catch((error53) => {
24230
24320
  if (isMissingFileError(error53))
24231
24321
  return null;
@@ -24238,7 +24328,7 @@ var GrokSessionImport = class {
24238
24328
  if (!session.isDirectory())
24239
24329
  continue;
24240
24330
  const directories = found.get(session.name) ?? [];
24241
- directories.push(path13.join(workspaceDirectory, session.name));
24331
+ directories.push(path14.join(workspaceDirectory, session.name));
24242
24332
  found.set(session.name, directories);
24243
24333
  }
24244
24334
  }
@@ -24246,25 +24336,25 @@ var GrokSessionImport = class {
24246
24336
  }
24247
24337
  async #candidate(sessionDirectory, active, signal) {
24248
24338
  signal.throwIfAborted();
24249
- const nativeSessionId = path13.basename(sessionDirectory);
24339
+ const nativeSessionId = path14.basename(sessionDirectory);
24250
24340
  const files = [
24251
- path13.join(sessionDirectory, "summary.json"),
24252
- path13.join(sessionDirectory, "updates.jsonl")
24341
+ path14.join(sessionDirectory, "summary.json"),
24342
+ path14.join(sessionDirectory, "updates.jsonl")
24253
24343
  ];
24254
24344
  return readStableFiles(files, async ([summaryInfo, updates]) => {
24255
24345
  if (!summaryInfo?.isFile() || !updates?.isFile() || summaryInfo.size > MAX_METADATA_BYTES)
24256
24346
  return null;
24257
24347
  try {
24258
24348
  const summary = await readJson(files[0], signal);
24259
- if (!isRecord13(summary) || !isRecord13(summary.info) || summary.info.id !== nativeSessionId)
24349
+ if (!isRecord14(summary) || !isRecord14(summary.info) || summary.info.id !== nativeSessionId)
24260
24350
  return null;
24261
24351
  if (typeof summary.session_kind === "string" && SUBAGENT_SESSION_KINDS.has(summary.session_kind))
24262
24352
  return null;
24263
24353
  const nativeCwd = summary.info.cwd;
24264
- if (typeof nativeCwd !== "string" || !path13.isAbsolute(nativeCwd) || nativeCwd.includes("\0"))
24354
+ if (typeof nativeCwd !== "string" || !path14.isAbsolute(nativeCwd) || nativeCwd.includes("\0"))
24265
24355
  return null;
24266
- const cwd = path13.resolve(nativeCwd);
24267
- if (encodeURIComponent(cwd) !== path13.basename(path13.dirname(sessionDirectory)))
24356
+ const cwd = path14.resolve(nativeCwd);
24357
+ if (encodeURIComponent(cwd) !== path14.basename(path14.dirname(sessionDirectory)))
24268
24358
  return null;
24269
24359
  if (!(await stat(cwd)).isDirectory())
24270
24360
  return null;
@@ -24483,7 +24573,7 @@ var GrokSubagentLifecycle = class {
24483
24573
  };
24484
24574
 
24485
24575
  // dist/grok-models.js
24486
- function isRecord14(value) {
24576
+ function isRecord15(value) {
24487
24577
  return typeof value === "object" && value !== null && !Array.isArray(value);
24488
24578
  }
24489
24579
  function nonBlank(value) {
@@ -24495,7 +24585,7 @@ function thinkingOptions(value) {
24495
24585
  const seen = /* @__PURE__ */ new Set();
24496
24586
  const options = [];
24497
24587
  for (const candidate of value) {
24498
- if (!isRecord14(candidate) || !nonBlank(candidate.label))
24588
+ if (!isRecord15(candidate) || !nonBlank(candidate.label))
24499
24589
  continue;
24500
24590
  const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
24501
24591
  if (!id.success || seen.has(id.data))
@@ -24506,7 +24596,7 @@ function thinkingOptions(value) {
24506
24596
  return options;
24507
24597
  }
24508
24598
  function parseGrokModelState(value) {
24509
- if (!isRecord14(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
24599
+ if (!isRecord15(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
24510
24600
  return null;
24511
24601
  }
24512
24602
  const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
@@ -24518,12 +24608,12 @@ function parseGrokModelState(value) {
24518
24608
  const models = [];
24519
24609
  let currentThinkingOptionId;
24520
24610
  for (const candidate of value.availableModels) {
24521
- if (!isRecord14(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
24611
+ if (!isRecord15(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
24522
24612
  continue;
24523
24613
  const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
24524
24614
  if (!ref.success)
24525
24615
  continue;
24526
- const metadata = isRecord14(candidate._meta) ? candidate._meta : {};
24616
+ const metadata = isRecord15(candidate._meta) ? candidate._meta : {};
24527
24617
  const options2 = thinkingOptions(metadata.reasoningEfforts);
24528
24618
  if (Array.isArray(metadata.contextWindows) && metadata.contextWindows.includes(5e5)) {
24529
24619
  defaultContextWindowTokensByModel.set(ref.data.id, 5e5);
@@ -24562,10 +24652,10 @@ function parseGrokModelState(value) {
24562
24652
  };
24563
24653
  }
24564
24654
  function modelStateFromInitialize(response) {
24565
- return parseGrokModelState(isRecord14(response._meta) ? response._meta.modelState : void 0);
24655
+ return parseGrokModelState(isRecord15(response._meta) ? response._meta.modelState : void 0);
24566
24656
  }
24567
24657
  function modelStateFromSessionResponse(response) {
24568
- return parseGrokModelState(isRecord14(response) ? response.models : void 0);
24658
+ return parseGrokModelState(isRecord15(response) ? response.models : void 0);
24569
24659
  }
24570
24660
  function stateForGrokModel(modelState, nativeState, model2 = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
24571
24661
  const selectedModel = model2;
@@ -24586,10 +24676,10 @@ function stateForGrokModel(modelState, nativeState, model2 = modelState.currentM
24586
24676
  // dist/grok-credits.js
24587
24677
  import { readFile as readFile5 } from "node:fs/promises";
24588
24678
  import os6 from "node:os";
24589
- import path14 from "node:path";
24679
+ import path15 from "node:path";
24590
24680
  var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
24591
24681
  var REQUEST_TIMEOUT_MS = 15e3;
24592
- function isRecord15(value) {
24682
+ function isRecord16(value) {
24593
24683
  return typeof value === "object" && value !== null && !Array.isArray(value);
24594
24684
  }
24595
24685
  function finitePercent(value) {
@@ -24598,7 +24688,7 @@ function finitePercent(value) {
24598
24688
  return Math.min(100, Math.max(0, value));
24599
24689
  }
24600
24690
  function nonNegativeCentValue(value) {
24601
- if (!isRecord15(value))
24691
+ if (!isRecord16(value))
24602
24692
  return void 0;
24603
24693
  const amount = value.val === void 0 ? 0 : value.val;
24604
24694
  if (typeof amount !== "number" || !Number.isFinite(amount) || amount < 0)
@@ -24606,7 +24696,7 @@ function nonNegativeCentValue(value) {
24606
24696
  return amount;
24607
24697
  }
24608
24698
  function grokHome2(environment) {
24609
- return environment.GROK_HOME ?? path14.join(environment.HOME ?? environment.USERPROFILE ?? os6.homedir(), ".grok");
24699
+ return environment.GROK_HOME ?? path15.join(environment.HOME ?? environment.USERPROFILE ?? os6.homedir(), ".grok");
24610
24700
  }
24611
24701
  function periodTypeFrom(value) {
24612
24702
  if (typeof value !== "string")
@@ -24622,7 +24712,7 @@ function productUsageFrom(value) {
24622
24712
  if (!Array.isArray(value))
24623
24713
  return void 0;
24624
24714
  const products = value.flatMap((entry) => {
24625
- if (!isRecord15(entry) || typeof entry.product !== "string")
24715
+ if (!isRecord16(entry) || typeof entry.product !== "string")
24626
24716
  return [];
24627
24717
  const usagePercent = finitePercent(entry.usagePercent);
24628
24718
  const labels = {
@@ -24643,10 +24733,10 @@ function productUsageFrom(value) {
24643
24733
  return products.length > 0 ? products : void 0;
24644
24734
  }
24645
24735
  function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
24646
- if (!isRecord15(value) || !isRecord15(value.config))
24736
+ if (!isRecord16(value) || !isRecord16(value.config))
24647
24737
  return null;
24648
24738
  const config2 = value.config;
24649
- const period = isRecord15(config2.currentPeriod) ? config2.currentPeriod : void 0;
24739
+ const period = isRecord16(config2.currentPeriod) ? config2.currentPeriod : void 0;
24650
24740
  const periodType = periodTypeFrom(period?.type);
24651
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);
24652
24742
  let usedPercent = finitePercent(config2.creditUsagePercent);
@@ -24673,11 +24763,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
24673
24763
  };
24674
24764
  }
24675
24765
  function selectAccessToken(auth, now) {
24676
- if (!isRecord15(auth))
24766
+ if (!isRecord16(auth))
24677
24767
  return null;
24678
- const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) && isRecord15(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")));
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")));
24679
24769
  for (const [, value] of entries) {
24680
- if (!isRecord15(value) || typeof value.key !== "string")
24770
+ if (!isRecord16(value) || typeof value.key !== "string")
24681
24771
  continue;
24682
24772
  if (typeof value.expires_at === "string") {
24683
24773
  const expiresAt = Date.parse(value.expires_at);
@@ -24698,7 +24788,7 @@ async function fetchGrokAccount(input = {}) {
24698
24788
  if ([environment.XAI_API_KEY, environment.GROK_API_KEY, environment.GROK_TOKEN].some((value) => value?.trim()))
24699
24789
  return null;
24700
24790
  const now = input.now ?? /* @__PURE__ */ new Date();
24701
- const authPath = path14.join(grokHome2(environment), "auth.json");
24791
+ const authPath = path15.join(grokHome2(environment), "auth.json");
24702
24792
  const raw = input.readAuthFile ? await input.readAuthFile(authPath) : await readFile5(authPath, "utf8");
24703
24793
  const token = selectAccessToken(JSON.parse(raw), now);
24704
24794
  if (!token)
@@ -24748,7 +24838,7 @@ async function fetchGrokCredits(input = {}) {
24748
24838
 
24749
24839
  // dist/grok-usage.js
24750
24840
  var USD_TICKS_PER_DOLLAR = 1e10;
24751
- function isRecord16(value) {
24841
+ function isRecord17(value) {
24752
24842
  return typeof value === "object" && value !== null && !Array.isArray(value);
24753
24843
  }
24754
24844
  function optionalToken(value) {
@@ -24765,7 +24855,7 @@ function combineUsage(base, next) {
24765
24855
  return base === null ? next : parseHostUsage({ ...base, ...next });
24766
24856
  }
24767
24857
  function usageFromNative(value) {
24768
- if (!isRecord16(value))
24858
+ if (!isRecord17(value))
24769
24859
  return null;
24770
24860
  const inputTokens = optionalToken(value.inputTokens);
24771
24861
  const cachedRead = optionalToken(value.cachedReadTokens);
@@ -24789,7 +24879,7 @@ function usageFromNative(value) {
24789
24879
  }
24790
24880
  }
24791
24881
  function usageFromResponse(value) {
24792
- if (!isRecord16(value))
24882
+ if (!isRecord17(value))
24793
24883
  return null;
24794
24884
  const buckets = [
24795
24885
  value.input_tokens,
@@ -24889,7 +24979,7 @@ var GrokTurnUsage = class {
24889
24979
  }
24890
24980
  };
24891
24981
  function usageFromSignals(value) {
24892
- if (!isRecord16(value))
24982
+ if (!isRecord17(value))
24893
24983
  return null;
24894
24984
  try {
24895
24985
  return parseHostUsage({
@@ -24909,7 +24999,7 @@ var summedUsageFields = [
24909
24999
  "totalTokens"
24910
25000
  ];
24911
25001
  function nativeCostTicks(value) {
24912
- if (!isRecord16(value))
25002
+ if (!isRecord17(value))
24913
25003
  return void 0;
24914
25004
  const ticks = value.costUsdTicks;
24915
25005
  if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
@@ -24917,7 +25007,7 @@ function nativeCostTicks(value) {
24917
25007
  return ticks;
24918
25008
  }
24919
25009
  function sessionCostFromNative(value, initialCostUsd) {
24920
- if (!isRecord16(value))
25010
+ if (!isRecord17(value))
24921
25011
  return void 0;
24922
25012
  if (value.costIsPartial !== void 0 && value.costIsPartial !== false)
24923
25013
  return void 0;
@@ -24946,7 +25036,7 @@ function sessionUsageFromHistory(events) {
24946
25036
  continue;
24947
25037
  const usage = usageFromNative(event.usage);
24948
25038
  const ticks2 = nativeCostTicks(event.usage);
24949
- const complete = isRecord16(event.usage) && (event.usage.usageIsIncomplete === void 0 || event.usage.usageIsIncomplete === false) && usage?.inputTokens !== void 0 && usage.cachedInputTokens !== void 0 && usage.cachedInputTokens <= usage.inputTokens;
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;
24950
25040
  latestByKey.set(key, { usage, complete, ...ticks2 !== void 0 ? { ticks: ticks2 } : {} });
24951
25041
  }
24952
25042
  if (latestByKey.size === 0)
@@ -25000,7 +25090,7 @@ function usageFromCompact(tokensAfter, contextWindowTokens) {
25000
25090
  function usageFromUpdate(update, metadata, contextWindowTokens) {
25001
25091
  try {
25002
25092
  if (update?.sessionUpdate === "usage_update") {
25003
- const cost = isRecord16(update.cost) ? update.cost : null;
25093
+ const cost = isRecord17(update.cost) ? update.cost : null;
25004
25094
  return parseHostUsage({
25005
25095
  contextUsedTokens: update.used,
25006
25096
  contextWindowTokens: update.size,
@@ -25743,7 +25833,12 @@ var GrokHarnessSession = class {
25743
25833
  const projection = projectGrokToolOutput(event.content, event.rawOutput, this.#toolOutputLimit);
25744
25834
  if (hasGrokToolProjection(projection))
25745
25835
  item = applyGrokToolProjection(item, projection);
25746
- active.tools.set(event.callId, { item, ...event.status ? { status: event.status } : {} });
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
+ });
25747
25842
  this.#event({ type: "item.started", turnId: active.command.turnId, item });
25748
25843
  if (event.status === "completed" || event.status === "failed") {
25749
25844
  this.#completeTool(active, event.callId, event.status, event.content, event.rawOutput);
@@ -25809,6 +25904,9 @@ var GrokHarnessSession = class {
25809
25904
  }
25810
25905
  if (event.status)
25811
25906
  tool.status = event.status;
25907
+ const generatedImage = mergeGrokGeneratedImage(tool.generatedImage, projectGrokGeneratedImage(event.content, event.rawOutput));
25908
+ if (generatedImage)
25909
+ tool.generatedImage = generatedImage;
25812
25910
  if (event.status === "completed" || event.status === "failed") {
25813
25911
  this.#completeTool(active, event.callId, event.status, event.content, event.rawOutput);
25814
25912
  }
@@ -25835,16 +25933,21 @@ var GrokHarnessSession = class {
25835
25933
  return;
25836
25934
  this.#completeWatchedSubagents(active, tool.item, content, rawOutput);
25837
25935
  const changes = projectGrokFileChanges(content, this.#cwd);
25838
- if (!changes)
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)
25839
25947
  return;
25840
- const fileItem = {
25841
- type: "fileChange",
25842
- itemId: hostItemIdSchema.parse(this.#randomUUID()),
25843
- sourceItemIds: [tool.item.itemId],
25844
- changes
25845
- };
25846
- this.#event({ type: "item.started", turnId: active.command.turnId, item: fileItem });
25847
- 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" });
25848
25951
  }
25849
25952
  #completeSubagentTool(active, callId, status, event) {
25850
25953
  const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content);
@@ -26159,7 +26262,7 @@ var GrokAdapter = class {
26159
26262
  async inspect(input = {}) {
26160
26263
  if (this.#closePromise)
26161
26264
  return { status: "unavailable", error: invalidState("Grok Adapter is closed") };
26162
- const cwd = path15.resolve(input.cwd ?? process.cwd());
26265
+ const cwd = path16.resolve(input.cwd ?? process.cwd());
26163
26266
  if (!input.refresh) {
26164
26267
  const cached2 = this.#inspectionCache.get(cwd);
26165
26268
  if (cached2)
@@ -26221,7 +26324,7 @@ var GrokAdapter = class {
26221
26324
  }
26222
26325
  };
26223
26326
  }
26224
- const cwd = path15.resolve(input.cwd);
26327
+ const cwd = path16.resolve(input.cwd);
26225
26328
  const parsedRef = input.kind === "resume" ? nativeSessionRefSchema.safeParse(input.nativeRef) : null;
26226
26329
  if (parsedRef && (!parsedRef.success || parsedRef.data.harnessId !== this.harnessId)) {
26227
26330
  return {