@indigoai-us/hq-cli 5.345.268 → 5.345.269

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 CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [5.345.269] — 2026-11-29
6
+ - Shard `.github/workflows/hq-hook.yml` self-hosted Windows (`matrix.beaker`) `Unit and pipe tests` across 6 parallel `hq-windows` runners using a prebuilt `cargo nextest` archive (`windows-build-archive` + `windows-test-shard`), cutting release-tag Windows test wall time while preserving full target parity and all `build` job release duties.
7
+ - Run the hq-hook Windows baseline shard and join jobs on the AWS Windows runners: they no longer ask for the `beaker` label, so they use the same `self-hosted, Windows, X64, hq-windows` label set as the PR and train Windows jobs they are compared with.
8
+ - Fixed: Allow Antigravity's `schedule` timer/cron tool in `hq-hook` PreToolUse with exact argument key validation (`DurationSeconds`, `CronExpression`, `Prompt`, `TimerCondition`, `IsDaemon`, `ExactTiming`, `MaxIterations`) so Antigravity sessions can run polling loops without being refused fail-closed.
9
+ - Read permission-fallback flag snapshot directories via the caller's environment lookup (`TMPDIR` / `LOCALAPPDATA`) so scoped readers and unit tests do not inherit host temporary snapshot files.
10
+ - Fixed: `hq-hook` command rules now scan here-document bodies when a here-document is piped into another command such as `cat <<'EOF' | python3`, matching the shell hook's handling of piped here-documents.
11
+ - Native UserPromptSubmit `/skill` handling now has tests that run every accepted `hook-lib.sh` revision, including the released hq-core 16.0.52 library, against the shell hook. When the native check cannot decide, the refusal now gives the check's reason and the matching remedy (update the HQ CLI, or `/hq-bug`) instead of asking you to start hqd.
12
+ - Internal: Wait up to 10 s for WMI `Win32_ProcessStartTrace` ETW delivery in `crates/hq-hook/tests/windows/GuiProbe.cs` across positive controls and phase completions, and include `SessionId` and non-baseline Toolhelp snapshots in failure diagnostics.
13
+ - The hook engine now records a panic as one fixed-format line in `~/.hq/logs/hook-engine.jsonl` (location, a message class and versions; no payload or argument values), and the daemon sends each new line within minutes as a `hook_engine_crash` event under the existing telemetry consent and `HQ_TELEMETRY=0` opt-out. Hook answers and exit codes are unchanged.
14
+ - The version gate accepts two optional server fields: `blockedVersions`, which forces an update off a withdrawn release, and `targetVersion`, the exact release that update installs. Servers that do not send them behave as before.
15
+ - Changed: the host canary record shipped with the CLI is refreshed for the 5.345.269 release build.
16
+ - Cap concurrent child-hook spawns in `agents_v2_company_folder_hooks` tests and use bash builtins in 1-second timeout fixtures so parallel runs do not contend on macOS process startup.
17
+
5
18
  ## [5.345.268] — 2026-11-29
6
19
  - Isolate `SCCACHE_SERVER_PORT` and local `SCCACHE_DIR` per runner (`beaker` -> port `4226` / `hq-sccache/beaker`, `beaker-2` -> port `4227` / `hq-sccache/beaker-2`) in all Beaker `Configure sccache (Beaker)` workflow steps so concurrent `beaker` and `beaker-2` jobs on the same Windows host do not collide on `127.0.0.1:4226` or share a local cache directory.
7
20
  - Speed up hq-hook builds on the Beaker Windows runners: the release-tag Windows job builds in the workspace target folder again instead of a per-runner folder outside the checkout, and the release-tag, train build-archive and train Clippy jobs on Beaker use the machine-local compiler cache instead of the shared S3 cache, which those jobs could only read and which held no Beaker builds.
package/README.md CHANGED
@@ -159,6 +159,18 @@ is about to send its fields prints this line once instead, and records it under
159
159
  HQ sends a usage event when you run a signed-in command (CLI version and a timestamp; when enabled, first-sync guidance shown or followed and the flag key cli.first-sync-next-step; never command names, file contents, or secrets) to improve the CLI. Set HQ_TELEMETRY=0 to turn this off.
