@indigoai-us/hq-cli 5.345.219 → 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.
Files changed (199) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/dist/command-catalog.generated.d.ts +169 -3
  3. package/dist/command-catalog.generated.js +206 -3
  4. package/dist/commands/auth.js +4 -1
  5. package/dist/commands/bot-runtime.d.ts +18 -5
  6. package/dist/commands/bot-runtime.js +29 -12
  7. package/dist/commands/bot.d.ts +85 -0
  8. package/dist/commands/bot.js +245 -16
  9. package/dist/commands/cloud.d.ts +16 -0
  10. package/dist/commands/cloud.js +112 -102
  11. package/dist/commands/core-checkpoint-native.d.ts +13 -0
  12. package/dist/commands/core-checkpoint-native.js +167 -52
  13. package/dist/commands/core-hook-registration-plan.js +5 -4
  14. package/dist/commands/core-stop-autosave.d.ts +21 -0
  15. package/dist/commands/core-stop-autosave.js +300 -0
  16. package/dist/commands/core.js +2 -0
  17. package/dist/commands/daemon.d.ts +5 -0
  18. package/dist/commands/daemon.js +52 -9
  19. package/dist/commands/doctor-usage.d.ts +5 -0
  20. package/dist/commands/doctor-usage.js +25 -0
  21. package/dist/commands/env.d.ts +49 -4
  22. package/dist/commands/env.js +355 -5
  23. package/dist/commands/integrations.js +84 -3
  24. package/dist/commands/lanes-shared.d.ts +3 -0
  25. package/dist/commands/lanes.d.ts +3 -0
  26. package/dist/commands/lanes.js +87 -3
  27. package/dist/commands/packs.js +23 -0
  28. package/dist/commands/pkg-update.d.ts +6 -0
  29. package/dist/commands/pkg-update.js +15 -7
  30. package/dist/commands/run.js +55 -45
  31. package/dist/commands/sources.js +4 -3
  32. package/dist/commands/sync-core.d.ts +1 -0
  33. package/dist/commands/sync-core.js +77 -3
  34. package/dist/commands/whoami.js +96 -80
  35. package/dist/lib/bot/config.d.ts +17 -0
  36. package/dist/lib/bot/config.js +13 -0
  37. package/dist/lib/bot/fleet-cron.js +29 -4
  38. package/dist/lib/bot/fleet-local.d.ts +30 -2
  39. package/dist/lib/bot/fleet-local.js +60 -1
  40. package/dist/lib/bot/grok-login-scope.d.ts +36 -0
  41. package/dist/lib/bot/grok-login-scope.js +93 -0
  42. package/dist/lib/bot/inflight.d.ts +9 -0
  43. package/dist/lib/bot/jobs/hot-signal-sync.d.ts +51 -0
  44. package/dist/lib/bot/jobs/hot-signal-sync.js +90 -9
  45. package/dist/lib/bot/legacy-provider-login.d.ts +32 -9
  46. package/dist/lib/bot/legacy-provider-login.js +28 -22
  47. package/dist/lib/bot/run.d.ts +29 -5
  48. package/dist/lib/bot/run.js +203 -1
  49. package/dist/lib/bot/runtime-sign-in-check.js +6 -1
  50. package/dist/lib/bot/runtime-sign-in.d.ts +2 -0
  51. package/dist/lib/bot/signals-try-now.d.ts +76 -0
  52. package/dist/lib/bot/signals-try-now.js +111 -0
  53. package/dist/lib/capacity/collectors/claude-oauth.d.ts +22 -3
  54. package/dist/lib/capacity/collectors/claude-oauth.js +78 -22
  55. package/dist/lib/capacity/scheduler.d.ts +8 -0
  56. package/dist/lib/capacity/scheduler.js +5 -2
  57. package/dist/lib/core-utils/sentry-report.js +2 -0
  58. package/dist/lib/daemon/machine-checks.d.ts +22 -1
  59. package/dist/lib/daemon/machine-checks.js +54 -12
  60. package/dist/lib/daemon/run.js +71 -8
  61. package/dist/lib/daemon/runtime-notifications.d.ts +7 -0
  62. package/dist/lib/daemon/runtime-notifications.js +50 -0
  63. package/dist/lib/daemon/stop-autosave-lock.d.ts +19 -0
  64. package/dist/lib/daemon/stop-autosave-lock.js +166 -0
  65. package/dist/lib/daemon/stop-autosave.d.ts +28 -0
  66. package/dist/lib/daemon/stop-autosave.js +111 -0
  67. package/dist/lib/daemon/stop-diagnostics.d.ts +11 -0
  68. package/dist/lib/daemon/stop-diagnostics.js +136 -0
  69. package/dist/lib/daemon/stop-job-executor.d.ts +19 -0
  70. package/dist/lib/daemon/stop-job-executor.js +126 -0
  71. package/dist/lib/daemon/stop-jobs.d.ts +93 -0
  72. package/dist/lib/daemon/stop-jobs.js +599 -0
  73. package/dist/lib/doctor/checks/fleet-hook-core.d.ts +9 -1
  74. package/dist/lib/doctor/checks/fleet-hook-core.js +39 -15
  75. package/dist/lib/doctor/checks/host-core.js +1 -1
  76. package/dist/lib/environment/access-probes.d.ts +234 -0
  77. package/dist/lib/environment/access-probes.js +918 -0
  78. package/dist/lib/environment/profile.d.ts +15 -2
  79. package/dist/lib/environment/profile.js +55 -20
  80. package/dist/lib/environment/rfc3339.d.ts +8 -0
  81. package/dist/lib/environment/rfc3339.js +26 -0
  82. package/dist/lib/environment/work-requirements.d.ts +169 -0
  83. package/dist/lib/environment/work-requirements.js +389 -0
  84. package/dist/lib/hook-engine/coverage.d.ts +137 -7
  85. package/dist/lib/hook-engine/coverage.js +1424 -4
  86. package/dist/lib/hook-engine/fleet-registration.d.ts +17 -5
  87. package/dist/lib/hook-engine/fleet-registration.js +53 -17
  88. package/dist/lib/hook-engine/git-stop-config.json +513 -0
  89. package/dist/lib/hook-engine/native-stop-compatibility.json +311 -0
  90. package/dist/lib/hook-engine/reconcile.js +2 -2
  91. package/dist/lib/hot-channels/alert.d.ts +10 -1
  92. package/dist/lib/hot-channels/alert.js +38 -8
  93. package/dist/lib/hot-channels/signals-claude-login.d.ts +53 -0
  94. package/dist/lib/hot-channels/signals-claude-login.js +96 -0
  95. package/dist/lib/hot-channels/signals-pass.d.ts +143 -17
  96. package/dist/lib/hot-channels/signals-pass.js +324 -17
  97. package/dist/lib/hot-channels/signals-runtime.d.ts +30 -0
  98. package/dist/lib/hot-channels/signals-runtime.js +82 -0
  99. package/dist/lib/install/hook-target.js +1 -1
  100. package/dist/lib/lanes/host-capacity.d.ts +26 -2
  101. package/dist/lib/lanes/host-capacity.js +17 -2
  102. package/dist/lib/lanes/host-compute.d.ts +90 -0
  103. package/dist/lib/lanes/host-compute.js +185 -0
  104. package/dist/lib/lanes/index.d.ts +2 -0
  105. package/dist/lib/lanes/index.js +1 -0
  106. package/dist/lib/lanes/reconcile.js +22 -1
  107. package/dist/lib/lanes/resource-usage.d.ts +155 -0
  108. package/dist/lib/lanes/resource-usage.js +589 -0
  109. package/dist/lib/lanes/run-size.d.ts +46 -0
  110. package/dist/lib/lanes/run-size.js +197 -0
  111. package/dist/lib/lanes/store.js +27 -0
  112. package/dist/lib/lanes/throttle.d.ts +36 -1
  113. package/dist/lib/lanes/throttle.js +47 -10
  114. package/dist/lib/lanes/types.d.ts +40 -0
  115. package/dist/lib/lanes/types.js +2 -2
  116. package/dist/lib/lanes/watcher.js +13 -4
  117. package/dist/lib/lanes/worker-process.d.ts +25 -2
  118. package/dist/lib/lanes/worker-process.js +71 -19
  119. package/dist/lib/placement/match.d.ts +192 -0
  120. package/dist/lib/placement/match.js +667 -0
  121. package/dist/lib/safe-store.d.ts +14 -0
  122. package/dist/lib/safe-store.js +77 -4
  123. package/dist/lib/search-index/index.d.ts +88 -4
  124. package/dist/lib/search-index/index.js +299 -25
  125. package/dist/lib/search-index/max-doc-bytes.d.ts +17 -6
  126. package/dist/lib/search-index/max-doc-bytes.js +48 -23
  127. package/dist/lib/signals/codex-lockdown.d.ts +79 -0
  128. package/dist/lib/signals/codex-lockdown.js +271 -0
  129. package/dist/lib/signals/codex-login.d.ts +37 -0
  130. package/dist/lib/signals/codex-login.js +83 -0
  131. package/dist/lib/signals/engine.d.ts +28 -0
  132. package/dist/lib/signals/engine.js +77 -0
  133. package/dist/lib/signals/reply.d.ts +48 -0
  134. package/dist/lib/signals/reply.js +94 -12
  135. package/dist/lib/signals/run-record.js +6 -1
  136. package/dist/lib/signals/settings.d.ts +5 -0
  137. package/dist/lib/signals/settings.js +2 -0
  138. package/dist/lib/signals/steps/adapters.js +6 -0
  139. package/dist/lib/signals/steps/extract.d.ts +135 -12
  140. package/dist/lib/signals/steps/extract.js +416 -84
  141. package/dist/lib/signals/steps/types.d.ts +21 -0
  142. package/dist/lib/sync-core/engine-home.d.ts +41 -2
  143. package/dist/lib/sync-core/engine-home.js +132 -19
  144. package/dist/lib/sync-core/reconcile.js +1 -1
  145. package/dist/lib/sync-core/release-compare.d.ts +7 -0
  146. package/dist/lib/sync-core/release-compare.js +16 -0
  147. package/dist/lib/sync-core/release.d.ts +2 -1
  148. package/dist/lib/sync-core/release.js +2 -10
  149. package/dist/lib/sync-core/rollout-state.d.ts +2 -1
  150. package/dist/lib/sync-core/rollout-state.js +5 -2
  151. package/dist/lib/sync-core/vault-uid.d.ts +2 -0
  152. package/dist/lib/sync-core/vault-uid.js +4 -0
  153. package/dist/run/schema-env-overrides.d.ts +24 -0
  154. package/dist/run/schema-env-overrides.js +72 -0
  155. package/dist/schemas/hq-work-requirements.v1.schema.json +145 -0
  156. package/dist/utils/auth-session-check.d.ts +16 -0
  157. package/dist/utils/auth-session-check.js +16 -0
  158. package/dist/utils/client-health-contract.d.ts +6 -0
  159. package/dist/utils/client-health-contract.js +13 -0
  160. package/dist/utils/client-health.d.ts +7 -0
  161. package/dist/utils/client-health.js +22 -1
  162. package/dist/utils/command-usage.d.ts +40 -0
  163. package/dist/utils/command-usage.js +61 -0
  164. package/dist/utils/duplicate-command-usage.d.ts +72 -0
  165. package/dist/utils/duplicate-command-usage.js +125 -0
  166. package/dist/utils/host-registration.d.ts +1 -1
  167. package/dist/utils/host-registration.js +6 -1
  168. package/dist/utils/resident-package-preload.js +4 -0
  169. package/dist/utils/sentry-fingerprint.js +9 -0
  170. package/dist/utils/windows-bash.d.ts +2 -0
  171. package/dist/utils/windows-bash.js +2 -1
  172. package/package.json +15 -10
  173. package/scripts/bench-core-compare.mjs +313 -0
  174. package/scripts/bench-core.mjs +399 -12
  175. package/scripts/check-function-manifest.mjs +121 -7
  176. package/dist/commands/__fixtures__/access-vault.d.ts +0 -95
  177. package/dist/commands/__fixtures__/access-vault.js +0 -166
  178. package/dist/commands/__fixtures__/make-tar.d.ts +0 -38
  179. package/dist/commands/__fixtures__/make-tar.js +0 -102
  180. package/dist/commands/secrets-public-types.test-d.d.ts +0 -2
  181. package/dist/commands/secrets-public-types.test-d.js +0 -18
  182. package/dist/lib/decisions/fixtures/us001.d.ts +0 -137
  183. package/dist/lib/decisions/fixtures/us001.js +0 -21
  184. package/dist/lib/doctor/__testing__/fake-hq-tree.d.ts +0 -226
  185. package/dist/lib/doctor/__testing__/fake-hq-tree.js +0 -408
  186. package/dist/lib/doctor/__testing__/run-doctor.d.ts +0 -8
  187. package/dist/lib/doctor/__testing__/run-doctor.js +0 -69
  188. package/dist/lib/fingerprint/fixtures.d.ts +0 -19
  189. package/dist/lib/fingerprint/fixtures.js +0 -61
  190. package/dist/lib/hot-channels/adapters/__fixtures__/dummy.d.ts +0 -33
  191. package/dist/lib/hot-channels/adapters/__fixtures__/dummy.js +0 -53
  192. package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.d.ts +0 -38
  193. package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.js +0 -64
  194. package/dist/lib/mesh/live/daemon/mqtt-events.test-d.d.ts +0 -2
  195. package/dist/lib/mesh/live/daemon/mqtt-events.test-d.js +0 -10
  196. package/dist/lib/test-utils/isolated-flag-company-context.d.ts +0 -3
  197. package/dist/lib/test-utils/isolated-flag-company-context.js +0 -18
  198. package/scripts/hook-engine-manifest.mjs +0 -22
  199. package/scripts/mesh-daemon-if-stale.mjs +0 -20
@@ -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
+ }