@codexhost/cli-linux-arm64 0.20.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +1 -1
  2. package/app/codexhost-distribution.json +1 -1
  3. package/app/console-server.mjs +27 -6
  4. package/app/console-web.js +35 -7
  5. package/app/desktop-controller.mjs +166 -52
  6. package/app/host-runtime.mjs +35350 -28799
  7. package/app/plugins/antigravity/assets/icon.svg +1 -1
  8. package/app/plugins/antigravity/plugin.mjs +411 -231
  9. package/app/plugins/claude-code/plugin.mjs +538 -109
  10. package/app/plugins/codebuddy/plugin.mjs +36 -6
  11. package/app/plugins/codex-usage/plugin.mjs +36 -6
  12. package/app/plugins/copilot/plugin.mjs +28 -6
  13. package/app/plugins/cursor-cli/plugin.mjs +28 -6
  14. package/app/plugins/deepseek-harness/plugin.mjs +53 -11
  15. package/app/plugins/devin/plugin.mjs +28 -6
  16. package/app/plugins/grok/plugin.mjs +255 -192
  17. package/app/plugins/hermes/plugin.mjs +28 -6
  18. package/app/plugins/kimi-code/plugin.mjs +53 -16
  19. package/app/plugins/kiro-cli/plugin.mjs +28 -6
  20. package/app/plugins/omp/plugin.mjs +143 -28
  21. package/app/plugins/opencode/plugin.mjs +54 -15
  22. package/app/plugins/pi/plugin.mjs +154 -29
  23. package/app/plugins/qoder/plugin.mjs +43 -6
  24. package/app/plugins/qoder-cn/plugin.mjs +43 -6
  25. package/app/plugins/qwen-code/plugin.mjs +28 -6
  26. package/app/plugins/workbuddy/plugin.mjs +36 -6
  27. package/app/plugins/zcode/plugin.mjs +36 -6
  28. package/app/renderer-extension.js +27 -6
  29. package/app/web/assets/index-CN4a4sj0.js +201 -0
  30. package/app/web/assets/{index-D6-hvggd.css → index-DJW4bmyx.css} +1 -1
  31. package/app/web/codexhost-settings.js +35 -7
  32. package/app/web/index.html +2 -2
  33. package/app/web/plugins/deepseek-ai__dsh-api-remotes/client.js +1 -1
  34. package/app/web/plugins/deepseek-ai__dsh-api-session-controller/client.js +7 -7
  35. package/app/web/plugins/deepseek-ai__dsh-client-ui-chat/client.js +9 -9
  36. package/app/web/plugins/deepseek-ai__dsh-client-ui-codexhost/client.js +6 -6
  37. package/app/web/plugins/deepseek-ai__dsh-client-ui-conversation/client.js +22 -22
  38. package/app/web/plugins/deepseek-ai__dsh-client-ui-input-trigger/client.js +1 -1
  39. package/app/web/plugins/deepseek-ai__dsh-client-ui-layout/client.js +2 -2
  40. package/app/web/plugins/deepseek-ai__dsh-client-ui-model-selection/client.js +1 -1
  41. package/app/web/plugins/deepseek-ai__dsh-client-ui-settings-general/client.js +1 -1
  42. package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar/client.js +1 -1
  43. package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-documentpreview/client.js +9 -9
  44. package/app/web/plugins/deepseek-ai__dsh-client-ui-tool/client.js +1 -1
  45. package/app/web/plugins/deepseek-ai__dsh-client-ui-workspace/client.js +2 -2
  46. package/app/web-modules/server.mjs +1123 -722
  47. package/bin/codexhost +0 -0
  48. package/libexec/codexhost-shim +0 -0
  49. package/libexec/codexhost-updater +0 -0
  50. package/package.json +1 -1
  51. package/app/web/assets/index-D85gPBbQ.js +0 -201
@@ -15024,7 +15024,7 @@ var nonNegativeSafeIntegerSchema = external_exports.number().int().safe().nonneg
15024
15024
  var finiteNonNegativeNumberSchema = external_exports.number().finite().nonnegative();
15025
15025
  var cacheHitRatePercentSchema = external_exports.number().finite().min(0).max(100);
