bivium 0.6.1 → 0.7.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.
package/index.d.ts CHANGED
@@ -10,7 +10,10 @@ export declare function plan(options?: PlanOptions): Promise<PlanResult>;
10
10
  export interface PlanOptions<Suite extends string = string> {
11
11
  /** The repository. Default: the current directory. */
12
12
  cwd?: string;
13
- /** The ref to compare the working tree with. Default: the config's `base`, else the upstream default branch. */
13
+ /**
14
+ * The ref to compare the working tree with. Default: the config's `base`,
15
+ * else the upstream default branch.
16
+ */
14
17
  base?: string;
15
18
  /** The config. Default: the `bivium.config.*` file in `cwd`. */
16
19
  config?: Config<Suite>;
@@ -22,7 +25,11 @@ export interface Config<Suite extends string = string> {
22
25
  suites: Readonly<Record<Suite, SuiteConfig>>;
23
26
  /** Plugins that narrow what a change to some files selects. */
24
27
  narrowers?: readonly Narrower<NoInfer<Suite>>[];
25
- /** Paths (directories or files, not globs) the graph reads. A changed file outside them that isn't ignored runs everything. Default: the whole repository. */
28
+ /**
29
+ * Paths (directories or files, not globs) the graph reads. A changed file
30
+ * outside them that isn't ignored runs everything. Default: the
31
+ * whole repository.
32
+ */
26
33
  roots?: string | readonly string[];
27
34
  /**
28
35
  * Files no test can observe except through an edge (docs, stories). A
@@ -31,7 +38,10 @@ export interface Config<Suite extends string = string> {
31
38
  * dependencies are unknown.
32
39
  */
33
40
  ignore?: Globs;
34
- /** Specifier prefix → path, as the bundler aliases it: `{ "my-package": "src" }`. Tried before `package.json` `exports`. */
41
+ /**
42
+ * Specifier prefix → path, as the bundler aliases it: `{ "my-package":
43
+ * "src" }`. Tried before `package.json` `exports`.
44
+ */
35
45
  alias?: Readonly<Record<string, string>>;
36
46
  /**
37
47
  * Generated file glob → its inputs, which it depends on transitively, as
@@ -47,9 +57,15 @@ export interface Config<Suite extends string = string> {
47
57
  * `edges`: `{ "tests/*.test.ts": "tests/__snapshots__/$1.test.ts.snap" }`.
48
58
  */
49
59
  reads?: Readonly<Record<string, Globs>>;
50
- /** The selector's own files, which can't be trusted to select themselves. The config file is always one. */
60
+ /**
61
+ * The selector's own files, which can't be trusted to select themselves.
62
+ * The config file is always one.
63
+ */
51
64
  self?: Globs;
52
- /** Files only an import reaches. Deleting one never orphans a suite: an importer left pointing at it doesn't resolve, so it runs anyway. */
65
+ /**
66
+ * Files only an import reaches. Deleting one never orphans a suite: an
67
+ * importer left pointing at it doesn't resolve, so it runs anyway.
68
+ */
53
69
  importOnly?: Globs;
54
70
  /**
55
71
  * Files whose disk reads and non-literal imports reach no file of the
@@ -58,9 +74,16 @@ export interface Config<Suite extends string = string> {
58
74
  * unknown; an `@depends-on` or `@reads` still declares what one does read.
59
75
  */
60
76
  hermetic?: Globs;
61
- /** Modules that may bind named imports as barrels. Default: every module made only of re-exports. */
77
+ /**
78
+ * Modules that may bind named imports as barrels. Default: every module
79
+ * made only of re-exports.
80
+ */
62
81
  barrels?: Globs;
63
- /** Packages to treat as external though no `package.json` declares them: ones a dependency installs. Any other undeclared bare specifier is unknown. */
82
+ /**
83
+ * Packages to treat as external though no `package.json` declares them:
84
+ * ones a dependency installs. Any other undeclared bare specifier
85
+ * is unknown.
86
+ */
64
87
  external?: readonly string[];
65
88
  /**
66
89
  * Packages no test uses except by importing them: linters, formatters,
@@ -76,10 +99,10 @@ export interface Config<Suite extends string = string> {
76
99
  * Packages a test may load other than by an import bivium sees: a test
77
100
  * environment, a plugin a config names by string (`jsdom`, `happy-dom`,
78
101
  * `ts-jest`). Globs over package names. Setting it, even to `[]`, says
79
- * every other package without an executable is loaded only by imports, so a lockfile
80
- * change that reaches one no test imports selects nothing beyond its
81
- * importers. A package with a `bin` in the lockfile is always taken to
82
- * be one a test may run. Default: unset, and any package may be.
102
+ * every other package without an executable is loaded only by imports, so
103
+ * a lockfile change that reaches one no test imports selects nothing
104
+ * beyond its importers. A package with a `bin` in the lockfile is always
105
+ * taken to be one a test may run. Default: unset, and any package may be.
83
106
  */
84
107
  loadedByName?: Globs;
85
108
  /** Suffixes tried after a specifier, in order. */
@@ -87,10 +110,11 @@ export interface Config<Suite extends string = string> {
87
110
  /**
88
111
  * Globs `bivium check` allows to be dead: an `@depends-on`, `@reads`,
89
112
  * `@lists` or `import.meta.glob` pattern in `file`, or an `edges` or
90
- * `reads` key or value or a suite's `setup` when `file` is the config's, as written there, that matches no
91
- * file or matches files a change to which selects nothing (ignored, and
92
- * not in the graph). Each needs a reason, and an entry that matches no
93
- * dead glob fails the check, so the list stays current.
113
+ * `reads` key or value or a suite's `setup` when `file` is the config's,
114
+ * as written there, that matches no file or matches files a change to
115
+ * which selects nothing (ignored, and not in the graph). Each needs a
116
+ * reason, and an entry that matches no dead glob fails the check, so the
117
+ * list stays current.
94
118
  */
95
119
  deadGlobs?: readonly {
96
120
  file: string;
@@ -99,9 +123,9 @@ export interface Config<Suite extends string = string> {
99
123
  }[];
100
124
  /**
101
125
  * Nodes `bivium check` allows to have unknown dependencies, each with a
102
- * reason. With this set, even to `[]`, `check` fails on an unknown node some test
103
- * reaches that isn't listed, and on a listed node that's no longer
104
- * unknown, so a new unknown can't hide behind one that went away.
126
+ * reason. With this set, even to `[]`, `check` fails on an unknown node
127
+ * some test reaches that isn't listed, and on a listed node that's no
128
+ * longer unknown, so a new unknown can't hide behind one that went away.
105
129
  */
106
130
  knownUnknowns?: readonly {
107
131
  file: string;
@@ -109,14 +133,19 @@ export interface Config<Suite extends string = string> {
109
133
  }[];
110
134
  /** The default base ref. */
111
135
  base?: string;
112
- /** The extraction cache's directory, or `false` for none. Default: `node_modules/.cache/bivium`, or `.bivium/cache` without `node_modules`. */
136
+ /**
137
+ * The extraction cache's directory, or `false` for none. Default:
138
+ * `node_modules/.cache/bivium`, or `.bivium/cache` without `node_modules`.
139
+ */
113
140
  cache?: boolean | string;
114
141
  }
115
142
  /** A test suite: its files, how to run them, and how they're wired. */
116
143
  export interface SuiteConfig {
117
- /** The suite's test files. */
118
144
  tests: Globs;
119
- /** The command `bivium run` runs. `{files}` is replaced by the selected files, or nothing for all of them; without it, they're appended. */
145
+ /**
146
+ * The command `bivium run` runs. `{files}` is replaced by the selected
147
+ * files, or nothing for all of them; without it, they're appended.
148
+ */
120
149
  run?: string;
121
150
  /**
122
151
  * Where the orphan rule applies: a changed file under one of these paths
@@ -132,9 +161,15 @@ export interface SuiteConfig {
132
161
  * exist, and the rest are edges where they do.
133
162
  */
134
163
  urls?: Readonly<Record<string, string | readonly string[]>>;
135
- /** Pages only a `goto()` opens. A changed file that only such pages load, and that no test opens, is wired to no test. */
164
+ /**
165
+ * Pages only a `goto()` opens. A changed file that only such pages load,
166
+ * and that no test opens, is wired to no test.
167
+ */
136
168
  pages?: Globs;
137
- /** Files whose change runs the whole suite: a second harness, a runner config. */
169
+ /**
170
+ * Files whose change runs the whole suite: a second harness, a
171
+ * runner config.
172
+ */
138
173
  wiring?: Globs;
139
174
  /**
140
175
  * Files the runner loads before every test (Vitest and Jest `setupFiles`,
@@ -142,7 +177,10 @@ export interface SuiteConfig {
142
177
  * depends on them, and on what they import.
143
178
  */
144
179
  setup?: Globs;
145
- /** Files under `root` the runner never reads, such as type-check inputs: exempt from the orphan rule. */
180
+ /**
181
+ * Files under `root` the runner never reads, such as type-check inputs:
182
+ * exempt from the orphan rule.
183
+ */
146
184
  nonInputs?: Globs;
147
185
  /**
148
186
  * Whether the suite's tests can observe types. `false` for a suite that
@@ -154,10 +192,12 @@ export interface SuiteConfig {
154
192
  * `true`, for a type-checking suite (`tsc`, `vitest --typecheck`).
155
193
  */
156
194
  types?: boolean;
157
- /** The step output `bivium plan --github` writes the selection to. Default: `<name>-tests`. */
195
+ /**
196
+ * The step output `bivium plan --github` writes the selection
197
+ * to. Default: `<name>-tests`.
198
+ */
158
199
  output?: string;
159
200
  }
160
- /** One glob, or several. */
161
201
  export type Globs = string | readonly string[];
162
202
  /**
163
203
  * Replaces the coarse seeds of some changed files with finer ones from a
@@ -167,8 +207,8 @@ export type Globs = string | readonly string[];
167
207
  * The matched files still seed the walk, but it stops at the `opaque`
168
208
  * nodes they reach the tests through; the narrower's seeds stand in for
169
209
  * those. A narrower can only narrow: its selection is cut to what the
170
- * coarse walk selects. One that can't decide returns `{ all: reason }`, and
171
- * one that throws counts as that.
210
+ * coarse walk selects. One that can't decide returns `{ all: reason }`,
211
+ * and one that throws counts as that.
172
212
  */
173
213
  export interface Narrower<Suite extends string = string> {
174
214
  /** Names it in reasons: `css/: …`. */
@@ -202,13 +242,18 @@ export interface Tree {
202
242
  }
203
243
  /** The working tree's dependency graph, read-only. */
204
244
  export interface GraphView<Suite extends string = string> {
205
- /** Every node: repository files, barrel names (`src/index.js#Button`) and packages (`pkg:svelte`). */
245
+ /**
246
+ * Every node: repository files, barrel names (`src/index.js#Button`) and
247
+ * packages (`pkg:svelte`).
248
+ */
206
249
  nodes(): readonly string[];
207
250
  /** The nodes that import `node` directly. */
208
251
  importers(node: string): readonly string[];
209
- /** Every node that depends on one of `nodes`, transitively and including them, not counting files whose dependencies are unknown. */
252
+ /**
253
+ * Every node that depends on one of `nodes`, transitively and including
254
+ * them, not counting files whose dependencies are unknown.
255
+ */
210
256
  dependents(nodes: Iterable<string>): ReadonlySet<string>;
211
- /** A suite's test files. */
212
257
  tests(suite: Suite): readonly string[];
213
258
  }
214
259
  /**
@@ -231,11 +276,17 @@ export interface PlanResult<Suite extends string = string> {
231
276
  causes: FullRunCause<Suite>[];
232
277
  /** How many test files each suite has. */
233
278
  totals: Record<Suite, number>;
234
- /** A line per package a lockfile or `package.json` change changed, and that selects through its importers or nothing: `bun.lock: svelte 5.1.0 → 5.2.0`. */
279
+ /**
280
+ * A line per package a lockfile or `package.json` change changed, and that
281
+ * selects through its importers or nothing: `bun.lock: svelte 5.1.0 →
282
+ * 5.2.0`.
283
+ */
235
284
  packages: string[];
236
- /** The base ref. */
237
285
  base: string;
238
- /** The merge base of `base` and `HEAD`, which the working tree is compared with. */
286
+ /**
287
+ * The merge base of `base` and `HEAD`, which the working tree is
288
+ * compared with.
289
+ */
239
290
  mergeBase: string;
240
291
  /** The files changed since the merge base, untracked ones included. */
241
292
  changed: string[];
@@ -278,7 +329,10 @@ export interface FullRunCause<Suite extends string = string> {
278
329
  }
279
330
  /** Types a config. Returns it unchanged. */
280
331
  export declare function defineConfig<Suite extends string>(config: Config<Suite>): Config<Suite>;
281
- /** An error bivium names: its `code` says which failure, its `kind` what to do. */
332
+ /**
333
+ * An error bivium names: its `code` says which failure, its `kind` what
334
+ * to do.
335
+ */
282
336
  export declare class BiviumError extends Error {
283
337
  readonly code: BiviumErrorCode;
284
338
  readonly kind: BiviumErrorKind;
@@ -290,17 +344,9 @@ export declare class BiviumError extends Error {
290
344
  */
291
345
  export type BiviumErrorCode =
292
346
  /** No command, or `why` without a test. */
293
- "BV_MISSING_ARGUMENT"
294
- /** A command bivium doesn't have. */
295
- | "BV_UNKNOWN_COMMAND"
296
- /** An option the command doesn't take. */
297
- | "BV_UNKNOWN_OPTION"
347
+ "BV_MISSING_ARGUMENT" | "BV_UNKNOWN_COMMAND" | "BV_UNKNOWN_OPTION"
298
348
  /** An option's value is missing or of the wrong form. */
299
- | "BV_BAD_OPTION_VALUE"
300
- /** More arguments than the command takes. */
301
- | "BV_UNEXPECTED_ARGUMENT"
302
- /** A suite the config doesn't define. */
303
- | "BV_UNKNOWN_SUITE"
349
+ | "BV_BAD_OPTION_VALUE" | "BV_UNEXPECTED_ARGUMENT" | "BV_UNKNOWN_SUITE"
304
350
  /** A path that is no suite's test. */
305
351
  | "BV_UNKNOWN_TEST"
306
352
  /** A path that names no file of the graph. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bivium",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Run only the tests your change can reach.",
5
5
  "license": "MIT",
6
6
  "author": "Eric Liu (https://github.com/metonym)",
package/shared.js CHANGED
@@ -8,7 +8,7 @@ import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
8
8
  import { isAbsolute, join } from "node:path";
9
9
 
10
10
  // package.json
11
- var version = "0.6.1";
11
+ var version = "0.7.0";
12
12
 
13
13
  // src/env.ts
14
14
  function githubOutputPath() {
@@ -17,9 +17,25 @@ function githubOutputPath() {
17
17
  function nowMs() {
18
18
  return Date.now();
19
19
  }
20
+ function environment() {
21
+ return process.env;
22
+ }
23
+ var AGENT_ENV = [
24
+ "AGENT",
25
+ "AI_AGENT",
26
+ "CLAUDECODE",
27
+ "CODEX_CI",
28
+ "CODEX_THREAD_ID"
29
+ ];
30
+ function agentVariable(env) {
31
+ return AGENT_ENV.find((name) => {
32
+ const value = env[name];
33
+ return value !== undefined && value !== "" && value !== "0";
34
+ });
35
+ }
20
36
 
21
37
  // src/cache.ts
22
- var SCANNER_VERSION = 7;
38
+ var SCANNER_VERSION = 9;
23
39
  var MAGIC = "bivium-extractions";
24
40
  var FILE = "extractions.json";
25
41
  function isHeader(value) {
@@ -1375,7 +1391,7 @@ function createResolver({
1375
1391
  const found = probe(posix.join(svelteKitRoot(fromDir), "static", rest));
1376
1392
  return found.length > 0 ? { files: found } : undefined;
1377
1393
  }
1378
- const found = probe(posix.join(fromDir, bare));
1394
+ const found = probe(posix.join(fromDir, bare).replace(/(.)\/+$/, "$1"));
1379
1395
  return found.length > 0 ? { files: found } : undefined;
1380
1396
  };
1381
1397
  const resolveBare = (scope, bare) => {
@@ -2933,6 +2949,19 @@ function addPattern(deps, pattern, kind) {
2933
2949
  deps.patternKinds ??= new Map;
2934
2950
  deps.patternKinds.set(pattern, kind);
2935
2951
  }
2952
+ function addCause(deps, cause) {
2953
+ if (!deps.unknown.includes(cause))
2954
+ deps.unknown.push(cause);
2955
+ }
2956
+ function addPages(deps, pages) {
2957
+ for (const page of pages) {
2958
+ if (!deps.files.has(page)) {
2959
+ deps.pages ??= new Set;
2960
+ deps.pages.add(page);
2961
+ }
2962
+ deps.files.add(page);
2963
+ }
2964
+ }
2936
2965
  var NON_LITERAL_GOTO = "non-literal goto(";
2937
2966
  var HERMETIC_CAUSES = new Set([
2938
2967
  UNDECLARED_READS,
@@ -3047,28 +3076,22 @@ function graphFrom(files, extractions, { config, packages, tsconfigs }) {
3047
3076
  (erased ? typed : valued).add(node);
3048
3077
  };
3049
3078
  if (resolved === undefined) {
3050
- const cause = `unresolved "${specifier}"`;
3051
- if (!deps.unknown.includes(cause))
3052
- deps.unknown.push(cause);
3079
+ addCause(deps, `unresolved "${specifier}"`);
3053
3080
  } else if ("pkg" in resolved) {
3054
3081
  add(`pkg:${resolved.pkg}`);
3055
3082
  external.add(`pkg:${resolved.pkg}`);
3056
3083
  } else {
3057
3084
  if (type !== true && !declaration && JS_SPECIFIER.test(specifier.replace(QUERY, "")) && resolved.files.every((file) => DECLARATION.test(file))) {
3058
- const cause = `only declarations for "${specifier}"`;
3059
- if (!deps.unknown.includes(cause))
3060
- deps.unknown.push(cause);
3085
+ addCause(deps, `only declarations for "${specifier}"`);
3061
3086
  }
3062
- for (const file of resolved.files) {
3087
+ const nodes = resolved.files.flatMap((file) => {
3063
3088
  const barrel = names && named.get(file);
3064
- if (!barrel || !names) {
3065
- add(file);
3066
- continue;
3067
- }
3068
- for (const name of names) {
3069
- add(barrel.has(name) ? `${file}#${name}` : file);
3070
- }
3071
- }
3089
+ if (!barrel || !names)
3090
+ return [file];
3091
+ return names.map((name) => barrel.has(name) ? `${file}#${name}` : file);
3092
+ });
3093
+ for (const node of nodes)
3094
+ add(node);
3072
3095
  }
3073
3096
  }
3074
3097
  for (const node of typed) {
@@ -3085,25 +3108,18 @@ function graphFrom(files, extractions, { config, packages, tsconfigs }) {
3085
3108
  if (suite) {
3086
3109
  for (const argument of found.gotos) {
3087
3110
  const url = gotoUrl(argument);
3088
- if (url === undefined) {
3089
- if (found.dependsOn.length === 0) {
3090
- deps.unknown.push(`${NON_LITERAL_GOTO}${argument})`);
3091
- }
3092
- } else if (url !== "about:blank") {
3093
- const mapped = mapUrl(suite, url.replace(QUERY, ""));
3094
- if (mapped === undefined)
3095
- deps.unknown.push(`goto("${url}")`);
3096
- else if (exists.has(mapped[0] ?? "")) {
3097
- for (const page of mapped.filter((file) => exists.has(file))) {
3098
- if (!deps.files.has(page)) {
3099
- deps.pages ??= new Set;
3100
- deps.pages.add(page);
3101
- }
3102
- deps.files.add(page);
3103
- }
3104
- } else
3105
- deps.unknown.push(`missing fixture "${url}"`);
3111
+ if (url === undefined && found.dependsOn.length === 0) {
3112
+ deps.unknown.push(`${NON_LITERAL_GOTO}${argument})`);
3106
3113
  }
3114
+ if (url === undefined || url === "about:blank")
3115
+ continue;
3116
+ const mapped = mapUrl(suite, url.replace(QUERY, ""));
3117
+ if (mapped === undefined)
3118
+ deps.unknown.push(`goto("${url}")`);
3119
+ else if (exists.has(mapped[0] ?? "")) {
3120
+ addPages(deps, mapped.filter((file) => exists.has(file)));
3121
+ } else
3122
+ deps.unknown.push(`missing fixture "${url}"`);
3107
3123
  }
3108
3124
  }
3109
3125
  for (const glob of found.dependsOn) {
@@ -4284,9 +4300,142 @@ function planTests(graph, changed, config, {
4284
4300
  // src/settings.ts
4285
4301
  import { posix as posix5 } from "node:path";
4286
4302
 
4287
- // src/text.ts
4288
- function plural(count, one, many = `${one}s`) {
4289
- return `${count} ${count === 1 ? one : many}`;
4303
+ // src/terminal.ts
4304
+ var asIs = (text) => text;
4305
+ var PLAIN = {
4306
+ good: asIs,
4307
+ warn: asIs,
4308
+ bad: asIs,
4309
+ dim: asIs,
4310
+ bold: asIs,
4311
+ faint: asIs
4312
+ };
4313
+ function createPaint() {
4314
+ const wrap = (code) => (text) => text === "" ? text : `\x1B[${code}m${text}\x1B[39m`;
4315
+ return {
4316
+ good: wrap(32),
4317
+ warn: wrap(33),
4318
+ bad: wrap(31),
4319
+ dim: wrap(90),
4320
+ bold: (text) => text === "" ? text : `\x1B[1m${text}\x1B[22m`,
4321
+ faint: (text) => text === "" ? text : `\x1B[2m${text}\x1B[22m`
4322
+ };
4323
+ }
4324
+ function wantsColor(forced, terminal, env, agent) {
4325
+ if (forced !== undefined)
4326
+ return forced;
4327
+ if ((env.NO_COLOR ?? "") !== "")
4328
+ return false;
4329
+ const force = env.FORCE_COLOR;
4330
+ if (force !== undefined && force !== "")
4331
+ return force !== "0";
4332
+ return terminal && !agent;
4333
+ }
4334
+ var SEPARATOR = " · ";
4335
+ var branch = (index, count) => index === count - 1 ? "└ " : "├ ";
4336
+ var NOTE_INDENT = " ";
4337
+ function closingLine(paint, what, detail) {
4338
+ return `${paint.good("✓")} ${what}${detail === undefined ? "" : paint.dim(`${SEPARATOR}${detail}`)}`;
4339
+ }
4340
+ function failLine(paint, what, detail) {
4341
+ return `${paint.bad("✗")} ${what}${detail === undefined ? "" : paint.dim(`${SEPARATOR}${detail}`)}`;
4342
+ }
4343
+ function truncateWords(text, max) {
4344
+ if ([...text].length <= max)
4345
+ return text;
4346
+ const cut = [...text].slice(0, max - 1).join("");
4347
+ const space = cut.lastIndexOf(" ");
4348
+ return `${(space > max / 2 ? cut.slice(0, space) : cut).replace(/[\s,;:]+$/, "")}…`;
4349
+ }
4350
+ var HASH_TAIL = /[-.][^-./]+\.\w+$/;
4351
+ var WORD_END = /(?<=[-_.])/;
4352
+ var width = (text) => [...text].length;
4353
+ function truncatePath(path, max) {
4354
+ if (width(path) <= max)
4355
+ return path;
4356
+ const parts = path.split("/");
4357
+ const name = parts.pop() ?? path;
4358
+ for (let keep = parts.length - 1;keep >= 0; keep--) {
4359
+ const candidate = `…/${[...parts.slice(parts.length - keep), name].join("/")}`;
4360
+ if (width(candidate) <= max)
4361
+ return candidate;
4362
+ }
4363
+ const prefix = parts.length > 0 ? "…/" : "";
4364
+ const tail = HASH_TAIL.exec(name)?.[0] ?? "";
4365
+ const stem = name.slice(0, name.length - tail.length);
4366
+ const room = max - width(prefix) - width(tail) - 1;
4367
+ if (room < 4)
4368
+ return `${prefix}…${[...name].slice(-(max - width(prefix) - 1)).join("")}`;
4369
+ const words = stem.split(WORD_END);
4370
+ const first = words[0] ?? "";
4371
+ let end = "";
4372
+ for (let i = words.length - 1;i > 0; i--) {
4373
+ const word = words[i] ?? "";
4374
+ if (width(first) + 1 + width(word + end) > room)
4375
+ break;
4376
+ end = word + end;
4377
+ }
4378
+ return end === "" ? `${prefix}${[...stem].slice(0, room).join("")}…${tail}` : `${prefix}${first}…${end}${tail}`;
4379
+ }
4380
+ var ESCAPE = /\x1b\[[0-9;]*m/g;
4381
+ var textWidth = (text) => typeof Bun === "undefined" ? [...text.replace(ESCAPE, "")].length : Bun.stringWidth(text);
4382
+ var MEASURE = 80;
4383
+ var RULE = "\x00rule";
4384
+ function aligned(table, rightColumns = [], paintRule = asIs, indent = " ") {
4385
+ const blank = (cell) => cell === "" || cell === RULE;
4386
+ const used = new Set(table.flatMap((row) => row.flatMap((cell, i) => blank(cell) ? [] : [i])));
4387
+ const keep = (row) => row.filter((_, i) => used.has(i));
4388
+ const rows = table.map(keep);
4389
+ const right = [...used].sort((a, b) => a - b).flatMap((column, i) => rightColumns.includes(column) ? [i] : []);
4390
+ const cellWidth = (cell) => cell === RULE ? 0 : textWidth(cell);
4391
+ const widths = [];
4392
+ for (const row of rows) {
4393
+ for (const [i, cell] of row.entries()) {
4394
+ if (i === row.length - 1 && !right.includes(i))
4395
+ continue;
4396
+ widths[i] = Math.max(widths[i] ?? 0, cellWidth(cell));
4397
+ }
4398
+ }
4399
+ const pad = (cell, i) => " ".repeat(Math.max(0, (widths[i] ?? 0) - cellWidth(cell)));
4400
+ const columnsWidth = (from, to) => widths.slice(from, to).reduce((sum, w) => sum + w + 2, 0);
4401
+ return rows.map((row) => {
4402
+ const first = row.indexOf(RULE);
4403
+ if (first !== -1) {
4404
+ const last = row.lastIndexOf(RULE);
4405
+ const line = "─".repeat(columnsWidth(first, last + 1) - 2);
4406
+ return `${indent}${" ".repeat(columnsWidth(0, first))}${paintRule(line)}`;
4407
+ }
4408
+ return `${indent}${row.map((cell, i) => right.includes(i) ? pad(cell, i) + cell : i === row.length - 1 ? cell : cell + pad(cell, i)).join(" ")}`.trimEnd();
4409
+ });
4410
+ }
4411
+ var headerRow = (paint, cells) => cells.map((cell) => paint.faint(cell));
4412
+ var plural = (count, one, many = `${one}s`) => `${count} ${count === 1 ? one : many}`;
4413
+ var SILENT = { step: () => {}, clear: () => {} };
4414
+ var BAR_WIDTH = 20;
4415
+ var CLEAR_LINE = "\r\x1B[2K";
4416
+ function createProgress(write, paint, nowMs) {
4417
+ const startMs = nowMs();
4418
+ let text = "";
4419
+ let doneRatio = 0;
4420
+ const render = () => {
4421
+ const done = Math.round(Math.min(1, Math.max(0, doneRatio)) * BAR_WIDTH);
4422
+ const bar = paint.good("━".repeat(done)) + paint.dim("─".repeat(BAR_WIDTH - done));
4423
+ const seconds = Math.floor((nowMs() - startMs) / 1000);
4424
+ write(`${CLEAR_LINE}${bar} ${text}${paint.dim(` · ${seconds} s`)}`);
4425
+ };
4426
+ const timer = setInterval(render, 1000);
4427
+ timer.unref();
4428
+ return {
4429
+ step(next, ratio) {
4430
+ text = next;
4431
+ doneRatio = ratio;
4432
+ render();
4433
+ },
4434
+ clear() {
4435
+ clearInterval(timer);
4436
+ write(CLEAR_LINE);
4437
+ }
4438
+ };
4290
4439
  }
4291
4440
 
4292
4441
  // src/tsconfig.ts
@@ -4816,4 +4965,4 @@ async function plan2(options = {}) {
4816
4965
  };
4817
4966
  }
4818
4967
 
4819
- export { version, githubOutputPath, BiviumError2, didYouMean, globToRegExp, defineConfig2, inRoot, sorted, QUERY, UNDECLARED_READS, RELATIVE, aliasPath, createResolver, SCANNED, formatOf, extract, stringsOf, finish, gotoPage, walksByTypes, importersOf, affectedBy, formatSelection, orphanOf, plural, computePlan, prepare, plan2 };
4968
+ export { version, githubOutputPath, nowMs, environment, agentVariable, BiviumError2, didYouMean, globToRegExp, defineConfig2, inRoot, sorted, QUERY, UNDECLARED_READS, RELATIVE, aliasPath, createResolver, SCANNED, formatOf, extract, stringsOf, finish, gotoPage, walksByTypes, importersOf, affectedBy, formatSelection, orphanOf, PLAIN, createPaint, wantsColor, SEPARATOR, branch, NOTE_INDENT, closingLine, failLine, truncateWords, truncatePath, textWidth, MEASURE, RULE, aligned, headerRow, plural, SILENT, createProgress, computePlan, prepare, plan2 };