codeam-cli 2.76.9 → 2.76.11

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 (3) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/index.js +1093 -575
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -90,11 +90,11 @@ var require_src = __commonJS({
90
90
  });
91
91
 
92
92
  // src/integrations/stdio-proxy.ts
93
- var import_node_child_process36, import_node_readline3, RESTART_CHECK_INTERVAL_MS, SIGKILL_ESCALATION_MS, TOOL_CALL_TIMEOUT_MS, REPLAY_INIT_ID, RestartableStdioProxy;
93
+ var import_node_child_process37, import_node_readline3, RESTART_CHECK_INTERVAL_MS, SIGKILL_ESCALATION_MS, TOOL_CALL_TIMEOUT_MS, REPLAY_INIT_ID, RestartableStdioProxy;
94
94
  var init_stdio_proxy = __esm({
95
95
  "src/integrations/stdio-proxy.ts"() {
96
96
  "use strict";
97
- import_node_child_process36 = require("child_process");
97
+ import_node_child_process37 = require("child_process");
98
98
  import_node_readline3 = __toESM(require("readline"));
99
99
  RESTART_CHECK_INTERVAL_MS = 3e4;
100
100
  SIGKILL_ESCALATION_MS = 2e3;
@@ -128,11 +128,11 @@ var init_stdio_proxy = __esm({
128
128
  rl.on("close", () => this.child?.stdin?.end());
129
129
  const timer = setInterval(() => this.checkRestart(stdout), RESTART_CHECK_INTERVAL_MS);
130
130
  timer.unref();
131
- return new Promise((resolve12) => {
131
+ return new Promise((resolve14) => {
132
132
  this.ended = (code) => {
133
133
  clearInterval(timer);
134
134
  process.exitCode = code;
135
- resolve12();
135
+ resolve14();
136
136
  };
137
137
  });
138
138
  }
@@ -271,7 +271,7 @@ var init_stdio_proxy = __esm({
271
271
  }
272
272
  async spawnChild(stdout, preResolved) {
273
273
  const spec = preResolved ?? await this.opts.spawnSpec();
274
- const spawn46 = this.opts.spawnImpl ?? import_node_child_process36.spawn;
274
+ const spawn46 = this.opts.spawnImpl ?? import_node_child_process37.spawn;
275
275
  const child = spawn46(spec.command, spec.args, {
276
276
  env: { ...process.env, ...spec.env },
277
277
  // env only — never argv
@@ -313,18 +313,18 @@ function deploymentNameFromKey(key) {
313
313
  return null;
314
314
  }
315
315
  function defaultSpawn(timeoutMs) {
316
- return (cmd, args2, opts) => new Promise((resolve12) => {
316
+ return (cmd, args2, opts) => new Promise((resolve14) => {
317
317
  let out2 = "";
318
318
  let err = "";
319
319
  let done = false;
320
320
  const finish = (code) => {
321
321
  if (done) return;
322
322
  done = true;
323
- resolve12({ code, stdout: out2, stderr: err });
323
+ resolve14({ code, stdout: out2, stderr: err });
324
324
  };
325
325
  let child;
326
326
  try {
327
- child = (0, import_node_child_process37.spawn)(cmd, args2, { cwd: opts.cwd, env: opts.env, stdio: ["ignore", "pipe", "pipe"] });
327
+ child = (0, import_node_child_process38.spawn)(cmd, args2, { cwd: opts.cwd, env: opts.env, stdio: ["ignore", "pipe", "pipe"] });
328
328
  } catch (e) {
329
329
  finish(1);
330
330
  err = e instanceof Error ? e.message : String(e);
@@ -357,8 +357,8 @@ function defaultSpawn(timeoutMs) {
357
357
  });
358
358
  }
359
359
  function resolveConvexBin(cwd) {
360
- const local = path107.join(cwd, "node_modules", ".bin", process.platform === "win32" ? "convex.cmd" : "convex");
361
- if (fs93.existsSync(local)) return { cmd: local, args: [] };
360
+ const local = path110.join(cwd, "node_modules", ".bin", process.platform === "win32" ? "convex.cmd" : "convex");
361
+ if (fs96.existsSync(local)) return { cmd: local, args: [] };
362
362
  return { cmd: "npx", args: ["--yes", "convex"] };
363
363
  }
364
364
  function redact(text, key) {
@@ -489,13 +489,13 @@ async function runConvexAdminMcp(client3, id) {
489
489
  });
490
490
  await server.connect(new StdioServerTransport());
491
491
  }
492
- var import_node_child_process37, fs93, path107, TOOLS;
492
+ var import_node_child_process38, fs96, path110, TOOLS;
493
493
  var init_convex_admin_mcp = __esm({
494
494
  "src/integrations/convex-admin-mcp.ts"() {
495
495
  "use strict";
496
- import_node_child_process37 = require("child_process");
497
- fs93 = __toESM(require("fs"));
498
- path107 = __toESM(require("path"));
496
+ import_node_child_process38 = require("child_process");
497
+ fs96 = __toESM(require("fs"));
498
+ path110 = __toESM(require("path"));
499
499
  TOOLS = [
500
500
  {
501
501
  name: "tables",
@@ -656,7 +656,7 @@ async function runHttpRelay(delivery, client3, id) {
656
656
  requestInit: { headers: buildHttpHeaders(delivery.httpHeaders, token) }
657
657
  });
658
658
  const stdioTransport = new StdioServerTransport();
659
- await new Promise((resolve12, reject) => {
659
+ await new Promise((resolve14, reject) => {
660
660
  let done = false;
661
661
  const watchdog = createToolCallWatchdog({
662
662
  timeoutMs: TOOL_CALL_TIMEOUT_MS,
@@ -670,7 +670,7 @@ async function runHttpRelay(delivery, client3, id) {
670
670
  void httpTransport.close().catch(() => void 0);
671
671
  void stdioTransport.close().catch(() => void 0);
672
672
  if (err) reject(err);
673
- else resolve12();
673
+ else resolve14();
674
674
  };
675
675
  stdioTransport.onmessage = (msg) => {
676
676
  watchdog.onClientMessage(msg);
@@ -3595,11 +3595,11 @@ function quiet(fn) {
3595
3595
  log.debug(TAG, "ignored sync error", err);
3596
3596
  }
3597
3597
  }
3598
- function rmIfExistsQuiet(path109) {
3598
+ function rmIfExistsQuiet(path112) {
3599
3599
  try {
3600
- fs2.rmSync(path109, { force: true });
3600
+ fs2.rmSync(path112, { force: true });
3601
3601
  } catch (err) {
3602
- log.debug(TAG, `rmIfExists failed for ${path109}`, err);
3602
+ log.debug(TAG, `rmIfExists failed for ${path112}`, err);
3603
3603
  }
3604
3604
  }
3605
3605
  function killQuiet(target, signal = "SIGTERM") {
@@ -3803,8 +3803,8 @@ function createGetModuleFromFilename(basePath = process.argv[1] ? (0, import_pat
3803
3803
  return decodedFile;
3804
3804
  };
3805
3805
  }
3806
- function normalizeWindowsPath(path109) {
3807
- return path109.replace(/^[A-Z]:/, "").replace(/\\/g, "/");
3806
+ function normalizeWindowsPath(path112) {
3807
+ return path112.replace(/^[A-Z]:/, "").replace(/\\/g, "/");
3808
3808
  }
3809
3809
 
3810
3810
  // ../../node_modules/@posthog/core/dist/error-tracking/index.mjs
@@ -4726,11 +4726,11 @@ async function raceWithTimeout(promise, timeoutMs, onTimeout) {
4726
4726
  try {
4727
4727
  return await Promise.race([
4728
4728
  promise,
4729
- new Promise((resolve12, reject) => {
4729
+ new Promise((resolve14, reject) => {
4730
4730
  timeoutHandle = safeSetTimeout(() => {
4731
4731
  try {
4732
4732
  onTimeout?.();
4733
- resolve12();
4733
+ resolve14();
4734
4734
  } catch (error) {
4735
4735
  reject(error);
4736
4736
  }
@@ -6537,13 +6537,13 @@ var PostHogCoreStateless = class {
6537
6537
  sentFromRoute += batchMessages.length;
6538
6538
  }
6539
6539
  }
6540
- async _sendOtlpBatch({ path: path109, payload }) {
6540
+ async _sendOtlpBatch({ path: path112, payload }) {
6541
6541
  if (this.disabled) return {
6542
6542
  kind: "fatal",
6543
6543
  error: new Error("The client is disabled")
6544
6544
  };
6545
6545
  const serialized = JSON.stringify(payload);
6546
- const url2 = `${this.host}/i/v1/${path109}?token=${encodeURIComponent(this.apiKey)}`;
6546
+ const url2 = `${this.host}/i/v1/${path112}?token=${encodeURIComponent(this.apiKey)}`;
6547
6547
  const gzippedPayload = this.disableCompression ? null : await this.compressPayload(serialized);
6548
6548
  const fetchOptions = {
6549
6549
  method: "POST",
@@ -7783,14 +7783,14 @@ async function addSourceContext(frames, openSourceFile = import_promises.open, l
7783
7783
  LRU_FILE_CONTENTS_CACHE.reduce();
7784
7784
  return frames;
7785
7785
  }
7786
- async function openRegularSourceFile(path109, openSourceFile, logger) {
7786
+ async function openRegularSourceFile(path112, openSourceFile, logger) {
7787
7787
  let fileHandle;
7788
7788
  let isValid = false;
7789
7789
  try {
7790
- fileHandle = await openSourceFile(path109, import_node_fs.constants.O_RDONLY | import_node_fs.constants.O_NONBLOCK);
7790
+ fileHandle = await openSourceFile(path112, import_node_fs.constants.O_RDONLY | import_node_fs.constants.O_NONBLOCK);
7791
7791
  const fileStat = await fileHandle.stat();
7792
7792
  if (!fileStat.isFile()) return;
7793
- if (fileStat.size > MAX_CONTEXTLINES_FILE_SIZE) return void logger?.debug(`Skipping source context for oversized file ${path109}: ${fileStat.size} bytes exceeds ${MAX_CONTEXTLINES_FILE_SIZE}`);
7793
+ if (fileStat.size > MAX_CONTEXTLINES_FILE_SIZE) return void logger?.debug(`Skipping source context for oversized file ${path112}: ${fileStat.size} bytes exceeds ${MAX_CONTEXTLINES_FILE_SIZE}`);
7794
7794
  isValid = true;
7795
7795
  return fileHandle;
7796
7796
  } catch {
@@ -7800,17 +7800,17 @@ async function openRegularSourceFile(path109, openSourceFile, logger) {
7800
7800
  });
7801
7801
  }
7802
7802
  }
7803
- async function getContextLinesFromFile(path109, ranges, output, cacheKey, openSourceFile, logger) {
7804
- const fileHandle = await openRegularSourceFile(path109, openSourceFile, logger);
7803
+ async function getContextLinesFromFile(path112, ranges, output, cacheKey, openSourceFile, logger) {
7804
+ const fileHandle = await openRegularSourceFile(path112, openSourceFile, logger);
7805
7805
  if (void 0 === fileHandle) return void LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1);
7806
7806
  const openedFileHandle = fileHandle;
7807
- return new Promise((resolve12) => {
7807
+ return new Promise((resolve14) => {
7808
7808
  let finished = false;
7809
7809
  function destroyStreamAndResolve(stream2) {
7810
7810
  if (finished) return;
7811
7811
  finished = true;
7812
7812
  stream2?.destroy();
7813
- openedFileHandle.close().then(resolve12, resolve12);
7813
+ openedFileHandle.close().then(resolve14, resolve14);
7814
7814
  }
7815
7815
  let stream;
7816
7816
  try {
@@ -7903,22 +7903,22 @@ function clearLineContext(frame) {
7903
7903
  delete frame.context_line;
7904
7904
  delete frame.post_context;
7905
7905
  }
7906
- function shouldSkipContextLinesForFile(path109) {
7907
- return path109.startsWith("node:") || path109.endsWith(".min.js") || path109.endsWith(".min.cjs") || path109.endsWith(".min.mjs") || path109.startsWith("data:");
7906
+ function shouldSkipContextLinesForFile(path112) {
7907
+ return path112.startsWith("node:") || path112.endsWith(".min.js") || path112.endsWith(".min.cjs") || path112.endsWith(".min.mjs") || path112.startsWith("data:");
7908
7908
  }
7909
7909
  function shouldSkipContextLinesForFrame(frame) {
7910
7910
  if (void 0 !== frame.lineno && frame.lineno > MAX_CONTEXTLINES_LINENO) return true;
7911
7911
  if (void 0 !== frame.colno && frame.colno > MAX_CONTEXTLINES_COLNO) return true;
7912
7912
  return false;
7913
7913
  }
7914
- function makeSourceCacheKey(path109, basePath) {
7915
- if ((0, import_node_path.isAbsolute)(path109)) return JSON.stringify([
7914
+ function makeSourceCacheKey(path112, basePath) {
7915
+ if ((0, import_node_path.isAbsolute)(path112)) return JSON.stringify([
7916
7916
  null,
7917
- path109
7917
+ path112
7918
7918
  ]);
7919
7919
  return void 0 === basePath ? void 0 : JSON.stringify([
7920
7920
  basePath,
7921
- path109
7921
+ path112
7922
7922
  ]);
7923
7923
  }
7924
7924
  function rangeExistsInContentCache(cacheKey, range) {
@@ -8999,7 +8999,7 @@ var V1CaptureSender = class {
8999
8999
  this.fetchFn = hooks.fetch;
9000
9000
  this.onError = hooks.onError;
9001
9001
  this.now = hooks.now ?? Date.now;
9002
- this.sleep = hooks.sleep ?? ((ms) => new Promise((resolve12) => safeSetTimeout(resolve12, ms)));
9002
+ this.sleep = hooks.sleep ?? ((ms) => new Promise((resolve14) => safeSetTimeout(resolve14, ms)));
9003
9003
  this.generateRequestId = hooks.generateRequestId ?? uuidv7;
9004
9004
  this.compress = hooks.compress ?? gzipCompress;
9005
9005
  }
@@ -9363,9 +9363,9 @@ var PostHogBackendClient = class extends PostHogCoreStateless {
9363
9363
  if (!waitUntil) return;
9364
9364
  if (this.disabled || this.optedOut) return;
9365
9365
  if (!this._waitUntilCycle) {
9366
- let resolve12;
9366
+ let resolve14;
9367
9367
  const promise = new Promise((r) => {
9368
- resolve12 = r;
9368
+ resolve14 = r;
9369
9369
  });
9370
9370
  try {
9371
9371
  waitUntil(promise);
@@ -9373,7 +9373,7 @@ var PostHogBackendClient = class extends PostHogCoreStateless {
9373
9373
  return;
9374
9374
  }
9375
9375
  this._waitUntilCycle = {
9376
- resolve: resolve12,
9376
+ resolve: resolve14,
9377
9377
  startedAt: Date.now(),
9378
9378
  timer: void 0
9379
9379
  };
@@ -9397,12 +9397,12 @@ var PostHogBackendClient = class extends PostHogCoreStateless {
9397
9397
  return cycle?.resolve;
9398
9398
  }
9399
9399
  async resolveWaitUntilFlush() {
9400
- const resolve12 = this._consumeWaitUntilCycle();
9400
+ const resolve14 = this._consumeWaitUntilCycle();
9401
9401
  try {
9402
9402
  await this.flushWithPendingPromises();
9403
9403
  } catch {
9404
9404
  } finally {
9405
- resolve12?.();
9405
+ resolve14?.();
9406
9406
  }
9407
9407
  }
9408
9408
  getPersistedProperty(key) {
@@ -9660,15 +9660,15 @@ var PostHogBackendClient = class extends PostHogCoreStateless {
9660
9660
  async waitForLocalEvaluationReady(timeoutMs = THIRTY_SECONDS) {
9661
9661
  if (this.isLocalEvaluationReady()) return true;
9662
9662
  if (void 0 === this.featureFlagsPoller) return false;
9663
- return new Promise((resolve12) => {
9663
+ return new Promise((resolve14) => {
9664
9664
  const timeout = setTimeout(() => {
9665
9665
  cleanup();
9666
- resolve12(false);
9666
+ resolve14(false);
9667
9667
  }, timeoutMs);
9668
9668
  const cleanup = this._events.on("localEvaluationFlagsLoaded", (count) => {
9669
9669
  clearTimeout(timeout);
9670
9670
  cleanup();
9671
- resolve12(count > 0);
9671
+ resolve14(count > 0);
9672
9672
  });
9673
9673
  });
9674
9674
  }
@@ -10172,7 +10172,7 @@ var PostHogBackendClient = class extends PostHogCoreStateless {
10172
10172
  }
10173
10173
  async _shutdown(shutdownTimeoutMs) {
10174
10174
  const shutdownDeadlineMs = Date.now() + (shutdownTimeoutMs ?? 3e4);
10175
- const resolve12 = this._consumeWaitUntilCycle();
10175
+ const resolve14 = this._consumeWaitUntilCycle();
10176
10176
  await this.featureFlagsPoller?.stopPoller(shutdownTimeoutMs);
10177
10177
  this.errorTracking.shutdown();
10178
10178
  if (this._metrics) {
@@ -10184,7 +10184,7 @@ var PostHogBackendClient = class extends PostHogCoreStateless {
10184
10184
  return await super._shutdown(Math.max(0, shutdownDeadlineMs - Date.now()));
10185
10185
  } finally {
10186
10186
  this.distinctIdHasSentFlagCalls = {};
10187
- resolve12?.();
10187
+ resolve14?.();
10188
10188
  }
10189
10189
  }
10190
10190
  async _requestRemoteConfigPayload(flagKey) {
@@ -10579,7 +10579,7 @@ function readAnonId() {
10579
10579
  }
10580
10580
  function superProperties() {
10581
10581
  return {
10582
- cliVersion: true ? "2.76.9" : "0.0.0-dev",
10582
+ cliVersion: true ? "2.76.11" : "0.0.0-dev",
10583
10583
  nodeVersion: process.version,
10584
10584
  platform: process.platform,
10585
10585
  arch: process.arch,
@@ -10726,10 +10726,10 @@ var _execSeam = {
10726
10726
  }
10727
10727
  };
10728
10728
  var _execSeamAsync = {
10729
- exec: (file, args2, opts) => new Promise((resolve12, reject) => {
10729
+ exec: (file, args2, opts) => new Promise((resolve14, reject) => {
10730
10730
  (0, import_child_process.execFile)(file, args2, opts, (err, stdout) => {
10731
10731
  if (err) reject(err);
10732
- else resolve12(typeof stdout === "string" ? stdout : stdout.toString("utf8"));
10732
+ else resolve14(typeof stdout === "string" ? stdout : stdout.toString("utf8"));
10733
10733
  });
10734
10734
  })
10735
10735
  };
@@ -10824,7 +10824,7 @@ var http = __toESM(require("http"));
10824
10824
  // package.json
10825
10825
  var package_default = {
10826
10826
  name: "codeam-cli",
10827
- version: "2.76.9",
10827
+ version: "2.76.11",
10828
10828
  description: "Workflow-continuity bridge for AI coding agents. Wrap Claude Code or Codex in a PTY and supervise, approve, and redirect the session from any device \u2014 async. The terminal companion for CodeAgent Mobile.",
10829
10829
  type: "commonjs",
10830
10830
  main: "dist/index.js",
@@ -10958,8 +10958,8 @@ async function requestCode(pluginId, pluginSecretHash) {
10958
10958
  });
10959
10959
  let timer;
10960
10960
  const timeoutSentinel = /* @__PURE__ */ Symbol("request-code-timeout");
10961
- const timeoutPromise = new Promise((resolve12) => {
10962
- timer = setTimeout(() => resolve12(timeoutSentinel), REQUEST_CODE_TIMEOUT_MS);
10961
+ const timeoutPromise = new Promise((resolve14) => {
10962
+ timer = setTimeout(() => resolve14(timeoutSentinel), REQUEST_CODE_TIMEOUT_MS);
10963
10963
  });
10964
10964
  const result = await Promise.race([post3, timeoutPromise]);
10965
10965
  clearTimeout(timer);
@@ -11413,7 +11413,7 @@ async function postBeadsProvisioning(input) {
11413
11413
  }
11414
11414
  }
11415
11415
  async function _postJsonAuthed(url2, body, pluginAuthToken) {
11416
- return new Promise((resolve12, reject) => {
11416
+ return new Promise((resolve14, reject) => {
11417
11417
  const data = JSON.stringify(body);
11418
11418
  const u2 = new URL(url2);
11419
11419
  const transport = u2.protocol === "https:" ? https : http;
@@ -11443,9 +11443,9 @@ async function _postJsonAuthed(url2, body, pluginAuthToken) {
11443
11443
  return;
11444
11444
  }
11445
11445
  try {
11446
- resolve12(JSON.parse(responseBody));
11446
+ resolve14(JSON.parse(responseBody));
11447
11447
  } catch {
11448
- resolve12(null);
11448
+ resolve14(null);
11449
11449
  }
11450
11450
  });
11451
11451
  }
@@ -11471,7 +11471,7 @@ function makeHttpError(statusCode, retryAfterHeader, responseBody) {
11471
11471
  return err;
11472
11472
  }
11473
11473
  async function _postJson(url2, body, extraHeaders) {
11474
- return new Promise((resolve12, reject) => {
11474
+ return new Promise((resolve14, reject) => {
11475
11475
  const data = JSON.stringify(body);
11476
11476
  const u2 = new URL(url2);
11477
11477
  const transport = u2.protocol === "https:" ? https : http;
@@ -11501,9 +11501,9 @@ async function _postJson(url2, body, extraHeaders) {
11501
11501
  return;
11502
11502
  }
11503
11503
  try {
11504
- resolve12(JSON.parse(body2));
11504
+ resolve14(JSON.parse(body2));
11505
11505
  } catch {
11506
- resolve12(null);
11506
+ resolve14(null);
11507
11507
  }
11508
11508
  });
11509
11509
  }
@@ -11518,7 +11518,7 @@ async function _postJson(url2, body, extraHeaders) {
11518
11518
  });
11519
11519
  }
11520
11520
  async function _getJson(url2, extraHeaders) {
11521
- return new Promise((resolve12, reject) => {
11521
+ return new Promise((resolve14, reject) => {
11522
11522
  const u2 = new URL(url2);
11523
11523
  const transport = u2.protocol === "https:" ? https : http;
11524
11524
  const req = transport.request(
@@ -11542,9 +11542,9 @@ async function _getJson(url2, extraHeaders) {
11542
11542
  return;
11543
11543
  }
11544
11544
  try {
11545
- resolve12(JSON.parse(body));
11545
+ resolve14(JSON.parse(body));
11546
11546
  } catch {
11547
- resolve12(null);
11547
+ resolve14(null);
11548
11548
  }
11549
11549
  });
11550
11550
  }
@@ -12160,7 +12160,7 @@ var CommandRelayService = class _CommandRelayService {
12160
12160
  // fresh + clear the "CLI update available" banner after a self-update
12161
12161
  // (a codespace that reinstalls @latest reconnects via heartbeat, not
12162
12162
  // pair/reconnect). Older backends ignore the extra field.
12163
- ..."2.76.9" ? { ideVersion: "2.76.9" } : {}
12163
+ ..."2.76.11" ? { ideVersion: "2.76.11" } : {}
12164
12164
  };
12165
12165
  try {
12166
12166
  const res = await _postJson(`${API_BASE2}/api/plugin/heartbeat`, body);
@@ -12305,8 +12305,8 @@ async function stopRelayWithGoodbye(relay, timeoutMs = RELAY_GOODBYE_TIMEOUT_MS)
12305
12305
  try {
12306
12306
  await Promise.race([
12307
12307
  relay.stopAndFlush(),
12308
- new Promise((resolve12) => {
12309
- timer = setTimeout(resolve12, timeoutMs);
12308
+ new Promise((resolve14) => {
12309
+ timer = setTimeout(resolve14, timeoutMs);
12310
12310
  })
12311
12311
  ]);
12312
12312
  } catch {
@@ -12415,7 +12415,7 @@ var _transport2 = {
12415
12415
  post: _post
12416
12416
  };
12417
12417
  function _post(url2, headers, payload) {
12418
- return new Promise((resolve12, reject) => {
12418
+ return new Promise((resolve14, reject) => {
12419
12419
  let settled = false;
12420
12420
  const u2 = new URL(url2);
12421
12421
  const lib = u2.protocol === "https:" ? https3 : http3;
@@ -12440,7 +12440,7 @@ function _post(url2, headers, payload) {
12440
12440
  res.on("end", () => {
12441
12441
  if (settled) return;
12442
12442
  settled = true;
12443
- resolve12({ statusCode: res.statusCode ?? 0, body });
12443
+ resolve14({ statusCode: res.statusCode ?? 0, body });
12444
12444
  });
12445
12445
  }
12446
12446
  );
@@ -12478,10 +12478,10 @@ var WINDOWS_LEGACY_JUNCTIONS = [
12478
12478
  /[\\/]Start Menu([\\/]|$)/i,
12479
12479
  /[\\/]Templates([\\/]|$)/i
12480
12480
  ];
12481
- function isUnsafeWindowsWatchRoot(dir, homedir52) {
12481
+ function isUnsafeWindowsWatchRoot(dir, homedir54) {
12482
12482
  const norm = (p2) => p2.replace(/\//g, "\\").replace(/\\+$/, "").toLowerCase();
12483
12483
  const cwd = norm(dir);
12484
- const home = norm(homedir52);
12484
+ const home = norm(homedir54);
12485
12485
  if (cwd === home) return true;
12486
12486
  if (/^[a-z]:$/.test(cwd)) return true;
12487
12487
  const sysRoots = [
@@ -13139,12 +13139,12 @@ var _gitSeam = {
13139
13139
  run: _runGitImpl
13140
13140
  };
13141
13141
  async function _runGitImpl(cwd, args2, opts = {}) {
13142
- return new Promise((resolve12) => {
13142
+ return new Promise((resolve14) => {
13143
13143
  let proc;
13144
13144
  try {
13145
13145
  proc = (0, import_child_process3.spawn)("git", args2, { cwd, env: process.env });
13146
13146
  } catch {
13147
- resolve12(null);
13147
+ resolve14(null);
13148
13148
  return;
13149
13149
  }
13150
13150
  let stdout = "";
@@ -13155,13 +13155,13 @@ async function _runGitImpl(cwd, args2, opts = {}) {
13155
13155
  proc.stderr?.on("data", (c2) => {
13156
13156
  stderr += c2.toString();
13157
13157
  });
13158
- proc.on("error", () => resolve12(null));
13158
+ proc.on("error", () => resolve14(null));
13159
13159
  proc.on("close", (code) => {
13160
13160
  if (code === 0 || opts.allowNonZeroExit) {
13161
- resolve12(stdout);
13161
+ resolve14(stdout);
13162
13162
  } else {
13163
13163
  log.trace("fileWatcher", `git ${args2.join(" ")} exited ${code} stderr=${stderr.slice(0, 200)}`);
13164
- resolve12(null);
13164
+ resolve14(null);
13165
13165
  }
13166
13166
  });
13167
13167
  });
@@ -13247,7 +13247,7 @@ var ChunkEmitter = class {
13247
13247
  if (this.pairingInvalid) {
13248
13248
  return Promise.resolve({ dead: true });
13249
13249
  }
13250
- return new Promise((resolve12) => {
13250
+ return new Promise((resolve14) => {
13251
13251
  let refreshedOnce = false;
13252
13252
  const attempt = (attemptsLeft) => {
13253
13253
  _transport3.post(this.url, this.headers, payload).then(({ statusCode, body: resBody }) => {
@@ -13255,13 +13255,13 @@ var ChunkEmitter = class {
13255
13255
  if (statusCode === 410 || statusCode === 404 && /SESSION_NOT_FOUND|SESSION_GONE/.test(resBody)) {
13256
13256
  process.stderr.write("[codeam] session was deleted/disconnected \u2014 stopping output stream.\n");
13257
13257
  log.info("chunkEmitter", `dead status=${statusCode} took=${tookMs}ms`);
13258
- resolve12({ dead: true });
13258
+ resolve14({ dead: true });
13259
13259
  return;
13260
13260
  }
13261
13261
  if (statusCode === 401 || statusCode === 403) {
13262
13262
  if (refreshedOnce) {
13263
13263
  this.markPairingInvalid(statusCode, tookMs);
13264
- resolve12({ dead: true });
13264
+ resolve14({ dead: true });
13265
13265
  return;
13266
13266
  }
13267
13267
  log.warn("chunkEmitter", `auth ${statusCode} took=${tookMs}ms \u2014 attempting silent refresh`);
@@ -13277,10 +13277,10 @@ var ChunkEmitter = class {
13277
13277
  }
13278
13278
  if (refresh.kind === "gone") {
13279
13279
  this.markPairingInvalid(statusCode, tookMs);
13280
- resolve12({ dead: true });
13280
+ resolve14({ dead: true });
13281
13281
  return;
13282
13282
  }
13283
- resolve12({ dead: false });
13283
+ resolve14({ dead: false });
13284
13284
  })();
13285
13285
  return;
13286
13286
  }
@@ -13291,7 +13291,7 @@ var ChunkEmitter = class {
13291
13291
  } else {
13292
13292
  log.info("chunkEmitter", `ok status=${statusCode} took=${tookMs}ms`);
13293
13293
  }
13294
- resolve12({ dead: false });
13294
+ resolve14({ dead: false });
13295
13295
  }).catch((err) => {
13296
13296
  log.warn(
13297
13297
  "chunkEmitter",
@@ -13302,7 +13302,7 @@ var ChunkEmitter = class {
13302
13302
  const delay = 200 * (maxRetries - attemptsLeft + 1);
13303
13303
  setTimeout(() => attempt(attemptsLeft - 1), delay);
13304
13304
  } else {
13305
- resolve12({ dead: false });
13305
+ resolve14({ dead: false });
13306
13306
  }
13307
13307
  });
13308
13308
  };
@@ -13325,7 +13325,7 @@ var _transport3 = {
13325
13325
  post: _post2
13326
13326
  };
13327
13327
  function _post2(url2, headers, payload) {
13328
- return new Promise((resolve12, reject) => {
13328
+ return new Promise((resolve14, reject) => {
13329
13329
  let settled = false;
13330
13330
  const u2 = new URL(url2);
13331
13331
  const transport = u2.protocol === "https:" ? https4 : http4;
@@ -13349,7 +13349,7 @@ function _post2(url2, headers, payload) {
13349
13349
  res.on("end", () => {
13350
13350
  if (settled) return;
13351
13351
  settled = true;
13352
- resolve12({ statusCode: res.statusCode ?? 0, body: resData });
13352
+ resolve14({ statusCode: res.statusCode ?? 0, body: resData });
13353
13353
  });
13354
13354
  }
13355
13355
  );
@@ -14443,12 +14443,12 @@ async function applyFileReview(workingDir, filePath, action) {
14443
14443
  return { ok: true, action, filePath, repoRoot };
14444
14444
  }
14445
14445
  function runGit2(cwd, args2) {
14446
- return new Promise((resolve12) => {
14446
+ return new Promise((resolve14) => {
14447
14447
  let proc;
14448
14448
  try {
14449
14449
  proc = (0, import_child_process6.spawn)("git", args2, { cwd, env: process.env });
14450
14450
  } catch (err) {
14451
- resolve12({ ok: false, code: -1, stdout: "", stderr: err.message });
14451
+ resolve14({ ok: false, code: -1, stdout: "", stderr: err.message });
14452
14452
  return;
14453
14453
  }
14454
14454
  let stdout = "";
@@ -14461,11 +14461,11 @@ function runGit2(cwd, args2) {
14461
14461
  });
14462
14462
  proc.on(
14463
14463
  "error",
14464
- (err) => resolve12({ ok: false, code: -1, stdout, stderr: stderr + err.message })
14464
+ (err) => resolve14({ ok: false, code: -1, stdout, stderr: stderr + err.message })
14465
14465
  );
14466
14466
  proc.on(
14467
14467
  "close",
14468
- (code) => resolve12({ ok: code === 0, code: code ?? -1, stdout, stderr })
14468
+ (code) => resolve14({ ok: code === 0, code: code ?? -1, stdout, stderr })
14469
14469
  );
14470
14470
  });
14471
14471
  }
@@ -16804,13 +16804,13 @@ var UnixPtyStrategy = class {
16804
16804
  this.proc = null;
16805
16805
  if (proc) {
16806
16806
  proc.removeAllListeners("exit");
16807
- const exited = new Promise((resolve12) => {
16808
- if (proc.exitCode !== null || proc.signalCode !== null) return resolve12();
16809
- proc.once("exit", () => resolve12());
16807
+ const exited = new Promise((resolve14) => {
16808
+ if (proc.exitCode !== null || proc.signalCode !== null) return resolve14();
16809
+ proc.once("exit", () => resolve14());
16810
16810
  });
16811
16811
  proc.kill("SIGTERM");
16812
- const timer = new Promise((resolve12) => {
16813
- const t2 = setTimeout(() => resolve12("timeout"), timeoutMs);
16812
+ const timer = new Promise((resolve14) => {
16813
+ const t2 = setTimeout(() => resolve14("timeout"), timeoutMs);
16814
16814
  void exited.then(() => clearTimeout(t2));
16815
16815
  });
16816
16816
  if (await Promise.race([exited, timer]) === "timeout") {
@@ -17237,10 +17237,10 @@ function buildForPlatform(platform3) {
17237
17237
  var import_node_crypto5 = require("crypto");
17238
17238
 
17239
17239
  // src/agents/claude/resolver.ts
17240
- function buildClaudeLaunch(extraArgs = [], os70 = createOsStrategy()) {
17241
- const found = os70.findInPath("claude") ?? os70.findInPath("claude-code");
17240
+ function buildClaudeLaunch(extraArgs = [], os72 = createOsStrategy()) {
17241
+ const found = os72.findInPath("claude") ?? os72.findInPath("claude-code");
17242
17242
  if (!found) return null;
17243
- return os70.buildLaunch(found, extraArgs);
17243
+ return os72.buildLaunch(found, extraArgs);
17244
17244
  }
17245
17245
 
17246
17246
  // src/agents/claude/installer.ts
@@ -17267,12 +17267,12 @@ function isAvailable() {
17267
17267
  }
17268
17268
  function augmentPath() {
17269
17269
  const dirs = probeInstallDirs();
17270
- const sep7 = path15.delimiter;
17270
+ const sep8 = path15.delimiter;
17271
17271
  const current2 = process.env.PATH ?? "";
17272
- const existing = new Set(current2.split(sep7).filter(Boolean));
17272
+ const existing = new Set(current2.split(sep8).filter(Boolean));
17273
17273
  const additions = dirs.filter((d3) => !existing.has(d3));
17274
17274
  if (additions.length === 0) return;
17275
- process.env.PATH = additions.join(sep7) + sep7 + current2;
17275
+ process.env.PATH = additions.join(sep8) + sep8 + current2;
17276
17276
  }
17277
17277
  function runInstaller() {
17278
17278
  const isWindows = process.platform === "win32";
@@ -17284,15 +17284,15 @@ function runInstaller() {
17284
17284
  "-Command",
17285
17285
  "irm https://claude.ai/install.ps1 | iex"
17286
17286
  ] : ["-c", "curl -fsSL https://claude.ai/install.sh | bash"];
17287
- return new Promise((resolve12) => {
17287
+ return new Promise((resolve14) => {
17288
17288
  const proc = (0, import_child_process9.spawn)(cmd, args2, { stdio: "inherit" });
17289
17289
  proc.on("error", (err) => {
17290
17290
  console.error(`
17291
17291
  \u2717 Installer failed to launch: ${err.message}`);
17292
- resolve12(false);
17292
+ resolve14(false);
17293
17293
  });
17294
17294
  proc.on("exit", (code) => {
17295
- resolve12(code === 0);
17295
+ resolve14(code === 0);
17296
17296
  });
17297
17297
  });
17298
17298
  }
@@ -17427,7 +17427,7 @@ function extractSetupTokenFromOutput(output) {
17427
17427
  return m ? m[0] : null;
17428
17428
  }
17429
17429
  function captureClaudeSetupToken() {
17430
- return new Promise((resolve12, reject) => {
17430
+ return new Promise((resolve14, reject) => {
17431
17431
  const child = (0, import_node_child_process2.spawn)("claude", ["setup-token"], {
17432
17432
  stdio: ["inherit", "pipe", "inherit"]
17433
17433
  });
@@ -17441,7 +17441,7 @@ function captureClaudeSetupToken() {
17441
17441
  child.on("exit", (code) => {
17442
17442
  const token = extractSetupTokenFromOutput(out2);
17443
17443
  if (token) {
17444
- resolve12({ method: "setup_token", credential: token, source: "setup-token" });
17444
+ resolve14({ method: "setup_token", credential: token, source: "setup-token" });
17445
17445
  return;
17446
17446
  }
17447
17447
  reject(
@@ -17527,17 +17527,17 @@ function parseUsageOutput(raw) {
17527
17527
  return { percent, resetAt };
17528
17528
  }
17529
17529
  async function fetchClaudeQuota() {
17530
- return new Promise((resolve12) => {
17530
+ return new Promise((resolve14) => {
17531
17531
  const claudeCmd = findInPath("claude") ? "claude" : "claude-code";
17532
17532
  if (!claudeCmd) {
17533
- resolve12(null);
17533
+ resolve14(null);
17534
17534
  return;
17535
17535
  }
17536
17536
  const helperPath = path17.join(os11.tmpdir(), "codeam-quota-helper.py");
17537
17537
  fs13.writeFileSync(helperPath, HELPER_SCRIPT, { mode: 420 });
17538
17538
  const python = findInPath("python3") ?? findInPath("python");
17539
17539
  if (!python) {
17540
- resolve12(null);
17540
+ resolve14(null);
17541
17541
  return;
17542
17542
  }
17543
17543
  const proc = (0, import_child_process10.spawn)(python, [helperPath, claudeCmd, "--tools", ""], {
@@ -17564,13 +17564,13 @@ async function fetchClaudeQuota() {
17564
17564
  fs13.unlinkSync(helperPath);
17565
17565
  } catch {
17566
17566
  }
17567
- resolve12(result);
17567
+ resolve14(result);
17568
17568
  }, 5e3);
17569
17569
  }, 8e3);
17570
17570
  setTimeout(() => {
17571
17571
  if (!resolved) {
17572
17572
  resolved = true;
17573
- resolve12(null);
17573
+ resolve14(null);
17574
17574
  }
17575
17575
  try {
17576
17576
  proc.kill();
@@ -17609,12 +17609,12 @@ function killActiveSpawnAndCaptureChildren() {
17609
17609
  }
17610
17610
  async function spawnAndCapture(cmd, args2, opts = {}) {
17611
17611
  const timeoutMs = opts.timeoutMs ?? 6e4;
17612
- return new Promise((resolve12) => {
17612
+ return new Promise((resolve14) => {
17613
17613
  let settled = false;
17614
17614
  const settle = (value) => {
17615
17615
  if (settled) return;
17616
17616
  settled = true;
17617
- resolve12(value);
17617
+ resolve14(value);
17618
17618
  };
17619
17619
  let child;
17620
17620
  try {
@@ -18066,8 +18066,8 @@ var ClaudeRuntimeStrategy = class {
18066
18066
  meta = getAgent("claude");
18067
18067
  mode = "interactive";
18068
18068
  os;
18069
- constructor(os70) {
18070
- this.os = os70;
18069
+ constructor(os72) {
18070
+ this.os = os72;
18071
18071
  }
18072
18072
  /**
18073
18073
  * Claude Code's react-ink TUI enables bracketed-paste mode at
@@ -19065,7 +19065,7 @@ function newestRolloutIdSince(sessionsRoot, resolvedCwd, floorMs) {
19065
19065
  return bestId;
19066
19066
  }
19067
19067
  function sleep2(ms) {
19068
- return new Promise((resolve12) => setTimeout(resolve12, ms));
19068
+ return new Promise((resolve14) => setTimeout(resolve14, ms));
19069
19069
  }
19070
19070
  function getCurrentUsage2(historyDir) {
19071
19071
  if (!import_node_fs4.default.existsSync(historyDir)) return null;
@@ -19167,8 +19167,8 @@ function codexCredentialLocator() {
19167
19167
  function codexLoginLauncher() {
19168
19168
  return {
19169
19169
  async ensureInstalled() {
19170
- const os70 = createOsStrategy();
19171
- return os70.findInPath("codex") !== null;
19170
+ const os72 = createOsStrategy();
19171
+ return os72.findInPath("codex") !== null;
19172
19172
  },
19173
19173
  launch() {
19174
19174
  return (0, import_node_child_process3.spawn)("codex", ["login"], { stdio: "inherit" });
@@ -19191,8 +19191,8 @@ var CodexRuntimeStrategy = class {
19191
19191
  meta = getAgent("codex");
19192
19192
  mode = "interactive";
19193
19193
  os;
19194
- constructor(os70) {
19195
- this.os = os70;
19194
+ constructor(os72) {
19195
+ this.os = os72;
19196
19196
  }
19197
19197
  async prepareLaunch() {
19198
19198
  let binary = this.os.findInPath("codex");
@@ -19303,16 +19303,16 @@ var CodexRuntimeStrategy = class {
19303
19303
  });
19304
19304
  }
19305
19305
  };
19306
- function resolveNpm(os70) {
19307
- return os70.id === "win32" ? "npm.cmd" : "npm";
19306
+ function resolveNpm(os72) {
19307
+ return os72.id === "win32" ? "npm.cmd" : "npm";
19308
19308
  }
19309
- async function installCodexViaNpm(os70) {
19310
- return new Promise((resolve12, reject) => {
19311
- const proc = (0, import_node_child_process4.spawn)(resolveNpm(os70), ["install", "-g", "@openai/codex"], {
19309
+ async function installCodexViaNpm(os72) {
19310
+ return new Promise((resolve14, reject) => {
19311
+ const proc = (0, import_node_child_process4.spawn)(resolveNpm(os72), ["install", "-g", "@openai/codex"], {
19312
19312
  stdio: "inherit"
19313
19313
  });
19314
19314
  proc.on("close", (code) => {
19315
- if (code === 0) resolve12();
19315
+ if (code === 0) resolve14();
19316
19316
  else reject(new Error(`npm install -g @openai/codex exited ${code}`));
19317
19317
  });
19318
19318
  proc.on("error", (err) => {
@@ -19325,16 +19325,16 @@ async function installCodexViaNpm(os70) {
19325
19325
  });
19326
19326
  });
19327
19327
  }
19328
- function augmentNpmGlobalBin(os70) {
19328
+ function augmentNpmGlobalBin(os72) {
19329
19329
  try {
19330
- const result = (0, import_node_child_process4.spawnSync)(resolveNpm(os70), ["prefix", "-g"], {
19330
+ const result = (0, import_node_child_process4.spawnSync)(resolveNpm(os72), ["prefix", "-g"], {
19331
19331
  stdio: ["ignore", "pipe", "ignore"]
19332
19332
  });
19333
19333
  if (result.status !== 0) return;
19334
19334
  const prefix = result.stdout.toString().trim();
19335
19335
  if (!prefix) return;
19336
- const binDir = os70.id === "win32" ? prefix : path26.join(prefix, "bin");
19337
- os70.augmentPath([binDir]);
19336
+ const binDir = os72.id === "win32" ? prefix : path26.join(prefix, "bin");
19337
+ os72.augmentPath([binDir]);
19338
19338
  } catch {
19339
19339
  }
19340
19340
  }
@@ -19432,7 +19432,7 @@ var defaultOsRunner = {
19432
19432
  }
19433
19433
  },
19434
19434
  run(cmd, args2, opts = {}) {
19435
- return new Promise((resolve12) => {
19435
+ return new Promise((resolve14) => {
19436
19436
  const spawnEnv = opts.env ?? process.env;
19437
19437
  const child = (0, import_node_child_process5.spawn)(cmd, args2, { stdio: ["ignore", "pipe", "pipe"], env: spawnEnv });
19438
19438
  let stderrBuf = "";
@@ -19441,7 +19441,7 @@ var defaultOsRunner = {
19441
19441
  const done = (code) => {
19442
19442
  if (settled) return;
19443
19443
  settled = true;
19444
- resolve12({ code, stderr: stderrBuf, stdout: stdoutBuf });
19444
+ resolve14({ code, stderr: stderrBuf, stdout: stdoutBuf });
19445
19445
  };
19446
19446
  child.stdout?.on("data", (b) => {
19447
19447
  const chunk = b.toString();
@@ -19528,10 +19528,10 @@ function manualInstallHint(runner, tools) {
19528
19528
  const argv = osPackageInstallArgv(detectPackageManager(runner), [...tools]);
19529
19529
  return argv ? `\`sudo ${argv.join(" ")}\`` : `your package manager (e.g. \`${pkgs}\`)`;
19530
19530
  }
19531
- function writeUnzipShim(os70, runner) {
19531
+ function writeUnzipShim(os72, runner) {
19532
19532
  const python = ["python3", "python"].find((p2) => runner.which(p2));
19533
19533
  if (!python) return null;
19534
- const dir = os70.scratchPath("codeam-cr-prereq");
19534
+ const dir = os72.scratchPath("codeam-cr-prereq");
19535
19535
  const shim = path28.join(dir, "unzip");
19536
19536
  const script = `#!/bin/sh
19537
19537
  set -e
@@ -19553,9 +19553,9 @@ exec ${python} -m zipfile -e "$archive" "$dest"
19553
19553
  (0, import_node_fs6.chmodSync)(shim, 448);
19554
19554
  return dir;
19555
19555
  }
19556
- async function ensureInstallPrerequisites(os70, deps = {}) {
19556
+ async function ensureInstallPrerequisites(os72, deps = {}) {
19557
19557
  const runner = deps.runner ?? defaultOsRunner;
19558
- const missing = REQUIRED_TOOLS.filter((t2) => os70.findInPath(t2) === null);
19558
+ const missing = REQUIRED_TOOLS.filter((t2) => os72.findInPath(t2) === null);
19559
19559
  if (missing.length === 0) return { ok: true, extraPath: [] };
19560
19560
  log.info(
19561
19561
  "coderabbit",
@@ -19574,10 +19574,10 @@ async function ensureInstallPrerequisites(os70, deps = {}) {
19574
19574
  );
19575
19575
  }
19576
19576
  }
19577
- const stillMissing = REQUIRED_TOOLS.filter((t2) => os70.findInPath(t2) === null);
19577
+ const stillMissing = REQUIRED_TOOLS.filter((t2) => os72.findInPath(t2) === null);
19578
19578
  if (stillMissing.length === 0) return { ok: true, extraPath: [] };
19579
19579
  if (stillMissing.length === 1 && stillMissing[0] === "unzip") {
19580
- const shimDir = writeUnzipShim(os70, runner);
19580
+ const shimDir = writeUnzipShim(os72, runner);
19581
19581
  if (shimDir) {
19582
19582
  log.info("coderabbit", "unzip is unavailable \u2014 using a scoped python zipfile shim");
19583
19583
  return { ok: true, extraPath: [shimDir] };
@@ -19590,7 +19590,7 @@ async function ensureInstallPrerequisites(os70, deps = {}) {
19590
19590
  };
19591
19591
  }
19592
19592
  function defaultRunInstallScript(env) {
19593
- return new Promise((resolve12) => {
19593
+ return new Promise((resolve14) => {
19594
19594
  const proc = (0, import_node_child_process6.spawn)(
19595
19595
  "sh",
19596
19596
  ["-c", `curl -fsSL --connect-timeout 15 --max-time 120 ${INSTALL_URL} | sh`],
@@ -19602,7 +19602,7 @@ function defaultRunInstallScript(env) {
19602
19602
  if (settled) return;
19603
19603
  settled = true;
19604
19604
  clearTimeout(timer);
19605
- resolve12({ code, output });
19605
+ resolve14({ code, output });
19606
19606
  };
19607
19607
  const onData = (b) => {
19608
19608
  const chunk = b.toString();
@@ -19640,15 +19640,15 @@ function summarizeInstallFailure(output) {
19640
19640
  }
19641
19641
  return lines.length > 0 ? lines[lines.length - 1] : null;
19642
19642
  }
19643
- async function ensureCoderabbitInstalled(os70, deps = {}) {
19644
- if (os70.findInPath("coderabbit")) return { ok: true };
19645
- if (os70.id === "win32") {
19643
+ async function ensureCoderabbitInstalled(os72, deps = {}) {
19644
+ if (os72.findInPath("coderabbit")) return { ok: true };
19645
+ if (os72.id === "win32") {
19646
19646
  return {
19647
19647
  ok: false,
19648
19648
  error: "CodeRabbit on Windows requires WSL. Install the CLI inside your WSL distribution (curl -fsSL https://cli.coderabbit.ai/install.sh | sh), then try again."
19649
19649
  };
19650
19650
  }
19651
- const prereq = await ensureInstallPrerequisites(os70, deps);
19651
+ const prereq = await ensureInstallPrerequisites(os72, deps);
19652
19652
  if (!prereq.ok) return { ok: false, error: prereq.error };
19653
19653
  const env = { ...process.env };
19654
19654
  if (prereq.extraPath.length > 0) {
@@ -19657,8 +19657,8 @@ async function ensureCoderabbitInstalled(os70, deps = {}) {
19657
19657
  log.info("coderabbit", "CodeRabbit CLI not found \u2014 installing via the official script");
19658
19658
  const run3 = deps.runInstallScript ?? defaultRunInstallScript;
19659
19659
  const { code, output } = await run3(env);
19660
- os70.augmentPath([`${os70.homeDir()}/.local/bin`, "/opt/homebrew/bin"]);
19661
- const binary = os70.findInPath("coderabbit");
19660
+ os72.augmentPath([`${os72.homeDir()}/.local/bin`, "/opt/homebrew/bin"]);
19661
+ const binary = os72.findInPath("coderabbit");
19662
19662
  const detail = summarizeInstallFailure(output);
19663
19663
  if (binary !== null) {
19664
19664
  if (code === 0) return { ok: true };
@@ -19712,10 +19712,10 @@ function coderabbitCredentialLocator() {
19712
19712
  validate: validateNonEmptyCredential
19713
19713
  };
19714
19714
  }
19715
- function coderabbitLoginLauncher(os70) {
19715
+ function coderabbitLoginLauncher(os72) {
19716
19716
  return {
19717
19717
  async ensureInstalled() {
19718
- const result = await ensureCoderabbitInstalled(os70);
19718
+ const result = await ensureCoderabbitInstalled(os72);
19719
19719
  if (!result.ok && result.error) console.error(`
19720
19720
  \u2717 ${result.error}
19721
19721
  `);
@@ -19775,8 +19775,8 @@ function pickLine(obj) {
19775
19775
  function toHunk(raw, groupSeverity) {
19776
19776
  if (!raw || typeof raw !== "object") return null;
19777
19777
  const o = raw;
19778
- const path109 = asString(pick(o, ["file_path", "filePath", "file", "path", "filename", "fileName"])) ?? asString(pick(o, ["location"])?.path);
19779
- if (!path109) return null;
19778
+ const path112 = asString(pick(o, ["file_path", "filePath", "file", "path", "filename", "fileName"])) ?? asString(pick(o, ["location"])?.path);
19779
+ if (!path112) return null;
19780
19780
  const message = asString(
19781
19781
  pick(o, [
19782
19782
  "comment",
@@ -19793,7 +19793,7 @@ function toHunk(raw, groupSeverity) {
19793
19793
  const severity = normSeverity(pick(o, ["severity", "level", "priority", "impact"])) ?? normSeverity(groupSeverity);
19794
19794
  const locObj = pick(o, ["location"]) ?? o;
19795
19795
  return {
19796
- path: path109.trim(),
19796
+ path: path112.trim(),
19797
19797
  line: pickLine(o) ?? pickLine(locObj),
19798
19798
  severity,
19799
19799
  message: (title && message ? `${title}: ${message}` : title || message).trim() || "(no message)"
@@ -19876,10 +19876,10 @@ function parsePlain(stdout) {
19876
19876
  for (const line of stdout.split(/\r?\n/)) {
19877
19877
  const m = line.match(HUNK_LINE_RE);
19878
19878
  if (!m) continue;
19879
- const [, path109, lineNo, sevToken, message] = m;
19880
- if (!path109 || !lineNo || !message) continue;
19879
+ const [, path112, lineNo, sevToken, message] = m;
19880
+ if (!path112 || !lineNo || !message) continue;
19881
19881
  hunks.push({
19882
- path: path109.trim(),
19882
+ path: path112.trim(),
19883
19883
  line: Number(lineNo),
19884
19884
  severity: sevToken ? SEVERITY_MAP[sevToken.toLowerCase()] : void 0,
19885
19885
  message: message.trim().replace(/^[*-]\s+/, "")
@@ -19939,8 +19939,8 @@ var CoderabbitRuntimeStrategy = class {
19939
19939
  meta = getAgent("coderabbit");
19940
19940
  mode = "batch";
19941
19941
  os;
19942
- constructor(os70) {
19943
- this.os = os70;
19942
+ constructor(os72) {
19943
+ this.os = os72;
19944
19944
  }
19945
19945
  getDefaultArgs() {
19946
19946
  return ["review", "--agent"];
@@ -19976,7 +19976,7 @@ var CoderabbitRuntimeStrategy = class {
19976
19976
  }
19977
19977
  async runOneShot(input) {
19978
19978
  const launch = await this.prepareInvocation(input);
19979
- return new Promise((resolve12, reject) => {
19979
+ return new Promise((resolve14, reject) => {
19980
19980
  const stdoutBuf = [];
19981
19981
  const stderrBuf = [];
19982
19982
  const proc = (0, import_node_child_process8.spawn)(launch.cmd, launch.args, {
@@ -19988,7 +19988,7 @@ var CoderabbitRuntimeStrategy = class {
19988
19988
  if (settled) return;
19989
19989
  settled = true;
19990
19990
  clearTimeout(timer);
19991
- resolve12(out2);
19991
+ resolve14(out2);
19992
19992
  };
19993
19993
  const timer = setTimeout(() => {
19994
19994
  if (settled) return;
@@ -20211,10 +20211,10 @@ function cursorCredentialLocator() {
20211
20211
  validate: validateNonEmptyCredential
20212
20212
  };
20213
20213
  }
20214
- function cursorLoginLauncher(os70) {
20214
+ function cursorLoginLauncher(os72) {
20215
20215
  return {
20216
20216
  async ensureInstalled() {
20217
- if (os70.findInPath("cursor-agent")) return true;
20217
+ if (os72.findInPath("cursor-agent")) return true;
20218
20218
  console.error(
20219
20219
  "\n \u2717 cursor-agent binary not on PATH.\n Install Cursor (https://cursor.com/) and ensure the CLI\n plugin is enabled, then re-run `codeam link cursor`.\n"
20220
20220
  );
@@ -20278,8 +20278,8 @@ var CursorRuntimeStrategy = class {
20278
20278
  meta = getAgent("cursor");
20279
20279
  mode = "interactive";
20280
20280
  os;
20281
- constructor(os70) {
20282
- this.os = os70;
20281
+ constructor(os72) {
20282
+ this.os = os72;
20283
20283
  }
20284
20284
  async prepareLaunch() {
20285
20285
  const binary = this.os.findInPath("cursor-agent");
@@ -20497,10 +20497,10 @@ function aiderCredentialLocator() {
20497
20497
  validate: validateNonEmptyCredential
20498
20498
  };
20499
20499
  }
20500
- function aiderLoginLauncher(os70) {
20500
+ function aiderLoginLauncher(os72) {
20501
20501
  return {
20502
20502
  async ensureInstalled() {
20503
- if (os70.findInPath("aider")) return true;
20503
+ if (os72.findInPath("aider")) return true;
20504
20504
  console.error(
20505
20505
  "\n \u2717 aider binary not on PATH.\n Install Aider:\n pip install aider-chat\n then re-run `codeam link aider`.\n"
20506
20506
  );
@@ -20510,7 +20510,7 @@ function aiderLoginLauncher(os70) {
20510
20510
  console.error(
20511
20511
  "\n Aider has no interactive login flow.\n Set ANTHROPIC_API_KEY or OPENAI_API_KEY in your shell,\n or re-run `codeam link aider --api-key=<your-key>`.\n"
20512
20512
  );
20513
- return (0, import_node_child_process11.spawn)(os70.id === "win32" ? "cmd.exe" : "sh", os70.id === "win32" ? ["/c", "exit", "0"] : ["-c", "exit 0"], {
20513
+ return (0, import_node_child_process11.spawn)(os72.id === "win32" ? "cmd.exe" : "sh", os72.id === "win32" ? ["/c", "exit", "0"] : ["-c", "exit 0"], {
20514
20514
  stdio: "ignore"
20515
20515
  });
20516
20516
  }
@@ -20599,16 +20599,16 @@ function defaultSdkDir() {
20599
20599
  return resolveSdkDirViaRequire();
20600
20600
  }
20601
20601
  function resolveClaudeNativeBinary(deps = {}) {
20602
- const existsSync33 = deps.existsSync ?? import_fs.default.existsSync;
20602
+ const existsSync35 = deps.existsSync ?? import_fs.default.existsSync;
20603
20603
  const platformKey = deps.platformKey ?? currentPlatformKey();
20604
20604
  const sdkDir = deps.sdkDir !== void 0 ? deps.sdkDir : defaultSdkDir();
20605
20605
  if (!sdkDir) return null;
20606
20606
  const scopeDir = import_path4.default.dirname(sdkDir);
20607
20607
  const binName = platformKey.startsWith("win32-") ? "claude.exe" : "claude";
20608
20608
  const candidate = import_path4.default.join(scopeDir, `claude-agent-sdk-${platformKey}`, binName);
20609
- return existsSync33(candidate) ? candidate : null;
20609
+ return existsSync35(candidate) ? candidate : null;
20610
20610
  }
20611
- var realSleep = (ms) => new Promise((resolve12) => setTimeout(resolve12, ms));
20611
+ var realSleep = (ms) => new Promise((resolve14) => setTimeout(resolve14, ms));
20612
20612
  async function waitForClaudeNativeBinary(opts = {}) {
20613
20613
  const timeoutMs = opts.timeoutMs ?? 18e4;
20614
20614
  const pollMs = opts.pollMs ?? 500;
@@ -20688,18 +20688,18 @@ function augmentUserLocalBinPaths(deps = {}) {
20688
20688
  env.PATH = [...additions, ...parts].join(p2.delimiter);
20689
20689
  }
20690
20690
  function resolveCursorAgentBinary(deps = {}) {
20691
- const existsSync33 = deps.existsSync ?? import_fs.default.existsSync;
20691
+ const existsSync35 = deps.existsSync ?? import_fs.default.existsSync;
20692
20692
  const platform3 = deps.platform ?? process.platform;
20693
20693
  const env = deps.env ?? process.env;
20694
20694
  if (platform3 === "win32") {
20695
20695
  const localAppData = env.LOCALAPPDATA;
20696
20696
  if (!localAppData) return null;
20697
20697
  const exe = import_path4.default.win32.join(localAppData, "cursor-agent", "cursor-agent.exe");
20698
- return existsSync33(exe) ? exe : null;
20698
+ return existsSync35(exe) ? exe : null;
20699
20699
  }
20700
20700
  const home = deps.homedir ?? import_os4.default.homedir();
20701
20701
  const unix = import_path4.default.posix.join(home, ".local", "bin", "cursor-agent");
20702
- return existsSync33(unix) ? unix : null;
20702
+ return existsSync35(unix) ? unix : null;
20703
20703
  }
20704
20704
  async function waitForCursorAgent(opts = {}) {
20705
20705
  const timeoutMs = opts.timeoutMs ?? 18e4;
@@ -20720,7 +20720,7 @@ var PERMANENT_ADAPTER_STARTUP_RE = /IneligibleTierError|UNSUPPORTED_CLIENT|no lo
20720
20720
  function probeAdapterModuleGraph(command2, args2, opts = {}) {
20721
20721
  const livenessMs = opts.livenessMs ?? 400;
20722
20722
  const spawnFn = opts.spawnFn ?? import_child_process13.spawn;
20723
- return new Promise((resolve12) => {
20723
+ return new Promise((resolve14) => {
20724
20724
  let settled = false;
20725
20725
  let stderr = "";
20726
20726
  let timer;
@@ -20733,12 +20733,12 @@ function probeAdapterModuleGraph(command2, args2, opts = {}) {
20733
20733
  child?.kill("SIGKILL");
20734
20734
  } catch {
20735
20735
  }
20736
- resolve12(r);
20736
+ resolve14(r);
20737
20737
  };
20738
20738
  try {
20739
20739
  child = spawnFn(command2, [...args2], { stdio: ["pipe", "ignore", "pipe"] });
20740
20740
  } catch {
20741
- resolve12("ok");
20741
+ resolve14("ok");
20742
20742
  return;
20743
20743
  }
20744
20744
  child.stderr?.on("data", (d3) => {
@@ -20785,8 +20785,8 @@ var AiderRuntimeStrategy = class {
20785
20785
  meta = getAgent("aider");
20786
20786
  mode = "interactive";
20787
20787
  os;
20788
- constructor(os70) {
20789
- this.os = os70;
20788
+ constructor(os72) {
20789
+ this.os = os72;
20790
20790
  }
20791
20791
  async prepareLaunch() {
20792
20792
  augmentUserLocalBinPaths();
@@ -20919,8 +20919,8 @@ function geminiCredentialLocator() {
20919
20919
  function geminiLoginLauncher() {
20920
20920
  return {
20921
20921
  async ensureInstalled() {
20922
- const os70 = createOsStrategy();
20923
- return os70.findInPath("gemini") !== null;
20922
+ const os72 = createOsStrategy();
20923
+ return os72.findInPath("gemini") !== null;
20924
20924
  },
20925
20925
  launch() {
20926
20926
  return (0, import_node_child_process12.spawn)("gemini", ["auth", "login"], { stdio: "inherit" });
@@ -21110,8 +21110,8 @@ var GeminiRuntimeStrategy = class {
21110
21110
  meta = getAgent("gemini");
21111
21111
  mode = "interactive";
21112
21112
  os;
21113
- constructor(os70) {
21114
- this.os = os70;
21113
+ constructor(os72) {
21114
+ this.os = os72;
21115
21115
  }
21116
21116
  async prepareLaunch() {
21117
21117
  const binary = this.os.findInPath("gemini");
@@ -21327,7 +21327,7 @@ function newestSessionSince(bucket, floorMs) {
21327
21327
  return bestId;
21328
21328
  }
21329
21329
  function sleep3(ms) {
21330
- return new Promise((resolve12) => setTimeout(resolve12, ms));
21330
+ return new Promise((resolve14) => setTimeout(resolve14, ms));
21331
21331
  }
21332
21332
  function joinTextParts(parts) {
21333
21333
  if (!Array.isArray(parts)) return "";
@@ -21404,8 +21404,8 @@ var KimiRuntimeStrategy = class {
21404
21404
  meta = getAgent("kimi");
21405
21405
  mode = "interactive";
21406
21406
  os;
21407
- constructor(os70) {
21408
- this.os = os70;
21407
+ constructor(os72) {
21408
+ this.os = os72;
21409
21409
  }
21410
21410
  async prepareLaunch() {
21411
21411
  const binary = this.os.findInPath("kimi");
@@ -21549,8 +21549,8 @@ var OpencodeRuntimeStrategy = class {
21549
21549
  meta = getAgent("opencode");
21550
21550
  mode = "interactive";
21551
21551
  os;
21552
- constructor(os70) {
21553
- this.os = os70;
21552
+ constructor(os72) {
21553
+ this.os = os72;
21554
21554
  }
21555
21555
  async prepareLaunch() {
21556
21556
  const binary = this.os.findInPath("opencode");
@@ -21636,20 +21636,20 @@ var OpencodeRuntimeStrategy = class {
21636
21636
 
21637
21637
  // src/agents/registry.ts
21638
21638
  var runtimeBuilders = {
21639
- claude: (os70) => new ClaudeRuntimeStrategy(os70),
21640
- codex: (os70) => new CodexRuntimeStrategy(os70),
21641
- coderabbit: (os70) => new CoderabbitRuntimeStrategy(os70),
21642
- cursor: (os70) => new CursorRuntimeStrategy(os70),
21643
- aider: (os70) => new AiderRuntimeStrategy(os70),
21644
- gemini: (os70) => new GeminiRuntimeStrategy(os70),
21645
- kimi: (os70) => new KimiRuntimeStrategy(os70),
21646
- opencode: (os70) => new OpencodeRuntimeStrategy(os70)
21639
+ claude: (os72) => new ClaudeRuntimeStrategy(os72),
21640
+ codex: (os72) => new CodexRuntimeStrategy(os72),
21641
+ coderabbit: (os72) => new CoderabbitRuntimeStrategy(os72),
21642
+ cursor: (os72) => new CursorRuntimeStrategy(os72),
21643
+ aider: (os72) => new AiderRuntimeStrategy(os72),
21644
+ gemini: (os72) => new GeminiRuntimeStrategy(os72),
21645
+ kimi: (os72) => new KimiRuntimeStrategy(os72),
21646
+ opencode: (os72) => new OpencodeRuntimeStrategy(os72)
21647
21647
  };
21648
21648
  var deployBuilders = {
21649
21649
  claude: () => new ClaudeDeployStrategy(),
21650
21650
  codex: () => new CodexDeployStrategy()
21651
21651
  };
21652
- function createAgentStrategy(agent, os70 = createOsStrategy()) {
21652
+ function createAgentStrategy(agent, os72 = createOsStrategy()) {
21653
21653
  if (!AGENT_REGISTRY[agent]?.enabled) {
21654
21654
  throw new Error(
21655
21655
  `Agent "${agent}" is not supported in this codeam-cli version. Upgrade with 'npm i -g codeam-cli@latest'.`
@@ -21659,10 +21659,10 @@ function createAgentStrategy(agent, os70 = createOsStrategy()) {
21659
21659
  if (!build) {
21660
21660
  throw new Error(`No runtime strategy registered for agent "${agent}"`);
21661
21661
  }
21662
- return build(os70);
21662
+ return build(os72);
21663
21663
  }
21664
- function createInteractiveAgentStrategy(agent, os70 = createOsStrategy()) {
21665
- const s = createAgentStrategy(agent, os70);
21664
+ function createInteractiveAgentStrategy(agent, os72 = createOsStrategy()) {
21665
+ const s = createAgentStrategy(agent, os72);
21666
21666
  if (s.mode !== "interactive") {
21667
21667
  throw new Error(
21668
21668
  `Agent "${agent}" is a batch agent; use createAgentStrategy + .runOneShot for one-shot reviews.`
@@ -21778,7 +21778,7 @@ async function link(args2 = []) {
21778
21778
  waitSpin.start(waitMsg());
21779
21779
  const countdown = setInterval(() => waitSpin.message(waitMsg()), 1e3);
21780
21780
  countdown.unref?.();
21781
- const paired = await new Promise((resolve12, reject) => {
21781
+ const paired = await new Promise((resolve14, reject) => {
21782
21782
  let stopPoll = null;
21783
21783
  const sigint = () => {
21784
21784
  clearInterval(countdown);
@@ -21791,7 +21791,7 @@ async function link(args2 = []) {
21791
21791
  process.removeListener("SIGINT", sigint);
21792
21792
  clearInterval(countdown);
21793
21793
  waitSpin.stop("Paired");
21794
- resolve12(info);
21794
+ resolve14(info);
21795
21795
  },
21796
21796
  () => {
21797
21797
  clearInterval(countdown);
@@ -21949,14 +21949,14 @@ async function captureFreshCredentials(ctx) {
21949
21949
  }
21950
21950
  };
21951
21951
  try {
21952
- const token = await new Promise((resolve12, reject) => {
21952
+ const token = await new Promise((resolve14, reject) => {
21953
21953
  let settled = false;
21954
21954
  const tryExtract = async () => {
21955
21955
  if (settled) return;
21956
21956
  const t2 = await ctx.locator.extract();
21957
21957
  if (t2 && !settled) {
21958
21958
  settled = true;
21959
- resolve12(t2);
21959
+ resolve14(t2);
21960
21960
  }
21961
21961
  };
21962
21962
  watcher.on("add", () => void tryExtract());
@@ -22200,7 +22200,7 @@ function deliverPendingCoderabbitCallback(callbackUrl) {
22200
22200
  function runCoderabbitOAuthLogin(deps) {
22201
22201
  const timeoutMs = deps.timeoutMs ?? 18e4;
22202
22202
  const spawnProc = deps.spawn ?? spawnCoderabbitLoginProc;
22203
- return new Promise((resolve12) => {
22203
+ return new Promise((resolve14) => {
22204
22204
  let settled = false;
22205
22205
  let stdout = "";
22206
22206
  let last = null;
@@ -22213,13 +22213,13 @@ function runCoderabbitOAuthLogin(deps) {
22213
22213
  child.kill("SIGKILL");
22214
22214
  } catch {
22215
22215
  }
22216
- resolve12(r);
22216
+ resolve14(r);
22217
22217
  };
22218
22218
  let child;
22219
22219
  try {
22220
22220
  child = spawnProc("coderabbit", ["auth", "login", "--agent"]);
22221
22221
  } catch (err) {
22222
- resolve12({ ok: false, error: err instanceof Error ? err.message : "spawn failed" });
22222
+ resolve14({ ok: false, error: err instanceof Error ? err.message : "spawn failed" });
22223
22223
  return;
22224
22224
  }
22225
22225
  const timer = setTimeout(
@@ -22376,8 +22376,8 @@ function collectChangedFiles(cwd) {
22376
22376
  }
22377
22377
  return [...byPath.values()];
22378
22378
  }
22379
- function restoreCoderabbitOauthBlob(os70, value) {
22380
- const dir = path40.join(os70.homeDir(), ".coderabbit");
22379
+ function restoreCoderabbitOauthBlob(os72, value) {
22380
+ const dir = path40.join(os72.homeDir(), ".coderabbit");
22381
22381
  (0, import_node_fs7.mkdirSync)(dir, { recursive: true });
22382
22382
  let file = "auth.json";
22383
22383
  let contents = value.trim();
@@ -22397,26 +22397,26 @@ function installFailureMessage(result) {
22397
22397
  return result.error ?? "CodeRabbit CLI could not be installed";
22398
22398
  }
22399
22399
  async function configureCoderabbit(input, deps = {}) {
22400
- const os70 = deps.os ?? createOsStrategy();
22400
+ const os72 = deps.os ?? createOsStrategy();
22401
22401
  const ensureInstalled = deps.ensureInstalled ?? ensureCoderabbitInstalled;
22402
22402
  const isLoggedIn = deps.isLoggedIn ?? defaultIsLoggedIn;
22403
22403
  const runOAuth = deps.runOAuthLogin ?? runCoderabbitOAuthLogin;
22404
22404
  const snapshot = deps.snapshotDir ?? (() => snapshotCredentialDir());
22405
22405
  const capture2 = deps.captureCredential ?? ((b) => diffCapturedCredential(b));
22406
22406
  const loginWithApiKey = deps.loginWithApiKey ?? defaultLoginWithApiKey;
22407
- const home = os70.homeDir();
22408
- os70.augmentPath(
22409
- os70.id === "win32" ? [
22407
+ const home = os72.homeDir();
22408
+ os72.augmentPath(
22409
+ os72.id === "win32" ? [
22410
22410
  path40.join(home, ".local", "bin"),
22411
22411
  path40.join(process.env.APPDATA ?? path40.join(home, "AppData", "Roaming"), "npm"),
22412
22412
  path40.join(home, "scoop", "shims")
22413
22413
  ] : [path40.join(home, ".local", "bin"), "/opt/homebrew/bin", "/usr/local/bin"]
22414
22414
  );
22415
- const installed2 = os70.findInPath("coderabbit") !== null;
22415
+ const installed2 = os72.findInPath("coderabbit") !== null;
22416
22416
  const base = () => ({
22417
22417
  action: input.action,
22418
22418
  supported: true,
22419
- installed: os70.findInPath("coderabbit") !== null,
22419
+ installed: os72.findInPath("coderabbit") !== null,
22420
22420
  loggedIn: false
22421
22421
  });
22422
22422
  if (input.action === "status") {
@@ -22430,7 +22430,7 @@ async function configureCoderabbit(input, deps = {}) {
22430
22430
  const key = (input.apiKey ?? "").trim();
22431
22431
  if (!key) return { ...res2, error: "No API key provided" };
22432
22432
  if (!res2.installed) {
22433
- const inst = await ensureInstalled(os70);
22433
+ const inst = await ensureInstalled(os72);
22434
22434
  res2.installed = inst.ok;
22435
22435
  if (!inst.ok) return { ...res2, error: installFailureMessage(inst) };
22436
22436
  }
@@ -22454,7 +22454,7 @@ async function configureCoderabbit(input, deps = {}) {
22454
22454
  }
22455
22455
  if (!res2.installed) {
22456
22456
  deps.onEvent?.({ kind: "installing" });
22457
- const inst = await ensureInstalled(os70);
22457
+ const inst = await ensureInstalled(os72);
22458
22458
  res2.installed = inst.ok;
22459
22459
  if (!inst.ok) return { ...res2, error: installFailureMessage(inst) };
22460
22460
  }
@@ -22471,7 +22471,7 @@ async function configureCoderabbit(input, deps = {}) {
22471
22471
  return { ...res2, loggedIn: true, linked: true };
22472
22472
  }
22473
22473
  try {
22474
- restoreCoderabbitOauthBlob(os70, cred.credential);
22474
+ restoreCoderabbitOauthBlob(os72, cred.credential);
22475
22475
  } catch (err) {
22476
22476
  return {
22477
22477
  ...res2,
@@ -22495,7 +22495,7 @@ async function configureCoderabbit(input, deps = {}) {
22495
22495
  const res2 = base();
22496
22496
  if (!installed2) {
22497
22497
  deps.onEvent?.({ kind: "installing" });
22498
- const inst = await ensureInstalled(os70);
22498
+ const inst = await ensureInstalled(os72);
22499
22499
  res2.installed = inst.ok;
22500
22500
  if (!inst.ok) return { ...res2, error: installFailureMessage(inst) };
22501
22501
  }
@@ -22535,7 +22535,7 @@ async function configureCoderabbit(input, deps = {}) {
22535
22535
  }
22536
22536
  const res = base();
22537
22537
  if (!res.installed) {
22538
- const inst = await ensureInstalled(os70);
22538
+ const inst = await ensureInstalled(os72);
22539
22539
  res.installed = inst.ok;
22540
22540
  if (!inst.ok) return { ...res, error: installFailureMessage(inst) };
22541
22541
  }
@@ -22692,23 +22692,23 @@ async function reviewPullRequest(params, deps) {
22692
22692
  return report;
22693
22693
  }
22694
22694
  function defaultRunGh(args2) {
22695
- return new Promise((resolve12) => {
22695
+ return new Promise((resolve14) => {
22696
22696
  const stdout = [];
22697
22697
  const stderr = [];
22698
22698
  let proc;
22699
22699
  try {
22700
22700
  proc = (0, import_node_child_process17.spawn)("gh", args2, { stdio: ["ignore", "pipe", "pipe"] });
22701
22701
  } catch (err) {
22702
- resolve12({ code: -1, stdout: "", stderr: err instanceof Error ? err.message : String(err) });
22702
+ resolve14({ code: -1, stdout: "", stderr: err instanceof Error ? err.message : String(err) });
22703
22703
  return;
22704
22704
  }
22705
22705
  proc.stdout?.on("data", (b) => stdout.push(b));
22706
22706
  proc.stderr?.on("data", (b) => stderr.push(b));
22707
22707
  proc.on("error", (err) => {
22708
- resolve12({ code: -1, stdout: "", stderr: err.message });
22708
+ resolve14({ code: -1, stdout: "", stderr: err.message });
22709
22709
  });
22710
22710
  proc.on("close", (code) => {
22711
- resolve12({
22711
+ resolve14({
22712
22712
  code: code ?? 0,
22713
22713
  stdout: Buffer.concat(stdout).toString("utf8"),
22714
22714
  stderr: Buffer.concat(stderr).toString("utf8")
@@ -23028,7 +23028,7 @@ var import_node_fs11 = __toESM(require("fs"));
23028
23028
  var import_node_path9 = __toESM(require("path"));
23029
23029
  var import_yazl = require("yazl");
23030
23030
  function buildZip(cwd, list, outFile) {
23031
- return new Promise((resolve12, reject) => {
23031
+ return new Promise((resolve14, reject) => {
23032
23032
  const zip = new import_yazl.ZipFile();
23033
23033
  for (const f of list.files) {
23034
23034
  const abs = import_node_path9.default.join(cwd, f.rel);
@@ -23038,7 +23038,7 @@ function buildZip(cwd, list, outFile) {
23038
23038
  if (list.envExample) zip.addBuffer(Buffer.from(list.envExample), ".env.example");
23039
23039
  const out2 = import_node_fs11.default.createWriteStream(outFile, { mode: 384 });
23040
23040
  zip.outputStream.pipe(out2);
23041
- out2.on("close", () => resolve12(import_node_fs11.default.statSync(outFile).size));
23041
+ out2.on("close", () => resolve14(import_node_fs11.default.statSync(outFile).size));
23042
23042
  out2.on("error", reject);
23043
23043
  zip.outputStream.on("error", reject);
23044
23044
  zip.end();
@@ -23230,12 +23230,12 @@ async function isExecutableBinary(p2) {
23230
23230
  }
23231
23231
  }
23232
23232
  function extractTgz(tgzPath, destDir) {
23233
- return new Promise((resolve12, reject) => {
23233
+ return new Promise((resolve14, reject) => {
23234
23234
  const child = (0, import_child_process14.spawn)("tar", ["-xzf", tgzPath, "-C", destDir], { stdio: "ignore" });
23235
23235
  child.on("error", (err) => reject(err));
23236
23236
  child.on(
23237
23237
  "exit",
23238
- (code) => code === 0 ? resolve12() : reject(new Error(`tar exited with code ${code} while extracting cloudflared`))
23238
+ (code) => code === 0 ? resolve14() : reject(new Error(`tar exited with code ${code} while extracting cloudflared`))
23239
23239
  );
23240
23240
  });
23241
23241
  }
@@ -23621,9 +23621,9 @@ var healRestartCounts = /* @__PURE__ */ new Map();
23621
23621
  function resetBuildHealState(sessionId) {
23622
23622
  healRestartCounts.delete(sessionId);
23623
23623
  }
23624
- function readMarker2(markerPath4) {
23624
+ function readMarker2(markerPath5) {
23625
23625
  try {
23626
- return fs42.readFileSync(markerPath4, "utf8").trim();
23626
+ return fs42.readFileSync(markerPath5, "utf8").trim();
23627
23627
  } catch {
23628
23628
  return null;
23629
23629
  }
@@ -23633,12 +23633,12 @@ function watchForBuildClobber(deps) {
23633
23633
  const debounceMs = deps.debounceMs ?? DEFAULT_DEBOUNCE_MS;
23634
23634
  const maxRestarts = deps.maxRestarts ?? DEFAULT_MAX_RESTARTS;
23635
23635
  const nextDir = path49.join(deps.cwd, ".next");
23636
- const markerPath4 = path49.join(nextDir, BUILD_MARKER_NAME);
23636
+ const markerPath5 = path49.join(nextDir, BUILD_MARKER_NAME);
23637
23637
  let stopped = false;
23638
23638
  let debounceTimer = null;
23639
23639
  let dirUnwatch = null;
23640
23640
  let cwdUnwatch = null;
23641
- let lastKnownMarker = readMarker2(markerPath4);
23641
+ let lastKnownMarker = readMarker2(markerPath5);
23642
23642
  const stop = () => {
23643
23643
  if (stopped) return;
23644
23644
  stopped = true;
@@ -23653,7 +23653,7 @@ function watchForBuildClobber(deps) {
23653
23653
  };
23654
23654
  const onDebouncedClobber = () => {
23655
23655
  if (stopped) return;
23656
- const current2 = readMarker2(markerPath4);
23656
+ const current2 = readMarker2(markerPath5);
23657
23657
  if (current2 === lastKnownMarker) return;
23658
23658
  lastKnownMarker = current2;
23659
23659
  const count = (healRestartCounts.get(deps.sessionId) ?? 0) + 1;
@@ -23671,7 +23671,7 @@ function watchForBuildClobber(deps) {
23671
23671
  }
23672
23672
  log.info(
23673
23673
  "preview",
23674
- `build-heal: ${markerPath4} changed (a build likely ran) \u2014 restarting the dev server (${count}/${maxRestarts})`
23674
+ `build-heal: ${markerPath5} changed (a build likely ran) \u2014 restarting the dev server (${count}/${maxRestarts})`
23675
23675
  );
23676
23676
  deps.notify("Rebuilt \u2014 restarting preview");
23677
23677
  deps.restart();
@@ -23686,7 +23686,7 @@ function watchForBuildClobber(deps) {
23686
23686
  };
23687
23687
  const attachDirWatch = () => {
23688
23688
  if (dirUnwatch) return;
23689
- lastKnownMarker = readMarker2(markerPath4);
23689
+ lastKnownMarker = readMarker2(markerPath5);
23690
23690
  dirUnwatch = watchDir(nextDir, (filename) => {
23691
23691
  if (filename === null || filename === BUILD_MARKER_NAME) onMarkerTouched();
23692
23692
  });
@@ -23816,17 +23816,17 @@ function expoGoDeepLink(publicUrl) {
23816
23816
  return `exps://${new URL(publicUrl).host}`;
23817
23817
  }
23818
23818
  function isExpoManifestServed(port, host2 = "127.0.0.1") {
23819
- return new Promise((resolve12) => {
23819
+ return new Promise((resolve14) => {
23820
23820
  const req = http6.get(
23821
23821
  { host: host2, port, path: "/", headers: { "expo-platform": "ios" }, timeout: 1500 },
23822
23822
  (res) => {
23823
23823
  const ok = res.statusCode !== void 0 && res.statusCode >= 200 && res.statusCode < 300;
23824
23824
  res.resume();
23825
- resolve12(ok);
23825
+ resolve14(ok);
23826
23826
  }
23827
23827
  );
23828
23828
  req.once("timeout", () => req.destroy());
23829
- req.once("error", () => resolve12(false));
23829
+ req.once("error", () => resolve14(false));
23830
23830
  });
23831
23831
  }
23832
23832
  async function waitForExpoManifest(port, opts) {
@@ -23974,12 +23974,12 @@ function describeDetectionFailure(raw) {
23974
23974
  // src/services/preview/port-ready.ts
23975
23975
  var net = __toESM(require("net"));
23976
23976
  function isPortListening(port, host2 = "127.0.0.1") {
23977
- return new Promise((resolve12) => {
23977
+ return new Promise((resolve14) => {
23978
23978
  const socket = new net.Socket();
23979
23979
  const done = (result) => {
23980
23980
  socket.removeAllListeners();
23981
23981
  socket.destroy();
23982
- resolve12(result);
23982
+ resolve14(result);
23983
23983
  };
23984
23984
  socket.setTimeout(1e3);
23985
23985
  socket.once("connect", () => done(true));
@@ -24017,14 +24017,14 @@ const { PGLiteSocketServer } = require('@electric-sql/pglite-socket');
24017
24017
  })().catch((e) => { console.error(String(e && e.message)); process.exit(1); });
24018
24018
  `;
24019
24019
  function isListening(port) {
24020
- return new Promise((resolve12) => {
24020
+ return new Promise((resolve14) => {
24021
24021
  const s = net2.connect({ host: "127.0.0.1", port }, () => {
24022
24022
  s.destroy();
24023
- resolve12(true);
24024
- }).on("error", () => resolve12(false));
24023
+ resolve14(true);
24024
+ }).on("error", () => resolve14(false));
24025
24025
  s.setTimeout(1e3, () => {
24026
24026
  s.destroy();
24027
- resolve12(false);
24027
+ resolve14(false);
24028
24028
  });
24029
24029
  });
24030
24030
  }
@@ -24072,7 +24072,7 @@ function stopChild(child) {
24072
24072
  // src/services/preview/run-setup.ts
24073
24073
  var import_child_process18 = require("child_process");
24074
24074
  function runSetupCommand(cmd, args2, cwd, env, opts) {
24075
- return new Promise((resolve12) => {
24075
+ return new Promise((resolve14) => {
24076
24076
  const child = (0, import_child_process18.spawn)(cmd, args2, {
24077
24077
  cwd,
24078
24078
  env: { ...process.env, ...env ?? {} },
@@ -24092,20 +24092,20 @@ function runSetupCommand(cmd, args2, cwd, env, opts) {
24092
24092
  settled = true;
24093
24093
  log.info("preview", `${tag}: timed out after ${opts.timeoutMs}ms \u2014 killing`);
24094
24094
  killQuiet(child);
24095
- resolve12({ status: "timeout", code: null });
24095
+ resolve14({ status: "timeout", code: null });
24096
24096
  }, opts.timeoutMs);
24097
24097
  child.once("exit", (code) => {
24098
24098
  if (settled) return;
24099
24099
  settled = true;
24100
24100
  clearTimeout(timer);
24101
- if (code === 0) resolve12({ status: "ok", code: 0 });
24102
- else resolve12({ status: "failed", code });
24101
+ if (code === 0) resolve14({ status: "ok", code: 0 });
24102
+ else resolve14({ status: "failed", code });
24103
24103
  });
24104
24104
  child.once("error", () => {
24105
24105
  if (settled) return;
24106
24106
  settled = true;
24107
24107
  clearTimeout(timer);
24108
- resolve12({ status: "failed", code: null });
24108
+ resolve14({ status: "failed", code: null });
24109
24109
  });
24110
24110
  });
24111
24111
  }
@@ -24561,23 +24561,23 @@ async function awaitTunnelRegistered(candidate, hostname3, deadlineMs) {
24561
24561
  ac.signal.addEventListener("abort", detach, { once: true });
24562
24562
  };
24563
24563
  try {
24564
- return await new Promise((resolve12) => {
24564
+ return await new Promise((resolve14) => {
24565
24565
  const onChunk = (chunk) => {
24566
24566
  const s = chunk.toString();
24567
24567
  if (!url2) url2 = parseCloudflaredUrl(s);
24568
24568
  if (TUNNEL_REGISTERED_RE.test(s)) registered = true;
24569
24569
  const trimmed = s.replace(/\n+$/g, "");
24570
24570
  if (trimmed.length > 0) log.info("preview", `cloudflared: ${trimmed}`);
24571
- if (url2 && registered) resolve12({ kind: "registered", url: url2 });
24571
+ if (url2 && registered) resolve14({ kind: "registered", url: url2 });
24572
24572
  };
24573
24573
  const onExit = (code) => {
24574
- resolve12({ kind: "exited", sawUrl: url2 != null, code });
24574
+ resolve14({ kind: "exited", sawUrl: url2 != null, code });
24575
24575
  };
24576
24576
  const { stdout, stderr } = candidate;
24577
24577
  if (stdout) scoped(() => stdout.on("data", onChunk), () => stdout.off("data", onChunk));
24578
24578
  if (stderr) scoped(() => stderr.on("data", onChunk), () => stderr.off("data", onChunk));
24579
24579
  scoped(() => candidate.on("exit", onExit), () => candidate.off("exit", onExit));
24580
- timer = setTimeout(() => resolve12({ kind: "timeout", sawUrl: url2 != null }), deadlineMs);
24580
+ timer = setTimeout(() => resolve14({ kind: "timeout", sawUrl: url2 != null }), deadlineMs);
24581
24581
  });
24582
24582
  } finally {
24583
24583
  ac.abort();
@@ -24600,7 +24600,7 @@ function verdictFor(res) {
24600
24600
  }
24601
24601
  return { adopt: true };
24602
24602
  }
24603
- var probePort = (port) => new Promise((resolve12) => {
24603
+ var probePort = (port) => new Promise((resolve14) => {
24604
24604
  const req = http7.get(
24605
24605
  { host: "127.0.0.1", port, path: "/", timeout: PROBE_TIMEOUT_MS },
24606
24606
  (res) => {
@@ -24611,16 +24611,16 @@ var probePort = (port) => new Promise((resolve12) => {
24611
24611
  });
24612
24612
  res.on(
24613
24613
  "end",
24614
- () => resolve12({ contentType: res.headers["content-type"], bodyStart: body })
24614
+ () => resolve14({ contentType: res.headers["content-type"], bodyStart: body })
24615
24615
  );
24616
- res.on("error", () => resolve12(null));
24616
+ res.on("error", () => resolve14(null));
24617
24617
  }
24618
24618
  );
24619
24619
  req.on("timeout", () => {
24620
24620
  req.destroy();
24621
- resolve12(null);
24621
+ resolve14(null);
24622
24622
  });
24623
- req.on("error", () => resolve12(null));
24623
+ req.on("error", () => resolve14(null));
24624
24624
  });
24625
24625
  async function canAdoptPort(port, probe = probePort) {
24626
24626
  try {
@@ -25157,7 +25157,9 @@ function hasServableProject(cwd) {
25157
25157
  const entries2 = rootEntries(cwd);
25158
25158
  if (!entries2) return false;
25159
25159
  if (entries2.some((e) => SERVABLE_ROOT_FILES.has(e) || /\.html?$/i.test(e))) return true;
25160
- return ["public", "src"].some((dir) => import_node_fs14.default.existsSync(import_node_path12.default.join(cwd, dir, "index.html")));
25160
+ return ["public", "src", "dist", "build"].some(
25161
+ (dir) => import_node_fs14.default.existsSync(import_node_path12.default.join(cwd, dir, "index.html"))
25162
+ );
25161
25163
  }
25162
25164
  function isEmptyScratchProject(cwd) {
25163
25165
  if (!isScratchWorkspace(cwd)) return false;
@@ -25165,14 +25167,35 @@ function isEmptyScratchProject(cwd) {
25165
25167
  return entries2 !== null && entries2.every((e) => e.startsWith(".") || AGENT_NOTES.has(e));
25166
25168
  }
25167
25169
  var bringUps = /* @__PURE__ */ new Set();
25168
- function notePreviewBringUp(sessionId) {
25170
+ var AUTO_PREVIEW_MARKER = import_node_path12.default.join(".codeam", "auto-preview-state.json");
25171
+ function markerPath2(cwd) {
25172
+ return import_node_path12.default.join(cwd, AUTO_PREVIEW_MARKER);
25173
+ }
25174
+ function hasAttemptedMarker(cwd) {
25175
+ try {
25176
+ return import_node_fs14.default.existsSync(markerPath2(cwd));
25177
+ } catch {
25178
+ return false;
25179
+ }
25180
+ }
25181
+ function writeAttemptedMarker(cwd) {
25182
+ try {
25183
+ const file = markerPath2(cwd);
25184
+ import_node_fs14.default.mkdirSync(import_node_path12.default.dirname(file), { recursive: true });
25185
+ import_node_fs14.default.writeFileSync(file, '{"attempted":true}\n', "utf-8");
25186
+ } catch {
25187
+ }
25188
+ }
25189
+ function notePreviewBringUp(sessionId, cwd = process.cwd()) {
25169
25190
  bringUps.add(sessionId);
25191
+ if (isScratchWorkspace(cwd)) writeAttemptedMarker(cwd);
25170
25192
  }
25171
25193
  function maybeAutoOpenScratchPreview(sessionId, bridge, cwd = process.cwd()) {
25172
- if (!isScratchWorkspace(cwd) || bringUps.has(sessionId)) return false;
25194
+ if (!isScratchWorkspace(cwd) || bringUps.has(sessionId) || hasAttemptedMarker(cwd)) return false;
25173
25195
  if (bridge.status().status !== "idle") return false;
25174
25196
  if (!hasServableProject(cwd)) return false;
25175
25197
  bringUps.add(sessionId);
25198
+ writeAttemptedMarker(cwd);
25176
25199
  void bridge.start().catch(() => {
25177
25200
  });
25178
25201
  return true;
@@ -25183,13 +25206,13 @@ var import_node_crypto11 = require("crypto");
25183
25206
  var import_promises5 = __toESM(require("fs/promises"));
25184
25207
  var import_node_os7 = __toESM(require("os"));
25185
25208
  var import_node_path13 = __toESM(require("path"));
25186
- function markerPath2(cwd, homeDir2 = import_node_os7.default.homedir()) {
25209
+ function markerPath3(cwd, homeDir2 = import_node_os7.default.homedir()) {
25187
25210
  const key = (0, import_node_crypto11.createHash)("sha256").update(import_node_path13.default.resolve(cwd)).digest("hex").slice(0, 16);
25188
25211
  return import_node_path13.default.join(homeDir2, ".codeam", "preview-active", `${key}.json`);
25189
25212
  }
25190
25213
  async function writeActivePreviewMarker(cwd, detection, homeDir2) {
25191
25214
  try {
25192
- const file = markerPath2(cwd, homeDir2);
25215
+ const file = markerPath3(cwd, homeDir2);
25193
25216
  await import_promises5.default.mkdir(import_node_path13.default.dirname(file), { recursive: true });
25194
25217
  await import_promises5.default.writeFile(
25195
25218
  file,
@@ -25200,11 +25223,11 @@ async function writeActivePreviewMarker(cwd, detection, homeDir2) {
25200
25223
  }
25201
25224
  }
25202
25225
  async function clearActivePreviewMarker(cwd, homeDir2) {
25203
- await import_promises5.default.rm(markerPath2(cwd, homeDir2), { force: true }).catch(() => void 0);
25226
+ await import_promises5.default.rm(markerPath3(cwd, homeDir2), { force: true }).catch(() => void 0);
25204
25227
  }
25205
25228
  async function readActivePreviewMarker(cwd, homeDir2) {
25206
25229
  try {
25207
- const raw = await import_promises5.default.readFile(markerPath2(cwd, homeDir2), "utf8");
25230
+ const raw = await import_promises5.default.readFile(markerPath3(cwd, homeDir2), "utf8");
25208
25231
  const parsed = JSON.parse(raw);
25209
25232
  return parsed.detection && typeof parsed.detection.command === "string" ? parsed.detection : null;
25210
25233
  } catch {
@@ -25347,12 +25370,16 @@ function buildHouseProxyChildEnv(cfg) {
25347
25370
  };
25348
25371
  if (cfg.openRouter === true) {
25349
25372
  env.ANTHROPIC_API_KEY = "";
25350
- } else {
25351
- const model = typeof cfg.model === "string" && cfg.model ? cfg.model : "MiniMax-M3";
25352
- env.ANTHROPIC_MODEL = model;
25353
- env.ANTHROPIC_DEFAULT_SONNET_MODEL = model;
25354
- env.ANTHROPIC_DEFAULT_OPUS_MODEL = model;
25355
- env.ANTHROPIC_DEFAULT_HAIKU_MODEL = model;
25373
+ } else if (typeof cfg.model === "string" && cfg.model) {
25374
+ env.ANTHROPIC_MODEL = cfg.model;
25375
+ env.ANTHROPIC_DEFAULT_SONNET_MODEL = cfg.model;
25376
+ env.ANTHROPIC_DEFAULT_OPUS_MODEL = cfg.model;
25377
+ env.ANTHROPIC_DEFAULT_HAIKU_MODEL = cfg.model;
25378
+ } else if (!isManagedProviderId(cfg.managedAgentId)) {
25379
+ env.ANTHROPIC_MODEL = "MiniMax-M3";
25380
+ env.ANTHROPIC_DEFAULT_SONNET_MODEL = "MiniMax-M3";
25381
+ env.ANTHROPIC_DEFAULT_OPUS_MODEL = "MiniMax-M3";
25382
+ env.ANTHROPIC_DEFAULT_HAIKU_MODEL = "MiniMax-M3";
25356
25383
  }
25357
25384
  if (typeof cfg.claudeConfigDir === "string" && cfg.claudeConfigDir) {
25358
25385
  env.CLAUDE_CONFIG_DIR = cfg.claudeConfigDir;
@@ -26008,18 +26035,18 @@ async function startInspectorProxy(opts) {
26008
26035
  clientSocket.on("error", drop2);
26009
26036
  clientSocket.on("close", drop2);
26010
26037
  });
26011
- await new Promise((resolve12, reject) => {
26038
+ await new Promise((resolve14, reject) => {
26012
26039
  server.once("error", reject);
26013
- server.listen(0, "127.0.0.1", () => resolve12());
26040
+ server.listen(0, "127.0.0.1", () => resolve14());
26014
26041
  });
26015
26042
  const port = server.address().port;
26016
26043
  return {
26017
26044
  port,
26018
- close: () => new Promise((resolve12) => {
26045
+ close: () => new Promise((resolve14) => {
26019
26046
  for (const socket of upgraded) socket.destroy();
26020
26047
  upgraded.clear();
26021
26048
  server.closeAllConnections?.();
26022
- server.close(() => resolve12());
26049
+ server.close(() => resolve14());
26023
26050
  })
26024
26051
  };
26025
26052
  }
@@ -27103,12 +27130,12 @@ var _spawnSeam = {
27103
27130
  run: _defaultSpawn
27104
27131
  };
27105
27132
  function _defaultSpawn(binaryPath, args2, opts) {
27106
- return new Promise((resolve12) => {
27133
+ return new Promise((resolve14) => {
27107
27134
  let proc;
27108
27135
  try {
27109
27136
  proc = (0, import_child_process21.spawn)(binaryPath, args2, { cwd: opts.cwd, env: opts.env });
27110
27137
  } catch (err) {
27111
- resolve12({ code: -1, stdout: "", stderr: err.message });
27138
+ resolve14({ code: -1, stdout: "", stderr: err.message });
27112
27139
  return;
27113
27140
  }
27114
27141
  let stdout = "";
@@ -27119,8 +27146,8 @@ function _defaultSpawn(binaryPath, args2, opts) {
27119
27146
  proc.stderr?.on("data", (c2) => {
27120
27147
  stderr += c2.toString();
27121
27148
  });
27122
- proc.on("error", (err) => resolve12({ code: -1, stdout, stderr: err.message }));
27123
- proc.on("close", (code) => resolve12({ code: code ?? -1, stdout, stderr }));
27149
+ proc.on("error", (err) => resolve14({ code: -1, stdout, stderr: err.message }));
27150
+ proc.on("close", (code) => resolve14({ code: code ?? -1, stdout, stderr }));
27124
27151
  });
27125
27152
  }
27126
27153
  var _adapterSeam = {
@@ -27297,22 +27324,22 @@ var _installSpawnSeam = {
27297
27324
  run: _defaultInstallSpawn
27298
27325
  };
27299
27326
  function _defaultInstallSpawn(strategy) {
27300
- return new Promise((resolve12) => {
27327
+ return new Promise((resolve14) => {
27301
27328
  let proc;
27302
27329
  try {
27303
27330
  proc = (0, import_child_process22.spawn)(strategy.command, strategy.args, { env: process.env });
27304
27331
  } catch (err) {
27305
- resolve12({ ok: false, code: -1, stderr: err.message });
27332
+ resolve14({ ok: false, code: -1, stderr: err.message });
27306
27333
  return;
27307
27334
  }
27308
27335
  let stderr = "";
27309
27336
  proc.stderr?.on("data", (c2) => {
27310
27337
  stderr += c2.toString();
27311
27338
  });
27312
- proc.on("error", (err) => resolve12({ ok: false, code: -1, stderr: err.message }));
27339
+ proc.on("error", (err) => resolve14({ ok: false, code: -1, stderr: err.message }));
27313
27340
  proc.on(
27314
27341
  "close",
27315
- (code) => resolve12({ ok: code === 0, code: code ?? -1, stderr })
27342
+ (code) => resolve14({ ok: code === 0, code: code ?? -1, stderr })
27316
27343
  );
27317
27344
  });
27318
27345
  }
@@ -27373,11 +27400,11 @@ function resolveDoltInstallStrategy(platform3) {
27373
27400
  }
27374
27401
  var DOLT_RELEASE_BASE = "https://github.com/dolthub/dolt/releases/latest/download";
27375
27402
  function doltPlatformTuple(platform3, arch2) {
27376
- const os70 = platform3 === "win32" ? "windows" : platform3 === "darwin" ? "darwin" : "linux";
27403
+ const os72 = platform3 === "win32" ? "windows" : platform3 === "darwin" ? "darwin" : "linux";
27377
27404
  const a = arch2 === "x64" ? "amd64" : arch2 === "arm64" ? "arm64" : null;
27378
27405
  if (!a) return null;
27379
- if (os70 === "windows" && a !== "amd64") return null;
27380
- return `${os70}-${a}`;
27406
+ if (os72 === "windows" && a !== "amd64") return null;
27407
+ return `${os72}-${a}`;
27381
27408
  }
27382
27409
  function resolveDoltTarballStrategy(targetDir, platform3, arch2) {
27383
27410
  const tuple = doltPlatformTuple(platform3, arch2);
@@ -27481,14 +27508,14 @@ var _doltInstallSpawnSeam = {
27481
27508
  };
27482
27509
  var DOLT_INSTALL_TIMEOUT_MS = 12e4;
27483
27510
  function _defaultDoltInstallSpawn(strategy) {
27484
- return new Promise((resolve12) => {
27511
+ return new Promise((resolve14) => {
27485
27512
  let settled = false;
27486
27513
  let timer;
27487
27514
  const finish = (r) => {
27488
27515
  if (settled) return;
27489
27516
  settled = true;
27490
27517
  if (timer) clearTimeout(timer);
27491
- resolve12(r);
27518
+ resolve14(r);
27492
27519
  };
27493
27520
  let proc;
27494
27521
  try {
@@ -29075,7 +29102,7 @@ var vcsAgentReviewH = async (ctx, cmd, parsed) => {
29075
29102
  });
29076
29103
  const token = ctx.pluginAuthToken;
29077
29104
  void (async () => {
29078
- const os70 = createOsStrategy();
29105
+ const os72 = createOsStrategy();
29079
29106
  try {
29080
29107
  const report = await reviewPullRequest(
29081
29108
  {
@@ -29084,7 +29111,7 @@ var vcsAgentReviewH = async (ctx, cmd, parsed) => {
29084
29111
  baseBranch: parsed.baseBranch
29085
29112
  },
29086
29113
  {
29087
- runReview: (input) => new CoderabbitRuntimeStrategy(os70).runOneShot(input),
29114
+ runReview: (input) => new CoderabbitRuntimeStrategy(os72).runOneShot(input),
29088
29115
  runGh: (args2) => defaultRunGh(args2),
29089
29116
  postReport: async (r) => {
29090
29117
  if (!token) return;
@@ -29229,13 +29256,13 @@ function resolveGlobalNodeModulesDir(opts) {
29229
29256
  var STALE_STAGING_AGE_MS = CLI_UPDATE_INSTALL_TIMEOUT_MS;
29230
29257
  function sweepStaleCliStagingDirs(nodeModulesDir, now = Date.now(), deps) {
29231
29258
  if (!nodeModulesDir) return 0;
29232
- const readdirSync17 = deps?.readdirSync ?? fs63.readdirSync;
29233
- const statSync16 = deps?.statSync ?? fs63.statSync;
29234
- const rmSync11 = deps?.rmSync ?? fs63.rmSync;
29259
+ const readdirSync18 = deps?.readdirSync ?? fs63.readdirSync;
29260
+ const statSync17 = deps?.statSync ?? fs63.statSync;
29261
+ const rmSync14 = deps?.rmSync ?? fs63.rmSync;
29235
29262
  let removed = 0;
29236
29263
  let entries2;
29237
29264
  try {
29238
- entries2 = readdirSync17(nodeModulesDir);
29265
+ entries2 = readdirSync18(nodeModulesDir);
29239
29266
  } catch {
29240
29267
  return 0;
29241
29268
  }
@@ -29243,9 +29270,9 @@ function sweepStaleCliStagingDirs(nodeModulesDir, now = Date.now(), deps) {
29243
29270
  if (!/^\.codeam-cli-/.test(name)) continue;
29244
29271
  const full = path72.join(nodeModulesDir, name);
29245
29272
  try {
29246
- const st3 = statSync16(full);
29273
+ const st3 = statSync17(full);
29247
29274
  if (now - st3.mtimeMs < STALE_STAGING_AGE_MS) continue;
29248
- rmSync11(full, { recursive: true, force: true });
29275
+ rmSync14(full, { recursive: true, force: true });
29249
29276
  removed++;
29250
29277
  } catch {
29251
29278
  }
@@ -29266,16 +29293,16 @@ async function runNpmInstallLatest() {
29266
29293
  const invocation = buildNpmInstallInvocation({ sudo: useSudo });
29267
29294
  const useShell = process.platform === "win32";
29268
29295
  const command2 = useShell && invocation.command.includes(" ") ? `"${invocation.command}"` : invocation.command;
29269
- const result = await new Promise((resolve12) => {
29296
+ const result = await new Promise((resolve14) => {
29270
29297
  (0, import_child_process25.execFile)(
29271
29298
  command2,
29272
29299
  invocation.args,
29273
29300
  { timeout: CLI_UPDATE_INSTALL_TIMEOUT_MS, shell: useShell },
29274
29301
  (err, _stdout, stderr) => {
29275
29302
  if (!err) {
29276
- resolve12({ ok: true });
29303
+ resolve14({ ok: true });
29277
29304
  } else {
29278
- resolve12({ ok: false, error: (stderr || err.message).slice(0, 300) });
29305
+ resolve14({ ok: false, error: (stderr || err.message).slice(0, 300) });
29279
29306
  }
29280
29307
  }
29281
29308
  );
@@ -29628,8 +29655,8 @@ async function runDetectOneShot(generate, timeoutMs = PREVIEW_DETECT_TIMEOUT_MS)
29628
29655
  };
29629
29656
  const onFailedOutput = (stdout) => onStderr(`
29630
29657
  ${stdout}`);
29631
- const deadline = new Promise((resolve12) => {
29632
- timer = setTimeout(() => resolve12({ raw: null, timedOut: true, stderr }), timeoutMs);
29658
+ const deadline = new Promise((resolve14) => {
29659
+ timer = setTimeout(() => resolve14({ raw: null, timedOut: true, stderr }), timeoutMs);
29633
29660
  timer.unref?.();
29634
29661
  });
29635
29662
  const oneShot = generate(PREVIEW_DETECT_PROMPT, { timeoutMs, onStderr, onFailedOutput }).then(
@@ -30097,7 +30124,7 @@ function buildKeepAlive(ctx) {
30097
30124
  let timer = null;
30098
30125
  async function setIdleTimeout(minutes) {
30099
30126
  if (!ctx.inCodespace || !ctx.codespaceName) return;
30100
- await new Promise((resolve12) => {
30127
+ await new Promise((resolve14) => {
30101
30128
  const proc = (0, import_child_process26.spawn)(
30102
30129
  "gh",
30103
30130
  [
@@ -30111,8 +30138,8 @@ function buildKeepAlive(ctx) {
30111
30138
  { stdio: "ignore", detached: true }
30112
30139
  );
30113
30140
  proc.unref();
30114
- proc.on("exit", () => resolve12());
30115
- proc.on("error", () => resolve12());
30141
+ proc.on("exit", () => resolve14());
30142
+ proc.on("error", () => resolve14());
30116
30143
  });
30117
30144
  }
30118
30145
  return {
@@ -30364,11 +30391,11 @@ function resolveTokenValue(args2) {
30364
30391
  }
30365
30392
  const fileFlag = args2.find((a) => a.startsWith("--token-file="));
30366
30393
  if (fileFlag) {
30367
- const path109 = fileFlag.slice("--token-file=".length);
30394
+ const path112 = fileFlag.slice("--token-file=".length);
30368
30395
  try {
30369
- const content = fs64.readFileSync(path109, "utf8").trim();
30370
- if (content.length === 0) fail(`--token-file ${path109} is empty`);
30371
- rmIfExistsQuiet(path109);
30396
+ const content = fs64.readFileSync(path112, "utf8").trim();
30397
+ if (content.length === 0) fail(`--token-file ${path112} is empty`);
30398
+ rmIfExistsQuiet(path112);
30372
30399
  return content;
30373
30400
  } catch (err) {
30374
30401
  fail(`Could not read --token-file: ${err.message}`);
@@ -31069,10 +31096,10 @@ function augmentKimiPath() {
31069
31096
  }
31070
31097
  var augmentPath2 = augmentKimiPath;
31071
31098
  async function runInstaller2() {
31072
- return new Promise((resolve12) => {
31099
+ return new Promise((resolve14) => {
31073
31100
  const proc = (0, import_node_child_process25.spawn)("sh", ["-c", `curl -fsSL ${INSTALL_URL2} | bash`], { stdio: "inherit" });
31074
- proc.on("close", (code) => resolve12(code === 0));
31075
- proc.on("error", () => resolve12(false));
31101
+ proc.on("close", (code) => resolve14(code === 0));
31102
+ proc.on("error", () => resolve14(false));
31076
31103
  });
31077
31104
  }
31078
31105
  async function ensureKimiInstalled() {
@@ -31122,10 +31149,10 @@ function augmentOpencodePath() {
31122
31149
  }
31123
31150
  var augmentPath3 = augmentOpencodePath;
31124
31151
  async function runInstaller3() {
31125
- return new Promise((resolve12) => {
31152
+ return new Promise((resolve14) => {
31126
31153
  const proc = (0, import_node_child_process26.spawn)("sh", ["-c", `curl -fsSL ${INSTALL_URL3} | bash`], { stdio: "inherit" });
31127
- proc.on("close", (code) => resolve12(code === 0));
31128
- proc.on("error", () => resolve12(false));
31154
+ proc.on("close", (code) => resolve14(code === 0));
31155
+ proc.on("error", () => resolve14(false));
31129
31156
  });
31130
31157
  }
31131
31158
  async function ensureOpencodeInstalled() {
@@ -31333,11 +31360,11 @@ async function resolveAcpAdapterWithRetry(agent, opts = {}) {
31333
31360
  const timeoutMs = opts.timeoutMs ?? DEFAULT_ADAPTER_RETRY_TIMEOUT_MS;
31334
31361
  const pollMs = opts.pollMs ?? DEFAULT_ADAPTER_RETRY_POLL_MS;
31335
31362
  const now = opts.now ?? Date.now;
31336
- const sleep5 = opts.sleep ?? ((ms) => new Promise((resolve13) => setTimeout(resolve13, ms)));
31337
- const resolve12 = opts.resolve ?? getAcpAdapter;
31363
+ const sleep5 = opts.sleep ?? ((ms) => new Promise((resolve15) => setTimeout(resolve15, ms)));
31364
+ const resolve14 = opts.resolve ?? getAcpAdapter;
31338
31365
  const attempt = () => {
31339
31366
  try {
31340
- return resolve12(agent);
31367
+ return resolve14(agent);
31341
31368
  } catch {
31342
31369
  return null;
31343
31370
  }
@@ -31492,7 +31519,7 @@ function parseJsonl(filePath) {
31492
31519
  return messages;
31493
31520
  }
31494
31521
  function postWithStatus(endpoint, body, pluginAuthToken) {
31495
- return new Promise((resolve12) => {
31522
+ return new Promise((resolve14) => {
31496
31523
  const payload = JSON.stringify(body);
31497
31524
  const u2 = new URL(`${API_BASE7}${endpoint}`);
31498
31525
  const transport = u2.protocol === "https:" ? https6 : http10;
@@ -31523,17 +31550,17 @@ function postWithStatus(endpoint, body, pluginAuthToken) {
31523
31550
  const ra = Number(res.headers["retry-after"]);
31524
31551
  retryAfterMs = Number.isFinite(ra) && ra > 0 ? ra * 1e3 : 2e4;
31525
31552
  }
31526
- resolve12({ ok, status: status2, retryAfterMs });
31553
+ resolve14({ ok, status: status2, retryAfterMs });
31527
31554
  }
31528
31555
  );
31529
31556
  req.on("error", (err) => {
31530
31557
  log.warn("history:post", `${endpoint} network error`, err);
31531
- resolve12({ ok: false, status: null, retryAfterMs: null });
31558
+ resolve14({ ok: false, status: null, retryAfterMs: null });
31532
31559
  });
31533
31560
  req.on("timeout", () => {
31534
31561
  log.warn("history:post", `${endpoint} timeout after 15s`);
31535
31562
  req.destroy();
31536
- resolve12({ ok: false, status: null, retryAfterMs: null });
31563
+ resolve14({ ok: false, status: null, retryAfterMs: null });
31537
31564
  });
31538
31565
  req.write(payload);
31539
31566
  req.end();
@@ -34107,12 +34134,12 @@ var Connection = class {
34107
34134
  const id = this.nextRequestId++;
34108
34135
  let cancel = () => {
34109
34136
  };
34110
- const responsePromise = new Promise((resolve12, reject) => {
34137
+ const responsePromise = new Promise((resolve14, reject) => {
34111
34138
  const pendingResponse = {
34112
34139
  resolve: (response) => {
34113
34140
  try {
34114
34141
  const value = mapResponse ? mapResponse(response) : response;
34115
- resolve12(value);
34142
+ resolve14(value);
34116
34143
  } catch (error) {
34117
34144
  reject(error);
34118
34145
  }
@@ -34190,8 +34217,8 @@ var Connection = class {
34190
34217
  initialize(stream, handlers2) {
34191
34218
  this.stream = stream;
34192
34219
  this.staticHandlers = handlers2;
34193
- this.closedPromise = new Promise((resolve12) => {
34194
- this.abortController.signal.addEventListener("abort", () => resolve12());
34220
+ this.closedPromise = new Promise((resolve14) => {
34221
+ this.abortController.signal.addEventListener("abort", () => resolve14());
34195
34222
  });
34196
34223
  void this.receive();
34197
34224
  }
@@ -34979,8 +35006,8 @@ var AsyncQueue = class {
34979
35006
  if (this.failed) {
34980
35007
  return Promise.reject(this.failure);
34981
35008
  }
34982
- return new Promise((resolve12, reject) => {
34983
- this.waiters.push({ resolve: resolve12, reject });
35009
+ return new Promise((resolve14, reject) => {
35010
+ this.waiters.push({ resolve: resolve14, reject });
34984
35011
  });
34985
35012
  }
34986
35013
  };
@@ -36672,7 +36699,7 @@ var AcpClient = class {
36672
36699
  this.pendingToolCalls.clear();
36673
36700
  try {
36674
36701
  const result = await Promise.race([send, idle.promise]);
36675
- await new Promise((resolve12) => setImmediate(resolve12));
36702
+ await new Promise((resolve14) => setImmediate(resolve14));
36676
36703
  log.info(
36677
36704
  "acpClient",
36678
36705
  `prompt \u2190 ok stopReason=${result.stopReason ?? "?"} elapsedMs=${Date.now() - t0}`
@@ -36888,8 +36915,8 @@ var AcpClient = class {
36888
36915
  if (!this.connection || !this.sessionId) return "deferred";
36889
36916
  this.mcpReprovisionPending = servers;
36890
36917
  if (this.mcpDebounceTimer) clearTimeout(this.mcpDebounceTimer);
36891
- const settled = new Promise((resolve12) => {
36892
- this.mcpDebounceWaiters.push(resolve12);
36918
+ const settled = new Promise((resolve14) => {
36919
+ this.mcpDebounceWaiters.push(resolve14);
36893
36920
  });
36894
36921
  this.mcpDebounceTimer = setTimeout(() => {
36895
36922
  this.mcpDebounceTimer = null;
@@ -37133,15 +37160,15 @@ var AcpClient = class {
37133
37160
  } else {
37134
37161
  child.kill("SIGTERM");
37135
37162
  }
37136
- const grace = new Promise((resolve12) => {
37163
+ const grace = new Promise((resolve14) => {
37137
37164
  const t2 = setTimeout(() => {
37138
37165
  if (process.platform !== "win32" && pid) killQuiet(-pid, "SIGKILL");
37139
37166
  else killQuiet(child, "SIGKILL");
37140
- resolve12();
37167
+ resolve14();
37141
37168
  }, 2e3);
37142
37169
  child.once("exit", () => {
37143
37170
  clearTimeout(t2);
37144
- resolve12();
37171
+ resolve14();
37145
37172
  });
37146
37173
  });
37147
37174
  await grace;
@@ -37370,7 +37397,7 @@ var os50 = __toESM(require("os"));
37370
37397
  function runAgentInstallScript(script, opts = {}) {
37371
37398
  const timeoutMs = opts.timeoutMs ?? 18e4;
37372
37399
  const scope = opts.logScope ?? "agent-install";
37373
- return new Promise((resolve12) => {
37400
+ return new Promise((resolve14) => {
37374
37401
  const home = process.env.HOME || os50.homedir();
37375
37402
  const child = (0, import_child_process27.spawn)("sh", ["-c", script], {
37376
37403
  env: { ...process.env, HOME: home },
@@ -37386,7 +37413,7 @@ function runAgentInstallScript(script, opts = {}) {
37386
37413
  const done = (result) => {
37387
37414
  if (settled) return;
37388
37415
  settled = true;
37389
- resolve12(result);
37416
+ resolve14(result);
37390
37417
  };
37391
37418
  const timer = setTimeout(() => {
37392
37419
  log.warn(scope, `agent install timed out (${Math.round(timeoutMs / 1e3)}s)`);
@@ -37999,7 +38026,7 @@ var _transport4 = {
37999
38026
  get: _get
38000
38027
  };
38001
38028
  function _post3(url2, headers, payload) {
38002
- return new Promise((resolve12, reject) => {
38029
+ return new Promise((resolve14, reject) => {
38003
38030
  let settled = false;
38004
38031
  const u2 = new URL(url2);
38005
38032
  const lib = u2.protocol === "https:" ? https7 : http11;
@@ -38024,7 +38051,7 @@ function _post3(url2, headers, payload) {
38024
38051
  res.on("end", () => {
38025
38052
  if (settled) return;
38026
38053
  settled = true;
38027
- resolve12({ statusCode: res.statusCode ?? 0, body });
38054
+ resolve14({ statusCode: res.statusCode ?? 0, body });
38028
38055
  });
38029
38056
  }
38030
38057
  );
@@ -38041,7 +38068,7 @@ function _post3(url2, headers, payload) {
38041
38068
  });
38042
38069
  }
38043
38070
  function _get(url2, headers) {
38044
- return new Promise((resolve12, reject) => {
38071
+ return new Promise((resolve14, reject) => {
38045
38072
  let settled = false;
38046
38073
  const u2 = new URL(url2);
38047
38074
  const lib = u2.protocol === "https:" ? https7 : http11;
@@ -38065,7 +38092,7 @@ function _get(url2, headers) {
38065
38092
  res.on("end", () => {
38066
38093
  if (settled) return;
38067
38094
  settled = true;
38068
- resolve12({ statusCode: res.statusCode ?? 0, body });
38095
+ resolve14({ statusCode: res.statusCode ?? 0, body });
38069
38096
  });
38070
38097
  }
38071
38098
  );
@@ -39296,12 +39323,12 @@ function runGit3(cwd, args2) {
39296
39323
  return _runGitImpl2.run(cwd, args2);
39297
39324
  }
39298
39325
  function defaultRunGit(cwd, args2) {
39299
- return new Promise((resolve12) => {
39326
+ return new Promise((resolve14) => {
39300
39327
  let proc;
39301
39328
  try {
39302
39329
  proc = (0, import_child_process29.spawn)("git", args2, { cwd, env: process.env });
39303
39330
  } catch {
39304
- resolve12(null);
39331
+ resolve14(null);
39305
39332
  return;
39306
39333
  }
39307
39334
  let stdout = "";
@@ -39312,22 +39339,22 @@ function defaultRunGit(cwd, args2) {
39312
39339
  proc.stderr?.on("data", (c2) => {
39313
39340
  stderr += c2.toString();
39314
39341
  });
39315
- proc.on("error", () => resolve12(null));
39342
+ proc.on("error", () => resolve14(null));
39316
39343
  proc.on("close", (code) => {
39317
39344
  if (code === 0) {
39318
- resolve12(stdout);
39345
+ resolve14(stdout);
39319
39346
  } else {
39320
39347
  log.trace(
39321
39348
  "turnFiles",
39322
39349
  `git ${args2.join(" ")} exited ${code} stderr=${stderr.slice(0, 200)}`
39323
39350
  );
39324
- resolve12(null);
39351
+ resolve14(null);
39325
39352
  }
39326
39353
  });
39327
39354
  });
39328
39355
  }
39329
39356
  async function discoverRepos(workingDir, maxDepth = 4) {
39330
- const fs94 = await import("fs/promises");
39357
+ const fs97 = await import("fs/promises");
39331
39358
  const out2 = [];
39332
39359
  await walk2(workingDir, 0);
39333
39360
  return out2;
@@ -39335,7 +39362,7 @@ async function discoverRepos(workingDir, maxDepth = 4) {
39335
39362
  if (depth2 > maxDepth) return;
39336
39363
  let entries2 = [];
39337
39364
  try {
39338
- const dirents = await fs94.readdir(dir, { withFileTypes: true });
39365
+ const dirents = await fs97.readdir(dir, { withFileTypes: true });
39339
39366
  entries2 = dirents.filter((d3) => !d3.name.startsWith(".") || d3.name === ".git").map((d3) => ({ name: d3.name, isDirectory: d3.isDirectory() }));
39340
39367
  } catch {
39341
39368
  return;
@@ -39738,25 +39765,25 @@ function baselineKey(entry) {
39738
39765
 
39739
39766
  // src/agents/acp/withTimeout.ts
39740
39767
  function withTimeout(p2, ms) {
39741
- return new Promise((resolve12) => {
39768
+ return new Promise((resolve14) => {
39742
39769
  let settled = false;
39743
39770
  const timer = setTimeout(() => {
39744
39771
  if (settled) return;
39745
39772
  settled = true;
39746
- resolve12(void 0);
39773
+ resolve14(void 0);
39747
39774
  }, ms);
39748
39775
  p2.then(
39749
39776
  (v) => {
39750
39777
  if (settled) return;
39751
39778
  settled = true;
39752
39779
  clearTimeout(timer);
39753
- resolve12(v);
39780
+ resolve14(v);
39754
39781
  },
39755
39782
  () => {
39756
39783
  if (settled) return;
39757
39784
  settled = true;
39758
39785
  clearTimeout(timer);
39759
- resolve12(void 0);
39786
+ resolve14(void 0);
39760
39787
  }
39761
39788
  );
39762
39789
  });
@@ -39853,13 +39880,13 @@ var import_node_crypto13 = require("crypto");
39853
39880
  var import_promises6 = __toESM(require("fs/promises"));
39854
39881
  var import_node_os14 = __toESM(require("os"));
39855
39882
  var import_node_path20 = __toESM(require("path"));
39856
- function markerPath3(cwd, homeDir2 = import_node_os14.default.homedir()) {
39883
+ function markerPath4(cwd, homeDir2 = import_node_os14.default.homedir()) {
39857
39884
  const key = (0, import_node_crypto13.createHash)("sha256").update(import_node_path20.default.resolve(cwd)).digest("hex").slice(0, 16);
39858
39885
  return import_node_path20.default.join(homeDir2, ".codeam", "conversation-active", `${key}.json`);
39859
39886
  }
39860
39887
  async function writeActiveConversationMarker(cwd, conversationId, homeDir2) {
39861
39888
  try {
39862
- const file = markerPath3(cwd, homeDir2);
39889
+ const file = markerPath4(cwd, homeDir2);
39863
39890
  await import_promises6.default.mkdir(import_node_path20.default.dirname(file), { recursive: true });
39864
39891
  await import_promises6.default.writeFile(
39865
39892
  file,
@@ -39871,7 +39898,7 @@ async function writeActiveConversationMarker(cwd, conversationId, homeDir2) {
39871
39898
  }
39872
39899
  async function readActiveConversationMarker(cwd, homeDir2) {
39873
39900
  try {
39874
- const raw = await import_promises6.default.readFile(markerPath3(cwd, homeDir2), "utf8");
39901
+ const raw = await import_promises6.default.readFile(markerPath4(cwd, homeDir2), "utf8");
39875
39902
  const parsed = JSON.parse(raw);
39876
39903
  return typeof parsed.conversationId === "string" && parsed.conversationId ? parsed.conversationId : null;
39877
39904
  } catch {
@@ -39925,7 +39952,7 @@ function isProcessMidTurn(pid, home) {
39925
39952
  var import_node_child_process28 = require("child_process");
39926
39953
  var fs77 = __toESM(require("fs"));
39927
39954
  var path88 = __toESM(require("path"));
39928
- var defaultCommandRunner = (file, args2, cwd, timeoutMs, env) => new Promise((resolve12) => {
39955
+ var defaultCommandRunner = (file, args2, cwd, timeoutMs, env) => new Promise((resolve14) => {
39929
39956
  (0, import_node_child_process28.execFile)(
39930
39957
  file,
39931
39958
  args2,
@@ -39941,7 +39968,7 @@ var defaultCommandRunner = (file, args2, cwd, timeoutMs, env) => new Promise((re
39941
39968
  const rawCode = err.code;
39942
39969
  code = typeof rawCode === "number" ? rawCode : 1;
39943
39970
  }
39944
- resolve12({ code, stdout: stdout ?? "", stderr: stderr ?? "" });
39971
+ resolve14({ code, stdout: stdout ?? "", stderr: stderr ?? "" });
39945
39972
  }
39946
39973
  );
39947
39974
  });
@@ -41191,11 +41218,11 @@ function previewMcpServer(bridge) {
41191
41218
  };
41192
41219
  }
41193
41220
  function httpCall(baseUrl, token) {
41194
- return async (path109, method, body, timeoutMs) => {
41221
+ return async (path112, method, body, timeoutMs) => {
41195
41222
  const ac = new AbortController();
41196
41223
  const timer = setTimeout(() => ac.abort(), timeoutMs);
41197
41224
  try {
41198
- const res = await fetch(`${baseUrl}${path109}`, {
41225
+ const res = await fetch(`${baseUrl}${path112}`, {
41199
41226
  method,
41200
41227
  headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
41201
41228
  ...method === "POST" ? { body: JSON.stringify(body ?? {}) } : {},
@@ -41323,11 +41350,11 @@ function scratchMcpServer(bridge) {
41323
41350
  };
41324
41351
  }
41325
41352
  function httpCall2(baseUrl, token) {
41326
- return async (path109, method, body, timeoutMs) => {
41353
+ return async (path112, method, body, timeoutMs) => {
41327
41354
  const ac = new AbortController();
41328
41355
  const timer = setTimeout(() => ac.abort(), timeoutMs);
41329
41356
  try {
41330
- const res = await fetch(`${baseUrl}${path109}`, {
41357
+ const res = await fetch(`${baseUrl}${path112}`, {
41331
41358
  method,
41332
41359
  headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
41333
41360
  ...method === "POST" ? { body: JSON.stringify(body ?? {}) } : {},
@@ -41583,24 +41610,24 @@ var AgentPreviewBridge = class {
41583
41610
  * preview tools are then simply absent, never a failed session. */
41584
41611
  listen() {
41585
41612
  if (this.listening) return this.listening;
41586
- this.listening = new Promise((resolve12) => {
41613
+ this.listening = new Promise((resolve14) => {
41587
41614
  const server = http12.createServer((req, res) => {
41588
41615
  void this.handle(req, res);
41589
41616
  });
41590
41617
  server.on("error", (err) => {
41591
41618
  log.warn("agent-preview", `bridge failed to listen: ${String(err)}`);
41592
- resolve12(null);
41619
+ resolve14(null);
41593
41620
  });
41594
41621
  server.listen(0, "127.0.0.1", () => {
41595
41622
  const addr = server.address();
41596
41623
  if (!addr || typeof addr === "string") {
41597
- resolve12(null);
41624
+ resolve14(null);
41598
41625
  return;
41599
41626
  }
41600
41627
  server.unref();
41601
41628
  this.server = server;
41602
41629
  this.bound = { url: `http://127.0.0.1:${addr.port}`, token: this.token };
41603
- resolve12(this.bound);
41630
+ resolve14(this.bound);
41604
41631
  });
41605
41632
  });
41606
41633
  return this.listening;
@@ -41637,9 +41664,9 @@ var AgentPreviewBridge = class {
41637
41664
  }
41638
41665
  const inflight = this.inflight;
41639
41666
  let timer;
41640
- const pending2 = new Promise((resolve12) => {
41667
+ const pending2 = new Promise((resolve14) => {
41641
41668
  timer = setTimeout(
41642
- () => resolve12({
41669
+ () => resolve14({
41643
41670
  status: "starting",
41644
41671
  message: "The preview is still coming up (dependencies or a slow dev server). It keeps going in the background \u2014 call preview_status in a minute."
41645
41672
  }),
@@ -41842,7 +41869,7 @@ function authorized(header, token) {
41842
41869
  return presented.length === expected.length && (0, import_node_crypto14.timingSafeEqual)(presented, expected);
41843
41870
  }
41844
41871
  function readJson(req) {
41845
- return new Promise((resolve12, reject) => {
41872
+ return new Promise((resolve14, reject) => {
41846
41873
  let raw = "";
41847
41874
  req.setEncoding("utf8");
41848
41875
  req.on("data", (chunk) => {
@@ -41853,10 +41880,10 @@ function readJson(req) {
41853
41880
  }
41854
41881
  });
41855
41882
  req.on("end", () => {
41856
- if (!raw) return resolve12({});
41883
+ if (!raw) return resolve14({});
41857
41884
  try {
41858
41885
  const parsed = JSON.parse(raw);
41859
- resolve12(parsed && typeof parsed === "object" ? parsed : {});
41886
+ resolve14(parsed && typeof parsed === "object" ? parsed : {});
41860
41887
  } catch {
41861
41888
  reject(new Error("invalid JSON"));
41862
41889
  }
@@ -42983,15 +43010,15 @@ async function prewarmNewMcpEntries(manifest, previousIds) {
42983
43010
  );
42984
43011
  await Promise.all(
42985
43012
  fresh.map(
42986
- (e) => new Promise((resolve12) => {
43013
+ (e) => new Promise((resolve14) => {
42987
43014
  const mcp = e.delivery.mcp;
42988
43015
  const child = (0, import_node_child_process29.execFile)(
42989
43016
  mcp.command,
42990
43017
  [...mcp.args, "--help"],
42991
43018
  { timeout: 9e4 },
42992
- () => resolve12()
43019
+ () => resolve14()
42993
43020
  );
42994
- child.on("error", () => resolve12());
43021
+ child.on("error", () => resolve14());
42995
43022
  })
42996
43023
  )
42997
43024
  );
@@ -43258,7 +43285,7 @@ var StreamingState = class {
43258
43285
  * protested "J'ai rien refusé". The line is the user's evidence.
43259
43286
  */
43260
43287
  registerPermission(args2) {
43261
- return new Promise((resolve12) => {
43288
+ return new Promise((resolve14) => {
43262
43289
  const timeoutTimer = setTimeout(() => {
43263
43290
  if (this.pending?.kind === "permission" && this.pending.questionId === args2.questionId) {
43264
43291
  log.warn(
@@ -43271,14 +43298,14 @@ var StreamingState = class {
43271
43298
  content: permissionExpiredNotice(),
43272
43299
  done: true
43273
43300
  });
43274
- resolve12({ outcome: { outcome: "cancelled" } });
43301
+ resolve14({ outcome: { outcome: "cancelled" } });
43275
43302
  }
43276
43303
  }, PERMISSION_TIMEOUT_MS);
43277
43304
  this.setPending({
43278
43305
  kind: "permission",
43279
43306
  questionId: args2.questionId,
43280
43307
  options: args2.options,
43281
- resolve: resolve12,
43308
+ resolve: resolve14,
43282
43309
  timeoutTimer
43283
43310
  });
43284
43311
  });
@@ -43315,14 +43342,14 @@ var StreamingState = class {
43315
43342
  const byId = optionId ? this.pending.options.find((o) => o.optionId === optionId) : void 0;
43316
43343
  const picked = byId ?? this.pending.options[index];
43317
43344
  clearTimeout(this.pending.timeoutTimer);
43318
- const resolve12 = this.pending.resolve;
43345
+ const resolve14 = this.pending.resolve;
43319
43346
  this.setPending(null);
43320
43347
  if (!picked) {
43321
43348
  log.warn("acpRunner", `select_option index=${index} out of bounds \u2014 cancel`);
43322
- resolve12({ outcome: { outcome: "cancelled" } });
43349
+ resolve14({ outcome: { outcome: "cancelled" } });
43323
43350
  return { kind: "resolved", optionId: null };
43324
43351
  }
43325
- resolve12({ outcome: { outcome: "selected", optionId: picked.optionId } });
43352
+ resolve14({ outcome: { outcome: "selected", optionId: picked.optionId } });
43326
43353
  return { kind: "resolved", optionId: picked.optionId };
43327
43354
  }
43328
43355
  const text = this.pending.options[index];
@@ -45921,10 +45948,10 @@ var NativeTuiDriver = class _NativeTuiDriver {
45921
45948
  this.lastOutput = this.now();
45922
45949
  }
45923
45950
  whenSafeToYield() {
45924
- return new Promise((resolve12) => {
45951
+ return new Promise((resolve14) => {
45925
45952
  const tick = () => {
45926
45953
  const quietFor = this.now() - this.lastOutput;
45927
- if (quietFor >= this.idleMs) resolve12();
45954
+ if (quietFor >= this.idleMs) resolve14();
45928
45955
  else setTimeout(tick, this.idleMs - quietFor);
45929
45956
  };
45930
45957
  tick();
@@ -45987,10 +46014,10 @@ var AcpDriver = class {
45987
46014
  * one ever is, assume resumable so behaviour is unchanged.
45988
46015
  */
45989
46016
  hasTranscript(conversationId) {
45990
- const resolve12 = this.deps.runtime.resolveHistoryFile;
45991
- if (typeof resolve12 !== "function") return true;
46017
+ const resolve14 = this.deps.runtime.resolveHistoryFile;
46018
+ if (typeof resolve14 !== "function") return true;
45992
46019
  try {
45993
- return resolve12.call(this.deps.runtime, this.deps.opts.cwd, conversationId) !== null;
46020
+ return resolve14.call(this.deps.runtime, this.deps.opts.cwd, conversationId) !== null;
45994
46021
  } catch {
45995
46022
  return true;
45996
46023
  }
@@ -46054,11 +46081,11 @@ var AcpDriver = class {
46054
46081
  this.turnActive = false;
46055
46082
  const waiters = this.waiters;
46056
46083
  this.waiters = [];
46057
- waiters.forEach((resolve12) => resolve12());
46084
+ waiters.forEach((resolve14) => resolve14());
46058
46085
  }
46059
46086
  whenSafeToYield() {
46060
46087
  if (!this.turnActive) return Promise.resolve();
46061
- return new Promise((resolve12) => this.waiters.push(resolve12));
46088
+ return new Promise((resolve14) => this.waiters.push(resolve14));
46062
46089
  }
46063
46090
  };
46064
46091
 
@@ -46712,8 +46739,8 @@ async function start(requestedAgent, presetSession) {
46712
46739
  let gateTimer;
46713
46740
  await Promise.race([
46714
46741
  Promise.all([depsReady, agentBinaryReady]),
46715
- new Promise((resolve12) => {
46716
- gateTimer = setTimeout(resolve12, GATE_TIMEOUT_MS);
46742
+ new Promise((resolve14) => {
46743
+ gateTimer = setTimeout(resolve14, GATE_TIMEOUT_MS);
46717
46744
  })
46718
46745
  ]);
46719
46746
  if (gateTimer) clearTimeout(gateTimer);
@@ -47094,7 +47121,7 @@ async function pair(args2 = []) {
47094
47121
  waitSpin.message(waitMessage());
47095
47122
  }, 1e3);
47096
47123
  countdownInterval.unref?.();
47097
- await new Promise((resolve12) => {
47124
+ await new Promise((resolve14) => {
47098
47125
  let stopPolling = null;
47099
47126
  function sigintHandler() {
47100
47127
  clearInterval(countdownInterval);
@@ -47145,7 +47172,7 @@ async function pair(args2 = []) {
47145
47172
  pluginAuthToken: info.pluginAuthToken
47146
47173
  });
47147
47174
  }
47148
- resolve12();
47175
+ resolve14();
47149
47176
  },
47150
47177
  () => {
47151
47178
  clearInterval(countdownInterval);
@@ -47374,12 +47401,12 @@ var GitHubCodespacesProvider = class {
47374
47401
  }
47375
47402
  if (!isAuthed) {
47376
47403
  resetStdinForChild();
47377
- await new Promise((resolve12, reject) => {
47404
+ await new Promise((resolve14, reject) => {
47378
47405
  const proc = (0, import_child_process30.spawn)("gh", ["auth", "login", "-s", "codespace,repo,read:user"], {
47379
47406
  stdio: "inherit"
47380
47407
  });
47381
47408
  proc.on("exit", (code) => {
47382
- if (code === 0) resolve12();
47409
+ if (code === 0) resolve14();
47383
47410
  else reject(new Error("gh auth login failed."));
47384
47411
  });
47385
47412
  proc.on("error", reject);
@@ -47408,13 +47435,13 @@ var GitHubCodespacesProvider = class {
47408
47435
  }
47409
47436
  wt(noteLines.join("\n"), "One more permission needed");
47410
47437
  resetStdinForChild();
47411
- const refreshCode = await new Promise((resolve12, reject) => {
47438
+ const refreshCode = await new Promise((resolve14, reject) => {
47412
47439
  const proc = (0, import_child_process30.spawn)(
47413
47440
  "gh",
47414
47441
  ["auth", "refresh", "-h", "github.com", "-s", "codespace"],
47415
47442
  { stdio: "inherit" }
47416
47443
  );
47417
- proc.on("exit", (code) => resolve12(code ?? 1));
47444
+ proc.on("exit", (code) => resolve14(code ?? 1));
47418
47445
  proc.on("error", reject);
47419
47446
  });
47420
47447
  if (refreshCode !== 0) {
@@ -47558,10 +47585,10 @@ var GitHubCodespacesProvider = class {
47558
47585
  if (q(proceed) || !proceed) return;
47559
47586
  O2.step(`Installing gh via ${installCmd.describe}\u2026`);
47560
47587
  resetStdinForChild();
47561
- const ok = await new Promise((resolve12) => {
47588
+ const ok = await new Promise((resolve14) => {
47562
47589
  const proc = (0, import_child_process30.spawn)(installCmd.exe, installCmd.args, { stdio: "inherit" });
47563
- proc.on("exit", (code) => resolve12(code === 0));
47564
- proc.on("error", () => resolve12(false));
47590
+ proc.on("exit", (code) => resolve14(code === 0));
47591
+ proc.on("error", () => resolve14(false));
47565
47592
  });
47566
47593
  if (ok) O2.success("gh installed");
47567
47594
  else O2.error("gh install failed");
@@ -47585,14 +47612,14 @@ var GitHubCodespacesProvider = class {
47585
47612
  "Expanding GitHub scopes"
47586
47613
  );
47587
47614
  resetStdinForChild();
47588
- await new Promise((resolve12, reject) => {
47615
+ await new Promise((resolve14, reject) => {
47589
47616
  const proc = (0, import_child_process30.spawn)(
47590
47617
  "gh",
47591
47618
  ["auth", "refresh", "-h", "github.com", "-s", "repo,read:org"],
47592
47619
  { stdio: "inherit" }
47593
47620
  );
47594
47621
  proc.on("exit", (code) => {
47595
- if (code === 0) resolve12();
47622
+ if (code === 0) resolve14();
47596
47623
  else reject(new Error(
47597
47624
  "gh auth refresh failed. Re-run `gh auth refresh -h github.com -s repo,read:org` manually."
47598
47625
  ));
@@ -47763,13 +47790,13 @@ var GitHubCodespacesProvider = class {
47763
47790
  }
47764
47791
  async streamCommand(workspaceId, command2) {
47765
47792
  resetStdinForChild();
47766
- return new Promise((resolve12, reject) => {
47793
+ return new Promise((resolve14, reject) => {
47767
47794
  const proc = (0, import_child_process30.spawn)(
47768
47795
  "gh",
47769
47796
  ["codespace", "ssh", "-c", workspaceId, "--", "-tt", command2],
47770
47797
  { stdio: "inherit" }
47771
47798
  );
47772
- proc.on("exit", (code) => resolve12({ code: code ?? 0 }));
47799
+ proc.on("exit", (code) => resolve14({ code: code ?? 0 }));
47773
47800
  proc.on("error", reject);
47774
47801
  });
47775
47802
  }
@@ -47790,7 +47817,7 @@ var GitHubCodespacesProvider = class {
47790
47817
  "--",
47791
47818
  `mkdir -p ${shellQuote(remoteDir)} && tar -xzf - -C ${shellQuote(remoteDir)}`
47792
47819
  ];
47793
- await new Promise((resolve12, reject) => {
47820
+ await new Promise((resolve14, reject) => {
47794
47821
  const tar = (0, import_child_process30.spawn)("tar", tarArgs, {
47795
47822
  stdio: ["ignore", "pipe", "pipe"],
47796
47823
  env: tarEnv
@@ -47810,7 +47837,7 @@ var GitHubCodespacesProvider = class {
47810
47837
  ssh.on("error", reject);
47811
47838
  ssh.on("exit", (code) => {
47812
47839
  if (code === 0) {
47813
- resolve12();
47840
+ resolve14();
47814
47841
  } else {
47815
47842
  const reason = (sshErr || tarErr || `exit ${code}`).trim().slice(0, 500);
47816
47843
  reject(new Error(`Remote tar failed: ${reason}`));
@@ -47828,7 +47855,7 @@ var GitHubCodespacesProvider = class {
47828
47855
  parts.push(`chmod ${options.mode.toString(8)} ${shellQuote(remotePath)}`);
47829
47856
  }
47830
47857
  const cmd = parts.join(" && ");
47831
- await new Promise((resolve12, reject) => {
47858
+ await new Promise((resolve14, reject) => {
47832
47859
  const proc = (0, import_child_process30.spawn)(
47833
47860
  "gh",
47834
47861
  ["codespace", "ssh", "-c", workspaceId, "--", cmd],
@@ -47840,7 +47867,7 @@ var GitHubCodespacesProvider = class {
47840
47867
  });
47841
47868
  proc.on("error", reject);
47842
47869
  proc.on("exit", (code) => {
47843
- if (code === 0) resolve12();
47870
+ if (code === 0) resolve14();
47844
47871
  else reject(new Error(`Remote write failed: ${(stderr || `exit ${code}`).trim().slice(0, 500)}`));
47845
47872
  });
47846
47873
  proc.stdin?.write(contents);
@@ -47930,10 +47957,10 @@ var GitpodProvider = class {
47930
47957
  "Authenticating Gitpod"
47931
47958
  );
47932
47959
  resetStdinForChild2();
47933
- await new Promise((resolve12, reject) => {
47960
+ await new Promise((resolve14, reject) => {
47934
47961
  const proc = (0, import_child_process31.spawn)("gitpod", ["login"], { stdio: "inherit" });
47935
47962
  proc.on("exit", (code) => {
47936
- if (code === 0) resolve12();
47963
+ if (code === 0) resolve14();
47937
47964
  else reject(new Error("gitpod login failed."));
47938
47965
  });
47939
47966
  proc.on("error", reject);
@@ -48082,13 +48109,13 @@ var GitpodProvider = class {
48082
48109
  }
48083
48110
  async streamCommand(workspaceId, command2) {
48084
48111
  resetStdinForChild2();
48085
- return new Promise((resolve12, reject) => {
48112
+ return new Promise((resolve14, reject) => {
48086
48113
  const proc = (0, import_child_process31.spawn)(
48087
48114
  "gitpod",
48088
48115
  ["workspace", "ssh", workspaceId, "--", "-tt", command2],
48089
48116
  { stdio: "inherit" }
48090
48117
  );
48091
- proc.on("exit", (code) => resolve12({ code: code ?? 0 }));
48118
+ proc.on("exit", (code) => resolve14({ code: code ?? 0 }));
48092
48119
  proc.on("error", reject);
48093
48120
  });
48094
48121
  }
@@ -48102,7 +48129,7 @@ var GitpodProvider = class {
48102
48129
  tarArgs.push(".");
48103
48130
  const tarEnv = { ...process.env, COPYFILE_DISABLE: "1" };
48104
48131
  const remoteCmd = `mkdir -p ${shellQuote2(remoteDir)} && tar -xzf - -C ${shellQuote2(remoteDir)}`;
48105
- await new Promise((resolve12, reject) => {
48132
+ await new Promise((resolve14, reject) => {
48106
48133
  const tar = (0, import_child_process31.spawn)("tar", tarArgs, {
48107
48134
  stdio: ["ignore", "pipe", "pipe"],
48108
48135
  env: tarEnv
@@ -48123,7 +48150,7 @@ var GitpodProvider = class {
48123
48150
  tar.on("error", reject);
48124
48151
  ssh.on("error", reject);
48125
48152
  ssh.on("exit", (code) => {
48126
- if (code === 0) resolve12();
48153
+ if (code === 0) resolve14();
48127
48154
  else reject(new Error(`Remote tar failed: ${(sshErr || tarErr || `exit ${code}`).trim().slice(0, 500)}`));
48128
48155
  });
48129
48156
  });
@@ -48138,7 +48165,7 @@ var GitpodProvider = class {
48138
48165
  parts.push(`chmod ${options.mode.toString(8)} ${shellQuote2(remotePath)}`);
48139
48166
  }
48140
48167
  const cmd = parts.join(" && ");
48141
- await new Promise((resolve12, reject) => {
48168
+ await new Promise((resolve14, reject) => {
48142
48169
  const proc = (0, import_child_process31.spawn)(
48143
48170
  "gitpod",
48144
48171
  ["workspace", "ssh", workspaceId, "--", cmd],
@@ -48150,7 +48177,7 @@ var GitpodProvider = class {
48150
48177
  });
48151
48178
  proc.on("error", reject);
48152
48179
  proc.on("exit", (code) => {
48153
- if (code === 0) resolve12();
48180
+ if (code === 0) resolve14();
48154
48181
  else reject(new Error(`Remote write failed: ${(stderr || `exit ${code}`).trim().slice(0, 500)}`));
48155
48182
  });
48156
48183
  proc.stdin?.write(contents);
@@ -48207,14 +48234,14 @@ var GitLabWorkspacesProvider = class {
48207
48234
  "Authenticating GitLab"
48208
48235
  );
48209
48236
  resetStdinForChild3();
48210
- await new Promise((resolve12, reject) => {
48237
+ await new Promise((resolve14, reject) => {
48211
48238
  const proc = (0, import_child_process32.spawn)(
48212
48239
  "glab",
48213
48240
  ["auth", "login", "--scopes", "api,read_user,read_repository"],
48214
48241
  { stdio: "inherit" }
48215
48242
  );
48216
48243
  proc.on("exit", (code) => {
48217
- if (code === 0) resolve12();
48244
+ if (code === 0) resolve14();
48218
48245
  else reject(new Error("glab auth login failed."));
48219
48246
  });
48220
48247
  proc.on("error", reject);
@@ -48379,13 +48406,13 @@ Docs: https://docs.gitlab.com/ee/user/workspace/configuration.html`
48379
48406
  async streamCommand(workspaceId, command2) {
48380
48407
  const sshHost = process.env.CODEAM_GITLAB_SSH_HOST ?? "workspaces.gitlab.com";
48381
48408
  resetStdinForChild3();
48382
- return new Promise((resolve12, reject) => {
48409
+ return new Promise((resolve14, reject) => {
48383
48410
  const proc = (0, import_child_process32.spawn)(
48384
48411
  "ssh",
48385
48412
  ["-tt", "-o", "StrictHostKeyChecking=accept-new", `${workspaceId}@${sshHost}`, command2],
48386
48413
  { stdio: "inherit" }
48387
48414
  );
48388
- proc.on("exit", (code) => resolve12({ code: code ?? 0 }));
48415
+ proc.on("exit", (code) => resolve14({ code: code ?? 0 }));
48389
48416
  proc.on("error", reject);
48390
48417
  });
48391
48418
  }
@@ -48400,7 +48427,7 @@ Docs: https://docs.gitlab.com/ee/user/workspace/configuration.html`
48400
48427
  tarArgs.push(".");
48401
48428
  const tarEnv = { ...process.env, COPYFILE_DISABLE: "1" };
48402
48429
  const remoteCmd = `mkdir -p ${shellQuote3(remoteDir)} && tar -xzf - -C ${shellQuote3(remoteDir)}`;
48403
- await new Promise((resolve12, reject) => {
48430
+ await new Promise((resolve14, reject) => {
48404
48431
  const tar = (0, import_child_process32.spawn)("tar", tarArgs, { stdio: ["ignore", "pipe", "pipe"], env: tarEnv });
48405
48432
  const ssh = (0, import_child_process32.spawn)(
48406
48433
  "ssh",
@@ -48418,7 +48445,7 @@ Docs: https://docs.gitlab.com/ee/user/workspace/configuration.html`
48418
48445
  tar.on("error", reject);
48419
48446
  ssh.on("error", reject);
48420
48447
  ssh.on("exit", (code) => {
48421
- if (code === 0) resolve12();
48448
+ if (code === 0) resolve14();
48422
48449
  else reject(new Error(`Remote tar failed: ${(sshErr || tarErr || `exit ${code}`).trim().slice(0, 500)}`));
48423
48450
  });
48424
48451
  });
@@ -48431,7 +48458,7 @@ Docs: https://docs.gitlab.com/ee/user/workspace/configuration.html`
48431
48458
  parts.push(`chmod ${options.mode.toString(8)} ${shellQuote3(remotePath)}`);
48432
48459
  }
48433
48460
  const cmd = parts.join(" && ");
48434
- await new Promise((resolve12, reject) => {
48461
+ await new Promise((resolve14, reject) => {
48435
48462
  const proc = (0, import_child_process32.spawn)(
48436
48463
  "ssh",
48437
48464
  ["-o", "StrictHostKeyChecking=accept-new", `${workspaceId}@${sshHost}`, cmd],
@@ -48443,7 +48470,7 @@ Docs: https://docs.gitlab.com/ee/user/workspace/configuration.html`
48443
48470
  });
48444
48471
  proc.on("error", reject);
48445
48472
  proc.on("exit", (code) => {
48446
- if (code === 0) resolve12();
48473
+ if (code === 0) resolve14();
48447
48474
  else reject(new Error(`Remote write failed: ${(stderr || `exit ${code}`).trim().slice(0, 500)}`));
48448
48475
  });
48449
48476
  proc.stdin?.write(contents);
@@ -48534,10 +48561,10 @@ var RailwayProvider = class {
48534
48561
  "Authenticating Railway"
48535
48562
  );
48536
48563
  resetStdinForChild4();
48537
- await new Promise((resolve12, reject) => {
48564
+ await new Promise((resolve14, reject) => {
48538
48565
  const proc = (0, import_child_process33.spawn)("railway", ["login"], { stdio: "inherit" });
48539
48566
  proc.on("exit", (code) => {
48540
- if (code === 0) resolve12();
48567
+ if (code === 0) resolve14();
48541
48568
  else reject(new Error("railway login failed."));
48542
48569
  });
48543
48570
  proc.on("error", reject);
@@ -48677,13 +48704,13 @@ var RailwayProvider = class {
48677
48704
  throw new Error("Invalid Railway workspace id (expected projectId/serviceId).");
48678
48705
  }
48679
48706
  resetStdinForChild4();
48680
- return new Promise((resolve12, reject) => {
48707
+ return new Promise((resolve14, reject) => {
48681
48708
  const proc = (0, import_child_process33.spawn)(
48682
48709
  "railway",
48683
48710
  ["shell", "--project", projectId, "--service", serviceId, "--command", command2],
48684
48711
  { stdio: "inherit" }
48685
48712
  );
48686
- proc.on("exit", (code) => resolve12({ code: code ?? 0 }));
48713
+ proc.on("exit", (code) => resolve14({ code: code ?? 0 }));
48687
48714
  proc.on("error", reject);
48688
48715
  });
48689
48716
  }
@@ -48701,7 +48728,7 @@ var RailwayProvider = class {
48701
48728
  tarArgs.push(".");
48702
48729
  const tarEnv = { ...process.env, COPYFILE_DISABLE: "1" };
48703
48730
  const remoteCmd = `mkdir -p ${shellQuote4(remoteDir)} && tar -xzf - -C ${shellQuote4(remoteDir)}`;
48704
- await new Promise((resolve12, reject) => {
48731
+ await new Promise((resolve14, reject) => {
48705
48732
  const tar = (0, import_child_process33.spawn)("tar", tarArgs, { stdio: ["ignore", "pipe", "pipe"], env: tarEnv });
48706
48733
  const sh = (0, import_child_process33.spawn)(
48707
48734
  "railway",
@@ -48719,7 +48746,7 @@ var RailwayProvider = class {
48719
48746
  tar.on("error", reject);
48720
48747
  sh.on("error", reject);
48721
48748
  sh.on("exit", (code) => {
48722
- if (code === 0) resolve12();
48749
+ if (code === 0) resolve14();
48723
48750
  else reject(new Error(`Remote tar failed: ${(shErr || tarErr || `exit ${code}`).trim().slice(0, 500)}`));
48724
48751
  });
48725
48752
  });
@@ -48735,7 +48762,7 @@ var RailwayProvider = class {
48735
48762
  parts.push(`chmod ${options.mode.toString(8)} ${shellQuote4(remotePath)}`);
48736
48763
  }
48737
48764
  const cmd = parts.join(" && ");
48738
- await new Promise((resolve12, reject) => {
48765
+ await new Promise((resolve14, reject) => {
48739
48766
  const proc = (0, import_child_process33.spawn)(
48740
48767
  "railway",
48741
48768
  ["shell", "--project", projectId, "--service", serviceId, "--command", cmd],
@@ -48747,7 +48774,7 @@ var RailwayProvider = class {
48747
48774
  });
48748
48775
  proc.on("error", reject);
48749
48776
  proc.on("exit", (code) => {
48750
- if (code === 0) resolve12();
48777
+ if (code === 0) resolve14();
48751
48778
  else reject(new Error(`Remote write failed: ${(stderr || `exit ${code}`).trim().slice(0, 500)}`));
48752
48779
  });
48753
48780
  proc.stdin?.write(contents);
@@ -49622,10 +49649,10 @@ async function host(args2) {
49622
49649
  }
49623
49650
 
49624
49651
  // src/commands/host-agent.ts
49625
- var import_node_child_process35 = require("child_process");
49626
- var os67 = __toESM(require("os"));
49627
- var fs91 = __toESM(require("fs"));
49628
- var path105 = __toESM(require("path"));
49652
+ var import_node_child_process36 = require("child_process");
49653
+ var os69 = __toESM(require("os"));
49654
+ var fs94 = __toESM(require("fs"));
49655
+ var path108 = __toESM(require("path"));
49629
49656
 
49630
49657
  // src/skills/persist-from-payload.ts
49631
49658
  function persistOrClearSkillsFromPayload(skills) {
@@ -49946,7 +49973,7 @@ var defaultGitToolingRunner = {
49946
49973
  }
49947
49974
  },
49948
49975
  run(cmd, args2, opts = {}) {
49949
- return new Promise((resolve12) => {
49976
+ return new Promise((resolve14) => {
49950
49977
  const child = (0, import_node_child_process31.spawn)(cmd, args2, {
49951
49978
  stdio: [opts.input !== void 0 ? "pipe" : "ignore", "ignore", "pipe"]
49952
49979
  });
@@ -49955,7 +49982,7 @@ var defaultGitToolingRunner = {
49955
49982
  const done = (code) => {
49956
49983
  if (settled) return;
49957
49984
  settled = true;
49958
- resolve12({ code, stderr });
49985
+ resolve14({ code, stderr });
49959
49986
  };
49960
49987
  child.stderr?.on("data", (b) => {
49961
49988
  stderr += b.toString();
@@ -49982,8 +50009,10 @@ var defaultGitToolingRunner = {
49982
50009
  }
49983
50010
  };
49984
50011
 
49985
- // src/commands/host/self-update.ts
49986
- var import_node_child_process33 = require("child_process");
50012
+ // src/lib/cli-versions.ts
50013
+ var fs91 = __toESM(require("fs"));
50014
+ var os67 = __toESM(require("os"));
50015
+ var path105 = __toESM(require("path"));
49987
50016
 
49988
50017
  // src/lib/updateNotifier.ts
49989
50018
  var fs90 = __toESM(require("fs"));
@@ -50034,14 +50063,14 @@ function compareSemver(a, b) {
50034
50063
  return 0;
50035
50064
  }
50036
50065
  function fetchLatest() {
50037
- return new Promise((resolve12) => {
50066
+ return new Promise((resolve14) => {
50038
50067
  const req = https8.get(
50039
50068
  REGISTRY_URL,
50040
50069
  { headers: { Accept: "application/json" }, timeout: REQUEST_TIMEOUT_MS },
50041
50070
  (res) => {
50042
50071
  if (res.statusCode !== 200) {
50043
50072
  res.resume();
50044
- resolve12(null);
50073
+ resolve14(null);
50045
50074
  return;
50046
50075
  }
50047
50076
  let buf = "";
@@ -50053,21 +50082,21 @@ function fetchLatest() {
50053
50082
  try {
50054
50083
  const json = JSON.parse(buf);
50055
50084
  if (typeof json.version === "string") {
50056
- resolve12(json.version);
50085
+ resolve14(json.version);
50057
50086
  } else {
50058
- resolve12(null);
50087
+ resolve14(null);
50059
50088
  }
50060
50089
  } catch {
50061
- resolve12(null);
50090
+ resolve14(null);
50062
50091
  }
50063
50092
  });
50064
50093
  }
50065
50094
  );
50066
50095
  req.on("timeout", () => {
50067
50096
  req.destroy();
50068
- resolve12(null);
50097
+ resolve14(null);
50069
50098
  });
50070
- req.on("error", () => resolve12(null));
50099
+ req.on("error", () => resolve14(null));
50071
50100
  });
50072
50101
  }
50073
50102
  function notifyIfStale(currentVersion, latest) {
@@ -50143,7 +50172,7 @@ async function autoUpgradeBeforeCriticalCommand() {
50143
50172
  if (process.env.NODE_ENV === "test") return;
50144
50173
  if (process.env.CODEAM_DISABLE_UPDATE_CHECK === "1") return;
50145
50174
  if (process.env.CI) return;
50146
- const current2 = true ? "2.76.9" : null;
50175
+ const current2 = true ? "2.76.11" : null;
50147
50176
  if (!current2) return;
50148
50177
  const cache = readCache();
50149
50178
  const fresh = cache && Date.now() - cache.fetchedAt < TTL_MS;
@@ -50160,7 +50189,7 @@ function checkForUpdates() {
50160
50189
  if (process.env.CODEAM_DISABLE_UPDATE_CHECK === "1") return;
50161
50190
  if (process.env.CI) return;
50162
50191
  if (!process.stdout.isTTY) return;
50163
- const current2 = true ? "2.76.9" : null;
50192
+ const current2 = true ? "2.76.11" : null;
50164
50193
  if (!current2) return;
50165
50194
  const cache = readCache();
50166
50195
  const fresh = cache && Date.now() - cache.fetchedAt < TTL_MS;
@@ -50174,16 +50203,264 @@ function checkForUpdates() {
50174
50203
  });
50175
50204
  }
50176
50205
 
50206
+ // src/lib/cli-versions.ts
50207
+ var CLI_PKG = "codeam-cli";
50208
+ var SEMVER_DIR = /^\d+\.\d+\.\d+(?:[-+][\w.-]+)?$/;
50209
+ var GC_KEEP_NEWEST = 3;
50210
+ var LOCK_STALE_MS = 15 * 6e4;
50211
+ function versionedModeSupported(platform3 = process.platform) {
50212
+ return platform3 !== "win32";
50213
+ }
50214
+ function cliVersionsRoot(env = process.env) {
50215
+ return env.CODEAM_CLI_VERSIONS_DIR || path105.join(os67.homedir(), ".codeam", "cli");
50216
+ }
50217
+ function packageDirOf(versionDir) {
50218
+ return path105.join(versionDir, "node_modules", CLI_PKG);
50219
+ }
50220
+ function isRecord6(v) {
50221
+ return typeof v === "object" && v !== null;
50222
+ }
50223
+ function readPkg2(versionDir) {
50224
+ try {
50225
+ const raw = JSON.parse(
50226
+ fs91.readFileSync(path105.join(packageDirOf(versionDir), "package.json"), "utf8")
50227
+ );
50228
+ return isRecord6(raw) ? raw : null;
50229
+ } catch {
50230
+ return null;
50231
+ }
50232
+ }
50233
+ function entryOf(versionDir) {
50234
+ const pkg = readPkg2(versionDir);
50235
+ if (!pkg) return null;
50236
+ const bin = pkg.bin;
50237
+ const named = isRecord6(bin) ? bin.codeam : void 0;
50238
+ const rel = typeof bin === "string" ? bin : typeof named === "string" ? named : "dist/index.js";
50239
+ const entry = path105.join(packageDirOf(versionDir), rel);
50240
+ return fs91.existsSync(entry) ? entry : null;
50241
+ }
50242
+ function launcherOf(versionDir) {
50243
+ const entry = entryOf(versionDir);
50244
+ if (!entry) return null;
50245
+ const bin = path105.join(versionDir, "node_modules", ".bin", "codeam");
50246
+ try {
50247
+ return fs91.realpathSync(bin) === fs91.realpathSync(entry) ? bin : entry;
50248
+ } catch {
50249
+ return entry;
50250
+ }
50251
+ }
50252
+ function versionOf(versionDir) {
50253
+ const v = readPkg2(versionDir)?.version;
50254
+ return typeof v === "string" ? v : null;
50255
+ }
50256
+ var BAD_MARKER_TTL_MS = 24 * 60 * 6e4;
50257
+ var PRE_READY_WINDOW_MS = 60 * 6e4;
50258
+ function isBad(versionDir, now = Date.now()) {
50259
+ try {
50260
+ return now - fs91.statSync(path105.join(versionDir, ".bad")).mtimeMs < BAD_MARKER_TTL_MS;
50261
+ } catch {
50262
+ return false;
50263
+ }
50264
+ }
50265
+ function recordPreReadyFailure(versionDir, now = Date.now()) {
50266
+ const file = path105.join(versionDir, ".prefail");
50267
+ let count = 0;
50268
+ try {
50269
+ const [n, at3] = fs91.readFileSync(file, "utf8").trim().split(" ").map(Number);
50270
+ if (Number.isFinite(n) && Number.isFinite(at3) && now - at3 < PRE_READY_WINDOW_MS) {
50271
+ count = n;
50272
+ }
50273
+ } catch {
50274
+ }
50275
+ count += 1;
50276
+ try {
50277
+ fs91.writeFileSync(file, `${count} ${now}`);
50278
+ } catch {
50279
+ }
50280
+ return count;
50281
+ }
50282
+ function clearPreReadyFailures(versionDir) {
50283
+ fs91.rmSync(path105.join(versionDir, ".prefail"), { force: true });
50284
+ }
50285
+ function markBad(versionDir, reason) {
50286
+ try {
50287
+ fs91.writeFileSync(path105.join(versionDir, ".bad"), `${(/* @__PURE__ */ new Date()).toISOString()} ${reason}
50288
+ `);
50289
+ } catch {
50290
+ }
50291
+ }
50292
+ function pointerTarget(root, name) {
50293
+ try {
50294
+ return fs91.realpathSync(path105.join(root, name));
50295
+ } catch {
50296
+ return null;
50297
+ }
50298
+ }
50299
+ function atomicPoint(root, name, targetDir) {
50300
+ const tmp = path105.join(root, `.${name}.tmp-${process.pid}-${Date.now()}`);
50301
+ fs91.symlinkSync(path105.relative(root, targetDir), tmp, "dir");
50302
+ try {
50303
+ fs91.renameSync(tmp, path105.join(root, name));
50304
+ } catch (err) {
50305
+ fs91.rmSync(tmp, { force: true });
50306
+ throw err;
50307
+ }
50308
+ }
50309
+ function switchCurrent(root, versionDir) {
50310
+ const old = pointerTarget(root, "current");
50311
+ if (old && path105.resolve(old) !== path105.resolve(versionDir)) atomicPoint(root, "previous", old);
50312
+ atomicPoint(root, "current", versionDir);
50313
+ }
50314
+ function validCurrent(root) {
50315
+ const dir = pointerTarget(root, "current");
50316
+ if (!dir || isBad(dir)) return null;
50317
+ const version3 = versionOf(dir);
50318
+ const entry = launcherOf(dir);
50319
+ return version3 && entry ? { dir, version: version3, entry } : null;
50320
+ }
50321
+ function rollbackCurrent(root) {
50322
+ const prev = pointerTarget(root, "previous");
50323
+ if (!prev || isBad(prev) || !entryOf(prev)) return null;
50324
+ const cur = pointerTarget(root, "current");
50325
+ if (cur && path105.resolve(cur) !== path105.resolve(prev)) atomicPoint(root, "previous", cur);
50326
+ atomicPoint(root, "current", prev);
50327
+ return versionOf(prev);
50328
+ }
50329
+ function hostEntry(root, ownVersion, fallback, platform3 = process.platform) {
50330
+ if (!versionedModeSupported(platform3) || !ownVersion) return fallback;
50331
+ const cur = validCurrent(root);
50332
+ return cur && compareSemver(cur.version, ownVersion) >= 0 ? cur.entry : fallback;
50333
+ }
50334
+ function versionDirContaining(root, file) {
50335
+ if (!file) return null;
50336
+ let real;
50337
+ let realRoot;
50338
+ try {
50339
+ real = fs91.realpathSync(file);
50340
+ realRoot = fs91.realpathSync(root);
50341
+ } catch {
50342
+ return null;
50343
+ }
50344
+ const rel = path105.relative(realRoot, real);
50345
+ if (rel.startsWith("..") || path105.isAbsolute(rel)) return null;
50346
+ const first = rel.split(path105.sep)[0];
50347
+ return first && SEMVER_DIR.test(first) ? path105.join(realRoot, first) : null;
50348
+ }
50349
+ function pidAlive3(pid) {
50350
+ try {
50351
+ process.kill(pid, 0);
50352
+ return true;
50353
+ } catch (err) {
50354
+ return err.code === "EPERM";
50355
+ }
50356
+ }
50357
+ function livePids(versionDir) {
50358
+ let names;
50359
+ try {
50360
+ names = fs91.readdirSync(path105.join(versionDir, ".pids"));
50361
+ } catch {
50362
+ return [];
50363
+ }
50364
+ return names.map(Number).filter((pid) => Number.isInteger(pid) && pid > 0 && pidAlive3(pid));
50365
+ }
50366
+ function registerRunningVersion(root = cliVersionsRoot(), entry = process.argv[1]) {
50367
+ const dir = versionDirContaining(root, entry);
50368
+ if (!dir) return;
50369
+ const file = path105.join(dir, ".pids", String(process.pid));
50370
+ try {
50371
+ fs91.mkdirSync(path105.dirname(file), { recursive: true });
50372
+ fs91.writeFileSync(file, "");
50373
+ process.once("exit", () => fs91.rmSync(file, { force: true }));
50374
+ } catch {
50375
+ }
50376
+ }
50377
+ function gcVersions(root) {
50378
+ const removed = [];
50379
+ let names;
50380
+ try {
50381
+ names = fs91.readdirSync(root).filter((n) => SEMVER_DIR.test(n));
50382
+ } catch {
50383
+ return removed;
50384
+ }
50385
+ const keep = new Set(
50386
+ [...names].sort((a, b) => compareSemver(b, a)).slice(0, GC_KEEP_NEWEST)
50387
+ );
50388
+ for (const p2 of [pointerTarget(root, "current"), pointerTarget(root, "previous")]) {
50389
+ if (p2) keep.add(path105.basename(p2));
50390
+ }
50391
+ for (const name of names) {
50392
+ const dir = path105.join(root, name);
50393
+ if (keep.has(name) || livePids(dir).length > 0) continue;
50394
+ try {
50395
+ fs91.rmSync(dir, { recursive: true, force: true });
50396
+ removed.push(name);
50397
+ } catch {
50398
+ }
50399
+ }
50400
+ return removed;
50401
+ }
50402
+ function acquireInstallLock(root) {
50403
+ const lock = path105.join(root, ".install.lock");
50404
+ for (let attempt = 0; attempt < 2; attempt++) {
50405
+ try {
50406
+ const fd = fs91.openSync(lock, "wx");
50407
+ fs91.writeSync(fd, String(process.pid));
50408
+ fs91.closeSync(fd);
50409
+ return () => fs91.rmSync(lock, { force: true });
50410
+ } catch (err) {
50411
+ if (err.code !== "EEXIST") return null;
50412
+ let stale = false;
50413
+ try {
50414
+ const owner = Number(fs91.readFileSync(lock, "utf8"));
50415
+ const age = Date.now() - fs91.statSync(lock).mtimeMs;
50416
+ stale = !Number.isInteger(owner) || !pidAlive3(owner) || age > LOCK_STALE_MS;
50417
+ } catch {
50418
+ stale = true;
50419
+ }
50420
+ if (!stale) return null;
50421
+ fs91.rmSync(lock, { force: true });
50422
+ }
50423
+ }
50424
+ return null;
50425
+ }
50426
+
50427
+ // src/commands/host/host-launch.ts
50428
+ var import_node_child_process34 = require("child_process");
50429
+ var fs93 = __toESM(require("fs"));
50430
+ var os68 = __toESM(require("os"));
50431
+ var path107 = __toESM(require("path"));
50432
+
50433
+ // src/exit-codes.ts
50434
+ var EXIT_OK = 0;
50435
+ var EXIT_FAILURE = 1;
50436
+ var EXIT_USAGE = 2;
50437
+ var EXIT_NEEDS_PAIRING = 3;
50438
+ var EXIT_HOST_NOT_ENROLLED = 78;
50439
+ var EXIT_SIGINT = 130;
50440
+ var EXIT_SIGTERM = 143;
50441
+ var EXIT_CODE_NAMES = {
50442
+ [EXIT_OK]: "ok",
50443
+ [EXIT_FAILURE]: "failure",
50444
+ [EXIT_USAGE]: "usage_error",
50445
+ [EXIT_NEEDS_PAIRING]: "needs_pairing",
50446
+ [EXIT_HOST_NOT_ENROLLED]: "host_not_enrolled",
50447
+ [EXIT_SIGINT]: "sigint",
50448
+ [EXIT_SIGTERM]: "sigterm"
50449
+ };
50450
+
50177
50451
  // src/commands/host/self-update.ts
50452
+ var import_node_child_process33 = require("child_process");
50453
+ var fs92 = __toESM(require("fs"));
50454
+ var path106 = __toESM(require("path"));
50178
50455
  var SELF_UPDATE_PKG = "codeam-cli";
50179
50456
  var SELF_UPDATE_INTERVAL_MS = 60 * 60 * 1e3;
50457
+ var SELF_UPDATE_STARTUP_DELAY_MS = 5e3;
50180
50458
  var SELF_UPDATE_DEFER_MAX_MS = 24 * 60 * 60 * 1e3;
50181
50459
  var SELF_UPDATE_VIEW_TIMEOUT_MS = 3e4;
50182
50460
  var SELF_UPDATE_INSTALL_TIMEOUT_MS = 18e4;
50183
50461
  var SELF_UPDATE_LS_TIMEOUT_MS = 15e3;
50184
- var SUDO_PREFLIGHT_TIMEOUT_MS = 5e3;
50185
50462
  function currentCliVersion() {
50186
- return true ? "2.76.9" : null;
50463
+ return true ? "2.76.11" : null;
50187
50464
  }
50188
50465
  async function installedVersion(deps) {
50189
50466
  const ls = await deps.run(
@@ -50199,10 +50476,10 @@ async function installedVersion(deps) {
50199
50476
  }
50200
50477
  }
50201
50478
  function runCmd(cmd, args2, timeoutMs) {
50202
- return new Promise((resolve12) => {
50479
+ return new Promise((resolve14) => {
50203
50480
  (0, import_node_child_process33.execFile)(cmd, args2, { timeout: timeoutMs }, (err, stdout, stderr) => {
50204
50481
  const code = err && typeof err.code === "number" ? err.code : err ? null : 0;
50205
- resolve12({ code, stdout: stdout ?? "", stderr: stderr ?? "" });
50482
+ resolve14({ code, stdout: stdout ?? "", stderr: stderr ?? "" });
50206
50483
  });
50207
50484
  });
50208
50485
  }
@@ -50210,7 +50487,11 @@ async function runSelfUpdate() {
50210
50487
  return runSelfUpdateWith({
50211
50488
  run: runCmd,
50212
50489
  currentVersion: currentCliVersion,
50213
- isRoot: () => process.getuid?.() === 0
50490
+ isRoot: () => process.getuid?.() === 0,
50491
+ versionsRoot: cliVersionsRoot(),
50492
+ runningEntry: process.argv[1],
50493
+ nodePath: process.execPath,
50494
+ platform: process.platform
50214
50495
  });
50215
50496
  }
50216
50497
  async function runSelfUpdateWith(deps) {
@@ -50220,6 +50501,15 @@ async function runSelfUpdateWith(deps) {
50220
50501
  log.trace("host-agent", "self-update: no __CLI_VERSION__ \u2014 skipping");
50221
50502
  return { status: "skipped" };
50222
50503
  }
50504
+ const root = deps.versionsRoot ?? cliVersionsRoot();
50505
+ const versioned = versionedModeSupported(deps.platform) ? validCurrent(root) : null;
50506
+ if (versioned && compareSemver(versioned.version, current2) > 0) {
50507
+ log.info(
50508
+ "host-agent",
50509
+ `self-update: ${versioned.version} already current in ${root} (running ${current2}) \u2014 restarting onto it`
50510
+ );
50511
+ return { status: "updated", version: versioned.version };
50512
+ }
50223
50513
  const onDisk = await installedVersion(deps);
50224
50514
  if (onDisk && compareSemver(onDisk, current2) > 0) {
50225
50515
  log.info(
@@ -50245,49 +50535,299 @@ async function runSelfUpdateWith(deps) {
50245
50535
  if (compareSemver(latest, current2) <= 0) {
50246
50536
  return { status: "current" };
50247
50537
  }
50248
- log.info("host-agent", `self-update: ${current2} \u2192 ${latest} available \u2014 installing`);
50249
- const installArgs = ["install", "-g", `${SELF_UPDATE_PKG}@latest`];
50250
- let install = await deps.run("npm", installArgs, SELF_UPDATE_INSTALL_TIMEOUT_MS);
50251
- if (install.code !== 0 && !deps.isRoot() && /EACCES/i.test(install.stderr)) {
50252
- const canSudo = await deps.run("sudo", ["-n", "true"], SUDO_PREFLIGHT_TIMEOUT_MS);
50253
- if (canSudo.code === 0) {
50254
- log.info("host-agent", "self-update: install hit EACCES \u2014 retrying with sudo");
50255
- install = await deps.run("sudo", ["npm", ...installArgs], SELF_UPDATE_INSTALL_TIMEOUT_MS);
50256
- } else {
50538
+ if (!versionedModeSupported(deps.platform)) {
50539
+ log.info("host-agent", `self-update: ${current2} \u2192 ${latest} available \u2014 installing (global)`);
50540
+ return await installGlobalLegacy(deps, latest, current2);
50541
+ }
50542
+ log.info("host-agent", `self-update: ${current2} \u2192 ${latest} available \u2014 installing side-by-side`);
50543
+ return await installVersioned(deps, root, latest, current2);
50544
+ } catch (err) {
50545
+ log.warn(
50546
+ "host-agent",
50547
+ `self-update: unexpected error: ${err instanceof Error ? err.message : String(err)}`
50548
+ );
50549
+ return { status: "skipped" };
50550
+ }
50551
+ }
50552
+ var VERIFY_TIMEOUT_MS = 3e4;
50553
+ async function installVersioned(deps, root, latest, running2) {
50554
+ const node = deps.nodePath ?? process.execPath;
50555
+ const target = path106.join(root, latest);
50556
+ try {
50557
+ fs92.mkdirSync(root, { recursive: true });
50558
+ } catch {
50559
+ return { status: "skipped" };
50560
+ }
50561
+ if (isBad(target)) {
50562
+ log.warn("host-agent", `self-update: ${latest} is marked bad (crashed before ready) \u2014 not reinstalling`);
50563
+ return { status: "skipped" };
50564
+ }
50565
+ const release3 = acquireInstallLock(root);
50566
+ if (!release3) {
50567
+ log.info("host-agent", "self-update: another install holds the lock \u2014 skipping this tick");
50568
+ return { status: "skipped" };
50569
+ }
50570
+ try {
50571
+ const runningDir = versionDirContaining(root, deps.runningEntry);
50572
+ const reusable = entryOf(target) && versionOf(target) === latest;
50573
+ if (!reusable) {
50574
+ if (runningDir && path106.resolve(runningDir) === path106.resolve(target)) {
50575
+ return { status: "skipped" };
50576
+ }
50577
+ fs92.rmSync(target, { recursive: true, force: true });
50578
+ const install = await deps.run(
50579
+ "npm",
50580
+ [
50581
+ "install",
50582
+ "--prefix",
50583
+ target,
50584
+ "--no-audit",
50585
+ "--no-fund",
50586
+ "--loglevel=error",
50587
+ `${SELF_UPDATE_PKG}@${latest}`
50588
+ ],
50589
+ SELF_UPDATE_INSTALL_TIMEOUT_MS
50590
+ );
50591
+ if (install.code !== 0) {
50592
+ fs92.rmSync(target, { recursive: true, force: true });
50257
50593
  log.warn(
50258
50594
  "host-agent",
50259
- "self-update: the npm global prefix is not writable by this user and passwordless sudo is unavailable \u2014 install codeam-cli under a user-writable prefix, or let a privileged agent on this host install it (this box restarts onto it automatically)"
50595
+ `self-update: versioned install exited ${String(install.code)} \u2014 staying on ${running2}: ` + install.stderr.slice(-300)
50260
50596
  );
50597
+ return { status: "skipped" };
50261
50598
  }
50262
50599
  }
50263
- if (install.code !== 0) {
50600
+ const entry = entryOf(target);
50601
+ const check = entry ? await deps.run(node, [entry, "--version"], VERIFY_TIMEOUT_MS) : { code: null, stdout: "", stderr: "no entry point" };
50602
+ if (check.code !== 0 || !check.stdout.includes(latest)) {
50603
+ fs92.rmSync(target, { recursive: true, force: true });
50264
50604
  log.warn(
50265
50605
  "host-agent",
50266
- `self-update: install exited ${String(install.code)} \u2014 staying on ${current2}`
50606
+ `self-update: ${latest} failed verification (exit ${String(check.code)}: ${(check.stdout + check.stderr).trim().slice(-200)}) \u2014 staying on ${running2}`
50267
50607
  );
50268
50608
  return { status: "skipped" };
50269
50609
  }
50270
- const after = await deps.run(
50271
- "npm",
50272
- ["view", SELF_UPDATE_PKG, "version"],
50273
- SELF_UPDATE_VIEW_TIMEOUT_MS
50610
+ switchCurrent(root, target);
50611
+ const removed = gcVersions(root);
50612
+ log.info(
50613
+ "host-agent",
50614
+ `self-update: ${latest} installed + verified at ${target}, now current` + (removed.length ? ` (gc: ${removed.join(", ")})` : "")
50274
50615
  );
50275
- const installed2 = after.code === 0 ? after.stdout.trim() || latest : latest;
50276
- return { status: "updated", version: installed2 };
50616
+ return { status: "updated", version: latest };
50277
50617
  } catch (err) {
50618
+ const cur = pointerTarget(root, "current");
50619
+ if (!cur || path106.basename(cur) !== latest) fs92.rmSync(target, { recursive: true, force: true });
50278
50620
  log.warn(
50279
50621
  "host-agent",
50280
- `self-update: unexpected error: ${err instanceof Error ? err.message : String(err)}`
50622
+ `self-update: versioned install failed: ${err instanceof Error ? err.message : String(err)}`
50281
50623
  );
50282
50624
  return { status: "skipped" };
50625
+ } finally {
50626
+ release3();
50627
+ }
50628
+ }
50629
+ async function installGlobalLegacy(deps, latest, running2) {
50630
+ const install = await deps.run(
50631
+ "npm",
50632
+ ["install", "-g", `${SELF_UPDATE_PKG}@latest`],
50633
+ SELF_UPDATE_INSTALL_TIMEOUT_MS
50634
+ );
50635
+ if (install.code !== 0) {
50636
+ log.warn("host-agent", `self-update: install exited ${String(install.code)} \u2014 staying on ${running2}`);
50637
+ return { status: "skipped" };
50283
50638
  }
50639
+ return { status: "updated", version: latest };
50640
+ }
50641
+
50642
+ // src/commands/host/host-launch.ts
50643
+ var SUPERVISED_FLAG = "--supervised";
50644
+ var READY_MESSAGE = "codeam-host-ready";
50645
+ var MAX_FAST_RESPAWNS = 5;
50646
+ var FAST_EXIT_MS = 3e4;
50647
+ var readySent = false;
50648
+ function signalHostReady(send = process.send?.bind(process)) {
50649
+ if (readySent || !send) return;
50650
+ readySent = true;
50651
+ try {
50652
+ send(READY_MESSAGE);
50653
+ } catch {
50654
+ }
50655
+ }
50656
+ function defaultDeps() {
50657
+ return {
50658
+ ownVersion: true ? "2.76.11" : null,
50659
+ root: cliVersionsRoot(),
50660
+ args: process.argv.slice(3),
50661
+ execPath: process.execPath,
50662
+ platform: process.platform,
50663
+ now: () => Date.now(),
50664
+ spawn: (cmd, args2) => (0, import_node_child_process34.spawn)(cmd, args2, { stdio: ["inherit", "inherit", "inherit", "ipc"] }),
50665
+ exit: (code) => process.exit(code),
50666
+ reraise: (signal) => {
50667
+ process.removeAllListeners(signal);
50668
+ process.kill(process.pid, signal);
50669
+ },
50670
+ warn: (msg) => process.stderr.write(`${msg}
50671
+ `),
50672
+ stdinIsTty: Boolean(process.stdin.isTTY)
50673
+ };
50674
+ }
50675
+ async function superviseCurrent(over = {}) {
50676
+ const deps = { ...defaultDeps(), ...over };
50677
+ if (!versionedModeSupported(deps.platform) || deps.args.includes(SUPERVISED_FLAG)) return "self";
50678
+ let fastRespawns = 0;
50679
+ for (; ; ) {
50680
+ const cur = validCurrent(deps.root);
50681
+ if (!cur || !deps.ownVersion || compareSemver(cur.version, deps.ownVersion) <= 0) return "self";
50682
+ const startedAt = deps.now();
50683
+ let ready = false;
50684
+ let stopping = false;
50685
+ const child = deps.spawn(deps.execPath, [cur.entry, "host-agent", SUPERVISED_FLAG, ...deps.args]);
50686
+ child.on("message", (m) => {
50687
+ if (m === READY_MESSAGE) {
50688
+ ready = true;
50689
+ clearPreReadyFailures(cur.dir);
50690
+ }
50691
+ });
50692
+ const signals = deps.stdinIsTty ? ["SIGTERM", "SIGHUP"] : ["SIGTERM", "SIGHUP", "SIGINT"];
50693
+ const forward = (sig) => () => {
50694
+ stopping = true;
50695
+ try {
50696
+ child.kill(sig);
50697
+ } catch {
50698
+ }
50699
+ };
50700
+ const handlers2 = signals.map((sig) => [sig, forward(sig)]);
50701
+ for (const [sig, h] of handlers2) process.on(sig, h);
50702
+ const ignoreSigint = () => {
50703
+ stopping = true;
50704
+ };
50705
+ if (deps.stdinIsTty) process.on("SIGINT", ignoreSigint);
50706
+ const { code, signal } = await new Promise(
50707
+ (resolve14) => {
50708
+ child.once("exit", (c2, s) => resolve14({ code: c2, signal: s }));
50709
+ child.once("error", () => resolve14({ code: 1, signal: null }));
50710
+ }
50711
+ );
50712
+ for (const [sig, h] of handlers2) process.off(sig, h);
50713
+ if (deps.stdinIsTty) process.off("SIGINT", ignoreSigint);
50714
+ if (signal) {
50715
+ deps.reraise(signal);
50716
+ return "supervised";
50717
+ }
50718
+ if (stopping || code === EXIT_HOST_NOT_ENROLLED) {
50719
+ deps.exit(code ?? 1);
50720
+ return "supervised";
50721
+ }
50722
+ if (code === 0) {
50723
+ fastRespawns = deps.now() - startedAt < FAST_EXIT_MS ? fastRespawns + 1 : 0;
50724
+ if (fastRespawns > MAX_FAST_RESPAWNS) {
50725
+ deps.warn("codeam: host-agent keeps restarting \u2014 running the launcher\u2019s own version");
50726
+ return "self";
50727
+ }
50728
+ continue;
50729
+ }
50730
+ if (!ready) {
50731
+ const strikes = recordPreReadyFailure(cur.dir);
50732
+ if (strikes < 2) {
50733
+ deps.warn(`codeam: ${cur.version} exited ${String(code)} before ready \u2014 retrying once`);
50734
+ continue;
50735
+ }
50736
+ markBad(cur.dir, `host-agent exited ${String(code)} before ready (${strikes}x)`);
50737
+ const now = rollbackCurrent(deps.root);
50738
+ deps.warn(
50739
+ `codeam: ${cur.version} exited ${String(code)} before ready twice \u2014 marked bad` + (now ? `, rolled back to ${now}` : "")
50740
+ );
50741
+ continue;
50742
+ }
50743
+ deps.exit(code ?? 1);
50744
+ return "supervised";
50745
+ }
50746
+ }
50747
+ function needsSelfRelaunch(env = process.env, pid = process.pid, ctx = {}) {
50748
+ if (env.INVOCATION_ID || pid === 1) return false;
50749
+ const ppid = ctx.ppid ?? process.ppid;
50750
+ if (ppid === 1 && isOurTiniEntrypoint((ctx.pid1Cmdline ?? readPid1Cmdline)())) return false;
50751
+ return true;
50752
+ }
50753
+ function readPid1Cmdline() {
50754
+ try {
50755
+ return fs93.readFileSync("/proc/1/cmdline", "utf8").split("\0").filter(Boolean);
50756
+ } catch {
50757
+ return [];
50758
+ }
50759
+ }
50760
+ function isOurTiniEntrypoint(argv) {
50761
+ return argv.some((a) => path107.basename(a) === "tini") && argv.includes("host-agent");
50762
+ }
50763
+ function relaunchArgv(execPath, argv) {
50764
+ return ["-c", 'sleep 2; exec "$0" "$@"', execPath, ...argv.slice(1)];
50765
+ }
50766
+ function defaultRestartForUpdate(version3, supervised, io = {}) {
50767
+ const exit = io.exit ?? ((code) => process.exit(code));
50768
+ const relaunch = !supervised && (io.needsRelaunch ?? needsSelfRelaunch());
50769
+ log.info(
50770
+ "host-agent",
50771
+ `self-update: installed ${version3}, restarting${supervised ? " (supervised)" : relaunch ? " (self-relaunch, no supervisor)" : ""}`
50772
+ );
50773
+ if (relaunch) {
50774
+ const entry = io.entry ?? hostEntry(
50775
+ io.root ?? cliVersionsRoot(),
50776
+ io.ownVersion === void 0 ? currentCliVersion() : io.ownVersion,
50777
+ io.argv1 ?? process.argv[1] ?? ""
50778
+ );
50779
+ const argv = [process.argv[0] ?? process.execPath, entry, ...process.argv.slice(2)];
50780
+ try {
50781
+ (io.relaunch ?? ((a) => (0, import_node_child_process34.spawn)("/bin/sh", relaunchArgv(process.execPath, a), {
50782
+ cwd: process.cwd(),
50783
+ env: process.env,
50784
+ detached: true,
50785
+ stdio: "ignore"
50786
+ }).unref()))(argv);
50787
+ } catch (err) {
50788
+ log.error("host-agent", "self-update: relaunch failed \u2014 staying on the old binary", err);
50789
+ return;
50790
+ }
50791
+ }
50792
+ exit(0);
50793
+ }
50794
+ function isContainerEnvironment(existsSyncFn = fs93.existsSync, readFileSyncFn = (p2) => fs93.readFileSync(p2, "utf8")) {
50795
+ try {
50796
+ if (existsSyncFn("/.dockerenv")) return true;
50797
+ } catch {
50798
+ }
50799
+ try {
50800
+ const cgroup = readFileSyncFn("/proc/1/cgroup");
50801
+ if (/docker|containerd|kubepods/.test(cgroup)) return true;
50802
+ } catch {
50803
+ }
50804
+ return false;
50805
+ }
50806
+ function hostAgentPidFile(home = os68.homedir()) {
50807
+ return path107.join(home, ".codeam", "host-agent.pid");
50808
+ }
50809
+ function writeHostAgentPidFile(file = hostAgentPidFile(), pid = process.pid) {
50810
+ try {
50811
+ fs93.mkdirSync(path107.dirname(file), { recursive: true });
50812
+ fs93.writeFileSync(file, String(pid));
50813
+ process.once("exit", () => {
50814
+ try {
50815
+ if (fs93.readFileSync(file, "utf8").trim() === String(pid)) fs93.rmSync(file, { force: true });
50816
+ } catch {
50817
+ }
50818
+ });
50819
+ } catch {
50820
+ }
50821
+ }
50822
+ function bindSupervisedLifecycle(proc, onOrphaned) {
50823
+ proc.once("disconnect", onOrphaned);
50284
50824
  }
50285
50825
 
50286
50826
  // src/commands/host/teardown.ts
50287
- var import_node_child_process34 = require("child_process");
50827
+ var import_node_child_process35 = require("child_process");
50288
50828
  var defaultDisableService = () => {
50289
50829
  try {
50290
- (0, import_node_child_process34.execFileSync)("systemctl", ["disable", "--now", "codeam-host-agent"], { stdio: "ignore" });
50830
+ (0, import_node_child_process35.execFileSync)("systemctl", ["disable", "--now", "codeam-host-agent"], { stdio: "ignore" });
50291
50831
  } catch {
50292
50832
  }
50293
50833
  };
@@ -50458,8 +50998,8 @@ var DOCKER_RUN_TIMEOUT_MS = 12e4;
50458
50998
  var DOCKER_RUN_WITH_PULL_TIMEOUT_MS = 6e5;
50459
50999
  var defaultDockerRunner = {
50460
51000
  run(args2, opts = {}) {
50461
- return new Promise((resolve12) => {
50462
- const child = (0, import_node_child_process35.spawn)("docker", args2, {
51001
+ return new Promise((resolve14) => {
51002
+ const child = (0, import_node_child_process36.spawn)("docker", args2, {
50463
51003
  stdio: ["ignore", "pipe", "pipe"],
50464
51004
  env: { ...process.env, ...opts.env }
50465
51005
  });
@@ -50477,7 +51017,7 @@ var defaultDockerRunner = {
50477
51017
  if (settled) return;
50478
51018
  settled = true;
50479
51019
  clearTimeout(timer);
50480
- resolve12({ code, stderr: stderrBuf, stdout: stdoutBuf });
51020
+ resolve14({ code, stderr: stderrBuf, stdout: stdoutBuf });
50481
51021
  };
50482
51022
  child.stdout?.on("data", (b) => {
50483
51023
  stdoutBuf += b.toString();
@@ -50504,13 +51044,16 @@ var CONTROL_AGENT_META = {
50504
51044
  // Synthetic control channel — capability flags are moot (no agent runs).
50505
51045
  acp: false
50506
51046
  };
50507
- var defaultSpawner = (env, cwd, args2 = []) => (0, import_node_child_process35.spawn)(process.execPath, [process.argv[1], "pair-auto", ...args2], {
51047
+ function sessionEntry() {
51048
+ return hostEntry(cliVersionsRoot(), currentCliVersion(), process.argv[1]);
51049
+ }
51050
+ var defaultSpawner = (env, cwd, args2 = []) => (0, import_node_child_process36.spawn)(process.execPath, [sessionEntry(), "pair-auto", ...args2], {
50508
51051
  cwd,
50509
51052
  env: { ...process.env, ...env },
50510
51053
  stdio: ["ignore", "pipe", "pipe"],
50511
51054
  detached: false
50512
51055
  });
50513
- var defaultResumeSpawner = (env, cwd) => (0, import_node_child_process35.spawn)(process.execPath, [process.argv[1]], {
51056
+ var defaultResumeSpawner = (env, cwd) => (0, import_node_child_process36.spawn)(process.execPath, [sessionEntry()], {
50514
51057
  cwd,
50515
51058
  // CODEAM_AUTO_APPROVE=1 → ACP path (baton off). CODEAM_RESUME_LATEST=1 →
50516
51059
  // continue the user's most-recent conversation instead of opening an empty
@@ -50529,48 +51072,12 @@ var defaultOnIdentityRejected = () => {
50529
51072
  "host-agent",
50530
51073
  "host identity rejected by backend \u2014 disabled service + wiped sealed identity, exiting"
50531
51074
  );
50532
- process.exit(1);
51075
+ process.exit(EXIT_HOST_NOT_ENROLLED);
50533
51076
  };
50534
51077
  var ORPHAN_TERM_GRACE_MS = 3e3;
50535
51078
  var ORPHAN_KILL_SETTLE_MS = 500;
50536
- function needsSelfRelaunch(env = process.env, pid = process.pid) {
50537
- return !env.INVOCATION_ID && pid !== 1;
50538
- }
50539
- function isContainerEnvironment(existsSyncFn = fs91.existsSync, readFileSyncFn = (p2) => fs91.readFileSync(p2, "utf8")) {
50540
- try {
50541
- if (existsSyncFn("/.dockerenv")) return true;
50542
- } catch {
50543
- }
50544
- try {
50545
- const cgroup = readFileSyncFn("/proc/1/cgroup");
50546
- if (/docker|containerd|kubepods/.test(cgroup)) return true;
50547
- } catch {
50548
- }
50549
- return false;
50550
- }
50551
- function relaunchArgv(execPath, argv) {
50552
- return ["-c", 'sleep 2; exec "$0" "$@"', execPath, ...argv.slice(1)];
50553
- }
50554
51079
  var defaultOnUpdated = (version3) => {
50555
- const relaunch = needsSelfRelaunch();
50556
- log.info(
50557
- "host-agent",
50558
- `self-update: installed ${version3}, restarting${relaunch ? " (self-relaunch, no supervisor)" : ""}`
50559
- );
50560
- if (relaunch) {
50561
- try {
50562
- (0, import_node_child_process35.spawn)("/bin/sh", relaunchArgv(process.execPath, process.argv), {
50563
- cwd: process.cwd(),
50564
- env: process.env,
50565
- detached: true,
50566
- stdio: "ignore"
50567
- }).unref();
50568
- } catch (err) {
50569
- log.error("host-agent", "self-update: relaunch failed \u2014 staying on the old binary", err);
50570
- return;
50571
- }
50572
- }
50573
- process.exit(0);
51080
+ defaultRestartForUpdate(version3, process.argv.slice(3).includes(SUPERVISED_FLAG));
50574
51081
  };
50575
51082
  var HostAgentSupervisor = class {
50576
51083
  constructor(identity, deps = {}) {
@@ -50606,6 +51113,7 @@ var HostAgentSupervisor = class {
50606
51113
  heartbeatTimer = null;
50607
51114
  /** Periodic self-update timer (npm check + install + restart). */
50608
51115
  selfUpdateTimer = null;
51116
+ selfUpdateStartupTimer = null;
50609
51117
  /** Self-update check + install (injectable; defaults to runSelfUpdate). */
50610
51118
  selfUpdate;
50611
51119
  now;
@@ -50699,11 +51207,17 @@ var HostAgentSupervisor = class {
50699
51207
  this.reportLiveSet("boot");
50700
51208
  const updateMs = this.selfUpdateIntervalMs();
50701
51209
  if (updateMs > 0) {
51210
+ this.selfUpdateStartupTimer = setTimeout(
51211
+ () => void this.selfUpdateTick(),
51212
+ SELF_UPDATE_STARTUP_DELAY_MS
51213
+ );
51214
+ this.selfUpdateStartupTimer.unref?.();
50702
51215
  this.selfUpdateTimer = setInterval(() => void this.selfUpdateTick(), updateMs);
50703
51216
  this.selfUpdateTimer.unref?.();
50704
51217
  } else {
50705
51218
  log.info("host-agent", "self-update disabled (CODEAM_HOST_SELF_UPDATE_MS<=0)");
50706
51219
  }
51220
+ (this.deps.writePidFile ?? writeHostAgentPidFile)();
50707
51221
  log.info("host-agent", `supervisor up host=${this.identity.hostId.slice(0, 8)}`);
50708
51222
  }
50709
51223
  /** Stop the control channel + heartbeats + kill every child. */
@@ -50725,6 +51239,10 @@ var HostAgentSupervisor = class {
50725
51239
  clearInterval(this.selfUpdateTimer);
50726
51240
  this.selfUpdateTimer = null;
50727
51241
  }
51242
+ if (this.selfUpdateStartupTimer) {
51243
+ clearTimeout(this.selfUpdateStartupTimer);
51244
+ this.selfUpdateStartupTimer = null;
51245
+ }
50728
51246
  this.relay?.stop();
50729
51247
  for (const child of this.children.values()) {
50730
51248
  killQuiet(child.proc);
@@ -50770,6 +51288,7 @@ var HostAgentSupervisor = class {
50770
51288
  }
50771
51289
  const latencyMs = await sendHostHeartbeat(this.identity, metrics);
50772
51290
  this.metrics.recordLatency(latencyMs);
51291
+ signalHostReady();
50773
51292
  if (!this.reportedConnected) {
50774
51293
  this.reportedConnected = true;
50775
51294
  void reportProgress(
@@ -51001,13 +51520,13 @@ var HostAgentSupervisor = class {
51001
51520
  const relay = this.relay;
51002
51521
  if (!relay) return;
51003
51522
  const raw = cmd.payload?.path;
51004
- const target = typeof raw === "string" && raw.trim() ? path105.resolve(raw.trim()) : os67.homedir();
51523
+ const target = typeof raw === "string" && raw.trim() ? path108.resolve(raw.trim()) : os69.homedir();
51005
51524
  try {
51006
- const dirents = await fs91.promises.readdir(target, { withFileTypes: true });
51525
+ const dirents = await fs94.promises.readdir(target, { withFileTypes: true });
51007
51526
  const entries2 = dirents.filter((d3) => !d3.name.startsWith(".")).map((d3) => ({ name: d3.name, isDir: d3.isDirectory() })).sort(
51008
51527
  (a, b) => a.isDir === b.isDir ? a.name.localeCompare(b.name) : a.isDir ? -1 : 1
51009
51528
  );
51010
- const parent = path105.dirname(target);
51529
+ const parent = path108.dirname(target);
51011
51530
  await relay.sendResult(cmd.id, "completed", {
51012
51531
  path: target,
51013
51532
  // null at the filesystem root so the UI can hide the ".." affordance.
@@ -51351,18 +51870,24 @@ var HostAgentSupervisor = class {
51351
51870
  let extraArgs = [];
51352
51871
  if (payload.houseProxy) {
51353
51872
  const { baseUrl, token, agentKind, openRouter } = payload.houseProxy;
51873
+ const managedAgentId = isManagedProviderId(payload.agentId) ? payload.agentId : void 0;
51354
51874
  childEnv = {
51355
- ...buildHouseProxyChildEnv({ baseUrl, token, openRouter: openRouter === true }),
51875
+ ...buildHouseProxyChildEnv({
51876
+ baseUrl,
51877
+ token,
51878
+ openRouter: openRouter === true,
51879
+ ...managedAgentId ? { managedAgentId } : {}
51880
+ }),
51356
51881
  CODEAM_AUTO_TOKEN: payload.autoPairToken
51357
51882
  };
51358
- const houseConfigDir = path105.join(
51359
- os67.homedir(),
51883
+ const houseConfigDir = path108.join(
51884
+ os69.homedir(),
51360
51885
  ".codeam",
51361
51886
  "house-claude",
51362
51887
  payload.deployId
51363
51888
  );
51364
51889
  try {
51365
- fs91.mkdirSync(houseConfigDir, { recursive: true, mode: 448 });
51890
+ fs94.mkdirSync(houseConfigDir, { recursive: true, mode: 448 });
51366
51891
  } catch {
51367
51892
  }
51368
51893
  childEnv.CLAUDE_CONFIG_DIR = houseConfigDir;
@@ -51371,7 +51896,8 @@ var HostAgentSupervisor = class {
51371
51896
  baseUrl,
51372
51897
  token,
51373
51898
  openRouter: !!openRouter,
51374
- claudeConfigDir: houseConfigDir
51899
+ claudeConfigDir: houseConfigDir,
51900
+ ...managedAgentId ? { managedAgentId } : {}
51375
51901
  }, payload.deployId);
51376
51902
  } else {
51377
51903
  const auth = await this.resolveAgentAuth(this.identity, payload.sealedAgentAuth);
@@ -51388,7 +51914,7 @@ var HostAgentSupervisor = class {
51388
51914
  report("installing", "installing agent CLI");
51389
51915
  await this.runAgentInstall(payload.agentInstallScript);
51390
51916
  }
51391
- const home = process.env.HOME || os67.homedir();
51917
+ const home = process.env.HOME || os69.homedir();
51392
51918
  childEnv.PATH = `${home}/.local/bin:${process.env.PATH ?? ""}`;
51393
51919
  if (payload.cloneToken) {
51394
51920
  try {
@@ -51396,13 +51922,13 @@ var HostAgentSupervisor = class {
51396
51922
  if ((payload.repoProvider ?? "github") === "gitlab") {
51397
51923
  const glabCmd = await ensureGlabCli(defaultGitToolingRunner);
51398
51924
  if (glabCmd) {
51399
- childEnv.PATH = `${codeamBinDir()}${path105.delimiter}${childEnv.PATH}`;
51925
+ childEnv.PATH = `${codeamBinDir()}${path108.delimiter}${childEnv.PATH}`;
51400
51926
  await ensureGlabAuth(defaultGitToolingRunner, glabCmd, payload.cloneToken);
51401
51927
  }
51402
51928
  } else {
51403
51929
  const ghCmd = await ensureGhCli(defaultGitToolingRunner, payload.cloneToken);
51404
51930
  if (ghCmd) {
51405
- childEnv.PATH = `${codeamBinDir()}${path105.delimiter}${childEnv.PATH}`;
51931
+ childEnv.PATH = `${codeamBinDir()}${path108.delimiter}${childEnv.PATH}`;
51406
51932
  await ensureGhAuth(defaultGitToolingRunner, ghCmd, payload.cloneToken);
51407
51933
  }
51408
51934
  }
@@ -51430,9 +51956,9 @@ var HostAgentSupervisor = class {
51430
51956
  );
51431
51957
  if (!payload.suppressOnboardingWelcome) {
51432
51958
  try {
51433
- const cfgDir = childEnv.CLAUDE_CONFIG_DIR || path105.join(os67.homedir(), ".claude");
51434
- const projectDir = path105.join(cfgDir, "projects", encodeCwd(cwd));
51435
- const hasPriorConversation = fs91.existsSync(projectDir) && fs91.readdirSync(projectDir).some((f) => f.endsWith(".jsonl"));
51959
+ const cfgDir = childEnv.CLAUDE_CONFIG_DIR || path108.join(os69.homedir(), ".claude");
51960
+ const projectDir = path108.join(cfgDir, "projects", encodeCwd(cwd));
51961
+ const hasPriorConversation = fs94.existsSync(projectDir) && fs94.readdirSync(projectDir).some((f) => f.endsWith(".jsonl"));
51436
51962
  if (hasPriorConversation) {
51437
51963
  childEnv.CODEAM_RESUME_LATEST = "1";
51438
51964
  log.info(
@@ -51586,7 +52112,7 @@ var HostAgentSupervisor = class {
51586
52112
  fallbackResumeTarget() {
51587
52113
  const session = getActiveSession();
51588
52114
  if (!session || !session.pluginId || !session.pollSecret || !session.agent) return null;
51589
- const cwd = session.cwd && fs91.existsSync(session.cwd) ? session.cwd : process.cwd();
52115
+ const cwd = session.cwd && fs94.existsSync(session.cwd) ? session.cwd : process.cwd();
51590
52116
  if (isFilesystemRoot(cwd)) {
51591
52117
  log.warn(
51592
52118
  "host-agent",
@@ -51626,7 +52152,7 @@ var HostAgentSupervisor = class {
51626
52152
  log.warn("host-agent", `self_hosted_resume ${sessionId.slice(0, 8)}: no saved pairing on this box`);
51627
52153
  return;
51628
52154
  }
51629
- if (!session.cwd || !fs91.existsSync(session.cwd)) {
52155
+ if (!session.cwd || !fs94.existsSync(session.cwd)) {
51630
52156
  log.warn("host-agent", `self_hosted_resume ${sessionId.slice(0, 8)}: workspace is gone`);
51631
52157
  return;
51632
52158
  }
@@ -51668,7 +52194,7 @@ var HostAgentSupervisor = class {
51668
52194
  const persisted = new Map((this.sessionStore.load() ?? []).map((r) => [r.deployId, r.agent]));
51669
52195
  for (const c2 of this.children.values()) persisted.set(c2.deployId, c2.agent);
51670
52196
  return this.listSavedSessions().map((s) => ({ s, deployId: deployIdFromWorkspace(s.cwd) })).filter(
51671
- (x) => x.deployId !== null && !!x.s.cwd && fs91.existsSync(x.s.cwd)
52197
+ (x) => x.deployId !== null && !!x.s.cwd && fs94.existsSync(x.s.cwd)
51672
52198
  ).map(({ s, deployId }) => {
51673
52199
  const agent = persisted.get(deployId);
51674
52200
  return { deployId, sessionId: s.id, ...agent ? { agent } : {} };
@@ -51720,7 +52246,7 @@ var HostAgentSupervisor = class {
51720
52246
  if (this.children.has(deployId)) return;
51721
52247
  const st3 = this.resumeStateFor(target);
51722
52248
  try {
51723
- const cwd = fs91.existsSync(target.cwd) ? target.cwd : process.cwd();
52249
+ const cwd = fs94.existsSync(target.cwd) ? target.cwd : process.cwd();
51724
52250
  const proc = this.resumeSpawner(
51725
52251
  { ...readHouseProxyChildEnv(deployId), CODEAM_RESUME_SESSION_ID: session.id },
51726
52252
  cwd
@@ -51747,7 +52273,7 @@ var HostAgentSupervisor = class {
51747
52273
  return;
51748
52274
  }
51749
52275
  if (tracked && signal) {
51750
- this.onResumeChildExit(target, 128 + (os67.constants.signals[signal] ?? 9), `signal ${signal}`);
52276
+ this.onResumeChildExit(target, 128 + (os69.constants.signals[signal] ?? 9), `signal ${signal}`);
51751
52277
  return;
51752
52278
  }
51753
52279
  log.warn(
@@ -51790,7 +52316,7 @@ var HostAgentSupervisor = class {
51790
52316
  if (Date.now() - child.startedAt < CRASH_RESPAWN_MIN_UPTIME_MS) return false;
51791
52317
  const session = pickSavedSessionForWorkspace(this.listSavedSessions(), child.cwd);
51792
52318
  if (!session) return false;
51793
- const exitCode = typeof code === "number" ? code : 128 + (signal ? os67.constants.signals[signal] ?? 9 : 9);
52319
+ const exitCode = typeof code === "number" ? code : 128 + (signal ? os69.constants.signals[signal] ?? 9 : 9);
51794
52320
  log.warn(
51795
52321
  "host-agent",
51796
52322
  `session deploy=${child.deployId.slice(0, 8)} died (${signal ?? code}) after ${Math.round((Date.now() - child.startedAt) / 1e3)}s \u2014 respawning it (resume)`
@@ -51939,12 +52465,12 @@ var HostAgentSupervisor = class {
51939
52465
  this.untrackChild(deployId);
51940
52466
  }
51941
52467
  const dirs = [
51942
- path105.join(selfHostedWorkspaceRoot(), deployId),
51943
- path105.join(os67.homedir(), ".codeam", "house-claude", deployId)
52468
+ path108.join(selfHostedWorkspaceRoot(), deployId),
52469
+ path108.join(os69.homedir(), ".codeam", "house-claude", deployId)
51944
52470
  ];
51945
52471
  for (const dir of dirs) {
51946
52472
  try {
51947
- fs91.rmSync(dir, { recursive: true, force: true });
52473
+ fs94.rmSync(dir, { recursive: true, force: true });
51948
52474
  } catch (err) {
51949
52475
  log.warn(
51950
52476
  "host-agent",
@@ -52022,13 +52548,19 @@ async function resolveHostIdentity(enrollToken) {
52022
52548
  }
52023
52549
  async function hostAgent(args2 = []) {
52024
52550
  installRelayCrashGuards();
52551
+ if (await superviseCurrent({ args: args2 }) === "supervised") return;
52025
52552
  const tokenArg = args2.find((a) => a.startsWith("--token="));
52026
52553
  const enrollToken = (tokenArg ? tokenArg.slice("--token=".length).trim() : "") || process.env.CODEAM_ENROLL_TOKEN || void 0;
52027
52554
  const identity = await resolveHostIdentity(enrollToken);
52028
52555
  if (!identity) {
52029
- throw new Error(
52030
- "host-agent: no sealed host identity and no enroll token. Re-run the installer from the app (tokens expire after 15 min)."
52556
+ log.error(
52557
+ "host-agent",
52558
+ "no sealed host identity and no enroll token. Re-run the installer from the app (tokens expire after 15 min)."
52559
+ );
52560
+ process.stderr.write(
52561
+ "host-agent: no sealed host identity and no enroll token. Re-run the installer from the app (tokens expire after 15 min).\n"
52031
52562
  );
52563
+ process.exit(EXIT_HOST_NOT_ENROLLED);
52032
52564
  }
52033
52565
  const supervisor = new HostAgentSupervisor(identity);
52034
52566
  supervisor.start();
@@ -52038,6 +52570,7 @@ async function hostAgent(args2 = []) {
52038
52570
  };
52039
52571
  process.once("SIGINT", shutdown);
52040
52572
  process.once("SIGTERM", shutdown);
52573
+ if (args2.includes(SUPERVISED_FLAG)) bindSupervisedLifecycle(process, shutdown);
52041
52574
  await new Promise(() => {
52042
52575
  });
52043
52576
  }
@@ -52104,8 +52637,8 @@ async function invite() {
52104
52637
  var import_node_dns = require("dns");
52105
52638
  var import_node_util11 = require("util");
52106
52639
  var import_node_crypto17 = require("crypto");
52107
- var fs92 = __toESM(require("fs"));
52108
- var path106 = __toESM(require("path"));
52640
+ var fs95 = __toESM(require("fs"));
52641
+ var path109 = __toESM(require("path"));
52109
52642
  var import_picocolors14 = __toESM(require("picocolors"));
52110
52643
  var dnsResolveP = (0, import_node_util11.promisify)(import_node_dns.resolve);
52111
52644
  async function checkDns(apiBase2) {
@@ -52161,13 +52694,13 @@ async function checkHealth(apiBase2) {
52161
52694
  }
52162
52695
  }
52163
52696
  function checkConfigDir() {
52164
- const dir = path106.join(require("os").homedir(), ".codeam");
52697
+ const dir = path109.join(require("os").homedir(), ".codeam");
52165
52698
  try {
52166
- fs92.mkdirSync(dir, { recursive: true, mode: 448 });
52167
- const probe = path106.join(dir, ".doctor-probe");
52168
- fs92.writeFileSync(probe, "ok", { mode: 384 });
52169
- const read = fs92.readFileSync(probe, "utf8");
52170
- fs92.unlinkSync(probe);
52699
+ fs95.mkdirSync(dir, { recursive: true, mode: 448 });
52700
+ const probe = path109.join(dir, ".doctor-probe");
52701
+ fs95.writeFileSync(probe, "ok", { mode: 384 });
52702
+ const read = fs95.readFileSync(probe, "utf8");
52703
+ fs95.unlinkSync(probe);
52171
52704
  if (read !== "ok") throw new Error("write/read round-trip mismatch");
52172
52705
  return {
52173
52706
  id: "config-dir",
@@ -52207,9 +52740,9 @@ function checkSessions() {
52207
52740
  }
52208
52741
  }
52209
52742
  function checkAgentBinaries() {
52210
- const os70 = createOsStrategy();
52743
+ const os72 = createOsStrategy();
52211
52744
  return getEnabledAgents().map((meta) => {
52212
- const found = os70.findInPath(meta.binaryName);
52745
+ const found = os72.findInPath(meta.binaryName);
52213
52746
  return {
52214
52747
  id: `agent-${meta.id}`,
52215
52748
  label: `Agent binary: ${meta.displayName} (${meta.binaryName})`,
@@ -52231,7 +52764,7 @@ function checkNodePty() {
52231
52764
  detail: "not required on this platform"
52232
52765
  };
52233
52766
  }
52234
- const vendoredPath = path106.join(__dirname, "vendor", "node-pty");
52767
+ const vendoredPath = path109.join(__dirname, "vendor", "node-pty");
52235
52768
  for (const target of [vendoredPath, "node-pty"]) {
52236
52769
  try {
52237
52770
  require(target);
@@ -52273,7 +52806,7 @@ function checkChokidar() {
52273
52806
  }
52274
52807
  async function doctor(args2 = []) {
52275
52808
  const json = args2.includes("--json");
52276
- const cliVersion = true ? "2.76.9" : "0.0.0-dev";
52809
+ const cliVersion = true ? "2.76.11" : "0.0.0-dev";
52277
52810
  const apiBase2 = resolveApiBaseUrl();
52278
52811
  const diagnosticId = (0, import_node_crypto17.randomUUID)();
52279
52812
  log.info("doctor", `run id=${diagnosticId} cli=${cliVersion}`);
@@ -52470,7 +53003,7 @@ async function completion(args2) {
52470
53003
  }
52471
53004
 
52472
53005
  // src/integrations/mcp-run.ts
52473
- var import_node_child_process38 = require("child_process");
53006
+ var import_node_child_process39 = require("child_process");
52474
53007
 
52475
53008
  // src/integrations/launcher-env.ts
52476
53009
  var LAUNCHER_ENV = Object.freeze({
@@ -52554,7 +53087,7 @@ function resolveDelivery(id) {
52554
53087
  function commandExists(command2) {
52555
53088
  try {
52556
53089
  const probe = process.platform === "win32" ? "where" : "which";
52557
- (0, import_node_child_process38.execFileSync)(probe, [command2], { stdio: "ignore" });
53090
+ (0, import_node_child_process39.execFileSync)(probe, [command2], { stdio: "ignore" });
52558
53091
  return true;
52559
53092
  } catch {
52560
53093
  return false;
@@ -52587,7 +53120,7 @@ function ensureCommand(command2) {
52587
53120
  }
52588
53121
  if (command2 === "uvx") {
52589
53122
  try {
52590
- (0, import_node_child_process38.execSync)("curl -LsSf https://astral.sh/uv/install.sh | sh", {
53123
+ (0, import_node_child_process39.execSync)("curl -LsSf https://astral.sh/uv/install.sh | sh", {
52591
53124
  stdio: ["ignore", process.stderr, process.stderr],
52592
53125
  timeout: 18e4,
52593
53126
  env: { ...process.env, UV_NO_MODIFY_PATH: "1" }
@@ -52596,7 +53129,7 @@ function ensureCommand(command2) {
52596
53129
  }
52597
53130
  if (resolveLauncherPath(command2) !== command2) return;
52598
53131
  try {
52599
- (0, import_node_child_process38.execSync)("python3 -m pip install --user --quiet uv", {
53132
+ (0, import_node_child_process39.execSync)("python3 -m pip install --user --quiet uv", {
52600
53133
  stdio: ["ignore", process.stderr, process.stderr],
52601
53134
  timeout: 18e4
52602
53135
  });
@@ -52674,7 +53207,7 @@ async function mcpRun(args2) {
52674
53207
  }
52675
53208
 
52676
53209
  // src/integrations/mcp-warm.ts
52677
- var import_node_child_process39 = require("child_process");
53210
+ var import_node_child_process40 = require("child_process");
52678
53211
  function specOf(delivery) {
52679
53212
  if (!delivery.command) return null;
52680
53213
  const spec = (delivery.args ?? []).find((a) => !a.startsWith("-"));
@@ -52717,8 +53250,8 @@ var WARM_PACKAGE_TIMEOUT_MS = 12e4;
52717
53250
  var WARM_TOTAL_BUDGET_MS = 10 * 6e4;
52718
53251
  var WARM_CONCURRENCY = 4;
52719
53252
  function runCapturing(command2, args2, timeoutMs) {
52720
- return new Promise((resolve12) => {
52721
- const child = (0, import_node_child_process39.spawn)(command2, args2, {
53253
+ return new Promise((resolve14) => {
53254
+ const child = (0, import_node_child_process40.spawn)(command2, args2, {
52722
53255
  env: { ...process.env, ...LAUNCHER_ENV },
52723
53256
  stdio: ["ignore", "ignore", "pipe"],
52724
53257
  // `npx`/`uv` are `.cmd` shims on Windows; Node ≥ 20.12 refuses to spawn a
@@ -52732,15 +53265,15 @@ function runCapturing(command2, args2, timeoutMs) {
52732
53265
  child.stderr?.on("data", (c2) => stderr += c2);
52733
53266
  const timer = setTimeout(() => {
52734
53267
  child.kill("SIGKILL");
52735
- resolve12({ status: null, stderr, error: new Error(`spawn ${command2} ETIMEDOUT`) });
53268
+ resolve14({ status: null, stderr, error: new Error(`spawn ${command2} ETIMEDOUT`) });
52736
53269
  }, timeoutMs);
52737
53270
  child.on("error", (error) => {
52738
53271
  clearTimeout(timer);
52739
- resolve12({ status: null, stderr, error });
53272
+ resolve14({ status: null, stderr, error });
52740
53273
  });
52741
53274
  child.on("close", (status2) => {
52742
53275
  clearTimeout(timer);
52743
- resolve12({ status: status2, stderr });
53276
+ resolve14({ status: status2, stderr });
52744
53277
  });
52745
53278
  });
52746
53279
  }
@@ -52797,7 +53330,7 @@ async function mcpWarm(argv = [], opts = {}) {
52797
53330
  // src/commands/version.ts
52798
53331
  var import_picocolors15 = __toESM(require("picocolors"));
52799
53332
  function version2() {
52800
- const v = true ? "2.76.9" : "unknown";
53333
+ const v = true ? "2.76.11" : "unknown";
52801
53334
  console.log(`${import_picocolors15.default.bold("codeam-cli")} ${import_picocolors15.default.cyan(v)}`);
52802
53335
  }
52803
53336
 
@@ -52929,32 +53462,17 @@ function tryShowSubcommandHelp(cmd, args2) {
52929
53462
  }
52930
53463
  var _subcommandHelpKeys = Object.keys(HELPS);
52931
53464
 
52932
- // src/exit-codes.ts
52933
- var EXIT_OK = 0;
52934
- var EXIT_FAILURE = 1;
52935
- var EXIT_USAGE = 2;
52936
- var EXIT_NEEDS_PAIRING = 3;
52937
- var EXIT_SIGINT = 130;
52938
- var EXIT_SIGTERM = 143;
52939
- var EXIT_CODE_NAMES = {
52940
- [EXIT_OK]: "ok",
52941
- [EXIT_FAILURE]: "failure",
52942
- [EXIT_USAGE]: "usage_error",
52943
- [EXIT_NEEDS_PAIRING]: "needs_pairing",
52944
- [EXIT_SIGINT]: "sigint",
52945
- [EXIT_SIGTERM]: "sigterm"
52946
- };
52947
-
52948
53465
  // src/index.ts
52949
- var os69 = __toESM(require("os"));
53466
+ var os71 = __toESM(require("os"));
52950
53467
  if (!process.env.HOME) {
52951
53468
  try {
52952
- const home = os69.homedir();
53469
+ const home = os71.homedir();
52953
53470
  if (home) process.env.HOME = home;
52954
53471
  } catch {
52955
53472
  }
52956
53473
  }
52957
53474
  loadCodespaceEnv();
53475
+ registerRunningVersion();
52958
53476
  var [, , command, ...args] = process.argv;
52959
53477
  async function main() {
52960
53478
  const isMetaCommand = command === "--version" || command === "-v" || command === "version" || command === "--help" || command === "-h" || command === "help";