cotal-ai 0.169.0 → 0.170.0
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/daemon/account.js +9 -3
- package/dist/daemon/client.js +2 -2
- package/dist/daemon/desktop.js +140 -2
- package/dist/daemon/generation.js +10 -4
- package/dist/daemon/install.js +3 -2
- package/dist/daemon/manager.js +111 -13
- package/dist/daemon/protocol.js +9 -6
- package/dist/daemon/server.js +101 -21
- package/dist/daemon/update-entry.js +43 -16
- package/dist/daemon/update-generation.js +6 -7
- package/dist/execution-store.js +10 -2
- package/dist/execution-transaction.js +2 -2
- package/package.json +19 -19
- package/seeded-connectors/_shared/docs-bundle.bin +0 -0
- package/seeded-connectors/_shared/docs-index.bin +0 -0
- package/seeded-connectors/_shared/placements.json +2 -2
- package/seeded-connectors/claude/dist/index.js +8 -2
- package/seeded-connectors/claude/dist/mcp.cjs +15 -15
- package/seeded-connectors/claude/dist/setup.d.ts.map +1 -1
- package/seeded-connectors/claude/package.json +1 -1
- package/seeded-connectors/codex/dist/host.js +14 -14
- package/seeded-connectors/codex/dist/index.js +2 -2
- package/seeded-connectors/codex/dist/personal.js +12 -12
- package/seeded-connectors/codex/dist/setup.d.ts +0 -4
- package/seeded-connectors/codex/dist/setup.d.ts.map +1 -1
- package/seeded-connectors/codex/package.json +1 -1
- package/seeded-connectors/hermes/dist/index.js +1 -1
- package/seeded-connectors/hermes/dist/launch.js +10 -10
- package/seeded-connectors/hermes/package.json +1 -1
- package/seeded-connectors/hermes/plugin/cotal/_sidecar/standalone.cjs +12 -12
- package/seeded-connectors/jcode/dist/host.d.ts.map +1 -1
- package/seeded-connectors/jcode/dist/host.js +21 -21
- package/seeded-connectors/jcode/dist/index.js +1 -1
- package/seeded-connectors/jcode/dist/mcp.js +5 -5
- package/seeded-connectors/jcode/package.json +1 -1
- package/seeded-connectors/opencode/dist/index.js +1 -1
- package/seeded-connectors/opencode/dist/plugin/index.js +15 -15
- package/seeded-connectors/opencode/package.json +1 -1
- package/seeded-connectors/pi/dist/index.js +2 -2
- package/seeded-connectors/pi/dist/standalone.js +13 -13
- package/seeded-connectors/pi/package.json +1 -1
- package/seeded-connectors/web/package.json +1 -1
package/dist/daemon/account.js
CHANGED
|
@@ -4,7 +4,11 @@ import { loadIdpSession, requestAccountMachine, signedInMachineAccounts, withIdp
|
|
|
4
4
|
import { validateCatalogSnapshot } from "@cotal-ai/cli";
|
|
5
5
|
import { accountComputerId } from "./account-identity.js";
|
|
6
6
|
/** Poll account intent without interpreting transport failure as an empty desired set. */
|
|
7
|
-
export function createAccountComputer(home, version, reconciler) {
|
|
7
|
+
export function createAccountComputer(home, version, reconciler, onChange) {
|
|
8
|
+
const notify = () => { try {
|
|
9
|
+
onChange?.();
|
|
10
|
+
}
|
|
11
|
+
catch { } };
|
|
8
12
|
let vitals;
|
|
9
13
|
let vitalsError;
|
|
10
14
|
let sampling;
|
|
@@ -51,7 +55,7 @@ export function createAccountComputer(home, version, reconciler) {
|
|
|
51
55
|
state = context.state;
|
|
52
56
|
if (context.work || context.state.mode === "per-space" || context.state.mode === "sign-in-required")
|
|
53
57
|
return;
|
|
54
|
-
context.work = poll().catch((error) => { context.state.message = error instanceof Error && error.message.startsWith("invalid computer") ? error.message : "account computer request failed; existing connections are unchanged"; }).finally(() => { tasks.delete(context.work); context.work = undefined; if (!stopped && pendingNames.delete(account.ownerKey))
|
|
58
|
+
context.work = poll().catch((error) => { context.state.message = error instanceof Error && error.message.startsWith("invalid computer") ? error.message : "account computer request failed; existing connections are unchanged"; }).finally(() => { tasks.delete(context.work); context.work = undefined; notify(); if (!stopped && pendingNames.delete(account.ownerKey))
|
|
55
59
|
void tick().catch(() => { }); });
|
|
56
60
|
tasks.add(context.work);
|
|
57
61
|
async function poll() {
|
|
@@ -131,6 +135,7 @@ export function createAccountComputer(home, version, reconciler) {
|
|
|
131
135
|
state.message = "account computer request failed; existing connections are unchanged";
|
|
132
136
|
} }).finally(() => {
|
|
133
137
|
work = undefined;
|
|
138
|
+
notify();
|
|
134
139
|
if (!stopped) {
|
|
135
140
|
timer = setTimeout(run, 5000);
|
|
136
141
|
timer.unref();
|
|
@@ -220,12 +225,13 @@ export function createAccountComputer(home, version, reconciler) {
|
|
|
220
225
|
context.state.computer = name;
|
|
221
226
|
}
|
|
222
227
|
// Polling owns network work. Saving a local preference never waits for a host.
|
|
228
|
+
notify();
|
|
223
229
|
void tick().catch(() => { state.message = "account computer request failed; existing connections are unchanged"; });
|
|
224
230
|
return name;
|
|
225
231
|
},
|
|
226
232
|
signedIn() { for (const context of contexts.values())
|
|
227
233
|
context.abort.abort(); contexts.clear(); if (timer)
|
|
228
|
-
clearTimeout(timer); run(); },
|
|
234
|
+
clearTimeout(timer); notify(); run(); },
|
|
229
235
|
status: () => {
|
|
230
236
|
const ordered = [...contexts.values()].sort((a, b) => Number(b.state.hostSupport === "supported") - Number(a.state.hostSupport === "supported") || (a.state.idpUrl ?? "").localeCompare(b.state.idpUrl ?? "") || (a.state.sub ?? "").localeCompare(b.state.sub ?? ""));
|
|
231
237
|
const computers = new Map();
|
package/dist/daemon/client.js
CHANGED
|
@@ -76,8 +76,8 @@ export async function managerViaDaemon(opts, request) {
|
|
|
76
76
|
try {
|
|
77
77
|
const id = randomUUID().replaceAll("-", "");
|
|
78
78
|
sock.write(encode({ v: DAEMON_PROTOCOL_VERSION, id, ...request }));
|
|
79
|
-
// A start may reconcile connectors for up to
|
|
80
|
-
const reply = JSON.parse(await readLine(sock, request.op === "manager-start" ?
|
|
79
|
+
// A start may reconcile connectors for up to ten minutes, then wait for Manager readiness.
|
|
80
|
+
const reply = JSON.parse(await readLine(sock, request.op === "manager-start" ? 730_000 : 130_000));
|
|
81
81
|
if (!reply.ok)
|
|
82
82
|
throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", `the daemon refused ${request.op}: ${reply.error.code} ${reply.error.message}`, { native: { code: reply.error.code }, remedy: reply.error.remedy ?? (reply.error.code === "UNKNOWN_OP" ? "restart the recorded Cotal daemon user service with this platform's service manager, then retry" : "inspect the daemon's hosting records and retry the operation") });
|
|
83
83
|
if (reply.id !== id || "event" in reply || !("state" in reply.result))
|
package/dist/daemon/desktop.js
CHANGED
|
@@ -19,7 +19,7 @@ export function parseDesktopRequest(value) {
|
|
|
19
19
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
20
20
|
throw new Error("request must be an object");
|
|
21
21
|
const o = value;
|
|
22
|
-
const simple = ["about", "status", "install", "log", "update-check"].includes(String(o.op));
|
|
22
|
+
const simple = ["about", "status", "status-watch", "install", "log", "update-check"].includes(String(o.op));
|
|
23
23
|
const scoped = ["connect-check", "register", "service-connect", "service-disconnect", "service-status"].includes(String(o.op));
|
|
24
24
|
const fields = o.op === "update-policy" ? ["op", "auto"] : o.op === "update-release" ? ["op", "version"] : o.op === "update-settings" ? ["op", "auto", "notify"] : o.op === "name" ? ["op", "name"] : o.op === "space-intent" ? ["op", "space", "enabled"] : simple ? ["op"] : scoped ? ["op", "space"] : o.op === "setup" ? ["op", "space", "idp"] : (o.op === "login" || o.op === "logout") ? ["op", "idp"] : o.op === "spaces" ? ["op", "refresh"] : [];
|
|
25
25
|
if (!fields.length || Object.keys(o).some((key) => !fields.includes(key)))
|
|
@@ -192,7 +192,7 @@ export async function runDesktopBridge(opts) {
|
|
|
192
192
|
emit({ v: 1, event: "result", ok: true, result: { assets } });
|
|
193
193
|
return;
|
|
194
194
|
}
|
|
195
|
-
if (req.op === "status" || req.op === "install" || req.op === "setup")
|
|
195
|
+
if (req.op === "status" || req.op === "status-watch" || req.op === "install" || req.op === "setup")
|
|
196
196
|
assertDesktopSetupComplete();
|
|
197
197
|
target = opts.resolveTarget();
|
|
198
198
|
const { paths, home } = target;
|
|
@@ -306,6 +306,144 @@ export async function runDesktopBridge(opts) {
|
|
|
306
306
|
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
|
+
if (req.op === "status-watch") {
|
|
310
|
+
const sock = await openVerified({ ...client, timeoutMs: 5000 });
|
|
311
|
+
let outcome;
|
|
312
|
+
try {
|
|
313
|
+
const id = randomUUID().replaceAll("-", "");
|
|
314
|
+
outcome = await new Promise((resolve, reject) => {
|
|
315
|
+
let buf = "";
|
|
316
|
+
let seenFirst = false;
|
|
317
|
+
let settled = false;
|
|
318
|
+
const finish = (err, value) => {
|
|
319
|
+
if (settled)
|
|
320
|
+
return;
|
|
321
|
+
settled = true;
|
|
322
|
+
clearTimeout(initialTimer);
|
|
323
|
+
sock.removeAllListeners("data");
|
|
324
|
+
sock.removeAllListeners("end");
|
|
325
|
+
sock.removeAllListeners("close");
|
|
326
|
+
sock.removeAllListeners("error");
|
|
327
|
+
if (err)
|
|
328
|
+
reject(err);
|
|
329
|
+
else
|
|
330
|
+
resolve(value);
|
|
331
|
+
};
|
|
332
|
+
const initialTimer = setTimeout(() => finish(new Error("timed out waiting for the daemon's reply")), 20_000);
|
|
333
|
+
sock.setEncoding("utf8");
|
|
334
|
+
sock.on("data", (chunk) => {
|
|
335
|
+
buf += chunk;
|
|
336
|
+
for (;;) {
|
|
337
|
+
const nl = buf.indexOf("\n");
|
|
338
|
+
if (nl === -1) {
|
|
339
|
+
if (Buffer.byteLength(buf, "utf8") > MAX_LINE_BYTES)
|
|
340
|
+
finish(new Error("daemon reply exceeds the line limit"));
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const line = buf.slice(0, nl);
|
|
344
|
+
buf = buf.slice(nl + 1);
|
|
345
|
+
if (Buffer.byteLength(line, "utf8") + 1 > MAX_LINE_BYTES) {
|
|
346
|
+
finish(new Error("daemon reply exceeds the line limit"));
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
let frame;
|
|
350
|
+
try {
|
|
351
|
+
frame = JSON.parse(line);
|
|
352
|
+
}
|
|
353
|
+
catch (err) {
|
|
354
|
+
finish(err);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (frame.v !== DAEMON_PROTOCOL_VERSION || frame.id !== id) {
|
|
358
|
+
finish(new Error("mismatched daemon reply"));
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
if (!seenFirst) {
|
|
362
|
+
seenFirst = true;
|
|
363
|
+
clearTimeout(initialTimer);
|
|
364
|
+
if (!frame.ok) {
|
|
365
|
+
if (frame.error.code === "UNKNOWN_OP")
|
|
366
|
+
finish(undefined, { kind: "unknown-op" });
|
|
367
|
+
else
|
|
368
|
+
finish(undefined, { kind: "refused", frame });
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
if (!frame.ok || !("event" in frame) || frame.event !== "status") {
|
|
373
|
+
finish(new Error("mismatched daemon status-watch event"));
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (frame.result.version !== opts.version) {
|
|
377
|
+
finish(undefined, { kind: "version-mismatch", status: frame.result });
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
emit({ v: 1, event: "status", ok: true, watchMode: "push", result: frame.result });
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
sock.once("end", () => finish(seenFirst ? undefined : new Error("daemon closed the connection without a reply"), { kind: "closed" }));
|
|
384
|
+
sock.once("close", () => finish(seenFirst ? undefined : new Error("daemon closed the connection without a reply"), { kind: "closed" }));
|
|
385
|
+
sock.once("error", (err) => finish(err));
|
|
386
|
+
sock.write(encode({ v: DAEMON_PROTOCOL_VERSION, id, op: "status-watch" }));
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
finally {
|
|
390
|
+
sock.destroy();
|
|
391
|
+
}
|
|
392
|
+
if (outcome.kind === "unknown-op") {
|
|
393
|
+
let currentStatus;
|
|
394
|
+
try {
|
|
395
|
+
currentStatus = await queryDaemon(client);
|
|
396
|
+
}
|
|
397
|
+
catch { }
|
|
398
|
+
const daemonVersion = currentStatus?.ok ? currentStatus.result.version : undefined;
|
|
399
|
+
emit({
|
|
400
|
+
v: 1,
|
|
401
|
+
event: "result",
|
|
402
|
+
ok: false,
|
|
403
|
+
error: {
|
|
404
|
+
code: "VERSION_MISMATCH",
|
|
405
|
+
message: "The running daemon and this app have different versions. Update them together before making changes.",
|
|
406
|
+
native: {
|
|
407
|
+
code: "UNKNOWN_OP",
|
|
408
|
+
detail: {
|
|
409
|
+
watchMode: "refused-unknown-op",
|
|
410
|
+
appVersion: opts.version,
|
|
411
|
+
...(daemonVersion !== undefined ? { daemonVersion } : {}),
|
|
412
|
+
},
|
|
413
|
+
},
|
|
414
|
+
},
|
|
415
|
+
...(currentStatus?.ok ? { result: { status: currentStatus.result } } : {}),
|
|
416
|
+
});
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
if (outcome.kind === "refused") {
|
|
420
|
+
emit({ ...outcome.frame, event: "result" });
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
if (outcome.kind === "version-mismatch") {
|
|
424
|
+
emit({
|
|
425
|
+
v: 1,
|
|
426
|
+
event: "result",
|
|
427
|
+
ok: false,
|
|
428
|
+
error: {
|
|
429
|
+
code: "VERSION_MISMATCH",
|
|
430
|
+
message: "The running daemon and this app have different versions. Update them together before making changes.",
|
|
431
|
+
native: {
|
|
432
|
+
code: "VERSION_MISMATCH",
|
|
433
|
+
detail: {
|
|
434
|
+
watchMode: "version-mismatch",
|
|
435
|
+
appVersion: opts.version,
|
|
436
|
+
daemonVersion: outcome.status.version,
|
|
437
|
+
},
|
|
438
|
+
},
|
|
439
|
+
},
|
|
440
|
+
result: { status: outcome.status },
|
|
441
|
+
});
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
emit({ v: 1, event: "result", ok: true, result: { closed: true, watchMode: "push" } });
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
309
447
|
const status = await queryDaemon(client);
|
|
310
448
|
if (!status.ok) {
|
|
311
449
|
emit({ ...status, event: "result" });
|
|
@@ -65,14 +65,20 @@ async function reconcileInstalledGeneration() {
|
|
|
65
65
|
let error = "";
|
|
66
66
|
child.stderr.setEncoding("utf8");
|
|
67
67
|
child.stderr.on("data", (chunk) => { error = (error + chunk).slice(-1500); });
|
|
68
|
-
|
|
68
|
+
// A cold home reconciles every built-in before Manager readiness is bounded.
|
|
69
|
+
const timeoutMs = 10 * 60_000;
|
|
70
|
+
let timedOut = false;
|
|
71
|
+
const timer = setTimeout(() => { timedOut = true; child.kill("SIGKILL"); }, timeoutMs);
|
|
69
72
|
child.once("error", (cause) => { clearTimeout(timer); reject(cause); });
|
|
70
|
-
child.once("close", (code) => {
|
|
73
|
+
child.once("close", (code, signal) => {
|
|
71
74
|
clearTimeout(timer);
|
|
72
75
|
if (code === 0)
|
|
73
76
|
resolve();
|
|
74
|
-
else
|
|
75
|
-
|
|
77
|
+
else {
|
|
78
|
+
const cause = timedOut ? `timed out after ${timeoutMs}ms, signal ${signal ?? "unknown"}` : signal ? `signal ${signal}` : `exit ${code}`;
|
|
79
|
+
const detail = error.trim().split(/\r?\n/).at(-1)?.replace(/\s+/g, " ").trim();
|
|
80
|
+
reject(new Error(`replacement connector reconciliation failed (${cause})${detail ? `: ${detail}` : ""}; run \`cotal ext seed --repair\` with the installed CLI`));
|
|
81
|
+
}
|
|
76
82
|
});
|
|
77
83
|
});
|
|
78
84
|
}
|
package/dist/daemon/install.js
CHANGED
|
@@ -314,9 +314,9 @@ function applyInstallUnlocked(paths, daemonHome, omittedRelativePathEntries) {
|
|
|
314
314
|
function recoveredLinuxUnit(daemonHome) {
|
|
315
315
|
if (process.platform !== "linux")
|
|
316
316
|
return undefined;
|
|
317
|
-
const
|
|
317
|
+
const unitDirectory = systemdUserUnitDirectory();
|
|
318
318
|
try {
|
|
319
|
-
lstatSync(
|
|
319
|
+
lstatSync(join(unitDirectory, daemonUnitName(daemonHome)));
|
|
320
320
|
}
|
|
321
321
|
catch (error) {
|
|
322
322
|
if (error.code === "ENOENT")
|
|
@@ -324,6 +324,7 @@ function recoveredLinuxUnit(daemonHome) {
|
|
|
324
324
|
throw error;
|
|
325
325
|
}
|
|
326
326
|
// A name is not authority. Require this installation's exact protected source and loaded fragment.
|
|
327
|
+
const rendered = renderDaemonUnit(unitDirectory, daemonHome);
|
|
327
328
|
try {
|
|
328
329
|
assertSystemdSource(rendered.unitPath, rendered.sha256);
|
|
329
330
|
}
|
package/dist/daemon/manager.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** Per-space stock Manager children. Only an answered instance records a hosting intent. */
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
|
-
import { appendFileSync, chmodSync, existsSync, lstatSync, readFileSync, readdirSync, renameSync, rmSync, statSync } from "node:fs";
|
|
5
|
-
import { join } from "node:path";
|
|
4
|
+
import { appendFileSync, chmodSync, copyFileSync, cpSync, existsSync, lstatSync, mkdtempSync, readFileSync, readdirSync, renameSync, rmSync, statSync } from "node:fs";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
6
|
import { assertLifecycleToken, BASELINE_LIFECYCLE_ENDPOINT, controlReplyFrom, dialerFor, drainAndClose, invokeRepairingSplit, issuedUserCaller, jwtFromCreds, mkSecretDir, parseRemoteEndpointDeregisterResult, registry, resolveService, standaloneConnectOpts, unansweredRequest, writeSecretFileAtomic, } from "@cotal-ai/core";
|
|
7
7
|
import { daemonArgv } from "@cotal-ai/cli/self-exec";
|
|
8
8
|
import { writeDefaultPersonaForLaunch } from "@cotal-ai/cli/default-persona";
|
|
@@ -10,14 +10,69 @@ import { loadIdpSession, retainManagerAuthorityRoute, withIdpSessionDir } from "
|
|
|
10
10
|
import { controlCaller, findMesh, homeCotalDir, isCommandFailure, isConnectRefusal, resolveControlTarget, spaceFromSegment, spaceSegment, userAuthStateDir, workspaceSecretStore } from "@cotal-ai/workspace";
|
|
11
11
|
import { DIAL_TIMEOUT_MS, DialNotAdmitted, dialWithRetry, epRailFailure, notAdmittedRefusal } from "@cotal-ai/workspace/control";
|
|
12
12
|
import { installedGenerationVersion, reconcileHostedConnectors, ReplacedDaemonGeneration } from "./generation.js";
|
|
13
|
-
import { daemonPaths, daemonPathsFor } from "./endpoint.js";
|
|
13
|
+
import { checkDir, daemonPaths, daemonPathsFor, ensureDir } from "./endpoint.js";
|
|
14
14
|
import { daemonStartedByOwnedService, installedDaemonIdentity, unitReceiptFile } from "./install.js";
|
|
15
15
|
import { readHostedAgents } from "./agents.js";
|
|
16
16
|
import { readManagerCleanup, writeManagerCleanup, validateManagerCleanupAuthority, managerCleanupFile } from "./manager-cleanup.js";
|
|
17
17
|
import { processBirth } from "./lifetime.js";
|
|
18
18
|
import { probeLiveness } from "@cotal-ai/workspace/liveness";
|
|
19
|
+
import { executionInventory, executionSha256, protectedExecutionEntry } from "../cotal.js";
|
|
19
20
|
export const daemonManagerRoot = (space, home) => join(home, "daemon", spaceSegment(space), "manager");
|
|
20
21
|
export const daemonManagerIntentFile = (space, home) => join(home, "daemon", spaceSegment(space), "manager-host.json");
|
|
22
|
+
/** The app can disappear while the Manager is serving. Both its lazy peers and the bearer
|
|
23
|
+
* commands it gives seats must resolve against the same complete runtime it starts with. */
|
|
24
|
+
function retainAppManagerArgv(home, argv) {
|
|
25
|
+
if (process.platform !== "darwin" && process.platform !== "linux")
|
|
26
|
+
return argv;
|
|
27
|
+
const entry = argv.at(-1);
|
|
28
|
+
const source = dirname(dirname(entry));
|
|
29
|
+
if (!existsSync(join(source, "desktop-runtime.json")))
|
|
30
|
+
return argv;
|
|
31
|
+
const inventory = (root) => {
|
|
32
|
+
if (!lstatSync(root).isDirectory())
|
|
33
|
+
throw new Error("the Cotal app runtime is not a real directory");
|
|
34
|
+
return JSON.stringify(executionInventory(root));
|
|
35
|
+
};
|
|
36
|
+
const expected = inventory(source);
|
|
37
|
+
protectedExecutionEntry(process.execPath);
|
|
38
|
+
const nodeHash = executionSha256(readFileSync(process.execPath));
|
|
39
|
+
const store = join(home, "daemon", "app-manager-runtimes");
|
|
40
|
+
checkDir(dirname(store));
|
|
41
|
+
ensureDir(store);
|
|
42
|
+
const retained = join(store, executionSha256(`${nodeHash}\n${expected}`));
|
|
43
|
+
const verify = (root) => {
|
|
44
|
+
checkDir(root);
|
|
45
|
+
const node = join(root, "cotal-node");
|
|
46
|
+
protectedExecutionEntry(node);
|
|
47
|
+
if (!lstatSync(node).isFile() || executionSha256(readFileSync(node)) !== nodeHash || inventory(join(root, "runtime")) !== expected)
|
|
48
|
+
throw new Error("the retained Cotal app runtime differs from the installed app");
|
|
49
|
+
};
|
|
50
|
+
if (!existsSync(retained)) {
|
|
51
|
+
const staging = mkdtempSync(join(store, ".copy-"));
|
|
52
|
+
try {
|
|
53
|
+
cpSync(source, join(staging, "runtime"), { recursive: true, verbatimSymlinks: true });
|
|
54
|
+
const node = join(staging, "cotal-node");
|
|
55
|
+
copyFileSync(process.execPath, node);
|
|
56
|
+
chmodSync(node, 0o700);
|
|
57
|
+
verify(staging);
|
|
58
|
+
// A seat may still use this bearer command. Never replace a published copy.
|
|
59
|
+
try {
|
|
60
|
+
renameSync(staging, retained);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (!["EEXIST", "ENOTEMPTY"].includes(error.code ?? ""))
|
|
64
|
+
throw error;
|
|
65
|
+
verify(retained);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
rmSync(staging, { recursive: true, force: true });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else
|
|
73
|
+
verify(retained);
|
|
74
|
+
return [join(retained, "cotal-node"), ...argv.slice(1, -1), join(retained, "runtime", "dist", "cotal.js")];
|
|
75
|
+
}
|
|
21
76
|
/** Forget only the daemon's per-space hosting records after its owned service was removed. */
|
|
22
77
|
export function forgetHostedManagerIntents(home) {
|
|
23
78
|
let entries;
|
|
@@ -49,7 +104,11 @@ export class HostedManagerRefusal extends Error {
|
|
|
49
104
|
this.remedy = remedy;
|
|
50
105
|
}
|
|
51
106
|
}
|
|
52
|
-
export function createHostedManagers(home = homeCotalDir(), version = installedGenerationVersion(), daemonHome) {
|
|
107
|
+
export function createHostedManagers(home = homeCotalDir(), version = installedGenerationVersion(), daemonHome, onChange) {
|
|
108
|
+
const notify = () => { try {
|
|
109
|
+
onChange?.();
|
|
110
|
+
}
|
|
111
|
+
catch { } };
|
|
53
112
|
const homeArg = daemonHome === undefined ? undefined : /^[A-Za-z0-9_./-]+$/.test(daemonHome) ? daemonHome : JSON.stringify(daemonHome);
|
|
54
113
|
const command = (text) => homeArg === undefined ? text : text.replace(/cotal daemon (setup|status|login|serve)\b(?! --daemon-home)/g, (match) => `${match} --daemon-home ${homeArg}`);
|
|
55
114
|
let reconcileTask;
|
|
@@ -175,6 +234,7 @@ export function createHostedManagers(home = homeCotalDir(), version = installedG
|
|
|
175
234
|
reason = safeDiagnostic(reason).slice(0, 1500);
|
|
176
235
|
l.view = { ...l.view, state: "refused", reason, lastRefusal: reason, next };
|
|
177
236
|
persistRefusal(l);
|
|
237
|
+
notify();
|
|
178
238
|
return l.view;
|
|
179
239
|
};
|
|
180
240
|
const status = (space) => {
|
|
@@ -310,7 +370,7 @@ export function createHostedManagers(home = homeCotalDir(), version = installedG
|
|
|
310
370
|
if (!reply.ok)
|
|
311
371
|
throw new Error(reply.error ?? "the hosted Manager did not answer status");
|
|
312
372
|
if (l.child === child && !l.stopping && !closed && !generationPending)
|
|
313
|
-
l.view = { ...l.view, state: "answering", connectors: connectors(reply.data), reason: undefined, next: undefined, observedAt: new Date().toISOString() };
|
|
373
|
+
l.view = { ...l.view, state: "answering", connectors: connectors(reply.data), reason: undefined, lastRefusal: undefined, next: undefined, observedAt: new Date().toISOString() };
|
|
314
374
|
}
|
|
315
375
|
catch (error) {
|
|
316
376
|
if (l.child === child && !l.stopping && !closed && !generationPending) {
|
|
@@ -357,14 +417,34 @@ export function createHostedManagers(home = homeCotalDir(), version = installedG
|
|
|
357
417
|
}
|
|
358
418
|
// Parent IPC proves child responsiveness without the daemon obtaining mesh credentials.
|
|
359
419
|
await generationCall(child, randomUUID(), "inspect");
|
|
360
|
-
if (current())
|
|
420
|
+
if (current()) {
|
|
361
421
|
l.healthFailures = 0;
|
|
422
|
+
try {
|
|
423
|
+
const agents = await readHostedAgents(child);
|
|
424
|
+
if (current()) {
|
|
425
|
+
const prevKey = l.agents?.state === "read" ? JSON.stringify(l.agents.agents) : l.agents?.state;
|
|
426
|
+
const nextKey = JSON.stringify(agents);
|
|
427
|
+
l.agents = { space: l.view.space, observedAt: new Date().toISOString(), state: "read", agents };
|
|
428
|
+
if (prevKey !== nextKey)
|
|
429
|
+
notify();
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
catch {
|
|
433
|
+
if (current()) {
|
|
434
|
+
const prevState = l.agents?.state;
|
|
435
|
+
l.agents = { space: l.view.space, observedAt: new Date().toISOString(), state: "unreadable", message: "Could not read agents for this space." };
|
|
436
|
+
if (prevState !== "unreadable")
|
|
437
|
+
notify();
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
362
441
|
}
|
|
363
442
|
catch (error) {
|
|
364
443
|
if (!current())
|
|
365
444
|
return;
|
|
366
445
|
l.healthFailures = (l.healthFailures ?? 0) + 1;
|
|
367
446
|
l.view = { ...l.view, state: "starting", reason: "the hosted Manager parent IPC probe did not answer", observedAt: new Date().toISOString(), next: `inspect \`cotal daemon status --space ${l.view.space}\`; restore the Manager connection or stop its seats before running \`cotal daemon setup --space ${l.view.space}\`` };
|
|
447
|
+
notify();
|
|
368
448
|
if (l.healthFailures < 3)
|
|
369
449
|
return;
|
|
370
450
|
const attempt = randomUUID();
|
|
@@ -445,14 +525,19 @@ export function createHostedManagers(home = homeCotalDir(), version = installedG
|
|
|
445
525
|
}
|
|
446
526
|
}
|
|
447
527
|
l.child = undefined;
|
|
528
|
+
l.agents = undefined;
|
|
529
|
+
notify();
|
|
448
530
|
}
|
|
449
531
|
const schedule = (l) => {
|
|
450
532
|
if (closed || l.stopping || l.view.state === "refused")
|
|
451
533
|
return;
|
|
452
534
|
l.view = { ...l.view, state: "restarting", pid: l.child?.pid };
|
|
453
|
-
if (generationPending)
|
|
535
|
+
if (generationPending) {
|
|
536
|
+
notify();
|
|
454
537
|
return;
|
|
538
|
+
}
|
|
455
539
|
l.view = { ...l.view, restarts: l.view.restarts + 1 };
|
|
540
|
+
notify();
|
|
456
541
|
const delay = Math.min(30_000, 1000 * 2 ** Math.min(l.failures++, 5));
|
|
457
542
|
l.timer = setTimeout(() => {
|
|
458
543
|
l.timer = undefined;
|
|
@@ -539,7 +624,7 @@ export function createHostedManagers(home = homeCotalDir(), version = installedG
|
|
|
539
624
|
appendFileSync(logFile, safe, { mode: 0o600 });
|
|
540
625
|
chmodSync(logFile, 0o600);
|
|
541
626
|
};
|
|
542
|
-
const [node, ...argv] = daemonArgv();
|
|
627
|
+
const [node, ...argv] = retainAppManagerArgv(home, daemonArgv());
|
|
543
628
|
closeProbeSession(l);
|
|
544
629
|
l.exchangeFailedUntil = undefined;
|
|
545
630
|
l.lastExchangeError = undefined;
|
|
@@ -666,8 +751,13 @@ export function createHostedManagers(home = homeCotalDir(), version = installedG
|
|
|
666
751
|
writeManagerCleanup(home, { ...cleanup, phase: "hosted" });
|
|
667
752
|
writeSecretFileAtomic(path, JSON.stringify({ v: 1, space }));
|
|
668
753
|
rmSync(refusalFile(space), { force: true });
|
|
669
|
-
l.view = { ...l.view, state: "answering", registrationCleanup: undefined, connectors: connectors(reply.data), reason: undefined, next: undefined, observedAt: new Date().toISOString() };
|
|
754
|
+
l.view = { ...l.view, state: "answering", registrationCleanup: undefined, connectors: connectors(reply.data), reason: undefined, lastRefusal: undefined, next: undefined, observedAt: new Date().toISOString() };
|
|
670
755
|
l.failures = 0;
|
|
756
|
+
try {
|
|
757
|
+
l.agents = { space, observedAt: new Date().toISOString(), state: "read", agents: await readHostedAgents(child) };
|
|
758
|
+
}
|
|
759
|
+
catch { }
|
|
760
|
+
notify();
|
|
671
761
|
observe(l);
|
|
672
762
|
return { ...l.view };
|
|
673
763
|
}
|
|
@@ -724,7 +814,7 @@ export function createHostedManagers(home = homeCotalDir(), version = installedG
|
|
|
724
814
|
throw new Error("the hosted Manager is stopping");
|
|
725
815
|
writeSecretFileAtomic(daemonManagerIntentFile(space, home), JSON.stringify({ v: 1, space }));
|
|
726
816
|
rmSync(refusalFile(space), { force: true });
|
|
727
|
-
l.view = { ...l.view, state: "answering", connectors: connectors(reply.data), reason: undefined, next: undefined, observedAt: new Date().toISOString() };
|
|
817
|
+
l.view = { ...l.view, state: "answering", connectors: connectors(reply.data), reason: undefined, lastRefusal: undefined, next: undefined, observedAt: new Date().toISOString() };
|
|
728
818
|
const retryClaudeSetup = l.view.connectors?.some(connector => connector.agent === "claude" && connector.state === "unavailable" && connector.reason?.startsWith("Claude wake channel setup failed:"));
|
|
729
819
|
if (retryClaudeSetup || !l.view.connectors?.some(connector => connector.state === "available")) {
|
|
730
820
|
const child = l.child;
|
|
@@ -814,8 +904,10 @@ export function createHostedManagers(home = homeCotalDir(), version = installedG
|
|
|
814
904
|
};
|
|
815
905
|
return {
|
|
816
906
|
start, status, refresh,
|
|
817
|
-
async agents() {
|
|
907
|
+
async agents(cachedOnly = false) {
|
|
818
908
|
const observations = await Promise.all([...live.values()].filter(l => l.view.state !== "stopped").map(async (l) => {
|
|
909
|
+
if (cachedOnly && l.agents && l.child && !l.stopping)
|
|
910
|
+
return l.agents;
|
|
819
911
|
const child = l.child;
|
|
820
912
|
const space = l.view.space;
|
|
821
913
|
try {
|
|
@@ -824,10 +916,14 @@ export function createHostedManagers(home = homeCotalDir(), version = installedG
|
|
|
824
916
|
const agents = await readHostedAgents(child);
|
|
825
917
|
if (l.child !== child || l.stopping)
|
|
826
918
|
throw new Error("Manager changed");
|
|
827
|
-
|
|
919
|
+
const row = { space, observedAt: new Date().toISOString(), state: "read", agents };
|
|
920
|
+
l.agents = row;
|
|
921
|
+
return row;
|
|
828
922
|
}
|
|
829
923
|
catch {
|
|
830
|
-
|
|
924
|
+
const row = { space, observedAt: new Date().toISOString(), state: "unreadable", message: "Could not read agents for this space." };
|
|
925
|
+
l.agents = row;
|
|
926
|
+
return row;
|
|
831
927
|
}
|
|
832
928
|
}));
|
|
833
929
|
let bytes = 0;
|
|
@@ -1050,7 +1146,9 @@ export function createHostedManagers(home = homeCotalDir(), version = installedG
|
|
|
1050
1146
|
held.view = { ...held.view, registrationCleanup: undefined };
|
|
1051
1147
|
}
|
|
1052
1148
|
held.view = { ...held.view, state: "stopped", pid: undefined, reason: undefined, lastRefusal: undefined, next: options?.account ? "enable this space for this computer in the dashboard to host its Manager again" : `run \`cotal daemon setup --space ${space}\` to host its Manager again` };
|
|
1149
|
+
held.agents = undefined;
|
|
1053
1150
|
rmSync(refusalFile(space), { force: true });
|
|
1151
|
+
notify();
|
|
1054
1152
|
},
|
|
1055
1153
|
async resume() {
|
|
1056
1154
|
const recordRefusal = (space, error) => {
|
package/dist/daemon/protocol.js
CHANGED
|
@@ -7,15 +7,17 @@
|
|
|
7
7
|
* request id when one could be read. An oversized line closes the connection after its refusal,
|
|
8
8
|
* including an incomplete tail after earlier valid requests. The limit includes the newline.
|
|
9
9
|
*
|
|
10
|
-
* Sign-in streams: `login-start` answers with one `login-prompt` event, then
|
|
11
|
-
* `login-result` event, both tagged with the request id and the attempt id.
|
|
12
|
-
*
|
|
13
|
-
* the
|
|
10
|
+
* Sign-in and status streams: `login-start` answers with one `login-prompt` event, then one
|
|
11
|
+
* `login-result` event, both tagged with the request id and the attempt id. `status-watch` answers
|
|
12
|
+
* with one `status` event immediately and pushes another whenever the watched daemon status changes,
|
|
13
|
+
* until the connection closes. No frame carries a session, token, JWT or device code; the
|
|
14
|
+
* verification URL and user code are the only IdP values the requester sees, because a person must
|
|
15
|
+
* type them.
|
|
14
16
|
*/
|
|
15
17
|
import { computerName } from "./name-validation.js";
|
|
16
18
|
import { normalizeIdpUrl } from "@cotal-ai/auth";
|
|
17
19
|
import { DAEMON_PROTOCOL_VERSION, MAX_LINE_BYTES } from "./endpoint.js";
|
|
18
|
-
const DAEMON_OPS = ["update-settings", "update-check", "name", "daemon-stop", "space-intent", "status", "spaces", "manager-start", "manager-status", "managers-stop", "managers-prepare-restart", "managers-abort-restart", "login-start", "login-cancel", "logout", "connect-check", "register", "service-connect", "service-disconnect", "service-status"];
|
|
20
|
+
const DAEMON_OPS = ["update-settings", "update-check", "name", "daemon-stop", "space-intent", "status", "status-watch", "spaces", "manager-start", "manager-status", "managers-stop", "managers-prepare-restart", "managers-abort-restart", "login-start", "login-cancel", "logout", "connect-check", "register", "service-connect", "service-disconnect", "service-status"];
|
|
19
21
|
/** The fields each op takes besides `v`, `id` and `op`. Required ones must be present. */
|
|
20
22
|
const OP_FIELDS = {
|
|
21
23
|
"update-settings": { required: [], optional: ["auto", "notify"] },
|
|
@@ -24,6 +26,7 @@ const OP_FIELDS = {
|
|
|
24
26
|
"space-intent": { required: ["space", "enabled"], optional: [] },
|
|
25
27
|
name: { required: [], optional: ["name"] },
|
|
26
28
|
status: { required: [], optional: [] },
|
|
29
|
+
"status-watch": { required: [], optional: [] },
|
|
27
30
|
"manager-start": { required: ["space"], optional: [] },
|
|
28
31
|
"manager-status": { required: ["space"], optional: [] },
|
|
29
32
|
"managers-stop": { required: [], optional: [] },
|
|
@@ -109,7 +112,7 @@ export function parseRequest(line) {
|
|
|
109
112
|
return bad(id, "commit must be a boolean");
|
|
110
113
|
return { ok: true, request: { v, id, op, ...(obj.commit !== undefined ? { commit: obj.commit } : {}) } };
|
|
111
114
|
}
|
|
112
|
-
if (op === "status" || op === "managers-stop" || op === "managers-prepare-restart" || op === "managers-abort-restart")
|
|
115
|
+
if (op === "status" || op === "status-watch" || op === "managers-stop" || op === "managers-prepare-restart" || op === "managers-abort-restart")
|
|
113
116
|
return { ok: true, request: { v, id, op } };
|
|
114
117
|
if (op === "login-cancel") {
|
|
115
118
|
if (typeof obj.attempt !== "string" || !ATTEMPT_PATTERN.test(obj.attempt))
|