@indigoai-us/hq-cli 5.345.220 → 5.345.221
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 +118 -0
- package/dist/command-catalog.generated.d.ts +144 -2
- package/dist/command-catalog.generated.js +175 -2
- package/dist/commands/auth.js +4 -1
- package/dist/commands/bot-runtime.d.ts +18 -5
- package/dist/commands/bot-runtime.js +29 -12
- package/dist/commands/bot.d.ts +39 -2
- package/dist/commands/bot.js +140 -11
- package/dist/commands/core-stop-autosave.d.ts +21 -0
- package/dist/commands/core-stop-autosave.js +300 -0
- package/dist/commands/core.js +2 -0
- package/dist/commands/daemon.d.ts +5 -0
- package/dist/commands/daemon.js +31 -7
- package/dist/commands/doctor-usage.d.ts +5 -0
- package/dist/commands/doctor-usage.js +25 -0
- package/dist/commands/env.d.ts +49 -4
- package/dist/commands/env.js +355 -5
- package/dist/commands/lanes-shared.d.ts +3 -0
- package/dist/commands/lanes.d.ts +3 -0
- package/dist/commands/lanes.js +87 -3
- package/dist/commands/sources.js +3 -3
- package/dist/commands/sync-core.d.ts +1 -0
- package/dist/commands/sync-core.js +77 -3
- package/dist/commands/whoami.js +96 -80
- package/dist/lib/bot/config.d.ts +17 -0
- package/dist/lib/bot/config.js +13 -0
- package/dist/lib/bot/fleet-cron.js +24 -2
- package/dist/lib/bot/fleet-local.d.ts +30 -2
- package/dist/lib/bot/fleet-local.js +60 -1
- package/dist/lib/bot/grok-login-scope.d.ts +36 -0
- package/dist/lib/bot/grok-login-scope.js +93 -0
- package/dist/lib/bot/legacy-provider-login.d.ts +32 -9
- package/dist/lib/bot/legacy-provider-login.js +28 -22
- package/dist/lib/bot/runtime-sign-in-check.js +6 -1
- package/dist/lib/bot/runtime-sign-in.d.ts +2 -0
- package/dist/lib/core-utils/sentry-report.js +2 -0
- package/dist/lib/daemon/machine-checks.d.ts +22 -1
- package/dist/lib/daemon/machine-checks.js +54 -12
- package/dist/lib/daemon/run.js +66 -8
- package/dist/lib/daemon/stop-autosave-lock.d.ts +19 -0
- package/dist/lib/daemon/stop-autosave-lock.js +166 -0
- package/dist/lib/daemon/stop-autosave.d.ts +28 -0
- package/dist/lib/daemon/stop-autosave.js +111 -0
- package/dist/lib/daemon/stop-diagnostics.d.ts +11 -0
- package/dist/lib/daemon/stop-diagnostics.js +136 -0
- package/dist/lib/daemon/stop-job-executor.d.ts +19 -0
- package/dist/lib/daemon/stop-job-executor.js +126 -0
- package/dist/lib/daemon/stop-jobs.d.ts +93 -0
- package/dist/lib/daemon/stop-jobs.js +599 -0
- package/dist/lib/doctor/checks/fleet-hook-core.js +1 -1
- package/dist/lib/doctor/checks/host-core.js +1 -1
- package/dist/lib/environment/access-probes.d.ts +234 -0
- package/dist/lib/environment/access-probes.js +918 -0
- package/dist/lib/environment/profile.d.ts +15 -2
- package/dist/lib/environment/profile.js +55 -20
- package/dist/lib/environment/rfc3339.d.ts +8 -0
- package/dist/lib/environment/rfc3339.js +26 -0
- package/dist/lib/environment/work-requirements.d.ts +169 -0
- package/dist/lib/environment/work-requirements.js +389 -0
- package/dist/lib/hook-engine/coverage.d.ts +137 -7
- package/dist/lib/hook-engine/coverage.js +1424 -4
- package/dist/lib/hook-engine/fleet-registration.js +2 -2
- package/dist/lib/hook-engine/git-stop-config.json +513 -0
- package/dist/lib/hook-engine/native-stop-compatibility.json +311 -0
- package/dist/lib/hook-engine/reconcile.js +2 -2
- package/dist/lib/hot-channels/alert.d.ts +2 -2
- package/dist/lib/hot-channels/alert.js +8 -5
- package/dist/lib/hot-channels/signals-pass.d.ts +126 -17
- package/dist/lib/hot-channels/signals-pass.js +296 -17
- package/dist/lib/hot-channels/signals-runtime.d.ts +30 -0
- package/dist/lib/hot-channels/signals-runtime.js +82 -0
- package/dist/lib/install/hook-target.js +1 -1
- package/dist/lib/lanes/host-capacity.d.ts +26 -2
- package/dist/lib/lanes/host-capacity.js +17 -2
- package/dist/lib/lanes/host-compute.d.ts +90 -0
- package/dist/lib/lanes/host-compute.js +185 -0
- package/dist/lib/lanes/index.d.ts +2 -0
- package/dist/lib/lanes/index.js +1 -0
- package/dist/lib/lanes/reconcile.js +22 -1
- package/dist/lib/lanes/resource-usage.d.ts +155 -0
- package/dist/lib/lanes/resource-usage.js +589 -0
- package/dist/lib/lanes/run-size.d.ts +46 -0
- package/dist/lib/lanes/run-size.js +197 -0
- package/dist/lib/lanes/store.js +27 -0
- package/dist/lib/lanes/throttle.d.ts +36 -1
- package/dist/lib/lanes/throttle.js +47 -10
- package/dist/lib/lanes/types.d.ts +40 -0
- package/dist/lib/lanes/types.js +2 -2
- package/dist/lib/lanes/watcher.js +13 -4
- package/dist/lib/lanes/worker-process.d.ts +25 -2
- package/dist/lib/lanes/worker-process.js +71 -19
- package/dist/lib/placement/match.d.ts +192 -0
- package/dist/lib/placement/match.js +667 -0
- package/dist/lib/safe-store.d.ts +14 -0
- package/dist/lib/safe-store.js +77 -4
- package/dist/lib/search-index/index.d.ts +88 -4
- package/dist/lib/search-index/index.js +288 -24
- package/dist/lib/search-index/max-doc-bytes.d.ts +17 -6
- package/dist/lib/search-index/max-doc-bytes.js +48 -23
- package/dist/lib/signals/codex-lockdown.d.ts +79 -0
- package/dist/lib/signals/codex-lockdown.js +271 -0
- package/dist/lib/signals/codex-login.d.ts +37 -0
- package/dist/lib/signals/codex-login.js +83 -0
- package/dist/lib/signals/engine.d.ts +27 -0
- package/dist/lib/signals/engine.js +70 -0
- package/dist/lib/signals/reply.js +22 -1
- package/dist/lib/signals/run-record.js +6 -1
- package/dist/lib/signals/settings.d.ts +5 -0
- package/dist/lib/signals/settings.js +2 -0
- package/dist/lib/signals/steps/extract.d.ts +85 -9
- package/dist/lib/signals/steps/extract.js +317 -68
- package/dist/lib/signals/steps/types.d.ts +2 -0
- package/dist/lib/sync-core/engine-home.d.ts +35 -1
- package/dist/lib/sync-core/engine-home.js +119 -16
- package/dist/lib/sync-core/rollout-state.d.ts +2 -1
- package/dist/lib/sync-core/rollout-state.js +5 -2
- package/dist/lib/sync-core/vault-uid.d.ts +2 -0
- package/dist/lib/sync-core/vault-uid.js +4 -0
- package/dist/schemas/hq-work-requirements.v1.schema.json +145 -0
- package/dist/utils/auth-session-check.d.ts +16 -0
- package/dist/utils/auth-session-check.js +16 -0
- package/dist/utils/client-health-contract.d.ts +6 -0
- package/dist/utils/client-health-contract.js +13 -0
- package/dist/utils/client-health.d.ts +7 -0
- package/dist/utils/client-health.js +22 -1
- package/dist/utils/command-usage.d.ts +40 -0
- package/dist/utils/command-usage.js +61 -0
- package/dist/utils/duplicate-command-usage.d.ts +72 -0
- package/dist/utils/duplicate-command-usage.js +125 -0
- package/dist/utils/host-registration.js +2 -1
- package/dist/utils/resident-package-preload.js +4 -0
- package/dist/utils/sentry-fingerprint.js +9 -0
- package/dist/utils/windows-bash.d.ts +2 -0
- package/dist/utils/windows-bash.js +2 -1
- package/package.json +9 -8
- package/scripts/bench-core-compare.mjs +313 -0
- package/scripts/bench-core.mjs +399 -12
- package/scripts/check-function-manifest.mjs +116 -3
package/scripts/bench-core.mjs
CHANGED
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
// node scripts/bench-core.mjs --root ~/bench/hq-copy --core old,new --hq-hook ~/bin/hq-hook
|
|
22
22
|
// node scripts/bench-core.mjs --root ~/bench/hq-copy --core selected --host claude
|
|
23
23
|
// node scripts/bench-core.mjs --root ~/HQ --allow-live-root --home ~ --core selected
|
|
24
|
+
// node scripts/bench-core.mjs --root ~/bench/hq-copy --host bots --core new,selected --home ~
|
|
25
|
+
// node scripts/bench-core.mjs --root ~/bench/hq-copy --host agents-v2 --core old \
|
|
26
|
+
// --core-cmd 'old=["/bin/bash","/srv/hq/hooks/hq-agents-v2-hook-adapter.sh","{event}"]'
|
|
27
|
+
// node scripts/bench-core.mjs --root ~/bench/hq-copy --core old --save-baseline ~/bench/old-baseline.json
|
|
24
28
|
//
|
|
25
29
|
// Options:
|
|
26
30
|
// --root <dir> HQ root the hooks run against. Use a throwaway copy:
|
|
@@ -28,17 +32,34 @@
|
|
|
28
32
|
// --allow-live-root Run against a root that live sessions use (it has a
|
|
29
33
|
// host registration and session folders from a real
|
|
30
34
|
// host). Without it such a root is refused.
|
|
31
|
-
// --host <list> claude, codex, grok
|
|
35
|
+
// --host <list> claude, codex, grok, and the bot hosts fleet-local
|
|
36
|
+
// (local bots) and agents-v2 (hosted agents); bots is
|
|
37
|
+
// both bot hosts (default: claude, codex, grok).
|
|
32
38
|
// --core <list> old the old dispatcher of that host
|
|
33
|
-
// (master-hook.sh or the host's adapter script)
|
|
34
|
-
//
|
|
39
|
+
// (master-hook.sh or the host's adapter script).
|
|
40
|
+
// A bot host's adapter is not in this
|
|
41
|
+
// repository: give it with --core-cmd old=...
|
|
42
|
+
// new hq-hook run --host <host> <Event>; a bot host
|
|
43
|
+
// gets its own event name (pre_tool_call,
|
|
44
|
+
// post_tool_call, pre_llm_call)
|
|
35
45
|
// selected whatever the host's registration under
|
|
36
|
-
// --root runs for the event
|
|
46
|
+
// --root runs for the event; for a bot host,
|
|
47
|
+
// the hq-fleet profile's hooks block under
|
|
48
|
+
// --home (.hq-fleet/config.yaml, or
|
|
49
|
+
// .hq-fleet/profiles/<name>/config.yaml), run
|
|
50
|
+
// with its --hq-root set to --root
|
|
37
51
|
// or a name given with --core-cmd. Default: selected.
|
|
38
52
|
// --hq-hook <path> The hq-hook binary for --core new (default: hq-hook on PATH).
|
|
39
53
|
// --core-cmd <name>=<json array>
|
|
40
54
|
// A core given as a command line. {host} and {event} are
|
|
41
|
-
// replaced in each element
|
|
55
|
+
// replaced in each element ({event} is the bot host's
|
|
56
|
+
// own event name on a bot host). Repeatable. The name
|
|
57
|
+
// old sets the old core of the bot hosts (required with
|
|
58
|
+
// --core old and a bot host); the other hosts keep
|
|
59
|
+
// their own old core.
|
|
60
|
+
// --fleet-profile <name>
|
|
61
|
+
// The hq-fleet profile --core selected reads for a bot
|
|
62
|
+
// host, when more than one registers it.
|
|
42
63
|
// --tools <list> shell, read, edit (default: all three; a host without
|
|
43
64
|
// that tool skips it).
|
|
44
65
|
// --runs <n> Samples per measurement (default 15, at least 5).
|
|
@@ -58,6 +79,18 @@
|
|
|
58
79
|
// --timeout-ms <n> Per hook process (default 30000).
|
|
59
80
|
// --label <text> Machine name written in the report (default: hostname).
|
|
60
81
|
// --out <file> Report path (default: ./hq-bench-core-<platform>-<time>.json).
|
|
82
|
+
// --save-baseline <file>
|
|
83
|
+
// Also write the report to <file> as this machine's
|
|
84
|
+
// old-core baseline: the same JSON plus a block
|
|
85
|
+
// baseline: { core: "old", machine, hostname, platform,
|
|
86
|
+
// arch, captured_at }. Only with --core including old,
|
|
87
|
+
// and only when every old-core measurement has samples.
|
|
88
|
+
// Measure the old core first, then compare a later
|
|
89
|
+
// new-core report with scripts/bench-core-compare.mjs.
|
|
90
|
+
//
|
|
91
|
+
// Every report records started_at (when the run began) and machine.hostname,
|
|
92
|
+
// so bench-core-compare.mjs can check that a baseline was captured first and
|
|
93
|
+
// on the same machine.
|
|
61
94
|
//
|
|
62
95
|
// Exit code: 0 every measurement passes, 1 at least one fails, 3 none fails
|
|
63
96
|
// but at least one is not decidable, 2 usage or setup error (including a core
|
|
@@ -101,7 +134,10 @@ import { pathToFileURL } from "node:url";
|
|
|
101
134
|
|
|
102
135
|
export const REPORT_SCHEMA = "hq-bench-core.v1";
|
|
103
136
|
export const TARGETS_MS = Object.freeze({ tool_call: 150, prompt: 300 });
|
|
137
|
+
// The default hosts. The bot hosts run on a bot box and are measured when named.
|
|
104
138
|
export const HOSTS = Object.freeze(["claude", "codex", "grok"]);
|
|
139
|
+
export const BOT_HOSTS = Object.freeze(["fleet-local", "agents-v2"]);
|
|
140
|
+
export const ALL_HOSTS = Object.freeze([...HOSTS, ...BOT_HOSTS]);
|
|
105
141
|
export const TOOLS = Object.freeze(["shell", "read", "edit"]);
|
|
106
142
|
const BUILTIN_CORES = ["old", "new", "selected"];
|
|
107
143
|
|
|
@@ -111,8 +147,35 @@ export const HOST_TOOLS = Object.freeze({
|
|
|
111
147
|
claude: { shell: "Bash", read: "Read", edit: "Edit" },
|
|
112
148
|
codex: { shell: "Bash", read: null, edit: "apply_patch" },
|
|
113
149
|
grok: { shell: "run_terminal_command", read: "read_file", edit: "search_replace" },
|
|
150
|
+
// The HQ Fleet runtime's tools (crates/hq-hook/src/host/fleet.rs). The edit
|
|
151
|
+
// is write_file, the file tool the recorded payloads carry.
|
|
152
|
+
"fleet-local": { shell: "terminal", read: "read_file", edit: "write_file" },
|
|
153
|
+
"agents-v2": { shell: "terminal", read: "read_file", edit: "write_file" },
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
export function isBotHost(host) {
|
|
157
|
+
return BOT_HOSTS.includes(host);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// The bot hosts' own names for the measured events.
|
|
161
|
+
export const BOT_EVENT = Object.freeze({
|
|
162
|
+
PreToolUse: "pre_tool_call",
|
|
163
|
+
PostToolUse: "post_tool_call",
|
|
164
|
+
UserPromptSubmit: "pre_llm_call",
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// The shell adapter each bot host's profile registers
|
|
168
|
+
// (FLEET_ADAPTERS in src/lib/hook-engine/fleet-registration.ts).
|
|
169
|
+
const BOT_ADAPTERS = Object.freeze({
|
|
170
|
+
"fleet-local": "hq-fleet-local-hook-adapter.sh",
|
|
171
|
+
"agents-v2": "hq-agents-v2-hook-adapter.sh",
|
|
114
172
|
});
|
|
115
173
|
|
|
174
|
+
// The event word a core is called with: a bot host's own name, else the common one.
|
|
175
|
+
export function hostEvent(host, event) {
|
|
176
|
+
return isBotHost(host) ? BOT_EVENT[event] ?? event : event;
|
|
177
|
+
}
|
|
178
|
+
|
|
116
179
|
const OLD_ENTRY = Object.freeze({
|
|
117
180
|
claude: [".claude", "hooks", "master-hook.sh"],
|
|
118
181
|
codex: [".codex", "hooks", "hq-codex-hook-adapter.sh"],
|
|
@@ -164,6 +227,8 @@ export function parseArgs(argv) {
|
|
|
164
227
|
timeoutMs: 30000,
|
|
165
228
|
label: null,
|
|
166
229
|
out: null,
|
|
230
|
+
fleetProfile: null,
|
|
231
|
+
saveBaseline: null,
|
|
167
232
|
allowLiveRoot: false,
|
|
168
233
|
targets: { ...TARGETS_MS },
|
|
169
234
|
help: false,
|
|
@@ -183,7 +248,12 @@ export function parseArgs(argv) {
|
|
|
183
248
|
index += 1;
|
|
184
249
|
switch (flag) {
|
|
185
250
|
case "--root": options.root = path.resolve(value); break;
|
|
186
|
-
case "--host": case "--hosts":
|
|
251
|
+
case "--host": case "--hosts": {
|
|
252
|
+
const named = list(value, [...ALL_HOSTS, "bots"], flag);
|
|
253
|
+
options.hosts = [...new Set(named.flatMap((host) => (host === "bots" ? BOT_HOSTS : [host])))];
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
case "--fleet-profile": options.fleetProfile = value; break;
|
|
187
257
|
case "--core": case "--cores": options.cores = list(value, null, flag); break;
|
|
188
258
|
case "--tools": options.tools = list(value, TOOLS, flag); break;
|
|
189
259
|
case "--runs": options.runs = wholeNumber(value, flag, 5); break;
|
|
@@ -194,6 +264,7 @@ export function parseArgs(argv) {
|
|
|
194
264
|
case "--timeout-ms": options.timeoutMs = wholeNumber(value, flag, 100); break;
|
|
195
265
|
case "--label": options.label = value; break;
|
|
196
266
|
case "--out": options.out = path.resolve(value); break;
|
|
267
|
+
case "--save-baseline": options.saveBaseline = path.resolve(value); break;
|
|
197
268
|
case "--targets": {
|
|
198
269
|
const parts = String(value).split(",");
|
|
199
270
|
if (parts.length !== 2) throw new UsageError("--targets needs <tool call ms>,<prompt ms>");
|
|
@@ -216,7 +287,8 @@ export function parseArgs(argv) {
|
|
|
216
287
|
const at = value.indexOf("=");
|
|
217
288
|
if (at < 1) throw new UsageError("--core-cmd needs <name>=<json array>");
|
|
218
289
|
const name = value.slice(0, at);
|
|
219
|
-
|
|
290
|
+
// old is allowed: it is how a bot host's old core is given.
|
|
291
|
+
if (name !== "old" && BUILTIN_CORES.includes(name)) throw new UsageError(`--core-cmd: ${name} is a built-in core name`);
|
|
220
292
|
let command;
|
|
221
293
|
try {
|
|
222
294
|
command = JSON.parse(value.slice(at + 1));
|
|
@@ -239,6 +311,21 @@ export function parseArgs(argv) {
|
|
|
239
311
|
throw new UsageError(`--core: unknown core ${core} (use old, new, selected or a --core-cmd name)`);
|
|
240
312
|
}
|
|
241
313
|
}
|
|
314
|
+
const bots = options.hosts.filter(isBotHost);
|
|
315
|
+
if (options.coreCommands.old && bots.length === 0) {
|
|
316
|
+
throw new UsageError("--core-cmd old sets the old core of the bot hosts (fleet-local, agents-v2), and --host names none; the other hosts' old core is built in");
|
|
317
|
+
}
|
|
318
|
+
if (options.cores.includes("old") && bots.length > 0 && !options.coreCommands.old) {
|
|
319
|
+
throw new UsageError(`--core old: ${bots.join(" and ")} ${bots.length > 1 ? "have" : "has"} no old adapter in this repository; give the bot's old dispatcher with --core-cmd old=<json array>, for example old='["/bin/bash","<abs>/${BOT_ADAPTERS[bots[0]]}","{event}"]'`);
|
|
320
|
+
}
|
|
321
|
+
if (options.saveBaseline) {
|
|
322
|
+
if (!options.cores.includes("old")) {
|
|
323
|
+
throw new UsageError("--save-baseline needs a run that measures the old core (--core old or --core old,new)");
|
|
324
|
+
}
|
|
325
|
+
if (options.out && [options.out, options.out.replace(/\.json$/i, "") + ".txt"].includes(options.saveBaseline)) {
|
|
326
|
+
throw new UsageError("--save-baseline and --out must be different files");
|
|
327
|
+
}
|
|
328
|
+
}
|
|
242
329
|
return options;
|
|
243
330
|
}
|
|
244
331
|
|
|
@@ -366,6 +453,7 @@ export function buildPayload({ host, event, tool, root, sessionId, callId }) {
|
|
|
366
453
|
}
|
|
367
454
|
}
|
|
368
455
|
const toolEvent = event === "PreToolUse" || event === "PostToolUse";
|
|
456
|
+
if (isBotHost(host)) return botPayload({ host, event, tool, hostTool, root, sessionId, callId, scratch, readme, toolEvent });
|
|
369
457
|
if (host === "grok") {
|
|
370
458
|
const payload = {
|
|
371
459
|
hookEventName: GROK_EVENT[event] ?? event,
|
|
@@ -396,6 +484,50 @@ export function buildPayload({ host, event, tool, root, sessionId, callId }) {
|
|
|
396
484
|
return payload;
|
|
397
485
|
}
|
|
398
486
|
|
|
487
|
+
// The HQ Fleet runtime's shape, as in the recorded payloads under
|
|
488
|
+
// crates/hq-hook/tests/fixtures/host-payloads/<fleet-local|agents-v2>/:
|
|
489
|
+
// hook_event_name (the runtime's own name), tool_name, tool_input, session_id,
|
|
490
|
+
// cwd and extra. Tool events carry the runtime's documented extra keys; the
|
|
491
|
+
// prompt event (pre_llm_call) carries a turn id in extra, so every prompt
|
|
492
|
+
// sample is a different payload.
|
|
493
|
+
function botPayload({ event, tool, hostTool, root, sessionId, callId, scratch, readme, toolEvent }) {
|
|
494
|
+
const payload = {
|
|
495
|
+
hook_event_name: BOT_EVENT[event] ?? event,
|
|
496
|
+
tool_name: null,
|
|
497
|
+
tool_input: null,
|
|
498
|
+
session_id: sessionId,
|
|
499
|
+
cwd: root,
|
|
500
|
+
extra: {},
|
|
501
|
+
};
|
|
502
|
+
if (!toolEvent) {
|
|
503
|
+
payload.extra = { turn_id: `${callId}-turn` };
|
|
504
|
+
return payload;
|
|
505
|
+
}
|
|
506
|
+
let result;
|
|
507
|
+
if (tool === "shell") {
|
|
508
|
+
payload.tool_input = { command: "echo bench" };
|
|
509
|
+
result = { output: "bench\n", exit_code: 0 };
|
|
510
|
+
} else if (tool === "read") {
|
|
511
|
+
payload.tool_input = { path: readme };
|
|
512
|
+
result = { content: "bench" };
|
|
513
|
+
} else {
|
|
514
|
+
payload.tool_input = { path: scratch, content: "bench" };
|
|
515
|
+
result = { ok: true };
|
|
516
|
+
}
|
|
517
|
+
payload.tool_name = hostTool;
|
|
518
|
+
payload.extra = {
|
|
519
|
+
task_id: "",
|
|
520
|
+
tool_call_id: callId,
|
|
521
|
+
turn_id: `${callId}-turn`,
|
|
522
|
+
api_request_id: `${callId}-request`,
|
|
523
|
+
middleware_trace: [],
|
|
524
|
+
};
|
|
525
|
+
if (event === "PostToolUse") {
|
|
526
|
+
Object.assign(payload.extra, { result: JSON.stringify(result), status: "ok", error_type: null, error_message: null, duration_ms: 1 });
|
|
527
|
+
}
|
|
528
|
+
return payload;
|
|
529
|
+
}
|
|
530
|
+
|
|
399
531
|
// The call id makes every prompt payload different, so a core that skips a
|
|
400
532
|
// payload it has seen in the last few seconds still does the full work.
|
|
401
533
|
function benchPrompt(callId) {
|
|
@@ -490,7 +622,7 @@ export function codexRegistrations(text, event, toolName, platform = process.pla
|
|
|
490
622
|
export function describeCore(commands) {
|
|
491
623
|
const text = commands.join("\n");
|
|
492
624
|
const native = /hq-hook(?:\.exe)?["']?\s+run\s+--host\b/.test(text);
|
|
493
|
-
const bash = /master-hook\.sh|hq-codex-hook-adapter\.sh|hq-codex-hook\.cmd|hq-grok-hook-adapter\.sh/.test(text);
|
|
625
|
+
const bash = /master-hook\.sh|hq-codex-hook-adapter\.sh|hq-codex-hook\.cmd|hq-grok-hook-adapter\.sh|hq-fleet-local-hook-adapter\.sh|hq-agents-v2-hook-adapter\.sh/.test(text);
|
|
494
626
|
// The native hook engine that replaces master-hook.sh today: a pinned
|
|
495
627
|
// hq-hook called with the event name, not with run --host.
|
|
496
628
|
const engine = /hq-hook(?:\.exe)?["']?\s+(?!run\b)[A-Z][A-Za-z]+\b/.test(text);
|
|
@@ -499,6 +631,224 @@ export function describeCore(commands) {
|
|
|
499
631
|
return kinds[0] ?? "unknown";
|
|
500
632
|
}
|
|
501
633
|
|
|
634
|
+
// A command as a literal POSIX argv, or null when it uses variables or shell
|
|
635
|
+
// syntax (the same rule as literalArgv in src/lib/hook-engine/fleet-registration.ts,
|
|
636
|
+
// which the doctor's fleet-hook-core check reads profiles with).
|
|
637
|
+
export function literalArgv(command) {
|
|
638
|
+
const out = [];
|
|
639
|
+
let word = "";
|
|
640
|
+
let quote = "";
|
|
641
|
+
let started = false;
|
|
642
|
+
for (let i = 0; i < command.length; i += 1) {
|
|
643
|
+
const ch = command[i];
|
|
644
|
+
if (quote === "'") {
|
|
645
|
+
if (ch === quote) quote = "";
|
|
646
|
+
else word += ch;
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
649
|
+
if (ch === "\\") {
|
|
650
|
+
const next = command[++i];
|
|
651
|
+
if (next === undefined) return null;
|
|
652
|
+
word += next;
|
|
653
|
+
started = true;
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
656
|
+
if (quote === '"') {
|
|
657
|
+
if (ch === quote) quote = "";
|
|
658
|
+
else if ("$`".includes(ch)) return null;
|
|
659
|
+
else word += ch;
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
if (ch === "'" || ch === '"') {
|
|
663
|
+
quote = ch;
|
|
664
|
+
started = true;
|
|
665
|
+
} else if (/\s/.test(ch)) {
|
|
666
|
+
if (started) {
|
|
667
|
+
out.push(word);
|
|
668
|
+
word = "";
|
|
669
|
+
started = false;
|
|
670
|
+
}
|
|
671
|
+
} else if (";$`|&<>()\n\0".includes(ch)) {
|
|
672
|
+
return null;
|
|
673
|
+
} else {
|
|
674
|
+
word += ch;
|
|
675
|
+
started = true;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
if (quote) return null;
|
|
679
|
+
if (started) out.push(word);
|
|
680
|
+
return out;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
function yamlScalar(raw) {
|
|
684
|
+
const text = raw.trim();
|
|
685
|
+
if (text.startsWith('"')) {
|
|
686
|
+
const match = /^"(?:[^"\\]|\\.)*"/.exec(text);
|
|
687
|
+
if (!match) return null;
|
|
688
|
+
try {
|
|
689
|
+
return JSON.parse(match[0]);
|
|
690
|
+
} catch {
|
|
691
|
+
return null;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
if (text.startsWith("'")) {
|
|
695
|
+
const match = /^'((?:[^']|'')*)'/.exec(text);
|
|
696
|
+
return match ? match[1].replaceAll("''", "'") : null;
|
|
697
|
+
}
|
|
698
|
+
if (text === "" || /^[|>]/.test(text)) return null;
|
|
699
|
+
return text.replace(/\s+#.*$/, "");
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// The hooks block of an hq-fleet profile's config.yaml: { <event>: [command] }.
|
|
703
|
+
// The script needs nothing but Node, so this reads JSON, or the YAML subset a
|
|
704
|
+
// profile's hooks block is written in: event keys holding a list of mappings
|
|
705
|
+
// with a one-line command. An unreadable command marks the whole event null,
|
|
706
|
+
// so selected cannot time only the readable subset of its hooks.
|
|
707
|
+
export function fleetHooks(text) {
|
|
708
|
+
try {
|
|
709
|
+
const document = JSON.parse(text);
|
|
710
|
+
const hooks = document?.hooks;
|
|
711
|
+
if (!hooks || typeof hooks !== "object") return {};
|
|
712
|
+
const found = {};
|
|
713
|
+
for (const [event, entries] of Object.entries(hooks)) {
|
|
714
|
+
if (!Array.isArray(entries)) continue;
|
|
715
|
+
const commands = entries.filter((entry) => entry != null && Object.hasOwn(entry, "command")).map((entry) => entry.command);
|
|
716
|
+
found[event] = commands.some((command) => typeof command !== "string") ? null : commands;
|
|
717
|
+
}
|
|
718
|
+
return found;
|
|
719
|
+
} catch {
|
|
720
|
+
// YAML.
|
|
721
|
+
}
|
|
722
|
+
const found = {};
|
|
723
|
+
const lines = text.split(/\r?\n/);
|
|
724
|
+
const start = lines.findIndex((line) => /^hooks:/.test(line));
|
|
725
|
+
if (start >= 0 && !/^hooks:\s*(#.*)?$/.test(lines[start])) {
|
|
726
|
+
throw new UsageError("unsupported Fleet hooks mapping; cannot benchmark a partial registration");
|
|
727
|
+
}
|
|
728
|
+
if (start < 0) return found;
|
|
729
|
+
let eventIndent = null;
|
|
730
|
+
let event = null;
|
|
731
|
+
for (const line of lines.slice(start + 1)) {
|
|
732
|
+
if (/^\s*(#.*)?$/.test(line)) continue;
|
|
733
|
+
const indent = line.length - line.trimStart().length;
|
|
734
|
+
if (indent === 0) break;
|
|
735
|
+
const inlineEvent = /^\s*([A-Za-z_][\w-]*):\s*([^#\s].*)$/.exec(line);
|
|
736
|
+
if (inlineEvent && (eventIndent === null || indent <= eventIndent)) {
|
|
737
|
+
throw new UsageError("unsupported Fleet event mapping; cannot benchmark a partial registration");
|
|
738
|
+
}
|
|
739
|
+
if (/^\s*(?:-\s*)?["']/.test(line) || /^\s*-\s*[{&*]/.test(line)) {
|
|
740
|
+
throw new UsageError("unsupported Fleet hook entry; cannot benchmark a partial registration");
|
|
741
|
+
}
|
|
742
|
+
const key = /^\s*([A-Za-z_][\w-]*):\s*(#.*)?$/.exec(line);
|
|
743
|
+
if (key && (eventIndent === null || indent <= eventIndent)) {
|
|
744
|
+
eventIndent = indent;
|
|
745
|
+
event = key[1];
|
|
746
|
+
found[event] ??= [];
|
|
747
|
+
continue;
|
|
748
|
+
}
|
|
749
|
+
// A list item may sit at the key's own indent (" pre_llm_call:\n - command: x").
|
|
750
|
+
if (event === null || (indent < eventIndent || (indent === eventIndent && !line.trimStart().startsWith("-")))) continue;
|
|
751
|
+
const command = /^\s*(?:-\s+)?command:\s*(.*)$/.exec(line);
|
|
752
|
+
if (command) {
|
|
753
|
+
const value = yamlScalar(command[1]);
|
|
754
|
+
if (value === null) found[event] = null;
|
|
755
|
+
else if (found[event] !== null) found[event].push(value);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
return found;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// The hq-fleet profiles under the home folder, as the doctor's
|
|
762
|
+
// fleet-hook-core check finds them: <base>/config.yaml for a single profile,
|
|
763
|
+
// else <base>/profiles/<name>/config.yaml. <base> is HQ_FLEET_HOME when given
|
|
764
|
+
// with --env, else <home>/.hq-fleet.
|
|
765
|
+
function fleetProfiles(options) {
|
|
766
|
+
const base = options.env?.HQ_FLEET_HOME?.trim() || (options.home ? path.join(options.home, ".hq-fleet") : null);
|
|
767
|
+
if (!base) return { base: null, profiles: [] };
|
|
768
|
+
if (fs.existsSync(path.join(base, "config.yaml"))) {
|
|
769
|
+
return { base, profiles: [{ name: path.basename(base), file: path.join(base, "config.yaml") }] };
|
|
770
|
+
}
|
|
771
|
+
try {
|
|
772
|
+
const names = fs.readdirSync(path.join(base, "profiles")).sort();
|
|
773
|
+
return { base, profiles: names.map((name) => ({ name, file: path.join(base, "profiles", name, "config.yaml") })) };
|
|
774
|
+
} catch {
|
|
775
|
+
return { base, profiles: [] };
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// selected for a bot host: the HQ entries one hq-fleet profile registers for
|
|
780
|
+
// the event and this host. A native entry (hq-hook run --host <host>) runs as
|
|
781
|
+
// registered with its --hq-root set to --root, so the run stays on the
|
|
782
|
+
// throwaway root; a shell adapter entry runs as registered.
|
|
783
|
+
function botSelected({ host, event, options, rootEnv }) {
|
|
784
|
+
const { base, profiles } = fleetProfiles(options);
|
|
785
|
+
const candidates = [];
|
|
786
|
+
const belongsToHost = (argv) => {
|
|
787
|
+
if (!argv || argv.length === 0) return false;
|
|
788
|
+
const native = path.basename(argv[0]).replace(/\.exe$/i, "") === "hq-hook" && argv[1] === "run" && argv[2] === "--host" && argv[3] === host;
|
|
789
|
+
const adapter = argv[1] !== "run" && argv.some((arg) => path.basename(arg) === BOT_ADAPTERS[host]);
|
|
790
|
+
return native || adapter;
|
|
791
|
+
};
|
|
792
|
+
for (const profile of profiles) {
|
|
793
|
+
if (options.fleetProfile && profile.name !== options.fleetProfile) continue;
|
|
794
|
+
let text;
|
|
795
|
+
try {
|
|
796
|
+
const stat = fs.lstatSync(profile.file);
|
|
797
|
+
if (!stat.isFile()) continue;
|
|
798
|
+
text = fs.readFileSync(profile.file, "utf8");
|
|
799
|
+
} catch {
|
|
800
|
+
continue;
|
|
801
|
+
}
|
|
802
|
+
const hooks = fleetHooks(text);
|
|
803
|
+
const commands = hooks[event];
|
|
804
|
+
if (commands === null) throw new UsageError(`${profile.file}: unreadable command for ${event}; cannot benchmark a partial registration`);
|
|
805
|
+
const argvs = (commands ?? []).map(literalArgv);
|
|
806
|
+
if (argvs.some((argv) => !argv || argv.length === 0)) {
|
|
807
|
+
throw new UsageError(`${profile.file}: nonliteral command for ${event}; cannot benchmark a partial registration`);
|
|
808
|
+
}
|
|
809
|
+
const mine = argvs.filter(belongsToHost);
|
|
810
|
+
// Select one profile for the host, rather than stitching together events
|
|
811
|
+
// from different profiles that no real bot would run together.
|
|
812
|
+
const registersHost = Object.values(hooks).some((entries) =>
|
|
813
|
+
Array.isArray(entries) && entries.some((command) => belongsToHost(literalArgv(command))));
|
|
814
|
+
if (registersHost) candidates.push({ profile, argvs: mine });
|
|
815
|
+
}
|
|
816
|
+
const where = base ? `an hq-fleet profile under ${base}${options.fleetProfile ? ` named ${options.fleetProfile}` : ""}` : "an hq-fleet profile (no home folder given)";
|
|
817
|
+
if (candidates.length === 0 || (candidates.length === 1 && candidates[0].argvs.length === 0)) {
|
|
818
|
+
return { steps: [], detected: "none", missing: `no ${host} registration for ${event} in ${where}` };
|
|
819
|
+
}
|
|
820
|
+
if (candidates.length > 1) {
|
|
821
|
+
return {
|
|
822
|
+
steps: [],
|
|
823
|
+
detected: "none",
|
|
824
|
+
missing: `more than one hq-fleet profile registers ${host} for ${event} (${candidates.map((candidate) => candidate.profile.name).join(", ")}); pick one with --fleet-profile`,
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
const steps = candidates[0].argvs.map((registered) => {
|
|
828
|
+
let argv = [...registered];
|
|
829
|
+
if (argv[1] === "run") {
|
|
830
|
+
const normalized = [];
|
|
831
|
+
let replaced = false;
|
|
832
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
833
|
+
const arg = argv[index];
|
|
834
|
+
if (arg === "--hq-root" || arg.startsWith("--hq-root=")) {
|
|
835
|
+
if (!replaced) normalized.push("--hq-root", options.root);
|
|
836
|
+
replaced = true;
|
|
837
|
+
if (arg === "--hq-root") index += 1;
|
|
838
|
+
} else normalized.push(arg);
|
|
839
|
+
}
|
|
840
|
+
if (!replaced) normalized.push("--hq-root", options.root);
|
|
841
|
+
argv = normalized;
|
|
842
|
+
}
|
|
843
|
+
// The fallback argument names the adapter; it is not what runs, so it
|
|
844
|
+
// does not count when the core is named.
|
|
845
|
+
const fallbackAt = argv.indexOf("--fleet-fallback");
|
|
846
|
+
const named = argv[1] === "run" && fallbackAt > 0 ? argv.filter((_, index) => index !== fallbackAt && index !== fallbackAt + 1) : argv;
|
|
847
|
+
return { file: argv[0], args: argv.slice(1), env: { ...rootEnv }, cwd: options.root, display: argv.join(" "), named: named.join(" ") };
|
|
848
|
+
});
|
|
849
|
+
return { steps, detected: describeCore(steps.map((step) => step.named)), profile: candidates[0].profile.file };
|
|
850
|
+
}
|
|
851
|
+
|
|
502
852
|
function defaultBash(platform) {
|
|
503
853
|
if (platform !== "win32") return "bash";
|
|
504
854
|
for (const base of [process.env.ProgramFiles, process.env["ProgramFiles(x86)"], process.env.LOCALAPPDATA && path.join(process.env.LOCALAPPDATA, "Programs")]) {
|
|
@@ -516,14 +866,21 @@ export function resolveInvocation({ host, core, event, tool, options, platform =
|
|
|
516
866
|
const bash = options.bash ?? process.env.HQ_BASH_EXE ?? defaultBash(platform);
|
|
517
867
|
const rootEnv = { CLAUDE_PROJECT_DIR: root, HQ_ROOT: root };
|
|
518
868
|
const hostTool = tool ? HOST_TOOLS[host][tool] : null;
|
|
869
|
+
const bot = isBotHost(host);
|
|
870
|
+
const word = hostEvent(host, event);
|
|
519
871
|
|
|
520
|
-
|
|
521
|
-
|
|
872
|
+
// --core-cmd old is the old core of the bot hosts only.
|
|
873
|
+
if (options.coreCommands[core] && (core !== "old" || bot)) {
|
|
874
|
+
const [file, ...args] = options.coreCommands[core].map((part) => part.replaceAll("{host}", host).replaceAll("{event}", word));
|
|
522
875
|
return { steps: [{ file, args, env: rootEnv, cwd: root, display: [file, ...args].join(" ") }], detected: core };
|
|
523
876
|
}
|
|
524
877
|
|
|
878
|
+
if (core === "old" && bot) {
|
|
879
|
+
return { steps: [], detected: "old", missing: `${host} has no old adapter in this repository; give it with --core-cmd old=<json array>` };
|
|
880
|
+
}
|
|
881
|
+
|
|
525
882
|
if (core === "new") {
|
|
526
|
-
const args = ["run", "--host", host,
|
|
883
|
+
const args = ["run", "--host", host, word];
|
|
527
884
|
return { steps: [{ file: options.hqHook, args, env: rootEnv, cwd: root, display: `${options.hqHook} ${args.join(" ")}` }], detected: "new" };
|
|
528
885
|
}
|
|
529
886
|
|
|
@@ -540,6 +897,7 @@ export function resolveInvocation({ host, core, event, tool, options, platform =
|
|
|
540
897
|
// Project files under --root are HQ's own; in the home folder only entries
|
|
541
898
|
// that run an HQ core count.
|
|
542
899
|
// With no home folder given, no user-level file is read.
|
|
900
|
+
if (bot) return botSelected({ host, event: word, options, rootEnv });
|
|
543
901
|
const inHome = (...parts) => (options.home ? path.join(options.home, ...parts) : null);
|
|
544
902
|
const registrations = [];
|
|
545
903
|
if (host === "claude") {
|
|
@@ -708,7 +1066,8 @@ function killTree(child) {
|
|
|
708
1066
|
|
|
709
1067
|
// A refusal a hook writes to stdout while exiting 0: Claude Code and Codex
|
|
710
1068
|
// read decision "block" or "deny", hookSpecificOutput.permissionDecision
|
|
711
|
-
// "deny" or "ask", and continue false; Grok Build reads the same names
|
|
1069
|
+
// "deny" or "ask", and continue false; Grok Build reads the same names; the
|
|
1070
|
+
// HQ Fleet runtime reads action "block". The
|
|
712
1071
|
// harmless test payload must not be refused; a refused sample says nothing
|
|
713
1072
|
// about a normal call. Returns the refusal as text, or null.
|
|
714
1073
|
export function refusalIn(stdout) {
|
|
@@ -726,6 +1085,8 @@ export function refusalIn(stdout) {
|
|
|
726
1085
|
if (!answer || typeof answer !== "object") return null;
|
|
727
1086
|
const decision = String(answer.decision ?? "").toLowerCase();
|
|
728
1087
|
if (decision === "block" || decision === "deny") return `decision ${decision}`;
|
|
1088
|
+
// The HQ Fleet runtime's own refusal on pre_tool_call.
|
|
1089
|
+
if (String(answer.action ?? "").toLowerCase() === "block") return "action block";
|
|
729
1090
|
const specific = answer.hookSpecificOutput ?? {};
|
|
730
1091
|
const permission = String(specific.permissionDecision ?? "").toLowerCase();
|
|
731
1092
|
if (permission === "deny" || permission === "ask") return `permissionDecision ${permission}`;
|
|
@@ -1072,6 +1433,7 @@ export async function main(argv, io = { out: process.stdout, err: process.stderr
|
|
|
1072
1433
|
io.out.write(usage());
|
|
1073
1434
|
return 0;
|
|
1074
1435
|
}
|
|
1436
|
+
const startedAt = new Date().toISOString();
|
|
1075
1437
|
let report;
|
|
1076
1438
|
try {
|
|
1077
1439
|
report = await runBenchmark(options, (text) => io.err.write(`bench-core: ${text}\n`));
|
|
@@ -1079,6 +1441,8 @@ export async function main(argv, io = { out: process.stdout, err: process.stderr
|
|
|
1079
1441
|
io.err.write(`bench-core: ${error.message}\n`);
|
|
1080
1442
|
return 2;
|
|
1081
1443
|
}
|
|
1444
|
+
report = { schema: report.schema, started_at: startedAt, ...report };
|
|
1445
|
+
report.machine = { label: report.machine.label, hostname: os.hostname(), ...report.machine };
|
|
1082
1446
|
const stamp = report.generated_at.replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z");
|
|
1083
1447
|
const out = options.out ?? path.resolve(`hq-bench-core-${process.platform}-${stamp}.json`);
|
|
1084
1448
|
const text = formatReport(report);
|
|
@@ -1088,6 +1452,29 @@ export async function main(argv, io = { out: process.stdout, err: process.stderr
|
|
|
1088
1452
|
fs.writeFileSync(textOut, text);
|
|
1089
1453
|
io.out.write(text);
|
|
1090
1454
|
io.out.write(`report: ${out}\nreport (text): ${textOut}\n`);
|
|
1455
|
+
if (options.saveBaseline) {
|
|
1456
|
+
const old = report.results.filter((result) => result.core === "old");
|
|
1457
|
+
const empty = old.filter((result) => result.n === 0);
|
|
1458
|
+
if (old.length === 0 || empty.length > 0) {
|
|
1459
|
+
const which = empty.map((result) => `${result.host} ${result.measure}${result.host_tool ? ` ${result.host_tool}` : ""}`).join(", ");
|
|
1460
|
+
io.err.write(`bench-core: --save-baseline: the old core has no samples${which ? ` for ${which}` : ""}; no baseline written\n`);
|
|
1461
|
+
return 2;
|
|
1462
|
+
}
|
|
1463
|
+
const baseline = {
|
|
1464
|
+
...report,
|
|
1465
|
+
baseline: {
|
|
1466
|
+
core: "old",
|
|
1467
|
+
machine: report.machine.label,
|
|
1468
|
+
hostname: report.machine.hostname,
|
|
1469
|
+
platform: report.machine.platform,
|
|
1470
|
+
arch: report.machine.arch,
|
|
1471
|
+
captured_at: report.generated_at,
|
|
1472
|
+
},
|
|
1473
|
+
};
|
|
1474
|
+
fs.mkdirSync(path.dirname(options.saveBaseline), { recursive: true });
|
|
1475
|
+
fs.writeFileSync(options.saveBaseline, `${JSON.stringify(baseline, null, 2)}\n`);
|
|
1476
|
+
io.out.write(`baseline (old core): ${options.saveBaseline}\n`);
|
|
1477
|
+
}
|
|
1091
1478
|
return report.exit_code;
|
|
1092
1479
|
}
|
|
1093
1480
|
|