@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.
@@ -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;
@@ -885,7 +885,10 @@ export function trustGrokProjectHooks(hqRoot, deps = DEFAULT_DEPS) {
885
885
  let wantJson;
886
886
  if (grok && grok.events.length > 0) {
887
887
  try {
888
- candidate?.commitStable?.(acceptedHosts);
888
+ if (candidate?.commitStable)
889
+ candidate.commitStable(acceptedHosts);
890
+ else
891
+ candidate?.recordAccepted?.(acceptedHosts);
889
892
  }
890
893
  catch (error) {
891
894
  return { runtime: 'grok', status: 'failed', trusted: 0, reason: errorMessage(error) };
@@ -985,6 +988,9 @@ export function trustGrokProjectHooks(hqRoot, deps = DEFAULT_DEPS) {
985
988
  const target = (deps.coreNextTarget ?? ((h) => coreNextTargetOrWarn(h)))(home);
986
989
  // Only the events the new core covers in full on Grok switch.
987
990
  const grok = forHost(target, hqRoot, 'grok');
991
+ if (grok && grok.events.length > 0) {
992
+ getCoreNextCandidate(target)?.recordAccepted?.(['grok']);
993
+ }
988
994
  wantJson = grok || platform === 'win32'
989
995
  ? grokBridgeJson(fs.readFileSync(sourceBridgeJson, 'utf8'), hqRoot, grok, platform, home)
990
996
  : undefined;
@@ -1,14 +1,10 @@
1
1
  import { type EngineOptions } from '../lib/hook-engine/resolve.js';
2
2
  import { type NativeTarget } from '../lib/hook-engine/registration.js';
3
+ import { type CanaryHost } from '../lib/hook-engine/canary-gate.js';
3
4
  export { CORE_NEXT_FLAG, coreNextEnabled } from './core-next-flag.js';
4
5
  export { coreNextStrictReason, ENGINE_STRICT_ENV, ENGINE_STRICT_FILE } from './core-next-kill.js';
5
- /** Name of the release-stable link next to the pinned engine versions. */
6
- export declare const STABLE_LINK_NAME = "stable";
7
- /** Record of canary-accepted hook engines committed to `stable`, under the home folder. */
8
- export declare const ACCEPTED_HOOK_ENGINE_RECORD: string;
9
- /** Schema of [`ACCEPTED_HOOK_ENGINE_RECORD`]. */
10
- export declare const ACCEPTED_HOOK_ENGINE_SCHEMA = "hq.accepted-hook-engine.v1";
11
- export type CoreNextHost = 'claude' | 'codex' | 'grok' | 'fleet-local' | 'agents-v2' | 'antigravity';
6
+ export { ACCEPTED_HOOK_ENGINE_RECORD, ACCEPTED_HOOK_ENGINE_SCHEMA, STABLE_LINK_NAME, StableDowngradeRefused, linkStableEngine, readAcceptedHookEngineRecord, stableEnginePath, type AcceptedHookEngineEntry, type AcceptedHookEngineRecord, type CoreNextHost, type LinkStableEngineOptions, } from '../lib/hook-engine/stable-link.js';
7
+ import { type CoreNextHost } from '../lib/hook-engine/stable-link.js';
12
8
  /**
13
9
  * `project`: the HQ root's own registration, always answers.
14
10
  * `global`: the user-scope Claude Code entry; answers nothing inside an HQ
@@ -44,6 +40,11 @@ export interface CoreNextCandidateMeta {
44
40
  pinnedEngine: string;
45
41
  engineVersion: string;
46
42
  commitStable?: (acceptedHosts?: readonly CoreNextHost[]) => string;
43
+ /**
44
+ * Record `acceptedHosts` in `<home>/.hq/bin/hq-hook/accepted-engine.json`
45
+ * after `stable` is linked and a real host canary has passed on this machine.
46
+ */
47
+ recordAccepted?: (acceptedHosts?: readonly CoreNextHost[]) => void;
47
48
  }
48
49
  /** Read the candidate engine metadata attached by [`coreNextTarget`], if any. */
49
50
  export declare function getCoreNextCandidate(target: CoreNextTarget | null | undefined): CoreNextCandidateMeta | undefined;
@@ -84,16 +85,6 @@ export declare function probeEngine(engine: string): EngineCapabilities;
84
85
  * new-core registration with nothing to run.
85
86
  */
86
87
  export declare function checkStableEngine(stable: string, pinned: string): void;
87
- /** The stable path that stands for a pinned engine path. */
88
- export declare function stableEnginePath(pinned: string, home: string): string;
89
- /**
90
- * Point `<home>/.hq/bin/hq-hook/stable` at the pinned engine's version folder
91
- * and return the stable engine path. The link is replaced by rename, so a
92
- * planted file at the temporary name or the link itself is never followed. A
93
- * `stable` that is a real folder (not a link) is someone else's and is left
94
- * alone: the call fails and the caller keeps the current registrations.
95
- */
96
- export declare function linkStableEngine(pinned: string, home: string, platform?: NodeJS.Platform): string;
97
88
  export interface CoreNextOptions {
98
89
  platform?: NodeJS.Platform;
99
90
  /** Reads the engine's capabilities; `probeEngine` by default. */
@@ -130,22 +121,6 @@ export interface CoreNextEngine {
130
121
  * writes. Both fail when the pinned bundle or the stable link is wrong.
131
122
  */
132
123
  export declare function resolveCoreNextEngine(home: string, options: CoreNextEngineOptions): CoreNextEngine;
133
- /** One canary-accepted engine recorded when `commitStable` moved `stable` to it. */
134
- export interface AcceptedHookEngineEntry {
135
- engineVersion: string;
136
- pinnedEngine: string;
137
- acceptedAt: string;
138
- hosts: CoreNextHost[];
139
- }
140
- export interface AcceptedHookEngineRecord {
141
- schema: typeof ACCEPTED_HOOK_ENGINE_SCHEMA;
142
- engines: Record<string, AcceptedHookEngineEntry>;
143
- }
144
- /**
145
- * Read `<home>/.hq/bin/hq-hook/accepted-engine.json`; null when absent,
146
- * unreadable, invalid, or writable by another user.
147
- */
148
- export declare function readAcceptedHookEngineRecord(home: string, platform?: NodeJS.Platform): AcceptedHookEngineRecord | null;
149
124
  /**
150
125
  * Record `pinned` (`engineVersion`) as canary-accepted for `hosts` after
151
126
  * committing `<home>/.hq/bin/hq-hook/stable`. Merges `hosts` when the same
@@ -183,7 +158,9 @@ export declare function existingAcceptedStableHookEngine(home: string, options:
183
158
  * Windows), regardless of `core.next`. When the npm engine package is gone,
184
159
  * reuses an existing runnable `stable` or relinks `stable` from an already-
185
160
  * pinned copy of this CLI's version under `<home>/.hq/bin/hq-hook/<version>`.
186
- * Returns null when no usable engine exists on disk.
161
+ * When `stable` names a newer engine that still runs, it is kept and returned
162
+ * (the link never moves back on its own). Returns null when no usable engine
163
+ * exists on disk.
187
164
  */
188
165
  export declare function ensureStableHookEngine(home: string, options?: {
189
166
  platform?: NodeJS.Platform;
@@ -238,7 +215,7 @@ export declare function coreNextTarget(home: string, env?: NodeJS.ProcessEnv, op
238
215
  * capable event. [`coreNextTarget`] builds its target here, and `hq doctor`
239
216
  * uses it to ask the same questions without installing anything.
240
217
  */
241
- export declare function coreNextTargetFor(home: string, env: NodeJS.ProcessEnv, stable: string, caps: EngineCapabilities, platform?: NodeJS.Platform, warn?: (message: string) => void): CoreNextTarget | null;
218
+ export declare function coreNextTargetFor(home: string, env: NodeJS.ProcessEnv, stable: string, caps: EngineCapabilities, platform?: NodeJS.Platform, warn?: (message: string) => void, onCanaryPassed?: (host: CanaryHost) => void): CoreNextTarget | null;
242
219
  /**
243
220
  * Set by `hq reindex --from-hook` (a reindex the daemon runs for a hook's
244
221
  * request note): the host canary gate then keeps every host on the core it is