@cloop/runner 0.3.12 → 0.3.14
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.
- package/dist/{box-V3CQHA36.js → box-E6SANWEH.js} +9 -9
- package/dist/{chunk-Q4TAV5GV.js → chunk-3J5FFRLN.js} +3 -3
- package/dist/{chunk-JUQALHVZ.js → chunk-5CE6AYV3.js} +279 -77
- package/dist/{chunk-6IQ3ABBS.js → chunk-6OF7Y676.js} +1 -1
- package/dist/{chunk-GNNGDCKP.js → chunk-B2ZI2UWS.js} +236 -189
- package/dist/{chunk-WRSJZ5WD.js → chunk-BGXIAFPO.js} +1 -1
- package/dist/{chunk-7SELZL6Z.js → chunk-EPMOUT5Y.js} +5 -1
- package/dist/{chunk-UZYPDPGL.js → chunk-I726UEFM.js} +1 -1
- package/dist/{chunk-YULXWTUB.js → chunk-NMVZPTFM.js} +1 -1
- package/dist/{chunk-UBXT5IDU.js → chunk-YEO27QQP.js} +7 -1
- package/dist/{connect-XMPA7BZG.js → connect-NPS3USHB.js} +9 -7
- package/dist/{disconnect-ATKLCLYO.js → disconnect-XUT7JS2D.js} +7 -7
- package/dist/{existing-runner-LS2M5OAF.js → existing-runner-IUTBWXDA.js} +7 -7
- package/dist/index.js +15 -15
- package/dist/{login-4ZGAE7QV.js → login-4HWONCHL.js} +2 -2
- package/dist/{mcp-server-4EH6Z5Z3.js → mcp-server-KRQ643F5.js} +1 -1
- package/dist/{runner-7PUTRUFX.js → runner-UVQLEEEP.js} +3 -3
- package/dist/{runs-IVQRNCF5.js → runs-4BKFXNM5.js} +2 -2
- package/dist/{statusline-NDXFVGUT.js → statusline-PXEKVHFD.js} +1 -1
- package/dist/{takeover-3RVPILL7.js → takeover-FCKTVLQY.js} +4 -4
- package/dist/{use-QN3OGZGP.js → use-Z2BUDTNA.js} +7 -7
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
readRunnerState,
|
|
4
4
|
runnerStatePath,
|
|
5
5
|
threadsFilePath
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-BGXIAFPO.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-
|
|
34
|
+
} from "./chunk-B2ZI2UWS.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-
|
|
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-
|
|
52
|
+
} from "./chunk-I726UEFM.js";
|
|
51
53
|
import {
|
|
52
54
|
ConnectFailure,
|
|
53
55
|
connectReport,
|
|
54
56
|
deviceLogin,
|
|
55
57
|
newAttempt,
|
|
56
58
|
sendConnectReport
|
|
57
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-EPMOUT5Y.js";
|
|
58
60
|
import {
|
|
59
61
|
VERSION
|
|
60
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-6OF7Y676.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
|
|
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
|
|
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;
|
|
@@ -659,18 +771,19 @@ function claudeDialect(bin = "claude", fallback = DEFAULT_FALLBACK_MODEL, askEve
|
|
|
659
771
|
// src/drivers/codex.ts
|
|
660
772
|
import { execFile as execFile2 } from "child_process";
|
|
661
773
|
import { basename as basename2 } from "path";
|
|
662
|
-
function exec2(bin, args) {
|
|
774
|
+
function exec2(bin, args, timeout = 1e4) {
|
|
663
775
|
const command = commandFor(bin, args);
|
|
664
776
|
return new Promise(
|
|
665
777
|
(resolve3) => execFile2(
|
|
666
778
|
command.file,
|
|
667
779
|
command.args,
|
|
668
780
|
{
|
|
669
|
-
timeout
|
|
781
|
+
timeout,
|
|
670
782
|
encoding: "utf-8",
|
|
783
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
671
784
|
...command.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}
|
|
672
785
|
},
|
|
673
|
-
(err, out2, errOut) => resolve3({ ok: !err, out: `${out2}${errOut}
|
|
786
|
+
(err, out2, errOut) => resolve3({ ok: !err, out: `${out2}${errOut}`, stdout: out2 })
|
|
674
787
|
)
|
|
675
788
|
);
|
|
676
789
|
}
|
|
@@ -697,6 +810,25 @@ async function probeCodex(bin = "codex") {
|
|
|
697
810
|
experimental: true
|
|
698
811
|
};
|
|
699
812
|
}
|
|
813
|
+
async function codexModels(bin = "codex") {
|
|
814
|
+
const { ok, stdout } = await exec2(bin, ["debug", "models"], 3e4);
|
|
815
|
+
if (!ok) return [];
|
|
816
|
+
try {
|
|
817
|
+
const { models } = JSON.parse(stdout);
|
|
818
|
+
const rank = (m) => typeof m.priority === "number" ? m.priority : Number.POSITIVE_INFINITY;
|
|
819
|
+
return (models ?? []).filter((m) => typeof m.slug === "string" && m.visibility === "list").sort((a, b) => rank(a) - rank(b)).map((m) => m.slug);
|
|
820
|
+
} catch {
|
|
821
|
+
return [];
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
function errorMessage(message) {
|
|
825
|
+
try {
|
|
826
|
+
const inner = JSON.parse(message).error?.message;
|
|
827
|
+
return typeof inner === "string" ? inner : message;
|
|
828
|
+
} catch {
|
|
829
|
+
return message;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
700
832
|
function parseCodexLine(raw) {
|
|
701
833
|
let msg;
|
|
702
834
|
try {
|
|
@@ -732,7 +864,11 @@ function parseCodexLine(raw) {
|
|
|
732
864
|
if (msg.type === "turn.failed") {
|
|
733
865
|
const message = msg.error?.message;
|
|
734
866
|
return [
|
|
735
|
-
{
|
|
867
|
+
{
|
|
868
|
+
type: "result",
|
|
869
|
+
ok: false,
|
|
870
|
+
...typeof message === "string" ? { text: errorMessage(message) } : {}
|
|
871
|
+
}
|
|
736
872
|
];
|
|
737
873
|
}
|
|
738
874
|
return [];
|
|
@@ -752,6 +888,7 @@ function codexDialect(bin = "codex") {
|
|
|
752
888
|
return resume && run.session_id ? ["exec", ...policy, "resume", run.session_id, "--json", ...model, "-"] : ["exec", "--cd", run.repo, "--json", ...policy, ...model, "-"];
|
|
753
889
|
},
|
|
754
890
|
opening: (_run, prompt) => prompt,
|
|
891
|
+
models: () => codexModels(bin),
|
|
755
892
|
parse: parseCodexLine,
|
|
756
893
|
// 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.
|
|
757
894
|
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} `)),
|
|
@@ -760,22 +897,22 @@ function codexDialect(bin = "codex") {
|
|
|
760
897
|
}
|
|
761
898
|
|
|
762
899
|
// src/legacy-staging.ts
|
|
763
|
-
import { existsSync as
|
|
900
|
+
import { existsSync as existsSync4, mkdirSync, renameSync, rmSync as rmSync2 } from "fs";
|
|
764
901
|
import { homedir as homedir2 } from "os";
|
|
765
|
-
import { join } from "path";
|
|
902
|
+
import { join as join2 } from "path";
|
|
766
903
|
|
|
767
904
|
// src/commands/disconnect.ts
|
|
768
905
|
import { execFileSync } from "child_process";
|
|
769
|
-
import { existsSync as
|
|
906
|
+
import { existsSync as existsSync3, readFileSync, rmSync } from "fs";
|
|
770
907
|
import { homedir } from "os";
|
|
771
908
|
import { basename as basename3 } from "path";
|
|
772
909
|
|
|
773
910
|
// src/existing-runner.ts
|
|
774
|
-
import { existsSync } from "fs";
|
|
911
|
+
import { existsSync as existsSync2 } from "fs";
|
|
775
912
|
var ALL = Object.keys(ENVIRONMENTS);
|
|
776
913
|
function runnersOnThisComputer() {
|
|
777
914
|
if (legacyStagingRunner()) return ["staging"];
|
|
778
|
-
return ALL.filter((env) =>
|
|
915
|
+
return ALL.filter((env) => existsSync2(boxPath(env)));
|
|
779
916
|
}
|
|
780
917
|
function existingRunnerEnvironment() {
|
|
781
918
|
const named = process.env.CLOOP_ORIGIN;
|
|
@@ -807,7 +944,7 @@ function unitOrigin(contents) {
|
|
|
807
944
|
return launcher ? launcher.replace(/%%/g, "%") : null;
|
|
808
945
|
}
|
|
809
946
|
function disconnectPlan(opts) {
|
|
810
|
-
const exists = opts.exists ??
|
|
947
|
+
const exists = opts.exists ?? existsSync3;
|
|
811
948
|
const read = opts.read ?? ((path) => readFileSync(path, "utf-8"));
|
|
812
949
|
const installed = ["local", "workstation"].map((kind) => ({ kind, service: installedService({ ...opts, kind }) })).filter(({ service }) => exists(service.path));
|
|
813
950
|
const services = installed.map(({ service }) => service);
|
|
@@ -945,16 +1082,16 @@ var MOVED = [
|
|
|
945
1082
|
"box.json"
|
|
946
1083
|
];
|
|
947
1084
|
function legacyStagingRunner() {
|
|
948
|
-
if (
|
|
1085
|
+
if (existsSync4(boxPath("staging"))) return false;
|
|
949
1086
|
const origin = runnerOrigin("production");
|
|
950
1087
|
return origin !== void 0 && environmentOf(origin) === "staging";
|
|
951
1088
|
}
|
|
952
1089
|
function moveRunnerFiles(from, to) {
|
|
953
1090
|
mkdirSync(to, { recursive: true, mode: 448 });
|
|
954
1091
|
for (const name of MOVED) {
|
|
955
|
-
const source =
|
|
956
|
-
const target =
|
|
957
|
-
if (
|
|
1092
|
+
const source = join2(from, name);
|
|
1093
|
+
const target = join2(to, name);
|
|
1094
|
+
if (existsSync4(source) && !existsSync4(target)) renameSync(source, target);
|
|
958
1095
|
}
|
|
959
1096
|
}
|
|
960
1097
|
function legacyServices(platform) {
|
|
@@ -967,7 +1104,7 @@ function legacyServices(platform) {
|
|
|
967
1104
|
uid: process.getuid?.() ?? 0,
|
|
968
1105
|
...process.env.CLOOP_UNIT_DIR ? { dir: process.env.CLOOP_UNIT_DIR } : {}
|
|
969
1106
|
})
|
|
970
|
-
).filter((service) =>
|
|
1107
|
+
).filter((service) => existsSync4(service.path));
|
|
971
1108
|
}
|
|
972
1109
|
async function moveLegacyStagingRunner(services) {
|
|
973
1110
|
if (!legacyStagingRunner()) return false;
|
|
@@ -1179,7 +1316,7 @@ function isWorkstation(previous, boxServiceInstalled2) {
|
|
|
1179
1316
|
return boxServiceInstalled2 || Boolean(previous && !isLocal(previous));
|
|
1180
1317
|
}
|
|
1181
1318
|
function boxServiceInstalled() {
|
|
1182
|
-
return
|
|
1319
|
+
return existsSync5(
|
|
1183
1320
|
installedService({
|
|
1184
1321
|
platform: process.platform,
|
|
1185
1322
|
kind: "workstation",
|
|
@@ -1232,22 +1369,22 @@ function cmdValue(value) {
|
|
|
1232
1369
|
function cmdWord(arg) {
|
|
1233
1370
|
return `"${cmdValue(arg)}"`;
|
|
1234
1371
|
}
|
|
1235
|
-
var
|
|
1372
|
+
var psQuote2 = (value) => `'${value.replace(/'/g, "''")}'`;
|
|
1236
1373
|
function registerTaskScript(task, launcher) {
|
|
1237
1374
|
return [
|
|
1238
1375
|
"$ErrorActionPreference = 'Stop'",
|
|
1239
1376
|
"$user = [Security.Principal.WindowsIdentity]::GetCurrent().Name",
|
|
1240
|
-
`$launcher = ${
|
|
1377
|
+
`$launcher = ${psQuote2(launcher)}`,
|
|
1241
1378
|
[
|
|
1242
1379
|
"try {",
|
|
1243
|
-
`Register-ScheduledTask -TaskName ${
|
|
1380
|
+
`Register-ScheduledTask -TaskName ${psQuote2(task)} -Force`,
|
|
1244
1381
|
"-Action (New-ScheduledTaskAction -Execute (Join-Path $env:WINDIR 'System32\\cmd.exe') -Argument ('/d /c ' + [char]34 + $launcher + [char]34))",
|
|
1245
1382
|
"-Trigger (New-ScheduledTaskTrigger -AtLogOn -User $user)",
|
|
1246
1383
|
"-Principal (New-ScheduledTaskPrincipal -UserId $user -LogonType Interactive -RunLevel Limited)",
|
|
1247
1384
|
"-Settings (New-ScheduledTaskSettingsSet -ExecutionTimeLimit ([TimeSpan]::Zero) -MultipleInstances IgnoreNew -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable)",
|
|
1248
1385
|
"| Out-Null",
|
|
1249
1386
|
"} catch {",
|
|
1250
|
-
`$kept = Get-ScheduledTask -TaskName ${
|
|
1387
|
+
`$kept = Get-ScheduledTask -TaskName ${psQuote2(task)} -ErrorAction SilentlyContinue;`,
|
|
1251
1388
|
"if (-not ($kept.Actions | Where-Object { ($_.Execute + ' ' + $_.Arguments).Contains($launcher) })) { throw }",
|
|
1252
1389
|
"}"
|
|
1253
1390
|
].join(" ")
|
|
@@ -1261,8 +1398,8 @@ function programFor(script, node, npx, version) {
|
|
|
1261
1398
|
}
|
|
1262
1399
|
function findNpx() {
|
|
1263
1400
|
const name = process.platform === "win32" ? "npx.cmd" : "npx";
|
|
1264
|
-
const beside =
|
|
1265
|
-
return
|
|
1401
|
+
const beside = join3(dirname(process.execPath), name);
|
|
1402
|
+
return existsSync5(beside) ? beside : which(name);
|
|
1266
1403
|
}
|
|
1267
1404
|
async function awaitDaemon(since, read = readRunnerState, { timeoutMs = 15e3, pollMs = 500 } = {}) {
|
|
1268
1405
|
for (let waited = 0; ; waited += pollMs) {
|
|
@@ -1299,14 +1436,14 @@ function installedService(opts) {
|
|
|
1299
1436
|
const { label, unit, task, file } = serviceIdentity(opts.kind, opts.environment);
|
|
1300
1437
|
if (opts.platform === "darwin") {
|
|
1301
1438
|
return {
|
|
1302
|
-
path:
|
|
1439
|
+
path: join3(opts.dir ?? join3(opts.home, "Library", "LaunchAgents"), `${label}.plist`),
|
|
1303
1440
|
steps: [{ command: ["launchctl", "bootout", `gui/${opts.uid}/${label}`], mayFail: true }],
|
|
1304
1441
|
running: ["launchctl", "print", `gui/${opts.uid}/${label}`]
|
|
1305
1442
|
};
|
|
1306
1443
|
}
|
|
1307
1444
|
if (opts.platform === "win32") {
|
|
1308
1445
|
return {
|
|
1309
|
-
path:
|
|
1446
|
+
path: join3(opts.dir ?? join3(opts.home, "AppData", "Local", "Cloop"), `${file}.cmd`),
|
|
1310
1447
|
steps: [
|
|
1311
1448
|
{ command: ["schtasks", "/end", "/tn", task], mayFail: true },
|
|
1312
1449
|
{ command: ["schtasks", "/delete", "/tn", task, "/f"], mayFail: true }
|
|
@@ -1315,7 +1452,7 @@ function installedService(opts) {
|
|
|
1315
1452
|
};
|
|
1316
1453
|
}
|
|
1317
1454
|
return {
|
|
1318
|
-
path:
|
|
1455
|
+
path: join3(opts.dir ?? join3(opts.home, ".config", "systemd", "user"), unit),
|
|
1319
1456
|
steps: [{ command: ["systemctl", "--user", "disable", "--now", unit], mayFail: true }],
|
|
1320
1457
|
running: ["systemctl", "--user", "is-active", "--quiet", unit]
|
|
1321
1458
|
};
|
|
@@ -1328,9 +1465,9 @@ function unitFor(opts) {
|
|
|
1328
1465
|
kind: opts.kind === "workstation" ? "local" : "workstation"
|
|
1329
1466
|
});
|
|
1330
1467
|
if (opts.platform === "darwin") {
|
|
1331
|
-
const agents = opts.dir ??
|
|
1332
|
-
const path2 =
|
|
1333
|
-
const log =
|
|
1468
|
+
const agents = opts.dir ?? join3(opts.home, "Library", "LaunchAgents");
|
|
1469
|
+
const path2 = join3(agents, `${label}.plist`);
|
|
1470
|
+
const log = join3(opts.home, "Library", "Logs", `${file}.log`);
|
|
1334
1471
|
const xml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
1335
1472
|
const contents2 = [
|
|
1336
1473
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
@@ -1367,9 +1504,9 @@ function unitFor(opts) {
|
|
|
1367
1504
|
};
|
|
1368
1505
|
}
|
|
1369
1506
|
if (opts.platform === "win32") {
|
|
1370
|
-
const dir = opts.dir ??
|
|
1371
|
-
const path2 =
|
|
1372
|
-
const log =
|
|
1507
|
+
const dir = opts.dir ?? join3(opts.home, "AppData", "Local", "Cloop");
|
|
1508
|
+
const path2 = join3(dir, `${file}.cmd`);
|
|
1509
|
+
const log = join3(dir, `${file}.log`);
|
|
1373
1510
|
const psLog = log.replace(/'/g, "''");
|
|
1374
1511
|
const contents2 = [
|
|
1375
1512
|
"@echo off",
|
|
@@ -1408,8 +1545,8 @@ function unitFor(opts) {
|
|
|
1408
1545
|
]
|
|
1409
1546
|
};
|
|
1410
1547
|
}
|
|
1411
|
-
const units = opts.dir ??
|
|
1412
|
-
const path =
|
|
1548
|
+
const units = opts.dir ?? join3(opts.home, ".config", "systemd", "user");
|
|
1549
|
+
const path = join3(units, unit);
|
|
1413
1550
|
const contents = [
|
|
1414
1551
|
"[Unit]",
|
|
1415
1552
|
`Description=${task}: answers the Cloop Agent over the mesh`,
|
|
@@ -1480,13 +1617,13 @@ function findCheckouts(home, limit = 8) {
|
|
|
1480
1617
|
for (const root of CHECKOUT_ROOTS) {
|
|
1481
1618
|
let entries;
|
|
1482
1619
|
try {
|
|
1483
|
-
entries =
|
|
1620
|
+
entries = readdirSync2(join3(home, root), { withFileTypes: true });
|
|
1484
1621
|
} catch {
|
|
1485
1622
|
continue;
|
|
1486
1623
|
}
|
|
1487
1624
|
for (const entry of entries) {
|
|
1488
|
-
const path =
|
|
1489
|
-
if (!entry.isDirectory() || !
|
|
1625
|
+
const path = join3(home, root, entry.name);
|
|
1626
|
+
if (!entry.isDirectory() || !existsSync5(join3(path, ".git"))) continue;
|
|
1490
1627
|
found.push({ repo: { label: entry.name, path }, at: lastCommitAt(path) });
|
|
1491
1628
|
}
|
|
1492
1629
|
}
|
|
@@ -1506,7 +1643,7 @@ function rerunCommand(argv, script = process.argv[1] ?? "") {
|
|
|
1506
1643
|
return [base, "connect", ...staging, ...argv].join(" ");
|
|
1507
1644
|
}
|
|
1508
1645
|
function workFolder(home) {
|
|
1509
|
-
return { label: "Cloop", path:
|
|
1646
|
+
return { label: "Cloop", path: join3(home, "Cloop") };
|
|
1510
1647
|
}
|
|
1511
1648
|
function workFolderLine(found, home, argv, terminal) {
|
|
1512
1649
|
const rerun = rerunCommand(argv.filter((a) => a !== "--ask"));
|
|
@@ -1664,7 +1801,7 @@ async function installService(kind, argv, attempt, services = systemServices) {
|
|
|
1664
1801
|
uid: process.getuid?.() ?? 0,
|
|
1665
1802
|
...process.env.CLOOP_UNIT_DIR ? { dir: process.env.CLOOP_UNIT_DIR } : {}
|
|
1666
1803
|
});
|
|
1667
|
-
mkdirSync2(
|
|
1804
|
+
mkdirSync2(join3(unit.path, ".."), { recursive: true });
|
|
1668
1805
|
writeFileSync(unit.path, unit.contents);
|
|
1669
1806
|
if (argv.includes("--no-start")) {
|
|
1670
1807
|
out(
|
|
@@ -1676,7 +1813,7 @@ async function installService(kind, argv, attempt, services = systemServices) {
|
|
|
1676
1813
|
const since = Date.now();
|
|
1677
1814
|
const run = (command) => void services.run(command);
|
|
1678
1815
|
try {
|
|
1679
|
-
if (
|
|
1816
|
+
if (existsSync5(unit.retire.path)) {
|
|
1680
1817
|
out(
|
|
1681
1818
|
` This computer has one ${environment} runner, so connect stops and removes ${unit.retire.path}.`
|
|
1682
1819
|
);
|
|
@@ -1906,19 +2043,35 @@ async function connect(argv, attempt, deps = {}) {
|
|
|
1906
2043
|
);
|
|
1907
2044
|
const t3Url = (flag(argv, "--t3-url") ?? DEFAULT_T3_URL).replace(/\/+$/, "");
|
|
1908
2045
|
const harnessBin = (name) => process.platform === "win32" ? which(name) ?? name : name;
|
|
2046
|
+
findLocalCodex(homedir3());
|
|
2047
|
+
findLocalClaude(homedir3());
|
|
2048
|
+
const readCodex = deps.probes?.codex ?? (() => probeCodex(harnessBin("codex")));
|
|
2049
|
+
const readClaude = deps.probes?.claude ?? (() => probeClaude(harnessBin("claude")));
|
|
1909
2050
|
const found = await detect(
|
|
1910
2051
|
deps.probes ?? {
|
|
1911
2052
|
t3: () => forced && forced !== "t3" ? Promise.resolve(false) : t3Answers(t3Url),
|
|
1912
|
-
claude:
|
|
1913
|
-
codex:
|
|
2053
|
+
claude: readClaude,
|
|
2054
|
+
codex: readCodex
|
|
1914
2055
|
}
|
|
1915
2056
|
);
|
|
1916
2057
|
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
2058
|
const workstation = isWorkstation(previous, boxServiceInstalled());
|
|
2059
|
+
const machine = !deps.probes;
|
|
2060
|
+
const current = await prepareAgents(found, forced, workstation, {
|
|
2061
|
+
chatGptApp: deps.chatGptApp ?? (() => machine && hasChatGptApp(homedir3())),
|
|
2062
|
+
installCodex: deps.installCodex ?? (async () => machine && installCodex(homedir3())),
|
|
2063
|
+
installClaude: deps.installClaude ?? (async () => machine && installClaude(homedir3())),
|
|
2064
|
+
readCodex,
|
|
2065
|
+
readClaude,
|
|
2066
|
+
updateClaude: deps.updateClaude ?? updateClaude,
|
|
2067
|
+
signInCodex: deps.signInCodex ?? (() => signInCodex(harnessBin("codex"))),
|
|
2068
|
+
signInClaude: deps.signInClaude ?? (() => signInClaude(harnessBin("claude"))),
|
|
2069
|
+
terminal: deps.terminal ?? Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
2070
|
+
installed: (agent, ok) => {
|
|
2071
|
+
attempt[agent === "codex" ? "codexInstall" : "claudeInstall"] = ok ? "ok" : "failed";
|
|
2072
|
+
}
|
|
2073
|
+
});
|
|
2074
|
+
attempt.harnesses = harnessesFound(current);
|
|
1922
2075
|
const choice = chooseDriver(current, forced, workstation);
|
|
1923
2076
|
if (!choice.ok) throw new ConnectFailure(choice.code, choice.line);
|
|
1924
2077
|
const local = fallbackDriver(current, forced, workstation);
|
|
@@ -1929,17 +2082,79 @@ async function connect(argv, attempt, deps = {}) {
|
|
|
1929
2082
|
say: (line2) => out(`${bold("Cloop runner")} ${line2}`)
|
|
1930
2083
|
});
|
|
1931
2084
|
}
|
|
1932
|
-
async function
|
|
2085
|
+
async function prepareAgents(found, forced, workstation, deps) {
|
|
2086
|
+
if (workstation || forced === "t3") return found;
|
|
2087
|
+
let current = found;
|
|
2088
|
+
const say = (line2) => out(`${bold("Cloop runner")} ${line2}`);
|
|
2089
|
+
const chatGptApp = forced !== "claude-code" && deps.chatGptApp();
|
|
2090
|
+
const getCodex = async (why) => {
|
|
2091
|
+
say(`${why} Installing the latest Codex from ${CODEX_RELEASES}.`);
|
|
2092
|
+
const codex = await deps.installCodex() ? await deps.readCodex() : null;
|
|
2093
|
+
deps.installed("codex", Boolean(codex));
|
|
2094
|
+
if (codex) say(`Installed Codex${codex.version ? ` ${codex.version}` : ""}.`);
|
|
2095
|
+
else
|
|
2096
|
+
out(`${red("\u2717")} Codex did not install. Install it yourself: npm install -g @openai/codex`);
|
|
2097
|
+
return codex;
|
|
2098
|
+
};
|
|
2099
|
+
const codexVersion = current.codex?.version;
|
|
2100
|
+
if (!current.codex && forced === "codex")
|
|
2101
|
+
current = { ...current, codex: await getCodex("Codex is not installed here.") };
|
|
2102
|
+
else if (!current.codex && chatGptApp)
|
|
2103
|
+
current = {
|
|
2104
|
+
...current,
|
|
2105
|
+
codex: await getCodex(
|
|
2106
|
+
"The ChatGPT app is here, and Codex signs in with your ChatGPT account."
|
|
2107
|
+
)
|
|
2108
|
+
};
|
|
2109
|
+
else if (current.codex && codexVersion && olderThan(codexVersion, CODEX_FLOOR))
|
|
2110
|
+
current = { ...current, codex: await getCodex(codexTooOld(codexVersion)) ?? current.codex };
|
|
2111
|
+
if (!current.claude && (forced === "claude-code" || !current.codex && forced !== "codex")) {
|
|
2112
|
+
say(
|
|
2113
|
+
`${current.codex || forced ? "Claude Code is not installed here." : "No coding agent here."} Installing Claude Code with Anthropic's installer.`
|
|
2114
|
+
);
|
|
2115
|
+
const claude = await deps.installClaude() ? await deps.readClaude() : null;
|
|
2116
|
+
deps.installed("claude", Boolean(claude));
|
|
2117
|
+
if (claude) say(`Installed Claude Code ${claude.version}.`);
|
|
2118
|
+
else
|
|
2119
|
+
out(
|
|
2120
|
+
`${red("\u2717")} Claude Code did not install. Install it yourself: https://claude.ai/download`
|
|
2121
|
+
);
|
|
2122
|
+
current = { ...current, claude };
|
|
2123
|
+
}
|
|
2124
|
+
current = await claudeAtFloor(current, forced, deps.updateClaude);
|
|
2125
|
+
if (!deps.terminal) return current;
|
|
2126
|
+
const driver = forced ?? (current.claude?.signedIn ? "claude-code" : current.codex?.signedIn ? "codex" : current.codex && (chatGptApp || !current.claude) ? "codex" : current.claude ? "claude-code" : null);
|
|
2127
|
+
if (driver === "codex" && current.codex && !current.codex.signedIn) {
|
|
2128
|
+
say("Sign in to Codex with your ChatGPT account; your browser opens.");
|
|
2129
|
+
current = { ...current, codex: await deps.signInCodex() ?? current.codex };
|
|
2130
|
+
}
|
|
2131
|
+
if (driver === "claude-code" && current.claude && !current.claude.signedIn) {
|
|
2132
|
+
say("Sign in to Claude Code; your browser opens.");
|
|
2133
|
+
current = { ...current, claude: await deps.signInClaude() ?? current.claude };
|
|
2134
|
+
}
|
|
2135
|
+
return current;
|
|
2136
|
+
}
|
|
2137
|
+
function signInCodex(bin) {
|
|
2138
|
+
const login = runShown2(
|
|
2139
|
+
[bin, "login", ...process.platform === "linux" ? ["--device-auth"] : []],
|
|
2140
|
+
true
|
|
2141
|
+
);
|
|
2142
|
+
return login.status === 0 ? probeCodex(bin) : Promise.resolve(null);
|
|
2143
|
+
}
|
|
2144
|
+
function signInClaude(bin) {
|
|
2145
|
+
return runShown2([bin, "auth", "login"], true).status === 0 ? probeClaude(bin) : Promise.resolve(null);
|
|
2146
|
+
}
|
|
2147
|
+
async function claudeAtFloor(found, forced, update) {
|
|
1933
2148
|
const version = found.claude?.version;
|
|
1934
2149
|
const codex = forced === "codex" || !forced && !found.claude?.signedIn && Boolean(found.codex?.signedIn);
|
|
1935
2150
|
if (!version || codex || !olderThan(version, CLAUDE_FLOOR)) return found;
|
|
1936
|
-
|
|
1937
|
-
const
|
|
1938
|
-
if (answer === null || answer.trim() && !isYes(answer))
|
|
1939
|
-
throw new ConnectFailure("harness_outdated", `${claudeTooOld(version)} ${fix}`);
|
|
1940
|
-
const claude = await deps.update();
|
|
2151
|
+
out(`${bold("Cloop runner")} ${claudeTooOld(version)} Updating it.`);
|
|
2152
|
+
const claude = await update();
|
|
1941
2153
|
if (!claude?.version || olderThan(claude.version, CLAUDE_FLOOR))
|
|
1942
|
-
throw new ConnectFailure(
|
|
2154
|
+
throw new ConnectFailure(
|
|
2155
|
+
"harness_outdated",
|
|
2156
|
+
"Claude Code did not update. Run `claude update`, then run `cloop connect` again."
|
|
2157
|
+
);
|
|
1943
2158
|
out(`${bold("Cloop runner")} Claude Code updated to ${claude.version}.`);
|
|
1944
2159
|
return { ...found, claude };
|
|
1945
2160
|
}
|
|
@@ -1953,7 +2168,7 @@ var WINGET_UPDATE = [
|
|
|
1953
2168
|
"--accept-source-agreements",
|
|
1954
2169
|
"--accept-package-agreements"
|
|
1955
2170
|
];
|
|
1956
|
-
async function updateClaude(run =
|
|
2171
|
+
async function updateClaude(run = runShown2, probe = probeClaude) {
|
|
1957
2172
|
const update = run(["claude", "update"], false);
|
|
1958
2173
|
if (WINGET_MANAGED.test(update.output)) {
|
|
1959
2174
|
out(
|
|
@@ -1966,7 +2181,7 @@ async function updateClaude(run = runShown, probe = probeClaude) {
|
|
|
1966
2181
|
}
|
|
1967
2182
|
return probe();
|
|
1968
2183
|
}
|
|
1969
|
-
function
|
|
2184
|
+
function runShown2(command, show) {
|
|
1970
2185
|
const { file, args, windowsVerbatimArguments } = commandFor(
|
|
1971
2186
|
command[0],
|
|
1972
2187
|
command.slice(1)
|
|
@@ -1979,20 +2194,6 @@ function runShown(command, show) {
|
|
|
1979
2194
|
});
|
|
1980
2195
|
return { status: result.status, output: `${result.stdout ?? ""}${result.stderr ?? ""}` };
|
|
1981
2196
|
}
|
|
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
2197
|
async function runConnect(argv, deps = {}) {
|
|
1997
2198
|
pinRunnerEnvironment();
|
|
1998
2199
|
const environment = runnerEnvironment();
|
|
@@ -2085,6 +2286,7 @@ export {
|
|
|
2085
2286
|
detect,
|
|
2086
2287
|
harnessesFound,
|
|
2087
2288
|
rememberedDriver,
|
|
2289
|
+
prepareAgents,
|
|
2088
2290
|
claudeAtFloor,
|
|
2089
2291
|
WINGET_UPDATE,
|
|
2090
2292
|
updateClaude,
|