cotal-ai 0.163.1 → 0.163.2

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.
Files changed (32) hide show
  1. package/dist/daemon/account.js +3 -4
  2. package/dist/daemon/install.js +16 -1
  3. package/dist/daemon/manager.js +40 -32
  4. package/dist/daemon/server.js +31 -9
  5. package/dist/daemon/update-entry.js +5 -1
  6. package/package.json +19 -19
  7. package/seeded-connectors/_shared/docs-bundle.bin +0 -0
  8. package/seeded-connectors/_shared/docs-index.bin +0 -0
  9. package/seeded-connectors/_shared/placements.json +2 -2
  10. package/seeded-connectors/claude/dist/index.js +2 -2
  11. package/seeded-connectors/claude/dist/mcp.cjs +16 -16
  12. package/seeded-connectors/claude/package.json +1 -1
  13. package/seeded-connectors/codex/dist/host.js +13 -13
  14. package/seeded-connectors/codex/dist/index.js +1 -1
  15. package/seeded-connectors/codex/dist/personal.js +9 -9
  16. package/seeded-connectors/codex/package.json +1 -1
  17. package/seeded-connectors/hermes/dist/index.js +1 -1
  18. package/seeded-connectors/hermes/dist/launch.js +26 -26
  19. package/seeded-connectors/hermes/package.json +1 -1
  20. package/seeded-connectors/hermes/plugin/cotal/_sidecar/standalone.cjs +23 -23
  21. package/seeded-connectors/jcode/dist/host.js +14 -14
  22. package/seeded-connectors/jcode/dist/index.js +2 -2
  23. package/seeded-connectors/jcode/dist/mcp.js +2 -2
  24. package/seeded-connectors/jcode/package.json +1 -1
  25. package/seeded-connectors/opencode/dist/index.js +1 -1
  26. package/seeded-connectors/opencode/dist/plugin/index.js +14 -14
  27. package/seeded-connectors/opencode/dist/plugin.d.ts.map +1 -1
  28. package/seeded-connectors/opencode/package.json +1 -1
  29. package/seeded-connectors/pi/dist/index.js +8 -8
  30. package/seeded-connectors/pi/dist/standalone.js +10 -10
  31. package/seeded-connectors/pi/package.json +1 -1
  32. package/seeded-connectors/web/package.json +1 -1
@@ -3,7 +3,6 @@ import { findMesh } from "@cotal-ai/workspace";
3
3
  import { loadIdpSession, requestAccountMachine, signedInMachineAccounts, withIdpSessionDir } from "@cotal-ai/auth";
4
4
  import { validateCatalogSnapshot } from "@cotal-ai/cli";
5
5
  import { accountComputerId } from "./account-identity.js";
6
- import { hasDaemonConnectIntent } from "./service.js";
7
6
  /** Poll account intent without interpreting transport failure as an empty desired set. */
