@cloop/runner 0.3.18 → 0.3.22

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.
@@ -3,18 +3,22 @@ import {
3
3
  readRunnerState,
4
4
  runnerStatePath,
5
5
  threadsFilePath
6
- } from "./chunk-QINWGIXU.js";
6
+ } from "./chunk-Z7WF67JW.js";
7
7
  import {
8
8
  BoxToolError,
9
9
  CLOOP_THREAD_PREFIX,
10
10
  ENVIRONMENTS,
11
+ MIN_PROTOCOL,
11
12
  RUNTIME_MODES,
13
+ T3Client,
12
14
  T3Driver,
15
+ T3HttpError,
13
16
  boxPath,
14
17
  cloopCommand,
15
18
  commandFor,
16
19
  defaultT3BinSources,
17
20
  environmentOf,
21
+ exchangePairing,
18
22
  isLocal,
19
23
  isYes,
20
24
  localRunsFilePath,
@@ -22,6 +26,7 @@ import {
22
26
  pickT3Bin,
23
27
  questionLine,
24
28
  quoteWindowsArg,
29
+ readEnvironment,
25
30
  readRunnerConfig,
26
31
  runT3,
27
32
  runnerDir,
@@ -32,7 +37,7 @@ import {
32
37
  windowsExecutable,
33
38
  windowsPowerShellEnv,
34
39
  writeBoxConfig
35
- } from "./chunk-R22774MI.js";
40
+ } from "./chunk-TNNAPOD5.js";
36
41
  import {
37
42
  getMachine,
38
43
  shortMachineName
@@ -50,17 +55,17 @@ import {
50
55
  } from "./chunk-R3CLO2FB.js";
51
56
  import {
52
57
  connectWebhook
53
- } from "./chunk-LORK2EOG.js";
58
+ } from "./chunk-VKINCK5H.js";
54
59
  import {
55
60
  ConnectFailure,
56
61
  connectReport,
57
62
  deviceLogin,
58
63
  newAttempt,
59
64
  sendConnectReport
60
- } from "./chunk-EIBHDWUG.js";
65
+ } from "./chunk-OF3PX5L2.js";
61
66
  import {
62
67
  VERSION
63
- } from "./chunk-OBFJRACJ.js";
68
+ } from "./chunk-AJAVT5YZ.js";
64
69
  import {
65
70
  STAGING_ORIGIN,
66
71
  getOrigin,
@@ -80,34 +85,41 @@ import {
80
85
  writeFileSync
81
86
  } from "fs";
82
87
  import { homedir as homedir4, userInfo } from "os";
83
- import { basename as basename4, dirname, join as join3, resolve as resolve2 } from "path";
88
+ import { basename as basename5, dirname as dirname2, join as join3, resolve as resolve2 } from "path";
84
89
  import { createInterface } from "readline/promises";
85
90
  import { Writable } from "stream";
86
91
 
87
92
  // src/agent-install.ts
88
93
  import { spawn } from "child_process";
89
- import { existsSync, readdirSync } from "fs";
90
- import { delimiter, join, posix, win32 } from "path";
94
+ import { existsSync, readdirSync, realpathSync } from "fs";
95
+ import { basename, delimiter, dirname, join, posix, win32 } from "path";
91
96
  var CODEX_RELEASES = "https://github.com/openai/codex/releases/latest/download";
92
97
  var CODEX_TRIPLES = {
93
98
  "darwin-arm64": "aarch64-apple-darwin",
94
99
  "darwin-x64": "x86_64-apple-darwin",
95
100
  "linux-x64": "x86_64-unknown-linux-musl",
96
101
  "linux-arm64": "aarch64-unknown-linux-musl",
97
- "win32-x64": "x86_64-pc-windows-msvc.exe",
98
- "win32-arm64": "aarch64-pc-windows-msvc.exe"
102
+ "win32-x64": "x86_64-pc-windows-msvc",
103
+ "win32-arm64": "aarch64-pc-windows-msvc"
99
104
  };
100
105
  function codexAsset(platform, arch) {
101
106
  const triple = CODEX_TRIPLES[`${platform}-${arch}`];
102
- return triple ? `codex-${triple}` : null;
107
+ return triple ? `codex-package-${triple}` : null;
103
108
  }
104
- var codexBinDir = (home) => join(home, ".cloop", "bin");
109
+ var codexHome = (home) => join(home, ".cloop", "codex");
110
+ var codexBinDir = (home) => join(codexHome(home), "bin");
111
+ var CODE_MODE_HOST = "codex-code-mode-host";
112
+ var exe = (name, platform) => platform === "win32" ? `${name}.exe` : name;
113
+ var oneFileCodex = (home, platform) => join(home, ".cloop", "bin", exe("codex", platform));
105
114
  var psQuote = (value) => `'${value.replace(/'/g, "''")}'`;
115
+ var CODEX_SUMS = `${CODEX_RELEASES}/codex-package_SHA256SUMS`;
106
116
  function codexInstallCommand(home, platform = process.platform, arch = process.arch) {
107
117
  const asset = codexAsset(platform, arch);
108
118
  if (!asset) return null;
109
- const dir = codexBinDir(home);
110
- const url = `${CODEX_RELEASES}/${asset}.tar.gz`;
119
+ const dir = codexHome(home);
120
+ const file = `${asset}.tar.gz`;
121
+ const url = `${CODEX_RELEASES}/${file}`;
122
+ const old = oneFileCodex(home, platform);
111
123
  if (platform === "win32")
112
124
  return [
113
125
  "powershell",
@@ -118,24 +130,60 @@ function codexInstallCommand(home, platform = process.platform, arch = process.a
118
130
  [
119
131
  "$ErrorActionPreference = 'Stop'",
120
132
  `$d = ${psQuote(dir)}`,
121
- "New-Item -ItemType Directory -Force -Path $d | Out-Null",
122
- "$t = Join-Path ([IO.Path]::GetTempPath()) 'codex.tar.gz'",
133
+ "$s = $d + '.new'",
134
+ "$o = $d + '.old'",
135
+ "if (Test-Path $s) { Remove-Item -Recurse -Force $s }",
136
+ "New-Item -ItemType Directory -Force -Path $s | Out-Null",
137
+ "$t = Join-Path $s 'codex-package.tar.gz'",
123
138
  `Invoke-WebRequest -UseBasicParsing ${psQuote(url)} -OutFile $t`,
124
- "tar.exe -xzf $t -C $d",
125
- `Move-Item -Force (Join-Path $d ${psQuote(asset)}) (Join-Path $d 'codex.exe')`,
126
- "Remove-Item -Force $t"
139
+ "$h = Join-Path $s 'codex-package_SHA256SUMS'",
140
+ // GitHub serves the digest list as octet-stream, so .Content would be bytes; a file reads as lines.
141
+ `Invoke-WebRequest -UseBasicParsing ${psQuote(CODEX_SUMS)} -OutFile $h`,
142
+ `$line = Get-Content $h | Where-Object { $_.Trim().EndsWith(${psQuote(` ${file}`)}) } | Select-Object -First 1`,
143
+ `if (-not $line) { throw ${psQuote(`${file} is not in codex-package_SHA256SUMS`)} }`,
144
+ "$want = ($line.Trim() -split '\\s+')[0].ToLower()",
145
+ "$got = (Get-FileHash -Algorithm SHA256 $t).Hash.ToLower()",
146
+ `if ($got -ne $want) { throw ${psQuote(`${file} does not match its SHA-256 in codex-package_SHA256SUMS`)} }`,
147
+ "tar.exe -xzf $t -C $s",
148
+ "Remove-Item -Force $t, $h",
149
+ `foreach ($f in 'codex.exe', '${CODE_MODE_HOST}.exe') { if (-not (Test-Path (Join-Path $s (Join-Path 'bin' $f)))) { throw ($f + ' is not in the Codex package') } }`,
150
+ "if (Test-Path $o) { Remove-Item -Recurse -Force $o }",
151
+ "if (Test-Path $d) { Move-Item $d $o }",
152
+ "Move-Item $s $d",
153
+ "if (Test-Path $o) { Remove-Item -Recurse -Force $o -ErrorAction SilentlyContinue }",
154
+ `Remove-Item -Force -ErrorAction SilentlyContinue ${psQuote(old)}`
127
155
  ].join("; ")
128
156
  ];
129
157
  return [
130
158
  "sh",
131
159
  "-c",
132
- 'mkdir -p "$1" && curl -fsSL "$2" | tar -xz -C "$1" && mv -f "$1/$3" "$1/codex" && chmod 755 "$1/codex"',
160
+ POSIX_INSTALL,
133
161
  "cloop",
134
162
  dir,
135
163
  url,
136
- asset
164
+ CODEX_SUMS,
165
+ file,
166
+ platform === "darwin" ? "shasum -a 256" : "sha256sum",
167
+ CODE_MODE_HOST,
168
+ old
137
169
  ];
138
170
  }
171
+ var POSIX_INSTALL = [
172
+ 'rm -rf "$1.new" "$1.old"',
173
+ 'mkdir -p "$1.new"',
174
+ 'curl -fsSL "$2" -o "$1.new/codex-package.tar.gz"',
175
+ `want=$(curl -fsSL "$3" | awk -v f="$4" '$2 == f { print $1 }')`,
176
+ 'got=$($5 "$1.new/codex-package.tar.gz" | cut -d" " -f1)',
177
+ '{ [ -n "$want" ] && [ "$want" = "$got" ] || { echo "$4 does not match its SHA-256 in codex-package_SHA256SUMS" >&2; exit 1; }; }',
178
+ 'tar -xzf "$1.new/codex-package.tar.gz" -C "$1.new"',
179
+ 'rm -f "$1.new/codex-package.tar.gz"',
180
+ 'test -x "$1.new/bin/codex"',
181
+ 'test -x "$1.new/bin/$6"',
182
+ '{ [ ! -e "$1" ] || mv "$1" "$1.old"; }',
183
+ 'mv "$1.new" "$1"',
184
+ 'rm -rf "$1.old"',
185
+ 'rm -f "$7"'
186
+ ].join(" && ");
139
187
  async function installCodex(home, run = runShown) {
140
188
  const command = codexInstallCommand(home);
141
189
  if (!command || !await run(command)) return false;
@@ -176,6 +224,16 @@ function findIn(folder, name, env) {
176
224
  function findLocalCodex(home, env = process.env) {
177
225
  findIn(codexBinDir(home), "codex", env);
178
226
  }
227
+ function codexHostMissing(path, platform = process.platform) {
228
+ if (!path) return false;
229
+ try {
230
+ const real = realpathSync(path);
231
+ if (basename(real).toLowerCase() !== exe("codex", platform)) return false;
232
+ return !existsSync(join(dirname(real), exe(CODE_MODE_HOST, platform)));
233
+ } catch {
234
+ return false;
235
+ }
236
+ }
179
237
  function findLocalClaude(home, env = process.env) {
180
238
  findIn(join(home, ".local", "bin"), "claude", env);
181
239
  }
@@ -194,175 +252,6 @@ function hasChatGptApp(home, platform = process.platform, env = process.env, fs
194
252
  return false;
195
253
  }
196
254
 
197
- // src/t3.ts
198
- var T3_SCOPE = "orchestration:read orchestration:operate";
199
- var MIN_PROTOCOL = 2;
200
- async function readEnvironment(t3Url, fetchFn = fetch) {
201
- const res = await fetchFn(`${t3Url}/.well-known/t3/environment`);
202
- if (!res.ok) throw new Error(`T3 environment ${res.status} at ${t3Url}`);
203
- return await res.json();
204
- }
205
- async function exchangePairing(t3Url, credential, label, fetchFn = fetch) {
206
- const form = new URLSearchParams({
207
- grant_type: "urn:ietf:params:oauth:grant-type:token-exchange",
208
- subject_token: credential,
209
- subject_token_type: "urn:t3:params:oauth:token-type:environment-bootstrap",
210
- requested_token_type: "urn:ietf:params:oauth:token-type:access_token",
211
- scope: T3_SCOPE,
212
- client_label: label,
213
- client_device_type: "bot"
214
- });
215
- const res = await fetchFn(`${t3Url}/oauth/token`, { method: "POST", body: form });
216
- if (!res.ok) throw new T3HttpError("token exchange", res.status);
217
- const token = await res.json();
218
- if (!sameScopes(token.scope, T3_SCOPE))
219
- throw new Error(`T3 granted scope "${token.scope}", wanted "${T3_SCOPE}"`);
220
- return token;
221
- }
222
- function sameScopes(a, b) {
223
- const set = (s) => [...new Set(s.split(/\s+/).filter(Boolean))].sort().join(" ");
224
- return set(a) === set(b);
225
- }
226
- var T3HttpError = class extends Error {
227
- constructor(path, status) {
228
- super(`T3 ${path} ${status}`);
229
- this.status = status;
230
- this.name = "T3HttpError";
231
- }
232
- status;
233
- };
234
- var T3Client = class {
235
- constructor(t3Url, token, fetchFn = fetch) {
236
- this.t3Url = t3Url;
237
- this.token = token;
238
- this.fetchFn = fetchFn;
239
- }
240
- t3Url;
241
- token;
242
- fetchFn;
243
- async http(path, headers = {}) {
244
- const res = await this.fetchFn(`${this.t3Url}${path}`, {
245
- headers: { authorization: `Bearer ${this.token}`, ...headers }
246
- });
247
- if (!res.ok) throw new T3HttpError(path, res.status);
248
- return await res.json();
249
- }
250
- async openSocket() {
251
- const ticket = await this.fetchFn(`${this.t3Url}/api/auth/websocket-ticket`, {
252
- method: "POST",
253
- headers: { authorization: `Bearer ${this.token}` }
254
- });
255
- if (!ticket.ok) throw new T3HttpError("/api/auth/websocket-ticket", ticket.status);
256
- const { ticket: wsTicket } = await ticket.json();
257
- const { WebSocket } = await import("ws");
258
- const url = `${this.t3Url.replace(/^http/, "ws")}/ws?wsTicket=${encodeURIComponent(wsTicket)}&orchestrationProtocol=2&clientSurface=web&clientAppVersion=cloop-box`;
259
- return new WebSocket(url);
260
- }
261
- /** One request over a fresh /ws socket. The daemon makes a few calls a minute, so a socket per call is simpler than keeping one alive. */
262
- async rpc(tag, payload) {
263
- const ws = await this.openSocket();
264
- return new Promise((resolve3, reject) => {
265
- let settled = false;
266
- const finish = (fn) => {
267
- if (settled) return;
268
- settled = true;
269
- clearTimeout(timer);
270
- fn();
271
- try {
272
- ws.close();
273
- } catch {
274
- }
275
- };
276
- const timer = setTimeout(
277
- () => finish(() => reject(new Error(`T3 rpc ${tag} timed out`))),
278
- 15e3
279
- );
280
- ws.on(
281
- "error",
282
- (err) => finish(() => reject(err instanceof Error ? err : new Error(String(err))))
283
- );
284
- ws.on(
285
- "close",
286
- () => finish(() => reject(new Error(`T3 rpc ${tag}: socket closed before a reply`)))
287
- );
288
- ws.on("open", () => {
289
- ws.send(JSON.stringify({ _tag: "Request", id: 1, tag, payload, headers: [] }));
290
- });
291
- ws.on("message", (data) => {
292
- for (const msg of parseFrames(data)) {
293
- if (msg._tag !== "Exit" || String(msg.requestId) !== "1") continue;
294
- const exit = msg.exit;
295
- if (exit._tag === "Success") finish(() => resolve3(exit.value));
296
- else {
297
- finish(
298
- () => reject(
299
- new Error(`T3 rpc ${tag} failed: ${JSON.stringify(exit.cause).slice(0, 300)}`)
300
- )
301
- );
302
- }
303
- }
304
- });
305
- });
306
- }
307
- /**
308
- * A streaming request, such as `orchestration.subscribeThread`, on its own
309
- * socket. Every item is acked, as Effect RPC requires. `done` resolves with
310
- * the reason the stream ended and never rejects; `close` interrupts it.
311
- */
312
- async stream(tag, payload, onItem) {
313
- const ws = await this.openSocket();
314
- let resolveDone = () => {
315
- };
316
- const done = new Promise((r) => {
317
- resolveDone = r;
318
- });
319
- const end = (reason) => {
320
- resolveDone(reason);
321
- try {
322
- ws.close();
323
- } catch {
324
- }
325
- };
326
- ws.on("error", (err) => end(`error: ${err instanceof Error ? err.message : String(err)}`));
327
- ws.on("close", () => end("closed"));
328
- ws.on("open", () => {
329
- ws.send(JSON.stringify({ _tag: "Request", id: 1, tag, payload, headers: [] }));
330
- });
331
- ws.on("message", (data) => {
332
- for (const msg of parseFrames(data)) {
333
- if (String(msg.requestId) !== "1") continue;
334
- if (msg._tag === "Chunk") {
335
- ws.send(JSON.stringify({ _tag: "Ack", requestId: msg.requestId }));
336
- for (const value of msg.values) onItem(value);
337
- } else if (msg._tag === "Exit") {
338
- const exit = msg.exit;
339
- end(
340
- exit._tag === "Success" ? "exit" : `failed: ${JSON.stringify(exit.cause).slice(0, 300)}`
341
- );
342
- }
343
- }
344
- });
345
- return {
346
- done,
347
- close: () => {
348
- try {
349
- ws.send(JSON.stringify({ _tag: "Interrupt", requestId: "1" }));
350
- } catch {
351
- }
352
- end("closed by client");
353
- }
354
- };
355
- }
356
- };
357
- function parseFrames(data) {
358
- try {
359
- const raw = JSON.parse(String(data));
360
- return Array.isArray(raw) ? raw : [raw];
361
- } catch {
362
- return [];
363
- }
364
- }
365
-
366
255
  // src/box-tools.ts
367
256
  var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
368
257
  function parseLaunchArgs(args) {
@@ -487,7 +376,7 @@ async function revokeOwnDevice(origin, deviceToken, fetchFn = fetch) {
487
376
 
488
377
  // src/drivers/claude-code.ts
489
378
  import { execFile } from "child_process";
490
- import { basename, isAbsolute, relative, resolve } from "path";
379
+ import { basename as basename2, isAbsolute, relative, resolve } from "path";
491
380
  var SUBSCRIPTIONS = {
492
381
  max: "Claude Max",
493
382
  pro: "Claude Pro",
@@ -647,7 +536,11 @@ function parseClaudeLine(raw, run) {
647
536
  return [];
648
537
  }
649
538
  if (msg.type === "system" && msg.subtype === "init" && typeof msg.session_id === "string") {
650
- return [{ type: "session", id: msg.session_id }];
539
+ const servers = Array.isArray(msg.mcp_servers) ? msg.mcp_servers : [];
540
+ const notReady = servers.filter(
541
+ (s) => typeof s?.name === "string" && (s.status === "pending" || s.status === "failed")
542
+ ).map((s) => `${s.name} (${s.status})`);
543
+ return [{ type: "session", id: msg.session_id, ...notReady.length ? { notReady } : {} }];
651
544
  }
652
545
  if (msg.type === "assistant") {
653
546
  const content = msg.message?.content;
@@ -664,7 +557,7 @@ function parseClaudeLine(raw, run) {
664
557
  {
665
558
  type: "tool",
666
559
  name: block.name,
667
- ...path ? { target: basename(path) } : {},
560
+ ...path ? { target: basename2(path) } : {},
668
561
  ...summary ? { summary } : {},
669
562
  ...detail ? { detail } : {}
670
563
  }
@@ -704,6 +597,7 @@ function parseClaudeLine(raw, run) {
704
597
  }
705
598
  return [];
706
599
  }
600
+ var MCP_STARTUP_WAIT_MS = 2e4;
707
601
  var DEFAULT_FALLBACK_MODEL = "opus";
708
602
  function claudeDialect(bin = "claude", fallback = DEFAULT_FALLBACK_MODEL, askEverything = false, options = {}) {
709
603
  const permission = () => askEverything ? "ask" : "full";
@@ -714,6 +608,7 @@ function claudeDialect(bin = "claude", fallback = DEFAULT_FALLBACK_MODEL, askEve
714
608
  aliases: ["claude-code", "claudeAgent", "claude"],
715
609
  bin,
716
610
  capabilities: ["view", "start", "steer", "report"],
611
+ env: { CLAUDE_CODE_MCP_STARTUP_WAIT_MS: String(MCP_STARTUP_WAIT_MS) },
717
612
  keepsStdin: true,
718
613
  args(run, resume) {
719
614
  return [
@@ -764,14 +659,14 @@ function claudeDialect(bin = "claude", fallback = DEFAULT_FALLBACK_MODEL, askEve
764
659
  });
765
660
  },
766
661
  parse: parseClaudeLine,
767
- owns: (run, command) => command.includes(basename(bin)) && [run.work_id, run.session_id].some((id) => id !== null && command.includes(id)),
662
+ owns: (run, command) => command.includes(basename2(bin)) && [run.work_id, run.session_id].some((id) => id !== null && command.includes(id)),
768
663
  probe: () => probeClaude(bin)
769
664
  };
770
665
  }
771
666
 
772
667
  // src/drivers/codex.ts
773
668
  import { execFile as execFile2 } from "child_process";
774
- import { basename as basename2 } from "path";
669
+ import { basename as basename3 } from "path";
775
670
  function exec2(bin, args, timeout = 1e4) {
776
671
  const command = commandFor(bin, args);
777
672
  return new Promise(
@@ -857,7 +752,7 @@ function parseCodexLine(raw) {
857
752
  {
858
753
  type: "tool",
859
754
  name: "Edit",
860
- ...typeof path === "string" ? { target: basename2(path) } : {}
755
+ ...typeof path === "string" ? { target: basename3(path) } : {}
861
756
  }
862
757
  ];
863
758
  }
@@ -892,7 +787,7 @@ function codexDialect(bin = "codex") {
892
787
  models: () => codexModels(bin),
893
788
  parse: parseCodexLine,
894
789
  // A fresh run's command line names no id: Codex makes its session id after the start. So a run is also matched by its exact repository, which one open run per repository makes unique.
895
- owns: (run, command) => command.includes(basename2(bin)) && command.includes("exec") && command.includes("--json") && (run.session_id !== null && command.includes(run.session_id) || command.includes(`--cd ${run.repo} `)),
790
+ owns: (run, command) => command.includes(basename3(bin)) && command.includes("exec") && command.includes("--json") && (run.session_id !== null && command.includes(run.session_id) || command.includes(`--cd ${run.repo} `)),
896
791
  probe: () => probeCodex(bin)
897
792
  };
898
793
  }
@@ -906,7 +801,7 @@ import { join as join2 } from "path";
906
801
  import { execFileSync } from "child_process";
907
802
  import { existsSync as existsSync3, readFileSync, rmSync } from "fs";
908
803
  import { homedir } from "os";
909
- import { basename as basename3 } from "path";
804
+ import { basename as basename4 } from "path";
910
805
 
911
806
  // src/existing-runner.ts
912
807
  import { existsSync as existsSync2 } from "fs";
@@ -1009,7 +904,7 @@ async function disconnect(plan, opts) {
1009
904
  ...command[0] === "powershell" ? { env: windowsPowerShellEnv() } : {}
1010
905
  }));
1011
906
  if (plan.isBox && !opts.yes) {
1012
- const unit = plan.services.map((s) => basename3(s.path)).find((n) => n.startsWith("cloop-box"));
907
+ const unit = plan.services.map((s) => basename4(s.path)).find((n) => n.startsWith("cloop-box"));
1013
908
  say(`This computer runs ${unit}, the ${env} Cloop box with T3 Code. Disconnect would:`);
1014
909
  for (const s of plan.services) say(` stop and remove ${s.path}`);
1015
910
  if (plan.deviceToken) say(` revoke its runner device on Cloop (${plan.origin})`);
@@ -1383,7 +1278,10 @@ function which(bin) {
1383
1278
  }
1384
1279
  function whichPosix(bin) {
1385
1280
  try {
1386
- return execFileSync2("which", [bin], { encoding: "utf-8", env: CLEAN_ENV }).trim() || null;
1281
+ return execFileSync2("which", [bin], {
1282
+ encoding: "utf-8",
1283
+ env: { ...CLEAN_ENV, PATH: process.env.PATH }
1284
+ }).trim() || null;
1387
1285
  } catch {
1388
1286
  return null;
1389
1287
  }
@@ -1635,7 +1533,7 @@ function programFor(script, node, npx, version) {
1635
1533
  }
1636
1534
  function findNpx() {
1637
1535
  const name = process.platform === "win32" ? "npx.cmd" : "npx";
1638
- const beside = join3(dirname(process.execPath), name);
1536
+ const beside = join3(dirname2(process.execPath), name);
1639
1537
  return existsSync5(beside) ? beside : which(name);
1640
1538
  }
1641
1539
  async function awaitDaemon(since, read = readRunnerState, { timeoutMs = 15e3, pollMs = 500 } = {}) {
@@ -1826,7 +1724,7 @@ function resolveRepos(paths, toplevel, isFolder = folderAt) {
1826
1724
  if (!isFolder(full))
1827
1725
  return `${p} is not a folder. Pass --repo <path> for each folder Cloop may work in.`;
1828
1726
  const top = toplevel(full) ?? full;
1829
- if (!repos.some((r) => r.path === top)) repos.push({ label: basename4(top), path: top });
1727
+ if (!repos.some((r) => r.path === top)) repos.push({ label: basename5(top), path: top });
1830
1728
  }
1831
1729
  return repos;
1832
1730
  }
@@ -1917,7 +1815,7 @@ async function reposFor(argv) {
1917
1815
  return repos2;
1918
1816
  }
1919
1817
  const here = gitTop(process.cwd());
1920
- if (here) return [{ label: basename4(here), path: here }];
1818
+ if (here) return [{ label: basename5(here), path: here }];
1921
1819
  const home = homedir4();
1922
1820
  const work = workFolder(home);
1923
1821
  const found = findCheckouts(home);
@@ -2299,6 +2197,7 @@ async function connect(argv, attempt, deps = {}) {
2299
2197
  const terminal = deps.terminal ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
2300
2198
  const current = await prepareAgents(found, forced, workstation, {
2301
2199
  chatGptApp: deps.chatGptApp ?? (() => machine && hasChatGptApp(homedir4())),
2200
+ codexHostMissing: deps.codexHostMissing ?? (() => machine && codexHostMissing(which("codex"))),
2302
2201
  installCodex: deps.installCodex ?? (async () => machine && installCodex(homedir4())),
2303
2202
  installClaude: deps.installClaude ?? (async () => machine && installClaude(homedir4())),
2304
2203
  readCodex,
@@ -2307,8 +2206,9 @@ async function connect(argv, attempt, deps = {}) {
2307
2206
  signInCodex: deps.signInCodex ?? (() => signInCodex(harnessBin("codex"))),
2308
2207
  signInClaude: deps.signInClaude ?? (() => signInClaude(harnessBin("claude"))),
2309
2208
  terminal,
2310
- installed: (agent, ok) => {
2209
+ installed: (agent, ok, reason) => {
2311
2210
  attempt[agent === "codex" ? "codexInstall" : "claudeInstall"] = ok ? "ok" : "failed";
2211
+ if (agent === "codex") attempt.codexInstallReason = reason ?? null;
2312
2212
  }
2313
2213
  });
2314
2214
  attempt.harnesses = harnessesFound(current);
@@ -2375,10 +2275,10 @@ async function prepareAgents(found, forced, workstation, deps) {
2375
2275
  let current = found;
2376
2276
  const say = (line2) => out(`${bold("Cloop runner")} ${line2}`);
2377
2277
  const chatGptApp = forced !== "claude-code" && deps.chatGptApp();
2378
- const getCodex = async (why) => {
2278
+ const getCodex = async (why, reason) => {
2379
2279
  say(`${why} Installing the latest Codex from ${CODEX_RELEASES}.`);
2380
2280
  const codex = await deps.installCodex() ? await deps.readCodex() : null;
2381
- deps.installed("codex", Boolean(codex));
2281
+ deps.installed("codex", Boolean(codex), reason);
2382
2282
  if (codex) say(`Installed Codex${codex.version ? ` ${codex.version}` : ""}.`);
2383
2283
  else
2384
2284
  out(`${red("\u2717")} Codex did not install. Install it yourself: npm install -g @openai/codex`);
@@ -2386,16 +2286,28 @@ async function prepareAgents(found, forced, workstation, deps) {
2386
2286
  };
2387
2287
  const codexVersion = current.codex?.version;
2388
2288
  if (!current.codex && forced === "codex")
2389
- current = { ...current, codex: await getCodex("Codex is not installed here.") };
2289
+ current = { ...current, codex: await getCodex("Codex is not installed here.", "named") };
2390
2290
  else if (!current.codex && chatGptApp)
2391
2291
  current = {
2392
2292
  ...current,
2393
2293
  codex: await getCodex(
2394
- "The ChatGPT app is here, and Codex signs in with your ChatGPT account."
2294
+ "The ChatGPT app is here, and Codex signs in with your ChatGPT account.",
2295
+ "chatgpt_app"
2395
2296
  )
2396
2297
  };
2397
2298
  else if (current.codex && codexVersion && olderThan(codexVersion, CODEX_FLOOR))
2398
- current = { ...current, codex: await getCodex(codexTooOld(codexVersion)) ?? current.codex };
2299
+ current = {
2300
+ ...current,
2301
+ codex: await getCodex(codexTooOld(codexVersion), "floor") ?? current.codex
2302
+ };
2303
+ else if (current.codex && deps.codexHostMissing())
2304
+ current = {
2305
+ ...current,
2306
+ codex: await getCodex(
2307
+ `This Codex has no ${CODE_MODE_HOST} beside it, so none of its tools can run.`,
2308
+ "host_missing"
2309
+ ) ?? current.codex
2310
+ };
2399
2311
  if (!current.claude && (forced === "claude-code" || !current.codex && forced !== "codex")) {
2400
2312
  say(
2401
2313
  `${current.codex || forced ? "Claude Code is not installed here." : "No coding agent here."} Installing Claude Code with Anthropic's installer.`
@@ -2522,7 +2434,6 @@ async function connectCommand(argv) {
2522
2434
  }
2523
2435
 
2524
2436
  export {
2525
- T3Client,
2526
2437
  runBoxTool,
2527
2438
  probeClaudePermissions,
2528
2439
  probeClaude,