cotal-ai 0.164.6 → 0.164.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/dist/daemon/install-darwin.js +2 -9
- package/dist/daemon/install-identity.js +50 -0
- package/dist/daemon/install-native-run.js +22 -0
- package/dist/daemon/install-receipt.js +24 -0
- package/dist/daemon/install-win32.js +3 -3
- package/dist/daemon/install-xml.js +10 -0
- package/dist/daemon/install.js +25 -89
- package/dist/daemon/ownership-win32.js +40 -0
- 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 +1 -1
- package/seeded-connectors/claude/dist/mcp.cjs +2 -2
- package/seeded-connectors/claude/package.json +1 -1
- package/seeded-connectors/codex/dist/host.js +2 -2
- package/seeded-connectors/codex/dist/index.js +1 -1
- package/seeded-connectors/codex/dist/personal.js +2 -2
- package/seeded-connectors/codex/package.json +1 -1
- package/seeded-connectors/hermes/dist/index.js +1 -1
- package/seeded-connectors/hermes/dist/launch.js +2 -2
- package/seeded-connectors/hermes/package.json +1 -1
- package/seeded-connectors/hermes/plugin/cotal/_sidecar/standalone.cjs +2 -2
- package/seeded-connectors/jcode/dist/host.js +2 -2
- package/seeded-connectors/jcode/dist/index.js +2 -2
- package/seeded-connectors/jcode/dist/mcp.js +1 -1
- 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 +2 -2
- package/seeded-connectors/opencode/package.json +1 -1
- package/seeded-connectors/pi/dist/index.js +2 -2
- package/seeded-connectors/pi/dist/standalone.js +2 -2
- package/seeded-connectors/pi/package.json +1 -1
- package/seeded-connectors/web/package.json +1 -1
|
@@ -34,15 +34,8 @@ export function launchAgentLabel(daemonHome) {
|
|
|
34
34
|
return "ai.cotal.daemon";
|
|
35
35
|
return `ai.cotal.daemon.${createHash("sha256").update(daemonHome).digest("hex").slice(0, 16)}`;
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
export
|
|
39
|
-
if (!value || value.length > 4096 || /[\u0000-\u001f\u007f]/u.test(value) || [...value].some((scalar) => {
|
|
40
|
-
const cp = scalar.codePointAt(0);
|
|
41
|
-
return cp >= 0xd800 && cp <= 0xdfff || cp === 0xfffe || cp === 0xffff;
|
|
42
|
-
}))
|
|
43
|
-
throw new CommandFailure("refused", "USAGE_INVALID", "the daemon job needs bounded XML text without control or invalid Unicode characters; no job bytes were prepared");
|
|
44
|
-
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
45
|
-
}
|
|
37
|
+
import { xmlText } from "./install-xml.js";
|
|
38
|
+
export { xmlText } from "./install-xml.js";
|
|
46
39
|
/** The plist this install writes. launchd execs `ProgramArguments` directly, with no shell. */
|
|
47
40
|
export function renderLaunchAgent(input) {
|
|
48
41
|
if ([input.argv[0] ?? "", input.workingDirectory, input.logPath].some((path) => !isAbsolute(path)))
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { CommandFailure } from "@cotal-ai/workspace/local-observation";
|
|
3
|
+
/** Whether the verified source carries the installer-owned native launch marker. */
|
|
4
|
+
export function recordedSourceMarked(receipt, mechanism) {
|
|
5
|
+
const source = readFileSync(receipt.unitPath).toString(mechanism === "scheduled-task" ? "utf16le" : "utf8");
|
|
6
|
+
return mechanism === "systemd-user" ? source.includes("Environment=COTAL_DAEMON_NATIVE_SERVICE=1")
|
|
7
|
+
: mechanism === "launchd-agent" ? source.includes("<key>COTAL_DAEMON_NATIVE_SERVICE</key><string>1</string>")
|
|
8
|
+
: source.includes("daemon-native.js") || (source.includes("cotal-desktop.exe</Command>") && source.includes("<Arguments>--daemon"));
|
|
9
|
+
}
|
|
10
|
+
/** Compare the verified source's executable and entry with the caller's immutable launch coordinates. */
|
|
11
|
+
export function recordedSourceIdentity(receipt, mechanism, expected) {
|
|
12
|
+
const bytes = readFileSync(receipt.unitPath);
|
|
13
|
+
const decode = (value) => value.replaceAll("<", "<").replaceAll(">", ">").replaceAll(""", '"').replaceAll("'", "'").replaceAll("&", "&");
|
|
14
|
+
let argv;
|
|
15
|
+
if (mechanism === "systemd-user") {
|
|
16
|
+
const line = /^ExecStart=(.*)$/m.exec(bytes.toString("utf8"))?.[1];
|
|
17
|
+
if (!line)
|
|
18
|
+
throw new CommandFailure("refused", "CONFLICT", "the recorded daemon unit has no readable executable and entry");
|
|
19
|
+
argv = [...line.matchAll(/"((?:\\.|[^"\\])*)"|([^\s"]+)/g)].map(match => (match[1] ?? match[2]).replace(/\\([\\"])/g, "$1").replaceAll("%%", "%").replaceAll("$$", "$"));
|
|
20
|
+
}
|
|
21
|
+
else if (mechanism === "launchd-agent") {
|
|
22
|
+
const array = /<key>ProgramArguments<\/key>\s*<array>([\s\S]*?)<\/array>/.exec(bytes.toString("utf8"))?.[1] ?? "";
|
|
23
|
+
argv = [...array.matchAll(/<string>([^<]*)<\/string>/g)].map(match => decode(match[1]));
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const text = bytes.subarray(2).toString("utf16le");
|
|
27
|
+
const executable = decode(/<Command>([^<]*)<\/Command>/.exec(text)?.[1] ?? "");
|
|
28
|
+
const args = decode(/<Arguments>([^<]*)<\/Arguments>/.exec(text)?.[1] ?? "");
|
|
29
|
+
argv = [executable, ...[...args.matchAll(/"([^"]*)"|(\S+)/g)].map(match => match[1] ?? match[2])];
|
|
30
|
+
}
|
|
31
|
+
const coordinate = (args) => {
|
|
32
|
+
const daemon = args.indexOf("daemon");
|
|
33
|
+
const entry = daemon >= 2 ? args[daemon - 1] : args[0];
|
|
34
|
+
return { executable: args[0], entry };
|
|
35
|
+
};
|
|
36
|
+
const installed = coordinate(argv), current = coordinate(typeof expected === "function" ? expected() : expected);
|
|
37
|
+
if (mechanism === "launchd-agent")
|
|
38
|
+
installed.entry = argv[argv.indexOf("daemon") - 2].replace(/daemon-cwd\.js$/, "cotal.js");
|
|
39
|
+
if (mechanism === "scheduled-task")
|
|
40
|
+
installed.entry = installed.entry.replace(/daemon-native\.js$/, "cotal.js");
|
|
41
|
+
if (!installed.executable || !installed.entry)
|
|
42
|
+
throw new CommandFailure("refused", "CONFLICT", "the recorded daemon installation could not be identified");
|
|
43
|
+
const canonical = (path) => { try {
|
|
44
|
+
return realpathSync(path);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return path;
|
|
48
|
+
} };
|
|
49
|
+
return { same: canonical(installed.executable) === canonical(current.executable) && canonical(installed.entry) === canonical(current.entry), installed: `${installed.executable} ${installed.entry}`, current: `${current.executable} ${current.entry}` };
|
|
50
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
import { CommandFailure } from "@cotal-ai/workspace/local-observation";
|
|
4
|
+
/** Runs one native tool by absolute path with the existing bounds, never through a shell. */
|
|
5
|
+
export function nativeRun(file, args, env) {
|
|
6
|
+
const started = Date.now();
|
|
7
|
+
const result = spawnSync(file, args, { encoding: "utf8", timeout: 30_000, maxBuffer: 256 * 1024, stdio: ["ignore", "pipe", "pipe"], windowsHide: true, ...(env ? { env } : {}) });
|
|
8
|
+
if (result.error || result.signal) {
|
|
9
|
+
const elapsedMs = Date.now() - started;
|
|
10
|
+
const code = result.error?.code;
|
|
11
|
+
const reason = code === "ETIMEDOUT" ? "timed out after 30 s"
|
|
12
|
+
: code === "ENOBUFS" ? "exceeded its 256 KiB output limit"
|
|
13
|
+
: code ? `could not start or complete (${code})`
|
|
14
|
+
: `exited by signal ${result.signal}`;
|
|
15
|
+
throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", `${basename(file)} ${reason} (elapsed ${elapsedMs} ms); no further native step was taken`, {
|
|
16
|
+
native: { code: code ?? result.signal ?? "NATIVE_TOOL_FAILED", detail: { elapsedMs, timeoutMs: 30_000, signal: result.signal } },
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const stdout = typeof result.stdout === "string" ? result.stdout : "";
|
|
20
|
+
const stderr = typeof result.stderr === "string" ? result.stderr : "";
|
|
21
|
+
return { status: result.status, stdout, detail: (stderr.trim() || stdout.trim()).replace(/[\u0000-\u001f\u007f]+/gu, " ").slice(0, 300) };
|
|
22
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
/** Where the receipt lives: beside the lifetime lock, in this daemon's own state directory. */
|
|
4
|
+
export function unitReceiptFile(paths) {
|
|
5
|
+
return join(paths.state, "service-unit.json");
|
|
6
|
+
}
|
|
7
|
+
/** Read the existing installer receipt shape without loading installation commands. */
|
|
8
|
+
export function readReceipt(paths) {
|
|
9
|
+
let o;
|
|
10
|
+
try {
|
|
11
|
+
o = JSON.parse(readFileSync(unitReceiptFile(paths), "utf8"));
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
if (!o || typeof o !== "object")
|
|
17
|
+
return undefined;
|
|
18
|
+
const r = o;
|
|
19
|
+
if (r.v !== 1 || typeof r.unit !== "string" || typeof r.unitPath !== "string" || typeof r.unitSha256 !== "string" || typeof r.installedAt !== "string")
|
|
20
|
+
return undefined;
|
|
21
|
+
if (r.mechanism !== undefined && r.mechanism !== "systemd-user" && r.mechanism !== "launchd-agent" && r.mechanism !== "scheduled-task")
|
|
22
|
+
return undefined;
|
|
23
|
+
return { v: 1, ...(r.mechanism !== undefined ? { mechanism: r.mechanism } : {}), unit: r.unit, unitPath: r.unitPath, unitSha256: r.unitSha256, installedAt: r.installedAt, ...(typeof r.daemonHome === "string" ? { daemonHome: r.daemonHome } : {}) };
|
|
24
|
+
}
|
|
@@ -26,9 +26,9 @@ import { createHash } from "node:crypto";
|
|
|
26
26
|
import { lstatSync, rmSync } from "node:fs";
|
|
27
27
|
import { homedir, userInfo } from "node:os";
|
|
28
28
|
import { basename, join, win32 } from "node:path";
|
|
29
|
-
import { writeSecretFileCreateOnly } from "@cotal-ai/core";
|
|
30
|
-
import { CommandFailure, readLocalRecordSource } from "@cotal-ai/workspace";
|
|
31
|
-
import { xmlText } from "./install-
|
|
29
|
+
import { writeSecretFileCreateOnly } from "@cotal-ai/core/secret-fs";
|
|
30
|
+
import { CommandFailure, readLocalRecordSource } from "@cotal-ai/workspace/local-observation";
|
|
31
|
+
import { xmlText } from "./install-xml.js";
|
|
32
32
|
/** A System32 tool, resolved from the Windows directory and never from `PATH`. */
|
|
33
33
|
function system32(...segments) {
|
|
34
34
|
return join(process.env.SystemRoot || process.env.windir || "C:\\Windows", "System32", ...segments);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CommandFailure } from "@cotal-ai/workspace/local-observation";
|
|
2
|
+
/** XML character data: bounded, without controls or code points XML cannot carry, and escaped. */
|
|
3
|
+
export function xmlText(value) {
|
|
4
|
+
if (!value || value.length > 4096 || /[\u0000-\u001f\u007f]/u.test(value) || [...value].some((scalar) => {
|
|
5
|
+
const cp = scalar.codePointAt(0);
|
|
6
|
+
return cp >= 0xd800 && cp <= 0xdfff || cp === 0xfffe || cp === 0xffff;
|
|
7
|
+
}))
|
|
8
|
+
throw new CommandFailure("refused", "USAGE_INVALID", "the daemon job needs bounded XML text without control or invalid Unicode characters; no job bytes were prepared");
|
|
9
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
10
|
+
}
|
package/dist/daemon/install.js
CHANGED
|
@@ -31,8 +31,11 @@
|
|
|
31
31
|
*/
|
|
32
32
|
import { spawnSync } from "node:child_process";
|
|
33
33
|
import { createHash } from "node:crypto";
|
|
34
|
-
import { existsSync, lstatSync, mkdirSync, readFileSync,
|
|
35
|
-
import {
|
|
34
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, rmSync } from "node:fs";
|
|
35
|
+
import { delimiter, dirname, isAbsolute, join, posix } from "node:path";
|
|
36
|
+
import { recordedSourceIdentity, recordedSourceMarked } from "./install-identity.js";
|
|
37
|
+
import { nativeRun } from "./install-native-run.js";
|
|
38
|
+
import { checkWindowsRecordedUnit } from "./ownership-win32.js";
|
|
36
39
|
import { Worker } from "node:worker_threads";
|
|
37
40
|
import { setTimeout as delay } from "node:timers/promises";
|
|
38
41
|
import { randomUUID } from "node:crypto";
|
|
@@ -49,10 +52,8 @@ import { scheduledTaskName, scheduledTaskService } from "./install-win32.js";
|
|
|
49
52
|
import { daemonCommandCopy } from "./guidance.js";
|
|
50
53
|
import { recoverPausedTask } from "./restart-recovery.js";
|
|
51
54
|
import { removeAllServiceRecords } from "./service-records.js";
|
|
52
|
-
|
|
53
|
-
export
|
|
54
|
-
return join(paths.state, "service-unit.json");
|
|
55
|
-
}
|
|
55
|
+
import { readReceipt, unitReceiptFile } from "./install-receipt.js";
|
|
56
|
+
export { unitReceiptFile } from "./install-receipt.js";
|
|
56
57
|
/** `cotal-daemon.service`, or `cotal-daemon-<16 hex>.service` for an explicit daemon home, derived
|
|
57
58
|
* the same way its socket directory is so the two always agree. */
|
|
58
59
|
export function daemonUnitName(daemonHome) {
|
|
@@ -60,23 +61,6 @@ export function daemonUnitName(daemonHome) {
|
|
|
60
61
|
return "cotal-daemon.service";
|
|
61
62
|
return `cotal-daemon-${createHash("sha256").update(daemonHome).digest("hex").slice(0, 16)}.service`;
|
|
62
63
|
}
|
|
63
|
-
function readReceipt(paths) {
|
|
64
|
-
let o;
|
|
65
|
-
try {
|
|
66
|
-
o = JSON.parse(readFileSync(unitReceiptFile(paths), "utf8"));
|
|
67
|
-
}
|
|
68
|
-
catch {
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
71
|
-
if (!o || typeof o !== "object")
|
|
72
|
-
return undefined;
|
|
73
|
-
const r = o;
|
|
74
|
-
if (r.v !== 1 || typeof r.unit !== "string" || typeof r.unitPath !== "string" || typeof r.unitSha256 !== "string" || typeof r.installedAt !== "string")
|
|
75
|
-
return undefined;
|
|
76
|
-
if (r.mechanism !== undefined && r.mechanism !== "systemd-user" && r.mechanism !== "launchd-agent" && r.mechanism !== "scheduled-task")
|
|
77
|
-
return undefined;
|
|
78
|
-
return { v: 1, ...(r.mechanism !== undefined ? { mechanism: r.mechanism } : {}), unit: r.unit, unitPath: r.unitPath, unitSha256: r.unitSha256, installedAt: r.installedAt, ...(typeof r.daemonHome === "string" ? { daemonHome: r.daemonHome } : {}) };
|
|
79
|
-
}
|
|
80
64
|
function writeReceipt(paths, receipt) {
|
|
81
65
|
writeSecretFile(unitReceiptFile(paths), `${JSON.stringify(receipt)}\n`);
|
|
82
66
|
}
|
|
@@ -166,24 +150,6 @@ export function assertScheduledEntry(entry) {
|
|
|
166
150
|
if (!file)
|
|
167
151
|
throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", `the scheduled task entry is missing or is not a file: ${entry}; no task was prepared`, { remedy: "repair or reinstall this Cotal installation before running \`cotal daemon install\` again" });
|
|
168
152
|
}
|
|
169
|
-
function nativeRun(file, args, env) {
|
|
170
|
-
const started = Date.now();
|
|
171
|
-
const result = spawnSync(file, args, { encoding: "utf8", timeout: 30_000, maxBuffer: 256 * 1024, stdio: ["ignore", "pipe", "pipe"], windowsHide: true, ...(env ? { env } : {}) });
|
|
172
|
-
if (result.error || result.signal) {
|
|
173
|
-
const elapsedMs = Date.now() - started;
|
|
174
|
-
const code = result.error?.code;
|
|
175
|
-
const reason = code === "ETIMEDOUT" ? "timed out after 30 s"
|
|
176
|
-
: code === "ENOBUFS" ? "exceeded its 256 KiB output limit"
|
|
177
|
-
: code ? `could not start or complete (${code})`
|
|
178
|
-
: `exited by signal ${result.signal}`;
|
|
179
|
-
throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", `${basename(file)} ${reason} (elapsed ${elapsedMs} ms); no further native step was taken`, {
|
|
180
|
-
native: { code: code ?? result.signal ?? "NATIVE_TOOL_FAILED", detail: { elapsedMs, timeoutMs: 30_000, signal: result.signal } },
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
const stdout = typeof result.stdout === "string" ? result.stdout : "";
|
|
184
|
-
const stderr = typeof result.stderr === "string" ? result.stderr : "";
|
|
185
|
-
return { status: result.status, stdout, detail: (stderr.trim() || stdout.trim()).replace(/[\u0000-\u001f\u007f]+/gu, " ").slice(0, 300) };
|
|
186
|
-
}
|
|
187
153
|
/** This OS's per-user supervisor, or `undefined` on Linux, whose systemd route is below. */
|
|
188
154
|
function nativeService() {
|
|
189
155
|
if (process.platform === "linux")
|
|
@@ -303,14 +269,16 @@ function recordedUnit(paths, daemonHome) {
|
|
|
303
269
|
const mechanism = receipt.mechanism ?? "systemd-user";
|
|
304
270
|
if (mechanism !== (service ? service.mechanism : "systemd-user"))
|
|
305
271
|
throw new CommandFailure("refused", "CONFLICT", `the recorded unit ${receipt.unit} is a ${mechanism} unit, which this OS does not run; nothing was removed`);
|
|
272
|
+
if (process.platform === "win32") {
|
|
273
|
+
checkWindowsRecordedUnit(paths, receipt, service);
|
|
274
|
+
return { receipt, plan: { mechanism, unit: receipt.unit, unitPath: receipt.unitPath, installedAt: receipt.installedAt }, service };
|
|
275
|
+
}
|
|
306
276
|
try {
|
|
307
277
|
lstatSync(receipt.unitPath);
|
|
308
278
|
}
|
|
309
279
|
catch {
|
|
310
280
|
throw new CommandFailure("refused", "TARGET_NOT_FOUND", `the recorded unit file ${receipt.unitPath} is gone; nothing was removed. Delete ${unitReceiptFile(paths)} by hand to forget it`);
|
|
311
281
|
}
|
|
312
|
-
if (mechanism === "scheduled-task" && receipt.unitPath !== join(paths.state, "service-task.xml"))
|
|
313
|
-
throw new CommandFailure("refused", "CONFLICT", "the scheduled-task receipt names a definition outside this daemon state; nothing was changed");
|
|
314
282
|
if (service)
|
|
315
283
|
service.check(receipt);
|
|
316
284
|
else {
|
|
@@ -402,46 +370,7 @@ export function installedDaemonIdentity(paths, daemonHome) {
|
|
|
402
370
|
return recordedDaemonIdentity(recordedUnit(paths, daemonHome));
|
|
403
371
|
}
|
|
404
372
|
function recordedDaemonIdentity({ receipt, plan }) {
|
|
405
|
-
|
|
406
|
-
const decode = (value) => value.replaceAll("<", "<").replaceAll(">", ">").replaceAll(""", '"').replaceAll("'", "'").replaceAll("&", "&");
|
|
407
|
-
let argv;
|
|
408
|
-
if (plan.mechanism === "systemd-user") {
|
|
409
|
-
const line = /^ExecStart=(.*)$/m.exec(bytes.toString("utf8"))?.[1];
|
|
410
|
-
if (!line)
|
|
411
|
-
throw new CommandFailure("refused", "CONFLICT", "the recorded daemon unit has no readable executable and entry");
|
|
412
|
-
argv = [...line.matchAll(/"((?:\\.|[^"\\])*)"|([^\s"]+)/g)].map(match => (match[1] ?? match[2]).replace(/\\([\\"])/g, "$1").replaceAll("%%", "%").replaceAll("$$", "$"));
|
|
413
|
-
}
|
|
414
|
-
else if (plan.mechanism === "launchd-agent") {
|
|
415
|
-
const array = /<key>ProgramArguments<\/key>\s*<array>([\s\S]*?)<\/array>/.exec(bytes.toString("utf8"))?.[1] ?? "";
|
|
416
|
-
argv = [...array.matchAll(/<string>([^<]*)<\/string>/g)].map(match => decode(match[1]));
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
const text = bytes.subarray(2).toString("utf16le");
|
|
420
|
-
const executable = decode(/<Command>([^<]*)<\/Command>/.exec(text)?.[1] ?? "");
|
|
421
|
-
const args = decode(/<Arguments>([^<]*)<\/Arguments>/.exec(text)?.[1] ?? "");
|
|
422
|
-
argv = [executable, ...[...args.matchAll(/"([^"]*)"|(\S+)/g)].map(match => match[1] ?? match[2])];
|
|
423
|
-
}
|
|
424
|
-
const expected = daemonServeArgv(receipt.daemonHome);
|
|
425
|
-
const coordinate = (args) => {
|
|
426
|
-
const daemon = args.indexOf("daemon");
|
|
427
|
-
const entry = daemon >= 2 ? args[daemon - 1] : args[0];
|
|
428
|
-
return { executable: args[0], entry };
|
|
429
|
-
};
|
|
430
|
-
const installed = coordinate(argv), current = coordinate(expected);
|
|
431
|
-
// launchd pins the adjacent cwd bootstrap instead of cotal.js itself.
|
|
432
|
-
if (plan.mechanism === "launchd-agent")
|
|
433
|
-
installed.entry = argv[argv.indexOf("daemon") - 2].replace(/daemon-cwd\.js$/, "cotal.js");
|
|
434
|
-
if (plan.mechanism === "scheduled-task")
|
|
435
|
-
installed.entry = installed.entry.replace(/daemon-native\.js$/, "cotal.js");
|
|
436
|
-
if (!installed.executable || !installed.entry)
|
|
437
|
-
throw new CommandFailure("refused", "CONFLICT", "the recorded daemon installation could not be identified");
|
|
438
|
-
const canonical = (path) => { try {
|
|
439
|
-
return realpathSync(path);
|
|
440
|
-
}
|
|
441
|
-
catch {
|
|
442
|
-
return path;
|
|
443
|
-
} };
|
|
444
|
-
return { same: canonical(installed.executable) === canonical(current.executable) && canonical(installed.entry) === canonical(current.entry), installed: `${installed.executable} ${installed.entry}`, current: `${current.executable} ${current.entry}` };
|
|
373
|
+
return recordedSourceIdentity(receipt, plan.mechanism, () => daemonServeArgv(receipt.daemonHome));
|
|
445
374
|
}
|
|
446
375
|
/** A native launch marker is trusted only with this installation's verified recorded source. */
|
|
447
376
|
export function daemonStartedByOwnedService(paths, daemonHome) {
|
|
@@ -452,10 +381,7 @@ export function daemonStartedByOwnedService(paths, daemonHome) {
|
|
|
452
381
|
if (!recordedDaemonIdentity(recorded).same)
|
|
453
382
|
return { state: "not-owned", reason: "identity-differs" };
|
|
454
383
|
const { receipt, plan } = recorded;
|
|
455
|
-
const
|
|
456
|
-
const marked = plan.mechanism === "systemd-user" ? source.includes("Environment=COTAL_DAEMON_NATIVE_SERVICE=1")
|
|
457
|
-
: plan.mechanism === "launchd-agent" ? source.includes("<key>COTAL_DAEMON_NATIVE_SERVICE</key><string>1</string>")
|
|
458
|
-
: source.includes("daemon-native.js") || (source.includes("cotal-desktop.exe</Command>") && source.includes("<Arguments>--daemon"));
|
|
384
|
+
const marked = recordedSourceMarked(receipt, plan.mechanism);
|
|
459
385
|
return marked ? { state: "owned", reason: "verified" } : { state: "not-owned", reason: "source-marker-absent" };
|
|
460
386
|
}
|
|
461
387
|
catch {
|
|
@@ -484,12 +410,22 @@ export function observeDaemonOwnedService(paths, daemonHome, signal) {
|
|
|
484
410
|
return new Promise(resolve => {
|
|
485
411
|
// Reuse the installer's exact source, identity and native-job checks. The worker's
|
|
486
412
|
// default argv names this helper, so explicitly preserve the daemon's launch vector.
|
|
413
|
+
let expected;
|
|
414
|
+
if (process.platform === "win32") {
|
|
415
|
+
try {
|
|
416
|
+
expected = daemonServeArgv(daemonHome);
|
|
417
|
+
}
|
|
418
|
+
catch {
|
|
419
|
+
resolve({ state: "unknown", reason: "observation-failed" });
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
487
423
|
const worker = new Worker(`
|
|
488
424
|
const { parentPort, workerData } = require('node:worker_threads');
|
|
489
425
|
process.argv = workerData.argv;
|
|
490
426
|
process.execArgv = workerData.execArgv;
|
|
491
|
-
import(workerData.module).then(m => parentPort.postMessage(m.daemonStartedByOwnedService(workerData.paths, workerData.home))).catch(() => parentPort.postMessage({ state: 'unknown', reason: 'worker-failed' }));
|
|
492
|
-
`, { eval: true, workerData: { module: import.meta.url, paths, home: daemonHome, argv: process.argv, execArgv: process.execArgv }, stdout: true, stderr: true });
|
|
427
|
+
import(workerData.module).then(m => parentPort.postMessage(workerData.expected ? m.observeWindowsOwnedService(workerData.paths, workerData.expected) : m.daemonStartedByOwnedService(workerData.paths, workerData.home))).catch(() => parentPort.postMessage({ state: 'unknown', reason: 'worker-failed' }));
|
|
428
|
+
`, { eval: true, workerData: { module: expected ? new URL("./ownership-win32.js", import.meta.url).href : import.meta.url, expected, paths, home: daemonHome, argv: process.argv, execArgv: process.execArgv }, stdout: true, stderr: true });
|
|
493
429
|
worker.stdout.resume();
|
|
494
430
|
worker.stderr.resume();
|
|
495
431
|
let settled = false;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { lstatSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { CommandFailure } from "@cotal-ai/workspace/local-observation";
|
|
4
|
+
import { scheduledTaskService } from "./install-win32.js";
|
|
5
|
+
import { nativeRun } from "./install-native-run.js";
|
|
6
|
+
import { recordedSourceIdentity, recordedSourceMarked } from "./install-identity.js";
|
|
7
|
+
import { readReceipt, unitReceiptFile } from "./install-receipt.js";
|
|
8
|
+
/** The Windows receipt and registered job checks shared by installer and observer. */
|
|
9
|
+
export function checkWindowsRecordedUnit(paths, receipt, service) {
|
|
10
|
+
const mechanism = receipt.mechanism ?? "systemd-user";
|
|
11
|
+
if (mechanism !== "scheduled-task")
|
|
12
|
+
throw new CommandFailure("refused", "CONFLICT", `the recorded unit ${receipt.unit} is a ${mechanism} unit, which this OS does not run; nothing was removed`);
|
|
13
|
+
try {
|
|
14
|
+
lstatSync(receipt.unitPath);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
throw new CommandFailure("refused", "TARGET_NOT_FOUND", `the recorded unit file ${receipt.unitPath} is gone; nothing was removed. Delete ${unitReceiptFile(paths)} by hand to forget it`);
|
|
18
|
+
}
|
|
19
|
+
if (receipt.unitPath !== join(paths.state, "service-task.xml"))
|
|
20
|
+
throw new CommandFailure("refused", "CONFLICT", "the scheduled-task receipt names a definition outside this daemon state; nothing was changed");
|
|
21
|
+
service.check(receipt);
|
|
22
|
+
}
|
|
23
|
+
/** Fresh Windows provenance through the installer's exact receipt, source, task and identity checks. */
|
|
24
|
+
export function observeWindowsOwnedService(paths, expected) {
|
|
25
|
+
if (process.env.COTAL_DAEMON_NATIVE_SERVICE !== "1")
|
|
26
|
+
return { state: "not-owned", reason: "marker-absent" };
|
|
27
|
+
try {
|
|
28
|
+
const receipt = readReceipt(paths);
|
|
29
|
+
if (!receipt)
|
|
30
|
+
throw new CommandFailure("refused", "TARGET_NOT_FOUND", "this daemon has no installed unit recorded by `cotal daemon install`; nothing was removed");
|
|
31
|
+
checkWindowsRecordedUnit(paths, receipt, scheduledTaskService(nativeRun));
|
|
32
|
+
if (!recordedSourceIdentity(receipt, "scheduled-task", expected).same)
|
|
33
|
+
return { state: "not-owned", reason: "identity-differs" };
|
|
34
|
+
const marked = recordedSourceMarked(receipt, "scheduled-task");
|
|
35
|
+
return marked ? { state: "owned", reason: "verified" } : { state: "not-owned", reason: "source-marker-absent" };
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return { state: "unknown", reason: "observation-failed" };
|
|
39
|
+
}
|
|
40
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cotal-ai",
|
|
3
|
-
"version": "0.164.
|
|
3
|
+
"version": "0.164.7",
|
|
4
4
|
"description": "Cotal — lateral agent coordination over NATS. Run `npx cotal-ai` for the CLI.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -33,28 +33,28 @@
|
|
|
33
33
|
"node": ">=22.10"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@cotal-ai/auth": "0.164.
|
|
37
|
-
"@cotal-ai/cli": "0.164.
|
|
38
|
-
"@cotal-ai/connector-core": "0.164.
|
|
39
|
-
"@cotal-ai/core": "0.164.
|
|
40
|
-
"@cotal-ai/delivery": "0.164.
|
|
41
|
-
"@cotal-ai/manager": "0.164.
|
|
42
|
-
"@cotal-ai/registry": "0.164.
|
|
43
|
-
"@cotal-ai/runtime": "0.164.
|
|
44
|
-
"@cotal-ai/seat": "0.164.
|
|
45
|
-
"@cotal-ai/workspace": "0.164.
|
|
36
|
+
"@cotal-ai/auth": "0.164.7",
|
|
37
|
+
"@cotal-ai/cli": "0.164.7",
|
|
38
|
+
"@cotal-ai/connector-core": "0.164.7",
|
|
39
|
+
"@cotal-ai/core": "0.164.7",
|
|
40
|
+
"@cotal-ai/delivery": "0.164.7",
|
|
41
|
+
"@cotal-ai/manager": "0.164.7",
|
|
42
|
+
"@cotal-ai/registry": "0.164.7",
|
|
43
|
+
"@cotal-ai/runtime": "0.164.7",
|
|
44
|
+
"@cotal-ai/seat": "0.164.7",
|
|
45
|
+
"@cotal-ai/workspace": "0.164.7",
|
|
46
46
|
"jose": "^6.2.3"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@cotal-ai/connector-claude-code": "0.164.
|
|
50
|
-
"@cotal-ai/connector-codex": "0.164.
|
|
51
|
-
"@cotal-ai/connector-hermes": "0.164.
|
|
52
|
-
"@cotal-ai/connector-jcode": "0.164.
|
|
53
|
-
"@cotal-ai/connector-opencode": "0.164.
|
|
54
|
-
"@cotal-ai/linear": "0.164.
|
|
55
|
-
"@cotal-ai/pi": "0.164.
|
|
49
|
+
"@cotal-ai/connector-claude-code": "0.164.7",
|
|
50
|
+
"@cotal-ai/connector-codex": "0.164.7",
|
|
51
|
+
"@cotal-ai/connector-hermes": "0.164.7",
|
|
52
|
+
"@cotal-ai/connector-jcode": "0.164.7",
|
|
53
|
+
"@cotal-ai/connector-opencode": "0.164.7",
|
|
54
|
+
"@cotal-ai/linear": "0.164.7",
|
|
55
|
+
"@cotal-ai/pi": "0.164.7",
|
|
56
56
|
"@cotal-ai/smoke-kit": "0.0.0",
|
|
57
|
-
"@cotal-ai/web": "0.164.
|
|
57
|
+
"@cotal-ai/web": "0.164.7",
|
|
58
58
|
"@nats-io/jetstream": "^3.4.0",
|
|
59
59
|
"@nats-io/transport-node": "^3.4.0",
|
|
60
60
|
"typescript": "^5.9.3"
|
|
Binary file
|
|
Binary file
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"v": 1,
|
|
3
3
|
"files": {
|
|
4
|
-
"docs-bundle.bin": "
|
|
5
|
-
"docs-index.bin": "
|
|
4
|
+
"docs-bundle.bin": "b335e77856e098f0816c3c680a431888a40c5710c5dd7fa6b87041b26a1cdb85",
|
|
5
|
+
"docs-index.bin": "d8cb7995ac02f7a305ce098b2ab396f6a30a75d34c4209c6def90dff8940c09e"
|
|
6
6
|
},
|
|
7
7
|
"placements": {
|
|
8
8
|
"claude": [
|