@liberseek/boft-cli-win32-arm64 0.7.8 → 0.7.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.
@@ -6,6 +6,7 @@ var __export = (target, all) => {
6
6
  };
7
7
 
8
8
  // ../../harness-broker/dist/client.js
9
+ import { execFile } from "node:child_process";
9
10
  import { randomUUID } from "node:crypto";
10
11
  import { lstat, readFile } from "node:fs/promises";
11
12
  import net, {} from "node:net";
@@ -14604,6 +14605,10 @@ var hostTurnIdSchema = opaqueIdSchema.brand();
14604
14605
  var hostItemIdSchema = opaqueIdSchema.brand();
14605
14606
  var hostInteractionIdSchema = opaqueIdSchema.brand();
14606
14607
 
14608
+ // ../../shared-contracts/dist/thread-prewarm.js
14609
+ var threadPrewarmDiscardParamsSchema = external_exports.object({ threadId: hostThreadIdSchema });
14610
+ var threadPrewarmDiscardResultSchema = external_exports.object({ discarded: external_exports.boolean() });
14611
+
14607
14612
  // ../../shared-contracts/dist/harness-plugins.js
14608
14613
  var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
14609
14614
  var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
@@ -14671,6 +14676,9 @@ var consoleOpenResultSchema = external_exports.strictObject({
14671
14676
  url: external_exports.string().max(2048).regex(/^http:\/\/(?:127\.0\.0\.1|localhost):\d{1,5}\/(?:\?.*)?$/u)
14672
14677
  });