8
7
  export function createAccountComputer(home, version, reconciler) {
9
8
  let vitals;
@@ -149,9 +148,9 @@ export function createAccountComputer(home, version, reconciler) {
149
148
  throw new Error("Refresh your spaces before changing this computer's connection.");
150
149
  if (entry.mode !== "user")
151
150
  return false;
152
- // Reconnecting an existing manual service does not change an account's desired spaces.
153
- // Its own renewal proof, not a human session, authorizes that connection.
154
- if (enabled && !entry.catalogOwner && !entry.catalogId && hasDaemonConnectIntent(space, home))
151
+ // Manual service registrations use their own prerequisite and renewal flow.
152
+ // Only catalog-owned spaces change an account computer's desired spaces.
153
+ if (!entry.catalogOwner && !entry.catalogId)
155
154
  return false;
156
155
  const candidates = signedInMachineAccounts(home).filter(item => entry.catalogOwner ? item.ownerKey === entry.catalogOwner : item.idpUrl === entry.userAuth?.idp.url);
157
156
  const account = candidates.length === 1 ? candidates[0] : undefined;
@@ -316,7 +316,9 @@ function recordedUnit(paths, daemonHome) {
316
316
  else {
317
317
  const unit = daemonUnitName(daemonHome);
318
318
  if (receipt.daemonHome !== daemonHome || receipt.unit !== unit || receipt.unitPath !== join(systemdUserUnitDirectory(), unit))
319
- throw new CommandFailure("refused", "CONFLICT", "the systemd receipt does not name this daemon home's unit in the user manager's unit directory; nothing was changed");
319
+ throw new CommandFailure("refused", "CONFLICT", "the systemd receipt does not name this daemon home's unit in the user manager's unit directory; nothing was changed", {
320
+ remedy: `inspect ${codeSpan(unitReceiptFile(paths))} and ${codeSpan(receipt.unitPath)}. If this receipt is stale, remove only ${codeSpan(unitReceiptFile(paths))} to forget it, then run ${codeSpan(daemonCommandCopy("install", daemonHome))}. For an owned installation, run ${codeSpan(daemonCommandCopy("uninstall", daemonHome))} before reinstalling`,
321
+ });
320
322
  try {
321
323
  assertSystemdSource(receipt.unitPath, receipt.unitSha256);
322
324
  }
@@ -382,6 +384,19 @@ export async function startInstalled(paths, daemonHome, expectedVersion, report)
382
384
  submitSystemdUnitControl("start", plan.unit);
383
385
  return plan;
384
386
  }
387
+ /** Validate a present service receipt from persistent state without runtime discovery. Return false only when absent. */
388
+ export function preflightInstalledDaemon(paths, daemonHome) {
389
+ try {
390
+ lstatSync(unitReceiptFile(paths));
391
+ }
392
+ catch (error) {
393
+ if (error.code === "ENOENT")
394
+ return false;
395
+ throw error;
396
+ }
397
+ installedDaemonIdentity(paths, daemonHome);
398
+ return true;
399
+ }
385
400
  /** The executable and entry pinned by the verified native source, compared with this CLI. */
386
401
  export function installedDaemonIdentity(paths, daemonHome) {
387
402
  return recordedDaemonIdentity(recordedUnit(paths, daemonHome));
@@ -57,7 +57,15 @@ export function createHostedManagers(home = homeCotalDir(), version = installedG
57
57
  let closed = false;
58
58
  let generationPending = false;
59
59
  let generationPrepared = false;
60
- let generationTask;
60
+ let generationTask = Promise.resolve();
61
+ const generationOwners = new Set();
62
+ const generationReleases = new Set();
63
+ let generationAcquisitions = 0;
64
+ const queueGeneration = (operation) => {
65
+ const task = generationTask.then(operation);
66
+ generationTask = task.catch(() => { });
67
+ return task;
68
+ };
61
69
  const generationAttempts = new Map();
62
70
  const generationCall = (child, attemptId, op) => new Promise((resolve, reject) => {
63
71
  if (child.exitCode !== null || child.signalCode !== null) {
@@ -684,14 +692,15 @@ export function createHostedManagers(home = homeCotalDir(), version = installedG
684
692
  return { space: l.view.space, seats };
685
693
  }));
686
694
  },
687
- prepareGenerationRestart() {
688
- if (generationTask)
689
- return generationTask.then(() => { if (!generationPrepared)
690
- throw new Error("generation preparation was rolled back; retry the transition"); });
691
- if (generationPrepared)
692
- return Promise.resolve();
693
- const task = (async () => {
694
- generationPending = true;
695
+ prepareGenerationRestart(owner) {
696
+ generationPending = true;
697
+ generationAcquisitions++;
698
+ return queueGeneration(async () => {
699
+ generationAcquisitions--;
700
+ if (generationPrepared) {
701
+ generationOwners.add(owner);
702
+ return;
703
+ }
695
704
  try {
696
705
  await Promise.all([...live.values()].map((l) => l.healthTask));
697
706
  // A timed-out prepare can still have landed. Roll back every retained attempt before retrying.
@@ -746,6 +755,8 @@ export function createHostedManagers(home = homeCotalDir(), version = installedG
746
755
  }
747
756
  // Keep empty-manager admission fences held through the caller's close.
748
757
  generationPrepared = true;
758
+ generationOwners.add(owner);
759
+ generationReleases.clear();
749
760
  }
750
761
  catch (error) {
751
762
  for (const [child, attemptId] of generationAttempts) {
@@ -755,7 +766,7 @@ export function createHostedManagers(home = homeCotalDir(), version = installedG
755
766
  }
756
767
  catch { /* Retain the exact attempt for rollback on the next automatic retry. */ }
757
768
  }
758
- generationPending = generationAttempts.size !== 0;
769
+ generationPending = generationAttempts.size !== 0 || generationAcquisitions !== 0;
759
770
  if (!generationPending)
760
771
  for (const l of live.values()) {
761
772
  if (!l.child && !l.starting && !l.timer && l.view.state === "restarting")
@@ -765,34 +776,31 @@ export function createHostedManagers(home = homeCotalDir(), version = installedG
765
776
  }
766
777
  throw error;
767
778
  }
768
- })();
769
- const held = task.finally(() => { if (generationTask === held)
770
- generationTask = undefined; });
771
- generationTask = held;
772
- return held;
779
+ });
773
780
  },
774
- abortGenerationRestart() {
775
- const previous = generationTask;
776
- generationPrepared = false;
777
- const task = (async () => {
778
- await previous?.catch(() => { });
781
+ abortGenerationRestart(owner) {
782
+ return queueGeneration(async () => {
783
+ if (!generationOwners.delete(owner) && !generationReleases.has(owner))
784
+ return;
785
+ if (generationOwners.size !== 0)
786
+ return;
787
+ // Keep release authority and exact child attempts if an abort is unconfirmed.
788
+ generationReleases.add(owner);
779
789
  generationPrepared = false;
780
790
  for (const [child, attemptId] of generationAttempts) {
781
791
  await generationCall(child, attemptId, "abort");
782
792
  generationAttempts.delete(child);
783
793
  }
784
- generationPending = false;
785
- for (const l of live.values()) {
786
- if (!l.child && !l.starting && !l.timer && l.view.state === "restarting")
787
- schedule(l);
788
- else if (l.child)
789
- observe(l);
790
- }
791
- })();
792
- const held = task.finally(() => { if (generationTask === held)
793
- generationTask = undefined; });
794
- generationTask = held;
795
- return held;
794
+ generationReleases.clear();
795
+ generationPending = generationAcquisitions !== 0;
796
+ if (!generationPending)
797
+ for (const l of live.values()) {
798
+ if (!l.child && !l.starting && !l.timer && l.view.state === "restarting")
799
+ schedule(l);
800
+ else if (l.child)
801
+ observe(l);
802
+ }
803
+ });
796
804
  },
797
805
  all: () => [...new Set([...spaces(true), ...live.keys()])].map(status),
798
806
  async disconnect(space, options) {
@@ -19,9 +19,9 @@ import { chmodSync, closeSync, linkSync, unlinkSync, lstatSync } from "node:fs";
19
19
  import { randomBytes } from "node:crypto";
20
20
  import { join } from "node:path";
21
21
  import { createServer } from "node:net";
22
- import { listenPipe, windowsUserSid } from "@cotal-ai/seat";
22
+ import { localPeerCredentials, listenPipe, windowsUserSid } from "@cotal-ai/seat";
23
23
  import { DAEMON_PROTOCOL_VERSION, MAX_LINE_BYTES, EndpointRefusal, adoptPipe, assertSocketPathFits, assertSupportedPlatform, checkSocket, defaultPeerUid, ensureDir, ensureStateDir } from "./endpoint.js";
24
- import { claimSocketPath, generationOf, holdLifetime } from "./lifetime.js";
24
+ import { claimSocketPath, generationOf, holdLifetime, processBirth } from "./lifetime.js";
25
25
  import { encode, parseRequest } from "./protocol.js";
26
26
  import { createLoginCoordinator } from "./login.js";
27
27
  import { connectCheck } from "./connect.js";
@@ -116,7 +116,8 @@ async function serveLocked(opts, uid, lock) {
116
116
  sock.on("error", () => { });
117
117
  };
118
118
  // One connection whose peer the kernel already reported as this user: decode its requests.
119
- const serveConnection = (sock) => {
119
+ const daemonRestartOwner = `daemon:${process.pid}:${processBirth(process.pid)}`;
120
+ const serveConnection = (sock, restartOwner) => {
120
121
  counters.accepted++;
121
122
  let buf = "";
122
123
  let bufBytes = 0;
@@ -214,10 +215,11 @@ async function serveLocked(opts, uid, lock) {
214
215
  }
215
216
  if (req.op === "managers-prepare-restart" || req.op === "managers-abort-restart") {
216
217
  managerResult(async () => {
218
+ const owner = restartOwner();
217
219
  if (req.op === "managers-prepare-restart")
218
- await managers.prepareGenerationRestart();
220
+ await managers.prepareGenerationRestart(owner);
219
221
  else
220
- await managers.abortGenerationRestart();
222
+ await managers.abortGenerationRestart(owner);
221
223
  return status();
222
224
  });
223
225
  return;
@@ -433,7 +435,14 @@ async function serveLocked(opts, uid, lock) {
433
435
  };
434
436
  let endpoint;
435
437
  if (paths.dir === undefined) {
436
- endpoint = publishPipe(paths, counters, log, (sock) => { track(sock); serveConnection(sock); });
438
+ endpoint = publishPipe(paths, counters, log, (sock, peer) => {
439
+ track(sock);
440
+ serveConnection(sock, () => {
441
+ if (!Number.isSafeInteger(peer.pid) || peer.pid <= 0 || !peer.birth)
442
+ throw new Error("restart owner process identity is unavailable");
443
+ return JSON.stringify(["peer", peer.user, peer.pid, peer.birth]);
444
+ });
445
+ });
437
446
  }
438
447
  else {
439
448
  const peerUid = opts.peerUid ?? defaultPeerUid;
@@ -455,7 +464,20 @@ async function serveLocked(opts, uid, lock) {
455
464
  sock.destroy();
456
465
  return;
457
466
  }
458
- serveConnection(sock);
467
+ let owner;
468
+ try {
469
+ const identity = localPeerCredentials(sock);
470
+ const birth = processBirth(identity.pid);
471
+ if (identity.uid === uid && Number.isSafeInteger(identity.pid) && identity.pid > 0 && birth) {
472
+ owner = JSON.stringify(["peer", identity.uid, identity.pid, birth]);
473
+ }
474
+ }
475
+ catch { /* Ordinary requests do not require restart ownership. */ }
476
+ serveConnection(sock, () => {
477
+ if (!owner)
478
+ throw new Error("restart owner process identity is unavailable");
479
+ return owner;
480
+ });
459
481
  });
460
482
  }
461
483
  let closed;
@@ -500,7 +522,7 @@ async function serveLocked(opts, uid, lock) {
500
522
  return { paths, counters, dirOutcome, status, close, stopped,
501
523
  generationSeats: () => managers.generationSeats(),
502
524
  generationPending(installed, waiting = "preparing activation") { generation = installed ? { installed, running: opts.version, waiting } : undefined; },
503
- async prepareGenerationRestart() { await resumed; await managers.prepareGenerationRestart(); }, abortGenerationRestart: () => managers.abortGenerationRestart() };
525
+ async prepareGenerationRestart() { await resumed; await managers.prepareGenerationRestart(daemonRestartOwner); }, abortGenerationRestart: () => managers.abortGenerationRestart(daemonRestartOwner) };
504
526
  }
505
527
  /** Linux and macOS: publish the unix socket, and on close remove it only if it is still ours. */
506
528
  async function publishSocket(paths, uid, lock, counters, log, accept) {
@@ -635,7 +657,7 @@ function publishPipe(paths, counters, log, accept) {
635
657
  log(`daemon: could not adopt an authenticated pipe connection (${e.message}); dropped`);
636
658
  continue;
637
659
  }
638
- accept(sock);
660
+ accept(sock, peer);
639
661
  }
640
662
  })();
641
663
  return {
@@ -1,5 +1,6 @@
1
1
  /** The binary composes machine-daemon custody with the stock package updater. */
2
2
  import { existsSync } from "node:fs";
3
+ import { join } from "node:path";
3
4
  import { registry } from "@cotal-ai/core";
4
5
  import { update, updateRuntime, localUpdateManagers, readManagerContinuity, updateManagerPin } from "@cotal-ai/cli/update";
5
6
  import { withIdpSessionDir, withRemoteExchangeRetry } from "@cotal-ai/auth";
@@ -7,7 +8,7 @@ import { brokerAddressKey, assertRecordIdentity, CommandFailure, homeCotalDir, r
7
8
  import { askManager } from "@cotal-ai/workspace/control";
8
9
  import { daemonPaths, EndpointRefusal } from "./endpoint.js";
9
10
  import { managerViaDaemon, queryDaemon } from "./client.js";
10
- import { installedDaemonIdentity, restartInstalled, unitReceiptFile } from "./install.js";
11
+ import { installedDaemonIdentity, preflightInstalledDaemon, restartInstalled, unitReceiptFile } from "./install.js";
11
12
  import { excludeLifetime, processBirth, readLifetimeRecord } from "./lifetime.js";
12
13
  import { waitForInstalledDaemonGeneration } from "./update-generation.js";
13
14
  import { adoptAutomaticUpdateChild } from "./update-scope.js";
@@ -39,6 +40,9 @@ const composed = { ...command, async run(args) {
39
40
  }
40
41
  throw error;
41
42
  }
43
+ }, async preflightReplacement() {
44
+ await updateRuntime.preflightReplacement?.();
45
+ preflightInstalledDaemon({ state: join(homeCotalDir(), "daemon") });
42
46
  }, adoptUpdateChild: adoptAutomaticUpdateChild, preparedRestart: () => preparedRestart, async prepareReplacement() {
43
47
  if (process.env.COTAL_AUTO_UPDATE !== "1" || !daemonObserved)
44
48
  return async () => { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cotal-ai",
3
- "version": "0.163.1",
3
+ "version": "0.163.2",
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.163.1",
37
- "@cotal-ai/cli": "0.163.1",
38
- "@cotal-ai/connector-core": "0.163.1",
39
- "@cotal-ai/core": "0.163.1",
40
- "@cotal-ai/delivery": "0.163.1",
41
- "@cotal-ai/manager": "0.163.1",
42
- "@cotal-ai/registry": "0.163.1",
43
- "@cotal-ai/runtime": "0.163.1",
44
- "@cotal-ai/seat": "0.163.1",
45
- "@cotal-ai/workspace": "0.163.1",
36
+ "@cotal-ai/auth": "0.163.2",
37
+ "@cotal-ai/cli": "0.163.2",
38
+ "@cotal-ai/connector-core": "0.163.2",
39
+ "@cotal-ai/core": "0.163.2",
40
+ "@cotal-ai/delivery": "0.163.2",
41
+ "@cotal-ai/manager": "0.163.2",
42
+ "@cotal-ai/registry": "0.163.2",
43
+ "@cotal-ai/runtime": "0.163.2",
44
+ "@cotal-ai/seat": "0.163.2",
45
+ "@cotal-ai/workspace": "0.163.2",
46
46
  "jose": "^6.2.3"
47
47
  },
48
48
  "devDependencies": {
49
- "@cotal-ai/connector-claude-code": "0.163.1",
50
- "@cotal-ai/connector-codex": "0.163.1",
51
- "@cotal-ai/connector-hermes": "0.163.1",
52
- "@cotal-ai/connector-jcode": "0.163.1",
53
- "@cotal-ai/connector-opencode": "0.163.1",
54
- "@cotal-ai/linear": "0.163.1",
55
- "@cotal-ai/pi": "0.163.1",
49
+ "@cotal-ai/connector-claude-code": "0.163.2",
50
+ "@cotal-ai/connector-codex": "0.163.2",
51
+ "@cotal-ai/connector-hermes": "0.163.2",
52
+ "@cotal-ai/connector-jcode": "0.163.2",
53
+ "@cotal-ai/connector-opencode": "0.163.2",
54
+ "@cotal-ai/linear": "0.163.2",
55
+ "@cotal-ai/pi": "0.163.2",
56
56
  "@cotal-ai/smoke-kit": "0.0.0",
57
- "@cotal-ai/web": "0.163.1",
57
+ "@cotal-ai/web": "0.163.2",
58
58
  "@nats-io/jetstream": "^3.4.0",
59
59
  "@nats-io/transport-node": "^3.4.0",
60
60
  "typescript": "^5.9.3"
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "v": 1,
3
3
  "files": {
4
- "docs-bundle.bin": "0d78ebcce12222457a4d90b63db9eb0cb8afcc676740ab6a7d16f67e9682d1ac",
5
- "docs-index.bin": "c1d373fb23cae5bd6238d5ad3572f029d058b91a195e6421b527f647086d03aa"
4
+ "docs-bundle.bin": "ea31640c4025c61e02fb58c6cb23626c85f6de8386ca337f62a20711bf3c2365",
5
+ "docs-index.bin": "9f7a81321181ee90129460cd8316871472ad93152d44b159c2f207aab790eff9"
6
6
  },
7
7
  "placements": {
8
8
  "claude": [