@cloop/runner 0.3.39 → 0.3.41

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.
@@ -53,17 +53,17 @@ import {
53
53
  which,
54
54
  workFolder,
55
55
  workFolderLine
56
- } from "./chunk-6R6XDZKO.js";
56
+ } from "./chunk-3XQ44U27.js";
57
57
  import "./chunk-KDTPUD2Y.js";
58
- import "./chunk-A27N773G.js";
59
- import "./chunk-FWAHPPAG.js";
58
+ import "./chunk-WIAWWXGP.js";
59
+ import "./chunk-SDVTQCW7.js";
60
60
  import "./chunk-VK6GV757.js";
61
61
  import "./chunk-365HFCQQ.js";
62
62
  import "./chunk-PKIEWBR7.js";
63
- import "./chunk-DCX2BZPA.js";
64
- import "./chunk-H3NH6NQT.js";
63
+ import "./chunk-LGKSLIU2.js";
64
+ import "./chunk-4MMTNAPM.js";
65
65
  import "./chunk-SBYSVZ7J.js";
66
- import "./chunk-6TW44BUM.js";
66
+ import "./chunk-ILLDES3M.js";
67
67
  import "./chunk-D5UZW42X.js";
68
68
  export {
69
69
  DEFAULT_T3_URL,
@@ -7,17 +7,17 @@ import {
7
7
  runnerOrigin,
8
8
  stopService,
9
9
  unitOrigin
10
- } from "./chunk-6R6XDZKO.js";
10
+ } from "./chunk-3XQ44U27.js";
11
11
  import "./chunk-KDTPUD2Y.js";
12
- import "./chunk-A27N773G.js";
13
- import "./chunk-FWAHPPAG.js";
12
+ import "./chunk-WIAWWXGP.js";
13
+ import "./chunk-SDVTQCW7.js";
14
14
  import "./chunk-VK6GV757.js";
15
15
  import "./chunk-365HFCQQ.js";
16
16
  import "./chunk-PKIEWBR7.js";
17
- import "./chunk-DCX2BZPA.js";
18
- import "./chunk-H3NH6NQT.js";
17
+ import "./chunk-LGKSLIU2.js";
18
+ import "./chunk-4MMTNAPM.js";
19
19
  import "./chunk-SBYSVZ7J.js";
20
- import "./chunk-6TW44BUM.js";
20
+ import "./chunk-ILLDES3M.js";
21
21
  import "./chunk-D5UZW42X.js";
22
22
  export {
23
23
  disconnect,
@@ -2,17 +2,17 @@
2
2
  import {
3
3
  existingRunnerEnvironment,
4
4
  pinExistingRunner
5
- } from "./chunk-6R6XDZKO.js";
5
+ } from "./chunk-3XQ44U27.js";
6
6
  import "./chunk-KDTPUD2Y.js";
7
- import "./chunk-A27N773G.js";
8
- import "./chunk-FWAHPPAG.js";
7
+ import "./chunk-WIAWWXGP.js";
8
+ import "./chunk-SDVTQCW7.js";
9
9
  import "./chunk-VK6GV757.js";
10
10
  import "./chunk-365HFCQQ.js";
11
11
  import "./chunk-PKIEWBR7.js";
12
- import "./chunk-DCX2BZPA.js";
13
- import "./chunk-H3NH6NQT.js";
12
+ import "./chunk-LGKSLIU2.js";
13
+ import "./chunk-4MMTNAPM.js";
14
14
  import "./chunk-SBYSVZ7J.js";
15
- import "./chunk-6TW44BUM.js";
15
+ import "./chunk-ILLDES3M.js";
16
16
  import "./chunk-D5UZW42X.js";
17
17
  export {
18
18
  existingRunnerEnvironment,
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-365HFCQQ.js";
5
5
  import {
6
6
  VERSION
7
- } from "./chunk-6TW44BUM.js";
7
+ } from "./chunk-ILLDES3M.js";
8
8
  import {
9
9
  applyEnvironmentFlag
10
10
  } from "./chunk-D5UZW42X.js";
@@ -68,7 +68,7 @@ Add --staging to any command to use Cloop staging instead of production.
68
68
  A production machine and a staging machine can run side by side on one computer.
