@cloop/runner 0.3.12 → 0.3.13

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,7 +3,7 @@ import {
3
3
  readRunnerState,
4
4
  runnerStatePath,
5
5
  threadsFilePath
6
- } from "./chunk-WRSJZ5WD.js";
6
+ } from "./chunk-VWNTDZE3.js";
7
7
  import {
8
8
  BoxToolError,
9
9
  CLOOP_THREAD_PREFIX,
@@ -31,33 +31,35 @@ import {
31
31
  windowsExecutable,
32
32
  windowsPowerShellEnv,
33
33
  writeBoxConfig
34
- } from "./chunk-GNNGDCKP.js";
34
+ } from "./chunk-QVFCIDR4.js";
35
35
  import {
36
36
  getMachine,
37
37
  shortMachineName
38
38
  } from "./chunk-NTXQLEMQ.js";
39
39
  import {
40
40
  CLAUDE_FLOOR,
41
+ CODEX_FLOOR,
41
42
  claudeTooOld,
43
+ codexTooOld,
42
44
  olderThan
43
- } from "./chunk-UBXT5IDU.js";
45
+ } from "./chunk-YEO27QQP.js";
44
46
  import {
45
47
  READ_TOOLS,
46
48
  readOnlySettings
47
49
  } from "./chunk-R3CLO2FB.js";
