@karlorz/codexhost-cli-win32-arm64 0.13.3-7 → 0.14.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 (34) hide show
  1. package/README.md +1 -1
  2. package/app/codexhost-distribution.json +1 -1
  3. package/app/console-server.mjs +55 -4
  4. package/app/console-web.js +344 -54
  5. package/app/cpa-live-voice-hook.js +55 -4
  6. package/app/desktop-controller.mjs +69 -8
  7. package/app/host-runtime.mjs +743 -230
  8. package/app/plugins/antigravity/plugin.mjs +88 -12
  9. package/app/plugins/claude-code/plugin.mjs +397 -21
  10. package/app/plugins/codebuddy/plugin.mjs +107 -17
  11. package/app/plugins/codex-usage/plugin.mjs +67 -7
  12. package/app/plugins/copilot/assets/icon.png +0 -0
  13. package/app/plugins/copilot/manifest.json +26 -0
  14. package/app/plugins/copilot/plugin.mjs +34645 -0
  15. package/app/plugins/cursor-cli/plugin.mjs +88 -6
  16. package/app/plugins/deepseek-harness/plugin.mjs +73 -6
  17. package/app/plugins/enabled.json +1 -0
  18. package/app/plugins/grok/plugin.mjs +272 -60
  19. package/app/plugins/hermes/plugin.mjs +70 -4
  20. package/app/plugins/kimi-code/plugin.mjs +73 -6
  21. package/app/plugins/kiro-cli/plugin.mjs +73 -6
  22. package/app/plugins/omp/plugin.mjs +73 -112
  23. package/app/plugins/opencode/plugin.mjs +75 -6
  24. package/app/plugins/pi/plugin.mjs +204 -44
  25. package/app/plugins/qoder/plugin.mjs +73 -6
  26. package/app/plugins/qoder-cn/plugin.mjs +73 -6
  27. package/app/plugins/workbuddy/plugin.mjs +368 -41
  28. package/app/plugins/zcode/plugin.mjs +74 -6
  29. package/app/renderer-extension.js +749 -157
  30. package/bin/codexhost.exe +0 -0
  31. package/libexec/codexhost-node-repl.exe +0 -0
  32. package/libexec/codexhost-shim.exe +0 -0
  33. package/libexec/codexhost-updater.exe +0 -0
  34. package/package.json +1 -1
@@ -14662,10 +14662,19 @@ var model = external_exports.string().min(1).max(512);
14662
14662
  var project = external_exports.string().min(1).max(4096);
14663
14663
  var usageStatisticsParamsSchema = external_exports.strictObject({
14664
14664
  range: external_exports.enum(USAGE_STATISTICS_RANGES),
14665
+ /** Display timezone for ranges, dates and hourly buckets; omitted means the Host's local zone. */
14666
+ timeZone: external_exports.string().min(1).max(128).refine((value) => {
14667
+ try {
14668
+ new Intl.DateTimeFormat("en", { timeZone: value });
14669
+ return true;
14670
+ } catch {
14671
+ return false;
14672
+ }
14673
+ }, "Unsupported usage statistics timezone").optional(),
14665
14674
  harness: harness.optional(),
14666
14675
  model: model.nullable().optional(),
14667
14676
  project: project.nullable().optional(),
14668
- /** One local date inside the range. */
14677
+ /** One date in the query timezone inside the range. */
14669
14678
  date: localDate.optional()
14670
14679
  });
