cotal-ai 0.164.17 → 0.164.18
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/cotal.js +118 -7
- package/dist/daemon/auto-update.js +10 -4
- package/dist/daemon/execution-preinstall.js +4 -2
- package/dist/daemon/execution-update.js +19 -11
- package/dist/daemon/update-entry.js +26 -3
- package/dist/daemon/update-launchd-runner.js +1 -1
- package/dist/daemon/update-launchd.js +4 -2
- package/dist/execution-store.js +32 -6
- package/dist/execution-transaction.js +16 -6
- 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 +1 -1
- 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
package/dist/cotal.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
|
-
import { closeSync, constants, existsSync, fstatSync, lstatSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync } from "node:fs";
|
|
4
|
-
import {
|
|
3
|
+
import { chmodSync, closeSync, constants, cpSync, existsSync, fstatSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, rmSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
5
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
7
|
import { setFlagsFromString } from "node:v8";
|
|
7
8
|
setFlagsFromString("--no-maglev");
|
|
@@ -44,6 +45,52 @@ export function protectedExecutionEntry(path) {
|
|
|
44
45
|
typeof process.getuid !== "function" || (info.uid !== process.getuid() && info.uid !== 0)))
|
|
45
46
|
throw new Error(`unprotected execution entry: ${path}`);
|
|
46
47
|
}
|
|
48
|
+
/** The installed package folder and the folders above it belong to the package manager. An account
|
|
49
|
+
* that can write one of them can already replace this bootstrap, so their modes are no boundary:
|
|
50
|
+
* Homebrew keeps `lib` group-writable, and npm under a umask of 0002 creates the package
|
|
51
|
+
* group-writable. Only another account's ownership is refused. */
|
|
52
|
+
export function executionLocation(path) {
|
|
53
|
+
const info = lstatSync(path);
|
|
54
|
+
if (process.platform !== "win32" && (typeof process.getuid !== "function" || (info.uid !== process.getuid() && info.uid !== 0)))
|
|
55
|
+
throw new Error(`execution location belongs to another account: ${path}`);
|
|
56
|
+
}
|
|
57
|
+
/** Whether accounts other than the owner run this installation: they can read and search its
|
|
58
|
+
* package folder. The generation store beside it is then as readable as the package, and never
|
|
59
|
+
* writable by them. */
|
|
60
|
+
export function executionShared(installed) {
|
|
61
|
+
return process.platform !== "win32" && (lstatSync(installed).mode & 0o005) === 0o005;
|
|
62
|
+
}
|
|
63
|
+
const PUBLISHED = /\n\/\/ cotal execution publication [a-f0-9]{32}\n$/;
|
|
64
|
+
/** 0.164.16 and 0.164.17 kept the store, its records and the published bootstrap private to the
|
|
65
|
+
* updating account, which locked every other account out of a system-wide installation. The
|
|
66
|
+
* store's owner opens them for reading here. */
|
|
67
|
+
function shareExecutionStore(installed) {
|
|
68
|
+
try {
|
|
69
|
+
if (typeof process.getuid !== "function" || !executionShared(installed))
|
|
70
|
+
return;
|
|
71
|
+
const store = executionStore(installed), info = lstatSync(store, { throwIfNoEntry: false });
|
|
72
|
+
if (!info?.isDirectory() || info.uid !== process.getuid() || (info.mode & 0o005) === 0o005)
|
|
73
|
+
return;
|
|
74
|
+
const open = (path, directory) => {
|
|
75
|
+
const entry = lstatSync(path, { throwIfNoEntry: false });
|
|
76
|
+
if (entry && (directory ? entry.isDirectory() : entry.isFile()))
|
|
77
|
+
chmodSync(path, directory ? 0o755 : 0o644);
|
|
78
|
+
};
|
|
79
|
+
for (const name of readdirSync(store)) {
|
|
80
|
+
if (ID.test(name)) {
|
|
81
|
+
open(join(store, name), true);
|
|
82
|
+
open(join(store, name, "inventory.json"), false);
|
|
83
|
+
}
|
|
84
|
+
else if (/^\.active-[a-f0-9]{64}\.json$/.test(name))
|
|
85
|
+
open(join(store, name), false);
|
|
86
|
+
}
|
|
87
|
+
const bootstrap = join(installed, "dist", "cotal.js");
|
|
88
|
+
if (PUBLISHED.test(readFileSync(bootstrap, "utf8")))
|
|
89
|
+
chmodSync(bootstrap, 0o755);
|
|
90
|
+
chmodSync(store, 0o755);
|
|
91
|
+
}
|
|
92
|
+
catch { /* the store stays private to its owner, as it was */ }
|
|
93
|
+
}
|
|
47
94
|
export function executionBinding(root) {
|
|
48
95
|
const meta = object(JSON.parse(readFileSync(join(root, "package.json"), "utf8")));
|
|
49
96
|
if (meta.name !== "cotal-ai" || typeof meta.version !== "string" || !meta.version)
|
|
@@ -107,12 +154,18 @@ export function selectExecutionProgram(root) {
|
|
|
107
154
|
throw new Error("retained execution generations are unavailable on the desktop runtime");
|
|
108
155
|
return initial();
|
|
109
156
|
}
|
|
157
|
+
shareExecutionStore(installed);
|
|
110
158
|
let value;
|
|
111
159
|
try {
|
|
112
160
|
value = executionRecord(descriptorPath);
|
|
113
161
|
}
|
|
114
162
|
catch (error) {
|
|
115
|
-
|
|
163
|
+
const code = error.code;
|
|
164
|
+
if (code === "ENOENT")
|
|
165
|
+
return initial();
|
|
166
|
+
// Another account's store that this account cannot read. A bootstrap the package manager
|
|
167
|
+
// installed carries no publication line, and no descriptor selects a generation for it.
|
|
168
|
+
if ((code === "EACCES" || code === "EPERM") && !PUBLISHED.test(readFileSync(join(installed, "dist", "cotal.js"), "utf8")))
|
|
116
169
|
return initial();
|
|
117
170
|
throw error;
|
|
118
171
|
}
|
|
@@ -148,9 +201,8 @@ export function selectExecutionProgram(root) {
|
|
|
148
201
|
if (typeof generation.id !== "string" || !ID.test(generation.id) || typeof generation.version !== "string" ||
|
|
149
202
|
typeof generation.inventorySha256 !== "string" || !HASH.test(generation.inventorySha256))
|
|
150
203
|
throw new Error("invalid retained execution identity");
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
protectedExecutionEntry(ancestor);
|
|
204
|
+
for (const path of [installed, dirname(installed), dirname(dirname(installed)), dirname(dirname(dirname(installed)))])
|
|
205
|
+
executionLocation(path);
|
|
154
206
|
const store = executionStore(installed), container = join(store, generation.id), selected = join(container, "cotal-ai");
|
|
155
207
|
for (const path of [store, container, selected]) {
|
|
156
208
|
const info = lstatSync(path);
|
|
@@ -175,14 +227,73 @@ const executionStarted = Symbol.for("cotal.execution.started");
|
|
|
175
227
|
function startedHere() {
|
|
176
228
|
return !!process.argv[1] && realpathSync.native(process.argv[1]) === realpathSync.native(fileURLToPath(import.meta.url));
|
|
177
229
|
}
|
|
230
|
+
/** Set by an updater that gives its retained copy explicit modes. */
|
|
231
|
+
export const executionCopyModesEnv = "COTAL_EXECUTION_COPY_MODES";
|
|
232
|
+
/** Whether this Node applies the process umask to the folders a recursive `cpSync` creates, as Node
|
|
233
|
+
* before 24.22 does, and that umask leaves group or other write. */
|
|
234
|
+
function copiesSharedWrite() {
|
|
235
|
+
const umask = process.umask(0o022);
|
|
236
|
+
process.umask(umask);
|
|
237
|
+
if ((umask & 0o022) === 0o022)
|
|
238
|
+
return false;
|
|
239
|
+
let scratch;
|
|
240
|
+
try {
|
|
241
|
+
scratch = mkdtempSync(join(tmpdir(), "cotal-copy-probe-"));
|
|
242
|
+
mkdirSync(join(scratch, "from"), { mode: 0o700 });
|
|
243
|
+
cpSync(join(scratch, "from"), join(scratch, "to"), { recursive: true });
|
|
244
|
+
return (lstatSync(join(scratch, "to")).mode & 0o022) !== 0;
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
finally {
|
|
250
|
+
if (scratch)
|
|
251
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/** The 0.164.16 and 0.164.17 updaters start the staged target once for its version line, then copy
|
|
255
|
+
* it with `cpSync`, refuse a copy with group-writable folders, and read the daemon's paths, which
|
|
256
|
+
* throws on Linux without `XDG_RUNTIME_DIR`. Where either holds they refuse every attempt and leave
|
|
257
|
+
* what they staged behind. This target cannot change that process, so it names the one-time manual
|
|
258
|
+
* install, removes the staged installs and fails the version check. Returns whether it did. */
|
|
259
|
+
function refuseDoomedStagedCheck(root) {
|
|
260
|
+
if (process.platform === "win32" || process.argv.length !== 3 || process.argv[2] !== "--version" ||
|
|
261
|
+
process.env.COTAL_SKIP_CONNECTOR_SEED !== "1" || process.env[executionCopyModesEnv] === "explicit")
|
|
262
|
+
return false;
|
|
263
|
+
const prefix = dirname(dirname(dirname(root))), store = dirname(prefix);
|
|
264
|
+
if (basename(dirname(root)) !== "node_modules" || basename(dirname(dirname(root))) !== "lib" ||
|
|
265
|
+
!/^\.installing-[A-Za-z0-9]{6}$/.test(basename(prefix)) || basename(store) !== ".cotal-generations")
|
|
266
|
+
return false;
|
|
267
|
+
const reason = process.platform === "linux" && !process.env.XDG_RUNTIME_DIR ? "it needs XDG_RUNTIME_DIR, which this session does not set"
|
|
268
|
+
: copiesSharedWrite() ? "its Node copies the new version with group-writable folders under the current umask, then refuses its own copy" : undefined;
|
|
269
|
+
if (!reason)
|
|
270
|
+
return false;
|
|
271
|
+
const home = dirname(dirname(store));
|
|
272
|
+
const remedy = existsSync(join(home, "nodebin"))
|
|
273
|
+
? "run the installer from get.cotal.ai again"
|
|
274
|
+
: `run npm install -g --prefix ${home} cotal-ai@latest`;
|
|
275
|
+
process.stderr.write(`the installed Cotal updater cannot finish here: ${reason}. Install the new version once by hand: ${remedy}. Later updates run on their own`);
|
|
276
|
+
for (const name of readdirSync(store)) {
|
|
277
|
+
if (/^\.installing-[A-Za-z0-9]{6}$/.test(name))
|
|
278
|
+
try {
|
|
279
|
+
rmSync(join(store, name), { recursive: true, force: true });
|
|
280
|
+
}
|
|
281
|
+
catch { /* the next attempt removes it */ }
|
|
282
|
+
}
|
|
283
|
+
process.exitCode = 1;
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
178
286
|
/** Explicit CLI delegation for a wrapper that imports the bootstrap rather than launching it. */
|
|
179
287
|
export function startExecutionProgram() {
|
|
180
288
|
if (Reflect.get(globalThis, executionStarted))
|
|
181
289
|
return;
|
|
182
290
|
Object.defineProperty(globalThis, executionStarted, { value: true });
|
|
183
291
|
let selected;
|
|
292
|
+
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), import.meta.url.endsWith(".ts") ? "." : "..");
|
|
293
|
+
if (startedHere() && refuseDoomedStagedCheck(realpathSync.native(packageRoot)))
|
|
294
|
+
return;
|
|
184
295
|
try {
|
|
185
|
-
selected = selectExecutionProgram(
|
|
296
|
+
selected = selectExecutionProgram(packageRoot);
|
|
186
297
|
}
|
|
187
298
|
catch (error) {
|
|
188
299
|
process.stderr.write(`${error instanceof Error ? error.message : String(error)}; reinstall with npm install -g cotal-ai@latest\n`);
|
|
@@ -3,7 +3,7 @@ import { readFileSync, existsSync, closeSync, ftruncateSync } from "node:fs";
|
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { openPrivateAppend, writeSecretFileAtomic } from "@cotal-ai/core";
|
|
6
|
-
import { checkForUpdate, homeCotalDir, loadExtensionsManifest, newerUpdate, readUpdateCheck, readUpdateRecovery, readUpdateSettings, recoveryDisposition, UPDATE_DAY_MS, UPDATE_HOUR_MS } from "@cotal-ai/workspace";
|
|
6
|
+
import { checkForUpdate, homeCotalDir, loadExtensionsManifest, logicalExecutionEntry, newerUpdate, readUpdateCheck, readUpdateRecovery, readUpdateSettings, recoveryDisposition, UPDATE_DAY_MS, UPDATE_HOUR_MS } from "@cotal-ai/workspace";
|
|
7
7
|
import { cleanWindowsUpdate, startWindowsUpdate } from "./update-windows.js";
|
|
8
8
|
import { WINDOWS_INTERRUPTED_UPDATE, readWindowsUpdatePause } from "@cotal-ai/workspace";
|
|
9
9
|
import { cleanLaunchUpdate, startLaunchUpdate } from "./update-launchd.js";
|
|
@@ -217,11 +217,14 @@ export function automaticUpdates(host) {
|
|
|
217
217
|
}
|
|
218
218
|
return;
|
|
219
219
|
}
|
|
220
|
-
|
|
220
|
+
const updating = state.result;
|
|
221
|
+
const ended = await new Promise(resolve => {
|
|
221
222
|
const logPath = join(homeCotalDir(), "update-attempt.log");
|
|
222
223
|
const outputFd = openPrivateAppend(logPath);
|
|
223
224
|
ftruncateSync(outputFd, 0);
|
|
224
|
-
|
|
225
|
+
// A daemon loaded from a retained generation starts the updater at the installed entry: the
|
|
226
|
+
// generation's own bootstrap is not an installation, and its updater refuses to stage from it.
|
|
227
|
+
child = spawn(process.execPath, [logicalExecutionEntry() ?? fileURLToPath(new URL("../cotal.js", import.meta.url)), "update", "--self"], { env: { ...process.env, COTAL_NO_UPDATE_CHECK: "1", COTAL_AUTO_UPDATE: "1" }, stdio: ["ignore", outputFd, outputFd], detached: true, windowsHide: true });
|
|
225
228
|
closeSync(outputFd);
|
|
226
229
|
const readOutput = () => { try {
|
|
227
230
|
return readFileSync(logPath, "utf8").slice(-4000);
|
|
@@ -234,7 +237,10 @@ export function automaticUpdates(host) {
|
|
|
234
237
|
});
|
|
235
238
|
child = undefined;
|
|
236
239
|
const recorded = JSON.parse(readFileSync(join(homeCotalDir(), "update-attempt.json"), "utf8"));
|
|
237
|
-
|
|
240
|
+
// An updater that ended without recording an outcome did not update: say so and count it.
|
|
241
|
+
state = ended.code !== 0 && recorded.result === updating
|
|
242
|
+
? { ...recorded, failures: recorded.failures + 1, result: `updater ended with ${ended.code ?? "a signal"}: ${ended.output.trim().split("\n").filter(Boolean).slice(-3).join(" ").slice(0, 400)}`, next: Date.now() + UPDATE_HOUR_MS }
|
|
243
|
+
: recorded;
|
|
238
244
|
persist();
|
|
239
245
|
host.report(state.result);
|
|
240
246
|
}
|
|
@@ -12,9 +12,11 @@ export async function readExecutionPreinstall(request) {
|
|
|
12
12
|
preflightInstalledDaemon({ state: join(homeCotalDir(), "daemon") }, undefined, request.daemonArgv);
|
|
13
13
|
return withRemoteExchangeRetry(async () => {
|
|
14
14
|
const readOne = (flags) => readManagerContinuity(flags, { readOnly: true, retainGraph: true, installedEntry: request.installedEntry });
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
// A session with no runtime directory cannot reach a daemon socket, which is the same answer
|
|
16
|
+
// as a daemon that is not running.
|
|
17
|
+
let paths, reply;
|
|
17
18
|
try {
|
|
19
|
+
paths = daemonPaths();
|
|
18
20
|
reply = await queryDaemon({ paths });
|
|
19
21
|
}
|
|
20
22
|
catch (error) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { existsSync, realpathSync } from "node:fs";
|
|
2
|
+
import { existsSync, realpathSync, rmSync } from "node:fs";
|
|
3
3
|
import { dirname, join, basename } from "node:path";
|
|
4
4
|
import { logicalExecutionEntry, executionIdentity, cmdSpawnSpec } from "@cotal-ai/workspace";
|
|
5
5
|
import { updateRuntime, verifyGlobalEntry } from "@cotal-ai/cli/update";
|
|
6
6
|
import { assertExecutionDestination, executionStagingPrefix, journalExecutionTransaction, publishExecutionTransaction, readExecutionTransaction, retainExecutionGeneration, retireSupersededExecutionDescriptor } from "../execution-transaction.js";
|
|
7
|
-
import { executionInventory, executionSha256 } from "../cotal.js";
|
|
7
|
+
import { executionCopyModesEnv, executionInventory, executionSha256 } from "../cotal.js";
|
|
8
8
|
import { daemonServeArgv } from "./install.js";
|
|
9
9
|
import { readExecutionPreinstall } from "./execution-preinstall.js";
|
|
10
10
|
import { targetExecutionPreinstall } from "./execution-preinstall-client.js";
|
|
@@ -24,7 +24,7 @@ export function preflightExecutionUpdate() {
|
|
|
24
24
|
}
|
|
25
25
|
function verifySelected(root, version) {
|
|
26
26
|
const entry = join(root, "dist/cotal.js");
|
|
27
|
-
const result = spawnSync(process.execPath, [entry, "--version"], { env: { ...process.env, COTAL_SKIP_CONNECTOR_SEED: "1" }, encoding: "utf8", timeout: 30_000 });
|
|
27
|
+
const result = spawnSync(process.execPath, [entry, "--version"], { env: { ...process.env, COTAL_SKIP_CONNECTOR_SEED: "1", [executionCopyModesEnv]: "explicit" }, encoding: "utf8", timeout: 30_000 });
|
|
28
28
|
if (result.status !== 0 || result.stdout.split(/\r?\n/, 1)[0] !== `cotal-ai ${version}`)
|
|
29
29
|
throw new Error(`selected execution did not confirm cotal-ai@${version}: ${result.stderr}`);
|
|
30
30
|
}
|
|
@@ -34,14 +34,20 @@ export async function prepareExecutionUpdate(version, globalRoot, checked) {
|
|
|
34
34
|
if (realpathSync.native(join(globalRoot, "cotal-ai")) !== installed)
|
|
35
35
|
throw new Error("staged update global root differs from logical installation");
|
|
36
36
|
const staging = executionStagingPrefix(installed);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
let generation;
|
|
38
|
+
try {
|
|
39
|
+
const npm = cmdSpawnSpec("npm", ["install", "-g", "--prefix", staging, `cotal-ai@${version}`, "--ignore-scripts", "--no-audit", "--no-fund", "--fetch-retries=0", "--fetch-timeout=15000"]);
|
|
40
|
+
const result = await updateRuntime.spawnGlobal(globalRoot, "install", npm.file, npm.args, process.env, false, npm.windowsVerbatimArguments);
|
|
41
|
+
if (result.status !== 0)
|
|
42
|
+
throw new Error(`target staging failed: ${result.error ?? result.stderr ?? result.stdout}`);
|
|
43
|
+
const source = join(staging, "lib/node_modules/cotal-ai");
|
|
44
|
+
verifyGlobalEntry(join(staging, "lib/node_modules"), version);
|
|
45
|
+
verifySelected(source, version);
|
|
46
|
+
generation = retainExecutionGeneration(installed, source);
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
rmSync(staging, { recursive: true, force: true });
|
|
50
|
+
}
|
|
45
51
|
let journal;
|
|
46
52
|
let accepted = false;
|
|
47
53
|
const getJournal = () => {
|
|
@@ -72,6 +78,8 @@ export async function prepareExecutionUpdate(version, globalRoot, checked) {
|
|
|
72
78
|
restore() { if (!journal)
|
|
73
79
|
throw new Error("execution transaction has no rollback journal"); publishExecutionTransaction(installed, journal, true); },
|
|
74
80
|
verify(expected) { verifySelected(installed, expected); },
|
|
81
|
+
discard() { if (!journal)
|
|
82
|
+
rmSync(dirname(generation.root), { recursive: true, force: true }); },
|
|
75
83
|
};
|
|
76
84
|
}
|
|
77
85
|
export function recoverExecutionUpdate(path) {
|
|
@@ -46,6 +46,20 @@ async function posixGenerationLifecycle(paths) {
|
|
|
46
46
|
close() { },
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
+
/** Refuse a session that has no runtime directory while this account's daemon runs: its socket cannot be named from here. */
|
|
50
|
+
function assertDaemonReachable() {
|
|
51
|
+
try {
|
|
52
|
+
daemonPaths();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (!(error instanceof EndpointRefusal) || error.code !== "NO_RUNTIME_DIR")
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
const lifetime = readLifetimeRecord(join(homeCotalDir(), "daemon", "daemon.lock"));
|
|
60
|
+
if (lifetime?.start && processBirth(lifetime.pid) === lifetime.start)
|
|
61
|
+
throw new Error("the machine daemon is running and this session has no XDG_RUNTIME_DIR to reach it; run the update from a login session of this account, or leave it to the daemon's automatic update");
|
|
62
|
+
}
|
|
49
63
|
const command = registry.resolve("command", "update");
|
|
50
64
|
registry.unregister("command", "update");
|
|
51
65
|
const composed = { ...command, async run(args) {
|
|
@@ -67,6 +81,7 @@ const composed = { ...command, async run(args) {
|
|
|
67
81
|
preflightExecution: preflightExecutionUpdate,
|
|
68
82
|
executionGlobalRoot: () => dirname(executionInstallRoot()),
|
|
69
83
|
prepareExecution: async (version, root) => {
|
|
84
|
+
assertDaemonReachable();
|
|
70
85
|
const execution = await prepareExecutionUpdate(version, root, receipt => { targetReceipt = receipt; });
|
|
71
86
|
replacementVersion = version;
|
|
72
87
|
return execution;
|
|
@@ -96,13 +111,21 @@ const composed = { ...command, async run(args) {
|
|
|
96
111
|
await updateRuntime.preflightReplacement?.();
|
|
97
112
|
preflightInstalledDaemon({ state: join(homeCotalDir(), "daemon") });
|
|
98
113
|
}, adoptUpdateChild: adoptAutomaticUpdateChild, preparedRestart: () => preparedRestart, async prepareReplacement() {
|
|
99
|
-
|
|
114
|
+
let paths;
|
|
115
|
+
try {
|
|
116
|
+
paths = daemonPaths();
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
if (!(error instanceof EndpointRefusal) || error.code !== "NO_RUNTIME_DIR")
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
100
122
|
if (targetReceipt && !targetAdmissionChecked) {
|
|
101
|
-
|
|
123
|
+
// The lifetime record lives under the home, so it is readable in a session with no runtime directory.
|
|
124
|
+
const lifetime = readLifetimeRecord(paths?.lock ?? join(homeCotalDir(), "daemon", "daemon.lock"));
|
|
102
125
|
if (targetReceipt.daemon ? !lifetime?.start || lifetime.pid !== targetReceipt.daemon.pid || lifetime.start !== targetReceipt.daemon.start || processBirth(lifetime.pid) !== lifetime.start : lifetime !== undefined)
|
|
103
126
|
throw new Error("machine daemon lifetime changed after target pre-install checks; retry the update");
|
|
104
127
|
}
|
|
105
|
-
if (!daemonObserved) {
|
|
128
|
+
if (!daemonObserved || !paths) {
|
|
106
129
|
targetAdmissionChecked = true;
|
|
107
130
|
return async () => { };
|
|
108
131
|
}
|
|
@@ -19,7 +19,7 @@ try {
|
|
|
19
19
|
try {
|
|
20
20
|
ftruncateSync(log, 0);
|
|
21
21
|
code = await new Promise((resolve, reject) => {
|
|
22
|
-
const child = spawn(process.execPath, [fileURLToPath(new URL("../cotal.js", import.meta.url)), "update", "--self"], {
|
|
22
|
+
const child = spawn(process.execPath, [process.argv[3] ?? fileURLToPath(new URL("../cotal.js", import.meta.url)), "update", "--self"], {
|
|
23
23
|
env: { ...process.env, COTAL_AUTO_UPDATE: "1", COTAL_NO_UPDATE_CHECK: "1" }, stdio: ["ignore", log, log],
|
|
24
24
|
});
|
|
25
25
|
child.once("error", reject);
|
|
@@ -6,7 +6,7 @@ import { fileURLToPath } from "node:url";
|
|
|
6
6
|
import { writeSecretFileAtomic } from "@cotal-ai/core";
|
|
7
7
|
import { assertSystemdSource, createSystemdSource } from "@cotal-ai/cli";
|
|
8
8
|
import { darwinLaunchdJob } from "@cotal-ai/seat";
|
|
9
|
-
import { homeCotalDir, readLocalRecordSource, UPDATE_HOUR_MS } from "@cotal-ai/workspace";
|
|
9
|
+
import { homeCotalDir, logicalExecutionEntry, readLocalRecordSource, UPDATE_HOUR_MS } from "@cotal-ai/workspace";
|
|
10
10
|
import { daemonStartedByOwnedService } from "./install.js";
|
|
11
11
|
import { daemonPaths } from "./endpoint.js";
|
|
12
12
|
import { processBirth } from "./lifetime.js";
|
|
@@ -135,7 +135,9 @@ export function startLaunchUpdate(failures) {
|
|
|
135
135
|
if (cleanLaunchUpdate() === "pending")
|
|
136
136
|
throw new Error("previous launchd updater still has native custody");
|
|
137
137
|
const label = `ai.cotal.update.${randomBytes(16).toString("hex")}`;
|
|
138
|
-
|
|
138
|
+
// The runner starts the updater at the installed entry, which a daemon loaded from a retained
|
|
139
|
+
// generation names here: that generation's own bootstrap is not an installation.
|
|
140
|
+
const argv = [process.execPath, fileURLToPath(new URL("./update-launchd-runner.js", import.meta.url)), label, logicalExecutionEntry() ?? fileURLToPath(new URL("../cotal.js", import.meta.url))];
|
|
139
141
|
const source = join(homeCotalDir(), `${label}.plist`);
|
|
140
142
|
const text = renderUpdateLaunchAgent(label, argv, process.env);
|
|
141
143
|
const sha256 = createHash("sha256").update(text).digest("hex");
|
package/dist/execution-store.js
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
|
-
import { accessSync, constants, cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { accessSync, chmodSync, constants, cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
|
-
import { executionBinding, executionDescriptorPath, executionInventory, executionSha256, executionStore, protectedExecutionEntry } from "./cotal.js";
|
|
4
|
+
import { executionBinding, executionDescriptorPath, executionInventory, executionLocation, executionSha256, executionShared, executionStore, protectedExecutionEntry } from "./cotal.js";
|
|
5
|
+
/** Remove group and other write from a tree this process just created. Node before 24.22 applies the
|
|
6
|
+
* process umask to the folders a recursive `cpSync` creates, not the source modes, so a umask of 0002
|
|
7
|
+
* leaves them group-writable. A copy that stands in for a package other accounts run is readable by
|
|
8
|
+
* them whatever the umask. */
|
|
9
|
+
function withoutSharedWrite(path, shared) {
|
|
10
|
+
const info = lstatSync(path);
|
|
11
|
+
if (info.isSymbolicLink())
|
|
12
|
+
return;
|
|
13
|
+
const mode = (info.mode & 0o7755) | (shared ? (info.isDirectory() || (info.mode & 0o100) !== 0 ? 0o055 : 0o044) : 0);
|
|
14
|
+
if (mode !== (info.mode & 0o7777))
|
|
15
|
+
chmodSync(path, mode);
|
|
16
|
+
if (info.isDirectory())
|
|
17
|
+
for (const name of readdirSync(path))
|
|
18
|
+
withoutSharedWrite(join(path, name), shared);
|
|
19
|
+
}
|
|
5
20
|
/** Prepare one complete, caller-verified package. Does not change the active artifact or run npm. */
|
|
6
21
|
export function retainExecutionGeneration(installedRoot, verifiedSource) {
|
|
7
22
|
if (existsSync(join(installedRoot, "desktop-runtime.json")) || existsSync(join(verifiedSource, "desktop-runtime.json")))
|
|
@@ -11,8 +26,9 @@ export function retainExecutionGeneration(installedRoot, verifiedSource) {
|
|
|
11
26
|
for (const path of [installedRoot, verifiedSource]) {
|
|
12
27
|
if (!lstatSync(path).isDirectory() || lstatSync(path).isSymbolicLink())
|
|
13
28
|
throw new Error("execution package must be a real directory");
|
|
14
|
-
protectedExecutionEntry(path);
|
|
15
29
|
}
|
|
30
|
+
executionLocation(installedRoot);
|
|
31
|
+
protectedExecutionEntry(verifiedSource);
|
|
16
32
|
try {
|
|
17
33
|
accessSync(installedRoot, constants.W_OK);
|
|
18
34
|
accessSync(dirname(dirname(installedRoot)), constants.W_OK);
|
|
@@ -20,9 +36,12 @@ export function retainExecutionGeneration(installedRoot, verifiedSource) {
|
|
|
20
36
|
catch {
|
|
21
37
|
throw new Error(`installation is not writable; use the owning command: npm install -g --prefix ${dirname(dirname(dirname(installedRoot)))} cotal-ai@latest`);
|
|
22
38
|
}
|
|
23
|
-
const store = executionStore(installedRoot);
|
|
24
|
-
if (!lstatSync(store, { throwIfNoEntry: false }))
|
|
39
|
+
const store = executionStore(installedRoot), shared = executionShared(installedRoot);
|
|
40
|
+
if (!lstatSync(store, { throwIfNoEntry: false })) {
|
|
25
41
|
mkdirSync(store, { mode: 0o700 });
|
|
42
|
+
if (shared)
|
|
43
|
+
chmodSync(store, 0o755);
|
|
44
|
+
}
|
|
26
45
|
if (!lstatSync(store).isDirectory() || lstatSync(store).isSymbolicLink())
|
|
27
46
|
throw new Error("unsafe execution generation store");
|
|
28
47
|
protectedExecutionEntry(store);
|
|
@@ -31,6 +50,7 @@ export function retainExecutionGeneration(installedRoot, verifiedSource) {
|
|
|
31
50
|
try {
|
|
32
51
|
const root = join(staging, "cotal-ai");
|
|
33
52
|
cpSync(verifiedSource, root, { recursive: true, dereference: false, verbatimSymlinks: true });
|
|
53
|
+
withoutSharedWrite(root, shared);
|
|
34
54
|
if (JSON.stringify(before) !== JSON.stringify(executionInventory(root)) ||
|
|
35
55
|
JSON.stringify(before) !== JSON.stringify(executionInventory(verifiedSource)))
|
|
36
56
|
throw new Error("verified execution source changed during retention");
|
|
@@ -41,6 +61,10 @@ export function retainExecutionGeneration(installedRoot, verifiedSource) {
|
|
|
41
61
|
throw new Error("retained execution package has no declared bootstrap and program");
|
|
42
62
|
const inventorySha256 = executionSha256(JSON.stringify(before));
|
|
43
63
|
writeFileSync(join(staging, "inventory.json"), JSON.stringify(before), { mode: 0o600, flag: "wx" });
|
|
64
|
+
if (shared) {
|
|
65
|
+
chmodSync(join(staging, "inventory.json"), 0o644);
|
|
66
|
+
chmodSync(staging, 0o755);
|
|
67
|
+
}
|
|
44
68
|
const id = randomBytes(16).toString("hex");
|
|
45
69
|
renameSync(staging, join(store, id));
|
|
46
70
|
return { id, root: join(store, id, "cotal-ai"), version: meta.version, inventorySha256 };
|
|
@@ -60,11 +84,13 @@ export function describeExecutionGeneration(installedRoot, generation) {
|
|
|
60
84
|
export function writeExecutionDescriptor(installedRoot, descriptor) {
|
|
61
85
|
if (existsSync(join(installedRoot, "desktop-runtime.json")))
|
|
62
86
|
throw new Error("retained execution generations are unavailable on the desktop runtime");
|
|
63
|
-
|
|
87
|
+
executionLocation(installedRoot);
|
|
64
88
|
const path = executionDescriptorPath(installedRoot);
|
|
65
89
|
const temporary = `${path}.${randomBytes(16).toString("hex")}`;
|
|
66
90
|
try {
|
|
67
91
|
writeFileSync(temporary, `${JSON.stringify(descriptor)}\n`, { flag: "wx", mode: 0o600 });
|
|
92
|
+
if (executionShared(installedRoot))
|
|
93
|
+
chmodSync(temporary, 0o644);
|
|
68
94
|
renameSync(temporary, path);
|
|
69
95
|
}
|
|
70
96
|
finally {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
|
-
import { accessSync, constants, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { accessSync, chmodSync, constants, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, join, resolve } from "node:path";
|
|
4
|
-
import { executionBinding, executionLaunchBinding, executionDescriptorPath, executionRecord, executionSha256, executionStore, protectedExecutionEntry, selectExecutionProgram } from "./cotal.js";
|
|
4
|
+
import { executionBinding, executionLaunchBinding, executionDescriptorPath, executionLocation, executionRecord, executionSha256, executionShared, executionStore, protectedExecutionEntry, selectExecutionProgram } from "./cotal.js";
|
|
5
5
|
import { retainExecutionGeneration, writeExecutionDescriptor } from "./execution-store.js";
|
|
6
6
|
/** The admission check runs before creating staging, records or configuration directories. */
|
|
7
7
|
export function assertExecutionDestination(installed) {
|
|
@@ -13,7 +13,7 @@ export function assertExecutionDestination(installed) {
|
|
|
13
13
|
const stat = lstatSync(path);
|
|
14
14
|
if (!stat.isDirectory() || stat.isSymbolicLink())
|
|
15
15
|
throw new Error(`unsafe staged update destination: ${path}`);
|
|
16
|
-
|
|
16
|
+
executionLocation(path);
|
|
17
17
|
}
|
|
18
18
|
try {
|
|
19
19
|
for (const path of [installed, join(installed, "dist"), dirname(dirname(installed))])
|
|
@@ -28,6 +28,7 @@ function atomicFile(path, bytes, mode) {
|
|
|
28
28
|
const temporary = `${path}.${randomBytes(16).toString("hex")}`;
|
|
29
29
|
try {
|
|
30
30
|
writeFileSync(temporary, bytes, { flag: "wx", mode });
|
|
31
|
+
chmodSync(temporary, mode);
|
|
31
32
|
renameSync(temporary, path);
|
|
32
33
|
}
|
|
33
34
|
finally {
|
|
@@ -83,22 +84,31 @@ export function publishExecutionTransaction(installed, path, restore = false) {
|
|
|
83
84
|
] };
|
|
84
85
|
writeExecutionDescriptor(installed, transitional);
|
|
85
86
|
}
|
|
86
|
-
atomicFile(join(installed, "dist/cotal.js"), bootstrap, 0o700);
|
|
87
|
+
atomicFile(join(installed, "dist/cotal.js"), bootstrap, executionShared(installed) ? 0o755 : 0o700);
|
|
87
88
|
if (descriptor)
|
|
88
89
|
writeExecutionDescriptor(installed, descriptor);
|
|
89
90
|
else
|
|
90
91
|
rmSync(executionDescriptorPath(installed), { force: true });
|
|
91
92
|
selectExecutionProgram(installed);
|
|
92
93
|
}
|
|
93
|
-
/** Stage only within the owned retained store; npm receives this private prefix, never the live root.
|
|
94
|
+
/** Stage only within the owned retained store; npm receives this private prefix, never the live root.
|
|
95
|
+
* The caller holds the claim on npm's global root, so a staging folder already here was abandoned by
|
|
96
|
+
* an attempt that ended, and it is removed first. */
|
|
94
97
|
export function executionStagingPrefix(installed) {
|
|
95
98
|
assertExecutionDestination(installed);
|
|
96
99
|
const store = executionStore(installed);
|
|
97
|
-
if (!lstatSync(store, { throwIfNoEntry: false }))
|
|
100
|
+
if (!lstatSync(store, { throwIfNoEntry: false })) {
|
|
98
101
|
mkdirSync(store, { mode: 0o700 });
|
|
102
|
+
if (executionShared(installed))
|
|
103
|
+
chmodSync(store, 0o755);
|
|
104
|
+
}
|
|
99
105
|
if (!lstatSync(store).isDirectory() || lstatSync(store).isSymbolicLink())
|
|
100
106
|
throw new Error("unsafe execution generation store");
|
|
101
107
|
protectedExecutionEntry(store);
|
|
108
|
+
for (const name of readdirSync(store)) {
|
|
109
|
+
if (/^\.(?:installing|preparing)-[A-Za-z0-9]{6}$/.test(name))
|
|
110
|
+
rmSync(join(store, name), { recursive: true, force: true });
|
|
111
|
+
}
|
|
102
112
|
return mkdtempSync(join(store, ".installing-"));
|
|
103
113
|
}
|
|
104
114
|
/** Remove a superseded active descriptor after an in-place package-manager install took over. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cotal-ai",
|
|
3
|
-
"version": "0.164.
|
|
3
|
+
"version": "0.164.18",
|
|
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": [
|
|
@@ -37,28 +37,28 @@
|
|
|
37
37
|
"node": ">=22.10"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@cotal-ai/auth": "0.164.
|
|
41
|
-
"@cotal-ai/cli": "0.164.
|
|
42
|
-
"@cotal-ai/connector-core": "0.164.
|
|
43
|
-
"@cotal-ai/core": "0.164.
|
|
44
|
-
"@cotal-ai/delivery": "0.164.
|
|
45
|
-
"@cotal-ai/manager": "0.164.
|
|
46
|
-
"@cotal-ai/registry": "0.164.
|
|
47
|
-
"@cotal-ai/runtime": "0.164.
|
|
48
|
-
"@cotal-ai/seat": "0.164.
|
|
49
|
-
"@cotal-ai/workspace": "0.164.
|
|
40
|
+
"@cotal-ai/auth": "0.164.18",
|
|
41
|
+
"@cotal-ai/cli": "0.164.18",
|
|
42
|
+
"@cotal-ai/connector-core": "0.164.18",
|
|
43
|
+
"@cotal-ai/core": "0.164.18",
|
|
44
|
+
"@cotal-ai/delivery": "0.164.18",
|
|
45
|
+
"@cotal-ai/manager": "0.164.18",
|
|
46
|
+
"@cotal-ai/registry": "0.164.18",
|
|
47
|
+
"@cotal-ai/runtime": "0.164.18",
|
|
48
|
+
"@cotal-ai/seat": "0.164.18",
|
|
49
|
+
"@cotal-ai/workspace": "0.164.18",
|
|
50
50
|
"jose": "^6.2.3"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@cotal-ai/connector-claude-code": "0.164.
|
|
54
|
-
"@cotal-ai/connector-codex": "0.164.
|
|
55
|
-
"@cotal-ai/connector-hermes": "0.164.
|
|
56
|
-
"@cotal-ai/connector-jcode": "0.164.
|
|
57
|
-
"@cotal-ai/connector-opencode": "0.164.
|
|
58
|
-
"@cotal-ai/linear": "0.164.
|
|
59
|
-
"@cotal-ai/pi": "0.164.
|
|
53
|
+
"@cotal-ai/connector-claude-code": "0.164.18",
|
|
54
|
+
"@cotal-ai/connector-codex": "0.164.18",
|
|
55
|
+
"@cotal-ai/connector-hermes": "0.164.18",
|
|
56
|
+
"@cotal-ai/connector-jcode": "0.164.18",
|
|
57
|
+
"@cotal-ai/connector-opencode": "0.164.18",
|
|
58
|
+
"@cotal-ai/linear": "0.164.18",
|
|
59
|
+
"@cotal-ai/pi": "0.164.18",
|
|
60
60
|
"@cotal-ai/smoke-kit": "0.0.0",
|
|
61
|
-
"@cotal-ai/web": "0.164.
|
|
61
|
+
"@cotal-ai/web": "0.164.18",
|
|
62
62
|
"@nats-io/jetstream": "^3.4.0",
|
|
63
63
|
"@nats-io/transport-node": "^3.4.0",
|
|
64
64
|
"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": "dfd5ed803165e56096ecaffcd82146f381db718f5fd8ed66da7e5492d35ef824",
|
|
5
|
+
"docs-index.bin": "97ea7b0c6af5a59164d8db7a1e9e559bddab036786ba3d5e3bec0e6034ed3818"
|
|
6
6
|
},
|
|
7
7
|
"placements": {
|
|
8
8
|
"claude": [
|