@karlorz/codexhost-cli-darwin-x64 0.21.0-0 → 0.22.0-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 (45) hide show
  1. package/README.md +1 -1
  2. package/app/codexhost-distribution.json +1 -1
  3. package/app/console-server.mjs +1 -0
  4. package/app/console-web.js +2 -1
  5. package/app/cpa-live-voice-hook.js +213 -178
  6. package/app/desktop-controller.mjs +8 -2
  7. package/app/host-runtime.mjs +96 -26
  8. package/app/overlay-voice-bootstrap.js +1 -1616
  9. package/app/plugins/antigravity/plugin.mjs +1144 -1254
  10. package/app/plugins/claude-code/plugin.mjs +389 -80
  11. package/app/plugins/codebuddy/plugin.mjs +1 -0
  12. package/app/plugins/codex-usage/plugin.mjs +1 -0
  13. package/app/plugins/copilot/plugin.mjs +1 -0
  14. package/app/plugins/cursor-cli/plugin.mjs +1 -0
  15. package/app/plugins/deepseek-harness/plugin.mjs +1 -0
  16. package/app/plugins/devin/plugin.mjs +1 -0
  17. package/app/plugins/grok/plugin.mjs +232 -217
  18. package/app/plugins/hermes/plugin.mjs +1 -0
  19. package/app/plugins/kimi-code/plugin.mjs +1 -0
  20. package/app/plugins/kiro-cli/plugin.mjs +1 -0
  21. package/app/plugins/omp/plugin.mjs +108 -22
  22. package/app/plugins/opencode/plugin.mjs +1 -0
  23. package/app/plugins/pi/plugin.mjs +119 -23
  24. package/app/plugins/qoder/plugin.mjs +1 -0
  25. package/app/plugins/qoder-cn/plugin.mjs +1 -0
  26. package/app/plugins/qwen-code/plugin.mjs +1 -0
  27. package/app/plugins/workbuddy/plugin.mjs +1 -0
  28. package/app/plugins/zcode/plugin.mjs +1 -0
  29. package/app/renderer-extension.js +799 -476
  30. package/app/voice-qualification.json +13 -13
  31. package/app/web/assets/index-CYo5zTz_.js +201 -0
  32. package/app/web/codexhost-settings.js +2 -1
  33. package/app/web/index.html +1 -1
  34. package/app/web/plugins/deepseek-ai__dsh-api-remotes/client.js +1 -1
  35. package/app/web/plugins/deepseek-ai__dsh-api-session-controller/client.js +3 -3
  36. package/app/web/plugins/deepseek-ai__dsh-client-ui-chat/client.js +9 -9
  37. package/app/web/plugins/deepseek-ai__dsh-client-ui-codexhost/client.js +2 -2
  38. package/app/web/plugins/deepseek-ai__dsh-client-ui-conversation/client.js +1 -1
  39. package/app/web/plugins/deepseek-ai__dsh-client-ui-tool/client.js +1 -1
  40. package/app/web-modules/server.mjs +130 -74
  41. package/bin/codexhost +0 -0
  42. package/libexec/codexhost-shim +0 -0
  43. package/libexec/codexhost-updater +0 -0
  44. package/package.json +1 -1
  45. package/app/web/assets/index-DLXdvkWR.js +0 -201
@@ -17354,6 +17354,7 @@ var remoteSessionOperationSchema = external_exports.discriminatedUnion("kind", [
17354
17354
  message: "A history continuation requires its connection epoch"
17355
17355
  }).optional()
17356
17356
  }),
17357
+ external_exports.strictObject({ kind: external_exports.literal("usage"), ...thread, epoch: identity }),
17357
17358
  external_exports.strictObject({
17358
17359
  kind: external_exports.literal("configure"),
17359
17360
  ...thread,
@@ -23486,6 +23487,107 @@ function grokLiveCommands(native) {
23486
23487
  }));
23487
23488
  }
23488
23489
 
