@cloop/runner 0.3.2 → 0.3.8
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-VE2WJH3A.js → box-HUVPOJZK.js} +315 -39
- package/dist/{chunk-6SRPPUR2.js → chunk-3IP5XIPV.js} +3 -3
- package/dist/{chunk-43GTYT5U.js → chunk-3TDL6X5T.js} +1 -1
- package/dist/{chunk-NEGKYXHS.js → chunk-3WD7S6VI.js} +235 -87
- package/dist/{chunk-UIFPQQCQ.js → chunk-4MM5O7TV.js} +1 -1
- package/dist/{chunk-CKFWWGDD.js → chunk-EQTFHMUJ.js} +1 -1
- package/dist/{chunk-23ZHP4EN.js → chunk-GUPXSBOJ.js} +221 -64
- package/dist/{chunk-LOSZGPY4.js → chunk-OODVBR3F.js} +1 -1
- package/dist/{chunk-LAQSZU6I.js → chunk-WE4KRF7A.js} +3 -1
- package/dist/{connect-YCCLIBTL.js → connect-YJA2CS6L.js} +24 -10
- package/dist/{disconnect-TVAN3LLV.js → disconnect-S4GR7LCM.js} +6 -6
- package/dist/index.js +17 -15
- package/dist/{login-OF62R2RQ.js → login-RAZOAK6J.js} +2 -2
- package/dist/{mcp-server-V2M6VOQP.js → mcp-server-673BK6ER.js} +1 -1
- package/dist/{runner-64HZZDG6.js → runner-NZRNAFEP.js} +3 -3
- package/dist/{runs-4DXIUYDF.js → runs-RZL34AFT.js} +2 -2
- package/dist/{statusline-354ALD5T.js → statusline-KIE2H6EM.js} +1 -1
- package/dist/{takeover-Y7ZKSHGQ.js → takeover-V2IHVUAB.js} +4 -4
- package/dist/{use-AECELCU6.js → use-ZP4SPNI6.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-GUPXSBOJ.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-OODVBR3F.js";
|
|
55
|
+
import "./chunk-WE4KRF7A.js";
|
|
44
56
|
import "./chunk-NYGELUTR.js";
|
|
45
57
|
import {
|
|
46
58
|
VERSION
|
|
47
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-4MM5O7TV.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 } = {}) {
|
|
@@ -186,7 +437,7 @@ async function localDriver(cfg, name) {
|
|
|
186
437
|
repos: cfg.repos,
|
|
187
438
|
label: cfg.label,
|
|
188
439
|
harnesses: () => machineHarnesses(cfg),
|
|
189
|
-
log
|
|
440
|
+
log: log2
|
|
190
441
|
});
|
|
191
442
|
driver.warmHarnesses();
|
|
192
443
|
return driver;
|
|
@@ -206,7 +457,7 @@ async function run() {
|
|
|
206
457
|
process.exit(1);
|
|
207
458
|
}
|
|
208
459
|
if (!cfg.deviceToken) {
|
|
209
|
-
|
|
460
|
+
log2("no runner device on this machine; run `cloop connect` so the Agent can reach it");
|
|
210
461
|
}
|
|
211
462
|
const name = process.env.CLOOP_DRIVER ?? cfg.driver ?? "t3";
|
|
212
463
|
const local = isLocal(cfg) ? cfg : null;
|
|
@@ -232,7 +483,7 @@ async function run() {
|
|
|
232
483
|
client: () => t3.client,
|
|
233
484
|
t3Bin: isLocal(cfg) ? null : cfg.t3Bin,
|
|
234
485
|
scope: () => cfg && !isLocal(cfg) ? cfg.scope : void 0,
|
|
235
|
-
log,
|
|
486
|
+
log: log2,
|
|
236
487
|
watched: ({ work_id, thread_id }) => {
|
|
237
488
|
const e = watch.list().find((x) => work_id ? x.work_id === work_id : x.thread_id === thread_id);
|
|
238
489
|
return e && { thread_id: e.thread_id, settled: Boolean(e.settled_at) };
|
|
@@ -242,23 +493,31 @@ async function run() {
|
|
|
242
493
|
file: threadsFilePath(),
|
|
243
494
|
watch: (id, onEvent) => driver.watch(id, onEvent),
|
|
244
495
|
send: (frame) => socket.send({ ...frame }),
|
|
245
|
-
log
|
|
496
|
+
log: log2
|
|
246
497
|
});
|
|
498
|
+
let inFlight = 0;
|
|
499
|
+
let callsStarted = 0;
|
|
247
500
|
const onCall = async (frame) => {
|
|
248
501
|
const started = Date.now();
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
+
}
|
|
262
521
|
};
|
|
263
522
|
const socket = new MeshSocket({
|
|
264
523
|
meshUrl: getMeshUrl(),
|
|
@@ -271,18 +530,18 @@ async function run() {
|
|
|
271
530
|
onCall: (frame) => void onCall(frame),
|
|
272
531
|
onAck: (of, ok) => watch.ack(of, ok),
|
|
273
532
|
onOpen: () => {
|
|
274
|
-
|
|
275
|
-
recordConnected(
|
|
533
|
+
log2(`connected to ${getMeshUrl()}`);
|
|
534
|
+
recordConnected(log2);
|
|
276
535
|
watch.flush();
|
|
277
536
|
},
|
|
278
|
-
onClose: (code) =>
|
|
537
|
+
onClose: (code) => log2(
|
|
279
538
|
code === REVOKED_CLOSE ? "disconnected by Cloop (revoked), checking" : "disconnected, reconnecting"
|
|
280
539
|
),
|
|
281
540
|
onRefused: () => void (async () => {
|
|
282
541
|
const fresh = await awaitNewDeviceToken(token ?? "", () => readRunnerConfig()?.deviceToken);
|
|
283
542
|
const next = fresh ? readRunnerConfig() : null;
|
|
284
543
|
if (fresh && next) {
|
|
285
|
-
|
|
544
|
+
log2("reconnecting with the device token `cloop connect` just wrote");
|
|
286
545
|
token = fresh;
|
|
287
546
|
cfg = next;
|
|
288
547
|
if (!isLocal(next)) t3.client = new T3Client(next.t3Url, next.token);
|
|
@@ -290,17 +549,17 @@ async function run() {
|
|
|
290
549
|
socket.restart(fresh);
|
|
291
550
|
return;
|
|
292
551
|
}
|
|
293
|
-
|
|
552
|
+
log2(REFUSED_LINE);
|
|
294
553
|
stop(1);
|
|
295
554
|
})()
|
|
296
555
|
});
|
|
297
556
|
socket.start();
|
|
298
|
-
|
|
557
|
+
log2(
|
|
299
558
|
`connecting to ${getMeshUrl()} as ${sessionKey} (${readCredentials()?.deviceName ?? machine}) driver=${driver.name}`
|
|
300
559
|
);
|
|
301
560
|
watch.start();
|
|
302
561
|
setInterval(() => watch.flush(), RESEND_MS).unref();
|
|
303
|
-
if (driver instanceof LocalDriver) serveTakeovers(driver,
|
|
562
|
+
if (driver instanceof LocalDriver) serveTakeovers(driver, log2);
|
|
304
563
|
const renewT3 = async () => {
|
|
305
564
|
if (!cfg || isLocal(cfg) || Date.parse(cfg.expiresAt) - Date.now() >= REPAIR_BEFORE_MS) return;
|
|
306
565
|
try {
|
|
@@ -317,14 +576,16 @@ async function run() {
|
|
|
317
576
|
writeBoxConfig(renewed);
|
|
318
577
|
t3.client = new T3Client(renewed.t3Url, renewed.token);
|
|
319
578
|
t3.renewalFailed = false;
|
|
320
|
-
|
|
579
|
+
log2(`T3 session renewed until ${renewed.expiresAt}`);
|
|
321
580
|
} catch (err) {
|
|
322
581
|
t3.renewalFailed = true;
|
|
323
|
-
|
|
582
|
+
log2(`T3 session renewal failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
324
583
|
}
|
|
325
584
|
};
|
|
585
|
+
const update = selfUpdate(driver.name === "t3" ? "workstation" : "local");
|
|
326
586
|
const beat = async () => {
|
|
327
587
|
await renewT3();
|
|
588
|
+
const callsBefore = callsStarted;
|
|
328
589
|
let running = 0;
|
|
329
590
|
let outsideThreads = [];
|
|
330
591
|
const shown = showsOtherThreads(readRunnerConfig());
|
|
@@ -342,7 +603,7 @@ async function run() {
|
|
|
342
603
|
new Set(listed.threads.map((t) => t.id))
|
|
343
604
|
);
|
|
344
605
|
} catch (err) {
|
|
345
|
-
|
|
606
|
+
log2(`${driver.name} unreachable: ${err instanceof Error ? err.message : String(err)}`);
|
|
346
607
|
}
|
|
347
608
|
socket.sendPresence(
|
|
348
609
|
boxPresence({
|
|
@@ -356,11 +617,12 @@ async function run() {
|
|
|
356
617
|
t3: cfg && !isLocal(cfg) ? t3Presence(cfg, t3.renewalFailed) : null
|
|
357
618
|
})
|
|
358
619
|
);
|
|
620
|
+
update.beat({ running, inFlight: inFlight + callsStarted - callsBefore });
|
|
359
621
|
};
|
|
360
622
|
void beat();
|
|
361
623
|
setInterval(() => void beat(), BEAT_MS);
|
|
362
624
|
const stop = (code = 0) => {
|
|
363
|
-
|
|
625
|
+
log2("stopping");
|
|
364
626
|
watch.stop();
|
|
365
627
|
if (driver instanceof LocalDriver) driver.stop();
|
|
366
628
|
lock.release();
|
|
@@ -372,6 +634,10 @@ async function run() {
|
|
|
372
634
|
await new Promise(() => {
|
|
373
635
|
});
|
|
374
636
|
}
|
|
637
|
+
function flag(argv, name) {
|
|
638
|
+
const i = argv.indexOf(name);
|
|
639
|
+
return i >= 0 ? argv[i + 1] : void 0;
|
|
640
|
+
}
|
|
375
641
|
async function boxCommand(argv) {
|
|
376
642
|
switch (argv[0]) {
|
|
377
643
|
case "connect":
|
|
@@ -380,6 +646,16 @@ async function boxCommand(argv) {
|
|
|
380
646
|
case "run":
|
|
381
647
|
await run();
|
|
382
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
|
+
}
|
|
383
659
|
default:
|
|
384
660
|
console.error(
|
|
385
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";
|