@cotal-ai/cli 0.171.1 → 0.171.3
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 +140 -85
- package/dist/command.js.map +1 -1
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +12 -8
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/app-identity.d.ts +6 -0
- package/dist/commands/app-identity.d.ts.map +1 -1
- package/dist/commands/app-identity.js +4 -4
- package/dist/commands/app-identity.js.map +1 -1
- package/dist/commands/backup-maintenance.js +1 -1
- package/dist/commands/backup-maintenance.js.map +1 -1
- package/dist/commands/backup.d.ts.map +1 -1
- package/dist/commands/backup.js +12 -5
- package/dist/commands/backup.js.map +1 -1
- package/dist/commands/down.d.ts.map +1 -1
- package/dist/commands/down.js +11 -7
- package/dist/commands/down.js.map +1 -1
- package/dist/commands/ext.js +1 -1
- package/dist/commands/ext.js.map +1 -1
- package/dist/commands/help.d.ts.map +1 -1
- package/dist/commands/help.js +2 -13
- package/dist/commands/help.js.map +1 -1
- package/dist/commands/history-clear.d.ts.map +1 -1
- package/dist/commands/history-clear.js +18 -2
- package/dist/commands/history-clear.js.map +1 -1
- package/dist/commands/join.js +7 -2
- package/dist/commands/join.js.map +1 -1
- package/dist/commands/manager-service.d.ts +1 -1
- package/dist/commands/manager-service.d.ts.map +1 -1
- package/dist/commands/manager-service.js +9 -4
- package/dist/commands/manager-service.js.map +1 -1
- package/dist/commands/reset-space-apply.d.ts.map +1 -1
- package/dist/commands/reset-space-apply.js +2 -1
- package/dist/commands/reset-space-apply.js.map +1 -1
- package/dist/commands/reset-store-apply.d.ts +6 -0
- package/dist/commands/reset-store-apply.d.ts.map +1 -1
- package/dist/commands/reset-store-apply.js +22 -2
- package/dist/commands/reset-store-apply.js.map +1 -1
- package/dist/commands/service-registry.d.ts.map +1 -1
- package/dist/commands/service-registry.js +2 -0
- package/dist/commands/service-registry.js.map +1 -1
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +14 -2
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/space-registration.d.ts +3 -1
- package/dist/commands/space-registration.d.ts.map +1 -1
- package/dist/commands/space-registration.js +20 -14
- package/dist/commands/space-registration.js.map +1 -1
- package/dist/commands/space.d.ts +1 -0
- package/dist/commands/space.d.ts.map +1 -1
- package/dist/commands/space.js +5 -1
- package/dist/commands/space.js.map +1 -1
- package/dist/commands/spawn-preview.d.ts +1 -1
- package/dist/commands/spawn-preview.d.ts.map +1 -1
- package/dist/commands/spawn-preview.js +36 -6
- package/dist/commands/spawn-preview.js.map +1 -1
- package/dist/commands/spawn.d.ts +7 -2
- package/dist/commands/spawn.d.ts.map +1 -1
- package/dist/commands/spawn.js +158 -75
- package/dist/commands/spawn.js.map +1 -1
- package/dist/commands/stack-down.js +9 -4
- package/dist/commands/stack-down.js.map +1 -1
- package/dist/commands/stack-gone.d.ts +8 -5
- package/dist/commands/stack-gone.d.ts.map +1 -1
- package/dist/commands/stack-gone.js +8 -6
- package/dist/commands/stack-gone.js.map +1 -1
- package/dist/commands/stack-up.d.ts +2 -1
- package/dist/commands/stack-up.d.ts.map +1 -1
- package/dist/commands/stack-up.js +9 -5
- package/dist/commands/stack-up.js.map +1 -1
- package/dist/commands/status.d.ts +6 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +71 -27
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/up.d.ts +2 -1
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +72 -43
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/update.d.ts +9 -3
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +230 -40
- package/dist/commands/update.js.map +1 -1
- package/dist/ext-loader.d.ts +1 -1
- package/dist/ext-loader.d.ts.map +1 -1
- package/dist/ext-loader.js +3 -3
- package/dist/ext-loader.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/backup-artifact.d.ts.map +1 -1
- package/dist/lib/backup-artifact.js +11 -3
- package/dist/lib/backup-artifact.js.map +1 -1
- package/dist/lib/credential-authority.d.ts.map +1 -1
- package/dist/lib/credential-authority.js +3 -1
- package/dist/lib/credential-authority.js.map +1 -1
- package/dist/lib/delivery-proc.d.ts +2 -1
- package/dist/lib/delivery-proc.d.ts.map +1 -1
- package/dist/lib/delivery-proc.js.map +1 -1
- package/dist/lib/local-process-stop.d.ts +2 -0
- package/dist/lib/local-process-stop.d.ts.map +1 -1
- package/dist/lib/local-process-stop.js +1 -0
- package/dist/lib/local-process-stop.js.map +1 -1
- package/dist/lib/manager-proc.d.ts +4 -2
- package/dist/lib/manager-proc.d.ts.map +1 -1
- package/dist/lib/manager-proc.js +10 -3
- package/dist/lib/manager-proc.js.map +1 -1
- package/dist/lib/manifest/render.d.ts.map +1 -1
- package/dist/lib/manifest/render.js +4 -0
- package/dist/lib/manifest/render.js.map +1 -1
- package/dist/lib/nats-bin.d.ts +1 -0
- package/dist/lib/nats-bin.d.ts.map +1 -1
- package/dist/lib/nats-bin.js +1 -0
- package/dist/lib/nats-bin.js.map +1 -1
- package/dist/lib/persona-files.d.ts +1 -1
- package/dist/lib/persona-files.d.ts.map +1 -1
- package/dist/lib/persona-files.js +10 -2
- package/dist/lib/persona-files.js.map +1 -1
- package/dist/lib/registry-errors.d.ts +4 -0
- package/dist/lib/registry-errors.d.ts.map +1 -1
- package/dist/lib/registry-errors.js +3 -2
- package/dist/lib/registry-errors.js.map +1 -1
- package/dist/lib/restore.d.ts +4 -3
- 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/self-exec.d.ts.map +1 -1
- package/dist/lib/self-exec.js +24 -3
- package/dist/lib/self-exec.js.map +1 -1
- package/dist/lib/service-adapters.d.ts +1 -1
- package/dist/lib/service-adapters.d.ts.map +1 -1
- package/dist/lib/service-adapters.js +2 -2
- package/dist/lib/service-adapters.js.map +1 -1
- package/dist/lib/service-census.d.ts +5 -5
- package/dist/lib/service-install-intent.d.ts +2 -2
- package/dist/lib/service-instances.d.ts +2 -2
- package/dist/lib/service-preset-target.d.ts.map +1 -1
- package/dist/lib/service-preset-target.js +6 -1
- package/dist/lib/service-preset-target.js.map +1 -1
- package/dist/lib/service-presets.d.ts +1 -1
- package/dist/lib/service-presets.d.ts.map +1 -1
- package/dist/lib/service-presets.js +7 -5
- package/dist/lib/service-presets.js.map +1 -1
- package/dist/lib/service-process.d.ts +2 -0
- package/dist/lib/service-process.d.ts.map +1 -1
- package/dist/lib/service-process.js +3 -3
- package/dist/lib/service-process.js.map +1 -1
- package/dist/lib/service-supervision.d.ts +1 -1
- package/dist/lib/service-systemd-attempt-read.d.ts +3 -3
- package/dist/lib/service-uninstall-intent.d.ts +2 -2
- package/dist/lib/stack-journal.d.ts +5 -2
- package/dist/lib/stack-journal.d.ts.map +1 -1
- package/dist/lib/stack-journal.js +5 -2
- package/dist/lib/stack-journal.js.map +1 -1
- package/dist/lib/team-agent-removal.d.ts +1 -1
- package/dist/lib/update-pending.d.ts.map +1 -1
- package/dist/lib/update-pending.js +4 -2
- package/dist/lib/update-pending.js.map +1 -1
- package/dist/lib/update-snapshot.js +3 -3
- package/dist/lib/update-snapshot.js.map +1 -1
- package/dist/lib/version.d.ts +2 -0
- package/dist/lib/version.d.ts.map +1 -1
- package/dist/lib/version.js +15 -1
- package/dist/lib/version.js.map +1 -1
- package/dist/seed/reconcile.d.ts.map +1 -1
- package/dist/seed/reconcile.js +5 -2
- package/dist/seed/reconcile.js.map +1 -1
- package/package.json +12 -4
|
@@ -15,6 +15,7 @@ export declare const UPDATE_PARENT_WAITS_ENV = "COTAL_UPDATE_PARENT_WAITS";
|
|
|
15
15
|
export declare const updateFlags: readonly FlagSpec[];
|
|
16
16
|
interface CommandResult {
|
|
17
17
|
readonly status: number | null;
|
|
18
|
+
readonly signal?: NodeJS.Signals | null;
|
|
18
19
|
readonly stdout: string;
|
|
19
20
|
readonly stderr: string;
|
|
20
21
|
readonly error?: string;
|
|
@@ -74,14 +75,16 @@ export interface UpdateRuntime {
|
|
|
74
75
|
prepareReplacement?(): Promise<() => Promise<void>>;
|
|
75
76
|
/** Validate recorded local service ownership before replacing packages or reconciling connectors. */
|
|
76
77
|
preflightReplacement?(): Promise<void>;
|
|
77
|
-
claimGlobalUpdate(root: string): () => void;
|
|
78
|
+
claimGlobalUpdate(root: string, onWait?: () => void): () => void;
|
|
79
|
+
/** Read the selected global package again after acquiring its update reservation. */
|
|
80
|
+
globalVersion?(root: string): string | undefined;
|
|
78
81
|
selfArgv(): string[];
|
|
79
82
|
/** Whether this CLI runs from a source checkout, where `--self` installs a separate global copy. */
|
|
80
83
|
checkout(): boolean;
|
|
81
84
|
/** The verified prefix of an installed POSIX npm CLI, absent for a checkout or local/npx copy. */
|
|
82
85
|
installPrefix(): string | undefined;
|
|
83
86
|
npm(args: string[], inherit?: boolean): CommandResult;
|
|
84
|
-
npmAsync(args: string[]): Promise<CommandResult>;
|
|
87
|
+
npmAsync(args: string[], archiveCache?: string): Promise<CommandResult>;
|
|
85
88
|
spawn(file: string, args: string[], env: NodeJS.ProcessEnv, inherit?: boolean): CommandResult;
|
|
86
89
|
spawnGlobal(root: string, operation: "install" | "reconcile", file: string, args: string[], env: NodeJS.ProcessEnv, inherit?: boolean, windowsVerbatimArguments?: boolean): Promise<CommandResult>;
|
|
87
90
|
verifyGlobalEntry(root: string, expectedVersion: string): string;
|
|
@@ -96,7 +99,10 @@ export { installedCliVersion, repairInstallModes };
|
|
|
96
99
|
export declare const updateRuntime: UpdateRuntime;
|
|
97
100
|
export declare function update(args: ParsedArgs, rt?: UpdateRuntime): Promise<void>;
|
|
98
101
|
/** Resume an abandoned replacement before a command or daemon can activate its closure. */
|
|
99
|
-
export declare function recoverInterruptedUpdate(rt?: UpdateRuntime, startup?: boolean): Promise<
|
|
102
|
+
export declare function recoverInterruptedUpdate(rt?: UpdateRuntime, startup?: boolean): Promise<{
|
|
103
|
+
entry: string;
|
|
104
|
+
version: string;
|
|
105
|
+
} | undefined>;
|
|
100
106
|
/** Check mode is installation metadata only; target and mutation inputs are never ignored. */
|
|
101
107
|
export declare function validateUpdateArguments(args: ParsedArgs): void;
|
|
102
108
|
/** Injectable command body: production keeps one process seam; the smoke covers every decision branch. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../src/commands/update.ts"],"names":[],"mappings":"AAIA,OAAO,EAAmB,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../src/commands/update.ts"],"names":[],"mappings":"AAIA,OAAO,EAAmB,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAyBL,KAAK,kBAAkB,EAOxB,MAAM,qBAAqB,CAAC;AAO7B,OAAO,EAAE,kBAAkB,EAAoB,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAc,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAUpE,OAAO,EAUL,KAAK,UAAU,EAEhB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAwC,KAAK,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACjH,OAAO,EAAuB,KAAK,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAIhG,OAAO,EAA+C,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC5G,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,UAAU,IAAI,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAK1E;;2DAE2D;AAC3D,eAAO,MAAM,uBAAuB,8BAA8B,CAAC;AAEnE,eAAO,MAAM,WAAW,EAAE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B,GAC7B,IAAI,CAcN;AA4lBD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAYtD;AAQD;;qGAEqG;AACrG,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAa5F;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,CAgB/E"}
|
package/dist/commands/update.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
-
import { existsSync, lstatSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync } from "node:fs";
|
|
2
|
+
import { existsSync, lstatSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { homedir, tmpdir } from "node:os";
|
|
4
4
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
5
5
|
import { globalConfigDir } from "@cotal-ai/core";
|
|
6
|
-
import { CommandFailure, isCommandFailure, jsonFlag, plainFlag, presentationOf, protectedLocalDirectory, renderReport, writeResult, cmdSpawnSpec, beginGlobalUpdateChild, processStartToken, claimUpdateClosureAccess, updateClosureOwner, homeCotalDir, readUpdateRecovery, clearUpdateRecovery, writeUpdateRecovery, readUpdateSettings, recordUpdateCompletion, recordUpdateDeferral, recordUpdateRefusal, recordUpdateReplacement, setUpdateSetting, bindExtensionPeers, claimGlobalNpmUpdateLock, launcherInstallRoot, logicalExecutionEntry, loadExtensionsManifest, provenance, SEEDED_EXTENSIONS, targetFlags, resolveControlTarget, recoveryDisposition, liveUpdateClosureOwner, recoveryProcessStartToken, observeUnownedRecovery, } from "@cotal-ai/workspace";
|
|
6
|
+
import { CommandFailure, isCommandFailure, jsonFlag, plainFlag, presentationOf, protectedLocalDirectory, renderReport, writeResult, cmdSpawnSpec, beginGlobalUpdateChild, processGroupMembers, processStartToken, claimUpdateClosureAccess, updateClosureOwner, homeCotalDir, readUpdateRecovery, clearUpdateRecovery, writeUpdateRecovery, readUpdateSettings, recordUpdateCompletion, recordUpdateDeferral, recordUpdateRefusal, recordUpdateReplacement, setUpdateSetting, bindExtensionPeers, claimGlobalNpmUpdateLock, launcherInstallRoot, logicalExecutionEntry, loadExtensionsManifest, provenance, SEEDED_EXTENSIONS, targetFlags, resolveControlTarget, recoveryDisposition, liveUpdateClosureOwner, recoveryProcessStartToken, observeUnownedRecovery, } from "@cotal-ai/workspace";
|
|
7
7
|
import { retainUnusableRecovery } from "../lib/update-recovery-state.js";
|
|
8
8
|
import { readUpdatePending } from "../lib/update-pending.js";
|
|
9
9
|
import { snapshotUpdateClosure } from "../lib/update-snapshot.js";
|
|
@@ -31,7 +31,7 @@ import { managerPin } from "../lib/manager-choice.js";
|
|
|
31
31
|
import { localUpdateManagers, recordedUpdateManagers } from "../lib/update-managers.js";
|
|
32
32
|
export { localUpdateManagers } from "../lib/update-managers.js";
|
|
33
33
|
export { managerPin as updateManagerPin } from "../lib/manager-choice.js";
|
|
34
|
-
import { assertRecordIdentity, brokerAddressKey } from "@cotal-ai/workspace";
|
|
34
|
+
import { assertRecordIdentity, brokerAddressKey, brokerUrlKey } from "@cotal-ai/workspace";
|
|
35
35
|
const UPDATE_TARGET_ENV = "COTAL_UPDATE_TARGET_VERSION";
|
|
36
36
|
const UPDATE_PARENT_ENV = "COTAL_UPDATE_PARENT";
|
|
37
37
|
/** Set by a parent that waits for the installed daemon generation after its reconcile child and prints
|
|
@@ -87,7 +87,16 @@ export const updateRuntime = {
|
|
|
87
87
|
extensions: () => loadExtensionsManifest().extensions,
|
|
88
88
|
verifyExtension: verifyCurrentExtension,
|
|
89
89
|
claimUpdatePass: () => claimExtensionUpdatePass(),
|
|
90
|
-
claimGlobalUpdate: (root) => claimGlobalNpmUpdateLock(root, { waitMs: 10 * 60_000 }),
|
|
90
|
+
claimGlobalUpdate: (root, onWait) => claimGlobalNpmUpdateLock(root, { waitMs: 10 * 60_000, onWait }),
|
|
91
|
+
globalVersion: (root) => {
|
|
92
|
+
const path = join(root, "cotal-ai", "package.json");
|
|
93
|
+
if (!existsSync(path))
|
|
94
|
+
return undefined;
|
|
95
|
+
const meta = JSON.parse(readFileSync(path, "utf8"));
|
|
96
|
+
if (meta.name !== "cotal-ai" || !meta.version || !STRICT_SEMVER.test(meta.version))
|
|
97
|
+
throw new Error("the installed global cotal-ai version is invalid");
|
|
98
|
+
return meta.version;
|
|
99
|
+
},
|
|
91
100
|
selfArgv,
|
|
92
101
|
checkout: () => seedWriterKind() === "checkout",
|
|
93
102
|
installPrefix: () => {
|
|
@@ -163,10 +172,11 @@ export async function update(args, rt = updateRuntime) {
|
|
|
163
172
|
});
|
|
164
173
|
const environments = [...new Set([process.env, rt.env])];
|
|
165
174
|
const previous = environments.map(env => ({ env, values: { TMPDIR: env.TMPDIR, TMP: env.TMP, TEMP: env.TEMP } }));
|
|
175
|
+
let continuation;
|
|
166
176
|
try {
|
|
167
177
|
for (const env of environments)
|
|
168
178
|
Object.assign(env, { TMPDIR: scratch, TMP: scratch, TEMP: scratch });
|
|
169
|
-
await updateInstallation(args, rt);
|
|
179
|
+
continuation = await updateInstallation(args, rt);
|
|
170
180
|
}
|
|
171
181
|
finally {
|
|
172
182
|
for (const { env, values } of previous)
|
|
@@ -178,10 +188,23 @@ export async function update(args, rt = updateRuntime) {
|
|
|
178
188
|
}
|
|
179
189
|
rmSync(scratch, { recursive: true, force: true, maxRetries: 3 });
|
|
180
190
|
}
|
|
191
|
+
if (continuation) {
|
|
192
|
+
const result = rt.spawn(rt.nodePath, [continuation, "update", ...args.raw], rt.env, true);
|
|
193
|
+
if (result.error)
|
|
194
|
+
throw new Error(`cannot continue the update through the restored installation: ${result.error}`);
|
|
195
|
+
if (result.status !== 0)
|
|
196
|
+
process.exitCode = result.status ?? 1;
|
|
197
|
+
// The installed command owns any remaining activation and its exit result.
|
|
198
|
+
rt.generationWaited = true;
|
|
199
|
+
}
|
|
200
|
+
if (args.values.self === true && !process.exitCode && childBinding(rt).kind === "none")
|
|
201
|
+
collectArchiveCaches(dirname(scratch));
|
|
181
202
|
}
|
|
182
203
|
async function updateInstallation(args, rt) {
|
|
183
|
-
if (args.values.check === true)
|
|
184
|
-
|
|
204
|
+
if (args.values.check === true) {
|
|
205
|
+
await checkUpdate(args, rt);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
185
208
|
if (args.values.self === true && existsSync(join(cliPackageRoot(), "desktop-runtime.json"))) {
|
|
186
209
|
throw new CommandFailure("refused", "UNSUPPORTED", "this Cotal runtime belongs to the desktop app; npm self-update would separate it from its bundled runtime", {
|
|
187
210
|
remedy: "update the desktop app with its signed platform installer; no npm self-update was attempted",
|
|
@@ -202,8 +225,13 @@ async function updateInstallation(args, rt) {
|
|
|
202
225
|
});
|
|
203
226
|
}
|
|
204
227
|
}
|
|
205
|
-
|
|
206
|
-
|
|
228
|
+
const restored = await recoverInterruptedUpdate(rt);
|
|
229
|
+
if (restored) {
|
|
230
|
+
if (args.values.self !== true)
|
|
231
|
+
return;
|
|
232
|
+
if (restored.version !== rt.version())
|
|
233
|
+
return restored.entry;
|
|
234
|
+
}
|
|
207
235
|
// A folder above the config folder is not one this command repairs. Refuse it before the mode
|
|
208
236
|
// repair and before seeding, so a refusal writes nothing and does not replace the binary.
|
|
209
237
|
try {
|
|
@@ -227,31 +255,29 @@ async function updateInstallation(args, rt) {
|
|
|
227
255
|
const code = await executeUpdate(Boolean(args.values.self), rt, args.values);
|
|
228
256
|
if (code !== 0)
|
|
229
257
|
process.exitCode = code;
|
|
230
|
-
else {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
if (args.values.self !== true && childBinding(rt).kind !== "bound")
|
|
234
|
-
recordUpdateCompletion(rt.version(), "manual update reconciled", true);
|
|
258
|
+
else if (args.values.self !== true && childBinding(rt).kind !== "bound") {
|
|
259
|
+
clearUpdateRecovery();
|
|
260
|
+
recordUpdateCompletion(rt.version(), "manual update reconciled", true);
|
|
235
261
|
}
|
|
236
262
|
}
|
|
237
263
|
/** Resume an abandoned replacement before a command or daemon can activate its closure. */
|
|
238
264
|
export async function recoverInterruptedUpdate(rt = updateRuntime, startup = false) {
|
|
239
265
|
if (childBinding(rt).kind === "bound")
|
|
240
|
-
return
|
|
266
|
+
return;
|
|
241
267
|
const observed = readUpdateRecovery();
|
|
242
268
|
if (!observed)
|
|
243
|
-
return
|
|
269
|
+
return;
|
|
244
270
|
if (startup) {
|
|
245
271
|
// A restarted daemon must answer the updater that still owns the closure. It may only
|
|
246
272
|
// observe that live transaction here, never compete with it for restoration authority.
|
|
247
273
|
if (liveUpdateClosureOwner(observed, rt.recoveryOwnerStart ?? recoveryProcessStartToken))
|
|
248
|
-
return
|
|
274
|
+
return;
|
|
249
275
|
}
|
|
250
276
|
const release = claimUpdateClosureAccess(true);
|
|
251
277
|
try {
|
|
252
278
|
const record = readUpdateRecovery();
|
|
253
279
|
if (!record)
|
|
254
|
-
return
|
|
280
|
+
return;
|
|
255
281
|
const now = rt.now?.() ?? Date.now();
|
|
256
282
|
let decision = recoveryDisposition(record, now, rt.recoveryOwnerStart ?? recoveryProcessStartToken);
|
|
257
283
|
if (decision.action === "wait") {
|
|
@@ -272,17 +298,14 @@ export async function recoverInterruptedUpdate(rt = updateRuntime, startup = fal
|
|
|
272
298
|
throw new CommandFailure("refused", "CONFLICT", `${decision.instruction} Retention could not complete: ${message(error)}`, { remedy: "inspect the recovery records and retained folders in the Cotal home, correct access, then run `cotal update --self`" });
|
|
273
299
|
}
|
|
274
300
|
rt.out(`Retained unusable interrupted-update records in ${retained}; continuing the update.`);
|
|
275
|
-
return
|
|
301
|
+
return;
|
|
276
302
|
}
|
|
277
303
|
if (startup && (decision.action === "wait" || decision.action === "active" || decision.action === "restore" && record.phase === "paused"))
|
|
278
|
-
return
|
|
304
|
+
return;
|
|
279
305
|
if (decision.action !== "restore")
|
|
280
|
-
throw new CommandFailure("refused", decision.action === "active" ? "LIFECYCLE_BLOCKED" : decision.action === "wait" ? "CONFLICT" : "DEPENDENCY_UNAVAILABLE", decision.instruction, { native: { code: decision.action === "active" ? "UPDATE_RECOVERY_OWNER_ACTIVE" : decision.action === "wait" ? "UPDATE_RECOVERY_OBSERVATION_WAIT" : "UPDATE_RECOVERY_INSPECTION_FAILED" }, remedy: "follow the recovery instruction above, then run `cotal update --self`" });
|
|
306
|
+
throw new CommandFailure("refused", decision.action === "active" ? "LIFECYCLE_BLOCKED" : decision.action === "wait" ? "CONFLICT" : "DEPENDENCY_UNAVAILABLE", decision.instruction, { native: { code: decision.action === "active" ? "UPDATE_RECOVERY_OWNER_ACTIVE" : decision.action === "wait" ? "UPDATE_RECOVERY_OBSERVATION_WAIT" : "UPDATE_RECOVERY_INSPECTION_FAILED" }, ...(decision.action === "active" ? {} : { remedy: "follow the recovery instruction above, then run `cotal update --self`" }) });
|
|
281
307
|
if (!record.owner)
|
|
282
|
-
return
|
|
283
|
-
const start = processStartToken(record.owner.pid);
|
|
284
|
-
if (start !== undefined && start === record.owner.start)
|
|
285
|
-
return false;
|
|
308
|
+
return;
|
|
286
309
|
try {
|
|
287
310
|
if (!record.snapshot)
|
|
288
311
|
throw new Error("interrupted update has no closure snapshot");
|
|
@@ -317,7 +340,7 @@ export async function recoverInterruptedUpdate(rt = updateRuntime, startup = fal
|
|
|
317
340
|
clearUpdateRecovery();
|
|
318
341
|
recordUpdateCompletion(version, `repaired paused installation at ${version}`, true);
|
|
319
342
|
rt.out(`Repaired the paused installation with cotal-ai@${version}; the machine service and its hosted Managers were verified.`);
|
|
320
|
-
return
|
|
343
|
+
return { entry, version };
|
|
321
344
|
}
|
|
322
345
|
let entry;
|
|
323
346
|
let recoveredExecution;
|
|
@@ -352,7 +375,7 @@ export async function recoverInterruptedUpdate(rt = updateRuntime, startup = fal
|
|
|
352
375
|
clearUpdateRecovery();
|
|
353
376
|
recoveredExecution?.complete?.();
|
|
354
377
|
rt.out(`Restored cotal-ai@${record.previous} after an interrupted update.`);
|
|
355
|
-
return
|
|
378
|
+
return { entry, version: record.previous };
|
|
356
379
|
}
|
|
357
380
|
finally {
|
|
358
381
|
releaseGlobal();
|
|
@@ -701,23 +724,26 @@ export async function isStoppedLocalMesh(target) {
|
|
|
701
724
|
/** A prepared controller that completed ordinary down is cold only while its own instance records
|
|
702
725
|
* prove every process gone, no supervisor may serve it, and its recorded broker has no listener.
|
|
703
726
|
* The target resolver refuses before returning a MeshTarget for this lifecycle. */
|
|
704
|
-
async function stoppedController(d) {
|
|
727
|
+
async function stoppedController(d, server) {
|
|
705
728
|
if (typeof d.space !== "string" || typeof d.root !== "string" || !d.stopped ||
|
|
706
729
|
d.rootMissing === true || d.unsettled !== undefined || d.home !== undefined || d.stackSpace !== undefined)
|
|
707
730
|
return false;
|
|
708
731
|
const journal = readStackJournal(d.root)?.journal;
|
|
709
732
|
if (!journal || journal.space !== d.space || journal.operation.kind !== "down" || journal.operation.phase !== "completed")
|
|
710
733
|
return false;
|
|
734
|
+
if (server !== undefined && brokerUrlKey(server) !== brokerUrlKey(journal.server))
|
|
735
|
+
return false;
|
|
711
736
|
const instances = serviceInstances(d.space);
|
|
712
737
|
if (journal.members.some((member) => member.instanceId !== null &&
|
|
713
738
|
!instances.some((row) => row.name === member.instanceId && row.record.value.definition === member.definition)))
|
|
714
739
|
return false;
|
|
715
740
|
if (instances.some((row) => !["stopped", "failed"].includes(row.record.value.state) || !processGone(observeServiceProcess(row.record.value))))
|
|
716
741
|
return false;
|
|
717
|
-
stackScopeRefusals(journal, `\`cotal update --space ${d.space}\``);
|
|
718
742
|
if (supervisorMayServe(d.space))
|
|
719
743
|
return false;
|
|
720
|
-
|
|
744
|
+
const brokerStopped = await assertEndpointUnreachable(journal.server).then(() => true, () => false);
|
|
745
|
+
stackScopeRefusals(journal, `\`cotal update --space ${d.space}\``, { brokerStopped });
|
|
746
|
+
return brokerStopped;
|
|
721
747
|
}
|
|
722
748
|
/** The refusal sentence this command prints. A {@link MeshTargetError} arrives RAW here — the
|
|
723
749
|
* control resolver rethrows the codes it does not absorb before the connect helper can wrap them —
|
|
@@ -912,7 +938,7 @@ export async function readManagerContinuity(flags, options = {}) {
|
|
|
912
938
|
console.log(c.dim(` ${e.details.space}: prepared in ${e.details.root}, not started; no manager running`));
|
|
913
939
|
return "none";
|
|
914
940
|
}
|
|
915
|
-
if (e.code === "not-started" &&
|
|
941
|
+
if (e.code === "not-started" && await stoppedController(e.details, server)) {
|
|
916
942
|
console.log(c.dim(` ${e.details.space}: stopped; no manager running`));
|
|
917
943
|
return "none";
|
|
918
944
|
}
|
|
@@ -1062,8 +1088,10 @@ function checkInstalledClosure(version, rt) {
|
|
|
1062
1088
|
const staging = mkdtempSync(join(tmpdir(), "cotal-closure-check-"));
|
|
1063
1089
|
try {
|
|
1064
1090
|
const result = rt.npm(["install", "--prefix", staging, "--cache", join(staging, ".npm-cache"), "--logs-max=0", "--update-notifier=false", "--ignore-scripts", "--package-lock=false", "--no-audit", "--no-fund", "--fetch-retries=2", "--fetch-retry-mintimeout=1000", "--fetch-retry-maxtimeout=2000", "--fetch-timeout=15000", "--prefer-online", ...names.map(name => `${name}@${version}`)]);
|
|
1091
|
+
if (result.signal)
|
|
1092
|
+
throw new DependencyCheckInterrupted(`npm dependency check was terminated by ${result.signal}`);
|
|
1065
1093
|
if (result.status !== 0)
|
|
1066
|
-
throw
|
|
1094
|
+
throw releaseReadError(result, `installed extension dependency closure is unavailable: ${failure(result)}`);
|
|
1067
1095
|
}
|
|
1068
1096
|
finally {
|
|
1069
1097
|
rmSync(staging, { recursive: true, force: true, maxRetries: 3 });
|
|
@@ -1077,11 +1105,17 @@ async function checkReleaseArchives(version, rt) {
|
|
|
1077
1105
|
const pending = new Set(["cotal-ai"]);
|
|
1078
1106
|
const names = ["cotal-ai"];
|
|
1079
1107
|
try {
|
|
1108
|
+
if (process.platform === "linux" || process.platform === "darwin") {
|
|
1109
|
+
const start = processStartToken(process.pid);
|
|
1110
|
+
if (!start)
|
|
1111
|
+
throw new Error("cannot identify the archive cache owner");
|
|
1112
|
+
writeFileSync(join(cache, ".owner"), `${process.pid}\n${start}\n`, { mode: 0o600, flag: "wx" });
|
|
1113
|
+
}
|
|
1080
1114
|
for (let offset = 0; offset < names.length;) {
|
|
1081
1115
|
const batch = names.slice(offset, offset + 3);
|
|
1082
1116
|
// Settle every read before validating or removing its shared private cache. Validation below
|
|
1083
1117
|
// stays in discovery order, including when independent registry requests finish out of order.
|
|
1084
|
-
const manifests = await Promise.allSettled(batch.map(name => rt.npmAsync(["view", `${name}@${version}`, "--json", ...options])));
|
|
1118
|
+
const manifests = await Promise.allSettled(batch.map(name => rt.npmAsync(["view", `${name}@${version}`, "--json", ...options], cache)));
|
|
1085
1119
|
offset += batch.length;
|
|
1086
1120
|
for (const [index, name] of batch.entries()) {
|
|
1087
1121
|
const spec = `${name}@${version}`;
|
|
@@ -1131,7 +1165,7 @@ async function checkReleaseArchives(version, rt) {
|
|
|
1131
1165
|
// Its cache add accepts multiple specs. Bound each group rather than starting npm per archive.
|
|
1132
1166
|
for (let offset = 0; offset < names.length; offset += 6) {
|
|
1133
1167
|
const specs = names.slice(offset, offset + 6).map(name => `${name}@${version}`);
|
|
1134
|
-
const archive = await rt.npmAsync(["cache", "add", ...specs, "--json", "--ignore-scripts", ...options]);
|
|
1168
|
+
const archive = await rt.npmAsync(["cache", "add", ...specs, "--json", "--ignore-scripts", ...options], cache);
|
|
1135
1169
|
if (archive.status !== 0)
|
|
1136
1170
|
throw releaseReadError(archive, `archives for ${specs.join(", ")} could not be downloaded and verified`);
|
|
1137
1171
|
}
|
|
@@ -1140,22 +1174,115 @@ async function checkReleaseArchives(version, rt) {
|
|
|
1140
1174
|
rmSync(cache, { recursive: true, force: true, maxRetries: 3 });
|
|
1141
1175
|
}
|
|
1142
1176
|
}
|
|
1177
|
+
/** Only caches with recorded custody can be reclaimed. A worker cannot open its cache before its
|
|
1178
|
+
* process group is recorded, and the owner cannot start new workers after it exits. */
|
|
1179
|
+
function collectArchiveCaches(parent) {
|
|
1180
|
+
if (process.platform !== "linux" && process.platform !== "darwin")
|
|
1181
|
+
return;
|
|
1182
|
+
try {
|
|
1183
|
+
parent = realpathSync(parent);
|
|
1184
|
+
}
|
|
1185
|
+
catch {
|
|
1186
|
+
return;
|
|
1187
|
+
}
|
|
1188
|
+
const uid = process.getuid();
|
|
1189
|
+
const privateDirectory = (path) => {
|
|
1190
|
+
const info = lstatSync(path);
|
|
1191
|
+
return info.isDirectory() && info.uid === uid && (info.mode & 0o077) === 0;
|
|
1192
|
+
};
|
|
1193
|
+
const deadOwner = (cache) => {
|
|
1194
|
+
const file = join(cache, ".owner");
|
|
1195
|
+
const info = lstatSync(file);
|
|
1196
|
+
if (!info.isFile() || info.uid !== uid || info.size > 256 || (info.mode & 0o077) !== 0)
|
|
1197
|
+
return false;
|
|
1198
|
+
const owner = /^([1-9]\d*)\n([^\r\n]+)\n$/.exec(readFileSync(file, "utf8"));
|
|
1199
|
+
const pid = Number(owner?.[1]);
|
|
1200
|
+
return !!owner && Number.isSafeInteger(pid) && pid > 1 && recoveryProcessStartToken(pid) !== owner[2];
|
|
1201
|
+
};
|
|
1202
|
+
const absentGroup = (pid) => {
|
|
1203
|
+
if (!Number.isSafeInteger(pid) || pid < 2)
|
|
1204
|
+
return false;
|
|
1205
|
+
try {
|
|
1206
|
+
process.kill(-pid, 0);
|
|
1207
|
+
if (process.platform !== "linux")
|
|
1208
|
+
return false;
|
|
1209
|
+
const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
1210
|
+
return /^[ZX] /.test(stat.slice(stat.lastIndexOf(") ") + 2)) && processGroupMembers(pid).length === 0;
|
|
1211
|
+
}
|
|
1212
|
+
catch (error) {
|
|
1213
|
+
return error.code === "ESRCH";
|
|
1214
|
+
}
|
|
1215
|
+
};
|
|
1216
|
+
function sweep(directory) {
|
|
1217
|
+
for (const name of readdirSync(directory)) {
|
|
1218
|
+
if (!/^cotal-release-check-[a-zA-Z0-9]{6}$/.test(name))
|
|
1219
|
+
continue;
|
|
1220
|
+
const cache = join(directory, name);
|
|
1221
|
+
try {
|
|
1222
|
+
if (!privateDirectory(cache))
|
|
1223
|
+
continue;
|
|
1224
|
+
protectedLocalDirectory(cache, "the release archive cache");
|
|
1225
|
+
if (!deadOwner(cache))
|
|
1226
|
+
continue;
|
|
1227
|
+
const workers = readdirSync(cache).filter(name => name.startsWith(".worker-"));
|
|
1228
|
+
if (workers.every(worker => {
|
|
1229
|
+
const match = /^\.worker-([1-9]\d*)$/.exec(worker);
|
|
1230
|
+
return !!match && absentGroup(Number(match[1]));
|
|
1231
|
+
}))
|
|
1232
|
+
rmSync(cache, { recursive: true, force: true, maxRetries: 3 });
|
|
1233
|
+
}
|
|
1234
|
+
catch { /* Unprovable or already collected scratch is left alone. */ }
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
try {
|
|
1238
|
+
sweep(parent);
|
|
1239
|
+
for (const name of readdirSync(parent)) {
|
|
1240
|
+
if (!/^cotal-update-[a-zA-Z0-9]{6}$/.test(name))
|
|
1241
|
+
continue;
|
|
1242
|
+
const scratch = join(parent, name);
|
|
1243
|
+
try {
|
|
1244
|
+
if (privateDirectory(scratch))
|
|
1245
|
+
sweep(scratch);
|
|
1246
|
+
}
|
|
1247
|
+
catch { /* Another command can retire its scratch during the scan. */ }
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
catch { /* Temporary storage cleanup is best effort. */ }
|
|
1251
|
+
}
|
|
1143
1252
|
class ReleaseNotAvailable extends Error {
|
|
1144
1253
|
}
|
|
1145
1254
|
class ReleaseDateExcluded extends Error {
|
|
1146
1255
|
}
|
|
1256
|
+
class DependencyCheckInterrupted extends Error {
|
|
1257
|
+
}
|
|
1258
|
+
class RegistryUnavailable extends Error {
|
|
1259
|
+
}
|
|
1260
|
+
const NETWORK_ERROR_CODE = /^(?:ENETUNREACH|EHOSTUNREACH|ENETDOWN|EHOSTDOWN|ECONNRESET|ECONNREFUSED|ECONNABORTED|ETIMEDOUT|ESOCKETTIMEDOUT|EAI_AGAIN|ENOTFOUND)$/;
|
|
1261
|
+
function registryNetworkFailure(error) {
|
|
1262
|
+
if (error instanceof RegistryUnavailable)
|
|
1263
|
+
return true;
|
|
1264
|
+
const code = /(?:^|\n|^target staging failed: )npm (?:error|ERR!) code ([A-Z_]+)(?:\s|$)/.exec(message(error))?.[1];
|
|
1265
|
+
return code !== undefined && NETWORK_ERROR_CODE.test(code);
|
|
1266
|
+
}
|
|
1147
1267
|
function releaseReadError(result, detail) {
|
|
1148
1268
|
if (result.status !== null && !result.error) {
|
|
1149
1269
|
try {
|
|
1150
1270
|
const error = JSON.parse(result.stdout).error;
|
|
1151
1271
|
if (error?.code === "ETARGET" && [error.summary, error.detail].some(text => typeof text === "string" && /with a date before\b/i.test(text)))
|
|
1152
1272
|
return new ReleaseDateExcluded(`${detail}: npm's min-release-age or before setting excludes this release. Adjust that date filter and run \`cotal update --self\` again`);
|
|
1273
|
+
// A first-party scoped read can fail while the public registry still answers.
|
|
1274
|
+
if (!detail.includes("@cotal-ai/") && typeof error?.code === "string" && NETWORK_ERROR_CODE.test(error.code))
|
|
1275
|
+
return new RegistryUnavailable(detail);
|
|
1153
1276
|
if (error?.code === "E404" || error?.code === "ETARGET")
|
|
1154
1277
|
return new ReleaseNotAvailable(detail);
|
|
1278
|
+
if (typeof error?.code === "string" && /^[A-Z][A-Z0-9_]{0,39}$/.test(error.code)) {
|
|
1279
|
+
const registry = detail.includes("@cotal-ai/") ? "the @cotal-ai:registry setting in .npmrc" : "your npm registry settings";
|
|
1280
|
+
return new Error(`${detail} (npm ${error.code}${error.code === "ECONNREFUSED" ? ": registry connection refused" : ""}); check ${registry}, authentication, proxy and TLS configuration`);
|
|
1281
|
+
}
|
|
1155
1282
|
}
|
|
1156
1283
|
catch { /* An unstructured failure is not evidence of registry propagation. */ }
|
|
1157
1284
|
}
|
|
1158
|
-
return new Error(detail);
|
|
1285
|
+
return registryNetworkFailure(new Error(failure(result))) ? new RegistryUnavailable(detail) : new Error(detail);
|
|
1159
1286
|
}
|
|
1160
1287
|
async function waitForReleaseArchives(version, current, rt) {
|
|
1161
1288
|
const now = rt.now ?? Date.now;
|
|
@@ -1240,13 +1367,23 @@ async function upgradeAndReconcile(targetVersion, current, rt, target) {
|
|
|
1240
1367
|
rt.out(`✓ release archives checked (${((Date.now() - releaseChecksStarted) / 1000).toFixed(1)} s)`);
|
|
1241
1368
|
}
|
|
1242
1369
|
catch (e) {
|
|
1370
|
+
if (e instanceof DependencyCheckInterrupted) {
|
|
1371
|
+
recordUpdateDeferral(targetVersion, message(e));
|
|
1372
|
+
rt.err(c.red(`✗ ${message(e)}. No installed packages were replaced. Run \`cotal update --self\` again.`));
|
|
1373
|
+
return 1;
|
|
1374
|
+
}
|
|
1243
1375
|
if (e instanceof ReleaseDateExcluded) {
|
|
1244
1376
|
recordUpdateDeferral(targetVersion, "npm date filter excludes the release");
|
|
1245
1377
|
rt.err(c.red(`✗ ${message(e)}. No global install was attempted.`));
|
|
1246
1378
|
return 1;
|
|
1247
1379
|
}
|
|
1380
|
+
if (registryNetworkFailure(e)) {
|
|
1381
|
+
recordUpdateDeferral(targetVersion, "waiting for registry access", true);
|
|
1382
|
+
rt.out("The registry cannot be reached; nothing was changed.");
|
|
1383
|
+
return 0;
|
|
1384
|
+
}
|
|
1248
1385
|
recordUpdateDeferral(targetVersion, "waiting for registry or extension closure availability", true);
|
|
1249
|
-
rt.err(c.red(`✗ cotal-ai@${targetVersion}
|
|
1386
|
+
rt.err(c.red(`✗ cotal-ai@${targetVersion} update preflight failed: ${message(e)}. No global install was attempted. ${e instanceof ReleaseNotAvailable ? "The release is still reaching the registry; run `cotal update --self` again in a few minutes." : "Correct the reported failure, then run `cotal update --self` again."}`));
|
|
1250
1387
|
return 1;
|
|
1251
1388
|
}
|
|
1252
1389
|
let prefix;
|
|
@@ -1297,12 +1434,33 @@ async function upgradeAndReconcile(targetVersion, current, rt, target) {
|
|
|
1297
1434
|
}
|
|
1298
1435
|
let releaseGlobal;
|
|
1299
1436
|
try {
|
|
1300
|
-
releaseGlobal = rt.claimGlobalUpdate(root);
|
|
1437
|
+
releaseGlobal = rt.claimGlobalUpdate(root, () => rt.out("Waiting up to 10 minutes for another updater to release npm's global root"));
|
|
1301
1438
|
}
|
|
1302
1439
|
catch (e) {
|
|
1303
1440
|
rt.err(c.red(`✗ could not reserve npm's global root for update: ${message(e)}`));
|
|
1304
1441
|
return 1;
|
|
1305
1442
|
}
|
|
1443
|
+
// Another updater may have finished while this process still has the old generation loaded.
|
|
1444
|
+
// Re-enter through its verified installation instead of replacing it or rolling back to stale code.
|
|
1445
|
+
try {
|
|
1446
|
+
const installed = rt.globalVersion?.(root);
|
|
1447
|
+
if (installed && compareSemver(installed, current) > 0 && compareSemver(installed, targetVersion) >= 0) {
|
|
1448
|
+
const entry = rt.verifyGlobalEntry(root, installed);
|
|
1449
|
+
releaseGlobal();
|
|
1450
|
+
rt.out(`Another update installed cotal-ai@${installed}; rechecking the installed CLI`);
|
|
1451
|
+
const child = rt.spawn(rt.nodePath, [entry, "update", "--self", ...targetArgv(target), ...(target["stop-agents"] === true ? ["--stop-agents"] : [])], rt.env, true);
|
|
1452
|
+
if (child.stderr)
|
|
1453
|
+
rt.stderr(child.stderr);
|
|
1454
|
+
if (child.stdout)
|
|
1455
|
+
rt.stdout(child.stdout);
|
|
1456
|
+
return child.status ?? 1;
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
catch (error) {
|
|
1460
|
+
releaseGlobal();
|
|
1461
|
+
rt.err(`could not recheck the installed global CLI: ${message(error)}`);
|
|
1462
|
+
return 1;
|
|
1463
|
+
}
|
|
1306
1464
|
let execution;
|
|
1307
1465
|
let stagedExecution = false;
|
|
1308
1466
|
if (rt.prepareExecution) {
|
|
@@ -1323,6 +1481,11 @@ async function upgradeAndReconcile(targetVersion, current, rt, target) {
|
|
|
1323
1481
|
}
|
|
1324
1482
|
catch { /* an unpublished copy left behind selects nothing */ }
|
|
1325
1483
|
releaseGlobal();
|
|
1484
|
+
if (!execution && message(error).startsWith("target staging failed: ") && registryNetworkFailure(error)) {
|
|
1485
|
+
recordUpdateDeferral(targetVersion, "waiting for registry access", true);
|
|
1486
|
+
rt.out("The registry cannot be reached; nothing was changed.");
|
|
1487
|
+
return 0;
|
|
1488
|
+
}
|
|
1326
1489
|
recordUpdateDeferral(targetVersion, `staged pre-install check refused: ${preflightDetail(error)}`);
|
|
1327
1490
|
rt.err(`staged pre-install check refused: ${message(error)}; no installed packages or connector state were changed`);
|
|
1328
1491
|
return 1;
|
|
@@ -1352,6 +1515,10 @@ async function upgradeAndReconcile(targetVersion, current, rt, target) {
|
|
|
1352
1515
|
rt.out(`✓ recovery snapshot saved (${((Date.now() - snapshotStarted) / 1000).toFixed(1)} s)`);
|
|
1353
1516
|
}
|
|
1354
1517
|
catch (error) {
|
|
1518
|
+
try {
|
|
1519
|
+
execution?.discard?.();
|
|
1520
|
+
}
|
|
1521
|
+
catch { /* an unpublished copy left behind selects nothing */ }
|
|
1355
1522
|
releaseClosure?.();
|
|
1356
1523
|
await releaseAdmission?.();
|
|
1357
1524
|
releaseGlobal();
|
|
@@ -1625,9 +1792,10 @@ export function installedUpdatePrefix(packageRoot, entry) {
|
|
|
1625
1792
|
return undefined;
|
|
1626
1793
|
const prefix = dirname(dirname(modules));
|
|
1627
1794
|
const meta = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
1795
|
+
const linked = realpathSync(join(prefix, "bin", "cotal"));
|
|
1628
1796
|
if (basename(root) !== "cotal-ai" || !meta.version ||
|
|
1629
1797
|
verifyGlobalEntry(modules, meta.version) !== realpathSync(entry) ||
|
|
1630
|
-
realpathSync(join(
|
|
1798
|
+
(linked !== realpathSync(entry) && linked !== join(root, "dist", "cotal-npm")))
|
|
1631
1799
|
throw new Error("the invoked cotal package and its global bin link do not identify the same install");
|
|
1632
1800
|
return prefix;
|
|
1633
1801
|
}
|
|
@@ -1645,14 +1813,35 @@ export function verifyGlobalEntry(root, expectedVersion) {
|
|
|
1645
1813
|
throw new Error(`the installed cotal executable escapes its package: ${entry}`);
|
|
1646
1814
|
return entry;
|
|
1647
1815
|
}
|
|
1648
|
-
async function runNpmAsync(args) {
|
|
1816
|
+
async function runNpmAsync(args, archiveCache) {
|
|
1649
1817
|
try {
|
|
1650
1818
|
const { file, args: spawnArgs, windowsVerbatimArguments } = cmdSpawnSpec("npm", args);
|
|
1651
|
-
const
|
|
1819
|
+
const gated = archiveCache !== undefined && (process.platform === "linux" || process.platform === "darwin");
|
|
1820
|
+
const gate = 'IFS= read -r permit <&3 && [ "$permit" = run ] || exit 1; exec 3<&-; exec "$@"';
|
|
1821
|
+
const child = spawn(gated ? "/bin/sh" : file, gated ? ["-c", gate, "cotal-release-check", file, ...spawnArgs] : spawnArgs, {
|
|
1822
|
+
windowsVerbatimArguments, windowsHide: true,
|
|
1823
|
+
...(gated ? { detached: true, stdio: ["ignore", "pipe", "pipe", "pipe"] } : {}),
|
|
1824
|
+
});
|
|
1652
1825
|
let stdout = "", stderr = "", error;
|
|
1653
1826
|
child.stdout?.on("data", (chunk) => { stdout += chunk.toString(); });
|
|
1654
1827
|
child.stderr?.on("data", (chunk) => { stderr += chunk.toString(); });
|
|
1655
1828
|
child.once("error", cause => { error = cause.message; });
|
|
1829
|
+
if (gated) {
|
|
1830
|
+
const permit = child.stdio[3];
|
|
1831
|
+
permit.on("error", cause => { error = message(cause); });
|
|
1832
|
+
try {
|
|
1833
|
+
if (child.pid === undefined)
|
|
1834
|
+
permit.end();
|
|
1835
|
+
else {
|
|
1836
|
+
writeFileSync(join(archiveCache, `.worker-${child.pid}`), "", { mode: 0o600 });
|
|
1837
|
+
permit.end("run\n");
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
catch (cause) {
|
|
1841
|
+
error = message(cause);
|
|
1842
|
+
permit.end();
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1656
1845
|
const status = await new Promise(resolveClose => child.once("close", resolveClose));
|
|
1657
1846
|
return { status, stdout, stderr, ...(error ? { error } : {}) };
|
|
1658
1847
|
}
|
|
@@ -1668,6 +1857,7 @@ function runNpm(args, inherit = false) {
|
|
|
1668
1857
|
: { encoding: "utf8", windowsVerbatimArguments });
|
|
1669
1858
|
return {
|
|
1670
1859
|
status: result.status,
|
|
1860
|
+
signal: result.signal,
|
|
1671
1861
|
stdout: `${result.stdout ?? ""}`,
|
|
1672
1862
|
stderr: `${result.stderr ?? ""}`,
|
|
1673
1863
|
error: result.error?.message,
|