@indigoai-us/hq-cli 5.345.220 → 5.345.222
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 +164 -0
- package/dist/command-catalog.generated.d.ts +175 -2
- package/dist/command-catalog.generated.js +213 -2
- package/dist/commands/auth.js +6 -2
- 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-delegate-w1b.js +9 -3
- 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 +6 -0
- package/dist/commands/daemon.js +46 -8
- 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/link.d.ts +2 -0
- package/dist/commands/link.js +14 -2
- package/dist/commands/mesh.js +23 -3
- package/dist/commands/sources.js +3 -3
- package/dist/commands/sync-core.d.ts +7 -0
- package/dist/commands/sync-core.js +132 -3
- package/dist/commands/whoami.js +96 -80
- package/dist/data/command-states.json +3 -0
- 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/catalog.js +2 -0
- package/dist/lib/daemon/install.d.ts +2 -1
- package/dist/lib/daemon/install.js +9 -0
- package/dist/lib/daemon/legacy.d.ts +1 -0
- package/dist/lib/daemon/legacy.js +5 -2
- package/dist/lib/daemon/machine-check-owner.d.ts +2 -0
- package/dist/lib/daemon/machine-check-owner.js +6 -1
- package/dist/lib/daemon/machine-checks.d.ts +29 -2
- package/dist/lib/daemon/machine-checks.js +64 -13
- package/dist/lib/daemon/mesh-owner.d.ts +45 -0
- package/dist/lib/daemon/mesh-owner.js +166 -0
- package/dist/lib/daemon/native-notice-ledger.d.ts +27 -0
- package/dist/lib/daemon/native-notice-ledger.js +113 -0
- package/dist/lib/daemon/run.d.ts +15 -0
- package/dist/lib/daemon/run.js +137 -11
- package/dist/lib/daemon/selfcheck.d.ts +35 -2
- package/dist/lib/daemon/selfcheck.js +118 -9
- 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 +146 -7
- package/dist/lib/hook-engine/coverage.js +1480 -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 +362 -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/mesh/live/daemon/config.d.ts +8 -1
- package/dist/lib/mesh/live/daemon/config.js +16 -0
- package/dist/lib/mesh/live/daemon/install.d.ts +31 -2
- package/dist/lib/mesh/live/daemon/install.js +142 -1
- package/dist/lib/mesh/live/daemon/login-home.d.ts +5 -0
- package/dist/lib/mesh/live/daemon/login-home.js +27 -0
- package/dist/lib/mesh/live/daemon/unit-home.d.ts +49 -0
- package/dist/lib/mesh/live/daemon/unit-home.js +134 -0
- package/dist/lib/placement/match.d.ts +192 -0
- package/dist/lib/placement/match.js +667 -0
- package/dist/lib/registry/registry.d.ts +35 -7
- package/dist/lib/registry/registry.js +88 -13
- package/dist/lib/safe-store.d.ts +14 -0
- package/dist/lib/safe-store.js +77 -4
- package/dist/lib/scan-packages/index.js +24 -2
- 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 +49 -23
- package/dist/lib/service-manager/startup-migration.d.ts +1 -0
- package/dist/lib/service-manager/startup-migration.js +3 -0
- 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-holds.d.ts +14 -0
- package/dist/lib/sync-core/engine-holds.js +60 -0
- package/dist/lib/sync-core/engine-home.d.ts +37 -1
- package/dist/lib/sync-core/engine-home.js +119 -16
- package/dist/lib/sync-core/reconcile.js +8 -0
- 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-settings.d.ts +21 -0
- package/dist/lib/sync-core/vault-settings.js +131 -0
- package/dist/lib/sync-core/vault-uid.d.ts +2 -0
- package/dist/lib/sync-core/vault-uid.js +4 -0
- package/dist/lib/windows/install-followup.d.ts +2 -0
- package/dist/lib/windows/install-followup.js +4 -1
- 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 +5 -2
- package/dist/utils/pack-contributions.d.ts +3 -0
- package/dist/utils/pack-contributions.js +110 -23
- package/dist/utils/resident-package-preload.js +4 -0
- package/dist/utils/self-update.d.ts +3 -1
- package/dist/utils/self-update.js +56 -11
- package/dist/utils/sentry-fingerprint.js +9 -0
- package/dist/utils/update-lock.d.ts +151 -14
- package/dist/utils/update-lock.js +782 -46
- package/dist/utils/version-gate.js +12 -2
- 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
|
@@ -42,7 +42,7 @@ import { isVersionRequest } from "../version-request.js";
|
|
|
42
42
|
import { Sentry } from "../sentry.js";
|
|
43
43
|
import { isCliTelemetryDisabled } from "./cli-telemetry.js";
|
|
44
44
|
import { DEFAULT_VAULT_API_URL } from "./cognito-session.js";
|
|
45
|
-
import { acquireUpdateLock, } from "./update-lock.js";
|
|
45
|
+
import { acquireUpdateLock, STARTUP_TAKEOVER_WAIT_MS, } from "./update-lock.js";
|
|
46
46
|
import { HQ_CLI_NPM_UPDATE_COMMAND, hqCliNpmInstallCommand, npmGlobalInstallArgv } from "./npm-install-flags.js";
|
|
47
47
|
/** Prevent an update package manager's lifecycle child from starting another updater. */
|
|
48
48
|
export const UPDATE_RECURSION_GUARD_ENV = "HQ_RESCUE_SELF_UPDATED";
|
|
@@ -1825,12 +1825,22 @@ function enforceUpdateRequired(decision, deps = {}) {
|
|
|
1825
1825
|
// for the cross-repo contract. A fresh holder means someone else is already
|
|
1826
1826
|
// installing the version we want: skip and continue on the current version
|
|
1827
1827
|
// (the gate must never break the CLI).
|
|
1828
|
-
|
|
1828
|
+
// Start-up path: a short mutex wait, so a wedged takeover mutex costs every
|
|
1829
|
+
// command at most a second instead of ten.
|
|
1830
|
+
const lock = deps.acquireLock
|
|
1831
|
+
? deps.acquireLock()
|
|
1832
|
+
: acquireUpdateLock({ takeoverWaitMs: STARTUP_TAKEOVER_WAIT_MS });
|
|
1829
1833
|
if (!lock) {
|
|
1830
1834
|
console.error(chalk.dim(" Another hq updater is already installing (update lock held); continuing on the current version."));
|
|
1831
1835
|
return;
|
|
1832
1836
|
}
|
|
1833
1837
|
currentVersionGatePhase = "lock_acquired";
|
|
1838
|
+
// A racing taker may have moved our lock between acquisition and now.
|
|
1839
|
+
if (typeof lock.stillHeld === "function" && !lock.stillHeld()) {
|
|
1840
|
+
lock.release();
|
|
1841
|
+
console.error(chalk.dim(" Another hq updater took over the update lock; continuing on the current version."));
|
|
1842
|
+
return;
|
|
1843
|
+
}
|
|
1834
1844
|
let attempt;
|
|
1835
1845
|
try {
|
|
1836
1846
|
attempt = attemptRequiredUpdate(decision, deps, install);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** System32\bash.exe (WSL) or a WindowsApps alias: never used as Git Bash. */
|
|
2
|
+
export declare function isExcludedWindowsBash(file: string, env: Record<string, string | undefined>): boolean;
|
|
1
3
|
export declare function resolveWindowsBash(env: Record<string, string | undefined>): {
|
|
2
4
|
executable?: string;
|
|
3
5
|
cause: unknown;
|
|
@@ -19,7 +19,8 @@ function isWithinWindowsDirectory(file, directory) {
|
|
|
19
19
|
return normalizedFile === normalizedDirectory
|
|
20
20
|
|| normalizedFile.startsWith(`${normalizedDirectory}${path.win32.sep}`);
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
/** System32\bash.exe (WSL) or a WindowsApps alias: never used as Git Bash. */
|
|
23
|
+
export function isExcludedWindowsBash(file, env) {
|
|
23
24
|
if (path.win32.basename(file).toLowerCase() !== "bash.exe")
|
|
24
25
|
return false;
|
|
25
26
|
const windowsDir = envValue(env, "SystemRoot") ?? envValue(env, "WINDIR") ?? "C:\\Windows";
|
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.222",
|
|
4
4
|
"description": "HQ by Indigo management CLI — modules and cloud sync",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"contracts",
|
|
30
30
|
"scripts/install-hook-engine.mjs",
|
|
31
31
|
"scripts/check-function-manifest.mjs",
|
|
32
|
-
"scripts/bench-core.mjs"
|
|
32
|
+
"scripts/bench-core.mjs",
|
|
33
|
+
"scripts/bench-core-compare.mjs"
|
|
33
34
|
],
|
|
34
35
|
"scripts": {
|
|
35
36
|
"build": "node scripts/generate-dsn.mjs && node scripts/build-flag-registry-worker.mjs && tsc && node scripts/generate-command-catalog.mjs --check && node scripts/copy-schemas.mjs && node scripts/chmod-bins.mjs && node scripts/bundle-sync-runner.mjs",
|
|
@@ -123,11 +124,11 @@
|
|
|
123
124
|
"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
|
|
124
125
|
},
|
|
125
126
|
"optionalDependencies": {
|
|
126
|
-
"@indigoai-us/hq-hook-win32-x64": "5.345.
|
|
127
|
-
"@indigoai-us/hq-hook-win32-arm64": "5.345.
|
|
128
|
-
"@indigoai-us/hq-hook-darwin-x64": "5.345.
|
|
129
|
-
"@indigoai-us/hq-hook-darwin-arm64": "5.345.
|
|
130
|
-
"@indigoai-us/hq-hook-linux-x64": "5.345.
|
|
131
|
-
"@indigoai-us/hq-hook-linux-arm64": "5.345.
|
|
127
|
+
"@indigoai-us/hq-hook-win32-x64": "5.345.222",
|
|
128
|
+
"@indigoai-us/hq-hook-win32-arm64": "5.345.222",
|
|
129
|
+
"@indigoai-us/hq-hook-darwin-x64": "5.345.222",
|
|
130
|
+
"@indigoai-us/hq-hook-darwin-arm64": "5.345.222",
|
|
131
|
+
"@indigoai-us/hq-hook-linux-x64": "5.345.222",
|
|
132
|
+
"@indigoai-us/hq-hook-linux-arm64": "5.345.222"
|
|
132
133
|
}
|
|
133
134
|
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// bench-core-compare.mjs: compares a new-core speed gate report with the
|
|
3
|
+
// old-core baseline captured earlier on the same machine.
|
|
4
|
+
//
|
|
5
|
+
// The speed gate (scripts/bench-core.mjs) decides pass or fail on its own;
|
|
6
|
+
// this script only puts the old core's numbers beside it. It needs Node 20 or
|
|
7
|
+
// later and nothing else, so it runs on a bot box or on any machine the two
|
|
8
|
+
// JSON files were copied to.
|
|
9
|
+
//
|
|
10
|
+
// Usage:
|
|
11
|
+
// 1. On the bot box, measure the old core first and keep it as the baseline:
|
|
12
|
+
// node scripts/bench-core.mjs --root ~/bench/hq-copy --core old --save-baseline ~/bench/old-baseline.json
|
|
13
|
+
// 2. Later, on the same machine, measure the new core:
|
|
14
|
+
// node scripts/bench-core.mjs --root ~/bench/hq-copy --core new --hq-hook ~/bin/hq-hook --out ~/bench/new.json
|
|
15
|
+
// 3. Compare:
|
|
16
|
+
// node scripts/bench-core-compare.mjs --baseline ~/bench/old-baseline.json --report ~/bench/new.json
|
|
17
|
+
// node scripts/bench-core-compare.mjs --baseline old-baseline.json --report new.json --json --output compare.json
|
|
18
|
+
//
|
|
19
|
+
// Options:
|
|
20
|
+
// --baseline <file> A report written by bench-core.mjs --save-baseline.
|
|
21
|
+
// --report <file> A later bench-core.mjs report (the new core).
|
|
22
|
+
// --json Print the comparison as JSON instead of text.
|
|
23
|
+
// --output <file> Also write the comparison JSON to <file>, to copy off
|
|
24
|
+
// the machine.
|
|
25
|
+
//
|
|
26
|
+
// It refuses (exit 2, naming the field) unless:
|
|
27
|
+
// - both files are bench-core reports (schema hq-bench-core.v1);
|
|
28
|
+
// - the baseline has a baseline block for the old core and old-core results;
|
|
29
|
+
// - baseline.captured_at is earlier than the report's started_at (the old
|
|
30
|
+
// core was measured first);
|
|
31
|
+
// - baseline machine, hostname, platform and arch equal the report's
|
|
32
|
+
// machine.label, machine.hostname, machine.platform and machine.arch
|
|
33
|
+
// (the same machine);
|
|
34
|
+
// - the report was measured against the speed gate's targets (150 ms per
|
|
35
|
+
// tool call, 300 ms per prompt).
|
|
36
|
+
//
|
|
37
|
+
// For every host and measurement present in both (the old core in the
|
|
38
|
+
// baseline, each other core in the report) it lists the old median, the new
|
|
39
|
+
// median, the difference in ms and in percent, and the report's own verdict
|
|
40
|
+
// for that measurement, unchanged. A host or measurement present in only one
|
|
41
|
+
// of the two is listed as missing; that is not an error.
|
|
42
|
+
//
|
|
43
|
+
// Exit code: 0 the report passes the speed gate, 1 it does not (fail, or not
|
|
44
|
+
// decidable, or a setup error in the report), 2 refusal or usage error. The
|
|
45
|
+
// comparison never changes the gate's answer: a report that fails stays 1 even
|
|
46
|
+
// when it is faster than the baseline.
|
|
47
|
+
|
|
48
|
+
import * as fs from "node:fs";
|
|
49
|
+
import * as path from "node:path";
|
|
50
|
+
import { pathToFileURL } from "node:url";
|
|
51
|
+
|
|
52
|
+
export const REPORT_SCHEMA = "hq-bench-core.v1";
|
|
53
|
+
export const COMPARE_SCHEMA = "hq-bench-core-compare.v1";
|
|
54
|
+
export const GATE_TARGETS_MS = Object.freeze({ tool_call: 150, prompt: 300 });
|
|
55
|
+
const PASS = "pass";
|
|
56
|
+
|
|
57
|
+
export class UsageError extends Error {}
|
|
58
|
+
export class Refusal extends Error {
|
|
59
|
+
constructor(field, message) {
|
|
60
|
+
super(`${field}: ${message}`);
|
|
61
|
+
this.field = field;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function parseArgs(argv) {
|
|
66
|
+
const options = { baseline: null, report: null, json: false, output: null, help: false };
|
|
67
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
68
|
+
const flag = argv[index];
|
|
69
|
+
if (flag === "-h" || flag === "--help") {
|
|
70
|
+
options.help = true;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (flag === "--json") {
|
|
74
|
+
options.json = true;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const value = argv[index + 1];
|
|
78
|
+
if (value === undefined) throw new UsageError(`${flag} needs a value`);
|
|
79
|
+
index += 1;
|
|
80
|
+
switch (flag) {
|
|
81
|
+
case "--baseline": options.baseline = path.resolve(value); break;
|
|
82
|
+
case "--report": options.report = path.resolve(value); break;
|
|
83
|
+
case "--output": options.output = path.resolve(value); break;
|
|
84
|
+
default: throw new UsageError(`unknown option: ${flag}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (options.help) return options;
|
|
88
|
+
if (!options.baseline) throw new UsageError("--baseline is required");
|
|
89
|
+
if (!options.report) throw new UsageError("--report is required");
|
|
90
|
+
return options;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function readReport(file, flag) {
|
|
94
|
+
let text;
|
|
95
|
+
try {
|
|
96
|
+
text = fs.readFileSync(file, "utf8");
|
|
97
|
+
} catch (error) {
|
|
98
|
+
throw new UsageError(`${flag}: cannot read ${file} (${error.code ?? error.message})`);
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
return JSON.parse(text);
|
|
102
|
+
} catch {
|
|
103
|
+
throw new UsageError(`${flag}: ${file} is not JSON`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function time(value) {
|
|
108
|
+
if (typeof value !== "string") return null;
|
|
109
|
+
const ms = Date.parse(value);
|
|
110
|
+
return Number.isFinite(ms) ? ms : null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Throws a Refusal naming the field when the pair cannot be compared.
|
|
114
|
+
export function checkPair(baseline, report) {
|
|
115
|
+
if (baseline?.schema !== REPORT_SCHEMA) throw new Refusal("baseline schema", `expected ${REPORT_SCHEMA}, found ${baseline?.schema ?? "none"}`);
|
|
116
|
+
if (report?.schema !== REPORT_SCHEMA) throw new Refusal("report schema", `expected ${REPORT_SCHEMA}, found ${report?.schema ?? "none"}`);
|
|
117
|
+
const block = baseline.baseline;
|
|
118
|
+
if (!block || typeof block !== "object") {
|
|
119
|
+
throw new Refusal("baseline", "the baseline file has no baseline block; write it with bench-core.mjs --core old --save-baseline <file>");
|
|
120
|
+
}
|
|
121
|
+
if (block.core !== "old") throw new Refusal("baseline.core", `expected old, found ${block.core ?? "none"}`);
|
|
122
|
+
if (!Array.isArray(baseline.results) || !baseline.results.some((result) => result.core === "old")) {
|
|
123
|
+
throw new Refusal("baseline results", "the baseline has no old-core results");
|
|
124
|
+
}
|
|
125
|
+
if (!Array.isArray(report.results)) throw new Refusal("report results", "the report has no results");
|
|
126
|
+
|
|
127
|
+
const captured = time(block.captured_at);
|
|
128
|
+
if (captured === null) throw new Refusal("baseline.captured_at", `missing or not a time (${block.captured_at ?? "none"})`);
|
|
129
|
+
const started = time(report.started_at);
|
|
130
|
+
if (started === null) throw new Refusal("report started_at", `missing or not a time (${report.started_at ?? "none"}); measure again with a bench-core.mjs that records it`);
|
|
131
|
+
if (!(captured < started)) {
|
|
132
|
+
throw new Refusal("baseline.captured_at", `the baseline (${block.captured_at}) was not captured before the report started (${report.started_at}); measure the old core first`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const machine = report.machine ?? {};
|
|
136
|
+
for (const [field, theirs] of [["machine", "label"], ["hostname", "hostname"], ["platform", "platform"], ["arch", "arch"]]) {
|
|
137
|
+
const mine = block[field];
|
|
138
|
+
const other = machine[theirs];
|
|
139
|
+
if (mine === undefined || mine === null || mine === "") throw new Refusal(`baseline.${field}`, "missing");
|
|
140
|
+
if (other === undefined || other === null || other === "") throw new Refusal(`report machine.${theirs}`, "missing");
|
|
141
|
+
if (mine !== other) {
|
|
142
|
+
throw new Refusal(`baseline.${field}`, `the baseline was captured on ${mine} and the report on ${other}; compare only runs from the same machine`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const targets = report.targets_ms ?? {};
|
|
147
|
+
if (report.gate_targets !== true || targets.tool_call !== GATE_TARGETS_MS.tool_call || targets.prompt !== GATE_TARGETS_MS.prompt) {
|
|
148
|
+
throw new Refusal("report targets_ms", `the report was not measured against the speed gate's targets (${GATE_TARGETS_MS.tool_call} ms per tool call, ${GATE_TARGETS_MS.prompt} ms per prompt)`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function keyOf(result) {
|
|
153
|
+
return `${result.host}/${result.measure}/${result.tool ?? ""}`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function describe(result) {
|
|
157
|
+
return result.measure === "tool_call" ? `tool call: ${result.host_tool ?? result.tool}` : "prompt";
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function round1(value) {
|
|
161
|
+
return Math.round(value * 10) / 10;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// The report's gate verdict, carried over unchanged. Anything but a clean
|
|
165
|
+
// pass is not a pass.
|
|
166
|
+
export function gateOf(report) {
|
|
167
|
+
const passes = report.verdict === PASS && report.exit_code === 0 && (report.setup_errors ?? []).length === 0;
|
|
168
|
+
return { verdict: report.verdict ?? null, exit_code: report.exit_code ?? null, passes };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function compare(baseline, report) {
|
|
172
|
+
checkPair(baseline, report);
|
|
173
|
+
const old = new Map();
|
|
174
|
+
for (const result of baseline.results.filter((entry) => entry.core === "old")) old.set(keyOf(result), result);
|
|
175
|
+
const newer = report.results.filter((entry) => entry.core !== "old");
|
|
176
|
+
const newKeys = new Set(newer.map(keyOf));
|
|
177
|
+
|
|
178
|
+
const rows = [];
|
|
179
|
+
const missing = [];
|
|
180
|
+
for (const result of newer) {
|
|
181
|
+
const before = old.get(keyOf(result));
|
|
182
|
+
if (!before) {
|
|
183
|
+
missing.push({ host: result.host, measure: result.measure, tool: result.tool ?? null, host_tool: result.host_tool ?? null, core: result.core, only_in: "report" });
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const oldMedian = before.median_ms ?? null;
|
|
187
|
+
const newMedian = result.median_ms ?? null;
|
|
188
|
+
const delta = oldMedian !== null && newMedian !== null ? round1(newMedian - oldMedian) : null;
|
|
189
|
+
const percent = delta !== null && oldMedian > 0 ? round1((delta / oldMedian) * 100) : null;
|
|
190
|
+
rows.push({
|
|
191
|
+
host: result.host,
|
|
192
|
+
measure: result.measure,
|
|
193
|
+
tool: result.tool ?? null,
|
|
194
|
+
host_tool: result.host_tool ?? null,
|
|
195
|
+
core: result.core,
|
|
196
|
+
target_ms: result.target_ms,
|
|
197
|
+
old_median_ms: oldMedian,
|
|
198
|
+
new_median_ms: newMedian,
|
|
199
|
+
delta_ms: delta,
|
|
200
|
+
delta_percent: percent,
|
|
201
|
+
verdict: result.verdict,
|
|
202
|
+
reason: result.reason ?? null,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
for (const [key, result] of old) {
|
|
206
|
+
if (!newKeys.has(key)) {
|
|
207
|
+
missing.push({ host: result.host, measure: result.measure, tool: result.tool ?? null, host_tool: result.host_tool ?? null, core: "old", only_in: "baseline" });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const gate = gateOf(report);
|
|
212
|
+
return {
|
|
213
|
+
schema: COMPARE_SCHEMA,
|
|
214
|
+
machine: baseline.baseline.machine,
|
|
215
|
+
hostname: baseline.baseline.hostname,
|
|
216
|
+
platform: baseline.baseline.platform,
|
|
217
|
+
arch: baseline.baseline.arch,
|
|
218
|
+
baseline_captured_at: baseline.baseline.captured_at,
|
|
219
|
+
report_started_at: report.started_at,
|
|
220
|
+
report_generated_at: report.generated_at ?? null,
|
|
221
|
+
targets_ms: { ...GATE_TARGETS_MS },
|
|
222
|
+
gate,
|
|
223
|
+
rows,
|
|
224
|
+
missing,
|
|
225
|
+
exit_code: gate.passes ? 0 : 1,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function fmt(value, unit = "") {
|
|
230
|
+
return value === null || value === undefined ? "n/a" : `${value}${unit}`;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function signed(value, unit) {
|
|
234
|
+
if (value === null || value === undefined) return "n/a";
|
|
235
|
+
return `${value > 0 ? "+" : ""}${value}${unit}`;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export function formatComparison(result) {
|
|
239
|
+
const lines = [];
|
|
240
|
+
lines.push(`hq bench-core compare machine=${result.machine} hostname=${result.hostname} platform=${result.platform} ${result.arch}`);
|
|
241
|
+
lines.push(`baseline (old core) captured ${result.baseline_captured_at}; report started ${result.report_started_at}`);
|
|
242
|
+
lines.push("");
|
|
243
|
+
const header = ["host", "measure", "core", "target", "old median", "new median", "delta", "delta %", "gate verdict"];
|
|
244
|
+
const rows = result.rows.map((row) => [
|
|
245
|
+
row.host,
|
|
246
|
+
describe(row),
|
|
247
|
+
row.core,
|
|
248
|
+
`${row.target_ms} ms`,
|
|
249
|
+
`${fmt(row.old_median_ms)} ms`,
|
|
250
|
+
`${fmt(row.new_median_ms)} ms`,
|
|
251
|
+
signed(row.delta_ms, " ms"),
|
|
252
|
+
signed(row.delta_percent, "%"),
|
|
253
|
+
row.verdict,
|
|
254
|
+
]);
|
|
255
|
+
const widths = header.map((title, column) => Math.max(title.length, ...rows.map((row) => row[column].length)));
|
|
256
|
+
const line = (cells) => cells.map((cell, column) => cell.padEnd(widths[column])).join(" ").trimEnd();
|
|
257
|
+
lines.push(line(header));
|
|
258
|
+
for (const row of rows) lines.push(line(row));
|
|
259
|
+
if (result.missing.length > 0) {
|
|
260
|
+
lines.push("");
|
|
261
|
+
for (const entry of result.missing) {
|
|
262
|
+
lines.push(`missing: ${entry.host} ${describe(entry)} (${entry.core}) is only in the ${entry.only_in}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
lines.push("");
|
|
266
|
+
lines.push(`speed gate (from the report, unchanged): ${result.gate.verdict ?? "n/a"} (report exit code ${fmt(result.gate.exit_code)})`);
|
|
267
|
+
lines.push(result.gate.passes ? "result: pass" : "result: not a pass; the comparison does not change the gate's answer");
|
|
268
|
+
return `${lines.join("\n")}\n`;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function usage() {
|
|
272
|
+
const source = fs.readFileSync(new URL(import.meta.url), "utf8").split("\n");
|
|
273
|
+
const start = source.findIndex((text) => text.startsWith("// Usage"));
|
|
274
|
+
const end = source.findIndex((text, index) => index > start && !text.startsWith("//"));
|
|
275
|
+
return `${source.slice(start, end).map((text) => text.replace(/^\/\/ ?/, "")).join("\n")}\n`;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export async function main(argv, io = { out: process.stdout, err: process.stderr }) {
|
|
279
|
+
let options;
|
|
280
|
+
let result;
|
|
281
|
+
try {
|
|
282
|
+
options = parseArgs(argv);
|
|
283
|
+
if (options.help) {
|
|
284
|
+
io.out.write(usage());
|
|
285
|
+
return 0;
|
|
286
|
+
}
|
|
287
|
+
const baseline = readReport(options.baseline, "--baseline");
|
|
288
|
+
const report = readReport(options.report, "--report");
|
|
289
|
+
result = compare(baseline, report);
|
|
290
|
+
} catch (error) {
|
|
291
|
+
if (error instanceof Refusal) {
|
|
292
|
+
io.err.write(`bench-core-compare: refused: ${error.message}\n`);
|
|
293
|
+
return 2;
|
|
294
|
+
}
|
|
295
|
+
if (error instanceof UsageError) {
|
|
296
|
+
io.err.write(`bench-core-compare: ${error.message}\n`);
|
|
297
|
+
return 2;
|
|
298
|
+
}
|
|
299
|
+
throw error;
|
|
300
|
+
}
|
|
301
|
+
const json = `${JSON.stringify(result, null, 2)}\n`;
|
|
302
|
+
io.out.write(options.json ? json : formatComparison(result));
|
|
303
|
+
if (options.output) {
|
|
304
|
+
fs.mkdirSync(path.dirname(options.output), { recursive: true });
|
|
305
|
+
fs.writeFileSync(options.output, json);
|
|
306
|
+
if (!options.json) io.out.write(`comparison: ${options.output}\n`);
|
|
307
|
+
}
|
|
308
|
+
return result.exit_code;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(fs.realpathSync(process.argv[1])).href) {
|
|
312
|
+
process.exitCode = await main(process.argv.slice(2));
|
|
313
|
+
}
|