@indigoai-us/hq-cli 5.345.217 → 5.345.219
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +105 -0
- package/README.md +1 -1
- package/assets/bot-workers/setup/skills/add-a-pack.md +3 -3
- package/assets/scaffold/core/scripts/hq-session.sh +4 -0
- package/dist/command-catalog.generated.d.ts +69 -0
- package/dist/command-catalog.generated.js +83 -0
- package/dist/commands/agents.d.ts +22 -0
- package/dist/commands/agents.js +92 -1
- package/dist/commands/cloud.d.ts +1 -1
- package/dist/commands/cloud.js +1 -1
- package/dist/commands/core-hook-registration-plan.d.ts +8 -0
- package/dist/commands/core-hook-registration-plan.js +21 -0
- package/dist/commands/core-hq-session-native.js +3 -0
- package/dist/commands/core.js +9 -0
- package/dist/commands/doctor.js +4 -0
- package/dist/commands/install-global.js +1 -1
- package/dist/commands/lanes-shared.d.ts +2 -0
- package/dist/commands/lanes-watch.js +28 -1
- package/dist/commands/lanes.d.ts +2 -0
- package/dist/commands/lanes.js +99 -9
- package/dist/commands/members.js +1 -1
- package/dist/commands/pack-start-bot.d.ts +1 -1
- package/dist/commands/pack-start-bot.js +2 -2
- package/dist/commands/pkg-update.js +1 -1
- package/dist/commands/reindex.js +6 -0
- package/dist/commands/sync-narrow.js +1 -1
- package/dist/commands/team-sync.js +1 -1
- package/dist/data/command-states.json +8 -1
- package/dist/index.js +8 -0
- package/dist/lib/anywhere-person-setting.d.ts +2 -2
- package/dist/lib/anywhere-person-setting.js +2 -2
- package/dist/lib/billing/usage-cost.js +5 -2
- package/dist/lib/bot/pack-link.d.ts +2 -2
- package/dist/lib/bot/pack-link.js +2 -2
- package/dist/lib/daemon/anywhere-listener.d.ts +33 -1
- package/dist/lib/daemon/anywhere-listener.js +86 -4
- package/dist/lib/daemon/hook-env.d.ts +32 -0
- package/dist/lib/daemon/hook-env.js +51 -0
- package/dist/lib/daemon/machine-check-owner.d.ts +21 -0
- package/dist/lib/daemon/machine-check-owner.js +95 -0
- package/dist/lib/daemon/machine-check-registration.d.ts +4 -0
- package/dist/lib/daemon/machine-check-registration.js +64 -0
- package/dist/lib/daemon/machine-checks.d.ts +144 -0
- package/dist/lib/daemon/machine-checks.js +412 -0
- package/dist/lib/daemon/ops/policy.js +5 -3
- package/dist/lib/daemon/run.js +37 -5
- package/dist/lib/daemon/server.d.ts +2 -0
- package/dist/lib/daemon/server.js +6 -0
- package/dist/lib/daemon/state-file.d.ts +12 -1
- package/dist/lib/daemon/state-file.js +23 -1
- package/dist/lib/doctor/checks/fleet-hook-core.d.ts +4 -0
- package/dist/lib/doctor/checks/fleet-hook-core.js +103 -0
- package/dist/lib/doctor/checks/host-core.d.ts +2 -0
- package/dist/lib/doctor/checks/host-core.js +81 -11
- package/dist/lib/doctor/checks/machine-checks.d.ts +16 -0
- package/dist/lib/doctor/checks/machine-checks.js +103 -0
- package/dist/lib/doctor/checks/sync-runtime.js +3 -3
- package/dist/lib/doctor/registry.js +4 -0
- package/dist/lib/doctor/types.d.ts +4 -0
- package/dist/lib/environment/credential-shapes.d.ts +61 -0
- package/dist/lib/environment/credential-shapes.js +333 -0
- package/dist/lib/environment/profile.js +4 -16
- package/dist/lib/hook-engine/canary-gate.d.ts +64 -0
- package/dist/lib/hook-engine/canary-gate.js +147 -0
- package/dist/lib/hook-engine/coverage.d.ts +15 -0
- package/dist/lib/hook-engine/coverage.js +130 -0
- package/dist/lib/hook-engine/fleet-registration.d.ts +30 -0
- package/dist/lib/hook-engine/fleet-registration.js +132 -0
- package/dist/lib/hook-engine/reconcile.js +297 -116
- package/dist/lib/hook-engine/registration-identity.d.ts +33 -0
- package/dist/lib/hook-engine/registration-identity.js +97 -0
- package/dist/lib/hook-engine/registration.d.ts +1 -23
- package/dist/lib/hook-engine/registration.js +1 -52
- package/dist/lib/hook-engine/resolve.d.ts +2 -0
- package/dist/lib/hook-engine/resolve.js +7 -3
- package/dist/lib/install/claude-targets.js +28 -15
- package/dist/lib/install/codex-pack-contributions.js +1 -1
- package/dist/lib/install/codex-targets.js +24 -11
- package/dist/lib/install/hook-target.d.ts +2 -2
- package/dist/lib/install/hook-target.js +7 -5
- package/dist/lib/lanes/canonical-host.d.ts +8 -1
- package/dist/lib/lanes/canonical-host.js +9 -3
- package/dist/lib/lanes/machine-identity.d.ts +15 -0
- package/dist/lib/lanes/machine-identity.js +26 -0
- package/dist/lib/lanes/spawn.js +17 -3
- package/dist/lib/packages/setup-block.d.ts +2 -2
- package/dist/lib/packages/setup-block.js +2 -2
- package/dist/lib/packages/start-bot.d.ts +1 -1
- package/dist/lib/packages/start-bot.js +1 -1
- package/dist/main.js +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/callback-port-busy.d.ts +1 -1
- package/dist/utils/callback-port-busy.js +4 -4
- package/dist/utils/core-next-flag.d.ts +4 -0
- package/dist/utils/core-next-flag.js +22 -0
- package/dist/utils/core-next-kill.d.ts +16 -0
- package/dist/utils/core-next-kill.js +35 -0
- package/dist/utils/hook-trust.js +4 -1
- package/dist/utils/host-registration.d.ts +80 -17
- package/dist/utils/host-registration.js +194 -47
- package/package.json +8 -8
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Shared offline kill switches without installer imports. */
|
|
2
|
+
import * as fs from 'node:fs';
|
|
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');
|
|
10
|
+
/**
|
|
11
|
+
* Why the new core is switched off on this machine, or null. The same four
|
|
12
|
+
* switches the engine reads (`crates/hq-hook/src/core_next.rs` `kill_reason`):
|
|
13
|
+
* `HQ_CORE_NEXT=off|0|false|no`, `HQ_HOOK_ENGINE=off`, and the files
|
|
14
|
+
* `~/.hq/state/core-next.off` and `~/.hq/hook-engine.off` (a link counts, as
|
|
15
|
+
* for the engine). With any of them on, `hq reindex` removes the new-core
|
|
16
|
+
* entries it added, so the registrations are what they were before the switch.
|
|
17
|
+
*/
|
|
18
|
+
export function coreNextKillReason(home, env = process.env) {
|
|
19
|
+
const coreNextEnv = (env[CORE_NEXT_KILL_ENV] ?? '').trim();
|
|
20
|
+
if (/^(off|0|false|no)$/i.test(coreNextEnv))
|
|
21
|
+
return `${CORE_NEXT_KILL_ENV}=${env[CORE_NEXT_KILL_ENV]}`;
|
|
22
|
+
if (/^off$/i.test((env[ENGINE_KILL_ENV] ?? '').trim()))
|
|
23
|
+
return `${ENGINE_KILL_ENV}=${env[ENGINE_KILL_ENV]}`;
|
|
24
|
+
for (const file of [path.join(home, CORE_NEXT_KILL_FILE), path.join(home, ENGINE_KILL_FILE)]) {
|
|
25
|
+
try {
|
|
26
|
+
fs.lstatSync(file);
|
|
27
|
+
return file;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// Absent: this switch is off.
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=core-next-kill.js.map
|
package/dist/utils/hook-trust.js
CHANGED
|
@@ -11,6 +11,7 @@ import { parse as parseToml } from 'smol-toml';
|
|
|
11
11
|
import { acquireLock, atomicReplace, backupConfig, realpathOrSelf, releaseLock, restoreFromBackup, } from '../commands/mcp-registration.js';
|
|
12
12
|
import { findExecutableOnPath } from './resolve-executable.js';
|
|
13
13
|
import { loadShippedCodexHookFiles } from './shipped-codex-hooks.js';
|
|
14
|
+
import { forHost } from '../lib/hook-engine/coverage.js';
|
|
14
15
|
import { coreNextTargetOrWarn, grokBridgeJson, replaceFileNoFollow } from './host-registration.js';
|
|
15
16
|
import { planResolvedCommandSpawn } from './windows-spawn.js';
|
|
16
17
|
/**
|
|
@@ -837,7 +838,9 @@ export function trustGrokProjectHooks(hqRoot, deps = DEFAULT_DEPS) {
|
|
|
837
838
|
let wantJson;
|
|
838
839
|
try {
|
|
839
840
|
const target = (deps.coreNextTarget ?? ((h) => coreNextTargetOrWarn(h)))(home);
|
|
840
|
-
|
|
841
|
+
// Only the events the new core covers in full on Grok switch.
|
|
842
|
+
const grok = forHost(target, hqRoot, 'grok');
|
|
843
|
+
wantJson = grok ? grokBridgeJson(fs.readFileSync(sourceBridgeJson, 'utf8'), hqRoot, grok) : undefined;
|
|
841
844
|
}
|
|
842
845
|
catch (error) {
|
|
843
846
|
process.stderr.write(`hq: warning: the Grok user hook file stays on the old dispatcher (${errorMessage(error)})\n`);
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
+
import { type EngineOptions } from '../lib/hook-engine/resolve.js';
|
|
1
2
|
import { type NativeTarget } from '../lib/hook-engine/registration.js';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
export declare const CORE_NEXT_KILL_ENV = "HQ_CORE_NEXT";
|
|
5
|
-
export declare const CORE_NEXT_KILL_FILE: string;
|
|
6
|
-
/** The engine-wide kill switch the bridge already honors; the engine checks it too. */
|
|
7
|
-
export declare const ENGINE_KILL_ENV = "HQ_HOOK_ENGINE";
|
|
8
|
-
export declare const ENGINE_KILL_FILE: string;
|
|
3
|
+
export { CORE_NEXT_FLAG, coreNextEnabled } from './core-next-flag.js';
|
|
4
|
+
export { coreNextKillReason, CORE_NEXT_KILL_ENV, CORE_NEXT_KILL_FILE, ENGINE_KILL_ENV, ENGINE_KILL_FILE } from './core-next-kill.js';
|
|
9
5
|
/** Name of the release-stable link next to the pinned engine versions. */
|
|
10
6
|
export declare const STABLE_LINK_NAME = "stable";
|
|
11
|
-
export type CoreNextHost = 'claude' | 'codex' | 'grok';
|
|
7
|
+
export type CoreNextHost = 'claude' | 'codex' | 'grok' | 'fleet-local';
|
|
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
|
|
@@ -28,6 +24,14 @@ export interface CoreNextTarget {
|
|
|
28
24
|
coreNext: string;
|
|
29
25
|
events: readonly string[];
|
|
30
26
|
fallback?: FallbackTarget;
|
|
27
|
+
/** The old dispatcher's hooks the engine does in full, per event (`capabilities --json` `covers`). */
|
|
28
|
+
covers?: Readonly<Record<string, readonly string[]>>;
|
|
29
|
+
/**
|
|
30
|
+
* The host canary gate (US-019 criterion 4): true when `host` may switch
|
|
31
|
+
* events in `root` to this engine. Set by [`coreNextTarget`]; checked by
|
|
32
|
+
* `forHost` (`hook-engine/coverage.ts`) before any event switches.
|
|
33
|
+
*/
|
|
34
|
+
canary?: (root: string, host: CoreNextHost) => boolean;
|
|
31
35
|
}
|
|
32
36
|
/** The target one event is registered to: the new core only for an event it can take. */
|
|
33
37
|
export declare function targetForEvent(target: FallbackTarget | CoreNextTarget, event: string): FallbackTarget | CoreNextTarget;
|
|
@@ -43,7 +47,10 @@ export declare const CAPABILITIES_SCHEMA = "hq-hook.capabilities.v1";
|
|
|
43
47
|
/** What an engine reported: its version and the evaluators it runs per event. */
|
|
44
48
|
export interface EngineCapabilities {
|
|
45
49
|
version: string;
|
|
50
|
+
registrationHosts?: string[];
|
|
46
51
|
events: Record<string, string[]>;
|
|
52
|
+
/** The old dispatcher's hooks the engine does in full, per event; empty for an engine that does not say. */
|
|
53
|
+
covers?: Record<string, string[]>;
|
|
47
54
|
}
|
|
48
55
|
/** Evaluators `event` needs that `caps` lacks; null when the event has no switch rule. */
|
|
49
56
|
export declare function missingEvaluators(caps: EngineCapabilities, event: string): string[] | null;
|
|
@@ -62,8 +69,6 @@ export declare function probeEngine(engine: string): EngineCapabilities;
|
|
|
62
69
|
* new-core registration with nothing to run.
|
|
63
70
|
*/
|
|
64
71
|
export declare function checkStableEngine(stable: string, pinned: string): void;
|
|
65
|
-
/** `core.next` for this machine, person or company, offline. */
|
|
66
|
-
export declare function coreNextEnabled(env?: NodeJS.ProcessEnv): boolean;
|
|
67
72
|
/** The stable path that stands for a pinned engine path. */
|
|
68
73
|
export declare function stableEnginePath(pinned: string, home: string): string;
|
|
69
74
|
/**
|
|
@@ -78,7 +83,28 @@ export interface CoreNextOptions {
|
|
|
78
83
|
platform?: NodeJS.Platform;
|
|
79
84
|
/** Reads the engine's capabilities; `probeEngine` by default. */
|
|
80
85
|
probe?: (engine: string) => EngineCapabilities;
|
|
86
|
+
/** Where gate warnings go (once each); standard error by default. */
|
|
87
|
+
warn?: (message: string) => void;
|
|
88
|
+
}
|
|
89
|
+
/** Why this home stays on shell registrations, or null when engine selection may run. */
|
|
90
|
+
export declare function coreNextOffReason(home: string, env: NodeJS.ProcessEnv, platform: NodeJS.Platform): string | null;
|
|
91
|
+
export type CoreNextEngineLookup = Pick<EngineOptions, 'platform' | 'arch' | 'version' | 'resolvePackage'>;
|
|
92
|
+
export interface CoreNextEngineOptions {
|
|
93
|
+
mode: 'install' | 'read-only';
|
|
94
|
+
platform?: NodeJS.Platform;
|
|
95
|
+
probe?: (engine: string) => EngineCapabilities;
|
|
96
|
+
lookup?: CoreNextEngineLookup;
|
|
81
97
|
}
|
|
98
|
+
export interface CoreNextEngine {
|
|
99
|
+
stable: string;
|
|
100
|
+
pinned: string;
|
|
101
|
+
caps: EngineCapabilities;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The one engine selection. Install links the stable path. Read-only never
|
|
105
|
+
* writes. Both fail when the pinned bundle or the stable link is wrong.
|
|
106
|
+
*/
|
|
107
|
+
export declare function resolveCoreNextEngine(home: string, options: CoreNextEngineOptions): CoreNextEngine;
|
|
82
108
|
/**
|
|
83
109
|
* The new-core target when `core.next` is on, the engine for this CLI is
|
|
84
110
|
* installed, the stable link resolves to it, it runs, and it has every
|
|
@@ -95,9 +121,7 @@ export declare function coreNextTarget(home: string, env?: NodeJS.ProcessEnv, op
|
|
|
95
121
|
* [`coreNextTarget`], with any failure turned into one warning and null, so
|
|
96
122
|
* `hq install` and `hq reindex` go on with the old registrations.
|
|
97
123
|
*/
|
|
98
|
-
export declare function coreNextTargetOrWarn(home: string, env?: NodeJS.ProcessEnv, options?: CoreNextOptions
|
|
99
|
-
warn?: (message: string) => void;
|
|
100
|
-
}): CoreNextTarget | null;
|
|
124
|
+
export declare function coreNextTargetOrWarn(home: string, env?: NodeJS.ProcessEnv, options?: CoreNextOptions): CoreNextTarget | null;
|
|
101
125
|
/** Test hook: forget which warnings were printed. */
|
|
102
126
|
export declare function _resetCoreNextWarningsForTests(): void;
|
|
103
127
|
/** Arguments after the engine path for one host, event and scope. */
|
|
@@ -106,12 +130,51 @@ export declare function coreNextArgs(host: CoreNextHost, event: string, root: st
|
|
|
106
130
|
export declare function coreNextCommand(engine: string, host: CoreNextHost, event: string, root: string, scope: CoreNextScope): string;
|
|
107
131
|
/** PowerShell form, for hosts that run hook commands through PowerShell on Windows. */
|
|
108
132
|
export declare function coreNextCommandWindows(engine: string, host: CoreNextHost, event: string, root: string, scope: CoreNextScope): string;
|
|
133
|
+
type HookEntry = Record<string, unknown>;
|
|
134
|
+
/** What [`placeEvent`] needs to know about one event's registrations in one file. */
|
|
135
|
+
export interface EventOptions {
|
|
136
|
+
/** An HQ shell-side entry for this event: the old dispatcher, the hqd shim or the pinned launcher. */
|
|
137
|
+
isShell: (entry: HookEntry) => boolean;
|
|
138
|
+
/** An HQ new-core entry (`hq-hook run --host ...`) for this HQ root. */
|
|
139
|
+
isNative: (entry: HookEntry) => boolean;
|
|
140
|
+
/** The shell entry wanted in the place of `entry` (a shell entry, or a new-core entry that took its place). */
|
|
141
|
+
toShell: (entry: HookEntry) => HookEntry;
|
|
142
|
+
/**
|
|
143
|
+
* The new-core entry wanted in the place of the shell entry `entry`, when
|
|
144
|
+
* this event switches on this host; null when it stays on the shell.
|
|
145
|
+
*/
|
|
146
|
+
toNative: ((entry: HookEntry) => HookEntry) | null;
|
|
147
|
+
/** A shell entry to add, as its own group at the end, when the event has none left in this file. */
|
|
148
|
+
restore?: HookEntry | null;
|
|
149
|
+
/** Keep only the first HQ entry (user-scope files, which hold one HQ entry per event). */
|
|
150
|
+
single?: boolean;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* One event's hook groups for the registration switch (hq-core-rust US-017,
|
|
154
|
+
* coverage-gated). An event is on exactly one core per file:
|
|
155
|
+
*
|
|
156
|
+
* - It switches (`toNative` given) only when the new core does every hook the
|
|
157
|
+
* old dispatcher runs for it on this host (`hook-engine/coverage.ts`). The
|
|
158
|
+
* new-core entry then takes the shell entry's place, so the engine owns the
|
|
159
|
+
* whole event, and its kill-switch hand-back to the old dispatcher runs the
|
|
160
|
+
* shell hooks exactly once.
|
|
161
|
+
* - Otherwise it stays on the shell: every new-core entry for this root is
|
|
162
|
+
* removed, and one standing where the shell entry was becomes the shell
|
|
163
|
+
* entry again. `restore` adds the shell entry back when it is gone from the
|
|
164
|
+
* file (moved out by an HQ settings merge).
|
|
165
|
+
*
|
|
166
|
+
* Entries keep their place and their extra fields both ways, so switching on
|
|
167
|
+
* and off gives the original bytes back. Groups and entries that are not HQ's
|
|
168
|
+
* stay where they are.
|
|
169
|
+
*/
|
|
170
|
+
export declare function placeEvent(groups: readonly unknown[], options: EventOptions): unknown[];
|
|
109
171
|
/**
|
|
110
172
|
* The Grok Build user hook file (`~/.grok/hooks/hq-hq-bridge.json`) for a
|
|
111
|
-
* target
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
173
|
+
* target (already narrowed to the events the new core covers in full on
|
|
174
|
+
* Grok). With no target it is the shipped source text unchanged. With the new
|
|
175
|
+
* core each entry that calls the bash bridge, on a switched event, calls the
|
|
176
|
+
* engine instead; matchers, timeouts, the other events and every other entry
|
|
177
|
+
* stay as they are.
|
|
115
178
|
*/
|
|
116
179
|
export declare function grokBridgeJson(source: string, root: string, target: CoreNextTarget | null, platform?: NodeJS.Platform): string;
|
|
117
180
|
/**
|
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
* The registration switch (hq-core-rust US-017): which core each host's hook
|
|
3
3
|
* registration calls.
|
|
4
4
|
*
|
|
5
|
-
* Flag `core.next` off (the default): `hq reindex`
|
|
6
|
-
* writes today, byte for byte
|
|
7
|
-
*
|
|
5
|
+
* Flag `core.next` off (the default), or its kill switch on: `hq reindex`
|
|
6
|
+
* writes the registrations it writes today, byte for byte, and removes the
|
|
7
|
+
* new-core entries it added. Flag on: each switched event keeps its shell
|
|
8
|
+
* registration (the old dispatcher still runs every hook with no native port)
|
|
9
|
+
* and gains, beside it, an entry that calls the native entry point directly,
|
|
10
|
+
* with no shell wrapper:
|
|
8
11
|
*
|
|
9
12
|
* <home>/.hq/bin/hq-hook/stable/<binary> run --host <host> <Event> --hq-root <root> [scope]
|
|
10
13
|
*
|
|
@@ -18,6 +21,11 @@
|
|
|
18
21
|
* which carries the server's person, company and machine targeting. No network
|
|
19
22
|
* call: reindex runs from lifecycle hooks.
|
|
20
23
|
*
|
|
24
|
+
* The switch is gated by the host canary (US-019 criterion 4,
|
|
25
|
+
* `hook-engine/canary-gate.ts`): Claude Code, Codex and Grok Build move an
|
|
26
|
+
* event to the new core only with a current passing canary for the engine's
|
|
27
|
+
* version and the root's hq-core gate, unless `HQ_SKIP_HOST_CANARY_GATE=1`.
|
|
28
|
+
*
|
|
21
29
|
* The switch is per event. Before an event is pointed at the new core, the
|
|
22
30
|
* engine behind the stable path is started (`--version`, then `capabilities
|
|
23
31
|
* --json`), and the event switches only when every evaluator it needs
|
|
@@ -25,26 +33,25 @@
|
|
|
25
33
|
* registration it would have with the flag off. Windows keeps the old
|
|
26
34
|
* registrations for every event until US-022.
|
|
27
35
|
*
|
|
28
|
-
* The kill switch
|
|
29
|
-
* `HQ_CORE_NEXT=off` or the file
|
|
30
|
-
* event to the old dispatcher
|
|
36
|
+
* The kill switch is read in two places. The engine
|
|
37
|
+
* (`crates/hq-hook/src/core_next.rs`): `HQ_CORE_NEXT=off` or the file
|
|
38
|
+
* `~/.hq/state/core-next.off` hands the next event to the old dispatcher
|
|
39
|
+
* without a reinstall. And `hq reindex` ([`coreNextKillReason`]): it then
|
|
40
|
+
* removes the new-core entries, so the old dispatcher does not run twice.
|
|
31
41
|
*/
|
|
32
42
|
import { execFileSync } from 'node:child_process';
|
|
33
43
|
import * as fs from 'node:fs';
|
|
34
44
|
import * as path from 'node:path';
|
|
35
|
-
import { readLocalOverride } from '@indigoai-us/hq-flags-client';
|
|
36
|
-
import { readFlagSnapshotFile, readPersonFlagSnapshotFile } from '../lib/flag-snapshot-file.js';
|
|
37
|
-
import { resolveProcessFlagCompanyContext } from '../lib/process-flag-company-context.js';
|
|
38
45
|
import { installHookEngine } from '../lib/hook-engine/resolve.js';
|
|
46
|
+
// Read-only names stay on this namespace. host-registration.test.ts mocks a module that exports only installHookEngine.
|
|
47
|
+
import * as hookEngineResolve from '../lib/hook-engine/resolve.js';
|
|
39
48
|
import { launcherRoot, quotePosix, quoteWindows } from '../lib/hook-engine/registration.js';
|
|
40
49
|
import { openStoreDir } from '../lib/safe-store.js';
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
export
|
|
45
|
-
|
|
46
|
-
export const ENGINE_KILL_ENV = 'HQ_HOOK_ENGINE';
|
|
47
|
-
export const ENGINE_KILL_FILE = path.join('.hq', 'hook-engine.off');
|
|
50
|
+
import { SKIP_CANARY_GATE_ENV, checkHostCanary } from '../lib/hook-engine/canary-gate.js';
|
|
51
|
+
export { CORE_NEXT_FLAG, coreNextEnabled } from './core-next-flag.js';
|
|
52
|
+
import { CORE_NEXT_FLAG, coreNextEnabled } from './core-next-flag.js';
|
|
53
|
+
export { coreNextKillReason, CORE_NEXT_KILL_ENV, CORE_NEXT_KILL_FILE, ENGINE_KILL_ENV, ENGINE_KILL_FILE } from './core-next-kill.js';
|
|
54
|
+
import { coreNextKillReason } from './core-next-kill.js';
|
|
48
55
|
/** Name of the release-stable link next to the pinned engine versions. */
|
|
49
56
|
export const STABLE_LINK_NAME = 'stable';
|
|
50
57
|
/** The target one event is registered to: the new core only for an event it can take. */
|
|
@@ -118,7 +125,14 @@ export function probeEngine(engine) {
|
|
|
118
125
|
for (const [event, ids] of Object.entries(doc.events)) {
|
|
119
126
|
events[event] = Array.isArray(ids) ? ids.filter((id) => typeof id === 'string') : [];
|
|
120
127
|
}
|
|
121
|
-
|
|
128
|
+
const covers = {};
|
|
129
|
+
const reported = doc.covers;
|
|
130
|
+
if (reported && typeof reported === 'object' && !Array.isArray(reported)) {
|
|
131
|
+
for (const [event, ids] of Object.entries(reported)) {
|
|
132
|
+
covers[event] = Array.isArray(ids) ? ids.filter((id) => typeof id === 'string') : [];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return { version: version.slice('hq-hook '.length), events, covers, registrationHosts: doc.registration_hosts };
|
|
122
136
|
}
|
|
123
137
|
/**
|
|
124
138
|
* Check that the stable path resolves to the pinned engine before a
|
|
@@ -138,18 +152,6 @@ export function checkStableEngine(stable, pinned) {
|
|
|
138
152
|
if (!fs.statSync(resolved).isFile())
|
|
139
153
|
throw new Error(`${resolved} is not a file`);
|
|
140
154
|
}
|
|
141
|
-
/** `core.next` for this machine, person or company, offline. */
|
|
142
|
-
export function coreNextEnabled(env = process.env) {
|
|
143
|
-
const override = readLocalOverride(CORE_NEXT_FLAG, env);
|
|
144
|
-
if (override !== null)
|
|
145
|
-
return override;
|
|
146
|
-
const { companyUid: uid, companySlug } = resolveProcessFlagCompanyContext(env);
|
|
147
|
-
// An explicit company slug that does not resolve stays off, as for the launcher flag.
|
|
148
|
-
if (!uid && companySlug)
|
|
149
|
-
return false;
|
|
150
|
-
const snapshot = uid ? readFlagSnapshotFile(uid, { env }) : readPersonFlagSnapshotFile({ env });
|
|
151
|
-
return snapshot?.flags[CORE_NEXT_FLAG] === true;
|
|
152
|
-
}
|
|
153
155
|
function hookEngineDir(home) {
|
|
154
156
|
return path.join(home, '.hq', 'bin', 'hq-hook');
|
|
155
157
|
}
|
|
@@ -257,6 +259,44 @@ function pointsAt(link, folder) {
|
|
|
257
259
|
return false;
|
|
258
260
|
}
|
|
259
261
|
}
|
|
262
|
+
/** Why this home stays on shell registrations, or null when engine selection may run. */
|
|
263
|
+
export function coreNextOffReason(home, env, platform) {
|
|
264
|
+
const killed = coreNextKillReason(home, env);
|
|
265
|
+
if (killed)
|
|
266
|
+
return killed;
|
|
267
|
+
if (platform === 'win32')
|
|
268
|
+
return 'Windows keeps shell registration';
|
|
269
|
+
if (!coreNextEnabled({ ...env, HOME: home, USERPROFILE: home }))
|
|
270
|
+
return 'core.next is off';
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* The one engine selection. Install links the stable path. Read-only never
|
|
275
|
+
* writes. Both fail when the pinned bundle or the stable link is wrong.
|
|
276
|
+
*/
|
|
277
|
+
export function resolveCoreNextEngine(home, options) {
|
|
278
|
+
const platform = options.platform ?? process.platform;
|
|
279
|
+
let pinned;
|
|
280
|
+
let stable;
|
|
281
|
+
if (options.mode === 'install') {
|
|
282
|
+
const installed = installHookEngine(options.lookup ? { ...options.lookup, home } : { home });
|
|
283
|
+
if (!installed)
|
|
284
|
+
throw new Error('the hook engine for this CLI is not installed');
|
|
285
|
+
pinned = installed;
|
|
286
|
+
stable = linkStableEngine(pinned, home, platform);
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
const found = hookEngineResolve.findHookEngine({ ...options.lookup, home });
|
|
290
|
+
if (!found)
|
|
291
|
+
throw new Error('the pinned hook engine is unavailable');
|
|
292
|
+
hookEngineResolve.assertPinnedHookEngineMatches(found);
|
|
293
|
+
pinned = found.pinned;
|
|
294
|
+
stable = stableEnginePath(found.pinned, home);
|
|
295
|
+
}
|
|
296
|
+
checkStableEngine(stable, pinned);
|
|
297
|
+
const caps = (options.probe ?? probeEngine)(stable);
|
|
298
|
+
return { stable, pinned, caps };
|
|
299
|
+
}
|
|
260
300
|
/**
|
|
261
301
|
* The new-core target when `core.next` is on, the engine for this CLI is
|
|
262
302
|
* installed, the stable link resolves to it, it runs, and it has every
|
|
@@ -270,19 +310,44 @@ function pointsAt(link, folder) {
|
|
|
270
310
|
*/
|
|
271
311
|
export function coreNextTarget(home, env = process.env, options = {}) {
|
|
272
312
|
const platform = options.platform ?? process.platform;
|
|
273
|
-
if (
|
|
313
|
+
if (coreNextOffReason(home, env, platform))
|
|
274
314
|
return null;
|
|
275
|
-
|
|
315
|
+
const { stable, caps } = resolveCoreNextEngine(home, { mode: 'install', platform, probe: options.probe });
|
|
316
|
+
const events = capableEvents(caps);
|
|
317
|
+
if (!events.length)
|
|
276
318
|
return null;
|
|
277
|
-
|
|
278
|
-
if (!pinned)
|
|
279
|
-
throw new Error('the hook engine for this CLI is not installed');
|
|
280
|
-
const stable = linkStableEngine(pinned, home, platform);
|
|
281
|
-
checkStableEngine(stable, pinned);
|
|
282
|
-
const events = capableEvents((options.probe ?? probeEngine)(stable));
|
|
283
|
-
return events.length ? { coreNext: stable, events } : null;
|
|
319
|
+
return { coreNext: stable, events, covers: caps.covers ?? {}, canary: hostCanaryGate(home, env, caps.version, platform, options.warn) };
|
|
284
320
|
}
|
|
285
321
|
const warned = new Set();
|
|
322
|
+
function warnOnce(message, warn) {
|
|
323
|
+
if (warned.has(message))
|
|
324
|
+
return;
|
|
325
|
+
warned.add(message);
|
|
326
|
+
(warn ?? ((text) => process.stderr.write(`${text}\n`)))(message);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* The host canary gate for an engine at `version` (hq-core-rust US-019
|
|
330
|
+
* criterion 4, `hook-engine/canary-gate.ts`): Claude Code, Codex and Grok
|
|
331
|
+
* Build switch an event only with a current passing canary for this engine
|
|
332
|
+
* version and the root's hq-core gate. A refusal is one warning and the old
|
|
333
|
+
* registrations on that host. `HQ_SKIP_HOST_CANARY_GATE=1` lets the switch go
|
|
334
|
+
* on, with a warning that names what it bypassed. `fleet-local` is not a host
|
|
335
|
+
* the canary runs and is not gated here.
|
|
336
|
+
*/
|
|
337
|
+
function hostCanaryGate(home, env, version, platform, warn) {
|
|
338
|
+
return (root, host) => {
|
|
339
|
+
if (host === 'fleet-local')
|
|
340
|
+
return true;
|
|
341
|
+
const gate = checkHostCanary({ home, root, host, engineVersion: version, env, platform });
|
|
342
|
+
if (gate.skipped) {
|
|
343
|
+
warnOnce(`hq: warning: ${SKIP_CANARY_GATE_ENV} is set: bypassing the host canary gate and switching ${host} hook events to the new core (hq-hook ${version}) without a passing host canary (${gate.reason})`, warn);
|
|
344
|
+
}
|
|
345
|
+
else if (!gate.allowed) {
|
|
346
|
+
warnOnce(`hq: warning: flag ${CORE_NEXT_FLAG} is on, but ${host} has no passing host canary for hq-hook ${version} and this HQ root (${gate.reason}); keeping the old hook registrations on ${host}. Run scripts/host-canary.mjs --host ${host}, or bypass the gate with hq reindex --skip-host-canary-gate`, warn);
|
|
347
|
+
}
|
|
348
|
+
return gate.allowed;
|
|
349
|
+
};
|
|
350
|
+
}
|
|
286
351
|
/**
|
|
287
352
|
* [`coreNextTarget`], with any failure turned into one warning and null, so
|
|
288
353
|
* `hq install` and `hq reindex` go on with the old registrations.
|
|
@@ -292,11 +357,7 @@ export function coreNextTargetOrWarn(home, env = process.env, options = {}) {
|
|
|
292
357
|
return coreNextTarget(home, env, options);
|
|
293
358
|
}
|
|
294
359
|
catch (error) {
|
|
295
|
-
|
|
296
|
-
if (!warned.has(message)) {
|
|
297
|
-
warned.add(message);
|
|
298
|
-
(options.warn ?? ((text) => process.stderr.write(`${text}\n`)))(message);
|
|
299
|
-
}
|
|
360
|
+
warnOnce(`hq: warning: flag ${CORE_NEXT_FLAG} is on, but the new hook core cannot be used (${error.message}); keeping the old hook registrations`, options.warn);
|
|
300
361
|
return null;
|
|
301
362
|
}
|
|
302
363
|
}
|
|
@@ -318,12 +379,98 @@ export function coreNextCommandWindows(engine, host, event, root, scope) {
|
|
|
318
379
|
return '& ' + [engine, ...coreNextArgs(host, event, root, scope)].map(quoteWindows).join(' ');
|
|
319
380
|
}
|
|
320
381
|
const GROK_BRIDGE_SCRIPT = 'hq-hq-bridge.sh';
|
|
382
|
+
function groupEntries(group) {
|
|
383
|
+
return group && typeof group === 'object' && Array.isArray(group.hooks) ? group.hooks : null;
|
|
384
|
+
}
|
|
385
|
+
function isEntry(value) {
|
|
386
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* One event's hook groups for the registration switch (hq-core-rust US-017,
|
|
390
|
+
* coverage-gated). An event is on exactly one core per file:
|
|
391
|
+
*
|
|
392
|
+
* - It switches (`toNative` given) only when the new core does every hook the
|
|
393
|
+
* old dispatcher runs for it on this host (`hook-engine/coverage.ts`). The
|
|
394
|
+
* new-core entry then takes the shell entry's place, so the engine owns the
|
|
395
|
+
* whole event, and its kill-switch hand-back to the old dispatcher runs the
|
|
396
|
+
* shell hooks exactly once.
|
|
397
|
+
* - Otherwise it stays on the shell: every new-core entry for this root is
|
|
398
|
+
* removed, and one standing where the shell entry was becomes the shell
|
|
399
|
+
* entry again. `restore` adds the shell entry back when it is gone from the
|
|
400
|
+
* file (moved out by an HQ settings merge).
|
|
401
|
+
*
|
|
402
|
+
* Entries keep their place and their extra fields both ways, so switching on
|
|
403
|
+
* and off gives the original bytes back. Groups and entries that are not HQ's
|
|
404
|
+
* stay where they are.
|
|
405
|
+
*/
|
|
406
|
+
export function placeEvent(groups, options) {
|
|
407
|
+
const hasShell = groups.some((group) => groupEntries(group)?.some((entry) => isEntry(entry) && options.isShell(entry)));
|
|
408
|
+
let shellPlaced = hasShell;
|
|
409
|
+
let shellKept = false;
|
|
410
|
+
const out = [];
|
|
411
|
+
for (const group of groups) {
|
|
412
|
+
const entries = groupEntries(group);
|
|
413
|
+
if (!entries) {
|
|
414
|
+
out.push(group);
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
let removed = false;
|
|
418
|
+
const kept = [];
|
|
419
|
+
for (const entry of entries) {
|
|
420
|
+
if (!isEntry(entry)) {
|
|
421
|
+
kept.push(entry);
|
|
422
|
+
}
|
|
423
|
+
else if (options.isShell(entry)) {
|
|
424
|
+
if (options.single && shellKept) {
|
|
425
|
+
removed = true;
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
kept.push(options.toShell(entry));
|
|
429
|
+
shellKept = true;
|
|
430
|
+
}
|
|
431
|
+
else if (options.isNative(entry)) {
|
|
432
|
+
removed = true;
|
|
433
|
+
if (!shellPlaced) {
|
|
434
|
+
kept.push(options.toShell(entry));
|
|
435
|
+
shellPlaced = true;
|
|
436
|
+
shellKept = true;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
kept.push(entry);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
if (kept.length > 0 || !removed)
|
|
444
|
+
out.push({ ...group, hooks: kept });
|
|
445
|
+
}
|
|
446
|
+
if (!shellPlaced && options.restore)
|
|
447
|
+
out.push({ hooks: [options.restore] });
|
|
448
|
+
const toNative = options.toNative;
|
|
449
|
+
if (!toNative)
|
|
450
|
+
return out;
|
|
451
|
+
let switched = false;
|
|
452
|
+
return out.map((group) => {
|
|
453
|
+
const entries = groupEntries(group);
|
|
454
|
+
if (switched || !entries)
|
|
455
|
+
return group;
|
|
456
|
+
return {
|
|
457
|
+
...group,
|
|
458
|
+
hooks: entries.map((entry) => {
|
|
459
|
+
if (switched || !isEntry(entry) || !options.isShell(entry))
|
|
460
|
+
return entry;
|
|
461
|
+
switched = true;
|
|
462
|
+
return toNative(entry);
|
|
463
|
+
}),
|
|
464
|
+
};
|
|
465
|
+
});
|
|
466
|
+
}
|
|
321
467
|
/**
|
|
322
468
|
* The Grok Build user hook file (`~/.grok/hooks/hq-hq-bridge.json`) for a
|
|
323
|
-
* target
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
469
|
+
* target (already narrowed to the events the new core covers in full on
|
|
470
|
+
* Grok). With no target it is the shipped source text unchanged. With the new
|
|
471
|
+
* core each entry that calls the bash bridge, on a switched event, calls the
|
|
472
|
+
* engine instead; matchers, timeouts, the other events and every other entry
|
|
473
|
+
* stay as they are.
|
|
327
474
|
*/
|
|
328
475
|
export function grokBridgeJson(source, root, target, platform = process.platform) {
|
|
329
476
|
if (!target)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indigoai-us/hq-cli",
|
|
3
|
-
"version": "5.345.
|
|
3
|
+
"version": "5.345.219",
|
|
4
4
|
"description": "HQ by Indigo management CLI — modules and cloud sync",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"gen:hq-mcp-tools": "node scripts/generate-hq-mcp-tools.mjs",
|
|
43
43
|
"test:db": "vitest run src/lib/db test/commands/db.test.ts test/commands/db-tenant-isolation.test.ts",
|
|
44
44
|
"test:e2e": "vitest run --config vitest.e2e.config.ts",
|
|
45
|
-
"coverage": "vitest run --coverage --coverage.reporter=text-summary --coverage.reporter=json-summary",
|
|
45
|
+
"coverage": "vitest run --coverage --coverage.reporter=text-summary --coverage.reporter=json-summary --reporter=default --reporter=./scripts/ci/coverage-timing-reporter.mjs",
|
|
46
46
|
"check:lanes-module-cycles": "node scripts/check-lanes-module-cycles.mjs",
|
|
47
47
|
"vitest": "vitest",
|
|
48
48
|
"clean": "rm -rf dist",
|
|
@@ -119,11 +119,11 @@
|
|
|
119
119
|
"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
|
|
120
120
|
},
|
|
121
121
|
"optionalDependencies": {
|
|
122
|
-
"@indigoai-us/hq-hook-win32-x64": "5.345.
|
|
123
|
-
"@indigoai-us/hq-hook-win32-arm64": "5.345.
|
|
124
|
-
"@indigoai-us/hq-hook-darwin-x64": "5.345.
|
|
125
|
-
"@indigoai-us/hq-hook-darwin-arm64": "5.345.
|
|
126
|
-
"@indigoai-us/hq-hook-linux-x64": "5.345.
|
|
127
|
-
"@indigoai-us/hq-hook-linux-arm64": "5.345.
|
|
122
|
+
"@indigoai-us/hq-hook-win32-x64": "5.345.219",
|
|
123
|
+
"@indigoai-us/hq-hook-win32-arm64": "5.345.219",
|
|
124
|
+
"@indigoai-us/hq-hook-darwin-x64": "5.345.219",
|
|
125
|
+
"@indigoai-us/hq-hook-darwin-arm64": "5.345.219",
|
|
126
|
+
"@indigoai-us/hq-hook-linux-x64": "5.345.219",
|
|
127
|
+
"@indigoai-us/hq-hook-linux-arm64": "5.345.219"
|
|
128
128
|
}
|
|
129
129
|
}
|