@cotal-ai/cli 0.185.3 → 0.186.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/chat/stdio.d.ts.map +1 -1
- package/dist/chat/stdio.js +3 -2
- package/dist/chat/stdio.js.map +1 -1
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +15 -5
- package/dist/command.js.map +1 -1
- package/dist/commands/agents.d.ts +8 -1
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +114 -25
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/chat.d.ts.map +1 -1
- package/dist/commands/chat.js +11 -1
- package/dist/commands/chat.js.map +1 -1
- package/dist/commands/doctor.js +2 -0
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/endpoint-authoring.d.ts.map +1 -1
- package/dist/commands/endpoint-authoring.js +5 -3
- package/dist/commands/endpoint-authoring.js.map +1 -1
- package/dist/commands/ext.d.ts.map +1 -1
- package/dist/commands/ext.js +25 -14
- package/dist/commands/ext.js.map +1 -1
- package/dist/commands/help.d.ts.map +1 -1
- package/dist/commands/help.js +6 -11
- package/dist/commands/help.js.map +1 -1
- package/dist/commands/join.d.ts.map +1 -1
- package/dist/commands/join.js +6 -3
- package/dist/commands/join.js.map +1 -1
- package/dist/commands/models.d.ts.map +1 -1
- package/dist/commands/models.js +6 -4
- package/dist/commands/models.js.map +1 -1
- package/dist/commands/personas.js +2 -2
- package/dist/commands/personas.js.map +1 -1
- package/dist/commands/send.d.ts.map +1 -1
- package/dist/commands/send.js +36 -18
- package/dist/commands/send.js.map +1 -1
- package/dist/commands/service-registry.d.ts.map +1 -1
- package/dist/commands/service-registry.js +2 -1
- package/dist/commands/service-registry.js.map +1 -1
- package/dist/commands/setup-current-connectors.d.ts +3 -6
- package/dist/commands/setup-current-connectors.d.ts.map +1 -1
- package/dist/commands/setup-current-connectors.js +17 -1
- package/dist/commands/setup-current-connectors.js.map +1 -1
- package/dist/commands/setup.d.ts +3 -5
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +28 -23
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/space-delete.d.ts.map +1 -1
- package/dist/commands/space-delete.js +21 -10
- package/dist/commands/space-delete.js.map +1 -1
- package/dist/commands/spawn-managed-launch.d.ts.map +1 -1
- package/dist/commands/spawn-managed-launch.js +5 -4
- package/dist/commands/spawn-managed-launch.js.map +1 -1
- package/dist/commands/spawn-preview.js +2 -2
- package/dist/commands/spawn-preview.js.map +1 -1
- package/dist/commands/spawn.d.ts.map +1 -1
- package/dist/commands/spawn.js +3 -2
- package/dist/commands/spawn.js.map +1 -1
- package/dist/commands/stack-down.d.ts +1 -1
- package/dist/commands/stack-down.d.ts.map +1 -1
- package/dist/commands/stack-down.js +19 -3
- package/dist/commands/stack-down.js.map +1 -1
- package/dist/commands/stack-lost-records.d.ts +1 -1
- package/dist/commands/stack-lost-records.d.ts.map +1 -1
- package/dist/commands/stack-lost-records.js +7 -5
- package/dist/commands/stack-lost-records.js.map +1 -1
- package/dist/commands/stack-up.js +1 -1
- package/dist/commands/stack-up.js.map +1 -1
- package/dist/commands/status-health.d.ts.map +1 -1
- package/dist/commands/status-health.js +10 -12
- package/dist/commands/status-health.js.map +1 -1
- package/dist/commands/status-model.d.ts +1 -0
- package/dist/commands/status-model.d.ts.map +1 -1
- package/dist/commands/status-render.d.ts.map +1 -1
- package/dist/commands/status-render.js +3 -1
- package/dist/commands/status-render.js.map +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +4 -3
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/sync.d.ts +1 -1
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +29 -8
- package/dist/commands/sync.js.map +1 -1
- package/dist/commands/up-args.d.ts +2 -0
- package/dist/commands/up-args.d.ts.map +1 -1
- package/dist/commands/up-args.js +9 -12
- package/dist/commands/up-args.js.map +1 -1
- package/dist/commands/up-broker-auth.d.ts +3 -1
- package/dist/commands/up-broker-auth.d.ts.map +1 -1
- package/dist/commands/up-broker-auth.js +9 -1
- package/dist/commands/up-broker-auth.js.map +1 -1
- package/dist/commands/up-detach.d.ts +10 -1
- package/dist/commands/up-detach.d.ts.map +1 -1
- package/dist/commands/up-detach.js +28 -13
- package/dist/commands/up-detach.js.map +1 -1
- package/dist/commands/up-foreground-listener.d.ts +1 -1
- package/dist/commands/up-foreground-listener.d.ts.map +1 -1
- package/dist/commands/up-foreground-listener.js +7 -3
- package/dist/commands/up-foreground-listener.js.map +1 -1
- package/dist/commands/up-host.d.ts +8 -0
- package/dist/commands/up-host.d.ts.map +1 -1
- package/dist/commands/up-host.js +27 -1
- package/dist/commands/up-host.js.map +1 -1
- package/dist/commands/up-resume.d.ts.map +1 -1
- package/dist/commands/up-resume.js +4 -2
- package/dist/commands/up-resume.js.map +1 -1
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +13 -13
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/update-caches.d.ts +1 -0
- package/dist/commands/update-caches.d.ts.map +1 -1
- package/dist/commands/update-caches.js +41 -12
- package/dist/commands/update-caches.js.map +1 -1
- package/dist/commands/update-continuity.d.ts +2 -0
- package/dist/commands/update-continuity.d.ts.map +1 -1
- package/dist/commands/update-continuity.js +27 -4
- package/dist/commands/update-continuity.js.map +1 -1
- package/dist/commands/update-modes.d.ts +4 -0
- package/dist/commands/update-modes.d.ts.map +1 -0
- package/dist/commands/update-modes.js +61 -0
- package/dist/commands/update-modes.js.map +1 -0
- package/dist/commands/update-posix-gate.d.ts +2 -0
- package/dist/commands/update-posix-gate.d.ts.map +1 -0
- package/dist/commands/update-posix-gate.js +131 -0
- package/dist/commands/update-posix-gate.js.map +1 -0
- package/dist/commands/update-process.d.ts +17 -3
- package/dist/commands/update-process.d.ts.map +1 -1
- package/dist/commands/update-process.js +358 -97
- package/dist/commands/update-process.js.map +1 -1
- package/dist/commands/update-release.d.ts.map +1 -1
- package/dist/commands/update-release.js +31 -9
- package/dist/commands/update-release.js.map +1 -1
- package/dist/commands/update-windows-install.js +23 -5
- package/dist/commands/update-windows-install.js.map +1 -1
- package/dist/commands/update.d.ts +8 -7
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +107 -101
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/who.d.ts +2 -2
- package/dist/commands/who.d.ts.map +1 -1
- package/dist/commands/who.js +14 -10
- package/dist/commands/who.js.map +1 -1
- package/dist/commands/whoami.d.ts.map +1 -1
- package/dist/commands/whoami.js +6 -4
- package/dist/commands/whoami.js.map +1 -1
- package/dist/console/app.d.ts.map +1 -1
- package/dist/console/app.js +9 -8
- package/dist/console/app.js.map +1 -1
- package/dist/console/commands.d.ts.map +1 -1
- package/dist/console/commands.js +10 -14
- package/dist/console/commands.js.map +1 -1
- package/dist/console/ui/Tiles.d.ts +1 -1
- package/dist/console/ui/Tiles.d.ts.map +1 -1
- package/dist/console/ui/Tiles.js +10 -3
- package/dist/console/ui/Tiles.js.map +1 -1
- package/dist/console/ui/theme.d.ts.map +1 -1
- package/dist/console/ui/theme.js +1 -0
- package/dist/console/ui/theme.js.map +1 -1
- package/dist/console/ui/topo/Map.js +1 -1
- package/dist/console/ui/topo/Map.js.map +1 -1
- package/dist/lib/backup-artifact.d.ts +2 -2
- package/dist/lib/backup-artifact.d.ts.map +1 -1
- package/dist/lib/backup-artifact.js +2 -2
- package/dist/lib/backup-artifact.js.map +1 -1
- package/dist/lib/broker-service.d.ts +1 -1
- package/dist/lib/broker-service.d.ts.map +1 -1
- package/dist/lib/broker-service.js +28 -23
- package/dist/lib/broker-service.js.map +1 -1
- package/dist/lib/broker-store-health.d.ts +4 -0
- package/dist/lib/broker-store-health.d.ts.map +1 -1
- package/dist/lib/broker-store-health.js +23 -2
- package/dist/lib/broker-store-health.js.map +1 -1
- package/dist/lib/choose-target.js +1 -1
- package/dist/lib/choose-target.js.map +1 -1
- package/dist/lib/held-name.d.ts +3 -2
- package/dist/lib/held-name.d.ts.map +1 -1
- package/dist/lib/held-name.js +10 -6
- package/dist/lib/held-name.js.map +1 -1
- package/dist/lib/held-seat-records.d.ts +11 -0
- package/dist/lib/held-seat-records.d.ts.map +1 -0
- package/dist/lib/held-seat-records.js +34 -0
- package/dist/lib/held-seat-records.js.map +1 -0
- package/dist/lib/install-umask.d.ts +5 -2
- package/dist/lib/install-umask.d.ts.map +1 -1
- package/dist/lib/install-umask.js +92 -9
- package/dist/lib/install-umask.js.map +1 -1
- package/dist/lib/manager-choice.d.ts +3 -3
- package/dist/lib/manager-choice.d.ts.map +1 -1
- package/dist/lib/manager-choice.js +17 -5
- package/dist/lib/manager-choice.js.map +1 -1
- 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 +17 -4
- package/dist/lib/manager-proc.js.map +1 -1
- package/dist/lib/manifest/spawn-plan.d.ts +1 -1
- package/dist/lib/manifest/spawn-plan.d.ts.map +1 -1
- package/dist/lib/manifest/spawn-plan.js +2 -2
- package/dist/lib/manifest/spawn-plan.js.map +1 -1
- package/dist/lib/npm-invocation.d.ts +3 -1
- package/dist/lib/npm-invocation.d.ts.map +1 -1
- package/dist/lib/npm-invocation.js +59 -3
- package/dist/lib/npm-invocation.js.map +1 -1
- package/dist/lib/npm-reachability.d.ts +8 -0
- package/dist/lib/npm-reachability.d.ts.map +1 -0
- package/dist/lib/npm-reachability.js +175 -0
- package/dist/lib/npm-reachability.js.map +1 -0
- package/dist/lib/restore-streams.d.ts +1 -1
- package/dist/lib/restore-streams.js +1 -1
- package/dist/lib/restore.d.ts.map +1 -1
- package/dist/lib/restore.js +22 -42
- package/dist/lib/restore.js.map +1 -1
- package/dist/lib/rolled-back-runs.d.ts.map +1 -1
- package/dist/lib/rolled-back-runs.js +3 -0
- package/dist/lib/rolled-back-runs.js.map +1 -1
- package/dist/lib/service-manager-reboot.d.ts +5 -0
- package/dist/lib/service-manager-reboot.d.ts.map +1 -0
- package/dist/lib/service-manager-reboot.js +39 -0
- package/dist/lib/service-manager-reboot.js.map +1 -0
- package/dist/lib/service-preset-target.d.ts +1 -1
- package/dist/lib/service-preset-target.d.ts.map +1 -1
- package/dist/lib/service-preset-target.js +29 -9
- package/dist/lib/service-preset-target.js.map +1 -1
- package/dist/lib/service-process.d.ts.map +1 -1
- package/dist/lib/service-process.js +10 -5
- package/dist/lib/service-process.js.map +1 -1
- package/dist/lib/spawn-defaults.d.ts.map +1 -1
- package/dist/lib/spawn-defaults.js +3 -1
- package/dist/lib/spawn-defaults.js.map +1 -1
- package/dist/lib/teardown-spare.d.ts +2 -1
- package/dist/lib/teardown-spare.d.ts.map +1 -1
- package/dist/lib/teardown-spare.js +11 -6
- package/dist/lib/teardown-spare.js.map +1 -1
- package/dist/lib/transient.d.ts +1 -0
- package/dist/lib/transient.d.ts.map +1 -1
- package/dist/lib/transient.js +3 -3
- package/dist/lib/transient.js.map +1 -1
- package/dist/lib/update-connector-config.d.ts +2 -0
- package/dist/lib/update-connector-config.d.ts.map +1 -1
- package/dist/lib/update-connector-config.js +69 -3
- package/dist/lib/update-connector-config.js.map +1 -1
- package/dist/lib/update-manager-install-linux.d.ts +6 -7
- package/dist/lib/update-manager-install-linux.d.ts.map +1 -1
- package/dist/lib/update-manager-install-linux.js +70 -43
- package/dist/lib/update-manager-install-linux.js.map +1 -1
- package/dist/lib/update-managers.d.ts +2 -0
- package/dist/lib/update-managers.d.ts.map +1 -1
- package/dist/lib/update-managers.js +14 -3
- package/dist/lib/update-managers.js.map +1 -1
- package/dist/lib/version.d.ts +9 -0
- package/dist/lib/version.d.ts.map +1 -1
- package/dist/lib/version.js +12 -4
- package/dist/lib/version.js.map +1 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +2 -0
- package/dist/render.js.map +1 -1
- package/dist/seed/reconcile.d.ts.map +1 -1
- package/dist/seed/reconcile.js +9 -8
- package/dist/seed/reconcile.js.map +1 -1
- package/dist/seed/store.d.ts +1 -0
- package/dist/seed/store.d.ts.map +1 -1
- package/dist/seed/store.js +2 -0
- package/dist/seed/store.js.map +1 -1
- package/dist/telemetry.d.ts +3 -3
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +10 -5
- package/dist/telemetry.js.map +1 -1
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js +2 -0
- package/dist/ui.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
1
2
|
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
-
import { existsSync, mkdtempSync, readFileSync, realpathSync, rmSync, watch, writeFileSync } from "node:fs";
|
|
3
|
+
import { existsSync, mkdtempSync, readFileSync, realpathSync, rmSync, unlinkSync, watch, writeFileSync } from "node:fs";
|
|
3
4
|
import { homedir, tmpdir } from "node:os";
|
|
4
5
|
import { basename, dirname, isAbsolute, join, parse, relative, resolve, sep } from "node:path";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
7
|
import { cmdSpawnSpec, beginGlobalUpdateChild, processGroupMembers, processStartToken } from "@cotal-ai/workspace";
|
|
7
8
|
import { withInstallUmask } from "../lib/install-umask.js";
|
|
8
9
|
import { npmInvocation, npmLifecycleEnvironment, npmUpdateChildEnvironment } from "../lib/npm-invocation.js";
|
|
@@ -10,12 +11,21 @@ import { compareSemver } from "../seed/reconcile.js";
|
|
|
10
11
|
export class RegistryUnavailable extends Error {
|
|
11
12
|
}
|
|
12
13
|
export class StagingTimeout extends Error {
|
|
13
|
-
npmOutput;
|
|
14
14
|
constructor(npmOutput) {
|
|
15
15
|
super("Package staging reached its time limit");
|
|
16
|
-
this
|
|
16
|
+
stagingDiagnostic.set(this, npmOutput);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
function stagingNpmFailure(result) {
|
|
20
|
+
const text = result.error || result.stderr.trim() || result.stdout.trim() || `npm exited ${result.status}`;
|
|
21
|
+
const error = new Error(`target staging failed: ${result.scrub?.(text) ?? text}`);
|
|
22
|
+
stagingDiagnostic.set(error, `target staging failed: ${text}`);
|
|
23
|
+
return error;
|
|
24
|
+
}
|
|
25
|
+
const stagingDiagnostic = new WeakMap();
|
|
26
|
+
export function rawStagingDiagnostic(error) {
|
|
27
|
+
return error instanceof Error ? stagingDiagnostic.get(error) ?? message(error) : message(error);
|
|
28
|
+
}
|
|
19
29
|
export function parseNpmVersion(output) {
|
|
20
30
|
const parsed = JSON.parse(output.trim());
|
|
21
31
|
// `npm view cotal-ai@latest version --json` returns a bare string ("0.13.2") only while the
|
|
@@ -77,64 +87,319 @@ export function verifyGlobalEntry(root, expectedVersion) {
|
|
|
77
87
|
throw new Error(`the installed cotal executable escapes its package: ${entry}`);
|
|
78
88
|
return entry;
|
|
79
89
|
}
|
|
90
|
+
const SHELL_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
91
|
+
const npmChildPermitGate = 'IFS= read -r permit <&3 && [ "$permit" = run ] || exit 1; exec 3<&-; exec "$@"';
|
|
92
|
+
const shellPreservesCache = new Map();
|
|
93
|
+
const pinnedPosixGate = new AsyncLocalStorage();
|
|
94
|
+
function hasNonIdentifierEnv(env) {
|
|
95
|
+
for (const [key, value] of Object.entries(env)) {
|
|
96
|
+
if (value !== undefined && key && !key.includes("=") && !SHELL_IDENTIFIER.test(key))
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
function shellPreservesNonIdentifiers(shell) {
|
|
102
|
+
let key = shell;
|
|
103
|
+
try {
|
|
104
|
+
key = `${shell}\0${realpathSync(shell)}`;
|
|
105
|
+
}
|
|
106
|
+
catch { /* keep literal shell path */ }
|
|
107
|
+
const cached = shellPreservesCache.get(key);
|
|
108
|
+
if (cached !== undefined)
|
|
109
|
+
return cached;
|
|
110
|
+
const probeKey = "cotal_gate_probe:1";
|
|
111
|
+
const probe = spawnSync(shell, ["-c", 'exec "$@"', "cotal-gate-probe", process.execPath, "-e", `process.stdout.write(process.env[${JSON.stringify(probeKey)}] === "1" ? "1" : "0")`], { env: { [probeKey]: "1" }, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5000, killSignal: "SIGKILL", windowsHide: true });
|
|
112
|
+
const preserves = !probe.error && probe.signal === null && probe.stdout === "1";
|
|
113
|
+
shellPreservesCache.set(key, preserves);
|
|
114
|
+
return preserves;
|
|
115
|
+
}
|
|
116
|
+
export async function withPosixGateScratch(scratchDir, run) {
|
|
117
|
+
if (pinnedPosixGate.getStore())
|
|
118
|
+
return run();
|
|
119
|
+
const ownDir = scratchDir === undefined ? mkdtempSync(join(tmpdir(), "cotal-update-")) : undefined;
|
|
120
|
+
const store = { dir: realpathSync(scratchDir ?? ownDir) };
|
|
121
|
+
try {
|
|
122
|
+
return await pinnedPosixGate.run(store, run);
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
if (store.path) {
|
|
126
|
+
try {
|
|
127
|
+
unlinkSync(store.path);
|
|
128
|
+
}
|
|
129
|
+
catch { /* already removed */ }
|
|
130
|
+
}
|
|
131
|
+
if (ownDir)
|
|
132
|
+
rmSync(ownDir, { recursive: true, force: true, maxRetries: 3 });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export function pinPosixGateIfNeeded(env, shell = "/bin/sh") {
|
|
136
|
+
if (process.platform === "win32")
|
|
137
|
+
return;
|
|
138
|
+
if (hasNonIdentifierEnv(env) && !shellPreservesNonIdentifiers(shell))
|
|
139
|
+
posixGateScriptPath();
|
|
140
|
+
}
|
|
141
|
+
export function posixGateScriptPath() {
|
|
142
|
+
const store = pinnedPosixGate.getStore();
|
|
143
|
+
if (store?.path)
|
|
144
|
+
return store.path;
|
|
145
|
+
const path = fileURLToPath(new URL(import.meta.url.endsWith(".ts") ? "./update-posix-gate.ts" : "./update-posix-gate.js", import.meta.url));
|
|
146
|
+
if (!existsSync(path)) {
|
|
147
|
+
throw new Error(`missing POSIX update gate helper (${path}); reinstall with \`npm install -g cotal-ai@latest\` or run \`pnpm --filter @cotal-ai/cli build\` in a source checkout`);
|
|
148
|
+
}
|
|
149
|
+
if (!store)
|
|
150
|
+
return path;
|
|
151
|
+
const copy = join(store.dir, path.endsWith(".ts") ? "update-posix-gate.mts" : "update-posix-gate.mjs");
|
|
152
|
+
writeFileSync(copy, readFileSync(path), { mode: 0o600, flag: "wx" });
|
|
153
|
+
store.path = copy;
|
|
154
|
+
return copy;
|
|
155
|
+
}
|
|
156
|
+
function encodeGateEnv(entries) {
|
|
157
|
+
const parts = [];
|
|
158
|
+
const header = Buffer.allocUnsafe(4);
|
|
159
|
+
header.writeUInt32BE(entries.length, 0);
|
|
160
|
+
parts.push(header);
|
|
161
|
+
for (const [key, value] of entries) {
|
|
162
|
+
const keyBytes = Buffer.from(key, "utf8");
|
|
163
|
+
const valueBytes = Buffer.from(value, "utf8");
|
|
164
|
+
const lengths = Buffer.allocUnsafe(8);
|
|
165
|
+
lengths.writeUInt32BE(keyBytes.length, 0);
|
|
166
|
+
lengths.writeUInt32BE(valueBytes.length, 4);
|
|
167
|
+
parts.push(lengths, keyBytes, valueBytes);
|
|
168
|
+
}
|
|
169
|
+
const trailer = Buffer.allocUnsafe(4);
|
|
170
|
+
trailer.writeUInt32BE(0xffffffff, 0);
|
|
171
|
+
parts.push(trailer);
|
|
172
|
+
return Buffer.concat(parts);
|
|
173
|
+
}
|
|
80
174
|
// The pipe closes without permission if the parent dies before publishing the PID.
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
175
|
+
// When the gate shell drops non-identifier names, pass them over inherited descriptor 4:
|
|
176
|
+
// in-process via --import for our own Node children so parent/published PIDs never change,
|
|
177
|
+
// or through the adjacent gate stage for external commands such as npm.
|
|
178
|
+
export function npmChildGate(label, file, args, env, shell = "/bin/sh", operation = "npm") {
|
|
179
|
+
const extra = [];
|
|
180
|
+
for (const [key, value] of Object.entries(env)) {
|
|
181
|
+
if (value === undefined || !key || key.includes("="))
|
|
182
|
+
continue;
|
|
183
|
+
if (!SHELL_IDENTIFIER.test(key))
|
|
184
|
+
extra.push([key, value]);
|
|
185
|
+
}
|
|
186
|
+
if (extra.length === 0 || shellPreservesNonIdentifiers(shell))
|
|
187
|
+
return { file: shell, args: ["-c", npmChildPermitGate, label, file, ...args], env };
|
|
188
|
+
const gateScript = posixGateScriptPath();
|
|
189
|
+
const inProcessPreload = operation === "reconcile" && file === process.execPath;
|
|
190
|
+
const gateEnv = {};
|
|
191
|
+
for (const [key, value] of Object.entries(env)) {
|
|
192
|
+
if (value === undefined || !SHELL_IDENTIFIER.test(key))
|
|
193
|
+
continue;
|
|
194
|
+
if (!inProcessPreload && key === "NODE_OPTIONS")
|
|
195
|
+
continue;
|
|
196
|
+
gateEnv[key] = value;
|
|
197
|
+
}
|
|
198
|
+
if (!inProcessPreload && env.NODE_OPTIONS !== undefined)
|
|
199
|
+
extra.push(["NODE_OPTIONS", env.NODE_OPTIONS]);
|
|
200
|
+
const envPayload = encodeGateEnv(extra);
|
|
201
|
+
if (inProcessPreload) {
|
|
202
|
+
const preloadUrl = pathToFileURL(gateScript);
|
|
203
|
+
preloadUrl.searchParams.set("label", label);
|
|
204
|
+
return {
|
|
205
|
+
file: shell,
|
|
206
|
+
args: ["-c", npmChildPermitGate, label, file, "--import", preloadUrl.href, ...args],
|
|
207
|
+
env: gateEnv,
|
|
208
|
+
envPayload,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
file: shell,
|
|
213
|
+
args: ["-c", npmChildPermitGate, label, process.execPath, gateScript, label, file, ...args],
|
|
214
|
+
env: gateEnv,
|
|
215
|
+
envPayload,
|
|
216
|
+
groupCleanup: true,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
export function releaseChildGate(child, permitted, envPayload, onPermitError, groupCleanup = false, startTokenOf = processStartToken) {
|
|
220
|
+
const permit = child.stdio[3];
|
|
221
|
+
const envPipe = envPayload ? child.stdio[4] : undefined;
|
|
222
|
+
permit.on("error", onPermitError);
|
|
223
|
+
envPipe?.on("error", () => { });
|
|
224
|
+
if (permitted && groupCleanup && child.pid !== undefined && child.pid > 1) {
|
|
225
|
+
const pgid = child.pid;
|
|
226
|
+
const leaderStart = startTokenOf(pgid);
|
|
227
|
+
if (leaderStart !== undefined) {
|
|
228
|
+
child.once("exit", (_code, sig) => {
|
|
229
|
+
if (sig === null)
|
|
230
|
+
return;
|
|
231
|
+
try {
|
|
232
|
+
// Once the leader is reaped, a recycled PID could lead a new group only after all our
|
|
233
|
+
// members exited; verify no new leader holds pgid and our group still has live members.
|
|
234
|
+
const currentStart = startTokenOf(pgid);
|
|
235
|
+
if (currentStart !== undefined && currentStart !== leaderStart)
|
|
236
|
+
return;
|
|
237
|
+
if (processGroupMembers(pgid).length === 0)
|
|
238
|
+
return;
|
|
239
|
+
const groupSig = sig === "SIGPIPE" || sig === "SIGXFSZ" || sig === "SIGUSR1" ? "SIGTERM" : sig;
|
|
240
|
+
process.kill(-pgid, groupSig);
|
|
241
|
+
}
|
|
242
|
+
catch { /* group already gone */ }
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
envPipe?.end(permitted ? envPayload : undefined);
|
|
247
|
+
permit.end(permitted ? "run\n" : undefined);
|
|
248
|
+
}
|
|
249
|
+
const STOP_GRACE_MS = 2000;
|
|
250
|
+
const STOP_REAP_MS = 1000;
|
|
251
|
+
const FORWARDED_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
252
|
+
const SIGNAL_EXIT_CODE = { SIGHUP: 129, SIGINT: 130, SIGTERM: 143 };
|
|
253
|
+
function stopDetachedGroup(child, pgid, label, initial, rejectClose) {
|
|
254
|
+
const signalGroup = (signal) => {
|
|
255
|
+
try {
|
|
256
|
+
process.kill(-pgid, signal);
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
if (error.code !== "ESRCH")
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
const stopping = (async () => {
|
|
264
|
+
signalGroup(initial);
|
|
265
|
+
const graceDeadline = performance.now() + STOP_GRACE_MS;
|
|
266
|
+
while (processGroupMembers(pgid).length && performance.now() < graceDeadline) {
|
|
267
|
+
await new Promise(resolve => setTimeout(resolve, 25));
|
|
268
|
+
}
|
|
269
|
+
if (processGroupMembers(pgid).length)
|
|
270
|
+
signalGroup("SIGKILL");
|
|
271
|
+
const deadline = performance.now() + STOP_REAP_MS;
|
|
272
|
+
while (processGroupMembers(pgid).length) {
|
|
273
|
+
if (performance.now() >= deadline)
|
|
274
|
+
throw new Error(`could not stop ${label} npm process group ${pgid}`);
|
|
275
|
+
await new Promise(resolve => setTimeout(resolve, 25));
|
|
276
|
+
}
|
|
277
|
+
})();
|
|
278
|
+
void stopping.catch(error => {
|
|
279
|
+
child.stdin?.destroy();
|
|
280
|
+
child.stdout?.destroy();
|
|
281
|
+
child.stderr?.destroy();
|
|
282
|
+
child.unref();
|
|
283
|
+
rejectClose(error);
|
|
284
|
+
});
|
|
285
|
+
return stopping;
|
|
286
|
+
}
|
|
287
|
+
function finishInterrupt(interrupted, removeSignals) {
|
|
288
|
+
removeSignals?.();
|
|
289
|
+
if (process.listenerCount(interrupted) === 0) {
|
|
290
|
+
process.kill(process.pid, interrupted);
|
|
291
|
+
setTimeout(() => process.exit(SIGNAL_EXIT_CODE[interrupted]), 100).unref();
|
|
292
|
+
return new Promise(() => { });
|
|
293
|
+
}
|
|
294
|
+
process.kill(process.pid, interrupted);
|
|
295
|
+
}
|
|
296
|
+
export async function runNpmAsync(args, cache, stopOnSignal = false) {
|
|
297
|
+
let interrupted;
|
|
298
|
+
let removeSignals;
|
|
299
|
+
let npm;
|
|
84
300
|
try {
|
|
85
|
-
const
|
|
301
|
+
const prefix = args.indexOf("--prefix");
|
|
302
|
+
npm = npmInvocation(process.env, args, args[0] === "install" && prefix >= 0 ? args[prefix + 1] : undefined);
|
|
86
303
|
const { file, args: spawnArgs, windowsVerbatimArguments } = cmdSpawnSpec(npm.file, npm.args, npm.env);
|
|
87
|
-
const gated =
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
304
|
+
const gated = cache !== undefined && (process.platform === "linux" || process.platform === "darwin");
|
|
305
|
+
const launch = gated ? npmChildGate("cotal-release-check", file, spawnArgs, npm.env) : undefined;
|
|
306
|
+
const child = spawn(launch ? launch.file : file, launch ? launch.args : spawnArgs, {
|
|
307
|
+
cwd: npm.cwd, env: launch ? launch.env : npm.env, windowsVerbatimArguments, windowsHide: true,
|
|
308
|
+
...(launch ? { detached: true, stdio: launch.envPayload ? ["ignore", "pipe", "pipe", "pipe", "pipe"] : ["ignore", "pipe", "pipe", "pipe"] }
|
|
309
|
+
: args[0] === "install" ? { stdio: ["ignore", "pipe", "pipe"] } : {}),
|
|
91
310
|
});
|
|
92
311
|
let stdout = "", stderr = "", error;
|
|
93
|
-
|
|
94
|
-
|
|
312
|
+
let stopping;
|
|
313
|
+
let rejectClose;
|
|
314
|
+
const close = new Promise((resolveClose, reject) => {
|
|
315
|
+
rejectClose = reject;
|
|
316
|
+
child.once("close", (status, signal) => resolveClose({ status, signal }));
|
|
317
|
+
});
|
|
318
|
+
child.stdout?.setEncoding("utf8").on("data", (chunk) => { stdout += chunk; });
|
|
319
|
+
child.stderr?.setEncoding("utf8").on("data", (chunk) => { stderr += chunk; });
|
|
95
320
|
child.once("error", cause => { error = cause.message; });
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
321
|
+
if (launch) {
|
|
322
|
+
let permitted = false;
|
|
323
|
+
if (child.pid !== undefined) {
|
|
324
|
+
try {
|
|
325
|
+
writeFileSync(join(cache, `.worker-${child.pid}`), "", { mode: 0o600, flag: "wx" });
|
|
326
|
+
permitted = true;
|
|
327
|
+
if (stopOnSignal) {
|
|
328
|
+
const pgid = child.pid;
|
|
329
|
+
const handlers = FORWARDED_SIGNALS.map(signal => {
|
|
330
|
+
const handler = () => {
|
|
331
|
+
interrupted ??= signal;
|
|
332
|
+
stopping ??= stopDetachedGroup(child, pgid, "dependency-check", signal, rejectClose);
|
|
333
|
+
};
|
|
334
|
+
process.on(signal, handler);
|
|
335
|
+
return [signal, handler];
|
|
336
|
+
});
|
|
337
|
+
removeSignals = () => { for (const [signal, handler] of handlers)
|
|
338
|
+
process.off(signal, handler); };
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
catch (cause) {
|
|
342
|
+
error = message(cause);
|
|
105
343
|
}
|
|
106
344
|
}
|
|
107
|
-
|
|
108
|
-
error = message(cause);
|
|
109
|
-
permit.end();
|
|
110
|
-
}
|
|
345
|
+
releaseChildGate(child, permitted, launch.envPayload, cause => { error = message(cause); }, launch.groupCleanup);
|
|
111
346
|
}
|
|
112
|
-
const
|
|
113
|
-
|
|
347
|
+
const result = await close;
|
|
348
|
+
if (stopping)
|
|
349
|
+
await stopping;
|
|
350
|
+
if (interrupted) {
|
|
351
|
+
npm.config?.dispose();
|
|
352
|
+
await finishInterrupt(interrupted, removeSignals);
|
|
353
|
+
removeSignals = undefined;
|
|
354
|
+
}
|
|
355
|
+
return {
|
|
356
|
+
...result, signal: result.signal ?? interrupted ?? null, stdout, stderr,
|
|
357
|
+
...(error ? { error } : {}), ...(npm.config && { scrub: npm.config.scrub }),
|
|
358
|
+
};
|
|
114
359
|
}
|
|
115
360
|
catch (error) {
|
|
116
|
-
|
|
361
|
+
if (interrupted) {
|
|
362
|
+
npm?.config?.dispose();
|
|
363
|
+
await finishInterrupt(interrupted, removeSignals);
|
|
364
|
+
removeSignals = undefined;
|
|
365
|
+
}
|
|
366
|
+
return { status: null, stdout: "", stderr: "", error: message(error), scrub: npm?.config?.scrub };
|
|
367
|
+
}
|
|
368
|
+
finally {
|
|
369
|
+
removeSignals?.();
|
|
370
|
+
npm?.config?.dispose();
|
|
117
371
|
}
|
|
118
372
|
}
|
|
119
373
|
export function runNpm(args, inherit = false) {
|
|
374
|
+
let npm;
|
|
120
375
|
try {
|
|
121
|
-
|
|
376
|
+
npm = npmInvocation(process.env, args);
|
|
122
377
|
const { file, args: spawnArgs, windowsVerbatimArguments } = cmdSpawnSpec(npm.file, npm.args, npm.env);
|
|
123
378
|
const result = spawnSync(file, spawnArgs, {
|
|
124
379
|
cwd: npm.cwd, env: npm.env, windowsVerbatimArguments,
|
|
125
|
-
...(inherit ? { stdio: "inherit" } : { encoding: "utf8" }), windowsHide: true,
|
|
380
|
+
...(inherit && !npm.config ? { stdio: "inherit" } : { encoding: "utf8" }), windowsHide: true,
|
|
126
381
|
});
|
|
382
|
+
const scrub = npm.config?.scrub;
|
|
383
|
+
const stdout = String(result.stdout ?? ""), stderr = String(result.stderr ?? "");
|
|
384
|
+
if (inherit && scrub) {
|
|
385
|
+
process.stdout.write(scrub(stdout));
|
|
386
|
+
process.stderr.write(scrub(stderr));
|
|
387
|
+
}
|
|
127
388
|
return {
|
|
128
389
|
status: result.status,
|
|
129
390
|
signal: result.signal,
|
|
130
|
-
stdout:
|
|
131
|
-
stderr:
|
|
391
|
+
stdout: inherit ? "" : stdout,
|
|
392
|
+
stderr: inherit ? "" : stderr,
|
|
132
393
|
error: result.error?.message,
|
|
133
394
|
errorCode: result.error?.code,
|
|
395
|
+
...(scrub && { scrub }),
|
|
134
396
|
};
|
|
135
397
|
}
|
|
136
398
|
catch (e) {
|
|
137
|
-
return { status: null, stdout: "", stderr: "", error: message(e), errorCode: e?.code };
|
|
399
|
+
return { status: null, stdout: "", stderr: "", error: message(e), errorCode: e?.code, scrub: npm?.config?.scrub };
|
|
400
|
+
}
|
|
401
|
+
finally {
|
|
402
|
+
npm?.config?.dispose();
|
|
138
403
|
}
|
|
139
404
|
}
|
|
140
405
|
export function runProcess(file, args, env, inherit = false) {
|
|
@@ -147,17 +412,26 @@ export function runProcess(file, args, env, inherit = false) {
|
|
|
147
412
|
error: result.error?.message,
|
|
148
413
|
};
|
|
149
414
|
}
|
|
150
|
-
export function runGlobalProcess(...args) {
|
|
151
|
-
const [root, operation, file, argv, env, inherit = false, verbatim = false] = args;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
415
|
+
export async function runGlobalProcess(...args) {
|
|
416
|
+
const [root, operation, file, argv, env, inherit = false, verbatim = false, staging] = args;
|
|
417
|
+
if (process.platform === "win32" && operation === "install")
|
|
418
|
+
return runWindowsInstall(root, file, argv, env, inherit, verbatim, staging);
|
|
419
|
+
if (process.platform === "linux") {
|
|
420
|
+
try {
|
|
421
|
+
pinPosixGateIfNeeded(env);
|
|
422
|
+
}
|
|
423
|
+
catch (e) {
|
|
424
|
+
return { status: null, stdout: "", stderr: "", error: message(e) };
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return runGlobalChild(...args);
|
|
155
428
|
}
|
|
156
429
|
async function runGlobalChild(root, operation, file, args, env, inherit = false, windowsVerbatimArguments = false, staging) {
|
|
157
430
|
const gated = process.platform === "linux";
|
|
158
431
|
const mutation = beginGlobalUpdateChild(root, operation, gated);
|
|
159
432
|
let cache;
|
|
160
433
|
let lifecycle;
|
|
434
|
+
let npm;
|
|
161
435
|
let published = false;
|
|
162
436
|
let preservePending = false;
|
|
163
437
|
const watchers = [];
|
|
@@ -167,14 +441,16 @@ async function runGlobalChild(root, operation, file, args, env, inherit = false,
|
|
|
167
441
|
try {
|
|
168
442
|
if (operation === "reconcile")
|
|
169
443
|
env = npmUpdateChildEnvironment(env);
|
|
170
|
-
const pipeConsole = process.platform === "win32" && inherit;
|
|
171
|
-
const npm = operation === "install" && file === "npm" ? npmInvocation(env, args) : undefined;
|
|
172
|
-
if (npm)
|
|
173
|
-
({ file, args, windowsVerbatimArguments } = cmdSpawnSpec(npm.file, npm.args, npm.env));
|
|
174
444
|
const reconcileCache = gated && operation === "reconcile";
|
|
175
445
|
cache = mkdtempSync(join(tmpdir(), reconcileCache ? "cotal-update-reconcile-" : "cotal-update-npm-"));
|
|
446
|
+
npm = operation === "install" && file === "npm" ? npmInvocation(env, args, staging ?? cache) : undefined;
|
|
447
|
+
const pipeConsole = process.platform === "win32" && inherit && !npm?.config;
|
|
448
|
+
if (npm)
|
|
449
|
+
({ file, args, windowsVerbatimArguments } = cmdSpawnSpec(npm.file, npm.args, npm.env));
|
|
176
450
|
if (npm)
|
|
177
451
|
lifecycle = npmLifecycleEnvironment(npm, cache);
|
|
452
|
+
const childEnv = { ...(lifecycle?.env ?? npm?.env ?? env), npm_config_cache: cache, npm_config_logs_max: "0", npm_config_update_notifier: "false" };
|
|
453
|
+
const launch = gated ? npmChildGate("cotal-update", file, args, childEnv, "/bin/sh", operation === "reconcile" ? "reconcile" : "npm") : undefined;
|
|
178
454
|
let recordCache = gated && (staging !== undefined || reconcileCache);
|
|
179
455
|
if (recordCache) {
|
|
180
456
|
try {
|
|
@@ -198,31 +474,30 @@ async function runGlobalChild(root, operation, file, args, env, inherit = false,
|
|
|
198
474
|
watchers.push(watcher);
|
|
199
475
|
}
|
|
200
476
|
}
|
|
201
|
-
const
|
|
477
|
+
const inheritOutput = inherit && !npm?.config;
|
|
478
|
+
const child = withInstallUmask(() => spawn(launch ? launch.file : file, launch ? launch.args : args, {
|
|
202
479
|
// Corepack searches ancestors for a package manager. Keep only npm at the filesystem root.
|
|
203
480
|
...(operation === "install" ? { cwd: parse(homedir()).root } : {}),
|
|
204
|
-
env:
|
|
481
|
+
env: launch ? launch.env : childEnv,
|
|
205
482
|
// A separate process group keeps terminal interrupts out of npm's live replacement.
|
|
206
483
|
// Keep the ChildProcess referenced and await close; this is not a background update.
|
|
207
484
|
detached: true,
|
|
208
485
|
windowsHide: true,
|
|
209
486
|
windowsVerbatimArguments,
|
|
210
|
-
stdio: updateChildStdio(gated,
|
|
487
|
+
stdio: updateChildStdio(gated, inheritOutput, pipeConsole, launch?.envPayload !== undefined),
|
|
211
488
|
}));
|
|
212
|
-
const permit = gated ? child.stdio[3] : undefined;
|
|
213
489
|
let error = "";
|
|
214
490
|
let stdout = "";
|
|
215
491
|
let stderr = "";
|
|
216
|
-
child.stdout?.on("data", (chunk) => { if (pipeConsole)
|
|
492
|
+
child.stdout?.setEncoding("utf8").on("data", (chunk) => { if (pipeConsole)
|
|
217
493
|
process.stdout.write(chunk);
|
|
218
494
|
else
|
|
219
|
-
stdout += chunk
|
|
220
|
-
child.stderr?.on("data", (chunk) => { if (pipeConsole)
|
|
495
|
+
stdout += chunk; });
|
|
496
|
+
child.stderr?.setEncoding("utf8").on("data", (chunk) => { if (pipeConsole)
|
|
221
497
|
process.stderr.write(chunk);
|
|
222
498
|
else
|
|
223
|
-
stderr += chunk
|
|
499
|
+
stderr += chunk; });
|
|
224
500
|
child.once("error", (e) => { error = e.message; });
|
|
225
|
-
permit?.on("error", (e) => { error = e.message; });
|
|
226
501
|
if (child.pid !== undefined) {
|
|
227
502
|
try {
|
|
228
503
|
// Publish cache custody before the gate permits npm to write to it.
|
|
@@ -243,7 +518,8 @@ async function runGlobalChild(root, operation, file, args, env, inherit = false,
|
|
|
243
518
|
preservePending = true;
|
|
244
519
|
}
|
|
245
520
|
}
|
|
246
|
-
|
|
521
|
+
if (launch)
|
|
522
|
+
releaseChildGate(child, published, launch.envPayload, (e) => { error = e.message; }, launch.groupCleanup);
|
|
247
523
|
let rejectClose;
|
|
248
524
|
const close = new Promise((resolveClose, reject) => {
|
|
249
525
|
rejectClose = reject;
|
|
@@ -251,48 +527,25 @@ async function runGlobalChild(root, operation, file, args, env, inherit = false,
|
|
|
251
527
|
});
|
|
252
528
|
if (staging !== undefined && child.pid !== undefined) {
|
|
253
529
|
const pgid = child.pid;
|
|
254
|
-
const signalGroup = (signal) => {
|
|
255
|
-
try {
|
|
256
|
-
process.kill(-pgid, signal);
|
|
257
|
-
}
|
|
258
|
-
catch (error) {
|
|
259
|
-
if (error.code !== "ESRCH")
|
|
260
|
-
throw error;
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
const grace = 2000;
|
|
264
|
-
const reap = 1000;
|
|
265
530
|
const stop = () => {
|
|
266
531
|
if (stopping)
|
|
267
532
|
return;
|
|
268
533
|
clearTimeout(elapsed);
|
|
269
534
|
clearTimeout(idle);
|
|
270
|
-
stopping = (
|
|
271
|
-
signalGroup("SIGTERM");
|
|
272
|
-
await new Promise(resolve => setTimeout(resolve, grace));
|
|
273
|
-
if (processGroupMembers(pgid).length)
|
|
274
|
-
signalGroup("SIGKILL");
|
|
275
|
-
const deadline = performance.now() + reap;
|
|
276
|
-
while (processGroupMembers(pgid).length) {
|
|
277
|
-
if (performance.now() >= deadline)
|
|
278
|
-
throw new Error(`could not stop staging npm process group ${pgid}`);
|
|
279
|
-
await new Promise(resolve => setTimeout(resolve, 25));
|
|
280
|
-
}
|
|
281
|
-
})();
|
|
282
|
-
void stopping.catch(error => {
|
|
283
|
-
child.stdin?.destroy();
|
|
284
|
-
child.stdout?.destroy();
|
|
285
|
-
child.stderr?.destroy();
|
|
286
|
-
child.unref();
|
|
287
|
-
rejectClose(error);
|
|
288
|
-
});
|
|
535
|
+
stopping = stopDetachedGroup(child, pgid, "staging", "SIGTERM", rejectClose);
|
|
289
536
|
};
|
|
290
537
|
// Leave room for TERM and KILL within the five-minute staging budget. Idle time
|
|
291
538
|
// covers three 15-second fetch attempts plus their one- and two-second backoffs.
|
|
292
|
-
elapsed = setTimeout(stop, 300_000 -
|
|
539
|
+
elapsed = setTimeout(stop, 300_000 - STOP_GRACE_MS - STOP_REAP_MS);
|
|
293
540
|
idle = setTimeout(stop, 50_000);
|
|
294
541
|
}
|
|
295
542
|
const closed = await close;
|
|
543
|
+
const scrub = npm?.config?.scrub;
|
|
544
|
+
if (inherit && scrub) {
|
|
545
|
+
process.stdout.write(scrub(stdout));
|
|
546
|
+
process.stderr.write(scrub(stderr));
|
|
547
|
+
stdout = stderr = "";
|
|
548
|
+
}
|
|
296
549
|
clearTimeout(elapsed);
|
|
297
550
|
clearTimeout(idle);
|
|
298
551
|
if (stopping) {
|
|
@@ -305,12 +558,13 @@ async function runGlobalChild(root, operation, file, args, env, inherit = false,
|
|
|
305
558
|
mutation.complete(closed.status, closed.signal, closed.signal !== null
|
|
306
559
|
? `${operation} child terminated by ${closed.signal}`
|
|
307
560
|
: `Windows npm intermediary exited ${closed.status}; descendant completion is unproved`);
|
|
308
|
-
|
|
561
|
+
const result = { status: error ? null : closed.status, signal: closed.signal, stdout, stderr, ...(error ? { error } : {}), ...(scrub && { scrub }) };
|
|
562
|
+
return staging && scrub && result.status !== 0 ? { ...result, stagingFailure: stagingNpmFailure(result) } : result;
|
|
309
563
|
}
|
|
310
564
|
catch (e) {
|
|
311
565
|
if (e instanceof StagingTimeout)
|
|
312
566
|
throw e;
|
|
313
|
-
return { status: null, stdout: "", stderr: "", error: message(e) };
|
|
567
|
+
return { status: null, stdout: "", stderr: "", error: npm?.config?.scrub(message(e)) ?? message(e) };
|
|
314
568
|
}
|
|
315
569
|
finally {
|
|
316
570
|
for (const watcher of watchers)
|
|
@@ -320,21 +574,24 @@ async function runGlobalChild(root, operation, file, args, env, inherit = false,
|
|
|
320
574
|
if (!published && !preservePending)
|
|
321
575
|
mutation.clear();
|
|
322
576
|
lifecycle?.dispose();
|
|
577
|
+
npm?.config?.dispose();
|
|
323
578
|
if (cache)
|
|
324
579
|
rmSync(cache, { recursive: true, force: true, maxRetries: 3 });
|
|
325
580
|
}
|
|
326
581
|
}
|
|
327
|
-
function updateChildStdio(gated, inherit, pipeConsole) {
|
|
582
|
+
function updateChildStdio(gated, inherit, pipeConsole, hasEnvPayload) {
|
|
328
583
|
if (gated)
|
|
329
|
-
return [...Array(3).fill(inherit ? "inherit" : "pipe"), "pipe"];
|
|
584
|
+
return [...Array(3).fill(inherit ? "inherit" : "pipe"), "pipe", ...(hasEnvPayload ? ["pipe"] : [])];
|
|
330
585
|
return pipeConsole ? ["ignore", "pipe", "pipe"] : inherit ? "inherit" : undefined;
|
|
331
586
|
}
|
|
332
|
-
async function runWindowsInstall(root, file, args, env, inherit, verbatim) {
|
|
333
|
-
const npm = file === "npm" ? npmInvocation(env, args) : undefined;
|
|
334
|
-
if (npm)
|
|
335
|
-
({ file, args, windowsVerbatimArguments: verbatim } = cmdSpawnSpec(npm.file, npm.args, npm.env));
|
|
587
|
+
async function runWindowsInstall(root, file, args, env, inherit, verbatim, staging) {
|
|
336
588
|
const cache = mkdtempSync(join(tmpdir(), "cotal-update-npm-"));
|
|
589
|
+
let npm;
|
|
337
590
|
try {
|
|
591
|
+
npm = file === "npm" ? npmInvocation(env, args, staging ?? cache) : undefined;
|
|
592
|
+
const target = npm?.config ? args.find(arg => arg.startsWith("cotal-ai@"))?.slice("cotal-ai@".length) : undefined;
|
|
593
|
+
if (npm)
|
|
594
|
+
({ file, args, windowsVerbatimArguments: verbatim } = cmdSpawnSpec(npm.file, npm.args, npm.env));
|
|
338
595
|
const mutation = beginGlobalUpdateChild(root, "install");
|
|
339
596
|
let published = false;
|
|
340
597
|
let error;
|
|
@@ -351,7 +608,7 @@ async function runWindowsInstall(root, file, args, env, inherit, verbatim) {
|
|
|
351
608
|
published = true;
|
|
352
609
|
try {
|
|
353
610
|
mutation.markLive(worker.pid);
|
|
354
|
-
worker.send({ file, args, cwd: parse(homedir()).root, log: join(cache, "install.log"), verbatim });
|
|
611
|
+
worker.send({ file, args, cwd: parse(homedir()).root, log: join(cache, "install.log"), verbatim, config: npm?.config?.file, target });
|
|
355
612
|
}
|
|
356
613
|
catch (cause) {
|
|
357
614
|
error = message(cause);
|
|
@@ -375,9 +632,10 @@ async function runWindowsInstall(root, file, args, env, inherit, verbatim) {
|
|
|
375
632
|
}
|
|
376
633
|
}
|
|
377
634
|
catch (cause) {
|
|
378
|
-
return { status: null, stdout: "", stderr: "", error: message(cause) };
|
|
635
|
+
return { status: null, stdout: "", stderr: "", error: npm?.config?.scrub(message(cause)) ?? message(cause) };
|
|
379
636
|
}
|
|
380
637
|
finally {
|
|
638
|
+
npm?.config?.dispose();
|
|
381
639
|
rmSync(cache, { recursive: true, force: true, maxRetries: 3 });
|
|
382
640
|
}
|
|
383
641
|
}
|
|
@@ -385,6 +643,8 @@ async function runWindowsInstall(root, file, args, env, inherit, verbatim) {
|
|
|
385
643
|
export function latestNotAvailable(result, version) {
|
|
386
644
|
if (result.status === 0 || result.status === null || result.error)
|
|
387
645
|
return false;
|
|
646
|
+
if (result.missingVersion !== undefined)
|
|
647
|
+
return result.missingVersion === version;
|
|
388
648
|
try {
|
|
389
649
|
const error = JSON.parse(result.stdout).error;
|
|
390
650
|
return error?.code === "ETARGET" && error.summary === `No matching version found for cotal-ai@${version}.`;
|
|
@@ -393,8 +653,9 @@ export function latestNotAvailable(result, version) {
|
|
|
393
653
|
return false;
|
|
394
654
|
}
|
|
395
655
|
}
|
|
396
|
-
export function failure(result) {
|
|
397
|
-
|
|
656
|
+
export function failure(result, raw = false) {
|
|
657
|
+
const text = [result.signal && `process terminated by ${result.signal}`, result.error, result.stderr.trim(), result.stdout.trim()].filter(Boolean).join("\n") || `process exited ${result.status}`;
|
|
658
|
+
return raw ? text : result.scrub?.(text) ?? text;
|
|
398
659
|
}
|
|
399
660
|
export function message(value) {
|
|
400
661
|
return value instanceof Error ? value.message : String(value);
|