@cloop/runner 0.3.7 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{box-IWMUX74G.js → box-V3DFX5TB.js} +77 -45
- package/dist/{chunk-VYM5NYS6.js → chunk-3SIF2NNR.js} +3 -3
- package/dist/{chunk-EQTFHMUJ.js → chunk-5SUC54R3.js} +11 -10
- package/dist/{chunk-5FZAHWPX.js → chunk-6QXNXJ7C.js} +1 -1
- package/dist/{chunk-QP6ZNGU3.js → chunk-AA2SZUIY.js} +366 -233
- package/dist/{chunk-IKCGVBHA.js → chunk-D5UZW42X.js} +1 -0
- package/dist/{chunk-NYGELUTR.js → chunk-ES5BRAKJ.js} +1 -1
- package/dist/{chunk-E5CKL2Q3.js → chunk-EVIVOEJY.js} +1 -1
- package/dist/{chunk-3IP5XIPV.js → chunk-FNJ74LO3.js} +4 -4
- package/dist/{chunk-5L76PKXT.js → chunk-GPQ2MSET.js} +1 -1
- package/dist/{chunk-NUU4GXGV.js → chunk-NTXQLEMQ.js} +1 -1
- package/dist/{chunk-3WD7S6VI.js → chunk-S3AB7HKD.js} +129 -71
- package/dist/{chunk-3TDL6X5T.js → chunk-TEEFTSXG.js} +1 -1
- package/dist/{chunk-PSUEFPEA.js → chunk-XQZO3UE6.js} +3 -3
- package/dist/{connect-QKQAJECG.js → connect-3IS2XXSU.js} +14 -10
- package/dist/disconnect-IMVUEDIP.js +30 -0
- package/dist/existing-runner-DYL2ZND4.js +20 -0
- package/dist/{hook-activity-I7TV7YG7.js → hook-activity-GAJ5NABA.js} +4 -4
- package/dist/{hook-session-start-MFX6HR3W.js → hook-session-start-DJ6W2NCO.js} +3 -3
- package/dist/index.js +32 -21
- package/dist/{install-EMEZBBK7.js → install-WXKWNTAO.js} +1 -1
- package/dist/{login-3IJKY6EZ.js → login-67UJOSXI.js} +4 -4
- package/dist/{mcp-server-H2DF37BP.js → mcp-server-BQIXVJYD.js} +12 -12
- package/dist/runner-2O56SWXN.js +13 -0
- package/dist/{runs-RZL34AFT.js → runs-CMRLRCTD.js} +3 -3
- package/dist/{statusline-I3MT77CR.js → statusline-G6SQFIVR.js} +3 -3
- package/dist/{takeover-V2IHVUAB.js → takeover-HFQOQTLP.js} +7 -7
- package/dist/{use-PB7RVN6H.js → use-XTJPDK4Y.js} +15 -16
- package/package.json +1 -1
- package/dist/disconnect-5FEZUWJP.js +0 -28
- package/dist/runner-5G4CLAXF.js +0 -13
|
@@ -3,15 +3,18 @@ import {
|
|
|
3
3
|
readRunnerState,
|
|
4
4
|
runnerStatePath,
|
|
5
5
|
threadsFilePath
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-5SUC54R3.js";
|
|
7
7
|
import {
|
|
8
8
|
BoxToolError,
|
|
9
9
|
CLOOP_THREAD_PREFIX,
|
|
10
|
+
ENVIRONMENTS,
|
|
10
11
|
RUNTIME_MODES,
|
|
11
12
|
T3Driver,
|
|
12
13
|
boxPath,
|
|
14
|
+
cloopCommand,
|
|
13
15
|
commandFor,
|
|
14
16
|
defaultT3BinSources,
|
|
17
|
+
environmentOf,
|
|
15
18
|
isLocal,
|
|
16
19
|
isYes,
|
|
17
20
|
localRunsFilePath,
|
|
@@ -20,83 +23,59 @@ import {
|
|
|
20
23
|
questionLine,
|
|
21
24
|
readRunnerConfig,
|
|
22
25
|
runT3,
|
|
26
|
+
runnerDir,
|
|
27
|
+
runnerEnvironment,
|
|
28
|
+
serviceIdentity,
|
|
23
29
|
t3BaseDirArgs,
|
|
24
30
|
t3Candidates,
|
|
25
31
|
writeBoxConfig
|
|
26
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-S3AB7HKD.js";
|
|
33
|
+
import {
|
|
34
|
+
getMachine,
|
|
35
|
+
shortMachineName
|
|
36
|
+
} from "./chunk-NTXQLEMQ.js";
|
|
27
37
|
import {
|
|
28
38
|
CLAUDE_FLOOR,
|
|
29
39
|
claudeTooOld,
|
|
30
40
|
olderThan
|
|
31
41
|
} from "./chunk-UBXT5IDU.js";
|
|
32
|
-
import {
|
|
33
|
-
getMachine,
|
|
34
|
-
shortMachineName
|
|
35
|
-
} from "./chunk-NUU4GXGV.js";
|
|
36
42
|
import {
|
|
37
43
|
READ_TOOLS,
|
|
38
44
|
readOnlySettings
|
|
39
45
|
} from "./chunk-R3CLO2FB.js";
|
|
40
46
|
import {
|
|
41
47
|
connectWebhook
|
|
42
|
-
} from "./chunk-
|
|
48
|
+
} from "./chunk-3SIF2NNR.js";
|
|
43
49
|
import {
|
|
44
50
|
ConnectFailure,
|
|
45
51
|
connectReport,
|
|
46
52
|
deviceLogin,
|
|
47
53
|
newAttempt,
|
|
48
54
|
sendConnectReport
|
|
49
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-XQZO3UE6.js";
|
|
50
56
|
import {
|
|
51
57
|
VERSION
|
|
52
|
-
} from "./chunk-
|
|
58
|
+
} from "./chunk-GPQ2MSET.js";
|
|
53
59
|
import {
|
|
54
60
|
STAGING_ORIGIN,
|
|
55
61
|
getOrigin,
|
|
56
62
|
pinRunnerEnvironment,
|
|
57
63
|
pinnedOriginSource
|
|
58
|
-
} from "./chunk-
|
|
59
|
-
|
|
60
|
-
// src/commands/disconnect.ts
|
|
61
|
-
import { execFileSync as execFileSync2 } from "child_process";
|
|
62
|
-
import { existsSync as existsSync2, readFileSync, rmSync as rmSync2 } from "fs";
|
|
63
|
-
import { homedir as homedir2 } from "os";
|
|
64
|
-
|
|
65
|
-
// src/device-revoke.ts
|
|
66
|
-
function tokenGone(revoke) {
|
|
67
|
-
return revoke === "revoked" || revoke === "already_revoked" || revoke === "no_device";
|
|
68
|
-
}
|
|
69
|
-
async function revokeOwnDevice(origin, deviceToken, fetchFn = fetch) {
|
|
70
|
-
if (!deviceToken) return "no_device";
|
|
71
|
-
try {
|
|
72
|
-
const res = await fetchFn(`${origin}/api/agent/mesh/device-revoke`, {
|
|
73
|
-
method: "POST",
|
|
74
|
-
headers: { authorization: `Bearer ${deviceToken}` },
|
|
75
|
-
signal: AbortSignal.timeout(1e4)
|
|
76
|
-
});
|
|
77
|
-
const body = await res.json().catch(() => null);
|
|
78
|
-
if (res.ok && body?.outcome === "revoked") return "revoked";
|
|
79
|
-
if (res.ok && body?.outcome === "already_revoked") return "already_revoked";
|
|
80
|
-
if (res.status === 401 && body?.error === "unknown_device") return "unknown_device";
|
|
81
|
-
return "failed";
|
|
82
|
-
} catch {
|
|
83
|
-
return "failed";
|
|
84
|
-
}
|
|
85
|
-
}
|
|
64
|
+
} from "./chunk-D5UZW42X.js";
|
|
86
65
|
|
|
87
66
|
// src/commands/connect.ts
|
|
88
|
-
import { execFileSync } from "child_process";
|
|
67
|
+
import { execFileSync as execFileSync2 } from "child_process";
|
|
89
68
|
import { randomUUID } from "crypto";
|
|
90
69
|
import {
|
|
91
|
-
existsSync,
|
|
92
|
-
mkdirSync,
|
|
70
|
+
existsSync as existsSync4,
|
|
71
|
+
mkdirSync as mkdirSync2,
|
|
93
72
|
readdirSync,
|
|
94
|
-
rmSync,
|
|
73
|
+
rmSync as rmSync3,
|
|
95
74
|
statSync,
|
|
96
75
|
writeFileSync
|
|
97
76
|
} from "fs";
|
|
98
|
-
import { homedir, userInfo } from "os";
|
|
99
|
-
import { basename as
|
|
77
|
+
import { homedir as homedir3, userInfo } from "os";
|
|
78
|
+
import { basename as basename4, dirname, join as join2, resolve as resolve2 } from "path";
|
|
100
79
|
import { createInterface } from "readline/promises";
|
|
101
80
|
import { Writable } from "stream";
|
|
102
81
|
|
|
@@ -369,6 +348,28 @@ async function runBoxTool(ctx, tool, args) {
|
|
|
369
348
|
}
|
|
370
349
|
}
|
|
371
350
|
|
|
351
|
+
// src/device-revoke.ts
|
|
352
|
+
function tokenGone(revoke) {
|
|
353
|
+
return revoke === "revoked" || revoke === "already_revoked" || revoke === "no_device";
|
|
354
|
+
}
|
|
355
|
+
async function revokeOwnDevice(origin, deviceToken, fetchFn = fetch) {
|
|
356
|
+
if (!deviceToken) return "no_device";
|
|
357
|
+
try {
|
|
358
|
+
const res = await fetchFn(`${origin}/api/agent/mesh/device-revoke`, {
|
|
359
|
+
method: "POST",
|
|
360
|
+
headers: { authorization: `Bearer ${deviceToken}` },
|
|
361
|
+
signal: AbortSignal.timeout(1e4)
|
|
362
|
+
});
|
|
363
|
+
const body = await res.json().catch(() => null);
|
|
364
|
+
if (res.ok && body?.outcome === "revoked") return "revoked";
|
|
365
|
+
if (res.ok && body?.outcome === "already_revoked") return "already_revoked";
|
|
366
|
+
if (res.status === 401 && body?.error === "unknown_device") return "unknown_device";
|
|
367
|
+
return "failed";
|
|
368
|
+
} catch {
|
|
369
|
+
return "failed";
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
372
373
|
// src/drivers/claude-code.ts
|
|
373
374
|
import { execFile } from "child_process";
|
|
374
375
|
import { basename, isAbsolute, relative, resolve } from "path";
|
|
@@ -756,6 +757,235 @@ function codexDialect(bin = "codex") {
|
|
|
756
757
|
};
|
|
757
758
|
}
|
|
758
759
|
|
|
760
|
+
// src/legacy-staging.ts
|
|
761
|
+
import { existsSync as existsSync3, mkdirSync, renameSync, rmSync as rmSync2 } from "fs";
|
|
762
|
+
import { homedir as homedir2 } from "os";
|
|
763
|
+
import { join } from "path";
|
|
764
|
+
|
|
765
|
+
// src/commands/disconnect.ts
|
|
766
|
+
import { execFileSync } from "child_process";
|
|
767
|
+
import { existsSync as existsSync2, readFileSync, rmSync } from "fs";
|
|
768
|
+
import { homedir } from "os";
|
|
769
|
+
import { basename as basename3 } from "path";
|
|
770
|
+
|
|
771
|
+
// src/existing-runner.ts
|
|
772
|
+
import { existsSync } from "fs";
|
|
773
|
+
var ALL = Object.keys(ENVIRONMENTS);
|
|
774
|
+
function runnersOnThisComputer() {
|
|
775
|
+
if (legacyStagingRunner()) return ["staging"];
|
|
776
|
+
return ALL.filter((env) => existsSync(boxPath(env)));
|
|
777
|
+
}
|
|
778
|
+
function existingRunnerEnvironment() {
|
|
779
|
+
const named = process.env.CLOOP_ORIGIN;
|
|
780
|
+
if (named) return environmentOf(named);
|
|
781
|
+
const found = runnersOnThisComputer();
|
|
782
|
+
return found.length === 1 && found[0] ? found[0] : "production";
|
|
783
|
+
}
|
|
784
|
+
var BOTH_RUNNERS_LINE = "This computer has a production runner and a staging runner. This acts on the production runner. Add --staging for the staging runner.";
|
|
785
|
+
function pinExistingRunner() {
|
|
786
|
+
const named = Boolean(process.env.CLOOP_ORIGIN);
|
|
787
|
+
const environment = existingRunnerEnvironment();
|
|
788
|
+
pinRunnerEnvironment(runnerOrigin(environment) ?? ENVIRONMENTS[environment].origin);
|
|
789
|
+
return {
|
|
790
|
+
environment: runnerEnvironment(),
|
|
791
|
+
note: !named && runnersOnThisComputer().length === ALL.length ? BOTH_RUNNERS_LINE : null
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
// src/commands/disconnect.ts
|
|
796
|
+
function doneLine(env) {
|
|
797
|
+
return `This computer is no longer a ${env} Cloop runner. To connect it again: ${["npx -y @cloop/runner@latest connect", ENVIRONMENTS[env].flag].filter(Boolean).join(" ")}`;
|
|
798
|
+
}
|
|
799
|
+
function unitOrigin(contents) {
|
|
800
|
+
const plist = /<key>CLOOP_ORIGIN<\/key><string>([^<]+)<\/string>/.exec(contents)?.[1];
|
|
801
|
+
if (plist) return plist.replace(/&/g, "&");
|
|
802
|
+
const unit = /Environment="CLOOP_ORIGIN=([^"]+)"/.exec(contents)?.[1];
|
|
803
|
+
if (unit) return unit.replace(/%%/g, "%");
|
|
804
|
+
const launcher = /^set "CLOOP_ORIGIN=(.+)"\r?$/m.exec(contents)?.[1];
|
|
805
|
+
return launcher ? launcher.replace(/%%/g, "%") : null;
|
|
806
|
+
}
|
|
807
|
+
function disconnectPlan(opts) {
|
|
808
|
+
const exists = opts.exists ?? existsSync2;
|
|
809
|
+
const read = opts.read ?? ((path) => readFileSync(path, "utf-8"));
|
|
810
|
+
const installed = ["local", "workstation"].map((kind) => ({ kind, service: installedService({ ...opts, kind }) })).filter(({ service }) => exists(service.path));
|
|
811
|
+
const services = installed.map(({ service }) => service);
|
|
812
|
+
const fromUnit = services.map((service) => {
|
|
813
|
+
try {
|
|
814
|
+
return unitOrigin(read(service.path));
|
|
815
|
+
} catch {
|
|
816
|
+
return null;
|
|
817
|
+
}
|
|
818
|
+
}).find(Boolean);
|
|
819
|
+
return {
|
|
820
|
+
origin: opts.boxOrigin ?? fromUnit ?? opts.fallbackOrigin,
|
|
821
|
+
deviceToken: opts.deviceToken,
|
|
822
|
+
services,
|
|
823
|
+
box: exists(opts.box) ? opts.box : null,
|
|
824
|
+
files: opts.files.filter((file) => exists(file)),
|
|
825
|
+
isBox: opts.platform !== "darwin" && opts.platform !== "win32" && installed.some(({ kind }) => kind === "workstation")
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
async function stopService(service, run, waitMs = 1e4) {
|
|
829
|
+
await runSteps(service.steps, run);
|
|
830
|
+
const until = Date.now() + waitMs;
|
|
831
|
+
for (; ; ) {
|
|
832
|
+
try {
|
|
833
|
+
run(service.running);
|
|
834
|
+
} catch {
|
|
835
|
+
return true;
|
|
836
|
+
}
|
|
837
|
+
if (Date.now() >= until) return false;
|
|
838
|
+
await new Promise((resolve3) => setTimeout(resolve3, 250));
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
function revokeLine(revoke, origin, box) {
|
|
842
|
+
const env = environmentOf(origin);
|
|
843
|
+
const keep = box ? ` Kept ${box}, which holds the device token, so you can try again.` : "";
|
|
844
|
+
switch (revoke) {
|
|
845
|
+
case "revoked":
|
|
846
|
+
return [`Revoked this computer on Cloop (${origin}).`];
|
|
847
|
+
case "already_revoked":
|
|
848
|
+
return [`Cloop (${origin}) had already revoked this computer.`];
|
|
849
|
+
case "no_device":
|
|
850
|
+
return ["No runner device on this computer to revoke."];
|
|
851
|
+
case "unknown_device":
|
|
852
|
+
return [
|
|
853
|
+
`Cloop at ${origin} never issued this computer's device token, so it belongs to the other environment.${keep}`,
|
|
854
|
+
"Run `cloop disconnect --staging` for a staging runner, or `cloop disconnect` for production."
|
|
855
|
+
];
|
|
856
|
+
case "failed":
|
|
857
|
+
return [
|
|
858
|
+
`Could not revoke this computer at ${origin}: Cloop did not answer as expected.${keep}`,
|
|
859
|
+
`Run \`${cloopCommand(env, "disconnect")}\` again when Cloop answers, or press Disconnect on its card on the Threads page and then delete that file.`
|
|
860
|
+
];
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
async function disconnect(plan, opts) {
|
|
864
|
+
const { say } = opts;
|
|
865
|
+
const env = environmentOf(plan.origin);
|
|
866
|
+
const run = opts.run ?? ((command) => void execFileSync(command[0], command.slice(1), {
|
|
867
|
+
stdio: "ignore",
|
|
868
|
+
timeout: 15e3
|
|
869
|
+
}));
|
|
870
|
+
if (plan.isBox && !opts.yes) {
|
|
871
|
+
const unit = plan.services.map((s) => basename3(s.path)).find((n) => n.startsWith("cloop-box"));
|
|
872
|
+
say(`This computer runs ${unit}, the ${env} Cloop box with T3 Code. Disconnect would:`);
|
|
873
|
+
for (const s of plan.services) say(` stop and remove ${s.path}`);
|
|
874
|
+
if (plan.deviceToken) say(` revoke its runner device on Cloop (${plan.origin})`);
|
|
875
|
+
for (const f of [...plan.box ? [plan.box] : [], ...plan.files]) say(` delete ${f}`);
|
|
876
|
+
say(`Run \`${cloopCommand(env, "disconnect --yes")}\` to do this.`);
|
|
877
|
+
return 1;
|
|
878
|
+
}
|
|
879
|
+
for (const service of plan.services) {
|
|
880
|
+
if (!await stopService(service, run, opts.stopWaitMs)) {
|
|
881
|
+
say(
|
|
882
|
+
`Could not stop the service in ${service.path}. Nothing was removed. Stop it with \`${service.steps.map((s) => s.command.join(" ")).join(" && ")}\`, then run \`${cloopCommand(env, "disconnect")}\` again.`
|
|
883
|
+
);
|
|
884
|
+
return 1;
|
|
885
|
+
}
|
|
886
|
+
say(`Stopped the service in ${service.path}`);
|
|
887
|
+
}
|
|
888
|
+
const revoked = await opts.revoke(plan.origin, plan.deviceToken);
|
|
889
|
+
const gone = tokenGone(revoked);
|
|
890
|
+
for (const service of plan.services) {
|
|
891
|
+
rmSync(service.path, { force: true });
|
|
892
|
+
say(`Removed ${service.path}`);
|
|
893
|
+
}
|
|
894
|
+
for (const file of [...gone && plan.box ? [plan.box] : [], ...plan.files]) {
|
|
895
|
+
rmSync(file, { force: true });
|
|
896
|
+
say(`Deleted ${file}`);
|
|
897
|
+
}
|
|
898
|
+
for (const line2 of revokeLine(revoked, plan.origin, plan.box)) say(line2);
|
|
899
|
+
if (!gone) return 1;
|
|
900
|
+
say(doneLine(env));
|
|
901
|
+
return 0;
|
|
902
|
+
}
|
|
903
|
+
function runnerOrigin(env) {
|
|
904
|
+
return disconnectPlan(thisComputer(env, "")).origin || void 0;
|
|
905
|
+
}
|
|
906
|
+
function thisComputer(env, fallbackOrigin) {
|
|
907
|
+
const cfg = readRunnerConfig(env);
|
|
908
|
+
return {
|
|
909
|
+
platform: process.platform,
|
|
910
|
+
environment: env,
|
|
911
|
+
home: homedir(),
|
|
912
|
+
uid: process.getuid?.() ?? 0,
|
|
913
|
+
...process.env.CLOOP_UNIT_DIR ? { dir: process.env.CLOOP_UNIT_DIR } : {},
|
|
914
|
+
box: boxPath(env),
|
|
915
|
+
deviceToken: cfg?.deviceToken ?? null,
|
|
916
|
+
...cfg?.origin ? { boxOrigin: cfg.origin } : {},
|
|
917
|
+
fallbackOrigin,
|
|
918
|
+
files: [localRunsFilePath(env), runnerStatePath(env), threadsFilePath(env)]
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
async function disconnectCommand(argv) {
|
|
922
|
+
const { environment, note } = pinExistingRunner();
|
|
923
|
+
if (note) console.log(note);
|
|
924
|
+
const plan = disconnectPlan(
|
|
925
|
+
thisComputer(legacyStagingRunner() ? "production" : environment, getOrigin())
|
|
926
|
+
);
|
|
927
|
+
process.exitCode = await disconnect(plan, {
|
|
928
|
+
yes: argv.includes("--yes"),
|
|
929
|
+
revoke: (origin, token) => revokeOwnDevice(origin, token),
|
|
930
|
+
say: (line2) => console.log(line2)
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
// src/legacy-staging.ts
|
|
935
|
+
var MOVED = [
|
|
936
|
+
"box-threads.json",
|
|
937
|
+
"runner-state.json",
|
|
938
|
+
"local-runs.json",
|
|
939
|
+
"runs",
|
|
940
|
+
"takeover",
|
|
941
|
+
"update.json",
|
|
942
|
+
"update.log",
|
|
943
|
+
"box.json"
|
|
944
|
+
];
|
|
945
|
+
function legacyStagingRunner() {
|
|
946
|
+
if (existsSync3(boxPath("staging"))) return false;
|
|
947
|
+
const origin = runnerOrigin("production");
|
|
948
|
+
return origin !== void 0 && environmentOf(origin) === "staging";
|
|
949
|
+
}
|
|
950
|
+
function moveRunnerFiles(from, to) {
|
|
951
|
+
mkdirSync(to, { recursive: true, mode: 448 });
|
|
952
|
+
for (const name of MOVED) {
|
|
953
|
+
const source = join(from, name);
|
|
954
|
+
const target = join(to, name);
|
|
955
|
+
if (existsSync3(source) && !existsSync3(target)) renameSync(source, target);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
function legacyServices(platform) {
|
|
959
|
+
return ["local", "workstation"].map(
|
|
960
|
+
(kind) => installedService({
|
|
961
|
+
platform,
|
|
962
|
+
kind,
|
|
963
|
+
environment: "production",
|
|
964
|
+
home: homedir2(),
|
|
965
|
+
uid: process.getuid?.() ?? 0,
|
|
966
|
+
...process.env.CLOOP_UNIT_DIR ? { dir: process.env.CLOOP_UNIT_DIR } : {}
|
|
967
|
+
})
|
|
968
|
+
).filter((service) => existsSync3(service.path));
|
|
969
|
+
}
|
|
970
|
+
async function moveLegacyStagingRunner(services) {
|
|
971
|
+
if (!legacyStagingRunner()) return false;
|
|
972
|
+
const run = (command) => void services.run(command);
|
|
973
|
+
const units = legacyServices(services.platform);
|
|
974
|
+
for (const unit of units)
|
|
975
|
+
if (!await stopService(unit, run))
|
|
976
|
+
throw new Error(
|
|
977
|
+
`Could not stop the staging runner in ${unit.path}. Stop it with \`${unit.steps.map((s) => s.command.join(" ")).join(" && ")}\`, then run this again.`
|
|
978
|
+
);
|
|
979
|
+
for (const unit of units) rmSync2(unit.path, { force: true });
|
|
980
|
+
moveRunnerFiles(runnerDir("production"), runnerDir("staging"));
|
|
981
|
+
console.error("[runner:environment] moved staging runner from ~/.cloop to ~/.cloop/staging");
|
|
982
|
+
return true;
|
|
983
|
+
}
|
|
984
|
+
function movedLine(connecting) {
|
|
985
|
+
const line2 = "Moved the staging runner from ~/.cloop to ~/.cloop/staging, so a production runner can run beside it.";
|
|
986
|
+
return connecting === "staging" ? line2 : `${line2} It is stopped. Start it again with: cloop connect --staging`;
|
|
987
|
+
}
|
|
988
|
+
|
|
759
989
|
// src/t3-pair-link.ts
|
|
760
990
|
var CODE = /^[A-Za-z0-9_-]{8,256}$/;
|
|
761
991
|
function tokenOf(url) {
|
|
@@ -799,14 +1029,14 @@ function which(bin) {
|
|
|
799
1029
|
}
|
|
800
1030
|
function whichPosix(bin) {
|
|
801
1031
|
try {
|
|
802
|
-
return
|
|
1032
|
+
return execFileSync2("which", [bin], { encoding: "utf-8", env: CLEAN_ENV }).trim() || null;
|
|
803
1033
|
} catch {
|
|
804
1034
|
return null;
|
|
805
1035
|
}
|
|
806
1036
|
}
|
|
807
1037
|
function where(bin) {
|
|
808
1038
|
try {
|
|
809
|
-
const found =
|
|
1039
|
+
const found = execFileSync2("where", [bin], {
|
|
810
1040
|
encoding: "utf-8",
|
|
811
1041
|
// `where` matches extensions through PATHEXT, which CLEAN_ENV alone drops.
|
|
812
1042
|
env: { ...CLEAN_ENV, PATHEXT: process.env.PATHEXT, SystemRoot: process.env.SystemRoot }
|
|
@@ -847,7 +1077,7 @@ function boxSession(t3Url, t3Bin, env, token) {
|
|
|
847
1077
|
}
|
|
848
1078
|
async function mintSession(t3Url, opts = {}) {
|
|
849
1079
|
const env = await workstationEnvironment(t3Url, opts.fetchFn);
|
|
850
|
-
const sources = opts.sources ?? defaultT3BinSources(
|
|
1080
|
+
const sources = opts.sources ?? defaultT3BinSources(homedir3(), opts.stored);
|
|
851
1081
|
try {
|
|
852
1082
|
const t3Bin = opts.bin ?? pickT3Bin(t3Candidates(env.serverVersion, sources), env.serverVersion);
|
|
853
1083
|
if (!t3Bin) throw new Error("no t3 binary found; pass --t3-bin or set T3_BIN");
|
|
@@ -964,11 +1194,12 @@ function isWorkstation(previous, boxServiceInstalled2) {
|
|
|
964
1194
|
return boxServiceInstalled2 || Boolean(previous && !isLocal(previous));
|
|
965
1195
|
}
|
|
966
1196
|
function boxServiceInstalled() {
|
|
967
|
-
return
|
|
1197
|
+
return existsSync4(
|
|
968
1198
|
installedService({
|
|
969
1199
|
platform: process.platform,
|
|
970
1200
|
kind: "workstation",
|
|
971
|
-
|
|
1201
|
+
environment: runnerEnvironment(),
|
|
1202
|
+
home: homedir3(),
|
|
972
1203
|
uid: process.getuid?.() ?? 0,
|
|
973
1204
|
...process.env.CLOOP_UNIT_DIR ? { dir: process.env.CLOOP_UNIT_DIR } : {}
|
|
974
1205
|
}).path
|
|
@@ -1024,8 +1255,8 @@ function programFor(script, node, npx, version) {
|
|
|
1024
1255
|
}
|
|
1025
1256
|
function findNpx() {
|
|
1026
1257
|
const name = process.platform === "win32" ? "npx.cmd" : "npx";
|
|
1027
|
-
const beside =
|
|
1028
|
-
return
|
|
1258
|
+
const beside = join2(dirname(process.execPath), name);
|
|
1259
|
+
return existsSync4(beside) ? beside : which(name);
|
|
1029
1260
|
}
|
|
1030
1261
|
async function awaitDaemon(since, read = readRunnerState, { timeoutMs = 15e3, pollMs = 500 } = {}) {
|
|
1031
1262
|
for (let waited = 0; ; waited += pollMs) {
|
|
@@ -1053,20 +1284,22 @@ function unitEnv(env) {
|
|
|
1053
1284
|
}
|
|
1054
1285
|
return picked;
|
|
1055
1286
|
}
|
|
1287
|
+
function serviceEnv(env = process.env) {
|
|
1288
|
+
const origin = getOrigin();
|
|
1289
|
+
return unitEnv({ ...env, CLOOP_ORIGIN: origin, CLOOP_MESH_URL: env.CLOOP_MESH_URL || origin });
|
|
1290
|
+
}
|
|
1056
1291
|
function installedService(opts) {
|
|
1057
|
-
const
|
|
1292
|
+
const { label, unit, task, file } = serviceIdentity(opts.kind, opts.environment);
|
|
1058
1293
|
if (opts.platform === "darwin") {
|
|
1059
|
-
const label = `com.cloop.${name}`;
|
|
1060
1294
|
return {
|
|
1061
|
-
path:
|
|
1295
|
+
path: join2(opts.dir ?? join2(opts.home, "Library", "LaunchAgents"), `${label}.plist`),
|
|
1062
1296
|
steps: [{ command: ["launchctl", "bootout", `gui/${opts.uid}/${label}`], mayFail: true }],
|
|
1063
1297
|
running: ["launchctl", "print", `gui/${opts.uid}/${label}`]
|
|
1064
1298
|
};
|
|
1065
1299
|
}
|
|
1066
1300
|
if (opts.platform === "win32") {
|
|
1067
|
-
const task = name === "box" ? "Cloop Box" : "Cloop Runner";
|
|
1068
1301
|
return {
|
|
1069
|
-
path:
|
|
1302
|
+
path: join2(opts.dir ?? join2(opts.home, "AppData", "Local", "Cloop"), `${file}.cmd`),
|
|
1070
1303
|
steps: [
|
|
1071
1304
|
{ command: ["schtasks", "/end", "/tn", task], mayFail: true },
|
|
1072
1305
|
{ command: ["schtasks", "/delete", "/tn", task, "/f"], mayFail: true }
|
|
@@ -1074,25 +1307,23 @@ function installedService(opts) {
|
|
|
1074
1307
|
running: ["schtasks", "/query", "/tn", task]
|
|
1075
1308
|
};
|
|
1076
1309
|
}
|
|
1077
|
-
const unit = `cloop-${name}.service`;
|
|
1078
1310
|
return {
|
|
1079
|
-
path:
|
|
1311
|
+
path: join2(opts.dir ?? join2(opts.home, ".config", "systemd", "user"), unit),
|
|
1080
1312
|
steps: [{ command: ["systemctl", "--user", "disable", "--now", unit], mayFail: true }],
|
|
1081
1313
|
running: ["systemctl", "--user", "is-active", "--quiet", unit]
|
|
1082
1314
|
};
|
|
1083
1315
|
}
|
|
1084
1316
|
function unitFor(opts) {
|
|
1085
1317
|
const env = Object.entries(opts.env);
|
|
1086
|
-
const
|
|
1318
|
+
const { label, unit, task, file } = serviceIdentity(opts.kind, opts.environment);
|
|
1087
1319
|
const retire = installedService({
|
|
1088
1320
|
...opts,
|
|
1089
1321
|
kind: opts.kind === "workstation" ? "local" : "workstation"
|
|
1090
1322
|
});
|
|
1091
1323
|
if (opts.platform === "darwin") {
|
|
1092
|
-
const
|
|
1093
|
-
const
|
|
1094
|
-
const
|
|
1095
|
-
const log = join(opts.home, "Library", "Logs", `cloop-${name}.log`);
|
|
1324
|
+
const agents = opts.dir ?? join2(opts.home, "Library", "LaunchAgents");
|
|
1325
|
+
const path2 = join2(agents, `${label}.plist`);
|
|
1326
|
+
const log = join2(opts.home, "Library", "Logs", `${file}.log`);
|
|
1096
1327
|
const xml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
1097
1328
|
const contents2 = [
|
|
1098
1329
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
@@ -1129,10 +1360,9 @@ function unitFor(opts) {
|
|
|
1129
1360
|
};
|
|
1130
1361
|
}
|
|
1131
1362
|
if (opts.platform === "win32") {
|
|
1132
|
-
const
|
|
1133
|
-
const
|
|
1134
|
-
const
|
|
1135
|
-
const log = join(dir, `cloop-${name}.log`);
|
|
1363
|
+
const dir = opts.dir ?? join2(opts.home, "AppData", "Local", "Cloop");
|
|
1364
|
+
const path2 = join2(dir, `${file}.cmd`);
|
|
1365
|
+
const log = join2(dir, `${file}.log`);
|
|
1136
1366
|
const psLog = log.replace(/'/g, "''");
|
|
1137
1367
|
const contents2 = [
|
|
1138
1368
|
"@echo off",
|
|
@@ -1187,12 +1417,11 @@ function unitFor(opts) {
|
|
|
1187
1417
|
]
|
|
1188
1418
|
};
|
|
1189
1419
|
}
|
|
1190
|
-
const
|
|
1191
|
-
const
|
|
1192
|
-
const path = join(units, unit);
|
|
1420
|
+
const units = opts.dir ?? join2(opts.home, ".config", "systemd", "user");
|
|
1421
|
+
const path = join2(units, unit);
|
|
1193
1422
|
const contents = [
|
|
1194
1423
|
"[Unit]",
|
|
1195
|
-
`Description
|
|
1424
|
+
`Description=${task}: answers the Cloop Agent over the mesh`,
|
|
1196
1425
|
"After=network-online.target",
|
|
1197
1426
|
// A disconnected runner exits 1 on every start. Three in ten minutes and
|
|
1198
1427
|
// systemd marks the unit failed instead of restarting it forever.
|
|
@@ -1230,7 +1459,7 @@ function resolveRepos(paths, toplevel, isFolder = folderAt) {
|
|
|
1230
1459
|
if (!isFolder(full))
|
|
1231
1460
|
return `${p} is not a folder. Pass --repo <path> for each folder Cloop may work in.`;
|
|
1232
1461
|
const top = toplevel(full) ?? full;
|
|
1233
|
-
if (!repos.some((r) => r.path === top)) repos.push({ label:
|
|
1462
|
+
if (!repos.some((r) => r.path === top)) repos.push({ label: basename4(top), path: top });
|
|
1234
1463
|
}
|
|
1235
1464
|
return repos;
|
|
1236
1465
|
}
|
|
@@ -1245,7 +1474,7 @@ var CHECKOUT_ROOTS = ["projects", "code", "repos", "src", "Developer", "dev", "w
|
|
|
1245
1474
|
function lastCommitAt(path) {
|
|
1246
1475
|
try {
|
|
1247
1476
|
return Number(
|
|
1248
|
-
|
|
1477
|
+
execFileSync2("git", ["-C", path, "log", "-1", "--format=%ct"], {
|
|
1249
1478
|
encoding: "utf-8",
|
|
1250
1479
|
stdio: ["ignore", "pipe", "ignore"],
|
|
1251
1480
|
timeout: 5e3
|
|
@@ -1260,13 +1489,13 @@ function findCheckouts(home, limit = 8) {
|
|
|
1260
1489
|
for (const root of CHECKOUT_ROOTS) {
|
|
1261
1490
|
let entries;
|
|
1262
1491
|
try {
|
|
1263
|
-
entries = readdirSync(
|
|
1492
|
+
entries = readdirSync(join2(home, root), { withFileTypes: true });
|
|
1264
1493
|
} catch {
|
|
1265
1494
|
continue;
|
|
1266
1495
|
}
|
|
1267
1496
|
for (const entry of entries) {
|
|
1268
|
-
const path =
|
|
1269
|
-
if (!entry.isDirectory() || !
|
|
1497
|
+
const path = join2(home, root, entry.name);
|
|
1498
|
+
if (!entry.isDirectory() || !existsSync4(join2(path, ".git"))) continue;
|
|
1270
1499
|
found.push({ repo: { label: entry.name, path }, at: lastCommitAt(path) });
|
|
1271
1500
|
}
|
|
1272
1501
|
}
|
|
@@ -1286,13 +1515,15 @@ function rerunCommand(argv, script = process.argv[1] ?? "") {
|
|
|
1286
1515
|
return [base, "connect", ...staging, ...argv].join(" ");
|
|
1287
1516
|
}
|
|
1288
1517
|
function workFolder(home) {
|
|
1289
|
-
return { label: "Cloop", path:
|
|
1518
|
+
return { label: "Cloop", path: join2(home, "Cloop") };
|
|
1290
1519
|
}
|
|
1291
|
-
function workFolderLine(found, home,
|
|
1520
|
+
function workFolderLine(found, home, argv, terminal) {
|
|
1521
|
+
const rerun = rerunCommand(argv.filter((a) => a !== "--ask"));
|
|
1292
1522
|
const here = `Cloop works in ${tilde(workFolder(home).path, home)}.`;
|
|
1293
1523
|
if (!found.length) return `${here} To let it work in a checkout, run: ${rerun} --repo <path>`;
|
|
1294
1524
|
const list = found.map((r) => `${r.label} (${tilde(r.path, home)})`).join(", ");
|
|
1295
|
-
|
|
1525
|
+
const pick = terminal ? `, or ${rerun} --ask to pick from the list` : "";
|
|
1526
|
+
return `${here} Recent checkouts: ${list}. To let it work in one, run: ${rerun} --repo ${tilde(found[0]?.path ?? "", home)}${pick}.`;
|
|
1296
1527
|
}
|
|
1297
1528
|
async function askRepos(found, home, ask, say) {
|
|
1298
1529
|
const work = workFolder(home);
|
|
@@ -1308,6 +1539,9 @@ async function askRepos(found, home, ask, say) {
|
|
|
1308
1539
|
say(` Type numbers from 1 to ${found.length}, like 1,3, or press Enter.`);
|
|
1309
1540
|
}
|
|
1310
1541
|
}
|
|
1542
|
+
function asksForFolders(argv, found, terminal) {
|
|
1543
|
+
return found.length > 0 && terminal && argv.includes("--ask");
|
|
1544
|
+
}
|
|
1311
1545
|
async function reposFor(argv) {
|
|
1312
1546
|
const given = flags(argv, "--repo");
|
|
1313
1547
|
if (given.length) {
|
|
@@ -1316,12 +1550,13 @@ async function reposFor(argv) {
|
|
|
1316
1550
|
return repos2;
|
|
1317
1551
|
}
|
|
1318
1552
|
const here = gitTop(process.cwd());
|
|
1319
|
-
if (here) return [{ label:
|
|
1320
|
-
const home =
|
|
1553
|
+
if (here) return [{ label: basename4(here), path: here }];
|
|
1554
|
+
const home = homedir3();
|
|
1321
1555
|
const work = workFolder(home);
|
|
1322
1556
|
const found = findCheckouts(home);
|
|
1323
1557
|
let repos = [work];
|
|
1324
|
-
|
|
1558
|
+
const terminal = Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
1559
|
+
if (asksForFolders(argv, found, terminal)) {
|
|
1325
1560
|
const prompt = createInterface({ input: process.stdin, output: process.stdout });
|
|
1326
1561
|
const closed = () => new ConnectFailure(
|
|
1327
1562
|
"no_repo",
|
|
@@ -1332,8 +1567,8 @@ async function reposFor(argv) {
|
|
|
1332
1567
|
} finally {
|
|
1333
1568
|
prompt.close();
|
|
1334
1569
|
}
|
|
1335
|
-
} else out(`${bold("Cloop runner")} ${workFolderLine(found, home,
|
|
1336
|
-
if (repos.some((r) => r.path === work.path))
|
|
1570
|
+
} else out(`${bold("Cloop runner")} ${workFolderLine(found, home, argv, terminal)}`);
|
|
1571
|
+
if (repos.some((r) => r.path === work.path)) mkdirSync2(work.path, { recursive: true });
|
|
1337
1572
|
return repos;
|
|
1338
1573
|
}
|
|
1339
1574
|
function askOrClosed(prompt, closed) {
|
|
@@ -1354,7 +1589,7 @@ function askOrClosed(prompt, closed) {
|
|
|
1354
1589
|
}
|
|
1355
1590
|
function gitTop(path) {
|
|
1356
1591
|
try {
|
|
1357
|
-
return
|
|
1592
|
+
return execFileSync2("git", ["-C", path, "rev-parse", "--show-toplevel"], {
|
|
1358
1593
|
encoding: "utf-8",
|
|
1359
1594
|
stdio: ["ignore", "pipe", "ignore"]
|
|
1360
1595
|
}).trim();
|
|
@@ -1375,7 +1610,7 @@ function harnessLine(h) {
|
|
|
1375
1610
|
const account = h.signedIn ? h.account ?? "signed in" : "signed out";
|
|
1376
1611
|
return `${h.name}${version}, ${account}${h.experimental ? " (experimental)" : ""}`;
|
|
1377
1612
|
}
|
|
1378
|
-
async function runSteps(steps, run = (command) => void
|
|
1613
|
+
async function runSteps(steps, run = (command) => void execFileSync2(command[0], command.slice(1), { stdio: "ignore", timeout: 15e3 }), wait = (ms) => new Promise((r) => setTimeout(r, ms))) {
|
|
1379
1614
|
for (const step of steps) {
|
|
1380
1615
|
const tries = step.tries ?? 1;
|
|
1381
1616
|
for (let attempt = 1; ; attempt++) {
|
|
@@ -1392,7 +1627,7 @@ async function runSteps(steps, run = (command) => void execFileSync(command[0],
|
|
|
1392
1627
|
}
|
|
1393
1628
|
var systemServices = {
|
|
1394
1629
|
platform: process.platform,
|
|
1395
|
-
run: (command) =>
|
|
1630
|
+
run: (command) => execFileSync2(command[0], command.slice(1), {
|
|
1396
1631
|
encoding: "utf-8",
|
|
1397
1632
|
stdio: ["ignore", "pipe", "ignore"],
|
|
1398
1633
|
timeout: 15e3
|
|
@@ -1426,16 +1661,18 @@ async function installService(kind, argv, attempt, services = systemServices) {
|
|
|
1426
1661
|
attempt.step = "service_write";
|
|
1427
1662
|
const program = programFor(process.argv[1] ?? "cloop", process.execPath, findNpx(), VERSION);
|
|
1428
1663
|
if (typeof program === "string") throw new ConnectFailure("npx_missing", program);
|
|
1664
|
+
const environment = runnerEnvironment();
|
|
1429
1665
|
const unit = unitFor({
|
|
1430
1666
|
platform: services.platform,
|
|
1431
1667
|
kind,
|
|
1432
|
-
|
|
1668
|
+
environment,
|
|
1669
|
+
home: homedir3(),
|
|
1433
1670
|
program,
|
|
1434
|
-
env:
|
|
1671
|
+
env: serviceEnv(),
|
|
1435
1672
|
uid: process.getuid?.() ?? 0,
|
|
1436
1673
|
...process.env.CLOOP_UNIT_DIR ? { dir: process.env.CLOOP_UNIT_DIR } : {}
|
|
1437
1674
|
});
|
|
1438
|
-
|
|
1675
|
+
mkdirSync2(join2(unit.path, ".."), { recursive: true });
|
|
1439
1676
|
writeFileSync(unit.path, unit.contents);
|
|
1440
1677
|
if (argv.includes("--no-start")) {
|
|
1441
1678
|
out(
|
|
@@ -1447,10 +1684,12 @@ async function installService(kind, argv, attempt, services = systemServices) {
|
|
|
1447
1684
|
const since = Date.now();
|
|
1448
1685
|
const run = (command) => void services.run(command);
|
|
1449
1686
|
try {
|
|
1450
|
-
if (
|
|
1451
|
-
out(
|
|
1687
|
+
if (existsSync4(unit.retire.path)) {
|
|
1688
|
+
out(
|
|
1689
|
+
` This computer has one ${environment} runner, so connect stops and removes ${unit.retire.path}.`
|
|
1690
|
+
);
|
|
1452
1691
|
await runSteps(unit.retire.steps, run);
|
|
1453
|
-
|
|
1692
|
+
rmSync3(unit.retire.path, { force: true });
|
|
1454
1693
|
}
|
|
1455
1694
|
await runSteps(unit.start, run);
|
|
1456
1695
|
} catch (err) {
|
|
@@ -1488,6 +1727,7 @@ async function installService(kind, argv, attempt, services = systemServices) {
|
|
|
1488
1727
|
out(` Linger: turned on for ${user}, so the runner keeps running after you log out.`);
|
|
1489
1728
|
}
|
|
1490
1729
|
out(` Service: ${unit.path}, started and connected. Logs: ${dim(unit.logs)}`);
|
|
1730
|
+
out(`${bold("Cloop runner")} Connected the ${environment} runner.`);
|
|
1491
1731
|
}
|
|
1492
1732
|
async function connectT3(argv, attempt, fallback, chosen, services) {
|
|
1493
1733
|
const previous = readRunnerConfig();
|
|
@@ -1580,7 +1820,7 @@ async function connectT3(argv, attempt, fallback, chosen, services) {
|
|
|
1580
1820
|
async function connectLocal(driver, found, argv, attempt, chosen, services) {
|
|
1581
1821
|
attempt.step = "repos";
|
|
1582
1822
|
const repos = await reposFor(argv);
|
|
1583
|
-
const work = workFolder(
|
|
1823
|
+
const work = workFolder(homedir3()).path;
|
|
1584
1824
|
attempt.workFolder = repos.every((r) => r.path === work);
|
|
1585
1825
|
const harness = driver === "claude-code" ? found.claude : found.codex;
|
|
1586
1826
|
const bin = which(driver === "claude-code" ? "claude" : "codex") ?? (driver === "claude-code" ? "claude" : "codex");
|
|
@@ -1712,7 +1952,7 @@ async function claudeAtFloor(found, forced, deps) {
|
|
|
1712
1952
|
}
|
|
1713
1953
|
async function updateClaude() {
|
|
1714
1954
|
try {
|
|
1715
|
-
|
|
1955
|
+
execFileSync2("claude", ["update"], { stdio: "inherit", timeout: 3e5 });
|
|
1716
1956
|
} catch {
|
|
1717
1957
|
return null;
|
|
1718
1958
|
}
|
|
@@ -1733,15 +1973,27 @@ function terminalYesNo() {
|
|
|
1733
1973
|
};
|
|
1734
1974
|
}
|
|
1735
1975
|
async function runConnect(argv, deps = {}) {
|
|
1736
|
-
const replacedOrigin = runnerOrigin();
|
|
1737
1976
|
pinRunnerEnvironment();
|
|
1738
|
-
|
|
1739
|
-
`[runner:connect] origin=${getOrigin()} source=${pinnedOriginSource()} replaced_origin=${replacedOrigin ?? "none"}`
|
|
1740
|
-
);
|
|
1977
|
+
const environment = runnerEnvironment();
|
|
1741
1978
|
const attempt = newAttempt();
|
|
1742
|
-
if (replacedOrigin) attempt.replacedOrigin = replacedOrigin;
|
|
1743
1979
|
let error = null;
|
|
1744
1980
|
try {
|
|
1981
|
+
attempt.step = "legacy_move";
|
|
1982
|
+
try {
|
|
1983
|
+
if (await moveLegacyStagingRunner(deps.services ?? systemServices))
|
|
1984
|
+
out(`${bold("Cloop runner")} ${movedLine(environment)}`);
|
|
1985
|
+
} catch (err) {
|
|
1986
|
+
throw new ConnectFailure(
|
|
1987
|
+
"legacy_move_failed",
|
|
1988
|
+
err instanceof Error ? err.message : String(err)
|
|
1989
|
+
);
|
|
1990
|
+
}
|
|
1991
|
+
attempt.step = "detect";
|
|
1992
|
+
const replacedOrigin = runnerOrigin(environment);
|
|
1993
|
+
console.error(
|
|
1994
|
+
`[runner:connect] origin=${getOrigin()} source=${pinnedOriginSource()} replaced_origin=${replacedOrigin ?? "none"}`
|
|
1995
|
+
);
|
|
1996
|
+
if (replacedOrigin) attempt.replacedOrigin = replacedOrigin;
|
|
1745
1997
|
await connect(argv, attempt, deps);
|
|
1746
1998
|
} catch (err) {
|
|
1747
1999
|
error = err instanceof ConnectFailure ? err.code : "unexpected";
|
|
@@ -1759,133 +2011,6 @@ async function connectCommand(argv) {
|
|
|
1759
2011
|
if (await runConnect(argv)) process.exit(1);
|
|
1760
2012
|
}
|
|
1761
2013
|
|
|
1762
|
-
// src/commands/disconnect.ts
|
|
1763
|
-
var DONE_LINE = "This computer is no longer a Cloop runner. To connect it again: npx -y @cloop/runner@latest connect";
|
|
1764
|
-
function unitOrigin(contents) {
|
|
1765
|
-
const plist = /<key>CLOOP_ORIGIN<\/key><string>([^<]+)<\/string>/.exec(contents)?.[1];
|
|
1766
|
-
if (plist) return plist.replace(/&/g, "&");
|
|
1767
|
-
const unit = /Environment="CLOOP_ORIGIN=([^"]+)"/.exec(contents)?.[1];
|
|
1768
|
-
if (unit) return unit.replace(/%%/g, "%");
|
|
1769
|
-
const launcher = /^set "CLOOP_ORIGIN=(.+)"\r?$/m.exec(contents)?.[1];
|
|
1770
|
-
return launcher ? launcher.replace(/%%/g, "%") : null;
|
|
1771
|
-
}
|
|
1772
|
-
function disconnectPlan(opts) {
|
|
1773
|
-
const exists = opts.exists ?? existsSync2;
|
|
1774
|
-
const read = opts.read ?? ((path) => readFileSync(path, "utf-8"));
|
|
1775
|
-
const services = ["local", "workstation"].map((kind) => installedService({ ...opts, kind })).filter((service) => exists(service.path));
|
|
1776
|
-
const fromUnit = services.map((service) => {
|
|
1777
|
-
try {
|
|
1778
|
-
return unitOrigin(read(service.path));
|
|
1779
|
-
} catch {
|
|
1780
|
-
return null;
|
|
1781
|
-
}
|
|
1782
|
-
}).find(Boolean);
|
|
1783
|
-
return {
|
|
1784
|
-
origin: opts.boxOrigin ?? fromUnit ?? opts.fallbackOrigin,
|
|
1785
|
-
deviceToken: opts.deviceToken,
|
|
1786
|
-
services,
|
|
1787
|
-
box: exists(opts.box) ? opts.box : null,
|
|
1788
|
-
files: opts.files.filter((file) => exists(file)),
|
|
1789
|
-
isBox: opts.platform !== "darwin" && services.some((s) => s.path.endsWith("/cloop-box.service"))
|
|
1790
|
-
};
|
|
1791
|
-
}
|
|
1792
|
-
function revokeLine(revoke, origin, box) {
|
|
1793
|
-
const keep = box ? ` Kept ${box}, which holds the device token, so you can try again.` : "";
|
|
1794
|
-
switch (revoke) {
|
|
1795
|
-
case "revoked":
|
|
1796
|
-
return [`Revoked this computer on Cloop (${origin}).`];
|
|
1797
|
-
case "already_revoked":
|
|
1798
|
-
return [`Cloop (${origin}) had already revoked this computer.`];
|
|
1799
|
-
case "no_device":
|
|
1800
|
-
return ["No runner device on this computer to revoke."];
|
|
1801
|
-
case "unknown_device":
|
|
1802
|
-
return [
|
|
1803
|
-
`Cloop at ${origin} never issued this computer's device token, so it belongs to the other environment.${keep}`,
|
|
1804
|
-
"Run `cloop disconnect --staging` for a staging runner, or `cloop disconnect` for production."
|
|
1805
|
-
];
|
|
1806
|
-
case "failed":
|
|
1807
|
-
return [
|
|
1808
|
-
`Could not revoke this computer at ${origin}: Cloop did not answer as expected.${keep}`,
|
|
1809
|
-
"Run `cloop disconnect` again when Cloop answers, or press Disconnect on its card on the Threads page and then delete that file."
|
|
1810
|
-
];
|
|
1811
|
-
}
|
|
1812
|
-
}
|
|
1813
|
-
async function disconnect(plan, opts) {
|
|
1814
|
-
const { say } = opts;
|
|
1815
|
-
const run = opts.run ?? ((command) => void execFileSync2(command[0], command.slice(1), {
|
|
1816
|
-
stdio: "ignore",
|
|
1817
|
-
timeout: 15e3
|
|
1818
|
-
}));
|
|
1819
|
-
if (plan.isBox && !opts.yes) {
|
|
1820
|
-
say("This computer runs cloop-box.service, a Cloop box with T3 Code. Disconnect would:");
|
|
1821
|
-
for (const s of plan.services) say(` stop and remove ${s.path}`);
|
|
1822
|
-
if (plan.deviceToken) say(` revoke its runner device on Cloop (${plan.origin})`);
|
|
1823
|
-
for (const f of [...plan.box ? [plan.box] : [], ...plan.files]) say(` delete ${f}`);
|
|
1824
|
-
say("Run `cloop disconnect --yes` to do this.");
|
|
1825
|
-
return 1;
|
|
1826
|
-
}
|
|
1827
|
-
for (const service of plan.services) {
|
|
1828
|
-
await runSteps(service.steps, run);
|
|
1829
|
-
const stillRunning = async () => {
|
|
1830
|
-
const until = Date.now() + (opts.stopWaitMs ?? 1e4);
|
|
1831
|
-
for (; ; ) {
|
|
1832
|
-
try {
|
|
1833
|
-
run(service.running);
|
|
1834
|
-
} catch {
|
|
1835
|
-
return false;
|
|
1836
|
-
}
|
|
1837
|
-
if (Date.now() >= until) return true;
|
|
1838
|
-
await new Promise((resolve3) => setTimeout(resolve3, 250));
|
|
1839
|
-
}
|
|
1840
|
-
};
|
|
1841
|
-
if (await stillRunning()) {
|
|
1842
|
-
say(
|
|
1843
|
-
`Could not stop the service in ${service.path}. Nothing was removed. Stop it with \`${service.steps.map((s) => s.command.join(" ")).join(" && ")}\`, then run \`cloop disconnect\` again.`
|
|
1844
|
-
);
|
|
1845
|
-
return 1;
|
|
1846
|
-
}
|
|
1847
|
-
say(`Stopped the service in ${service.path}`);
|
|
1848
|
-
}
|
|
1849
|
-
const revoked = await opts.revoke(plan.origin, plan.deviceToken);
|
|
1850
|
-
const gone = tokenGone(revoked);
|
|
1851
|
-
for (const service of plan.services) {
|
|
1852
|
-
rmSync2(service.path, { force: true });
|
|
1853
|
-
say(`Removed ${service.path}`);
|
|
1854
|
-
}
|
|
1855
|
-
for (const file of [...gone && plan.box ? [plan.box] : [], ...plan.files]) {
|
|
1856
|
-
rmSync2(file, { force: true });
|
|
1857
|
-
say(`Deleted ${file}`);
|
|
1858
|
-
}
|
|
1859
|
-
for (const line2 of revokeLine(revoked, plan.origin, plan.box)) say(line2);
|
|
1860
|
-
if (!gone) return 1;
|
|
1861
|
-
say(DONE_LINE);
|
|
1862
|
-
return 0;
|
|
1863
|
-
}
|
|
1864
|
-
function runnerOrigin() {
|
|
1865
|
-
return disconnectPlan(thisComputer(readRunnerConfig(), "")).origin || void 0;
|
|
1866
|
-
}
|
|
1867
|
-
function thisComputer(cfg, fallbackOrigin) {
|
|
1868
|
-
return {
|
|
1869
|
-
platform: process.platform,
|
|
1870
|
-
home: homedir2(),
|
|
1871
|
-
uid: process.getuid?.() ?? 0,
|
|
1872
|
-
...process.env.CLOOP_UNIT_DIR ? { dir: process.env.CLOOP_UNIT_DIR } : {},
|
|
1873
|
-
box: boxPath(),
|
|
1874
|
-
deviceToken: cfg?.deviceToken ?? null,
|
|
1875
|
-
...cfg?.origin ? { boxOrigin: cfg.origin } : {},
|
|
1876
|
-
fallbackOrigin,
|
|
1877
|
-
files: [localRunsFilePath(), runnerStatePath(), threadsFilePath()]
|
|
1878
|
-
};
|
|
1879
|
-
}
|
|
1880
|
-
async function disconnectCommand(argv) {
|
|
1881
|
-
const plan = disconnectPlan(thisComputer(readRunnerConfig(), getOrigin()));
|
|
1882
|
-
process.exitCode = await disconnect(plan, {
|
|
1883
|
-
yes: argv.includes("--yes"),
|
|
1884
|
-
revoke: (origin, token) => revokeOwnDevice(origin, token),
|
|
1885
|
-
say: (line2) => console.log(line2)
|
|
1886
|
-
});
|
|
1887
|
-
}
|
|
1888
|
-
|
|
1889
2014
|
export {
|
|
1890
2015
|
T3Client,
|
|
1891
2016
|
runBoxTool,
|
|
@@ -1895,12 +2020,6 @@ export {
|
|
|
1895
2020
|
claudeDialect,
|
|
1896
2021
|
probeCodex,
|
|
1897
2022
|
codexDialect,
|
|
1898
|
-
DONE_LINE,
|
|
1899
|
-
unitOrigin,
|
|
1900
|
-
disconnectPlan,
|
|
1901
|
-
disconnect,
|
|
1902
|
-
runnerOrigin,
|
|
1903
|
-
disconnectCommand,
|
|
1904
2023
|
DEFAULT_T3_URL,
|
|
1905
2024
|
which,
|
|
1906
2025
|
preferExecutable,
|
|
@@ -1926,6 +2045,7 @@ export {
|
|
|
1926
2045
|
findNpx,
|
|
1927
2046
|
awaitDaemon,
|
|
1928
2047
|
unitEnv,
|
|
2048
|
+
serviceEnv,
|
|
1929
2049
|
installedService,
|
|
1930
2050
|
unitFor,
|
|
1931
2051
|
resolveRepos,
|
|
@@ -1936,6 +2056,7 @@ export {
|
|
|
1936
2056
|
workFolder,
|
|
1937
2057
|
workFolderLine,
|
|
1938
2058
|
askRepos,
|
|
2059
|
+
asksForFolders,
|
|
1939
2060
|
askOrClosed,
|
|
1940
2061
|
runSteps,
|
|
1941
2062
|
systemServices,
|
|
@@ -1945,5 +2066,17 @@ export {
|
|
|
1945
2066
|
rememberedDriver,
|
|
1946
2067
|
claudeAtFloor,
|
|
1947
2068
|
runConnect,
|
|
1948
|
-
connectCommand
|
|
2069
|
+
connectCommand,
|
|
2070
|
+
legacyStagingRunner,
|
|
2071
|
+
moveRunnerFiles,
|
|
2072
|
+
moveLegacyStagingRunner,
|
|
2073
|
+
doneLine,
|
|
2074
|
+
unitOrigin,
|
|
2075
|
+
disconnectPlan,
|
|
2076
|
+
stopService,
|
|
2077
|
+
disconnect,
|
|
2078
|
+
runnerOrigin,
|
|
2079
|
+
disconnectCommand,
|
|
2080
|
+
existingRunnerEnvironment,
|
|
2081
|
+
pinExistingRunner
|
|
1949
2082
|
};
|