@liberseek/boft-cli-linux-x64 0.8.4 → 0.8.6

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 (39) hide show
  1. package/README.md +2 -2
  2. package/THIRD_PARTY_NOTICES.txt +6 -2
  3. package/app/codexhost-distribution.json +1 -1
  4. package/app/console-server.mjs +129 -28
  5. package/app/console-web.js +336 -78
  6. package/app/desktop-controller.mjs +1741 -60
  7. package/app/host-runtime.mjs +4983 -2002
  8. package/app/plugins/antigravity/plugin.mjs +423 -63
  9. package/app/plugins/claude-code/plugin.mjs +417 -264
  10. package/app/plugins/codebuddy/plugin.mjs +256 -134
  11. package/app/plugins/codex-usage/plugin.mjs +97 -32
  12. package/app/plugins/copilot/plugin.mjs +122 -57
  13. package/app/plugins/cursor-cli/plugin.mjs +236 -139
  14. package/app/plugins/deepseek-harness/plugin.mjs +584 -86
  15. package/app/plugins/devin/assets/icon.svg +1 -0
  16. package/app/plugins/devin/manifest.json +30 -0
  17. package/app/plugins/devin/plugin.mjs +23425 -0
  18. package/app/plugins/enabled.json +2 -0
  19. package/app/plugins/grok/plugin.mjs +839 -500
  20. package/app/plugins/hermes/plugin.mjs +522 -200
  21. package/app/plugins/kimi-code/plugin.mjs +134 -22
  22. package/app/plugins/kiro-cli/plugin.mjs +84 -19
  23. package/app/plugins/muse/plugin.mjs +74 -9
  24. package/app/plugins/omp/plugin.mjs +104 -39
  25. package/app/plugins/opencode/plugin.mjs +126 -61
  26. package/app/plugins/pi/plugin.mjs +1769 -468
  27. package/app/plugins/qoder/plugin.mjs +9617 -8682
  28. package/app/plugins/qoder-cn/plugin.mjs +9617 -8682
  29. package/app/plugins/qwen-code/assets/icon.svg +1 -0
  30. package/app/plugins/qwen-code/manifest.json +29 -0
  31. package/app/plugins/qwen-code/plugin.mjs +29366 -0
  32. package/app/plugins/workbuddy/plugin.mjs +256 -134
  33. package/app/plugins/zcode/plugin.mjs +265 -42
  34. package/app/renderer-extension.js +3286 -528
  35. package/bin/boft +0 -0
  36. package/libexec/boft-shim +0 -0
  37. package/libexec/boft-updater +0 -0
  38. package/licenses/Qwen-Code-SDK-LICENSE.txt +203 -0
  39. package/package.json +2 -2