14673
14678
  var CONSOLE_HOST_METHODS = Object.freeze([
14679
+ "codexhost/console/remote-connections",
14680
+ "codexhost/runtime/status",
14681
+ "codexhost/remote/ssh-setup",
14674
14682
  "codexhost/harness/plugins/list",
14675
14683
  "codexhost/harness/display-settings/get",
14676
14684
  "codexhost/harness/display-settings/set",
@@ -15616,6 +15624,80 @@ var updateStatusResultSchema = external_exports.strictObject({
15616
15624
  status: updateStatusSchema.nullable()
15617
15625
  });
15618
15626
 
15627
+ // ../../shared-contracts/dist/remote-runtime.js
15628
+ var remoteUpdatePhaseSchema = external_exports.enum([
15629
+ "idle",
15630
+ "installing",
15631
+ "restarting",
15632
+ "succeeded",
15633
+ "failed"
15634
+ ]);
15635
+ var runtimeStatusSchema = external_exports.object({
15636
+ runningVersion: external_exports.string().nullable(),
15637
+ installedVersion: external_exports.string().nullable(),
15638
+ restartRequired: external_exports.boolean(),
15639
+ remote: external_exports.boolean(),
15640
+ updateSupported: external_exports.boolean(),
15641
+ update: external_exports.object({
15642
+ phase: remoteUpdatePhaseSchema,
15643
+ targetVersion: external_exports.string().nullable(),
15644
+ error: external_exports.string().nullable()
15645
+ })
15646
+ });
15647
+ var remoteUpdateParamsSchema = external_exports.object({
15648
+ version: external_exports.string().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u)
15649
+ }).strict();
15650
+ var remoteSshSetupParamsSchema = external_exports.object({
15651
+ hostname: external_exports.string().min(1).max(1024).refine((value) => !value.startsWith("-") && !/\s/u.test(value)),
15652
+ port: external_exports.number().int().min(1).max(65535).nullable(),
15653
+ identity: external_exports.string().max(4096).nullable(),
15654
+ action: external_exports.enum(["inspect", "install", "update", "repair", "uninstall"]),
15655
+ uninstallPackage: external_exports.boolean().optional(),
15656
+ version: external_exports.string().regex(/^\d+\.\d+\.\d+$/u).nullable()
15657
+ }).strict();
15658
+ var remoteSshSetupResultSchema = external_exports.object({ state: external_exports.enum(["installed", "not-installed"]) }).strict();
15659
+
15660
+ // ../../shared-contracts/dist/remote-connections.js
15661
+ var hostId = external_exports.string().min(1).max(1024);
15662
+ var codexSshConnectionSchema = external_exports.object({
15663
+ hostId,
15664
+ displayName: external_exports.string().min(1).max(1024),
15665
+ source: external_exports.enum(["codex-managed", "discovered"]),
15666
+ sshAlias: external_exports.string().max(1024).nullable(),
15667
+ sshHost: external_exports.string().min(1).max(1024),
15668
+ sshPort: external_exports.number().int().min(1).max(65535).nullable(),
15669
+ identity: external_exports.string().max(4096).nullable(),
15670
+ autoConnect: external_exports.boolean(),
15671
+ connectionAnalyticsId: external_exports.string().max(1024).optional()
15672
+ });
15673
+ var codexSshDraftSchema = external_exports.strictObject({
15674
+ displayName: external_exports.string().min(1).max(1024),
15675
+ hostname: external_exports.string().min(1).max(1024),
15676
+ sshPort: external_exports.number().int().min(1).max(65535).nullable(),
15677
+ identity: external_exports.string().max(4096).nullable()
15678
+ });
15679
+ var remoteConnectionsRequestSchema = external_exports.discriminatedUnion("action", [
15680
+ external_exports.strictObject({ action: external_exports.literal("list") }),
15681
+ external_exports.strictObject({
15682
+ action: external_exports.literal("save"),
15683
+ draft: codexSshDraftSchema,
15684
+ previous: codexSshConnectionSchema.nullable()
15685
+ }),
15686
+ external_exports.strictObject({ action: external_exports.literal("remove"), previous: codexSshConnectionSchema }),
15687
+ external_exports.strictObject({ action: external_exports.literal("connect"), hostId, enabled: external_exports.boolean() }),
15688
+ external_exports.strictObject({ action: external_exports.literal("state"), hostId }),
15689
+ external_exports.strictObject({ action: external_exports.literal("runtime"), hostId }),
15690
+ external_exports.strictObject({
15691
+ action: external_exports.literal("update"),
15692
+ hostId: hostId.refine((id) => id !== "local"),
15693
+ version: remoteUpdateParamsSchema.shape.version
15694
+ })
15695
+ ]);
15696
+ var remoteConnectionsReplySchema = external_exports.union([
15697
+ external_exports.strictObject({ result: jsonValueSchema }),
15698
+ external_exports.strictObject({ error: external_exports.strictObject({ code: external_exports.number().int(), message: external_exports.string() }) })
15699
+ ]);
15700
+
15619
15701
  // ../../shared-contracts/dist/index.js
15620
15702
  var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
15621
15703
 
@@ -15941,9 +16023,12 @@ var HARNESS_BROKER_MAX_FRAME_BYTES = 8 * 1024 * 1024;
15941
16023
  var HARNESS_BROKER_MAX_PENDING_REQUESTS = 32;
15942
16024
  var HARNESS_BROKER_REQUEST_TIMEOUT_MS = 15e3;
15943
16025
  var HARNESS_BROKER_SESSION_IMPORT_PAGE_SIZE = 100;
16026
+ var HARNESS_BROKER_IDLE_TIMEOUT_MS = 60 * 60 * 1e3;
16027
+ var HARNESS_BROKER_RETIRING_ERROR_CODE = "brokerRetiring";
15944
16028
  var harnessBrokerMethodSchema = external_exports.enum([
15945
16029
  "adapter.inspect",
15946
16030
  "adapter.inspectAccount",
16031
+ "adapter.credits",
15947
16032
  "adapter.open",
15948
16033
  "adapter.sessionImport.list",
15949
16034
  "adapter.sessionImport.resolve",
@@ -16063,6 +16148,14 @@ function defaultHarnessBrokerDescriptorPath(environment = process.env, harnessId
16063
16148
  return path.join(defaultHarnessBrokerDirectory(environment), `${harnessId}-broker-v1.json`);
16064
16149
  return environment[HARNESS_BROKER_DESCRIPTOR_ENV] ?? path.join(defaultHarnessBrokerDirectory(environment), HARNESS_BROKER_DESCRIPTOR_FILE);
16065
16150
  }
16151
+ function harnessBrokerLaunchAgentLabel(harnessId = "claude-code") {
16152
+ harnessPluginIdSchema.parse(harnessId);
16153
+ return harnessId === "claude-code" ? "ai.bytepioneer.codexhost.native-harness-broker" : `ai.bytepioneer.codexhost.${harnessId}-broker`;
16154
+ }
16155
+ function harnessBrokerLaunchAgentPlistPath(environment = process.env, harnessId = "claude-code") {
16156
+ const home = environment.HOME || os.homedir();
16157
+ return path.join(home, "Library", "LaunchAgents", `${harnessBrokerLaunchAgentLabel(harnessId)}.plist`);
16158
+ }
16066
16159
 
16067
16160
  // ../../harness-broker/dist/validation.js
16068
16161
  var cwdSchema = external_exports.string().min(1).max(16384);
@@ -16389,10 +16482,55 @@ async function readDescriptor(descriptorPath) {
16389
16482
  try {
16390
16483
  process.kill(descriptor.ownerPid, 0);
16391
16484
  } catch {
16392
- throw new Error("Aqua Harness broker owner process is unavailable");
16485
+ throw new BrokerNotRunningError("its owner process has exited");
16393
16486
  }
16394
16487
  return descriptor;
16395
16488
  }
16489
+ var BrokerNotRunningError = class extends Error {
16490
+ };
16491
+ var BrokerRetiringError = class extends Error {
16492
+ };
16493
+ var BrokerRequestNotDeliveredError = class extends Error {
16494
+ };
16495
+ var HarnessNotInstalledError = class extends Error {
16496
+ };
16497
+ var BROKER_NOT_RUNNING_CODES = /* @__PURE__ */ new Set(["ENOENT", "ECONNREFUSED"]);
16498
+ var BROKER_START_TIMEOUT_MS = 15e3;
16499
+ var BROKER_START_POLL_MS = 250;
16500
+ function classifyConnectFailure(error52) {
16501
+ if (error52 instanceof BrokerNotRunningError)
16502
+ return error52;
16503
+ const code = error52?.code;
16504
+ if (code && BROKER_NOT_RUNNING_CODES.has(code)) {
16505
+ return new BrokerNotRunningError(code === "ENOENT" ? "its descriptor or socket is missing" : "its socket refused the connection");
16506
+ }
16507
+ return error52 instanceof Error ? error52 : new Error(String(error52));
16508
+ }
16509
+ function describeBrokerFailure(error52, harnessId) {
16510
+ if (error52 instanceof BrokerNotRunningError) {
16511
+ return `The ${harnessId} Aqua Harness broker on this Mac could not be started (${error52.message}). Keep the desktop user logged in, then repair the remote service or run on this Mac: codexhost broker install --harness ${harnessId}`;
16512
+ }
16513
+ return error52 instanceof Error ? error52.message : String(error52);
16514
+ }
16515
+ function runLaunchctl(arguments_) {
16516
+ return new Promise((resolve2) => {
16517
+ execFile("/bin/launchctl", arguments_, { timeout: 1e4 }, (error52) => resolve2(!error52));
16518
+ });
16519
+ }
16520
+ async function startBrokerLaunchAgent(harnessId, environment) {
16521
+ const uid = process.getuid?.();
16522
+ if (uid === void 0)
16523
+ return;
16524
+ const target = `gui/${uid}/${harnessBrokerLaunchAgentLabel(harnessId)}`;
16525
+ if (await runLaunchctl(["kickstart", target]))
16526
+ return;
16527
+ await runLaunchctl([
16528
+ "bootstrap",
16529
+ `gui/${uid}`,
16530
+ harnessBrokerLaunchAgentPlistPath(environment, harnessId)
16531
+ ]);
16532
+ await runLaunchctl(["kickstart", target]);
16533
+ }
16396
16534
  var BrokerConnection = class _BrokerConnection {
16397
16535
  #onClose;
16398
16536
  onClose(callback) {
@@ -16416,21 +16554,31 @@ var BrokerConnection = class _BrokerConnection {
16416
16554
  socket.once("error", (error52) => this.#fail(error52));
16417
16555
  }
16418
16556
  static async connect(descriptorPath, harnessId) {
16419
- const descriptor = await readDescriptor(descriptorPath);
16420
- if (descriptor.harnessId !== harnessId)
16421
- throw new Error("Aqua broker belongs to another Harness");
16422
- const socket = net.createConnection(descriptor.socketPath);
16423
- await new Promise((resolve2, reject) => {
16424
- const timeout = setTimeout(() => reject(new Error("Timed out connecting to Aqua Harness broker")), HARNESS_BROKER_REQUEST_TIMEOUT_MS);
16425
- socket.once("connect", () => {
16426
- clearTimeout(timeout);
16427
- resolve2();
16428
- });
16429
- socket.once("error", (error52) => {
16430
- clearTimeout(timeout);
16431
- reject(error52);
16557
+ let descriptor;
16558
+ let socket;
16559
+ let connecting;
16560
+ try {
16561
+ descriptor = await readDescriptor(descriptorPath);
16562
+ if (descriptor.harnessId !== harnessId)
16563
+ throw new Error("Aqua broker belongs to another Harness");
16564
+ connecting = net.createConnection(descriptor.socketPath);
16565
+ const pending = connecting;
16566
+ await new Promise((resolve2, reject) => {
16567
+ const timeout = setTimeout(() => reject(new Error("Timed out connecting to Aqua Harness broker")), HARNESS_BROKER_REQUEST_TIMEOUT_MS);
16568
+ pending.once("connect", () => {
16569
+ clearTimeout(timeout);
16570
+ resolve2();
16571
+ });
16572
+ pending.once("error", (error52) => {
16573
+ clearTimeout(timeout);
16574
+ reject(error52);
16575
+ });
16432
16576
  });
16433
- });
16577
+ socket = pending;
16578
+ } catch (error52) {
16579
+ connecting?.destroy();
16580
+ throw classifyConnectFailure(error52);
16581
+ }
16434
16582
  const connection = new _BrokerConnection(descriptor, socket);
16435
16583
  const hello = connection.#waitForHello();
16436
16584
  await writeBrokerFrame(socket, {
@@ -16483,15 +16631,24 @@ var BrokerConnection = class _BrokerConnection {
16483
16631
  }, HARNESS_BROKER_REQUEST_TIMEOUT_MS);
16484
16632
  this.#pending.set(id, { resolve: resolve2, reject, timeout });
16485
16633
  });
16486
- await writeBrokerFrame(this.#socket, {
16487
- version: HARNESS_BROKER_PROTOCOL_VERSION,
16488
- generation: this.#descriptor.generation,
16489
- sequence: this.#inputSequence,
16490
- kind: "request",
16491
- id,
16492
- method,
16493
- params
16494
- });
16634
+ try {
16635
+ await writeBrokerFrame(this.#socket, {
16636
+ version: HARNESS_BROKER_PROTOCOL_VERSION,
16637
+ generation: this.#descriptor.generation,
16638
+ sequence: this.#inputSequence,
16639
+ kind: "request",
16640
+ id,
16641
+ method,
16642
+ params
16643
+ });
16644
+ } catch (error52) {
16645
+ const pending = this.#pending.get(id);
16646
+ if (pending)
16647
+ clearTimeout(pending.timeout);
16648
+ this.#pending.delete(id);
16649
+ response.catch(() => void 0);
16650
+ throw new BrokerRequestNotDeliveredError(error52 instanceof Error ? error52.message : String(error52));
16651
+ }
16495
16652
  return response;
16496
16653
  }
16497
16654
  close() {
@@ -16535,6 +16692,8 @@ var BrokerConnection = class _BrokerConnection {
16535
16692
  this.#pending.delete(frame.id);
16536
16693
  if (frame.ok)
16537
16694
  pending.resolve(frame.value);
16695
+ else if (frame.error?.code === HARNESS_BROKER_RETIRING_ERROR_CODE)
16696
+ pending.reject(new BrokerRetiringError(frame.error.message));
16538
16697
  else
16539
16698
  pending.reject(new Error(frame.error?.message ?? "Broker request failed"));
16540
16699
  }
@@ -16760,18 +16919,20 @@ var BrokeredHarnessAdapter = class {
16760
16919
  harnessId;
16761
16920
  #descriptorPath;
16762
16921
  #forwardEnvironment;
16922
+ #isInstalled;
16923
+ #startBroker;
16924
+ #startTimeoutMs;
16763
16925
  #connection = null;
16764
16926
  #closed = false;
16765
16927
  #sessionImportListing = null;
16928
+ #credits = null;
16929
+ #creditsRefresh = null;
16766
16930
  subagents = {
16767
16931
  readSnapshot: async (input) => {
16768
16932
  try {
16769
- return parseHarnessResult(await (await this.#connect()).request("adapter.subagent.readSnapshot", input));
16933
+ return parseHarnessResult(await this.#request("adapter.subagent.readSnapshot", input));
16770
16934
  } catch (error52) {
16771
- return {
16772
- ok: false,
16773
- error: unavailable(error52 instanceof Error ? error52.message : String(error52))
16774
- };
16935
+ return { ok: false, error: this.#error(error52) };
16775
16936
  }
16776
16937
  }
16777
16938
  };
@@ -16861,12 +17022,39 @@ var BrokeredHarnessAdapter = class {
16861
17022
  if (input.liveCommandCatalog)
16862
17023
  this.liveCommandCatalog = true;
16863
17024
  this.#descriptorPath = input.descriptorPath ?? defaultHarnessBrokerDescriptorPath(input.environment, this.harnessId);
17025
+ this.#isInstalled = input.isInstalled;
17026
+ const environment = input.environment ?? process.env;
17027
+ this.#startBroker = input.startBroker === false ? void 0 : input.startBroker ?? (process.platform === "darwin" && !input.descriptorPath ? () => startBrokerLaunchAgent(this.harnessId, environment) : void 0);
17028
+ this.#startTimeoutMs = input.startTimeoutMs ?? BROKER_START_TIMEOUT_MS;
17029
+ }
17030
+ credits() {
17031
+ return this.#credits;
17032
+ }
17033
+ refreshCredits() {
17034
+ if (this.#closed)
17035
+ return Promise.resolve(null);
17036
+ if (this.#creditsRefresh)
17037
+ return this.#creditsRefresh;
17038
+ this.#creditsRefresh = this.#readCredits().finally(() => {
17039
+ this.#creditsRefresh = null;
17040
+ });
17041
+ return this.#creditsRefresh;
17042
+ }
17043
+ async #readCredits() {
17044
+ try {
17045
+ const value = await this.#request("adapter.credits", {}, true);
17046
+ const credits = accountCreditsSnapshotSchema.nullable().parse(value);
17047
+ if (!this.#closed)
17048
+ this.#credits = credits;
17049
+ } catch {
17050
+ }
17051
+ return this.#credits;
16864
17052
  }
16865
17053
  async inspectAccount() {
16866
17054
  if (this.#closed)
16867
17055
  return null;
16868
17056
  try {
16869
- const value = await (await this.#connect()).request("adapter.inspectAccount", {});
17057
+ const value = await this.#request("adapter.inspectAccount", {}, true);
16870
17058
  return harnessAccountSnapshotSchema.nullable().parse(value);
16871
17059
  } catch {
16872
17060
  return null;
@@ -16876,33 +17064,46 @@ var BrokeredHarnessAdapter = class {
16876
17064
  if (this.#closed)
16877
17065
  return failedInspection("Aqua Harness broker adapter is closed");
16878
17066
  try {
16879
- return harnessInspectionSchema.parse(await (await this.#connect()).request("adapter.inspect", input));
17067
+ return harnessInspectionSchema.parse(await this.#request("adapter.inspect", input, true));
16880
17068
  } catch (error52) {
16881
17069
  this.#connection = null;
16882
- return failedInspection(error52 instanceof Error ? error52.message : String(error52));
17070
+ if (error52 instanceof HarnessNotInstalledError)
17071
+ return { status: "notInstalled", error: this.#error(error52) };
17072
+ return failedInspection(describeBrokerFailure(error52, this.harnessId));
16883
17073
  }
16884
17074
  }
16885
17075
  async open(input) {
16886
17076
  if (this.#closed)
16887
17077
  return { ok: false, error: unavailable("Aqua Harness broker adapter is closed", false) };
17078
+ const safeInput = { ...input };
17079
+ delete safeInput.environment;
17080
+ if (this.#forwardEnvironment && input.environment) {
17081
+ const allowed2 = [
17082
+ "CODEXHOST_CLI_PATH",
17083
+ "CODEXHOST_CLI_NODE_PATH",
17084
+ "CODEXHOST_RUNTIME_ENDPOINT",
17085
+ "CODEXHOST_RUNTIME_TOKEN",
17086
+ "CODEXHOST_THREAD_ID"
17087
+ ];
17088
+ const environment = Object.fromEntries(Object.entries(input.environment).filter(([key, value]) => allowed2.includes(key) && value !== void 0));
17089
+ if (Object.keys(environment).length)
17090
+ safeInput.environment = environment;
17091
+ }
16888
17092
  let connection;
16889
17093
  try {
16890
- const safeInput = { ...input };
16891
- delete safeInput.environment;
16892
- if (this.#forwardEnvironment && input.environment) {
16893
- const allowed2 = [
16894
- "CODEXHOST_CLI_PATH",
16895
- "CODEXHOST_CLI_NODE_PATH",
16896
- "CODEXHOST_RUNTIME_ENDPOINT",
16897
- "CODEXHOST_RUNTIME_TOKEN",
16898
- "CODEXHOST_THREAD_ID"
16899
- ];
16900
- const environment = Object.fromEntries(Object.entries(input.environment).filter(([key, value]) => allowed2.includes(key) && value !== void 0));
16901
- if (Object.keys(environment).length)
16902
- safeInput.environment = environment;
16903
- }
16904
- connection = await this.#connect();
16905
- const result = parseHarnessResult(await connection.request("adapter.open", safeInput));
17094
+ let value;
17095
+ for (let attempt = 0; ; attempt += 1) {
17096
+ connection = await this.#connect();
17097
+ try {
17098
+ value = await connection.request("adapter.open", safeInput);
17099
+ break;
17100
+ } catch (error52) {
17101
+ if (attempt > 0 || !(error52 instanceof BrokerRetiringError || error52 instanceof BrokerRequestNotDeliveredError))
17102
+ throw error52;
17103
+ this.#connection = null;
17104
+ }
17105
+ }
17106
+ const result = parseHarnessResult(value);
16906
17107
  if (!result.ok)
16907
17108
  return result;
16908
17109
  const session = new BrokeredHarnessSession(connection, parseSessionMetadata(result.value), this.harnessId, safeInput, () => this.#connect(), () => {
@@ -16913,25 +17114,51 @@ var BrokeredHarnessAdapter = class {
16913
17114
  } catch (error52) {
16914
17115
  connection?.close();
16915
17116
  this.#connection = null;
16916
- return {
16917
- ok: false,
16918
- error: unavailable(error52 instanceof Error ? error52.message : String(error52))
16919
- };
17117
+ return { ok: false, error: this.#error(error52) };
16920
17118
  }
16921
17119
  }
16922
17120
  async close() {
16923
17121
  this.#closed = true;
17122
+ this.#credits = null;
16924
17123
  await Promise.allSettled([...this.#sessions].map((session) => session.close()));
16925
17124
  this.#sessions.clear();
16926
17125
  const connection = await this.#connection?.catch(() => null);
16927
17126
  await connection?.dispose();
16928
17127
  this.#connection = null;
16929
17128
  }
17129
+ #error(error52) {
17130
+ if (error52 instanceof HarnessNotInstalledError)
17131
+ return {
17132
+ code: "notInstalled",
17133
+ message: error52.message,
17134
+ retryable: false,
17135
+ stage: "harnessBroker"
17136
+ };
17137
+ return unavailable(describeBrokerFailure(error52, this.harnessId));
17138
+ }
17139
+ /**
17140
+ * Sends one adapter-level request. A broker that retired between requests refuses it
17141
+ * unprocessed, so it is retried once on a fresh broker. Idempotent reads also retry
17142
+ * once after a plain disconnect.
17143
+ */
17144
+ async #request(method, params, idempotent = false) {
17145
+ for (let attempt = 0; ; attempt += 1) {
17146
+ const connection = await this.#connect();
17147
+ try {
17148
+ return await connection.request(method, params);
17149
+ } catch (error52) {
17150
+ const retryable = error52 instanceof BrokerRetiringError || error52 instanceof BrokerRequestNotDeliveredError || idempotent && connection.closed;
17151
+ if (attempt > 0 || !retryable)
17152
+ throw error52;
17153
+ this.#connection = null;
17154
+ }
17155
+ }
17156
+ }
16930
17157
  #connect() {
16931
17158
  if (this.#closed)
16932
17159
  return Promise.reject(new Error("Aqua Harness broker adapter is closed"));
16933
17160
  if (!this.#connection) {
16934
- const pending = BrokerConnection.connect(this.#descriptorPath, this.harnessId).then((connection) => {
17161
+ const pending = this.#establish().then((connection) => {
16935
17162
  connection.onClose(() => {
16936
17163
  if (this.#connection === pending)
16937
17164
  this.#connection = null;
@@ -16946,6 +17173,28 @@ var BrokeredHarnessAdapter = class {
16946
17173
  }
16947
17174
  return this.#connection;
16948
17175
  }
17176
+ async #establish() {
17177
+ try {
17178
+ return await BrokerConnection.connect(this.#descriptorPath, this.harnessId);
17179
+ } catch (error52) {
17180
+ if (!(error52 instanceof BrokerNotRunningError) || !this.#startBroker)
17181
+ throw error52;
17182
+ }
17183
+ if (this.#isInstalled && !this.#isInstalled()) {
17184
+ throw new HarnessNotInstalledError(`${this.harnessId} is not installed on this Mac`);
17185
+ }
17186
+ const deadline = Date.now() + this.#startTimeoutMs;
17187
+ for (; ; ) {
17188
+ await this.#startBroker();
17189
+ try {
17190
+ return await BrokerConnection.connect(this.#descriptorPath, this.harnessId);
17191
+ } catch (error52) {
17192
+ if (!(error52 instanceof BrokerNotRunningError) || Date.now() >= deadline)
17193
+ throw error52;
17194
+ }
17195
+ await new Promise((resolve2) => setTimeout(resolve2, BROKER_START_POLL_MS));
17196
+ }
17197
+ }
16949
17198
  };
16950
17199
 
16951
17200
  // dist/claude-code-adapter.js
@@ -42832,6 +43081,62 @@ var ClaudeBackgroundOccupancy = class {
42832
43081
  }
42833
43082
  };
42834
43083
 
43084
+ // ../../harness-adapter/dist/session-import.js
43085
+ var SessionImportScope = class {
43086
+ #abort = new AbortController();
43087
+ #options;
43088
+ #pending = /* @__PURE__ */ new Set();
43089
+ constructor(options) {
43090
+ this.#options = options;
43091
+ }
43092
+ #closed() {
43093
+ return {
43094
+ ok: false,
43095
+ error: { code: "invalidState", message: this.#options.closedMessage, retryable: false }
43096
+ };
43097
+ }
43098
+ read(operation) {
43099
+ const signal = this.#abort.signal;
43100
+ if (signal.aborted)
43101
+ return Promise.resolve(this.#closed());
43102
+ let started;
43103
+ try {
43104
+ started = operation(signal);
43105
+ } catch (error52) {
43106
+ started = Promise.reject(error52 instanceof Error ? error52 : new Error("Session read failed"));
43107
+ }
43108
+ const request = started.then((value) => signal.aborted ? this.#closed() : { ok: true, value }).catch(() => signal.aborted ? this.#closed() : {
43109
+ ok: false,
43110
+ error: {
43111
+ code: "unavailable",
43112
+ message: this.#options.unavailableMessage,
43113
+ retryable: true
43114
+ }
43115
+ }).finally(() => this.#pending.delete(request));
43116
+ this.#pending.add(request);
43117
+ return request;
43118
+ }
43119
+ /** `read` for `resolveCandidate`: a null source is the selected Session having disappeared. */
43120
+ async resolve(operation) {
43121
+ const result = await this.read(operation);
43122
+ if (!result.ok)
43123
+ return result;
43124
+ return result.value ? { ok: true, value: result.value } : {
43125
+ ok: false,
43126
+ error: {
43127
+ code: "sessionNotFound",
43128
+ message: this.#options.notFoundMessage,
43129
+ retryable: false
43130
+ }
43131
+ };
43132
+ }
43133
+ /** Idempotent. Resolves after every started read has settled. */
43134
+ async close() {
43135
+ this.#abort.abort();
43136
+ await Promise.allSettled(this.#pending);
43137
+ }
43138
+ };
43139
+
42835
43140
  // dist/command.js
42836
43141
  import path6 from "node:path";
42837
43142
 
@@ -43075,13 +43380,13 @@ function resolveHarnessExecutable(spec, input, dependencies = {}) {
43075
43380
  }
43076
43381
 
43077
43382
  // ../../harness-discovery/dist/installation.js
43078
- import { execFile } from "node:child_process";
43383
+ import { execFile as execFile2 } from "node:child_process";
43079
43384
  import { homedir } from "node:os";
43080
43385
  function runInstallationCommand(command, args, environment, timeout = 3e4) {
43081
43386
  const env = withNodeRuntimeOnPath(environment);
43082
43387
  const invocation = /\.[cm]?js$/i.test(command) ? commandInvocation(process.execPath, [command, ...args], env) : commandInvocation(command, args, env);
43083
43388
  return new Promise((resolve2, reject) => {
43084
- const child = execFile(invocation.command, invocation.arguments, {
43389
+ const child = execFile2(invocation.command, invocation.arguments, {
43085
43390
  env,
43086
43391
  cwd: env.HOME ?? env.USERPROFILE ?? homedir(),
43087
43392
  encoding: "utf8",
@@ -45833,11 +46138,11 @@ async function applyGatewayModelCatalog(snapshot, environment, dependencies = {}
45833
46138
  }
45834
46139
 
45835
46140
  // dist/process-fence.js
45836
- import { execFile as execFile2 } from "node:child_process";
46141
+ import { execFile as execFile3 } from "node:child_process";
45837
46142
  import path15 from "node:path";
45838
46143
  import { setTimeout as setTimeout2 } from "node:timers/promises";
45839
46144
  import { promisify } from "node:util";
45840
- var executeFile = promisify(execFile2);
46145
+ var executeFile = promisify(execFile3);
45841
46146
  function signalGroup(pid, signal) {
45842
46147
  try {
45843
46148
  process.kill(-pid, signal);
@@ -47739,6 +48044,9 @@ var ClaudeHarnessSession = class {
47739
48044
  this.#statePublished = durable;
47740
48045
  this.outputs = this.#channel.outputs;
47741
48046
  }
48047
+ get nativeWriterRef() {
48048
+ return this.#nativeRef;
48049
+ }
47742
48050
  async readSnapshot() {
47743
48051
  if (this.#phase !== "open") {
47744
48052
  return { ok: false, error: invalidState("Claude Code Session is not open") };
@@ -49545,6 +49853,13 @@ var ClaudeCodeAdapter = class {
49545
49853
  commandCatalog = claudeCommandCatalog;
49546
49854
  liveCommandCatalog = true;
49547
49855
  harnessId = claudeCodeHarnessId2;
49856
+ sessionImport = Object.freeze({
49857
+ listCandidates: async () => {
49858
+ const result = await this.#importScope.read((signal) => this.#importIndex.list(signal));
49859
+ return result.ok ? { ok: true, value: result.value.map(({ candidate }) => candidate) } : result;
49860
+ },
49861
+ resolveCandidate: (nativeSessionId) => this.#importScope.resolve((signal) => this.#importIndex.resolve(nativeSessionId, signal))
49862
+ });
49548
49863
  subagents = {
49549
49864
  readSnapshot: async (input) => {
49550
49865
  if (input.parent.harnessId !== this.harnessId || input.nativeSubagentId.trim().length === 0) {
@@ -49585,31 +49900,15 @@ var ClaudeCodeAdapter = class {
49585
49900
  }
49586
49901
  }
49587
49902
  };
49588
- sessionImport = Object.freeze({
49589
- listCandidates: async () => {
49590
- const result = await this.#readImport((signal) => this.#importIndex.list(signal));
49591
- return result.ok ? { ok: true, value: result.value.map(({ candidate }) => candidate) } : result;
49592
- },
49593
- resolveCandidate: async (nativeSessionId) => {
49594
- const result = await this.#readImport((signal) => this.#importIndex.resolve(nativeSessionId, signal));
49595
- if (!result.ok)
49596
- return result;
49597
- return result.value ? { ok: true, value: result.value } : {
49598
- ok: false,
49599
- error: {
49600
- code: "sessionNotFound",
49601
- message: "Claude Code Session is no longer importable",
49602
- retryable: false
49603
- }
49604
- };
49605
- }
49606
- });
49607
49903
  #cancelTimeoutMs;
49608
49904
  #closeTimeoutMs;
49609
49905
  #dependencies;
49610
- #importAbort = new AbortController();
49611
49906
  #importIndex;
49612
- #importRequests = /* @__PURE__ */ new Set();
49907
+ #importScope = new SessionImportScope({
49908
+ closedMessage: "Claude Code Adapter is closed",
49909
+ unavailableMessage: "Claude Code Session discovery failed; check storage access and duplicate Session identities, then retry after closing native clients",
49910
+ notFoundMessage: "Claude Code Session is no longer importable"
49911
+ });
49613
49912
  #pendingSessions;
49614
49913
  #toolOutputLimit;
49615
49914
  #continuationQuiescenceMs;
@@ -49695,24 +49994,6 @@ var ClaudeCodeAdapter = class {
49695
49994
  readSessionMessages: (input) => this.#dependencies.readSessionMessages(input)
49696
49995
  });
49697
49996
  }
49698
- #readImport(operation) {
49699
- if (this.#importAbort.signal.aborted) {
49700
- return Promise.resolve({
49701
- ok: false,
49702
- error: invalidState("Claude Code Adapter is closed")
49703
- });
49704
- }
49705
- const request = operation(this.#importAbort.signal).then((value) => ({ ok: true, value })).catch(() => ({
49706
- ok: false,
49707
- error: {
49708
- code: "unavailable",
49709
- message: "Claude Code Session discovery failed; check native storage access and duplicate Session identities, then retry after closing native clients",
49710
- retryable: true
49711
- }
49712
- })).finally(() => this.#importRequests.delete(request));
49713
- this.#importRequests.add(request);
49714
- return request;
49715
- }
49716
49997
  async inspect(input = {}) {
49717
49998
  if (this.#closePromise) {
49718
49999
  return {
@@ -50038,10 +50319,9 @@ var ClaudeCodeAdapter = class {
50038
50319
  }
50039
50320
  close() {
50040
50321
  if (!this.#closePromise) {
50041
- this.#importAbort.abort();
50042
50322
  this.#inspectionCache.clear();
50043
50323
  this.#closePromise = Promise.all([
50044
- ...this.#importRequests,
50324
+ this.#importScope.close(),
50045
50325
  ...[...this.#inspectors].map((inspector) => inspector.close()),
50046
50326
  ...[...this.#sessions].map((session) => session.close()),
50047
50327
  ...this.#inspectionInFlight.values()
@@ -50119,7 +50399,7 @@ function createClaudeInstallation(environment, command) {
50119
50399
 
50120
50400
  // dist/user-shell-environment.js
50121
50401
  import path18 from "node:path";
50122
- import { execFile as execFile3 } from "node:child_process";
50402
+ import { execFile as execFile4 } from "node:child_process";
50123
50403
  var ENVIRONMENT_MARKER = Buffer.from("\0CODEXHOST_USER_SHELL_ENV_V1\0");
50124
50404
  var ENVIRONMENT_COMMAND = "printf '\\0CODEXHOST_USER_SHELL_ENV_V1\\0'; /usr/bin/env -0";
50125
50405
  var SHELL_ENVIRONMENT_TIMEOUT_MS = 3e3;
@@ -50168,7 +50448,7 @@ async function withUserShellEnvironment(environment, dependencies) {
50168
50448
  if (cached2)
50169
50449
  return mergeMissingEnvironment(environment, cached2);
50170
50450
  const run = dependencies?.run ?? ((command, arguments_, options) => new Promise((resolve2) => {
50171
- const child = execFile3(command, arguments_, {
50451
+ const child = execFile4(command, arguments_, {
50172
50452
  ...options,
50173
50453
  encoding: "buffer",
50174
50454
  killSignal: "SIGKILL"
@@ -50202,6 +50482,17 @@ async function createHarnessAdapter(context) {
50202
50482
  commandCatalog: claudeCommandCatalog,
50203
50483
  liveCommandCatalog: true,
50204
50484
  environment,
50485
+ isInstalled: () => {
50486
+ try {
50487
+ resolveClaudeCodeExecutable({
50488
+ ...environment[CLAUDE_CODE_COMMAND_ENV] ? { command: environment[CLAUDE_CODE_COMMAND_ENV] } : {},
50489
+ environment
50490
+ });
50491
+ return true;
50492
+ } catch (error52) {
50493
+ return !(error52 instanceof ClaudeCodeExecutableError);
50494
+ }
50495
+ },
50205
50496
  ...context.brokerDescriptorPath ? { descriptorPath: context.brokerDescriptorPath } : {}
50206
50497
  });
50207
50498
  }
@@ -50217,6 +50508,8 @@ async function createHarnessAdapter(context) {
50217
50508
  });
50218
50509
  }
50219
50510
  async function warmup(adapter) {
50511
+ if (adapter instanceof BrokeredHarnessAdapter)
50512
+ return;
50220
50513
  try {
50221
50514
  await adapter.inspect();
50222
50515
  } catch {