@indigoai-us/hq-cli 5.345.218 → 5.345.220

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 (138) hide show
  1. package/CHANGELOG.md +130 -0
  2. package/dist/command-catalog.generated.d.ts +94 -1
  3. package/dist/command-catalog.generated.js +114 -1
  4. package/dist/commands/agents.d.ts +22 -0
  5. package/dist/commands/agents.js +92 -1
  6. package/dist/commands/bot.d.ts +48 -0
  7. package/dist/commands/bot.js +108 -8
  8. package/dist/commands/cloud.d.ts +16 -0
  9. package/dist/commands/cloud.js +112 -102
  10. package/dist/commands/core-checkpoint-native.d.ts +13 -0
  11. package/dist/commands/core-checkpoint-native.js +167 -52
  12. package/dist/commands/core-hook-registration-plan.d.ts +8 -0
  13. package/dist/commands/core-hook-registration-plan.js +22 -0
  14. package/dist/commands/core.js +9 -0
  15. package/dist/commands/daemon.js +21 -2
  16. package/dist/commands/doctor.js +4 -0
  17. package/dist/commands/integrations.js +84 -3
  18. package/dist/commands/lanes-shared.d.ts +2 -0
  19. package/dist/commands/lanes-watch.js +28 -1
  20. package/dist/commands/lanes.d.ts +2 -0
  21. package/dist/commands/lanes.js +99 -9
  22. package/dist/commands/packs.js +23 -0
  23. package/dist/commands/pkg-update.d.ts +6 -0
  24. package/dist/commands/pkg-update.js +15 -7
  25. package/dist/commands/reindex.js +6 -0
  26. package/dist/commands/run.js +55 -45
  27. package/dist/commands/sources.js +3 -2
  28. package/dist/index.js +8 -0
  29. package/dist/lib/anywhere-person-setting.d.ts +2 -2
  30. package/dist/lib/anywhere-person-setting.js +2 -2
  31. package/dist/lib/bot/fleet-cron.js +5 -2
  32. package/dist/lib/bot/inflight.d.ts +9 -0
  33. package/dist/lib/bot/jobs/hot-signal-sync.d.ts +51 -0
  34. package/dist/lib/bot/jobs/hot-signal-sync.js +90 -9
  35. package/dist/lib/bot/run.d.ts +29 -5
  36. package/dist/lib/bot/run.js +203 -1
  37. package/dist/lib/bot/signals-try-now.d.ts +76 -0
  38. package/dist/lib/bot/signals-try-now.js +111 -0
  39. package/dist/lib/capacity/collectors/claude-oauth.d.ts +22 -3
  40. package/dist/lib/capacity/collectors/claude-oauth.js +78 -22
  41. package/dist/lib/capacity/scheduler.d.ts +8 -0
  42. package/dist/lib/capacity/scheduler.js +5 -2
  43. package/dist/lib/daemon/anywhere-listener.d.ts +33 -1
  44. package/dist/lib/daemon/anywhere-listener.js +86 -4
  45. package/dist/lib/daemon/machine-check-owner.d.ts +21 -0
  46. package/dist/lib/daemon/machine-check-owner.js +95 -0
  47. package/dist/lib/daemon/machine-check-registration.d.ts +4 -0
  48. package/dist/lib/daemon/machine-check-registration.js +64 -0
  49. package/dist/lib/daemon/machine-checks.d.ts +144 -0
  50. package/dist/lib/daemon/machine-checks.js +412 -0
  51. package/dist/lib/daemon/run.js +35 -4
  52. package/dist/lib/daemon/runtime-notifications.d.ts +7 -0
  53. package/dist/lib/daemon/runtime-notifications.js +50 -0
  54. package/dist/lib/daemon/server.d.ts +2 -0
  55. package/dist/lib/daemon/server.js +6 -0
  56. package/dist/lib/daemon/state-file.d.ts +12 -1
  57. package/dist/lib/daemon/state-file.js +23 -1
  58. package/dist/lib/doctor/checks/fleet-hook-core.d.ts +12 -0
  59. package/dist/lib/doctor/checks/fleet-hook-core.js +127 -0
  60. package/dist/lib/doctor/checks/host-core.js +3 -1
  61. package/dist/lib/doctor/checks/machine-checks.d.ts +16 -0
  62. package/dist/lib/doctor/checks/machine-checks.js +103 -0
  63. package/dist/lib/doctor/registry.js +4 -0
  64. package/dist/lib/doctor/types.d.ts +4 -0
  65. package/dist/lib/hook-engine/canary-gate.d.ts +64 -0
  66. package/dist/lib/hook-engine/canary-gate.js +147 -0
  67. package/dist/lib/hook-engine/coverage.d.ts +3 -1
  68. package/dist/lib/hook-engine/coverage.js +8 -2
  69. package/dist/lib/hook-engine/fleet-registration.d.ts +42 -0
  70. package/dist/lib/hook-engine/fleet-registration.js +168 -0
  71. package/dist/lib/hook-engine/reconcile.js +3 -2
  72. package/dist/lib/hook-engine/registration-identity.d.ts +33 -0
  73. package/dist/lib/hook-engine/registration-identity.js +97 -0
  74. package/dist/lib/hook-engine/registration.d.ts +1 -30
  75. package/dist/lib/hook-engine/registration.js +1 -88
  76. package/dist/lib/hook-engine/resolve.d.ts +2 -0
  77. package/dist/lib/hook-engine/resolve.js +7 -3
  78. package/dist/lib/hot-channels/alert.d.ts +10 -1
  79. package/dist/lib/hot-channels/alert.js +34 -7
  80. package/dist/lib/hot-channels/signals-claude-login.d.ts +53 -0
  81. package/dist/lib/hot-channels/signals-claude-login.js +96 -0
  82. package/dist/lib/hot-channels/signals-pass.d.ts +17 -0
  83. package/dist/lib/hot-channels/signals-pass.js +31 -3
  84. package/dist/lib/lanes/canonical-host.d.ts +8 -1
  85. package/dist/lib/lanes/canonical-host.js +9 -3
  86. package/dist/lib/lanes/machine-identity.d.ts +15 -0
  87. package/dist/lib/lanes/machine-identity.js +26 -0
  88. package/dist/lib/lanes/spawn.js +17 -3
  89. package/dist/lib/search-index/index.js +11 -1
  90. package/dist/lib/signals/engine.d.ts +1 -0
  91. package/dist/lib/signals/engine.js +7 -0
  92. package/dist/lib/signals/reply.d.ts +48 -0
  93. package/dist/lib/signals/reply.js +72 -11
  94. package/dist/lib/signals/steps/adapters.js +6 -0
  95. package/dist/lib/signals/steps/extract.d.ts +50 -3
  96. package/dist/lib/signals/steps/extract.js +100 -17
  97. package/dist/lib/signals/steps/types.d.ts +19 -0
  98. package/dist/lib/sync-core/engine-home.d.ts +6 -1
  99. package/dist/lib/sync-core/engine-home.js +13 -3
  100. package/dist/lib/sync-core/reconcile.js +1 -1
  101. package/dist/lib/sync-core/release-compare.d.ts +7 -0
  102. package/dist/lib/sync-core/release-compare.js +16 -0
  103. package/dist/lib/sync-core/release.d.ts +2 -1
  104. package/dist/lib/sync-core/release.js +2 -10
  105. package/dist/run/schema-env-overrides.d.ts +24 -0
  106. package/dist/run/schema-env-overrides.js +72 -0
  107. package/dist/utils/core-next-flag.d.ts +4 -0
  108. package/dist/utils/core-next-flag.js +22 -0
  109. package/dist/utils/core-next-kill.d.ts +16 -0
  110. package/dist/utils/core-next-kill.js +35 -0
  111. package/dist/utils/host-registration.d.ts +33 -23
  112. package/dist/utils/host-registration.js +90 -66
  113. package/package.json +14 -10
  114. package/scripts/check-function-manifest.mjs +5 -4
  115. package/dist/commands/__fixtures__/access-vault.d.ts +0 -95
  116. package/dist/commands/__fixtures__/access-vault.js +0 -166
  117. package/dist/commands/__fixtures__/make-tar.d.ts +0 -38
  118. package/dist/commands/__fixtures__/make-tar.js +0 -102
  119. package/dist/commands/secrets-public-types.test-d.d.ts +0 -2
  120. package/dist/commands/secrets-public-types.test-d.js +0 -18
  121. package/dist/lib/decisions/fixtures/us001.d.ts +0 -137
  122. package/dist/lib/decisions/fixtures/us001.js +0 -21
  123. package/dist/lib/doctor/__testing__/fake-hq-tree.d.ts +0 -226
  124. package/dist/lib/doctor/__testing__/fake-hq-tree.js +0 -408
  125. package/dist/lib/doctor/__testing__/run-doctor.d.ts +0 -8
  126. package/dist/lib/doctor/__testing__/run-doctor.js +0 -69
  127. package/dist/lib/fingerprint/fixtures.d.ts +0 -19
  128. package/dist/lib/fingerprint/fixtures.js +0 -61
  129. package/dist/lib/hot-channels/adapters/__fixtures__/dummy.d.ts +0 -33
  130. package/dist/lib/hot-channels/adapters/__fixtures__/dummy.js +0 -53
  131. package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.d.ts +0 -38
  132. package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.js +0 -64
  133. package/dist/lib/mesh/live/daemon/mqtt-events.test-d.d.ts +0 -2
  134. package/dist/lib/mesh/live/daemon/mqtt-events.test-d.js +0 -10
  135. package/dist/lib/test-utils/isolated-flag-company-context.d.ts +0 -3
  136. package/dist/lib/test-utils/isolated-flag-company-context.js +0 -18
  137. package/scripts/hook-engine-manifest.mjs +0 -22
  138. package/scripts/mesh-daemon-if-stale.mjs +0 -20
