@liberseek/boft-cli-linux-x64 0.8.7 → 0.8.9

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 (67) hide show
  1. package/README.md +1 -1
  2. package/app/codexhost-distribution.json +1 -1
  3. package/app/console-server.mjs +59 -6
  4. package/app/console-web.js +1376 -1053
  5. package/app/desktop-controller.mjs +239 -57
  6. package/app/host-runtime.mjs +32921 -24901
  7. package/app/plugins/antigravity/assets/icon.svg +1 -1
  8. package/app/plugins/antigravity/plugin.mjs +9491 -4266
  9. package/app/plugins/claude-code/plugin.mjs +580 -116
  10. package/app/plugins/codebuddy/plugin.mjs +85 -8
  11. package/app/plugins/codex-usage/plugin.mjs +70 -6
  12. package/app/plugins/copilot/plugin.mjs +62 -6
  13. package/app/plugins/cursor-cli/plugin.mjs +62 -6
  14. package/app/plugins/deepseek-harness/plugin.mjs +87 -11
  15. package/app/plugins/devin/plugin.mjs +61 -6
  16. package/app/plugins/grok/plugin.mjs +320 -223
  17. package/app/plugins/hermes/plugin.mjs +61 -6
  18. package/app/plugins/kimi-code/plugin.mjs +87 -16
  19. package/app/plugins/kiro-cli/plugin.mjs +62 -6
  20. package/app/plugins/muse/plugin.mjs +61 -6
  21. package/app/plugins/omp/plugin.mjs +195 -31
  22. package/app/plugins/opencode/plugin.mjs +88 -15
  23. package/app/plugins/pi/plugin.mjs +207 -32
  24. package/app/plugins/qoder/plugin.mjs +99 -7
  25. package/app/plugins/qoder-cn/plugin.mjs +99 -7
  26. package/app/plugins/qwen-code/plugin.mjs +62 -6
  27. package/app/plugins/workbuddy/plugin.mjs +89 -11
  28. package/app/plugins/zcode/plugin.mjs +70 -6
  29. package/app/renderer-extension.js +1767 -1187
  30. package/app/web/assets/index-C2OA-eHT.js +201 -0
  31. package/app/web/assets/index-DJW4bmyx.css +1 -0
  32. package/app/web/assets/langs/{graphql-B8vkg11W.js → graphql-ChAeyPkT.js} +1 -1
  33. package/app/web/assets/langs/{http-DmoDEjMt.js → http-BvreBIbD.js} +1 -1
  34. package/app/web/assets/langs/{php-DJ5ovfAM.js → php-D8omCIuJ.js} +1 -1
  35. package/app/web/assets/langs/{rst-U5-R5x3p.js → rst-Do7RLLCS.js} +1 -1
  36. package/app/web/assets/langs/{ruby-VKVsnS0H.js → ruby-rH_O_vse.js} +1 -1
  37. package/app/web/assets/langs/{svelte-C20lOv9V.js → svelte-xZy73wAj.js} +1 -1
  38. package/app/web/assets/langs/{vue-z6Y-lzP-.js → vue-C4DW8agZ.js} +1 -1
  39. package/app/web/assets/{vendor-dSL872WO.js → vendor-C9g2bw8s.js} +3 -3
  40. package/app/web/codexhost-settings.js +1383 -1056
  41. package/app/web/index.html +4 -3
  42. package/app/web/plugins/deepseek-ai__dsh-api-gateway/client.js +2 -2
  43. package/app/web/plugins/deepseek-ai__dsh-api-remotes/client.js +1 -1
  44. package/app/web/plugins/deepseek-ai__dsh-api-session-controller/client.js +11 -11
  45. package/app/web/plugins/deepseek-ai__dsh-client-connection/client.js +1 -1
  46. package/app/web/plugins/deepseek-ai__dsh-client-locale/client.js +3 -3
  47. package/app/web/plugins/deepseek-ai__dsh-client-ui-attachment/client.js +1 -1
  48. package/app/web/plugins/deepseek-ai__dsh-client-ui-chat/client.js +74 -69
  49. package/app/web/plugins/deepseek-ai__dsh-client-ui-codexhost/client.js +3 -3
  50. package/app/web/plugins/deepseek-ai__dsh-client-ui-conversation/client.js +28 -28
  51. package/app/web/plugins/deepseek-ai__dsh-client-ui-input-trigger/client.js +1 -1
  52. package/app/web/plugins/deepseek-ai__dsh-client-ui-layout/client.js +2 -2
  53. package/app/web/plugins/deepseek-ai__dsh-client-ui-model-selection/client.js +1 -1
  54. package/app/web/plugins/deepseek-ai__dsh-client-ui-session/client.js +1 -1
  55. package/app/web/plugins/deepseek-ai__dsh-client-ui-settings-general/client.js +1 -1
  56. package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar/client.js +1 -1
  57. package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-documentpreview/client.js +9 -9
  58. package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-files/client.js +1 -1
  59. package/app/web/plugins/deepseek-ai__dsh-client-ui-tool/client.js +18 -18
  60. package/app/web/plugins/deepseek-ai__dsh-client-ui-workspace/client.js +11 -11
  61. package/app/web-modules/server.mjs +2458 -1615
  62. package/bin/boft +0 -0
  63. package/libexec/boft-shim +0 -0
  64. package/libexec/boft-updater +0 -0
  65. package/package.json +1 -1
  66. package/app/web/assets/index-CP6wY-1D.css +0 -1
  67. package/app/web/assets/index-Da35Phrd.js +0 -199
