@indigoai-us/hq-cli 5.345.217 → 5.345.218
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 +27 -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/commands/cloud.d.ts +1 -1
- package/dist/commands/cloud.js +1 -1
- package/dist/commands/core-hq-session-native.js +3 -0
- package/dist/commands/install-global.js +1 -1
- 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/sync-narrow.js +1 -1
- package/dist/commands/team-sync.js +1 -1
- package/dist/data/command-states.json +8 -1
- 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/hook-env.d.ts +32 -0
- package/dist/lib/daemon/hook-env.js +51 -0
- package/dist/lib/daemon/ops/policy.js +5 -3
- package/dist/lib/daemon/run.js +7 -1
- package/dist/lib/doctor/checks/host-core.d.ts +2 -0
- package/dist/lib/doctor/checks/host-core.js +78 -10
- package/dist/lib/doctor/checks/sync-runtime.js +3 -3
- 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/coverage.d.ts +13 -0
- package/dist/lib/hook-engine/coverage.js +124 -0
- package/dist/lib/hook-engine/reconcile.js +294 -114
- package/dist/lib/hook-engine/registration.d.ts +10 -3
- package/dist/lib/hook-engine/registration.js +52 -16
- 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/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/hook-trust.js +4 -1
- package/dist/utils/host-registration.d.ts +57 -4
- package/dist/utils/host-registration.js +140 -13
- package/package.json +7 -7
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import * as path from 'path';
|
|
8
8
|
import { engineArgs, isCoreNextEntry, isNativeEntry } from '../hook-engine/registration.js';
|
|
9
|
-
import { coreNextArgs, targetForEvent } from '../../utils/host-registration.js';
|
|
9
|
+
import { coreNextArgs, placeEvent, targetForEvent } from '../../utils/host-registration.js';
|
|
10
10
|
/** Events master-hook.sh is registered for at user scope. */
|
|
11
11
|
const GLOBAL_HOOK_EVENTS = [
|
|
12
12
|
'SessionStart',
|
|
@@ -151,28 +151,41 @@ export function addHqHooks(doc, hqRoot, target = 'master') {
|
|
|
151
151
|
const hooks = { ...(doc.hooks ?? {}) };
|
|
152
152
|
let changed = false;
|
|
153
153
|
for (const event of GLOBAL_HOOK_EVENTS) {
|
|
154
|
-
// With the new core (US-017), an event it
|
|
155
|
-
// flag-off target
|
|
154
|
+
// With the new core (US-017), an event it does not cover in full keeps
|
|
155
|
+
// the flag-off target; a covered event's new-core entry takes the place of
|
|
156
|
+
// that target's entry (see `placeEvent`). The caller narrows `target` to
|
|
157
|
+
// the covered events (`hook-engine/coverage.ts` `forHost`).
|
|
156
158
|
const t = targetForEvent(target, event);
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
: '
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
const shellTarget = isCoreNext(t) ? (t.fallback ?? 'master') : t;
|
|
160
|
+
const shellWant = typeof shellTarget !== 'object'
|
|
161
|
+
? { type: 'command', command: hookCommand(hqRoot, event, shellTarget), timeout: 300 }
|
|
162
|
+
: { type: 'command', command: shellTarget.engine, args: engineArgs(hqRoot, event, 'claude', true), timeout: 300 };
|
|
163
|
+
const want = isCoreNext(t)
|
|
164
|
+
? { type: 'command', command: t.coreNext, args: coreNextArgs('claude', event, hqRoot, 'global'), timeout: 300 }
|
|
165
|
+
: shellWant;
|
|
162
166
|
let groups = Array.isArray(hooks[event]) ? [...hooks[event]] : [];
|
|
163
|
-
const present = groups.some((g) => Array.isArray(g?.hooks) && g.hooks.some((h) => h.command === want.command && JSON.stringify(h.args) === JSON.stringify('args' in want ? want.args : undefined)));
|
|
164
|
-
if (present)
|
|
165
|
-
continue;
|
|
166
167
|
// To or from the new core, the HQ entry keeps its place among the user's
|
|
167
168
|
// own entries, so their positions (and Codex's position-keyed trust) do
|
|
168
169
|
// not move. Other target swaps keep today's behaviour.
|
|
169
170
|
const inPlace = isCoreNext(target) || groups.some((g) => Array.isArray(g?.hooks) && g.hooks.some((h) => isCoreNextEntry(h, hqRoot)));
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
if (inPlace) {
|
|
172
|
+
const next = placeEvent(groups, {
|
|
173
|
+
isShell: (h) => isHqHookEntry(h, hqRoot) && !isCoreNextEntry(h, hqRoot),
|
|
174
|
+
isNative: (h) => isCoreNextEntry(h, hqRoot),
|
|
175
|
+
toShell: () => shellWant,
|
|
176
|
+
toNative: isCoreNext(t) ? () => want : null,
|
|
177
|
+
restore: shellWant,
|
|
178
|
+
single: true,
|
|
179
|
+
});
|
|
180
|
+
if (JSON.stringify(next) !== JSON.stringify(groups)) {
|
|
181
|
+
hooks[event] = next;
|
|
182
|
+
changed = true;
|
|
183
|
+
}
|
|
174
184
|
continue;
|
|
175
185
|
}
|
|
186
|
+
const present = groups.some((g) => Array.isArray(g?.hooks) && g.hooks.some((h) => h.command === want.command && JSON.stringify(h.args) === JSON.stringify('args' in want ? want.args : undefined)));
|
|
187
|
+
if (present)
|
|
188
|
+
continue;
|
|
176
189
|
groups = removeHqHooks({ hooks: { [event]: groups } }, hqRoot).hooks?.[event] ?? [];
|
|
177
190
|
groups.push({ hooks: [want] });
|
|
178
191
|
hooks[event] = groups;
|
|
@@ -204,7 +204,7 @@ export function syncCodexPackHooks(packDir, items, remove = false, home = os.hom
|
|
|
204
204
|
return;
|
|
205
205
|
const target = hooksPath(home);
|
|
206
206
|
if (hqRoot && sharedAnywherePack) {
|
|
207
|
-
const hookTarget = hookTargetFor(hqRoot, home);
|
|
207
|
+
const hookTarget = hookTargetFor(hqRoot, home, undefined, process.env, 'codex');
|
|
208
208
|
writeConfigAtomic({
|
|
209
209
|
target,
|
|
210
210
|
pack: 'hq-anywhere',
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
import * as fs from 'fs';
|
|
13
13
|
import { engineArgs, isCoreNextEntry, isNativeEntry, quotePosix, quoteWindows } from '../hook-engine/registration.js';
|
|
14
14
|
import * as path from 'path';
|
|
15
|
-
import {
|
|
16
|
-
import { coreNextCommand, coreNextCommandWindows, targetForEvent } from '../../utils/host-registration.js';
|
|
15
|
+
import { shimPath } from './claude-targets.js';
|
|
16
|
+
import { coreNextCommand, coreNextCommandWindows, placeEvent, targetForEvent } from '../../utils/host-registration.js';
|
|
17
17
|
/** Events the Codex hook adapter is registered for at user scope. */
|
|
18
18
|
const CODEX_HOOK_EVENTS = [
|
|
19
19
|
'SessionStart',
|
|
@@ -212,20 +212,33 @@ export function addCodexHooks(doc, hqRoot, target = 'master') {
|
|
|
212
212
|
for (const event of CODEX_HOOK_EVENTS) {
|
|
213
213
|
const want = codexUserHookEntry(hqRoot, event, target);
|
|
214
214
|
let groups = Array.isArray(hooks[event]) ? [...hooks[event]] : [];
|
|
215
|
-
const present = groups.some((g) => Array.isArray(g?.hooks) && g.hooks.some((h) => h.command === want.command && h.commandWindows === ('commandWindows' in want ? want.commandWindows : undefined)));
|
|
216
|
-
if (present)
|
|
217
|
-
continue;
|
|
218
215
|
// To or from the new core, the HQ entry keeps its place: Codex keys a
|
|
219
216
|
// user's trust of each hook by its position, so moving HQ's entry behind
|
|
220
|
-
// the user's own would drop the user's trust.
|
|
221
|
-
//
|
|
217
|
+
// the user's own would drop the user's trust. Only an event the new core
|
|
218
|
+
// covers in full switches (the caller narrows `target`); the others keep
|
|
219
|
+
// the adapter entry. Other target swaps keep today's behaviour.
|
|
222
220
|
const inPlace = (typeof target === 'object' && 'coreNext' in target) || groups.some((g) => Array.isArray(g?.hooks) && g.hooks.some((h) => isCoreNextEntry(h, hqRoot)));
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
221
|
+
if (inPlace) {
|
|
222
|
+
const t = targetForEvent(target, event);
|
|
223
|
+
const switched = typeof t === 'object' && 'coreNext' in t;
|
|
224
|
+
const shellWant = switched ? codexUserHookEntry(hqRoot, event, t.fallback ?? 'master') : want;
|
|
225
|
+
const next = placeEvent(groups, {
|
|
226
|
+
isShell: (h) => isAdapterEntry(h, hqRoot) && !isCoreNextEntry(h, hqRoot),
|
|
227
|
+
isNative: (h) => isCoreNextEntry(h, hqRoot),
|
|
228
|
+
toShell: () => shellWant,
|
|
229
|
+
toNative: switched ? () => want : null,
|
|
230
|
+
restore: shellWant,
|
|
231
|
+
single: true,
|
|
232
|
+
});
|
|
233
|
+
if (JSON.stringify(next) !== JSON.stringify(groups)) {
|
|
234
|
+
hooks[event] = next;
|
|
235
|
+
changed = true;
|
|
236
|
+
}
|
|
227
237
|
continue;
|
|
228
238
|
}
|
|
239
|
+
const present = groups.some((g) => Array.isArray(g?.hooks) && g.hooks.some((h) => h.command === want.command && h.commandWindows === ('commandWindows' in want ? want.commandWindows : undefined)));
|
|
240
|
+
if (present)
|
|
241
|
+
continue;
|
|
229
242
|
groups = removeCodexHooks({ hooks: { [event]: groups } }, hqRoot).hooks?.[event] ?? [];
|
|
230
243
|
groups.push({ hooks: [want] });
|
|
231
244
|
hooks[event] = groups;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type FallbackTarget } from '../../utils/host-registration.js';
|
|
1
|
+
import { type CoreNextHost, type FallbackTarget } from '../../utils/host-registration.js';
|
|
2
2
|
import { type HookTarget } from './claude-targets.js';
|
|
3
3
|
/**
|
|
4
4
|
* True when this user's hq daemon unit (launchd plist, systemd unit, or the
|
|
@@ -10,7 +10,7 @@ export declare function isDaemonInstalled(home: string, platform?: NodeJS.Platfo
|
|
|
10
10
|
* US-010: with hqd installed (and the checkout shipping the shim), hooks go to
|
|
11
11
|
* the hqd shim; otherwise to master-hook.sh / the Codex adapter.
|
|
12
12
|
*/
|
|
13
|
-
export declare function hookTargetFor(hqRoot: string, home: string, daemonInstalled?: boolean, env?: NodeJS.ProcessEnv): HookTarget;
|
|
13
|
+
export declare function hookTargetFor(hqRoot: string, home: string, daemonInstalled?: boolean, env?: NodeJS.ProcessEnv, host?: CoreNextHost): HookTarget;
|
|
14
14
|
/** The target with `core.next` off: the pinned launcher, the hqd shim, or master-hook.sh. */
|
|
15
15
|
export declare function legacyHookTarget(hqRoot: string, home: string, daemonInstalled?: boolean, env?: NodeJS.ProcessEnv): FallbackTarget;
|
|
16
16
|
//# sourceMappingURL=hook-target.d.ts.map
|
|
@@ -13,6 +13,7 @@ import { readDaemonConfig } from '../daemon/config.js';
|
|
|
13
13
|
import { daemonPaths } from '../daemon/paths.js';
|
|
14
14
|
import { registrationEngine } from '../hook-engine/registration.js';
|
|
15
15
|
import { coreNextTargetOrWarn } from '../../utils/host-registration.js';
|
|
16
|
+
import { forHost } from '../hook-engine/coverage.js';
|
|
16
17
|
import { shimPath } from './claude-targets.js';
|
|
17
18
|
/**
|
|
18
19
|
* True when this user's hq daemon unit (launchd plist, systemd unit, or the
|
|
@@ -33,12 +34,13 @@ export function isDaemonInstalled(home, platform = process.platform, queryTask =
|
|
|
33
34
|
* US-010: with hqd installed (and the checkout shipping the shim), hooks go to
|
|
34
35
|
* the hqd shim; otherwise to master-hook.sh / the Codex adapter.
|
|
35
36
|
*/
|
|
36
|
-
export function hookTargetFor(hqRoot, home, daemonInstalled, env = process.env) {
|
|
37
|
+
export function hookTargetFor(hqRoot, home, daemonInstalled, env = process.env, host = 'claude') {
|
|
37
38
|
// hq-core-rust US-017: `core.next` on registers the new core's entry point
|
|
38
|
-
// for the events it
|
|
39
|
-
// A failure to set up the new core
|
|
40
|
-
// with the flag-off target for every
|
|
41
|
-
|
|
39
|
+
// for the events it covers in full on this host in this HQ root; every
|
|
40
|
+
// other event keeps the flag-off target. A failure to set up the new core
|
|
41
|
+
// is one warning, and install goes on with the flag-off target for every
|
|
42
|
+
// event.
|
|
43
|
+
const coreNext = forHost(coreNextTargetOrWarn(home, env), hqRoot, host);
|
|
42
44
|
const fallback = legacyHookTarget(hqRoot, home, daemonInstalled, env);
|
|
43
45
|
return coreNext ? { ...coreNext, fallback } : fallback;
|
|
44
46
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* A pack that declares one can be set up from the HQ app chat: the pack's own
|
|
6
6
|
* bot (`setup.bot.name`, also a worker under `contributes.workers`) asks the
|
|
7
7
|
* questions in order with tap-to-answer suggestions, then runs `setup.run`
|
|
8
|
-
* with the answers. `hq
|
|
8
|
+
* with the answers. `hq install` validates the block and fails naming
|
|
9
9
|
* the field; a pack without the block is untouched.
|
|
10
10
|
*
|
|
11
11
|
* Validation (contract):
|
|
@@ -37,7 +37,7 @@ export interface SetupBlockContext {
|
|
|
37
37
|
export declare function parseSetupBlock(raw: unknown, ctx: SetupBlockContext): PackSetup | undefined;
|
|
38
38
|
/**
|
|
39
39
|
* The validated setup block of an installed pack, or undefined when the pack
|
|
40
|
-
* has none or the block is invalid (`hq
|
|
40
|
+
* has none or the block is invalid (`hq packs list` prints `setup: no`).
|
|
41
41
|
*/
|
|
42
42
|
export declare function readInstalledPackSetup(manifest: Pick<PackManifest, "setup" | "contributes"> | null | undefined, packDir: string, existsSync?: (p: string) => boolean): PackSetup | undefined;
|
|
43
43
|
//# sourceMappingURL=setup-block.d.ts.map
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* A pack that declares one can be set up from the HQ app chat: the pack's own
|
|
6
6
|
* bot (`setup.bot.name`, also a worker under `contributes.workers`) asks the
|
|
7
7
|
* questions in order with tap-to-answer suggestions, then runs `setup.run`
|
|
8
|
-
* with the answers. `hq
|
|
8
|
+
* with the answers. `hq install` validates the block and fails naming
|
|
9
9
|
* the field; a pack without the block is untouched.
|
|
10
10
|
*
|
|
11
11
|
* Validation (contract):
|
|
@@ -217,7 +217,7 @@ export function parseSetupBlock(raw, ctx) {
|
|
|
217
217
|
}
|
|
218
218
|
/**
|
|
219
219
|
* The validated setup block of an installed pack, or undefined when the pack
|
|
220
|
-
* has none or the block is invalid (`hq
|
|
220
|
+
* has none or the block is invalid (`hq packs list` prints `setup: no`).
|
|
221
221
|
*/
|
|
222
222
|
export function readInstalledPackSetup(manifest, packDir, existsSync) {
|
|
223
223
|
if (!manifest || manifest.setup === undefined)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `hq
|
|
2
|
+
* `hq install <source> --start-bot` (sample-pack-in-app-setup US-003,
|
|
3
3
|
* build contract section 3).
|
|
4
4
|
*
|
|
5
5
|
* After a pack with a valid `setup:` block is wired, create the personal bot
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `hq
|
|
2
|
+
* `hq install <source> --start-bot` (sample-pack-in-app-setup US-003,
|
|
3
3
|
* build contract section 3).
|
|
4
4
|
*
|
|
5
5
|
* After a pack with a valid `setup:` block is wired, create the personal bot
|
package/dist/main.js
CHANGED
|
@@ -231,7 +231,7 @@ export async function runCli() {
|
|
|
231
231
|
// Login must be usable before any identity or company is available, so do
|
|
232
232
|
// not make a pre-auth feature-flag request on this path. Other commands
|
|
233
233
|
// retain the shared asynchronous registry refresh.
|
|
234
|
-
const isAuthLogin = process.argv[2] === "auth" && process.argv[3] === "login";
|
|
234
|
+
const isAuthLogin = process.argv[2] === "login" || (process.argv[2] === "auth" && process.argv[3] === "login");
|
|
235
235
|
if (!isAuthLogin) {
|
|
236
236
|
runGlobalNetworkLifecycle(process.argv, () => {
|
|
237
237
|
void kickFlagRegistryReadiness({
|
package/dist/types.d.ts
CHANGED
|
@@ -130,7 +130,7 @@ export interface PackManifest {
|
|
|
130
130
|
/**
|
|
131
131
|
* Guided in-app setup. Optional — absent on
|
|
132
132
|
* legacy packs, which install unchanged. Validated by
|
|
133
|
-
* `lib/packages/setup-block.ts`; `hq
|
|
133
|
+
* `lib/packages/setup-block.ts`; `hq install --start-bot` creates the
|
|
134
134
|
* bot it names and the bot's system prompt renders the questions and the run
|
|
135
135
|
* command from it.
|
|
136
136
|
*/
|
|
@@ -8,7 +8,7 @@ export declare const DEFAULT_CALLBACK_PORT = 8765;
|
|
|
8
8
|
export declare function callbackPortBusyGuidance(port: number): string;
|
|
9
9
|
/**
|
|
10
10
|
* The LOOSE predicate for a caller that just invoked browserLogin and is
|
|
11
|
-
* catching its own error (`hq
|
|
11
|
+
* catching its own error (`hq login`): an EADDRINUSE by errno
|
|
12
12
|
* code OR message is the callback-port collision, because the callback server is
|
|
13
13
|
* the only listener that call could have opened. NOT for the shared boundary —
|
|
14
14
|
* use {@link callbackPortBusyMessage} there.
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
// address already in use 127.0.0.1:8765`. That Node error carries no `expected`
|
|
22
22
|
// flag and is not an AuthError/CognitoAuthError/…, so every predicate in
|
|
23
23
|
// handleTopLevelError returned false and the collision was captured as a
|
|
24
|
-
// high-priority, unfixable "crash". `hq
|
|
24
|
+
// high-priority, unfixable "crash". `hq login` already classified the
|
|
25
25
|
// identical condition in a file-private helper; this module lifts that
|
|
26
26
|
// classification to the shared boundary so every implicit call site is covered
|
|
27
27
|
// from one source of truth.
|
|
28
28
|
//
|
|
29
29
|
// Two predicates, differing ONLY by how much context the caller already has:
|
|
30
30
|
// - isCallbackPortBusy(err): the LOOSE form for a call site that KNOWS it just
|
|
31
|
-
// invoked browserLogin (`hq
|
|
31
|
+
// invoked browserLogin (`hq login`). There the only listener
|
|
32
32
|
// in play is the callback server, so an EADDRINUSE — by code or message — is
|
|
33
33
|
// unambiguously the callback port.
|
|
34
34
|
// - callbackPortBusyMessage(err, port): the STRUCTURAL form for the shared
|
|
@@ -47,12 +47,12 @@ const EADDRINUSE = "EADDRINUSE";
|
|
|
47
47
|
*/
|
|
48
48
|
export function callbackPortBusyGuidance(port) {
|
|
49
49
|
return (`The browser-login callback port (127.0.0.1:${port}) is already in use. ` +
|
|
50
|
-
"Another `hq
|
|
50
|
+
"Another `hq login` may still be waiting for browser sign-in. Finish that login, " +
|
|
51
51
|
"or stop its terminal/process, then retry.");
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* The LOOSE predicate for a caller that just invoked browserLogin and is
|
|
55
|
-
* catching its own error (`hq
|
|
55
|
+
* catching its own error (`hq login`): an EADDRINUSE by errno
|
|
56
56
|
* code OR message is the callback-port collision, because the callback server is
|
|
57
57
|
* the only listener that call could have opened. NOT for the shared boundary —
|
|
58
58
|
* use {@link callbackPortBusyMessage} there.
|
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`);
|
|
@@ -28,6 +28,8 @@ export interface CoreNextTarget {
|
|
|
28
28
|
coreNext: string;
|
|
29
29
|
events: readonly string[];
|
|
30
30
|
fallback?: FallbackTarget;
|
|
31
|
+
/** The old dispatcher's hooks the engine does in full, per event (`capabilities --json` `covers`). */
|
|
32
|
+
covers?: Readonly<Record<string, readonly string[]>>;
|
|
31
33
|
}
|
|
32
34
|
/** The target one event is registered to: the new core only for an event it can take. */
|
|
33
35
|
export declare function targetForEvent(target: FallbackTarget | CoreNextTarget, event: string): FallbackTarget | CoreNextTarget;
|
|
@@ -44,6 +46,8 @@ export declare const CAPABILITIES_SCHEMA = "hq-hook.capabilities.v1";
|
|
|
44
46
|
export interface EngineCapabilities {
|
|
45
47
|
version: string;
|
|
46
48
|
events: Record<string, string[]>;
|
|
49
|
+
/** The old dispatcher's hooks the engine does in full, per event; empty for an engine that does not say. */
|
|
50
|
+
covers?: Record<string, string[]>;
|
|
47
51
|
}
|
|
48
52
|
/** Evaluators `event` needs that `caps` lacks; null when the event has no switch rule. */
|
|
49
53
|
export declare function missingEvaluators(caps: EngineCapabilities, event: string): string[] | null;
|
|
@@ -62,6 +66,15 @@ export declare function probeEngine(engine: string): EngineCapabilities;
|
|
|
62
66
|
* new-core registration with nothing to run.
|
|
63
67
|
*/
|
|
64
68
|
export declare function checkStableEngine(stable: string, pinned: string): void;
|
|
69
|
+
/**
|
|
70
|
+
* Why the new core is switched off on this machine, or null. The same four
|
|
71
|
+
* switches the engine reads (`crates/hq-hook/src/core_next.rs` `kill_reason`):
|
|
72
|
+
* `HQ_CORE_NEXT=off|0|false|no`, `HQ_HOOK_ENGINE=off`, and the files
|
|
73
|
+
* `~/.hq/state/core-next.off` and `~/.hq/hook-engine.off` (a link counts, as
|
|
74
|
+
* for the engine). With any of them on, `hq reindex` removes the new-core
|
|
75
|
+
* entries it added, so the registrations are what they were before the switch.
|
|
76
|
+
*/
|
|
77
|
+
export declare function coreNextKillReason(home: string, env?: NodeJS.ProcessEnv): string | null;
|
|
65
78
|
/** `core.next` for this machine, person or company, offline. */
|
|
66
79
|
export declare function coreNextEnabled(env?: NodeJS.ProcessEnv): boolean;
|
|
67
80
|
/** The stable path that stands for a pinned engine path. */
|
|
@@ -106,12 +119,51 @@ export declare function coreNextArgs(host: CoreNextHost, event: string, root: st
|
|
|
106
119
|
export declare function coreNextCommand(engine: string, host: CoreNextHost, event: string, root: string, scope: CoreNextScope): string;
|
|
107
120
|
/** PowerShell form, for hosts that run hook commands through PowerShell on Windows. */
|
|
108
121
|
export declare function coreNextCommandWindows(engine: string, host: CoreNextHost, event: string, root: string, scope: CoreNextScope): string;
|
|
122
|
+
type HookEntry = Record<string, unknown>;
|
|
123
|
+
/** What [`placeEvent`] needs to know about one event's registrations in one file. */
|
|
124
|
+
export interface EventOptions {
|
|
125
|
+
/** An HQ shell-side entry for this event: the old dispatcher, the hqd shim or the pinned launcher. */
|
|
126
|
+
isShell: (entry: HookEntry) => boolean;
|
|
127
|
+
/** An HQ new-core entry (`hq-hook run --host ...`) for this HQ root. */
|
|
128
|
+
isNative: (entry: HookEntry) => boolean;
|
|
129
|
+
/** The shell entry wanted in the place of `entry` (a shell entry, or a new-core entry that took its place). */
|
|
130
|
+
toShell: (entry: HookEntry) => HookEntry;
|
|
131
|
+
/**
|
|
132
|
+
* The new-core entry wanted in the place of the shell entry `entry`, when
|
|
133
|
+
* this event switches on this host; null when it stays on the shell.
|
|
134
|
+
*/
|
|
135
|
+
toNative: ((entry: HookEntry) => HookEntry) | null;
|
|
136
|
+
/** A shell entry to add, as its own group at the end, when the event has none left in this file. */
|
|
137
|
+
restore?: HookEntry | null;
|
|
138
|
+
/** Keep only the first HQ entry (user-scope files, which hold one HQ entry per event). */
|
|
139
|
+
single?: boolean;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* One event's hook groups for the registration switch (hq-core-rust US-017,
|
|
143
|
+
* coverage-gated). An event is on exactly one core per file:
|
|
144
|
+
*
|
|
145
|
+
* - It switches (`toNative` given) only when the new core does every hook the
|
|
146
|
+
* old dispatcher runs for it on this host (`hook-engine/coverage.ts`). The
|
|
147
|
+
* new-core entry then takes the shell entry's place, so the engine owns the
|
|
148
|
+
* whole event, and its kill-switch hand-back to the old dispatcher runs the
|
|
149
|
+
* shell hooks exactly once.
|
|
150
|
+
* - Otherwise it stays on the shell: every new-core entry for this root is
|
|
151
|
+
* removed, and one standing where the shell entry was becomes the shell
|
|
152
|
+
* entry again. `restore` adds the shell entry back when it is gone from the
|
|
153
|
+
* file (moved out by an HQ settings merge).
|
|
154
|
+
*
|
|
155
|
+
* Entries keep their place and their extra fields both ways, so switching on
|
|
156
|
+
* and off gives the original bytes back. Groups and entries that are not HQ's
|
|
157
|
+
* stay where they are.
|
|
158
|
+
*/
|
|
159
|
+
export declare function placeEvent(groups: readonly unknown[], options: EventOptions): unknown[];
|
|
109
160
|
/**
|
|
110
161
|
* The Grok Build user hook file (`~/.grok/hooks/hq-hq-bridge.json`) for a
|
|
111
|
-
* target
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
162
|
+
* target (already narrowed to the events the new core covers in full on
|
|
163
|
+
* Grok). With no target it is the shipped source text unchanged. With the new
|
|
164
|
+
* core each entry that calls the bash bridge, on a switched event, calls the
|
|
165
|
+
* engine instead; matchers, timeouts, the other events and every other entry
|
|
166
|
+
* stay as they are.
|
|
115
167
|
*/
|
|
116
168
|
export declare function grokBridgeJson(source: string, root: string, target: CoreNextTarget | null, platform?: NodeJS.Platform): string;
|
|
117
169
|
/**
|
|
@@ -123,4 +175,5 @@ export declare function grokBridgeJson(source: string, root: string, target: Cor
|
|
|
123
175
|
* Throws on any refusal; the caller keeps the current file.
|
|
124
176
|
*/
|
|
125
177
|
export declare function replaceFileNoFollow(file: string, content: string, home?: string): void;
|
|
178
|
+
export {};
|
|
126
179
|
//# sourceMappingURL=host-registration.d.ts.map
|
|
@@ -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
|
*
|
|
@@ -25,9 +28,11 @@
|
|
|
25
28
|
* registration it would have with the flag off. Windows keeps the old
|
|
26
29
|
* registrations for every event until US-022.
|
|
27
30
|
*
|
|
28
|
-
* The kill switch
|
|
29
|
-
* `HQ_CORE_NEXT=off` or the file
|
|
30
|
-
* event to the old dispatcher
|
|
31
|
+
* The kill switch is read in two places. The engine
|
|
32
|
+
* (`crates/hq-hook/src/core_next.rs`): `HQ_CORE_NEXT=off` or the file
|
|
33
|
+
* `~/.hq/state/core-next.off` hands the next event to the old dispatcher
|
|
34
|
+
* without a reinstall. And `hq reindex` ([`coreNextKillReason`]): it then
|
|
35
|
+
* removes the new-core entries, so the old dispatcher does not run twice.
|
|
31
36
|
*/
|
|
32
37
|
import { execFileSync } from 'node:child_process';
|
|
33
38
|
import * as fs from 'node:fs';
|
|
@@ -118,7 +123,14 @@ export function probeEngine(engine) {
|
|
|
118
123
|
for (const [event, ids] of Object.entries(doc.events)) {
|
|
119
124
|
events[event] = Array.isArray(ids) ? ids.filter((id) => typeof id === 'string') : [];
|
|
120
125
|
}
|
|
121
|
-
|
|
126
|
+
const covers = {};
|
|
127
|
+
const reported = doc.covers;
|
|
128
|
+
if (reported && typeof reported === 'object' && !Array.isArray(reported)) {
|
|
129
|
+
for (const [event, ids] of Object.entries(reported)) {
|
|
130
|
+
covers[event] = Array.isArray(ids) ? ids.filter((id) => typeof id === 'string') : [];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return { version: version.slice('hq-hook '.length), events, covers };
|
|
122
134
|
}
|
|
123
135
|
/**
|
|
124
136
|
* Check that the stable path resolves to the pinned engine before a
|
|
@@ -138,6 +150,31 @@ export function checkStableEngine(stable, pinned) {
|
|
|
138
150
|
if (!fs.statSync(resolved).isFile())
|
|
139
151
|
throw new Error(`${resolved} is not a file`);
|
|
140
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Why the new core is switched off on this machine, or null. The same four
|
|
155
|
+
* switches the engine reads (`crates/hq-hook/src/core_next.rs` `kill_reason`):
|
|
156
|
+
* `HQ_CORE_NEXT=off|0|false|no`, `HQ_HOOK_ENGINE=off`, and the files
|
|
157
|
+
* `~/.hq/state/core-next.off` and `~/.hq/hook-engine.off` (a link counts, as
|
|
158
|
+
* for the engine). With any of them on, `hq reindex` removes the new-core
|
|
159
|
+
* entries it added, so the registrations are what they were before the switch.
|
|
160
|
+
*/
|
|
161
|
+
export function coreNextKillReason(home, env = process.env) {
|
|
162
|
+
const coreNextEnv = (env[CORE_NEXT_KILL_ENV] ?? '').trim();
|
|
163
|
+
if (/^(off|0|false|no)$/i.test(coreNextEnv))
|
|
164
|
+
return `${CORE_NEXT_KILL_ENV}=${env[CORE_NEXT_KILL_ENV]}`;
|
|
165
|
+
if (/^off$/i.test((env[ENGINE_KILL_ENV] ?? '').trim()))
|
|
166
|
+
return `${ENGINE_KILL_ENV}=${env[ENGINE_KILL_ENV]}`;
|
|
167
|
+
for (const file of [path.join(home, CORE_NEXT_KILL_FILE), path.join(home, ENGINE_KILL_FILE)]) {
|
|
168
|
+
try {
|
|
169
|
+
fs.lstatSync(file);
|
|
170
|
+
return file;
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
// Absent: this switch is off.
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
141
178
|
/** `core.next` for this machine, person or company, offline. */
|
|
142
179
|
export function coreNextEnabled(env = process.env) {
|
|
143
180
|
const override = readLocalOverride(CORE_NEXT_FLAG, env);
|
|
@@ -272,6 +309,9 @@ export function coreNextTarget(home, env = process.env, options = {}) {
|
|
|
272
309
|
const platform = options.platform ?? process.platform;
|
|
273
310
|
if (platform === 'win32')
|
|
274
311
|
return null;
|
|
312
|
+
// The kill switch rolls the registrations back as well as the next event.
|
|
313
|
+
if (coreNextKillReason(home, env))
|
|
314
|
+
return null;
|
|
275
315
|
if (!coreNextEnabled({ ...env, HOME: home, USERPROFILE: home }))
|
|
276
316
|
return null;
|
|
277
317
|
const pinned = installHookEngine({ home });
|
|
@@ -279,8 +319,9 @@ export function coreNextTarget(home, env = process.env, options = {}) {
|
|
|
279
319
|
throw new Error('the hook engine for this CLI is not installed');
|
|
280
320
|
const stable = linkStableEngine(pinned, home, platform);
|
|
281
321
|
checkStableEngine(stable, pinned);
|
|
282
|
-
const
|
|
283
|
-
|
|
322
|
+
const caps = (options.probe ?? probeEngine)(stable);
|
|
323
|
+
const events = capableEvents(caps);
|
|
324
|
+
return events.length ? { coreNext: stable, events, covers: caps.covers ?? {} } : null;
|
|
284
325
|
}
|
|
285
326
|
const warned = new Set();
|
|
286
327
|
/**
|
|
@@ -318,12 +359,98 @@ export function coreNextCommandWindows(engine, host, event, root, scope) {
|
|
|
318
359
|
return '& ' + [engine, ...coreNextArgs(host, event, root, scope)].map(quoteWindows).join(' ');
|
|
319
360
|
}
|
|
320
361
|
const GROK_BRIDGE_SCRIPT = 'hq-hq-bridge.sh';
|
|
362
|
+
function groupEntries(group) {
|
|
363
|
+
return group && typeof group === 'object' && Array.isArray(group.hooks) ? group.hooks : null;
|
|
364
|
+
}
|
|
365
|
+
function isEntry(value) {
|
|
366
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* One event's hook groups for the registration switch (hq-core-rust US-017,
|
|
370
|
+
* coverage-gated). An event is on exactly one core per file:
|
|
371
|
+
*
|
|
372
|
+
* - It switches (`toNative` given) only when the new core does every hook the
|
|
373
|
+
* old dispatcher runs for it on this host (`hook-engine/coverage.ts`). The
|
|
374
|
+
* new-core entry then takes the shell entry's place, so the engine owns the
|
|
375
|
+
* whole event, and its kill-switch hand-back to the old dispatcher runs the
|
|
376
|
+
* shell hooks exactly once.
|
|
377
|
+
* - Otherwise it stays on the shell: every new-core entry for this root is
|
|
378
|
+
* removed, and one standing where the shell entry was becomes the shell
|
|
379
|
+
* entry again. `restore` adds the shell entry back when it is gone from the
|
|
380
|
+
* file (moved out by an HQ settings merge).
|
|
381
|
+
*
|
|
382
|
+
* Entries keep their place and their extra fields both ways, so switching on
|
|
383
|
+
* and off gives the original bytes back. Groups and entries that are not HQ's
|
|
384
|
+
* stay where they are.
|
|
385
|
+
*/
|
|
386
|
+
export function placeEvent(groups, options) {
|
|
387
|
+
const hasShell = groups.some((group) => groupEntries(group)?.some((entry) => isEntry(entry) && options.isShell(entry)));
|
|
388
|
+
let shellPlaced = hasShell;
|
|
389
|
+
let shellKept = false;
|
|
390
|
+
const out = [];
|
|
391
|
+
for (const group of groups) {
|
|
392
|
+
const entries = groupEntries(group);
|
|
393
|
+
if (!entries) {
|
|
394
|
+
out.push(group);
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
let removed = false;
|
|
398
|
+
const kept = [];
|
|
399
|
+
for (const entry of entries) {
|
|
400
|
+
if (!isEntry(entry)) {
|
|
401
|
+
kept.push(entry);
|
|
402
|
+
}
|
|
403
|
+
else if (options.isShell(entry)) {
|
|
404
|
+
if (options.single && shellKept) {
|
|
405
|
+
removed = true;
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
kept.push(options.toShell(entry));
|
|
409
|
+
shellKept = true;
|
|
410
|
+
}
|
|
411
|
+
else if (options.isNative(entry)) {
|
|
412
|
+
removed = true;
|
|
413
|
+
if (!shellPlaced) {
|
|
414
|
+
kept.push(options.toShell(entry));
|
|
415
|
+
shellPlaced = true;
|
|
416
|
+
shellKept = true;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
kept.push(entry);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
if (kept.length > 0 || !removed)
|
|
424
|
+
out.push({ ...group, hooks: kept });
|
|
425
|
+
}
|
|
426
|
+
if (!shellPlaced && options.restore)
|
|
427
|
+
out.push({ hooks: [options.restore] });
|
|
428
|
+
const toNative = options.toNative;
|
|
429
|
+
if (!toNative)
|
|
430
|
+
return out;
|
|
431
|
+
let switched = false;
|
|
432
|
+
return out.map((group) => {
|
|
433
|
+
const entries = groupEntries(group);
|
|
434
|
+
if (switched || !entries)
|
|
435
|
+
return group;
|
|
436
|
+
return {
|
|
437
|
+
...group,
|
|
438
|
+
hooks: entries.map((entry) => {
|
|
439
|
+
if (switched || !isEntry(entry) || !options.isShell(entry))
|
|
440
|
+
return entry;
|
|
441
|
+
switched = true;
|
|
442
|
+
return toNative(entry);
|
|
443
|
+
}),
|
|
444
|
+
};
|
|
445
|
+
});
|
|
446
|
+
}
|
|
321
447
|
/**
|
|
322
448
|
* The Grok Build user hook file (`~/.grok/hooks/hq-hq-bridge.json`) for a
|
|
323
|
-
* target
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
449
|
+
* target (already narrowed to the events the new core covers in full on
|
|
450
|
+
* Grok). With no target it is the shipped source text unchanged. With the new
|
|
451
|
+
* core each entry that calls the bash bridge, on a switched event, calls the
|
|
452
|
+
* engine instead; matchers, timeouts, the other events and every other entry
|
|
453
|
+
* stay as they are.
|
|
327
454
|
*/
|
|
328
455
|
export function grokBridgeJson(source, root, target, platform = process.platform) {
|
|
329
456
|
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.218",
|
|
4
4
|
"description": "HQ by Indigo management CLI — modules and cloud sync",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -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.218",
|
|
123
|
+
"@indigoai-us/hq-hook-win32-arm64": "5.345.218",
|
|
124
|
+
"@indigoai-us/hq-hook-darwin-x64": "5.345.218",
|
|
125
|
+
"@indigoai-us/hq-hook-darwin-arm64": "5.345.218",
|
|
126
|
+
"@indigoai-us/hq-hook-linux-x64": "5.345.218",
|
|
127
|
+
"@indigoai-us/hq-hook-linux-arm64": "5.345.218"
|
|
128
128
|
}
|
|
129
129
|
}
|