160
160
  ```
161
161
 
162
+ The `hq daemon` also sends `hook_engine_crash` when the native hook engine
163
+ panics. The engine writes one line per panic to `~/.hq/logs/hook-engine.jsonl`;
164
+ the daemon checks for new lines every five minutes and sends each once, at most
165
+ 12 per hour (the number held back rides on the next event as
166
+ `properties.suppressed`). Each event carries `properties.crashId`, `signature`
167
+ (a hash of location and class), `location` (`file:line` in the engine source),
168
+ `messageClass` (a fixed set such as `unwrap-none`), `appVersion`, `engine`,
169
+ `release`, `os` and `arch`. It never carries the panic message, payloads,
170
+ arguments or paths outside the engine source. It is sent only when you have
171
+ opted in to telemetry (agents always collect), and never while `HQ_TELEMETRY=0`
172
+ is set; crashes from those periods are not sent later.
173
+
162
174
  Turn telemetry off:
163
175
 
164
176
  ```bash
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "schema": "hq.host-canary-release.v1",
3
- "cliVersion": "5.345.268",
3
+ "cliVersion": "5.345.269",
4
4
  "hosts": {
5
5
  "claude": [
6
6
  {
7
7
  "passed": true,
8
- "at": "2026-11-29T15:40:03.563Z",
9
- "engineVersion": "0.3.1+hq.5.345.268.src.1bc679792c3384cb9e00562515a145b7a3c05a3692fda4f61b0989900ce7470d",
8
+ "at": "2026-11-29T18:12:55.433Z",
9
+ "engineVersion": "0.3.1+hq.5.345.269.src.59ee74f3c4e4594944cf3944b26360e7060f2c54a18817cb87fa3cfddc33163d",
10
10
  "gateSha256": "a2879dfe692233f5953bac86672947bbd82f3c5247292f3efcb80f16c3d2c6b1"
11
11
  },
12
12
  {
13
13
  "passed": true,
14
- "at": "2026-11-29T15:40:24.985Z",
15
- "engineVersion": "0.3.1+hq.5.345.268.src.1bc679792c3384cb9e00562515a145b7a3c05a3692fda4f61b0989900ce7470d",
14
+ "at": "2026-11-29T18:13:15.465Z",
15
+ "engineVersion": "0.3.1+hq.5.345.269.src.59ee74f3c4e4594944cf3944b26360e7060f2c54a18817cb87fa3cfddc33163d",
16
16
  "gateSha256": "ca58a94859eae0a345c11c8d9c59303eb76350dc1cf223391037d21979c28718"
17
17
  },
18
18
  {
19
19
  "passed": true,
20
- "at": "2026-11-29T15:41:04.610Z",
21
- "engineVersion": "0.3.1+hq.5.345.268.src.1bc679792c3384cb9e00562515a145b7a3c05a3692fda4f61b0989900ce7470d",
20
+ "at": "2026-11-29T18:13:51.865Z",
21
+ "engineVersion": "0.3.1+hq.5.345.269.src.59ee74f3c4e4594944cf3944b26360e7060f2c54a18817cb87fa3cfddc33163d",
22
22
  "gateSha256": "ecdbab7c2e0a1d94eb9c98f15e760390f215bc7115a217ded24b4275322722d2"
23
23
  }
24
24
  ]
@@ -48,6 +48,7 @@ import { createDaemonSharedFlagReads, hqdListenerFlagGate } from "./shared-flag-
48
48
  import { createDaemonKillSwitchMonitors } from "./timed-flag-monitors.js";
49
49
  import { MACHINE_CHECKS_INTERVAL_MS, MACHINE_CHECKS_MIN_INTERVAL_MS, MACHINE_CHECKS_RESULT_FILE, readMachineCheckResults, startMachineCheckSchedule, } from "./machine-checks.js";
50
50
  import { HOOK_ENGINE_ROLLUP_STATE_FILE, hookEngineRollupLogLine, runHookEngineRollup, } from "../../utils/hook-engine-rollup.js";
51
+ import { HOOK_ENGINE_CRASH_STATE_FILE, runHookEngineCrashUpload, startHookEngineCrashSchedule, } from "../../utils/hook-engine-crash.js";
51
52
  import { createLanesReconcileWatcher } from "./lanes-reconcile-watcher.js";
52
53
  import { createLanesReconcileStatus, withLanesReconcileUnit } from "./lanes-reconcile-status.js";
53
54
  import { findLegacyUnits, legacyMeshUnitsToRetire, legacyOwnerLookup, } from "./legacy.js";
@@ -1310,6 +1311,16 @@ export async function runDaemon(opts) {
1310
1311
  log(line.level, line.message);
1311
1312
  },
1312
1313
  });
