@indigoai-us/hq-cli 5.345.264 → 5.345.268
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 +77 -0
- package/assets/scaffold/core/scripts/hq-delegate-grant.sh +4 -48
- package/assets/scaffold/core/scripts/hq-delegate-secrets.sh +16 -10
- package/assets/scaffold/core/scripts/hq-delegate-send.sh +17 -1
- package/contracts/host-canary-release.json +7 -7
- package/dist/command-catalog.generated.d.ts +30 -1
- package/dist/command-catalog.generated.js +37 -1
- package/dist/commands/core-delegate-w1b.js +21 -40
- package/dist/commands/core-delegate.js +11 -8
- package/dist/commands/core-job-notify-native.d.ts +6 -0
- package/dist/commands/core-job-notify-native.js +64 -4
- package/dist/commands/core-jobs-native.js +3 -16
- package/dist/commands/files-browse.d.ts +83 -4
- package/dist/commands/files-browse.js +404 -54
- package/dist/commands/groups.js +2 -2
- package/dist/commands/install-global.js +54 -17
- package/dist/commands/skill.js +15 -0
- package/dist/lib/agent-kit/mcp/tools.js +2 -2
- package/dist/lib/agent-kit/skills.js +12 -6
- package/dist/lib/daemon/machine-check-owner.js +1 -1
- package/dist/lib/daemon/machine-checks.d.ts +3 -11
- package/dist/lib/daemon/machine-checks.js +4 -15
- package/dist/lib/daemon/merge-sections.d.ts +44 -9
- package/dist/lib/daemon/merge-sections.js +234 -37
- package/dist/lib/daemon/run.js +1 -0
- package/dist/lib/doctor/checks/antigravity-wiring.js +20 -4
- package/dist/lib/doctor/checks/codex-wiring.d.ts +4 -2
- package/dist/lib/doctor/checks/codex-wiring.js +70 -13
- package/dist/lib/doctor/checks/fleet-hook-core.d.ts +4 -4
- package/dist/lib/doctor/checks/fleet-hook-core.js +5 -10
- package/dist/lib/doctor/checks/grok-wiring.js +38 -0
- package/dist/lib/doctor/checks/hook-engine.js +0 -2
- package/dist/lib/doctor/checks/host-core.d.ts +1 -1
- package/dist/lib/doctor/checks/host-core.js +17 -42
- package/dist/lib/doctor/fix/process-identity.d.ts +2 -0
- package/dist/lib/doctor/fix/process-identity.js +5 -2
- package/dist/lib/hook-engine/coverage.d.ts +10 -1
- package/dist/lib/hook-engine/coverage.js +76 -9
- package/dist/lib/hook-engine/fleet-registration.js +7 -4
- package/dist/lib/hook-engine/native-precompact-compatibility.json +8 -1
- package/dist/lib/hook-engine/native-stop-compatibility.json +30 -11
- package/dist/lib/hook-engine/reconcile.d.ts +10 -1
- package/dist/lib/hook-engine/reconcile.js +351 -44
- package/dist/lib/hook-engine/stable-gate.d.ts +43 -0
- package/dist/lib/hook-engine/stable-gate.js +276 -0
- package/dist/lib/hot-channels/fleet-complete.js +2 -2
- package/dist/lib/install/antigravity-targets.js +2 -1
- package/dist/lib/install/claude-targets.d.ts +6 -6
- package/dist/lib/install/claude-targets.js +13 -9
- package/dist/lib/install/codex-targets.d.ts +4 -4
- package/dist/lib/install/codex-targets.js +26 -16
- package/dist/lib/install/hook-target.d.ts +23 -2
- package/dist/lib/install/hook-target.js +89 -16
- package/dist/lib/outpost-identity-env.d.ts +18 -0
- package/dist/lib/outpost-identity-env.js +29 -0
- package/dist/lib/signals/reply.js +25 -5
- package/dist/lib/signals/steps/extract.d.ts +28 -4
- package/dist/lib/signals/steps/extract.js +158 -10
- package/dist/lib/sync-core/release.d.ts +1 -1
- package/dist/lib/sync-core/release.js +2 -2
- package/dist/utils/core-next-kill.d.ts +2 -15
- package/dist/utils/core-next-kill.js +5 -36
- package/dist/utils/hook-engine-rollup.js +0 -1
- package/dist/utils/hook-trust.d.ts +2 -0
- package/dist/utils/hook-trust.js +156 -13
- package/dist/utils/host-registration.d.ts +158 -4
- package/dist/utils/host-registration.js +500 -17
- package/package.json +7 -7
|
@@ -2,7 +2,7 @@
|
|
|
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)
|
|
5
|
+
* Flag `core.next` off (the default): `hq reindex`
|
|
6
6
|
* writes the registrations it writes today, byte for byte, and removes the
|
|
7
7
|
* new-core entries it added. Flag on: each switched event keeps its shell
|
|
8
8
|
* registration (the old dispatcher still runs every hook with no native port)
|
|
@@ -32,12 +32,6 @@
|
|
|
32
32
|
* ([`REQUIRED_EVALUATORS`]) is registered for it. Every other event keeps the
|
|
33
33
|
* registration it would have with the flag off. Windows keeps the old
|
|
34
34
|
* registrations for every event until US-022.
|
|
35
|
-
*
|
|
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.
|
|
41
35
|
*/
|
|
42
36
|
import { execFileSync } from 'node:child_process';
|
|
43
37
|
import * as fs from 'node:fs';
|
|
@@ -45,18 +39,43 @@ import * as path from 'node:path';
|
|
|
45
39
|
import { installHookEngine } from '../lib/hook-engine/resolve.js';
|
|
46
40
|
// Read-only names stay on this namespace. host-registration.test.ts mocks a module that exports only installHookEngine.
|
|
47
41
|
import * as hookEngineResolve from '../lib/hook-engine/resolve.js';
|
|
48
|
-
import { launcherRoot, quotePosix, quoteWindows } from '../lib/hook-engine/registration.js';
|
|
42
|
+
import { launcherRoot, quotePosix, quoteWindows, sameHqRoot } from '../lib/hook-engine/registration.js';
|
|
49
43
|
import { isCoreNextEntry, userHookSettingsFile } from '../lib/hook-engine/registration-identity.js';
|
|
50
44
|
import { openStoreDir } from '../lib/safe-store.js';
|
|
51
|
-
import { SKIP_CANARY_GATE_ENV, checkHostCanary } from '../lib/hook-engine/canary-gate.js';
|
|
45
|
+
import { CANARY_HOSTS, SKIP_CANARY_GATE_ENV, canaryGateSkipped, checkHostCanary } from '../lib/hook-engine/canary-gate.js';
|
|
52
46
|
import { resolvedUnder } from '../lib/hook-engine/coverage.js';
|
|
47
|
+
import { HQ_CLI_NPM_REPAIR_COMMAND } from './npm-install-flags.js';
|
|
48
|
+
let cachedCliPackageVersion;
|
|
49
|
+
function readCliPackageVersion() {
|
|
50
|
+
if (cachedCliPackageVersion !== undefined)
|
|
51
|
+
return cachedCliPackageVersion;
|
|
52
|
+
try {
|
|
53
|
+
const pkg = JSON.parse(fs.readFileSync(new URL('../../package.json', import.meta.url), 'utf8'));
|
|
54
|
+
cachedCliPackageVersion = typeof pkg.version === 'string' && /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(pkg.version)
|
|
55
|
+
? pkg.version
|
|
56
|
+
: null;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
cachedCliPackageVersion = null;
|
|
60
|
+
}
|
|
61
|
+
return cachedCliPackageVersion;
|
|
62
|
+
}
|
|
53
63
|
export { CORE_NEXT_FLAG, coreNextEnabled } from './core-next-flag.js';
|
|
54
64
|
import { CORE_NEXT_FLAG, coreNextEnabled } from './core-next-flag.js';
|
|
55
|
-
export {
|
|
56
|
-
import {
|
|
65
|
+
export { coreNextStrictReason, ENGINE_STRICT_ENV, ENGINE_STRICT_FILE } from './core-next-kill.js';
|
|
66
|
+
import { coreNextStrictReason, ENGINE_STRICT_FILE } from './core-next-kill.js';
|
|
57
67
|
const HOOK_ENGINE_LOG_RELATIVE = path.join('.hq', 'logs', 'hook-engine.jsonl');
|
|
58
68
|
/** Name of the release-stable link next to the pinned engine versions. */
|
|
59
69
|
export const STABLE_LINK_NAME = 'stable';
|
|
70
|
+
/** Record of canary-accepted hook engines committed to `stable`, under the home folder. */
|
|
71
|
+
export const ACCEPTED_HOOK_ENGINE_RECORD = path.join('.hq', 'bin', 'hq-hook', 'accepted-engine.json');
|
|
72
|
+
/** Schema of [`ACCEPTED_HOOK_ENGINE_RECORD`]. */
|
|
73
|
+
export const ACCEPTED_HOOK_ENGINE_SCHEMA = 'hq.accepted-hook-engine.v1';
|
|
74
|
+
const coreNextCandidates = new WeakMap();
|
|
75
|
+
/** Read the candidate engine metadata attached by [`coreNextTarget`], if any. */
|
|
76
|
+
export function getCoreNextCandidate(target) {
|
|
77
|
+
return target ? coreNextCandidates.get(target) : undefined;
|
|
78
|
+
}
|
|
60
79
|
/** The target one event is registered to: the new core only for an event it can take. */
|
|
61
80
|
export function targetForEvent(target, event) {
|
|
62
81
|
if (typeof target === 'object' && 'coreNext' in target && !target.events.includes(event))
|
|
@@ -282,9 +301,6 @@ function pointsAt(link, folder) {
|
|
|
282
301
|
}
|
|
283
302
|
/** Why this home stays on shell registrations, or null when engine selection may run. */
|
|
284
303
|
export function coreNextOffReason(home, env, platform) {
|
|
285
|
-
const killed = coreNextKillReason(home, env);
|
|
286
|
-
if (killed)
|
|
287
|
-
return killed;
|
|
288
304
|
if (platform === 'win32')
|
|
289
305
|
return 'Windows keeps shell registration';
|
|
290
306
|
if (!coreNextEnabled({ ...env, HOME: home, USERPROFILE: home }))
|
|
@@ -292,7 +308,9 @@ export function coreNextOffReason(home, env, platform) {
|
|
|
292
308
|
return null;
|
|
293
309
|
}
|
|
294
310
|
/**
|
|
295
|
-
* The one engine selection. Install links the stable path
|
|
311
|
+
* The one engine selection. Install links the stable path (unless `deferLink`
|
|
312
|
+
* is set, in which case `pinned` is probed directly so the caller can commit
|
|
313
|
+
* `stable` only after the host canary gate accepts it). Read-only never
|
|
296
314
|
* writes. Both fail when the pinned bundle or the stable link is wrong.
|
|
297
315
|
*/
|
|
298
316
|
export function resolveCoreNextEngine(home, options) {
|
|
@@ -304,6 +322,11 @@ export function resolveCoreNextEngine(home, options) {
|
|
|
304
322
|
if (!installed)
|
|
305
323
|
throw new Error('the hook engine for this CLI is not installed');
|
|
306
324
|
pinned = installed;
|
|
325
|
+
if (options.deferLink) {
|
|
326
|
+
stable = stableEnginePath(pinned, home);
|
|
327
|
+
const caps = (options.probe ?? probeEngine)(pinned);
|
|
328
|
+
return { stable, pinned, caps };
|
|
329
|
+
}
|
|
307
330
|
stable = linkStableEngine(pinned, home, platform);
|
|
308
331
|
}
|
|
309
332
|
else {
|
|
@@ -318,6 +341,281 @@ export function resolveCoreNextEngine(home, options) {
|
|
|
318
341
|
const caps = (options.probe ?? probeEngine)(stable);
|
|
319
342
|
return { stable, pinned, caps };
|
|
320
343
|
}
|
|
344
|
+
function engineBinaryCandidates(baseDir, platform) {
|
|
345
|
+
return platform === 'win32'
|
|
346
|
+
? [path.join(baseDir, 'hq-hook.exe')]
|
|
347
|
+
: platform === 'darwin'
|
|
348
|
+
? [path.join(baseDir, 'hq-hook.app', 'Contents', 'MacOS', 'hq-hook'), path.join(baseDir, 'hq-hook')]
|
|
349
|
+
: [path.join(baseDir, 'hq-hook')];
|
|
350
|
+
}
|
|
351
|
+
function isRunnableEngineFile(filePath, platform) {
|
|
352
|
+
try {
|
|
353
|
+
const resolved = fs.realpathSync(filePath);
|
|
354
|
+
const stat = fs.statSync(resolved);
|
|
355
|
+
if (!stat.isFile())
|
|
356
|
+
return null;
|
|
357
|
+
if (platform !== 'win32' && (stat.mode & 0o111) === 0)
|
|
358
|
+
return null;
|
|
359
|
+
return resolved;
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
return null;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Read `<home>/.hq/bin/hq-hook/accepted-engine.json`; null when absent,
|
|
367
|
+
* unreadable, invalid, or writable by another user.
|
|
368
|
+
*/
|
|
369
|
+
export function readAcceptedHookEngineRecord(home, platform = process.platform) {
|
|
370
|
+
const file = path.join(home, ACCEPTED_HOOK_ENGINE_RECORD);
|
|
371
|
+
let text;
|
|
372
|
+
try {
|
|
373
|
+
checkOwnedEntry(file, 'file', platform);
|
|
374
|
+
text = fs.readFileSync(file, 'utf8');
|
|
375
|
+
}
|
|
376
|
+
catch {
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
let doc;
|
|
380
|
+
try {
|
|
381
|
+
doc = JSON.parse(text);
|
|
382
|
+
}
|
|
383
|
+
catch {
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
const rec = doc;
|
|
387
|
+
if (!rec || rec.schema !== ACCEPTED_HOOK_ENGINE_SCHEMA || !rec.engines || typeof rec.engines !== 'object' || Array.isArray(rec.engines)) {
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
const engines = {};
|
|
391
|
+
for (const [key, raw] of Object.entries(rec.engines)) {
|
|
392
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
393
|
+
continue;
|
|
394
|
+
const entry = raw;
|
|
395
|
+
if (typeof entry.engineVersion !== 'string' || !entry.engineVersion)
|
|
396
|
+
continue;
|
|
397
|
+
if (typeof entry.pinnedEngine !== 'string' || !entry.pinnedEngine)
|
|
398
|
+
continue;
|
|
399
|
+
if (!Array.isArray(entry.hosts))
|
|
400
|
+
continue;
|
|
401
|
+
const hosts = entry.hosts.filter((h) => typeof h === 'string');
|
|
402
|
+
if (hosts.length === 0)
|
|
403
|
+
continue;
|
|
404
|
+
engines[key] = {
|
|
405
|
+
engineVersion: entry.engineVersion,
|
|
406
|
+
pinnedEngine: entry.pinnedEngine,
|
|
407
|
+
acceptedAt: typeof entry.acceptedAt === 'string' ? entry.acceptedAt : '',
|
|
408
|
+
hosts,
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
return { schema: ACCEPTED_HOOK_ENGINE_SCHEMA, engines };
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Record `pinned` (`engineVersion`) as canary-accepted for `hosts` after
|
|
415
|
+
* committing `<home>/.hq/bin/hq-hook/stable`. Merges `hosts` when the same
|
|
416
|
+
* canonical binary is already recorded. Uses store-rule-v2 atomic replace.
|
|
417
|
+
*/
|
|
418
|
+
export function recordAcceptedHookEngine(home, pinned, engineVersion, hosts, platform = process.platform) {
|
|
419
|
+
if (hosts.length === 0)
|
|
420
|
+
return;
|
|
421
|
+
const resolved = fs.realpathSync(pinned);
|
|
422
|
+
const existing = readAcceptedHookEngineRecord(home, platform);
|
|
423
|
+
const engines = { ...(existing?.engines ?? {}) };
|
|
424
|
+
const prior = engines[resolved];
|
|
425
|
+
const mergedHosts = [...new Set([...(prior?.engineVersion === engineVersion ? prior.hosts : []), ...hosts])];
|
|
426
|
+
engines[resolved] = {
|
|
427
|
+
engineVersion,
|
|
428
|
+
pinnedEngine: resolved,
|
|
429
|
+
acceptedAt: new Date().toISOString(),
|
|
430
|
+
hosts: mergedHosts,
|
|
431
|
+
};
|
|
432
|
+
const next = { schema: ACCEPTED_HOOK_ENGINE_SCHEMA, engines };
|
|
433
|
+
const file = path.join(home, ACCEPTED_HOOK_ENGINE_RECORD);
|
|
434
|
+
replaceFileNoFollow(file, `${JSON.stringify(next, null, 2)}\n`, home);
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Return `<home>/.hq/bin/hq-hook/stable/<binary>` if `stable` already resolves
|
|
438
|
+
* to a runnable engine file (and, when `excludeBinary` is given, does NOT
|
|
439
|
+
* resolve to that refused binary). Read-only; never installs or moves `stable`.
|
|
440
|
+
*/
|
|
441
|
+
export function existingStableHookEngine(home, options = {}) {
|
|
442
|
+
const platform = options.platform ?? process.platform;
|
|
443
|
+
let excludedResolved = null;
|
|
444
|
+
if (options.excludeBinary) {
|
|
445
|
+
try {
|
|
446
|
+
excludedResolved = fs.realpathSync(options.excludeBinary);
|
|
447
|
+
}
|
|
448
|
+
catch {
|
|
449
|
+
excludedResolved = path.resolve(options.excludeBinary);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
const stableDir = path.join(hookEngineDir(home), STABLE_LINK_NAME);
|
|
453
|
+
for (const candidate of engineBinaryCandidates(stableDir, platform)) {
|
|
454
|
+
const resolved = isRunnableEngineFile(candidate, platform);
|
|
455
|
+
if (!resolved)
|
|
456
|
+
continue;
|
|
457
|
+
if (excludedResolved && resolved === excludedResolved)
|
|
458
|
+
continue;
|
|
459
|
+
return candidate;
|
|
460
|
+
}
|
|
461
|
+
return null;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Return `<home>/.hq/bin/hq-hook/stable/<binary>` only when it resolves to a
|
|
465
|
+
* runnable engine that was recorded as canary-accepted (never an engine linked
|
|
466
|
+
* with `core.next` off, forced via `--skip-host-canary-gate`, or symlinked by
|
|
467
|
+
* hand) and covers every canary host in `requiredHosts`.
|
|
468
|
+
*/
|
|
469
|
+
export function existingAcceptedStableHookEngine(home, options) {
|
|
470
|
+
const platform = options.platform ?? process.platform;
|
|
471
|
+
const candidate = existingStableHookEngine(home, {
|
|
472
|
+
platform,
|
|
473
|
+
excludeBinary: options.excludeBinary,
|
|
474
|
+
});
|
|
475
|
+
if (!candidate)
|
|
476
|
+
return null;
|
|
477
|
+
let resolved;
|
|
478
|
+
try {
|
|
479
|
+
resolved = fs.realpathSync(candidate);
|
|
480
|
+
}
|
|
481
|
+
catch {
|
|
482
|
+
return null;
|
|
483
|
+
}
|
|
484
|
+
const record = readAcceptedHookEngineRecord(home, platform);
|
|
485
|
+
const entry = record?.engines[resolved];
|
|
486
|
+
if (!entry || entry.hosts.length === 0)
|
|
487
|
+
return null;
|
|
488
|
+
const required = options.requiredHosts ?? [];
|
|
489
|
+
for (const host of required) {
|
|
490
|
+
if (!CANARY_HOSTS.includes(host))
|
|
491
|
+
continue;
|
|
492
|
+
if (entry.hosts.includes(host))
|
|
493
|
+
continue;
|
|
494
|
+
const gate = checkHostCanary({
|
|
495
|
+
home,
|
|
496
|
+
root: options.root,
|
|
497
|
+
host: host,
|
|
498
|
+
engineVersion: entry.engineVersion,
|
|
499
|
+
env: options.env,
|
|
500
|
+
platform,
|
|
501
|
+
});
|
|
502
|
+
if (!gate.allowed || gate.skipped)
|
|
503
|
+
return null;
|
|
504
|
+
}
|
|
505
|
+
return { stable: candidate, engineVersion: entry.engineVersion };
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Install the pinned hook engine (if available) and point
|
|
509
|
+
* `<home>/.hq/bin/hq-hook/stable` at it (symlink on POSIX, junction on
|
|
510
|
+
* Windows), regardless of `core.next`. When the npm engine package is gone,
|
|
511
|
+
* reuses an existing runnable `stable` or relinks `stable` from an already-
|
|
512
|
+
* pinned copy of this CLI's version under `<home>/.hq/bin/hq-hook/<version>`.
|
|
513
|
+
* Returns null when no usable engine exists on disk.
|
|
514
|
+
*/
|
|
515
|
+
export function ensureStableHookEngine(home, options = {}) {
|
|
516
|
+
const platform = options.platform ?? process.platform;
|
|
517
|
+
const installed = installHookEngine(options.lookup ? { ...options.lookup, home, platform } : { home, platform });
|
|
518
|
+
if (installed) {
|
|
519
|
+
const stable = linkStableEngine(installed, home, platform);
|
|
520
|
+
checkStableEngine(stable, installed);
|
|
521
|
+
return stable;
|
|
522
|
+
}
|
|
523
|
+
const existing = existingStableHookEngine(home, { platform });
|
|
524
|
+
if (existing)
|
|
525
|
+
return existing;
|
|
526
|
+
// m-2: relink `stable` from an already-pinned copy of this CLI's version
|
|
527
|
+
// when `stable` was removed and the optional npm engine package is gone.
|
|
528
|
+
const version = options.lookup?.version ?? readCliPackageVersion();
|
|
529
|
+
if (version) {
|
|
530
|
+
const pinnedDir = path.join(hookEngineDir(home), version);
|
|
531
|
+
for (const candidate of engineBinaryCandidates(pinnedDir, platform)) {
|
|
532
|
+
if (!isRunnableEngineFile(candidate, platform))
|
|
533
|
+
continue;
|
|
534
|
+
const stable = linkStableEngine(candidate, home, platform);
|
|
535
|
+
checkStableEngine(stable, candidate);
|
|
536
|
+
return stable;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return null;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Resolve the engine behind `<home>/.hq/bin/hq-hook/stable` for portable
|
|
543
|
+
* fallback on a native-only HQ root.
|
|
544
|
+
*
|
|
545
|
+
* - When `core.next` is off (or on Windows where `core.next` is not active),
|
|
546
|
+
* links `stable` via [`ensureStableHookEngine`].
|
|
547
|
+
* - When `core.next` IS active and a candidate engine was refused by the host
|
|
548
|
+
* canary or coverage gate (M-2), NEVER links or runs that refused engine:
|
|
549
|
+
* keeps a previously accepted engine already at `stable`, or refuses clearly.
|
|
550
|
+
*/
|
|
551
|
+
export function resolvePortableEngineForNativeOnly(home, options) {
|
|
552
|
+
const platform = options.platform ?? process.platform;
|
|
553
|
+
const env = options.env ?? process.env;
|
|
554
|
+
const stableLink = path.join(home, '.hq', 'bin', 'hq-hook', STABLE_LINK_NAME);
|
|
555
|
+
if (coreNextOffReason(home, env, platform) !== null && !options.candidate) {
|
|
556
|
+
try {
|
|
557
|
+
const stable = ensureStableHookEngine(home, { platform, lookup: options.lookup });
|
|
558
|
+
if (stable)
|
|
559
|
+
return { stable };
|
|
560
|
+
return {
|
|
561
|
+
stable: null,
|
|
562
|
+
refusalReason: `native hook engine unavailable: the native hook engine (hq-hook) is not installed and ${stableLink} does not exist. Repair with: ${HQ_CLI_NPM_REPAIR_COMMAND}`,
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
catch (error) {
|
|
566
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
567
|
+
return {
|
|
568
|
+
stable: null,
|
|
569
|
+
refusalReason: `native hook engine unavailable: failed to link ${stableLink} (${detail}). Repair with: ${HQ_CLI_NPM_REPAIR_COMMAND}`,
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
// core.next is active (or a candidate was explicitly refused by canary/coverage):
|
|
574
|
+
// never link the refused candidate as `stable`. Fall back only to an engine
|
|
575
|
+
// already linked at `stable` that was recorded as canary-accepted for the
|
|
576
|
+
// active hosts, or refuse clearly.
|
|
577
|
+
const requiredHosts = [...new Set([
|
|
578
|
+
options.host,
|
|
579
|
+
...(options.requiredHosts ?? []),
|
|
580
|
+
...(options.candidate?.checkedHosts ?? []),
|
|
581
|
+
])];
|
|
582
|
+
const acceptedPrior = existingAcceptedStableHookEngine(home, {
|
|
583
|
+
platform,
|
|
584
|
+
excludeBinary: options.candidate?.pinnedEngine ?? null,
|
|
585
|
+
root: options.root,
|
|
586
|
+
env,
|
|
587
|
+
requiredHosts,
|
|
588
|
+
});
|
|
589
|
+
if (acceptedPrior)
|
|
590
|
+
return { stable: acceptedPrior.stable, keptPriorEngine: true };
|
|
591
|
+
const unacceptedPrior = existingStableHookEngine(home, {
|
|
592
|
+
platform,
|
|
593
|
+
excludeBinary: options.candidate?.pinnedEngine ?? null,
|
|
594
|
+
});
|
|
595
|
+
const refusedHosts = options.candidate?.refusedHosts?.length
|
|
596
|
+
? options.candidate.refusedHosts
|
|
597
|
+
: [options.host];
|
|
598
|
+
const hostList = refusedHosts.join(', ');
|
|
599
|
+
const canaryHosts = refusedHosts.filter((h) => CANARY_HOSTS.includes(h));
|
|
600
|
+
const remedyHost = canaryHosts[0] ?? (CANARY_HOSTS.includes(options.host) ? options.host : 'claude');
|
|
601
|
+
if (options.candidate) {
|
|
602
|
+
const ver = options.candidate.engineVersion ?? 'unknown';
|
|
603
|
+
const priorDetail = unacceptedPrior
|
|
604
|
+
? `the existing ${stableLink} engine has no passing canary acceptance record for ${requiredHosts.join(', ')}`
|
|
605
|
+
: `no previously canary-accepted engine exists at ${stableLink}`;
|
|
606
|
+
return {
|
|
607
|
+
stable: null,
|
|
608
|
+
refusalReason: `host canary gate refused hq-hook ${ver} for ${hostList} on native-only HQ root ${options.root} and ${priorDetail}; refusing to link or run an unaccepted engine (no hooks written). Run scripts/host-canary.mjs --host ${remedyHost}, or bypass the gate with hq reindex --skip-host-canary-gate`,
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
const priorDetail = unacceptedPrior
|
|
612
|
+
? `the existing ${stableLink} engine has no passing canary acceptance record`
|
|
613
|
+
: `no previously canary-accepted engine exists at ${stableLink}`;
|
|
614
|
+
return {
|
|
615
|
+
stable: null,
|
|
616
|
+
refusalReason: `native hook engine unavailable and ${priorDetail}; cannot create ${stableLink}. Repair: ${HQ_CLI_NPM_REPAIR_COMMAND}`,
|
|
617
|
+
};
|
|
618
|
+
}
|
|
321
619
|
/**
|
|
322
620
|
* The new-core target when `core.next` is on, the engine for this CLI is
|
|
323
621
|
* installed, the stable link resolves to it, it runs, and it has every
|
|
@@ -333,8 +631,32 @@ export function coreNextTarget(home, env = process.env, options = {}) {
|
|
|
333
631
|
const platform = options.platform ?? process.platform;
|
|
334
632
|
if (coreNextOffReason(home, env, platform))
|
|
335
633
|
return null;
|
|
336
|
-
const { stable, caps } = resolveCoreNextEngine(home, {
|
|
337
|
-
|
|
634
|
+
const { stable, pinned, caps } = resolveCoreNextEngine(home, {
|
|
635
|
+
mode: 'install',
|
|
636
|
+
platform,
|
|
637
|
+
probe: options.probe,
|
|
638
|
+
deferLink: options.deferLink,
|
|
639
|
+
});
|
|
640
|
+
const target = coreNextTargetFor(home, env, stable, caps, platform, options.warn);
|
|
641
|
+
if (!target)
|
|
642
|
+
return null;
|
|
643
|
+
coreNextCandidates.set(target, {
|
|
644
|
+
pinnedEngine: pinned,
|
|
645
|
+
engineVersion: caps.version,
|
|
646
|
+
...(options.deferLink
|
|
647
|
+
? {
|
|
648
|
+
commitStable: (acceptedHosts) => {
|
|
649
|
+
const linked = linkStableEngine(pinned, home, platform);
|
|
650
|
+
checkStableEngine(linked, pinned);
|
|
651
|
+
if (acceptedHosts && acceptedHosts.length > 0 && !canaryGateSkipped(env)) {
|
|
652
|
+
recordAcceptedHookEngine(home, pinned, caps.version, acceptedHosts, platform);
|
|
653
|
+
}
|
|
654
|
+
return linked;
|
|
655
|
+
},
|
|
656
|
+
}
|
|
657
|
+
: {}),
|
|
658
|
+
});
|
|
659
|
+
return target;
|
|
338
660
|
}
|
|
339
661
|
/**
|
|
340
662
|
* The new-core target for an engine at `stable` already probed (`caps`): its
|
|
@@ -513,7 +835,168 @@ export function coreNextCommand(engine, host, event, root, scope) {
|
|
|
513
835
|
export function coreNextCommandWindows(engine, host, event, root, scope) {
|
|
514
836
|
return '& ' + [engine, ...coreNextArgs(host, event, root, scope)].map(quoteWindows).join(' ');
|
|
515
837
|
}
|
|
838
|
+
const PORTABLE_NATIVE_PROJECT_PREAMBLE = `env BASH_ENV=/dev/null sh -c 'h="$HOME/.hq/bin/hq-hook/stable/hq-hook.app/Contents/MacOS/hq-hook"; [ -x "$h" ] || h="$HOME/.hq/bin/hq-hook/stable/hq-hook"; [ -x "$h" ] || { echo "hq-hook not found under $HOME/.hq/bin/hq-hook/stable - run: hq reindex --repo-root \\"$CLAUDE_PROJECT_DIR\\"" >&2; exit 2; }; exec "$h" run --host `;
|
|
839
|
+
const PORTABLE_NATIVE_SCOPED_PREAMBLE = `env BASH_ENV=/dev/null sh -c 'h="$HOME/.hq/bin/hq-hook/stable/hq-hook.app/Contents/MacOS/hq-hook"; [ -x "$h" ] || h="$HOME/.hq/bin/hq-hook/stable/hq-hook"; [ -x "$h" ] || { echo "hq-hook not found under $HOME/.hq/bin/hq-hook/stable - run: hq reindex --repo-root \\"$1\\"" >&2; exit 2; }; exec "$h" run --host `;
|
|
840
|
+
const PORTABLE_WINDOWS_PREFIX = 'powershell.exe -NoProfile -NonInteractive -EncodedCommand ';
|
|
841
|
+
const PORTABLE_WINDOWS_SCRIPT_PREFIX = `$h = Join-Path $env:USERPROFILE '.hq\\bin\\hq-hook\\stable\\hq-hook.exe'; if (-not (Test-Path -LiteralPath $h -PathType Leaf)) { [Console]::Error.WriteLine('hq-hook.exe not found under ~/.hq/bin/hq-hook/stable - run: hq reindex --repo-root ' + `;
|
|
842
|
+
/** Shipped post-US-027 fail-closed portable `hq-hook` shell command for `event` in `<root>/.claude/settings.json`. */
|
|
843
|
+
export function shippedPortableClaudeCommand(event) {
|
|
844
|
+
return `${PORTABLE_NATIVE_PROJECT_PREAMBLE}claude ${event} --hq-root "$CLAUDE_PROJECT_DIR"'`;
|
|
845
|
+
}
|
|
846
|
+
/** True only for HQ's exact shipped portable `.claude/settings.json` command for `event`. */
|
|
847
|
+
export function isShippedPortableClaudeCommand(command, event) {
|
|
848
|
+
return command === shippedPortableClaudeCommand(event);
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Fail-closed portable `hq-hook` command with an explicit HQ root (for user-scope
|
|
852
|
+
* settings, Grok user bridge, and Antigravity on native-only roots when `core.next`
|
|
853
|
+
* is off or no direct stable path is resolved).
|
|
854
|
+
*/
|
|
855
|
+
export function portableNativeCommand(host, event, root, scope) {
|
|
856
|
+
const flag = scope === 'global' ? ' --global' : scope === 'in-tree' ? ' --in-hq-tree' : '';
|
|
857
|
+
return `${PORTABLE_NATIVE_SCOPED_PREAMBLE}${host} ${event} --hq-root "$1"${flag}' _ ${quotePosix(launcherRoot(root))}`;
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* Inner PowerShell script executed by [`portableNativeCommandWindows`].
|
|
861
|
+
* Encoded as UTF-16LE Base64 under `-EncodedCommand` so neither Git Bash
|
|
862
|
+
* (Claude Code on Windows) nor Windows PowerShell (Codex `commandWindows`)
|
|
863
|
+
* expands `$h`, `$env:USERPROFILE`, `$LASTEXITCODE`, or root characters before
|
|
864
|
+
* the child `powershell.exe` parses the script.
|
|
865
|
+
*/
|
|
866
|
+
export function portableNativeWindowsScript(host, event, root, scope) {
|
|
867
|
+
const quotedRoot = quoteWindows(launcherRoot(root));
|
|
868
|
+
const args = coreNextArgs(host, event, root, scope).map(quoteWindows).join(' ');
|
|
869
|
+
return `${PORTABLE_WINDOWS_SCRIPT_PREFIX}${quotedRoot}); exit 2 }; & $h ${args}; exit $LASTEXITCODE`;
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* Windows PowerShell fail-closed portable `hq-hook.exe` wrapper (never POSIX `sh -c`,
|
|
873
|
+
* and never dollar-expressions inside a double-quoted `-Command` string) for
|
|
874
|
+
* user-scope Claude, Codex, Grok bridge, and Antigravity on native-only roots.
|
|
875
|
+
*/
|
|
876
|
+
export function portableNativeCommandWindows(host, event, root, scope) {
|
|
877
|
+
const encoded = Buffer.from(portableNativeWindowsScript(host, event, root, scope), 'utf16le').toString('base64');
|
|
878
|
+
return `${PORTABLE_WINDOWS_PREFIX}${encoded}`;
|
|
879
|
+
}
|
|
880
|
+
/** Portable native command for `platform`: PowerShell on Windows, POSIX `sh -c` elsewhere. */
|
|
881
|
+
export function portableNativeCommandForPlatform(host, event, root, scope, platform = process.platform) {
|
|
882
|
+
return platform === 'win32'
|
|
883
|
+
? portableNativeCommandWindows(host, event, root, scope)
|
|
884
|
+
: portableNativeCommand(host, event, root, scope);
|
|
885
|
+
}
|
|
886
|
+
function isWindowsPortableNativeCommand(command, host, root, scope) {
|
|
887
|
+
if (!command.startsWith(PORTABLE_WINDOWS_PREFIX))
|
|
888
|
+
return false;
|
|
889
|
+
const encoded = command.slice(PORTABLE_WINDOWS_PREFIX.length);
|
|
890
|
+
if (!encoded || encoded.length % 4 !== 0 || !/^[A-Za-z0-9+/]+={0,2}$/.test(encoded))
|
|
891
|
+
return false;
|
|
892
|
+
const buf = Buffer.from(encoded, 'base64');
|
|
893
|
+
if (buf.length === 0 || buf.length % 2 !== 0 || buf.toString('base64') !== encoded)
|
|
894
|
+
return false;
|
|
895
|
+
const script = buf.toString('utf16le');
|
|
896
|
+
if (!script.startsWith(PORTABLE_WINDOWS_SCRIPT_PREFIX) || !script.endsWith('; exit $LASTEXITCODE'))
|
|
897
|
+
return false;
|
|
898
|
+
const afterPrefix = script.slice(PORTABLE_WINDOWS_SCRIPT_PREFIX.length);
|
|
899
|
+
const sep = `); exit 2 }; & $h 'run' '--host' '${host}' '`;
|
|
900
|
+
const sepIdx = afterPrefix.indexOf(sep);
|
|
901
|
+
if (sepIdx <= 0)
|
|
902
|
+
return false;
|
|
903
|
+
const quotedRoot = afterPrefix.slice(0, sepIdx);
|
|
904
|
+
if (!quotedRoot.startsWith("'") || !quotedRoot.endsWith("'"))
|
|
905
|
+
return false;
|
|
906
|
+
const inner = quotedRoot.slice(1, -1);
|
|
907
|
+
if (!/^(?:[^']|'')*$/.test(inner))
|
|
908
|
+
return false;
|
|
909
|
+
const unquoted = inner.replace(/''/g, "'");
|
|
910
|
+
if (!sameHqRoot(unquoted, root))
|
|
911
|
+
return false;
|
|
912
|
+
const tail = afterPrefix.slice(sepIdx + sep.length);
|
|
913
|
+
const eventEnd = tail.indexOf("'");
|
|
914
|
+
if (eventEnd <= 0)
|
|
915
|
+
return false;
|
|
916
|
+
const event = tail.slice(0, eventEnd);
|
|
917
|
+
if (!/^[A-Za-z]+$/.test(event))
|
|
918
|
+
return false;
|
|
919
|
+
const flag = scope === 'global' ? " '--global'" : scope === 'in-tree' ? " '--in-hq-tree'" : '';
|
|
920
|
+
const wantTail = `${event}' '--hq-root' ${quotedRoot}${flag}; exit $LASTEXITCODE`;
|
|
921
|
+
return tail === wantTail;
|
|
922
|
+
}
|
|
923
|
+
/** True only for HQ's exact fail-closed portable native entry for `host`, `root`, and `scope`. */
|
|
924
|
+
export function isPortableNativeEntry(entry, host, root, scope) {
|
|
925
|
+
if (Array.isArray(entry.args) || typeof entry.command !== 'string')
|
|
926
|
+
return false;
|
|
927
|
+
if (isWindowsPortableNativeCommand(entry.command, host, root, scope))
|
|
928
|
+
return true;
|
|
929
|
+
const flag = scope === 'global' ? ' --global' : scope === 'in-tree' ? ' --in-hq-tree' : '';
|
|
930
|
+
const prefix = `${PORTABLE_NATIVE_SCOPED_PREAMBLE}${host} `;
|
|
931
|
+
if (!entry.command.startsWith(prefix))
|
|
932
|
+
return false;
|
|
933
|
+
const rest = entry.command.slice(prefix.length);
|
|
934
|
+
const middle = ` --hq-root "$1"${flag}' _ '`;
|
|
935
|
+
const midIdx = rest.indexOf(middle);
|
|
936
|
+
if (midIdx <= 0)
|
|
937
|
+
return false;
|
|
938
|
+
const event = rest.slice(0, midIdx);
|
|
939
|
+
if (!/^[A-Za-z]+$/.test(event))
|
|
940
|
+
return false;
|
|
941
|
+
const quotedRoot = rest.slice(midIdx + middle.length);
|
|
942
|
+
if (!quotedRoot.endsWith("'"))
|
|
943
|
+
return false;
|
|
944
|
+
const inner = quotedRoot.slice(0, -1);
|
|
945
|
+
// Validate strict POSIX single-quoted literal (only `'\''` may contain `'`).
|
|
946
|
+
if (!/^(?:[^']|'\\'')*$/.test(inner))
|
|
947
|
+
return false;
|
|
948
|
+
const unquoted = inner.replace(/'\\''/g, "'");
|
|
949
|
+
return sameHqRoot(unquoted, root);
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* Synthesize `~/.grok/hooks/hq-hq-bridge.json` with fail-closed portable native
|
|
953
|
+
* entries for a native-only HQ root when `core.next` is off or no direct stable
|
|
954
|
+
* target is active.
|
|
955
|
+
*/
|
|
956
|
+
export function portableGrokBridgeJson(root, platform = process.platform) {
|
|
957
|
+
const hooks = {};
|
|
958
|
+
for (const event of GROK_NATIVE_HOOK_EVENTS) {
|
|
959
|
+
const command = portableNativeCommandForPlatform('grok', event, root, 'in-tree', platform);
|
|
960
|
+
hooks[event] = [{ hooks: [{ type: 'command', command, timeout: 120 }] }];
|
|
961
|
+
}
|
|
962
|
+
return `${JSON.stringify({ hooks }, null, 2)}\n`;
|
|
963
|
+
}
|
|
516
964
|
const GROK_BRIDGE_SCRIPT = 'hq-hq-bridge.sh';
|
|
965
|
+
/** Canonical Grok Build hook events registered in ~/.grok/hooks/hq-hq-bridge.json. */
|
|
966
|
+
export const GROK_NATIVE_HOOK_EVENTS = [
|
|
967
|
+
'SessionStart',
|
|
968
|
+
'UserPromptSubmit',
|
|
969
|
+
'PreToolUse',
|
|
970
|
+
'PostToolUse',
|
|
971
|
+
'Stop',
|
|
972
|
+
'PreCompact',
|
|
973
|
+
'SessionEnd',
|
|
974
|
+
'SubagentStop',
|
|
975
|
+
'Notification',
|
|
976
|
+
'StopCancelled',
|
|
977
|
+
'StopFailure',
|
|
978
|
+
'PostToolUseFailure',
|
|
979
|
+
'PermissionDenied',
|
|
980
|
+
'SubagentStart',
|
|
981
|
+
'PostCompact',
|
|
982
|
+
];
|
|
983
|
+
/**
|
|
984
|
+
* Synthesize `~/.grok/hooks/hq-hq-bridge.json` directly for a native-only HQ
|
|
985
|
+
* root whose `.grok/hooks/hq-grok-user-bridge.{sh,json}` files were removed
|
|
986
|
+
* (US-027). Every event covered by `target` calls `hq-hook run --host grok`.
|
|
987
|
+
*/
|
|
988
|
+
export function nativeGrokBridgeJson(root, target, platform = process.platform) {
|
|
989
|
+
const hooks = {};
|
|
990
|
+
for (const event of GROK_NATIVE_HOOK_EVENTS) {
|
|
991
|
+
if (!target.events.includes(event))
|
|
992
|
+
continue;
|
|
993
|
+
const command = platform === 'win32'
|
|
994
|
+
? coreNextCommandWindows(target.coreNext, 'grok', event, root, 'in-tree')
|
|
995
|
+
: coreNextCommand(target.coreNext, 'grok', event, root, 'in-tree');
|
|
996
|
+
hooks[event] = [{ hooks: [{ type: 'command', command, timeout: 120 }] }];
|
|
997
|
+
}
|
|
998
|
+
return `${JSON.stringify({ hooks }, null, 2)}\n`;
|
|
999
|
+
}
|
|
517
1000
|
function groupEntries(group) {
|
|
518
1001
|
return group && typeof group === 'object' && Array.isArray(group.hooks) ? group.hooks : null;
|
|
519
1002
|
}
|
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.268",
|
|
4
4
|
"description": "HQ by Indigo management CLI — modules and cloud sync",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -128,11 +128,11 @@
|
|
|
128
128
|
"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
|
|
129
129
|
},
|
|
130
130
|
"optionalDependencies": {
|
|
131
|
-
"@indigoai-us/hq-hook-win32-x64": "5.345.
|
|
132
|
-
"@indigoai-us/hq-hook-win32-arm64": "5.345.
|
|
133
|
-
"@indigoai-us/hq-hook-darwin-x64": "5.345.
|
|
134
|
-
"@indigoai-us/hq-hook-darwin-arm64": "5.345.
|
|
135
|
-
"@indigoai-us/hq-hook-linux-x64": "5.345.
|
|
136
|
-
"@indigoai-us/hq-hook-linux-arm64": "5.345.
|
|
131
|
+
"@indigoai-us/hq-hook-win32-x64": "5.345.268",
|
|
132
|
+
"@indigoai-us/hq-hook-win32-arm64": "5.345.268",
|
|
133
|
+
"@indigoai-us/hq-hook-darwin-x64": "5.345.268",
|
|
134
|
+
"@indigoai-us/hq-hook-darwin-arm64": "5.345.268",
|
|
135
|
+
"@indigoai-us/hq-hook-linux-x64": "5.345.268",
|
|
136
|
+
"@indigoai-us/hq-hook-linux-arm64": "5.345.268"
|
|
137
137
|
}
|
|
138
138
|
}
|