23490
+ // dist/grok-models.js
23491
+ function isRecord6(value) {
23492
+ return typeof value === "object" && value !== null && !Array.isArray(value);
23493
+ }
23494
+ function nonBlank(value) {
23495
+ return typeof value === "string" && value.trim().length > 0;
23496
+ }
23497
+ function thinkingOptions(value) {
23498
+ if (!Array.isArray(value))
23499
+ return [];
23500
+ const seen = /* @__PURE__ */ new Set();
23501
+ const options = [];
23502
+ for (const candidate of value) {
23503
+ if (!isRecord6(candidate) || !nonBlank(candidate.label))
23504
+ continue;
23505
+ const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
23506
+ if (!id.success || seen.has(id.data))
23507
+ continue;
23508
+ seen.add(id.data);
23509
+ options.push({ id: id.data, label: candidate.label });
23510
+ }
23511
+ return options;
23512
+ }
23513
+ function parseGrokModelState(value) {
23514
+ if (!isRecord6(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
23515
+ return null;
23516
+ }
23517
+ const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
23518
+ if (!currentModel.success)
23519
+ return null;
23520
+ const allThinking = /* @__PURE__ */ new Map();
23521
+ const contextWindowTokensByModel = /* @__PURE__ */ new Map();
23522
+ const defaultContextWindowTokensByModel = /* @__PURE__ */ new Map();
23523
+ const models = [];
23524
+ let currentThinkingOptionId;
23525
+ for (const candidate of value.availableModels) {
23526
+ if (!isRecord6(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
23527
+ continue;
23528
+ const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
23529
+ if (!ref.success)
23530
+ continue;
23531
+ const metadata = isRecord6(candidate._meta) ? candidate._meta : {};
23532
+ const options2 = thinkingOptions(metadata.reasoningEfforts);
23533
+ if (Array.isArray(metadata.contextWindows) && metadata.contextWindows.includes(5e5)) {
23534
+ defaultContextWindowTokensByModel.set(ref.data.id, 5e5);
23535
+ }
23536
+ if (typeof metadata.totalContextTokens === "number" && Number.isSafeInteger(metadata.totalContextTokens) && metadata.totalContextTokens > 0) {
23537
+ contextWindowTokensByModel.set(ref.data.id, metadata.totalContextTokens);
23538
+ }
23539
+ for (const option of options2)
23540
+ allThinking.set(option.id, option);
23541
+ if (candidate.modelId === value.currentModelId && nonBlank(metadata.reasoningEffort)) {
23542
+ const parsed = harnessThinkingOptionIdSchema.safeParse(metadata.reasoningEffort);
23543
+ if (parsed.success && options2.some(({ id }) => id === parsed.data)) {
23544
+ currentThinkingOptionId = parsed.data;
23545
+ }
23546
+ }
23547
+ models.push({
23548
+ ref: ref.data,
23549
+ label: candidate.name,
23550
+ ...options2.length > 0 ? { supportedThinkingOptionIds: options2.map(({ id }) => id) } : {}
23551
+ });
23552
+ }
23553
+ if (!models.some(({ ref }) => ref.id === currentModel.data.id))
23554
+ return null;
23555
+ const options = [...allThinking.values()];
23556
+ return {
23557
+ currentModel: currentModel.data,
23558
+ contextWindowTokensByModel,
23559
+ defaultContextWindowTokensByModel,
23560
+ ...currentThinkingOptionId ? { currentThinkingOptionId } : {},
23561
+ catalog: {
23562
+ models,
23563
+ defaultModel: currentModel.data,
23564
+ thinkingOptions: options,
23565
+ ...currentThinkingOptionId ? { defaultThinkingOptionId: currentThinkingOptionId } : {}
23566
+ }
23567
+ };
23568
+ }
23569
+ function modelStateFromInitialize(response) {
23570
+ return parseGrokModelState(isRecord6(response._meta) ? response._meta.modelState : void 0);
23571
+ }
23572
+ function modelStateFromSessionResponse(response) {
23573
+ return parseGrokModelState(isRecord6(response) ? response.models : void 0);
23574
+ }
23575
+ function stateForGrokModel(modelState, nativeState, model2 = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
23576
+ const selectedModel = model2;
23577
+ const catalogModel = modelState.catalog.models.find(({ ref }) => ref.id === selectedModel.id);
23578
+ const availableThinkingOptions = catalogModel?.supportedThinkingOptionIds?.flatMap((id) => {
23579
+ const option = modelState.catalog.thinkingOptions.find((candidate) => candidate.id === id);
23580
+ return option ? [option] : [];
23581
+ });
23582
+ return {
23583
+ ...nativeState,
23584
+ effectiveModel: selectedModel,
23585
+ ...thinkingOptionId ? { effectiveThinkingOptionId: thinkingOptionId } : {},
23586
+ ...permissionModeId ? { effectivePermissionModeId: permissionModeId } : {},
23587
+ ...availableThinkingOptions ? { availableThinkingOptions } : {}
23588
+ };
23589
+ }
23590
+
23489
23591
  // dist/command.js
23490
23592
  import path11 from "node:path";
23491
23593
  var GrokExecutableError = class extends Error {
@@ -24120,7 +24222,7 @@ function splitLines(text) {
24120
24222
  // dist/grok-file-change.js
24121
24223
  var DEFAULT_GROK_FILE_CHANGE_TEXT_LIMIT = 4 * 1024 * 1024;
24122
24224
  var MAX_GROK_FILE_CHANGES_PER_TOOL = 32;
24123
- function isRecord6(value) {
24225
+ function isRecord7(value) {
24124
24226
  return typeof value === "object" && value !== null && !Array.isArray(value);
24125
24227
  }
24126
24228
  function validAbsolutePath(value) {
@@ -24171,7 +24273,7 @@ function projectGrokFileChanges(content, cwd, textLimit = DEFAULT_GROK_FILE_CHAN
24171
24273
  return null;
24172
24274
  const candidates = [];
24173
24275
  for (const entry of content) {
24174
- if (isRecord6(entry) && entry.type === "diff")
24276
+ if (isRecord7(entry) && entry.type === "diff")
24175
24277
  candidates.push(entry);
24176
24278
  }
24177
24279
  if (candidates.length === 0 || candidates.length > MAX_GROK_FILE_CHANGES_PER_TOOL)
@@ -24201,14 +24303,14 @@ function mediaFileExists2(absolutePath) {
24201
24303
  }
24202
24304
  }
24203
24305
  var GENERATED_IMAGE_TYPES = /* @__PURE__ */ new Set(["ImageGen", "ImageEdit"]);
24204
- function isRecord7(value) {
24306
+ function isRecord8(value) {
24205
24307
  return typeof value === "object" && value !== null && !Array.isArray(value);
24206
24308
  }
24207
24309
  function stringField(value, key) {
24208
- return isRecord7(value) && typeof value[key] === "string" && value[key].length > 0 ? value[key] : void 0;
24310
+ return isRecord8(value) && typeof value[key] === "string" && value[key].length > 0 ? value[key] : void 0;
24209
24311
  }
24210
24312
  function fromNativeRecord(value, exists) {
24211
- if (!isRecord7(value))
24313
+ if (!isRecord8(value))
24212
24314
  return null;
24213
24315
  const type = stringField(value, "type");
24214
24316
  const sessionFolder = stringField(value, "session_folder");
@@ -24245,10 +24347,10 @@ function projectGrokGeneratedImage(content, rawOutput, exists = mediaFileExists2
24245
24347
  if (!Array.isArray(content))
24246
24348
  return null;
24247
24349
  for (const entry of content) {
24248
- if (!isRecord7(entry))
24350
+ if (!isRecord8(entry))
24249
24351
  continue;
24250
- const nested = entry.type === "content" && isRecord7(entry.content) ? entry.content : entry;
24251
- if (isRecord7(nested) && nested.type === "text" && typeof nested.text === "string") {
24352
+ const nested = entry.type === "content" && isRecord8(entry.content) ? entry.content : entry;
24353
+ if (isRecord8(nested) && nested.type === "text" && typeof nested.text === "string") {
24252
24354
  const parsed = fromNativeRecord(parseJsonObject(nested.text), exists);
24253
24355
  if (parsed)
24254
24356
  return parsed;
@@ -24296,14 +24398,14 @@ var EXECUTE_TOOL_NAMES = /* @__PURE__ */ new Set([
24296
24398
  "cursor_shell",
24297
24399
  "monitor"
24298
24400
  ]);
24299
- function isRecord8(value) {
24401
+ function isRecord9(value) {
24300
24402
  return typeof value === "object" && value !== null && !Array.isArray(value);
24301
24403
  }
24302
24404
  function stringField2(value, key) {
24303
- return isRecord8(value) && typeof value[key] === "string" && value[key].length > 0 ? value[key] : void 0;
24405
+ return isRecord9(value) && typeof value[key] === "string" && value[key].length > 0 ? value[key] : void 0;
24304
24406
  }
24305
24407
  function numberField(value, key) {
24306
- if (!isRecord8(value))
24408
+ if (!isRecord9(value))
24307
24409
  return void 0;
24308
24410
  const field2 = value[key];
24309
24411
  if (field2 === null)
@@ -24326,7 +24428,7 @@ function firstReadableText(...candidates) {
24326
24428
  for (const candidate of candidates) {
24327
24429
  if (typeof candidate === "string" && candidate.length > 0)
24328
24430
  return candidate;
24329
- if (isRecord8(candidate)) {
24431
+ if (isRecord9(candidate)) {
24330
24432
  const nested = stringField2(candidate, "content") ?? stringField2(candidate, "text") ?? stringField2(candidate, "tool_result") ?? stringField2(candidate, "raw_output");
24331
24433
  if (nested)
24332
24434
  return nested;
@@ -24349,7 +24451,7 @@ function grokToolArguments(rawInput) {
24349
24451
  if (!parsed.success)
24350
24452
  return {};
24351
24453
  const argumentsValue = parsed.data;
24352
- if (!isRecord8(argumentsValue) || stringField2(argumentsValue, "path"))
24454
+ if (!isRecord9(argumentsValue) || stringField2(argumentsValue, "path"))
24353
24455
  return argumentsValue;
24354
24456
  const targetFile = stringField2(argumentsValue, "target_file");
24355
24457
  return targetFile ? { ...argumentsValue, path: targetFile } : argumentsValue;
@@ -24362,7 +24464,7 @@ function grokCommand(name, kind, rawInput) {
24362
24464
  return command;
24363
24465
  if (name && EXECUTE_TOOL_NAMES.has(name))
24364
24466
  return command;
24365
- return isRecord8(rawInput) && rawInput.variant === "Bash" ? command : void 0;
24467
+ return isRecord9(rawInput) && rawInput.variant === "Bash" ? command : void 0;
24366
24468
  }
24367
24469
  function grokCommandCwd(rawInput, fallback) {
24368
24470
  return stringField2(rawInput, "cwd") ?? fallback;
@@ -24389,11 +24491,11 @@ function acpContentText(content) {
24389
24491
  if (!Array.isArray(content))
24390
24492
  return "";
24391
24493
  return content.flatMap((entry) => {
24392
- if (!isRecord8(entry))
24494
+ if (!isRecord9(entry))
24393
24495
  return [];
24394
24496
  if (entry.type === "text" && typeof entry.text === "string")
24395
24497
  return [entry.text];
24396
- if (entry.type !== "content" || !isRecord8(entry.content))
24498
+ if (entry.type !== "content" || !isRecord9(entry.content))
24397
24499
  return [];
24398
24500
  return entry.content.type === "text" && typeof entry.content.text === "string" ? [entry.content.text] : [];
24399
24501
  }).join("\n");
@@ -24404,10 +24506,10 @@ function acpContentImages(content, remainingBytes) {
24404
24506
  const images = [];
24405
24507
  let remaining = remainingBytes;
24406
24508
  for (const entry of content) {
24407
- if (!isRecord8(entry))
24509
+ if (!isRecord9(entry))
24408
24510
  continue;
24409
24511
  const image = entry.type === "image" ? entry : entry.type === "content" ? entry.content : null;
24410
- if (!isRecord8(image) || image.type !== "image")
24512
+ if (!isRecord9(image) || image.type !== "image")
24411
24513
  continue;
24412
24514
  const mimeType = stringField2(image, "mimeType") ?? stringField2(image, "mime_type");
24413
24515
  const data = stringField2(image, "data");
@@ -24430,14 +24532,14 @@ function bashOutput(rawOutput) {
24430
24532
  function rawOutputProjection(rawOutput) {
24431
24533
  if (typeof rawOutput === "string")
24432
24534
  return rawOutput.length > 0 ? { text: rawOutput } : {};
24433
- if (!isRecord8(rawOutput))
24535
+ if (!isRecord9(rawOutput))
24434
24536
  return {};
24435
24537
  if (rawOutput.type === "Bash" || rawOutput.variant === "Bash" || numberField(rawOutput, "exit_code") !== void 0 || numberField(rawOutput, "exitCode") !== void 0) {
24436
24538
  const bash = bashOutput(rawOutput);
24437
24539
  if (bash.text !== void 0 || bash.exitCode !== void 0)
24438
24540
  return bash;
24439
24541
  }
24440
- const text = firstReadableText(rawOutput.content, rawOutput.text, rawOutput.tool_result, rawOutput.raw_output, isRecord8(rawOutput.FileContent) ? rawOutput.FileContent : void 0, isRecord8(rawOutput.Content) ? rawOutput.Content : void 0);
24542
+ const text = firstReadableText(rawOutput.content, rawOutput.text, rawOutput.tool_result, rawOutput.raw_output, isRecord9(rawOutput.FileContent) ? rawOutput.FileContent : void 0, isRecord9(rawOutput.Content) ? rawOutput.Content : void 0);
24441
24543
  if (text)
24442
24544
  return { text };
24443
24545
  if (typeof rawOutput.match_count === "number" && Number.isFinite(rawOutput.match_count)) {
@@ -24501,11 +24603,11 @@ var WAIT_TOOL_NAMES = /* @__PURE__ */ new Set([
24501
24603
  var KILL_TOOL_NAMES = /* @__PURE__ */ new Set(["kill_command_or_subagent", "kill_task"]);
24502
24604
  var DESCRIPTION_LIMIT = 500;
24503
24605
  var SUMMARY_LIMIT = 2e3;
24504
- function isRecord9(value) {
24606
+ function isRecord10(value) {
24505
24607
  return typeof value === "object" && value !== null && !Array.isArray(value);
24506
24608
  }
24507
24609
  function idField(value, key) {
24508
- if (!isRecord9(value))
24610
+ if (!isRecord10(value))
24509
24611
  return void 0;
24510
24612
  const field2 = value[key];
24511
24613
  if (typeof field2 === "string") {
@@ -24517,7 +24619,7 @@ function idField(value, key) {
24517
24619
  return void 0;
24518
24620
  }
24519
24621
  function stringField3(value, key) {
24520
- if (!isRecord9(value) || typeof value[key] !== "string")
24622
+ if (!isRecord10(value) || typeof value[key] !== "string")
24521
24623
  return void 0;
24522
24624
  const trimmed = value[key].trim();
24523
24625
  return trimmed.length > 0 ? trimmed : void 0;
@@ -24540,7 +24642,7 @@ function collectIds(value) {
24540
24642
  };
24541
24643
  push(idField(value, "task_id"));
24542
24644
  push(idField(value, "subagent_id"));
24543
- if (isRecord9(value)) {
24645
+ if (isRecord10(value)) {
24544
24646
  const list = value.task_ids ?? value.subagent_ids;
24545
24647
  if (Array.isArray(list)) {
24546
24648
  for (const entry of list)
@@ -24559,7 +24661,7 @@ function grokSubagentOperation(name, title, rawInput) {
24559
24661
  return "send";
24560
24662
  if (SPAWN_TOOL_NAMES.has(id))
24561
24663
  return "spawn";
24562
- if (isRecord9(rawInput) && rawInput.variant === "Task")
24664
+ if (isRecord10(rawInput) && rawInput.variant === "Task")
24563
24665
  return "spawn";
24564
24666
  return null;
24565
24667
  }
@@ -24582,7 +24684,7 @@ function grokSubagentRole(rawInput) {
24582
24684
  return bounded(stringField3(rawInput, "subagent_type") ?? stringField3(rawInput, "agent_type") ?? stringField3(rawInput, "type"), DESCRIPTION_LIMIT);
24583
24685
  }
24584
24686
  function grokSubagentBackground(rawInput) {
24585
- if (!isRecord9(rawInput))
24687
+ if (!isRecord10(rawInput))
24586
24688
  return true;
24587
24689
  if (rawInput.background === false || rawInput.run_in_background === false)
24588
24690
  return false;
@@ -24620,7 +24722,7 @@ function grokSubagentResultSummary(...candidates) {
24620
24722
  return void 0;
24621
24723
  }
24622
24724
  function grokSubagentEventFromUpdate(update) {
24623
- if (!isRecord9(update) || typeof update.sessionUpdate !== "string")
24725
+ if (!isRecord10(update) || typeof update.sessionUpdate !== "string")
24624
24726
  return null;
24625
24727
  const nativeSubagentId = idField(update, "subagent_id") ?? idField(update, "child_session_id");
24626
24728
  if (!nativeSubagentId)
@@ -24689,14 +24791,14 @@ function grokSubagentWaitSettlements(input) {
24689
24791
  return ids.map((id) => ({ id, status: overall }));
24690
24792
  }
24691
24793
  function taskOutputResults(rawOutput) {
24692
- if (!isRecord9(rawOutput))
24794
+ if (!isRecord10(rawOutput))
24693
24795
  return [];
24694
24796
  if (Array.isArray(rawOutput.results)) {
24695
- return rawOutput.results.filter(isRecord9);
24797
+ return rawOutput.results.filter(isRecord10);
24696
24798
  }
24697
24799
  const nested = firstRecord(rawOutput.MultiResult, rawOutput.multiResult, rawOutput.multi_result);
24698
24800
  if (nested && Array.isArray(nested.results)) {
24699
- return nested.results.filter(isRecord9);
24801
+ return nested.results.filter(isRecord10);
24700
24802
  }
24701
24803
  const single = firstRecord(rawOutput.Result, rawOutput.result);
24702
24804
  if (single)
@@ -24707,7 +24809,7 @@ function taskOutputResults(rawOutput) {
24707
24809
  }
24708
24810
  function firstRecord(...values) {
24709
24811
  for (const value of values) {
24710
- if (isRecord9(value))
24812
+ if (isRecord10(value))
24711
24813
  return value;
24712
24814
  }
24713
24815
  return void 0;
@@ -24730,7 +24832,7 @@ function taskOutputTextSettlements(rawOutput, content, ids) {
24730
24832
  return settled;
24731
24833
  }
24732
24834
  function taskOutputStatus(rawOutput, content) {
24733
- if (isRecord9(rawOutput) && typeof rawOutput.status === "string")
24835
+ if (isRecord10(rawOutput) && typeof rawOutput.status === "string")
24734
24836
  return rawOutput.status;
24735
24837
  const text = extractText(content) ?? extractText(rawOutput);
24736
24838
  if (!text)
@@ -24789,7 +24891,7 @@ function extractText(value, depth = 0) {
24789
24891
  const joined = parts.join("\n").trim();
24790
24892
  return joined.length > 0 ? joined : void 0;
24791
24893
  }
24792
- if (!isRecord9(value))
24894
+ if (!isRecord10(value))
24793
24895
  return void 0;
24794
24896
  if (typeof value.text === "string" && value.text.trim().length > 0)
24795
24897
  return value.text.trim();
@@ -24804,19 +24906,19 @@ function extractText(value, depth = 0) {
24804
24906
  // dist/grok-questions.js
24805
24907
  var GROK_ASK_USER_QUESTION_METHOD = "_x.ai/ask_user_question";
24806
24908
  var GROK_QUESTION_ACTIVITY_METHOD = "_x.ai/ask_user_question_activity";
24807
- function isRecord10(value) {
24909
+ function isRecord11(value) {
24808
24910
  return typeof value === "object" && value !== null && !Array.isArray(value);
24809
24911
  }
24810
24912
  function nonEmptyString(value) {
24811
24913
  return typeof value === "string" && value.trim().length > 0;
24812
24914
  }
24813
24915
  function parseGrokQuestionRequest(value) {
24814
- if (!isRecord10(value) || !nonEmptyString(value.sessionId) || !nonEmptyString(value.toolCallId) || value.mode !== "default" && value.mode !== "plan" || !Array.isArray(value.questions) || value.questions.length === 0) {
24916
+ if (!isRecord11(value) || !nonEmptyString(value.sessionId) || !nonEmptyString(value.toolCallId) || value.mode !== "default" && value.mode !== "plan" || !Array.isArray(value.questions) || value.questions.length === 0) {
24815
24917
  throw new Error("Grok question requires sessionId, toolCallId, mode and nonempty questions");
24816
24918
  }
24817
24919
  const seen = /* @__PURE__ */ new Set();
24818
24920
  const questions = value.questions.map((question) => {
24819
- if (!isRecord10(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") {
24921
+ if (!isRecord11(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") {
24820
24922
  throw new Error("Grok question text must be unique and options/multiSelect must be valid");
24821
24923
  }
24822
24924
  if (question.multiSelect != null && question.multi_select != null && question.multiSelect !== question.multi_select)
@@ -24824,7 +24926,7 @@ function parseGrokQuestionRequest(value) {
24824
24926
  seen.add(question.question);
24825
24927
  const labels = /* @__PURE__ */ new Set();
24826
24928
  const options = question.options.map((option) => {
24827
- if (!isRecord10(option) || !nonEmptyString(option.label) || labels.has(option.label) || typeof option.description !== "string" || option.preview != null && typeof option.preview !== "string") {
24929
+ if (!isRecord11(option) || !nonEmptyString(option.label) || labels.has(option.label) || typeof option.description !== "string" || option.preview != null && typeof option.preview !== "string") {
24828
24930
  throw new Error("Grok question options require unique labels and text descriptions/previews");
24829
24931
  }
24830
24932
  labels.add(option.label);
@@ -24984,7 +25086,7 @@ var GrokQuestions = class {
24984
25086
  };
24985
25087
 
24986
25088
  // dist/grok-question-record.js
24987
- function isRecord11(value) {
25089
+ function isRecord12(value) {
24988
25090
  return typeof value === "object" && value !== null && !Array.isArray(value);
24989
25091
  }
24990
25092
  function isAskUserQuestionName(name) {
@@ -24992,16 +25094,16 @@ function isAskUserQuestionName(name) {
24992
25094
  return normalized === "askuserquestion" || normalized === "ask_user_question" || normalized === "_x.ai/ask_user_question";
24993
25095
  }
24994
25096
  function questionsFromInput(rawInput) {
24995
- const questions = isRecord11(rawInput) ? rawInput.questions : void 0;
25097
+ const questions = isRecord12(rawInput) ? rawInput.questions : void 0;
24996
25098
  if (!Array.isArray(questions) || questions.length === 0)
24997
25099
  return null;
24998
25100
  const native = [];
24999
25101
  for (const value of questions) {
25000
- if (!isRecord11(value) || typeof value.question !== "string" || value.question.length === 0) {
25102
+ if (!isRecord12(value) || typeof value.question !== "string" || value.question.length === 0) {
25001
25103
  return null;
25002
25104
  }
25003
25105
  const options = Array.isArray(value.options) ? value.options.flatMap((option) => {
25004
- if (!isRecord11(option) || typeof option.label !== "string" || option.label.length === 0) {
25106
+ if (!isRecord12(option) || typeof option.label !== "string" || option.label.length === 0) {
25005
25107
  return [];
25006
25108
  }
25007
25109
  return [
@@ -25021,13 +25123,13 @@ function questionsFromInput(rawInput) {
25021
25123
  return toGrokHostQuestions(native);
25022
25124
  }
25023
25125
  function asRecord(value) {
25024
- if (isRecord11(value))
25126
+ if (isRecord12(value))
25025
25127
  return value;
25026
25128
  if (typeof value !== "string")
25027
25129
  return void 0;
25028
25130
  try {
25029
25131
  const parsed = JSON.parse(value);
25030
- return isRecord11(parsed) ? parsed : void 0;
25132
+ return isRecord12(parsed) ? parsed : void 0;
25031
25133
  } catch {
25032
25134
  return void 0;
25033
25135
  }
@@ -25036,7 +25138,7 @@ function userAnsweredMessage(rawOutput) {
25036
25138
  const parsed = asRecord(rawOutput);
25037
25139
  if (!parsed)
25038
25140
  return void 0;
25039
- if (isRecord11(parsed.UserAnswered) && typeof parsed.UserAnswered.message === "string") {
25141
+ if (isRecord12(parsed.UserAnswered) && typeof parsed.UserAnswered.message === "string") {
25040
25142
  return parsed.UserAnswered.message;
25041
25143
  }
25042
25144
  return typeof parsed.message === "string" ? parsed.message : void 0;
@@ -25065,7 +25167,7 @@ function answersFromOutput(rawOutput, questions) {
25065
25167
  if (message && /declined to answer/iu.test(message)) {
25066
25168
  return { outcome: "skipped", answers: {} };
25067
25169
  }
25068
- const nativeAnswers = parsed && isRecord11(parsed.answers) ? parsed.answers : void 0;
25170
+ const nativeAnswers = parsed && isRecord12(parsed.answers) ? parsed.answers : void 0;
25069
25171
  const answers = {};
25070
25172
  if (nativeAnswers) {
25071
25173
  for (const question of questions) {
@@ -25647,11 +25749,11 @@ var GROK_SESSION_DELETE_METHOD = "_x.ai/session/delete";
25647
25749
  function error51(code, message, retryable = false) {
25648
25750
  return { code, message, retryable };
25649
25751
  }
25650
- function isRecord12(value) {
25752
+ function isRecord13(value) {
25651
25753
  return typeof value === "object" && value !== null && !Array.isArray(value);
25652
25754
  }
25653
25755
  function isGrokMethodNotFound(error53) {
25654
- if (isRecord12(error53) && error53.code === -32601)
25756
+ if (isRecord13(error53) && error53.code === -32601)
25655
25757
  return true;
25656
25758
  const message = error53 instanceof Error ? error53.message : String(error53);
25657
25759
  return /method not found/iu.test(message);
@@ -25669,10 +25771,10 @@ function buildGrokForkParams(input) {
25669
25771
  };
25670
25772
  }
25671
25773
  function parseGrokForkResponse(value) {
25672
- if (!isRecord12(value) || value.error !== void 0)
25774
+ if (!isRecord13(value) || value.error !== void 0)
25673
25775
  return null;
25674
- const payload = typeof value.newSessionId !== "string" && isRecord12(value.result) ? value.result : value;
25675
- if (!isRecord12(payload) || payload.error !== void 0)
25776
+ const payload = typeof value.newSessionId !== "string" && isRecord13(value.result) ? value.result : value;
25777
+ if (!isRecord13(payload) || payload.error !== void 0)
25676
25778
  return null;
25677
25779
  if (typeof payload.newSessionId !== "string" || payload.newSessionId.length === 0)
25678
25780
  return null;
@@ -25836,7 +25938,7 @@ var GROK_SESSION_UPDATE_EXTENSION_METHODS = [
25836
25938
  "x.ai/session_notification",
25837
25939
  "_x.ai/session_notification"
25838
25940
  ];
25839
- function isRecord13(value) {
25941
+ function isRecord14(value) {
25840
25942
  return typeof value === "object" && value !== null && !Array.isArray(value);
25841
25943
  }
25842
25944
  function optionalNonNegativeInt(value) {
@@ -25857,7 +25959,7 @@ function isGrokExtensionSessionUpdateMethod(method) {
25857
25959
  return GROK_SESSION_UPDATE_EXTENSION_METHODS.includes(method);
25858
25960
  }
25859
25961
  function grokCompactionEventFromUpdate(update) {
25860
- if (!isRecord13(update) || typeof update.sessionUpdate !== "string")
25962
+ if (!isRecord14(update) || typeof update.sessionUpdate !== "string")
25861
25963
  return null;
25862
25964
  const tokensUsed = optionalNonNegativeInt(firstPresent(update, ["tokensUsed", "tokens_used"]));
25863
25965
  const contextWindowTokens = optionalNonNegativeInt(firstPresent(update, ["contextWindowTokens", "contextWindow", "context_window"]));
@@ -25919,7 +26021,7 @@ var BACKGROUND_SESSION_UPDATES = /* @__PURE__ */ new Set([
25919
26021
  "scheduled_task_fired",
25920
26022
  "scheduled_task_deleted"
25921
26023
  ]);
25922
- function isRecord14(value) {
26024
+ function isRecord15(value) {
25923
26025
  return typeof value === "object" && value !== null && !Array.isArray(value);
25924
26026
  }
25925
26027
  function firstPresent2(record4, keys) {
@@ -25948,10 +26050,10 @@ function booleanField(record4, keys) {
25948
26050
  return typeof value === "boolean" ? value : void 0;
25949
26051
  }
25950
26052
  function snapshotRecord(value) {
25951
- if (!isRecord14(value))
26053
+ if (!isRecord15(value))
25952
26054
  return void 0;
25953
26055
  const nested = value.task_snapshot ?? value.taskSnapshot;
25954
- return isRecord14(nested) ? nested : value;
26056
+ return isRecord15(nested) ? nested : value;
25955
26057
  }
25956
26058
  function backgroundKind(value, monitorDescription) {
25957
26059
  if (monitorDescription)
@@ -25967,7 +26069,7 @@ function fields(value) {
25967
26069
  return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== void 0));
25968
26070
  }
25969
26071
  function grokBackgroundEventFromUpdate(update) {
25970
- if (!isRecord14(update) || typeof update.sessionUpdate !== "string" || !BACKGROUND_SESSION_UPDATES.has(update.sessionUpdate))
26072
+ if (!isRecord15(update) || typeof update.sessionUpdate !== "string" || !BACKGROUND_SESSION_UPDATES.has(update.sessionUpdate))
25971
26073
  return null;
25972
26074
  const taskId = stringField4(update, ["task_id", "taskId"]);
25973
26075
  if (update.sessionUpdate === "task_backgrounded") {
@@ -26051,22 +26153,22 @@ function grokBackgroundEventFromUpdate(update) {
26051
26153
  return null;
26052
26154
  }
26053
26155
  function grokToolIsBackgrounded(rawOutput, rawInput) {
26054
- const exitCode = isRecord14(rawOutput) ? numberField2(rawOutput, ["exit_code", "exitCode"]) : void 0;
26156
+ const exitCode = isRecord15(rawOutput) ? numberField2(rawOutput, ["exit_code", "exitCode"]) : void 0;
26055
26157
  if (exitCode !== void 0 && exitCode !== null)
26056
26158
  return false;
26057
- if (isRecord14(rawOutput) && optionalString(rawOutput, ["signal"]) === "backgrounded")
26159
+ if (isRecord15(rawOutput) && optionalString(rawOutput, ["signal"]) === "backgrounded")
26058
26160
  return true;
26059
26161
  if (grokBackgroundTaskId(rawOutput, rawInput))
26060
26162
  return true;
26061
- return Boolean(isRecord14(rawInput) && (rawInput.background === true || rawInput.is_background === true));
26163
+ return Boolean(isRecord15(rawInput) && (rawInput.background === true || rawInput.is_background === true));
26062
26164
  }
26063
26165
  function grokBackgroundTaskId(rawOutput, rawInput) {
26064
- if (isRecord14(rawOutput)) {
26166
+ if (isRecord15(rawOutput)) {
26065
26167
  const id = stringField4(rawOutput, ["task_id", "taskId"]);
26066
26168
  if (id)
26067
26169
  return id;
26068
26170
  }
26069
- if (isRecord14(rawInput))
26171
+ if (isRecord15(rawInput))
26070
26172
  return stringField4(rawInput, ["task_id", "taskId"]);
26071
26173
  return void 0;
26072
26174
  }
@@ -26123,7 +26225,7 @@ function collectGrokScheduledLoops(events) {
26123
26225
  // dist/grok-manual-compaction.js
26124
26226
  var GROK_COMPACT_CONVERSATION_METHOD = "x.ai/compact_conversation";
26125
26227
  var GROK_COMPACT_CONVERSATION_FALLBACK_METHOD = "_x.ai/compact_conversation";
26126
- function isRecord15(value) {
26228
+ function isRecord16(value) {
26127
26229
  return typeof value === "object" && value !== null && !Array.isArray(value);
26128
26230
  }
26129
26231
  function optionalNonNegativeInt2(value) {
@@ -26135,7 +26237,7 @@ function optionalErrorMessage2(value) {
26135
26237
  function parseGrokCompactResult(value, cancelled = false) {
26136
26238
  if (cancelled)
26137
26239
  return { outcome: "cancelled" };
26138
- if (!isRecord15(value))
26240
+ if (!isRecord16(value))
26139
26241
  return { outcome: "succeeded" };
26140
26242
  const tokensBefore = optionalNonNegativeInt2(value.tokensBefore ?? value.tokens_before);
26141
26243
  const tokensAfter = optionalNonNegativeInt2(value.tokensAfter ?? value.tokens_after);
@@ -26173,7 +26275,7 @@ var GROK_REWIND_EXECUTE_METHOD = "_x.ai/rewind/execute";
26173
26275
  function error52(code, message, retryable = false) {
26174
26276
  return { code, message, retryable };
26175
26277
  }
26176
- function isRecord16(value) {
26278
+ function isRecord17(value) {
26177
26279
  return typeof value === "object" && value !== null && !Array.isArray(value);
26178
26280
  }
26179
26281
  function buildGrokRewindParams(input) {
@@ -26185,10 +26287,10 @@ function buildGrokRewindParams(input) {
26185
26287
  };
26186
26288
  }
26187
26289
  function parseGrokRewindResponse(value) {
26188
- if (!isRecord16(value))
26290
+ if (!isRecord17(value))
26189
26291
  return null;
26190
- const payload = typeof value.success !== "boolean" && isRecord16(value.result) ? value.result : value;
26191
- if (!isRecord16(payload) || typeof payload.success !== "boolean")
26292
+ const payload = typeof value.success !== "boolean" && isRecord17(value.result) ? value.result : value;
26293
+ if (!isRecord17(payload) || typeof payload.success !== "boolean")
26192
26294
  return null;
26193
26295
  return rewindPayload(payload);
26194
26296
  }
@@ -26354,7 +26456,7 @@ var GROK_CLOCK_ELICIT_PERSIST_FIXTURE = {
26354
26456
  ...GROK_CLOCK_ELICIT_FIXTURE,
26355
26457
  persist: ["session", "always"]
26356
26458
  };
26357
- function isRecord17(value) {
26459
+ function isRecord18(value) {
26358
26460
  return typeof value === "object" && value !== null && !Array.isArray(value);
26359
26461
  }
26360
26462
  function nonEmptyString2(value) {
@@ -26395,11 +26497,11 @@ function parsePersistOffer(value) {
26395
26497
  return out.length > 0 ? out : "invalid";
26396
26498
  }
26397
26499
  function schemaIsSupportedEmptyObject(schema) {
26398
- if (!isRecord17(schema) || !hasOnlyKeys(schema, SCHEMA_KEYS) || schema.type !== "object") {
26500
+ if (!isRecord18(schema) || !hasOnlyKeys(schema, SCHEMA_KEYS) || schema.type !== "object") {
26399
26501
  return false;
26400
26502
  }
26401
26503
  if (schema.properties !== void 0) {
26402
- if (!isRecord17(schema.properties) || Object.keys(schema.properties).length !== 0)
26504
+ if (!isRecord18(schema.properties) || Object.keys(schema.properties).length !== 0)
26403
26505
  return false;
26404
26506
  }
26405
26507
  if (schema.required !== void 0) {
@@ -26409,7 +26511,7 @@ function schemaIsSupportedEmptyObject(schema) {
26409
26511
  return true;
26410
26512
  }
26411
26513
  function parseGrokMcpElicitParams(params) {
26412
- if (!isRecord17(params))
26514
+ if (!isRecord18(params))
26413
26515
  return { status: "invalid", message: "elicitation params must be an object" };
26414
26516
  const sessionId = nonEmptyString2(params.sessionId);
26415
26517
  const toolCallId = nonEmptyString2(params.toolCallId);
@@ -26437,7 +26539,7 @@ function parseGrokMcpElicitParams(params) {
26437
26539
  return { status: "invalid", message: "form elicitation contains unreviewed fields" };
26438
26540
  }
26439
26541
  if (params.requestedSchema !== void 0) {
26440
- if (!isRecord17(params.requestedSchema)) {
26542
+ if (!isRecord18(params.requestedSchema)) {
26441
26543
  return { status: "invalid", message: "requestedSchema must be an object" };
26442
26544
  }
26443
26545
  if (!schemaIsSupportedEmptyObject(params.requestedSchema))
@@ -26504,7 +26606,7 @@ function projectGrokMcpElicitApproval(input) {
26504
26606
  };
26505
26607
  }
26506
26608
  function grokElicitationResolvedToolCallId(update) {
26507
- if (!isRecord17(update) || update.sessionUpdate !== "interaction_resolved")
26609
+ if (!isRecord18(update) || update.sessionUpdate !== "interaction_resolved")
26508
26610
  return void 0;
26509
26611
  return nonEmptyString2(update.tool_call_id) ?? nonEmptyString2(update.toolCallId);
26510
26612
  }
@@ -26660,7 +26762,7 @@ var GrokPermissionConfirmation = class {
26660
26762
  var GROK_EXIT_PLAN_MODE_METHODS = ["_x.ai/exit_plan_mode", "x.ai/exit_plan_mode"];
26661
26763
  var DECISION_ID = "plan-decision";
26662
26764
  var FEEDBACK_ID = "plan-feedback";
26663
- function isRecord18(value) {
26765
+ function isRecord19(value) {
26664
26766
  return typeof value === "object" && value !== null && !Array.isArray(value);
26665
26767
  }
26666
26768
  function nonEmptyString3(value) {
@@ -26670,7 +26772,7 @@ function isGrokExitPlanModeMethod(method) {
26670
26772
  return GROK_EXIT_PLAN_MODE_METHODS.includes(method);
26671
26773
  }
26672
26774
  function parseGrokPlanApprovalRequest(value) {
26673
- if (!isRecord18(value) || !nonEmptyString3(value.sessionId) || !nonEmptyString3(value.toolCallId)) {
26775
+ if (!isRecord19(value) || !nonEmptyString3(value.sessionId) || !nonEmptyString3(value.toolCallId)) {
26674
26776
  throw new Error("Grok plan approval requires sessionId and toolCallId");
26675
26777
  }
26676
26778
  const raw = value.planContent ?? value.plan_content;
@@ -26846,16 +26948,16 @@ var GrokTransportError = class extends Error {
26846
26948
  this.name = "GrokTransportError";
26847
26949
  }
26848
26950
  };
26849
- function isRecord19(value) {
26951
+ function isRecord20(value) {
26850
26952
  return typeof value === "object" && value !== null && !Array.isArray(value);
26851
26953
  }
26852
26954
  function acpToolName(update, metadata) {
26853
- if (!isRecord19(update))
26955
+ if (!isRecord20(update))
26854
26956
  return void 0;
26855
26957
  if (typeof update.name === "string" && update.name.length > 0)
26856
26958
  return update.name;
26857
- const meta3 = isRecord19(update._meta) ? update._meta : metadata;
26858
- const tool = meta3 && isRecord19(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
26959
+ const meta3 = isRecord20(update._meta) ? update._meta : metadata;
26960
+ const tool = meta3 && isRecord20(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
26859
26961
  return tool && typeof tool.name === "string" && tool.name.length > 0 ? tool.name : void 0;
26860
26962
  }
26861
26963
  function errorText(error53) {
@@ -26911,20 +27013,20 @@ function signalProcessTree(child, signal) {
26911
27013
  try {
26912
27014
  process.kill(-child.pid, signal);
26913
27015
  } catch (error53) {
26914
- if (!isRecord19(error53) || error53.code === "ESRCH")
27016
+ if (!isRecord20(error53) || error53.code === "ESRCH")
26915
27017
  return;
26916
27018
  try {
26917
27019
  child.kill(signal);
26918
27020
  } catch (fallback) {
26919
- if (!isRecord19(fallback) || fallback.code !== "ESRCH")
27021
+ if (!isRecord20(fallback) || fallback.code !== "ESRCH")
26920
27022
  throw fallback;
26921
27023
  }
26922
27024
  }
26923
27025
  }
26924
27026
  function grokNotificationMetadata(envelope, update) {
26925
- if (!isRecord19(envelope) && !isRecord19(update))
27027
+ if (!isRecord20(envelope) && !isRecord20(update))
26926
27028
  return void 0;
26927
- return { ...isRecord19(update) ? update : {}, ...isRecord19(envelope) ? envelope : {} };
27029
+ return { ...isRecord20(update) ? update : {}, ...isRecord20(envelope) ? envelope : {} };
26928
27030
  }
26929
27031
  function transportEvent(update, metadata) {
26930
27032
  const extension = update;
@@ -27053,7 +27155,7 @@ async function readNativeSignals(options, sessionId) {
27053
27155
  }
27054
27156
  }
27055
27157
  function isMissingFile(error53) {
27056
- return isRecord19(error53) && error53.code === "ENOENT";
27158
+ return isRecord20(error53) && error53.code === "ENOENT";
27057
27159
  }
27058
27160
  async function locateGrokNativeSession(options, sessionId) {
27059
27161
  if (sessionId.length === 0)
@@ -27076,7 +27178,7 @@ async function locateGrokNativeSession(options, sessionId) {
27076
27178
  try {
27077
27179
  summaryRaw = await readFile5(path17.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
27078
27180
  } catch (error53) {
27079
- if (isMissingFile(error53) || isRecord19(error53) && error53.code === "ENOTDIR")
27181
+ if (isMissingFile(error53) || isRecord20(error53) && error53.code === "ENOTDIR")
27080
27182
  continue;
27081
27183
  throw new GrokTransportError("unavailable", "Grok Native Session metadata could not be read", {
27082
27184
  cause: error53
@@ -27088,10 +27190,10 @@ async function locateGrokNativeSession(options, sessionId) {
27088
27190
  } catch {
27089
27191
  continue;
27090
27192
  }
27091
- if (!isRecord19(parsed))
27193
+ if (!isRecord20(parsed))
27092
27194
  continue;
27093
27195
  const info = parsed.info;
27094
- const cwd = isRecord19(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path17.resolve(info.cwd) : path17.resolve(decodeURIComponent(entry.name));
27196
+ const cwd = isRecord20(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path17.resolve(info.cwd) : path17.resolve(decodeURIComponent(entry.name));
27095
27197
  const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path17.resolve(parsed.source_workspace_dir) : void 0;
27096
27198
  matches.push({
27097
27199
  cwd,
@@ -27124,10 +27226,10 @@ function parseNativeHistory(contents, sessionId) {
27124
27226
  } catch {
27125
27227
  throw new GrokTransportError("protocolError", "Grok Native history contains invalid JSON");
27126
27228
  }
27127
- if (!isRecord19(record4) || !isRecord19(record4.params))
27229
+ if (!isRecord20(record4) || !isRecord20(record4.params))
27128
27230
  continue;
27129
27231
  const params = record4.params;
27130
- if (params.sessionId !== sessionId || !isRecord19(params.update))
27232
+ if (params.sessionId !== sessionId || !isRecord20(params.update))
27131
27233
  continue;
27132
27234
  let metadata = grokNotificationMetadata(params._meta, params.update._meta);
27133
27235
  if (typeof record4.timestamp === "number" && Number.isFinite(record4.timestamp))
@@ -27176,13 +27278,23 @@ var GrokAcpTransport = class {
27176
27278
  throw new Error("Grok ACP inspection cannot reuse an open Session");
27177
27279
  try {
27178
27280
  const initialize = await this.#ensureInitialized();
27281
+ const connection = this.#connection;
27282
+ if (!connection)
27283
+ throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
27179
27284
  if (initialize.agentCapabilities?.sessionCapabilities?.list) {
27180
- const connection = this.#connection;
27181
- if (!connection)
27182
- throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
27183
27285
  await withTimeout(connection.listSessions({ cwd: this.#options.cwd }), this.#options.commandTimeoutMs, "Grok Session inspection");
27184
27286
  }
27185
- return initialize;
27287
+ try {
27288
+ const response = await withTimeout(connection.request("_x.ai/models/list", {}), this.#options.commandTimeoutMs, "Grok Model inspection");
27289
+ const modelState = isRecord20(response) ? response.result : void 0;
27290
+ if (!parseGrokModelState(modelState))
27291
+ throw new GrokTransportError("protocolError", "Grok returned an invalid Model catalog");
27292
+ return { ...initialize, _meta: { ...initialize._meta, modelState } };
27293
+ } catch (error53) {
27294
+ if (isGrokMethodNotFound(error53))
27295
+ return initialize;
27296
+ throw error53;
27297
+ }
27186
27298
  } catch (error53) {
27187
27299
  const classified = classifyStartupError(error53);
27188
27300
  await this.close().catch(() => void 0);
@@ -27197,7 +27309,7 @@ var GrokAcpTransport = class {
27197
27309
  if (!this.#connection)
27198
27310
  throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
27199
27311
  const result = await withTimeout(this.#connection.request("_x.ai/session/usage", { sessionId: this.sessionId }), this.#options.commandTimeoutMs, "Grok Session usage");
27200
- return isRecord19(result) ? result.usage : void 0;
27312
+ return isRecord20(result) ? result.usage : void 0;
27201
27313
  }
27202
27314
  async readHistory(sessionId, cwd = this.#options.cwd) {
27203
27315
  return readGrokNativeHistory({ ...this.#options, cwd }, sessionId);
@@ -27302,7 +27414,7 @@ var GrokAcpTransport = class {
27302
27414
  sessionId: this.#sessionId,
27303
27415
  toolCallId
27304
27416
  }), 3e3, "Grok question activity");
27305
- if (!isRecord19(raw) || !("timeout" in raw))
27417
+ if (!isRecord20(raw) || !("timeout" in raw))
27306
27418
  throw new GrokTransportError("protocolError", "Invalid Grok activity acknowledgement");
27307
27419
  return raw.timeout === null ? null : questionAutoResolutionSchema.parse(raw.timeout);
27308
27420
  } catch (error53) {
@@ -27574,7 +27686,7 @@ var GrokAcpTransport = class {
27574
27686
  }
27575
27687
  } : {}
27576
27688
  });
27577
- if (!isRecord19(response) || !isRecord19(response._meta) || !isRecord19(response._meta.model)) {
27689
+ if (!isRecord20(response) || !isRecord20(response._meta) || !isRecord20(response._meta.model)) {
27578
27690
  throw new GrokTransportError("protocolError", "Grok rejected Model configuration");
27579
27691
  }
27580
27692
  const selected = response._meta.model.Ok;
@@ -27614,7 +27726,7 @@ var GrokAcpTransport = class {
27614
27726
  permission_mode: mode
27615
27727
  });
27616
27728
  const response = await connection.request("_x.ai/session/info", { sessionId });
27617
- if (!isRecord19(response) || !isRecord19(response.result) || response.result.sessionId !== sessionId) {
27729
+ if (!isRecord20(response) || !isRecord20(response.result) || response.result.sessionId !== sessionId) {
27618
27730
  throw new Error("Grok did not confirm the target Session");
27619
27731
  }
27620
27732
  })()
@@ -27700,7 +27812,7 @@ var GrokAcpTransport = class {
27700
27812
  if (!isGrokExtensionSessionUpdateMethod(method) && !isGrokBackgroundNotificationMethod(method)) {
27701
27813
  return;
27702
27814
  }
27703
- if (typeof params.sessionId !== "string" || !isRecord19(params.update))
27815
+ if (typeof params.sessionId !== "string" || !isRecord20(params.update))
27704
27816
  return;
27705
27817
  this.#handleUpdate(params);
27706
27818
  }
@@ -27710,7 +27822,7 @@ var GrokAcpTransport = class {
27710
27822
  taskId,
27711
27823
  source
27712
27824
  });
27713
- if (!isRecord19(result) || result.taskId !== taskId || !["killed", "already_exited", "not_found"].includes(String(result.outcome)))
27825
+ if (!isRecord20(result) || result.taskId !== taskId || !["killed", "already_exited", "not_found"].includes(String(result.outcome)))
27714
27826
  throw new GrokTransportError("protocolError", "Malformed Grok task kill response");
27715
27827
  return result.outcome;
27716
27828
  }
@@ -27725,7 +27837,7 @@ var GrokAcpTransport = class {
27725
27837
  sessionId: this.sessionId,
27726
27838
  taskId
27727
27839
  });
27728
- if (!isRecord19(result) || result.taskId !== taskId || typeof result.deleted !== "boolean")
27840
+ if (!isRecord20(result) || result.taskId !== taskId || typeof result.deleted !== "boolean")
27729
27841
  throw new GrokTransportError("protocolError", "Malformed Grok scheduler delete response");
27730
27842
  return result.deleted;
27731
27843
  }
@@ -27737,21 +27849,21 @@ var GrokAcpTransport = class {
27737
27849
  try {
27738
27850
  raw = await withTimeout(this.#connection.request(method, params), this.#options.commandTimeoutMs, `Grok ${method}`);
27739
27851
  } catch (error53) {
27740
- if (!isRecord19(error53) || error53.code !== -32601)
27852
+ if (!isRecord20(error53) || error53.code !== -32601)
27741
27853
  throw error53;
27742
27854
  try {
27743
27855
  raw = await withTimeout(this.#connection.request(`_${method}`, params), this.#options.commandTimeoutMs, `Grok _${method}`);
27744
27856
  } catch (fallback) {
27745
- if (isRecord19(fallback) && fallback.code === -32601)
27857
+ if (isRecord20(fallback) && fallback.code === -32601)
27746
27858
  throw new GrokTransportError("unsupported", `Grok does not support ${method}`);
27747
27859
  throw fallback;
27748
27860
  }
27749
27861
  }
27750
- if (isRecord19(raw) && raw.error !== void 0 && raw.error !== null) {
27751
- const message = typeof raw.error === "string" ? raw.error : isRecord19(raw.error) && typeof raw.error.message === "string" ? raw.error.message : `Grok ${method} failed`;
27862
+ if (isRecord20(raw) && raw.error !== void 0 && raw.error !== null) {
27863
+ const message = typeof raw.error === "string" ? raw.error : isRecord20(raw.error) && typeof raw.error.message === "string" ? raw.error.message : `Grok ${method} failed`;
27752
27864
  throw new GrokTransportError("unavailable", message);
27753
27865
  }
27754
- return isRecord19(raw) && "result" in raw ? raw.result : raw;
27866
+ return isRecord20(raw) && "result" in raw ? raw.result : raw;
27755
27867
  }
27756
27868
  #handlePermission(params) {
27757
27869
  const observer = this.#activePrompt ?? this.#background;
@@ -27936,7 +28048,7 @@ var SessionImportScope = class {
27936
28048
  // dist/session-import.js
27937
28049
  var MAX_METADATA_BYTES = 4 * 1024 * 1024;
27938
28050
  var SUBAGENT_SESSION_KINDS = /* @__PURE__ */ new Set(["subagent", "subagent_resume"]);
27939
- function isRecord20(value) {
28051
+ function isRecord21(value) {
27940
28052
  return typeof value === "object" && value !== null && !Array.isArray(value);
27941
28053
  }
27942
28054
  async function readJson(file2, signal) {
@@ -27949,7 +28061,7 @@ function processAlive(pid) {
27949
28061
  process.kill(pid, 0);
27950
28062
  return true;
27951
28063
  } catch (error53) {
27952
- return isRecord20(error53) && error53.code === "EPERM";
28064
+ return isRecord21(error53) && error53.code === "EPERM";
27953
28065
  }
27954
28066
  }
27955
28067
  async function firstUserText(file2, signal) {
@@ -27966,10 +28078,10 @@ async function firstUserText(file2, signal) {
27966
28078
  } catch {
27967
28079
  continue;
27968
28080
  }
27969
- const update = isRecord20(entry) && isRecord20(entry.params) ? entry.params.update : null;
27970
- if (!isRecord20(update) || update.sessionUpdate !== "user_message_chunk")
28081
+ const update = isRecord21(entry) && isRecord21(entry.params) ? entry.params.update : null;
28082
+ if (!isRecord21(update) || update.sessionUpdate !== "user_message_chunk")
27971
28083
  continue;
27972
- const text = isRecord20(update.content) ? update.content.text : null;
28084
+ const text = isRecord21(update.content) ? update.content.text : null;
27973
28085
  return typeof text === "string" ? text : "";
27974
28086
  }
27975
28087
  return null;
@@ -28046,7 +28158,7 @@ var GrokSessionImport = class {
28046
28158
  if (!Array.isArray(entries))
28047
28159
  return active;
28048
28160
  for (const entry of entries) {
28049
- if (isRecord20(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
28161
+ if (isRecord21(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
28050
28162
  active.add(entry.session_id);
28051
28163
  }
28052
28164
  return active;
@@ -28095,7 +28207,7 @@ var GrokSessionImport = class {
28095
28207
  return null;
28096
28208
  try {
28097
28209
  const summary = await readJson(files[0], signal);
28098
- if (!isRecord20(summary) || !isRecord20(summary.info) || summary.info.id !== nativeSessionId)
28210
+ if (!isRecord21(summary) || !isRecord21(summary.info) || summary.info.id !== nativeSessionId)
28099
28211
  return null;
28100
28212
  if (typeof summary.session_kind === "string" && SUBAGENT_SESSION_KINDS.has(summary.session_kind))
28101
28213
  return null;
@@ -28909,115 +29021,14 @@ var GrokBackgroundItems = class {
28909
29021
  await handle.close();
28910
29022
  }
28911
29023
  } catch (error53) {
28912
- if (isRecord21(error53) && error53.code === "ENOENT")
29024
+ if (isRecord22(error53) && error53.code === "ENOENT")
28913
29025
  return;
28914
29026
  }
28915
29027
  }
28916
29028
  };
28917
- function isRecord21(value) {
28918
- return typeof value === "object" && value !== null && !Array.isArray(value);
28919
- }
28920
-
28921
- // dist/grok-models.js
28922
29029
  function isRecord22(value) {
28923
29030
  return typeof value === "object" && value !== null && !Array.isArray(value);
28924
29031
  }
28925
- function nonBlank(value) {
28926
- return typeof value === "string" && value.trim().length > 0;
28927
- }
28928
- function thinkingOptions(value) {
28929
- if (!Array.isArray(value))
28930
- return [];
28931
- const seen = /* @__PURE__ */ new Set();
28932
- const options = [];
28933
- for (const candidate of value) {
28934
- if (!isRecord22(candidate) || !nonBlank(candidate.label))
28935
- continue;
28936
- const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
28937
- if (!id.success || seen.has(id.data))
28938
- continue;
28939
- seen.add(id.data);
28940
- options.push({ id: id.data, label: candidate.label });
28941
- }
28942
- return options;
28943
- }
28944
- function parseGrokModelState(value) {
28945
- if (!isRecord22(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
28946
- return null;
28947
- }
28948
- const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
28949
- if (!currentModel.success)
28950
- return null;
28951
- const allThinking = /* @__PURE__ */ new Map();
28952
- const contextWindowTokensByModel = /* @__PURE__ */ new Map();
28953
- const defaultContextWindowTokensByModel = /* @__PURE__ */ new Map();
28954
- const models = [];
28955
- let currentThinkingOptionId;
28956
- for (const candidate of value.availableModels) {
28957
- if (!isRecord22(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
28958
- continue;
28959
- const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
28960
- if (!ref.success)
28961
- continue;
28962
- const metadata = isRecord22(candidate._meta) ? candidate._meta : {};
28963
- const options2 = thinkingOptions(metadata.reasoningEfforts);
28964
- if (Array.isArray(metadata.contextWindows) && metadata.contextWindows.includes(5e5)) {
28965
- defaultContextWindowTokensByModel.set(ref.data.id, 5e5);
28966
- }
28967
- if (typeof metadata.totalContextTokens === "number" && Number.isSafeInteger(metadata.totalContextTokens) && metadata.totalContextTokens > 0) {
28968
- contextWindowTokensByModel.set(ref.data.id, metadata.totalContextTokens);
28969
- }
28970
- for (const option of options2)
28971
- allThinking.set(option.id, option);
28972
- if (candidate.modelId === value.currentModelId && nonBlank(metadata.reasoningEffort)) {
28973
- const parsed = harnessThinkingOptionIdSchema.safeParse(metadata.reasoningEffort);
28974
- if (parsed.success && options2.some(({ id }) => id === parsed.data)) {
28975
- currentThinkingOptionId = parsed.data;
28976
- }
28977
- }
28978
- models.push({
28979
- ref: ref.data,
28980
- label: candidate.name,
28981
- ...options2.length > 0 ? { supportedThinkingOptionIds: options2.map(({ id }) => id) } : {}
28982
- });
28983
- }
28984
- if (!models.some(({ ref }) => ref.id === currentModel.data.id))
28985
- return null;
28986
- const options = [...allThinking.values()];
28987
- return {
28988
- currentModel: currentModel.data,
28989
- contextWindowTokensByModel,
28990
- defaultContextWindowTokensByModel,
28991
- ...currentThinkingOptionId ? { currentThinkingOptionId } : {},
28992
- catalog: {
28993
- models,
28994
- defaultModel: currentModel.data,
28995
- thinkingOptions: options,
28996
- ...currentThinkingOptionId ? { defaultThinkingOptionId: currentThinkingOptionId } : {}
28997
- }
28998
- };
28999
- }
29000
- function modelStateFromInitialize(response) {
29001
- return parseGrokModelState(isRecord22(response._meta) ? response._meta.modelState : void 0);
29002
- }
29003
- function modelStateFromSessionResponse(response) {
29004
- return parseGrokModelState(isRecord22(response) ? response.models : void 0);
29005
- }
29006
- function stateForGrokModel(modelState, nativeState, model2 = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
29007
- const selectedModel = model2;
29008
- const catalogModel = modelState.catalog.models.find(({ ref }) => ref.id === selectedModel.id);
29009
- const availableThinkingOptions = catalogModel?.supportedThinkingOptionIds?.flatMap((id) => {
29010
- const option = modelState.catalog.thinkingOptions.find((candidate) => candidate.id === id);
29011
- return option ? [option] : [];
29012
- });
29013
- return {
29014
- ...nativeState,
29015
- effectiveModel: selectedModel,
29016
- ...thinkingOptionId ? { effectiveThinkingOptionId: thinkingOptionId } : {},
29017
- ...permissionModeId ? { effectivePermissionModeId: permissionModeId } : {},
29018
- ...availableThinkingOptions ? { availableThinkingOptions } : {}
29019
- };
29020
- }
29021
29032
 
29022
29033
  // dist/grok-credits.js
29023
29034
  import { readFile as readFile9 } from "node:fs/promises";
@@ -29518,6 +29529,7 @@ function capabilitiesForModels(modelState) {
29518
29529
  };
29519
29530
  }
29520
29531
  var DEFAULT_CLOSE_TIMEOUT_MS = 2e3;
29532
+ var INSPECTION_CACHE_TTL_MS = 3e4;
29521
29533
  function invalidState(message) {
29522
29534
  return { code: "invalidState", message, retryable: false };
29523
29535
  }
@@ -31445,8 +31457,8 @@ var GrokAdapter = class {
31445
31457
  const cwd = path22.resolve(input.cwd ?? process.cwd());
31446
31458
  if (!input.refresh) {
31447
31459
  const cached2 = this.#inspectionCache.get(cwd);
31448
- if (cached2)
31449
- return cached2;
31460
+ if (cached2 && Date.now() < cached2.expiresAt)
31461
+ return cached2.inspection;
31450
31462
  }
31451
31463
  let transport = null;
31452
31464
  const startedAt = Date.now();
@@ -31466,7 +31478,10 @@ var GrokAdapter = class {
31466
31478
  permissionModes: GROK_PERMISSION_MODE_CATALOG,
31467
31479
  capabilities: capabilitiesForModels(modelState)
31468
31480
  };
31469
- this.#inspectionCache.set(cwd, ready);
31481
+ this.#inspectionCache.set(cwd, {
31482
+ inspection: ready,
31483
+ expiresAt: Date.now() + INSPECTION_CACHE_TTL_MS
31484
+ });
31470
31485
  this.#scheduleCreditsRefresh();
31471
31486
  return ready;
31472
31487
  } catch (error53) {