@indigoai-us/hq-cli 5.345.267 → 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.
Files changed (52) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +12 -0
  3. package/contracts/host-canary-release.json +7 -7
  4. package/dist/commands/core-job-notify-native.d.ts +6 -0
  5. package/dist/commands/core-job-notify-native.js +64 -4
  6. package/dist/commands/core-jobs-native.js +3 -16
  7. package/dist/commands/install-global.js +54 -17
  8. package/dist/lib/daemon/machine-check-owner.js +1 -1
  9. package/dist/lib/daemon/machine-checks.d.ts +3 -11
  10. package/dist/lib/daemon/machine-checks.js +4 -15
  11. package/dist/lib/daemon/run.js +12 -0
  12. package/dist/lib/doctor/checks/codex-wiring.d.ts +4 -2
  13. package/dist/lib/doctor/checks/codex-wiring.js +70 -13
  14. package/dist/lib/doctor/checks/fleet-hook-core.d.ts +4 -4
  15. package/dist/lib/doctor/checks/fleet-hook-core.js +5 -10
  16. package/dist/lib/doctor/checks/grok-wiring.js +38 -0
  17. package/dist/lib/doctor/checks/hook-engine.js +0 -2
  18. package/dist/lib/doctor/checks/host-core.d.ts +1 -1
  19. package/dist/lib/doctor/checks/host-core.js +8 -38
  20. package/dist/lib/hook-engine/coverage.d.ts +10 -1
  21. package/dist/lib/hook-engine/coverage.js +63 -8
  22. package/dist/lib/hook-engine/fleet-registration.js +7 -4
  23. package/dist/lib/hook-engine/native-precompact-compatibility.json +7 -1
  24. package/dist/lib/hook-engine/native-stop-compatibility.json +30 -11
  25. package/dist/lib/hook-engine/reconcile.d.ts +10 -1
  26. package/dist/lib/hook-engine/reconcile.js +339 -42
  27. package/dist/lib/hook-engine/stable-gate.d.ts +43 -0
  28. package/dist/lib/hook-engine/stable-gate.js +276 -0
  29. package/dist/lib/hot-channels/fleet-complete.js +2 -2
  30. package/dist/lib/install/antigravity-targets.js +2 -1
  31. package/dist/lib/install/claude-targets.d.ts +6 -6
  32. package/dist/lib/install/claude-targets.js +13 -9
  33. package/dist/lib/install/codex-targets.d.ts +4 -4
  34. package/dist/lib/install/codex-targets.js +26 -16
  35. package/dist/lib/install/hook-target.d.ts +23 -2
  36. package/dist/lib/install/hook-target.js +89 -16
  37. package/dist/lib/outpost-identity-env.d.ts +18 -0
  38. package/dist/lib/outpost-identity-env.js +29 -0
  39. package/dist/lib/signals/steps/extract.js +46 -12
  40. package/dist/utils/core-next-kill.d.ts +2 -15
  41. package/dist/utils/core-next-kill.js +5 -36
  42. package/dist/utils/hook-engine-crash.d.ts +86 -0
  43. package/dist/utils/hook-engine-crash.js +325 -0
  44. package/dist/utils/hook-engine-rollup.d.ts +8 -3
  45. package/dist/utils/hook-engine-rollup.js +0 -1
  46. package/dist/utils/hook-trust.d.ts +2 -0
  47. package/dist/utils/hook-trust.js +156 -13
  48. package/dist/utils/host-registration.d.ts +158 -4
  49. package/dist/utils/host-registration.js +500 -17
  50. package/dist/utils/version-gate.d.ts +42 -4
  51. package/dist/utils/version-gate.js +84 -25
  52. package/package.json +7 -7
@@ -8,9 +8,9 @@ import * as path from 'node:path';
8
8
  import { spawnSync } from 'node:child_process';
9
9
  import { DAEMON_LAUNCHD_LABEL, DAEMON_SYSTEMD_UNIT, SYSTEM_UNIT_DIR, currentWindowsIdentity, legacyWindowsTask, windowsTaskName } from '../daemon/install.js';
10
10
  import { defaultRunCommand } from '../service-manager/launchd.js';
