@cloop/runner 0.2.10 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +4 -2
  2. package/dist/{box-P6LMNVYG.js → box-2SVXFDHE.js} +16 -15
  3. package/dist/{chunk-UL2WHOQJ.js → chunk-4H4SIIUH.js} +1 -1
  4. package/dist/{chunk-J6AEO3GT.js → chunk-5FZAHWPX.js} +1 -1
  5. package/dist/{chunk-NX2LAKNU.js → chunk-5LDFFQ4O.js} +712 -45
  6. package/dist/{chunk-HI3HDN35.js → chunk-6LC5XH3S.js} +3 -5
  7. package/dist/{chunk-C6EODIE5.js → chunk-DH6IJQG6.js} +8 -10
  8. package/dist/{chunk-AEWIRLRS.js → chunk-E5CKL2Q3.js} +1 -1
  9. package/dist/{chunk-3DIGCVL4.js → chunk-IKCGVBHA.js} +11 -0
  10. package/dist/{chunk-PRJBCKRP.js → chunk-N24VQSNB.js} +3 -3
  11. package/dist/{chunk-VNX4VJAM.js → chunk-NALGGZM6.js} +3 -3
  12. package/dist/{chunk-JX6VG5FE.js → chunk-NUU4GXGV.js} +1 -1
  13. package/dist/{chunk-AG6SI6I2.js → chunk-NYGELUTR.js} +1 -1
  14. package/dist/{chunk-MWWA2VH7.js → chunk-RPWSWVKD.js} +5 -2
  15. package/dist/{chunk-EN7WRLSI.js → chunk-TJXXWEJW.js} +192 -40
  16. package/dist/{connect-GURZFURZ.js → connect-NAHKIUBI.js} +9 -9
  17. package/dist/disconnect-KTTVOO6R.js +28 -0
  18. package/dist/{hook-activity-LBYV4WJW.js → hook-activity-I7TV7YG7.js} +4 -4
  19. package/dist/{hook-session-start-YSEV5DCB.js → hook-session-start-MFX6HR3W.js} +3 -3
  20. package/dist/index.js +17 -17
  21. package/dist/{install-HTDTCELB.js → install-EMEZBBK7.js} +1 -1
  22. package/dist/{login-DXPJ3ZOA.js → login-37QE2AGW.js} +4 -4
  23. package/dist/{mcp-server-4UMYMJ5P.js → mcp-server-FLCNIW4C.js} +6 -6
  24. package/dist/runner-EHVMTKAA.js +13 -0
  25. package/dist/{runs-HRDQ7YCY.js → runs-IDFJ3Z2K.js} +3 -4
  26. package/dist/{statusline-AV2F2IM4.js → statusline-HGIHZJY2.js} +3 -3
  27. package/dist/{takeover-PDYTQY5D.js → takeover-YUBFKEKJ.js} +7 -8
  28. package/dist/{use-52LTRRXJ.js → use-OLC3RTIL.js} +14 -10
  29. package/package.json +1 -1
  30. package/dist/chunk-DHUZXAK2.js +0 -640
  31. package/dist/disconnect-HGQW7TVG.js +0 -159
  32. package/dist/runner-SPOKUMLM.js +0 -13