@@ -0,0 +1,147 @@
1
+ /**
2
+ * The host canary gate (hq-core-rust US-019 criterion 4).
3
+ *
4
+ * `scripts/host-canary.mjs` runs a real Claude Code, Codex or Grok Build
5
+ * session against the hook core in a disposable copy of an HQ root. Before
6
+ * any event on a host is moved to the new core (the registration switch,
7
+ * US-017, and the flip, US-026) or the old core is deleted (US-027/028), a
8
+ * passing canary for that host must exist for:
9
+ *
10
+ * - the hq-hook engine version the switch would register (`hq-hook --version`);
11
+ * - the hq-core policy gate this HQ root ships
12
+ * (`.claude/hooks/policy-enforcement-gate.sh`, by SHA-256, the same hash
13
+ * the engine pins its gate port to; `null` when the root has none);
14
+ * - a run no older than [`CANARY_MAX_AGE_MS`].
15
+ *
16
+ * The canary keeps one small record per machine at
17
+ * `~/.hq/state/host-canary.json` ([`HOST_CANARY_RECORD`]): per host, whether
18
+ * the last standard run passed, when, and what it ran against. No paths,
19
+ * prompts, hook payloads, output or secrets go in it. The last run of a host
20
+ * replaces its entry, so a failure after a pass refuses again.
21
+ *
22
+ * Windows is never allowed: the canary does not run there yet, and the
23
+ * registration switch keeps Windows on the old core (US-022).
24
+ *
25
+ * The override, `HQ_SKIP_HOST_CANARY_GATE=1` (or `hq reindex
26
+ * --skip-host-canary-gate`), lets the switch go on without a passing canary
27
+ * and prints a warning that says so. The canary itself sets it for the
28
+ * reindex it runs on its disposable root: that reindex is what the canary
29
+ * tests.
30
+ */
31
+ import { createHash } from 'node:crypto';
32
+ import * as fs from 'node:fs';
33
+ import * as path from 'node:path';
34
+ /** The canary result record, under the home folder. */
35
+ export const HOST_CANARY_RECORD = path.join('.hq', 'state', 'host-canary.json');
36
+ /** Schema of [`HOST_CANARY_RECORD`]. */
37
+ export const CANARY_RECORD_SCHEMA = 'hq.host-canary-result.v1';
38
+ /** The hosts the canary runs and the switch covers. */
39
+ export const CANARY_HOSTS = ['claude', 'codex', 'grok'];
40
+ /** The oldest canary run the gate accepts: seven days. */
41
+ export const CANARY_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
42
+ /** Clock skew tolerated for a run recorded in the future. */
43
+ const FUTURE_SKEW_MS = 5 * 60 * 1000;
44
+ /** The override: switch events without a passing canary. */
45
+ export const SKIP_CANARY_GATE_ENV = 'HQ_SKIP_HOST_CANARY_GATE';
46
+ /** The hq-core gate script whose hash a canary run is bound to. */
47
+ export const GATE_SCRIPT = path.join('.claude', 'hooks', 'policy-enforcement-gate.sh');
48
+ /** SHA-256 of `<root>/.claude/hooks/policy-enforcement-gate.sh`, or null when it is absent. */
49
+ export function gateScriptSha256(root) {
50
+ let bytes;
51
+ try {
52
+ bytes = fs.readFileSync(path.join(root, GATE_SCRIPT));
53
+ }
54
+ catch (error) {
55
+ if (error.code === 'ENOENT')
56
+ return null;
57
+ throw error;
58
+ }
59
+ return createHash('sha256').update(bytes).digest('hex');
60
+ }
61
+ /** True when the override is set in `env`. */
62
+ export function canaryGateSkipped(env = process.env) {
63
+ return /^(1|true|yes|on)$/i.test((env[SKIP_CANARY_GATE_ENV] ?? '').trim());
64
+ }
65
+ /** The record at `<home>/.hq/state/host-canary.json`; null when there is none. Throws when it cannot be read or is not a record. */
66
+ export function readCanaryRecord(home) {
67
+ const file = path.join(home, HOST_CANARY_RECORD);
68
+ let text;
69
+ try {
70
+ text = fs.readFileSync(file, 'utf8');
71
+ }
72
+ catch (error) {
73
+ if (error.code === 'ENOENT')
74
+ return null;
75
+ throw new Error(`${file} cannot be read (${error.code ?? 'error'})`);
76
+ }
77
+ let doc;
78
+ try {
79
+ doc = JSON.parse(text);
80
+ }
81
+ catch {
82
+ throw new Error(`${file} is not JSON`);
83
+ }
84
+ const record = doc;
85
+ if (!record || record.schema !== CANARY_RECORD_SCHEMA || !record.hosts || typeof record.hosts !== 'object' || Array.isArray(record.hosts)) {
86
+ throw new Error(`${file} is not a ${CANARY_RECORD_SCHEMA} record`);
87
+ }
88
+ return record;
89
+ }
90
+ /** Why `record` does not let `host` switch, or null when it does. */
91
+ export function canaryRefusal(record, expected) {
92
+ const { host, engineVersion, gateSha256 } = expected;
93
+ const platform = expected.platform ?? process.platform;
94
+ if (platform === 'win32')
95
+ return 'Windows host canaries are not supported yet';
96
+ if (!CANARY_HOSTS.includes(host))
97
+ return `${host} is not a host the canary runs`;
98
+ if (!record)
99
+ return `no host canary result (${HOST_CANARY_RECORD} is missing)`;
100
+ const result = record.hosts[host];
101
+ if (!result || typeof result !== 'object')
102
+ return `no host canary result for ${host}`;
103
+ if (result.passed !== true)
104
+ return `the last ${host} canary failed`;
105
+ if (result.engineVersion === null)
106
+ return `the last ${host} canary reached no event on the new core`;
107
+ if (result.engineVersion !== engineVersion) {
108
+ return `the last ${host} canary ran hq-hook ${String(result.engineVersion)}, not ${engineVersion}`;
109
+ }
110
+ if (result.gateSha256 !== gateSha256) {
111
+ return `the last ${host} canary ran hq-core gate ${short(result.gateSha256)}, not ${short(gateSha256)}`;
112
+ }
113
+ const at = typeof result.at === 'string' ? Date.parse(result.at) : Number.NaN;
114
+ if (!Number.isFinite(at))
115
+ return `the last ${host} canary has no valid time`;
116
+ const now = expected.now ?? Date.now();
117
+ const maxAgeMs = expected.maxAgeMs ?? CANARY_MAX_AGE_MS;
118
+ if (at > now + FUTURE_SKEW_MS)
119
+ return `the last ${host} canary is dated in the future (${result.at})`;
120
+ if (now - at > maxAgeMs) {
121
+ return `the last ${host} canary is from ${result.at}, older than ${Math.round(maxAgeMs / 3_600_000)} hours`;
122
+ }
123
+ return null;
124
+ }
125
+ function short(hash) {
126
+ return typeof hash === 'string' ? hash.slice(0, 12) : 'none';
127
+ }
128
+ /**
129
+ * The gate for one host and HQ root: allowed when the record has a current
130
+ * passing canary for it, or when the override is set (then `skipped` is true
131
+ * and `reason` says what was bypassed). A record that cannot be read refuses.
132
+ */
133
+ export function checkHostCanary(options) {
134
+ let reason;
135
+ try {
136
+ reason = canaryRefusal(readCanaryRecord(options.home), { ...options, gateSha256: gateScriptSha256(options.root) });
137
+ }
138
+ catch (error) {
139
+ reason = error.message;
140
+ }
141
+ if (!reason)
142
+ return { allowed: true, reason: null, skipped: false };
143
+ if (canaryGateSkipped(options.env))
144
+ return { allowed: true, reason, skipped: true };
145
+ return { allowed: false, reason, skipped: false };
146
+ }
147
+ //# sourceMappingURL=canary-gate.js.map
@@ -7,7 +7,9 @@ export declare function shellHooks(root: string, host: CoreNextHost, event: stri
7
7
  export declare function uncoveredHooks(root: string, host: CoreNextHost, event: string, covers: Readonly<Record<string, readonly string[]>> | undefined): string[];
8
8
  /**
9
9
  * `target` narrowed to the events it covers in full on `host` in this HQ
10
- * root; null when none is covered (every event stays on the old dispatcher).
10
+ * root; null when none is covered (every event stays on the old dispatcher),
11
+ * or when the target's host canary gate refuses `host` (US-019 criterion 4:
12
+ * no event on that host switches).
11
13
  */
12
14
  export declare function forHost(target: CoreNextTarget | null, root: string, host: CoreNextHost): CoreNextTarget | null;
13
15
  //# sourceMappingURL=coverage.d.ts.map
@@ -113,12 +113,18 @@ export function uncoveredHooks(root, host, event, covers) {
113
113
  }
114
114
  /**
115
115
  * `target` narrowed to the events it covers in full on `host` in this HQ
116
- * root; null when none is covered (every event stays on the old dispatcher).
116
+ * root; null when none is covered (every event stays on the old dispatcher),
117
+ * or when the target's host canary gate refuses `host` (US-019 criterion 4:
118
+ * no event on that host switches).
117
119
  */
118
120
  export function forHost(target, root, host) {
119
121
  if (!target)
120
122
  return null;
121
123
  const events = target.events.filter((event) => uncoveredHooks(root, host, event, target.covers).length === 0);
122
- return events.length ? { ...target, events } : null;
124
+ if (!events.length)
125
+ return null;
126
+ if (target.canary && !target.canary(root, host))
127
+ return null;
128
+ return { ...target, events };
123
129
  }
124
130
  //# sourceMappingURL=coverage.js.map
@@ -0,0 +1,42 @@
1
+ import { probeEngine, type CoreNextEngineLookup, type EngineCapabilities } from '../../utils/host-registration.js';
2
+ import { verifyHookEngine } from './resolve.js';
3
+ export declare const FLEET_EVENTS: Record<string, string>;
4
+ /** Literal POSIX argv only. Never expands variables or executes shell syntax. */
5
+ export declare function literalArgv(command: string): string[] | null;
6
+ export type FleetHost = 'fleet-local' | 'agents-v2';
7
+ /** The shell adapter each Fleet host's profile registers. */
8
+ export declare const FLEET_ADAPTERS: Readonly<Record<FleetHost, string>>;
9
+ export declare function isFleetHost(value: unknown): value is FleetHost;
10
+ /**
11
+ * Why `argv` is not `host`'s exact adapter command, or null. The agents-v2
12
+ * adapter takes the event as its one positional argument and the rest from
13
+ * its environment contract, so its fallback is exactly
14
+ * `[<bash|sh>, <abs>/hq-agents-v2-hook-adapter.sh, <event>]`.
15
+ */
16
+ export declare function fallbackProblem(argv: unknown, host?: FleetHost, event?: string): string | null;
17
+ export type FleetEngineLookup = CoreNextEngineLookup;
18
+ /** Self-check, then probe, then the host claim. */
19
+ export declare function fleetEngineCapabilities(engine: string, probe?: typeof probeEngine, verify?: typeof verifyHookEngine, host?: FleetHost): EngineCapabilities;
20
+ export declare function inspectFleetEngine(engine: string, home: string, probe?: typeof probeEngine, verify?: typeof verifyHookEngine, lookup?: FleetEngineLookup, host?: FleetHost): EngineCapabilities;
21
+ export interface FleetPlanOptions {
22
+ home: string;
23
+ env?: NodeJS.ProcessEnv;
24
+ platform?: NodeJS.Platform;
25
+ /** Registration host; fleet-local when absent. */
26
+ host?: FleetHost;
27
+ inspect?: (engine: string) => EngineCapabilities;
28
+ /** Test injection. Production passes nothing and uses the desktop lookup. */
29
+ lookup?: FleetEngineLookup;
30
+ }
31
+ export interface FleetPlanEntry {
32
+ mode: 'native' | 'shell';
33
+ command: string;
34
+ argv: string[];
35
+ reason: string;
36
+ }
37
+ export declare function fleetRegistrationPlan(root: string, fallbacks: Record<string, string[]>, options: FleetPlanOptions): {
38
+ schema: string;
39
+ host: FleetHost;
40
+ events: Record<string, FleetPlanEntry>;
41
+ };
42
+ //# sourceMappingURL=fleet-registration.d.ts.map
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Fleet uses the same flag, evaluator and complete-hook gate as reindex.
3
+ *
4
+ * Two hq-fleet runtimes register here (US-040): `fleet-local` (local bots)
5
+ * and `agents-v2` (hosted agents). Each event gets exactly one entry: the
6
+ * native `hq-hook run --host <host>` call when the engine advertises the host
7
+ * and covers every old hook for the event (including `<host>-adapter:<Event>`),
8
+ * else the host's shell adapter command, which is also the native entry's
9
+ * `--fleet-fallback` argv, verbatim.
10
+ */
11
+ import * as fs from 'node:fs';
12
+ import * as path from 'node:path';
13
+ import { checkStableEngine, coreNextOffReason, capableEvents, probeEngine, missingEvaluators, resolveCoreNextEngine } from '../../utils/host-registration.js';
14
+ import { verifyHookEngine } from './resolve.js';
15
+ import { forHost, uncoveredHooks } from './coverage.js';
16
+ import { quotePosix } from './registration.js';
17
+ export const FLEET_EVENTS = { pre_tool_call: 'PreToolUse', post_tool_call: 'PostToolUse', pre_llm_call: 'UserPromptSubmit', on_session_start: 'SessionStart', pre_verify: 'Stop', on_session_finalize: 'SessionEnd', subagent_stop: 'SubagentStop' };
18
+ /** Literal POSIX argv only. Never expands variables or executes shell syntax. */
19
+ export function literalArgv(command) {
20
+ const out = [];
21
+ let word = '';
22
+ let quote = '';
23
+ let started = false;
24
+ for (let i = 0; i < command.length; i++) {
25
+ const ch = command[i];
26
+ if (quote === "'") {
27
+ if (ch === quote)
28
+ quote = '';
29
+ else
30
+ word += ch;
31
+ continue;
32
+ }
33
+ if (ch === '\\') {
34
+ const next = command[++i];
35
+ if (next === undefined)
36
+ return null;
37
+ word += next;
38
+ started = true;
39
+ continue;
40
+ }
41
+ if (quote === '"') {
42
+ if (ch === quote)
43
+ quote = '';
44
+ else if ('$`'.includes(ch))
45
+ return null;
46
+ else
47
+ word += ch;
48
+ continue;
49
+ }
50
+ if (ch === "'" || ch === '"') {
51
+ quote = ch;
52
+ started = true;
53
+ }
54
+ else if (/\s/.test(ch)) {
55
+ if (started) {
56
+ out.push(word);
57
+ word = '';
58
+ started = false;
59
+ }
60
+ }
61
+ else if (';$`|&<>()\n\0'.includes(ch))
62
+ return null;
63
+ else {
64
+ word += ch;
65
+ started = true;
66
+ }
67
+ }
68
+ if (quote)
69
+ return null;
70
+ if (started)
71
+ out.push(word);
72
+ return out;
73
+ }
74
+ /** The shell adapter each Fleet host's profile registers. */
75
+ export const FLEET_ADAPTERS = {
76
+ 'fleet-local': 'hq-fleet-local-hook-adapter.sh',
77
+ 'agents-v2': 'hq-agents-v2-hook-adapter.sh',
78
+ };
79
+ export function isFleetHost(value) {
80
+ return value === 'fleet-local' || value === 'agents-v2';
81
+ }
82
+ /**
83
+ * Why `argv` is not `host`'s exact adapter command, or null. The agents-v2
84
+ * adapter takes the event as its one positional argument and the rest from
85
+ * its environment contract, so its fallback is exactly
86
+ * `[<bash|sh>, <abs>/hq-agents-v2-hook-adapter.sh, <event>]`.
87
+ */
88
+ export function fallbackProblem(argv, host = 'fleet-local', event) {
89
+ if (!Array.isArray(argv) || argv.length < 2 || !argv.every(v => typeof v === 'string' && !v.includes('\0')))
90
+ return 'fallback must be a nonempty argv vector';
91
+ if (!path.isAbsolute(argv[0]))
92
+ return 'fallback executable must be absolute';
93
+ try {
94
+ fs.accessSync(argv[0], fs.constants.X_OK);
95
+ }
96
+ catch {
97
+ return 'fallback executable is unavailable';
98
+ }
99
+ const fleet = host === 'fleet-local';
100
+ if (['bash', 'sh'].includes(path.basename(argv[0]))) {
101
+ if (!path.isAbsolute(argv[1]) || path.basename(argv[1]) !== FLEET_ADAPTERS[host])
102
+ return fleet ? 'fallback must name the fleet adapter script' : 'fallback must name the agents-v2 adapter script';
103
+ try {
104
+ fs.accessSync(argv[1], fs.constants.R_OK);
105
+ }
106
+ catch {
107
+ return 'fallback adapter is unavailable';
108
+ }
109
+ if (!fleet && (event === undefined || argv.length !== 3 || argv[2] !== event))
110
+ return 'fallback must pass exactly the event to the agents-v2 adapter';
111
+ }
112
+ else
113
+ return fleet ? 'fallback must use the fleet shell adapter' : 'fallback must use the agents-v2 shell adapter';
114
+ return null;
115
+ }
116
+ /** Self-check, then probe, then the host claim. */
117
+ export function fleetEngineCapabilities(engine, probe = probeEngine, verify = verifyHookEngine, host = 'fleet-local') {
118
+ const problem = verify(engine);
119
+ if (problem)
120
+ throw new Error(problem);
121
+ const caps = probe(engine);
122
+ if (!caps.registrationHosts?.includes(host))
123
+ throw new Error(`engine does not support ${host} registration`);
124
+ return caps;
125
+ }
126
+ export function inspectFleetEngine(engine, home, probe = probeEngine, verify = verifyHookEngine, lookup = {}, host = 'fleet-local') {
127
+ const resolved = resolveCoreNextEngine(home, { mode: 'read-only', lookup, probe: e => fleetEngineCapabilities(e, probe, verify, host) });
128
+ checkStableEngine(engine, resolved.pinned);
129
+ return resolved.caps;
130
+ }
131
+ export function fleetRegistrationPlan(root, fallbacks, options) {
132
+ const host = options.host ?? 'fleet-local';
133
+ if (!isFleetHost(host))
134
+ throw new Error(`unsupported fleet registration host: ${String(host)}`);
135
+ const env = options.env ?? process.env;
136
+ let reason = coreNextOffReason(options.home, env, options.platform ?? process.platform);
137
+ let caps;
138
+ let engine = '';
139
+ if (!reason) {
140
+ try {
141
+ const resolved = resolveCoreNextEngine(options.home, { mode: 'read-only', platform: options.platform, lookup: options.lookup, probe: options.inspect ?? (e => fleetEngineCapabilities(e, undefined, undefined, host)) });
142
+ engine = resolved.stable;
143
+ caps = resolved.caps;
144
+ }
145
+ catch (error) {
146
+ reason = error.message;
147
+ }
148
+ }
149
+ // An injected inspect skips fleetEngineCapabilities, so check the host claim here too.
150
+ if (caps && !caps.registrationHosts?.includes(host)) {
151
+ reason = `engine does not support ${host} registration`;
152
+ caps = undefined;
153
+ }
154
+ const target = caps ? forHost({ coreNext: engine, events: capableEvents(caps), covers: caps.covers }, root, host) : null;
155
+ const events = {};
156
+ for (const [event, canonical] of Object.entries(FLEET_EVENTS)) {
157
+ const fallback = fallbacks[event] ?? [];
158
+ if (!Array.isArray(fallback) || !fallback.every(arg => typeof arg === 'string'))
159
+ throw new Error(`${event}: fallback must be an argv vector`);
160
+ const problem = fallbackProblem(fallback, host, event);
161
+ const native = !reason && !problem && target?.events.includes(canonical);
162
+ const argv = native ? [engine, 'run', '--host', host, event, '--hq-root', root, '--fleet-fallback', JSON.stringify(fallback)] : fallback;
163
+ const why = native ? 'complete evaluator and hook coverage' : reason ?? problem ?? (caps && missingEvaluators(caps, canonical)?.length ? 'required evaluators are missing' : `uncovered hooks: ${uncoveredHooks(root, host, canonical, caps?.covers).join(', ')}`);
164
+ events[event] = { mode: native ? 'native' : 'shell', argv, command: argv.map(quotePosix).join(' '), reason: why };
165
+ }
166
+ return { schema: 'hq.hook-registration-plan.v1', host, events };
167
+ }
168
+ //# sourceMappingURL=fleet-registration.js.map
@@ -6,6 +6,7 @@ import { addHqHooks, removeHqHooks } from '../install/claude-targets.js';
6
6
  import { legacyHookTarget } from '../install/hook-target.js';
7
7
  import { addCodexHooks, removeCodexHooks, codexHookEntry, codexHookTrustKeys } from '../install/codex-targets.js';
8
8
  import { engineArgs, isCoreNextEntry, isNativeEntry, registrationEngine } from './registration.js';
9
+ import { userHookSettingsFile } from './registration-identity.js';
9
10
  import { coreNextArgs, coreNextTargetOrWarn, placeEvent } from '../../utils/host-registration.js';
10
11
  import { forHost } from './coverage.js';
11
12
  /** The project master-hook command shipped in HQ's .claude/settings.json. */
@@ -157,8 +158,8 @@ export function reconcileHookRegistrations(root, home = homedir(), env = process
157
158
  result.failures.push(`${join(root, '.claude/settings.json')}: ${error.message}`);
158
159
  }
159
160
  for (const [file, runtime, global] of [
160
- [join(env.CLAUDE_CONFIG_DIR || join(home, '.claude'), 'settings.json'), 'claude', true],
161
- [join(env.CODEX_HOME || join(home, '.codex'), 'hooks.json'), 'codex', true],
161
+ [userHookSettingsFile('claude', home, env), 'claude', true],
162
+ [userHookSettingsFile('codex', home, env), 'codex', true],
162
163
  [join(root, '.codex/hooks.json'), 'codex', false],
163
164
  ]) {
164
165
  // Each file stands alone: an unreadable or locked project file must not
@@ -0,0 +1,33 @@
1
+ export interface NativeTarget {
2
+ engine: string;
3
+ }
4
+ /**
5
+ * Root spelling passed to the launcher. A trailing separator is dropped because
6
+ * Windows PowerShell 5.1 re-quotes a native argument containing a space as
7
+ * "...", and a final backslash would then escape the closing quote.
8
+ */
9
+ export declare function launcherRoot(root: string): string;
10
+ export declare function engineArgs(root: string, event: string, runtime: 'claude' | 'codex', global?: boolean): string[];
11
+ /**
12
+ * True when an entry's `--hq-root` names this HQ root: the same spelling
13
+ * (trailing separators aside), or another spelling of the same folder
14
+ * (`/private/tmp/x` and `/tmp/x`, a symlinked root and its target), found
15
+ * by resolving both. An entry for any other folder is not this root's.
16
+ */
17
+ export declare function sameHqRoot(value: string | undefined, root: string): boolean;
18
+ /** Recognize only our pinned executable with this root's argument. */
19
+ export declare function isNativeEntry(entry: Record<string, unknown>, root: string): boolean;
20
+ /**
21
+ * A registration that calls the new core's entry point, `hq-hook run --host
22
+ * <host> <Event> --hq-root <root>`, through the release-stable link
23
+ * (hq-core-rust US-017). Recognized by the stable path, the `run --host`
24
+ * words and a root argument that names this root ([`sameHqRoot`]), in exec
25
+ * form (`args`) or as a command string (Codex, Grok).
26
+ */
27
+ export declare const CORE_NEXT_LINK: RegExp;
28
+ export declare function isCoreNextEntry(entry: Record<string, unknown>, root: string): boolean;
29
+ export declare function quotePosix(value: string): string;
30
+ export declare function quoteWindows(value: string): string;
31
+ /** User-scope hook file `hq reindex` writes for this host. */
32
+ export declare function userHookSettingsFile(host: 'claude' | 'codex', home: string, env: NodeJS.ProcessEnv): string;
33
+ //# sourceMappingURL=registration-identity.d.ts.map
@@ -0,0 +1,97 @@
1
+ /** Pure registration recognition: no installer or package metadata imports. */
2
+ import { realpathSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ /**
5
+ * Root spelling passed to the launcher. A trailing separator is dropped because
6
+ * Windows PowerShell 5.1 re-quotes a native argument containing a space as
7
+ * "...", and a final backslash would then escape the closing quote.
8
+ */
9
+ export function launcherRoot(root) {
10
+ const trimmed = root.replace(/[\\/]+$/, '');
11
+ return trimmed === '' || /^[A-Za-z]:$/.test(trimmed) ? root : trimmed;
12
+ }
13
+ export function engineArgs(root, event, runtime, global = false) {
14
+ return [event, '--hq-root', launcherRoot(root), '--runtime', runtime, ...(global && runtime === 'claude' ? ['--global'] : [])];
15
+ }
16
+ /**
17
+ * The `--hq-root` value of an HQ entry: the argument after it in exec form,
18
+ * or the single-quoted word after it in a POSIX or PowerShell command string.
19
+ */
20
+ function hqRootArgument(entry) {
21
+ if (Array.isArray(entry.args)) {
22
+ const i = entry.args.indexOf('--hq-root');
23
+ const value = i >= 0 ? entry.args[i + 1] : undefined;
24
+ return typeof value === 'string' ? value : undefined;
25
+ }
26
+ if (typeof entry.command !== 'string')
27
+ return undefined;
28
+ // `& '...'` is the PowerShell form (quote doubled); anything else is POSIX (`'\''`).
29
+ if (entry.command.startsWith('& ')) {
30
+ const windows = entry.command.match(/'--hq-root' '((?:[^']|'')*)'/);
31
+ return windows ? windows[1].replace(/''/g, "'") : undefined;
32
+ }
33
+ const posix = entry.command.match(/'--hq-root' '((?:[^']|'\\'')*)'/);
34
+ return posix ? posix[1].replace(/'\\''/g, "'") : undefined;
35
+ }
36
+ function realpathOrNull(p) {
37
+ try {
38
+ return realpathSync(p);
39
+ }
40
+ catch {
41
+ // A path that does not exist names no folder, so it matches no root.
42
+ return null;
43
+ }
44
+ }
45
+ /**
46
+ * True when an entry's `--hq-root` names this HQ root: the same spelling
47
+ * (trailing separators aside), or another spelling of the same folder
48
+ * (`/private/tmp/x` and `/tmp/x`, a symlinked root and its target), found
49
+ * by resolving both. An entry for any other folder is not this root's.
50
+ */
51
+ export function sameHqRoot(value, root) {
52
+ if (value === undefined)
53
+ return false;
54
+ if (value === launcherRoot(root) || launcherRoot(value) === launcherRoot(root))
55
+ return true;
56
+ const a = realpathOrNull(value);
57
+ return a !== null && a === realpathOrNull(root);
58
+ }
59
+ /** Recognize only our pinned executable with this root's argument. */
60
+ export function isNativeEntry(entry, root) {
61
+ if (typeof entry.command !== 'string')
62
+ return false;
63
+ const pinned = /[\\/]\.hq[\\/]bin[\\/]hq-hook[\\/]\d+\.\d+\.\d+[^\\/]*[\\/]/;
64
+ if (!pinned.test(entry.command))
65
+ return false;
66
+ return sameHqRoot(hqRootArgument(entry), root);
67
+ }
68
+ /**
69
+ * A registration that calls the new core's entry point, `hq-hook run --host
70
+ * <host> <Event> --hq-root <root>`, through the release-stable link
71
+ * (hq-core-rust US-017). Recognized by the stable path, the `run --host`
72
+ * words and a root argument that names this root ([`sameHqRoot`]), in exec
73
+ * form (`args`) or as a command string (Codex, Grok).
74
+ */
75
+ export const CORE_NEXT_LINK = /[\\/]\.hq[\\/]bin[\\/]hq-hook[\\/]stable[\\/]/;
76
+ export function isCoreNextEntry(entry, root) {
77
+ if (typeof entry.command !== 'string' || !CORE_NEXT_LINK.test(entry.command))
78
+ return false;
79
+ const runHost = Array.isArray(entry.args)
80
+ ? entry.args[0] === 'run' && entry.args[1] === '--host'
81
+ : entry.command.includes(`${quotePosix('run')} ${quotePosix('--host')}`);
82
+ return runHost && sameHqRoot(hqRootArgument(entry), root);
83
+ }
84
+ export function quotePosix(value) { return "'" + value.replace(/'/g, "'\\''") + "'"; }
85
+ export function quoteWindows(value) {
86
+ // Codex 0.162.1 uses its Windows PowerShell runtime shell for hooks.
87
+ // Single-quoted literals prevent variable, subexpression and wildcard expansion.
88
+ // PowerShell also closes them on the typographic quotes U+2018-U+201B.
89
+ return "'" + value.replace(/['‘’‚‛]/g, '$&$&') + "'";
90
+ }
91
+ /** User-scope hook file `hq reindex` writes for this host. */
92
+ export function userHookSettingsFile(host, home, env) {
93
+ return host === 'claude'
94
+ ? join(env.CLAUDE_CONFIG_DIR || join(home, '.claude'), 'settings.json')
95
+ : join(env.CODEX_HOME || join(home, '.codex'), 'hooks.json');
96
+ }
97
+ //# sourceMappingURL=registration-identity.js.map
@@ -1,33 +1,4 @@
1
1
  export declare function launcherEnabled(env?: NodeJS.ProcessEnv): boolean;
2
2
  export declare function registrationEngine(home: string, env?: NodeJS.ProcessEnv): string | null;
3
- export interface NativeTarget {
4
- engine: string;
5
- }
6
- /**
7
- * Root spelling passed to the launcher. A trailing separator is dropped because
8
- * Windows PowerShell 5.1 re-quotes a native argument containing a space as
9
- * "...", and a final backslash would then escape the closing quote.
10
- */
11
- export declare function launcherRoot(root: string): string;
12
- export declare function engineArgs(root: string, event: string, runtime: 'claude' | 'codex', global?: boolean): string[];
13
- /**
14
- * True when an entry's `--hq-root` names this HQ root: the same spelling
15
- * (trailing separators aside), or another spelling of the same folder
16
- * (`/private/tmp/x` and `/tmp/x`, a symlinked root and its target), found
17
- * by resolving both. An entry for any other folder is not this root's.
18
- */
19
- export declare function sameHqRoot(value: string | undefined, root: string): boolean;
20
- /** Recognize only our pinned executable with this root's argument. */
21
- export declare function isNativeEntry(entry: Record<string, unknown>, root: string): boolean;
22
- /**
23
- * A registration that calls the new core's entry point, `hq-hook run --host
24
- * <host> <Event> --hq-root <root>`, through the release-stable link
25
- * (hq-core-rust US-017). Recognized by the stable path, the `run --host`
26
- * words and a root argument that names this root ([`sameHqRoot`]), in exec
27
- * form (`args`) or as a command string (Codex, Grok).
28
- */
29
- export declare const CORE_NEXT_LINK: RegExp;
30
- export declare function isCoreNextEntry(entry: Record<string, unknown>, root: string): boolean;
31
- export declare function quotePosix(value: string): string;
32
- export declare function quoteWindows(value: string): string;
3
+ export { launcherRoot, engineArgs, isNativeEntry, isCoreNextEntry, sameHqRoot, CORE_NEXT_LINK, quotePosix, quoteWindows, type NativeTarget } from './registration-identity.js';
33
4
  //# sourceMappingURL=registration.d.ts.map