11
- import { registrationEngine } from '../hook-engine/registration.js';
12
- import { coreNextTargetOrWarn } from '../../utils/host-registration.js';
13
- import { forHost } from '../hook-engine/coverage.js';
11
+ import { coreNextTargetOrWarn, getCoreNextCandidate } from '../../utils/host-registration.js';
12
+ import { forHost, isNativeOnlyCoreRoot } from '../hook-engine/coverage.js';
13
+ import { detectMachineHookHosts, evaluateStableCommit } from '../hook-engine/stable-gate.js';
14
14
  /**
15
15
  * True when this user's hq daemon unit (launchd plist, systemd unit, or the
16
16
  * per-user Windows Scheduled Task) exists. On Windows the shared task an older
@@ -26,19 +26,87 @@ export function isDaemonInstalled(home, platform = process.platform, queryTask =
26
26
  : [];
27
27
  return candidates.some((p) => fs.existsSync(p));
28
28
  }
29
+ function isMachineHookHost(host) {
30
+ return host === 'claude' || host === 'codex' || host === 'grok' || host === 'antigravity';
31
+ }
32
+ /**
33
+ * US-010 / US-017 / US-027: resolve the hook target and, on native-only roots,
34
+ * defer linking `stable` until EVERY host with HQ hook entries on this machine
35
+ * (plus `host`) accepts the candidate engine.
36
+ */
37
+ export function resolveInstallHookTarget(hqRoot, home, daemonInstalled, env = process.env, host = 'claude', platform = process.platform) {
38
+ const nativeOnly = isNativeOnlyCoreRoot(hqRoot);
39
+ const rawCoreNext = coreNextTargetOrWarn(home, env, { platform, deferLink: nativeOnly });
40
+ const candidate = getCoreNextCandidate(rawCoreNext);
41
+ const fallback = legacyHookTarget(hqRoot, home, daemonInstalled, env, host);
42
+ if (nativeOnly && rawCoreNext) {
43
+ const decision = evaluateStableCommit({
44
+ rawCoreNext,
45
+ root: hqRoot,
46
+ home,
47
+ env,
48
+ engineVersion: candidate?.engineVersion,
49
+ requiredHosts: isMachineHookHost(host) ? [host] : [],
50
+ });
51
+ const hostTarget = isMachineHookHost(host)
52
+ ? (decision.targets[host] ?? null)
53
+ : forHost(rawCoreNext, hqRoot, host, env);
54
+ const otherRefused = decision.refusedHosts.length > 0;
55
+ if (hostTarget && !otherRefused) {
56
+ const acceptedHosts = isMachineHookHost(host)
57
+ ? decision.acceptedHosts
58
+ : [...new Set([...decision.acceptedHosts, host])];
59
+ candidate?.commitStable?.(acceptedHosts);
60
+ return { target: { ...hostTarget, fallback } };
61
+ }
62
+ const refusedHosts = hostTarget
63
+ ? decision.refusedHosts
64
+ : [...new Set([host, ...decision.refusedHosts])];
65
+ const checkedHosts = [...new Set([host, ...decision.checkedHosts])];
66
+ const refusalSummary = decision.refusalSummary
67
+ ?? `hq: warning: keeping ${path.join(home, '.hq', 'bin', 'hq-hook', 'stable')} on its current engine instead of hq-hook ${candidate?.engineVersion ?? 'unknown'} because ${refusedHosts.join(', ')} refused it on ${hqRoot}`;
68
+ process.stderr.write(`${refusalSummary}\n`);
69
+ return {
70
+ target: fallback,
71
+ ...(candidate
72
+ ? {
73
+ refusedCandidate: {
74
+ pinnedEngine: candidate.pinnedEngine,
75
+ engineVersion: candidate.engineVersion,
76
+ refusedHosts,
77
+ checkedHosts,
78
+ refusalSummary,
79
+ },
80
+ }
81
+ : {}),
82
+ };
83
+ }
84
+ const coreNext = forHost(rawCoreNext, hqRoot, host, env);
85
+ if (coreNext) {
86
+ candidate?.commitStable?.([host]);
87
+ return { target: { ...coreNext, fallback } };
88
+ }
89
+ const existingHosts = nativeOnly ? detectMachineHookHosts(hqRoot, home, env) : [];
90
+ return {
91
+ target: fallback,
92
+ ...(nativeOnly && candidate
93
+ ? {
94
+ refusedCandidate: {
95
+ pinnedEngine: candidate.pinnedEngine,
96
+ engineVersion: candidate.engineVersion,
97
+ refusedHosts: [host],
98
+ checkedHosts: [...new Set([host, ...existingHosts])],
99
+ },
100
+ }
101
+ : {}),
102
+ };
103
+ }
29
104
  /**
30
105
  * US-010: with hqd installed (and the checkout shipping the shim), hooks go to
31
106
  * the hqd shim; otherwise to master-hook.sh / the Codex adapter.
32
107
  */