1314
+ // hq-hook crash lines go out within minutes, not with the daily rollup
1315
+ // (decision 3.1); same client, consent and HQ_TELEMETRY opt-out.
1316
+ const hookEngineCrashes = startHookEngineCrashSchedule({
1317
+ log,
1318
+ run: () => runHookEngineCrashUpload({
1319
+ home,
1320
+ env,
1321
+ stateFile: path.join(paths.root, HOOK_ENGINE_CRASH_STATE_FILE),
1322
+ }),
1323
+ });
1313
1324
  let laneReconcileWatcher = null;
1314
1325
  let laneReconcileWatcherRoot = null;
1315
1326
  let laneReconcileWatchFailedRoot = null;
@@ -1425,6 +1436,7 @@ export async function runDaemon(opts) {
1425
1436
  laneReconcileWatcherRoot = null;
1426
1437
  killSwitches.close();
1427
1438
  machineChecks.close();
1439
+ hookEngineCrashes.close();
1428
1440
  flagSnapshots.close();
1429
1441
  mergeSections.close();
1430
1442
  stateWriter.close();
@@ -0,0 +1,86 @@
1
+ import { type HookEngineRollupClient, type HookEngineRollupConsentBasis } from "./hook-engine-rollup.js";
2
+ export declare const HOOK_ENGINE_CRASH_EVENT = "hook_engine_crash";
3
+ export declare const HOOK_ENGINE_CRASH_STATE_FILE = "hook-engine-crash.json";
4
+ /** How often the daemon looks for new crash lines. */
5
+ export declare const HOOK_ENGINE_CRASH_INTERVAL_MS: number;
6
+ /** First look after the daemon starts. */
7
+ export declare const HOOK_ENGINE_CRASH_FIRST_DELAY_MS = 60000;
8
+ /** Bytes read from the end of the log (and of `.1` when the log is shorter). */
9
+ export declare const HOOK_ENGINE_CRASH_TAIL_BYTES: number;
10
+ /** Events sent per rolling hour, at most. */
11
+ export declare const HOOK_ENGINE_CRASH_MAX_PER_HOUR = 12;
12
+ /** Sent ids remembered for dedupe. */
13
+ export declare const HOOK_ENGINE_CRASH_MAX_SEEN = 512;
14
+ /** Lines older than this are never sent. */
15
+ export declare const HOOK_ENGINE_CRASH_LOOKBACK_MS: number;
16
+ export declare const HOOK_ENGINE_CRASH_MESSAGE_CLASSES: ReadonlySet<string>;
17
+ export interface HookEngineCrashProperties {
18
+ crashId: string;
19
+ signature: string;
20
+ location: string;
21
+ messageClass: string;
22
+ appVersion: string;
23
+ engine: string;
24
+ release?: string;
25
+ os: string;
26
+ arch: string;
27
+ suppressed?: number;
28
+ }
29
+ export interface HookEngineCrashEvent {
30
+ eventName: typeof HOOK_ENGINE_CRASH_EVENT;
31
+ app: "hq-cli";
32
+ source: "cli";
33
+ occurredAt: string;
34
+ consentBasis: HookEngineRollupConsentBasis;
35
+ schemaVersion: 1;
36
+ idempotencyKey: string;
37
+ properties: HookEngineCrashProperties;
38
+ }
39
+ export type HookEngineCrashClient = HookEngineRollupClient<HookEngineCrashEvent>;
40
+ export interface HookEngineCrashOptions {
41
+ home: string;
42
+ stateFile: string;
43
+ env?: NodeJS.ProcessEnv;
44
+ now?: () => number;
45
+ client?: () => HookEngineCrashClient | null;
46
+ }
47
+ export type HookEngineCrashResult = {
48
+ status: "disabled" | "no-identity" | "not-consented" | "consent-unknown" | "started" | "nothing-to-send";
49
+ } | {
50
+ status: "sent";
51
+ events: number;
52
+ suppressed: number;
53
+ } | {
54
+ status: "rejected";
55
+ events: number;
56
+ } | {
57
+ status: "send-failed";
58
+ };
59
+ interface CrashLine {
60
+ at: number;
61
+ properties: HookEngineCrashProperties;
62
+ }
63
+ /** Closed-shape properties for one engine-log row, or null when it is not a valid crash line. */
64
+ export declare function classifyHookEngineCrashRow(row: Record<string, unknown>): CrashLine | null;
65
+ /** Valid crash lines in the tail of the engine log (and its rotated copy), oldest first. */
66
+ export declare function readHookEngineCrashLines(home: string, maxBytes?: number): CrashLine[];
67
+ export declare function buildHookEngineCrashEvent(line: CrashLine, consentBasis: HookEngineRollupConsentBasis, suppressed?: number): HookEngineCrashEvent;
68
+ export declare function runHookEngineCrashUpload(options: HookEngineCrashOptions): Promise<HookEngineCrashResult>;
69
+ export declare function hookEngineCrashLogLine(result: HookEngineCrashResult): {
70
+ level: "info" | "warn";
71
+ message: string;
72
+ } | null;
73
+ export interface HookEngineCrashSchedule {
74
+ /** One tick (tests). Resolves when done; never rejects. */
75
+ tick(): Promise<void>;
76
+ close(): void;
77
+ }
78
+ /** The daemon's crash-upload timer: first look after a minute, then every five. */
79
+ export declare function startHookEngineCrashSchedule(options: {
80
+ run: () => Promise<HookEngineCrashResult>;
81
+ log: (level: "info" | "warn" | "error", message: string) => void;
82
+ firstDelayMs?: number;
83
+ intervalMs?: number;
84
+ }): HookEngineCrashSchedule;
85
+ export {};
86
+ //# sourceMappingURL=hook-engine-crash.d.ts.map
@@ -0,0 +1,325 @@
1
+ /**
2
+ * Prompt upload of hq-hook crash lines (decision 3.1).
3
+ *
4
+ * The Rust engine's panic hook (`crates/hq-hook/src/core_next/crash_report.rs`)
5
+ * appends one `kind: "panic"` line per crash to `~/.hq/logs/hook-engine.jsonl`.
6
+ * The daemon reads the tail of that log every few minutes and sends each new
7
+ * line as one `hook_engine_crash` event to `POST /v1/telemetry/events`, through
8
+ * the same signed-in client, consent read and `HQ_TELEMETRY` opt-out as the
9
+ * daily `hook_engine_failure_rollup` (`hook-engine-rollup.ts`). The rollup
10
+ * ignores `panic` lines, so nothing is counted twice.
11
+ *
12
+ * - Dedupe: every line carries a unique `id`. Ids already sent are kept in the
13
+ * state file, and the event's idempotency key is built from the id.
14
+ * - Rate limit: at most {@link HOOK_ENGINE_CRASH_MAX_PER_HOUR} events per
15
+ * rolling hour. Lines over the limit are not sent; their number rides on
16
+ * the next sent event as `suppressed`.
17
+ * - Nothing written before the uploader first saw consent (`sendFrom`), while
18
+ * `HQ_TELEMETRY=0` was set, while signed out, or while consent was declined
19
+ * is ever sent.
20
+ *
21
+ * Every property is checked against a closed shape; a line with anything else
22
+ * is skipped. The active-install denominator is `cli_session_started`, which
23
+ * already carries `properties.version` (`cli-telemetry.ts`).
24
+ */
25
+ import * as fs from "node:fs";
26
+ import * as path from "node:path";
27
+ import { HOOK_ENGINE_LOG_RELATIVE, defaultHookEngineRollupClient, engineVersion, } from "./hook-engine-rollup.js";
28
+ import { isCliTelemetryDisabled } from "./cli-telemetry.js";
29
+ import { readStoreFile, writeStoreFile } from "../lib/daemon/paths.js";
30
+ export const HOOK_ENGINE_CRASH_EVENT = "hook_engine_crash";
31
+ export const HOOK_ENGINE_CRASH_STATE_FILE = "hook-engine-crash.json";
32
+ /** How often the daemon looks for new crash lines. */
33
+ export const HOOK_ENGINE_CRASH_INTERVAL_MS = 5 * 60_000;
34
+ /** First look after the daemon starts. */
35
+ export const HOOK_ENGINE_CRASH_FIRST_DELAY_MS = 60_000;
36
+ /** Bytes read from the end of the log (and of `.1` when the log is shorter). */
37
+ export const HOOK_ENGINE_CRASH_TAIL_BYTES = 1024 * 1024;
38
+ /** Events sent per rolling hour, at most. */
39
+ export const HOOK_ENGINE_CRASH_MAX_PER_HOUR = 12;
40
+ /** Sent ids remembered for dedupe. */
41
+ export const HOOK_ENGINE_CRASH_MAX_SEEN = 512;
42
+ /** Lines older than this are never sent. */
43
+ export const HOOK_ENGINE_CRASH_LOOKBACK_MS = 7 * 86_400_000;
44
+ const HOUR_MS = 3_600_000;
45
+ const STATE_MAX_BYTES = 256 * 1024;
46
+ export const HOOK_ENGINE_CRASH_MESSAGE_CLASSES = new Set([
47
+ "non-string",
48
+ "unwrap-none",
49
+ "unwrap-err",
50
+ "index-out-of-bounds",
51
+ "slice-index",
52
+ "divide-by-zero",
53
+ "overflow",
54
+ "alloc",
55
+ "already-borrowed",
56
+ "poisoned",
57
+ "assertion",
58
+ "unimplemented",
59
+ "unreachable",
60
+ "other",
61
+ ]);
62
+ const ID_RE = /^[0-9a-f]{24}$/;
63
+ const SIGNATURE_RE = /^[0-9a-f]{16}$/;
64
+ const PLATFORM_RE = /^[a-z0-9_]{1,16}$/;
65
+ const LOCATION_RE = /^(?:[A-Za-z0-9/._-]{1,160}:\d{1,7}|unknown)$/;
66
+ const APP_VERSION_RE = /^\d{1,6}\.\d{1,6}\.\d{1,6}(?:-[0-9A-Za-z.-]{1,40})?$/;
67
+ const SUBJECT_RE = /^[a-z0-9:-]{1,80}$/;
68
+ const MAX_SUPPRESSED = 1_000_000;
69
+ function safeInteger(value, min, max) {
70
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= min && value <= max ? value : undefined;
71
+ }
72
+ function readState(file) {
73
+ const read = readStoreFile(file, STATE_MAX_BYTES);
74
+ if (!read)
75
+ return null;
76
+ try {
77
+ const raw = JSON.parse(read.text);
78
+ if (raw.version !== 1)
79
+ return null;
80
+ const state = { version: 1, seen: [], sentAt: [], suppressed: 0 };
81
+ if (typeof raw.subject === "string" && SUBJECT_RE.test(raw.subject))
82
+ state.subject = raw.subject;
83
+ const sendFrom = safeInteger(raw.sendFrom, 0, Number.MAX_SAFE_INTEGER);
84
+ if (sendFrom !== undefined)
85
+ state.sendFrom = sendFrom;
86
+ if (Array.isArray(raw.seen)) {
87
+ state.seen = raw.seen.filter((id) => typeof id === "string" && ID_RE.test(id)).slice(-HOOK_ENGINE_CRASH_MAX_SEEN);
88
+ }
89
+ if (Array.isArray(raw.sentAt)) {
90
+ state.sentAt = raw.sentAt
91
+ .filter((at) => safeInteger(at, 0, Number.MAX_SAFE_INTEGER) !== undefined)
92
+ .slice(-HOOK_ENGINE_CRASH_MAX_PER_HOUR);
93
+ }
94
+ state.suppressed = safeInteger(raw.suppressed, 0, MAX_SUPPRESSED) ?? 0;
95
+ return state;
96
+ }
97
+ catch {
98
+ return null;
99
+ }
100
+ }
101
+ function writeState(file, state) {
102
+ writeStoreFile(file, JSON.stringify(state), { create: true });
103
+ }
104
+ /** Closed-shape properties for one engine-log row, or null when it is not a valid crash line. */
105
+ export function classifyHookEngineCrashRow(row) {
106
+ if (row.kind !== "panic" || row.schema !== 1)
107
+ return null;
108
+ const at = typeof row.ts === "string" ? Date.parse(row.ts) : Number.NaN;
109
+ if (!Number.isFinite(at))
110
+ return null;
111
+ const { id, signature, location, message_class: messageClass, app_version: appVersion, os, arch } = row;
112
+ if (typeof id !== "string" || !ID_RE.test(id) ||
113
+ typeof signature !== "string" || !SIGNATURE_RE.test(signature) ||
114
+ typeof location !== "string" || !LOCATION_RE.test(location) ||
115
+ typeof messageClass !== "string" || !HOOK_ENGINE_CRASH_MESSAGE_CLASSES.has(messageClass) ||
116
+ typeof appVersion !== "string" || !APP_VERSION_RE.test(appVersion) ||
117
+ typeof os !== "string" || !PLATFORM_RE.test(os) ||
118
+ typeof arch !== "string" || !PLATFORM_RE.test(arch)) {
119
+ return null;
120
+ }
121
+ const version = engineVersion(row.engine);
122
+ return {
123
+ at,
124
+ properties: {
125
+ crashId: id,
126
+ signature,
127
+ location,
128
+ messageClass,
129
+ appVersion,
130
+ engine: version.engine,
131
+ ...(version.release ? { release: version.release } : {}),
132
+ os,
133
+ arch,
134
+ },
135
+ };
136
+ }
137
+ function readTail(file, maxBytes) {
138
+ try {
139
+ const flags = process.platform === "win32" ? fs.constants.O_RDONLY : fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW;
140
+ const fd = fs.openSync(file, flags);
141
+ try {
142
+ const stat = fs.fstatSync(fd);
143
+ if (!stat.isFile())
144
+ return "";
145
+ const length = Math.min(stat.size, maxBytes);
146
+ if (length <= 0)
147
+ return "";
148
+ const buffer = Buffer.alloc(length);
149
+ let read = 0;
150
+ while (read < length) {
151
+ const n = fs.readSync(fd, buffer, read, length - read, stat.size - length + read);
152
+ if (n === 0)
153
+ break;
154
+ read += n;
155
+ }
156
+ const text = buffer.subarray(0, read).toString("utf8");
157
+ // A cut first line is not a whole record.
158
+ return length < stat.size ? text.slice(text.indexOf("\n") + 1) : text;
159
+ }
160
+ finally {
161
+ fs.closeSync(fd);
162
+ }
163
+ }
164
+ catch {
165
+ return "";
166
+ }
167
+ }
168
+ /** Valid crash lines in the tail of the engine log (and its rotated copy), oldest first. */
169
+ export function readHookEngineCrashLines(home, maxBytes = HOOK_ENGINE_CRASH_TAIL_BYTES) {
170
+ const logFile = path.join(home, HOOK_ENGINE_LOG_RELATIVE);
171
+ const current = readTail(logFile, maxBytes);
172
+ const left = maxBytes - Buffer.byteLength(current);
173
+ const rotated = left > 0 ? readTail(`${logFile}.1`, left) : "";
174
+ const lines = [];
175
+ const byId = new Set();
176
+ for (const text of [rotated, current]) {
177
+ for (const raw of text.split("\n")) {
178
+ if (!raw.includes("\"kind\":\"panic\""))
179
+ continue;
180
+ let parsed;
181
+ try {
182
+ parsed = JSON.parse(raw);
183
+ }
184
+ catch {
185
+ continue;
186
+ }
187
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
188
+ continue;
189
+ const line = classifyHookEngineCrashRow(parsed);
190
+ if (!line || byId.has(line.properties.crashId))
191
+ continue;
192
+ byId.add(line.properties.crashId);
193
+ lines.push(line);
194
+ }
195
+ }
196
+ return lines.sort((a, b) => a.at - b.at);
197
+ }
198
+ export function buildHookEngineCrashEvent(line, consentBasis, suppressed = 0) {
199
+ return {
200
+ eventName: HOOK_ENGINE_CRASH_EVENT,
201
+ app: "hq-cli",
202
+ source: "cli",
203
+ occurredAt: new Date(line.at).toISOString(),
204
+ consentBasis,
205
+ schemaVersion: 1,
206
+ idempotencyKey: `hook-engine-crash.${line.properties.crashId}`,
207
+ properties: suppressed > 0 ? { ...line.properties, suppressed } : { ...line.properties },
208
+ };
209
+ }
210
+ function restart(file, saved, now, subject) {
211
+ const kept = subject ?? saved?.subject;
212
+ writeState(file, {
213
+ version: 1,
214
+ ...(kept ? { subject: kept } : {}),
215
+ sendFrom: now,
216
+ seen: saved?.seen ?? [],
217
+ sentAt: saved?.sentAt ?? [],
218
+ suppressed: 0,
219
+ });
220
+ }
221
+ export async function runHookEngineCrashUpload(options) {
222
+ const env = options.env ?? process.env;
223
+ const now = (options.now ?? Date.now)();
224
+ const saved = readState(options.stateFile);
225
+ if (isCliTelemetryDisabled(env)) {
226
+ restart(options.stateFile, saved, now);
227
+ return { status: "disabled" };
228
+ }
229
+ const client = (options.client ?? (defaultHookEngineRollupClient))();
230
+ if (!client) {
231
+ restart(options.stateFile, saved, now);
232
+ return { status: "no-identity" };
233
+ }
234
+ const consent = await client.consent();
235
+ if (consent === "unknown")
236
+ return { status: "consent-unknown" };
237
+ if (consent === "no") {
238
+ restart(options.stateFile, saved, now, client.subject);
239
+ return { status: "not-consented" };
240
+ }
241
+ if (!saved || saved.sendFrom === undefined || saved.subject !== client.subject || saved.sendFrom > now) {
242
+ restart(options.stateFile, saved, now, client.subject);
243
+ return { status: "started" };
244
+ }
245
+ const seen = new Set(saved.seen);
246
+ const oldest = Math.max(saved.sendFrom, now - HOOK_ENGINE_CRASH_LOOKBACK_MS);
247
+ const fresh = readHookEngineCrashLines(options.home).filter((line) => line.at >= oldest && line.at <= now + 60_000 && !seen.has(line.properties.crashId));
248
+ if (fresh.length === 0)
249
+ return { status: "nothing-to-send" };
250
+ const sentAt = saved.sentAt.filter((at) => at > now - HOUR_MS && at <= now);
251
+ const room = Math.max(0, HOOK_ENGINE_CRASH_MAX_PER_HOUR - sentAt.length);
252
+ const toSend = fresh.slice(0, room);
253
+ const over = fresh.slice(room);
254
+ const remember = (ids) => [...saved.seen, ...ids].slice(-HOOK_ENGINE_CRASH_MAX_SEEN);
255
+ const suppressed = Math.min(saved.suppressed + over.length, MAX_SUPPRESSED);
256
+ if (toSend.length === 0) {
257
+ writeState(options.stateFile, { ...saved, sentAt, seen: remember(over.map((l) => l.properties.crashId)), suppressed });
258
+ return { status: "nothing-to-send" };
259
+ }
260
+ const consentBasis = client.consentBasis ?? "opted-in";
261
+ // The suppressed count rides on the first event sent.
262
+ const events = toSend.map((line, index) => buildHookEngineCrashEvent(line, consentBasis, index === 0 ? suppressed : 0));
263
+ const result = await client.post(events);
264
+ if (result === "retry")
265
+ return { status: "send-failed" };
266
+ const ids = [...toSend, ...over].map((line) => line.properties.crashId);
267
+ if (result === "rejected") {
268
+ writeState(options.stateFile, { ...saved, sentAt, seen: remember(ids), suppressed: 0 });
269
+ return { status: "rejected", events: events.length };
270
+ }
271
+ writeState(options.stateFile, {
272
+ ...saved,
273
+ sentAt: [...sentAt, ...toSend.map(() => now)].slice(-HOOK_ENGINE_CRASH_MAX_PER_HOUR),
274
+ seen: remember(ids),
275
+ suppressed: 0,
276
+ });
277
+ return { status: "sent", events: events.length, suppressed };
278
+ }
279
+ export function hookEngineCrashLogLine(result) {
280
+ if (result.status === "sent")
281
+ return { level: "info", message: `hook-engine crash reports sent ${result.events} events` };
282
+ if (result.status === "rejected")
283
+ return { level: "warn", message: `hook-engine crash reports rejected (${result.events} events)` };
284
+ if (result.status === "send-failed")
285
+ return { level: "warn", message: "hook-engine crash report send failed; it retries on a later tick" };
286
+ return null;
287
+ }
288
+ /** The daemon's crash-upload timer: first look after a minute, then every five. */
289
+ export function startHookEngineCrashSchedule(options) {
290
+ let closed = false;
291
+ let running = false;
292
+ const tick = async () => {
293
+ if (closed || running)
294
+ return;
295
+ running = true;
296
+ try {
297
+ const line = hookEngineCrashLogLine(await options.run());
298
+ if (line)
299
+ options.log(line.level, line.message);
300
+ }
301
+ catch (error) {
302
+ options.log("warn", `hook-engine crash upload failed (${error instanceof Error ? error.name : "UnknownError"})`);
303
+ }
304
+ finally {
305
+ running = false;
306
+ }
307
+ };
308
+ let repeat;
309
+ const first = setTimeout(() => {
310
+ void tick();
311
+ repeat = setInterval(() => void tick(), options.intervalMs ?? HOOK_ENGINE_CRASH_INTERVAL_MS);
312
+ repeat.unref?.();
313
+ }, options.firstDelayMs ?? HOOK_ENGINE_CRASH_FIRST_DELAY_MS);
314
+ first.unref?.();
315
+ return {
316
+ tick,
317
+ close() {
318
+ closed = true;
319
+ clearTimeout(first);
320
+ if (repeat)
321
+ clearInterval(repeat);
322
+ },
323
+ };
324
+ }
325
+ //# sourceMappingURL=hook-engine-crash.js.map
@@ -38,11 +38,16 @@ export interface HookEngineRollupEvent {
38
38
  export type HookEngineRollupConsentBasis = "opted-in" | "agent-required";
39
39
  export type HookEngineRollupConsent = "yes" | "no" | "unknown";
40
40
  export type HookEngineRollupPostResult = "ok" | "retry" | "rejected";
41
- export interface HookEngineRollupClient {
41
+ /**
42
+ * The signed-in identity, its telemetry consent and its `/v1/telemetry/events`
43
+ * post. `E` is the event shape it posts: the daily rollup by default, or the
44
+ * crash uploader's `hook_engine_crash` (`hook-engine-crash.ts`).
45
+ */
46
+ export interface HookEngineRollupClient<E = HookEngineRollupEvent> {
42
47
  subject: string;
43
48
  consentBasis?: HookEngineRollupConsentBasis;
44
49
  consent(): Promise<HookEngineRollupConsent>;
45
- post(events: readonly HookEngineRollupEvent[]): Promise<HookEngineRollupPostResult>;
50
+ post(events: readonly E[]): Promise<HookEngineRollupPostResult>;
46
51
  }
47
52
  export interface HookEngineRollupOptions {
48
53
  home: string;
@@ -86,7 +91,7 @@ export declare function buildHookEngineRollupEvents(groups: ReadonlyArray<{
86
91
  day: string;
87
92
  properties: HookEngineFailureProperties;
88
93
  }>, runId: string, consentBasis?: HookEngineRollupConsentBasis): HookEngineRollupEvent[];
89
- export declare function defaultHookEngineRollupClient(): HookEngineRollupClient | null;
94
+ export declare function defaultHookEngineRollupClient<E = HookEngineRollupEvent>(): HookEngineRollupClient<E> | null;
90
95
  export declare function hookEngineRollupLogLine(result: HookEngineRollupResult, previous: HookEngineRollupResult["status"] | undefined): {
91
96
  level: "info" | "warn";
92
97
  message: string;
@@ -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(LATEST_PACKAGE_SPEC, { prefix });
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", LATEST_PACKAGE_SPEC, PNPM_FIRST_PARTY_RELEASE_AGE_EXCLUDE];
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", LATEST_PACKAGE_SPEC];
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.updateCommand;
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(`✗ hq-cli ${CLI_VERSION} is below the minimum required version (${decision.minVersion}).`);
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.updateCommand;
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
- if (!isNewerVersion(decision.latestVersion, CLI_VERSION)) {
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.updateCommand;
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, LATEST_PACKAGE_SPEC, runner);
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
- const converged = (deps.checkConvergence ?? checkUpdateConvergence)(decision.latestVersion);
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigoai-us/hq-cli",
3
- "version": "5.345.268",
3
+ "version": "5.345.269",
4
4
  "description": "HQ by Indigo management CLI — modules and cloud sync",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -128,11 +128,11 @@
128
128
  "*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
129
129
  },
130
130
  "optionalDependencies": {
131
- "@indigoai-us/hq-hook-win32-x64": "5.345.268",
132
- "@indigoai-us/hq-hook-win32-arm64": "5.345.268",
133
- "@indigoai-us/hq-hook-darwin-x64": "5.345.268",
134
- "@indigoai-us/hq-hook-darwin-arm64": "5.345.268",
135
- "@indigoai-us/hq-hook-linux-x64": "5.345.268",
136
- "@indigoai-us/hq-hook-linux-arm64": "5.345.268"
131
+ "@indigoai-us/hq-hook-win32-x64": "5.345.269",
132
+ "@indigoai-us/hq-hook-win32-arm64": "5.345.269",
133
+ "@indigoai-us/hq-hook-darwin-x64": "5.345.269",
134
+ "@indigoai-us/hq-hook-darwin-arm64": "5.345.269",
135
+ "@indigoai-us/hq-hook-linux-x64": "5.345.269",
136
+ "@indigoai-us/hq-hook-linux-arm64": "5.345.269"
137
137
  }
138
138
  }