@cotal-ai/cli 0.171.5 → 0.172.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/command.d.ts.map +1 -1
- package/dist/command.js +46 -19
- package/dist/command.js.map +1 -1
- package/dist/commands/down.d.ts.map +1 -1
- package/dist/commands/down.js +19 -6
- package/dist/commands/down.js.map +1 -1
- package/dist/commands/ext.d.ts +1 -1
- package/dist/commands/ext.d.ts.map +1 -1
- package/dist/commands/ext.js +37 -8
- package/dist/commands/ext.js.map +1 -1
- package/dist/commands/help.js +2 -2
- package/dist/commands/help.js.map +1 -1
- package/dist/commands/space-registration.d.ts.map +1 -1
- package/dist/commands/space-registration.js +9 -3
- package/dist/commands/space-registration.js.map +1 -1
- package/dist/commands/space.d.ts.map +1 -1
- package/dist/commands/space.js +34 -25
- package/dist/commands/space.js.map +1 -1
- package/dist/commands/stack-down.d.ts.map +1 -1
- package/dist/commands/stack-down.js +5 -4
- package/dist/commands/stack-down.js.map +1 -1
- package/dist/commands/stack-up.d.ts +5 -0
- package/dist/commands/stack-up.d.ts.map +1 -1
- package/dist/commands/stack-up.js +46 -20
- package/dist/commands/stack-up.js.map +1 -1
- package/dist/commands/status.d.ts +2 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +44 -22
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/up.d.ts +1 -1
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +34 -22
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/update.d.ts +5 -5
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +175 -34
- package/dist/commands/update.js.map +1 -1
- package/dist/lib/broker-service.d.ts +6 -4
- package/dist/lib/broker-service.d.ts.map +1 -1
- package/dist/lib/broker-service.js +36 -6
- package/dist/lib/broker-service.js.map +1 -1
- package/dist/lib/restore.d.ts +3 -2
- package/dist/lib/restore.d.ts.map +1 -1
- package/dist/lib/restore.js +12 -10
- package/dist/lib/restore.js.map +1 -1
- package/dist/lib/service-systemd.d.ts +3 -3
- package/dist/lib/service-systemd.d.ts.map +1 -1
- package/dist/lib/service-systemd.js +6 -6
- package/dist/lib/service-systemd.js.map +1 -1
- package/dist/lib/up-report.d.ts.map +1 -1
- package/dist/lib/up-report.js +9 -6
- package/dist/lib/up-report.js.map +1 -1
- package/dist/lib/update-pending.d.ts +1 -0
- package/dist/lib/update-pending.d.ts.map +1 -1
- package/dist/lib/update-pending.js +4 -3
- package/dist/lib/update-pending.js.map +1 -1
- package/dist/lib/version.d.ts +1 -0
- package/dist/lib/version.d.ts.map +1 -1
- package/dist/lib/version.js +2 -2
- package/dist/lib/version.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type FlagSpec, type ParsedArgs } from "@cotal-ai/core";
|
|
2
|
-
import { type InstalledExtension } from "@cotal-ai/workspace";
|
|
2
|
+
import { type InstalledExtension, UnreadableConnectorSelection } from "@cotal-ai/workspace";
|
|
3
3
|
import { repairInstallModes } from "../lib/install-umask.js";
|
|
4
4
|
import { installedCliVersion } from "../lib/version.js";
|
|
5
5
|
import { type MeshTarget } from "@cotal-ai/workspace";
|
|
@@ -63,8 +63,8 @@ export interface UpdateRuntime {
|
|
|
63
63
|
reportRunningManager(target: Record<string, unknown>): Promise<"none" | "legacy">;
|
|
64
64
|
/** Authenticate and retain an installed same-version repair before its connector writes. */
|
|
65
65
|
prepareReconciliation?(target: Record<string, unknown>): Promise<void>;
|
|
66
|
-
/**
|
|
67
|
-
waitForInstalledGeneration?(version: string): Promise<void>;
|
|
66
|
+
/** Wait for the replacement, or return why native daemon activation remains incomplete. */
|
|
67
|
+
waitForInstalledGeneration?(version: string): Promise<string | void>;
|
|
68
68
|
/** Explain whether the machine daemon can act on the saved automatic-update preference. */
|
|
69
69
|
automaticUpdateAdvice(): Promise<string | undefined>;
|
|
70
70
|
extensions(): readonly InstalledExtension[];
|
|
@@ -88,7 +88,7 @@ export interface UpdateRuntime {
|
|
|
88
88
|
npm(args: string[], inherit?: boolean): CommandResult;
|
|
89
89
|
npmAsync(args: string[], archiveCache?: string): Promise<CommandResult>;
|
|
90
90
|
spawn(file: string, args: string[], env: NodeJS.ProcessEnv, inherit?: boolean): CommandResult;
|
|
91
|
-
spawnGlobal(root: string, operation: "install" | "reconcile", file: string, args: string[], env: NodeJS.ProcessEnv, inherit?: boolean, windowsVerbatimArguments?: boolean): Promise<CommandResult>;
|
|
91
|
+
spawnGlobal(root: string, operation: "install" | "reconcile", file: string, args: string[], env: NodeJS.ProcessEnv, inherit?: boolean, windowsVerbatimArguments?: boolean, staging?: string): Promise<CommandResult>;
|
|
92
92
|
verifyGlobalEntry(root: string, expectedVersion: string): string;
|
|
93
93
|
out(message: string): void;
|
|
94
94
|
err(message: string): void;
|
|
@@ -108,7 +108,7 @@ export declare function recoverInterruptedUpdate(rt?: UpdateRuntime, startup?: b
|
|
|
108
108
|
/** Check mode is installation metadata only; target and mutation inputs are never ignored. */
|
|
109
109
|
export declare function validateUpdateArguments(args: ParsedArgs): void;
|
|
110
110
|
/** Injectable command body: production keeps one process seam; the smoke covers every decision branch. */
|
|
111
|
-
export declare function executeUpdate(self: boolean, rt?: UpdateRuntime, target?: Record<string, unknown
|
|
111
|
+
export declare function executeUpdate(self: boolean, rt?: UpdateRuntime, target?: Record<string, unknown>, unreadableSelection?: UnreadableConnectorSelection): Promise<number>;
|
|
112
112
|
/** Keep a first-party extension that npm's record in the prefix proves installed at `generation`,
|
|
113
113
|
* rebinding its shared peers to this binary's copies as its reinstall would; otherwise say why it
|
|
114
114
|
* still needs that reinstall. The update pass calls it under its own claim, so it needs no child. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../src/commands/update.ts"],"names":[],"mappings":"AAMA,OAAO,EAAmB,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO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5F;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,CAgB/E"}
|
package/dist/commands/update.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { spawn, spawnSync } from "node:child_process";
|
|
2
2
|
import { lookup } from "node:dns/promises";
|
|
3
|
-
import { existsSync, lstatSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { existsSync, lstatSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync, statSync, watch, writeFileSync } from "node:fs";
|
|
4
4
|
import { homedir, tmpdir } from "node:os";
|
|
5
5
|
import { isIP, SocketAddress } from "node:net";
|
|
6
|
-
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
6
|
+
import { basename, dirname, isAbsolute, join, parse, relative, resolve, sep } from "node:path";
|
|
7
7
|
import { globalConfigDir } from "@cotal-ai/core";
|
|
8
|
-
import { CommandFailure, isCommandFailure, jsonFlag, plainFlag, presentationOf, protectedLocalDirectory, renderReport, writeResult, cmdSpawnSpec, beginGlobalUpdateChild, processGroupMembers, processStartToken, claimUpdateClosureAccess, updateClosureOwner, homeCotalDir, isMeshRegistryError, preparedRecordSkipped, preparedRecordSpace, preparedSpacesDir, readPreparedSpaces, recordOperationWarning, readUpdateRecovery, clearUpdateRecovery, writeUpdateRecovery, readUpdateSettings, observeUpdateVersion, UPDATE_HOUR_MS, recordUpdateCompletion, recordUpdateDeferral, recordUpdateReleaseHold, recordUpdateRefusal, recordUpdateReplacement, prepareConnectorConfigForUpdate, setUpdateSetting, bindExtensionPeers, claimGlobalNpmUpdateLock, launcherInstallRoot, logicalExecutionEntry, loadExtensionsManifest, provenance, SEEDED_EXTENSIONS, targetFlags, resolveControlTarget, recoveryDisposition, liveUpdateClosureOwner, recoveryProcessStartToken, observeUnownedRecovery, } from "@cotal-ai/workspace";
|
|
8
|
+
import { CommandFailure, isCommandFailure, jsonFlag, plainFlag, presentationOf, protectedLocalDirectory, renderReport, writeResult, cmdSpawnSpec, oneLine, beginGlobalUpdateChild, processGroupMembers, processStartToken, claimUpdateClosureAccess, updateClosureOwner, homeCotalDir, isMeshRegistryError, preparedRecordSkipped, preparedRecordSpace, preparedSpacesDir, readPreparedSpaces, recordOperationWarning, readUpdateRecovery, clearUpdateRecovery, writeUpdateRecovery, readUpdateSettings, observeUpdateVersion, UPDATE_HOUR_MS, recordUpdateCompletion, recordUpdateDeferral, recordUpdateReleaseHold, recordUpdateRefusal, recordUpdateReplacement, prepareConnectorConfigForUpdate, setUpdateSetting, bindExtensionPeers, claimGlobalNpmUpdateLock, launcherInstallRoot, logicalExecutionEntry, loadExtensionsManifest, provenance, SEEDED_EXTENSIONS, targetFlags, resolveControlTarget, recoveryDisposition, liveUpdateClosureOwner, recoveryProcessStartToken, observeUnownedRecovery, UnreadableConnectorSelection, } from "@cotal-ai/workspace";
|
|
9
9
|
import { retainUnusableRecovery } from "../lib/update-recovery-state.js";
|
|
10
10
|
import { readUpdatePending } from "../lib/update-pending.js";
|
|
11
11
|
import { snapshotUpdateClosure } from "../lib/update-snapshot.js";
|
|
@@ -21,9 +21,9 @@ import { cliPackageRoot, entryScript, seedWriterKind } from "../seed/paths.js";
|
|
|
21
21
|
import { refreshConnectorInstalls } from "./setup.js";
|
|
22
22
|
import { c } from "../ui.js";
|
|
23
23
|
import { assertEndpointUnreachable } from "../lib/endpoint-cut.js";
|
|
24
|
-
import { supervisorMayServe } from "../lib/manager-proc.js";
|
|
24
|
+
import { isCliEntry, supervisorMayServe } from "../lib/manager-proc.js";
|
|
25
25
|
import { processGone, readStackJournal, stackScopeRefusals } from "../lib/stack-journal.js";
|
|
26
|
-
import { observeServiceProcess, serviceInstances } from "../lib/service-instances.js";
|
|
26
|
+
import { observeServiceProcess, serviceInstances, serviceInstanceStore } from "../lib/service-instances.js";
|
|
27
27
|
import { ConnectRefusal, isConnectRefusal, isWorkspaceTargetError, localMeshesForRoot, preparedNeverStarted, pruneStaleMeshes, renderWorkspaceError, resolveMeshTarget, } from "@cotal-ai/workspace";
|
|
28
28
|
import { refreshOwnedCompletions } from "../lib/completion-install.js";
|
|
29
29
|
import { legacyManagerReport, legacySeatLabel } from "../lib/legacy-manager-report.js";
|
|
@@ -214,6 +214,7 @@ async function updateInstallation(args, rt) {
|
|
|
214
214
|
remedy: "update the desktop app with its signed platform installer; no npm self-update was attempted",
|
|
215
215
|
});
|
|
216
216
|
}
|
|
217
|
+
let connectorSelection;
|
|
217
218
|
if (args.values.self === true) {
|
|
218
219
|
try {
|
|
219
220
|
rt.preflightExecution?.();
|
|
@@ -238,21 +239,30 @@ async function updateInstallation(args, rt) {
|
|
|
238
239
|
recoverExtensionPromotion();
|
|
239
240
|
}
|
|
240
241
|
catch (error) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
catch (error) {
|
|
252
|
-
rt.err(c.red(`✗ ${message(error)}`));
|
|
253
|
-
process.exitCode = 1;
|
|
254
|
-
return;
|
|
242
|
+
if (error instanceof UnreadableConnectorSelection)
|
|
243
|
+
connectorSelection = error;
|
|
244
|
+
else {
|
|
245
|
+
const failure = isCommandFailure(error) ? error : new CommandFailure("refused", "PERMISSION_DENIED", `Cannot prepare the Cotal connector configuration: ${message(error)}. No CLI update was staged.`, {
|
|
246
|
+
native: { outcome: "not-executed" }, remedy: "Correct the reported connector configuration problem, then run `cotal update --self` again.",
|
|
247
|
+
});
|
|
248
|
+
recordUpdateDeferral(rt.version(), `connector configuration preflight: ${preflightDetail(failure)}`);
|
|
249
|
+
throw failure;
|
|
250
|
+
}
|
|
255
251
|
}
|
|
252
|
+
// Built-in self-update skips the extension overlay. Validate its inventory after recovery.
|
|
253
|
+
if (!connectorSelection)
|
|
254
|
+
try {
|
|
255
|
+
loadExtensionsManifest();
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
if (error instanceof UnreadableConnectorSelection)
|
|
259
|
+
connectorSelection = error;
|
|
260
|
+
else {
|
|
261
|
+
rt.err(c.red(`✗ ${message(error)}`));
|
|
262
|
+
process.exitCode = 1;
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
256
266
|
}
|
|
257
267
|
const restored = await recoverInterruptedUpdate(rt);
|
|
258
268
|
if (restored) {
|
|
@@ -281,7 +291,7 @@ async function updateInstallation(args, rt) {
|
|
|
281
291
|
if (repaired)
|
|
282
292
|
rt.out(c.green(`✓ removed group and other write from ${repaired} ${repaired === 1 ? "entry" : "entries"} in Cotal's ${what} at ${root}`));
|
|
283
293
|
}
|
|
284
|
-
const code = await executeUpdate(Boolean(args.values.self), rt, args.values);
|
|
294
|
+
const code = await executeUpdate(Boolean(args.values.self), rt, args.values, restored ? undefined : connectorSelection);
|
|
285
295
|
if (code !== 0)
|
|
286
296
|
process.exitCode = code;
|
|
287
297
|
else if (args.values.self !== true && childBinding(rt).kind !== "bound") {
|
|
@@ -476,22 +486,23 @@ function checkUpdate(args, rt) {
|
|
|
476
486
|
warnings.push({ code: "RECONCILIATION_UNREADABLE", target: null, message: `Reconciliation state could not be read: ${reconciliation.error}` });
|
|
477
487
|
if (reconciliation.kind === "seed")
|
|
478
488
|
warnings.push({ code: "OPERATION_PARTIAL", target: null, message: reconciliation.instruction });
|
|
489
|
+
const manifestUnreadable = reconciliation.kind === "unreadable" && reconciliation.source === "manifest";
|
|
479
490
|
const result = { kind: "update-check", reconciliation, current, latest: latest.ok ? latest.version : null, updateAvailable: comparison === null ? null : comparison > 0, extensions, scope: "registry version and recorded installation versions", installationChanged: false, processesRestarted: false };
|
|
480
491
|
writeResult(presentationOf(args.values), {
|
|
481
492
|
command: "update", target: null, result, warnings,
|
|
482
493
|
...(warnings.length ? { completeness: "partial", partial: {
|
|
483
494
|
message: reconciliation.kind === "seed" ? "Connector seeding needs reconciliation." : "Some update information could not be established.",
|
|
484
|
-
remedy: reconciliation.kind === "seed" || reconciliation.kind === "unreadable" && reconciliation.source
|
|
495
|
+
remedy: reconciliation.kind === "seed" || reconciliation.kind === "unreadable" && reconciliation.source !== "receipt" ? reconciliation.instruction : missingNpm ? MISSING_NPM_REMEDY : "Check registry access or the unreadable inventory and repeat update --check.",
|
|
485
496
|
} } : {}),
|
|
486
497
|
}, (r) => ({ sections: [
|
|
487
498
|
...(r.reconciliation.kind === "none" ? [] : [{ title: "Reconciliation", blocks: [{ kind: "lines", lines: [r.reconciliation.instruction] }] }]),
|
|
488
499
|
{ title: "Update availability", blocks: [{ kind: "fields", rows: [["Running CLI", r.current], ["Registry latest", r.latest ?? "not established"], ["CLI update", r.updateAvailable === null ? { text: "unknown", tone: "waiting" } : r.updateAvailable ? { text: "available", tone: "waiting" } : comparison === 0 ? "matches latest tag" : "running version is ahead of latest tag"]] }] },
|
|
489
500
|
{ title: "Recorded extensions", blocks: [r.extensions === null ? { kind: "lines", lines: [{ text: "Inventory unavailable. No repair was attempted.", tone: "waiting" }] } : r.extensions.length ? { kind: "table", columns: [{ key: "package", label: "Package" }, { key: "version", label: "Recorded version" }, { key: "state", label: "Generation" }], rows: r.extensions.map((entry) => ({ package: entry.package, version: entry.version, state: !entry.firstParty ? { text: "third party", tone: "hint" } : entry.matchesCli ? { text: "matches running CLI", tone: "ok" } : { text: "differs from running CLI", tone: "waiting" } })) } : { kind: "lines", lines: ["No extensions in the recorded inventory."] }, { kind: "lines", lines: [{ text: "Version records only. Package contents, signatures and running processes were not checked. No installation was reconciled or restarted.", tone: "hint" }] }] },
|
|
490
|
-
{ title: "Next", blocks: [{ kind: "commands", items: [{ command: "cotal update", description: "Reconcile the current generation through the existing guarded updater" }, ...(r.updateAvailable ? [{ command: "cotal update --self", description: rt.checkout() ? "Install the verified latest CLI as a separate global copy and reconcile through it; this checkout does not change" : "Install the verified latest CLI and reconcile its generation" }] : []), { command: "cotal status", description: "Inspect this machine and its selected space" }] }] },
|
|
501
|
+
...(manifestUnreadable ? [] : [{ title: "Next", blocks: [{ kind: "commands", items: [{ command: "cotal update", description: "Reconcile the current generation through the existing guarded updater" }, ...(r.updateAvailable ? [{ command: "cotal update --self", description: rt.checkout() ? "Install the verified latest CLI as a separate global copy and reconcile through it; this checkout does not change" : "Install the verified latest CLI and reconcile its generation" }] : []), { command: "cotal status", description: "Inspect this machine and its selected space" }] }] }]),
|
|
491
502
|
] }));
|
|
492
503
|
}
|
|
493
504
|
/** Injectable command body: production keeps one process seam; the smoke covers every decision branch. */
|
|
494
|
-
export async function executeUpdate(self, rt = updateRuntime, target = {}) {
|
|
505
|
+
export async function executeUpdate(self, rt = updateRuntime, target = {}, unreadableSelection) {
|
|
495
506
|
const current = rt.version();
|
|
496
507
|
const child = childBinding(rt);
|
|
497
508
|
if (child.kind === "invalid") {
|
|
@@ -547,9 +558,13 @@ export async function executeUpdate(self, rt = updateRuntime, target = {}) {
|
|
|
547
558
|
rt.err(c.red(`✗ cotal-ai version check failed: ${latest.error}. ${MISSING_NPM_REMEDY}`));
|
|
548
559
|
return 1;
|
|
549
560
|
}
|
|
561
|
+
if (!latest.npmResult || !(releaseReadError(latest.npmResult, "cotal-ai version check failed") instanceof RegistryUnavailable)) {
|
|
562
|
+
rt.err(c.red(`✗ cotal-ai version check failed: ${oneLine(latest.error.split(/\r?\n/, 1)[0])}`));
|
|
563
|
+
return 1;
|
|
564
|
+
}
|
|
550
565
|
if (rt.env.COTAL_AUTO_UPDATE === "1")
|
|
551
566
|
recordUpdateDeferral(current, "waiting for registry availability", true);
|
|
552
|
-
else if (
|
|
567
|
+
else if (await npmProxyRefused(latest.npmResult, rt.env)) {
|
|
553
568
|
rt.err("The npm proxy refused the connection (ECONNREFUSED). The update did not start. Check HTTP_PROXY and HTTPS_PROXY, then retry.");
|
|
554
569
|
return 1;
|
|
555
570
|
}
|
|
@@ -567,11 +582,20 @@ export async function executeUpdate(self, rt = updateRuntime, target = {}) {
|
|
|
567
582
|
recordUpdateDeferral(current, "waiting for update preflight");
|
|
568
583
|
}
|
|
569
584
|
if (upgrading) {
|
|
585
|
+
// Replacing packages still requires an identifiable graph for dependency checks and rollback.
|
|
586
|
+
if (unreadableSelection)
|
|
587
|
+
throw unreadableSelection;
|
|
570
588
|
const code = await upgradeAndReconcile(latest.version, current, rt, target);
|
|
571
589
|
if (code === 0 && rt.env.COTAL_AUTO_UPDATE !== "1")
|
|
572
590
|
rt.generationWaited = true;
|
|
573
591
|
return code;
|
|
574
592
|
}
|
|
593
|
+
if (unreadableSelection) {
|
|
594
|
+
rt.err(unreadableSelection.message);
|
|
595
|
+
rt.out("No newer CLI version. No connector reconciliation was run.");
|
|
596
|
+
reportVersion(current, latest.version, rt, false);
|
|
597
|
+
return 0;
|
|
598
|
+
}
|
|
575
599
|
if (rt.isCurrent?.()) {
|
|
576
600
|
reportUncheckedPreparedRecords(rt, target);
|
|
577
601
|
rt.out("No newer CLI version; installed package closure is current. No connector reconciliation was run.");
|
|
@@ -936,6 +960,38 @@ export async function readUpdateManagerContinuity(manager, flags, readOne = read
|
|
|
936
960
|
return "none";
|
|
937
961
|
}
|
|
938
962
|
}
|
|
963
|
+
/** Link the answering Manager to the controller's live process before excluding its installation. */
|
|
964
|
+
function isForeignStackManager(target, status, installedEntry) {
|
|
965
|
+
if (process.platform !== "linux" || !target.root || !status || typeof status.instanceId !== "string" || typeof status.lifecycleUid !== "string")
|
|
966
|
+
return false;
|
|
967
|
+
try {
|
|
968
|
+
const journal = readStackJournal(target.root)?.journal;
|
|
969
|
+
if (!journal || journal.operation.kind !== "up" || journal.operation.phase !== "completed" || journal.space !== target.space || brokerAddressKey(journal.server) !== brokerAddressKey(target.server))
|
|
970
|
+
return false;
|
|
971
|
+
const member = journal.members.find(row => row.role === "manager");
|
|
972
|
+
if (!member?.instanceId || !member.process)
|
|
973
|
+
return false;
|
|
974
|
+
const instance = serviceInstanceStore(target.space).read(member.instanceId)?.record.value;
|
|
975
|
+
const native = instance?.adapterReadiness?.native;
|
|
976
|
+
if (!instance?.process || instance.definition !== member.definition || instance.state !== "running" ||
|
|
977
|
+
instance.process.pid !== member.process.pid || instance.process.token !== member.process.token ||
|
|
978
|
+
native?.instanceId !== status.instanceId || native.lifecycleUid !== status.lifecycleUid || observeServiceProcess(instance) !== "running")
|
|
979
|
+
return false;
|
|
980
|
+
const argv = readFileSync(`/proc/${instance.process.pid}/cmdline`, "utf8").split("\0");
|
|
981
|
+
// The controller places only the optional global color flag after its Node entry.
|
|
982
|
+
const verb = argv.indexOf("__service-manager");
|
|
983
|
+
const launch = argv[verb - (argv[verb - 1] === "--no-color" ? 2 : 1)];
|
|
984
|
+
if (!launch || !isAbsolute(launch))
|
|
985
|
+
return false;
|
|
986
|
+
const entry = realpathSync(launch);
|
|
987
|
+
const own = realpathSync(installedEntry ?? logicalExecutionEntry() ?? entryScript());
|
|
988
|
+
return entry !== own && isCliEntry(entry) && assertRecordIdentity(instance.process).kind === "match";
|
|
989
|
+
}
|
|
990
|
+
catch {
|
|
991
|
+
// An unreadable record or launch entry cannot prove a different installation.
|
|
992
|
+
return false;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
939
995
|
export async function readManagerContinuity(flags, options = {}) {
|
|
940
996
|
const { readMeshRegistry } = await import("@cotal-ai/workspace");
|
|
941
997
|
const registry = readMeshRegistry();
|
|
@@ -1113,6 +1169,8 @@ export async function readManagerContinuity(flags, options = {}) {
|
|
|
1113
1169
|
return "none";
|
|
1114
1170
|
throw new Error(status.error ?? "manager status request failed");
|
|
1115
1171
|
}
|
|
1172
|
+
if (typeof flags.creds !== "string" && isForeignStackManager(target, status.data, options.installedEntry))
|
|
1173
|
+
return "none";
|
|
1116
1174
|
const seats = await askManager(cliControl, target.space, target.server, "ps", undefined, target.auth, "owner", undefined, pin);
|
|
1117
1175
|
if (!seats.ok)
|
|
1118
1176
|
throw new Error(seats.error ?? "manager seat inventory request failed");
|
|
@@ -1407,7 +1465,7 @@ class DependencyCheckNoSpace extends Error {
|
|
|
1407
1465
|
}
|
|
1408
1466
|
class RegistryUnavailable extends Error {
|
|
1409
1467
|
}
|
|
1410
|
-
const NETWORK_ERROR_CODE = /^(?:ENETUNREACH|EHOSTUNREACH|ENETDOWN|EHOSTDOWN|ECONNRESET|ECONNREFUSED|ECONNABORTED|ETIMEDOUT|ESOCKETTIMEDOUT|EAI_AGAIN|ENOTFOUND)$/;
|
|
1468
|
+
const NETWORK_ERROR_CODE = /^(?:ENETUNREACH|EHOSTUNREACH|ENETDOWN|EHOSTDOWN|ECONNRESET|ECONNREFUSED|ECONNABORTED|ETIMEDOUT|EIDLETIMEOUT|ESOCKETTIMEDOUT|EAI_AGAIN|ENOTFOUND)$/;
|
|
1411
1469
|
function registryNetworkFailure(error) {
|
|
1412
1470
|
if (error instanceof RegistryUnavailable)
|
|
1413
1471
|
return true;
|
|
@@ -1636,7 +1694,7 @@ async function upgradeAndReconcile(targetVersion, current, rt, target) {
|
|
|
1636
1694
|
}
|
|
1637
1695
|
catch { /* an unpublished copy left behind selects nothing */ }
|
|
1638
1696
|
releaseGlobal();
|
|
1639
|
-
if (!execution && message(error).startsWith("target staging failed: ") && registryNetworkFailure(error)) {
|
|
1697
|
+
if (!execution && (error instanceof RegistryUnavailable || message(error).startsWith("target staging failed: ") && registryNetworkFailure(error))) {
|
|
1640
1698
|
recordUpdateDeferral(targetVersion, "waiting for registry access", true);
|
|
1641
1699
|
rt.out("The registry cannot be reached; nothing was changed.");
|
|
1642
1700
|
return 0;
|
|
@@ -1763,12 +1821,13 @@ async function upgradeAndReconcile(targetVersion, current, rt, target) {
|
|
|
1763
1821
|
rt.err(c.red(`✗ cotal-ai@${targetVersion} installed globally, but its reconcile failed: ${failure(child)}`));
|
|
1764
1822
|
return await repairReplacement(`reconcile failed: ${failure(child)}`, child.status ?? 1, readUpdateRecovery()?.phase === "verified-ready");
|
|
1765
1823
|
}
|
|
1824
|
+
let activationDeferred = undefined;
|
|
1766
1825
|
if (rt.env.COTAL_AUTO_UPDATE !== "1" || rt.automaticGenerationWait) {
|
|
1767
1826
|
try {
|
|
1768
1827
|
const recovery = readUpdateRecovery();
|
|
1769
1828
|
if (recovery && recovery.phase !== "verified-ready")
|
|
1770
1829
|
writeUpdateRecovery({ ...recovery, installed: targetVersion, phase: "verified-ready" });
|
|
1771
|
-
await rt.waitForInstalledGeneration?.(targetVersion);
|
|
1830
|
+
activationDeferred = await rt.waitForInstalledGeneration?.(targetVersion);
|
|
1772
1831
|
}
|
|
1773
1832
|
catch (error) {
|
|
1774
1833
|
rt.err(c.red(`✗ installed daemon generation: ${refusal(error)}`));
|
|
@@ -1784,8 +1843,12 @@ async function upgradeAndReconcile(targetVersion, current, rt, target) {
|
|
|
1784
1843
|
rt.out("Removing completed update recovery snapshot");
|
|
1785
1844
|
snapshot.discard();
|
|
1786
1845
|
clearUpdateRecovery();
|
|
1787
|
-
recordUpdateCompletion(targetVersion, `updated to ${targetVersion}`,
|
|
1846
|
+
recordUpdateCompletion(targetVersion, activationDeferred || `updated to ${targetVersion}`, !activationDeferred);
|
|
1788
1847
|
execution?.complete?.();
|
|
1848
|
+
if (activationDeferred) {
|
|
1849
|
+
rt.err(activationDeferred);
|
|
1850
|
+
return interrupted || 1;
|
|
1851
|
+
}
|
|
1789
1852
|
if (stagedExecution)
|
|
1790
1853
|
rt.out(c.green(`✓ cotal-ai@${targetVersion} in use and reconciled`));
|
|
1791
1854
|
else
|
|
@@ -1974,7 +2037,7 @@ async function runNpmAsync(args, archiveCache) {
|
|
|
1974
2037
|
const gated = archiveCache !== undefined && (process.platform === "linux" || process.platform === "darwin");
|
|
1975
2038
|
const gate = 'IFS= read -r permit <&3 && [ "$permit" = run ] || exit 1; exec 3<&-; exec "$@"';
|
|
1976
2039
|
const child = spawn(gated ? "/bin/sh" : file, gated ? ["-c", gate, "cotal-release-check", file, ...spawnArgs] : spawnArgs, {
|
|
1977
|
-
windowsVerbatimArguments, windowsHide: true,
|
|
2040
|
+
cwd: parse(homedir()).root, windowsVerbatimArguments, windowsHide: true,
|
|
1978
2041
|
...(gated ? { detached: true, stdio: ["ignore", "pipe", "pipe", "pipe"] } : {}),
|
|
1979
2042
|
});
|
|
1980
2043
|
let stdout = "", stderr = "", error;
|
|
@@ -2007,9 +2070,10 @@ async function runNpmAsync(args, archiveCache) {
|
|
|
2007
2070
|
function runNpm(args, inherit = false) {
|
|
2008
2071
|
try {
|
|
2009
2072
|
const { file, args: spawnArgs, windowsVerbatimArguments } = cmdSpawnSpec("npm", args);
|
|
2010
|
-
const result = spawnSync(file, spawnArgs,
|
|
2011
|
-
|
|
2012
|
-
: { encoding: "utf8"
|
|
2073
|
+
const result = spawnSync(file, spawnArgs, {
|
|
2074
|
+
cwd: parse(homedir()).root, windowsVerbatimArguments,
|
|
2075
|
+
...(inherit ? { stdio: "inherit" } : { encoding: "utf8" }),
|
|
2076
|
+
});
|
|
2013
2077
|
return {
|
|
2014
2078
|
status: result.status,
|
|
2015
2079
|
signal: result.signal,
|
|
@@ -2032,18 +2096,33 @@ function runProcess(file, args, env, inherit = false) {
|
|
|
2032
2096
|
error: result.error?.message,
|
|
2033
2097
|
};
|
|
2034
2098
|
}
|
|
2035
|
-
async function runGlobalProcess(root, operation, file, args, env, inherit = false, windowsVerbatimArguments = false) {
|
|
2099
|
+
async function runGlobalProcess(root, operation, file, args, env, inherit = false, windowsVerbatimArguments = false, staging) {
|
|
2036
2100
|
const gated = process.platform === "linux";
|
|
2037
2101
|
const mutation = beginGlobalUpdateChild(root, operation, gated);
|
|
2038
2102
|
let cache;
|
|
2039
2103
|
let published = false;
|
|
2040
2104
|
let preservePending = false;
|
|
2105
|
+
const watchers = [];
|
|
2106
|
+
let elapsed;
|
|
2107
|
+
let idle;
|
|
2108
|
+
let stopping;
|
|
2041
2109
|
try {
|
|
2042
2110
|
cache = mkdtempSync(join(tmpdir(), "cotal-update-npm-"));
|
|
2111
|
+
if (staging !== undefined) {
|
|
2112
|
+
// npm is quiet during a download. Its private cache receives the archive bytes and
|
|
2113
|
+
// the private prefix changes as packages unpack. Neither depends on terminal output.
|
|
2114
|
+
for (const path of [cache, staging]) {
|
|
2115
|
+
const watcher = watch(path, { recursive: true }, () => idle?.refresh());
|
|
2116
|
+
watcher.on("error", () => { clearTimeout(idle); idle = undefined; watcher.close(); });
|
|
2117
|
+
watchers.push(watcher);
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2043
2120
|
// The pipe closes without permission if the parent dies before publishing the PID.
|
|
2044
2121
|
// exec keeps the published PID and the real child keeps its original argv and stdin.
|
|
2045
2122
|
const gate = 'IFS= read -r permit <&3 && [ "$permit" = run ] || exit 1; exec 3<&-; exec "$@"';
|
|
2046
2123
|
const child = withInstallUmask(() => spawn(gated ? "/bin/sh" : file, gated ? ["-c", gate, "cotal-update", file, ...args] : args, {
|
|
2124
|
+
// Corepack searches ancestors for a package manager. Keep only npm at the filesystem root.
|
|
2125
|
+
...(operation === "install" ? { cwd: parse(homedir()).root } : {}),
|
|
2047
2126
|
env: { ...env, npm_config_cache: cache, npm_config_logs_max: "0", npm_config_update_notifier: "false" },
|
|
2048
2127
|
// A separate process group keeps terminal interrupts out of npm's live replacement.
|
|
2049
2128
|
// Keep the ChildProcess referenced and await close; this is not a background update.
|
|
@@ -2071,7 +2150,63 @@ async function runGlobalProcess(root, operation, file, args, env, inherit = fals
|
|
|
2071
2150
|
}
|
|
2072
2151
|
}
|
|
2073
2152
|
permit?.end(published ? "run\n" : undefined);
|
|
2074
|
-
|
|
2153
|
+
let rejectClose;
|
|
2154
|
+
const close = new Promise((resolveClose, reject) => {
|
|
2155
|
+
rejectClose = reject;
|
|
2156
|
+
child.once("close", (status, signal) => resolveClose({ status, signal }));
|
|
2157
|
+
});
|
|
2158
|
+
if (staging !== undefined && child.pid !== undefined) {
|
|
2159
|
+
const pgid = child.pid;
|
|
2160
|
+
const signalGroup = (signal) => {
|
|
2161
|
+
try {
|
|
2162
|
+
process.kill(-pgid, signal);
|
|
2163
|
+
}
|
|
2164
|
+
catch (error) {
|
|
2165
|
+
if (error.code !== "ESRCH")
|
|
2166
|
+
throw error;
|
|
2167
|
+
}
|
|
2168
|
+
};
|
|
2169
|
+
const grace = 2000;
|
|
2170
|
+
const reap = 1000;
|
|
2171
|
+
const stop = () => {
|
|
2172
|
+
if (stopping)
|
|
2173
|
+
return;
|
|
2174
|
+
clearTimeout(elapsed);
|
|
2175
|
+
clearTimeout(idle);
|
|
2176
|
+
stopping = (async () => {
|
|
2177
|
+
signalGroup("SIGTERM");
|
|
2178
|
+
await new Promise(resolve => setTimeout(resolve, grace));
|
|
2179
|
+
if (processGroupMembers(pgid).length)
|
|
2180
|
+
signalGroup("SIGKILL");
|
|
2181
|
+
const deadline = performance.now() + reap;
|
|
2182
|
+
while (processGroupMembers(pgid).length) {
|
|
2183
|
+
if (performance.now() >= deadline)
|
|
2184
|
+
throw new Error(`could not stop staging npm process group ${pgid}`);
|
|
2185
|
+
await new Promise(resolve => setTimeout(resolve, 25));
|
|
2186
|
+
}
|
|
2187
|
+
})();
|
|
2188
|
+
void stopping.catch(error => {
|
|
2189
|
+
child.stdin?.destroy();
|
|
2190
|
+
child.stdout?.destroy();
|
|
2191
|
+
child.stderr?.destroy();
|
|
2192
|
+
child.unref();
|
|
2193
|
+
rejectClose(error);
|
|
2194
|
+
});
|
|
2195
|
+
};
|
|
2196
|
+
// Leave room for TERM and KILL within the five-minute staging budget. Idle time
|
|
2197
|
+
// covers three 15-second fetch attempts plus their one- and two-second backoffs.
|
|
2198
|
+
elapsed = setTimeout(stop, 300_000 - grace - reap);
|
|
2199
|
+
idle = setTimeout(stop, 50_000);
|
|
2200
|
+
}
|
|
2201
|
+
const closed = await close;
|
|
2202
|
+
clearTimeout(elapsed);
|
|
2203
|
+
clearTimeout(idle);
|
|
2204
|
+
if (stopping) {
|
|
2205
|
+
await stopping;
|
|
2206
|
+
if (published)
|
|
2207
|
+
mutation.clear();
|
|
2208
|
+
throw new RegistryUnavailable("target staging could not reach the registry");
|
|
2209
|
+
}
|
|
2075
2210
|
if (published)
|
|
2076
2211
|
mutation.complete(closed.status, closed.signal, closed.signal !== null
|
|
2077
2212
|
? `${operation} child terminated by ${closed.signal}`
|
|
@@ -2079,9 +2214,15 @@ async function runGlobalProcess(root, operation, file, args, env, inherit = fals
|
|
|
2079
2214
|
return { status: error ? null : closed.status, signal: closed.signal, stdout, stderr, ...(error ? { error } : {}) };
|
|
2080
2215
|
}
|
|
2081
2216
|
catch (e) {
|
|
2217
|
+
if (e instanceof RegistryUnavailable)
|
|
2218
|
+
throw e;
|
|
2082
2219
|
return { status: null, stdout: "", stderr: "", error: message(e) };
|
|
2083
2220
|
}
|
|
2084
2221
|
finally {
|
|
2222
|
+
for (const watcher of watchers)
|
|
2223
|
+
watcher.close();
|
|
2224
|
+
clearTimeout(elapsed);
|
|
2225
|
+
clearTimeout(idle);
|
|
2085
2226
|
if (!published && !preservePending)
|
|
2086
2227
|
mutation.clear();
|
|
2087
2228
|
if (cache)
|