15026
15026
  var usageOutputTimingSchema = external_exports.object({
15027
- version: external_exports.literal(3).optional(),
15027
+ version: external_exports.union([external_exports.literal(3), external_exports.literal(4)]).optional(),
15028
15028
  requestId: external_exports.string().min(1),
15029
15029
  turnId: external_exports.string().min(1).max(1024),
15030
15030
  outputTokens: nonNegativeSafeIntegerSchema,
@@ -15032,16 +15032,16 @@ var usageOutputTimingSchema = external_exports.object({
15032
15032
  completedAtMs: nonNegativeSafeIntegerSchema
15033
15033
  }).strict().refine((value) => value.completedAtMs > value.startedAtMs);
15034
15034
  var usageMeasurementSchema = external_exports.object({
15035
- version: external_exports.union([external_exports.literal(2), external_exports.literal(3)]).optional(),
15035
+ version: external_exports.union([external_exports.literal(2), external_exports.literal(3), external_exports.literal(4)]).optional(),
15036
15036
  value: finiteNonNegativeNumberSchema,
15037
15037
  turnId: external_exports.string().min(1).max(1024),
15038
15038
  at: nonNegativeSafeIntegerSchema
15039
15039
  }).strict();
15040
15040
  var usageMeasurementsSchema = external_exports.object({
15041
- // Unversioned intervals can omit hidden thinking time; do not restore them into averages.
15042
- outputTimings: external_exports.array(usageOutputTimingSchema).transform((values) => values.filter((value) => value.version === 3)).optional(),
15041
+ // Older intervals can omit hidden thinking time; do not restore them into averages.
15042
+ outputTimings: external_exports.array(usageOutputTimingSchema).transform((values) => values.filter((value) => value.version === 4)).optional(),
15043
15043
  // Retain independent TTFT facts when dropping incompatible speed measurements.
15044
- outputTokensPerSecond: usageMeasurementSchema.refine((value) => value.version === 3).optional().catch(void 0),
15044
+ outputTokensPerSecond: usageMeasurementSchema.refine((value) => value.version === 4).optional().catch(void 0),
15045
15045
  timeToFirstOutputMs: usageMeasurementSchema.extend({ value: nonNegativeSafeIntegerSchema }).optional()
15046
15046
  }).strict();
15047
15047
  var indicatorTextSchema = (maximum) => harnessLocalizedTextSchema.refine((entries) => Object.values(entries).every((text) => text.length <= maximum));
@@ -15507,6 +15507,11 @@ var clientChannelEventSchema = external_exports.discriminatedUnion("type", [
15507
15507
  cursor: clientChannelCursorSchema,
15508
15508
  cwd: external_exports.string().optional()
15509
15509
  }),
15510
+ external_exports.object({
15511
+ type: external_exports.literal("harness-inspection-changed"),
15512
+ cursor: clientChannelCursorSchema,
15513
+ harnessId: external_exports.string().min(1)
15514
+ }),
15510
15515
  external_exports.object({ type: external_exports.literal("display-settings-changed"), cursor: clientChannelCursorSchema }),
15511
15516
  external_exports.object({
15512
15517
  type: external_exports.literal("preferences-changed"),
@@ -15578,6 +15583,8 @@ var clientItemTruncationSchema = external_exports.object({
15578
15583
  var clientTurnSchema = external_exports.object({
15579
15584
  id: external_exports.string().min(1),
15580
15585
  status: external_exports.string().min(1),
15586
+ /** Native history has no terminal evidence; Desktop's status vocabulary cannot express this. */
15587
+ codexhostTurnOutcome: external_exports.object({ status: external_exports.literal("unknown"), reason: external_exports.string() }).optional(),
15581
15588
  items: external_exports.array(external_exports.object({ id: external_exports.string().min(1), type: external_exports.string().min(1) }).passthrough()),
15582
15589
  /** Original file operations, independent of the cumulative Desktop fileChange card.
15583
15590
  * Insert before the named non-file Item; null appends at the end of the Turn.
@@ -16794,6 +16801,7 @@ var THREAD_WATCH_NOTICE_OUTCOMES = [
16794
16801
  "completed",
16795
16802
  "failed",
16796
16803
  "interrupted",
16804
+ "needsInput",
16797
16805
  "timedOut",
16798
16806
  "unreadable",
16799
16807
  "notFound"
@@ -16840,13 +16848,26 @@ var target = { hostId: identity.regex(/^remote-(?:ssh(?:-|:)|control:)/u) };
16840
16848
  var thread = { ...target, threadId: identity };
16841
16849
  var remoteSessionOperationSchema = external_exports.discriminatedUnion("kind", [
16842
16850
  external_exports.strictObject({ kind: external_exports.literal("hosts") }),
16851
+ external_exports.strictObject({ kind: external_exports.literal("status"), ...thread }),
16843
16852
  external_exports.strictObject({
16844
16853
  kind: external_exports.literal("list"),
16845
16854
  ...target,
16846
16855
  cursor: external_exports.string().nullable(),
16847
16856
  archived: external_exports.boolean()
16848
16857
  }),
16849
- external_exports.strictObject({ kind: external_exports.literal("read"), ...thread }),
16858
+ external_exports.strictObject({
16859
+ kind: external_exports.literal("read"),
16860
+ ...thread,
16861
+ page: external_exports.strictObject({
16862
+ cursor: external_exports.string().min(1).max(8192).nullable(),
16863
+ epoch: identity.optional(),
16864
+ sortDirection: external_exports.enum(["asc", "desc"]).optional(),
16865
+ limit: external_exports.number().int().min(1).max(20).optional()
16866
+ }).refine((page) => page.cursor === null || page.epoch !== void 0, {
16867
+ message: "A history continuation requires its connection epoch"
16868
+ }).optional()
16869
+ }),
16870
+ external_exports.strictObject({ kind: external_exports.literal("usage"), ...thread, epoch: identity }),
16850
16871
  external_exports.strictObject({
16851
16872
  kind: external_exports.literal("configure"),
16852
16873
  ...thread,
@@ -17225,6 +17246,7 @@ var requestTokenFields = [
17225
17246
  "cacheWrite1hInputTokens",
17226
17247
  "outputTokens",
17227
17248
  "reasoningOutputTokens",
17249
+ "timedOutputTokens",
17228
17250
  "startedAtMs",
17229
17251
  "completedAtMs"
17230
17252
  ];
@@ -22199,6 +22221,107 @@ function grokLiveCommands(native) {
22199
22221
  }));
22200
22222
  }
22201
22223
 
22224
+ // dist/grok-models.js
22225
+ function isRecord5(value) {
22226
+ return typeof value === "object" && value !== null && !Array.isArray(value);
22227
+ }
22228
+ function nonBlank(value) {
22229
+ return typeof value === "string" && value.trim().length > 0;
22230
+ }
22231
+ function thinkingOptions(value) {
22232
+ if (!Array.isArray(value))
22233
+ return [];
22234
+ const seen = /* @__PURE__ */ new Set();
22235
+ const options = [];
22236
+ for (const candidate of value) {
22237
+ if (!isRecord5(candidate) || !nonBlank(candidate.label))
22238
+ continue;
22239
+ const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
22240
+ if (!id.success || seen.has(id.data))
22241
+ continue;
22242
+ seen.add(id.data);
22243
+ options.push({ id: id.data, label: candidate.label });
22244
+ }
22245
+ return options;
22246
+ }
22247
+ function parseGrokModelState(value) {
22248
+ if (!isRecord5(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
22249
+ return null;
22250
+ }
22251
+ const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
22252
+ if (!currentModel.success)
22253
+ return null;
22254
+ const allThinking = /* @__PURE__ */ new Map();
22255
+ const contextWindowTokensByModel = /* @__PURE__ */ new Map();
22256
+ const defaultContextWindowTokensByModel = /* @__PURE__ */ new Map();
22257
+ const models = [];
22258
+ let currentThinkingOptionId;
22259
+ for (const candidate of value.availableModels) {
22260
+ if (!isRecord5(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
22261
+ continue;
22262
+ const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
22263
+ if (!ref.success)
22264
+ continue;
22265
+ const metadata = isRecord5(candidate._meta) ? candidate._meta : {};
22266
+ const options2 = thinkingOptions(metadata.reasoningEfforts);
22267
+ if (Array.isArray(metadata.contextWindows) && metadata.contextWindows.includes(5e5)) {
22268
+ defaultContextWindowTokensByModel.set(ref.data.id, 5e5);
22269
+ }
22270
+ if (typeof metadata.totalContextTokens === "number" && Number.isSafeInteger(metadata.totalContextTokens) && metadata.totalContextTokens > 0) {
22271
+ contextWindowTokensByModel.set(ref.data.id, metadata.totalContextTokens);
22272
+ }
22273
+ for (const option of options2)
22274
+ allThinking.set(option.id, option);
22275
+ if (candidate.modelId === value.currentModelId && nonBlank(metadata.reasoningEffort)) {
22276
+ const parsed = harnessThinkingOptionIdSchema.safeParse(metadata.reasoningEffort);
22277
+ if (parsed.success && options2.some(({ id }) => id === parsed.data)) {
22278
+ currentThinkingOptionId = parsed.data;
22279
+ }
22280
+ }
22281
+ models.push({
22282
+ ref: ref.data,
22283
+ label: candidate.name,
22284
+ ...options2.length > 0 ? { supportedThinkingOptionIds: options2.map(({ id }) => id) } : {}
22285
+ });
22286
+ }
22287
+ if (!models.some(({ ref }) => ref.id === currentModel.data.id))
22288
+ return null;
22289
+ const options = [...allThinking.values()];
22290
+ return {
22291
+ currentModel: currentModel.data,
22292
+ contextWindowTokensByModel,
22293
+ defaultContextWindowTokensByModel,
22294
+ ...currentThinkingOptionId ? { currentThinkingOptionId } : {},
22295
+ catalog: {
22296
+ models,
22297
+ defaultModel: currentModel.data,
22298
+ thinkingOptions: options,
22299
+ ...currentThinkingOptionId ? { defaultThinkingOptionId: currentThinkingOptionId } : {}
22300
+ }
22301
+ };
22302
+ }
22303
+ function modelStateFromInitialize(response) {
22304
+ return parseGrokModelState(isRecord5(response._meta) ? response._meta.modelState : void 0);
22305
+ }
22306
+ function modelStateFromSessionResponse(response) {
22307
+ return parseGrokModelState(isRecord5(response) ? response.models : void 0);
22308
+ }
22309
+ function stateForGrokModel(modelState, nativeState, model2 = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
22310
+ const selectedModel = model2;
22311
+ const catalogModel = modelState.catalog.models.find(({ ref }) => ref.id === selectedModel.id);
22312
+ const availableThinkingOptions = catalogModel?.supportedThinkingOptionIds?.flatMap((id) => {
22313
+ const option = modelState.catalog.thinkingOptions.find((candidate) => candidate.id === id);
22314
+ return option ? [option] : [];
22315
+ });
22316
+ return {
22317
+ ...nativeState,
22318
+ effectiveModel: selectedModel,
22319
+ ...thinkingOptionId ? { effectiveThinkingOptionId: thinkingOptionId } : {},
22320
+ ...permissionModeId ? { effectivePermissionModeId: permissionModeId } : {},
22321
+ ...availableThinkingOptions ? { availableThinkingOptions } : {}
22322
+ };
22323
+ }
22324
+
22202
22325
  // dist/command.js
22203
22326
  import path8 from "node:path";
22204
22327
  var GrokExecutableError = class extends Error {
@@ -22666,7 +22789,7 @@ function splitLines(text) {
22666
22789
  // dist/grok-file-change.js
22667
22790
  var DEFAULT_GROK_FILE_CHANGE_TEXT_LIMIT = 4 * 1024 * 1024;
22668
22791
  var MAX_GROK_FILE_CHANGES_PER_TOOL = 32;
22669
- function isRecord5(value) {
22792
+ function isRecord6(value) {
22670
22793
  return typeof value === "object" && value !== null && !Array.isArray(value);
22671
22794
  }
22672
22795
  function validAbsolutePath(value) {
@@ -22717,7 +22840,7 @@ function projectGrokFileChanges(content, cwd, textLimit = DEFAULT_GROK_FILE_CHAN
22717
22840
  return null;
22718
22841
  const candidates = [];
22719
22842
  for (const entry of content) {
22720
- if (isRecord5(entry) && entry.type === "diff")
22843
+ if (isRecord6(entry) && entry.type === "diff")
22721
22844
  candidates.push(entry);
22722
22845
  }
22723
22846
  if (candidates.length === 0 || candidates.length > MAX_GROK_FILE_CHANGES_PER_TOOL)
@@ -22754,14 +22877,14 @@ function grokMediaResolveRoots(cwd, sessionDirectory) {
22754
22877
  // dist/grok-tool-output.js
22755
22878
  var DEFAULT_GROK_TOOL_OUTPUT_LIMIT = 64e3;
22756
22879
  var EXECUTE_TOOL_NAMES = /* @__PURE__ */ new Set(["bash", "run_terminal_command", "shell", "cursor_shell"]);
22757
- function isRecord6(value) {
22880
+ function isRecord7(value) {
22758
22881
  return typeof value === "object" && value !== null && !Array.isArray(value);
22759
22882
  }
22760
22883
  function stringField(value, key) {
22761
- return isRecord6(value) && typeof value[key] === "string" && value[key].length > 0 ? value[key] : void 0;
22884
+ return isRecord7(value) && typeof value[key] === "string" && value[key].length > 0 ? value[key] : void 0;
22762
22885
  }
22763
22886
  function numberField(value, key) {
22764
- if (!isRecord6(value))
22887
+ if (!isRecord7(value))
22765
22888
  return void 0;
22766
22889
  const field2 = value[key];
22767
22890
  if (field2 === null)
@@ -22784,7 +22907,7 @@ function firstReadableText(...candidates) {
22784
22907
  for (const candidate of candidates) {
22785
22908
  if (typeof candidate === "string" && candidate.length > 0)
22786
22909
  return candidate;
22787
- if (isRecord6(candidate)) {
22910
+ if (isRecord7(candidate)) {
22788
22911
  const nested = stringField(candidate, "content") ?? stringField(candidate, "text") ?? stringField(candidate, "tool_result") ?? stringField(candidate, "raw_output");
22789
22912
  if (nested)
22790
22913
  return nested;
@@ -22807,7 +22930,7 @@ function grokToolArguments(rawInput) {
22807
22930
  if (!parsed.success)
22808
22931
  return {};
22809
22932
  const argumentsValue = parsed.data;
22810
- if (!isRecord6(argumentsValue) || stringField(argumentsValue, "path"))
22933
+ if (!isRecord7(argumentsValue) || stringField(argumentsValue, "path"))
22811
22934
  return argumentsValue;
22812
22935
  const targetFile = stringField(argumentsValue, "target_file");
22813
22936
  return targetFile ? { ...argumentsValue, path: targetFile } : argumentsValue;
@@ -22820,7 +22943,7 @@ function grokCommand(name, kind, rawInput) {
22820
22943
  return command;
22821
22944
  if (name && EXECUTE_TOOL_NAMES.has(name))
22822
22945
  return command;
22823
- return isRecord6(rawInput) && rawInput.variant === "Bash" ? command : void 0;
22946
+ return isRecord7(rawInput) && rawInput.variant === "Bash" ? command : void 0;
22824
22947
  }
22825
22948
  function grokCommandCwd(rawInput, fallback) {
22826
22949
  return stringField(rawInput, "cwd") ?? fallback;
@@ -22847,11 +22970,11 @@ function acpContentText(content) {
22847
22970
  if (!Array.isArray(content))
22848
22971
  return "";
22849
22972
  return content.flatMap((entry) => {
22850
- if (!isRecord6(entry))
22973
+ if (!isRecord7(entry))
22851
22974
  return [];
22852
22975
  if (entry.type === "text" && typeof entry.text === "string")
22853
22976
  return [entry.text];
22854
- if (entry.type !== "content" || !isRecord6(entry.content))
22977
+ if (entry.type !== "content" || !isRecord7(entry.content))
22855
22978
  return [];
22856
22979
  return entry.content.type === "text" && typeof entry.content.text === "string" ? [entry.content.text] : [];
22857
22980
  }).join("\n");
@@ -22862,10 +22985,10 @@ function acpContentImages(content, remainingBytes) {
22862
22985
  const images = [];
22863
22986
  let remaining = remainingBytes;
22864
22987
  for (const entry of content) {
22865
- if (!isRecord6(entry))
22988
+ if (!isRecord7(entry))
22866
22989
  continue;
22867
22990
  const image = entry.type === "image" ? entry : entry.type === "content" ? entry.content : null;
22868
- if (!isRecord6(image) || image.type !== "image")
22991
+ if (!isRecord7(image) || image.type !== "image")
22869
22992
  continue;
22870
22993
  const mimeType = stringField(image, "mimeType") ?? stringField(image, "mime_type");
22871
22994
  const data = stringField(image, "data");
@@ -22888,14 +23011,14 @@ function bashOutput(rawOutput) {
22888
23011
  function rawOutputProjection(rawOutput) {
22889
23012
  if (typeof rawOutput === "string")
22890
23013
  return rawOutput.length > 0 ? { text: rawOutput } : {};
22891
- if (!isRecord6(rawOutput))
23014
+ if (!isRecord7(rawOutput))
22892
23015
  return {};
22893
23016
  if (rawOutput.type === "Bash" || rawOutput.variant === "Bash" || numberField(rawOutput, "exit_code") !== void 0 || numberField(rawOutput, "exitCode") !== void 0) {
22894
23017
  const bash = bashOutput(rawOutput);
22895
23018
  if (bash.text !== void 0 || bash.exitCode !== void 0)
22896
23019
  return bash;
22897
23020
  }
22898
- 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);
23021
+ 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);
22899
23022
  if (text)
22900
23023
  return { text };
22901
23024
  if (typeof rawOutput.match_count === "number" && Number.isFinite(rawOutput.match_count)) {
@@ -22959,11 +23082,11 @@ var WAIT_TOOL_NAMES = /* @__PURE__ */ new Set([
22959
23082
  var KILL_TOOL_NAMES = /* @__PURE__ */ new Set(["kill_command_or_subagent", "kill_task"]);
22960
23083
  var DESCRIPTION_LIMIT = 500;
22961
23084
  var SUMMARY_LIMIT = 2e3;
22962
- function isRecord7(value) {
23085
+ function isRecord8(value) {
22963
23086
  return typeof value === "object" && value !== null && !Array.isArray(value);
22964
23087
  }
22965
23088
  function idField(value, key) {
22966
- if (!isRecord7(value))
23089
+ if (!isRecord8(value))
22967
23090
  return void 0;
22968
23091
  const field2 = value[key];
22969
23092
  if (typeof field2 === "string") {
@@ -22975,7 +23098,7 @@ function idField(value, key) {
22975
23098
  return void 0;
22976
23099
  }
22977
23100
  function stringField2(value, key) {
22978
- if (!isRecord7(value) || typeof value[key] !== "string")
23101
+ if (!isRecord8(value) || typeof value[key] !== "string")
22979
23102
  return void 0;
22980
23103
  const trimmed = value[key].trim();
22981
23104
  return trimmed.length > 0 ? trimmed : void 0;
@@ -22998,7 +23121,7 @@ function collectIds(value) {
22998
23121
  };
22999
23122
  push(idField(value, "task_id"));
23000
23123
  push(idField(value, "subagent_id"));
23001
- if (isRecord7(value)) {
23124
+ if (isRecord8(value)) {
23002
23125
  const list = value.task_ids ?? value.subagent_ids;
23003
23126
  if (Array.isArray(list)) {
23004
23127
  for (const entry of list)
@@ -23017,7 +23140,7 @@ function grokSubagentOperation(name, title, rawInput) {
23017
23140
  return "send";
23018
23141
  if (SPAWN_TOOL_NAMES.has(id))
23019
23142
  return "spawn";
23020
- if (isRecord7(rawInput) && rawInput.variant === "Task")
23143
+ if (isRecord8(rawInput) && rawInput.variant === "Task")
23021
23144
  return "spawn";
23022
23145
  return null;
23023
23146
  }
@@ -23040,7 +23163,7 @@ function grokSubagentRole(rawInput) {
23040
23163
  return bounded(stringField2(rawInput, "subagent_type") ?? stringField2(rawInput, "agent_type") ?? stringField2(rawInput, "type"), DESCRIPTION_LIMIT);
23041
23164
  }
23042
23165
  function grokSubagentBackground(rawInput) {
23043
- if (!isRecord7(rawInput))
23166
+ if (!isRecord8(rawInput))
23044
23167
  return true;
23045
23168
  if (rawInput.background === false || rawInput.run_in_background === false)
23046
23169
  return false;
@@ -23078,7 +23201,7 @@ function grokSubagentResultSummary(...candidates) {
23078
23201
  return void 0;
23079
23202
  }
23080
23203
  function grokSubagentEventFromUpdate(update) {
23081
- if (!isRecord7(update) || typeof update.sessionUpdate !== "string")
23204
+ if (!isRecord8(update) || typeof update.sessionUpdate !== "string")
23082
23205
  return null;
23083
23206
  const nativeSubagentId = idField(update, "subagent_id") ?? idField(update, "child_session_id");
23084
23207
  if (!nativeSubagentId)
@@ -23139,14 +23262,14 @@ function grokSubagentWaitSettlements(input) {
23139
23262
  return ids.map((id) => ({ id, status: overall }));
23140
23263
  }
23141
23264
  function taskOutputResults(rawOutput) {
23142
- if (!isRecord7(rawOutput))
23265
+ if (!isRecord8(rawOutput))
23143
23266
  return [];
23144
23267
  if (Array.isArray(rawOutput.results)) {
23145
- return rawOutput.results.filter(isRecord7);
23268
+ return rawOutput.results.filter(isRecord8);
23146
23269
  }
23147
23270
  const nested = firstRecord(rawOutput.MultiResult, rawOutput.multiResult, rawOutput.multi_result);
23148
23271
  if (nested && Array.isArray(nested.results)) {
23149
- return nested.results.filter(isRecord7);
23272
+ return nested.results.filter(isRecord8);
23150
23273
  }
23151
23274
  const single = firstRecord(rawOutput.Result, rawOutput.result);
23152
23275
  if (single)
@@ -23157,7 +23280,7 @@ function taskOutputResults(rawOutput) {
23157
23280
  }
23158
23281
  function firstRecord(...values) {
23159
23282
  for (const value of values) {
23160
- if (isRecord7(value))
23283
+ if (isRecord8(value))
23161
23284
  return value;
23162
23285
  }
23163
23286
  return void 0;
@@ -23180,7 +23303,7 @@ function taskOutputTextSettlements(rawOutput, content, ids) {
23180
23303
  return settled;
23181
23304
  }
23182
23305
  function taskOutputStatus(rawOutput, content) {
23183
- if (isRecord7(rawOutput) && typeof rawOutput.status === "string")
23306
+ if (isRecord8(rawOutput) && typeof rawOutput.status === "string")
23184
23307
  return rawOutput.status;
23185
23308
  const text = extractText(content) ?? extractText(rawOutput);
23186
23309
  if (!text)
@@ -23239,7 +23362,7 @@ function extractText(value, depth = 0) {
23239
23362
  const joined = parts.join("\n").trim();
23240
23363
  return joined.length > 0 ? joined : void 0;
23241
23364
  }
23242
- if (!isRecord7(value))
23365
+ if (!isRecord8(value))
23243
23366
  return void 0;
23244
23367
  if (typeof value.text === "string" && value.text.trim().length > 0)
23245
23368
  return value.text.trim();
@@ -23710,11 +23833,11 @@ var GROK_SESSION_DELETE_METHOD = "_x.ai/session/delete";
23710
23833
  function error51(code, message, retryable = false) {
23711
23834
  return { code, message, retryable };
23712
23835
  }
23713
- function isRecord8(value) {
23836
+ function isRecord9(value) {
23714
23837
  return typeof value === "object" && value !== null && !Array.isArray(value);
23715
23838
  }
23716
23839
  function isGrokMethodNotFound(error53) {
23717
- if (isRecord8(error53) && error53.code === -32601)
23840
+ if (isRecord9(error53) && error53.code === -32601)
23718
23841
  return true;
23719
23842
  const message = error53 instanceof Error ? error53.message : String(error53);
23720
23843
  return /method not found/iu.test(message);
@@ -23732,10 +23855,10 @@ function buildGrokForkParams(input) {
23732
23855
  };
23733
23856
  }
23734
23857
  function parseGrokForkResponse(value) {
23735
- if (!isRecord8(value) || value.error !== void 0)
23858
+ if (!isRecord9(value) || value.error !== void 0)
23736
23859
  return null;
23737
- const payload = typeof value.newSessionId !== "string" && isRecord8(value.result) ? value.result : value;
23738
- if (!isRecord8(payload) || payload.error !== void 0)
23860
+ const payload = typeof value.newSessionId !== "string" && isRecord9(value.result) ? value.result : value;
23861
+ if (!isRecord9(payload) || payload.error !== void 0)
23739
23862
  return null;
23740
23863
  if (typeof payload.newSessionId !== "string" || payload.newSessionId.length === 0)
23741
23864
  return null;
@@ -23899,7 +24022,7 @@ var GROK_SESSION_UPDATE_EXTENSION_METHODS = [
23899
24022
  "x.ai/session_notification",
23900
24023
  "_x.ai/session_notification"
23901
24024
  ];
23902
- function isRecord9(value) {
24025
+ function isRecord10(value) {
23903
24026
  return typeof value === "object" && value !== null && !Array.isArray(value);
23904
24027
  }
23905
24028
  function optionalNonNegativeInt(value) {
@@ -23920,7 +24043,7 @@ function isGrokExtensionSessionUpdateMethod(method) {
23920
24043
  return GROK_SESSION_UPDATE_EXTENSION_METHODS.includes(method);
23921
24044
  }
23922
24045
  function grokCompactionEventFromUpdate(update) {
23923
- if (!isRecord9(update) || typeof update.sessionUpdate !== "string")
24046
+ if (!isRecord10(update) || typeof update.sessionUpdate !== "string")
23924
24047
  return null;
23925
24048
  const tokensUsed = optionalNonNegativeInt(firstPresent(update, ["tokensUsed", "tokens_used"]));
23926
24049
  const contextWindowTokens = optionalNonNegativeInt(firstPresent(update, ["contextWindowTokens", "contextWindow", "context_window"]));
@@ -23959,7 +24082,7 @@ function grokCompactionEventFromUpdate(update) {
23959
24082
  // dist/grok-manual-compaction.js
23960
24083
  var GROK_COMPACT_CONVERSATION_METHOD = "x.ai/compact_conversation";
23961
24084
  var GROK_COMPACT_CONVERSATION_FALLBACK_METHOD = "_x.ai/compact_conversation";
23962
- function isRecord10(value) {
24085
+ function isRecord11(value) {
23963
24086
  return typeof value === "object" && value !== null && !Array.isArray(value);
23964
24087
  }
23965
24088
  function optionalNonNegativeInt2(value) {
@@ -23971,7 +24094,7 @@ function optionalErrorMessage2(value) {
23971
24094
  function parseGrokCompactResult(value, cancelled = false) {
23972
24095
  if (cancelled)
23973
24096
  return { outcome: "cancelled" };
23974
- if (!isRecord10(value))
24097
+ if (!isRecord11(value))
23975
24098
  return { outcome: "succeeded" };
23976
24099
  const tokensBefore = optionalNonNegativeInt2(value.tokensBefore ?? value.tokens_before);
23977
24100
  const tokensAfter = optionalNonNegativeInt2(value.tokensAfter ?? value.tokens_after);
@@ -24009,7 +24132,7 @@ var GROK_REWIND_EXECUTE_METHOD = "_x.ai/rewind/execute";
24009
24132
  function error52(code, message, retryable = false) {
24010
24133
  return { code, message, retryable };
24011
24134
  }
24012
- function isRecord11(value) {
24135
+ function isRecord12(value) {
24013
24136
  return typeof value === "object" && value !== null && !Array.isArray(value);
24014
24137
  }
24015
24138
  function buildGrokRewindParams(input) {
@@ -24021,10 +24144,10 @@ function buildGrokRewindParams(input) {
24021
24144
  };
24022
24145
  }
24023
24146
  function parseGrokRewindResponse(value) {
24024
- if (!isRecord11(value))
24147
+ if (!isRecord12(value))
24025
24148
  return null;
24026
- const payload = typeof value.success !== "boolean" && isRecord11(value.result) ? value.result : value;
24027
- if (!isRecord11(payload) || typeof payload.success !== "boolean")
24149
+ const payload = typeof value.success !== "boolean" && isRecord12(value.result) ? value.result : value;
24150
+ if (!isRecord12(payload) || typeof payload.success !== "boolean")
24028
24151
  return null;
24029
24152
  return rewindPayload(payload);
24030
24153
  }
@@ -24226,25 +24349,25 @@ var GrokPermissionConfirmation = class {
24226
24349
 
24227
24350
  // dist/grok-questions.js
24228
24351
  var GROK_ASK_USER_QUESTION_METHOD = "_x.ai/ask_user_question";
24229
- function isRecord12(value) {
24352
+ function isRecord13(value) {
24230
24353
  return typeof value === "object" && value !== null && !Array.isArray(value);
24231
24354
  }
24232
24355
  function nonEmptyString(value) {
24233
24356
  return typeof value === "string" && value.trim().length > 0;
24234
24357
  }
24235
24358
  function parseGrokQuestionRequest(value) {
24236
- if (!isRecord12(value) || !nonEmptyString(value.sessionId) || !nonEmptyString(value.toolCallId) || value.mode !== "default" && value.mode !== "plan" || !Array.isArray(value.questions) || value.questions.length === 0)
24359
+ if (!isRecord13(value) || !nonEmptyString(value.sessionId) || !nonEmptyString(value.toolCallId) || value.mode !== "default" && value.mode !== "plan" || !Array.isArray(value.questions) || value.questions.length === 0)
24237
24360
  throw new Error("Grok question requires sessionId, toolCallId, mode and nonempty questions");
24238
24361
  const seen = /* @__PURE__ */ new Set();
24239
24362
  const questions = value.questions.map((question) => {
24240
- if (!isRecord12(question) || !nonEmptyString(question.question) || seen.has(question.question) || !Array.isArray(question.options) || question.multiSelect != null && typeof question.multiSelect !== "boolean" || question.multi_select != null && typeof question.multi_select !== "boolean")
24363
+ if (!isRecord13(question) || !nonEmptyString(question.question) || seen.has(question.question) || !Array.isArray(question.options) || question.multiSelect != null && typeof question.multiSelect !== "boolean" || question.multi_select != null && typeof question.multi_select !== "boolean")
24241
24364
  throw new Error("Grok question text must be unique and options/multiSelect must be valid");
24242
24365
  if (question.multiSelect != null && question.multi_select != null && question.multiSelect !== question.multi_select)
24243
24366
  throw new Error("Grok question contains conflicting multi-select flags");
24244
24367
  seen.add(question.question);
24245
24368
  const labels = /* @__PURE__ */ new Set();
24246
24369
  const options = question.options.map((option) => {
24247
- if (!isRecord12(option) || !nonEmptyString(option.label) || labels.has(option.label) || typeof option.description !== "string" || option.preview != null && typeof option.preview !== "string")
24370
+ if (!isRecord13(option) || !nonEmptyString(option.label) || labels.has(option.label) || typeof option.description !== "string" || option.preview != null && typeof option.preview !== "string")
24248
24371
  throw new Error("Grok question options require unique labels and text descriptions/previews");
24249
24372
  labels.add(option.label);
24250
24373
  return {
@@ -24392,16 +24515,16 @@ var GrokTransportError = class extends Error {
24392
24515
  this.name = "GrokTransportError";
24393
24516
  }
24394
24517
  };
24395
- function isRecord13(value) {
24518
+ function isRecord14(value) {
24396
24519
  return typeof value === "object" && value !== null && !Array.isArray(value);
24397
24520
  }
24398
24521
  function acpToolName(update, metadata) {
24399
- if (!isRecord13(update))
24522
+ if (!isRecord14(update))
24400
24523
  return void 0;
24401
24524
  if (typeof update.name === "string" && update.name.length > 0)
24402
24525
  return update.name;
24403
- const meta3 = isRecord13(update._meta) ? update._meta : metadata;
24404
- const tool = meta3 && isRecord13(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
24526
+ const meta3 = isRecord14(update._meta) ? update._meta : metadata;
24527
+ const tool = meta3 && isRecord14(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
24405
24528
  return tool && typeof tool.name === "string" && tool.name.length > 0 ? tool.name : void 0;
24406
24529
  }
24407
24530
  function errorText(error53) {
@@ -24457,12 +24580,12 @@ function signalProcessTree(child, signal) {
24457
24580
  try {
24458
24581
  process.kill(-child.pid, signal);
24459
24582
  } catch (error53) {
24460
- if (!isRecord13(error53) || error53.code === "ESRCH")
24583
+ if (!isRecord14(error53) || error53.code === "ESRCH")
24461
24584
  return;
24462
24585
  try {
24463
24586
  child.kill(signal);
24464
24587
  } catch (fallback) {
24465
- if (!isRecord13(fallback) || fallback.code !== "ESRCH")
24588
+ if (!isRecord14(fallback) || fallback.code !== "ESRCH")
24466
24589
  throw fallback;
24467
24590
  }
24468
24591
  }
@@ -24577,7 +24700,7 @@ async function readNativeSignals(options, sessionId) {
24577
24700
  }
24578
24701
  }
24579
24702
  function isMissingFile(error53) {
24580
- return isRecord13(error53) && error53.code === "ENOENT";
24703
+ return isRecord14(error53) && error53.code === "ENOENT";
24581
24704
  }
24582
24705
  async function locateGrokNativeSession(options, sessionId) {
24583
24706
  if (sessionId.length === 0)
@@ -24600,7 +24723,7 @@ async function locateGrokNativeSession(options, sessionId) {
24600
24723
  try {
24601
24724
  summaryRaw = await readFile3(path13.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
24602
24725
  } catch (error53) {
24603
- if (isMissingFile(error53) || isRecord13(error53) && error53.code === "ENOTDIR")
24726
+ if (isMissingFile(error53) || isRecord14(error53) && error53.code === "ENOTDIR")
24604
24727
  continue;
24605
24728
  throw new GrokTransportError("unavailable", "Grok Native Session metadata could not be read", {
24606
24729
  cause: error53
@@ -24612,10 +24735,10 @@ async function locateGrokNativeSession(options, sessionId) {
24612
24735
  } catch {
24613
24736
  continue;
24614
24737
  }
24615
- if (!isRecord13(parsed))
24738
+ if (!isRecord14(parsed))
24616
24739
  continue;
24617
24740
  const info = parsed.info;
24618
- const cwd = isRecord13(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path13.resolve(info.cwd) : path13.resolve(decodeURIComponent(entry.name));
24741
+ const cwd = isRecord14(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path13.resolve(info.cwd) : path13.resolve(decodeURIComponent(entry.name));
24619
24742
  const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path13.resolve(parsed.source_workspace_dir) : void 0;
24620
24743
  matches.push({
24621
24744
  cwd,
@@ -24648,12 +24771,12 @@ function parseNativeHistory(contents, sessionId) {
24648
24771
  } catch {
24649
24772
  throw new GrokTransportError("protocolError", "Grok Native history contains invalid JSON");
24650
24773
  }
24651
- if (!isRecord13(record3) || !isRecord13(record3.params))
24774
+ if (!isRecord14(record3) || !isRecord14(record3.params))
24652
24775
  continue;
24653
24776
  const params = record3.params;
24654
- if (params.sessionId !== sessionId || !isRecord13(params.update))
24777
+ if (params.sessionId !== sessionId || !isRecord14(params.update))
24655
24778
  continue;
24656
- const metadata = isRecord13(params._meta) ? params._meta : void 0;
24779
+ const metadata = isRecord14(params._meta) ? params._meta : void 0;
24657
24780
  const event = transportEvent(params.update, metadata);
24658
24781
  if (event)
24659
24782
  events.push(metadata ? { ...event, metadata } : event);
@@ -24696,13 +24819,23 @@ var GrokAcpTransport = class {
24696
24819
  throw new Error("Grok ACP inspection cannot reuse an open Session");
24697
24820
  try {
24698
24821
  const initialize = await this.#ensureInitialized();
24822
+ const connection = this.#connection;
24823
+ if (!connection)
24824
+ throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
24699
24825
  if (initialize.agentCapabilities?.sessionCapabilities?.list) {
24700
- const connection = this.#connection;
24701
- if (!connection)
24702
- throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
24703
24826
  await withTimeout(connection.listSessions({ cwd: this.#options.cwd }), this.#options.commandTimeoutMs, "Grok Session inspection");
24704
24827
  }
24705
- return initialize;
24828
+ try {
24829
+ const response = await withTimeout(connection.request("_x.ai/models/list", {}), this.#options.commandTimeoutMs, "Grok Model inspection");
24830
+ const modelState = isRecord14(response) ? response.result : void 0;
24831
+ if (!parseGrokModelState(modelState))
24832
+ throw new GrokTransportError("protocolError", "Grok returned an invalid Model catalog");
24833
+ return { ...initialize, _meta: { ...initialize._meta, modelState } };
24834
+ } catch (error53) {
24835
+ if (isGrokMethodNotFound(error53))
24836
+ return initialize;
24837
+ throw error53;
24838
+ }
24706
24839
  } catch (error53) {
24707
24840
  const classified = classifyStartupError(error53);
24708
24841
  await this.close().catch(() => void 0);
@@ -24717,7 +24850,7 @@ var GrokAcpTransport = class {
24717
24850
  if (!this.#connection)
24718
24851
  throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
24719
24852
  const result = await withTimeout(this.#connection.request("_x.ai/session/usage", { sessionId: this.sessionId }), this.#options.commandTimeoutMs, "Grok Session usage");
24720
- return isRecord13(result) ? result.usage : void 0;
24853
+ return isRecord14(result) ? result.usage : void 0;
24721
24854
  }
24722
24855
  async readHistory(sessionId, cwd = this.#options.cwd) {
24723
24856
  return readGrokNativeHistory({ ...this.#options, cwd }, sessionId);
@@ -24980,7 +25113,7 @@ var GrokAcpTransport = class {
24980
25113
  ...reasoningEffort ? { reasoningEffort } : {},
24981
25114
  ...contextWindowTokens !== void 0 ? { _meta: { contextWindow: contextWindowTokens } } : {}
24982
25115
  });
24983
- if (!isRecord13(response) || !isRecord13(response._meta) || !isRecord13(response._meta.model)) {
25116
+ if (!isRecord14(response) || !isRecord14(response._meta) || !isRecord14(response._meta.model)) {
24984
25117
  throw new GrokTransportError("protocolError", "Grok rejected Model configuration");
24985
25118
  }
24986
25119
  const selected = response._meta.model.Ok;
@@ -25020,7 +25153,7 @@ var GrokAcpTransport = class {
25020
25153
  permission_mode: mode
25021
25154
  });
25022
25155
  const response = await connection.request("_x.ai/session/info", { sessionId });
25023
- if (!isRecord13(response) || !isRecord13(response.result) || response.result.sessionId !== sessionId) {
25156
+ if (!isRecord14(response) || !isRecord14(response.result) || response.result.sessionId !== sessionId) {
25024
25157
  throw new Error("Grok did not confirm the target Session");
25025
25158
  }
25026
25159
  })()
@@ -25075,7 +25208,7 @@ var GrokAcpTransport = class {
25075
25208
  this.#availableCommands = parseGrokAvailableCommands(update.availableCommands);
25076
25209
  return;
25077
25210
  }
25078
- const metadata = isRecord13(notification._meta) ? notification._meta : void 0;
25211
+ const metadata = isRecord14(notification._meta) ? notification._meta : void 0;
25079
25212
  const event = transportEvent(notification.update, metadata);
25080
25213
  if (!event)
25081
25214
  return;
@@ -25090,7 +25223,7 @@ var GrokAcpTransport = class {
25090
25223
  #handleExtensionNotification(method, params) {
25091
25224
  if (!isGrokExtensionSessionUpdateMethod(method))
25092
25225
  return;
25093
- if (typeof params.sessionId !== "string" || !isRecord13(params.update))
25226
+ if (typeof params.sessionId !== "string" || !isRecord14(params.update))
25094
25227
  return;
25095
25228
  this.#handleUpdate(params);
25096
25229
  }
@@ -25246,7 +25379,7 @@ var SessionImportScope = class {
25246
25379
  // dist/session-import.js
25247
25380
  var MAX_METADATA_BYTES = 4 * 1024 * 1024;
25248
25381
  var SUBAGENT_SESSION_KINDS = /* @__PURE__ */ new Set(["subagent", "subagent_resume"]);
25249
- function isRecord14(value) {
25382
+ function isRecord15(value) {
25250
25383
  return typeof value === "object" && value !== null && !Array.isArray(value);
25251
25384
  }
25252
25385
  async function readJson(file2, signal) {
@@ -25259,7 +25392,7 @@ function processAlive(pid) {
25259
25392
  process.kill(pid, 0);
25260
25393
  return true;
25261
25394
  } catch (error53) {
25262
- return isRecord14(error53) && error53.code === "EPERM";
25395
+ return isRecord15(error53) && error53.code === "EPERM";
25263
25396
  }
25264
25397
  }
25265
25398
  async function firstUserText(file2, signal) {
@@ -25276,10 +25409,10 @@ async function firstUserText(file2, signal) {
25276
25409
  } catch {
25277
25410
  continue;
25278
25411
  }
25279
- const update = isRecord14(entry) && isRecord14(entry.params) ? entry.params.update : null;
25280
- if (!isRecord14(update) || update.sessionUpdate !== "user_message_chunk")
25412
+ const update = isRecord15(entry) && isRecord15(entry.params) ? entry.params.update : null;
25413
+ if (!isRecord15(update) || update.sessionUpdate !== "user_message_chunk")
25281
25414
  continue;
25282
- const text = isRecord14(update.content) ? update.content.text : null;
25415
+ const text = isRecord15(update.content) ? update.content.text : null;
25283
25416
  return typeof text === "string" ? text : "";
25284
25417
  }
25285
25418
  return null;
@@ -25356,7 +25489,7 @@ var GrokSessionImport = class {
25356
25489
  if (!Array.isArray(entries))
25357
25490
  return active;
25358
25491
  for (const entry of entries) {
25359
- if (isRecord14(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
25492
+ if (isRecord15(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
25360
25493
  active.add(entry.session_id);
25361
25494
  }
25362
25495
  return active;
@@ -25405,7 +25538,7 @@ var GrokSessionImport = class {
25405
25538
  return null;
25406
25539
  try {
25407
25540
  const summary = await readJson(files[0], signal);
25408
- if (!isRecord14(summary) || !isRecord14(summary.info) || summary.info.id !== nativeSessionId)
25541
+ if (!isRecord15(summary) || !isRecord15(summary.info) || summary.info.id !== nativeSessionId)
25409
25542
  return null;
25410
25543
  if (typeof summary.session_kind === "string" && SUBAGENT_SESSION_KINDS.has(summary.session_kind))
25411
25544
  return null;
@@ -25631,107 +25764,6 @@ var GrokSubagentLifecycle = class {
25631
25764
  }
25632
25765
  };
25633
25766
 
25634
- // dist/grok-models.js
25635
- function isRecord15(value) {
25636
- return typeof value === "object" && value !== null && !Array.isArray(value);
25637
- }
25638
- function nonBlank(value) {
25639
- return typeof value === "string" && value.trim().length > 0;
25640
- }
25641
- function thinkingOptions(value) {
25642
- if (!Array.isArray(value))
25643
- return [];
25644
- const seen = /* @__PURE__ */ new Set();
25645
- const options = [];
25646
- for (const candidate of value) {
25647
- if (!isRecord15(candidate) || !nonBlank(candidate.label))
25648
- continue;
25649
- const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
25650
- if (!id.success || seen.has(id.data))
25651
- continue;
25652
- seen.add(id.data);
25653
- options.push({ id: id.data, label: candidate.label });
25654
- }
25655
- return options;
25656
- }
25657
- function parseGrokModelState(value) {
25658
- if (!isRecord15(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
25659
- return null;
25660
- }
25661
- const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
25662
- if (!currentModel.success)
25663
- return null;
25664
- const allThinking = /* @__PURE__ */ new Map();
25665
- const contextWindowTokensByModel = /* @__PURE__ */ new Map();
25666
- const defaultContextWindowTokensByModel = /* @__PURE__ */ new Map();
25667
- const models = [];
25668
- let currentThinkingOptionId;
25669
- for (const candidate of value.availableModels) {
25670
- if (!isRecord15(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
25671
- continue;
25672
- const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
25673
- if (!ref.success)
25674
- continue;
25675
- const metadata = isRecord15(candidate._meta) ? candidate._meta : {};
25676
- const options2 = thinkingOptions(metadata.reasoningEfforts);
25677
- if (Array.isArray(metadata.contextWindows) && metadata.contextWindows.includes(5e5)) {
25678
- defaultContextWindowTokensByModel.set(ref.data.id, 5e5);
25679
- }
25680
- if (typeof metadata.totalContextTokens === "number" && Number.isSafeInteger(metadata.totalContextTokens) && metadata.totalContextTokens > 0) {
25681
- contextWindowTokensByModel.set(ref.data.id, metadata.totalContextTokens);
25682
- }
25683
- for (const option of options2)
25684
- allThinking.set(option.id, option);
25685
- if (candidate.modelId === value.currentModelId && nonBlank(metadata.reasoningEffort)) {
25686
- const parsed = harnessThinkingOptionIdSchema.safeParse(metadata.reasoningEffort);
25687
- if (parsed.success && options2.some(({ id }) => id === parsed.data)) {
25688
- currentThinkingOptionId = parsed.data;
25689
- }
25690
- }
25691
- models.push({
25692
- ref: ref.data,
25693
- label: candidate.name,
25694
- ...options2.length > 0 ? { supportedThinkingOptionIds: options2.map(({ id }) => id) } : {}
25695
- });
25696
- }
25697
- if (!models.some(({ ref }) => ref.id === currentModel.data.id))
25698
- return null;
25699
- const options = [...allThinking.values()];
25700
- return {
25701
- currentModel: currentModel.data,
25702
- contextWindowTokensByModel,
25703
- defaultContextWindowTokensByModel,
25704
- ...currentThinkingOptionId ? { currentThinkingOptionId } : {},
25705
- catalog: {
25706
- models,
25707
- defaultModel: currentModel.data,
25708
- thinkingOptions: options,
25709
- ...currentThinkingOptionId ? { defaultThinkingOptionId: currentThinkingOptionId } : {}
25710
- }
25711
- };
25712
- }
25713
- function modelStateFromInitialize(response) {
25714
- return parseGrokModelState(isRecord15(response._meta) ? response._meta.modelState : void 0);
25715
- }
25716
- function modelStateFromSessionResponse(response) {
25717
- return parseGrokModelState(isRecord15(response) ? response.models : void 0);
25718
- }
25719
- function stateForGrokModel(modelState, nativeState, model2 = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
25720
- const selectedModel = model2;
25721
- const catalogModel = modelState.catalog.models.find(({ ref }) => ref.id === selectedModel.id);
25722
- const availableThinkingOptions = catalogModel?.supportedThinkingOptionIds?.flatMap((id) => {
25723
- const option = modelState.catalog.thinkingOptions.find((candidate) => candidate.id === id);
25724
- return option ? [option] : [];
25725
- });
25726
- return {
25727
- ...nativeState,
25728
- effectiveModel: selectedModel,
25729
- ...thinkingOptionId ? { effectiveThinkingOptionId: thinkingOptionId } : {},
25730
- ...permissionModeId ? { effectivePermissionModeId: permissionModeId } : {},
25731
- ...availableThinkingOptions ? { availableThinkingOptions } : {}
25732
- };
25733
- }
25734
-
25735
25767
  // dist/grok-credits.js
25736
25768
  import { readFile as readFile5 } from "node:fs/promises";
25737
25769
  import os6 from "node:os";
@@ -25976,6 +26008,9 @@ var GrokTurnUsage = class {
25976
26008
  #compacting = false;
25977
26009
  #startedAtMs;
25978
26010
  #streamKey;
26011
+ #reasoningObserved = false;
26012
+ #textStartedOutput = false;
26013
+ #bufferedToolInput = false;
25979
26014
  #outputTokens = 0;
25980
26015
  #durationMs = 0;
25981
26016
  #latestCacheHit;
@@ -25989,8 +26024,7 @@ var GrokTurnUsage = class {
25989
26024
  }
25990
26025
  observe(event) {
25991
26026
  if (event.type === "compaction.started" || event.type === "compaction.completed") {
25992
- this.#startedAtMs = void 0;
25993
- this.#streamKey = void 0;
26027
+ this.#resetResponse();
25994
26028
  this.#compacting = event.type === "compaction.started";
25995
26029
  }
25996
26030
  if (this.#compacting)
@@ -25998,14 +26032,29 @@ var GrokTurnUsage = class {
25998
26032
  if (event.type === "subagent.spawned")
25999
26033
  this.#cacheComplete = false;
26000
26034
  if (event.type === "agent.text" || event.type === "agent.thought" || event.type === "tool.input.delta") {
26001
- if (!event.text)
26035
+ if (!event.text || event.type === "tool.input.delta" && !event.text.trim())
26002
26036
  return null;
26003
26037
  const key = event.metadata?.streamStartMs;
26004
26038
  if (key !== void 0 && this.#streamKey !== void 0 && key !== this.#streamKey)
26005
- this.#startedAtMs = void 0;
26039
+ this.#resetResponse();
26006
26040
  if (key !== void 0)
26007
26041
  this.#streamKey = key;
26008
- this.#startedAtMs ??= Date.now();
26042
+ if (this.#bufferedToolInput)
26043
+ return null;
26044
+ if (event.type === "tool.input.delta" && this.#startedAtMs === void 0) {
26045
+ try {
26046
+ JSON.parse(event.text);
26047
+ this.#bufferedToolInput = true;
26048
+ return null;
26049
+ } catch {
26050
+ }
26051
+ }
26052
+ if (event.type === "agent.thought")
26053
+ this.#reasoningObserved = true;
26054
+ if (this.#startedAtMs === void 0) {
26055
+ this.#startedAtMs = Date.now();
26056
+ this.#textStartedOutput = event.type === "agent.text";
26057
+ }
26009
26058
  }
26010
26059
  if (event.type !== "response.completed")
26011
26060
  return null;
@@ -26015,9 +26064,12 @@ var GrokTurnUsage = class {
26015
26064
  this.#seen.add(event.messageId);
26016
26065
  }
26017
26066
  const duration3 = this.#startedAtMs === void 0 ? 0 : Date.now() - this.#startedAtMs;
26018
- this.#startedAtMs = void 0;
26019
- this.#streamKey = void 0;
26020
26067
  const usage = usageFromResponse(event.usage);
26068
+ const outputTokens = usage?.outputTokens;
26069
+ const reasoningOutputTokens = usage?.reasoningOutputTokens;
26070
+ const completeOutputBoundary = this.#reasoningObserved || reasoningOutputTokens === 0;
26071
+ const timedOutputTokens = completeOutputBoundary ? outputTokens : this.#textStartedOutput && outputTokens !== void 0 && reasoningOutputTokens !== void 0 && reasoningOutputTokens > 0 && reasoningOutputTokens < outputTokens ? outputTokens - reasoningOutputTokens : void 0;
26072
+ this.#resetResponse();
26021
26073
  this.#latestCacheHit = usage?.cacheHitRatePercent;
26022
26074
  if (usage?.inputTokens === void 0 || usage.cachedInputTokens === void 0)
26023
26075
  this.#cacheComplete = false;
@@ -26027,13 +26079,20 @@ var GrokTurnUsage = class {
26027
26079
  if (value !== void 0)
26028
26080
  this.#totals[field2] = (this.#totals[field2] ?? 0) + value;
26029
26081
  }
26030
- if (duration3 > 0 && usage.outputTokens !== void 0) {
26031
- this.#outputTokens += usage.outputTokens;
26082
+ if (duration3 > 0 && timedOutputTokens !== void 0) {
26083
+ this.#outputTokens += timedOutputTokens;
26032
26084
  this.#durationMs += duration3;
26033
26085
  }
26034
26086
  }
26035
26087
  return this.snapshot();
26036
26088
  }
26089
+ #resetResponse() {
26090
+ this.#startedAtMs = void 0;
26091
+ this.#streamKey = void 0;
26092
+ this.#reasoningObserved = false;
26093
+ this.#textStartedOutput = false;
26094
+ this.#bufferedToolInput = false;
26095
+ }
26037
26096
  metrics() {
26038
26097
  return {
26039
26098
  ...this.#durationMs > 0 ? { outputTokensPerSecond: this.#outputTokens * 1e3 / this.#durationMs } : {},
@@ -26209,6 +26268,7 @@ function capabilitiesForModels(modelState) {
26209
26268
  };
26210
26269
  }
26211
26270
  var DEFAULT_CLOSE_TIMEOUT_MS = 2e3;
26271
+ var INSPECTION_CACHE_TTL_MS = 3e4;
26212
26272
  function invalidState(message) {
26213
26273
  return { code: "invalidState", message, retryable: false };
26214
26274
  }
@@ -27350,8 +27410,8 @@ var GrokAdapter = class {
27350
27410
  const cwd = path16.resolve(input.cwd ?? process.cwd());
27351
27411
  if (!input.refresh) {
27352
27412
  const cached2 = this.#inspectionCache.get(cwd);
27353
- if (cached2)
27354
- return cached2;
27413
+ if (cached2 && Date.now() < cached2.expiresAt)
27414
+ return cached2.inspection;
27355
27415
  }
27356
27416
  let transport = null;
27357
27417
  const startedAt = Date.now();
@@ -27371,7 +27431,10 @@ var GrokAdapter = class {
27371
27431
  permissionModes: GROK_PERMISSION_MODE_CATALOG,
27372
27432
  capabilities: capabilitiesForModels(modelState)
27373
27433
  };
27374
- this.#inspectionCache.set(cwd, ready);
27434
+ this.#inspectionCache.set(cwd, {
27435
+ inspection: ready,
27436
+ expiresAt: Date.now() + INSPECTION_CACHE_TTL_MS
27437
+ });
27375
27438
  this.#scheduleCreditsRefresh();
27376
27439
  return ready;
27377
27440
  } catch (error53) {