ostia 0.3.1 → 0.5.0

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 (60) hide show
  1. package/README.md +4 -4
  2. package/docs/agent-protocol.md +13 -9
  3. package/docs/cli.md +90 -73
  4. package/docs/config.md +2 -2
  5. package/docs/document-schema.md +14 -12
  6. package/docs/library.md +17 -15
  7. package/docs/preload-recipes.md +4 -4
  8. package/docs/statistics.md +10 -10
  9. package/index.d.ts +197 -126
  10. package/package.json +1 -1
  11. package/src/ab/ab-runner.ts +6 -6
  12. package/src/ab/index.ts +15 -6
  13. package/src/bench/index.ts +12 -3
  14. package/src/bench/registry.ts +9 -7
  15. package/src/bench/run-tasks.ts +2 -2
  16. package/src/bench/runner.ts +2 -2
  17. package/src/bench/support.ts +8 -4
  18. package/src/bench/sweep.ts +3 -3
  19. package/src/cache/fingerprint.ts +2 -2
  20. package/src/capture/bunflags.ts +2 -2
  21. package/src/capture/cpu.ts +2 -2
  22. package/src/capture/heap-parse.ts +2 -2
  23. package/src/ci/index.ts +7 -6
  24. package/src/cli/agent.ts +54 -0
  25. package/src/cli/flags.ts +50 -9
  26. package/src/cli/help.ts +29 -11
  27. package/src/cli/output.ts +6 -3
  28. package/src/cli/run.ts +29 -5
  29. package/src/compare/index.ts +4 -4
  30. package/src/config/index.ts +14 -10
  31. package/src/config/validate.ts +4 -4
  32. package/src/glob.ts +2 -2
  33. package/src/index.ts +18 -1
  34. package/src/ir/document.ts +2 -2
  35. package/src/ir/types.ts +50 -27
  36. package/src/measure/alloc.ts +2 -2
  37. package/src/measure/cpu.ts +2 -2
  38. package/src/measure/environment.ts +11 -6
  39. package/src/measure/inprocess.ts +14 -10
  40. package/src/measure/instructions.ts +2 -2
  41. package/src/measure/noise.ts +51 -13
  42. package/src/measure/paired.ts +2 -2
  43. package/src/measure/peak.ts +4 -4
  44. package/src/measure/timing.ts +18 -3
  45. package/src/profile.ts +6 -4
  46. package/src/renderers/collapsed.ts +2 -2
  47. package/src/renderers/concise.ts +148 -0
  48. package/src/renderers/format.ts +13 -4
  49. package/src/renderers/index.ts +6 -0
  50. package/src/renderers/markdown.ts +2 -2
  51. package/src/renderers/mermaid.ts +2 -2
  52. package/src/renderers/minimal.ts +11 -10
  53. package/src/renderers/relative.ts +2 -2
  54. package/src/renderers/select.ts +2 -2
  55. package/src/renderers/terminal.ts +6 -3
  56. package/src/renderers/types.ts +3 -0
  57. package/src/spawn/index.ts +47 -14
  58. package/src/stats/bootstrap.ts +2 -2
  59. package/src/stats/index.ts +2 -2
  60. package/src/time.ts +75 -10
@@ -112,8 +112,8 @@ async function importTasks(suiteFile: string): Promise<RegisteredTask[]> {
112
112
  return [...getRegisteredTasks()];
113
113
  }
114
114
 
