@liberseek/boft-cli-win32-arm64 0.7.7 → 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",
@@ -15299,7 +15307,10 @@ var harnessInstallationStateSchema = external_exports.object({
15299
15307
  latestVersion: external_exports.string().min(1).max(128),
15300
15308
  updateAvailable: external_exports.boolean(),
15301
15309
  canUpdate: external_exports.boolean(),
15302
- message: external_exports.string().max(2048).optional()
15310
+ // Adapter-owned diagnostic text; UI uses messageCode rather than displaying it verbatim.
15311
+ message: external_exports.string().max(2048).optional(),
15312
+ messageCode: external_exports.string().min(1).max(128).optional(),
15313
+ latestVersionKind: external_exports.enum(["unknown", "tracking-branch"]).optional()
15303
15314
  }).strict();
15304
15315
 
15305
15316
  // ../../shared-contracts/dist/codex-accounts.js
@@ -15594,7 +15605,7 @@ var updateStatusSchema = external_exports.strictObject({
15594
15605
  }
15595
15606
  });
15596
15607
  var updateEmptyParamsSchema = external_exports.strictObject({});
15597
- var githubReleaseNotesUrlSchema = external_exports.string().max(300).regex(/^https:\/\/github\.com\/LiberSeek\/BOFT-CLI\/releases\/tag\/v[0-9A-Za-z.+-]+$/u, "release notes URL must identify a codexhost GitHub Release");
15608
+ var githubReleaseNotesUrlSchema = external_exports.string().max(300).regex(/^https:\/\/github\.com\/(LiberSeek|LIBERSEEK)\/BOFT-CLI\/releases\/tag\/v[0-9A-Za-z.+-]+$/u, "release notes URL must identify a codexhost GitHub Release");
15598
15609
  var updateCheckResultSchema = external_exports.strictObject({
15599
15610
  currentVersion: updateSemanticVersionSchema,
15600
15611
  installation: updateInstallationSchema.nullable(),
@@ -15613,6 +15624,80 @@ var updateStatusResultSchema = external_exports.strictObject({
15613
15624
  status: updateStatusSchema.nullable()
15614
15625
  });
15615
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
+
15616
15701
  // ../../shared-contracts/dist/index.js
15617
15702
  var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
15618
15703
 
@@ -15938,9 +16023,12 @@ var HARNESS_BROKER_MAX_FRAME_BYTES = 8 * 1024 * 1024;
15938
16023
  var HARNESS_BROKER_MAX_PENDING_REQUESTS = 32;
15939
16024
  var HARNESS_BROKER_REQUEST_TIMEOUT_MS = 15e3;
15940
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";
15941
16028
  var harnessBrokerMethodSchema = external_exports.enum([
15942
16029
  "adapter.inspect",
15943
16030
  "adapter.inspectAccount",
16031
+ "adapter.credits",
15944
16032
  "adapter.open",
15945
16033
  "adapter.sessionImport.list",
15946
16034
  "adapter.sessionImport.resolve",
@@ -16060,6 +16148,14 @@ function defaultHarnessBrokerDescriptorPath(environment = process.env, harnessId
16060
16148
  return path.join(defaultHarnessBrokerDirectory(environment), `${harnessId}-broker-v1.json`);
16061
16149
  return environment[HARNESS_BROKER_DESCRIPTOR_ENV] ?? path.join(defaultHarnessBrokerDirectory(environment), HARNESS_BROKER_DESCRIPTOR_FILE);
16062
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
+ }
16063
16159
 
16064
16160
  // ../../harness-broker/dist/validation.js
16065
16161
  var cwdSchema = external_exports.string().min(1).max(16384);
@@ -16386,10 +16482,55 @@ async function readDescriptor(descriptorPath) {
16386
16482
  try {
16387
16483
  process.kill(descriptor.ownerPid, 0);
16388
16484
  } catch {
16389
- throw new Error("Aqua Harness broker owner process is unavailable");
16485
+ throw new BrokerNotRunningError("its owner process has exited");
16390
16486
  }
16391
16487
  return descriptor;
16392
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
+ }
16393
16534
  var BrokerConnection = class _BrokerConnection {
16394
16535
  #onClose;
16395
16536
  onClose(callback) {
@@ -16413,21 +16554,31 @@ var BrokerConnection = class _BrokerConnection {
16413
16554
  socket.once("error", (error52) => this.#fail(error52));
16414
16555
  }
16415
16556
  static async connect(descriptorPath, harnessId) {
16416
- const descriptor = await readDescriptor(descriptorPath);
16417
- if (descriptor.harnessId !== harnessId)
16418
- throw new Error("Aqua broker belongs to another Harness");
16419
- const socket = net.createConnection(descriptor.socketPath);
16420
- await new Promise((resolve2, reject) => {
16421
- const timeout = setTimeout(() => reject(new Error("Timed out connecting to Aqua Harness broker")), HARNESS_BROKER_REQUEST_TIMEOUT_MS);
16422
- socket.once("connect", () => {
16423
- clearTimeout(timeout);
16424
- resolve2();
16425
- });
16426
- socket.once("error", (error52) => {
16427
- clearTimeout(timeout);
16428
- 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
+ });
16429
16576
  });
16430
- });
16577
+ socket = pending;
16578
+ } catch (error52) {
16579
+ connecting?.destroy();
16580
+ throw classifyConnectFailure(error52);
16581
+ }
16431
16582
  const connection = new _BrokerConnection(descriptor, socket);
16432
16583
  const hello = connection.#waitForHello();
16433
16584
  await writeBrokerFrame(socket, {
@@ -16480,15 +16631,24 @@ var BrokerConnection = class _BrokerConnection {
16480
16631
  }, HARNESS_BROKER_REQUEST_TIMEOUT_MS);
16481
16632
  this.#pending.set(id, { resolve: resolve2, reject, timeout });
16482
16633
  });
16483
- await writeBrokerFrame(this.#socket, {
16484
- version: HARNESS_BROKER_PROTOCOL_VERSION,
16485
- generation: this.#descriptor.generation,
16486
- sequence: this.#inputSequence,
16487
- kind: "request",
16488
- id,
16489
- method,
16490
- params
16491
- });
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
+ }
16492
16652
  return response;
16493
16653
  }
16494
16654
  close() {
@@ -16532,6 +16692,8 @@ var BrokerConnection = class _BrokerConnection {
16532
16692
  this.#pending.delete(frame.id);
16533
16693
  if (frame.ok)
16534
16694
  pending.resolve(frame.value);
16695
+ else if (frame.error?.code === HARNESS_BROKER_RETIRING_ERROR_CODE)
16696
+ pending.reject(new BrokerRetiringError(frame.error.message));
16535
16697
  else
16536
16698
  pending.reject(new Error(frame.error?.message ?? "Broker request failed"));
16537
16699
  }
@@ -16757,18 +16919,20 @@ var BrokeredHarnessAdapter = class {
16757
16919
  harnessId;
16758
16920
  #descriptorPath;
16759
16921
  #forwardEnvironment;
16922
+ #isInstalled;
16923
+ #startBroker;
16924
+ #startTimeoutMs;
16760
16925
  #connection = null;
16761
16926
  #closed = false;
16762
16927
  #sessionImportListing = null;
16928
+ #credits = null;
16929
+ #creditsRefresh = null;
16763
16930
  subagents = {
16764
16931
  readSnapshot: async (input) => {
16765
16932
  try {
16766
- return parseHarnessResult(await (await this.#connect()).request("adapter.subagent.readSnapshot", input));
16933
+ return parseHarnessResult(await this.#request("adapter.subagent.readSnapshot", input));
16767
16934
  } catch (error52) {
16768
- return {
16769
- ok: false,
16770
- error: unavailable(error52 instanceof Error ? error52.message : String(error52))
16771
- };
16935
+ return { ok: false, error: this.#error(error52) };
16772
16936
  }
16773
16937
  }
16774
16938
  };
@@ -16858,12 +17022,39 @@ var BrokeredHarnessAdapter = class {
16858
17022
  if (input.liveCommandCatalog)
16859
17023
  this.liveCommandCatalog = true;
16860
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;
16861
17052
  }
16862
17053
  async inspectAccount() {
16863
17054
  if (this.#closed)
16864
17055
  return null;
16865
17056
  try {
16866
- const value = await (await this.#connect()).request("adapter.inspectAccount", {});
17057
+ const value = await this.#request("adapter.inspectAccount", {}, true);
16867
17058
  return harnessAccountSnapshotSchema.nullable().parse(value);
16868
17059
  } catch {
16869
17060
  return null;
@@ -16873,33 +17064,46 @@ var BrokeredHarnessAdapter = class {
16873
17064
  if (this.#closed)
16874
17065
  return failedInspection("Aqua Harness broker adapter is closed");
16875
17066
  try {
16876
- return harnessInspectionSchema.parse(await (await this.#connect()).request("adapter.inspect", input));
17067
+ return harnessInspectionSchema.parse(await this.#request("adapter.inspect", input, true));
16877
17068
  } catch (error52) {
16878
17069
  this.#connection = null;
16879
- 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));
16880
17073
  }
16881
17074
  }
16882
17075
  async open(input) {
16883
17076
  if (this.#closed)
16884
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
+ }
16885
17092
  let connection;
16886
17093
  try {
16887
- const safeInput = { ...input };
16888
- delete safeInput.environment;
16889
- if (this.#forwardEnvironment && input.environment) {
16890
- const allowed2 = [
16891
- "CODEXHOST_CLI_PATH",
16892
- "CODEXHOST_CLI_NODE_PATH",
16893
- "CODEXHOST_RUNTIME_ENDPOINT",
16894
- "CODEXHOST_RUNTIME_TOKEN",
16895
- "CODEXHOST_THREAD_ID"
16896
- ];
16897
- const environment = Object.fromEntries(Object.entries(input.environment).filter(([key, value]) => allowed2.includes(key) && value !== void 0));
16898
- if (Object.keys(environment).length)
16899
- safeInput.environment = environment;
16900
- }
16901
- connection = await this.#connect();
16902
- 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);
16903
17107
  if (!result.ok)
16904
17108
  return result;
16905
17109
  const session = new BrokeredHarnessSession(connection, parseSessionMetadata(result.value), this.harnessId, safeInput, () => this.#connect(), () => {
@@ -16910,25 +17114,51 @@ var BrokeredHarnessAdapter = class {
16910
17114
  } catch (error52) {
16911
17115
  connection?.close();
16912
17116
  this.#connection = null;
16913
- return {
16914
- ok: false,
16915
- error: unavailable(error52 instanceof Error ? error52.message : String(error52))
16916
- };
17117
+ return { ok: false, error: this.#error(error52) };
16917
17118
  }
16918
17119
  }
16919
17120
  async close() {
16920
17121
  this.#closed = true;
17122
+ this.#credits = null;
16921
17123
  await Promise.allSettled([...this.#sessions].map((session) => session.close()));
16922
17124
  this.#sessions.clear();
16923
17125
  const connection = await this.#connection?.catch(() => null);
16924
17126
  await connection?.dispose();
16925
17127
  this.#connection = null;
16926
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
+ }
16927
17157
  #connect() {
16928
17158
  if (this.#closed)
16929
17159
  return Promise.reject(new Error("Aqua Harness broker adapter is closed"));
16930
17160
  if (!this.#connection) {
16931
- const pending = BrokerConnection.connect(this.#descriptorPath, this.harnessId).then((connection) => {
17161
+ const pending = this.#establish().then((connection) => {
16932
17162
  connection.onClose(() => {
16933
17163
  if (this.#connection === pending)
16934
17164
  this.#connection = null;
@@ -16943,6 +17173,28 @@ var BrokeredHarnessAdapter = class {
16943
17173
  }
16944
17174
  return this.#connection;
16945
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
+ }
16946
17198
  };
16947
17199
 
16948
17200
  // dist/claude-code-adapter.js
@@ -42829,6 +43081,62 @@ var ClaudeBackgroundOccupancy = class {
42829
43081
  }
42830
43082
  };
42831
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
+
42832
43140
  // dist/command.js
42833
43141
  import path6 from "node:path";
42834
43142
 
@@ -43072,13 +43380,13 @@ function resolveHarnessExecutable(spec, input, dependencies = {}) {
43072
43380
  }
43073
43381
 
43074
43382
  // ../../harness-discovery/dist/installation.js
43075
- import { execFile } from "node:child_process";
43383
+ import { execFile as execFile2 } from "node:child_process";
43076
43384
  import { homedir } from "node:os";
43077
43385
  function runInstallationCommand(command, args, environment, timeout = 3e4) {
43078
43386
  const env = withNodeRuntimeOnPath(environment);
43079
43387
  const invocation = /\.[cm]?js$/i.test(command) ? commandInvocation(process.execPath, [command, ...args], env) : commandInvocation(command, args, env);
43080
43388
  return new Promise((resolve2, reject) => {
43081
- const child = execFile(invocation.command, invocation.arguments, {
43389
+ const child = execFile2(invocation.command, invocation.arguments, {
43082
43390
  env,
43083
43391
  cwd: env.HOME ?? env.USERPROFILE ?? homedir(),
43084
43392
  encoding: "utf8",
@@ -45830,11 +46138,11 @@ async function applyGatewayModelCatalog(snapshot, environment, dependencies = {}
45830
46138
  }
45831
46139
 
45832
46140
  // dist/process-fence.js
45833
- import { execFile as execFile2 } from "node:child_process";
46141
+ import { execFile as execFile3 } from "node:child_process";
45834
46142
  import path15 from "node:path";
45835
46143
  import { setTimeout as setTimeout2 } from "node:timers/promises";
45836
46144
  import { promisify } from "node:util";
45837
- var executeFile = promisify(execFile2);
46145
+ var executeFile = promisify(execFile3);
45838
46146
  function signalGroup(pid, signal) {
45839
46147
  try {
45840
46148
  process.kill(-pid, signal);
@@ -47736,6 +48044,9 @@ var ClaudeHarnessSession = class {
47736
48044
  this.#statePublished = durable;
47737
48045
  this.outputs = this.#channel.outputs;
47738
48046
  }
48047
+ get nativeWriterRef() {
48048
+ return this.#nativeRef;
48049
+ }
47739
48050
  async readSnapshot() {
47740
48051
  if (this.#phase !== "open") {
47741
48052
  return { ok: false, error: invalidState("Claude Code Session is not open") };
@@ -49542,6 +49853,13 @@ var ClaudeCodeAdapter = class {
49542
49853
  commandCatalog = claudeCommandCatalog;
49543
49854
  liveCommandCatalog = true;
49544
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
+ });
49545
49863
  subagents = {
49546
49864
  readSnapshot: async (input) => {
49547
49865
  if (input.parent.harnessId !== this.harnessId || input.nativeSubagentId.trim().length === 0) {
@@ -49582,31 +49900,15 @@ var ClaudeCodeAdapter = class {
49582
49900
  }
49583
49901
  }
49584
49902
  };
49585
- sessionImport = Object.freeze({
49586
- listCandidates: async () => {
49587
- const result = await this.#readImport((signal) => this.#importIndex.list(signal));
49588
- return result.ok ? { ok: true, value: result.value.map(({ candidate }) => candidate) } : result;
49589
- },
49590
- resolveCandidate: async (nativeSessionId) => {
49591
- const result = await this.#readImport((signal) => this.#importIndex.resolve(nativeSessionId, signal));
49592
- if (!result.ok)
49593
- return result;
49594
- return result.value ? { ok: true, value: result.value } : {
49595
- ok: false,
49596
- error: {
49597
- code: "sessionNotFound",
49598
- message: "Claude Code Session is no longer importable",
49599
- retryable: false
49600
- }
49601
- };
49602
- }
49603
- });
49604
49903
  #cancelTimeoutMs;
49605
49904
  #closeTimeoutMs;
49606
49905
  #dependencies;
49607
- #importAbort = new AbortController();
49608
49906
  #importIndex;
49609
- #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
+ });
49610
49912
  #pendingSessions;
49611
49913
  #toolOutputLimit;
49612
49914
  #continuationQuiescenceMs;
@@ -49692,24 +49994,6 @@ var ClaudeCodeAdapter = class {
49692
49994
  readSessionMessages: (input) => this.#dependencies.readSessionMessages(input)
49693
49995
  });
49694
49996
  }
49695
- #readImport(operation) {
49696
- if (this.#importAbort.signal.aborted) {
49697
- return Promise.resolve({
49698
- ok: false,
49699
- error: invalidState("Claude Code Adapter is closed")
49700
- });
49701
- }
49702
- const request = operation(this.#importAbort.signal).then((value) => ({ ok: true, value })).catch(() => ({
49703
- ok: false,
49704
- error: {
49705
- code: "unavailable",
49706
- message: "Claude Code Session discovery failed; check native storage access and duplicate Session identities, then retry after closing native clients",
49707
- retryable: true
49708
- }
49709
- })).finally(() => this.#importRequests.delete(request));
49710
- this.#importRequests.add(request);
49711
- return request;
49712
- }
49713
49997
  async inspect(input = {}) {
49714
49998
  if (this.#closePromise) {
49715
49999
  return {
@@ -50035,10 +50319,9 @@ var ClaudeCodeAdapter = class {
50035
50319
  }
50036
50320
  close() {
50037
50321
  if (!this.#closePromise) {
50038
- this.#importAbort.abort();
50039
50322
  this.#inspectionCache.clear();
50040
50323
  this.#closePromise = Promise.all([
50041
- ...this.#importRequests,
50324
+ this.#importScope.close(),
50042
50325
  ...[...this.#inspectors].map((inspector) => inspector.close()),
50043
50326
  ...[...this.#sessions].map((session) => session.close()),
50044
50327
  ...this.#inspectionInFlight.values()
@@ -50103,6 +50386,7 @@ function createClaudeInstallation(environment, command) {
50103
50386
  updateAvailable: newerInstallationVersion(currentVersion, latestVersion),
50104
50387
  canUpdate,
50105
50388
  ...!canUpdate ? {
50389
+ messageCode: blocked ? "claude-policy-restricted" : "original-installer",
50106
50390
  message: blocked ? "Claude updates are restricted by the installation's settings or policy." : "Use the original installer or package manager for this Claude installation."
50107
50391
  } : {}
50108
50392
  };
@@ -50115,7 +50399,7 @@ function createClaudeInstallation(environment, command) {
50115
50399
 
50116
50400
  // dist/user-shell-environment.js
50117
50401
  import path18 from "node:path";
50118
- import { execFile as execFile3 } from "node:child_process";
50402
+ import { execFile as execFile4 } from "node:child_process";
50119
50403
  var ENVIRONMENT_MARKER = Buffer.from("\0CODEXHOST_USER_SHELL_ENV_V1\0");
50120
50404
  var ENVIRONMENT_COMMAND = "printf '\\0CODEXHOST_USER_SHELL_ENV_V1\\0'; /usr/bin/env -0";
50121
50405
  var SHELL_ENVIRONMENT_TIMEOUT_MS = 3e3;
@@ -50164,7 +50448,7 @@ async function withUserShellEnvironment(environment, dependencies) {
50164
50448
  if (cached2)
50165
50449
  return mergeMissingEnvironment(environment, cached2);
50166
50450
  const run = dependencies?.run ?? ((command, arguments_, options) => new Promise((resolve2) => {
50167
- const child = execFile3(command, arguments_, {
50451
+ const child = execFile4(command, arguments_, {
50168
50452
  ...options,
50169
50453
  encoding: "buffer",
50170
50454
  killSignal: "SIGKILL"
@@ -50198,6 +50482,17 @@ async function createHarnessAdapter(context) {
50198
50482
  commandCatalog: claudeCommandCatalog,
50199
50483
  liveCommandCatalog: true,
50200
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
+ },
50201
50496
  ...context.brokerDescriptorPath ? { descriptorPath: context.brokerDescriptorPath } : {}
50202
50497
  });
50203
50498
  }
@@ -50213,6 +50508,8 @@ async function createHarnessAdapter(context) {
50213
50508
  });
50214
50509
  }
50215
50510
  async function warmup(adapter) {
50511
+ if (adapter instanceof BrokeredHarnessAdapter)
50512
+ return;
50216
50513
  try {
50217
50514
  await adapter.inspect();
50218
50515
  } catch {