48
50
  import {
49
51
  connectWebhook
50
- } from "./chunk-UZYPDPGL.js";
52
+ } from "./chunk-6QPGSWSN.js";
51
53
  import {
52
54
  ConnectFailure,
53
55
  connectReport,
54
56
  deviceLogin,
55
57
  newAttempt,
56
58
  sendConnectReport
57
- } from "./chunk-7SELZL6Z.js";
59
+ } from "./chunk-OK7DODFL.js";
58
60
  import {
59
61
  VERSION
60
- } from "./chunk-6IQ3ABBS.js";
62
+ } from "./chunk-GFAI23T7.js";
61
63
  import {
62
64
  STAGING_ORIGIN,
63
65
  getOrigin,
@@ -69,18 +71,128 @@ import {
69
71
  import { execFileSync as execFileSync2, spawnSync } from "child_process";
70
72
  import { randomUUID } from "crypto";
71
73
  import {
72
- existsSync as existsSync4,
74
+ existsSync as existsSync5,
73
75
  mkdirSync as mkdirSync2,
74
- readdirSync,
76
+ readdirSync as readdirSync2,
75
77
  rmSync as rmSync3,
76
78
  statSync,
77
79
  writeFileSync
78
80
  } from "fs";
79
81
  import { homedir as homedir3, userInfo } from "os";
80
- import { basename as basename4, dirname, join as join2, resolve as resolve2 } from "path";
82
+ import { basename as basename4, dirname, join as join3, resolve as resolve2 } from "path";
81
83
  import { createInterface } from "readline/promises";
82
84
  import { Writable } from "stream";
83
85
 
86
+ // src/agent-install.ts
87
+ import { spawn } from "child_process";
88
+ import { existsSync, readdirSync } from "fs";
89
+ import { delimiter, join, posix, win32 } from "path";
90
+ var CODEX_RELEASES = "https://github.com/openai/codex/releases/latest/download";
91
+ var CODEX_TRIPLES = {
92
+ "darwin-arm64": "aarch64-apple-darwin",
93
+ "darwin-x64": "x86_64-apple-darwin",
94
+ "linux-x64": "x86_64-unknown-linux-musl",
95
+ "linux-arm64": "aarch64-unknown-linux-musl",
96
+ "win32-x64": "x86_64-pc-windows-msvc.exe",
97
+ "win32-arm64": "aarch64-pc-windows-msvc.exe"
98
+ };
99
+ function codexAsset(platform, arch) {
100
+ const triple = CODEX_TRIPLES[`${platform}-${arch}`];
101
+ return triple ? `codex-${triple}` : null;
102
+ }
103
+ var codexBinDir = (home) => join(home, ".cloop", "bin");
104
+ var psQuote = (value) => `'${value.replace(/'/g, "''")}'`;
105
+ function codexInstallCommand(home, platform = process.platform, arch = process.arch) {
106
+ const asset = codexAsset(platform, arch);
107
+ if (!asset) return null;
108
+ const dir = codexBinDir(home);
109
+ const url = `${CODEX_RELEASES}/${asset}.tar.gz`;
110
+ if (platform === "win32")
111
+ return [
112
+ "powershell",
113
+ "-NoProfile",
114
+ "-ExecutionPolicy",
115
+ "Bypass",
116
+ "-Command",
117
+ [
118
+ "$ErrorActionPreference = 'Stop'",
119
+ `$d = ${psQuote(dir)}`,
120
+ "New-Item -ItemType Directory -Force -Path $d | Out-Null",
121
+ "$t = Join-Path ([IO.Path]::GetTempPath()) 'codex.tar.gz'",
122
+ `Invoke-WebRequest -UseBasicParsing ${psQuote(url)} -OutFile $t`,
123
+ "tar.exe -xzf $t -C $d",
124
+ `Move-Item -Force (Join-Path $d ${psQuote(asset)}) (Join-Path $d 'codex.exe')`,
125
+ "Remove-Item -Force $t"
126
+ ].join("; ")
127
+ ];
128
+ return [
129
+ "sh",
130
+ "-c",
131
+ 'mkdir -p "$1" && curl -fsSL "$2" | tar -xz -C "$1" && mv -f "$1/$3" "$1/codex" && chmod 755 "$1/codex"',
132
+ "cloop",
133
+ dir,
134
+ url,
135
+ asset
136
+ ];
137
+ }
138
+ async function installCodex(home, run = runShown) {
139
+ const command = codexInstallCommand(home);
140
+ if (!command || !await run(command)) return false;
141
+ findLocalCodex(home);
142
+ return true;
143
+ }
144
+ function claudeInstallCommand(platform = process.platform) {
145
+ return platform === "win32" ? [
146
+ "powershell",
147
+ "-NoProfile",
148
+ "-ExecutionPolicy",
149
+ "Bypass",
150
+ "-Command",
151
+ "irm https://claude.ai/install.ps1 | iex"
152
+ ] : ["sh", "-c", "curl -fsSL https://claude.ai/install.sh | bash"];
153
+ }
154
+ async function installClaude(home, run = runShown) {
155
+ if (!await run(claudeInstallCommand())) return false;
156
+ findLocalClaude(home);
157
+ return true;
158
+ }
159
+ function runShown(command) {
160
+ return new Promise((done) => {
161
+ const child = spawn(command[0], command.slice(1), {
162
+ stdio: "inherit",
163
+ ...command[0] === "powershell" ? { env: windowsPowerShellEnv() } : {}
164
+ });
165
+ child.on("error", () => done(false));
166
+ child.on("close", (code) => done(code === 0));
167
+ });
168
+ }
169
+ function findIn(folder, name, env) {
170
+ if (!existsSync(join(folder, process.platform === "win32" ? `${name}.exe` : name))) return;
171
+ const parts = (env.PATH ?? "").split(delimiter).filter(Boolean);
172
+ if (parts[0] !== folder)
173
+ env.PATH = [folder, ...parts.filter((part) => part !== folder)].join(delimiter);
174
+ }
175
+ function findLocalCodex(home, env = process.env) {
176
+ findIn(codexBinDir(home), "codex", env);
177
+ }
178
+ function findLocalClaude(home, env = process.env) {
179
+ findIn(join(home, ".local", "bin"), "claude", env);
180
+ }
181
+ var realFs = { exists: existsSync, readdir: (path) => readdirSync(path) };
182
+ function hasChatGptApp(home, platform = process.platform, env = process.env, fs = realFs) {
183
+ try {
184
+ if (platform === "darwin")
185
+ return ["/Applications", posix.join(home, "Applications")].some(
186
+ (dir) => ["ChatGPT", "Codex"].some((name) => fs.exists(posix.join(dir, `${name}.app`)))
187
+ );
188
+ if (platform === "win32" && env.LOCALAPPDATA)
189
+ return fs.readdir(win32.join(env.LOCALAPPDATA, "Packages")).some((name) => /^OpenAI\./i.test(name));
190
+ } catch {
191
+ return false;
192
+ }
193
+ return false;
194
+ }
195
+
84
196
  // src/t3.ts
85
197
  var T3_SCOPE = "orchestration:read orchestration:operate";
86
198
  var MIN_PROTOCOL = 2;
@@ -760,22 +872,22 @@ function codexDialect(bin = "codex") {
760
872
  }
761
873
 
762
874
  // src/legacy-staging.ts
763
- import { existsSync as existsSync3, mkdirSync, renameSync, rmSync as rmSync2 } from "fs";
875
+ import { existsSync as existsSync4, mkdirSync, renameSync, rmSync as rmSync2 } from "fs";
764
876
  import { homedir as homedir2 } from "os";
765
- import { join } from "path";
877
+ import { join as join2 } from "path";
766
878
 
767
879
  // src/commands/disconnect.ts
768
880
  import { execFileSync } from "child_process";
769
- import { existsSync as existsSync2, readFileSync, rmSync } from "fs";
881
+ import { existsSync as existsSync3, readFileSync, rmSync } from "fs";
770
882
  import { homedir } from "os";
771
883
  import { basename as basename3 } from "path";
772
884
 
773
885
  // src/existing-runner.ts
774
- import { existsSync } from "fs";
886
+ import { existsSync as existsSync2 } from "fs";
775
887
  var ALL = Object.keys(ENVIRONMENTS);
776
888
  function runnersOnThisComputer() {
777
889
  if (legacyStagingRunner()) return ["staging"];
778
- return ALL.filter((env) => existsSync(boxPath(env)));
890
+ return ALL.filter((env) => existsSync2(boxPath(env)));
779
891
  }
780
892
  function existingRunnerEnvironment() {
781
893
  const named = process.env.CLOOP_ORIGIN;
@@ -807,7 +919,7 @@ function unitOrigin(contents) {
807
919
  return launcher ? launcher.replace(/%%/g, "%") : null;
808
920
  }
809
921
  function disconnectPlan(opts) {
810
- const exists = opts.exists ?? existsSync2;
922
+ const exists = opts.exists ?? existsSync3;
811
923
  const read = opts.read ?? ((path) => readFileSync(path, "utf-8"));
812
924
  const installed = ["local", "workstation"].map((kind) => ({ kind, service: installedService({ ...opts, kind }) })).filter(({ service }) => exists(service.path));
813
925
  const services = installed.map(({ service }) => service);
@@ -945,16 +1057,16 @@ var MOVED = [
945
1057
  "box.json"
946
1058
  ];
947
1059
  function legacyStagingRunner() {
948
- if (existsSync3(boxPath("staging"))) return false;
1060
+ if (existsSync4(boxPath("staging"))) return false;
949
1061
  const origin = runnerOrigin("production");
950
1062
  return origin !== void 0 && environmentOf(origin) === "staging";
951
1063
  }
952
1064
  function moveRunnerFiles(from, to) {
953
1065
  mkdirSync(to, { recursive: true, mode: 448 });
954
1066
  for (const name of MOVED) {
955
- const source = join(from, name);
956
- const target = join(to, name);
957
- if (existsSync3(source) && !existsSync3(target)) renameSync(source, target);
1067
+ const source = join2(from, name);
1068
+ const target = join2(to, name);
1069
+ if (existsSync4(source) && !existsSync4(target)) renameSync(source, target);
958
1070
  }
959
1071
  }
960
1072
  function legacyServices(platform) {
@@ -967,7 +1079,7 @@ function legacyServices(platform) {
967
1079
  uid: process.getuid?.() ?? 0,
968
1080
  ...process.env.CLOOP_UNIT_DIR ? { dir: process.env.CLOOP_UNIT_DIR } : {}
969
1081
  })
970
- ).filter((service) => existsSync3(service.path));
1082
+ ).filter((service) => existsSync4(service.path));
971
1083
  }
972
1084
  async function moveLegacyStagingRunner(services) {
973
1085
  if (!legacyStagingRunner()) return false;
@@ -1179,7 +1291,7 @@ function isWorkstation(previous, boxServiceInstalled2) {
1179
1291
  return boxServiceInstalled2 || Boolean(previous && !isLocal(previous));
1180
1292
  }
1181
1293
  function boxServiceInstalled() {
1182
- return existsSync4(
1294
+ return existsSync5(
1183
1295
  installedService({
1184
1296
  platform: process.platform,
1185
1297
  kind: "workstation",
@@ -1232,22 +1344,22 @@ function cmdValue(value) {
1232
1344
  function cmdWord(arg) {
1233
1345
  return `"${cmdValue(arg)}"`;
1234
1346
  }
1235
- var psQuote = (value) => `'${value.replace(/'/g, "''")}'`;
1347
+ var psQuote2 = (value) => `'${value.replace(/'/g, "''")}'`;
1236
1348
  function registerTaskScript(task, launcher) {
1237
1349
  return [
1238
1350
  "$ErrorActionPreference = 'Stop'",
1239
1351
  "$user = [Security.Principal.WindowsIdentity]::GetCurrent().Name",
1240
- `$launcher = ${psQuote(launcher)}`,
1352
+ `$launcher = ${psQuote2(launcher)}`,
1241
1353
  [
1242
1354
  "try {",
1243
- `Register-ScheduledTask -TaskName ${psQuote(task)} -Force`,
1355
+ `Register-ScheduledTask -TaskName ${psQuote2(task)} -Force`,
1244
1356
  "-Action (New-ScheduledTaskAction -Execute (Join-Path $env:WINDIR 'System32\\cmd.exe') -Argument ('/d /c ' + [char]34 + $launcher + [char]34))",
1245
1357
  "-Trigger (New-ScheduledTaskTrigger -AtLogOn -User $user)",
1246
1358
  "-Principal (New-ScheduledTaskPrincipal -UserId $user -LogonType Interactive -RunLevel Limited)",
1247
1359
  "-Settings (New-ScheduledTaskSettingsSet -ExecutionTimeLimit ([TimeSpan]::Zero) -MultipleInstances IgnoreNew -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable)",
1248
1360
  "| Out-Null",
1249
1361
  "} catch {",
1250
- `$kept = Get-ScheduledTask -TaskName ${psQuote(task)} -ErrorAction SilentlyContinue;`,
1362
+ `$kept = Get-ScheduledTask -TaskName ${psQuote2(task)} -ErrorAction SilentlyContinue;`,
1251
1363
  "if (-not ($kept.Actions | Where-Object { ($_.Execute + ' ' + $_.Arguments).Contains($launcher) })) { throw }",
1252
1364
  "}"
1253
1365
  ].join(" ")
@@ -1261,8 +1373,8 @@ function programFor(script, node, npx, version) {
1261
1373
  }
1262
1374
  function findNpx() {
1263
1375
  const name = process.platform === "win32" ? "npx.cmd" : "npx";
1264
- const beside = join2(dirname(process.execPath), name);
1265
- return existsSync4(beside) ? beside : which(name);
1376
+ const beside = join3(dirname(process.execPath), name);
1377
+ return existsSync5(beside) ? beside : which(name);
1266
1378
  }
1267
1379
  async function awaitDaemon(since, read = readRunnerState, { timeoutMs = 15e3, pollMs = 500 } = {}) {
1268
1380
  for (let waited = 0; ; waited += pollMs) {
@@ -1299,14 +1411,14 @@ function installedService(opts) {
1299
1411
  const { label, unit, task, file } = serviceIdentity(opts.kind, opts.environment);
1300
1412
  if (opts.platform === "darwin") {
1301
1413
  return {
1302
- path: join2(opts.dir ?? join2(opts.home, "Library", "LaunchAgents"), `${label}.plist`),
1414
+ path: join3(opts.dir ?? join3(opts.home, "Library", "LaunchAgents"), `${label}.plist`),
1303
1415
  steps: [{ command: ["launchctl", "bootout", `gui/${opts.uid}/${label}`], mayFail: true }],
1304
1416
  running: ["launchctl", "print", `gui/${opts.uid}/${label}`]
1305
1417
  };
1306
1418
  }
1307
1419
  if (opts.platform === "win32") {
1308
1420
  return {
1309
- path: join2(opts.dir ?? join2(opts.home, "AppData", "Local", "Cloop"), `${file}.cmd`),
1421
+ path: join3(opts.dir ?? join3(opts.home, "AppData", "Local", "Cloop"), `${file}.cmd`),
1310
1422
  steps: [
1311
1423
  { command: ["schtasks", "/end", "/tn", task], mayFail: true },
1312
1424
  { command: ["schtasks", "/delete", "/tn", task, "/f"], mayFail: true }
@@ -1315,7 +1427,7 @@ function installedService(opts) {
1315
1427
  };
1316
1428
  }
1317
1429
  return {
1318
- path: join2(opts.dir ?? join2(opts.home, ".config", "systemd", "user"), unit),
1430
+ path: join3(opts.dir ?? join3(opts.home, ".config", "systemd", "user"), unit),
1319
1431
  steps: [{ command: ["systemctl", "--user", "disable", "--now", unit], mayFail: true }],
1320
1432
  running: ["systemctl", "--user", "is-active", "--quiet", unit]
1321
1433
  };
@@ -1328,9 +1440,9 @@ function unitFor(opts) {
1328
1440
  kind: opts.kind === "workstation" ? "local" : "workstation"
1329
1441
  });
1330
1442
  if (opts.platform === "darwin") {
1331
- const agents = opts.dir ?? join2(opts.home, "Library", "LaunchAgents");
1332
- const path2 = join2(agents, `${label}.plist`);
1333
- const log = join2(opts.home, "Library", "Logs", `${file}.log`);
1443
+ const agents = opts.dir ?? join3(opts.home, "Library", "LaunchAgents");
1444
+ const path2 = join3(agents, `${label}.plist`);
1445
+ const log = join3(opts.home, "Library", "Logs", `${file}.log`);
1334
1446
  const xml = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1335
1447
  const contents2 = [
1336
1448
  '<?xml version="1.0" encoding="UTF-8"?>',
@@ -1367,9 +1479,9 @@ function unitFor(opts) {
1367
1479
  };
1368
1480
  }
1369
1481
  if (opts.platform === "win32") {
1370
- const dir = opts.dir ?? join2(opts.home, "AppData", "Local", "Cloop");
1371
- const path2 = join2(dir, `${file}.cmd`);
1372
- const log = join2(dir, `${file}.log`);
1482
+ const dir = opts.dir ?? join3(opts.home, "AppData", "Local", "Cloop");
1483
+ const path2 = join3(dir, `${file}.cmd`);
1484
+ const log = join3(dir, `${file}.log`);
1373
1485
  const psLog = log.replace(/'/g, "''");
1374
1486
  const contents2 = [
1375
1487
  "@echo off",
@@ -1408,8 +1520,8 @@ function unitFor(opts) {
1408
1520
  ]
1409
1521
  };
1410
1522
  }
1411
- const units = opts.dir ?? join2(opts.home, ".config", "systemd", "user");
1412
- const path = join2(units, unit);
1523
+ const units = opts.dir ?? join3(opts.home, ".config", "systemd", "user");
1524
+ const path = join3(units, unit);
1413
1525
  const contents = [
1414
1526
  "[Unit]",
1415
1527
  `Description=${task}: answers the Cloop Agent over the mesh`,
@@ -1480,13 +1592,13 @@ function findCheckouts(home, limit = 8) {
1480
1592
  for (const root of CHECKOUT_ROOTS) {
1481
1593
  let entries;
1482
1594
  try {
1483
- entries = readdirSync(join2(home, root), { withFileTypes: true });
1595
+ entries = readdirSync2(join3(home, root), { withFileTypes: true });
1484
1596
  } catch {
1485
1597
  continue;
1486
1598
  }
1487
1599
  for (const entry of entries) {
1488
- const path = join2(home, root, entry.name);
1489
- if (!entry.isDirectory() || !existsSync4(join2(path, ".git"))) continue;
1600
+ const path = join3(home, root, entry.name);
1601
+ if (!entry.isDirectory() || !existsSync5(join3(path, ".git"))) continue;
1490
1602
  found.push({ repo: { label: entry.name, path }, at: lastCommitAt(path) });
1491
1603
  }
1492
1604
  }
@@ -1506,7 +1618,7 @@ function rerunCommand(argv, script = process.argv[1] ?? "") {
1506
1618
  return [base, "connect", ...staging, ...argv].join(" ");
1507
1619
  }
1508
1620
  function workFolder(home) {
1509
- return { label: "Cloop", path: join2(home, "Cloop") };
1621
+ return { label: "Cloop", path: join3(home, "Cloop") };
1510
1622
  }
1511
1623
  function workFolderLine(found, home, argv, terminal) {
1512
1624
  const rerun = rerunCommand(argv.filter((a) => a !== "--ask"));
@@ -1664,7 +1776,7 @@ async function installService(kind, argv, attempt, services = systemServices) {
1664
1776
  uid: process.getuid?.() ?? 0,
1665
1777
  ...process.env.CLOOP_UNIT_DIR ? { dir: process.env.CLOOP_UNIT_DIR } : {}
1666
1778
  });
1667
- mkdirSync2(join2(unit.path, ".."), { recursive: true });
1779
+ mkdirSync2(join3(unit.path, ".."), { recursive: true });
1668
1780
  writeFileSync(unit.path, unit.contents);
1669
1781
  if (argv.includes("--no-start")) {
1670
1782
  out(
@@ -1676,7 +1788,7 @@ async function installService(kind, argv, attempt, services = systemServices) {
1676
1788
  const since = Date.now();
1677
1789
  const run = (command) => void services.run(command);
1678
1790
  try {
1679
- if (existsSync4(unit.retire.path)) {
1791
+ if (existsSync5(unit.retire.path)) {
1680
1792
  out(
1681
1793
  ` This computer has one ${environment} runner, so connect stops and removes ${unit.retire.path}.`
1682
1794
  );
@@ -1906,19 +2018,35 @@ async function connect(argv, attempt, deps = {}) {
1906
2018
  );
1907
2019
  const t3Url = (flag(argv, "--t3-url") ?? DEFAULT_T3_URL).replace(/\/+$/, "");
1908
2020
  const harnessBin = (name) => process.platform === "win32" ? which(name) ?? name : name;
2021
+ findLocalCodex(homedir3());
2022
+ findLocalClaude(homedir3());
2023
+ const readCodex = deps.probes?.codex ?? (() => probeCodex(harnessBin("codex")));
2024
+ const readClaude = deps.probes?.claude ?? (() => probeClaude(harnessBin("claude")));
1909
2025
  const found = await detect(
1910
2026
  deps.probes ?? {
1911
2027
  t3: () => forced && forced !== "t3" ? Promise.resolve(false) : t3Answers(t3Url),
1912
- claude: () => probeClaude(harnessBin("claude")),
1913
- codex: () => probeCodex(harnessBin("codex"))
2028
+ claude: readClaude,
2029
+ codex: readCodex
1914
2030
  }
1915
2031
  );
1916
2032
  attempt.harnesses = harnessesFound(found);
1917
- const current = await claudeAtFloor(found, forced, {
1918
- update: deps.updateClaude ?? updateClaude,
1919
- ask: deps.ask === void 0 ? terminalYesNo() : deps.ask
1920
- });
1921
2033
  const workstation = isWorkstation(previous, boxServiceInstalled());
2034
+ const machine = !deps.probes;
2035
+ const current = await prepareAgents(found, forced, workstation, {
2036
+ chatGptApp: deps.chatGptApp ?? (() => machine && hasChatGptApp(homedir3())),
2037
+ installCodex: deps.installCodex ?? (async () => machine && installCodex(homedir3())),
2038
+ installClaude: deps.installClaude ?? (async () => machine && installClaude(homedir3())),
2039
+ readCodex,
2040
+ readClaude,
2041
+ updateClaude: deps.updateClaude ?? updateClaude,
2042
+ signInCodex: deps.signInCodex ?? (() => signInCodex(harnessBin("codex"))),
2043
+ signInClaude: deps.signInClaude ?? (() => signInClaude(harnessBin("claude"))),
2044
+ terminal: deps.terminal ?? Boolean(process.stdin.isTTY && process.stdout.isTTY),
2045
+ installed: (agent, ok) => {
2046
+ attempt[agent === "codex" ? "codexInstall" : "claudeInstall"] = ok ? "ok" : "failed";
2047
+ }
2048
+ });
2049
+ attempt.harnesses = harnessesFound(current);
1922
2050
  const choice = chooseDriver(current, forced, workstation);
1923
2051
  if (!choice.ok) throw new ConnectFailure(choice.code, choice.line);
1924
2052
  const local = fallbackDriver(current, forced, workstation);
@@ -1929,17 +2057,79 @@ async function connect(argv, attempt, deps = {}) {
1929
2057
  say: (line2) => out(`${bold("Cloop runner")} ${line2}`)
1930
2058
  });
1931
2059
  }
1932
- async function claudeAtFloor(found, forced, deps) {
2060
+ async function prepareAgents(found, forced, workstation, deps) {
2061
+ if (workstation || forced === "t3") return found;
2062
+ let current = found;
2063
+ const say = (line2) => out(`${bold("Cloop runner")} ${line2}`);
2064
+ const chatGptApp = forced !== "claude-code" && deps.chatGptApp();
2065
+ const getCodex = async (why) => {
2066
+ say(`${why} Installing the latest Codex from ${CODEX_RELEASES}.`);
2067
+ const codex = await deps.installCodex() ? await deps.readCodex() : null;
2068
+ deps.installed("codex", Boolean(codex));
2069
+ if (codex) say(`Installed Codex${codex.version ? ` ${codex.version}` : ""}.`);
2070
+ else
2071
+ out(`${red("\u2717")} Codex did not install. Install it yourself: npm install -g @openai/codex`);
2072
+ return codex;
2073
+ };
2074
+ const codexVersion = current.codex?.version;
2075
+ if (!current.codex && forced === "codex")
2076
+ current = { ...current, codex: await getCodex("Codex is not installed here.") };
2077
+ else if (!current.codex && chatGptApp)
2078
+ current = {
2079
+ ...current,
2080
+ codex: await getCodex(
2081
+ "The ChatGPT app is here, and Codex signs in with your ChatGPT account."
2082
+ )
2083
+ };
2084
+ else if (current.codex && codexVersion && olderThan(codexVersion, CODEX_FLOOR))
2085
+ current = { ...current, codex: await getCodex(codexTooOld(codexVersion)) ?? current.codex };
2086
+ if (!current.claude && (forced === "claude-code" || !current.codex && forced !== "codex")) {
2087
+ say(
2088
+ `${current.codex || forced ? "Claude Code is not installed here." : "No coding agent here."} Installing Claude Code with Anthropic's installer.`
2089
+ );
2090
+ const claude = await deps.installClaude() ? await deps.readClaude() : null;
2091
+ deps.installed("claude", Boolean(claude));
2092
+ if (claude) say(`Installed Claude Code ${claude.version}.`);
2093
+ else
2094
+ out(
2095
+ `${red("\u2717")} Claude Code did not install. Install it yourself: https://claude.ai/download`
2096
+ );
2097
+ current = { ...current, claude };
2098
+ }
2099
+ current = await claudeAtFloor(current, forced, deps.updateClaude);
2100
+ if (!deps.terminal) return current;
2101
+ const driver = forced ?? (current.claude?.signedIn ? "claude-code" : current.codex?.signedIn ? "codex" : current.codex && (chatGptApp || !current.claude) ? "codex" : current.claude ? "claude-code" : null);
2102
+ if (driver === "codex" && current.codex && !current.codex.signedIn) {
2103
+ say("Sign in to Codex with your ChatGPT account; your browser opens.");
2104
+ current = { ...current, codex: await deps.signInCodex() ?? current.codex };
2105
+ }
2106
+ if (driver === "claude-code" && current.claude && !current.claude.signedIn) {
2107
+ say("Sign in to Claude Code; your browser opens.");
2108
+ current = { ...current, claude: await deps.signInClaude() ?? current.claude };
2109
+ }
2110
+ return current;
2111
+ }
2112
+ function signInCodex(bin) {
2113
+ const login = runShown2(
2114
+ [bin, "login", ...process.platform === "linux" ? ["--device-auth"] : []],
2115
+ true
2116
+ );
2117
+ return login.status === 0 ? probeCodex(bin) : Promise.resolve(null);
2118
+ }
2119
+ function signInClaude(bin) {
2120
+ return runShown2([bin, "auth", "login"], true).status === 0 ? probeClaude(bin) : Promise.resolve(null);
2121
+ }
2122
+ async function claudeAtFloor(found, forced, update) {
1933
2123
  const version = found.claude?.version;
1934
2124
  const codex = forced === "codex" || !forced && !found.claude?.signedIn && Boolean(found.codex?.signedIn);
1935
2125
  if (!version || codex || !olderThan(version, CLAUDE_FLOOR)) return found;
1936
- const fix = "Run `claude update`, then run `cloop connect` again.";
1937
- const answer = deps.ask ? await deps.ask(`${claudeTooOld(version)} Update it now with \`claude update\`? (Y/n) `) : null;
1938
- if (answer === null || answer.trim() && !isYes(answer))
1939
- throw new ConnectFailure("harness_outdated", `${claudeTooOld(version)} ${fix}`);
1940
- const claude = await deps.update();
2126
+ out(`${bold("Cloop runner")} ${claudeTooOld(version)} Updating it.`);
2127
+ const claude = await update();
1941
2128
  if (!claude?.version || olderThan(claude.version, CLAUDE_FLOOR))
1942
- throw new ConnectFailure("harness_outdated", `Claude Code did not update. ${fix}`);
2129
+ throw new ConnectFailure(
2130
+ "harness_outdated",
2131
+ "Claude Code did not update. Run `claude update`, then run `cloop connect` again."
2132
+ );
1943
2133
  out(`${bold("Cloop runner")} Claude Code updated to ${claude.version}.`);
1944
2134
  return { ...found, claude };
1945
2135
  }
@@ -1953,7 +2143,7 @@ var WINGET_UPDATE = [
1953
2143
  "--accept-source-agreements",
1954
2144
  "--accept-package-agreements"
1955
2145
  ];
1956
- async function updateClaude(run = runShown, probe = probeClaude) {
2146
+ async function updateClaude(run = runShown2, probe = probeClaude) {
1957
2147
  const update = run(["claude", "update"], false);
1958
2148
  if (WINGET_MANAGED.test(update.output)) {
1959
2149
  out(
@@ -1966,7 +2156,7 @@ async function updateClaude(run = runShown, probe = probeClaude) {
1966
2156
  }
1967
2157
  return probe();
1968
2158
  }
1969
- function runShown(command, show) {
2159
+ function runShown2(command, show) {
1970
2160
  const { file, args, windowsVerbatimArguments } = commandFor(
1971
2161
  command[0],
1972
2162
  command.slice(1)
@@ -1979,20 +2169,6 @@ function runShown(command, show) {
1979
2169
  });
1980
2170
  return { status: result.status, output: `${result.stdout ?? ""}${result.stderr ?? ""}` };
1981
2171
  }
1982
- function terminalYesNo() {
1983
- if (!process.stdin.isTTY || !process.stdout.isTTY) return null;
1984
- return async (question) => {
1985
- const prompt = createInterface({ input: process.stdin, output: process.stdout });
1986
- try {
1987
- return await askOrClosed(
1988
- prompt,
1989
- () => new ConnectFailure("harness_outdated", "No answer.")
1990
- )(question);
1991
- } finally {
1992
- prompt.close();
1993
- }
1994
- };
1995
- }
1996
2172
  async function runConnect(argv, deps = {}) {
1997
2173
  pinRunnerEnvironment();
1998
2174
  const environment = runnerEnvironment();
@@ -2085,6 +2261,7 @@ export {
2085
2261
  detect,
2086
2262
  harnessesFound,
2087
2263
  rememberedDriver,
2264
+ prepareAgents,
2088
2265
  claudeAtFloor,
2089
2266
  WINGET_UPDATE,
2090
2267
  updateClaude,
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  RUN_TEXT_MAX,
4
4
  runnerPath
5
- } from "./chunk-GNNGDCKP.js";
5
+ } from "./chunk-QVFCIDR4.js";
6
6
 
7
7
  // src/box-watch.ts
8
8
  import { randomUUID } from "crypto";
@@ -3,6 +3,7 @@
3
3
  // src/floors.ts
4
4
  var NODE_FLOOR = 20;
5
5
  var CLAUDE_FLOOR = "2.1.281";
6
+ var CODEX_FLOOR = "0.160.1";
6
7
  function olderThan(version, floor) {
7
8
  const parts = (v) => v.replace(/^v/, "").split(/[.+-]/).slice(0, 3).map(Number);
8
9
  const have = parts(version);
@@ -22,10 +23,15 @@ function nodeTooOld(version = process.versions.node) {
22
23
  function claudeTooOld(version) {
23
24
  return `Claude Code ${version} is older than ${CLAUDE_FLOOR}, the version Cloop runs on.`;
24
25
  }
26
+ function codexTooOld(version) {
27
+ return `Codex ${version} is older than ${CODEX_FLOOR}, the version Cloop runs on.`;
28
+ }
25
29
 
26
30
  export {
27
31
  CLAUDE_FLOOR,
32
+ CODEX_FLOOR,
28
33
  olderThan,
29
34
  nodeTooOld,
30
- claudeTooOld
35
+ claudeTooOld,
36
+ codexTooOld
31
37
  };
@@ -29,6 +29,7 @@ import {
29
29
  pairPrompt,
30
30
  pairT3,
31
31
  parsePicks,
32
+ prepareAgents,
32
33
  programFor,
33
34
  registerTaskScript,
34
35
  rememberedDriver,
@@ -49,17 +50,17 @@ import {
49
50
  which,
50
51
  workFolder,
51
52
  workFolderLine
52
- } from "./chunk-JUQALHVZ.js";
53
- import "./chunk-WRSJZ5WD.js";
54
- import "./chunk-GNNGDCKP.js";
53
+ } from "./chunk-T3B3OPMM.js";
54
+ import "./chunk-VWNTDZE3.js";
55
+ import "./chunk-QVFCIDR4.js";
55
56
  import "./chunk-NTXQLEMQ.js";
56
57
  import "./chunk-VK6GV757.js";
57
- import "./chunk-UBXT5IDU.js";
58
+ import "./chunk-YEO27QQP.js";
58
59
  import "./chunk-R3CLO2FB.js";
59
- import "./chunk-UZYPDPGL.js";
60
- import "./chunk-7SELZL6Z.js";
60
+ import "./chunk-6QPGSWSN.js";
61
+ import "./chunk-OK7DODFL.js";
61
62
  import "./chunk-ES5BRAKJ.js";
62
- import "./chunk-6IQ3ABBS.js";
63
+ import "./chunk-GFAI23T7.js";
63
64
  import "./chunk-D5UZW42X.js";
64
65
  export {
65
66
  DEFAULT_T3_URL,
@@ -91,6 +92,7 @@ export {
91
92
  pairPrompt,
92
93
  pairT3,
93
94
  parsePicks,
95
+ prepareAgents,
94
96
  programFor,
95
97
  registerTaskScript,
96
98
  rememberedDriver,
@@ -7,17 +7,17 @@ import {
7
7
  runnerOrigin,
8
8
  stopService,
9
9
  unitOrigin
10
- } from "./chunk-JUQALHVZ.js";
11
- import "./chunk-WRSJZ5WD.js";
12
- import "./chunk-GNNGDCKP.js";
10
+ } from "./chunk-T3B3OPMM.js";
11
+ import "./chunk-VWNTDZE3.js";
12
+ import "./chunk-QVFCIDR4.js";
13
13
  import "./chunk-NTXQLEMQ.js";
14
14
  import "./chunk-VK6GV757.js";
15
- import "./chunk-UBXT5IDU.js";
15
+ import "./chunk-YEO27QQP.js";
16
16
  import "./chunk-R3CLO2FB.js";
17
- import "./chunk-UZYPDPGL.js";
18
- import "./chunk-7SELZL6Z.js";
17
+ import "./chunk-6QPGSWSN.js";
18
+ import "./chunk-OK7DODFL.js";
19
19
  import "./chunk-ES5BRAKJ.js";
20
- import "./chunk-6IQ3ABBS.js";
20
+ import "./chunk-GFAI23T7.js";
21
21
  import "./chunk-D5UZW42X.js";
22
22
  export {
23
23
  disconnect,