@indigoai-us/hq-cli 5.345.267 → 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 +16 -0
- package/contracts/host-canary-release.json +7 -7
- 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/install-global.js +54 -17
- 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/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 +8 -38
- package/dist/lib/hook-engine/coverage.d.ts +10 -1
- package/dist/lib/hook-engine/coverage.js +63 -8
- package/dist/lib/hook-engine/fleet-registration.js +7 -4
- package/dist/lib/hook-engine/native-precompact-compatibility.json +7 -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 +339 -42
- 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/steps/extract.js +46 -12
- 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
|
@@ -8,9 +8,9 @@ import * as path from 'node:path';
|
|
|
8
8
|
import { spawnSync } from 'node:child_process';
|
|
9
9
|
import { DAEMON_LAUNCHD_LABEL, DAEMON_SYSTEMD_UNIT, SYSTEM_UNIT_DIR, currentWindowsIdentity, legacyWindowsTask, windowsTaskName } from '../daemon/install.js';
|
|
10
10
|
import { defaultRunCommand } from '../service-manager/launchd.js';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
11
|
+
import { coreNextTargetOrWarn, getCoreNextCandidate } from '../../utils/host-registration.js';
|
|
12
|
+
import { forHost, isNativeOnlyCoreRoot } from '../hook-engine/coverage.js';
|
|
13
|
+
import { detectMachineHookHosts, evaluateStableCommit } from '../hook-engine/stable-gate.js';
|
|
14
14
|
/**
|
|
15
15
|
* True when this user's hq daemon unit (launchd plist, systemd unit, or the
|
|
16
16
|
* per-user Windows Scheduled Task) exists. On Windows the shared task an older
|
|
@@ -26,19 +26,87 @@ export function isDaemonInstalled(home, platform = process.platform, queryTask =
|
|
|
26
26
|
: [];
|
|
27
27
|
return candidates.some((p) => fs.existsSync(p));
|
|
28
28
|
}
|
|
29
|
+
function isMachineHookHost(host) {
|
|
30
|
+
return host === 'claude' || host === 'codex' || host === 'grok' || host === 'antigravity';
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* US-010 / US-017 / US-027: resolve the hook target and, on native-only roots,
|
|
34
|
+
* defer linking `stable` until EVERY host with HQ hook entries on this machine
|
|
35
|
+
* (plus `host`) accepts the candidate engine.
|
|
36
|
+
*/
|
|
37
|
+
export function resolveInstallHookTarget(hqRoot, home, daemonInstalled, env = process.env, host = 'claude', platform = process.platform) {
|
|
38
|
+
const nativeOnly = isNativeOnlyCoreRoot(hqRoot);
|
|
39
|
+
const rawCoreNext = coreNextTargetOrWarn(home, env, { platform, deferLink: nativeOnly });
|
|
40
|
+
const candidate = getCoreNextCandidate(rawCoreNext);
|
|
41
|
+
const fallback = legacyHookTarget(hqRoot, home, daemonInstalled, env, host);
|
|
42
|
+
if (nativeOnly && rawCoreNext) {
|
|
43
|
+
const decision = evaluateStableCommit({
|
|
44
|
+
rawCoreNext,
|
|
45
|
+
root: hqRoot,
|
|
46
|
+
home,
|
|
47
|
+
env,
|
|
48
|
+
engineVersion: candidate?.engineVersion,
|
|
49
|
+
requiredHosts: isMachineHookHost(host) ? [host] : [],
|
|
50
|
+
});
|
|
51
|
+
const hostTarget = isMachineHookHost(host)
|
|
52
|
+
? (decision.targets[host] ?? null)
|
|
53
|
+
: forHost(rawCoreNext, hqRoot, host, env);
|
|
54
|
+
const otherRefused = decision.refusedHosts.length > 0;
|
|
55
|
+
if (hostTarget && !otherRefused) {
|
|
56
|
+
const acceptedHosts = isMachineHookHost(host)
|
|
57
|
+
? decision.acceptedHosts
|
|
58
|
+
: [...new Set([...decision.acceptedHosts, host])];
|
|
59
|
+
candidate?.commitStable?.(acceptedHosts);
|
|
60
|
+
return { target: { ...hostTarget, fallback } };
|
|
61
|
+
}
|
|
62
|
+
const refusedHosts = hostTarget
|
|
63
|
+
? decision.refusedHosts
|
|
64
|
+
: [...new Set([host, ...decision.refusedHosts])];
|
|
65
|
+
const checkedHosts = [...new Set([host, ...decision.checkedHosts])];
|
|
66
|
+
const refusalSummary = decision.refusalSummary
|
|
67
|
+
?? `hq: warning: keeping ${path.join(home, '.hq', 'bin', 'hq-hook', 'stable')} on its current engine instead of hq-hook ${candidate?.engineVersion ?? 'unknown'} because ${refusedHosts.join(', ')} refused it on ${hqRoot}`;
|
|
68
|
+
process.stderr.write(`${refusalSummary}\n`);
|
|
69
|
+
return {
|
|
70
|
+
target: fallback,
|
|
71
|
+
...(candidate
|
|
72
|
+
? {
|
|
73
|
+
refusedCandidate: {
|
|
74
|
+
pinnedEngine: candidate.pinnedEngine,
|
|
75
|
+
engineVersion: candidate.engineVersion,
|
|
76
|
+
refusedHosts,
|
|
77
|
+
checkedHosts,
|
|
78
|
+
refusalSummary,
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
: {}),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const coreNext = forHost(rawCoreNext, hqRoot, host, env);
|
|
85
|
+
if (coreNext) {
|
|
86
|
+
candidate?.commitStable?.([host]);
|
|
87
|
+
return { target: { ...coreNext, fallback } };
|
|
88
|
+
}
|
|
89
|
+
const existingHosts = nativeOnly ? detectMachineHookHosts(hqRoot, home, env) : [];
|
|
90
|
+
return {
|
|
91
|
+
target: fallback,
|
|
92
|
+
...(nativeOnly && candidate
|
|
93
|
+
? {
|
|
94
|
+
refusedCandidate: {
|
|
95
|
+
pinnedEngine: candidate.pinnedEngine,
|
|
96
|
+
engineVersion: candidate.engineVersion,
|
|
97
|
+
refusedHosts: [host],
|
|
98
|
+
checkedHosts: [...new Set([host, ...existingHosts])],
|
|
99
|
+
},
|
|
100
|
+
}
|
|
101
|
+
: {}),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
29
104
|
/**
|
|
30
105
|
* US-010: with hqd installed (and the checkout shipping the shim), hooks go to
|
|
31
106
|
* the hqd shim; otherwise to master-hook.sh / the Codex adapter.
|
|
32
107
|
*/
|
|
33
|
-
export function hookTargetFor(hqRoot, home, daemonInstalled, env = process.env, host = 'claude') {
|
|
34
|
-
|
|
35
|
-
// for the events it covers in full on this host in this HQ root; every
|
|
36
|
-
// other event keeps the flag-off target. A failure to set up the new core
|
|
37
|
-
// is one warning, and install goes on with the flag-off target for every
|
|
38
|
-
// event.
|
|
39
|
-
const coreNext = forHost(coreNextTargetOrWarn(home, env), hqRoot, host, env);
|
|
40
|
-
const fallback = legacyHookTarget(hqRoot, home, daemonInstalled, env, host);
|
|
41
|
-
return coreNext ? { ...coreNext, fallback } : fallback;
|
|
108
|
+
export function hookTargetFor(hqRoot, home, daemonInstalled, env = process.env, host = 'claude', platform = process.platform) {
|
|
109
|
+
return resolveInstallHookTarget(hqRoot, home, daemonInstalled, env, host, platform).target;
|
|
42
110
|
}
|
|
43
111
|
/**
|
|
44
112
|
* The target with `core.next` off: the pinned launcher, or master-hook.sh
|
|
@@ -51,10 +119,15 @@ export function hookTargetFor(hqRoot, home, daemonInstalled, env = process.env,
|
|
|
51
119
|
* the daemon is up. The root, daemon and host arguments stay for callers; they
|
|
52
120
|
* no longer change the answer.
|
|
53
121
|
*/
|
|
54
|
-
export function legacyHookTarget(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
122
|
+
export function legacyHookTarget(hqRoot, _home, _daemonInstalled, _env = process.env, _host = 'claude') {
|
|
123
|
+
// US-027 C-1: a native-only root deleted master-hook.sh and the Codex bash
|
|
124
|
+
// adapter; never emit `'master'` on it. Fall back to the fail-closed portable
|
|
125
|
+
// native wrapper so guards stay active (and fail closed if hq-hook is absent)
|
|
126
|
+
// even with core.next off or before a passing host canary.
|
|
127
|
+
if (isNativeOnlyCoreRoot(hqRoot))
|
|
128
|
+
return 'portable';
|
|
129
|
+
// US-027 M1: legacy shell launcher argv was removed from `hq-hook` and exits
|
|
130
|
+
// 2 on every event; never emit `{ engine }` launcher registrations.
|
|
58
131
|
return 'master';
|
|
59
132
|
}
|
|
60
133
|
//# sourceMappingURL=hook-target.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owner fields of an Outpost's identity env file. Dependency-free so the
|
|
3
|
+
* `hq core job` fast route can load it.
|
|
4
|
+
*/
|
|
5
|
+
export declare const OUTPOST_IDENTITY_ENV_FILE = "/etc/outpost/codex-identity.env";
|
|
6
|
+
export type OutpostIdentityOwnerKey = "OUTPOST_USER_ID" | "OUTPOST_OWNER_EMAIL" | "OWNER_EMAIL";
|
|
7
|
+
export type OutpostIdentityAssignment = {
|
|
8
|
+
key: OutpostIdentityOwnerKey;
|
|
9
|
+
value: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Read the owner assignments (OUTPOST_USER_ID, OUTPOST_OWNER_EMAIL,
|
|
13
|
+
* OWNER_EMAIL) in file order. Other keys in the file are ignored and never
|
|
14
|
+
* returned. Quoted values are unquoted; unquoted values lose a trailing
|
|
15
|
+
* ` # comment`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseOutpostIdentityAssignments(contents: string): OutpostIdentityAssignment[];
|
|
18
|
+
//# sourceMappingURL=outpost-identity-env.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owner fields of an Outpost's identity env file. Dependency-free so the
|
|
3
|
+
* `hq core job` fast route can load it.
|
|
4
|
+
*/
|
|
5
|
+
export const OUTPOST_IDENTITY_ENV_FILE = "/etc/outpost/codex-identity.env";
|
|
6
|
+
/**
|
|
7
|
+
* Read the owner assignments (OUTPOST_USER_ID, OUTPOST_OWNER_EMAIL,
|
|
8
|
+
* OWNER_EMAIL) in file order. Other keys in the file are ignored and never
|
|
9
|
+
* returned. Quoted values are unquoted; unquoted values lose a trailing
|
|
10
|
+
* ` # comment`.
|
|
11
|
+
*/
|
|
12
|
+
export function parseOutpostIdentityAssignments(contents) {
|
|
13
|
+
const assignments = [];
|
|
14
|
+
for (const line of contents.split(/\r?\n/)) {
|
|
15
|
+
const assignment = /^\s*(?:export\s+)?(OUTPOST_USER_ID|OUTPOST_OWNER_EMAIL|OWNER_EMAIL)\s*=\s*(.*?)\s*$/.exec(line);
|
|
16
|
+
if (!assignment)
|
|
17
|
+
continue;
|
|
18
|
+
let value = assignment[2] ?? "";
|
|
19
|
+
if ((value.startsWith("'") && value.endsWith("'")) || (value.startsWith('"') && value.endsWith('"'))) {
|
|
20
|
+
value = value.slice(1, -1);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
value = value.replace(/\s+#.*$/, "");
|
|
24
|
+
}
|
|
25
|
+
assignments.push({ key: assignment[1], value });
|
|
26
|
+
}
|
|
27
|
+
return assignments;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=outpost-identity-env.js.map
|
|
@@ -74,8 +74,9 @@
|
|
|
74
74
|
* prompt (stdin, never argv), the model returns candidate commands as JSON
|
|
75
75
|
* data, and the host validates them and runs the pinned wrapper. The helper
|
|
76
76
|
* reports no cost, so a turn that reached the model is charged the per-source
|
|
77
|
-
* estimate. The `claude -p` path below runs only when there is no helper,
|
|
78
|
-
* when the helper cannot run a completion (then for the rest of the
|
|
77
|
+
* estimate. The `claude -p` path below runs only when there is no helper,
|
|
78
|
+
* when the helper cannot start or run a completion (then for the rest of the
|
|
79
|
+
* run), or for one item the helper refuses as too large (then for that item).
|
|
79
80
|
*
|
|
80
81
|
* grok, checked 2026-11-05 against `grok --help` and the user guide grok
|
|
81
82
|
* 1.0.70 ships (its embedded 22-permissions-and-safety.md and 18-sandbox.md)
|
|
@@ -1421,6 +1422,8 @@ function runTurn(ctx, runtime, prompt, scope, budgetUsd, opts) {
|
|
|
1421
1422
|
}
|
|
1422
1423
|
return { ok: true, turns: parsed.turns, ...cost };
|
|
1423
1424
|
}
|
|
1425
|
+
/** Spawn error codes that mean the hq-fleet-local helper never started. */
|
|
1426
|
+
const FLEET_HELPER_NOT_STARTED = new Set(["ENOENT", "EACCES", "ENOTDIR", "EPERM", "ENOEXEC"]);
|
|
1424
1427
|
/**
|
|
1425
1428
|
* extract's errorKind for an `hq-fleet-local complete` error code, and whether
|
|
1426
1429
|
* the turn may have used the model (then it is charged the per-source
|
|
@@ -1451,23 +1454,35 @@ export function fleetExtractFailure(code) {
|
|
|
1451
1454
|
}
|
|
1452
1455
|
/**
|
|
1453
1456
|
* One item as a no-tool `hq-fleet-local complete` turn on the Fleet
|
|
1454
|
-
* Executive bot's own login.
|
|
1455
|
-
* (it
|
|
1456
|
-
* the claude CLI
|
|
1457
|
-
*
|
|
1457
|
+
* Executive bot's own login. "missing" when the helper cannot run a
|
|
1458
|
+
* completion (it could not start, or its release has no `complete`): the
|
|
1459
|
+
* caller then uses the claude CLI for the rest of the run. "too-large" when
|
|
1460
|
+
* the helper refuses this item's prompt as too large: the caller runs this
|
|
1461
|
+
* item alone on the claude CLI, which reads the item with its Read tool
|
|
1462
|
+
* instead of in the prompt, and keeps the helper for later items. The reply
|
|
1463
|
+
* is model output built from the item: it is only validated and run through
|
|
1464
|
+
* the pinned wrapper, never logged.
|
|
1458
1465
|
*/
|
|
1459
1466
|
async function runFleetTurn(ctx, target, prompt, scope, opts) {
|
|
1460
1467
|
// The step's own spawn runs the helper, as it runs every other extract process.
|
|
1461
1468
|
const run = async (command, args, o) => {
|
|
1462
1469
|
const r = ctx.spawn(command, [...args], { cwd: o.cwd, env: o.env, timeoutMs: o.timeoutMs, ...(o.input !== undefined ? { input: o.input } : {}) });
|
|
1463
|
-
const
|
|
1464
|
-
|
|
1470
|
+
const errno = r.error?.code;
|
|
1471
|
+
const timedOut = r.error !== undefined && (/ETIMEDOUT|timed out/i.test(r.error.message) || errno === "ETIMEDOUT");
|
|
1472
|
+
// Only an error that means the helper never started is reported as a
|
|
1473
|
+
// spawn error, which runFleetComplete reads as "missing" and the run
|
|
1474
|
+
// moves to the claude CLI. Any other error (ENOBUFS, a signal) came from
|
|
1475
|
+
// a helper that ran: it fails this item and the helper stays in use.
|
|
1476
|
+
const couldNotStart = r.error !== undefined && !timedOut && errno !== undefined && FLEET_HELPER_NOT_STARTED.has(errno);
|
|
1477
|
+
return { code: r.status, stdout: r.stdout, stderr: r.stderr, timedOut, ...(couldNotStart ? { spawnError: r.error.message } : {}) };
|
|
1465
1478
|
};
|
|
1466
1479
|
// The env the adapters step's signals pass gives the helper. The helper
|
|
1467
1480
|
// reads the bot's login from its profile and refuses an API key login.
|
|
1468
1481
|
const result = await runFleetComplete(target, prompt, { timeoutMs: opts.turnTimeoutMs, env: process.env, cwd: scope.turnDir, run });
|
|
1469
1482
|
if (result.kind === "missing")
|
|
1470
|
-
return
|
|
1483
|
+
return "missing";
|
|
1484
|
+
if (result.kind === "error" && result.code === "too_large")
|
|
1485
|
+
return "too-large";
|
|
1471
1486
|
const charged = { costUsd: opts.unpricedSourceEstimateUsd, costEstimated: true };
|
|
1472
1487
|
if (result.kind === "error") {
|
|
1473
1488
|
const { errorKind, reachedModel } = fleetExtractFailure(result.code);
|
|
@@ -1666,6 +1681,8 @@ export function createExtractStep(options = {}) {
|
|
|
1666
1681
|
// a helper. A Codex Fleet bot's target is never used for a claude turn.
|
|
1667
1682
|
let fleet = null;
|
|
1668
1683
|
let fleetFallback;
|
|
1684
|
+
// Items the helper refused as too large; each ran alone on the claude CLI.
|
|
1685
|
+
const fleetTooLarge = [];
|
|
1669
1686
|
if (runtime === "claude") {
|
|
1670
1687
|
const resolveFleet = options.resolveFleetComplete ?? (options.resolveBotRuntime ? () => null : () => defaultResolveFleetComplete());
|
|
1671
1688
|
try {
|
|
@@ -1850,16 +1867,33 @@ export function createExtractStep(options = {}) {
|
|
|
1850
1867
|
...(mode === "codex" || mode === "fleet" ? { itemText: fs.readFileSync(sourceFile, "utf8") } : {}),
|
|
1851
1868
|
});
|
|
1852
1869
|
let fleetTurn = null;
|
|
1870
|
+
// Set when the helper refused this item as too large and it runs alone on the claude CLI.
|
|
1871
|
+
let tooLargeFor;
|
|
1853
1872
|
if (fleet) {
|
|
1854
|
-
|
|
1855
|
-
if (
|
|
1873
|
+
const fleetResult = await runFleetTurn(ctx, fleet, promptFor("fleet"), scope, turnOpts);
|
|
1874
|
+
if (fleetResult === "missing") {
|
|
1856
1875
|
// The helper cannot run a completion: this item and the rest
|
|
1857
1876
|
// of the run use the claude CLI.
|
|
1858
1877
|
fleetFallback = `${fleet.botName}'s hq-fleet-local helper could not run a completion; using the claude CLI`;
|
|
1859
1878
|
fleet = null;
|
|
1860
1879
|
}
|
|
1880
|
+
else if (fleetResult === "too-large") {
|
|
1881
|
+
// Too large for the helper's prompt: this item alone runs on
|
|
1882
|
+
// the claude CLI, which reads it with its Read tool.
|
|
1883
|
+
fleetTooLarge.push(item.file);
|
|
1884
|
+
tooLargeFor = fleet.botName;
|
|
1885
|
+
}
|
|
1886
|
+
else {
|
|
1887
|
+
fleetTurn = fleetResult;
|
|
1888
|
+
}
|
|
1861
1889
|
}
|
|
1862
1890
|
turn = fleetTurn ?? runTurn(ctx, runtime, promptFor(runtime), scope, Math.max(0, remaining), turnOpts);
|
|
1891
|
+
if (tooLargeFor !== undefined && !turn.ok && turn.errorKind === "signed-out") {
|
|
1892
|
+
// The personal claude login is signed out, but the run is on the
|
|
1893
|
+
// bot's login, which still works: only this oversized item fails,
|
|
1894
|
+
// and the later items still run on the helper.
|
|
1895
|
+
turn = { ...turn, errorKind: "other", error: `too large for ${tooLargeFor}'s hq-fleet-local helper, and the claude CLI it fell back to is not logged in` };
|
|
1896
|
+
}
|
|
1863
1897
|
}
|
|
1864
1898
|
finally {
|
|
1865
1899
|
fs.rmSync(turnDir, { recursive: true, force: true });
|
|
@@ -1953,7 +1987,7 @@ export function createExtractStep(options = {}) {
|
|
|
1953
1987
|
...(failures.length ? { failures } : {}),
|
|
1954
1988
|
...(skippedItems.length ? { skippedItems } : {}),
|
|
1955
1989
|
...(rejected ? { rejectedCandidates: rejected } : {}),
|
|
1956
|
-
detail: { new: itemsOut, updated, skipped, runtime, ...(runtime === "claude" ? { login: fleet ? "fleet" : "claude-cli", ...(fleet ? { bot: fleet.botName } : {}) } : {}), ...(fleetFallback ? { loginFallback: fleetFallback } : {}), ...(choice.fallback ? { fallback: choice.fallback } : {}), ...(budgetStoppedAt ? { budgetStoppedAt } : {}), ...(unpricedSources ? { spendEstimated: true, unpricedSources, unpricedSourceEstimateUsd: turnOpts.unpricedSourceEstimateUsd } : {}), ...(uncitedCandidates ? { uncitedCandidates, uncitedSources } : {}), ...listingDetail },
|
|
1990
|
+
detail: { new: itemsOut, updated, skipped, runtime, ...(runtime === "claude" ? { login: fleet ? "fleet" : "claude-cli", ...(fleet ? { bot: fleet.botName } : {}) } : {}), ...(fleetFallback ? { loginFallback: fleetFallback } : {}), ...(fleetTooLarge.length ? { fleetTooLarge } : {}), ...(choice.fallback ? { fallback: choice.fallback } : {}), ...(budgetStoppedAt ? { budgetStoppedAt } : {}), ...(unpricedSources ? { spendEstimated: true, unpricedSources, unpricedSourceEstimateUsd: turnOpts.unpricedSourceEstimateUsd } : {}), ...(uncitedCandidates ? { uncitedCandidates, uncitedSources } : {}), ...listingDetail },
|
|
1957
1991
|
};
|
|
1958
1992
|
// Between-sources stop. An in-source stop sets budgetStoppedAt and leaves sourcesLeft at 0.
|
|
1959
1993
|
// Main names that next source in budgetStoppedAt; the estimate reason is recorded too.
|
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const CORE_NEXT_KILL_FILE: string;
|
|
4
|
-
/** The engine-wide kill switch the bridge already honors; the engine checks it too. */
|
|
5
|
-
export declare const ENGINE_KILL_ENV = "HQ_HOOK_ENGINE";
|
|
6
|
-
export declare const ENGINE_KILL_FILE: string;
|
|
1
|
+
/** Environment variable that enables strict mode (`HQ_HOOK_ENGINE=strict`). */
|
|
2
|
+
export declare const ENGINE_STRICT_ENV = "HQ_HOOK_ENGINE";
|
|
7
3
|
/** Strict-mode marker file under the home folder (matches crates/hq-hook/src/bridge.rs). */
|
|
8
4
|
export declare const ENGINE_STRICT_FILE: string;
|
|
9
|
-
/**
|
|
10
|
-
* Why the new core is switched off on this machine, or null. The same four
|
|
11
|
-
* switches the engine reads (`crates/hq-hook/src/core_next.rs` `kill_reason`):
|
|
12
|
-
* `HQ_CORE_NEXT=off|0|false|no`, `HQ_HOOK_ENGINE=off`, and the files
|
|
13
|
-
* `~/.hq/state/core-next.off` and `~/.hq/hook-engine.off` (a link counts, as
|
|
14
|
-
* for the engine). With any of them on, `hq reindex` removes the new-core
|
|
15
|
-
* entries it added, so the registrations are what they were before the switch.
|
|
16
|
-
*/
|
|
17
|
-
export declare function coreNextKillReason(home: string, env?: NodeJS.ProcessEnv): string | null;
|
|
18
5
|
/**
|
|
19
6
|
* Why strict mode is engaged on this machine, or null. Matches the engine's
|
|
20
7
|
* strict check (`crates/hq-hook/src/bridge.rs`): `HQ_HOOK_ENGINE=strict`
|
|
@@ -1,39 +1,10 @@
|
|
|
1
|
-
/** Shared
|
|
1
|
+
/** Shared strict-mode switch without installer imports. */
|
|
2
2
|
import * as fs from 'node:fs';
|
|
3
3
|
import * as path from 'node:path';
|
|
4
|
-
/**
|
|
5
|
-
export const
|
|
6
|
-
export const CORE_NEXT_KILL_FILE = path.join('.hq', 'state', 'core-next.off');
|
|
7
|
-
/** The engine-wide kill switch the bridge already honors; the engine checks it too. */
|
|
8
|
-
export const ENGINE_KILL_ENV = 'HQ_HOOK_ENGINE';
|
|
9
|
-
export const ENGINE_KILL_FILE = path.join('.hq', 'hook-engine.off');
|
|
4
|
+
/** Environment variable that enables strict mode (`HQ_HOOK_ENGINE=strict`). */
|
|
5
|
+
export const ENGINE_STRICT_ENV = 'HQ_HOOK_ENGINE';
|
|
10
6
|
/** Strict-mode marker file under the home folder (matches crates/hq-hook/src/bridge.rs). */
|
|
11
7
|
export const ENGINE_STRICT_FILE = path.join('.hq', 'hook-engine.strict');
|
|
12
|
-
/**
|
|
13
|
-
* Why the new core is switched off on this machine, or null. The same four
|
|
14
|
-
* switches the engine reads (`crates/hq-hook/src/core_next.rs` `kill_reason`):
|
|
15
|
-
* `HQ_CORE_NEXT=off|0|false|no`, `HQ_HOOK_ENGINE=off`, and the files
|
|
16
|
-
* `~/.hq/state/core-next.off` and `~/.hq/hook-engine.off` (a link counts, as
|
|
17
|
-
* for the engine). With any of them on, `hq reindex` removes the new-core
|
|
18
|
-
* entries it added, so the registrations are what they were before the switch.
|
|
19
|
-
*/
|
|
20
|
-
export function coreNextKillReason(home, env = process.env) {
|
|
21
|
-
const coreNextEnv = (env[CORE_NEXT_KILL_ENV] ?? '').trim();
|
|
22
|
-
if (/^(off|0|false|no)$/i.test(coreNextEnv))
|
|
23
|
-
return `${CORE_NEXT_KILL_ENV}=${env[CORE_NEXT_KILL_ENV]}`;
|
|
24
|
-
if (/^off$/i.test((env[ENGINE_KILL_ENV] ?? '').trim()))
|
|
25
|
-
return `${ENGINE_KILL_ENV}=${env[ENGINE_KILL_ENV]}`;
|
|
26
|
-
for (const file of [path.join(home, CORE_NEXT_KILL_FILE), path.join(home, ENGINE_KILL_FILE)]) {
|
|
27
|
-
try {
|
|
28
|
-
fs.lstatSync(file);
|
|
29
|
-
return file;
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
// Absent: this switch is off.
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
8
|
/**
|
|
38
9
|
* Why strict mode is engaged on this machine, or null. Matches the engine's
|
|
39
10
|
* strict check (`crates/hq-hook/src/bridge.rs`): `HQ_HOOK_ENGINE=strict`
|
|
@@ -41,10 +12,8 @@ export function coreNextKillReason(home, env = process.env) {
|
|
|
41
12
|
* link counts).
|
|
42
13
|
*/
|
|
43
14
|
export function coreNextStrictReason(home, env = process.env) {
|
|
44
|
-
if (
|
|
45
|
-
return
|
|
46
|
-
if (/^strict$/i.test((env[ENGINE_KILL_ENV] ?? '').trim()))
|
|
47
|
-
return `${ENGINE_KILL_ENV}=${env[ENGINE_KILL_ENV]}`;
|
|
15
|
+
if (/^strict$/i.test((env[ENGINE_STRICT_ENV] ?? '').trim()))
|
|
16
|
+
return `${ENGINE_STRICT_ENV}=${env[ENGINE_STRICT_ENV]}`;
|
|
48
17
|
const file = path.join(home, ENGINE_STRICT_FILE);
|
|
49
18
|
try {
|
|
50
19
|
fs.lstatSync(file);
|
|
@@ -22,7 +22,6 @@ const STATE_MAX_BYTES = 1024 * 1024;
|
|
|
22
22
|
const MAX_EXCLUDED_STRETCHES = 64;
|
|
23
23
|
const DAY_MS = 86_400_000;
|
|
24
24
|
export const HOOK_ENGINE_SHIPPED_HOOK_IDS = new Set([
|
|
25
|
-
"block-hq-grep",
|
|
26
25
|
"enforce-vault-write-access",
|
|
27
26
|
"block-numbered-policy-sibling",
|
|
28
27
|
"block-agent-secrets-reveal",
|
|
@@ -34,6 +34,8 @@ export interface HookTrustDependencies {
|
|
|
34
34
|
* flag `core.next`.
|
|
35
35
|
*/
|
|
36
36
|
coreNextTarget?: (home: string) => CoreNextTarget | null;
|
|
37
|
+
/** Test seam for linking `<home>/.hq/bin/hq-hook/stable` on native-only roots. */
|
|
38
|
+
ensureStableEngine?: (home: string, platform: NodeJS.Platform) => string | null;
|
|
37
39
|
/**
|
|
38
40
|
* Reads the HQ `.codex` hook files exactly as the installed core release
|
|
39
41
|
* ships them. Used only by the post-rescue re-trust; see
|
package/dist/utils/hook-trust.js
CHANGED
|
@@ -11,8 +11,11 @@ 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';
|
|
15
|
-
import {
|
|
14
|
+
import { forHost, isNativeOnlyCoreRoot } from '../lib/hook-engine/coverage.js';
|
|
15
|
+
import { isCoreNextEntry } from '../lib/hook-engine/registration.js';
|
|
16
|
+
import { detectMachineHookHosts, evaluateStableCommit } from '../lib/hook-engine/stable-gate.js';
|
|
17
|
+
import { HQ_CLI_NPM_REPAIR_COMMAND } from './npm-install-flags.js';
|
|
18
|
+
import { coreNextOffReason, coreNextTargetOrWarn, ensureStableHookEngine, getCoreNextCandidate, GROK_NATIVE_HOOK_EVENTS, grokBridgeJson, nativeGrokBridgeJson, portableGrokBridgeJson, replaceFileNoFollow, resolvePortableEngineForNativeOnly, STABLE_LINK_NAME } from './host-registration.js';
|
|
16
19
|
import { planResolvedCommandSpawn } from './windows-spawn.js';
|
|
17
20
|
/**
|
|
18
21
|
* The home directory every runtime's config is resolved under.
|
|
@@ -688,7 +691,7 @@ function textMatches(file, text) {
|
|
|
688
691
|
function tomlEscapeKey(value) {
|
|
689
692
|
return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
690
693
|
}
|
|
691
|
-
function grokTrustIsCurrent(hqRoot, home, wantJson) {
|
|
694
|
+
function grokTrustIsCurrent(hqRoot, home, wantJson, requireBridgeSh = true) {
|
|
692
695
|
const grokHome = path.join(home, '.grok');
|
|
693
696
|
// The key is written TOML-escaped, so match the escaped form. On POSIX paths
|
|
694
697
|
// (no backslash/quote) this is identical to the raw path.
|
|
@@ -714,7 +717,7 @@ function grokTrustIsCurrent(hqRoot, home, wantJson) {
|
|
|
714
717
|
return (folderTrusted &&
|
|
715
718
|
legacyTrusted &&
|
|
716
719
|
claudeCompatQuiet &&
|
|
717
|
-
filesMatch(path.join(sourceHooks, 'hq-grok-user-bridge.sh'), path.join(userHooks, 'hq-hq-bridge.sh')) &&
|
|
720
|
+
(!requireBridgeSh || filesMatch(path.join(sourceHooks, 'hq-grok-user-bridge.sh'), path.join(userHooks, 'hq-hq-bridge.sh'))) &&
|
|
718
721
|
(wantJson === undefined
|
|
719
722
|
? filesMatch(path.join(sourceHooks, 'hq-grok-user-bridge.json'), path.join(userHooks, 'hq-hq-bridge.json'))
|
|
720
723
|
: textMatches(path.join(userHooks, 'hq-hq-bridge.json'), wantJson)));
|
|
@@ -822,15 +825,156 @@ export function trustGrokProjectHooks(hqRoot, deps = DEFAULT_DEPS) {
|
|
|
822
825
|
const sourceHooks = path.join(hqRoot, '.grok', 'hooks');
|
|
823
826
|
const sourceBridgeSh = path.join(sourceHooks, 'hq-grok-user-bridge.sh');
|
|
824
827
|
const sourceBridgeJson = path.join(sourceHooks, 'hq-grok-user-bridge.json');
|
|
825
|
-
|
|
826
|
-
return {
|
|
827
|
-
runtime: 'grok',
|
|
828
|
-
status: 'skipped',
|
|
829
|
-
trusted: 0,
|
|
830
|
-
reason: 'project .grok bridge sources absent',
|
|
831
|
-
};
|
|
832
|
-
}
|
|
828
|
+
const legacySourcesPresent = fs.existsSync(sourceBridgeSh) && fs.existsSync(sourceBridgeJson);
|
|
833
829
|
const home = deps.homeDir?.() ?? process.env.HOME ?? os.homedir();
|
|
830
|
+
const platform = deps.platform ?? process.platform;
|
|
831
|
+
const nativeOnly = isNativeOnlyCoreRoot(hqRoot);
|
|
832
|
+
if (nativeOnly || !legacySourcesPresent) {
|
|
833
|
+
// Post-US-027 native-only root: `.grok/hooks/hq-grok-user-bridge.{sh,json}`
|
|
834
|
+
// were removed (or left behind by rescue before cleanup), so synthesize
|
|
835
|
+
// `~/.grok/hooks/hq-hq-bridge.json` directly for `hq-hook run --host grok`.
|
|
836
|
+
if (!nativeOnly && !fs.existsSync(path.join(hqRoot, '.grok'))) {
|
|
837
|
+
return {
|
|
838
|
+
runtime: 'grok',
|
|
839
|
+
status: 'skipped',
|
|
840
|
+
trusted: 0,
|
|
841
|
+
reason: 'project .grok bridge sources absent',
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
let target;
|
|
845
|
+
let grok;
|
|
846
|
+
try {
|
|
847
|
+
target = (deps.coreNextTarget ?? ((h) => coreNextTargetOrWarn(h, process.env, { platform, deferLink: nativeOnly })))(home);
|
|
848
|
+
}
|
|
849
|
+
catch (error) {
|
|
850
|
+
return { runtime: 'grok', status: 'failed', trusted: 0, reason: errorMessage(error) };
|
|
851
|
+
}
|
|
852
|
+
const candidate = getCoreNextCandidate(target);
|
|
853
|
+
let refusedHosts;
|
|
854
|
+
let checkedHosts;
|
|
855
|
+
let acceptedHosts = ['grok'];
|
|
856
|
+
if (nativeOnly && target && candidate?.commitStable) {
|
|
857
|
+
const decision = evaluateStableCommit({
|
|
858
|
+
rawCoreNext: target,
|
|
859
|
+
root: hqRoot,
|
|
860
|
+
home,
|
|
861
|
+
env: process.env,
|
|
862
|
+
engineVersion: candidate.engineVersion,
|
|
863
|
+
requiredHosts: ['grok'],
|
|
864
|
+
});
|
|
865
|
+
if (decision.allowed && decision.targets.grok && decision.targets.grok.events.length > 0) {
|
|
866
|
+
grok = decision.targets.grok;
|
|
867
|
+
acceptedHosts = decision.acceptedHosts;
|
|
868
|
+
}
|
|
869
|
+
else {
|
|
870
|
+
if (decision.refusalSummary)
|
|
871
|
+
process.stderr.write(`${decision.refusalSummary}\n`);
|
|
872
|
+
grok = null;
|
|
873
|
+
refusedHosts = decision.refusedHosts.length > 0 ? decision.refusedHosts : ['grok'];
|
|
874
|
+
checkedHosts = decision.checkedHosts;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
else {
|
|
878
|
+
try {
|
|
879
|
+
grok = forHost(target, hqRoot, 'grok');
|
|
880
|
+
}
|
|
881
|
+
catch (error) {
|
|
882
|
+
return { runtime: 'grok', status: 'failed', trusted: 0, reason: errorMessage(error) };
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
let wantJson;
|
|
886
|
+
if (grok && grok.events.length > 0) {
|
|
887
|
+
try {
|
|
888
|
+
candidate?.commitStable?.(acceptedHosts);
|
|
889
|
+
}
|
|
890
|
+
catch (error) {
|
|
891
|
+
return { runtime: 'grok', status: 'failed', trusted: 0, reason: errorMessage(error) };
|
|
892
|
+
}
|
|
893
|
+
wantJson = nativeGrokBridgeJson(hqRoot, grok, platform);
|
|
894
|
+
}
|
|
895
|
+
else if (nativeOnly) {
|
|
896
|
+
const candidateRefused = target !== null || (!deps.coreNextTarget && coreNextOffReason(home, process.env, platform) === null);
|
|
897
|
+
let stable;
|
|
898
|
+
let refusalReason;
|
|
899
|
+
let keptPriorEngine = false;
|
|
900
|
+
if (candidateRefused) {
|
|
901
|
+
const machineHosts = checkedHosts ?? [...new Set(['grok', ...detectMachineHookHosts(hqRoot, home, process.env)])];
|
|
902
|
+
const resolution = resolvePortableEngineForNativeOnly(home, {
|
|
903
|
+
platform,
|
|
904
|
+
env: process.env,
|
|
905
|
+
host: refusedHosts?.[0] ?? 'grok',
|
|
906
|
+
root: hqRoot,
|
|
907
|
+
candidate: candidate
|
|
908
|
+
? { ...candidate, refusedHosts, checkedHosts: machineHosts }
|
|
909
|
+
: (refusedHosts ? { refusedHosts, checkedHosts: machineHosts } : null),
|
|
910
|
+
requiredHosts: machineHosts,
|
|
911
|
+
});
|
|
912
|
+
stable = resolution.stable;
|
|
913
|
+
refusalReason = resolution.refusalReason;
|
|
914
|
+
keptPriorEngine = Boolean(resolution.keptPriorEngine);
|
|
915
|
+
}
|
|
916
|
+
else {
|
|
917
|
+
try {
|
|
918
|
+
stable = (deps.ensureStableEngine ?? ((h, p) => ensureStableHookEngine(h, { platform: p })))(home, platform);
|
|
919
|
+
}
|
|
920
|
+
catch (error) {
|
|
921
|
+
return { runtime: 'grok', status: 'failed', trusted: 0, reason: errorMessage(error) };
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
if (!stable) {
|
|
925
|
+
return {
|
|
926
|
+
runtime: 'grok',
|
|
927
|
+
status: 'failed',
|
|
928
|
+
trusted: 0,
|
|
929
|
+
reason: refusalReason ?? `native hook engine unavailable; cannot create ${path.join(home, '.hq', 'bin', 'hq-hook', STABLE_LINK_NAME)}. Repair: ${HQ_CLI_NPM_REPAIR_COMMAND}`,
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
// When keeping a previously accepted engine at `stable` after a refusal,
|
|
933
|
+
// preserve an already-written core.next bridge so it keeps running the
|
|
934
|
+
// prior `stable` engine without unnecessary churn.
|
|
935
|
+
const existingBridgePath = path.join(home, '.grok', 'hooks', 'hq-hq-bridge.json');
|
|
936
|
+
let preservedExisting = null;
|
|
937
|
+
if (keptPriorEngine && fs.existsSync(existingBridgePath)) {
|
|
938
|
+
try {
|
|
939
|
+
const existingText = fs.readFileSync(existingBridgePath, 'utf8');
|
|
940
|
+
const parsed = JSON.parse(existingText);
|
|
941
|
+
const hasAllCoreNext = Boolean(parsed.hooks
|
|
942
|
+
&& GROK_NATIVE_HOOK_EVENTS.every((ev) => Array.isArray(parsed.hooks?.[ev])
|
|
943
|
+
&& parsed.hooks[ev].some((g) => Array.isArray(g?.hooks) && g.hooks.some((h) => isCoreNextEntry(h, hqRoot)))));
|
|
944
|
+
if (hasAllCoreNext)
|
|
945
|
+
preservedExisting = existingText;
|
|
946
|
+
}
|
|
947
|
+
catch {
|
|
948
|
+
preservedExisting = null;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
wantJson = preservedExisting ?? portableGrokBridgeJson(hqRoot, platform);
|
|
952
|
+
}
|
|
953
|
+
else {
|
|
954
|
+
return {
|
|
955
|
+
runtime: 'grok',
|
|
956
|
+
status: 'skipped',
|
|
957
|
+
trusted: 0,
|
|
958
|
+
reason: 'project .grok bridge sources absent',
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
if (grokTrustIsCurrent(hqRoot, home, wantJson, false)) {
|
|
962
|
+
return { runtime: 'grok', status: 'unchanged', trusted: 0 };
|
|
963
|
+
}
|
|
964
|
+
try {
|
|
965
|
+
const grokHome = path.join(home, '.grok');
|
|
966
|
+
const userHooks = path.join(grokHome, 'hooks');
|
|
967
|
+
fs.mkdirSync(userHooks, { recursive: true });
|
|
968
|
+
writeGrokFolderTrust(path.join(grokHome, 'trusted_folders.toml'), hqRoot);
|
|
969
|
+
writeGrokLegacyTrust(path.join(grokHome, 'trusted-hook-projects'), hqRoot);
|
|
970
|
+
quietGrokClaudeCompat(path.join(grokHome, 'config.toml'));
|
|
971
|
+
replaceFileNoFollow(path.join(userHooks, 'hq-hq-bridge.json'), wantJson, home);
|
|
972
|
+
return { runtime: 'grok', status: 'trusted', trusted: 1 };
|
|
973
|
+
}
|
|
974
|
+
catch (error) {
|
|
975
|
+
return { runtime: 'grok', status: 'failed', trusted: 0, reason: errorMessage(error) };
|
|
976
|
+
}
|
|
977
|
+
}
|
|
834
978
|
// Flag `core.next` on: the user hook file calls the new core's entry point
|
|
835
979
|
// (hq-core-rust US-017) for each event the engine has every guard for. Off,
|
|
836
980
|
// when the engine is not available, or when the shipped file cannot be
|
|
@@ -841,7 +985,6 @@ export function trustGrokProjectHooks(hqRoot, deps = DEFAULT_DEPS) {
|
|
|
841
985
|
const target = (deps.coreNextTarget ?? ((h) => coreNextTargetOrWarn(h)))(home);
|
|
842
986
|
// Only the events the new core covers in full on Grok switch.
|
|
843
987
|
const grok = forHost(target, hqRoot, 'grok');
|
|
844
|
-
const platform = deps.platform ?? process.platform;
|
|
845
988
|
wantJson = grok || platform === 'win32'
|
|
846
989
|
? grokBridgeJson(fs.readFileSync(sourceBridgeJson, 'utf8'), hqRoot, grok, platform, home)
|
|
847
990
|
: undefined;
|