69
69
  `;
70
70
  async function pinExistingRunner() {
71
- const { pinExistingRunner: pin } = await import("./existing-runner-4CK4WX4T.js");
71
+ const { pinExistingRunner: pin } = await import("./existing-runner-HI4DFKSW.js");
72
72
  const { note } = pin();
73
73
  if (note) console.error(note);
74
74
  }
@@ -76,7 +76,7 @@ async function main() {
76
76
  switch (command) {
77
77
  case "login":
78
78
  case "auth": {
79
- const { loginCommand } = await import("./login-KHPQWRLN.js");
79
+ const { loginCommand } = await import("./login-UURPRX5F.js");
80
80
  await loginCommand(argv);
81
81
  break;
82
82
  }
@@ -86,61 +86,61 @@ async function main() {
86
86
  break;
87
87
  }
88
88
  case "serve": {
89
- const { startMcpServer } = await import("./mcp-server-TWESGZUO.js");
89
+ const { startMcpServer } = await import("./mcp-server-MTDAMQ7C.js");
90
90
  await startMcpServer();
91
91
  break;
92
92
  }
93
93
  case "statusline": {
94
- const { statuslineCommand } = await import("./statusline-MWKTBVHT.js");
94
+ const { statuslineCommand } = await import("./statusline-BV2IXFDB.js");
95
95
  statuslineCommand();
96
96
  break;
97
97
  }
98
98
  case "connect": {
99
- const { connectCommand } = await import("./connect-V7DIR53N.js");
99
+ const { connectCommand } = await import("./connect-SFAOSHIO.js");
100
100
  await connectCommand(argv.slice(1));
101
101
  break;
102
102
  }
103
103
  case "use": {
104
- const { useCommand } = await import("./use-OXDOSKC7.js");
104
+ const { useCommand } = await import("./use-6OHXWE5L.js");
105
105
  process.exitCode = await useCommand(argv.slice(1));
106
106
  break;
107
107
  }
108
108
  case "disconnect": {
109
- const { disconnectCommand } = await import("./disconnect-YVXPIISY.js");
109
+ const { disconnectCommand } = await import("./disconnect-ERRRZY25.js");
110
110
  await disconnectCommand(argv.slice(1));
111
111
  break;
112
112
  }
113
113
  case "box": {
114
- const { boxCommand } = await import("./box-CL2R6WOW.js");
114
+ const { boxCommand } = await import("./box-G664ZM6O.js");
115
115
  await boxCommand(argv.slice(1));
116
116
  break;
117
117
  }
118
118
  case "runs": {
119
119
  await pinExistingRunner();
120
- const { runsCommand } = await import("./runs-7FE4ODGK.js");
120
+ const { runsCommand } = await import("./runs-XR4MYK4X.js");
121
121
  process.exitCode = runsCommand();
122
122
  break;
123
123
  }
124
124
  case "watch": {
125
125
  await pinExistingRunner();
126
- const { watchCommand } = await import("./runs-7FE4ODGK.js");
126
+ const { watchCommand } = await import("./runs-XR4MYK4X.js");
127
127
  process.exitCode = await watchCommand(argv.slice(1));
128
128
  break;
129
129
  }
130
130
  case "takeover": {
131
131
  await pinExistingRunner();
132
- const { takeoverCommand } = await import("./takeover-AHNAFPBQ.js");
132
+ const { takeoverCommand } = await import("./takeover-H5YOSKV5.js");
133
133
  process.exitCode = await takeoverCommand(argv.slice(1));
134
134
  break;
135
135
  }
136
136
  case "resume": {
137
137
  await pinExistingRunner();
138
- const { resumeCommand } = await import("./runs-7FE4ODGK.js");
138
+ const { resumeCommand } = await import("./runs-XR4MYK4X.js");
139
139
  process.exitCode = await resumeCommand(argv.slice(1));
140
140
  break;
141
141
  }
142
142
  case "runner": {
143
- const { runnerCommand } = await import("./runner-O5CWGCVG.js");
143
+ const { runnerCommand } = await import("./runner-GMHC5FE7.js");
144
144
  await runnerCommand(argv.slice(1));
145
145
  break;
146
146
  }
@@ -3,9 +3,9 @@ import {
3
3
  deviceLogin,
4
4
  loginCommand,
5
5
  refusalSentence
6
- } from "./chunk-H3NH6NQT.js";
6
+ } from "./chunk-4MMTNAPM.js";
7
7
  import "./chunk-SBYSVZ7J.js";
8
- import "./chunk-6TW44BUM.js";
8
+ import "./chunk-ILLDES3M.js";
9
9
  import "./chunk-D5UZW42X.js";
10
10
  export {
11
11
  deviceLogin,
@@ -31,7 +31,7 @@ import {
31
31
  } from "./chunk-SBYSVZ7J.js";
32
32
  import {
33
33
  VERSION
34
- } from "./chunk-6TW44BUM.js";
34
+ } from "./chunk-ILLDES3M.js";
35
35
  import {
36
36
  getMeshUrl,
37
37
  getToken
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  connectWebhook,
4
4
  runnerCommand
5
- } from "./chunk-DCX2BZPA.js";
6
- import "./chunk-H3NH6NQT.js";
5
+ } from "./chunk-LGKSLIU2.js";
6
+ import "./chunk-4MMTNAPM.js";
7
7
  import "./chunk-SBYSVZ7J.js";
8
- import "./chunk-6TW44BUM.js";
8
+ import "./chunk-ILLDES3M.js";
9
9
  import "./chunk-D5UZW42X.js";
10
10
  export {
11
11
  connectWebhook,
@@ -9,8 +9,8 @@ import {
9
9
  runsCommand,
10
10
  sessionFolder,
11
11
  watchCommand
12
- } from "./chunk-EJXCUHHV.js";
13
- import "./chunk-FWAHPPAG.js";
12
+ } from "./chunk-NPTLMG3V.js";
13
+ import "./chunk-SDVTQCW7.js";
14
14
  import "./chunk-VK6GV757.js";
15
15
  import "./chunk-D5UZW42X.js";
16
16
  export {
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-VK6GV757.js";
8
8
  import {
9
9
  VERSION
10
- } from "./chunk-6TW44BUM.js";
10
+ } from "./chunk-ILLDES3M.js";
11
11
  import {
12
12
  getToken
13
13
  } from "./chunk-D5UZW42X.js";
@@ -9,10 +9,10 @@ import {
9
9
  takeoverDir,
10
10
  writeTakeoverReply,
11
11
  writeTakeoverRequest
12
- } from "./chunk-TFOUFEU3.js";
13
- import "./chunk-EJXCUHHV.js";
14
- import "./chunk-A27N773G.js";
15
- import "./chunk-FWAHPPAG.js";
12
+ } from "./chunk-LMW4JHRH.js";
13
+ import "./chunk-NPTLMG3V.js";
14
+ import "./chunk-WIAWWXGP.js";
15
+ import "./chunk-SDVTQCW7.js";
16
16
  import "./chunk-VK6GV757.js";
17
17
  import "./chunk-SBYSVZ7J.js";
18
18
  import "./chunk-D5UZW42X.js";
@@ -3,20 +3,20 @@ import {
3
3
  DRIVER_NAME,
4
4
  pinExistingRunner,
5
5
  runConnect
6
- } from "./chunk-6R6XDZKO.js";
6
+ } from "./chunk-3XQ44U27.js";
7
7
  import "./chunk-KDTPUD2Y.js";
8
- import "./chunk-A27N773G.js";
8
+ import "./chunk-WIAWWXGP.js";
9
9
  import {
10
10
  isLocal,
11
11
  readRunnerConfig
12
- } from "./chunk-FWAHPPAG.js";
12
+ } from "./chunk-SDVTQCW7.js";
13
13
  import "./chunk-VK6GV757.js";
14
14
  import "./chunk-365HFCQQ.js";
15
15
  import "./chunk-PKIEWBR7.js";
16
- import "./chunk-DCX2BZPA.js";
17
- import "./chunk-H3NH6NQT.js";
16
+ import "./chunk-LGKSLIU2.js";
17
+ import "./chunk-4MMTNAPM.js";
18
18
  import "./chunk-SBYSVZ7J.js";
19
- import "./chunk-6TW44BUM.js";
19
+ import "./chunk-ILLDES3M.js";
20
20
  import "./chunk-D5UZW42X.js";
21
21
 
22
22
  // src/commands/use.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloop/runner",
3
- "version": "0.3.39",
3
+ "version": "0.3.41",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "Make your computer and your agents Cloop machines: device login, the machine daemon, the Cloop MCP server, and Claude Code hooks.",
@@ -1,254 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- RUN_TEXT_MAX,
4
- boxPath,
5
- runnerPath
6
- } from "./chunk-FWAHPPAG.js";
7
-
8
- // src/box-watch.ts
9
- import { randomUUID } from "crypto";
10
- import { chmodSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "fs";
11
- import { dirname, join } from "path";
12
- var KEEP_MS = 7 * 24 * 36e5;
13
- function threadsFilePath(env) {
14
- return runnerPath(
15
- env,
16
- process.env.CLOOP_BOX_THREADS_FILE,
17
- (dir) => join(dir, "box-threads.json")
18
- );
19
- }
20
- function hostedThreadsFilePath(harness) {
21
- return join(dirname(boxPath()), `hosted-${harness}`, "box-threads.json");
22
- }
23
- function runnerStatePath(env, threadsFile = threadsFilePath(env)) {
24
- return join(dirname(threadsFile), "runner-state.json");
25
- }
26
- function writeRunnerState(state, path = runnerStatePath()) {
27
- mkdirSync(dirname(path), { recursive: true, mode: 448 });
28
- const tmp = `${path}.tmp`;
29
- writeFileSync(tmp, `${JSON.stringify(state)}
30
- `, { mode: 384 });
31
- renameSync(tmp, path);
32
- }
33
- function readRunnerState(path = runnerStatePath()) {
34
- try {
35
- const raw = JSON.parse(readFileSync(path, "utf-8"));
36
- return typeof raw.pid === "number" && typeof raw.connected_at === "string" ? { pid: raw.pid, connected_at: raw.connected_at } : null;
37
- } catch {
38
- return null;
39
- }
40
- }
41
- function isAlive(pid) {
42
- try {
43
- process.kill(pid, 0);
44
- return true;
45
- } catch (err) {
46
- return err.code === "EPERM";
47
- }
48
- }
49
- function lockThreadsFile(file, pid = process.pid, alive = isAlive) {
50
- const lock = `${file}.lock`;
51
- mkdirSync(dirname(lock), { recursive: true, mode: 448 });
52
- for (let attempt = 0; attempt < 2; attempt++) {
53
- try {
54
- writeFileSync(lock, String(pid), { flag: "wx", mode: 384 });
55
- return {
56
- ok: true,
57
- release: () => {
58
- try {
59
- if (readFileSync(lock, "utf-8") === String(pid)) unlinkSync(lock);
60
- } catch {
61
- }
62
- }
63
- };
64
- } catch (err) {
65
- if (err.code !== "EEXIST") throw err;
66
- let held = 0;
67
- try {
68
- held = Number(readFileSync(lock, "utf-8").trim());
69
- } catch (readErr) {
70
- if (readErr.code !== "ENOENT") throw readErr;
71
- continue;
72
- }
73
- if (Number.isInteger(held) && held > 0 && held !== pid && alive(held)) {
74
- return { ok: false, heldBy: held };
75
- }
76
- try {
77
- unlinkSync(lock);
78
- } catch (unlinkErr) {
79
- if (unlinkErr.code !== "ENOENT") throw unlinkErr;
80
- }
81
- }
82
- }
83
- return { ok: false, heldBy: -1 };
84
- }
85
- var BoxWatch = class {
86
- constructor(deps) {
87
- this.deps = deps;
88
- this.entries = this.load();
89
- }
90
- deps;
91
- entries;
92
- live = /* @__PURE__ */ new Map();
93
- stopped = false;
94
- list() {
95
- return this.entries;
96
- }
97
- start() {
98
- for (const e of this.entries) if (!e.settled_at) this.watch(e);
99
- }
100
- add(workId, threadId, why = "launch") {
101
- if (this.entries.some((e) => e.work_id === workId)) return;
102
- const entry = {
103
- work_id: workId,
104
- thread_id: threadId,
105
- launched_at: new Date(this.now()).toISOString()
106
- };
107
- this.entries.push(entry);
108
- this.save();
109
- this.deps.log(`${why} work=${workId} thread=${threadId}`);
110
- this.watch(entry);
111
- }
112
- /**
113
- * A send the thread took. A settled entry is watched again, so the turn
114
- * the send started reports its own end. A thread with no entry, one the
115
- * owner started outside Cloop, is watched from now under the app's
116
- * `workId`; without one nobody would read its end, so it stays unwatched.
117
- * A `workId` other than the entry's moves the entry to that row.
118
- */
119
- follow(threadId, workId) {
120
- const entry = this.entries.find((e) => e.thread_id === threadId);
121
- if (!entry) {
122
- if (workId) this.add(workId, threadId, "adopt");
123
- return;
124
- }
125
- if (workId && workId !== entry.work_id) {
126
- const unwatch = this.live.get(entry.work_id);
127
- this.live.delete(entry.work_id);
128
- if (unwatch) this.live.set(workId, unwatch);
129
- this.deps.log(`rebind thread=${threadId} work=${entry.work_id} to=${workId}`);
130
- entry.work_id = workId;
131
- entry.questions = void 0;
132
- }
133
- if (entry.settled_at) {
134
- entry.settled_at = void 0;
135
- entry.event = void 0;
136
- entry.sent_at = void 0;
137
- }
138
- this.save();
139
- this.watch(entry);
140
- }
141
- /** On every socket open and on a timer: send every event the mesh has not acked. */
142
- flush() {
143
- for (const e of this.entries) {
144
- for (const q of e.questions ?? []) if (!q.sent_at) this.trySend(e, q.event);
145
- if (e.event && !e.sent_at) this.trySend(e, e.event);
146
- }
147
- }
148
- /** `ok` false: the app refused the event for good (unknown work_id, bad frame), so it is not sent again either. */
149
- ack(eventId, ok = true) {
150
- for (const e of this.entries) {
151
- const held = [...e.questions ?? [], e].find((x) => x.event?.id === eventId && !x.sent_at);
152
- if (!held) continue;
153
- held.sent_at = new Date(this.now()).toISOString();
154
- this.save();
155
- this.deps.log(
156
- `event ${ok ? "acked" : "refused by the app"} work=${e.work_id} kind=${held.event?.kind}`
157
- );
158
- return;
159
- }
160
- }
161
- stop() {
162
- this.stopped = true;
163
- for (const unwatch of this.live.values()) unwatch();
164
- this.live.clear();
165
- }
166
- now() {
167
- return this.deps.now?.() ?? Date.now();
168
- }
169
- watch(e) {
170
- if (this.stopped || e.settled_at || this.live.has(e.work_id)) return;
171
- const unwatch = this.deps.watch(e.thread_id, (event) => this.onEvent(e, event));
172
- if (e.settled_at) unwatch();
173
- else this.live.set(e.work_id, unwatch);
174
- }
175
- onEvent(e, event) {
176
- if (e.settled_at) return;
177
- if (event.kind === "question") this.ask(e, event.question_id, event.summary);
178
- else if (event.kind === "progress") this.trySend(e, this.frame(e, event));
179
- else this.finish(e, event);
180
- }
181
- frame(e, event) {
182
- const { kind, summary } = event;
183
- return {
184
- type: "event",
185
- id: randomUUID(),
186
- work_id: e.work_id,
187
- thread_id: e.thread_id,
188
- kind,
189
- ...event.kind === "question" ? { question_id: event.question_id } : {},
190
- ...summary ? { summary: summary.slice(0, RUN_TEXT_MAX) } : {},
191
- ..."result" in event && event.result ? { result: event.result } : {},
192
- ..."pr_url" in event && event.pr_url ? { pr_url: event.pr_url } : {},
193
- ..."error" in event && event.error ? { error: event.error } : {},
194
- ..."harness" in event && event.harness ? { harness: event.harness } : {},
195
- at: new Date(this.now()).toISOString()
196
- };
197
- }
198
- ask(e, questionId, summary) {
199
- if (e.questions?.some((x) => x.event.question_id === questionId)) return;
200
- const event = this.frame(e, { kind: "question", question_id: questionId, summary });
201
- e.questions = [...e.questions ?? [], { event }];
202
- this.save();
203
- this.deps.log(`question work=${e.work_id} thread=${e.thread_id}`);
204
- this.trySend(e, event);
205
- }
206
- finish(e, end) {
207
- this.live.get(e.work_id)?.();
208
- this.live.delete(e.work_id);
209
- e.event = this.frame(e, end);
210
- e.settled_at = e.event.at;
211
- this.save();
212
- this.deps.log(
213
- `settle work=${e.work_id} thread=${e.thread_id} kind=${end.kind} pr=${end.pr_url ? "yes" : "no"}`
214
- );
215
- this.trySend(e, e.event);
216
- }
217
- trySend(e, event) {
218
- const sent = this.deps.send(event);
219
- this.deps.log(
220
- `event ${sent ? "sent" : "held"} work=${e.work_id} kind=${event.kind}${sent ? "" : "; socket down"}`
221
- );
222
- }
223
- load() {
224
- let raw;
225
- try {
226
- raw = JSON.parse(readFileSync(this.deps.file, "utf-8"));
227
- } catch {
228
- return [];
229
- }
230
- if (!Array.isArray(raw)) return [];
231
- const cutoff = this.now() - KEEP_MS;
232
- return raw.filter(
233
- (e) => typeof e?.work_id === "string" && typeof e?.thread_id === "string" && !(e.settled_at && Date.parse(e.settled_at) < cutoff)
234
- );
235
- }
236
- save() {
237
- mkdirSync(dirname(this.deps.file), { recursive: true, mode: 448 });
238
- const tmp = `${this.deps.file}.tmp`;
239
- writeFileSync(tmp, `${JSON.stringify(this.entries, null, 2)}
240
- `, { mode: 384 });
241
- chmodSync(tmp, 384);
242
- renameSync(tmp, this.deps.file);
243
- }
244
- };
245
-
246
- export {
247
- threadsFilePath,
248
- hostedThreadsFilePath,
249
- runnerStatePath,
250
- writeRunnerState,
251
- readRunnerState,
252
- lockThreadsFile,
253
- BoxWatch
254
- };