@cotal-ai/cli 0.171.0 → 0.171.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.
- 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/backup.d.ts.map +1 -1
- package/dist/commands/backup.js +12 -5
- package/dist/commands/backup.js.map +1 -1
- package/dist/commands/channels.d.ts.map +1 -1
- package/dist/commands/channels.js +2 -1
- package/dist/commands/channels.js.map +1 -1
- package/dist/commands/down.d.ts.map +1 -1
- package/dist/commands/down.js +4 -2
- package/dist/commands/down.js.map +1 -1
- package/dist/commands/help.js +1 -1
- package/dist/commands/help.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/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.map +1 -1
- package/dist/commands/spawn.js +43 -45
- package/dist/commands/spawn.js.map +1 -1
- package/dist/commands/stack-down.js +4 -2
- 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 +4 -1
- package/dist/commands/stack-up.js.map +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +2 -1
- 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 +25 -21
- 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 +227 -38
- package/dist/commands/update.js.map +1 -1
- package/dist/index.js +1 -1
- 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/history-command.d.ts +3 -0
- package/dist/lib/history-command.d.ts.map +1 -0
- package/dist/lib/history-command.js +6 -0
- package/dist/lib/history-command.js.map +1 -0
- package/dist/lib/manager-proc.d.ts +2 -1
- package/dist/lib/manager-proc.d.ts.map +1 -1
- package/dist/lib/manager-proc.js +2 -1
- 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/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/self-exec.d.ts.map +1 -1
- package/dist/lib/self-exec.js +16 -1
- package/dist/lib/self-exec.js.map +1 -1
- 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.map +1 -1
- package/dist/lib/service-presets.js +3 -1
- 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/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/watch-data.d.ts.map +1 -1
- package/dist/watch-data.js +2 -1
- package/dist/watch-data.js.map +1 -1
- package/package.json +4 -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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C,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,MAAM,GAAG,QAAQ,CAAC,CA8K5L;AAED;;kGAEkG;AAClG,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,mBAAmB,EAC3B,KAAK,EAAE,MAAM,EACb,KAAK,GAAE,MAAM,GAAG,SAAqB,EACrC,GAAG,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAkB,EACzC,OAAO,CAAC,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,mBAAmB,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,13 +724,15 @@ 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)))
|
|
@@ -912,7 +937,7 @@ export async function readManagerContinuity(flags, options = {}) {
|
|
|
912
937
|
console.log(c.dim(` ${e.details.space}: prepared in ${e.details.root}, not started; no manager running`));
|
|
913
938
|
return "none";
|
|
914
939
|
}
|
|
915
|
-
if (e.code === "not-started" &&
|
|
940
|
+
if (e.code === "not-started" && await stoppedController(e.details, server)) {
|
|
916
941
|
console.log(c.dim(` ${e.details.space}: stopped; no manager running`));
|
|
917
942
|
return "none";
|
|
918
943
|
}
|
|
@@ -1062,8 +1087,10 @@ function checkInstalledClosure(version, rt) {
|
|
|
1062
1087
|
const staging = mkdtempSync(join(tmpdir(), "cotal-closure-check-"));
|
|
1063
1088
|
try {
|
|
1064
1089
|
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}`)]);
|
|
1090
|
+
if (result.signal)
|
|
1091
|
+
throw new DependencyCheckInterrupted(`npm dependency check was terminated by ${result.signal}`);
|
|
1065
1092
|
if (result.status !== 0)
|
|
1066
|
-
throw
|
|
1093
|
+
throw releaseReadError(result, `installed extension dependency closure is unavailable: ${failure(result)}`);
|
|
1067
1094
|
}
|
|
1068
1095
|
finally {
|
|
1069
1096
|
rmSync(staging, { recursive: true, force: true, maxRetries: 3 });
|
|
@@ -1077,11 +1104,17 @@ async function checkReleaseArchives(version, rt) {
|
|
|
1077
1104
|
const pending = new Set(["cotal-ai"]);
|
|
1078
1105
|
const names = ["cotal-ai"];
|
|
1079
1106
|
try {
|
|
1107
|
+
if (process.platform === "linux" || process.platform === "darwin") {
|
|
1108
|
+
const start = processStartToken(process.pid);
|
|
1109
|
+
if (!start)
|
|
1110
|
+
throw new Error("cannot identify the archive cache owner");
|
|
1111
|
+
writeFileSync(join(cache, ".owner"), `${process.pid}\n${start}\n`, { mode: 0o600, flag: "wx" });
|
|
1112
|
+
}
|
|
1080
1113
|
for (let offset = 0; offset < names.length;) {
|
|
1081
1114
|
const batch = names.slice(offset, offset + 3);
|
|
1082
1115
|
// Settle every read before validating or removing its shared private cache. Validation below
|
|
1083
1116
|
// 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])));
|
|
1117
|
+
const manifests = await Promise.allSettled(batch.map(name => rt.npmAsync(["view", `${name}@${version}`, "--json", ...options], cache)));
|
|
1085
1118
|
offset += batch.length;
|
|
1086
1119
|
for (const [index, name] of batch.entries()) {
|
|
1087
1120
|
const spec = `${name}@${version}`;
|
|
@@ -1131,7 +1164,7 @@ async function checkReleaseArchives(version, rt) {
|
|
|
1131
1164
|
// Its cache add accepts multiple specs. Bound each group rather than starting npm per archive.
|
|
1132
1165
|
for (let offset = 0; offset < names.length; offset += 6) {
|
|
1133
1166
|
const specs = names.slice(offset, offset + 6).map(name => `${name}@${version}`);
|
|
1134
|
-
const archive = await rt.npmAsync(["cache", "add", ...specs, "--json", "--ignore-scripts", ...options]);
|
|
1167
|
+
const archive = await rt.npmAsync(["cache", "add", ...specs, "--json", "--ignore-scripts", ...options], cache);
|
|
1135
1168
|
if (archive.status !== 0)
|
|
1136
1169
|
throw releaseReadError(archive, `archives for ${specs.join(", ")} could not be downloaded and verified`);
|
|
1137
1170
|
}
|
|
@@ -1140,22 +1173,115 @@ async function checkReleaseArchives(version, rt) {
|
|
|
1140
1173
|
rmSync(cache, { recursive: true, force: true, maxRetries: 3 });
|
|
1141
1174
|
}
|
|
1142
1175
|
}
|
|
1176
|
+
/** Only caches with recorded custody can be reclaimed. A worker cannot open its cache before its
|
|
1177
|
+
* process group is recorded, and the owner cannot start new workers after it exits. */
|
|
1178
|
+
function collectArchiveCaches(parent) {
|
|
1179
|
+
if (process.platform !== "linux" && process.platform !== "darwin")
|
|
1180
|
+
return;
|
|
1181
|
+
try {
|
|
1182
|
+
parent = realpathSync(parent);
|
|
1183
|
+
}
|
|
1184
|
+
catch {
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
const uid = process.getuid();
|
|
1188
|
+
const privateDirectory = (path) => {
|
|
1189
|
+
const info = lstatSync(path);
|
|
1190
|
+
return info.isDirectory() && info.uid === uid && (info.mode & 0o077) === 0;
|
|
1191
|
+
};
|
|
1192
|
+
const deadOwner = (cache) => {
|
|
1193
|
+
const file = join(cache, ".owner");
|
|
1194
|
+
const info = lstatSync(file);
|
|
1195
|
+
if (!info.isFile() || info.uid !== uid || info.size > 256 || (info.mode & 0o077) !== 0)
|
|
1196
|
+
return false;
|
|
1197
|
+
const owner = /^([1-9]\d*)\n([^\r\n]+)\n$/.exec(readFileSync(file, "utf8"));
|
|
1198
|
+
const pid = Number(owner?.[1]);
|
|
1199
|
+
return !!owner && Number.isSafeInteger(pid) && pid > 1 && recoveryProcessStartToken(pid) !== owner[2];
|
|
1200
|
+
};
|
|
1201
|
+
const absentGroup = (pid) => {
|
|
1202
|
+
if (!Number.isSafeInteger(pid) || pid < 2)
|
|
1203
|
+
return false;
|
|
1204
|
+
try {
|
|
1205
|
+
process.kill(-pid, 0);
|
|
1206
|
+
if (process.platform !== "linux")
|
|
1207
|
+
return false;
|
|
1208
|
+
const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
1209
|
+
return /^[ZX] /.test(stat.slice(stat.lastIndexOf(") ") + 2)) && processGroupMembers(pid).length === 0;
|
|
1210
|
+
}
|
|
1211
|
+
catch (error) {
|
|
1212
|
+
return error.code === "ESRCH";
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1215
|
+
function sweep(directory) {
|
|
1216
|
+
for (const name of readdirSync(directory)) {
|
|
1217
|
+
if (!/^cotal-release-check-[a-zA-Z0-9]{6}$/.test(name))
|
|
1218
|
+
continue;
|
|
1219
|
+
const cache = join(directory, name);
|
|
1220
|
+
try {
|
|
1221
|
+
if (!privateDirectory(cache))
|
|
1222
|
+
continue;
|
|
1223
|
+
protectedLocalDirectory(cache, "the release archive cache");
|
|
1224
|
+
if (!deadOwner(cache))
|
|
1225
|
+
continue;
|
|
1226
|
+
const workers = readdirSync(cache).filter(name => name.startsWith(".worker-"));
|
|
1227
|
+
if (workers.every(worker => {
|
|
1228
|
+
const match = /^\.worker-([1-9]\d*)$/.exec(worker);
|
|
1229
|
+
return !!match && absentGroup(Number(match[1]));
|
|
1230
|
+
}))
|
|
1231
|
+
rmSync(cache, { recursive: true, force: true, maxRetries: 3 });
|
|
1232
|
+
}
|
|
1233
|
+
catch { /* Unprovable or already collected scratch is left alone. */ }
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
try {
|
|
1237
|
+
sweep(parent);
|
|
1238
|
+
for (const name of readdirSync(parent)) {
|
|
1239
|
+
if (!/^cotal-update-[a-zA-Z0-9]{6}$/.test(name))
|
|
1240
|
+
continue;
|
|
1241
|
+
const scratch = join(parent, name);
|
|
1242
|
+
try {
|
|
1243
|
+
if (privateDirectory(scratch))
|
|
1244
|
+
sweep(scratch);
|
|
1245
|
+
}
|
|
1246
|
+
catch { /* Another command can retire its scratch during the scan. */ }
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
catch { /* Temporary storage cleanup is best effort. */ }
|
|
1250
|
+
}
|
|
1143
1251
|
class ReleaseNotAvailable extends Error {
|
|
1144
1252
|
}
|
|
1145
1253
|
class ReleaseDateExcluded extends Error {
|
|
1146
1254
|
}
|
|
1255
|
+
class DependencyCheckInterrupted extends Error {
|
|
1256
|
+
}
|
|
1257
|
+
class RegistryUnavailable extends Error {
|
|
1258
|
+
}
|
|
1259
|
+
const NETWORK_ERROR_CODE = /^(?:ENETUNREACH|EHOSTUNREACH|ENETDOWN|EHOSTDOWN|ECONNRESET|ECONNREFUSED|ECONNABORTED|ETIMEDOUT|ESOCKETTIMEDOUT|EAI_AGAIN|ENOTFOUND)$/;
|
|
1260
|
+
function registryNetworkFailure(error) {
|
|
1261
|
+
if (error instanceof RegistryUnavailable)
|
|
1262
|
+
return true;
|
|
1263
|
+
const code = /(?:^|\n|^target staging failed: )npm (?:error|ERR!) code ([A-Z_]+)(?:\s|$)/.exec(message(error))?.[1];
|
|
1264
|
+
return code !== undefined && NETWORK_ERROR_CODE.test(code);
|
|
1265
|
+
}
|
|
1147
1266
|
function releaseReadError(result, detail) {
|
|
1148
1267
|
if (result.status !== null && !result.error) {
|
|
1149
1268
|
try {
|
|
1150
1269
|
const error = JSON.parse(result.stdout).error;
|
|
1151
1270
|
if (error?.code === "ETARGET" && [error.summary, error.detail].some(text => typeof text === "string" && /with a date before\b/i.test(text)))
|
|
1152
1271
|
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`);
|
|
1272
|
+
// A first-party scoped read can fail while the public registry still answers.
|
|
1273
|
+
if (!detail.includes("@cotal-ai/") && typeof error?.code === "string" && NETWORK_ERROR_CODE.test(error.code))
|
|
1274
|
+
return new RegistryUnavailable(detail);
|
|
1153
1275
|
if (error?.code === "E404" || error?.code === "ETARGET")
|
|
1154
1276
|
return new ReleaseNotAvailable(detail);
|
|
1277
|
+
if (typeof error?.code === "string" && /^[A-Z][A-Z0-9_]{0,39}$/.test(error.code)) {
|
|
1278
|
+
const registry = detail.includes("@cotal-ai/") ? "the @cotal-ai:registry setting in .npmrc" : "your npm registry settings";
|
|
1279
|
+
return new Error(`${detail} (npm ${error.code}${error.code === "ECONNREFUSED" ? ": registry connection refused" : ""}); check ${registry}, authentication, proxy and TLS configuration`);
|
|
1280
|
+
}
|
|
1155
1281
|
}
|
|
1156
1282
|
catch { /* An unstructured failure is not evidence of registry propagation. */ }
|
|
1157
1283
|
}
|
|
1158
|
-
return new Error(detail);
|
|
1284
|
+
return registryNetworkFailure(new Error(failure(result))) ? new RegistryUnavailable(detail) : new Error(detail);
|
|
1159
1285
|
}
|
|
1160
1286
|
async function waitForReleaseArchives(version, current, rt) {
|
|
1161
1287
|
const now = rt.now ?? Date.now;
|
|
@@ -1240,13 +1366,23 @@ async function upgradeAndReconcile(targetVersion, current, rt, target) {
|
|
|
1240
1366
|
rt.out(`✓ release archives checked (${((Date.now() - releaseChecksStarted) / 1000).toFixed(1)} s)`);
|
|
1241
1367
|
}
|
|
1242
1368
|
catch (e) {
|
|
1369
|
+
if (e instanceof DependencyCheckInterrupted) {
|
|
1370
|
+
recordUpdateDeferral(targetVersion, message(e));
|
|
1371
|
+
rt.err(c.red(`✗ ${message(e)}. No installed packages were replaced. Run \`cotal update --self\` again.`));
|
|
1372
|
+
return 1;
|
|
1373
|
+
}
|
|
1243
1374
|
if (e instanceof ReleaseDateExcluded) {
|
|
1244
1375
|
recordUpdateDeferral(targetVersion, "npm date filter excludes the release");
|
|
1245
1376
|
rt.err(c.red(`✗ ${message(e)}. No global install was attempted.`));
|
|
1246
1377
|
return 1;
|
|
1247
1378
|
}
|
|
1379
|
+
if (registryNetworkFailure(e)) {
|
|
1380
|
+
recordUpdateDeferral(targetVersion, "waiting for registry access", true);
|
|
1381
|
+
rt.out("The registry cannot be reached; nothing was changed.");
|
|
1382
|
+
return 0;
|
|
1383
|
+
}
|
|
1248
1384
|
recordUpdateDeferral(targetVersion, "waiting for registry or extension closure availability", true);
|
|
1249
|
-
rt.err(c.red(`✗ cotal-ai@${targetVersion}
|
|
1385
|
+
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
1386
|
return 1;
|
|
1251
1387
|
}
|
|
1252
1388
|
let prefix;
|
|
@@ -1297,12 +1433,33 @@ async function upgradeAndReconcile(targetVersion, current, rt, target) {
|
|
|
1297
1433
|
}
|
|
1298
1434
|
let releaseGlobal;
|
|
1299
1435
|
try {
|
|
1300
|
-
releaseGlobal = rt.claimGlobalUpdate(root);
|
|
1436
|
+
releaseGlobal = rt.claimGlobalUpdate(root, () => rt.out("Waiting up to 10 minutes for another updater to release npm's global root"));
|
|
1301
1437
|
}
|
|
1302
1438
|
catch (e) {
|
|
1303
1439
|
rt.err(c.red(`✗ could not reserve npm's global root for update: ${message(e)}`));
|
|
1304
1440
|
return 1;
|
|
1305
1441
|
}
|
|
1442
|
+
// Another updater may have finished while this process still has the old generation loaded.
|
|
1443
|
+
// Re-enter through its verified installation instead of replacing it or rolling back to stale code.
|
|
1444
|
+
try {
|
|
1445
|
+
const installed = rt.globalVersion?.(root);
|
|
1446
|
+
if (installed && compareSemver(installed, current) > 0 && compareSemver(installed, targetVersion) >= 0) {
|
|
1447
|
+
const entry = rt.verifyGlobalEntry(root, installed);
|
|
1448
|
+
releaseGlobal();
|
|
1449
|
+
rt.out(`Another update installed cotal-ai@${installed}; rechecking the installed CLI`);
|
|
1450
|
+
const child = rt.spawn(rt.nodePath, [entry, "update", "--self", ...targetArgv(target), ...(target["stop-agents"] === true ? ["--stop-agents"] : [])], rt.env, true);
|
|
1451
|
+
if (child.stderr)
|
|
1452
|
+
rt.stderr(child.stderr);
|
|
1453
|
+
if (child.stdout)
|
|
1454
|
+
rt.stdout(child.stdout);
|
|
1455
|
+
return child.status ?? 1;
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
catch (error) {
|
|
1459
|
+
releaseGlobal();
|
|
1460
|
+
rt.err(`could not recheck the installed global CLI: ${message(error)}`);
|
|
1461
|
+
return 1;
|
|
1462
|
+
}
|
|
1306
1463
|
let execution;
|
|
1307
1464
|
let stagedExecution = false;
|
|
1308
1465
|
if (rt.prepareExecution) {
|
|
@@ -1323,6 +1480,11 @@ async function upgradeAndReconcile(targetVersion, current, rt, target) {
|
|
|
1323
1480
|
}
|
|
1324
1481
|
catch { /* an unpublished copy left behind selects nothing */ }
|
|
1325
1482
|
releaseGlobal();
|
|
1483
|
+
if (!execution && message(error).startsWith("target staging failed: ") && registryNetworkFailure(error)) {
|
|
1484
|
+
recordUpdateDeferral(targetVersion, "waiting for registry access", true);
|
|
1485
|
+
rt.out("The registry cannot be reached; nothing was changed.");
|
|
1486
|
+
return 0;
|
|
1487
|
+
}
|
|
1326
1488
|
recordUpdateDeferral(targetVersion, `staged pre-install check refused: ${preflightDetail(error)}`);
|
|
1327
1489
|
rt.err(`staged pre-install check refused: ${message(error)}; no installed packages or connector state were changed`);
|
|
1328
1490
|
return 1;
|
|
@@ -1352,6 +1514,10 @@ async function upgradeAndReconcile(targetVersion, current, rt, target) {
|
|
|
1352
1514
|
rt.out(`✓ recovery snapshot saved (${((Date.now() - snapshotStarted) / 1000).toFixed(1)} s)`);
|
|
1353
1515
|
}
|
|
1354
1516
|
catch (error) {
|
|
1517
|
+
try {
|
|
1518
|
+
execution?.discard?.();
|
|
1519
|
+
}
|
|
1520
|
+
catch { /* an unpublished copy left behind selects nothing */ }
|
|
1355
1521
|
releaseClosure?.();
|
|
1356
1522
|
await releaseAdmission?.();
|
|
1357
1523
|
releaseGlobal();
|
|
@@ -1625,9 +1791,10 @@ export function installedUpdatePrefix(packageRoot, entry) {
|
|
|
1625
1791
|
return undefined;
|
|
1626
1792
|
const prefix = dirname(dirname(modules));
|
|
1627
1793
|
const meta = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
1794
|
+
const linked = realpathSync(join(prefix, "bin", "cotal"));
|
|
1628
1795
|
if (basename(root) !== "cotal-ai" || !meta.version ||
|
|
1629
1796
|
verifyGlobalEntry(modules, meta.version) !== realpathSync(entry) ||
|
|
1630
|
-
realpathSync(join(
|
|
1797
|
+
(linked !== realpathSync(entry) && linked !== join(root, "dist", "cotal-npm")))
|
|
1631
1798
|
throw new Error("the invoked cotal package and its global bin link do not identify the same install");
|
|
1632
1799
|
return prefix;
|
|
1633
1800
|
}
|
|
@@ -1645,14 +1812,35 @@ export function verifyGlobalEntry(root, expectedVersion) {
|
|
|
1645
1812
|
throw new Error(`the installed cotal executable escapes its package: ${entry}`);
|
|
1646
1813
|
return entry;
|
|
1647
1814
|
}
|
|
1648
|
-
async function runNpmAsync(args) {
|
|
1815
|
+
async function runNpmAsync(args, archiveCache) {
|
|
1649
1816
|
try {
|
|
1650
1817
|
const { file, args: spawnArgs, windowsVerbatimArguments } = cmdSpawnSpec("npm", args);
|
|
1651
|
-
const
|
|
1818
|
+
const gated = archiveCache !== undefined && (process.platform === "linux" || process.platform === "darwin");
|
|
1819
|
+
const gate = 'IFS= read -r permit <&3 && [ "$permit" = run ] || exit 1; exec 3<&-; exec "$@"';
|
|
1820
|
+
const child = spawn(gated ? "/bin/sh" : file, gated ? ["-c", gate, "cotal-release-check", file, ...spawnArgs] : spawnArgs, {
|
|
1821
|
+
windowsVerbatimArguments, windowsHide: true,
|
|
1822
|
+
...(gated ? { detached: true, stdio: ["ignore", "pipe", "pipe", "pipe"] } : {}),
|
|
1823
|
+
});
|
|
1652
1824
|
let stdout = "", stderr = "", error;
|
|
1653
1825
|
child.stdout?.on("data", (chunk) => { stdout += chunk.toString(); });
|
|
1654
1826
|
child.stderr?.on("data", (chunk) => { stderr += chunk.toString(); });
|
|
1655
1827
|
child.once("error", cause => { error = cause.message; });
|
|
1828
|
+
if (gated) {
|
|
1829
|
+
const permit = child.stdio[3];
|
|
1830
|
+
permit.on("error", cause => { error = message(cause); });
|
|
1831
|
+
try {
|
|
1832
|
+
if (child.pid === undefined)
|
|
1833
|
+
permit.end();
|
|
1834
|
+
else {
|
|
1835
|
+
writeFileSync(join(archiveCache, `.worker-${child.pid}`), "", { mode: 0o600 });
|
|
1836
|
+
permit.end("run\n");
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
catch (cause) {
|
|
1840
|
+
error = message(cause);
|
|
1841
|
+
permit.end();
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1656
1844
|
const status = await new Promise(resolveClose => child.once("close", resolveClose));
|
|
1657
1845
|
return { status, stdout, stderr, ...(error ? { error } : {}) };
|
|
1658
1846
|
}
|
|
@@ -1668,6 +1856,7 @@ function runNpm(args, inherit = false) {
|
|
|
1668
1856
|
: { encoding: "utf8", windowsVerbatimArguments });
|
|
1669
1857
|
return {
|
|
1670
1858
|
status: result.status,
|
|
1859
|
+
signal: result.signal,
|
|
1671
1860
|
stdout: `${result.stdout ?? ""}`,
|
|
1672
1861
|
stderr: `${result.stderr ?? ""}`,
|
|
1673
1862
|
error: result.error?.message,
|