33
- export function hookTargetFor(hqRoot, home, daemonInstalled, env = process.env, host = 'claude') {
34
- // hq-core-rust US-017: `core.next` on registers the new core's entry point
35
- // for the events it covers in full on this host in this HQ root; every
36
- // other event keeps the flag-off target. A failure to set up the new core
37
- // is one warning, and install goes on with the flag-off target for every
38
- // event.
39
- const coreNext = forHost(coreNextTargetOrWarn(home, env), hqRoot, host, env);
40
- const fallback = legacyHookTarget(hqRoot, home, daemonInstalled, env, host);
41
- return coreNext ? { ...coreNext, fallback } : fallback;
108
+ export function hookTargetFor(hqRoot, home, daemonInstalled, env = process.env, host = 'claude', platform = process.platform) {
109
+ return resolveInstallHookTarget(hqRoot, home, daemonInstalled, env, host, platform).target;
42
110
  }
43
111
  /**
44
112
  * The target with `core.next` off: the pinned launcher, or master-hook.sh
@@ -51,10 +119,15 @@ export function hookTargetFor(hqRoot, home, daemonInstalled, env = process.env,
51
119
  * the daemon is up. The root, daemon and host arguments stay for callers; they
52
120
  * no longer change the answer.
53
121
  */
54
- export function legacyHookTarget(_hqRoot, home, _daemonInstalled, env = process.env, _host = 'claude') {
55
- const engine = registrationEngine(home, env);
56
- if (engine)
57
- return { engine };
122
+ export function legacyHookTarget(hqRoot, _home, _daemonInstalled, _env = process.env, _host = 'claude') {
123
+ // US-027 C-1: a native-only root deleted master-hook.sh and the Codex bash
124
+ // adapter; never emit `'master'` on it. Fall back to the fail-closed portable
125
+ // native wrapper so guards stay active (and fail closed if hq-hook is absent)
126
+ // even with core.next off or before a passing host canary.
127
+ if (isNativeOnlyCoreRoot(hqRoot))
128
+ return 'portable';
129
+ // US-027 M1: legacy shell launcher argv was removed from `hq-hook` and exits
130
+ // 2 on every event; never emit `{ engine }` launcher registrations.
58
131
  return 'master';
59
132
  }
60
133
  //# sourceMappingURL=hook-target.js.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Owner fields of an Outpost's identity env file. Dependency-free so the
3
+ * `hq core job` fast route can load it.
4
+ */
5
+ export declare const OUTPOST_IDENTITY_ENV_FILE = "/etc/outpost/codex-identity.env";
6
+ export type OutpostIdentityOwnerKey = "OUTPOST_USER_ID" | "OUTPOST_OWNER_EMAIL" | "OWNER_EMAIL";
7
+ export type OutpostIdentityAssignment = {
8
+ key: OutpostIdentityOwnerKey;
9
+ value: string;
10
+ };
11
+ /**
12
+ * Read the owner assignments (OUTPOST_USER_ID, OUTPOST_OWNER_EMAIL,
13
+ * OWNER_EMAIL) in file order. Other keys in the file are ignored and never
14
+ * returned. Quoted values are unquoted; unquoted values lose a trailing
15
+ * ` # comment`.
16
+ */
17
+ export declare function parseOutpostIdentityAssignments(contents: string): OutpostIdentityAssignment[];
18
+ //# sourceMappingURL=outpost-identity-env.d.ts.map
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Owner fields of an Outpost's identity env file. Dependency-free so the
3
+ * `hq core job` fast route can load it.
4
+ */
5
+ export const OUTPOST_IDENTITY_ENV_FILE = "/etc/outpost/codex-identity.env";
6
+ /**
7
+ * Read the owner assignments (OUTPOST_USER_ID, OUTPOST_OWNER_EMAIL,
8
+ * OWNER_EMAIL) in file order. Other keys in the file are ignored and never
9
+ * returned. Quoted values are unquoted; unquoted values lose a trailing
10
+ * ` # comment`.
11
+ */
12
+ export function parseOutpostIdentityAssignments(contents) {
13
+ const assignments = [];
14
+ for (const line of contents.split(/\r?\n/)) {
15
+ const assignment = /^\s*(?:export\s+)?(OUTPOST_USER_ID|OUTPOST_OWNER_EMAIL|OWNER_EMAIL)\s*=\s*(.*?)\s*$/.exec(line);
16
+ if (!assignment)
17
+ continue;
18
+ let value = assignment[2] ?? "";
19
+ if ((value.startsWith("'") && value.endsWith("'")) || (value.startsWith('"') && value.endsWith('"'))) {
20
+ value = value.slice(1, -1);
21
+ }
22
+ else {
23
+ value = value.replace(/\s+#.*$/, "");
24
+ }
25
+ assignments.push({ key: assignment[1], value });
26
+ }
27
+ return assignments;
28
+ }
29
+ //# sourceMappingURL=outpost-identity-env.js.map
@@ -74,8 +74,9 @@
74
74
  * prompt (stdin, never argv), the model returns candidate commands as JSON
75
75
  * data, and the host validates them and runs the pinned wrapper. The helper
76
76
  * reports no cost, so a turn that reached the model is charged the per-source
77
- * estimate. The `claude -p` path below runs only when there is no helper, or
78
- * when the helper cannot run a completion (then for the rest of the run).
77
+ * estimate. The `claude -p` path below runs only when there is no helper,
78
+ * when the helper cannot start or run a completion (then for the rest of the
79
+ * run), or for one item the helper refuses as too large (then for that item).
79
80
  *
80
81
  * grok, checked 2026-11-05 against `grok --help` and the user guide grok
81
82
  * 1.0.70 ships (its embedded 22-permissions-and-safety.md and 18-sandbox.md)
@@ -1421,6 +1422,8 @@ function runTurn(ctx, runtime, prompt, scope, budgetUsd, opts) {
1421
1422
  }
1422
1423
  return { ok: true, turns: parsed.turns, ...cost };
1423
1424
  }
1425
+ /** Spawn error codes that mean the hq-fleet-local helper never started. */
1426
+ const FLEET_HELPER_NOT_STARTED = new Set(["ENOENT", "EACCES", "ENOTDIR", "EPERM", "ENOEXEC"]);
1424
1427
  /**
1425
1428
  * extract's errorKind for an `hq-fleet-local complete` error code, and whether
1426
1429
  * the turn may have used the model (then it is charged the per-source
@@ -1451,23 +1454,35 @@ export function fleetExtractFailure(code) {
1451
1454
  }
1452
1455
  /**
1453
1456
  * One item as a no-tool `hq-fleet-local complete` turn on the Fleet
1454
- * Executive bot's own login. Null when the helper cannot run a completion
1455
- * (it did not start, or its release has no `complete`): the caller then uses
1456
- * the claude CLI. The reply is model output built from the item: it is only
1457
- * validated and run through the pinned wrapper, never logged.
1457
+ * Executive bot's own login. "missing" when the helper cannot run a
1458
+ * completion (it could not start, or its release has no `complete`): the
1459
+ * caller then uses the claude CLI for the rest of the run. "too-large" when
1460
+ * the helper refuses this item's prompt as too large: the caller runs this
1461
+ * item alone on the claude CLI, which reads the item with its Read tool
1462
+ * instead of in the prompt, and keeps the helper for later items. The reply
1463
+ * is model output built from the item: it is only validated and run through
1464
+ * the pinned wrapper, never logged.
1458
1465
  */
1459
1466
  async function runFleetTurn(ctx, target, prompt, scope, opts) {
1460
1467
  // The step's own spawn runs the helper, as it runs every other extract process.
1461
1468
  const run = async (command, args, o) => {
1462
1469
  const r = ctx.spawn(command, [...args], { cwd: o.cwd, env: o.env, timeoutMs: o.timeoutMs, ...(o.input !== undefined ? { input: o.input } : {}) });
1463
- const timedOut = r.error !== undefined && (/ETIMEDOUT|timed out/i.test(r.error.message) || r.error.code === "ETIMEDOUT");
1464
- return { code: r.status, stdout: r.stdout, stderr: r.stderr, timedOut, ...(r.error && !timedOut ? { spawnError: r.error.message } : {}) };
1470
+ const errno = r.error?.code;
1471
+ const timedOut = r.error !== undefined && (/ETIMEDOUT|timed out/i.test(r.error.message) || errno === "ETIMEDOUT");
1472
+ // Only an error that means the helper never started is reported as a
1473
+ // spawn error, which runFleetComplete reads as "missing" and the run
1474
+ // moves to the claude CLI. Any other error (ENOBUFS, a signal) came from
1475
+ // a helper that ran: it fails this item and the helper stays in use.
1476
+ const couldNotStart = r.error !== undefined && !timedOut && errno !== undefined && FLEET_HELPER_NOT_STARTED.has(errno);
1477
+ return { code: r.status, stdout: r.stdout, stderr: r.stderr, timedOut, ...(couldNotStart ? { spawnError: r.error.message } : {}) };
1465
1478
  };
1466
1479
  // The env the adapters step's signals pass gives the helper. The helper
1467
1480
  // reads the bot's login from its profile and refuses an API key login.
1468
1481
  const result = await runFleetComplete(target, prompt, { timeoutMs: opts.turnTimeoutMs, env: process.env, cwd: scope.turnDir, run });
1469
1482
  if (result.kind === "missing")
1470
- return null;
1483
+ return "missing";
1484
+ if (result.kind === "error" && result.code === "too_large")
1485
+ return "too-large";
1471
1486
  const charged = { costUsd: opts.unpricedSourceEstimateUsd, costEstimated: true };
1472
1487
  if (result.kind === "error") {
1473
1488
  const { errorKind, reachedModel } = fleetExtractFailure(result.code);
@@ -1666,6 +1681,8 @@ export function createExtractStep(options = {}) {
1666
1681
  // a helper. A Codex Fleet bot's target is never used for a claude turn.
1667
1682
  let fleet = null;
1668
1683
  let fleetFallback;
1684
+ // Items the helper refused as too large; each ran alone on the claude CLI.
1685
+ const fleetTooLarge = [];
1669
1686
  if (runtime === "claude") {
1670
1687
  const resolveFleet = options.resolveFleetComplete ?? (options.resolveBotRuntime ? () => null : () => defaultResolveFleetComplete());
1671
1688
  try {
@@ -1850,16 +1867,33 @@ export function createExtractStep(options = {}) {
1850
1867
  ...(mode === "codex" || mode === "fleet" ? { itemText: fs.readFileSync(sourceFile, "utf8") } : {}),
1851
1868
  });
1852
1869
  let fleetTurn = null;
1870
+ // Set when the helper refused this item as too large and it runs alone on the claude CLI.
1871
+ let tooLargeFor;
1853
1872
  if (fleet) {
1854
- fleetTurn = await runFleetTurn(ctx, fleet, promptFor("fleet"), scope, turnOpts);
1855
- if (!fleetTurn) {
1873
+ const fleetResult = await runFleetTurn(ctx, fleet, promptFor("fleet"), scope, turnOpts);
1874
+ if (fleetResult === "missing") {
1856
1875
  // The helper cannot run a completion: this item and the rest
1857
1876
  // of the run use the claude CLI.
1858
1877
  fleetFallback = `${fleet.botName}'s hq-fleet-local helper could not run a completion; using the claude CLI`;
1859
1878
  fleet = null;
1860
1879
  }
1880
+ else if (fleetResult === "too-large") {
1881
+ // Too large for the helper's prompt: this item alone runs on
1882
+ // the claude CLI, which reads it with its Read tool.
1883
+ fleetTooLarge.push(item.file);
1884
+ tooLargeFor = fleet.botName;
1885
+ }
1886
+ else {
1887
+ fleetTurn = fleetResult;
1888
+ }
1861
1889
  }
1862
1890
  turn = fleetTurn ?? runTurn(ctx, runtime, promptFor(runtime), scope, Math.max(0, remaining), turnOpts);
1891
+ if (tooLargeFor !== undefined && !turn.ok && turn.errorKind === "signed-out") {
1892
+ // The personal claude login is signed out, but the run is on the
1893
+ // bot's login, which still works: only this oversized item fails,
1894
+ // and the later items still run on the helper.
1895
+ turn = { ...turn, errorKind: "other", error: `too large for ${tooLargeFor}'s hq-fleet-local helper, and the claude CLI it fell back to is not logged in` };
1896
+ }
1863
1897
  }
1864
1898
  finally {
1865
1899
  fs.rmSync(turnDir, { recursive: true, force: true });
@@ -1953,7 +1987,7 @@ export function createExtractStep(options = {}) {
1953
1987
  ...(failures.length ? { failures } : {}),
1954
1988
  ...(skippedItems.length ? { skippedItems } : {}),
1955
1989
  ...(rejected ? { rejectedCandidates: rejected } : {}),
1956
- detail: { new: itemsOut, updated, skipped, runtime, ...(runtime === "claude" ? { login: fleet ? "fleet" : "claude-cli", ...(fleet ? { bot: fleet.botName } : {}) } : {}), ...(fleetFallback ? { loginFallback: fleetFallback } : {}), ...(choice.fallback ? { fallback: choice.fallback } : {}), ...(budgetStoppedAt ? { budgetStoppedAt } : {}), ...(unpricedSources ? { spendEstimated: true, unpricedSources, unpricedSourceEstimateUsd: turnOpts.unpricedSourceEstimateUsd } : {}), ...(uncitedCandidates ? { uncitedCandidates, uncitedSources } : {}), ...listingDetail },
1990
+ detail: { new: itemsOut, updated, skipped, runtime, ...(runtime === "claude" ? { login: fleet ? "fleet" : "claude-cli", ...(fleet ? { bot: fleet.botName } : {}) } : {}), ...(fleetFallback ? { loginFallback: fleetFallback } : {}), ...(fleetTooLarge.length ? { fleetTooLarge } : {}), ...(choice.fallback ? { fallback: choice.fallback } : {}), ...(budgetStoppedAt ? { budgetStoppedAt } : {}), ...(unpricedSources ? { spendEstimated: true, unpricedSources, unpricedSourceEstimateUsd: turnOpts.unpricedSourceEstimateUsd } : {}), ...(uncitedCandidates ? { uncitedCandidates, uncitedSources } : {}), ...listingDetail },
1957
1991
  };
1958
1992
  // Between-sources stop. An in-source stop sets budgetStoppedAt and leaves sourcesLeft at 0.
1959
1993
  // Main names that next source in budgetStoppedAt; the estimate reason is recorded too.
@@ -1,20 +1,7 @@
1
- /** Engine-side kill switch: environment variable and file under the home folder. */
2
- export declare const CORE_NEXT_KILL_ENV = "HQ_CORE_NEXT";
3
- export declare const CORE_NEXT_KILL_FILE: string;
4
- /** The engine-wide kill switch the bridge already honors; the engine checks it too. */
5
- export declare const ENGINE_KILL_ENV = "HQ_HOOK_ENGINE";
6
- export declare const ENGINE_KILL_FILE: string;
1
+ /** Environment variable that enables strict mode (`HQ_HOOK_ENGINE=strict`). */
2
+ export declare const ENGINE_STRICT_ENV = "HQ_HOOK_ENGINE";
7
3
  /** Strict-mode marker file under the home folder (matches crates/hq-hook/src/bridge.rs). */
8
4
  export declare const ENGINE_STRICT_FILE: string;
9
- /**
10
- * Why the new core is switched off on this machine, or null. The same four
11
- * switches the engine reads (`crates/hq-hook/src/core_next.rs` `kill_reason`):
12
- * `HQ_CORE_NEXT=off|0|false|no`, `HQ_HOOK_ENGINE=off`, and the files
13
- * `~/.hq/state/core-next.off` and `~/.hq/hook-engine.off` (a link counts, as
14
- * for the engine). With any of them on, `hq reindex` removes the new-core
15
- * entries it added, so the registrations are what they were before the switch.
16
- */
17
- export declare function coreNextKillReason(home: string, env?: NodeJS.ProcessEnv): string | null;
18
5
  /**
19
6
  * Why strict mode is engaged on this machine, or null. Matches the engine's
20
7
  * strict check (`crates/hq-hook/src/bridge.rs`): `HQ_HOOK_ENGINE=strict`
@@ -1,39 +1,10 @@
1
- /** Shared offline kill switches without installer imports. */
1
+ /** Shared strict-mode switch without installer imports. */
2
2
  import * as fs from 'node:fs';
3
3
  import * as path from 'node:path';
4
- /** Engine-side kill switch: environment variable and file under the home folder. */
5
- export const CORE_NEXT_KILL_ENV = 'HQ_CORE_NEXT';
6
- export const CORE_NEXT_KILL_FILE = path.join('.hq', 'state', 'core-next.off');
7
- /** The engine-wide kill switch the bridge already honors; the engine checks it too. */
8
- export const ENGINE_KILL_ENV = 'HQ_HOOK_ENGINE';
9
- export const ENGINE_KILL_FILE = path.join('.hq', 'hook-engine.off');
4
+ /** Environment variable that enables strict mode (`HQ_HOOK_ENGINE=strict`). */
5
+ export const ENGINE_STRICT_ENV = 'HQ_HOOK_ENGINE';
10
6
  /** Strict-mode marker file under the home folder (matches crates/hq-hook/src/bridge.rs). */
11
7
  export const ENGINE_STRICT_FILE = path.join('.hq', 'hook-engine.strict');
12
- /**
13
- * Why the new core is switched off on this machine, or null. The same four
14
- * switches the engine reads (`crates/hq-hook/src/core_next.rs` `kill_reason`):
15
- * `HQ_CORE_NEXT=off|0|false|no`, `HQ_HOOK_ENGINE=off`, and the files
16
- * `~/.hq/state/core-next.off` and `~/.hq/hook-engine.off` (a link counts, as
17
- * for the engine). With any of them on, `hq reindex` removes the new-core
18
- * entries it added, so the registrations are what they were before the switch.
19
- */
20
- export function coreNextKillReason(home, env = process.env) {
21
- const coreNextEnv = (env[CORE_NEXT_KILL_ENV] ?? '').trim();
22
- if (/^(off|0|false|no)$/i.test(coreNextEnv))
23
- return `${CORE_NEXT_KILL_ENV}=${env[CORE_NEXT_KILL_ENV]}`;
24
- if (/^off$/i.test((env[ENGINE_KILL_ENV] ?? '').trim()))
25
- return `${ENGINE_KILL_ENV}=${env[ENGINE_KILL_ENV]}`;
26
- for (const file of [path.join(home, CORE_NEXT_KILL_FILE), path.join(home, ENGINE_KILL_FILE)]) {
27
- try {
28
- fs.lstatSync(file);
29
- return file;
30
- }
31
- catch {
32
- // Absent: this switch is off.
33
- }
34
- }
35
- return null;
36
- }
37
8
  /**
38
9
  * Why strict mode is engaged on this machine, or null. Matches the engine's
39
10
  * strict check (`crates/hq-hook/src/bridge.rs`): `HQ_HOOK_ENGINE=strict`
@@ -41,10 +12,8 @@ export function coreNextKillReason(home, env = process.env) {
41
12
  * link counts).
42
13
  */
43
14
  export function coreNextStrictReason(home, env = process.env) {
44
- if (coreNextKillReason(home, env) !== null)
45
- return null;
46
- if (/^strict$/i.test((env[ENGINE_KILL_ENV] ?? '').trim()))
47
- return `${ENGINE_KILL_ENV}=${env[ENGINE_KILL_ENV]}`;
15
+ if (/^strict$/i.test((env[ENGINE_STRICT_ENV] ?? '').trim()))
16
+ return `${ENGINE_STRICT_ENV}=${env[ENGINE_STRICT_ENV]}`;
48
17
  const file = path.join(home, ENGINE_STRICT_FILE);
49
18
  try {
50
19
  fs.lstatSync(file);
@@ -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