@cloop/runner 0.3.1 → 0.3.7
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/README.md +4 -0
- package/dist/{box-2SVXFDHE.js → box-IWMUX74G.js} +317 -39
- package/dist/{chunk-DH6IJQG6.js → chunk-3IP5XIPV.js} +3 -3
- package/dist/{chunk-6LC5XH3S.js → chunk-3TDL6X5T.js} +1 -1
- package/dist/{chunk-5LDFFQ4O.js → chunk-3WD7S6VI.js} +323 -95
- package/dist/{chunk-4H4SIIUH.js → chunk-5L76PKXT.js} +1 -1
- package/dist/{chunk-RPWSWVKD.js → chunk-EQTFHMUJ.js} +1 -1
- package/dist/{chunk-N24VQSNB.js → chunk-PSUEFPEA.js} +3 -1
- package/dist/{chunk-TJXXWEJW.js → chunk-QP6ZNGU3.js} +214 -64
- package/dist/{chunk-NALGGZM6.js → chunk-VYM5NYS6.js} +1 -1
- package/dist/{connect-NAHKIUBI.js → connect-QKQAJECG.js} +22 -10
- package/dist/{disconnect-KTTVOO6R.js → disconnect-5FEZUWJP.js} +6 -6
- package/dist/index.js +15 -14
- package/dist/{login-37QE2AGW.js → login-3IJKY6EZ.js} +2 -2
- package/dist/{mcp-server-FLCNIW4C.js → mcp-server-H2DF37BP.js} +1 -1
- package/dist/{runner-EHVMTKAA.js → runner-5G4CLAXF.js} +3 -3
- package/dist/{runs-IDFJ3Z2K.js → runs-RZL34AFT.js} +2 -2
- package/dist/{statusline-HGIHZJY2.js → statusline-I3MT77CR.js} +1 -1
- package/dist/{takeover-YUBFKEKJ.js → takeover-V2IHVUAB.js} +4 -4
- package/dist/{use-OLC3RTIL.js → use-PB7RVN6H.js} +6 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,6 +14,10 @@ Credentials live in `~/.cloop/credentials.json`. The API origin comes from `CLOO
|
|
|
14
14
|
|
|
15
15
|
To disconnect a runner, use Disconnect in its ⋯ menu on the Threads page.
|
|
16
16
|
|
|
17
|
+
### Windows
|
|
18
|
+
|
|
19
|
+
`cloop connect` on Windows writes `%LOCALAPPDATA%\Cloop\cloop-runner.cmd` and registers a per-user Task Scheduler task, `Cloop Runner`, that runs it at logon. No admin rights are needed. The log is `%LOCALAPPDATA%\Cloop\cloop-runner.log`. `cloop disconnect` deletes the task and the launcher. Use the native Claude Code install, which puts `claude.exe` on `PATH`. The Windows path is covered by unit tests and has not yet run on a Windows machine; details and the open points are in `docs/runbooks/cloop-local.md`, section "Windows".
|
|
20
|
+
|
|
17
21
|
## Commands
|
|
18
22
|
|
|
19
23
|
| Command | What it does |
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
serveTakeovers
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-3IP5XIPV.js";
|
|
5
|
+
import "./chunk-3TDL6X5T.js";
|
|
6
6
|
import {
|
|
7
7
|
MeshSocket,
|
|
8
8
|
defaultSocketFactory
|
|
@@ -10,21 +10,31 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
DEFAULT_FALLBACK_MODEL,
|
|
12
12
|
T3Client,
|
|
13
|
+
awaitDaemon,
|
|
13
14
|
claudeDialect,
|
|
14
15
|
codexDialect,
|
|
15
16
|
connectCommand,
|
|
17
|
+
findNpx,
|
|
18
|
+
installedService,
|
|
16
19
|
mintSession,
|
|
17
20
|
probeClaude,
|
|
18
21
|
probeClaudePermissions,
|
|
19
22
|
probeCodex,
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
programFor,
|
|
24
|
+
runBoxTool,
|
|
25
|
+
runSteps,
|
|
26
|
+
systemServices,
|
|
27
|
+
unitEnv,
|
|
28
|
+
unitFor,
|
|
29
|
+
which
|
|
30
|
+
} from "./chunk-QP6ZNGU3.js";
|
|
22
31
|
import {
|
|
23
32
|
BoxWatch,
|
|
24
33
|
lockThreadsFile,
|
|
34
|
+
readRunnerState,
|
|
25
35
|
threadsFilePath,
|
|
26
36
|
writeRunnerState
|
|
27
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-EQTFHMUJ.js";
|
|
28
38
|
import {
|
|
29
39
|
LocalDriver,
|
|
30
40
|
T3Driver,
|
|
@@ -32,20 +42,23 @@ import {
|
|
|
32
42
|
readRunnerConfig,
|
|
33
43
|
showsOtherThreads,
|
|
34
44
|
writeBoxConfig
|
|
35
|
-
} from "./chunk-
|
|
36
|
-
import
|
|
45
|
+
} from "./chunk-3WD7S6VI.js";
|
|
46
|
+
import {
|
|
47
|
+
olderThan
|
|
48
|
+
} from "./chunk-UBXT5IDU.js";
|
|
37
49
|
import {
|
|
38
50
|
getMachine
|
|
39
51
|
} from "./chunk-NUU4GXGV.js";
|
|
40
52
|
import "./chunk-VK6GV757.js";
|
|
41
53
|
import "./chunk-R3CLO2FB.js";
|
|
42
|
-
import "./chunk-
|
|
43
|
-
import "./chunk-
|
|
54
|
+
import "./chunk-VYM5NYS6.js";
|
|
55
|
+
import "./chunk-PSUEFPEA.js";
|
|
44
56
|
import "./chunk-NYGELUTR.js";
|
|
45
57
|
import {
|
|
46
58
|
VERSION
|
|
47
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-5L76PKXT.js";
|
|
48
60
|
import {
|
|
61
|
+
CONFIG_DIR,
|
|
49
62
|
getMeshUrl,
|
|
50
63
|
getToken,
|
|
51
64
|
readCredentials
|
|
@@ -125,6 +138,244 @@ async function listOutsideSessions(root = join(homedir(), ".claude", "projects")
|
|
|
125
138
|
return results;
|
|
126
139
|
}
|
|
127
140
|
|
|
141
|
+
// src/update.ts
|
|
142
|
+
import { execFile, spawn } from "child_process";
|
|
143
|
+
import { closeSync, mkdirSync, openSync, readFileSync, renameSync, writeFileSync } from "fs";
|
|
144
|
+
import { homedir as homedir2 } from "os";
|
|
145
|
+
import { join as join2 } from "path";
|
|
146
|
+
var REGISTRY_LATEST = "https://registry.npmjs.org/@cloop/runner/latest";
|
|
147
|
+
var FIRST_CHECK_MS = 10 * 6e4;
|
|
148
|
+
var CHECK_EVERY_MS = 6 * 36e5;
|
|
149
|
+
var ADOPT_WAIT_MS = 3e4;
|
|
150
|
+
var FETCH_WAIT_MS = 3 * 6e4;
|
|
151
|
+
var RELEASE = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/;
|
|
152
|
+
var log = (line) => console.error(`[workstation:update] ${line}`);
|
|
153
|
+
function namesVersion(unitText, version) {
|
|
154
|
+
const escaped = version.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
155
|
+
return new RegExp(`(?:^|[\\s"'>])@cloop/runner@${escaped}(?=[\\s"'<]|$)`).test(unitText);
|
|
156
|
+
}
|
|
157
|
+
function updateDecision(input) {
|
|
158
|
+
const stay = (why) => ({ kind: "stay", why });
|
|
159
|
+
if (!input.latest) return stay("no_latest");
|
|
160
|
+
if (!olderThan(input.current, input.latest)) return stay("current");
|
|
161
|
+
if (input.latest === input.failed) return stay("failed_before");
|
|
162
|
+
if (input.unitText === null || !namesVersion(input.unitText, input.current))
|
|
163
|
+
return stay("not_our_service");
|
|
164
|
+
if (!input.canDetach) return stay("no_detach");
|
|
165
|
+
if (input.running > 0 || input.inFlight > 0) return stay("busy");
|
|
166
|
+
return { kind: "hand_over", to: input.latest };
|
|
167
|
+
}
|
|
168
|
+
async function readLatest(get = fetch) {
|
|
169
|
+
try {
|
|
170
|
+
const res = await get(REGISTRY_LATEST, { signal: AbortSignal.timeout(5e3) });
|
|
171
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
172
|
+
const version = (await res.json()).version;
|
|
173
|
+
if (typeof version !== "string" || !RELEASE.test(version))
|
|
174
|
+
throw new Error("no release version");
|
|
175
|
+
return version;
|
|
176
|
+
} catch (err) {
|
|
177
|
+
log(`could not read latest from npm: ${err instanceof Error ? err.message : String(err)}`);
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function updateDir() {
|
|
182
|
+
return process.env.CLOOP_UPDATE_DIR ?? join2(homedir2(), CONFIG_DIR);
|
|
183
|
+
}
|
|
184
|
+
function updateLogPath() {
|
|
185
|
+
return join2(updateDir(), "update.log");
|
|
186
|
+
}
|
|
187
|
+
function statePath() {
|
|
188
|
+
return join2(updateDir(), "update.json");
|
|
189
|
+
}
|
|
190
|
+
function readFailed() {
|
|
191
|
+
try {
|
|
192
|
+
const failed = JSON.parse(readFileSync(statePath(), "utf-8")).failed;
|
|
193
|
+
return typeof failed === "string" ? failed : null;
|
|
194
|
+
} catch {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function recordFailed(version) {
|
|
199
|
+
try {
|
|
200
|
+
mkdirSync(updateDir(), { recursive: true, mode: 448 });
|
|
201
|
+
const temp = `${statePath()}.${process.pid}.tmp`;
|
|
202
|
+
writeFileSync(temp, `${JSON.stringify({ failed: version })}
|
|
203
|
+
`, { mode: 384 });
|
|
204
|
+
renameSync(temp, statePath());
|
|
205
|
+
} catch (err) {
|
|
206
|
+
log(`could not record ${version} as failed: ${err.code ?? err}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function handOverCommand(platform, npx, to, kind) {
|
|
210
|
+
const adopt2 = [
|
|
211
|
+
npx,
|
|
212
|
+
"-y",
|
|
213
|
+
`@cloop/runner@${to}`,
|
|
214
|
+
"box",
|
|
215
|
+
"adopt",
|
|
216
|
+
"--from",
|
|
217
|
+
VERSION,
|
|
218
|
+
"--kind",
|
|
219
|
+
kind
|
|
220
|
+
];
|
|
221
|
+
return platform === "linux" ? ["systemd-run", "--user", "--scope", "--quiet", "--collect", "--", ...adopt2] : adopt2;
|
|
222
|
+
}
|
|
223
|
+
function servicePath(kind) {
|
|
224
|
+
return installedService({
|
|
225
|
+
platform: process.platform,
|
|
226
|
+
kind,
|
|
227
|
+
home: homedir2(),
|
|
228
|
+
uid: process.getuid?.() ?? 0,
|
|
229
|
+
...process.env.CLOOP_UNIT_DIR ? { dir: process.env.CLOOP_UNIT_DIR } : {}
|
|
230
|
+
}).path;
|
|
231
|
+
}
|
|
232
|
+
function readText(path) {
|
|
233
|
+
try {
|
|
234
|
+
return readFileSync(path, "utf-8");
|
|
235
|
+
} catch {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function fetchVersion(npx, version) {
|
|
240
|
+
return new Promise((resolve) => {
|
|
241
|
+
execFile(
|
|
242
|
+
npx,
|
|
243
|
+
["-y", `@cloop/runner@${version}`, "--help"],
|
|
244
|
+
{ timeout: FETCH_WAIT_MS },
|
|
245
|
+
(err) => {
|
|
246
|
+
if (err) log(`could not fetch ${version}: ${err.message.split("\n")[0]}`);
|
|
247
|
+
resolve(!err);
|
|
248
|
+
}
|
|
249
|
+
);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
function selfUpdate(kind) {
|
|
253
|
+
let latest = null;
|
|
254
|
+
let handing = false;
|
|
255
|
+
let lastWhy = null;
|
|
256
|
+
const canDetach = process.platform === "darwin" || process.platform === "linux" && which("systemd-run") !== null;
|
|
257
|
+
const check = async () => {
|
|
258
|
+
const read = await readLatest();
|
|
259
|
+
if (!read || read === latest || !olderThan(VERSION, read) || read === readFailed()) return;
|
|
260
|
+
const npx = findNpx();
|
|
261
|
+
if (npx && await fetchVersion(npx, read)) latest = read;
|
|
262
|
+
};
|
|
263
|
+
setTimeout(() => {
|
|
264
|
+
void check();
|
|
265
|
+
setInterval(() => void check(), CHECK_EVERY_MS).unref();
|
|
266
|
+
}, FIRST_CHECK_MS).unref();
|
|
267
|
+
const handOver = (to) => {
|
|
268
|
+
const npx = findNpx();
|
|
269
|
+
if (!npx) {
|
|
270
|
+
log(`npx is not on PATH, so ${to} cannot start`);
|
|
271
|
+
recordFailed(to);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const [command, ...args] = handOverCommand(process.platform, npx, to, kind);
|
|
275
|
+
let fd;
|
|
276
|
+
try {
|
|
277
|
+
mkdirSync(updateDir(), { recursive: true, mode: 448 });
|
|
278
|
+
fd = openSync(updateLogPath(), "a");
|
|
279
|
+
} catch (err) {
|
|
280
|
+
log(`could not open ${updateLogPath()}: ${err.code ?? err}`);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
handing = true;
|
|
284
|
+
log(`handing over ${VERSION} -> ${to}; its log is ${updateLogPath()}`);
|
|
285
|
+
const child = spawn(command, args, { detached: true, stdio: ["ignore", fd, fd] });
|
|
286
|
+
closeSync(fd);
|
|
287
|
+
child.unref();
|
|
288
|
+
const failed = (why) => {
|
|
289
|
+
handing = false;
|
|
290
|
+
log(`${to} did not take over (${why}); staying on ${VERSION}`);
|
|
291
|
+
recordFailed(to);
|
|
292
|
+
};
|
|
293
|
+
child.on("error", (err) => failed(err.message));
|
|
294
|
+
child.on("exit", (code, signal) => {
|
|
295
|
+
if (code === 0) handing = false;
|
|
296
|
+
else failed(signal ? `signal ${signal}` : `exit ${code}`);
|
|
297
|
+
});
|
|
298
|
+
};
|
|
299
|
+
return {
|
|
300
|
+
beat({ running, inFlight }) {
|
|
301
|
+
if (handing) return;
|
|
302
|
+
const decision = updateDecision({
|
|
303
|
+
current: VERSION,
|
|
304
|
+
latest,
|
|
305
|
+
unitText: readText(servicePath(kind)),
|
|
306
|
+
running,
|
|
307
|
+
inFlight,
|
|
308
|
+
failed: readFailed(),
|
|
309
|
+
canDetach
|
|
310
|
+
});
|
|
311
|
+
if (decision.kind === "hand_over") {
|
|
312
|
+
lastWhy = null;
|
|
313
|
+
handOver(decision.to);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (decision.why !== lastWhy && latest) log(`staying on ${VERSION}: ${decision.why}`);
|
|
317
|
+
lastWhy = decision.why;
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function newDaemon(oldPid, read = readRunnerState) {
|
|
322
|
+
const state = read();
|
|
323
|
+
return state && state.pid !== oldPid ? state : null;
|
|
324
|
+
}
|
|
325
|
+
async function adopt(from, kind, { services: given, script = process.argv[1] ?? "cloop", npx = findNpx() } = {}) {
|
|
326
|
+
const oldPid = readRunnerState()?.pid;
|
|
327
|
+
const services = given ?? {
|
|
328
|
+
...systemServices,
|
|
329
|
+
awaitUp: (since2) => awaitDaemon(since2, () => newDaemon(oldPid), { timeoutMs: ADOPT_WAIT_MS })
|
|
330
|
+
};
|
|
331
|
+
const refuse = (why2) => {
|
|
332
|
+
log(`adopt ${from} -> ${VERSION} refused: ${why2}`);
|
|
333
|
+
recordFailed(VERSION);
|
|
334
|
+
return 1;
|
|
335
|
+
};
|
|
336
|
+
const program = programFor(script, process.execPath, npx, VERSION);
|
|
337
|
+
if (typeof program === "string") return refuse(program);
|
|
338
|
+
const unit = unitFor({
|
|
339
|
+
platform: services.platform,
|
|
340
|
+
kind,
|
|
341
|
+
home: homedir2(),
|
|
342
|
+
program,
|
|
343
|
+
env: unitEnv(process.env),
|
|
344
|
+
uid: process.getuid?.() ?? 0,
|
|
345
|
+
...process.env.CLOOP_UNIT_DIR ? { dir: process.env.CLOOP_UNIT_DIR } : {}
|
|
346
|
+
});
|
|
347
|
+
const old = readText(unit.path);
|
|
348
|
+
if (old === null) return refuse(`${unit.path} is missing`);
|
|
349
|
+
if (!namesVersion(old, from)) return refuse(`${unit.path} does not run ${from}`);
|
|
350
|
+
const run2 = (command) => void services.run(command);
|
|
351
|
+
const since = Date.now();
|
|
352
|
+
let why;
|
|
353
|
+
try {
|
|
354
|
+
writeFileSync(unit.path, unit.contents);
|
|
355
|
+
await runSteps(unit.start, run2);
|
|
356
|
+
if (await services.awaitUp(since)) {
|
|
357
|
+
log(`adopt ${from} -> ${VERSION}: up`);
|
|
358
|
+
return 0;
|
|
359
|
+
}
|
|
360
|
+
why = `the new daemon did not reach Cloop within ${ADOPT_WAIT_MS / 1e3} s`;
|
|
361
|
+
} catch (err) {
|
|
362
|
+
why = err instanceof Error ? err.message : String(err);
|
|
363
|
+
}
|
|
364
|
+
log(`adopt ${from} -> ${VERSION} failed: ${why}; putting ${from} back`);
|
|
365
|
+
recordFailed(VERSION);
|
|
366
|
+
try {
|
|
367
|
+
writeFileSync(unit.path, old);
|
|
368
|
+
await runSteps(unit.start, run2);
|
|
369
|
+
} catch (err) {
|
|
370
|
+
log(
|
|
371
|
+
`ROLLBACK FAILED: could not restart ${from} from ${unit.path}: ${err instanceof Error ? err.message : String(err)}. Run cloop connect on this machine.`
|
|
372
|
+
);
|
|
373
|
+
return 2;
|
|
374
|
+
}
|
|
375
|
+
log(`${from} is back`);
|
|
376
|
+
return 1;
|
|
377
|
+
}
|
|
378
|
+
|
|
128
379
|
// src/commands/box.ts
|
|
129
380
|
var BEAT_MS = 6e4;
|
|
130
381
|
var RESEND_MS = 5 * 6e4;
|
|
@@ -132,7 +383,7 @@ var REPAIR_BEFORE_MS = 2 * 24 * 36e5;
|
|
|
132
383
|
var EXPIRING_BEFORE_MS = 3 * 24 * 36e5;
|
|
133
384
|
var out = (line) => console.log(line);
|
|
134
385
|
var red = (s) => `\x1B[31m${s}\x1B[0m`;
|
|
135
|
-
var
|
|
386
|
+
var log2 = (line) => console.error(`[workstation:daemon] ${line}`);
|
|
136
387
|
var REVOKED_CLOSE = 4001;
|
|
137
388
|
var REFUSED_LINE = "refused: Cloop no longer accepts this runner. It was disconnected, or its login expired. Run `cloop connect` on it to connect it again.";
|
|
138
389
|
async function awaitNewDeviceToken(current, read, { tries = 3, delayMs = 2e3 } = {}) {
|
|
@@ -181,10 +432,12 @@ async function localDriver(cfg, name) {
|
|
|
181
432
|
dialect: name === "claude-code" ? claudeDialect(bin, cfg.fallbackModels ?? DEFAULT_FALLBACK_MODEL, cfg.askEverything, {
|
|
182
433
|
...await probeClaudePermissions(bin)
|
|
183
434
|
}) : codexDialect(bin),
|
|
435
|
+
// Codex on the same machine takes Claude Code's runs while its account is at its usage limit.
|
|
436
|
+
...name === "claude-code" ? { fallbackHarness: codexDialect() } : {},
|
|
184
437
|
repos: cfg.repos,
|
|
185
438
|
label: cfg.label,
|
|
186
439
|
harnesses: () => machineHarnesses(cfg),
|
|
187
|
-
log
|
|
440
|
+
log: log2
|
|
188
441
|
});
|
|
189
442
|
driver.warmHarnesses();
|
|
190
443
|
return driver;
|
|
@@ -204,7 +457,7 @@ async function run() {
|
|
|
204
457
|
process.exit(1);
|
|
205
458
|
}
|
|
206
459
|
if (!cfg.deviceToken) {
|
|
207
|
-
|
|
460
|
+
log2("no runner device on this machine; run `cloop connect` so the Agent can reach it");
|
|
208
461
|
}
|
|
209
462
|
const name = process.env.CLOOP_DRIVER ?? cfg.driver ?? "t3";
|
|
210
463
|
const local = isLocal(cfg) ? cfg : null;
|
|
@@ -230,7 +483,7 @@ async function run() {
|
|
|
230
483
|
client: () => t3.client,
|
|
231
484
|
t3Bin: isLocal(cfg) ? null : cfg.t3Bin,
|
|
232
485
|
scope: () => cfg && !isLocal(cfg) ? cfg.scope : void 0,
|
|
233
|
-
log,
|
|
486
|
+
log: log2,
|
|
234
487
|
watched: ({ work_id, thread_id }) => {
|
|
235
488
|
const e = watch.list().find((x) => work_id ? x.work_id === work_id : x.thread_id === thread_id);
|
|
236
489
|
return e && { thread_id: e.thread_id, settled: Boolean(e.settled_at) };
|
|
@@ -240,23 +493,31 @@ async function run() {
|
|
|
240
493
|
file: threadsFilePath(),
|
|
241
494
|
watch: (id, onEvent) => driver.watch(id, onEvent),
|
|
242
495
|
send: (frame) => socket.send({ ...frame }),
|
|
243
|
-
log
|
|
496
|
+
log: log2
|
|
244
497
|
});
|
|
498
|
+
let inFlight = 0;
|
|
499
|
+
let callsStarted = 0;
|
|
245
500
|
const onCall = async (frame) => {
|
|
246
501
|
const started = Date.now();
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
502
|
+
inFlight++;
|
|
503
|
+
callsStarted++;
|
|
504
|
+
try {
|
|
505
|
+
const result = await runBoxTool(
|
|
506
|
+
{
|
|
507
|
+
driver,
|
|
508
|
+
onLaunch: (workId, threadId) => watch.add(workId, threadId),
|
|
509
|
+
onResume: (threadId) => watch.resume(threadId)
|
|
510
|
+
},
|
|
511
|
+
frame.tool,
|
|
512
|
+
frame.args
|
|
513
|
+
);
|
|
514
|
+
socket.send({ type: "result", id: frame.id, ...result });
|
|
515
|
+
log2(
|
|
516
|
+
`call tool=${frame.tool} ok=${result.ok} ms=${Date.now() - started}${result.ok ? "" : ` error=${result.error} detail=${result.detail.slice(0, 300)}`}`
|
|
517
|
+
);
|
|
518
|
+
} finally {
|
|
519
|
+
inFlight--;
|
|
520
|
+
}
|
|
260
521
|
};
|
|
261
522
|
const socket = new MeshSocket({
|
|
262
523
|
meshUrl: getMeshUrl(),
|
|
@@ -269,18 +530,18 @@ async function run() {
|
|
|
269
530
|
onCall: (frame) => void onCall(frame),
|
|
270
531
|
onAck: (of, ok) => watch.ack(of, ok),
|
|
271
532
|
onOpen: () => {
|
|
272
|
-
|
|
273
|
-
recordConnected(
|
|
533
|
+
log2(`connected to ${getMeshUrl()}`);
|
|
534
|
+
recordConnected(log2);
|
|
274
535
|
watch.flush();
|
|
275
536
|
},
|
|
276
|
-
onClose: (code) =>
|
|
537
|
+
onClose: (code) => log2(
|
|
277
538
|
code === REVOKED_CLOSE ? "disconnected by Cloop (revoked), checking" : "disconnected, reconnecting"
|
|
278
539
|
),
|
|
279
540
|
onRefused: () => void (async () => {
|
|
280
541
|
const fresh = await awaitNewDeviceToken(token ?? "", () => readRunnerConfig()?.deviceToken);
|
|
281
542
|
const next = fresh ? readRunnerConfig() : null;
|
|
282
543
|
if (fresh && next) {
|
|
283
|
-
|
|
544
|
+
log2("reconnecting with the device token `cloop connect` just wrote");
|
|
284
545
|
token = fresh;
|
|
285
546
|
cfg = next;
|
|
286
547
|
if (!isLocal(next)) t3.client = new T3Client(next.t3Url, next.token);
|
|
@@ -288,17 +549,17 @@ async function run() {
|
|
|
288
549
|
socket.restart(fresh);
|
|
289
550
|
return;
|
|
290
551
|
}
|
|
291
|
-
|
|
552
|
+
log2(REFUSED_LINE);
|
|
292
553
|
stop(1);
|
|
293
554
|
})()
|
|
294
555
|
});
|
|
295
556
|
socket.start();
|
|
296
|
-
|
|
557
|
+
log2(
|
|
297
558
|
`connecting to ${getMeshUrl()} as ${sessionKey} (${readCredentials()?.deviceName ?? machine}) driver=${driver.name}`
|
|
298
559
|
);
|
|
299
560
|
watch.start();
|
|
300
561
|
setInterval(() => watch.flush(), RESEND_MS).unref();
|
|
301
|
-
if (driver instanceof LocalDriver) serveTakeovers(driver,
|
|
562
|
+
if (driver instanceof LocalDriver) serveTakeovers(driver, log2);
|
|
302
563
|
const renewT3 = async () => {
|
|
303
564
|
if (!cfg || isLocal(cfg) || Date.parse(cfg.expiresAt) - Date.now() >= REPAIR_BEFORE_MS) return;
|
|
304
565
|
try {
|
|
@@ -315,14 +576,16 @@ async function run() {
|
|
|
315
576
|
writeBoxConfig(renewed);
|
|
316
577
|
t3.client = new T3Client(renewed.t3Url, renewed.token);
|
|
317
578
|
t3.renewalFailed = false;
|
|
318
|
-
|
|
579
|
+
log2(`T3 session renewed until ${renewed.expiresAt}`);
|
|
319
580
|
} catch (err) {
|
|
320
581
|
t3.renewalFailed = true;
|
|
321
|
-
|
|
582
|
+
log2(`T3 session renewal failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
322
583
|
}
|
|
323
584
|
};
|
|
585
|
+
const update = selfUpdate(driver.name === "t3" ? "workstation" : "local");
|
|
324
586
|
const beat = async () => {
|
|
325
587
|
await renewT3();
|
|
588
|
+
const callsBefore = callsStarted;
|
|
326
589
|
let running = 0;
|
|
327
590
|
let outsideThreads = [];
|
|
328
591
|
const shown = showsOtherThreads(readRunnerConfig());
|
|
@@ -340,7 +603,7 @@ async function run() {
|
|
|
340
603
|
new Set(listed.threads.map((t) => t.id))
|
|
341
604
|
);
|
|
342
605
|
} catch (err) {
|
|
343
|
-
|
|
606
|
+
log2(`${driver.name} unreachable: ${err instanceof Error ? err.message : String(err)}`);
|
|
344
607
|
}
|
|
345
608
|
socket.sendPresence(
|
|
346
609
|
boxPresence({
|
|
@@ -354,11 +617,12 @@ async function run() {
|
|
|
354
617
|
t3: cfg && !isLocal(cfg) ? t3Presence(cfg, t3.renewalFailed) : null
|
|
355
618
|
})
|
|
356
619
|
);
|
|
620
|
+
update.beat({ running, inFlight: inFlight + callsStarted - callsBefore });
|
|
357
621
|
};
|
|
358
622
|
void beat();
|
|
359
623
|
setInterval(() => void beat(), BEAT_MS);
|
|
360
624
|
const stop = (code = 0) => {
|
|
361
|
-
|
|
625
|
+
log2("stopping");
|
|
362
626
|
watch.stop();
|
|
363
627
|
if (driver instanceof LocalDriver) driver.stop();
|
|
364
628
|
lock.release();
|
|
@@ -370,6 +634,10 @@ async function run() {
|
|
|
370
634
|
await new Promise(() => {
|
|
371
635
|
});
|
|
372
636
|
}
|
|
637
|
+
function flag(argv, name) {
|
|
638
|
+
const i = argv.indexOf(name);
|
|
639
|
+
return i >= 0 ? argv[i + 1] : void 0;
|
|
640
|
+
}
|
|
373
641
|
async function boxCommand(argv) {
|
|
374
642
|
switch (argv[0]) {
|
|
375
643
|
case "connect":
|
|
@@ -378,6 +646,16 @@ async function boxCommand(argv) {
|
|
|
378
646
|
case "run":
|
|
379
647
|
await run();
|
|
380
648
|
break;
|
|
649
|
+
case "adopt": {
|
|
650
|
+
const from = flag(argv, "--from");
|
|
651
|
+
const kind = flag(argv, "--kind");
|
|
652
|
+
if (!from || kind !== "workstation" && kind !== "local") {
|
|
653
|
+
console.error("Usage: cloop box adopt --from <version> --kind workstation|local");
|
|
654
|
+
process.exit(1);
|
|
655
|
+
}
|
|
656
|
+
process.exit(await adopt(from, kind));
|
|
657
|
+
break;
|
|
658
|
+
}
|
|
381
659
|
default:
|
|
382
660
|
console.error(
|
|
383
661
|
"Usage: cloop box connect [--t3-url <url>] [--t3-bin <path>] [--no-service] | cloop box run"
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
findRun
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-3TDL6X5T.js";
|
|
5
5
|
import {
|
|
6
6
|
lockThreadsFile,
|
|
7
7
|
threadsFilePath
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-EQTFHMUJ.js";
|
|
9
9
|
import {
|
|
10
10
|
isLocal,
|
|
11
11
|
localRunsFilePath,
|
|
12
12
|
readRunRecords,
|
|
13
13
|
readRunnerConfig,
|
|
14
14
|
takeoverSummary
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-3WD7S6VI.js";
|
|
16
16
|
import {
|
|
17
17
|
shortMachineName
|
|
18
18
|
} from "./chunk-NUU4GXGV.js";
|