@@ -1,159 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- localRunsFilePath
4
- } from "./chunk-DHUZXAK2.js";
5
- import {
6
- installedService,
7
- revokeOwnDevice,
8
- runSteps,
9
- tokenGone
10
- } from "./chunk-EN7WRLSI.js";
11
- import {
12
- runnerStatePath,
13
- threadsFilePath
14
- } from "./chunk-MWWA2VH7.js";
15
- import {
16
- boxPath,
17
- readRunnerConfig
18
- } from "./chunk-NX2LAKNU.js";
19
- import "./chunk-UBXT5IDU.js";
20
- import "./chunk-JX6VG5FE.js";
21
- import "./chunk-VK6GV757.js";
22
- import "./chunk-R3CLO2FB.js";
23
- import "./chunk-VNX4VJAM.js";
24
- import "./chunk-PRJBCKRP.js";
25
- import "./chunk-AG6SI6I2.js";
26
- import "./chunk-UL2WHOQJ.js";
27
- import {
28
- getOrigin
29
- } from "./chunk-3DIGCVL4.js";
30
-
31
- // src/commands/disconnect.ts
32
- import { execFileSync } from "child_process";
33
- import { existsSync, readFileSync, rmSync } from "fs";
34
- import { homedir } from "os";
35
- var DONE_LINE = "This computer is no longer a Cloop runner. To connect it again: npx -y @cloop/runner connect";
36
- function unitOrigin(contents) {
37
- const plist = /<key>CLOOP_ORIGIN<\/key><string>([^<]+)<\/string>/.exec(contents)?.[1];
38
- if (plist) return plist.replace(/&amp;/g, "&");
39
- const unit = /Environment="CLOOP_ORIGIN=([^"]+)"/.exec(contents)?.[1];
40
- return unit ? unit.replace(/%%/g, "%") : null;
41
- }
42
- function disconnectPlan(opts) {
43
- const exists = opts.exists ?? existsSync;
44
- const read = opts.read ?? ((path) => readFileSync(path, "utf-8"));
45
- const services = ["local", "workstation"].map((kind) => installedService({ ...opts, kind })).filter((service) => exists(service.path));
46
- const fromUnit = services.map((service) => {
47
- try {
48
- return unitOrigin(read(service.path));
49
- } catch {
50
- return null;
51
- }
52
- }).find(Boolean);
53
- return {
54
- origin: opts.boxOrigin ?? fromUnit ?? opts.fallbackOrigin,
55
- deviceToken: opts.deviceToken,
56
- services,
57
- box: exists(opts.box) ? opts.box : null,
58
- files: opts.files.filter((file) => exists(file)),
59
- isBox: opts.platform !== "darwin" && services.some((s) => s.path.endsWith("/cloop-box.service"))
60
- };
61
- }
62
- function revokeLine(revoke, origin, box) {
63
- const keep = box ? ` Kept ${box}, which holds the device token, so you can try again.` : "";
64
- switch (revoke) {
65
- case "revoked":
66
- return [`Revoked this computer on Cloop (${origin}).`];
67
- case "already_revoked":
68
- return [`Cloop (${origin}) had already revoked this computer.`];
69
- case "no_device":
70
- return ["No runner device on this computer to revoke."];
71
- case "unknown_device":
72
- return [
73
- `Cloop at ${origin} never issued this computer's device token, so it belongs to the other environment.${keep}`,
74
- "Run `cloop disconnect --staging` for a staging runner, or `cloop disconnect` for production."
75
- ];
76
- case "failed":
77
- return [
78
- `Could not revoke this computer at ${origin}: Cloop did not answer as expected.${keep}`,
79
- "Run `cloop disconnect` again when Cloop answers, or press Disconnect on its card on the Threads page and then delete that file."
80
- ];
81
- }
82
- }
83
- async function disconnect(plan, opts) {
84
- const { say } = opts;
85
- const run = opts.run ?? ((command) => void execFileSync(command[0], command.slice(1), {
86
- stdio: "ignore",
87
- timeout: 15e3
88
- }));
89
- if (plan.isBox && !opts.yes) {
90
- say("This computer runs cloop-box.service, a Cloop box with T3 Code. Disconnect would:");
91
- for (const s of plan.services) say(` stop and remove ${s.path}`);
92
- if (plan.deviceToken) say(` revoke its runner device on Cloop (${plan.origin})`);
93
- for (const f of [...plan.box ? [plan.box] : [], ...plan.files]) say(` delete ${f}`);
94
- say("Run `cloop disconnect --yes` to do this.");
95
- return 1;
96
- }
97
- for (const service of plan.services) {
98
- await runSteps(service.steps, run);
99
- const stillRunning = async () => {
100
- const until = Date.now() + (opts.stopWaitMs ?? 1e4);
101
- for (; ; ) {
102
- try {
103
- run(service.running);
104
- } catch {
105
- return false;
106
- }
107
- if (Date.now() >= until) return true;
108
- await new Promise((resolve) => setTimeout(resolve, 250));
109
- }
110
- };
111
- if (await stillRunning()) {
112
- say(
113
- `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.`
114
- );
115
- return 1;
116
- }
117
- say(`Stopped the service in ${service.path}`);
118
- }
119
- const revoked = await opts.revoke(plan.origin, plan.deviceToken);
120
- const gone = tokenGone(revoked);
121
- for (const service of plan.services) {
122
- rmSync(service.path, { force: true });
123
- say(`Removed ${service.path}`);
124
- }
125
- for (const file of [...gone && plan.box ? [plan.box] : [], ...plan.files]) {
126
- rmSync(file, { force: true });
127
- say(`Deleted ${file}`);
128
- }
129
- for (const line of revokeLine(revoked, plan.origin, plan.box)) say(line);
130
- if (!gone) return 1;
131
- say(DONE_LINE);
132
- return 0;
133
- }
134
- async function disconnectCommand(argv) {
135
- const cfg = readRunnerConfig();
136
- const plan = disconnectPlan({
137
- platform: process.platform,
138
- home: homedir(),
139
- uid: process.getuid?.() ?? 0,
140
- ...process.env.CLOOP_UNIT_DIR ? { dir: process.env.CLOOP_UNIT_DIR } : {},
141
- box: boxPath(),
142
- deviceToken: cfg?.deviceToken ?? null,
143
- ...cfg?.origin ? { boxOrigin: cfg.origin } : {},
144
- fallbackOrigin: getOrigin(),
145
- files: [localRunsFilePath(), runnerStatePath(), threadsFilePath()]
146
- });
147
- process.exitCode = await disconnect(plan, {
148
- yes: argv.includes("--yes"),
149
- revoke: (origin, token) => revokeOwnDevice(origin, token),
150
- say: (line) => console.log(line)
151
- });
152
- }
153
- export {
154
- DONE_LINE,
155
- disconnect,
156
- disconnectCommand,
157
- disconnectPlan,
158
- unitOrigin
159
- };
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- connectWebhook,
4
- runnerCommand
5
- } from "./chunk-VNX4VJAM.js";
6
- import "./chunk-PRJBCKRP.js";
7
- import "./chunk-AG6SI6I2.js";
8
- import "./chunk-UL2WHOQJ.js";
9
- import "./chunk-3DIGCVL4.js";
10
- export {
11
- connectWebhook,
12
- runnerCommand
13
- };