@indigoai-us/hq-cli 5.345.268 → 5.345.270
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/CHANGELOG.md +38 -0
- package/README.md +12 -0
- package/contracts/host-canary-release.json +7 -7
- package/dist/lib/daemon/run.js +12 -0
- package/dist/lib/hook-engine/native-stop-compatibility.json +2 -1
- package/dist/lib/hook-engine/reconcile.js +8 -0
- package/dist/lib/hook-engine/stable-heal.d.ts +17 -1
- package/dist/lib/hook-engine/stable-heal.js +42 -5
- package/dist/lib/hook-engine/stable-link.d.ts +70 -0
- package/dist/lib/hook-engine/stable-link.js +300 -0
- package/dist/lib/install/hook-target.js +4 -1
- package/dist/lib/signals/steps/extract.d.ts +27 -7
- package/dist/lib/signals/steps/extract.js +88 -87
- package/dist/utils/hook-engine-crash.d.ts +86 -0
- package/dist/utils/hook-engine-crash.js +325 -0
- package/dist/utils/hook-engine-rollup.d.ts +8 -3
- package/dist/utils/hook-trust.js +7 -1
- package/dist/utils/host-registration.d.ts +12 -35
- package/dist/utils/host-registration.js +47 -177
- package/dist/utils/version-gate.d.ts +42 -4
- package/dist/utils/version-gate.js +84 -25
- package/package.json +7 -7
|
@@ -65,12 +65,8 @@ import { CORE_NEXT_FLAG, coreNextEnabled } from './core-next-flag.js';
|
|
|
65
65
|
export { coreNextStrictReason, ENGINE_STRICT_ENV, ENGINE_STRICT_FILE } from './core-next-kill.js';
|
|
66
66
|
import { coreNextStrictReason, ENGINE_STRICT_FILE } from './core-next-kill.js';
|
|
67
67
|
const HOOK_ENGINE_LOG_RELATIVE = path.join('.hq', 'logs', 'hook-engine.jsonl');
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
/** Record of canary-accepted hook engines committed to `stable`, under the home folder. */
|
|
71
|
-
export const ACCEPTED_HOOK_ENGINE_RECORD = path.join('.hq', 'bin', 'hq-hook', 'accepted-engine.json');
|
|
72
|
-
/** Schema of [`ACCEPTED_HOOK_ENGINE_RECORD`]. */
|
|
73
|
-
export const ACCEPTED_HOOK_ENGINE_SCHEMA = 'hq.accepted-hook-engine.v1';
|
|
68
|
+
export { ACCEPTED_HOOK_ENGINE_RECORD, ACCEPTED_HOOK_ENGINE_SCHEMA, STABLE_LINK_NAME, StableDowngradeRefused, linkStableEngine, readAcceptedHookEngineRecord, stableEnginePath, } from '../lib/hook-engine/stable-link.js';
|
|
69
|
+
import { ACCEPTED_HOOK_ENGINE_RECORD, ACCEPTED_HOOK_ENGINE_SCHEMA, STABLE_LINK_NAME, StableDowngradeRefused, hookEngineDir, linkStableEngine, readAcceptedHookEngineRecord, stableEnginePath, } from '../lib/hook-engine/stable-link.js';
|
|
74
70
|
const coreNextCandidates = new WeakMap();
|
|
75
71
|
/** Read the candidate engine metadata attached by [`coreNextTarget`], if any. */
|
|
76
72
|
export function getCoreNextCandidate(target) {
|
|
@@ -192,113 +188,6 @@ export function checkStableEngine(stable, pinned) {
|
|
|
192
188
|
if (!fs.statSync(resolved).isFile())
|
|
193
189
|
throw new Error(`${resolved} is not a file`);
|
|
194
190
|
}
|
|
195
|
-
function hookEngineDir(home) {
|
|
196
|
-
return path.join(home, '.hq', 'bin', 'hq-hook');
|
|
197
|
-
}
|
|
198
|
-
/** The stable path that stands for a pinned engine path. */
|
|
199
|
-
export function stableEnginePath(pinned, home) {
|
|
200
|
-
const relative = path.relative(hookEngineDir(home), pinned);
|
|
201
|
-
const [, ...rest] = relative.split(/[\\/]/);
|
|
202
|
-
if (relative.startsWith('..') || path.isAbsolute(relative) || rest.length === 0) {
|
|
203
|
-
throw new Error(`hook engine ${pinned} is not under ${hookEngineDir(home)}`);
|
|
204
|
-
}
|
|
205
|
-
return path.join(hookEngineDir(home), STABLE_LINK_NAME, ...rest);
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Point `<home>/.hq/bin/hq-hook/stable` at the pinned engine's version folder
|
|
209
|
-
* and return the stable engine path. The link is replaced by rename, so a
|
|
210
|
-
* planted file at the temporary name or the link itself is never followed. A
|
|
211
|
-
* `stable` that is a real folder (not a link) is someone else's and is left
|
|
212
|
-
* alone: the call fails and the caller keeps the current registrations.
|
|
213
|
-
*/
|
|
214
|
-
export function linkStableEngine(pinned, home, platform = process.platform) {
|
|
215
|
-
const root = hookEngineDir(home);
|
|
216
|
-
const relative = path.relative(root, pinned).split(/[\\/]/);
|
|
217
|
-
const version = relative[0];
|
|
218
|
-
if (!version || version === '..' || version === STABLE_LINK_NAME || path.isAbsolute(path.relative(root, pinned))) {
|
|
219
|
-
throw new Error(`hook engine ${pinned} is not under ${root}`);
|
|
220
|
-
}
|
|
221
|
-
const stable = path.join(root, STABLE_LINK_NAME);
|
|
222
|
-
// Store rule v2: every path component this follows or creates under the home
|
|
223
|
-
// folder is a real folder of this user that group and others cannot write:
|
|
224
|
-
// .hq, .hq/bin, .hq/bin/hq-hook, the version folder and any folder below it
|
|
225
|
-
// up to the engine, and the engine file itself.
|
|
226
|
-
const components = [path.join(home, '.hq'), path.join(home, '.hq', 'bin'), root];
|
|
227
|
-
for (let i = 0; i < relative.length - 1; i += 1)
|
|
228
|
-
components.push(path.join(root, ...relative.slice(0, i + 1)));
|
|
229
|
-
for (const component of components)
|
|
230
|
-
checkOwnedEntry(component, 'folder', platform);
|
|
231
|
-
checkOwnedEntry(pinned, 'file', platform);
|
|
232
|
-
// Windows creates a junction, which needs an absolute target; elsewhere the
|
|
233
|
-
// link is relative so it names the version folder beside it.
|
|
234
|
-
const target = platform === 'win32' ? path.join(root, version) : version;
|
|
235
|
-
let current;
|
|
236
|
-
try {
|
|
237
|
-
current = fs.lstatSync(stable);
|
|
238
|
-
}
|
|
239
|
-
catch (error) {
|
|
240
|
-
if (error.code !== 'ENOENT')
|
|
241
|
-
throw error;
|
|
242
|
-
}
|
|
243
|
-
if (current && !current.isSymbolicLink())
|
|
244
|
-
throw new Error(`${stable} exists and is not a link; leaving it in place`);
|
|
245
|
-
if (current && pointsAt(stable, path.join(root, version)))
|
|
246
|
-
return stableEnginePath(pinned, home);
|
|
247
|
-
if (platform === 'win32') {
|
|
248
|
-
// A junction cannot be renamed over another. A running engine keeps its
|
|
249
|
-
// own image open, which the junction does not hold.
|
|
250
|
-
if (current) {
|
|
251
|
-
try {
|
|
252
|
-
fs.unlinkSync(stable);
|
|
253
|
-
}
|
|
254
|
-
catch {
|
|
255
|
-
fs.rmdirSync(stable);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
fs.symlinkSync(target, stable, 'junction');
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
261
|
-
const staged = path.join(root, `.${STABLE_LINK_NAME}.${process.pid}.tmp`);
|
|
262
|
-
try {
|
|
263
|
-
fs.unlinkSync(staged);
|
|
264
|
-
}
|
|
265
|
-
catch (error) {
|
|
266
|
-
if (error.code !== 'ENOENT')
|
|
267
|
-
throw error;
|
|
268
|
-
}
|
|
269
|
-
fs.symlinkSync(target, staged);
|
|
270
|
-
try {
|
|
271
|
-
fs.renameSync(staged, stable);
|
|
272
|
-
}
|
|
273
|
-
catch (error) {
|
|
274
|
-
try {
|
|
275
|
-
fs.unlinkSync(staged);
|
|
276
|
-
}
|
|
277
|
-
catch { /* already gone */ }
|
|
278
|
-
throw error;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
return stableEnginePath(pinned, home);
|
|
282
|
-
}
|
|
283
|
-
/** A real folder or file (not a link) of this user that group and others cannot write. */
|
|
284
|
-
function checkOwnedEntry(entry, kind, platform) {
|
|
285
|
-
const stat = fs.lstatSync(entry);
|
|
286
|
-
if (stat.isSymbolicLink() || (kind === 'folder' ? !stat.isDirectory() : !stat.isFile()))
|
|
287
|
-
throw new Error(`${entry} is not a ${kind}`);
|
|
288
|
-
if (typeof process.getuid === 'function' && stat.uid !== process.getuid())
|
|
289
|
-
throw new Error(`${entry} is not owned by this user`);
|
|
290
|
-
if (platform !== 'win32' && (stat.mode & 0o022) !== 0)
|
|
291
|
-
throw new Error(`${entry} is writable by group or others`);
|
|
292
|
-
}
|
|
293
|
-
/** True when the link resolves to `folder` (Windows reports junction targets in its own spelling). */
|
|
294
|
-
function pointsAt(link, folder) {
|
|
295
|
-
try {
|
|
296
|
-
return fs.realpathSync(link) === fs.realpathSync(folder);
|
|
297
|
-
}
|
|
298
|
-
catch {
|
|
299
|
-
return false;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
191
|
/** Why this home stays on shell registrations, or null when engine selection may run. */
|
|
303
192
|
export function coreNextOffReason(home, env, platform) {
|
|
304
193
|
if (platform === 'win32')
|
|
@@ -362,54 +251,6 @@ function isRunnableEngineFile(filePath, platform) {
|
|
|
362
251
|
return null;
|
|
363
252
|
}
|
|
364
253
|
}
|
|
365
|
-
/**
|
|
366
|
-
* Read `<home>/.hq/bin/hq-hook/accepted-engine.json`; null when absent,
|
|
367
|
-
* unreadable, invalid, or writable by another user.
|
|
368
|
-
*/
|
|
369
|
-
export function readAcceptedHookEngineRecord(home, platform = process.platform) {
|
|
370
|
-
const file = path.join(home, ACCEPTED_HOOK_ENGINE_RECORD);
|
|
371
|
-
let text;
|
|
372
|
-
try {
|
|
373
|
-
checkOwnedEntry(file, 'file', platform);
|
|
374
|
-
text = fs.readFileSync(file, 'utf8');
|
|
375
|
-
}
|
|
376
|
-
catch {
|
|
377
|
-
return null;
|
|
378
|
-
}
|
|
379
|
-
let doc;
|
|
380
|
-
try {
|
|
381
|
-
doc = JSON.parse(text);
|
|
382
|
-
}
|
|
383
|
-
catch {
|
|
384
|
-
return null;
|
|
385
|
-
}
|
|
386
|
-
const rec = doc;
|
|
387
|
-
if (!rec || rec.schema !== ACCEPTED_HOOK_ENGINE_SCHEMA || !rec.engines || typeof rec.engines !== 'object' || Array.isArray(rec.engines)) {
|
|
388
|
-
return null;
|
|
389
|
-
}
|
|
390
|
-
const engines = {};
|
|
391
|
-
for (const [key, raw] of Object.entries(rec.engines)) {
|
|
392
|
-
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
393
|
-
continue;
|
|
394
|
-
const entry = raw;
|
|
395
|
-
if (typeof entry.engineVersion !== 'string' || !entry.engineVersion)
|
|
396
|
-
continue;
|
|
397
|
-
if (typeof entry.pinnedEngine !== 'string' || !entry.pinnedEngine)
|
|
398
|
-
continue;
|
|
399
|
-
if (!Array.isArray(entry.hosts))
|
|
400
|
-
continue;
|
|
401
|
-
const hosts = entry.hosts.filter((h) => typeof h === 'string');
|
|
402
|
-
if (hosts.length === 0)
|
|
403
|
-
continue;
|
|
404
|
-
engines[key] = {
|
|
405
|
-
engineVersion: entry.engineVersion,
|
|
406
|
-
pinnedEngine: entry.pinnedEngine,
|
|
407
|
-
acceptedAt: typeof entry.acceptedAt === 'string' ? entry.acceptedAt : '',
|
|
408
|
-
hosts,
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
return { schema: ACCEPTED_HOOK_ENGINE_SCHEMA, engines };
|
|
412
|
-
}
|
|
413
254
|
/**
|
|
414
255
|
* Record `pinned` (`engineVersion`) as canary-accepted for `hosts` after
|
|
415
256
|
* committing `<home>/.hq/bin/hq-hook/stable`. Merges `hosts` when the same
|
|
@@ -510,16 +351,32 @@ export function existingAcceptedStableHookEngine(home, options) {
|
|
|
510
351
|
* Windows), regardless of `core.next`. When the npm engine package is gone,
|
|
511
352
|
* reuses an existing runnable `stable` or relinks `stable` from an already-
|
|
512
353
|
* pinned copy of this CLI's version under `<home>/.hq/bin/hq-hook/<version>`.
|
|
513
|
-
*
|
|
354
|
+
* When `stable` names a newer engine that still runs, it is kept and returned
|
|
355
|
+
* (the link never moves back on its own). Returns null when no usable engine
|
|
356
|
+
* exists on disk.
|
|
514
357
|
*/
|
|
515
358
|
export function ensureStableHookEngine(home, options = {}) {
|
|
516
359
|
const platform = options.platform ?? process.platform;
|
|
517
360
|
const installed = installHookEngine(options.lookup ? { ...options.lookup, home, platform } : { home, platform });
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
361
|
+
// `stable` naming a newer engine that still runs (this CLI was downgraded on
|
|
362
|
+
// purpose, or an older one is running): keep using that engine.
|
|
363
|
+
const linkOrKeepNewer = (engine) => {
|
|
364
|
+
try {
|
|
365
|
+
const stable = linkStableEngine(engine, home, platform);
|
|
366
|
+
checkStableEngine(stable, engine);
|
|
367
|
+
return stable;
|
|
368
|
+
}
|
|
369
|
+
catch (error) {
|
|
370
|
+
if (!(error instanceof StableDowngradeRefused))
|
|
371
|
+
throw error;
|
|
372
|
+
const existing = existingStableHookEngine(home, { platform });
|
|
373
|
+
if (!existing)
|
|
374
|
+
throw error;
|
|
375
|
+
return existing;
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
if (installed)
|
|
379
|
+
return linkOrKeepNewer(installed);
|
|
523
380
|
const existing = existingStableHookEngine(home, { platform });
|
|
524
381
|
if (existing)
|
|
525
382
|
return existing;
|
|
@@ -531,9 +388,7 @@ export function ensureStableHookEngine(home, options = {}) {
|
|
|
531
388
|
for (const candidate of engineBinaryCandidates(pinnedDir, platform)) {
|
|
532
389
|
if (!isRunnableEngineFile(candidate, platform))
|
|
533
390
|
continue;
|
|
534
|
-
|
|
535
|
-
checkStableEngine(stable, candidate);
|
|
536
|
-
return stable;
|
|
391
|
+
return linkOrKeepNewer(candidate);
|
|
537
392
|
}
|
|
538
393
|
}
|
|
539
394
|
return null;
|
|
@@ -637,20 +492,30 @@ export function coreNextTarget(home, env = process.env, options = {}) {
|
|
|
637
492
|
probe: options.probe,
|
|
638
493
|
deferLink: options.deferLink,
|
|
639
494
|
});
|
|
640
|
-
const
|
|
495
|
+
const passedCanaryHosts = new Set();
|
|
496
|
+
const target = coreNextTargetFor(home, env, stable, caps, platform, options.warn, (host) => {
|
|
497
|
+
passedCanaryHosts.add(host);
|
|
498
|
+
});
|
|
641
499
|
if (!target)
|
|
642
500
|
return null;
|
|
501
|
+
const recordAccepted = (acceptedHosts) => {
|
|
502
|
+
if (!acceptedHosts || acceptedHosts.length === 0 || canaryGateSkipped(env))
|
|
503
|
+
return;
|
|
504
|
+
const verified = acceptedHosts.filter((host) => CANARY_HOSTS.includes(host) && passedCanaryHosts.has(host));
|
|
505
|
+
if (verified.length === 0)
|
|
506
|
+
return;
|
|
507
|
+
recordAcceptedHookEngine(home, pinned, caps.version, verified, platform);
|
|
508
|
+
};
|
|
643
509
|
coreNextCandidates.set(target, {
|
|
644
510
|
pinnedEngine: pinned,
|
|
645
511
|
engineVersion: caps.version,
|
|
512
|
+
recordAccepted,
|
|
646
513
|
...(options.deferLink
|
|
647
514
|
? {
|
|
648
515
|
commitStable: (acceptedHosts) => {
|
|
649
516
|
const linked = linkStableEngine(pinned, home, platform);
|
|
650
517
|
checkStableEngine(linked, pinned);
|
|
651
|
-
|
|
652
|
-
recordAcceptedHookEngine(home, pinned, caps.version, acceptedHosts, platform);
|
|
653
|
-
}
|
|
518
|
+
recordAccepted(acceptedHosts);
|
|
654
519
|
return linked;
|
|
655
520
|
},
|
|
656
521
|
}
|
|
@@ -664,7 +529,7 @@ export function coreNextTarget(home, env = process.env, options = {}) {
|
|
|
664
529
|
* capable event. [`coreNextTarget`] builds its target here, and `hq doctor`
|
|
665
530
|
* uses it to ask the same questions without installing anything.
|
|
666
531
|
*/
|
|
667
|
-
export function coreNextTargetFor(home, env, stable, caps, platform = process.platform, warn) {
|
|
532
|
+
export function coreNextTargetFor(home, env, stable, caps, platform = process.platform, warn, onCanaryPassed) {
|
|
668
533
|
const events = capableEvents(caps);
|
|
669
534
|
if (!events.length)
|
|
670
535
|
return null;
|
|
@@ -673,7 +538,7 @@ export function coreNextTargetFor(home, env, stable, caps, platform = process.pl
|
|
|
673
538
|
events,
|
|
674
539
|
covers: caps.covers ?? {},
|
|
675
540
|
...(caps.registrationHosts ? { registrationHosts: caps.registrationHosts } : {}),
|
|
676
|
-
canary: hostCanaryGate(home, env, caps.version, platform, warn),
|
|
541
|
+
canary: hostCanaryGate(home, env, caps.version, platform, warn, onCanaryPassed),
|
|
677
542
|
}, env);
|
|
678
543
|
}
|
|
679
544
|
const warned = new Set();
|
|
@@ -721,7 +586,7 @@ function appendStrictCanaryLog(home, root, host, version, reason, strict) {
|
|
|
721
586
|
// Best-effort engine log; the stderr error still surfaces the failure.
|
|
722
587
|
}
|
|
723
588
|
}
|
|
724
|
-
function hostCanaryGate(home, env, version, platform, warn) {
|
|
589
|
+
function hostCanaryGate(home, env, version, platform, warn, onCanaryPassed) {
|
|
725
590
|
const strictLogged = new Set();
|
|
726
591
|
const logStrictOnce = (root, host, reason, strict) => {
|
|
727
592
|
const key = `${root}\0${host}`;
|
|
@@ -752,6 +617,8 @@ function hostCanaryGate(home, env, version, platform, warn) {
|
|
|
752
617
|
: `hq: warning: a reindex started by a hook keeps the old hook registrations on ${host}: it never changes a host's core. Run hq reindex to switch ${host} to the new core (hq-hook ${version})`, warn);
|
|
753
618
|
}
|
|
754
619
|
}
|
|
620
|
+
if (current && gate.allowed && !gate.skipped)
|
|
621
|
+
onCanaryPassed?.(host);
|
|
755
622
|
return current;
|
|
756
623
|
}
|
|
757
624
|
if (gate.skipped) {
|
|
@@ -765,6 +632,9 @@ function hostCanaryGate(home, env, version, platform, warn) {
|
|
|
765
632
|
}
|
|
766
633
|
warnOnce(`hq: warning: flag ${CORE_NEXT_FLAG} is on, but ${host} has no passing host canary for hq-hook ${version} and this HQ root (${gate.reason}); keeping the old hook registrations on ${host}. Run scripts/host-canary.mjs --host ${host}, or bypass the gate with hq reindex --skip-host-canary-gate`, warn);
|
|
767
634
|
}
|
|
635
|
+
else {
|
|
636
|
+
onCanaryPassed?.(host);
|
|
637
|
+
}
|
|
768
638
|
return gate.allowed;
|
|
769
639
|
};
|
|
770
640
|
}
|
|
@@ -49,7 +49,33 @@ export interface VersionCheckResponse {
|
|
|
49
49
|
updateCommand?: string;
|
|
50
50
|
downloadUrl?: string;
|
|
51
51
|
message?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Optional (decision 3.2): exact releases the server has pulled. A running
|
|
54
|
+
* version in this list is treated like one below `minVersion`. Servers that
|
|
55
|
+
* do not send it keep today's behavior.
|
|
56
|
+
*/
|
|
57
|
+
blockedVersions?: string[];
|
|
58
|
+
/**
|
|
59
|
+
* Optional: the release a blocked version is moved to. Without it the forced
|
|
60
|
+
* update installs `@latest`, as today. Ignored when the running version is not
|
|
61
|
+
* blocked, so the `minVersion` path is unchanged.
|
|
62
|
+
*/
|
|
63
|
+
targetVersion?: string;
|
|
64
|
+
/** Set by {@link applyBlockedVersions}, never by the server. */
|
|
65
|
+
blocked?: boolean;
|
|
66
|
+
/** Set by {@link applyBlockedVersions}: the exact version the forced update installs. */
|
|
67
|
+
pinnedVersion?: string;
|
|
52
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Apply the optional `blockedVersions` / `targetVersion` fields. Returns the
|
|
71
|
+
* decision unchanged unless `current` is in a well-formed blocklist; then the
|
|
72
|
+
* update is required, and a valid `targetVersion` that is neither `current`
|
|
73
|
+
* nor itself blocked becomes the exact version to install (and the target the
|
|
74
|
+
* messages and convergence check use). Malformed fields are ignored.
|
|
75
|
+
*/
|
|
76
|
+
export declare function applyBlockedVersions(decision: VersionCheckResponse, current?: string): VersionCheckResponse;
|
|
77
|
+
/** Whether `version` is in the response's well-formed `blockedVersions` list. */
|
|
78
|
+
export declare function isBlockedVersion(decision: Pick<VersionCheckResponse, "blockedVersions">, version: string): boolean;
|
|
53
79
|
/**
|
|
54
80
|
* Environment for every package-manager child an update starts.
|
|
55
81
|
*
|
|
@@ -245,13 +271,13 @@ export declare function derivePnpmHome(install: RunningInstall): string | null;
|
|
|
245
271
|
* environment already has the required values.
|
|
246
272
|
*/
|
|
247
273
|
export declare function pnpmUpdateEnv(install: RunningInstall, base?: NodeJS.ProcessEnv): NodeJS.ProcessEnv | undefined;
|
|
248
|
-
export declare function buildPrefixedInstallArgv(prefix: string): string[];
|
|
274
|
+
export declare function buildPrefixedInstallArgv(prefix: string, spec?: string): string[];
|
|
249
275
|
/**
|
|
250
276
|
* Argv for updating a pnpm-managed global install. `pnpm add -g` rewrites the
|
|
251
277
|
* PATH shim as part of the install, so the next invocation genuinely resolves
|
|
252
278
|
* the new version — which is the whole point of routing here instead of npm.
|
|
253
279
|
*/
|
|
254
|
-
export declare function buildPnpmInstallArgv(install?: RunningInstall): string[];
|
|
280
|
+
export declare function buildPnpmInstallArgv(install?: RunningInstall, spec?: string): string[];
|
|
255
281
|
/**
|
|
256
282
|
* Read the pnpm global install's current store and virtual-store locations.
|
|
257
283
|
* Newer pnpm versions can change both defaults, so a self-update must carry
|
|
@@ -270,9 +296,9 @@ export declare function pnpmInstalledVersion(install: RunningInstall): string |
|
|
|
270
296
|
*/
|
|
271
297
|
export declare function probePnpmVersion(cmd: string, args: string[], env: NodeJS.ProcessEnv, cwd: string): string | null;
|
|
272
298
|
/** Run the install-owned pnpm first; use PATH only if that version cannot run. */
|
|
273
|
-
export declare function performPnpmUpdate(install: RunningInstall, runner?: UpdateRunner, env?: NodeJS.ProcessEnv, probe?: typeof probePnpmVersion): UpdateResult;
|
|
299
|
+
export declare function performPnpmUpdate(install: RunningInstall, runner?: UpdateRunner, env?: NodeJS.ProcessEnv, probe?: typeof probePnpmVersion, spec?: string): UpdateResult;
|
|
274
300
|
/** Argv for updating a Bun-managed global install. */
|
|
275
|
-
export declare function buildBunInstallArgv(): string[];
|
|
301
|
+
export declare function buildBunInstallArgv(spec?: string): string[];
|
|
276
302
|
/**
|
|
277
303
|
* Filesystem surface used by {@link cleanStalePartialInstall}. Injected so the
|
|
278
304
|
* cleanup logic is unit-testable without touching a real global prefix.
|
|
@@ -410,6 +436,16 @@ export declare function runSupervisedUpdateCommand(cmd: string, args: string[],
|
|
|
410
436
|
export declare function runUpdateCommand(cmd: string, args: string[], env?: NodeJS.ProcessEnv, cwd?: string): UpdateResult;
|
|
411
437
|
declare function performUpdateCommand(cmd: string, args: string[], runner?: UpdateRunner, env?: NodeJS.ProcessEnv, cwd?: string): UpdateResult;
|
|
412
438
|
declare function performUpdate(command: string, runner?: UpdateRunner): UpdateResult;
|
|
439
|
+
/**
|
|
440
|
+
* The command a user should run by hand for this install layout. hq-pro's
|
|
441
|
+
* `updateCommand` is npm-shaped for every client, so a pnpm-managed install
|
|
442
|
+
* must never be told to run it: `npm install -g …` drops a fresh copy under the
|
|
443
|
+
* npm global prefix while pnpm's PATH shim keeps resolving the old build. That
|
|
444
|
+
* is verbatim the reported symptom (a stale shim still reporting 5.61.0 after a
|
|
445
|
+
* "successful" update), so both the hard gate and the soft nudge below have to
|
|
446
|
+
* speak the running manager's language.
|
|
447
|
+
*/
|
|
448
|
+
declare function manualUpdateCommand(install: RunningInstall, decision: VersionCheckResponse): string | undefined;
|
|
413
449
|
/**
|
|
414
450
|
* Soft notify when the server says we're below `latestVersion` but still ≥
|
|
415
451
|
* `minVersion`. Single chalk-yellow line on stderr; never blocks.
|
|
@@ -557,6 +593,8 @@ export declare function enforceVersionGate(onUpdateRecommended?: (decision: Vers
|
|
|
557
593
|
export declare function shouldSkipGate(argv: readonly string[]): boolean;
|
|
558
594
|
export declare const __test__: {
|
|
559
595
|
CLIENT_ID: string;
|
|
596
|
+
applyBlockedVersions: typeof applyBlockedVersions;
|
|
597
|
+
manualUpdateCommand: typeof manualUpdateCommand;
|
|
560
598
|
getVersionGatePhase: typeof getVersionGatePhase;
|
|
561
599
|
CONVERGENCE_TIMEOUT_MS: number;
|
|
562
600
|
DEFAULT_UPDATE_TIMEOUT_MS: number;
|
|
@@ -58,6 +58,50 @@ let currentVersionGatePhase = "unknown";
|
|
|
58
58
|
export function getVersionGatePhase() {
|
|
59
59
|
return currentVersionGatePhase;
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Apply the optional `blockedVersions` / `targetVersion` fields. Returns the
|
|
63
|
+
* decision unchanged unless `current` is in a well-formed blocklist; then the
|
|
64
|
+
* update is required, and a valid `targetVersion` that is neither `current`
|
|
65
|
+
* nor itself blocked becomes the exact version to install (and the target the
|
|
66
|
+
* messages and convergence check use). Malformed fields are ignored.
|
|
67
|
+
*/
|
|
68
|
+
export function applyBlockedVersions(decision, current = CLI_VERSION) {
|
|
69
|
+
const running = semver.valid(current);
|
|
70
|
+
if (!running || !Array.isArray(decision.blockedVersions))
|
|
71
|
+
return decision;
|
|
72
|
+
const blocked = decision.blockedVersions
|
|
73
|
+
.filter((v) => typeof v === "string")
|
|
74
|
+
.map((v) => semver.valid(v.trim()))
|
|
75
|
+
.filter((v) => v !== null);
|
|
76
|
+
if (!blocked.includes(running))
|
|
77
|
+
return decision;
|
|
78
|
+
const target = typeof decision.targetVersion === "string" ? semver.valid(decision.targetVersion.trim()) : null;
|
|
79
|
+
const pinned = target && target !== running && !blocked.includes(target) ? target : undefined;
|
|
80
|
+
return {
|
|
81
|
+
...decision,
|
|
82
|
+
updateRequired: true,
|
|
83
|
+
blocked: true,
|
|
84
|
+
...(pinned ? { pinnedVersion: pinned, latestVersion: pinned } : {}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** Whether `version` is in the response's well-formed `blockedVersions` list. */
|
|
88
|
+
export function isBlockedVersion(decision, version) {
|
|
89
|
+
const wanted = semver.valid(version);
|
|
90
|
+
if (!wanted || !Array.isArray(decision.blockedVersions))
|
|
91
|
+
return false;
|
|
92
|
+
return decision.blockedVersions.some((v) => typeof v === "string" && semver.valid(v.trim()) === wanted);
|
|
93
|
+
}
|
|
94
|
+
/** The package spec a required update installs: the pin when there is one, else `@latest`. */
|
|
95
|
+
function installSpec(decision) {
|
|
96
|
+
return decision.pinnedVersion ? `${CLI_NAME}@${decision.pinnedVersion}` : LATEST_PACKAGE_SPEC;
|
|
97
|
+
}
|
|
98
|
+
/** The server's bare npm command, with `@latest` swapped for the pin when there is one. */
|
|
99
|
+
function serverUpdateCommand(decision) {
|
|
100
|
+
const command = decision.updateCommand;
|
|
101
|
+
if (!command || !decision.pinnedVersion)
|
|
102
|
+
return command;
|
|
103
|
+
return command.split(/(\s+)/).map((part) => (part === LATEST_PACKAGE_SPEC ? installSpec(decision) : part)).join("");
|
|
104
|
+
}
|
|
61
105
|
function isOptedOut() {
|
|
62
106
|
// A process started by an update (re-exec, package-manager lifecycle script)
|
|
63
107
|
// carries the recursion guard and must never start another install.
|
|
@@ -750,16 +794,16 @@ export function pnpmUpdateEnv(install, base = process.env) {
|
|
|
750
794
|
result[pathKey] = [currentPath, binDir].filter(Boolean).join(path.delimiter);
|
|
751
795
|
return Object.keys(result).some((key) => result[key] !== base[key]) ? result : undefined;
|
|
752
796
|
}
|
|
753
|
-
export function buildPrefixedInstallArgv(prefix) {
|
|
754
|
-
return npmGlobalInstallArgv(
|
|
797
|
+
export function buildPrefixedInstallArgv(prefix, spec = LATEST_PACKAGE_SPEC) {
|
|
798
|
+
return npmGlobalInstallArgv(spec, { prefix });
|
|
755
799
|
}
|
|
756
800
|
/**
|
|
757
801
|
* Argv for updating a pnpm-managed global install. `pnpm add -g` rewrites the
|
|
758
802
|
* PATH shim as part of the install, so the next invocation genuinely resolves
|
|
759
803
|
* the new version — which is the whole point of routing here instead of npm.
|
|
760
804
|
*/
|
|
761
|
-
export function buildPnpmInstallArgv(install) {
|
|
762
|
-
const args = ["add", "-g",
|
|
805
|
+
export function buildPnpmInstallArgv(install, spec = LATEST_PACKAGE_SPEC) {
|
|
806
|
+
const args = ["add", "-g", spec, PNPM_FIRST_PARTY_RELEASE_AGE_EXCLUDE];
|
|
763
807
|
const dirs = install ? pnpmInstallDirs(install) : null;
|
|
764
808
|
if (dirs) {
|
|
765
809
|
args.push("--global-dir", dirs.globalDir, "--store-dir", dirs.storeDir);
|
|
@@ -865,7 +909,7 @@ export function probePnpmVersion(cmd, args, env, cwd) {
|
|
|
865
909
|
}
|
|
866
910
|
}
|
|
867
911
|
/** Run the install-owned pnpm first; use PATH only if that version cannot run. */
|
|
868
|
-
export function performPnpmUpdate(install, runner = runUpdateCommand, env = process.env, probe = probePnpmVersion) {
|
|
912
|
+
export function performPnpmUpdate(install, runner = runUpdateCommand, env = process.env, probe = probePnpmVersion, spec = LATEST_PACKAGE_SPEC) {
|
|
869
913
|
const cwd = mkdtempSync(path.join(os.tmpdir(), "hq-cli-pnpm-update-"));
|
|
870
914
|
const updateEnv = {
|
|
871
915
|
...packageManagerChildEnv(env),
|
|
@@ -877,7 +921,7 @@ export function performPnpmUpdate(install, runner = runUpdateCommand, env = proc
|
|
|
877
921
|
if (installedVersion) {
|
|
878
922
|
const command = `pnpm@${installedVersion}`;
|
|
879
923
|
if (probe("corepack", [command, "--version"], updateEnv, cwd) === installedVersion) {
|
|
880
|
-
return runner("corepack", [command, ...buildPnpmInstallArgv(install)], updateEnv, cwd);
|
|
924
|
+
return runner("corepack", [command, ...buildPnpmInstallArgv(install, spec)], updateEnv, cwd);
|
|
881
925
|
}
|
|
882
926
|
}
|
|
883
927
|
const fallbackVersion = probe("pnpm", ["--version"], updateEnv, cwd);
|
|
@@ -887,7 +931,7 @@ export function performPnpmUpdate(install, runner = runUpdateCommand, env = proc
|
|
|
887
931
|
// pnpm 10.28.1 and earlier reject --virtual-store-dir with -g. Keep the
|
|
888
932
|
// existing global directory and store, but omit only that unsupported flag.
|
|
889
933
|
const supportsGlobalVirtualStoreDir = semver.gte(fallbackVersion, "11.0.0");
|
|
890
|
-
const args = buildPnpmInstallArgv(install);
|
|
934
|
+
const args = buildPnpmInstallArgv(install, spec);
|
|
891
935
|
if (!supportsGlobalVirtualStoreDir) {
|
|
892
936
|
const index = args.indexOf("--virtual-store-dir");
|
|
893
937
|
if (index !== -1)
|
|
@@ -900,8 +944,8 @@ export function performPnpmUpdate(install, runner = runUpdateCommand, env = proc
|
|
|
900
944
|
}
|
|
901
945
|
}
|
|
902
946
|
/** Argv for updating a Bun-managed global install. */
|
|
903
|
-
export function buildBunInstallArgv() {
|
|
904
|
-
return ["add", "-g",
|
|
947
|
+
export function buildBunInstallArgv(spec = LATEST_PACKAGE_SPEC) {
|
|
948
|
+
return ["add", "-g", spec];
|
|
905
949
|
}
|
|
906
950
|
const nodeStaleInstallFs = {
|
|
907
951
|
readdirSync: (dir) => readdirSync(dir),
|
|
@@ -1016,7 +1060,7 @@ async function fetchVersionDecision(timeoutMs = FETCH_TIMEOUT_MS) {
|
|
|
1016
1060
|
typeof body.updateRequired !== "boolean") {
|
|
1017
1061
|
return null;
|
|
1018
1062
|
}
|
|
1019
|
-
return body;
|
|
1063
|
+
return applyBlockedVersions(body);
|
|
1020
1064
|
}
|
|
1021
1065
|
catch {
|
|
1022
1066
|
return null;
|
|
@@ -1386,18 +1430,19 @@ function performUpdate(command, runner = runUpdateCommand) {
|
|
|
1386
1430
|
* speak the running manager's language.
|
|
1387
1431
|
*/
|
|
1388
1432
|
function manualUpdateCommand(install, decision) {
|
|
1433
|
+
const spec = installSpec(decision);
|
|
1389
1434
|
if (install.manager === "pnpm") {
|
|
1390
1435
|
const version = pnpmInstalledVersion(install);
|
|
1391
1436
|
const plan = version
|
|
1392
|
-
? `corepack pnpm@${version} ${buildPnpmInstallArgv(install).join(" ")}`
|
|
1393
|
-
: `pnpm ${buildPnpmInstallArgv(install).join(" ")}`;
|
|
1437
|
+
? `corepack pnpm@${version} ${buildPnpmInstallArgv(install, spec).join(" ")}`
|
|
1438
|
+
: `pnpm ${buildPnpmInstallArgv(install, spec).join(" ")}`;
|
|
1394
1439
|
return plan;
|
|
1395
1440
|
}
|
|
1396
1441
|
if (install.manager === "bun")
|
|
1397
|
-
return `bun ${buildBunInstallArgv().join(" ")}`;
|
|
1442
|
+
return `bun ${buildBunInstallArgv(spec).join(" ")}`;
|
|
1398
1443
|
if (install.prefix)
|
|
1399
|
-
return `npm ${buildPrefixedInstallArgv(install.prefix).join(" ")}`;
|
|
1400
|
-
return decision
|
|
1444
|
+
return `npm ${buildPrefixedInstallArgv(install.prefix, spec).join(" ")}`;
|
|
1445
|
+
return serverUpdateCommand(decision);
|
|
1401
1446
|
}
|
|
1402
1447
|
/**
|
|
1403
1448
|
* Soft notify when the server says we're below `latestVersion` but still ≥
|
|
@@ -1738,6 +1783,10 @@ function execNewerGlobalHq(decision, install, deps) {
|
|
|
1738
1783
|
const version = probe(candidate);
|
|
1739
1784
|
if (!version || !semver.valid(version))
|
|
1740
1785
|
continue;
|
|
1786
|
+
if (isBlockedVersion(decision, version)) {
|
|
1787
|
+
console.error(chalk.dim(` Global ${candidate} is ${version}, also blocked; not using it.`));
|
|
1788
|
+
continue;
|
|
1789
|
+
}
|
|
1741
1790
|
if (!semver.gte(version, decision.minVersion) || !isNewerVersion(version, CLI_VERSION)) {
|
|
1742
1791
|
console.error(chalk.dim(` Global ${candidate} is ${version}, also below ${decision.minVersion}; not using it.`));
|
|
1743
1792
|
continue;
|
|
@@ -1774,11 +1823,13 @@ function execNewerGlobalHq(decision, install, deps) {
|
|
|
1774
1823
|
*/
|
|
1775
1824
|
function enforceUpdateRequired(decision, deps = {}) {
|
|
1776
1825
|
currentVersionGatePhase = "preflight";
|
|
1777
|
-
const banner = chalk.red.bold(
|
|
1826
|
+
const banner = chalk.red.bold(decision.blocked
|
|
1827
|
+
? `✗ hq-cli ${CLI_VERSION} has been withdrawn and must be replaced${decision.pinnedVersion ? ` with ${decision.pinnedVersion}` : ""}.`
|
|
1828
|
+
: `✗ hq-cli ${CLI_VERSION} is below the minimum required version (${decision.minVersion}).`);
|
|
1778
1829
|
console.error(banner);
|
|
1779
1830
|
if (decision.message)
|
|
1780
1831
|
console.error(chalk.dim(` ${decision.message}`));
|
|
1781
|
-
const command = decision
|
|
1832
|
+
const command = serverUpdateCommand(decision);
|
|
1782
1833
|
// ONE package-root walk decides both the manager and the prefix. A
|
|
1783
1834
|
// A pnpm- or Bun-managed install must be updated by its owning manager; the
|
|
1784
1835
|
// server's `updateCommand` and any npm prefix are wrong for those layouts, so
|
|
@@ -1806,7 +1857,10 @@ function enforceUpdateRequired(decision, deps = {}) {
|
|
|
1806
1857
|
// stale dist-tag, a bad cache, a misconfigured pin), reinstalling it on every
|
|
1807
1858
|
// invocation and announcing success each time is strictly worse than saying
|
|
1808
1859
|
// so once.
|
|
1809
|
-
|
|
1860
|
+
// A pinned target for a blocked release may be older (moving off a bad
|
|
1861
|
+
// latest); applyBlockedVersions already refused a pin equal to the running
|
|
1862
|
+
// version, so it converges.
|
|
1863
|
+
if (!decision.pinnedVersion && !isNewerVersion(decision.latestVersion, CLI_VERSION)) {
|
|
1810
1864
|
console.error(chalk.red(` Refusing to update: the offered version ${decision.latestVersion} is not newer than the running ${CLI_VERSION}.`));
|
|
1811
1865
|
console.error(chalk.dim(" This is a server-side or registry problem, not a local one — reinstalling would loop without ever converging."));
|
|
1812
1866
|
process.exit(75);
|
|
@@ -1872,7 +1926,7 @@ function enforceUpdateRequired(decision, deps = {}) {
|
|
|
1872
1926
|
* (EX_TEMPFAIL) on failure.
|
|
1873
1927
|
*/
|
|
1874
1928
|
function attemptRequiredUpdate(decision, deps, install) {
|
|
1875
|
-
const command = decision
|
|
1929
|
+
const command = serverUpdateCommand(decision);
|
|
1876
1930
|
const isManagedOutsideNpm = install.manager !== "npm";
|
|
1877
1931
|
const prefix = install.prefix;
|
|
1878
1932
|
// Any npm global install with a known prefix must build away from the live package.
|
|
@@ -1883,17 +1937,18 @@ function attemptRequiredUpdate(decision, deps, install) {
|
|
|
1883
1937
|
// the EXACT same command under elevation.
|
|
1884
1938
|
let primaryCmd;
|
|
1885
1939
|
let primaryArgs;
|
|
1940
|
+
const spec = installSpec(decision);
|
|
1886
1941
|
if (install.manager === "pnpm") {
|
|
1887
1942
|
primaryCmd = "pnpm";
|
|
1888
|
-
primaryArgs = buildPnpmInstallArgv(install);
|
|
1943
|
+
primaryArgs = buildPnpmInstallArgv(install, spec);
|
|
1889
1944
|
}
|
|
1890
1945
|
else if (install.manager === "bun") {
|
|
1891
1946
|
primaryCmd = "bun";
|
|
1892
|
-
primaryArgs = buildBunInstallArgv();
|
|
1947
|
+
primaryArgs = buildBunInstallArgv(spec);
|
|
1893
1948
|
}
|
|
1894
1949
|
else if (prefix) {
|
|
1895
1950
|
primaryCmd = "npm";
|
|
1896
|
-
primaryArgs = buildPrefixedInstallArgv(prefix);
|
|
1951
|
+
primaryArgs = buildPrefixedInstallArgv(prefix, spec);
|
|
1897
1952
|
}
|
|
1898
1953
|
else {
|
|
1899
1954
|
const parts = (command ?? "").split(/\s+/).filter(Boolean);
|
|
@@ -1913,7 +1968,7 @@ function attemptRequiredUpdate(decision, deps, install) {
|
|
|
1913
1968
|
console.error(chalk.dim(` Detected a ${install.manager}-managed global install; updating with ${install.manager}`));
|
|
1914
1969
|
console.error(chalk.dim(` Running: ${primaryCmd} ${primaryArgs.join(" ")}`));
|
|
1915
1970
|
result = install.manager === "pnpm"
|
|
1916
|
-
? performPnpmUpdate(install, runner, updateEnv ?? process.env, deps.probePnpmVersion)
|
|
1971
|
+
? performPnpmUpdate(install, runner, updateEnv ?? process.env, deps.probePnpmVersion, spec)
|
|
1917
1972
|
: performUpdateCommand(primaryCmd, primaryArgs, runner, updateEnv);
|
|
1918
1973
|
}
|
|
1919
1974
|
else if (prefix) {
|
|
@@ -1925,7 +1980,7 @@ function attemptRequiredUpdate(decision, deps, install) {
|
|
|
1925
1980
|
result = { ok: false, detail: "staged npm installer was not loaded" };
|
|
1926
1981
|
}
|
|
1927
1982
|
else {
|
|
1928
|
-
result = installStaged(prefix,
|
|
1983
|
+
result = installStaged(prefix, spec, runner);
|
|
1929
1984
|
}
|
|
1930
1985
|
}
|
|
1931
1986
|
else {
|
|
@@ -2038,7 +2093,9 @@ function attemptRequiredUpdate(decision, deps, install) {
|
|
|
2038
2093
|
// it is rather than as a success the caller will keep retrying — see
|
|
2039
2094
|
// checkUpdateConvergence.
|
|
2040
2095
|
currentVersionGatePhase = "verifying";
|
|
2041
|
-
|
|
2096
|
+
// A pin must land exactly: a newer build on PATH may be the withdrawn one.
|
|
2097
|
+
const converged = (deps.checkConvergence ??
|
|
2098
|
+
((target) => checkUpdateConvergence(target, decision.pinnedVersion ? { exactVersion: true } : {})))(decision.latestVersion);
|
|
2042
2099
|
if (converged === false) {
|
|
2043
2100
|
currentVersionGatePhase = "failed";
|
|
2044
2101
|
console.error(chalk.red(`✗ Update did not take effect: \`hq\` on PATH still resolves a different build than ${decision.latestVersion}.`));
|
|
@@ -2103,6 +2160,8 @@ export function shouldSkipGate(argv) {
|
|
|
2103
2160
|
}
|
|
2104
2161
|
export const __test__ = {
|
|
2105
2162
|
CLIENT_ID,
|
|
2163
|
+
applyBlockedVersions,
|
|
2164
|
+
manualUpdateCommand,
|
|
2106
2165
|
getVersionGatePhase,
|
|
2107
2166
|
CONVERGENCE_TIMEOUT_MS,
|
|
2108
2167
|
DEFAULT_UPDATE_TIMEOUT_MS,
|