14671
14680
  var usageStatisticsTotalsSchema = external_exports.strictObject({
@@ -14701,7 +14710,7 @@ var usageStatisticsSessionSchema = external_exports.strictObject({
14701
14710
  });
14702
14711
  var usageStatisticsResultSchema = external_exports.strictObject({
14703
14712
  range: external_exports.enum(USAGE_STATISTICS_RANGES),
14704
- /** First local date of the range; null for all time. */
14713
+ /** First date in the query timezone (Host local when omitted); null for all time. */
14705
14714
  from: localDate.nullable(),
14706
14715
  to: localDate,
14707
14716
  /** The filters these figures apply, echoed so a late answer to older filters is recognised. */
@@ -14741,7 +14750,7 @@ var usageStatisticsResultSchema = external_exports.strictObject({
14741
14750
  totals: usageStatisticsTotalsSchema,
14742
14751
  /** Each date and Harness of the range: every filter except the day. */
14743
14752
  daily: external_exports.array(external_exports.strictObject({ date: localDate, harness, ...totals })).max(2e5),
14744
- /** Local weekday (0 = Sunday) and hour, all filters applied. */
14753
+ /** Weekday (0 = Sunday) and hour in the query timezone, all filters applied. */
14745
14754
  hourly: external_exports.array(external_exports.strictObject({
14746
14755
  weekday: external_exports.number().int().min(0).max(6),
14747
14756
  hour: external_exports.number().int().min(0).max(23),
@@ -14832,6 +14841,8 @@ var CONSOLE_HOST_METHODS = Object.freeze([
14832
14841
  "codexhost/harness/display-settings/set",
14833
14842
  "codexhost/harness/inspect",
14834
14843
  "codexhost/harness/installation",
14844
+ "codexhost/harness/installation/start",
14845
+ "codexhost/harness/installation/status",
14835
14846
  "codexhost/harness/launch-settings/get",
14836
14847
  "codexhost/harness/launch-settings/set",
14837
14848
  "codexhost/harness/grok-computer-use/get",
@@ -14909,7 +14920,18 @@ var threadManualCompactionStartedSchema = external_exports.strictObject({
14909
14920
  var nonNegativeSafeIntegerSchema = external_exports.number().int().safe().nonnegative();
14910
14921
  var finiteNonNegativeNumberSchema = external_exports.number().finite().nonnegative();
14911
14922
  var cacheHitRatePercentSchema = external_exports.number().finite().min(0).max(100);
14923
+ var indicatorTextSchema = (maximum) => harnessLocalizedTextSchema.refine((entries) => Object.values(entries).every((text2) => text2.length <= maximum));
14924
+ var composerIndicatorsSchema = external_exports.array(external_exports.object({
14925
+ kind: external_exports.literal("countdown"),
14926
+ id: external_exports.string().min(1).max(64),
14927
+ expiresAtUnix: nonNegativeSafeIntegerSchema,
14928
+ label: indicatorTextSchema(256).optional(),
14929
+ tooltip: indicatorTextSchema(1024).optional()
14930
+ }).strict()).max(2).refine((entries) => new Set(entries.map(({ id: id2 }) => id2)).size === entries.length, {
14931
+ message: "Composer indicator IDs must be unique"
14932
+ });
14912
14933
  var threadUsageSnapshotSchema = external_exports.object({
14934
+ composerIndicators: composerIndicatorsSchema.optional(),
14913
14935
  inputTokens: nonNegativeSafeIntegerSchema.optional(),
14914
14936
  cachedInputTokens: nonNegativeSafeIntegerSchema.optional(),
14915
14937
  cacheWriteInputTokens: nonNegativeSafeIntegerSchema.optional(),
@@ -15317,7 +15339,9 @@ var harnessSessionCapabilitiesSchema = external_exports.object({
15317
15339
  }).strict().optional(),
15318
15340
  autonomousTurns: external_exports.object({
15319
15341
  observe: external_exports.boolean()
15320
- }).strict().optional()
15342
+ }).strict().optional(),
15343
+ /** True only when `turn.steer` delivers input into the active Turn through a native primitive. */
15344
+ steer: external_exports.boolean().optional()
15321
15345
  }).strict();
15322
15346
  var harnessConfigurationStateSchema = external_exports.object({
15323
15347
  effectiveModel: harnessModelRefSchema.optional(),
@@ -15449,6 +15473,15 @@ var threadOwnershipListResultSchema = external_exports.object({
15449
15473
  seen.add(thread.threadId);
15450
15474
  }
15451
15475
  });
15476
+ var threadSteeringInspectParamsSchema = external_exports.object({
15477
+ threadId: hostThreadIdSchema,
15478
+ /** The text about to be steered; a Harness command always stops and restarts. */
15479
+ text: external_exports.string().optional()
15480
+ }).strict();
15481
+ var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
15482
+ var threadSteeringInspectResultSchema = external_exports.object({
15483
+ delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
15484
+ }).strict();
15452
15485
 
15453
15486
  // ../../shared-contracts/dist/harness-plugins.js
15454
15487
  var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
@@ -15570,6 +15603,10 @@ var harnessInstallationStateSchema = external_exports.object({
15570
15603
  latestVersion: external_exports.string().min(1).max(128),
15571
15604
  updateAvailable: external_exports.boolean(),
15572
15605
  canUpdate: external_exports.boolean(),
15606
+ /** Defaults to CLI; some Harnesses ship only inside a desktop application. */
15607
+ versionKind: external_exports.enum(["cli", "application"]).optional(),
15608
+ /** Official download opened by the user; does not imply an automatic installation. */
15609
+ manualUpdateUrl: external_exports.url().max(2048).refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Manual updates require a credential-free HTTPS URL").optional(),
15573
15610
  // Adapter-owned diagnostic text; UI uses messageCode rather than displaying it verbatim.
15574
15611
  message: external_exports.string().max(2048).optional(),
15575
15612
  messageCode: external_exports.string().min(1).max(128).optional(),
@@ -15577,6 +15614,20 @@ var harnessInstallationStateSchema = external_exports.object({
15577
15614
  notice: harnessLocalizedTextSchema.optional(),
15578
15615
  latestVersionKind: external_exports.enum(["unknown", "tracking-branch"]).optional()
15579
15616
  }).strict();
15617
+ var harnessInstallationTaskParamsSchema = external_exports.object({ taskId: external_exports.string().uuid() }).strict();
15618
+ var harnessInstallationTaskSchema = external_exports.discriminatedUnion("status", [
15619
+ external_exports.object({ taskId: external_exports.string().uuid(), status: external_exports.literal("running") }).strict(),
15620
+ external_exports.object({
15621
+ taskId: external_exports.string().uuid(),
15622
+ status: external_exports.literal("succeeded"),
15623
+ result: harnessInstallationStateSchema
15624
+ }).strict(),
15625
+ external_exports.object({
15626
+ taskId: external_exports.string().uuid(),
15627
+ status: external_exports.literal("failed"),
15628
+ error: external_exports.object({ code: external_exports.number().int(), message: external_exports.string().min(1).max(2048) }).strict()
15629
+ }).strict()
15630
+ ]);
15580
15631
 
15581
15632
  // ../../shared-contracts/dist/codex-accounts.js
15582
15633
  var accountIdSchema = external_exports.string().min(1).max(256).regex(/^[A-Za-z0-9._~-]+$/u);
@@ -16135,6 +16186,7 @@ var usageFields = /* @__PURE__ */ new Set([
16135
16186
  ...safeIntegerFields,
16136
16187
  ...percentFields,
16137
16188
  "sessionCacheUsage",
16189
+ "composerIndicators",
16138
16190
  "totalCostUsd",
16139
16191
  "totalCredits",
16140
16192
  "contextUsagePercent",
@@ -16157,6 +16209,7 @@ function parseHostUsage(value) {
16157
16209
  throw new Error(`Harness Usage contains unknown field '${key}'`);
16158
16210
  }
16159
16211
  }
16212
+ const indicators = value.composerIndicators === void 0 ? {} : { composerIndicators: composerIndicatorsSchema.parse(value.composerIndicators) };
16160
16213
  for (const field of [
16161
16214
  "totalCredits",
16162
16215
  "contextUsagePercent",
@@ -16227,9 +16280,9 @@ function parseHostUsage(value) {
16227
16280
  if (value.costSource !== "publicPrice") {
16228
16281
  throw new Error("Harness Usage 'unpricedModels' must be provided with a 'publicPrice' cost");
16229
16282
  }
16230
- return { ...value, unpricedModels: [...models] };
16283
+ return { ...value, ...indicators, unpricedModels: [...models] };
16231
16284
  }
16232
- return { ...value };
16285
+ return { ...value, ...indicators };
16233
16286
  }
16234
16287
  var requestTokenFields = [
16235
16288
  "inputTokens",
@@ -16428,6 +16481,7 @@ var harnessBrokerMethodSchema = external_exports.enum([
16428
16481
  "adapter.open",
16429
16482
  "adapter.subagent.readSnapshot",
16430
16483
  "session.readSnapshot",
16484
+ "session.readCapabilities",
16431
16485
  "session.refreshUsage",
16432
16486
  "session.execute",
16433
16487
  "session.commands.list",
@@ -16608,6 +16662,11 @@ var turnStartSchema = external_exports.object({
16608
16662
  turnId: hostTurnIdSchema,
16609
16663
  input: external_exports.array(textInputSchema)
16610
16664
  }).strict();
16665
+ var turnSteerSchema = external_exports.object({
16666
+ type: external_exports.literal("turn.steer"),
16667
+ turnId: hostTurnIdSchema,
16668
+ input: external_exports.array(textInputSchema)
16669
+ }).strict();
16611
16670
  var turnCancelSchema = external_exports.object({ type: external_exports.literal("turn.cancel"), turnId: hostTurnIdSchema }).strict();
16612
16671
  var interactionResponseSchema = external_exports.union([
16613
16672
  external_exports.object({
@@ -16633,6 +16692,7 @@ var permissionSelectSchema = external_exports.object({
16633
16692
  }).strict();
16634
16693
  var brokerHostCommandSchema = external_exports.discriminatedUnion("type", [
16635
16694
  turnStartSchema,
16695
+ turnSteerSchema,
16636
16696
  turnCancelSchema,
16637
16697
  interactionRespondSchema,
16638
16698
  modelSelectSchema,
@@ -16825,6 +16885,7 @@ function parseSessionMetadata(value) {
16825
16885
  sessionId: candidate.sessionId,
16826
16886
  sessionGeneration: candidate.sessionGeneration,
16827
16887
  capabilities: harnessSessionCapabilitiesSchema.parse(candidate.capabilities),
16888
+ readCapabilities: candidate.readCapabilities === true,
16828
16889
  initialState: state,
16829
16890
  initialUsage: candidate.initialUsage === null ? null : parseHostUsage(candidate.initialUsage),
16830
16891
  commands: candidate.commands === true
@@ -17176,6 +17237,11 @@ var BrokeredHarnessSession = class {
17176
17237
  event: { type: "session.faulted", error: unavailable(error52.message) }
17177
17238
  });
17178
17239
  }
17240
+ async readCapabilities() {
17241
+ if (!this.#metadata.readCapabilities)
17242
+ return { ...this.capabilities, steer: false };
17243
+ return harnessSessionCapabilitiesSchema.parse(await this.#request("session.readCapabilities", {}));
17244
+ }
17179
17245
  async refreshUsage() {
17180
17246
  await this.#request("session.refreshUsage", {});
17181
17247
  }
@@ -17207,6 +17273,8 @@ var BrokeredHarnessSession = class {
17207
17273
  try {
17208
17274
  return parseHarnessResult(await this.#request("session.execute", { command }));
17209
17275
  } catch (error52) {
17276
+ if (command.type === "turn.steer")
17277
+ throw error52;
17210
17278
  return {
17211
17279
  ok: false,
17212
17280
  error: unavailable(error52 instanceof Error ? error52.message : String(error52))
@@ -17752,6 +17820,31 @@ function createClaudeUsageStatistics(environment) {
17752
17820
  });
17753
17821
  }
17754
17822
 
17823
+ // dist/claude-prompt-cache.js
17824
+ function lastClaudeAssistantResponseUnix(messages) {
17825
+ let latest;
17826
+ for (const entry of messages) {
17827
+ if (typeof entry !== "object" || entry === null || !("type" in entry) || entry.type !== "assistant" || "isSidechain" in entry && entry.isSidechain === true || "parent_tool_use_id" in entry && entry.parent_tool_use_id != null || !("timestamp" in entry) || typeof entry.timestamp !== "string")
17828
+ continue;
17829
+ const time3 = Math.floor(Date.parse(entry.timestamp) / 1e3);
17830
+ if (Number.isSafeInteger(time3) && time3 >= 0)
17831
+ latest = Math.max(latest ?? 0, time3);
17832
+ }
17833
+ return latest;
17834
+ }
17835
+ function claudePromptCacheIndicators(accountCreditsSupported, lastResponseAtUnix) {
17836
+ if (!accountCreditsSupported || lastResponseAtUnix === void 0)
17837
+ return [];
17838
+ return [
17839
+ {
17840
+ kind: "countdown",
17841
+ id: "prompt-cache",
17842
+ expiresAtUnix: lastResponseAtUnix + 3600,
17843
+ label: { en: "Prompt cache", "zh-CN": "提示词缓存" }
17844
+ }
17845
+ ];
17846
+ }
17847
+
17755
17848
  // dist/claude-code-adapter.js
17756
17849
  import { randomUUID as randomUUID5 } from "node:crypto";
17757
17850
  import path16 from "node:path";
@@ -54570,11 +54663,20 @@ function parseResultModelUsage(value) {
54570
54663
  if (!isRecord7(value))
54571
54664
  return void 0;
54572
54665
  const usage = [];
54573
- for (const entry of Object.values(value)) {
54666
+ for (const [model2, entry] of Object.entries(value)) {
54574
54667
  if (!isRecord7(entry) || !safeNonNegativeInteger(entry.inputTokens) || !safeNonNegativeInteger(entry.outputTokens)) {
54575
54668
  return void 0;
54576
54669
  }
54577
- usage.push({ inputTokens: entry.inputTokens, outputTokens: entry.outputTokens });
54670
+ const cacheRead = safeNonNegativeInteger(entry.cacheReadInputTokens) ? entry.cacheReadInputTokens : 0;
54671
+ const cacheWrite = safeNonNegativeInteger(entry.cacheCreationInputTokens) ? entry.cacheCreationInputTokens : 0;
54672
+ const promptTokens = entry.inputTokens + cacheRead + cacheWrite;
54673
+ usage.push({
54674
+ model: model2,
54675
+ inputTokens: entry.inputTokens,
54676
+ outputTokens: entry.outputTokens,
54677
+ ...Number.isSafeInteger(promptTokens) ? { promptTokens } : {},
54678
+ ...safeNonNegativeInteger(entry.contextWindow) && entry.contextWindow > 0 ? { contextWindowTokens: entry.contextWindow } : {}
54679
+ });
54578
54680
  }
54579
54681
  return usage;
54580
54682
  }
@@ -54931,6 +55033,7 @@ var ClaudeNativeTurnAccumulator = class {
54931
55033
  events.push({
54932
55034
  type: "message.completed",
54933
55035
  messageId,
55036
+ localCommand: true,
54934
55037
  ...checkpointId ? { checkpointId } : {}
54935
55038
  });
54936
55039
  }
@@ -55413,6 +55516,10 @@ function conversationMessages(values, sessionId) {
55413
55516
  const messages = [];
55414
55517
  const ids = /* @__PURE__ */ new Set();
55415
55518
  let promptId = null;
55519
+ const occupancy = new ClaudeBackgroundOccupancy();
55520
+ let accumulator = new ClaudeNativeTurnAccumulator();
55521
+ const sends = /* @__PURE__ */ new Set();
55522
+ let pendingNotification = false;
55416
55523
  for (const value of values) {
55417
55524
  if (!isRecord8(value))
55418
55525
  throw new Error("Claude history contains a malformed message");
@@ -55431,8 +55538,46 @@ function conversationMessages(values, sessionId) {
55431
55538
  message: value.message,
55432
55539
  nested: typeof value.parent_tool_use_id === "string" && value.parent_tool_use_id.length > 0,
55433
55540
  interrupted,
55541
+ startsTurn: false,
55434
55542
  syntheticUser: value.type === "user" && (interrupted || value.isSynthetic === true || value.isMeta === true || isTaskNotificationOrigin(value) || value.toolUseResult !== void 0 && value.toolUseResult !== null)
55435
55543
  };
55544
+ const notification = message.type === "user" && !message.nested && (isTaskNotificationOrigin(value) || textParts(message.message.content).some(isTaskNotificationRecord));
55545
+ message.startsTurn = isHumanUser(message) || notification && !occupancy.unsettled && !pendingNotification;
55546
+ if (message.startsTurn) {
55547
+ occupancy.clear();
55548
+ sends.clear();
55549
+ accumulator = new ClaudeNativeTurnAccumulator();
55550
+ }
55551
+ for (const event of accumulator.consume(value).events) {
55552
+ if (event.type === "subagent.started") {
55553
+ if (event.operation === "send") {
55554
+ sends.add(event.callId);
55555
+ if (event.nativeSubagentId)
55556
+ occupancy.occupyAgent(event.nativeSubagentId);
55557
+ } else if (event.background)
55558
+ occupancy.occupySpawn(event.callId, event.nativeSubagentId);
55559
+ } else if (event.type === "subagent.completed") {
55560
+ if (!event.isError && (event.continuesInBackground || sends.has(event.callId))) {
55561
+ occupancy.occupySpawn(event.callId, event.nativeSubagentId);
55562
+ } else
55563
+ occupancy.release(event.callId, event.nativeSubagentId);
55564
+ sends.delete(event.callId);
55565
+ } else if (event.type === "workflow.launched" && event.background && !event.isError) {
55566
+ occupancy.occupySpawn(event.callId, event.taskId);
55567
+ } else if (event.type === "subagent.settled") {
55568
+ occupancy.notify(event.callId, event.nativeSubagentId);
55569
+ }
55570
+ }
55571
+ if (notification)
55572
+ pendingNotification = true;
55573
+ if (message.type === "assistant" && !message.nested) {
55574
+ pendingNotification = false;
55575
+ if (["end_turn", "stop_sequence", "max_tokens"].includes(String(message.message.stop_reason))) {
55576
+ occupancy.releaseContinuations();
55577
+ }
55578
+ }
55579
+ if (interrupted)
55580
+ occupancy.clear();
55436
55581
  messages.push(message);
55437
55582
  if (isHumanUser(message)) {
55438
55583
  promptId = typeof value.promptId === "string" && value.promptId.length > 0 ? value.promptId : null;
@@ -55489,17 +55634,17 @@ function mapClaudeSnapshot(values, sessionId) {
55489
55634
  const turns = [];
55490
55635
  for (let index = 0; index < messages.length; ) {
55491
55636
  const user = messages[index];
55492
- if (!user || !isHumanUser(user)) {
55637
+ if (!user || !user.startsTurn) {
55493
55638
  index += 1;
55494
55639
  continue;
55495
55640
  }
55496
55641
  let end = index + 1;
55497
- while (end < messages.length && !isHumanUser(messages[end]))
55642
+ while (end < messages.length && !messages[end]?.startsTurn)
55498
55643
  end += 1;
55499
55644
  const turnMessages = messages.slice(index, end);
55500
55645
  const outcome = turnOutcome(turnMessages);
55501
55646
  const results = toolResultBlocks(turnMessages);
55502
- const checkpointMessage = turnMessages.findLast(({ type, interrupted }) => type === "assistant" || interrupted);
55647
+ const checkpointMessage = turnMessages.findLast(({ type, interrupted, nested }) => !nested && (type === "assistant" || interrupted));
55503
55648
  let agentMessageOrdinal = 0;
55504
55649
  let reasoningOrdinal = 0;
55505
55650
  let toolOrdinal = 0;
@@ -56663,12 +56808,21 @@ async function closeClaudeProcessGroup(child, timeoutMs) {
56663
56808
  throw new Error("Claude SDK process group did not exit");
56664
56809
  }
56665
56810
 
56811
+ // dist/transport.js
56812
+ var ClaudeSteerMissedTurnError = class extends Error {
56813
+ constructor() {
56814
+ super("Claude Code steer missed the active Turn");
56815
+ this.name = "ClaudeSteerMissedTurnError";
56816
+ }
56817
+ };
56818
+
56666
56819
  // dist/sdk-transport.js
56667
56820
  var CLIENT_APP = "codexhost-claude-code-adapter/0.0.0";
56668
56821
  var SESSION_ENTRYPOINT = "codexhost-sdk";
56669
56822
  var APPROVAL_TITLE_MAX_LENGTH = 120;
56670
56823
  var APPROVAL_DESCRIPTION_MAX_LENGTH = 500;
56671
56824
  var DEFAULT_ABORT_TIMEOUT_MS = 2e3;
56825
+ var DEFAULT_STEER_QUEUED_TIMEOUT_MS = 5e3;
56672
56826
  var WORKFLOW_AGENT_LABEL_LIMIT = 1e3;
56673
56827
  var INTERRUPT_TIMEOUT_MESSAGE = "Claude SDK interrupt timed out";
56674
56828
  var PushableInput = class {
@@ -56924,6 +57078,11 @@ var ClaudeSdkTransport = class {
56924
57078
  #queryFactory;
56925
57079
  #thinkingOptionId;
56926
57080
  #active = null;
57081
+ #steerQueuedTimeoutMs;
57082
+ #nativeSteer = false;
57083
+ /** Root tool calls of the requested Turn that have started and not yet returned a result. */
57084
+ #rootToolCalls = /* @__PURE__ */ new Set();
57085
+ #pendingSteers = /* @__PURE__ */ new Map();
56927
57086
  #autonomous = null;
56928
57087
  #autonomousTurnHandler = null;
56929
57088
  #idleHandler = null;
@@ -56947,6 +57106,7 @@ var ClaudeSdkTransport = class {
56947
57106
  this.sessionId = options.sessionId;
56948
57107
  this.#cwd = options.cwd;
56949
57108
  this.#abortTimeoutMs = options.abortTimeoutMs ?? DEFAULT_ABORT_TIMEOUT_MS;
57109
+ this.#steerQueuedTimeoutMs = options.steerQueuedTimeoutMs ?? DEFAULT_STEER_QUEUED_TIMEOUT_MS;
56950
57110
  this.#closeTimeoutMs = options.closeTimeoutMs;
56951
57111
  this.#command = options.command;
56952
57112
  this.#environment = options.environment ?? process.env;
@@ -57001,7 +57161,8 @@ var ClaudeSdkTransport = class {
57001
57161
  thinking: thinking.enabled ? { type: "adaptive", display: "summarized" } : { type: "disabled" },
57002
57162
  ...thinking.effort ? { effort: thinking.effort } : {},
57003
57163
  pathToClaudeCodeExecutable: executable,
57004
- settingSources: ["user"],
57164
+ // Omitted settingSources loads user, project and local settings like the
57165
+ // Claude Code CLI, so project CLAUDE.md and .claude/skills apply.
57005
57166
  permissionMode: this.#permissionMode,
57006
57167
  ...this.#allowDangerouslySkipPermissions ? { allowDangerouslySkipPermissions: true } : {},
57007
57168
  canUseTool: (toolName, input, options) => this.#canUseTool(toolName, input, options),
@@ -57038,6 +57199,40 @@ var ClaudeSdkTransport = class {
57038
57199
  return null;
57039
57200
  return { commands: this.#slashCommands, skillNames: this.#skillNames };
57040
57201
  }
57202
+ supportsNativeSteer() {
57203
+ return this.#nativeSteer;
57204
+ }
57205
+ /**
57206
+ * `priority: "next"` joins after the current tool call, and a tool result is always followed by
57207
+ * another model request. So a steer written while a root tool call runs folds into this Turn;
57208
+ * one written while Claude streams its final text may instead run as the next Turn.
57209
+ */
57210
+ canSteerActiveTurn() {
57211
+ return this.#nativeSteer && this.#active !== null && this.#rootToolCalls.size > 0;
57212
+ }
57213
+ #observeRootToolCalls(message) {
57214
+ if (!isRecord11(message) || message.parent_tool_use_id != null)
57215
+ return;
57216
+ if (message.type !== "assistant" && message.type !== "user")
57217
+ return;
57218
+ const body = message.message;
57219
+ if (!isRecord11(body) || !Array.isArray(body.content))
57220
+ return;
57221
+ for (const block of body.content) {
57222
+ if (!isRecord11(block))
57223
+ continue;
57224
+ if (message.type === "assistant" && block.type === "tool_use" && typeof block.id === "string") {
57225
+ this.#rootToolCalls.add(block.id);
57226
+ } else if (message.type === "user" && block.type === "tool_result" && typeof block.tool_use_id === "string") {
57227
+ this.#rootToolCalls.delete(block.tool_use_id);
57228
+ }
57229
+ }
57230
+ }
57231
+ #observeNativeCapabilities(message) {
57232
+ if (!isRecord11(message) || message.type !== "system" || message.subtype !== "init")
57233
+ return;
57234
+ this.#nativeSteer = Array.isArray(message.capabilities) && message.capabilities.includes("msg_lifecycle_v1");
57235
+ }
57041
57236
  #observeSlashCommands(message) {
57042
57237
  if (!isRecord11(message) || message.type !== "system")
57043
57238
  return;
@@ -57160,6 +57355,7 @@ var ClaudeSdkTransport = class {
57160
57355
  const unclaimed = this.#autonomous?.events ?? [];
57161
57356
  this.#autonomous = null;
57162
57357
  const promise2 = new Promise((resolve5, reject) => {
57358
+ this.#rootToolCalls.clear();
57163
57359
  this.#active = {
57164
57360
  accumulator: new ClaudeNativeTurnAccumulator(this.#provider ? { provider: this.#provider } : {}),
57165
57361
  onEvent,
@@ -57179,6 +57375,51 @@ var ClaudeSdkTransport = class {
57179
57375
  });
57180
57376
  return promise2;
57181
57377
  }
57378
+ /**
57379
+ * Claude accepts the input with `queued`; Claude Code 2.1.280 then emits `started` after the
57380
+ * current tool call, when `priority: "next"` joins the running Turn. Waiting for `started` would
57381
+ * hold the caller for a whole tool call.
57382
+ *
57383
+ * Once written, the input cannot be recalled: Claude delivers it in this Turn or runs it next.
57384
+ * The Turn ending first therefore does not reject it, and a missing `queued` receipt resolves
57385
+ * after a bounded wait so callers that serialize requests are never held indefinitely.
57386
+ */
57387
+ steer(text2, messageId) {
57388
+ if (this.#closePromise || !this.#started || !this.#query || !this.canSteerActiveTurn()) {
57389
+ return Promise.reject(new ClaudeSteerMissedTurnError());
57390
+ }
57391
+ const promise2 = new Promise((resolve5, reject) => {
57392
+ this.#pendingSteers.set(messageId, { resolve: resolve5, reject, timer: void 0 });
57393
+ });
57394
+ try {
57395
+ this.#input.push({
57396
+ type: "user",
57397
+ message: { role: "user", content: text2 },
57398
+ parent_tool_use_id: null,
57399
+ session_id: this.sessionId,
57400
+ uuid: messageId,
57401
+ origin: { kind: "human" },
57402
+ priority: "next"
57403
+ });
57404
+ } catch {
57405
+ this.#pendingSteers.delete(messageId);
57406
+ return Promise.reject(new ClaudeSteerMissedTurnError());
57407
+ }
57408
+ const pending = this.#pendingSteers.get(messageId);
57409
+ if (pending) {
57410
+ pending.timer = setTimeout(() => this.#acceptSteer(messageId), this.#steerQueuedTimeoutMs);
57411
+ pending.timer.unref?.();
57412
+ }
57413
+ return promise2;
57414
+ }
57415
+ #acceptSteer(messageId) {
57416
+ const pending = this.#pendingSteers.get(messageId);
57417
+ if (!pending)
57418
+ return;
57419
+ this.#pendingSteers.delete(messageId);
57420
+ clearTimeout(pending.timer);
57421
+ pending.resolve();
57422
+ }
57182
57423
  respondToInteraction(response) {
57183
57424
  const pending = this.#interactions.get(response.requestId);
57184
57425
  if (!pending) {
@@ -57350,6 +57591,7 @@ var ClaudeSdkTransport = class {
57350
57591
  }
57351
57592
  }
57352
57593
  async #close() {
57594
+ this.#rejectPendingSteers();
57353
57595
  const failures = [];
57354
57596
  this.#closeInteractions("all", "cancelled");
57355
57597
  try {
@@ -57403,6 +57645,7 @@ var ClaudeSdkTransport = class {
57403
57645
  }
57404
57646
  this.#query = null;
57405
57647
  const active = this.#active;
57648
+ this.#rootToolCalls.clear();
57406
57649
  this.#active = null;
57407
57650
  this.#autonomous = null;
57408
57651
  this.#idleAccumulator = null;
@@ -57457,6 +57700,26 @@ var ClaudeSdkTransport = class {
57457
57700
  await delay(10);
57458
57701
  }
57459
57702
  }
57703
+ #rejectPendingSteers() {
57704
+ const pending = [...this.#pendingSteers.values()];
57705
+ this.#pendingSteers.clear();
57706
+ const error52 = new Error("Claude Code steer receipt was lost after input was written");
57707
+ for (const entry of pending) {
57708
+ clearTimeout(entry.timer);
57709
+ entry.reject(error52);
57710
+ }
57711
+ }
57712
+ /** `queued` is Claude's acceptance of this message into the running Session. */
57713
+ #observeSteer(message) {
57714
+ if (this.#pendingSteers.size === 0 || !isRecord11(message) || message.type !== "command_lifecycle") {
57715
+ return;
57716
+ }
57717
+ if (message.state !== "queued")
57718
+ return;
57719
+ if (typeof message.command_uuid !== "string" || message.command_uuid.length === 0)
57720
+ return;
57721
+ this.#acceptSteer(message.command_uuid);
57722
+ }
57460
57723
  #observeBackgroundTasks(message) {
57461
57724
  if (!isRecord11(message) || message.type !== "system")
57462
57725
  return;
@@ -57497,6 +57760,7 @@ var ClaudeSdkTransport = class {
57497
57760
  this.#observeBackgroundTasks(message);
57498
57761
  this.#observeWorkflowAgents(message);
57499
57762
  this.#observeSlashCommands(message);
57763
+ this.#observeNativeCapabilities(message);
57500
57764
  const permissionMode = permissionModeFromMessage(message);
57501
57765
  if (permissionMode && permissionMode !== this.#permissionMode) {
57502
57766
  this.#permissionMode = permissionMode;
@@ -57505,13 +57769,16 @@ var ClaudeSdkTransport = class {
57505
57769
  const planLimit = parseClaudePlanLimitEvent(message);
57506
57770
  if (planLimit)
57507
57771
  this.#onPlanLimit(planLimit);
57772
+ this.#observeSteer(message);
57508
57773
  const active = this.#active;
57509
57774
  if (active) {
57775
+ this.#observeRootToolCalls(message);
57510
57776
  const interpreted2 = active.accumulator.consume(message);
57511
57777
  for (const event of interpreted2.events)
57512
57778
  active.onEvent(event);
57513
57779
  if (interpreted2.terminal) {
57514
57780
  this.#closeInteractions("root", "superseded");
57781
+ this.#rootToolCalls.clear();
57515
57782
  this.#active = null;
57516
57783
  active.resolve(interpreted2.terminal);
57517
57784
  }
@@ -57565,6 +57832,8 @@ var ClaudeSdkTransport = class {
57565
57832
  } catch (error52) {
57566
57833
  const active = this.#active;
57567
57834
  this.#closeInteractions("all", "cancelled");
57835
+ this.#rejectPendingSteers();
57836
+ this.#rootToolCalls.clear();
57568
57837
  this.#active = null;
57569
57838
  active?.reject(error52);
57570
57839
  if (!this.#closePromise)
@@ -58754,7 +59023,7 @@ function projectClaudePlanLimitToCredits(planLimit) {
58754
59023
  }
58755
59024
  var ClaudeHarnessSession = class {
58756
59025
  harnessId = claudeCodeHarnessId2;
58757
- capabilities = {
59026
+ capabilities = /* @__PURE__ */ ((session) => ({
58758
59027
  configuration: {
58759
59028
  selectModel: true,
58760
59029
  selectThinkingOption: true,
@@ -58762,11 +59031,16 @@ var ClaudeHarnessSession = class {
58762
59031
  permissionModeScope: "live"
58763
59032
  },
58764
59033
  history: { fork: true, forkAcrossCwd: false, rollbackLastTurn: true },
58765
- subagents: { observe: true, readTranscript: true }
58766
- };
59034
+ subagents: { observe: true, readTranscript: true },
59035
+ // Read live: native delivery joins this Turn only while a requested Turn runs a root tool call
59036
+ // on a CLI that confirms steers (`msg_lifecycle_v1`). Otherwise the Host stops and restarts.
59037
+ get steer() {
59038
+ return session.#transport?.canSteerActiveTurn?.() === true;
59039
+ }
59040
+ }))(this);
58767
59041
  commands;
58768
59042
  initialState;
58769
- initialUsage = null;
59043
+ initialUsage;
58770
59044
  outputs;
58771
59045
  #channel = new HarnessOutputChannel();
58772
59046
  #cancelTimeoutMs;
@@ -58805,7 +59079,10 @@ var ClaudeHarnessSession = class {
58805
59079
  #hardCancelTask = null;
58806
59080
  #usageGeneration = 0;
58807
59081
  #latestUsage = null;
59082
+ #lastAssistantResponseAtUnix;
59083
+ #accountCreditsSupported;
58808
59084
  #minimumContextUsedTokens = null;
59085
+ #latestRequestModel = null;
58809
59086
  #calibratedInputTokens = 0;
58810
59087
  #calibratedOutputTokens = 0;
58811
59088
  #calibratedCostUsd = 0;
@@ -58823,6 +59100,11 @@ var ClaudeHarnessSession = class {
58823
59100
  #continuationQuiescence = null;
58824
59101
  constructor(cwd, dependencies, closeTimeoutMs, onClosed, onPlanLimitObserved, options) {
58825
59102
  this.#cwd = cwd;
59103
+ this.#lastAssistantResponseAtUnix = options.usageHistory.lastResponseAtUnix;
59104
+ this.#accountCreditsSupported = options.accountCreditsSupported;
59105
+ const composerIndicators = claudePromptCacheIndicators(this.#accountCreditsSupported, this.#lastAssistantResponseAtUnix);
59106
+ this.initialUsage = composerIndicators.length ? { composerIndicators } : null;
59107
+ this.#latestUsage = this.initialUsage;
58826
59108
  this.#pendingSessions = options.pendingSessions;
58827
59109
  const environment = options.environment;
58828
59110
  this.#createTransport = environment ? (input) => dependencies.createTransport({ ...input, environment }) : dependencies.createTransport;
@@ -58977,6 +59259,8 @@ var ClaudeHarnessSession = class {
58977
59259
  }
58978
59260
  if (command.type === "turn.cancel")
58979
59261
  return this.#cancel(command);
59262
+ if (command.type === "turn.steer")
59263
+ return this.#steer(command);
58980
59264
  if (command.type === "interaction.respond")
58981
59265
  return this.#respond(command);
58982
59266
  if (command.type === "model.select")
@@ -59113,6 +59397,45 @@ var ClaudeHarnessSession = class {
59113
59397
  }
59114
59398
  return { ok: true, value: { turnId: command.turnId } };
59115
59399
  }
59400
+ async #steer(command) {
59401
+ if (!this.#active || this.#active.command.turnId !== command.turnId) {
59402
+ return { ok: false, error: invalidState("Claude Code steer target is not the active Turn") };
59403
+ }
59404
+ const text2 = command.input.map((input) => input.text).join("\n");
59405
+ if (text2.length === 0) {
59406
+ return {
59407
+ ok: false,
59408
+ error: {
59409
+ code: "invalidRequest",
59410
+ message: "Claude Code steer text must not be empty",
59411
+ retryable: false
59412
+ }
59413
+ };
59414
+ }
59415
+ const transport = this.#transport;
59416
+ if (!transport) {
59417
+ return { ok: false, error: invalidState("Claude Code steer missed the active Turn") };
59418
+ }
59419
+ if (transport.supportsNativeSteer?.() !== true) {
59420
+ return {
59421
+ ok: false,
59422
+ error: {
59423
+ code: "unsupported",
59424
+ message: "This Claude Code version does not confirm native steering",
59425
+ retryable: false
59426
+ }
59427
+ };
59428
+ }
59429
+ try {
59430
+ await transport.steer(text2, this.#randomUUID());
59431
+ } catch (error52) {
59432
+ if (error52 instanceof ClaudeSteerMissedTurnError) {
59433
+ return { ok: false, error: invalidState("Claude Code steer missed the active Turn") };
59434
+ }
59435
+ throw error52;
59436
+ }
59437
+ return { ok: true, value: { accepted: true } };
59438
+ }
59116
59439
  /** Built-ins plus the live commands and skills of the started native Session. */
59117
59440
  #liveCommandCatalog() {
59118
59441
  return claudeLiveCommandCatalog(claudeCommandCatalog, this.#transport?.slashCommands?.() ?? null);
@@ -59883,6 +60206,10 @@ var ClaudeHarnessSession = class {
59883
60206
  this.#completeReasoning(active, event.messageId, { status: "succeeded" });
59884
60207
  return;
59885
60208
  case "message.completed": {
60209
+ if (!event.localCommand) {
60210
+ this.#lastAssistantResponseAtUnix = Math.floor(Date.now() / 1e3);
60211
+ this.publishAccountCreditsSupport(this.#accountCreditsSupported);
60212
+ }
59886
60213
  this.#observeRootOutput(active);
59887
60214
  if (event.lastRequestUsage) {
59888
60215
  this.#requestUsageBoundary += 1;
@@ -59944,9 +60271,7 @@ var ClaudeHarnessSession = class {
59944
60271
  case "subagent.completed": {
59945
60272
  const subagent = active.subagents.complete(active.command.turnId, event, active.cancellationRequested);
59946
60273
  if (subagent.status === "running") {
59947
- if (subagent.nativeSubagentId) {
59948
- this.#occupancy.bind(event.callId, subagent.nativeSubagentId);
59949
- }
60274
+ this.#occupancy.occupySpawn(event.callId, subagent.nativeSubagentId);
59950
60275
  return;
59951
60276
  }
59952
60277
  this.#occupancy.release(event.callId, subagent.nativeSubagentId);
@@ -60505,6 +60830,8 @@ var ClaudeHarnessSession = class {
60505
60830
  const promptTokens = usage.inputTokens + usage.cacheCreationInputTokens + usage.cacheReadInputTokens;
60506
60831
  if (promptTokens > 0)
60507
60832
  this.#minimumContextUsedTokens = promptTokens;
60833
+ if (usage.model)
60834
+ this.#latestRequestModel = usage.model;
60508
60835
  const cacheHitRatePercent = claudeCacheHitRatePercent(usage);
60509
60836
  const contextWindowTokens = this.#latestUsage?.contextWindowTokens;
60510
60837
  this.#mergeAndPublishUsage({
@@ -60546,8 +60873,24 @@ var ClaudeHarnessSession = class {
60546
60873
  if (cacheHitRatePercent !== void 0)
60547
60874
  delta.cacheHitRatePercent = cacheHitRatePercent;
60548
60875
  }
60876
+ if (this.#latestUsage?.contextWindowTokens === void 0 && this.#minimumContextUsedTokens !== null) {
60877
+ const contextWindowTokens = this.#resultContextWindow(event.modelUsage);
60878
+ if (contextWindowTokens !== void 0) {
60879
+ delta.contextUsedTokens = this.#minimumContextUsedTokens;
60880
+ delta.contextWindowTokens = contextWindowTokens;
60881
+ }
60882
+ }
60549
60883
  this.#mergeAndPublishUsage(delta, active.command.turnId);
60550
60884
  }
60885
+ /** The latest request's Model, else the Model that carried the most prompt tokens. */
60886
+ #resultContextWindow(modelUsage) {
60887
+ if (!modelUsage?.length)
60888
+ return void 0;
60889
+ const latest = this.#latestRequestModel;
60890
+ const matched = latest ? modelUsage.find(({ model: model2 }) => model2 === latest) : void 0;
60891
+ const main = matched ?? modelUsage.reduce((best, entry) => (entry.promptTokens ?? entry.inputTokens) > (best.promptTokens ?? best.inputTokens) ? entry : best);
60892
+ return main.contextWindowTokens;
60893
+ }
60551
60894
  /**
60552
60895
  * Plan usage is account-wide, not Thread-scoped, so every observation is
60553
60896
  * offered to the Adapter's shared cache regardless of this Session's own
@@ -60560,6 +60903,15 @@ var ClaudeHarnessSession = class {
60560
60903
  if (effective)
60561
60904
  this.publishPlanLimit(effective);
60562
60905
  }
60906
+ publishAccountCreditsSupport(supported) {
60907
+ if (this.#phase !== "open")
60908
+ return;
60909
+ this.#accountCreditsSupported = supported;
60910
+ const composerIndicators = claudePromptCacheIndicators(supported, this.#lastAssistantResponseAtUnix);
60911
+ if (composerIndicators[0]?.expiresAtUnix === this.#latestUsage?.composerIndicators?.[0]?.expiresAtUnix)
60912
+ return;
60913
+ this.#mergeAndPublishUsage({ composerIndicators }, this.#active?.command.turnId);
60914
+ }
60563
60915
  publishPlanLimit(planLimit) {
60564
60916
  if (this.#phase !== "open")
60565
60917
  return;
@@ -60835,6 +61187,7 @@ var ClaudeCodeAdapter = class {
60835
61187
  #closePromise = null;
60836
61188
  #latestPlanLimit = null;
60837
61189
  #accountInspection = null;
61190
+ #accountCreditsSupported = false;
60838
61191
  constructor(options = {}, dependencies) {
60839
61192
  const environment = options.environment ?? process.env;
60840
61193
  this.#environment = environment;
@@ -60946,12 +61299,20 @@ var ClaudeCodeAdapter = class {
60946
61299
  return this.#accountInspection;
60947
61300
  }
60948
61301
  async #readAccount() {
61302
+ const planLimitAtStart = this.#latestPlanLimit;
60949
61303
  let inspector;
60950
61304
  try {
60951
61305
  this.#dependencies.inspectInstallation();
60952
61306
  inspector = this.#dependencies.createInspector({ cwd: process.cwd() });
60953
61307
  this.#inspectors.add(inspector);
60954
- return await inspector.inspectAccount?.() ?? null;
61308
+ const account = await inspector.inspectAccount?.() ?? null;
61309
+ if (this.#latestPlanLimit === planLimitAtStart) {
61310
+ this.#accountCreditsSupported = account?.credits !== void 0;
61311
+ for (const session of this.#sessions) {
61312
+ session.publishAccountCreditsSupport(this.#accountCreditsSupported);
61313
+ }
61314
+ }
61315
+ return account;
60955
61316
  } catch {
60956
61317
  return null;
60957
61318
  } finally {
@@ -61194,6 +61555,7 @@ var ClaudeCodeAdapter = class {
61194
61555
  ...durableRef ? { nativeRef: durableRef } : {},
61195
61556
  sessionId,
61196
61557
  usageHistory,
61558
+ accountCreditsSupported: this.#accountCreditsSupported,
61197
61559
  ...requestedModel ? { requestedModel } : {},
61198
61560
  requestedPermissionModeId,
61199
61561
  requestedThinkingOptionId,
@@ -61213,7 +61575,13 @@ var ClaudeCodeAdapter = class {
61213
61575
  return { requests: [], complete: true };
61214
61576
  try {
61215
61577
  const messages = await this.#dependencies.readSessionMessages({ cwd, sessionId });
61216
- return messages === null ? { requests: [], complete: false } : claudeUsageHistory(messages);
61578
+ if (messages === null)
61579
+ return { requests: [], complete: false };
61580
+ const lastResponseAtUnix = lastClaudeAssistantResponseUnix(messages);
61581
+ return {
61582
+ ...claudeUsageHistory(messages),
61583
+ ...lastResponseAtUnix !== void 0 ? { lastResponseAtUnix } : {}
61584
+ };
61217
61585
  } catch {
61218
61586
  return { requests: [], complete: false };
61219
61587
  }
@@ -61225,9 +61593,17 @@ var ClaudeCodeAdapter = class {
61225
61593
  next.fiveHour = planLimit.fiveHour;
61226
61594
  if (planLimit.sevenDay)
61227
61595
  next.sevenDay = planLimit.sevenDay;
61596
+ try {
61597
+ if (!accountCreditsSnapshotSchema.safeParse(projectClaudePlanLimitToCredits(next)).success)
61598
+ return null;
61599
+ } catch {
61600
+ return null;
61601
+ }
61228
61602
  this.#latestPlanLimit = next.fiveHour || next.sevenDay ? next : null;
61229
61603
  if (this.#latestPlanLimit) {
61604
+ this.#accountCreditsSupported = true;
61230
61605
  for (const session of this.#sessions) {
61606
+ session.publishAccountCreditsSupport(true);
61231
61607
  if (session !== origin)
61232
61608
  session.publishPlanLimit(this.#latestPlanLimit);
61233
61609
  }