115
- // The parent writes optsJson, so this checks only the fields every run
116
- // reads.
115
+ // The parent writes optsJson, so this checks only the fields every
116
+ // run reads.
117
117
  function isRunnerOpts(v: unknown): v is AbRunnerOpts {
118
118
  return (
119
119
  typeof v === "object" &&
@@ -157,8 +157,8 @@ type MeasureOutcome =
157
157
  // `before` threw isn't timed or torn down. Every side that was set up is
158
158
  // torn down once, in reverse order, even when a hook throws. When only one
159
159
  // side has thrown, the other side's task is called once more, before
160
- // teardown and only if that side is set up, to tell whether it throws too
161
- // (`"both"`).
160
+ // teardown and only if that side is set up, to tell whether it throws
161
+ // too (`"both"`).
162
162
  async function measureTask(
163
163
  base: RegisteredTask,
164
164
  cand: RegisteredTask,
@@ -302,8 +302,8 @@ async function measureMemory(
302
302
  // in this process. Each side is imported from its own path so its relative
303
303
  // imports resolve within its own tree, while bare imports (including
304
304
  // `ostia`, hence the shared registry) share `node_modules`. `baseSuite` is
305
- // "" when the file doesn't exist at the base ref: every task is
306
- // candidate-only.
305
+ // "" when the file doesn't exist at the base ref: every task
306
+ // is candidate-only.
307
307
  async function main(): Promise<number> {
308
308
  const [candSuite, baseSuite, outputPath, optsJson] = process.argv.slice(2);
309
309
  if (!candSuite || baseSuite === undefined || !outputPath || !optsJson) {
package/src/ab/index.ts CHANGED
@@ -110,15 +110,19 @@ export interface AbOptions {
110
110
  outDir?: string;
111
111
  cwd?: string;
112
112
  noiseCheck?: boolean;
113
+ /** Sample the noise floor for exactly this many ms instead. */
114
+ noiseBudgetMs?: number;
113
115
  /** Also compare each side's retained heap per call (see
114
116
  * `bench({ alloc })`) and how far its first call raises RSS (see
115
117
  * `bench({ peakMem })`), each the median of 3 fresh processes per side.
116
118
  * Task/group options override these. */
117
119
  alloc?: boolean;
118
120
  peakMem?: boolean;
119
- /** Flag a memory reading that moves past this many percent of the base's
120
- * and past its noise floor (default: 10). A memory regression fails the
121
- * run. */
121
+ /**
122
+ * Flag a memory reading that moves past this many percent of the base's
123
+ * and past its noise floor (default: 10). A memory regression fails
124
+ * the run.
125
+ */
122
126
  memThresholdPct?: number;
123
127
  /** Shell commands run once, in order, in a freshly extracted base tree
124
128
  * before it's used: to build what the suites import but git doesn't hold
@@ -215,8 +219,10 @@ async function saltScripts(dir: string): Promise<void> {
215
219
 
216
220
  interface TreeSetup {
217
221
  commands: string[];
218
- /** The project root and the directory `ab()` runs from, in the working
219
- * tree. */
222
+ /**
223
+ * The project root and the directory `ab()` runs from, in the
224
+ * working tree.
225
+ */
220
226
  toplevel: string;
221
227
  cwd: string;
222
228
  timeoutMs?: number | undefined;
@@ -863,7 +869,10 @@ export async function ab(opts: AbOptions): Promise<ProfileDocument> {
863
869
  return doc;
864
870
  }
865
871
 
866
- const { environment, noiseWarning } = captureRunEnvironment(opts.noiseCheck);
872
+ const { environment, noiseWarning } = captureRunEnvironment(
873
+ opts.noiseCheck,
874
+ opts.noiseBudgetMs,
875
+ );
867
876
 
868
877
  // "" when the file doesn't exist at the base ref: all its tasks are new.
869
878
  const baseSuites = candSuites.map((suite, i) => {
@@ -94,6 +94,8 @@ export interface BenchOptions {
94
94
  * Measure this machine's noise floor once, before any suite runs
95
95
  * (default: true), and stamp it on the document as `environment`. */
96
96
  noiseCheck?: boolean;
97
+ /** Sample the noise floor for exactly this many ms instead. */
98
+ noiseBudgetMs?: number;
97
99
  /**
98
100
  * SIGKILLs a suite file's subprocess (or, under `isolate`, one task's)
99
101
  * that hasn't finished after this many ms. No default. */
@@ -132,6 +134,7 @@ export interface BenchCliOverrides {
132
134
  bunFlags: string[];
133
135
  outDir?: string;
134
136
  noiseCheck: boolean;
137
+ noiseBudgetMs?: number;
135
138
  timeoutMs?: number;
136
139
  }
137
140
 
@@ -190,6 +193,9 @@ export async function resolveBenchOptions(
190
193
  ...(projects !== undefined && { projects }),
191
194
  ...(outDir !== undefined && { outDir }),
192
195
  noiseCheck: cli.noiseCheck,
196
+ ...(cli.noiseBudgetMs !== undefined && {
197
+ noiseBudgetMs: cli.noiseBudgetMs,
198
+ }),
193
199
  ...(timeoutMs !== undefined && { timeoutMs }),
194
200
  cwd,
195
201
  };
@@ -274,7 +280,10 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
274
280
  const path = absolutePath(cwd, given);
275
281
  return { given, path, ...launch(path) };
276
282
  });
277
- const { environment, noiseWarning } = captureRunEnvironment(opts.noiseCheck);
283
+ const { environment, noiseWarning } = captureRunEnvironment(
284
+ opts.noiseCheck,
285
+ opts.noiseBudgetMs,
286
+ );
278
287
 
279
288
  const measureOpts: RunnerOpts = {
280
289
  ...(opts.budgetMs !== undefined && { budgetMs: opts.budgetMs }),
@@ -466,8 +475,8 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
466
475
 
467
476
  // Plan order (registration order, filtered) within a suite, suites in
468
477
  // command-line order. Measurements are matched by workload id, not
469
- // position, because a task.skip()'d task has a workload but no
470
- // measurement.
478
+ // position, because a task.skip()'d task has a workload but
479
+ // no measurement.
471
480
  const workloads: Workload[] = [];
472
481
  const measurements: Measurement[] = [];
473
482
  for (const { suite, tasks, doc: sharedDoc } of plans) {
@@ -5,7 +5,7 @@ export const NO_TASKS_HINT =
5
5
  " If the suite does call task(), it imports a different copy of ostia than the CLI running it (a global install, or another version): run the one from the project's node_modules.";
6
6
 
7
7
  /** A task body or hook; it may return a promise, which the runner awaits. */
8
- type Hook = () => unknown;
8
+ export type Hook = () => unknown;
9
9
 
10
10
  export interface TaskOptions {
11
11
  /**
@@ -29,8 +29,9 @@ export interface TaskOptions {
29
29
  aliases?: string[];
30
30
  /**
31
31
  * What this task measures and why. Flows into `Workload.description` so
32
- * the intent travels with the numbers instead of living only in a source
33
- * comment. */
32
+ * the intent travels with the numbers instead of living only in a
33
+ * source comment.
34
+ */
34
35
  description?: string;
35
36
  /**
36
37
  * Give this task its own subprocess instead of sharing its suite file's,
@@ -207,11 +208,12 @@ type GroupRegistrar = (
207
208
  opts?: GroupOptions,
208
209
  ) => void;
209
210
 
210
- interface GroupFn extends GroupRegistrar {
211
+ export interface GroupFn extends GroupRegistrar {
211
212
  /**
212
213
  * Registers every task inside as skipped: the runner never measures
213
- * them, but the document still carries their workloads (marked
214
- * `Workload.skipped`). */
214
+ * them, but the document still carries their workloads
215
+ * (marked `Workload.skipped`).
216
+ */
215
217
  skip: GroupRegistrar;
216
218
  /**
217
219
  * When any task or group in the suite uses `.only`, the runner restricts
@@ -263,7 +265,7 @@ function registerTask(
263
265
 
264
266
  type TaskRegistrar = (name: string, fn: Hook, opts?: TaskOptions) => void;
265
267
 
266
- interface TaskFn extends TaskRegistrar {
268
+ export interface TaskFn extends TaskRegistrar {
267
269
  /**
268
270
  * Registers the task as skipped: the runner never measures it, but the
269
271
  * document still carries its workload (marked `Workload.skipped`) so a
@@ -49,8 +49,8 @@ export interface MeasureTasksOpts extends InprocessTimingOptions {
49
49
  noiseCheck?: boolean;
50
50
  }
51
51
 
52
- // Shared by every runner so a task has the same id under `bench()` and
53
- // `ab()`.
52
+ // Shared by every runner so a task has the same id under `bench()`
53
+ // and `ab()`.
54
54
  export function taskWorkload(
55
55
  suiteFile: string,
56
56
  t: RegisteredTask,
@@ -57,8 +57,8 @@ export interface RunnerOpts extends MeasureTasksOpts {
57
57
  preload?: string[];
58
58
  }
59
59
 
60
- // The parent serializes a `RunnerOpts`; only that it's an object is
61
- // checked.
60
+ // The parent serializes a `RunnerOpts`; only that it's an object
61
+ // is checked.
62
62
  function isRunnerOpts(value: unknown): value is RunnerOpts {
63
63
  return typeof value === "object" && value !== null && !Array.isArray(value);
64
64
  }
@@ -56,8 +56,8 @@ export async function loadIfExists(
56
56
  return (await Bun.file(path).exists()) ? loadDocument(path) : undefined;
57
57
  }
58
58
 
59
- // invariant: a `--peak-mem` reading is the median of this many fresh
60
- // processes.
59
+ // invariant: a `--peak-mem` reading is the median of this many
60
+ // fresh processes.
61
61
  export const PEAK_MEM_PROCESSES = 3;
62
62
  // Slack below this is what any suite that loads fixtures leaves behind
63
63
  // (8MB for caligula's), so it's too common to warn about.
@@ -76,11 +76,15 @@ export function peakHiddenWarning(
76
76
  };
77
77
  }
78
78
 
79
- export function captureRunEnvironment(noiseCheck: boolean | undefined): {
79
+ export function captureRunEnvironment(
80
+ noiseCheck: boolean | undefined,
81
+ noiseBudgetMs?: number,
82
+ ): {
80
83
  environment: Environment | undefined;
81
84
  noiseWarning: Warning | undefined;
82
85
  } {
83
- const environment = noiseCheck === false ? undefined : captureEnvironment();
86
+ const environment =
87
+ noiseCheck === false ? undefined : captureEnvironment(noiseBudgetMs);
84
88
  return {
85
89
  environment,
86
90
  noiseWarning: environment && noisyMachineWarning(environment),
@@ -1,6 +1,6 @@
1
1
  import { withCurrentParams } from "./registry.ts";
2
2
 
3
- type SweepPoint<T extends Record<string, readonly unknown[]>> = {
3
+ export type SweepPoint<T extends Record<string, readonly unknown[]>> = {
4
4
  [K in keyof T]: T[K][number];
5
5
  };
6
6
 
@@ -25,9 +25,9 @@ export function sweep<T extends Record<string, readonly unknown[]>>(
25
25
  const key = keys[index];
26
26
  if (key === undefined) {
27
27
  withCurrentParams(
28
- // eslint-disable-next-line typescript/consistent-type-assertions, no-restricted-syntax -- `dims` may hold any value, and params carry the point as given
28
+ // eslint-disable-next-line typescript/consistent-type-assertions -- `dims` may hold any value, and params carry the point as given
29
29
  point as Record<string, string | number | boolean>,
30
- // eslint-disable-next-line typescript/consistent-type-assertions, no-restricted-syntax -- every key of `dims` is set by now, which TS can't follow through a mapped type
30
+ // eslint-disable-next-line typescript/consistent-type-assertions -- every key of `dims` is set by now, which TS can't follow through a mapped type
31
31
  () => fn(point as SweepPoint<T>),
32
32
  );
33
33
  return;
@@ -45,8 +45,8 @@ export async function computeInputsDigest(
45
45
  const k = next++;
46
46
  const path = paths[k];
47
47
  if (path === undefined) continue;
48
- // `resolve`, not a join, since absolute patterns scan to absolute
49
- // paths.
48
+ // `resolve`, not a join, since absolute patterns scan to
49
+ // absolute paths.
50
50
  const buf = await Bun.file(resolve(cwd, path)).arrayBuffer();
51
51
  entries[k] = {
52
52
  path,
@@ -2,8 +2,8 @@ import { processEnv } from "../config/env.ts";
2
2
  import type { Warning } from "../ir/types.ts";
3
3
 
4
4
  // BUN_OPTIONS is split on whitespace; a backslash escapes a space or quote
5
- // (Bun doesn't honour quoting, and a literal backslash can't be
6
- // expressed).
5
+ // (Bun doesn't honour quoting, and a literal backslash can't
6
+ // be expressed).
7
7
  function escapeBunOption(flag: string): string {
8
8
  return flag.replace(/[\s"']/g, "\\$&");
9
9
  }
@@ -14,8 +14,8 @@ interface CpuCaptureResult {
14
14
  warnings: Warning[];
15
15
  }
16
16
 
17
- // BUN_CPU_PROFILE is documented but doesn't work on Bun 1.4.0, hence
18
- // flags/BUN_OPTIONS.
17
+ // BUN_CPU_PROFILE is documented but doesn't work on Bun 1.4.0,
18
+ // hence flags/BUN_OPTIONS.
19
19
  export async function runCpuCapture(
20
20
  opts: CpuCaptureOptions,
21
21
  ): Promise<CpuCaptureResult> {
@@ -12,8 +12,8 @@ export interface RawHeapSnapshot {
12
12
  strings: string[];
13
13
  }
14
14
 
15
- // Checks only the arrays `parseHeapSnapshot` walks and the count it
16
- // reports.
15
+ // Checks only the arrays `parseHeapSnapshot` walks and the count
16
+ // it reports.
17
17
  export function isRawHeapSnapshot(value: unknown): value is RawHeapSnapshot {
18
18
  if (typeof value !== "object" || value === null) return false;
19
19
  if (!("nodes" in value) || !Array.isArray(value.nodes)) return false;
package/src/ci/index.ts CHANGED
@@ -38,8 +38,9 @@ interface CiOptions {
38
38
  /**
39
39
  * Abort kills in-flight trials and suite processes and stops scheduling
40
40
  * workloads. `runCi` then resolves with `aborted: true`: the document
41
- * holds what completed, nothing is compared, and no run is written to the
42
- * cache. */
41
+ * holds what completed, nothing is compared, and no run is written to
42
+ * the cache.
43
+ */
43
44
  signal?: AbortSignal;
44
45
  }
45
46
 
@@ -83,8 +84,8 @@ interface CiSummary {
83
84
  }
84
85
 
85
86
  /**
86
- * Base of the two baseline errors, so the CLI reports either as
87
- * `baseline-missing`.
87
+ * Base of the two baseline errors, so the CLI reports either
88
+ * as `baseline-missing`.
88
89
  */
89
90
  export class BaselineError extends OstiaUsageError {}
90
91
 
@@ -145,8 +146,8 @@ async function measureSuiteWorkloads(
145
146
  `Workload suites ${JSON.stringify(suites)} matched no files.`,
146
147
  );
147
148
  }
148
- // Same CLI-over-config resolution as `ostia bench`; only the defaults
149
- // differ.
149
+ // Same CLI-over-config resolution as `ostia bench`; only the
150
+ // defaults differ.
150
151
  const benchOpts = await resolveBenchOptions(
151
152
  { suites: suiteFiles, preload: [], bunFlags: [], noiseCheck: false },
152
153
  config.bench,
@@ -0,0 +1,54 @@
1
+ import { processEnv } from "../config/env.ts";
2
+
3
+ // The variables a coding agent sets, as svelte-typecheck and svelte-lint
4
+ // read them, after `bun check`: `AGENT` and `CLAUDECODE`, `AI_AGENT`, the
5
+ // shared name, and Codex's `CODEX_CI` and `CODEX_THREAD_ID`. Kept the same
6
+ // so the three tools agree on what an agent is (metonym/ostia#53).
7
+ const AGENT_ENV = [
8
+ "AGENT",
9
+ "AI_AGENT",
10
+ "CLAUDECODE",
11
+ "CODEX_CI",
12
+ "CODEX_THREAD_ID",
13
+ ] as const;
14
+
15
+ type Env = Readonly<Record<string, string | undefined>>;
16
+
17
+ // The first agent variable set to anything but empty or `0`, which a
18
+ // person sets to say "not an agent" without unsetting it.
19
+ export function agentVariable(env: Env = processEnv()): string | undefined {
20
+ return AGENT_ENV.find((name) => {
21
+ const value = env[name];
22
+ return value !== undefined && value !== "" && value !== "0";
23
+ });
24
+ }
25
+
26
+ function asksForFormat(argv: readonly string[]): boolean {
27
+ return argv.some(
28
+ (arg) =>
29
+ arg === "--format" ||
30
+ arg.startsWith("--format=") ||
31
+ arg === "--json" ||
32
+ arg.startsWith("--json="),
33
+ );
34
+ }
35
+
36
+ // `argv` with the format to use when it names none: `OSTIA_FORMAT` when
37
+ // set, else `concise` for a coding agent, with a line saying so, so a
38
+ // person reading the agent's log knows why the table is missing.
39
+ export function withDefaultFormat(
40
+ argv: readonly string[],
41
+ env: Env = processEnv(),
42
+ ): { argv: string[]; notice?: string } {
43
+ if (asksForFormat(argv)) return { argv: [...argv] };
44
+ const chosen = env.OSTIA_FORMAT;
45
+ if (chosen !== undefined && chosen !== "") {
46
+ return { argv: [...argv, "--format", chosen] };
47
+ }
48
+ const agent = agentVariable(env);
49
+ if (agent === undefined) return { argv: [...argv] };
50
+ return {
51
+ argv: [...argv, "--format", "concise"],
52
+ notice: `ostia: ${agent} is set, so --format concise; pass --format or set OSTIA_FORMAT for another.\n`,
53
+ };
54
+ }
package/src/cli/flags.ts CHANGED
@@ -13,9 +13,18 @@ const DOCUMENT_FORMATS = [
13
13
  "json",
14
14
  "jsonl",
15
15
  "markdown",
16
- "minimal",
16
+ "events",
17
+ "concise",
17
18
  ] as const;
18
19
 
20
+ // The names a format went by, or shares with another tool: `minimal` was
21
+ // `events`' name until 0.5.0, and svelte-typecheck and svelte-lint call
22
+ // their agent format `agent`.
23
+ export const FORMAT_ALIASES: Readonly<Record<string, string>> = {
24
+ minimal: "events",
25
+ agent: "concise",
26
+ };
27
+
19
28
  export const VIZ_FORMATS = [
20
29
  "collapsed",
21
30
  "mermaid",
@@ -63,7 +72,12 @@ type FlagSpec =
63
72
  | { kind: "int"; min?: number; allowAuto?: boolean }
64
73
  | { kind: "number"; min: number }
65
74
  | { kind: "bool"; value: boolean }
66
- | { kind: "enum"; values: readonly string[] }
75
+ | {
76
+ kind: "enum";
77
+ values: readonly string[];
78
+ aliases?: Readonly<Record<string, string>>;
79
+ }
80
+ | { kind: "const"; value: string }
67
81
  | { kind: "list" }
68
82
  | { kind: "words" }
69
83
  | { kind: "exitCodes" };
@@ -85,8 +99,15 @@ export const flag = {
85
99
  def(dest, { kind: "number", min }),
86
100
  on: (dest: string): FlagDef => def(dest, { kind: "bool", value: true }),
87
101
  off: (dest: string): FlagDef => def(dest, { kind: "bool", value: false }),
88
- oneOf: (dest: string, values: readonly string[]): FlagDef =>
89
- def(dest, { kind: "enum", values }),
102
+ oneOf: (
103
+ dest: string,
104
+ values: readonly string[],
105
+ aliases?: Readonly<Record<string, string>>,
106
+ ): FlagDef =>
107
+ def(dest, { kind: "enum", values, ...(aliases && { aliases }) }),
108
+ /** Sets `dest` to `value`; `--flag=false` leaves it, as `--json=false`. */
109
+ is: (dest: string, value: string): FlagDef =>
110
+ def(dest, { kind: "const", value }),
90
111
  /** Repeatable; each occurrence appends one value. */
91
112
  list: (dest: string): FlagDef => def(dest, { kind: "list" }),
92
113
  /** Repeatable; each occurrence is whitespace-split and appended. */
@@ -104,6 +125,7 @@ export interface OutputArgs {
104
125
 
105
126
  export interface RunArgs extends OutputArgs {
106
127
  noiseCheck: boolean;
128
+ noiseBudgetMs?: number;
107
129
  }
108
130
 
109
131
  export const OUTPUT_DEFAULTS = {
@@ -124,7 +146,8 @@ export const HELP_FLAGS: FlagTable = {
124
146
  export const OUTPUT_FLAGS: FlagTable = {
125
147
  ...HELP_FLAGS,
126
148
  "--export-json": flag.str("exportJson"),
127
- "--format": flag.oneOf("format", DOCUMENT_FORMATS),
149
+ "--format": flag.oneOf("format", DOCUMENT_FORMATS, FORMAT_ALIASES),
150
+ "--json": flag.is("format", "json"),
128
151
  "--quiet": flag.on("quiet"),
129
152
  };
130
153
 
@@ -132,6 +155,12 @@ export const NOISE_CHECK_FLAGS: FlagTable = {
132
155
  "--no-noise-check": flag.off("noiseCheck"),
133
156
  };
134
157
 
158
+ // Apart from NOISE_CHECK_FLAGS, since `ci` takes those but its noise
159
+ // check follows the config, so it must reject this one.
160
+ const NOISE_BUDGET_FLAGS: FlagTable = {
161
+ "--noise-budget": flag.int("noiseBudgetMs"),
162
+ };
163
+
135
164
  export const CONFIG_FLAGS: FlagTable = {
136
165
  "--config": flag.str("config"),
137
166
  };
@@ -145,6 +174,7 @@ export interface ConfigArgs {
145
174
  export const RUN_FLAGS: FlagTable = {
146
175
  ...OUTPUT_FLAGS,
147
176
  ...NOISE_CHECK_FLAGS,
177
+ ...NOISE_BUDGET_FLAGS,
148
178
  "--timeout": flag.int("timeoutMs"),
149
179
  "--out-dir": flag.str("outDir"),
150
180
  };
@@ -174,8 +204,8 @@ interface ParseSpec<T> {
174
204
  /** Receives each bare word; omitted, a bare word is an unknown-flag error. */
175
205
  positional?: (arg: string, args: T) => void;
176
206
  /**
177
- * Receives everything after a `--`, verbatim; omitted, `--` is an unknown
178
- * flag.
207
+ * Receives everything after a `--`, verbatim; omitted, `--` is an
208
+ * unknown flag.
179
209
  */
180
210
  rest?: (rest: string[], args: T) => void;
181
211
  }
@@ -249,12 +279,23 @@ export function parseFlags<T extends object>(
249
279
  break;
250
280
  case "enum": {
251
281
  const raw = value();
252
- if (!spec.values.includes(raw)) {
282
+ const resolved = spec.aliases?.[raw] ?? raw;
283
+ if (!spec.values.includes(resolved)) {
253
284
  throw new CliUsageError(
254
285
  `Invalid ${name} "${raw}": expected one of: ${spec.values.join(", ")}`,
255
286
  );
256
287
  }
257
- set(dest, raw);
288
+ set(dest, resolved);
289
+ break;
290
+ }
291
+ case "const": {
292
+ const raw = eq > 0 ? arg.slice(eq + 1) : "true";
293
+ if (raw !== "true" && raw !== "false") {
294
+ throw new CliUsageError(
295
+ `Invalid ${name} "${raw}": expected true or false`,
296
+ );
297
+ }
298
+ if (raw === "true") set(dest, spec.value);
258
299
  break;
259
300
  }
260
301
  }
package/src/cli/help.ts CHANGED
@@ -11,6 +11,9 @@ Flags:
11
11
  --warmup N discarded warmup trials (default: 3)
12
12
  --no-interleave run commands one after another instead of round-robin
13
13
  --prepare CMD run before every trial, unmeasured; once, or once per command
14
+ --shell SH run each command, and --prepare, as SH -c CMD (sh, bash)
15
+ --save-output DIR save each trial's output as DIR/<command>/trial-N.log
16
+ --show-output pass each trial's output to stderr
14
17
  --time-source REGEX take each trial's time from capture group 1 in the command's output
15
18
  --time-unit UNIT unit of --time-source: ns | us | ms | s (default: ms); needs --time-source
16
19
  --cpu capture one extra CPU-profile trial
@@ -19,9 +22,12 @@ Flags:
19
22
  --timeout MS kill a trial or --prepare hook after MS
20
23
  --ignore-failure[=CODE,...] treat these exit codes (bare: all) as success
21
24
  --out-dir PATH artifact directory (default: node_modules/.cache/ostia)
22
- --no-noise-check skip the ~200ms noise-floor measurement
25
+ --no-noise-check skip the noise-floor checks (50 to 75 ms in all)
26
+ --noise-budget MS sample the noise floor for exactly MS, start and end
23
27
  --export-json PATH write the ProfileDocument to PATH
24
- --format FORMAT table | json | jsonl | markdown | minimal (default: table)
28
+ --format FORMAT table | concise | events | json | jsonl | markdown (default: table,
29
+ concise under a coding agent; OSTIA_FORMAT sets another)
30
+ --json same as --format json
25
31
  --quiet don't print the report
26
32
  --help show this message
27
33
 
@@ -60,9 +66,12 @@ Flags:
60
66
  --timeout MS kill a suite (or isolated task) process after MS
61
67
  --out-dir PATH scratch directory (default: node_modules/.cache/ostia)
62
68
  --config PATH read this config file instead of ostia.config.ts/.json
63
- --no-noise-check skip the ~200ms noise-floor measurement
69
+ --no-noise-check skip the noise-floor checks (50 to 75 ms in all)
70
+ --noise-budget MS sample the noise floor for exactly MS, start and end
64
71
  --export-json PATH write the ProfileDocument to PATH
65
- --format FORMAT table | json | jsonl | markdown | minimal (default: table)
72
+ --format FORMAT table | concise | events | json | jsonl | markdown (default: table,
73
+ concise under a coding agent; OSTIA_FORMAT sets another)
74
+ --json same as --format json
66
75
  --quiet don't print the report
67
76
  --help show this message
68
77
 
@@ -106,9 +115,12 @@ Flags:
106
115
  --keep-trees N base trees to keep cached, least recently used go first (default: 5)
107
116
  --clean remove every cached base tree, then exit
108
117
  --config PATH read this config file instead of ostia.config.ts/.json
109
- --no-noise-check skip the ~200ms noise-floor measurement
118
+ --no-noise-check skip the noise-floor checks (50 to 75 ms in all)
119
+ --noise-budget MS sample the noise floor for exactly MS, start and end
110
120
  --export-json PATH write the ProfileDocument to PATH
111
- --format FORMAT table | json | jsonl | markdown | minimal (default: table)
121
+ --format FORMAT table | concise | events | json | jsonl | markdown (default: table,
122
+ concise under a coding agent; OSTIA_FORMAT sets another)
123
+ --json same as --format json
112
124
  --progress print progress to stderr (default: when stderr is a terminal and not
113
125
  --quiet); --no-progress turns it off
114
126
  --quiet don't print the report
@@ -127,7 +139,7 @@ unknown ref, a failed setup or suite), 130 Ctrl-C.
127
139
  Examples:
128
140
  ostia ab bench/parse.bench.ts
129
141
  ostia ab bench/*.ts --base origin/main --rounds 21
130
- ostia ab bench/*.ts --filter parse --format minimal
142
+ ostia ab bench/*.ts --filter parse --format events
131
143
  ostia ab bench/*.ts --metric instructions --threshold 3
132
144
  ostia ab bench/*.ts --base-setup "bun scripts/generate.ts"
133
145
  ostia ab bench/paint.bench.ts --alloc --peak-mem
@@ -145,7 +157,9 @@ Flags:
145
157
  --baseline PATH the base document, when only the candidate is positional
146
158
  --config PATH read thresholds from this config file instead of ostia.config.ts/.json
147
159
  --export-json PATH write the candidate document with comparisons to PATH
148
- --format FORMAT table | json | jsonl | markdown | minimal (default: table)
160
+ --format FORMAT table | concise | events | json | jsonl | markdown (default: table,
161
+ concise under a coding agent; OSTIA_FORMAT sets another)
162
+ --json same as --format json
149
163
  --quiet don't print the report
150
164
  --help show this message
151
165
 
@@ -163,7 +177,9 @@ Formats:
163
177
  json pretty JSON document
164
178
  jsonl one metadata line, then one line per measurement
165
179
  markdown agent- and human-readable report
166
- minimal one compact JSON object per timing measurement, for LLM/CI consumption
180
+ concise one line per task, then its warnings (alias: agent)
181
+ events one compact JSON object per timing measurement, for scripts and CI
182
+ (alias: minimal)
167
183
  collapsed folded stacks: "root;a;b 42" - flamegraph.pl and most flame tooling
168
184
  mermaid call tree, top-15 frames by total time (never the whole profile)
169
185
  speedscope sampled profile JSON for speedscope.app
@@ -194,9 +210,11 @@ Flags:
194
210
  --save-baseline after a pass, save this run as the new baseline (always measures
195
211
  fresh: the cache is not used)
196
212
  --config PATH read this config file instead of ostia.config.ts/.json
197
- --no-noise-check skip the ~200ms noise-floor measurement
213
+ --no-noise-check skip the noise-floor checks (50 to 75 ms in all)
198
214
  --export-json PATH write the candidate document with comparisons to PATH
199
- --format FORMAT table | json | jsonl | markdown | minimal (default: table)
215
+ --format FORMAT table | concise | events | json | jsonl | markdown (default: table,
216
+ concise under a coding agent; OSTIA_FORMAT sets another)
217
+ --json same as --format json
200
218
  --quiet don't print the report
201
219
  --help show this message
202
220
 
package/src/cli/output.ts CHANGED
@@ -69,7 +69,8 @@ export async function orFail<T>(
69
69
  }
70
70
  }
71
71
 
72
- const MACHINE_FORMATS = new Set(["minimal", "json", "jsonl"]);
72
+ // `minimal` too, since this reads argv before the alias resolves.
73
+ const MACHINE_FORMATS = new Set(["events", "minimal", "json", "jsonl"]);
73
74
 
74
75
  // Machine errors are for scripts and agents: stderr isn't a terminal, or a
75
76
  // machine `--format` was asked for.
@@ -81,6 +82,8 @@ async function wantsMachineErrors(): Promise<boolean> {
81
82
  const argv = process.argv.slice(2);
82
83
  return argv.some(
83
84
  (arg, i) =>
85
+ arg === "--json" ||
86
+ arg === "--json=true" ||
84
87
  (arg === "--format" && MACHINE_FORMATS.has(argv[i + 1] ?? "")) ||
85
88
  (arg.startsWith("--format=") &&
86
89
  MACHINE_FORMATS.has(arg.slice("--format=".length))),
@@ -146,8 +149,8 @@ interface OutputOptions {
146
149
  }
147
150
 
148
151
  // Honors `--export-json`; returns the JSON text when `--format json` will
149
- // print it (the json renderer's output is exactly this, so serialize
150
- // once).
152
+ // print it (the json renderer's output is exactly this, so
153
+ // serialize once).
151
154
  export async function exportDocument(
152
155
  doc: ProfileDocument,
153
156
  { exportJson, format, quiet }: OutputOptions,