@@ -14662,13 +14662,25 @@ var threadPermissionModeSelectParamsSchema = external_exports.object({
14662
14662
  var nonNegativeSafeIntegerSchema = external_exports.number().int().safe().nonnegative();
14663
14663
  var finiteNonNegativeNumberSchema = external_exports.number().finite().nonnegative();
14664
14664
  var cacheHitRatePercentSchema = external_exports.number().finite().min(0).max(100);
14665
+ var usageOutputTimingSchema = external_exports.object({
14666
+ version: external_exports.union([external_exports.literal(3), external_exports.literal(4)]).optional(),
14667
+ requestId: external_exports.string().min(1),
14668
+ turnId: external_exports.string().min(1).max(1024),
14669
+ outputTokens: nonNegativeSafeIntegerSchema,
14670
+ startedAtMs: nonNegativeSafeIntegerSchema,
14671
+ completedAtMs: nonNegativeSafeIntegerSchema
14672
+ }).strict().refine((value) => value.completedAtMs > value.startedAtMs);
14665
14673
  var usageMeasurementSchema = external_exports.object({
14674
+ version: external_exports.union([external_exports.literal(2), external_exports.literal(3), external_exports.literal(4)]).optional(),
14666
14675
  value: finiteNonNegativeNumberSchema,
14667
14676
  turnId: external_exports.string().min(1).max(1024),
14668
14677
  at: nonNegativeSafeIntegerSchema
14669
14678
  }).strict();
14670
14679
  var usageMeasurementsSchema = external_exports.object({
14671
- outputTokensPerSecond: usageMeasurementSchema.optional(),
14680
+ // Older intervals can omit hidden thinking time; do not restore them into averages.
14681
+ outputTimings: external_exports.array(usageOutputTimingSchema).transform((values) => values.filter((value) => value.version === 4)).optional(),
14682
+ // Retain independent TTFT facts when dropping incompatible speed measurements.
14683
+ outputTokensPerSecond: usageMeasurementSchema.refine((value) => value.version === 4).optional().catch(void 0),
14672
14684
  timeToFirstOutputMs: usageMeasurementSchema.extend({ value: nonNegativeSafeIntegerSchema }).optional()
14673
14685
  }).strict();
14674
14686
  var indicatorTextSchema = (maximum) => harnessLocalizedTextSchema.refine((entries) => Object.values(entries).every((text2) => text2.length <= maximum));
@@ -14688,6 +14700,7 @@ var threadUsageSnapshotSchema = external_exports.object({
14688
14700
  cacheWriteInputTokens: nonNegativeSafeIntegerSchema.optional(),
14689
14701
  outputTokens: nonNegativeSafeIntegerSchema.optional(),
14690
14702
  outputTokensPerSecond: finiteNonNegativeNumberSchema.optional(),
14703
+ sessionOutputTokensPerSecond: finiteNonNegativeNumberSchema.optional(),
14691
14704
  apiOutputTokensPerSecond: finiteNonNegativeNumberSchema.optional(),
14692
14705
  reasoningOutputTokens: nonNegativeSafeIntegerSchema.optional(),
14693
14706
  totalTokens: nonNegativeSafeIntegerSchema.optional(),
@@ -14853,6 +14866,11 @@ var harnessModelSchema = external_exports.object({
14853
14866
  fastModel: harnessModelRefSchema.optional(),
14854
14867
  supportedThinkingOptionIds: external_exports.array(harnessThinkingOptionIdSchema).optional()
14855
14868
  }).strict();
14869
+ function catalogModelForRef(catalog, ref) {
14870
+ if (!ref)
14871
+ return void 0;
14872
+ return catalog?.models.find((model2) => model2.ref.id === ref.id || model2.fastModel?.id === ref.id);
14873
+ }
14856
14874
  var harnessThinkingOptionsSchema = external_exports.array(harnessThinkingOptionSchema).superRefine((options, context) => {
14857
14875
  const ids = /* @__PURE__ */ new Set();
14858
14876
  for (const [index, option2] of options.entries()) {
@@ -15119,11 +15137,19 @@ var threadSteeringInspectResultSchema = external_exports.object({
15119
15137
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
15120
15138
  }).strict();
15121
15139
 
15140
+ // ../../shared-contracts/dist/thread-archive-confirm.js
15141
+ var threadArchiveConfirmParamsSchema = external_exports.object({ threadId: hostThreadIdSchema }).strict();
15142
+ var threadArchiveConfirmResultSchema = external_exports.object({ confirmed: external_exports.boolean() }).strict();
15143
+
15122
15144
  // ../../shared-contracts/dist/client-channel.js
15123
15145
  var CLIENT_CHANNEL_VERSION = 1;
15124
15146
  var CLIENT_REQUEST_LIMIT_BYTES = 128 * 1024 * 1024;
15125
15147
  var clientThreadPinsSchema = external_exports.object({ threadIds: external_exports.array(external_exports.string().min(1)) }).strict();
15126
15148
  var clientThreadPinParamsSchema = external_exports.object({ threadId: external_exports.string().min(1).max(1024), pinned: external_exports.boolean() }).strict();
15149
+ var clientThreadTreeReadParamsSchema = external_exports.object({}).strict();
15150
+ var clientThreadTreeSchema = external_exports.object({
15151
+ parents: external_exports.record(external_exports.string().min(1), external_exports.string().min(1))
15152
+ }).strict();
15127
15153
  var clientProjectlessWorkspaceSchema = external_exports.object({
15128
15154
  prompt: external_exports.string().max(16384).optional()
15129
15155
  }).strict();
@@ -15145,6 +15171,11 @@ var clientChannelEventSchema = external_exports.discriminatedUnion("type", [
15145
15171
  cursor: clientChannelCursorSchema,
15146
15172
  cwd: external_exports.string().optional()
15147
15173
  }),
15174
+ external_exports.object({
15175
+ type: external_exports.literal("harness-inspection-changed"),
15176
+ cursor: clientChannelCursorSchema,
15177
+ harnessId: external_exports.string().min(1)
15178
+ }),
15148
15179
  external_exports.object({ type: external_exports.literal("display-settings-changed"), cursor: clientChannelCursorSchema }),
15149
15180
  external_exports.object({
15150
15181
  type: external_exports.literal("preferences-changed"),
@@ -15216,6 +15247,8 @@ var clientItemTruncationSchema = external_exports.object({
15216
15247
  var clientTurnSchema = external_exports.object({
15217
15248
  id: external_exports.string().min(1),
15218
15249
  status: external_exports.string().min(1),
15250
+ /** Native history has no terminal evidence; Desktop's status vocabulary cannot express this. */
15251
+ codexhostTurnOutcome: external_exports.object({ status: external_exports.literal("unknown"), reason: external_exports.string() }).optional(),
15219
15252
  items: external_exports.array(external_exports.object({ id: external_exports.string().min(1), type: external_exports.string().min(1) }).passthrough()),
15220
15253
  /** Original file operations, independent of the cumulative Desktop fileChange card.
15221
15254
  * Insert before the named non-file Item; null appends at the end of the Turn.
@@ -15254,7 +15287,12 @@ var clientThreadSnapshotSchema = external_exports.object({
15254
15287
  /** Current interruptible Host Turn, including command Turns omitted from client history. */
15255
15288
  activeTurnId: external_exports.string().min(1).nullable().optional(),
15256
15289
  /** Most recent explicit command in this Host process; not native conversation history. */
15257
- command: external_exports.object({ name: external_exports.string().min(1), turn: clientTurnSchema }).optional(),
15290
+ command: external_exports.object({
15291
+ name: external_exports.string().min(1),
15292
+ turn: clientTurnSchema,
15293
+ /** First ordinary Turn started after this command; its retained result is not a new event. */
15294
+ subsequentTurnId: external_exports.string().min(1).optional()
15295
+ }).optional(),
15258
15296
  thread: external_exports.object({
15259
15297
  id: external_exports.string().min(1),
15260
15298
  cwd: external_exports.string(),
@@ -15462,15 +15500,14 @@ var webAccessStateSchema = external_exports.object({
15462
15500
  quotaUntil: external_exports.string().optional()
15463
15501
  }).strict().optional()
15464
15502
  }).strict();
15465
- var webLocalAccessRequiredDetailsSchema = external_exports.object({ url: external_exports.string() }).strict();
15466
15503
 
15467
15504
  // ../../shared-contracts/dist/delegation-read.js
15468
15505
  var REMOTE_THREAD_REPLY_MAX_BYTES = 16 * 1024 * 1024;
15469
15506
  var delegationReadParamsSchema = external_exports.strictObject({
15470
15507
  threadId: external_exports.string().min(1).max(1024),
15471
15508
  view: external_exports.enum(["result", "messages"]),
15472
- cursor: external_exports.string().min(1).max(8192).optional(),
15473
- limit: external_exports.number().int().min(1).max(100).optional()
15509
+ from: external_exports.number().int().min(1).max(Number.MAX_SAFE_INTEGER).optional(),
15510
+ to: external_exports.number().int().min(1).max(Number.MAX_SAFE_INTEGER).optional()
15474
15511
  });
15475
15512
 
15476
15513
  // ../../shared-contracts/dist/credential-imports.js
@@ -16450,11 +16487,25 @@ var updateStatusResultSchema = external_exports.strictObject({
16450
16487
  status: updateStatusSchema.nullable()
16451
16488
  });
16452
16489
 
16490
+ // ../../shared-contracts/dist/desktop-attachments.js
16491
+ var ATTACHED_FILES_HEADING = /^\s*# Files mentioned by the user:[ \t]*(?:\r?\n|$)/u;
16492
+ var REQUEST_HEADING = /(?:^|\n)## My request:[ \t]*(?:\r?\n|$)/u;
16493
+ var IMAGE_ATTACHMENT_PATTERN = /(?:^|\n)## [^\r\n]+: ((?:\/|[A-Za-z]:[\\/]|\\\\)[^\r\n]+)\r?\nImage attachment: true(?=\r?\n|$)/gu;
16494
+ var CONTROL_CHARACTER_PATTERN = /[\u0000-\u001f\u007f]/u;
16495
+ function desktopImageAttachmentPaths(text2) {
16496
+ const end = text2.search(REQUEST_HEADING);
16497
+ const context = end < 0 ? text2 : text2.slice(0, end);
16498
+ if (!ATTACHED_FILES_HEADING.test(context))
16499
+ return [];
16500
+ return [...context.matchAll(IMAGE_ATTACHMENT_PATTERN)].map((match) => match[1] ?? "").filter((path20) => path20.length > 0 && !CONTROL_CHARACTER_PATTERN.test(path20));
16501
+ }
16502
+
16453
16503
  // ../../shared-contracts/dist/thread-watch-notice.js
16454
16504
  var THREAD_WATCH_NOTICE_OUTCOMES = [
16455
16505
  "completed",
16456
16506
  "failed",
16457
16507
  "interrupted",
16508
+ "needsInput",
16458
16509
  "timedOut",
16459
16510
  "unreadable",
16460
16511
  "notFound"
@@ -16501,13 +16552,26 @@ var target = { hostId: identity.regex(/^remote-(?:ssh(?:-|:)|control:)/u) };
16501
16552
  var thread = { ...target, threadId: identity };
16502
16553
  var remoteSessionOperationSchema = external_exports.discriminatedUnion("kind", [
16503
16554
  external_exports.strictObject({ kind: external_exports.literal("hosts") }),
16555
+ external_exports.strictObject({ kind: external_exports.literal("status"), ...thread }),
16504
16556
  external_exports.strictObject({
16505
16557
  kind: external_exports.literal("list"),
16506
16558
  ...target,
16507
16559
  cursor: external_exports.string().nullable(),
16508
16560
  archived: external_exports.boolean()
16509
16561
  }),
16510
- external_exports.strictObject({ kind: external_exports.literal("read"), ...thread }),
16562
+ external_exports.strictObject({
16563
+ kind: external_exports.literal("read"),
16564
+ ...thread,
16565
+ page: external_exports.strictObject({
16566
+ cursor: external_exports.string().min(1).max(8192).nullable(),
16567
+ epoch: identity.optional(),
16568
+ sortDirection: external_exports.enum(["asc", "desc"]).optional(),
16569
+ limit: external_exports.number().int().min(1).max(20).optional()
16570
+ }).refine((page) => page.cursor === null || page.epoch !== void 0, {
16571
+ message: "A history continuation requires its connection epoch"
16572
+ }).optional()
16573
+ }),
16574
+ external_exports.strictObject({ kind: external_exports.literal("usage"), ...thread, epoch: identity }),
16511
16575
  external_exports.strictObject({
16512
16576
  kind: external_exports.literal("configure"),
16513
16577
  ...thread,
@@ -16588,6 +16652,13 @@ var remoteConnectionsReplySchema = external_exports.union([
16588
16652
  external_exports.strictObject({ error: external_exports.strictObject({ code: external_exports.number().int(), message: external_exports.string() }) })
16589
16653
  ]);
16590
16654
 
16655
+ // ../../shared-contracts/dist/thread-title.js
16656
+ var threadTitleInputSchema = external_exports.strictObject({
16657
+ prompt: external_exports.string().trim().min(1).max(2e3),
16658
+ cwd: external_exports.string().max(4096).nullable()
16659
+ });
16660
+ var threadTitleResultSchema = external_exports.string().trim().min(1).max(60).nullable();
16661
+
16591
16662
  // ../../shared-contracts/dist/web-ui-extensions.js
16592
16663
  var webUiExtensionIdSchema = external_exports.string().max(214).regex(/^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/u);
16593
16664
  var localizedTextSchema2 = external_exports.union([
@@ -16765,6 +16836,7 @@ var usageFields = /* @__PURE__ */ new Set([
16765
16836
  "totalCredits",
16766
16837
  "contextUsagePercent",
16767
16838
  "outputTokensPerSecond",
16839
+ "sessionOutputTokensPerSecond",
16768
16840
  "apiOutputTokensPerSecond",
16769
16841
  "costSource",
16770
16842
  "unpricedModels"
@@ -16787,6 +16859,7 @@ function parseHostUsage(value) {
16787
16859
  for (const field2 of [
16788
16860
  "totalCredits",
16789
16861
  "contextUsagePercent",
16862
+ "sessionOutputTokensPerSecond",
16790
16863
  "apiOutputTokensPerSecond"
16791
16864
  ]) {
16792
16865
  const candidate = value[field2];
@@ -16871,6 +16944,7 @@ var requestTokenFields = [
16871
16944
  "cacheWrite1hInputTokens",
16872
16945
  "outputTokens",
16873
16946
  "reasoningOutputTokens",
16947
+ "timedOutputTokens",
16874
16948
  "startedAtMs",
16875
16949
  "completedAtMs"
16876
16950
  ];
@@ -16923,6 +16997,14 @@ function parseHostUsageRequest(value) {
16923
16997
  if (request.startedAtMs === void 0 !== (request.completedAtMs === void 0)) {
16924
16998
  throw new Error("Harness Usage request timing fields must be provided together");
16925
16999
  }
17000
+ if (request.timedOutputTokens !== void 0) {
17001
+ if (request.startedAtMs === void 0) {
17002
+ throw new Error("Harness Usage request 'timedOutputTokens' requires timing fields");
17003
+ }
17004
+ if (request.timedOutputTokens > request.outputTokens) {
17005
+ throw new Error("Harness Usage request 'timedOutputTokens' must not exceed 'outputTokens'");
17006
+ }
17007
+ }
16926
17008
  if (request.startedAtMs !== void 0 && request.completedAtMs !== void 0 && request.completedAtMs < request.startedAtMs) {
16927
17009
  throw new Error("Harness Usage request 'completedAtMs' must not precede 'startedAtMs'");
16928
17010
  }
@@ -18593,6 +18675,7 @@ function claudePromptCacheIndicators(accountCreditsSupported, lastResponseAtUnix
18593
18675
  // dist/claude-code-adapter.js
18594
18676
  import { randomUUID as randomUUID6 } from "node:crypto";
18595
18677
  import path17 from "node:path";
18678
+ import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
18596
18679
 
18597
18680
  // ../../../node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs
18598
18681
  import { createRequire as jre } from "node:module";
@@ -55753,6 +55836,8 @@ function parseClaudeWorkflowAgents(value) {
55753
55836
  var ClaudeNativeTurnAccumulator = class {
55754
55837
  #provider;
55755
55838
  #activeRootStreamMessageId = null;
55839
+ /** Native record UUIDs already published, across stream and request message IDs. */
55840
+ #publishedCheckpointIds = /* @__PURE__ */ new Set();
55756
55841
  #assistantErrors = [];
55757
55842
  #cancelRequested = false;
55758
55843
  #compactionState = "idle";
@@ -55898,7 +55983,8 @@ var ClaudeNativeTurnAccumulator = class {
55898
55983
  if (message.type !== "system")
55899
55984
  return;
55900
55985
  if (message.subtype === "init") {
55901
- events.push({ type: "segment.started" });
55986
+ const mcpServers = Array.isArray(message.mcp_servers) ? message.mcp_servers.flatMap((server) => isRecord6(server) && typeof server.name === "string" ? [server.name] : []) : void 0;
55987
+ events.push({ type: "segment.started", ...mcpServers ? { mcpServers } : {} });
55902
55988
  return;
55903
55989
  }
55904
55990
  if (message.subtype !== "background_tasks_changed" || !Array.isArray(message.tasks))
@@ -56089,6 +56175,25 @@ var ClaudeNativeTurnAccumulator = class {
56089
56175
  const messageId = this.#activeRootStreamMessageId ?? nativeMessageId ?? checkpointId ?? this.#nextMessageId();
56090
56176
  const state = this.#messageState(messageId);
56091
56177
  if (state.completed) {
56178
+ const splitText = checkpointId && !this.#publishedCheckpointIds.has(checkpointId) ? assistantText(message) : null;
56179
+ if (checkpointId && splitText) {
56180
+ this.#publishedCheckpointIds.add(checkpointId);
56181
+ state.text += splitText;
56182
+ events.push({ type: "text.delta", messageId, delta: splitText });
56183
+ this.#consumeToolUseBlocks(message, events, true);
56184
+ if (!this.#protocolConflict && !this.#textConflict) {
56185
+ const usage2 = state.usagePublished ? void 0 : assistantRequestUsage(message, this.#provider);
56186
+ if (usage2)
56187
+ state.usagePublished = true;
56188
+ events.push({
56189
+ type: "message.completed",
56190
+ messageId,
56191
+ checkpointId,
56192
+ ...usage2 ? { lastRequestUsage: usage2 } : {}
56193
+ });
56194
+ }
56195
+ return;
56196
+ }
56092
56197
  this.#consumeToolUseBlocks(message, events, true);
56093
56198
  const usage = assistantRequestUsage(message, this.#provider);
56094
56199
  if (usage && !state.usagePublished) {
@@ -56129,6 +56234,8 @@ var ClaudeNativeTurnAccumulator = class {
56129
56234
  });
56130
56235
  }
56131
56236
  state.completed = true;
56237
+ if (checkpointId)
56238
+ this.#publishedCheckpointIds.add(checkpointId);
56132
56239
  if (this.#activeRootStreamMessageId === messageId)
56133
56240
  this.#activeRootStreamMessageId = null;
56134
56241
  }
@@ -56269,7 +56376,12 @@ var ClaudeNativeTurnAccumulator = class {
56269
56376
  const existing = this.#messages.get(messageId);
56270
56377
  if (existing)
56271
56378
  return existing;
56272
- const created = { completed: false, reasoning: "", text: "", usagePublished: false };
56379
+ const created = {
56380
+ completed: false,
56381
+ reasoning: "",
56382
+ text: "",
56383
+ usagePublished: false
56384
+ };
56273
56385
  this.#messages.set(messageId, created);
56274
56386
  return created;
56275
56387
  }
@@ -56279,6 +56391,31 @@ var ClaudeNativeTurnAccumulator = class {
56279
56391
  }
56280
56392
  };
56281
56393
 
56394
+ // dist/claude-tool-item.js
56395
+ function mcpServerSegment(server) {
56396
+ const segment = server.replace(/[^a-zA-Z0-9_-]/g, "_");
56397
+ return server.startsWith("claude.ai ") ? segment.replace(/_+/g, "_").replace(/^_|_$/g, "") : segment;
56398
+ }
56399
+ function mcpTool(toolName, servers) {
56400
+ if (!toolName.startsWith("mcp__"))
56401
+ return null;
56402
+ const known = servers.map((server2) => `mcp__${mcpServerSegment(server2)}__`).filter((prefix) => toolName.length > prefix.length && toolName.startsWith(prefix)).sort((left, right) => right.length - left.length)[0];
56403
+ if (known)
56404
+ return { server: known.slice(5, -2), tool: toolName.slice(known.length) };
56405
+ const [, server, ...tool] = toolName.split("__");
56406
+ const name = tool.join("__");
56407
+ return server && name ? { server, tool: name } : null;
56408
+ }
56409
+ function claudeToolItem(itemId, toolName, args, mcpServers = []) {
56410
+ const mcp = mcpTool(toolName, mcpServers);
56411
+ if (mcp)
56412
+ return { type: "mcpToolCall", itemId, ...mcp, arguments: args };
56413
+ if (toolName === "WebSearch" && typeof args === "object" && args !== null && !Array.isArray(args) && typeof args.query === "string" && args.query.length > 0) {
56414
+ return { type: "webSearch", itemId, query: args.query };
56415
+ }
56416
+ return { type: "toolExecution", itemId, toolName, arguments: args };
56417
+ }
56418
+
56282
56419
  // dist/item-identity.js
56283
56420
  function claudeTranscriptItemId(nativeTurnKey, kind, ordinal) {
56284
56421
  return hostItemIdSchema.parse(`claude-item-v2-${nativeTurnKey}-${kind}-${ordinal}`);
@@ -56293,14 +56430,41 @@ function readClaudeQueuedCommand(value, sessionId) {
56293
56430
  if (value.type !== "attachment" || !isRecord7(attachment) || attachment.type !== "queued_command" || attachment.commandMode !== "prompt" || !isRecord7(attachment.origin) || attachment.origin.kind !== "human" || attachment.humanTurn === false || attachment.isMeta === true || attachment.isSynthetic === true || value.isMeta === true || value.isSynthetic === true || value.isSidechain === true || isRecord7(value.origin) && value.origin.kind !== "human" || typeof value.parent_tool_use_id === "string" && value.parent_tool_use_id.length > 0 || value.sessionId !== void 0 && value.sessionId !== sessionId || value.session_id !== sessionId) {
56294
56431
  return null;
56295
56432
  }
56296
- if (typeof value.uuid !== "string" || value.uuid.length === 0 || typeof attachment.source_uuid !== "string" || attachment.source_uuid.length === 0 || typeof attachment.prompt !== "string" || attachment.prompt.length === 0) {
56433
+ const prompt = promptText(attachment.prompt);
56434
+ if (typeof value.uuid !== "string" || value.uuid.length === 0 || typeof attachment.source_uuid !== "string" || attachment.source_uuid.length === 0 || prompt.length === 0) {
56297
56435
  throw new Error("Claude queued human input has an invalid identity or text prompt");
56298
56436
  }
56299
- return { uuid: value.uuid, sourceUuid: attachment.source_uuid, prompt: attachment.prompt };
56437
+ return { uuid: value.uuid, sourceUuid: attachment.source_uuid, prompt };
56438
+ }
56439
+ function promptText(prompt) {
56440
+ if (typeof prompt === "string")
56441
+ return prompt;
56442
+ if (!Array.isArray(prompt))
56443
+ return "";
56444
+ return prompt.flatMap((block) => isRecord7(block) && block.type === "text" && typeof block.text === "string" ? [block.text] : []).join("\n");
56300
56445
  }
56301
56446
 
56302
56447
  // dist/claude-history.js
56303
56448
  var claudeCodeHarnessId = harnessIdSchema.parse("claude-code");
56449
+ var CLAUDE_BLOCK_SPLIT_UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-0{8}[0-9a-f]{4}$/iu;
56450
+ function matchesClaudeCheckpointId(persistedId, expectedId) {
56451
+ if (persistedId === expectedId)
56452
+ return true;
56453
+ if (!CLAUDE_BLOCK_SPLIT_UUID_PATTERN.test(expectedId))
56454
+ return false;
56455
+ return persistedId.length === 36 && persistedId.slice(0, 24).toLowerCase() === expectedId.slice(0, 24).toLowerCase();
56456
+ }
56457
+ function isPersistedClaudeMessageId(expectedId, persistedIds) {
56458
+ if (persistedIds.has(expectedId))
56459
+ return true;
56460
+ if (!CLAUDE_BLOCK_SPLIT_UUID_PATTERN.test(expectedId))
56461
+ return false;
56462
+ for (const id2 of persistedIds) {
56463
+ if (matchesClaudeCheckpointId(id2, expectedId))
56464
+ return true;
56465
+ }
56466
+ return false;
56467
+ }
56304
56468
  function isRecord8(value) {
56305
56469
  return typeof value === "object" && value !== null && !Array.isArray(value);
56306
56470
  }
@@ -56396,6 +56560,12 @@ function visibleUserTextParts(message) {
56396
56560
  return [];
56397
56561
  return parts.filter((part) => !isLocalCommandRecord(part) && !isTaskNotificationRecord(part));
56398
56562
  }
56563
+ function hasRootToolResult(message) {
56564
+ if (message.type !== "user" || message.nested || !Array.isArray(message.message.content)) {
56565
+ return false;
56566
+ }
56567
+ return message.message.content.some((block) => isRecord8(block) && block.type === "tool_result");
56568
+ }
56399
56569
  function isInterruptionRecord(value, promptId) {
56400
56570
  if (value.type !== "user" || promptId === null || value.promptId !== promptId || value.promptSource !== void 0 || !isRecord8(value.message))
56401
56571
  return false;
@@ -56457,7 +56627,7 @@ function conversationMessages(values, sessionId) {
56457
56627
  interrupted,
56458
56628
  startsTurn: false,
56459
56629
  ...isRecord8(value.forkedFrom) && typeof value.forkedFrom.messageUuid === "string" ? { forkSourceUuid: value.forkedFrom.messageUuid } : {},
56460
- syntheticUser: value.type === "user" && (interrupted || value.isSynthetic === true || value.isMeta === true || isTaskNotificationOrigin(value) || value.toolUseResult !== void 0 && value.toolUseResult !== null)
56630
+ syntheticUser: value.type === "user" && (interrupted || value.isSynthetic === true || value.isMeta === true || value.isCompactSummary === true || value.isVisibleInTranscriptOnly === true || isTaskNotificationOrigin(value) || value.toolUseResult !== void 0 && value.toolUseResult !== null)
56461
56631
  };
56462
56632
  const notification = message.type === "user" && !message.nested && (isTaskNotificationOrigin(value) || textParts(message.message.content).some(isTaskNotificationRecord));
56463
56633
  message.startsTurn = isHumanUser(message) || notification && !occupancy.unsettled && !pendingNotification;
@@ -56563,10 +56733,17 @@ function itemOutcome(outcome) {
56563
56733
  }
56564
56734
  return { status: "succeeded" };
56565
56735
  }
56566
- function mapClaudeSnapshot(values, sessionId) {
56736
+ function isCheckpointCandidate(message) {
56737
+ return !message.nested && (message.type === "assistant" || message.interrupted || hasRootToolResult(message));
56738
+ }
56739
+ function mapClaudeSnapshot(values, sessionId, mcpServers) {
56740
+ return mapClaudeSnapshotWithCheckpointIds(values, sessionId, mcpServers).snapshot;
56741
+ }
56742
+ function mapClaudeSnapshotWithCheckpointIds(values, sessionId, mcpServers) {
56567
56743
  const messages = conversationMessages(values, sessionId);
56568
56744
  const durationsMs = recordDurationsMs(messages);
56569
56745
  const turns = [];
56746
+ const turnCheckpointIds = [];
56570
56747
  for (let index = 0; index < messages.length; ) {
56571
56748
  const user = messages[index];
56572
56749
  if (!user || !user.startsTurn) {
@@ -56581,7 +56758,7 @@ function mapClaudeSnapshot(values, sessionId) {
56581
56758
  const turnMessages = messages.slice(index, end);
56582
56759
  const outcome = turnOutcome(turnMessages);
56583
56760
  const results = toolResultBlocks(turnMessages);
56584
- const checkpointIndex = turnMessages.findLastIndex(({ type, interrupted, nested }) => !nested && (type === "assistant" || interrupted));
56761
+ const checkpointIndex = turnMessages.findLastIndex(isCheckpointCandidate);
56585
56762
  const lastSteering = turnMessages.findLastIndex(({ type }) => type === "steering");
56586
56763
  const checkpointMessage = checkpointIndex > lastSteering ? turnMessages[checkpointIndex] : void 0;
56587
56764
  const startedAtMs = turnMessages[0]?.timestampMs;
@@ -56589,6 +56766,7 @@ function mapClaudeSnapshot(values, sessionId) {
56589
56766
  let agentMessageOrdinal = 0;
56590
56767
  let reasoningOrdinal = 0;
56591
56768
  let toolOrdinal = 0;
56769
+ turnCheckpointIds.push(turnMessages.filter(isCheckpointCandidate).map((message) => message.uuid));
56592
56770
  turns.push({
56593
56771
  nativeTurnRef: nativeTurnRefSchema.parse({
56594
56772
  harnessId: claudeCodeHarnessId,
@@ -56723,16 +56901,8 @@ function mapClaudeSnapshot(values, sessionId) {
56723
56901
  });
56724
56902
  continue;
56725
56903
  }
56726
- const argumentsResult = jsonValueSchema.safeParse(block.input);
56727
56904
  items.push({
56728
- item: {
56729
- type: "toolExecution",
56730
- itemId,
56731
- toolName: block.name,
56732
- arguments: argumentsResult.success ? argumentsResult.data : null,
56733
- ...output ? { output: { content: [{ type: "text", text: output }] } } : {},
56734
- ...toolDurationMs !== void 0 ? { durationMs: toolDurationMs } : {}
56735
- },
56905
+ item: historyToolItem(itemId, block.name, block.input, output, mcpServers, toolDurationMs),
56736
56906
  outcome: toolOutcome
56737
56907
  });
56738
56908
  }
@@ -56742,7 +56912,14 @@ function mapClaudeSnapshot(values, sessionId) {
56742
56912
  });
56743
56913
  index = end;
56744
56914
  }
56745
- return { turns };
56915
+ return { snapshot: { turns }, turnCheckpointIds };
56916
+ }
56917
+ function historyToolItem(itemId, toolName, input, output, mcpServers, durationMs) {
56918
+ const argumentsResult = jsonValueSchema.safeParse(input);
56919
+ let item = claudeToolItem(itemId, toolName, argumentsResult.success ? argumentsResult.data : null, mcpServers);
56920
+ if (item.type !== "webSearch" && durationMs !== void 0)
56921
+ item = { ...item, durationMs };
56922
+ return output ? { ...item, output: { content: [{ type: "text", text: output }] } } : item;
56746
56923
  }
56747
56924
  function toolResultBlocks(messages) {
56748
56925
  const results = /* @__PURE__ */ new Map();
@@ -56893,16 +57070,8 @@ function mapClaudeSubagentSnapshot(values, parentSessionId, nativeSubagentId2, p
56893
57070
  });
56894
57071
  continue;
56895
57072
  }
56896
- const argumentsResult = jsonValueSchema.safeParse(block.input);
56897
57073
  items.push({
56898
- item: {
56899
- type: "toolExecution",
56900
- itemId,
56901
- toolName: block.name,
56902
- arguments: argumentsResult.success ? argumentsResult.data : null,
56903
- ...output ? { output: { content: [{ type: "text", text: output }] } } : {},
56904
- ...toolDurationMs !== void 0 ? { durationMs: toolDurationMs } : {}
56905
- },
57074
+ item: historyToolItem(itemId, block.name, block.input, output, void 0, toolDurationMs),
56906
57075
  outcome: toolOutcome
56907
57076
  });
56908
57077
  }
@@ -56961,6 +57130,10 @@ function nativeIds(snapshot) {
56961
57130
  ]));
56962
57131
  }
56963
57132
  async function readSnapshot(dependencies, cwd, sessionId) {
57133
+ const history = await readHistory(dependencies, cwd, sessionId);
57134
+ return history.ok ? { ok: true, value: history.value.snapshot } : history;
57135
+ }
57136
+ async function readHistory(dependencies, cwd, sessionId) {
56964
57137
  let messages;
56965
57138
  try {
56966
57139
  messages = await dependencies.readSessionMessages({ cwd, sessionId }) ?? [];
@@ -56977,7 +57150,7 @@ async function readSnapshot(dependencies, cwd, sessionId) {
56977
57150
  };
56978
57151
  }
56979
57152
  try {
56980
- return { ok: true, value: mapClaudeSnapshot(messages, sessionId) };
57153
+ return { ok: true, value: mapClaudeSnapshotWithCheckpointIds(messages, sessionId) };
56981
57154
  } catch {
56982
57155
  return {
56983
57156
  ok: false,
@@ -57017,9 +57190,10 @@ async function forkClaudeSession(input) {
57017
57190
  error: error51("protocolError", "Claude Code Session working directory is unavailable", false)
57018
57191
  };
57019
57192
  }
57020
- const source = await readSnapshot(input.dependencies, input.cwd, sourceRef.data.nativeSessionId);
57021
- if (!source.ok)
57022
- return source;
57193
+ const sourceHistory = await readHistory(input.dependencies, input.cwd, sourceRef.data.nativeSessionId);
57194
+ if (!sourceHistory.ok)
57195
+ return sourceHistory;
57196
+ const source = { ok: true, value: sourceHistory.value.snapshot };
57023
57197
  if (input.kind === "rollbackLastTurn" && source.value.turns.length === 0) {
57024
57198
  return {
57025
57199
  ok: false,
@@ -57049,7 +57223,12 @@ async function forkClaudeSession(input) {
57049
57223
  value: { sessionId: nativeRef.nativeSessionId, nativeRef, openMode: "create" }
57050
57224
  };
57051
57225
  }
57052
- const boundaryIndex = input.kind === "rollbackLastTurn" ? source.value.turns.length - 2 : source.value.turns.findIndex((turn) => checkpoint?.success && turn.checkpoint?.checkpointId === checkpoint.data.checkpointId);
57226
+ const boundaryIndex = input.kind === "rollbackLastTurn" ? source.value.turns.length - 2 : (
57227
+ // A live checkpoint names the last root Assistant record seen while the Turn ran;
57228
+ // the persisted Turn checkpoint can be a later root tool_result of the same Turn.
57229
+ // Fork at that Turn's final checkpoint so the native prefix keeps the whole Turn.
57230
+ sourceHistory.value.turnCheckpointIds.findIndex((ids, index) => checkpoint?.success && source.value.turns[index]?.checkpoint !== void 0 && ids.some((id2) => matchesClaudeCheckpointId(id2, checkpoint.data.checkpointId)))
57231
+ );
57053
57232
  const retained = source.value.turns[boundaryIndex];
57054
57233
  const boundaryId = retained?.checkpoint?.checkpointId ?? (input.kind === "rollbackLastTurn" ? retained?.nativeTurnRef.nativeTurnKey : void 0);
57055
57234
  if (boundaryIndex < 0 || !boundaryId) {
@@ -57238,12 +57417,13 @@ var ClaudeSessionImportIndex = class {
57238
57417
 
57239
57418
  // dist/claude-fork-references.js
57240
57419
  import { randomUUID as randomUUID4 } from "node:crypto";
57241
- import { readFile as readFile6, rename as rename4, rm as rm5, stat as stat5, writeFile as writeFile2 } from "node:fs/promises";
57420
+ import { readFile as readFile5, rename as rename4, rm as rm5, stat as stat5, writeFile as writeFile2 } from "node:fs/promises";
57242
57421
 
57243
57422
  // dist/claude-transcript.js
57423
+ import { createReadStream as createReadStream3 } from "node:fs";
57244
57424
  import os5 from "node:os";
57245
57425
  import path12 from "node:path";
57246
- import { readFile as readFile5, readdir as readdir3, stat as stat4 } from "node:fs/promises";
57426
+ import { readdir as readdir3, stat as stat4 } from "node:fs/promises";
57247
57427
  function projectDirectoryName(cwd) {
57248
57428
  return cwd.replace(/[^A-Za-z0-9]/gu, "-");
57249
57429
  }
@@ -57278,12 +57458,34 @@ async function findTranscriptFile(environment, cwd, relativeName) {
57278
57458
  function findClaudeTranscript(input) {
57279
57459
  return findTranscriptFile(input.environment, input.cwd, `${input.sessionId}.jsonl`);
57280
57460
  }
57461
+ async function* transcriptLines(transcript) {
57462
+ const stream = createReadStream3(transcript, { encoding: "utf8" });
57463
+ let pending = "";
57464
+ try {
57465
+ for await (const chunk of stream) {
57466
+ const contents = chunk;
57467
+ let start = 0;
57468
+ let newline;
57469
+ while ((newline = contents.indexOf("\n", start)) !== -1) {
57470
+ const line = pending + contents.slice(start, newline);
57471
+ pending = "";
57472
+ yield line;
57473
+ start = newline + 1;
57474
+ }
57475
+ pending += contents.slice(start);
57476
+ }
57477
+ if (pending.length > 0)
57478
+ yield pending;
57479
+ } finally {
57480
+ stream.destroy();
57481
+ }
57482
+ }
57281
57483
  function isRecord9(value) {
57282
57484
  return typeof value === "object" && value !== null && !Array.isArray(value);
57283
57485
  }
57284
- function parseTranscriptRecords(contents, sessionId) {
57486
+ async function parseTranscriptRecords(transcript, sessionId) {
57285
57487
  const messages = /* @__PURE__ */ new Map();
57286
- for (const line of contents.split("\n")) {
57488
+ for await (const line of transcriptLines(transcript)) {
57287
57489
  if (line.trim().length === 0)
57288
57490
  continue;
57289
57491
  let entry;
@@ -57303,14 +57505,14 @@ async function readClaudeTranscript(input) {
57303
57505
  const transcript = await findClaudeTranscript(input);
57304
57506
  if (!transcript)
57305
57507
  return null;
57306
- return parseTranscriptRecords(await readFile5(transcript, "utf8"), input.sessionId);
57508
+ return parseTranscriptRecords(transcript, input.sessionId);
57307
57509
  }
57308
57510
  async function readClaudeSubagentTranscript(input) {
57309
57511
  const relativeName = path12.join(input.sessionId, "subagents", `agent-${input.nativeSubagentId}.jsonl`);
57310
57512
  const transcript = await findTranscriptFile(input.environment, input.cwd, relativeName);
57311
57513
  if (!transcript)
57312
57514
  return null;
57313
- return parseTranscriptRecords(await readFile5(transcript, "utf8"), input.sessionId).filter((entry) => isRecord9(entry) && (entry.type === "user" || entry.type === "assistant"));
57515
+ return (await parseTranscriptRecords(transcript, input.sessionId)).filter((entry) => isRecord9(entry) && (entry.type === "user" || entry.type === "assistant"));
57314
57516
  }
57315
57517
 
57316
57518
  // dist/claude-fork-references.js
@@ -57349,7 +57551,7 @@ async function remapForkedSessionReferences(input) {
57349
57551
  const transcript = await findClaudeTranscript(input);
57350
57552
  if (!transcript)
57351
57553
  return 0;
57352
- const contents = await readFile6(transcript, "utf8");
57554
+ const contents = await readFile5(transcript, "utf8");
57353
57555
  if (!contents.includes('"sameAs"'))
57354
57556
  return 0;
57355
57557
  const lines = contents.split("\n");
@@ -57389,7 +57591,7 @@ async function remapForkedSessionReferences(input) {
57389
57591
 
57390
57592
  // dist/long-context.js
57391
57593
  import { randomUUID as randomUUID5 } from "node:crypto";
57392
- import { mkdir as mkdir4, readFile as readFile7, rename as rename5, rm as rm6, writeFile as writeFile3 } from "node:fs/promises";
57594
+ import { mkdir as mkdir4, readFile as readFile6, rename as rename5, rm as rm6, writeFile as writeFile3 } from "node:fs/promises";
57393
57595
  import os6 from "node:os";
57394
57596
  import path13 from "node:path";
57395
57597
  var MILLION_CONTEXT_MODELS = [{ id: "claude-opus-5-5", aliases: ["claude-opus-5.5"] }];
@@ -57401,7 +57603,7 @@ function claudeLongContextFile(environment) {
57401
57603
  }
57402
57604
  async function readClaudeLongContext(environment) {
57403
57605
  try {
57404
- const parsed = JSON.parse(await readFile7(claudeLongContextFile(environment), "utf8"));
57606
+ const parsed = JSON.parse(await readFile6(claudeLongContextFile(environment), "utf8"));
57405
57607
  if (typeof parsed === "object" && parsed !== null && "enabled" in parsed && typeof parsed.enabled === "boolean") {
57406
57608
  return parsed.enabled;
57407
57609
  }
@@ -57433,7 +57635,7 @@ function claudeSessionModel(model2, enabled) {
57433
57635
 
57434
57636
  // dist/model-catalog.js
57435
57637
  import { Buffer as Buffer2 } from "node:buffer";
57436
- import { readFile as readFile8 } from "node:fs/promises";
57638
+ import { readFile as readFile7 } from "node:fs/promises";
57437
57639
  import os7 from "node:os";
57438
57640
  import path14 from "node:path";
57439
57641
 
@@ -57455,6 +57657,37 @@ var CLAUDE_THINKING_OPTIONS = [
57455
57657
  ];
57456
57658
  var CLAUDE_THINKING_OPTION_IDS = CLAUDE_THINKING_OPTIONS.map(({ id: id2 }) => id2);
57457
57659
  var CLAUDE_DEFAULT_THINKING_OPTION_ID = harnessThinkingOptionIdSchema.parse("auto");
57660
+ function claudeSupportedThinkingOptionIds(model2) {
57661
+ if (model2.supportsEffort === void 0 && model2.supportedEffortLevels === void 0 && model2.supportsAdaptiveThinking === void 0 && model2.supportsThinkingOff === void 0) {
57662
+ return [...CLAUDE_THINKING_OPTION_IDS];
57663
+ }
57664
+ const efforts = new Set(model2.supportsEffort === false ? [] : model2.supportedEffortLevels ?? []);
57665
+ return CLAUDE_THINKING_OPTION_IDS.filter((id2) => {
57666
+ if (id2 === "off")
57667
+ return model2.supportsThinkingOff !== false;
57668
+ if (id2 === "auto")
57669
+ return true;
57670
+ if (id2 === "ultracode")
57671
+ return efforts.has("xhigh");
57672
+ return efforts.has(id2);
57673
+ });
57674
+ }
57675
+ var CLAUDE_EFFORT_ORDER = ["low", "medium", "high", "xhigh", "max"];
57676
+ function fitClaudeThinkingOptionId(requested, supported) {
57677
+ if (!supported || supported.includes(requested))
57678
+ return requested;
57679
+ const ceiling = CLAUDE_EFFORT_ORDER.indexOf(requested === "ultracode" ? "xhigh" : requested);
57680
+ let best = CLAUDE_DEFAULT_THINKING_OPTION_ID;
57681
+ let bestRank = -1;
57682
+ for (const id2 of supported) {
57683
+ const rank = CLAUDE_EFFORT_ORDER.indexOf(id2);
57684
+ if (rank > bestRank && rank <= ceiling) {
57685
+ best = id2;
57686
+ bestRank = rank;
57687
+ }
57688
+ }
57689
+ return best;
57690
+ }
57458
57691
  function parseClaudeThinkingOptionId(value) {
57459
57692
  const id2 = harnessThinkingOptionIdSchema.parse(value);
57460
57693
  if (!CLAUDE_THINKING_OPTION_IDS.includes(id2)) {
@@ -57486,8 +57719,14 @@ var CLAUDE_MODEL_VALUE_MAX_LENGTH = 512;
57486
57719
  var modelInfoSchema = external_exports.object({
57487
57720
  value: external_exports.string().trim().min(1).max(CLAUDE_MODEL_VALUE_MAX_LENGTH),
57488
57721
  displayName: external_exports.string().trim().min(1).max(HARNESS_MODEL_LABEL_MAX_LENGTH),
57489
- description: external_exports.string().trim().min(1).max(HARNESS_MODEL_LABEL_MAX_LENGTH).optional(),
57490
- resolvedModel: harnessResolvedModelLabelSchema.optional()
57722
+ description: external_exports.string().trim().max(HARNESS_MODEL_LABEL_MAX_LENGTH).optional(),
57723
+ resolvedModel: harnessResolvedModelLabelSchema.optional(),
57724
+ // Malformed capability fields count as unreported instead of failing the whole catalog;
57725
+ // unknown effort levels are ignored when mapping Thinking options.
57726
+ supportsEffort: external_exports.boolean().optional().catch(void 0),
57727
+ supportedEffortLevels: external_exports.array(external_exports.string()).optional().catch(void 0),
57728
+ supportsAdaptiveThinking: external_exports.boolean().optional().catch(void 0),
57729
+ supportsThinkingOff: external_exports.boolean().optional().catch(void 0)
57491
57730
  });
57492
57731
  var modelPickerOptionSchema = external_exports.object({
57493
57732
  model: external_exports.string().trim().min(1).max(CLAUDE_MODEL_VALUE_MAX_LENGTH),
@@ -57573,7 +57812,7 @@ async function readClaudeUserModelPicker(environment = process.env) {
57573
57812
  const settingsPath = path14.join(resolveClaudeConfigDirectory(environment), "settings.json");
57574
57813
  let raw;
57575
57814
  try {
57576
- raw = await readFile8(settingsPath, "utf8");
57815
+ raw = await readFile7(settingsPath, "utf8");
57577
57816
  } catch {
57578
57817
  return void 0;
57579
57818
  }
@@ -57670,12 +57909,17 @@ function uniqueDisplayLabels(rows) {
57670
57909
  }
57671
57910
  return labels;
57672
57911
  }
57912
+ function canonicalRow(row) {
57913
+ if (row.supportedEffortLevels === void 0)
57914
+ return row;
57915
+ return { ...row, supportedEffortLevels: [...new Set(row.supportedEffortLevels)].sort() };
57916
+ }
57673
57917
  function normalizeRows(value) {
57674
57918
  if (!Array.isArray(value))
57675
57919
  throw new Error("Claude Code Model catalog is not an array");
57676
57920
  const byValue = /* @__PURE__ */ new Map();
57677
57921
  for (const nativeRow of value) {
57678
- const row = modelInfoSchema.parse(nativeRow);
57922
+ const row = canonicalRow(modelInfoSchema.parse(nativeRow));
57679
57923
  const existing = byValue.get(row.value);
57680
57924
  if (existing && JSON.stringify(existing) !== JSON.stringify(row)) {
57681
57925
  throw new Error("Claude Code Model catalog contains conflicting selectable values");
@@ -57700,7 +57944,7 @@ function normalizeClaudeModelCatalog(snapshot) {
57700
57944
  ref: encodeClaudeModelRef(row.value),
57701
57945
  label: labels.get(row.value) ?? row.displayName,
57702
57946
  ...row.resolvedModel ? { resolvedModelLabel: row.resolvedModel } : {},
57703
- supportedThinkingOptionIds: [...CLAUDE_THINKING_OPTION_IDS]
57947
+ supportedThinkingOptionIds: claudeSupportedThinkingOptionIds(row)
57704
57948
  };
57705
57949
  });
57706
57950
  models.sort((left, right) => {
@@ -57914,7 +58158,7 @@ function projectClaudeAccountUsage(usage, account) {
57914
58158
  }
57915
58159
 
57916
58160
  // dist/gateway-models.js
57917
- import { readFile as readFile9 } from "node:fs/promises";
58161
+ import { readFile as readFile8 } from "node:fs/promises";
57918
58162
  import path15 from "node:path";
57919
58163
  var GATEWAY_MODELS_TIMEOUT_MS = 3e3;
57920
58164
  var GATEWAY_MODELS_MAX_BYTES = 2 * 1024 * 1024;
@@ -57964,7 +58208,7 @@ async function readClaudeUserSettingsEnv(environment) {
57964
58208
  if (!configDir)
57965
58209
  return {};
57966
58210
  try {
57967
- const raw = await readFile9(path15.join(configDir, "settings.json"), "utf8");
58211
+ const raw = await readFile8(path15.join(configDir, "settings.json"), "utf8");
57968
58212
  const parsed = JSON.parse(raw);
57969
58213
  if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
57970
58214
  return {};
@@ -58226,7 +58470,7 @@ function safeNonNegativeInteger2(value) {
58226
58470
  function userMessageContent(input) {
58227
58471
  if (typeof input === "string")
58228
58472
  return input;
58229
- const blocks = input.map((part) => part.type === "text" ? { type: "text", text: part.text } : {
58473
+ const blocks = input.map((part) => part.type !== "image" || "source" in part ? part : {
58230
58474
  type: "image",
58231
58475
  source: {
58232
58476
  type: "base64",
@@ -58528,7 +58772,10 @@ var ClaudeSdkTransport = class {
58528
58772
  // Adaptive Thinking is redacted by default: the API streams `thinking_delta`
58529
58773
  // frames carrying only token estimates and empty text, so no Reasoning Item
58530
58774
  // would ever start. Summarized display is the official channel for readable
58531
- // Thinking and is what Claude Code's own TUI renders.
58775
+ // Thinking and is what Claude Code's own TUI renders. The SDK passes this as
58776
+ // `--thinking adaptive`, which only turns Thinking on: Claude Code sends adaptive
58777
+ // Thinking to Models that support it and a token budget to the rest. The caller
58778
+ // fits the effort to the Model's catalog levels.
58532
58779
  thinking: thinking.enabled ? { type: "adaptive", display: "summarized" } : { type: "disabled" },
58533
58780
  ...thinking.effort ? { effort: thinking.effort } : {},
58534
58781
  pathToClaudeCodeExecutable: executable,
@@ -58631,13 +58878,23 @@ var ClaudeSdkTransport = class {
58631
58878
  throw new Error("Claude SDK transport is not started");
58632
58879
  return this.#permissionMode;
58633
58880
  }
58634
- async setModel(model2) {
58881
+ async setModel(model2, thinkingOptionId = this.#thinkingOptionId) {
58635
58882
  const activeQuery = this.#query;
58636
58883
  if (!this.#started || !activeQuery)
58637
58884
  throw new Error("Claude SDK transport is not started");
58638
- const thinking = claudeThinkingConfiguration(this.#thinkingOptionId);
58885
+ const id2 = parseClaudeThinkingOptionId(thinkingOptionId);
58886
+ const previous = claudeThinkingConfiguration(this.#thinkingOptionId);
58887
+ const thinking = claudeThinkingConfiguration(id2);
58639
58888
  const previousModel = this.#currentModel;
58640
58889
  await activeQuery.setModel(model2);
58890
+ if (id2 !== this.#thinkingOptionId && !thinking.ultracode) {
58891
+ try {
58892
+ await activeQuery.applyFlagSettings(claudeThinkingFlagSettings(thinking, previous));
58893
+ } catch (error52) {
58894
+ await this.#restoreOrFault(() => activeQuery.setModel(previousModel));
58895
+ throw error52;
58896
+ }
58897
+ }
58641
58898
  if (thinking.ultracode) {
58642
58899
  try {
58643
58900
  await activeQuery.applyFlagSettings(claudeThinkingFlagSettings(thinking, thinking));
@@ -58645,13 +58902,14 @@ var ClaudeSdkTransport = class {
58645
58902
  } catch (error52) {
58646
58903
  await this.#restoreOrFault(async () => {
58647
58904
  await activeQuery.setModel(previousModel);
58648
- await activeQuery.applyFlagSettings(claudeThinkingFlagSettings(thinking, null));
58649
- await this.#verifyUltracode(activeQuery);
58905
+ await activeQuery.applyFlagSettings(claudeThinkingFlagSettings(previous, thinking));
58906
+ await (previous.ultracode ? this.#verifyUltracode(activeQuery) : this.#verifyUltracodeOff(activeQuery));
58650
58907
  });
58651
58908
  throw error52;
58652
58909
  }
58653
58910
  }
58654
58911
  this.#currentModel = model2;
58912
+ this.#thinkingOptionId = id2;
58655
58913
  }
58656
58914
  async setThinkingOption(thinkingOptionId) {
58657
58915
  const activeQuery = this.#query;
@@ -58762,7 +59020,7 @@ var ClaudeSdkTransport = class {
58762
59020
  * The Turn ending first therefore does not reject it, and a missing `queued` receipt resolves
58763
59021
  * after a bounded wait so callers that serialize requests are never held indefinitely.
58764
59022
  */
58765
- steer(text2, messageId, onTakeover) {
59023
+ steer(content, messageId, onTakeover) {
58766
59024
  if (this.#closePromise || !this.#started || !this.#query || !this.canSteerActiveTurn()) {
58767
59025
  return Promise.reject(new ClaudeSteerMissedTurnError());
58768
59026
  }
@@ -58772,7 +59030,7 @@ var ClaudeSdkTransport = class {
58772
59030
  try {
58773
59031
  this.#input.push({
58774
59032
  type: "user",
58775
- message: { role: "user", content: text2 },
59033
+ message: { role: "user", content },
58776
59034
  parent_tool_use_id: null,
58777
59035
  session_id: this.sessionId,
58778
59036
  uuid: messageId,
@@ -60023,6 +60281,7 @@ var ClaudeToolLifecycle = class {
60023
60281
  #onDetached;
60024
60282
  #outputLimit;
60025
60283
  #taskTracker;
60284
+ #mcpServers;
60026
60285
  #nativeTurnKey;
60027
60286
  #tools = /* @__PURE__ */ new Map();
60028
60287
  #toolOrdinal = 0;
@@ -60033,6 +60292,7 @@ var ClaudeToolLifecycle = class {
60033
60292
  this.#onDetached = options.onDetached;
60034
60293
  this.#outputLimit = options.outputLimit;
60035
60294
  this.#taskTracker = options.taskTracker;
60295
+ this.#mcpServers = options.mcpServers ?? (() => []);
60036
60296
  this.#nativeTurnKey = options.nativeTurnKey;
60037
60297
  }
60038
60298
  get size() {
@@ -60048,12 +60308,7 @@ var ClaudeToolLifecycle = class {
60048
60308
  itemId,
60049
60309
  command,
60050
60310
  cwd: this.#cwd
60051
- } : {
60052
- type: "toolExecution",
60053
- itemId,
60054
- toolName: isClaudeTaskTool(event.toolName) ? "Todo" : event.toolName,
60055
- arguments: isClaudeTaskTool(event.toolName) ? {} : event.arguments
60056
- };
60311
+ } : isClaudeTaskTool(event.toolName) ? { type: "toolExecution", itemId, toolName: "Todo", arguments: {} } : claudeToolItem(itemId, event.toolName, event.arguments, this.#mcpServers());
60057
60312
  this.#tools.set(event.callId, {
60058
60313
  item,
60059
60314
  nativeName: event.toolName,
@@ -60098,6 +60353,8 @@ var ClaudeToolLifecycle = class {
60098
60353
  } : {},
60099
60354
  durationMs
60100
60355
  };
60356
+ } else if (tool.item.type === "webSearch") {
60357
+ tool.item = { ...tool.item, ...output ? { output } : {} };
60101
60358
  } else {
60102
60359
  tool.item = { ...tool.item, ...output ? { output } : {}, durationMs };
60103
60360
  }
@@ -60126,7 +60383,7 @@ var ClaudeToolLifecycle = class {
60126
60383
  for (const [callId, tool] of this.#tools) {
60127
60384
  this.#tools.delete(callId);
60128
60385
  const durationMs = Math.max(tool.elapsedMs, Date.now() - tool.startedAtMs, 0);
60129
- this.#completeItem(turnId, { ...tool.item, durationMs }, outcome);
60386
+ this.#completeItem(turnId, tool.item.type === "webSearch" ? tool.item : { ...tool.item, durationMs }, outcome);
60130
60387
  }
60131
60388
  }
60132
60389
  #completeItem(turnId, item, outcome) {
@@ -60178,6 +60435,135 @@ function estimateClaudeRequestCostUsd(usage) {
60178
60435
  return Number.isFinite(cost) && cost >= 0 ? cost : void 0;
60179
60436
  }
60180
60437
 
60438
+ // dist/turn-input.js
60439
+ import { constants as constants3 } from "node:fs";
60440
+ import { open as open5 } from "node:fs/promises";
60441
+ var MAX_IMAGE_FILE_BYTES = 20 * 1024 * 1024;
60442
+ var MAX_STEER_BASE64_BYTES = 5 * 1024 * 1024;
60443
+ var MAX_STEER_IMAGE_SIDE = 2e3;
60444
+ var HEADER_BYTES = 32;
60445
+ function imageMediaType(data) {
60446
+ if (data.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) {
60447
+ return "image/png";
60448
+ }
60449
+ if (data.subarray(0, 3).equals(Buffer.from([255, 216, 255])))
60450
+ return "image/jpeg";
60451
+ const head = data.subarray(0, 12).toString("latin1");
60452
+ if (head.startsWith("GIF87a") || head.startsWith("GIF89a"))
60453
+ return "image/gif";
60454
+ if (head.startsWith("RIFF") && head.slice(8) === "WEBP")
60455
+ return "image/webp";
60456
+ return null;
60457
+ }
60458
+ function jpegDimensions(data) {
60459
+ let offset = 2;
60460
+ while (offset + 9 <= data.length) {
60461
+ if (data[offset] !== 255)
60462
+ return null;
60463
+ const marker = data[offset + 1] ?? 0;
60464
+ if (marker === 255) {
60465
+ offset += 1;
60466
+ continue;
60467
+ }
60468
+ if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
60469
+ return { height: data.readUInt16BE(offset + 5), width: data.readUInt16BE(offset + 7) };
60470
+ }
60471
+ if (marker === 1 || marker >= 208 && marker <= 216) {
60472
+ offset += 2;
60473
+ continue;
60474
+ }
60475
+ offset += 2 + data.readUInt16BE(offset + 2);
60476
+ }
60477
+ return null;
60478
+ }
60479
+ function imageDimensions(data, mediaType) {
60480
+ if (data.length < 30)
60481
+ return null;
60482
+ switch (mediaType) {
60483
+ case "image/png":
60484
+ return { width: data.readUInt32BE(16), height: data.readUInt32BE(20) };
60485
+ case "image/gif":
60486
+ return { width: data.readUInt16LE(6), height: data.readUInt16LE(8) };
60487
+ case "image/webp": {
60488
+ const chunk = data.toString("latin1", 12, 16);
60489
+ if (chunk === "VP8 ") {
60490
+ return { width: data.readUInt16LE(26) & 16383, height: data.readUInt16LE(28) & 16383 };
60491
+ }
60492
+ if (chunk === "VP8L") {
60493
+ const bits = data.readUInt32LE(21);
60494
+ return { width: (bits & 16383) + 1, height: (bits >>> 14 & 16383) + 1 };
60495
+ }
60496
+ if (chunk === "VP8X") {
60497
+ return { width: data.readUIntLE(24, 3) + 1, height: data.readUIntLE(27, 3) + 1 };
60498
+ }
60499
+ return null;
60500
+ }
60501
+ case "image/jpeg":
60502
+ return jpegDimensions(data);
60503
+ }
60504
+ }
60505
+ function fitsSteer(data, mediaType) {
60506
+ if (Math.ceil(data.length / 3) * 4 > MAX_STEER_BASE64_BYTES)
60507
+ return false;
60508
+ const size = imageDimensions(data, mediaType);
60509
+ return size !== null && size.width > 0 && size.height > 0 && size.width <= MAX_STEER_IMAGE_SIDE && size.height <= MAX_STEER_IMAGE_SIDE;
60510
+ }
60511
+ async function imageBlock(file2, steer) {
60512
+ let handle;
60513
+ try {
60514
+ handle = await open5(file2, constants3.O_RDONLY | constants3.O_NONBLOCK);
60515
+ } catch {
60516
+ return null;
60517
+ }
60518
+ try {
60519
+ const stats = await handle.stat();
60520
+ if (!stats.isFile() || stats.size > MAX_IMAGE_FILE_BYTES)
60521
+ return null;
60522
+ if (steer && Math.ceil(stats.size / 3) * 4 > MAX_STEER_BASE64_BYTES)
60523
+ return null;
60524
+ const header = Buffer.alloc(HEADER_BYTES);
60525
+ const { bytesRead } = await handle.read(header, 0, HEADER_BYTES, 0);
60526
+ if (!imageMediaType(header.subarray(0, bytesRead)))
60527
+ return null;
60528
+ const buffer = Buffer.alloc(stats.size + 1);
60529
+ let length = 0;
60530
+ while (length < buffer.length) {
60531
+ const read = await handle.read(buffer, length, buffer.length - length, length);
60532
+ if (read.bytesRead === 0)
60533
+ break;
60534
+ length += read.bytesRead;
60535
+ }
60536
+ if (length > stats.size)
60537
+ return null;
60538
+ const data = buffer.subarray(0, length);
60539
+ const mediaType = imageMediaType(data.subarray(0, HEADER_BYTES));
60540
+ if (!mediaType)
60541
+ return null;
60542
+ if (steer && !fitsSteer(data, mediaType))
60543
+ return null;
60544
+ return {
60545
+ type: "image",
60546
+ source: { type: "base64", media_type: mediaType, data: data.toString("base64") }
60547
+ };
60548
+ } catch {
60549
+ return null;
60550
+ } finally {
60551
+ await handle.close().catch(() => void 0);
60552
+ }
60553
+ }
60554
+ async function claudeUserContent(text2, { steer = false } = {}) {
60555
+ const paths = [...new Set(desktopImageAttachmentPaths(text2))];
60556
+ if (paths.length === 0)
60557
+ return text2;
60558
+ const content = [{ type: "text", text: text2 }];
60559
+ for (const file2 of paths) {
60560
+ const block = await imageBlock(file2, steer);
60561
+ if (block)
60562
+ content.push(block);
60563
+ }
60564
+ return content.length > 1 ? content : text2;
60565
+ }
60566
+
60181
60567
  // dist/claude-code-adapter.js
60182
60568
  var claudeCodeHarnessId2 = harnessIdSchema.parse("claude-code");
60183
60569
  var claudeCommandCatalog = harnessCommandCatalogSchema.parse({
@@ -60265,6 +60651,7 @@ var DEFAULT_CONTINUATION_QUIESCENCE_MS = 2e3;
60265
60651
  function isRecord14(value) {
60266
60652
  return typeof value === "object" && value !== null && !Array.isArray(value);
60267
60653
  }
60654
+ var SYNTHETIC_AUTONOMOUS_TURN_KEY_PATTERN = /^autonomous-\d+$/u;
60268
60655
  function safeNonNegativeInteger3(value) {
60269
60656
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
60270
60657
  }
@@ -60474,12 +60861,16 @@ var ClaudeHarnessSession = class {
60474
60861
  #longContextEnabled;
60475
60862
  #requestedPermissionModeId;
60476
60863
  #requestedThinkingOptionId;
60864
+ /** This Session's folder's inspected catalog, which says what Thinking each Model accepts. */
60865
+ #modelCatalog;
60477
60866
  #readSessionMessages;
60478
60867
  #sessionId;
60479
60868
  #toolOutputLimit;
60480
60869
  #backgroundCommands;
60481
60870
  #continuationQuiescenceMs;
60482
60871
  #taskTracker = new ClaudeTaskTracker();
60872
+ /** MCP server names the latest native Segment reported; they disambiguate MCP Tool names. */
60873
+ #mcpServers = [];
60483
60874
  #acceptingTurn = false;
60484
60875
  #active = null;
60485
60876
  #closePromise = null;
@@ -60534,7 +60925,8 @@ var ClaudeHarnessSession = class {
60534
60925
  this.#requestedModel = options.requestedModel;
60535
60926
  this.#longContextEnabled = options.longContextEnabled;
60536
60927
  this.#requestedPermissionModeId = options.requestedPermissionModeId;
60537
- this.#requestedThinkingOptionId = options.requestedThinkingOptionId;
60928
+ this.#modelCatalog = options.modelCatalog;
60929
+ this.#requestedThinkingOptionId = fitClaudeThinkingOptionId(options.requestedThinkingOptionId, this.#supportedThinkingOptionIds(options.requestedModel ?? (this.#openMode === "create" ? CLAUDE_DEFAULT_MODEL_REF : void 0)));
60538
60930
  this.#sessionId = options.sessionId;
60539
60931
  this.#toolOutputLimit = options.toolOutputLimit;
60540
60932
  this.#backgroundCommands = new ClaudeBackgroundCommandItems({
@@ -60602,39 +60994,56 @@ var ClaudeHarnessSession = class {
60602
60994
  this.#readingHistory = true;
60603
60995
  try {
60604
60996
  let messages;
60605
- try {
60606
- const deadline = Date.now() + this.#closeTimeoutMs;
60607
- for (; ; ) {
60997
+ const deadline = Date.now() + this.#closeTimeoutMs;
60998
+ for (; ; ) {
60999
+ try {
60608
61000
  messages = await this.#readSessionMessages({
60609
61001
  cwd: this.#cwd,
60610
61002
  sessionId: this.#sessionId
60611
61003
  }) ?? [];
60612
- const ids = new Set(messages.flatMap((message) => isRecord14(message) && typeof message.uuid === "string" ? [message.uuid] : []));
60613
- if (this.#unpersistedMessageIds.every((id2) => ids.has(id2))) {
60614
- this.#unpersistedMessageIds = [];
60615
- break;
60616
- }
60617
- if (Date.now() >= deadline || this.#phase !== "open") {
60618
- return {
60619
- ok: false,
60620
- error: {
60621
- code: "sessionBusy",
60622
- message: "Claude Code history is still being persisted",
60623
- retryable: true
60624
- }
60625
- };
60626
- }
60627
- await delay2(25);
61004
+ } catch {
61005
+ return {
61006
+ ok: false,
61007
+ error: {
61008
+ code: "nativeFailure",
61009
+ message: "Claude Code history could not be read",
61010
+ retryable: true
61011
+ }
61012
+ };
60628
61013
  }
60629
- } catch {
60630
- return {
60631
- ok: false,
60632
- error: {
60633
- code: "nativeFailure",
60634
- message: "Claude Code history could not be read",
60635
- retryable: true
60636
- }
60637
- };
61014
+ let ids;
61015
+ try {
61016
+ ids = new Set(messages.flatMap((message) => {
61017
+ if (!isRecord14(message) || typeof message.uuid !== "string")
61018
+ return [];
61019
+ const queued = readClaudeQueuedCommand(message, this.#sessionId);
61020
+ return queued ? [message.uuid, queued.sourceUuid] : [message.uuid];
61021
+ }));
61022
+ } catch {
61023
+ return {
61024
+ ok: false,
61025
+ error: {
61026
+ code: "protocolError",
61027
+ message: "Claude Code history is invalid",
61028
+ retryable: false
61029
+ }
61030
+ };
61031
+ }
61032
+ if (this.#unpersistedMessageIds.every((id2) => isPersistedClaudeMessageId(id2, ids))) {
61033
+ this.#unpersistedMessageIds = [];
61034
+ break;
61035
+ }
61036
+ if (Date.now() >= deadline || this.#phase !== "open") {
61037
+ return {
61038
+ ok: false,
61039
+ error: {
61040
+ code: "sessionBusy",
61041
+ message: "Claude Code history is still being persisted",
61042
+ retryable: true
61043
+ }
61044
+ };
61045
+ }
61046
+ await delay2(25);
60638
61047
  }
60639
61048
  if (messages.length === 0 && isPendingClaudeSession(this.#nativeRef)) {
60640
61049
  try {
@@ -60665,7 +61074,10 @@ var ClaudeHarnessSession = class {
60665
61074
  try {
60666
61075
  return {
60667
61076
  ok: true,
60668
- value: { ...mapClaudeSnapshot(messages, this.#sessionId), state: this.#state }
61077
+ value: {
61078
+ ...mapClaudeSnapshot(messages, this.#sessionId, this.#mcpServers),
61079
+ state: this.#state
61080
+ }
60669
61081
  };
60670
61082
  } catch {
60671
61083
  return {
@@ -60729,6 +61141,7 @@ var ClaudeHarnessSession = class {
60729
61141
  }
60730
61142
  const turnInput = imageParts.length === 0 ? text2 : [...text2.length > 0 ? [{ type: "text", text: text2 }] : [], ...imageParts];
60731
61143
  this.#acceptingTurn = true;
61144
+ const content = await claudeUserContent(text2);
60732
61145
  const startingTransport = this.#transport === null;
60733
61146
  let transport;
60734
61147
  try {
@@ -60787,6 +61200,7 @@ var ClaudeHarnessSession = class {
60787
61200
  cwd: this.#cwd,
60788
61201
  outputLimit: this.#toolOutputLimit,
60789
61202
  taskTracker: this.#taskTracker,
61203
+ mcpServers: () => this.#mcpServers,
60790
61204
  nativeTurnKey,
60791
61205
  newItemId: () => hostItemIdSchema.parse(this.#randomUUID()),
60792
61206
  emit: (event) => this.#event(event),
@@ -60829,7 +61243,7 @@ var ClaudeHarnessSession = class {
60829
61243
  nativeTurnKey,
60830
61244
  formatVersion: 1
60831
61245
  });
60832
- const running = transport.runTurn(turnInput, nativeTurnRef.nativeTurnKey, (event) => {
61246
+ const running = transport.runTurn(imageParts.length > 0 ? turnInput : content, nativeTurnRef.nativeTurnKey, (event) => {
60833
61247
  this.#handleTurnEvent(active, event);
60834
61248
  });
60835
61249
  active.userMessageId = nativeTurnRef.nativeTurnKey;
@@ -60841,13 +61255,6 @@ var ClaudeHarnessSession = class {
60841
61255
  return { ok: true, value: { turnId: command.turnId } };
60842
61256
  }
60843
61257
  async #steer(command) {
60844
- const active = this.#active;
60845
- if (!active || active.command.turnId !== command.turnId) {
60846
- return { ok: false, error: invalidState("Claude Code steer target is not the active Turn") };
60847
- }
60848
- if (active.cancellationRequested) {
60849
- return { ok: false, error: invalidState("Claude Code steer target is being cancelled") };
60850
- }
60851
61258
  const text2 = command.input.map((input) => input.text).join("\n");
60852
61259
  if (text2.length === 0) {
60853
61260
  return {
@@ -60859,6 +61266,14 @@ var ClaudeHarnessSession = class {
60859
61266
  }
60860
61267
  };
60861
61268
  }
61269
+ const content = await claudeUserContent(text2, { steer: true });
61270
+ const active = this.#active;
61271
+ if (!active || active.command.turnId !== command.turnId) {
61272
+ return { ok: false, error: invalidState("Claude Code steer target is not the active Turn") };
61273
+ }
61274
+ if (active.cancellationRequested) {
61275
+ return { ok: false, error: invalidState("Claude Code steer target is being cancelled") };
61276
+ }
60862
61277
  const transport = this.#transport;
60863
61278
  if (!transport) {
60864
61279
  return { ok: false, error: invalidState("Claude Code steer missed the active Turn") };
@@ -60876,7 +61291,7 @@ var ClaudeHarnessSession = class {
60876
61291
  const messageId = this.#randomUUID();
60877
61292
  active.steersAwaitingNative.add(messageId);
60878
61293
  try {
60879
- await transport.steer(text2, messageId, (started) => this.#takeOverSteer(active, messageId, started));
61294
+ await transport.steer(content, messageId, (started) => this.#takeOverSteer(active, messageId, started));
60880
61295
  } catch (error52) {
60881
61296
  if (error52 instanceof ClaudeSteerMissedTurnError) {
60882
61297
  this.#takeOverSteer(active, messageId, false);
@@ -60969,6 +61384,7 @@ var ClaudeHarnessSession = class {
60969
61384
  cwd: this.#cwd,
60970
61385
  outputLimit: this.#toolOutputLimit,
60971
61386
  taskTracker: this.#taskTracker,
61387
+ mcpServers: () => this.#mcpServers,
60972
61388
  nativeTurnKey,
60973
61389
  newItemId: () => hostItemIdSchema.parse(this.#randomUUID()),
60974
61390
  emit: (event) => this.#event(event),
@@ -61112,11 +61528,12 @@ var ClaudeHarnessSession = class {
61112
61528
  resolveConfiguration = resolve5;
61113
61529
  });
61114
61530
  try {
61531
+ const thinkingOptionId = fitClaudeThinkingOptionId(this.#requestedThinkingOptionId, this.#supportedThinkingOptionIds(command.model));
61115
61532
  const transport = this.#transport;
61116
61533
  if (transport) {
61117
61534
  try {
61118
61535
  const sessionModel = claudeSessionModel(model2, await this.#longContextEnabled());
61119
- await transport.setModel(sessionModel);
61536
+ await transport.setModel(sessionModel, thinkingOptionId);
61120
61537
  this.#sdkModel = sessionModel;
61121
61538
  } catch (error52) {
61122
61539
  return {
@@ -61130,6 +61547,7 @@ var ClaudeHarnessSession = class {
61130
61547
  }
61131
61548
  }
61132
61549
  this.#requestedModel = command.model;
61550
+ this.#requestedThinkingOptionId = thinkingOptionId;
61133
61551
  const persistenceError = await this.#savePendingConfiguration();
61134
61552
  if (persistenceError)
61135
61553
  return { ok: false, error: persistenceError };
@@ -61164,6 +61582,17 @@ var ClaudeHarnessSession = class {
61164
61582
  }
61165
61583
  };
61166
61584
  }
61585
+ const supported = this.#supportedThinkingOptionIds(this.#effectiveModelRef());
61586
+ if (supported && !supported.includes(thinkingOptionId)) {
61587
+ return {
61588
+ ok: false,
61589
+ error: {
61590
+ code: "invalidRequest",
61591
+ message: "Claude Code Thinking option is unavailable for the selected Model",
61592
+ retryable: false
61593
+ }
61594
+ };
61595
+ }
61167
61596
  this.#usageGeneration += 1;
61168
61597
  this.#contextUsageFreshUntilMs = 0;
61169
61598
  this.#contextUsageCooldownUntilMs = 0;
@@ -61631,15 +62060,39 @@ var ClaudeHarnessSession = class {
61631
62060
  }
61632
62061
  }
61633
62062
  #configuredState(nativeReady = this.#state.nativeRef !== void 0) {
61634
- const effectiveModel = this.#requestedModel ?? (this.#openMode === "create" ? CLAUDE_DEFAULT_MODEL_REF : this.#state.effectiveModel);
62063
+ const effectiveModel = this.#effectiveModelRef();
62064
+ const supported = this.#supportedThinkingOptionIds(effectiveModel);
61635
62065
  return {
61636
62066
  ...nativeReady ? { nativeRef: this.#nativeRef } : {},
61637
62067
  ...effectiveModel ? { effectiveModel } : {},
61638
62068
  effectiveThinkingOptionId: this.#requestedThinkingOptionId,
61639
- availableThinkingOptions: [...CLAUDE_THINKING_OPTIONS],
62069
+ // A live Claude Code keeps running a choice made before the catalog arrived; it stays
62070
+ // listed until the next Model switch fits it.
62071
+ availableThinkingOptions: CLAUDE_THINKING_OPTIONS.filter(({ id: id2 }) => !supported || supported.includes(id2) || id2 === this.#requestedThinkingOptionId),
61640
62072
  effectivePermissionModeId: this.#requestedPermissionModeId
61641
62073
  };
61642
62074
  }
62075
+ #effectiveModelRef() {
62076
+ return this.#requestedModel ?? (this.#openMode === "create" ? CLAUDE_DEFAULT_MODEL_REF : this.#state.effectiveModel);
62077
+ }
62078
+ #supportedThinkingOptionIds(model2) {
62079
+ return catalogModelForRef(this.#modelCatalog(), model2)?.supportedThinkingOptionIds;
62080
+ }
62081
+ /**
62082
+ * Fits the requested Thinking to a catalog inspected after this Session opened, so the choice
62083
+ * Claude Code starts with is the one shown. A live Claude Code already runs the earlier choice.
62084
+ */
62085
+ refitThinking(cwd) {
62086
+ if (this.#phase !== "open" || cwd !== this.#cwd || this.#transport)
62087
+ return;
62088
+ this.#requestedThinkingOptionId = fitClaudeThinkingOptionId(this.#requestedThinkingOptionId, this.#supportedThinkingOptionIds(this.#effectiveModelRef()));
62089
+ if (this.#state.effectiveThinkingOptionId === void 0)
62090
+ return;
62091
+ const state = this.#configuredState();
62092
+ if (state.effectiveThinkingOptionId !== this.#state.effectiveThinkingOptionId || !isDeepStrictEqual2(state.availableThinkingOptions, this.#state.availableThinkingOptions)) {
62093
+ this.#publishState(state);
62094
+ }
62095
+ }
61643
62096
  #publishState(state = this.#state) {
61644
62097
  this.#state = state;
61645
62098
  this.#statePublished = true;
@@ -61664,6 +62117,8 @@ var ClaudeHarnessSession = class {
61664
62117
  return;
61665
62118
  switch (event.type) {
61666
62119
  case "segment.started":
62120
+ if (event.mcpServers)
62121
+ this.#mcpServers = event.mcpServers;
61667
62122
  this.#observeRootOutput(active);
61668
62123
  if (active.cancellation && !active.cancellation.interrupting) {
61669
62124
  this.#interruptCancelledSegment(active).catch(() => this.#hardCancel(active));
@@ -62110,6 +62565,7 @@ var ClaudeHarnessSession = class {
62110
62565
  cwd: this.#cwd,
62111
62566
  outputLimit: this.#toolOutputLimit,
62112
62567
  taskTracker: this.#taskTracker,
62568
+ mcpServers: () => this.#mcpServers,
62113
62569
  nativeTurnKey,
62114
62570
  newItemId: () => hostItemIdSchema.parse(this.#randomUUID()),
62115
62571
  emit: (event) => this.#event(event),
@@ -62606,11 +63062,12 @@ var ClaudeHarnessSession = class {
62606
63062
  checkpointId: active.checkpointId,
62607
63063
  formatVersion: 1
62608
63064
  }) : null;
62609
- if (active.userMessageId || active.checkpointId) {
63065
+ const trackUserMessageId = active.userMessageId !== null && !SYNTHETIC_AUTONOMOUS_TURN_KEY_PATTERN.test(active.userMessageId) && (outcome.status !== "cancelled" || active.checkpointId !== null);
63066
+ if (trackUserMessageId || active.checkpointId) {
62610
63067
  this.#unpersistedMessageIds = [
62611
63068
  .../* @__PURE__ */ new Set([
62612
63069
  ...this.#unpersistedMessageIds,
62613
- ...active.userMessageId ? [active.userMessageId] : [],
63070
+ ...trackUserMessageId && active.userMessageId ? [active.userMessageId] : [],
62614
63071
  ...active.checkpointId ? [active.checkpointId] : []
62615
63072
  ])
62616
63073
  ];
@@ -62869,8 +63326,11 @@ var ClaudeCodeAdapter = class {
62869
63326
  if (current)
62870
63327
  return current;
62871
63328
  const inspection = this.#inspectModels(cwd).then((result) => {
62872
- if (result.status === "ready")
63329
+ if (result.status === "ready") {
62873
63330
  this.#inspectionCache.set(cwd, result);
63331
+ for (const session of this.#sessions)
63332
+ session.refitThinking(cwd);
63333
+ }
62874
63334
  return result;
62875
63335
  });
62876
63336
  this.#inspectionInFlight.set(cwd, inspection);
@@ -63154,6 +63614,10 @@ var ClaudeCodeAdapter = class {
63154
63614
  longContextEnabled: () => readClaudeLongContext(this.#environment),
63155
63615
  requestedPermissionModeId,
63156
63616
  requestedThinkingOptionId,
63617
+ modelCatalog: () => {
63618
+ const inspection = this.#inspectionCache.get(cwd);
63619
+ return inspection?.status === "ready" ? inspection.catalog : void 0;
63620
+ },
63157
63621
  toolOutputLimit: this.#toolOutputLimit,
63158
63622
  cancelTimeoutMs: this.#cancelTimeoutMs,
63159
63623
  continuationQuiescenceMs: this.#continuationQuiescenceMs
@@ -63231,11 +63695,11 @@ var ClaudeCodeAdapter = class {
63231
63695
  };
63232
63696
 
63233
63697
  // dist/installation.js
63234
- import { readFile as readFile10, realpath as realpath5 } from "node:fs/promises";
63698
+ import { readFile as readFile9, realpath as realpath5 } from "node:fs/promises";
63235
63699
  import { homedir as homedir2 } from "node:os";
63236
63700
  import path18 from "node:path";
63237
63701
  async function readSettings(file2) {
63238
- const text2 = await readFile10(file2, "utf8").catch((error52) => {
63702
+ const text2 = await readFile9(file2, "utf8").catch((error52) => {
63239
63703
  if (error52.code === "ENOENT")
63240
63704
  return "{}";
63241
63705
  throw error52;