@@ -777,10 +777,10 @@ function mergeDefs(...defs) {
777
777
  function cloneDef(schema) {
778
778
  return mergeDefs(schema._zod.def);
779
779
  }
780
- function getElementAtPath(obj, path21) {
781
- if (!path21)
780
+ function getElementAtPath(obj, path20) {
781
+ if (!path20)
782
782
  return obj;
783
- return path21.reduce((acc, key) => acc?.[key], obj);
783
+ return path20.reduce((acc, key) => acc?.[key], obj);
784
784
  }
785
785
  function promiseAllObject(promisesObj) {
786
786
  const keys = Object.keys(promisesObj);
@@ -1189,11 +1189,11 @@ function explicitlyAborted(x, startIndex = 0) {
1189
1189
  }
1190
1190
  return false;
1191
1191
  }
1192
- function prefixIssues(path21, issues) {
1192
+ function prefixIssues(path20, issues) {
1193
1193
  return issues.map((iss) => {
1194
1194
  var _a4;
1195
1195
  (_a4 = iss).path ?? (_a4.path = []);
1196
- iss.path.unshift(path21);
1196
+ iss.path.unshift(path20);
1197
1197
  return iss;
1198
1198
  });
1199
1199
  }
@@ -1340,16 +1340,16 @@ function flattenError(error52, mapper = (issue2) => issue2.message) {
1340
1340
  }
1341
1341
  function formatError(error52, mapper = (issue2) => issue2.message) {
1342
1342
  const fieldErrors = { _errors: [] };
1343
- const processError = (error53, path21 = []) => {
1343
+ const processError = (error53, path20 = []) => {
1344
1344
  for (const issue2 of error53.issues) {
1345
1345
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1346
- issue2.errors.map((issues) => processError({ issues }, [...path21, ...issue2.path]));
1346
+ issue2.errors.map((issues) => processError({ issues }, [...path20, ...issue2.path]));
1347
1347
  } else if (issue2.code === "invalid_key") {
1348
- processError({ issues: issue2.issues }, [...path21, ...issue2.path]);
1348
+ processError({ issues: issue2.issues }, [...path20, ...issue2.path]);
1349
1349
  } else if (issue2.code === "invalid_element") {
1350
- processError({ issues: issue2.issues }, [...path21, ...issue2.path]);
1350
+ processError({ issues: issue2.issues }, [...path20, ...issue2.path]);
1351
1351
  } else {
1352
- const fullpath = [...path21, ...issue2.path];
1352
+ const fullpath = [...path20, ...issue2.path];
1353
1353
  if (fullpath.length === 0) {
1354
1354
  fieldErrors._errors.push(mapper(issue2));
1355
1355
  } else {
@@ -1376,17 +1376,17 @@ function formatError(error52, mapper = (issue2) => issue2.message) {
1376
1376
  }
1377
1377
  function treeifyError(error52, mapper = (issue2) => issue2.message) {
1378
1378
  const result = { errors: [] };
1379
- const processError = (error53, path21 = []) => {
1379
+ const processError = (error53, path20 = []) => {
1380
1380
  var _a4, _b2;
1381
1381
  for (const issue2 of error53.issues) {
1382
1382
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1383
- issue2.errors.map((issues) => processError({ issues }, [...path21, ...issue2.path]));
1383
+ issue2.errors.map((issues) => processError({ issues }, [...path20, ...issue2.path]));
1384
1384
  } else if (issue2.code === "invalid_key") {
1385
- processError({ issues: issue2.issues }, [...path21, ...issue2.path]);
1385
+ processError({ issues: issue2.issues }, [...path20, ...issue2.path]);
1386
1386
  } else if (issue2.code === "invalid_element") {
1387
- processError({ issues: issue2.issues }, [...path21, ...issue2.path]);
1387
+ processError({ issues: issue2.issues }, [...path20, ...issue2.path]);
1388
1388
  } else {
1389
- const fullpath = [...path21, ...issue2.path];
1389
+ const fullpath = [...path20, ...issue2.path];
1390
1390
  if (fullpath.length === 0) {
1391
1391
  result.errors.push(mapper(issue2));
1392
1392
  continue;
@@ -1418,8 +1418,8 @@ function treeifyError(error52, mapper = (issue2) => issue2.message) {
1418
1418
  }
1419
1419
  function toDotPath(_path) {
1420
1420
  const segs = [];
1421
- const path21 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1422
- for (const seg of path21) {
1421
+ const path20 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1422
+ for (const seg of path20) {
1423
1423
  if (typeof seg === "number")
1424
1424
  segs.push(`[${seg}]`);
1425
1425
  else if (typeof seg === "symbol")
@@ -3040,10 +3040,10 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
3040
3040
  const shape = def.shape;
3041
3041
  const propValues = {};
3042
3042
  for (const key in shape) {
3043
- const field = shape[key]._zod;
3044
- if (field.values) {
3043
+ const field2 = shape[key]._zod;
3044
+ if (field2.values) {
3045
3045
  propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
3046
- for (const v of field.values)
3046
+ for (const v of field2.values)
3047
3047
  propValues[key].add(v);
3048
3048
  }
3049
3049
  }
@@ -14111,13 +14111,13 @@ function resolveRef(ref, ctx) {
14111
14111
  if (!ref.startsWith("#")) {
14112
14112
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
14113
14113
  }
14114
- const path21 = ref.slice(1).split("/").filter(Boolean);
14115
- if (path21.length === 0) {
14114
+ const path20 = ref.slice(1).split("/").filter(Boolean);
14115
+ if (path20.length === 0) {
14116
14116
  return ctx.rootSchema;
14117
14117
  }
14118
14118
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
14119
- if (path21[0] === defsKey) {
14120
- const key = path21[1];
14119
+ if (path20[0] === defsKey) {
14120
+ const key = path20[1];
14121
14121
  if (!key || !ctx.defs[key]) {
14122
14122
  throw new Error(`Reference not found: ${ref}`);
14123
14123
  }
@@ -14683,6 +14683,8 @@ var usageStatisticsTotalsSchema = external_exports.strictObject({
14683
14683
  cachedInputTokens: count,
14684
14684
  cacheWriteInputTokens: count,
14685
14685
  cacheKnownInputTokens: count,
14686
+ cacheHitCachedInputTokens: count,
14687
+ cacheHitInputTokens: count,
14686
14688
  outputTokens: count,
14687
14689
  reasoningOutputTokens: count,
14688
14690
  /** USD at the public price, summed over the priced requests only. */
@@ -14790,6 +14792,51 @@ var hostInteractionIdSchema = opaqueIdSchema.brand();
14790
14792
  var threadPrewarmDiscardParamsSchema = external_exports.object({ threadId: hostThreadIdSchema });
14791
14793
  var threadPrewarmDiscardResultSchema = external_exports.object({ discarded: external_exports.boolean() });
14792
14794
 
14795
+ // ../../shared-contracts/dist/thread-questions.js
14796
+ var field = external_exports.discriminatedUnion("type", [
14797
+ external_exports.object({
14798
+ id: external_exports.string().min(1),
14799
+ type: external_exports.literal("choice"),
14800
+ prompt: external_exports.string(),
14801
+ options: external_exports.array(external_exports.object({
14802
+ value: external_exports.string().min(1),
14803
+ label: external_exports.string(),
14804
+ description: external_exports.string().optional()
14805
+ })).min(1),
14806
+ multiple: external_exports.boolean(),
14807
+ allowOther: external_exports.boolean(),
14808
+ optional: external_exports.boolean()
14809
+ }),
14810
+ external_exports.object({
14811
+ id: external_exports.string().min(1),
14812
+ type: external_exports.literal("text"),
14813
+ prompt: external_exports.string(),
14814
+ multiline: external_exports.boolean(),
14815
+ secret: external_exports.literal(false),
14816
+ optional: external_exports.boolean(),
14817
+ placeholder: external_exports.string().optional(),
14818
+ prefill: external_exports.string().optional()
14819
+ })
14820
+ ]);
14821
+ var threadQuestionSchema = external_exports.object({
14822
+ interactionId: external_exports.string().min(1),
14823
+ turnId: external_exports.string().min(1),
14824
+ title: external_exports.string().optional(),
14825
+ questions: external_exports.array(field).min(1)
14826
+ }).refine(({ questions }) => questions.some((q) => q.type === "choice" && q.multiple), {
14827
+ message: "Shared cards require at least one multi-select question"
14828
+ });
14829
+ var threadQuestionsListParamsSchema = external_exports.strictObject({ threadId: external_exports.string().min(1) });
14830
+ var threadQuestionsResultSchema = external_exports.object({ questions: external_exports.array(threadQuestionSchema) });
14831
+ var threadQuestionRespondParamsSchema = external_exports.strictObject({
14832
+ threadId: external_exports.string().min(1),
14833
+ turnId: external_exports.string().min(1),
14834
+ interactionId: external_exports.string().min(1),
14835
+ answers: external_exports.record(external_exports.string(), external_exports.array(external_exports.string())),
14836
+ cancelled: external_exports.boolean().default(false)
14837
+ });
14838
+ var threadQuestionRespondResultSchema = external_exports.object({ accepted: external_exports.literal(true) });
14839
+
14793
14840
  // ../../shared-contracts/dist/harness-plugins.js
14794
14841
  var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
14795
14842
  var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
@@ -15549,6 +15596,21 @@ var threadSteeringInspectParamsSchema = external_exports.object({
15549
15596
  /** The text about to be steered; a Harness command always stops and restarts. */
15550
15597
  text: external_exports.string().optional()
15551
15598
  }).strict();
15599
+ var threadSteeringContextSchema = external_exports.object({
15600
+ kind: external_exports.literal("application"),
15601
+ value: external_exports.string().transform((text2, context) => {
15602
+ try {
15603
+ return JSON.parse(text2);
15604
+ } catch {
15605
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
15606
+ return external_exports.NEVER;
15607
+ }
15608
+ }).pipe(external_exports.object({
15609
+ expectedTurnId: hostTurnIdSchema,
15610
+ clientUserMessageId: external_exports.string().min(1),
15611
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
15612
+ }).strict())
15613
+ }).strict().transform((context) => context.value);
15552
15614
  var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
15553
15615
  var threadSteeringInspectResultSchema = external_exports.object({
15554
15616
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
@@ -15559,7 +15621,10 @@ var harnessPluginRouteSchema = external_exports.object({
15559
15621
  harnessId: harnessPluginIdSchema,
15560
15622
  model: harnessModelRefSchema.optional(),
15561
15623
  thinkingOptionId: harnessThinkingOptionIdSchema.optional(),
15562
- permissionModeId: harnessPermissionModeIdSchema.optional()
15624
+ permissionModeId: harnessPermissionModeIdSchema.optional(),
15625
+ /** A draft prewarm create: stays unsubmitted until the user's first Turn.
15626
+ * Desktop forwards only the Model of a main-process prewarm to thread/start. */
15627
+ prewarm: external_exports.literal(true).optional()
15563
15628
  }).strict();
15564
15629
 
15565
15630
  // ../../shared-contracts/dist/harness-launch-settings.js
@@ -16158,26 +16223,26 @@ function parseHostUsage(value) {
16158
16223
  }
16159
16224
  }
16160
16225
  const indicators = value.composerIndicators === void 0 ? {} : { composerIndicators: composerIndicatorsSchema.parse(value.composerIndicators) };
16161
- for (const field of [
16226
+ for (const field2 of [
16162
16227
  "totalCredits",
16163
16228
  "contextUsagePercent",
16164
16229
  "apiOutputTokensPerSecond"
16165
16230
  ]) {
16166
- const candidate = value[field];
16231
+ const candidate = value[field2];
16167
16232
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
16168
- throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
16233
+ throw new Error(`Harness Usage '${field2}' must be a finite non-negative number`);
16169
16234
  }
16170
16235
  }
16171
- for (const field of tokenFields) {
16172
- const candidate = value[field];
16236
+ for (const field2 of tokenFields) {
16237
+ const candidate = value[field2];
16173
16238
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
16174
- throw new Error(`Harness Usage '${field}' must be a non-negative safe integer`);
16239
+ throw new Error(`Harness Usage '${field2}' must be a non-negative safe integer`);
16175
16240
  }
16176
16241
  }
16177
- for (const field of safeIntegerFields) {
16178
- const candidate = value[field];
16242
+ for (const field2 of safeIntegerFields) {
16243
+ const candidate = value[field2];
16179
16244
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
16180
- throw new Error(`Harness Usage '${field}' must be a non-negative safe integer`);
16245
+ throw new Error(`Harness Usage '${field2}' must be a non-negative safe integer`);
16181
16246
  }
16182
16247
  }
16183
16248
  if (value.outputTokensPerSecond !== void 0 && (typeof value.outputTokensPerSecond !== "number" || !Number.isFinite(value.outputTokensPerSecond) || value.outputTokensPerSecond < 0)) {
@@ -16186,16 +16251,16 @@ function parseHostUsage(value) {
16186
16251
  if (value.totalCostUsd !== void 0 && (typeof value.totalCostUsd !== "number" || !Number.isFinite(value.totalCostUsd) || value.totalCostUsd < 0)) {
16187
16252
  throw new Error("Harness Usage 'totalCostUsd' must be a finite non-negative number");
16188
16253
  }
16189
- for (const field of ["totalCredits", "contextUsagePercent"]) {
16190
- const candidate = value[field];
16254
+ for (const field2 of ["totalCredits", "contextUsagePercent"]) {
16255
+ const candidate = value[field2];
16191
16256
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
16192
- throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
16257
+ throw new Error(`Harness Usage '${field2}' must be a finite non-negative number`);
16193
16258
  }
16194
16259
  }
16195
- for (const field of percentFields) {
16196
- const candidate = value[field];
16260
+ for (const field2 of percentFields) {
16261
+ const candidate = value[field2];
16197
16262
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0 || candidate > 100)) {
16198
- throw new Error(`Harness Usage '${field}' must be between 0 and 100`);
16263
+ throw new Error(`Harness Usage '${field2}' must be between 0 and 100`);
16199
16264
  }
16200
16265
  }
16201
16266
  if (value.sessionCacheUsage !== void 0) {
@@ -16266,19 +16331,19 @@ function parseHostUsageRequest(value) {
16266
16331
  if (typeof value.requestId !== "string" || value.requestId.length === 0) {
16267
16332
  throw new Error("Harness Usage request 'requestId' must be a non-empty string");
16268
16333
  }
16269
- for (const field of ["model", "provider"]) {
16270
- const candidate = value[field];
16334
+ for (const field2 of ["model", "provider"]) {
16335
+ const candidate = value[field2];
16271
16336
  if (candidate !== void 0 && (typeof candidate !== "string" || candidate.length === 0)) {
16272
- throw new Error(`Harness Usage request '${field}' must be a non-empty string`);
16337
+ throw new Error(`Harness Usage request '${field2}' must be a non-empty string`);
16273
16338
  }
16274
16339
  }
16275
16340
  if (value.historical !== void 0 && typeof value.historical !== "boolean") {
16276
16341
  throw new Error("Harness Usage request 'historical' must be a boolean");
16277
16342
  }
16278
- for (const field of requestTokenFields) {
16279
- const candidate = value[field];
16343
+ for (const field2 of requestTokenFields) {
16344
+ const candidate = value[field2];
16280
16345
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
16281
- throw new Error(`Harness Usage request '${field}' must be a non-negative safe integer`);
16346
+ throw new Error(`Harness Usage request '${field2}' must be a non-negative safe integer`);
16282
16347
  }
16283
16348
  }
16284
16349
  if (value.inputTokens === void 0 || value.outputTokens === void 0) {
@@ -16538,30 +16603,6 @@ function consumeBrokerFrames(socket, onFrame, onError) {
16538
16603
  });
16539
16604
  }
16540
16605
 
16541
- // ../../harness-broker/dist/paths.js
16542
- import os from "node:os";
16543
- import path from "node:path";
16544
- var HARNESS_BROKER_DESCRIPTOR_ENV = "CODEXHOST_CLAUDE_BROKER_DESCRIPTOR";
16545
- var HARNESS_BROKER_DESCRIPTOR_FILE = "claude-code-broker-v1.json";
16546
- function defaultHarnessBrokerDirectory(environment = process.env) {
16547
- const home = environment.HOME || os.homedir();
16548
- return path.join(home, ".codexhost", "harness-broker");
16549
- }
16550
- function defaultHarnessBrokerDescriptorPath(environment = process.env, harnessId = "claude-code") {
16551
- harnessPluginIdSchema.parse(harnessId);
16552
- if (harnessId !== "claude-code")
16553
- return path.join(defaultHarnessBrokerDirectory(environment), `${harnessId}-broker-v1.json`);
16554
- return environment[HARNESS_BROKER_DESCRIPTOR_ENV] ?? path.join(defaultHarnessBrokerDirectory(environment), HARNESS_BROKER_DESCRIPTOR_FILE);
16555
- }
16556
- function harnessBrokerLaunchAgentLabel(harnessId = "claude-code") {
16557
- harnessPluginIdSchema.parse(harnessId);
16558
- return harnessId === "claude-code" ? "ai.bytepioneer.codexhost.native-harness-broker" : `ai.bytepioneer.codexhost.${harnessId}-broker`;
16559
- }
16560
- function harnessBrokerLaunchAgentPlistPath(environment = process.env, harnessId = "claude-code") {
16561
- const home = environment.HOME || os.homedir();
16562
- return path.join(home, "Library", "LaunchAgents", `${harnessBrokerLaunchAgentLabel(harnessId)}.plist`);
16563
- }
16564
-
16565
16606
  // ../../harness-broker/dist/validation.js
16566
16607
  var cwdSchema = external_exports.string().min(1).max(16384);
16567
16608
  var brokerEnvironmentSchema = external_exports.object({
@@ -16612,7 +16653,11 @@ var brokerOpenInputSchema = external_exports.discriminatedUnion("kind", [
16612
16653
  forkSchema,
16613
16654
  rollbackSchema
16614
16655
  ]);
16615
- var brokerInspectInputSchema = external_exports.object({ cwd: cwdSchema.optional(), refresh: external_exports.boolean().optional() }).strict();
16656
+ var brokerInspectInputSchema = external_exports.object({
16657
+ cwd: cwdSchema.optional(),
16658
+ refresh: external_exports.boolean().optional(),
16659
+ purpose: external_exports.literal("availability").optional()
16660
+ }).strict();
16616
16661
  var brokerSessionImportListParamsSchema = external_exports.object({
16617
16662
  offset: external_exports.number().int().nonnegative().safe(),
16618
16663
  limit: external_exports.number().int().min(1).max(HARNESS_BROKER_SESSION_IMPORT_PAGE_SIZE)
@@ -16627,10 +16672,10 @@ var brokerSessionImportSourceSchema = external_exports.object({
16627
16672
  candidate: harnessSessionImportCandidateSchema,
16628
16673
  nativeRef: nativeSessionRefSchema
16629
16674
  }).strict().superRefine((source, context) => {
16630
- if (source.nativeRef.harnessId !== "claude-code" || source.nativeRef.nativeSessionId !== source.candidate.nativeSessionId) {
16675
+ if (source.nativeRef.nativeSessionId !== source.candidate.nativeSessionId) {
16631
16676
  context.addIssue({
16632
16677
  code: "custom",
16633
- message: "Claude Session import source identity does not match"
16678
+ message: "Session import source identity does not match"
16634
16679
  });
16635
16680
  }
16636
16681
  });
@@ -16804,6 +16849,107 @@ var harnessOutputSchema = external_exports.custom((value) => {
16804
16849
  return false;
16805
16850
  });
16806
16851
 
16852
+ // ../../harness-broker/dist/session-import-client.js
16853
+ function createBrokerSessionImportCapability(input) {
16854
+ let listing = null;
16855
+ const closed = () => ({
16856
+ ok: false,
16857
+ error: { code: "invalidState", message: "Harness broker adapter is closed", retryable: false }
16858
+ });
16859
+ const invalid = () => ({
16860
+ ok: false,
16861
+ error: {
16862
+ code: "protocolError",
16863
+ message: "Harness broker returned invalid Session import metadata",
16864
+ retryable: false
16865
+ }
16866
+ });
16867
+ const list = async () => {
16868
+ try {
16869
+ const candidates = [];
16870
+ const identities = /* @__PURE__ */ new Set();
16871
+ let total;
16872
+ for (; ; ) {
16873
+ if (input.isClosed())
16874
+ return closed();
16875
+ const result = await input.request("adapter.sessionImport.list", {
16876
+ offset: candidates.length,
16877
+ limit: HARNESS_BROKER_SESSION_IMPORT_PAGE_SIZE
16878
+ });
16879
+ if (input.isClosed())
16880
+ return closed();
16881
+ if (!result.ok)
16882
+ return result;
16883
+ const page = brokerSessionImportPageSchema.safeParse(result.value);
16884
+ if (!page.success || total !== void 0 && total !== page.data.total || page.data.total < candidates.length + page.data.candidates.length || page.data.candidates.length === 0 && candidates.length < page.data.total)
16885
+ return invalid();
16886
+ total = page.data.total;
16887
+ for (const candidate of page.data.candidates) {
16888
+ if (identities.has(candidate.nativeSessionId))
16889
+ return invalid();
16890
+ identities.add(candidate.nativeSessionId);
16891
+ candidates.push(candidate);
16892
+ }
16893
+ if (candidates.length === total)
16894
+ return { ok: true, value: candidates };
16895
+ }
16896
+ } catch (error52) {
16897
+ return { ok: false, error: input.error(error52) };
16898
+ }
16899
+ };
16900
+ return {
16901
+ listCandidates() {
16902
+ if (input.isClosed())
16903
+ return Promise.resolve(closed());
16904
+ listing ??= list().finally(() => {
16905
+ listing = null;
16906
+ });
16907
+ return listing;
16908
+ },
16909
+ async resolveCandidate(nativeSessionId) {
16910
+ if (input.isClosed())
16911
+ return closed();
16912
+ try {
16913
+ const result = await input.request("adapter.sessionImport.resolve", { nativeSessionId });
16914
+ if (input.isClosed())
16915
+ return closed();
16916
+ if (!result.ok)
16917
+ return result;
16918
+ const source = brokerSessionImportSourceSchema.safeParse(result.value);
16919
+ if (!source.success || source.data.nativeRef.harnessId !== input.harnessId || source.data.candidate.nativeSessionId !== nativeSessionId)
16920
+ return invalid();
16921
+ return { ok: true, value: source.data };
16922
+ } catch (error52) {
16923
+ return { ok: false, error: input.error(error52) };
16924
+ }
16925
+ }
16926
+ };
16927
+ }
16928
+
16929
+ // ../../harness-broker/dist/paths.js
16930
+ import os from "node:os";
16931
+ import path from "node:path";
16932
+ var HARNESS_BROKER_DESCRIPTOR_ENV = "CODEXHOST_CLAUDE_BROKER_DESCRIPTOR";
16933
+ var HARNESS_BROKER_DESCRIPTOR_FILE = "claude-code-broker-v1.json";
16934
+ function defaultHarnessBrokerDirectory(environment = process.env) {
16935
+ const home = environment.HOME || os.homedir();
16936
+ return path.join(home, ".codexhost", "harness-broker");
16937
+ }
16938
+ function defaultHarnessBrokerDescriptorPath(environment = process.env, harnessId = "claude-code") {
16939
+ harnessPluginIdSchema.parse(harnessId);
16940
+ if (harnessId !== "claude-code")
16941
+ return path.join(defaultHarnessBrokerDirectory(environment), `${harnessId}-broker-v1.json`);
16942
+ return environment[HARNESS_BROKER_DESCRIPTOR_ENV] ?? path.join(defaultHarnessBrokerDirectory(environment), HARNESS_BROKER_DESCRIPTOR_FILE);
16943
+ }
16944
+ function harnessBrokerLaunchAgentLabel(harnessId = "claude-code") {
16945
+ harnessPluginIdSchema.parse(harnessId);
16946
+ return harnessId === "claude-code" ? "ai.bytepioneer.codexhost.native-harness-broker" : `ai.bytepioneer.codexhost.${harnessId}-broker`;
16947
+ }
16948
+ function harnessBrokerLaunchAgentPlistPath(environment = process.env, harnessId = "claude-code") {
16949
+ const home = environment.HOME || os.homedir();
16950
+ return path.join(home, "Library", "LaunchAgents", `${harnessBrokerLaunchAgentLabel(harnessId)}.plist`);
16951
+ }
16952
+
16807
16953
  // ../../harness-broker/dist/client.js
16808
16954
  function unavailable(message, retryable = true) {
16809
16955
  return { code: "unavailable", message, retryable, stage: "harnessBroker" };
@@ -17340,6 +17486,7 @@ var BrokeredHarnessAdapter = class {
17340
17486
  commandCatalog;
17341
17487
  liveCommandCatalog;
17342
17488
  harnessId;
17489
+ sessionImport;
17343
17490
  credits;
17344
17491
  refreshCredits;
17345
17492
  #descriptorPath;
@@ -17349,7 +17496,6 @@ var BrokeredHarnessAdapter = class {
17349
17496
  #startTimeoutMs;
17350
17497
  #connection = null;
17351
17498
  #closed = false;
17352
- #sessionImportListing = null;
17353
17499
  #credits = null;
17354
17500
  #creditsRefresh = null;
17355
17501
  subagents = {
@@ -17361,86 +17507,16 @@ var BrokeredHarnessAdapter = class {
17361
17507
  }
17362
17508
  }
17363
17509
  };
17364
- sessionImport = Object.freeze({
17365
- listCandidates: () => {
17366
- this.#sessionImportListing ??= this.#listSessionImportCandidates().finally(() => {
17367
- this.#sessionImportListing = null;
17368
- });
17369
- return this.#sessionImportListing;
17370
- },
17371
- resolveCandidate: async (nativeSessionId) => {
17372
- if (this.#closed) {
17373
- return {
17374
- ok: false,
17375
- error: unavailable("Claude Aqua broker adapter is closed", false)
17376
- };
17377
- }
17378
- try {
17379
- const result = parseHarnessResult(await (await this.#connect()).request("adapter.sessionImport.resolve", {
17380
- nativeSessionId
17381
- }));
17382
- if (!result.ok)
17383
- return result;
17384
- const parsed = brokerSessionImportSourceSchema.safeParse(result.value);
17385
- if (!parsed.success || parsed.data.candidate.nativeSessionId !== nativeSessionId) {
17386
- return {
17387
- ok: false,
17388
- error: {
17389
- ...unavailable("Harness broker returned an invalid Session source", false),
17390
- code: "protocolError"
17391
- }
17392
- };
17393
- }
17394
- return { ok: true, value: parsed.data };
17395
- } catch (error52) {
17396
- this.#connection = null;
17397
- return {
17398
- ok: false,
17399
- error: unavailable(error52 instanceof Error ? error52.message : String(error52))
17400
- };
17401
- }
17402
- }
17403
- });
17404
- async #listSessionImportCandidates() {
17405
- if (this.#closed) {
17406
- return {
17407
- ok: false,
17408
- error: unavailable("Claude Aqua broker adapter is closed", false)
17409
- };
17410
- }
17411
- try {
17412
- const candidates = [];
17413
- for (; ; ) {
17414
- const result = parseHarnessResult(await (await this.#connect()).request("adapter.sessionImport.list", {
17415
- offset: candidates.length,
17416
- limit: HARNESS_BROKER_SESSION_IMPORT_PAGE_SIZE
17417
- }));
17418
- if (!result.ok)
17419
- return result;
17420
- const parsed = brokerSessionImportPageSchema.safeParse(result.value);
17421
- if (!parsed.success || parsed.data.total < candidates.length + parsed.data.candidates.length || parsed.data.candidates.length === 0 && candidates.length < parsed.data.total) {
17422
- return {
17423
- ok: false,
17424
- error: {
17425
- ...unavailable("Harness broker returned invalid Session candidates", false),
17426
- code: "protocolError"
17427
- }
17428
- };
17429
- }
17430
- candidates.push(...parsed.data.candidates);
17431
- if (candidates.length === parsed.data.total)
17432
- return { ok: true, value: candidates };
17433
- }
17434
- } catch (error52) {
17435
- this.#connection = null;
17436
- return {
17437
- ok: false,
17438
- error: unavailable(error52 instanceof Error ? error52.message : String(error52))
17439
- };
17440
- }
17441
- }
17442
17510
  constructor(input = {}) {
17443
17511
  this.harnessId = harnessPluginIdSchema.parse(input.harnessId ?? "claude-code");
17512
+ if (input.sessionImport) {
17513
+ this.sessionImport = createBrokerSessionImportCapability({
17514
+ harnessId: this.harnessId,
17515
+ request: async (method, params) => parseHarnessResult(await this.#request(method, params, method === "adapter.sessionImport.resolve")),
17516
+ isClosed: () => this.#closed,
17517
+ error: (error52) => this.#error(error52)
17518
+ });
17519
+ }
17444
17520
  if (input.accountCredits !== false) {
17445
17521
  this.credits = () => this.#credits;
17446
17522
  this.refreshCredits = () => this.#refreshAccountCredits();
@@ -17904,7 +17980,7 @@ function claudePromptCacheIndicators(accountCreditsSupported, lastResponseAtUnix
17904
17980
 
17905
17981
  // dist/claude-code-adapter.js
17906
17982
  import { randomUUID as randomUUID6 } from "node:crypto";
17907
- import path18 from "node:path";
17983
+ import path17 from "node:path";
17908
17984
 
17909
17985
  // ../../../node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs
17910
17986
  import { createRequire as jre } from "node:module";
@@ -54664,7 +54740,6 @@ var ClaudePendingSessions = class {
54664
54740
  };
54665
54741
 
54666
54742
  // dist/claude-fork.js
54667
- import path11 from "node:path";
54668
54743
  import { isDeepStrictEqual } from "node:util";
54669
54744
 
54670
54745
  // dist/file-change.js
@@ -54806,6 +54881,17 @@ function targetedSubagentId(argumentsValue) {
54806
54881
  return void 0;
54807
54882
  return boundedString(argumentsValue.to ?? argumentsValue.recipient ?? argumentsValue.agentId, SUBAGENT_DESCRIPTION_LIMIT);
54808
54883
  }
54884
+ function claudeSendMessageFailed(nativeResult, outputText) {
54885
+ if (isRecord6(nativeResult) && typeof nativeResult.success === "boolean") {
54886
+ return nativeResult.success === false;
54887
+ }
54888
+ try {
54889
+ const parsed = JSON.parse(outputText ?? "");
54890
+ return isRecord6(parsed) && parsed.success === false;
54891
+ } catch {
54892
+ return false;
54893
+ }
54894
+ }
54809
54895
  function includesAuthenticationFailure(errors) {
54810
54896
  return errors.some((error52) => AUTHENTICATION_ERRORS.has(error52));
54811
54897
  }
@@ -55538,7 +55624,7 @@ var ClaudeNativeTurnAccumulator = class {
55538
55624
  events.push({
55539
55625
  type: "subagent.completed",
55540
55626
  callId,
55541
- isError,
55627
+ isError: isError || tool.name === "SendMessage" && claudeSendMessageFailed(nativeResult, outputText),
55542
55628
  ...subagentContinuesInBackground(nativeResult, outputText) ? { continuesInBackground: true } : {},
55543
55629
  ...agentId ? { nativeSubagentId: agentId } : {},
55544
55630
  ...resultSummary ? { resultSummary } : {}
@@ -55693,7 +55779,7 @@ function conversationMessages(values, sessionId) {
55693
55779
  let promptId = null;
55694
55780
  const occupancy = new ClaudeBackgroundOccupancy();
55695
55781
  let accumulator = new ClaudeNativeTurnAccumulator();
55696
- const sends = /* @__PURE__ */ new Set();
55782
+ const sends = /* @__PURE__ */ new Map();
55697
55783
  let pendingNotification = false;
55698
55784
  for (const value of values) {
55699
55785
  if (!isRecord7(value))
@@ -55712,6 +55798,8 @@ function conversationMessages(values, sessionId) {
55712
55798
  uuid: value.uuid,
55713
55799
  message: value.message,
55714
55800
  timestampMs: isoToMs(value.timestamp),
55801
+ // Failure metadata belongs to the outer SDK/transcript record, not its Message.
55802
+ failed: value.type === "assistant" && (typeof value.error === "string" || value.isApiErrorMessage === true),
55715
55803
  nested: typeof value.parent_tool_use_id === "string" && value.parent_tool_use_id.length > 0,
55716
55804
  interrupted,
55717
55805
  startsTurn: false,
@@ -55727,17 +55815,19 @@ function conversationMessages(values, sessionId) {
55727
55815
  for (const event of accumulator.consume(value).events) {
55728
55816
  if (event.type === "subagent.started") {
55729
55817
  if (event.operation === "send") {
55730
- sends.add(event.callId);
55731
- if (event.nativeSubagentId)
55732
- occupancy.occupyAgent(event.nativeSubagentId);
55818
+ sends.set(event.callId, event.nativeSubagentId);
55733
55819
  } else if (event.background)
55734
55820
  occupancy.occupySpawn(event.callId, event.nativeSubagentId);
55735
55821
  } else if (event.type === "subagent.completed") {
55736
- if (!event.isError && (event.continuesInBackground || sends.has(event.callId))) {
55822
+ if (sends.has(event.callId)) {
55823
+ const agentId = event.nativeSubagentId ?? sends.get(event.callId);
55824
+ if (!event.isError && agentId)
55825
+ occupancy.occupyAgent(agentId);
55826
+ sends.delete(event.callId);
55827
+ } else if (!event.isError && event.continuesInBackground) {
55737
55828
  occupancy.occupySpawn(event.callId, event.nativeSubagentId);
55738
55829
  } else
55739
55830
  occupancy.release(event.callId, event.nativeSubagentId);
55740
- sends.delete(event.callId);
55741
55831
  } else if (event.type === "workflow.launched" && event.background && !event.isError) {
55742
55832
  occupancy.occupySpawn(event.callId, event.taskId);
55743
55833
  } else if (event.type === "subagent.settled") {
@@ -55775,7 +55865,7 @@ function turnOutcome(messages) {
55775
55865
  if (messages.some(({ interrupted }) => interrupted))
55776
55866
  return { status: "cancelled", reason: "Cancelled by user" };
55777
55867
  const assistants = messages.filter(({ type }) => type === "assistant");
55778
- const failed = assistants.some(({ message }) => typeof message.error === "string");
55868
+ const failed = assistants.some(({ failed: failed2, nested }) => failed2 && !nested);
55779
55869
  if (failed) {
55780
55870
  return {
55781
55871
  status: "failed",
@@ -55868,6 +55958,7 @@ function mapClaudeSnapshot(values, sessionId) {
55868
55958
  }
55869
55959
  if (message.type !== "assistant")
55870
55960
  return [];
55961
+ const assistantOutcome = outcome.status === "failed" && (!message.failed || message.nested) ? { status: "succeeded" } : itemOutcome(outcome);
55871
55962
  const content = message.message.content;
55872
55963
  const text2 = textParts(content).join("");
55873
55964
  const reasoning = thinkingParts(content).join("");
@@ -55880,7 +55971,7 @@ function mapClaudeSnapshot(values, sessionId) {
55880
55971
  text: text2,
55881
55972
  ...recordDurationMs !== void 0 ? { durationMs: recordDurationMs } : {}
55882
55973
  },
55883
- outcome: itemOutcome(outcome)
55974
+ outcome: assistantOutcome
55884
55975
  }
55885
55976
  ] : [];
55886
55977
  }
@@ -55898,7 +55989,7 @@ function mapClaudeSnapshot(values, sessionId) {
55898
55989
  text: reasoning,
55899
55990
  ...recordDurationMs !== void 0 ? { durationMs: recordDurationMs } : {}
55900
55991
  },
55901
- outcome: itemOutcome(outcome)
55992
+ outcome: assistantOutcome
55902
55993
  });
55903
55994
  projectedReasoning = true;
55904
55995
  continue;
@@ -55911,7 +56002,7 @@ function mapClaudeSnapshot(values, sessionId) {
55911
56002
  text: text2,
55912
56003
  ...recordDurationMs !== void 0 ? { durationMs: recordDurationMs } : {}
55913
56004
  },
55914
- outcome: itemOutcome(outcome)
56005
+ outcome: assistantOutcome
55915
56006
  });
55916
56007
  projectedText = true;
55917
56008
  continue;
@@ -55924,7 +56015,7 @@ function mapClaudeSnapshot(values, sessionId) {
55924
56015
  if (!result)
55925
56016
  continue;
55926
56017
  const output = toolResultOutput(result.block);
55927
- const failed = result.block.is_error === true;
56018
+ const failed = result.block.is_error === true || block.name === "SendMessage" && claudeSendMessageFailed(void 0, output);
55928
56019
  const toolDurationMs = elapsedMs(message.timestampMs, result.timestampMs);
55929
56020
  const toolOutcome = failed ? {
55930
56021
  status: "failed",
@@ -56241,12 +56332,6 @@ async function forkClaudeSession(input) {
56241
56332
  error: error51("protocolError", "Claude Code Session working directory is unavailable", false)
56242
56333
  };
56243
56334
  }
56244
- if (path11.resolve(sourceInfo.cwd) !== input.cwd) {
56245
- return {
56246
- ok: false,
56247
- error: error51("unsupported", "Claude Code cannot Fork across working directories", false)
56248
- };
56249
- }
56250
56335
  const source = await readSnapshot(input.dependencies, input.cwd, sourceRef.data.nativeSessionId);
56251
56336
  if (!source.ok)
56252
56337
  return source;
@@ -56342,7 +56427,7 @@ async function forkClaudeSession(input) {
56342
56427
 
56343
56428
  // dist/claude-session-import.js
56344
56429
  import { realpath as realpath4, stat as stat3 } from "node:fs/promises";
56345
- import path12 from "node:path";
56430
+ import path11 from "node:path";
56346
56431
  function titleFromMetadata(metadata) {
56347
56432
  for (const value of [metadata.customTitle, metadata.summary, metadata.firstPrompt]) {
56348
56433
  if (typeof value !== "string")
@@ -56364,7 +56449,7 @@ async function sourceFromMetadata(metadata, isRunning, signal, canonicalCwds, pr
56364
56449
  ];
56365
56450
  let cwd = null;
56366
56451
  for (const candidate2 of new Set(candidates)) {
56367
- if (!path12.isAbsolute(candidate2))
56452
+ if (!path11.isAbsolute(candidate2))
56368
56453
  continue;
56369
56454
  let canonical = canonicalCwds.get(candidate2);
56370
56455
  if (!canonical) {
@@ -56441,7 +56526,7 @@ var ClaudeSessionImportIndex = class {
56441
56526
  if (!metadata || metadata.sessionId !== nativeSessionId)
56442
56527
  return null;
56443
56528
  const preferredCwds = [];
56444
- if (typeof metadata.cwd === "string" && path12.isAbsolute(metadata.cwd)) {
56529
+ if (typeof metadata.cwd === "string" && path11.isAbsolute(metadata.cwd)) {
56445
56530
  try {
56446
56531
  const messages = await this.#dependencies.readSessionMessages({
56447
56532
  cwd: metadata.cwd,
@@ -56456,7 +56541,7 @@ var ClaudeSessionImportIndex = class {
56456
56541
  continue;
56457
56542
  }
56458
56543
  const cwd = message.cwd;
56459
- if (path12.isAbsolute(cwd) && !preferredCwds.includes(cwd))
56544
+ if (path11.isAbsolute(cwd) && !preferredCwds.includes(cwd))
56460
56545
  preferredCwds.push(cwd);
56461
56546
  }
56462
56547
  } catch {
@@ -56472,13 +56557,13 @@ import { readFile as readFile6, rename as rename4, rm as rm5, stat as stat5, wri
56472
56557
 
56473
56558
  // dist/claude-transcript.js
56474
56559
  import os5 from "node:os";
56475
- import path13 from "node:path";
56560
+ import path12 from "node:path";
56476
56561
  import { readFile as readFile5, readdir as readdir3, stat as stat4 } from "node:fs/promises";
56477
56562
  function projectDirectoryName(cwd) {
56478
56563
  return cwd.replace(/[^A-Za-z0-9]/gu, "-");
56479
56564
  }
56480
56565
  function configDirectory(environment) {
56481
- return environment.CLAUDE_CONFIG_DIR ? path13.resolve(environment.CLAUDE_CONFIG_DIR) : path13.join(os5.homedir(), ".claude");
56566
+ return environment.CLAUDE_CONFIG_DIR ? path12.resolve(environment.CLAUDE_CONFIG_DIR) : path12.join(os5.homedir(), ".claude");
56482
56567
  }
56483
56568
  async function existingFile(file2) {
56484
56569
  try {
@@ -56488,8 +56573,8 @@ async function existingFile(file2) {
56488
56573
  }
56489
56574
  }
56490
56575
  async function findTranscriptFile(environment, cwd, relativeName) {
56491
- const projectsDirectory = path13.join(configDirectory(environment), "projects");
56492
- const expected = path13.join(projectsDirectory, projectDirectoryName(cwd), relativeName);
56576
+ const projectsDirectory = path12.join(configDirectory(environment), "projects");
56577
+ const expected = path12.join(projectsDirectory, projectDirectoryName(cwd), relativeName);
56493
56578
  if (await existingFile(expected))
56494
56579
  return expected;
56495
56580
  let projects;
@@ -56499,7 +56584,7 @@ async function findTranscriptFile(environment, cwd, relativeName) {
56499
56584
  return null;
56500
56585
  }
56501
56586
  for (const project2 of projects) {
56502
- const candidate = path13.join(projectsDirectory, project2, relativeName);
56587
+ const candidate = path12.join(projectsDirectory, project2, relativeName);
56503
56588
  if (await existingFile(candidate))
56504
56589
  return candidate;
56505
56590
  }
@@ -56536,7 +56621,7 @@ async function readClaudeTranscript(input) {
56536
56621
  return parseTranscriptRecords(await readFile5(transcript, "utf8"), input.sessionId);
56537
56622
  }
56538
56623
  async function readClaudeSubagentTranscript(input) {
56539
- const relativeName = path13.join(input.sessionId, "subagents", `agent-${input.nativeSubagentId}.jsonl`);
56624
+ const relativeName = path12.join(input.sessionId, "subagents", `agent-${input.nativeSubagentId}.jsonl`);
56540
56625
  const transcript = await findTranscriptFile(input.environment, input.cwd, relativeName);
56541
56626
  if (!transcript)
56542
56627
  return null;
@@ -56621,13 +56706,13 @@ async function remapForkedSessionReferences(input) {
56621
56706
  import { randomUUID as randomUUID5 } from "node:crypto";
56622
56707
  import { mkdir as mkdir4, readFile as readFile7, rename as rename5, rm as rm6, writeFile as writeFile3 } from "node:fs/promises";
56623
56708
  import os6 from "node:os";
56624
- import path14 from "node:path";
56709
+ import path13 from "node:path";
56625
56710
  var MILLION_CONTEXT_MODELS = [{ id: "claude-opus-5-5", aliases: ["claude-opus-5.5"] }];
56626
56711
  var MILLION_CONTEXT_MODEL_IDS = new Set(MILLION_CONTEXT_MODELS.flatMap((model2) => [model2.id, ...model2.aliases]));
56627
56712
  var MILLION_CONTEXT_SUFFIX = /\[1m\]$/iu;
56628
56713
  function claudeLongContextFile(environment) {
56629
- const root = environment.CODEXHOST_DATA_DIR ? path14.resolve(environment.CODEXHOST_DATA_DIR) : path14.join(os6.homedir(), ".codexhost");
56630
- return path14.join(root, "claude-code-long-context.json");
56714
+ const root = environment.CODEXHOST_DATA_DIR ? path13.resolve(environment.CODEXHOST_DATA_DIR) : path13.join(os6.homedir(), ".codexhost");
56715
+ return path13.join(root, "claude-code-long-context.json");
56631
56716
  }
56632
56717
  async function readClaudeLongContext(environment) {
56633
56718
  try {
@@ -56641,7 +56726,7 @@ async function readClaudeLongContext(environment) {
56641
56726
  }
56642
56727
  async function writeClaudeLongContext(environment, enabled) {
56643
56728
  const file2 = claudeLongContextFile(environment);
56644
- await mkdir4(path14.dirname(file2), { recursive: true, mode: 448 });
56729
+ await mkdir4(path13.dirname(file2), { recursive: true, mode: 448 });
56645
56730
  const temporary = `${file2}.${randomUUID5()}.tmp`;
56646
56731
  try {
56647
56732
  await writeFile3(temporary, `${JSON.stringify({ enabled })}
@@ -56665,7 +56750,7 @@ function claudeSessionModel(model2, enabled) {
56665
56750
  import { Buffer as Buffer2 } from "node:buffer";
56666
56751
  import { readFile as readFile8 } from "node:fs/promises";
56667
56752
  import os7 from "node:os";
56668
- import path15 from "node:path";
56753
+ import path14 from "node:path";
56669
56754
 
56670
56755
  // dist/thinking-options.js
56671
56756
  var option = (id2, label) => ({
@@ -56758,7 +56843,7 @@ function decodeClaudeModelRef(ref) {
56758
56843
  return value === "default" ? void 0 : value;
56759
56844
  }
56760
56845
  function resolveClaudeConfigDirectory(environment = process.env) {
56761
- return path15.resolve(environment.CLAUDE_CONFIG_DIR ?? path15.join(os7.homedir(), ".claude"));
56846
+ return path14.resolve(environment.CLAUDE_CONFIG_DIR ?? path14.join(os7.homedir(), ".claude"));
56762
56847
  }
56763
56848
  function parseModelPickerOptions(value) {
56764
56849
  if (!Array.isArray(value))
@@ -56800,7 +56885,7 @@ function parseClaudeModelPickerSettings(value) {
56800
56885
  };
56801
56886
  }
56802
56887
  async function readClaudeUserModelPicker(environment = process.env) {
56803
- const settingsPath = path15.join(resolveClaudeConfigDirectory(environment), "settings.json");
56888
+ const settingsPath = path14.join(resolveClaudeConfigDirectory(environment), "settings.json");
56804
56889
  let raw;
56805
56890
  try {
56806
56891
  raw = await readFile8(settingsPath, "utf8");
@@ -57146,7 +57231,7 @@ function projectClaudeAccountUsage(usage, account) {
57146
57231
 
57147
57232
  // dist/gateway-models.js
57148
57233
  import { readFile as readFile9 } from "node:fs/promises";
57149
- import path16 from "node:path";
57234
+ import path15 from "node:path";
57150
57235
  var GATEWAY_MODELS_TIMEOUT_MS = 3e3;
57151
57236
  var GATEWAY_MODELS_MAX_BYTES = 2 * 1024 * 1024;
57152
57237
  var OFFICIAL_ANTHROPIC_HOST = "api.anthropic.com";
@@ -57188,14 +57273,14 @@ function claudeConfigDirectory(environment) {
57188
57273
  if (configured)
57189
57274
  return configured;
57190
57275
  const home = trimmedEnv(environment, "HOME") ?? trimmedEnv(environment, "USERPROFILE");
57191
- return home ? path16.join(home, ".claude") : void 0;
57276
+ return home ? path15.join(home, ".claude") : void 0;
57192
57277
  }
57193
57278
  async function readClaudeUserSettingsEnv(environment) {
57194
57279
  const configDir = claudeConfigDirectory(environment);
57195
57280
  if (!configDir)
57196
57281
  return {};
57197
57282
  try {
57198
- const raw = await readFile9(path16.join(configDir, "settings.json"), "utf8");
57283
+ const raw = await readFile9(path15.join(configDir, "settings.json"), "utf8");
57199
57284
  const parsed = JSON.parse(raw);
57200
57285
  if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
57201
57286
  return {};
@@ -57328,7 +57413,7 @@ async function applyGatewayModelCatalog(snapshot, environment, dependencies = {}
57328
57413
 
57329
57414
  // dist/process-fence.js
57330
57415
  import { execFile as execFile3 } from "node:child_process";
57331
- import path17 from "node:path";
57416
+ import path16 from "node:path";
57332
57417
  import { setTimeout as setTimeout2 } from "node:timers/promises";
57333
57418
  import { promisify } from "node:util";
57334
57419
  var executeFile = promisify(execFile3);
@@ -57352,9 +57437,9 @@ async function closeClaudeProcessGroup(child, timeoutMs) {
57352
57437
  if (child.exitCode !== null || child.signalCode !== null)
57353
57438
  throw new Error("Claude process tree cannot be confirmed after its Windows root exited");
57354
57439
  const root = process.env.SystemRoot ?? process.env.SYSTEMROOT;
57355
- if (!root || !path17.win32.isAbsolute(root))
57440
+ if (!root || !path16.win32.isAbsolute(root))
57356
57441
  throw new Error("Windows SystemRoot is unavailable");
57357
- await executeFile(path17.win32.join(root, "System32", "taskkill.exe"), ["/PID", String(pid), "/T", "/F"], {
57442
+ await executeFile(path16.win32.join(root, "System32", "taskkill.exe"), ["/PID", String(pid), "/T", "/F"], {
57358
57443
  timeout: timeoutMs,
57359
57444
  windowsHide: true
57360
57445
  });
@@ -57683,6 +57768,8 @@ var ClaudeSdkTransport = class {
57683
57768
  /** Root tool calls of the requested Turn that have started and not yet returned a result. */
57684
57769
  #rootToolCalls = /* @__PURE__ */ new Set();
57685
57770
  #pendingSteers = /* @__PURE__ */ new Map();
57771
+ /** Written steers Claude has not yet drained into a native turn, by message ID. */
57772
+ #steerTakeovers = /* @__PURE__ */ new Map();
57686
57773
  #autonomous = null;
57687
57774
  #autonomousTurnHandler = null;
57688
57775
  #idleHandler = null;
@@ -57806,9 +57893,16 @@ var ClaudeSdkTransport = class {
57806
57893
  * `priority: "next"` joins after the current tool call, and a tool result is always followed by
57807
57894
  * another model request. So a steer written while a root tool call runs folds into this Turn;
57808
57895
  * one written while Claude streams its final text may instead run as the next Turn.
57896
+ *
57897
+ * A held Turn's continuation steers as well: while its idle stream is live, the pushed input
57898
+ * runs as that Turn's next Segment, and the background work the Turn waits on keeps running.
57809
57899
  */
57810
57900
  canSteerActiveTurn() {
57811
- return this.#nativeSteer && this.#active !== null && this.#rootToolCalls.size > 0;
57901
+ if (!this.#nativeSteer)
57902
+ return false;
57903
+ if (this.#active !== null)
57904
+ return this.#rootToolCalls.size > 0;
57905
+ return this.#idleLive && this.#idleHandler !== null;
57812
57906
  }
57813
57907
  #observeRootToolCalls(message) {
57814
57908
  if (!isRecord10(message) || message.parent_tool_use_id != null)
@@ -57842,11 +57936,11 @@ var ClaudeSdkTransport = class {
57842
57936
  this.#slashCommands = parseClaudeSlashCommands(message.commands);
57843
57937
  }
57844
57938
  }
57845
- async getContextUsage() {
57939
+ async getContextUsage(detail = "full") {
57846
57940
  const activeQuery = this.#query;
57847
57941
  if (!this.#started || !activeQuery)
57848
57942
  return null;
57849
- return parseContextUsage(await activeQuery.getContextUsage());
57943
+ return parseContextUsage(await activeQuery.getContextUsage({ detail }));
57850
57944
  }
57851
57945
  getPermissionMode() {
57852
57946
  if (!this.#started || !this.#query)
@@ -57984,7 +58078,7 @@ var ClaudeSdkTransport = class {
57984
58078
  * The Turn ending first therefore does not reject it, and a missing `queued` receipt resolves
57985
58079
  * after a bounded wait so callers that serialize requests are never held indefinitely.
57986
58080
  */
57987
- steer(text2, messageId) {
58081
+ steer(text2, messageId, onTakeover) {
57988
58082
  if (this.#closePromise || !this.#started || !this.#query || !this.canSteerActiveTurn()) {
57989
58083
  return Promise.reject(new ClaudeSteerMissedTurnError());
57990
58084
  }
@@ -58005,9 +58099,14 @@ var ClaudeSdkTransport = class {
58005
58099
  this.#pendingSteers.delete(messageId);
58006
58100
  return Promise.reject(new ClaudeSteerMissedTurnError());
58007
58101
  }
58102
+ if (onTakeover)
58103
+ this.#steerTakeovers.set(messageId, onTakeover);
58008
58104
  const pending = this.#pendingSteers.get(messageId);
58009
58105
  if (pending) {
58010
- pending.timer = setTimeout(() => this.#acceptSteer(messageId), this.#steerQueuedTimeoutMs);
58106
+ pending.timer = setTimeout(() => {
58107
+ this.#acceptSteer(messageId);
58108
+ this.#takeOverSteer(messageId, false);
58109
+ }, this.#steerQueuedTimeoutMs);
58011
58110
  pending.timer.unref?.();
58012
58111
  }
58013
58112
  return promise2;
@@ -58020,6 +58119,13 @@ var ClaudeSdkTransport = class {
58020
58119
  clearTimeout(pending.timer);
58021
58120
  pending.resolve();
58022
58121
  }
58122
+ #takeOverSteer(messageId, started) {
58123
+ const onTakeover = this.#steerTakeovers.get(messageId);
58124
+ if (!onTakeover)
58125
+ return;
58126
+ this.#steerTakeovers.delete(messageId);
58127
+ onTakeover(started);
58128
+ }
58023
58129
  respondToInteraction(response) {
58024
58130
  const pending = this.#interactions.get(response.requestId);
58025
58131
  if (!pending) {
@@ -58086,7 +58192,8 @@ var ClaudeSdkTransport = class {
58086
58192
  const activeQuery = this.#query;
58087
58193
  if (!activeQuery)
58088
58194
  throw new Error("Claude SDK transport is not running");
58089
- this.#idleAccumulator?.requestCancel();
58195
+ const idle = this.#idleAccumulator ??= new ClaudeNativeTurnAccumulator(this.#provider ? { provider: this.#provider } : {});
58196
+ idle.requestCancel();
58090
58197
  try {
58091
58198
  await this.#stopRequest(activeQuery.interrupt(), INTERRUPT_TIMEOUT_MESSAGE);
58092
58199
  } catch (error52) {
@@ -58301,6 +58408,9 @@ var ClaudeSdkTransport = class {
58301
58408
  }
58302
58409
  }
58303
58410
  #rejectPendingSteers() {
58411
+ for (const messageId of [...this.#steerTakeovers.keys()]) {
58412
+ this.#takeOverSteer(messageId, false);
58413
+ }
58304
58414
  const pending = [...this.#pendingSteers.values()];
58305
58415
  this.#pendingSteers.clear();
58306
58416
  const error52 = new Error("Claude Code steer receipt was lost after input was written");
@@ -58309,16 +58419,24 @@ var ClaudeSdkTransport = class {
58309
58419
  entry.reject(error52);
58310
58420
  }
58311
58421
  }
58312
- /** `queued` is Claude's acceptance of this message into the running Session. */
58422
+ /**
58423
+ * `queued` is Claude's acceptance of this message into the running Session. `started` is its
58424
+ * drain into a native turn, folded into the running one or run as the next; a terminal state
58425
+ * without `started` means no native turn takes it over.
58426
+ */
58313
58427
  #observeSteer(message) {
58314
- if (this.#pendingSteers.size === 0 || !isRecord10(message) || message.type !== "command_lifecycle") {
58428
+ if (this.#pendingSteers.size === 0 && this.#steerTakeovers.size === 0 || !isRecord10(message) || message.type !== "command_lifecycle") {
58315
58429
  return;
58316
58430
  }
58317
- if (message.state !== "queued")
58318
- return;
58319
58431
  if (typeof message.command_uuid !== "string" || message.command_uuid.length === 0)
58320
58432
  return;
58321
- this.#acceptSteer(message.command_uuid);
58433
+ if (message.state === "queued") {
58434
+ this.#acceptSteer(message.command_uuid);
58435
+ return;
58436
+ }
58437
+ if (["started", "completed", "cancelled", "discarded", "refused"].includes(String(message.state))) {
58438
+ this.#takeOverSteer(message.command_uuid, message.state === "started");
58439
+ }
58322
58440
  }
58323
58441
  #observeBackgroundTasks(message) {
58324
58442
  if (!isRecord10(message) || message.type !== "system")
@@ -58431,13 +58549,13 @@ var ClaudeSdkTransport = class {
58431
58549
  throw new Error("Claude SDK Query ended unexpectedly");
58432
58550
  } catch (error52) {
58433
58551
  const active = this.#active;
58552
+ if (!this.#closePromise)
58553
+ this.#onFault(error52);
58434
58554
  this.#closeInteractions("all", "cancelled");
58435
58555
  this.#rejectPendingSteers();
58436
58556
  this.#rootToolCalls.clear();
58437
58557
  this.#active = null;
58438
58558
  active?.reject(error52);
58439
- if (!this.#closePromise)
58440
- this.#onFault(error52);
58441
58559
  }
58442
58560
  }
58443
58561
  #spawn(options) {
@@ -58738,7 +58856,7 @@ var ClaudeSubagentLifecycle = class {
58738
58856
  });
58739
58857
  const outcome = cancellationRequested ? { status: "cancelled", reason: "Cancelled by user" } : event.isError ? { status: "failed", error: subagentFailure() } : { status: "succeeded" };
58740
58858
  this.#emit({ type: "item.completed", turnId, snapshot: { item, outcome } });
58741
- return subagent;
58859
+ return { operation: active.item.operation, subagent };
58742
58860
  }
58743
58861
  finalize(turnId, outcome) {
58744
58862
  for (const [callId, active] of this.#delegations) {
@@ -58946,9 +59064,9 @@ function stringField(value, keys) {
58946
59064
  if (!isRecord11(value))
58947
59065
  return void 0;
58948
59066
  for (const key of keys) {
58949
- const field = value[key];
58950
- if (typeof field === "string" && field.length > 0)
58951
- return field;
59067
+ const field2 = value[key];
59068
+ if (typeof field2 === "string" && field2.length > 0)
59069
+ return field2;
58952
59070
  }
58953
59071
  return void 0;
58954
59072
  }
@@ -59635,10 +59753,12 @@ var ClaudeHarnessSession = class {
59635
59753
  input: { image: true },
59636
59754
  history: { fork: true, forkAcrossCwd: false, rollbackLastTurn: true },
59637
59755
  subagents: { observe: true, readTranscript: true },
59638
- // Read live: native delivery joins this Turn only while a requested Turn runs a root tool call
59639
- // on a CLI that confirms steers (`msg_lifecycle_v1`). Otherwise the Host stops and restarts.
59756
+ // Read live: native delivery joins this Turn while a root tool call runs, or while a held
59757
+ // Turn's continuation waits on background work, on a CLI that confirms steers
59758
+ // (`msg_lifecycle_v1`). A Turn whose cancellation is in flight must not take more input;
59759
+ // every other case stops and restarts.
59640
59760
  get steer() {
59641
- return session.#transport?.canSteerActiveTurn?.() === true;
59761
+ return session.#transport?.canSteerActiveTurn?.() === true && session.#active?.cancellationRequested !== true;
59642
59762
  }
59643
59763
  }))(this);
59644
59764
  commands;
@@ -59690,7 +59810,6 @@ var ClaudeHarnessSession = class {
59690
59810
  #lastAssistantResponseAtUnix;
59691
59811
  #accountCreditsSupported;
59692
59812
  #minimumContextUsedTokens = null;
59693
- #latestRequestModel = null;
59694
59813
  #calibratedInputTokens = 0;
59695
59814
  #calibratedCachedInputTokens = 0;
59696
59815
  #calibratedCacheWriteInputTokens = 0;
@@ -59983,6 +60102,7 @@ var ClaudeHarnessSession = class {
59983
60102
  nativeTurnKey,
59984
60103
  nativeTurnRef: null,
59985
60104
  cancellationRequested: false,
60105
+ steersAwaitingNative: /* @__PURE__ */ new Set(),
59986
60106
  usageRequestIds: /* @__PURE__ */ new Set(),
59987
60107
  estimatedInputTokens: 0,
59988
60108
  estimatedCachedInputTokens: 0,
@@ -60023,9 +60143,13 @@ var ClaudeHarnessSession = class {
60023
60143
  return { ok: true, value: { turnId: command.turnId } };
60024
60144
  }
60025
60145
  async #steer(command) {
60026
- if (!this.#active || this.#active.command.turnId !== command.turnId) {
60146
+ const active = this.#active;
60147
+ if (!active || active.command.turnId !== command.turnId) {
60027
60148
  return { ok: false, error: invalidState("Claude Code steer target is not the active Turn") };
60028
60149
  }
60150
+ if (active.cancellationRequested) {
60151
+ return { ok: false, error: invalidState("Claude Code steer target is being cancelled") };
60152
+ }
60029
60153
  const text2 = command.input.map((input) => input.text).join("\n");
60030
60154
  if (text2.length === 0) {
60031
60155
  return {
@@ -60051,10 +60175,13 @@ var ClaudeHarnessSession = class {
60051
60175
  }
60052
60176
  };
60053
60177
  }
60178
+ const messageId = this.#randomUUID();
60179
+ active.steersAwaitingNative.add(messageId);
60054
60180
  try {
60055
- await transport.steer(text2, this.#randomUUID());
60181
+ await transport.steer(text2, messageId, (started) => this.#takeOverSteer(active, messageId, started));
60056
60182
  } catch (error52) {
60057
60183
  if (error52 instanceof ClaudeSteerMissedTurnError) {
60184
+ this.#takeOverSteer(active, messageId, false);
60058
60185
  return { ok: false, error: invalidState("Claude Code steer missed the active Turn") };
60059
60186
  }
60060
60187
  throw error52;
@@ -60157,6 +60284,7 @@ var ClaudeHarnessSession = class {
60157
60284
  nativeTurnKey,
60158
60285
  nativeTurnRef: null,
60159
60286
  cancellationRequested: false,
60287
+ steersAwaitingNative: /* @__PURE__ */ new Set(),
60160
60288
  usageRequestIds: /* @__PURE__ */ new Set(),
60161
60289
  estimatedInputTokens: 0,
60162
60290
  estimatedCachedInputTokens: 0,
@@ -60232,15 +60360,16 @@ var ClaudeHarnessSession = class {
60232
60360
  this.#contextUsageCooldownUntilMs = 0;
60233
60361
  this.#requestContextUsage(transport, void 0, CONTEXT_USAGE_RETRY_DELAYS_MS);
60234
60362
  }
60235
- refreshUsage() {
60363
+ async refreshUsage() {
60364
+ await this.#contextRefreshInFlight;
60236
60365
  if (this.#phase !== "open" || !this.#transport)
60237
- return Promise.resolve();
60366
+ return;
60238
60367
  const now = Date.now();
60239
60368
  if (now < this.#contextUsageFreshUntilMs || now < this.#contextUsageCooldownUntilMs) {
60240
- return Promise.resolve();
60369
+ return;
60241
60370
  }
60242
60371
  this.#requestContextUsage(this.#transport, this.#active?.command.turnId, CONTEXT_USAGE_RETRY_DELAYS_MS);
60243
- return this.#contextRefreshInFlight ?? Promise.resolve();
60372
+ await this.#contextRefreshInFlight;
60244
60373
  }
60245
60374
  blocksRollback(sessionId) {
60246
60375
  return this.#sessionId === sessionId && (this.#phase !== "open" || this.#active !== null || this.#acceptingTurn || this.#configurationTask !== null || this.#readingHistory);
@@ -60547,7 +60676,9 @@ var ClaudeHarnessSession = class {
60547
60676
  active.cancellationRequested = true;
60548
60677
  const transport = this.#transport;
60549
60678
  const taskIds = this.#backgroundTaskIds(active);
60550
- if (transport && (taskIds.length > 0 || active.held && (active.rootSegmentActive || this.#occupancy.awaitingContinuation))) {
60679
+ if (transport && (taskIds.length > 0 || // A written steer survives the interrupt and runs as Claude's next native turn, so the
60680
+ // Turn stays open to interrupt that turn too instead of leaking it into the next one.
60681
+ active.steersAwaitingNative.size > 0 || active.held && (active.rootSegmentActive || this.#occupancy.awaitingContinuation))) {
60551
60682
  await this.#cancelBackgroundWork(active, transport, taskIds);
60552
60683
  return { ok: true, value: { cancellationRequested: true } };
60553
60684
  }
@@ -60622,6 +60753,11 @@ var ClaudeHarnessSession = class {
60622
60753
  return;
60623
60754
  if (cancellation.stopping || cancellation.interrupting || active.rootSegmentActive)
60624
60755
  return;
60756
+ if (active.steersAwaitingNative.size > 0) {
60757
+ this.#armCancelEscalation(active);
60758
+ return;
60759
+ }
60760
+ this.#clearCancelEscalation();
60625
60761
  this.#clearCancellationQuiet(cancellation);
60626
60762
  const quiet = setTimeout(() => {
60627
60763
  cancellation.quiet = null;
@@ -60902,10 +61038,7 @@ var ClaudeHarnessSession = class {
60902
61038
  }
60903
61039
  this.#completeAgentItem(active, { status: "succeeded" }, false);
60904
61040
  active.subagents.start(active.command.turnId, event);
60905
- if (event.operation === "send") {
60906
- if (event.nativeSubagentId)
60907
- this.#occupancy.occupyAgent(event.nativeSubagentId);
60908
- } else if (event.background) {
61041
+ if (event.operation === "spawn" && event.background) {
60909
61042
  this.#occupancy.occupySpawn(event.callId, event.nativeSubagentId);
60910
61043
  }
60911
61044
  return;
@@ -60924,7 +61057,13 @@ var ClaudeHarnessSession = class {
60924
61057
  }
60925
61058
  return;
60926
61059
  case "subagent.completed": {
60927
- const subagent = active.subagents.complete(active.command.turnId, event, active.cancellationRequested);
61060
+ const { operation, subagent } = active.subagents.complete(active.command.turnId, event, active.cancellationRequested);
61061
+ if (operation === "send") {
61062
+ if (subagent.status === "running" && subagent.nativeSubagentId) {
61063
+ this.#occupancy.occupyAgent(subagent.nativeSubagentId);
61064
+ }
61065
+ return;
61066
+ }
60928
61067
  if (subagent.status === "running") {
60929
61068
  this.#occupancy.occupySpawn(event.callId, subagent.nativeSubagentId);
60930
61069
  return;
@@ -61254,6 +61393,7 @@ var ClaudeHarnessSession = class {
61254
61393
  const active = {
61255
61394
  command: { type: "turn.start", turnId, input: [] },
61256
61395
  compactionItem: null,
61396
+ steersAwaitingNative: /* @__PURE__ */ new Set(),
61257
61397
  item,
61258
61398
  agentMessageOrdinal: 1,
61259
61399
  assistantMessageId: null,
@@ -61395,7 +61535,7 @@ var ClaudeHarnessSession = class {
61395
61535
  this.#finishFailed(active, transportFailure(result.kind));
61396
61536
  }
61397
61537
  }
61398
- #requestContextUsage(transport, turnId, retryDelaysMs) {
61538
+ #requestContextUsage(transport, turnId, retryDelaysMs, detail = "full") {
61399
61539
  if (this.#phase !== "open" || this.#transport !== transport)
61400
61540
  return;
61401
61541
  if (this.#contextRefreshInFlight)
@@ -61404,7 +61544,8 @@ var ClaudeHarnessSession = class {
61404
61544
  transport,
61405
61545
  ...turnId !== void 0 ? { turnId } : {},
61406
61546
  generation: this.#usageGeneration,
61407
- retryDelaysMs
61547
+ retryDelaysMs,
61548
+ detail
61408
61549
  };
61409
61550
  this.#contextRefreshInFlight = this.#drainContextUsage();
61410
61551
  }
@@ -61430,14 +61571,16 @@ var ClaudeHarnessSession = class {
61430
61571
  return;
61431
61572
  }
61432
61573
  try {
61433
- const context = await request.transport.getContextUsage();
61574
+ const context = await request.transport.getContextUsage(request.detail);
61434
61575
  if (this.#phase !== "open" || this.#transport !== request.transport || this.#usageGeneration !== request.generation || this.#contextRefreshPending !== null) {
61435
61576
  return;
61436
61577
  }
61437
61578
  if (context === null)
61438
61579
  continue;
61439
- this.#contextUsageFreshUntilMs = Date.now() + CONTEXT_USAGE_TTL_MS;
61440
- this.#contextUsageCooldownUntilMs = 0;
61580
+ if (request.detail === "full") {
61581
+ this.#contextUsageFreshUntilMs = Date.now() + CONTEXT_USAGE_TTL_MS;
61582
+ this.#contextUsageCooldownUntilMs = 0;
61583
+ }
61441
61584
  const delta = {
61442
61585
  contextUsedTokens: Math.max(context.usedTokens, this.#minimumContextUsedTokens ?? 0),
61443
61586
  contextWindowTokens: context.maxTokens
@@ -61452,7 +61595,7 @@ var ClaudeHarnessSession = class {
61452
61595
  } catch {
61453
61596
  }
61454
61597
  }
61455
- if (this.#phase === "open" && this.#transport === request.transport && this.#usageGeneration === request.generation) {
61598
+ if (request.detail === "full" && this.#phase === "open" && this.#transport === request.transport && this.#usageGeneration === request.generation) {
61456
61599
  this.#contextUsageCooldownUntilMs = Date.now() + CONTEXT_USAGE_FAILURE_COOLDOWN_MS;
61457
61600
  }
61458
61601
  }
@@ -61533,8 +61676,6 @@ var ClaudeHarnessSession = class {
61533
61676
  const promptTokens = usage.inputTokens + usage.cacheCreationInputTokens + usage.cacheReadInputTokens;
61534
61677
  if (promptTokens > 0)
61535
61678
  this.#minimumContextUsedTokens = promptTokens;
61536
- if (usage.model)
61537
- this.#latestRequestModel = usage.model;
61538
61679
  const cacheHitRatePercent = this.#cacheHitRatePercent(usage);
61539
61680
  const contextWindowTokens = this.#latestUsage?.contextWindowTokens;
61540
61681
  this.#mergeAndPublishUsage({
@@ -61599,24 +61740,11 @@ var ClaudeHarnessSession = class {
61599
61740
  if (cacheHitRatePercent !== void 0)
61600
61741
  delta.cacheHitRatePercent = cacheHitRatePercent;
61601
61742
  }
61602
- if (this.#latestUsage?.contextWindowTokens === void 0 && this.#minimumContextUsedTokens !== null) {
61603
- const contextWindowTokens = this.#resultContextWindow(event.modelUsage);
61604
- if (contextWindowTokens !== void 0) {
61605
- delta.contextUsedTokens = this.#minimumContextUsedTokens;
61606
- delta.contextWindowTokens = contextWindowTokens;
61607
- }
61743
+ if (this.#transport && this.#minimumContextUsedTokens !== null && event.modelUsage?.some(({ contextWindowTokens }) => contextWindowTokens !== void 0)) {
61744
+ this.#requestContextUsage(this.#transport, active.command.turnId, [0], "summary");
61608
61745
  }
61609
61746
  this.#mergeAndPublishUsage(delta, active.command.turnId);
61610
61747
  }
61611
- /** The latest request's Model, else the Model that carried the most prompt tokens. */
61612
- #resultContextWindow(modelUsage) {
61613
- if (!modelUsage?.length)
61614
- return void 0;
61615
- const latest = this.#latestRequestModel;
61616
- const matched = latest ? modelUsage.find(({ model: model2 }) => model2 === latest) : void 0;
61617
- const main = matched ?? modelUsage.reduce((best, entry) => (entry.promptTokens ?? entry.inputTokens) > (best.promptTokens ?? best.inputTokens) ? entry : best);
61618
- return main.contextWindowTokens;
61619
- }
61620
61748
  /**
61621
61749
  * Plan usage is account-wide, not Thread-scoped, so every observation is
61622
61750
  * offered to the Adapter's shared cache regardless of this Session's own
@@ -61695,7 +61823,7 @@ var ClaudeHarnessSession = class {
61695
61823
  this.#clearContinuationQuiescence();
61696
61824
  const quiescence = setTimeout(() => {
61697
61825
  this.#continuationQuiescence = null;
61698
- if (this.#active !== active || !active.held || active.rootSegmentActive || this.#phase !== "open") {
61826
+ if (this.#active !== active || !active.held || active.rootSegmentActive || active.steersAwaitingNative.size > 0 || this.#phase !== "open") {
61699
61827
  return;
61700
61828
  }
61701
61829
  this.#occupancy.releaseContinuations();
@@ -61716,6 +61844,30 @@ var ClaudeHarnessSession = class {
61716
61844
  active.rootSegmentActive = true;
61717
61845
  this.#clearContinuationQuiescence();
61718
61846
  }
61847
+ /**
61848
+ * A drained steer runs in a native turn whose result still reaches this Turn, folded into the
61849
+ * running Root Segment or as the held Turn's next one. A steer that ends without one releases
61850
+ * its keep-open, so a Turn held only for it settles as if the steer had never been written.
61851
+ */
61852
+ #takeOverSteer(active, messageId, started) {
61853
+ if (!active.steersAwaitingNative.delete(messageId) || this.#active !== active)
61854
+ return;
61855
+ if (started) {
61856
+ this.#handleTurnEvent(active, { type: "segment.started" });
61857
+ return;
61858
+ }
61859
+ if (active.cancellation) {
61860
+ this.#settleCancellation(active);
61861
+ return;
61862
+ }
61863
+ if (!active.held || active.rootSegmentActive || active.steersAwaitingNative.size > 0 || this.#phase !== "open") {
61864
+ return;
61865
+ }
61866
+ if (this.#occupancy.awaitingContinuation)
61867
+ this.#armContinuationQuiescence(active);
61868
+ else if (!this.#occupancy.unsettled)
61869
+ this.#finish(active, { status: "succeeded" });
61870
+ }
61719
61871
  #finish(active, outcome) {
61720
61872
  if (this.#active !== active)
61721
61873
  return;
@@ -61726,7 +61878,7 @@ var ClaudeHarnessSession = class {
61726
61878
  active.cancellation = null;
61727
61879
  }
61728
61880
  this.#clearContinuationQuiescence();
61729
- const hold = outcome.status === "succeeded" && !active.cancellationRequested && this.#occupancy.unsettled;
61881
+ const hold = outcome.status === "succeeded" && !active.cancellationRequested && (this.#occupancy.unsettled || active.steersAwaitingNative.size > 0);
61730
61882
  this.#closeActiveInteractions(active, outcome.status === "succeeded" ? "superseded" : "cancelled", hold);
61731
61883
  const itemOutcome2 = outcome;
61732
61884
  if (active.compactionItem)
@@ -62008,7 +62160,7 @@ var ClaudeCodeAdapter = class {
62008
62160
  error: invalidState("Claude Code Adapter is closing")
62009
62161
  };
62010
62162
  }
62011
- const cwd = path18.resolve(input.cwd ?? process.cwd());
62163
+ const cwd = path17.resolve(input.cwd ?? process.cwd());
62012
62164
  if (!input.refresh) {
62013
62165
  const cached2 = this.#inspectionCache.get(cwd);
62014
62166
  if (cached2)
@@ -62213,7 +62365,7 @@ var ClaudeCodeAdapter = class {
62213
62365
  }
62214
62366
  requestedPermissionModeId = CLAUDE_DEFAULT_PERMISSION_MODE_ID;
62215
62367
  }
62216
- const cwd = path18.resolve(input.cwd);
62368
+ const cwd = path17.resolve(input.cwd);
62217
62369
  if (input.kind === "rollbackLastTurn") {
62218
62370
  for (const source of this.#sessions) {
62219
62371
  const ready = await source.prepareRollback(input.sourceRef.nativeSessionId);
@@ -62382,7 +62534,7 @@ var ClaudeCodeAdapter = class {
62382
62534
  // dist/installation.js
62383
62535
  import { readFile as readFile10, realpath as realpath5 } from "node:fs/promises";
62384
62536
  import { homedir as homedir2 } from "node:os";
62385
- import path19 from "node:path";
62537
+ import path18 from "node:path";
62386
62538
  async function readSettings(file2) {
62387
62539
  const text2 = await readFile10(file2, "utf8").catch((error52) => {
62388
62540
  if (error52.code === "ENOENT")
@@ -62403,9 +62555,9 @@ function createClaudeInstallation(environment, command) {
62403
62555
  ...command ? { command } : {}
62404
62556
  });
62405
62557
  const home = environment.HOME ?? environment.USERPROFILE ?? homedir2();
62406
- const config2 = environment.CLAUDE_CONFIG_DIR ? path19.resolve(home, environment.CLAUDE_CONFIG_DIR) : path19.join(home, ".claude");
62407
- const managedFile = process.platform === "darwin" ? "/Library/Application Support/ClaudeCode/managed-settings.json" : process.platform === "win32" ? path19.join(environment.ProgramFiles ?? "C:\\Program Files", "ClaudeCode", "managed-settings.json") : "/etc/claude-code/managed-settings.json";
62408
- const user = await readSettings(path19.join(config2, "settings.json"));
62558
+ const config2 = environment.CLAUDE_CONFIG_DIR ? path18.resolve(home, environment.CLAUDE_CONFIG_DIR) : path18.join(home, ".claude");
62559
+ const managedFile = process.platform === "darwin" ? "/Library/Application Support/ClaudeCode/managed-settings.json" : process.platform === "win32" ? path18.join(environment.ProgramFiles ?? "C:\\Program Files", "ClaudeCode", "managed-settings.json") : "/etc/claude-code/managed-settings.json";
62560
+ const user = await readSettings(path18.join(config2, "settings.json"));
62409
62561
  const managed = await readSettings(managedFile);
62410
62562
  const settings = { ...user, ...managed, env: { ...user.env, ...managed.env } };
62411
62563
  const env = { ...environment, ...settings.env };
@@ -62418,10 +62570,10 @@ function createClaudeInstallation(environment, command) {
62418
62570
  throw new Error("Unknown Claude release channel");
62419
62571
  const latestVersion = installationVersion(await fetchInstallationText(`https://downloads.claude.ai/claude-code-releases/${channel}`));
62420
62572
  const npm = await npmInstallation(executable, ["@anthropic-ai/claude-code"], env);
62421
- const launcher = path19.join(home, ".local", "bin", process.platform === "win32" ? "claude.exe" : "claude");
62573
+ const launcher = path18.join(home, ".local", "bin", process.platform === "win32" ? "claude.exe" : "claude");
62422
62574
  const selected = await realpath5(executable);
62423
- const versions = path19.join(home, ".local", "share", "claude", "versions") + path19.sep;
62424
- const native = path19.resolve(executable) === launcher && (selected.startsWith(versions) || process.platform === "win32" && selected === launcher);
62575
+ const versions = path18.join(home, ".local", "share", "claude", "versions") + path18.sep;
62576
+ const native = path18.resolve(executable) === launcher && (selected.startsWith(versions) || process.platform === "win32" && selected === launcher);
62425
62577
  const blocked = !!env.DISABLE_UPDATES && env.DISABLE_UPDATES !== "0" || !!settings.minimumVersion && newerInstallationVersion(latestVersion, installationVersion(settings.minimumVersion)) || !!settings.requiredMaximumVersion && newerInstallationVersion(installationVersion(settings.requiredMaximumVersion), latestVersion);
62426
62578
  const canUpdate = !blocked && (npm?.canUpdate ?? native);
62427
62579
  update = async () => {
@@ -62452,7 +62604,7 @@ function createClaudeInstallation(environment, command) {
62452
62604
  }
62453
62605
 
62454
62606
  // dist/user-shell-environment.js
62455
- import path20 from "node:path";
62607
+ import path19 from "node:path";
62456
62608
  import { execFile as execFile4 } from "node:child_process";
62457
62609
  var ENVIRONMENT_MARKER = Buffer.from("\0CODEXHOST_USER_SHELL_ENV_V1\0");
62458
62610
  var ENVIRONMENT_COMMAND = "printf '\\0CODEXHOST_USER_SHELL_ENV_V1\\0'; /usr/bin/env -0";
@@ -62495,7 +62647,7 @@ async function withUserShellEnvironment(environment, dependencies) {
62495
62647
  if (platform === "win32" || !environment.HOME)
62496
62648
  return environment;
62497
62649
  const shell = environment.SHELL?.trim() || defaultShell(platform);
62498
- if (!shell || !SUPPORTED_SHELLS.has(path20.basename(shell)))
62650
+ if (!shell || !SUPPORTED_SHELLS.has(path19.basename(shell)))
62499
62651
  return environment;
62500
62652
  const cacheKey = `${platform}\0${shell}\0${environment.HOME}`;
62501
62653
  const cached2 = dependencies ? void 0 : shellEnvironmentCache.get(cacheKey);
@@ -62533,6 +62685,7 @@ async function createHarnessAdapter(context) {
62533
62685
  const environment = await withUserShellEnvironment({ ...context.environment });
62534
62686
  if (context.platform === "darwin" && context.managedRemoteHost) {
62535
62687
  return new BrokeredHarnessAdapter({
62688
+ sessionImport: true,
62536
62689
  forwardDelegationEnvironment: true,
62537
62690
  commandCatalog: claudeCommandCatalog,
62538
62691
  liveCommandCatalog: true,