trivium 0.0.0 → 0.1.1

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/src/config.ts ADDED
@@ -0,0 +1,49 @@
1
+ // The config's shape and `defineConfig`, apart from the code that loads
2
+ // it: a config imports this, and the loader imports the config, so one
3
+ // module holding both makes a cycle that deadlocks on top-level await.
4
+
5
+ /** One scripted interaction for `trivium interactions`. */
6
+ export interface Step {
7
+ /** Names the step in reports. */
8
+ label: string;
9
+ /** Does the interaction, through the view's native input. */
10
+ run: (view: Bun.WebView) => Promise<unknown>;
11
+ }
12
+
13
+ /** What's specific to one page, from `trivium.config.ts`. */
14
+ export interface Config {
15
+ /** The page to measure when the command names none. */
16
+ url?: string;
17
+ /**
18
+ * The `performance.mark()` the page sets once it's interactive, such as
19
+ * right after `hydrate()`. Without one, trivium waits for `load`.
20
+ */
21
+ readyMark?: string;
22
+ /**
23
+ * Where the build puts content-hashed files, and how their names carry
24
+ * the hash.
25
+ */
26
+ assets?: {
27
+ /** @default "/assets/" */
28
+ path?: string;
29
+ /** @default /-[\w-]{8}(?=\.\w+$)/ */
30
+ hash?: RegExp;
31
+ };
32
+ /** The interactions `trivium interactions` does, in order. */
33
+ steps?: readonly Step[];
34
+ /** An element whose first appearance `load` and `compare` time. */
35
+ element?: { label: string; selector: string };
36
+ /**
37
+ * Selectors for loading indicators; `interactions` times how long any
38
+ * is visible.
39
+ */
40
+ loaders?: readonly string[];
41
+ }
42
+
43
+ /**
44
+ * Returns `config` as given, typed, for `export default`
45
+ * in `trivium.config.ts`.
46
+ */
47
+ export function defineConfig(config: Config): Config {
48
+ return config;
49
+ }
package/src/env.ts ADDED
@@ -0,0 +1,16 @@
1
+ // The one module that reads the environment, the clock and the working
2
+ // directory (code.md, Determinism), so a test can set what they return.
3
+
4
+ export function processEnv(): Readonly<Record<string, string | undefined>> {
5
+ // eslint-disable-next-line no-restricted-properties -- the one env reader
6
+ return process.env;
7
+ }
8
+
9
+ export function nowMs(): number {
10
+ // eslint-disable-next-line no-restricted-properties -- the one clock reader
11
+ return Date.now();
12
+ }
13
+
14
+ export function workingDirectory(): string {
15
+ return process.cwd();
16
+ }
package/src/errors.ts ADDED
@@ -0,0 +1,46 @@
1
+ // The codes `--json` prints as `error.code`, each with its cause in
2
+ // docs/agents.md, since agents branch on them; a code is never reused
3
+ // for another meaning.
4
+ type TriviumErrorCode =
5
+ | "TV_USAGE"
6
+ | "TV_CONFIG"
7
+ | "TV_UNSUPPORTED"
8
+ | "TV_TIMEOUT"
9
+ | "TV_INPUT"
10
+ | "TV_INTERNAL";
11
+
12
+ // One kind per code, so a caller branches on what to do without
13
+ // knowing every code.
14
+ type TriviumErrorKind = "usage" | "config" | "browser" | "input" | "other";
15
+
16
+ const KIND_BY_CODE = {
17
+ TV_USAGE: "usage",
18
+ TV_CONFIG: "config",
19
+ TV_UNSUPPORTED: "browser",
20
+ TV_TIMEOUT: "browser",
21
+ TV_INPUT: "input",
22
+ TV_INTERNAL: "other",
23
+ } as const satisfies Record<TriviumErrorCode, TriviumErrorKind>;
24
+
25
+ // The one error class, so main.ts can tell an error raised on purpose
26
+ // from a bug, which it reports as TV_INTERNAL.
27
+ export class TriviumError extends Error {
28
+ readonly code: TriviumErrorCode;
29
+ readonly kind: TriviumErrorKind;
30
+
31
+ constructor(code: TriviumErrorCode, message: string, options?: ErrorOptions) {
32
+ super(message, options);
33
+ this.name = "TriviumError";
34
+ this.code = code;
35
+ this.kind = KIND_BY_CODE[code];
36
+ }
37
+ }
38
+
39
+ // Every error leaves as a TriviumError, so --json always has a code.
40
+ export function toTriviumError(error: unknown): TriviumError {
41
+ if (error instanceof TriviumError) return error;
42
+ const message = error instanceof Error ? error.message : String(error);
43
+ return new TriviumError("TV_INTERNAL", `trivium: ${message}`, {
44
+ cause: error,
45
+ });
46
+ }
package/src/format.ts ADDED
@@ -0,0 +1,314 @@
1
+ // The text shared by every command's human and agent output.
2
+
3
+ export type Format = "human" | "agent" | "json";
4
+
5
+ export const FORMATS: readonly Format[] = ["human", "agent", "json"];
6
+
7
+ export const SCHEMA_VERSION = 1;
8
+
9
+ // A command returns all three forms, so main.ts picks one without the
10
+ // command knowing which.
11
+ export interface Outcome {
12
+ exitCode: 0 | 1;
13
+ json: {
14
+ schemaVersion: number;
15
+ ok: boolean;
16
+ command: string;
17
+ [field: string]: unknown;
18
+ };
19
+ text(format: "human" | "agent", paint: Paint): string;
20
+ }
21
+
22
+ // Color for the human format on a terminal only: the agent format and
23
+ // JSON are read by programs, and cli.md allows no ANSI when stdout isn't
24
+ // a terminal. Each color marks a verdict or recedes, never decorates.
25
+ export interface Paint {
26
+ good: (text: string) => string;
27
+ warn: (text: string) => string;
28
+ bad: (text: string) => string;
29
+ dim: (text: string) => string;
30
+ bold: (text: string) => string;
31
+ faint: (text: string) => string;
32
+ }
33
+
34
+ const asIs = (text: string) => text;
35
+
36
+ export const PLAIN: Paint = {
37
+ good: asIs,
38
+ warn: asIs,
39
+ bad: asIs,
40
+ dim: asIs,
41
+ bold: asIs,
42
+ faint: asIs,
43
+ };
44
+
45
+ // The 16 ANSI colors, never a fixed hex: each terminal theme defines
46
+ // its own green or gray, picked to read on its own background, light,
47
+ // dark or pink. Bun.color gives each code from a named color.
48
+ export function createPaint(): Paint {
49
+ const wrap = (name: string) => {
50
+ const code = Bun.color(name, "ansi-16") ?? "";
51
+ return (text: string) =>
52
+ code === "" || text === "" ? text : `${code}${text}\x1b[39m`;
53
+ };
54
+ return {
55
+ good: wrap("green"),
56
+ warn: wrap("olive"),
57
+ bad: wrap("maroon"),
58
+ // Bright black, the gray every theme dims secondary text with.
59
+ dim: wrap("#6e7681"),
60
+ // Bold is a weight, not a color, so it's an SGR code Bun.color can't
61
+ // give: section heads in --help only.
62
+ bold: (text) => (text === "" ? text : `\x1b[1m${text}\x1b[22m`),
63
+ // Faint is the text color at lower intensity, so a table's header
64
+ // recedes in every theme, even one whose gray is odd.
65
+ faint: (text) => (text === "" ? text : `\x1b[2m${text}\x1b[22m`),
66
+ };
67
+ }
68
+
69
+ // Every metric and size trivium reports is better lower, so a decrease
70
+ // is good and an increase bad.
71
+ export function paintChange(
72
+ paint: Paint,
73
+ delta: number,
74
+ ): (text: string) => string {
75
+ return delta < 0 ? paint.good : delta > 0 ? paint.bad : asIs;
76
+ }
77
+
78
+ // The human format's word for a rating: "needs work" for
79
+ // needs-improvement, so three verdicts fit one 80-column line. JSON
80
+ // keeps the full name.
81
+ export function ratingLabel(rating: string | undefined): string {
82
+ return rating === "needs-improvement" ? "needs work" : (rating ?? "");
83
+ }
84
+
85
+ // A rating's color, so good, needs-improvement and poor read at a glance.
86
+ export function paintRating(
87
+ paint: Paint,
88
+ rating: string | undefined,
89
+ ): (text: string) => string {
90
+ return rating === "good"
91
+ ? paint.good
92
+ : rating === "needs-improvement"
93
+ ? paint.warn
94
+ : rating === "poor"
95
+ ? paint.bad
96
+ : asIs;
97
+ }
98
+
99
+ // Missing values read "n/a", since typography.md bans the em dash.
100
+ export const MISSING = "n/a";
101
+
102
+ // Three significant figures at most (typography.md): whole
103
+ // milliseconds under a second, then seconds, so 1196 ms reads 1.20 s.
104
+ export function ms(value: number | undefined): string {
105
+ if (value === undefined) return MISSING;
106
+ const rounded = Math.round(value);
107
+ return Math.abs(rounded) < 1000
108
+ ? `${rounded} ms`
109
+ : `${(value / 1000).toPrecision(3)} s`;
110
+ }
111
+
112
+ // Bytes under 1,000, then kB and MB, so no size shows more than three
113
+ // significant figures.
114
+ export function byteSize(count: number): string {
115
+ const rounded = Math.round(count);
116
+ if (Math.abs(rounded) < 1000) return `${rounded} B`;
117
+ if (Math.abs(rounded) < 999_500) {
118
+ return `${(rounded / 1000).toPrecision(3)} kB`;
119
+ }
120
+ return `${(rounded / 1e6).toPrecision(3)} MB`;
121
+ }
122
+
123
+ // A zero difference has no sign, so "±" only ever means noise. The
124
+ // minus is ASCII, as typography.md's notation set has no other.
125
+ export const signed = (value: number, show: (n: number) => string): string =>
126
+ value === 0 ? show(0) : `${value > 0 ? "+" : "-"}${show(Math.abs(value))}`;
127
+
128
+ // typography.md's status-line separator, so every header splits its
129
+ // parts the same way.
130
+ export const SEPARATOR = " · ";
131
+
132
+ // A sub-row's branch, so a group's last row closes it: ├ then └.
133
+ export const branch = (index: number, count: number): string =>
134
+ index === count - 1 ? "└ " : "├ ";
135
+
136
+ // A note under a row, indented past the label's branch, as a reason or
137
+ // a problem that would push the row past 80 columns.
138
+ export const NOTE_INDENT = " ";
139
+
140
+ // The last line of a run that finished: what it did and how long it
141
+ // took, so a person sees it ended and why it took that long.
142
+ export function closingLine(
143
+ paint: Paint,
144
+ what: string,
145
+ detail?: string,
146
+ ): string {
147
+ return `${paint.good("✓")} ${what}${detail === undefined ? "" : paint.dim(`${SEPARATOR}${detail}`)}`;
148
+ }
149
+
150
+ // A duration for the closing line: seconds, or minutes and seconds past
151
+ // a minute, since a run takes seconds, not milliseconds.
152
+ export function elapsed(valueMs: number): string {
153
+ if (valueMs < 60_000) return ms(valueMs);
154
+ const minutes = Math.floor(valueMs / 60_000);
155
+ return `${minutes} m ${Math.round((valueMs % 60_000) / 1000)} s`;
156
+ }
157
+
158
+ // At a word boundary, so a label never ends mid-word; --json keeps
159
+ // it whole.
160
+ export function truncateWords(text: string, max: number): string {
161
+ if ([...text].length <= max) return text;
162
+ const cut = [...text].slice(0, max - 1).join("");
163
+ const space = cut.lastIndexOf(" ");
164
+ return `${(space > max / 2 ? cut.slice(0, space) : cut).replace(/[\s,;:]+$/, "")}…`;
165
+ }
166
+
167
+ // Since the file name matters more than its folders, and its first and
168
+ // last words more than its middle, folders go from the left first, then
169
+ // the stem's middle words, and the build hash and extension always stay,
170
+ // as in …/carbon-…DataTableSkeleton-Lp9Rk3Ds.js.
171
+ const HASH_TAIL = /[-.][^-./]+\.\w+$/;
172
+ const WORD_END = /(?<=[-_.])/;
173
+ const width = (text: string) => [...text].length;
174
+
175
+ export function truncatePath(path: string, max: number): string {
176
+ if (width(path) <= max) return path;
177
+ const parts = path.split("/");
178
+ const name = parts.pop() ?? path;
179
+ for (let keep = parts.length - 1; keep >= 0; keep--) {
180
+ const candidate = `…/${[...parts.slice(parts.length - keep), name].join("/")}`;
181
+ if (width(candidate) <= max) return candidate;
182
+ }
183
+ const prefix = parts.length > 0 ? "…/" : "";
184
+ const tail = HASH_TAIL.exec(name)?.[0] ?? "";
185
+ const stem = name.slice(0, name.length - tail.length);
186
+ const room = max - width(prefix) - width(tail) - 1;
187
+ if (room < 4)
188
+ return `${prefix}…${[...name].slice(-(max - width(prefix) - 1)).join("")}`;
189
+ const words = stem.split(WORD_END);
190
+ const first = words[0] ?? "";
191
+ let end = "";
192
+ for (let i = words.length - 1; i > 0; i--) {
193
+ const word = words[i] ?? "";
194
+ if (width(first) + 1 + width(word + end) > room) break;
195
+ end = word + end;
196
+ }
197
+ return end === ""
198
+ ? `${prefix}${[...stem].slice(0, room).join("")}…${tail}`
199
+ : `${prefix}${first}…${end}${tail}`;
200
+ }
201
+
202
+ // A mark in the left margin for a row that needs work, in its rating's
203
+ // color, so a scan finds what to fix while the numbers stay plain.
204
+ export function withGutter(
205
+ lines: readonly string[],
206
+ marks: ReadonlyMap<number, (text: string) => string>,
207
+ ): string[] {
208
+ return lines.map((line, i) => {
209
+ const mark = marks.get(i);
210
+ return mark === undefined ? line : `${mark("▌")}${line.slice(1)}`;
211
+ });
212
+ }
213
+
214
+ const MEASURE = 80;
215
+
216
+ // A cell that draws a rule as wide as its column, so totals read apart
217
+ // from the rows above them.
218
+ export const RULE = "\u0000rule";
219
+
220
+ // Numbers right-align (typography.md, Blocks), so the columns in
221
+ // `right` pad on the left. A left-aligned last cell is left ragged,
222
+ // since padding it would only add trailing spaces.
223
+ export function aligned(
224
+ table: readonly (readonly string[])[],
225
+ rightColumns: readonly number[] = [],
226
+ paintRule: (text: string) => string = asIs,
227
+ indent = " ",
228
+ ): string[] {
229
+ const blank = (cell: string) => cell === "" || cell === RULE;
230
+ // A column empty in every row, such as noise from one run, is left
231
+ // out, or it would print as a double gap.
232
+ const used = new Set(
233
+ table.flatMap((row) => row.flatMap((cell, i) => (blank(cell) ? [] : [i]))),
234
+ );
235
+ const keep = (row: readonly string[]) => row.filter((_, i) => used.has(i));
236
+ const rows = table.map(keep);
237
+ const right = [...used]
238
+ .sort((a, b) => a - b)
239
+ .flatMap((column, i) => (rightColumns.includes(column) ? [i] : []));
240
+ // Bun.stringWidth skips ANSI codes, so a colored cell pads as wide as
241
+ // it shows.
242
+ const width = (cell: string) => (cell === RULE ? 0 : Bun.stringWidth(cell));
243
+ const widths: number[] = [];
244
+ for (const row of rows) {
245
+ for (const [i, cell] of row.entries()) {
246
+ if (i === row.length - 1 && !right.includes(i)) continue;
247
+ widths[i] = Math.max(widths[i] ?? 0, width(cell));
248
+ }
249
+ }
250
+ const pad = (cell: string, i: number) =>
251
+ " ".repeat(Math.max(0, (widths[i] ?? 0) - width(cell)));
252
+ const columnsWidth = (from: number, to: number) =>
253
+ widths.slice(from, to).reduce((sum, w) => sum + w + 2, 0);
254
+ return rows.map((row) => {
255
+ const first = row.indexOf(RULE);
256
+ if (first !== -1) {
257
+ const last = row.lastIndexOf(RULE);
258
+ const line = "─".repeat(columnsWidth(first, last + 1) - 2);
259
+ return `${indent}${" ".repeat(columnsWidth(0, first))}${paintRule(line)}`;
260
+ }
261
+ // An empty row is a blank line, with no indent left trailing.
262
+ return `${indent}${row
263
+ .map((cell, i) =>
264
+ right.includes(i)
265
+ ? pad(cell, i) + cell
266
+ : i === row.length - 1
267
+ ? cell
268
+ : cell + pad(cell, i),
269
+ )
270
+ .join(" ")}`.trimEnd();
271
+ });
272
+ }
273
+
274
+ // aligned, with a row that overflows the measure shortened in its last
275
+ // cell by `shrink`, by just its overflow. Other rows, the header and a
276
+ // colored cell, which a cut would break, stay as they are.
277
+ export function fitted(
278
+ table: readonly (readonly string[])[],
279
+ rightColumns: readonly number[],
280
+ shrink: (text: string, max: number) => string,
281
+ paintRule: (text: string) => string = asIs,
282
+ ): string[] {
283
+ const lines = aligned(table, rightColumns, paintRule);
284
+ if (lines.every((line) => Bun.stringWidth(line) <= MEASURE)) return lines;
285
+ const shrunk = table.map((row, r) => {
286
+ const over = Bun.stringWidth(lines[r] ?? "") - MEASURE;
287
+ const last = row.length - 1;
288
+ const cell = row[last] ?? "";
289
+ if (r === 0 || over <= 0 || cell === RULE || cell.includes("\x1b")) {
290
+ return row;
291
+ }
292
+ const copy = [...row];
293
+ copy[last] = shrink(cell, Bun.stringWidth(cell) - over);
294
+ return copy;
295
+ });
296
+ return aligned(shrunk, rightColumns, paintRule);
297
+ }
298
+
299
+ // Lines with notes under some of them, keyed by the line's index, so a
300
+ // note follows its row without widening the table.
301
+ export function withNotes(
302
+ lines: readonly string[],
303
+ notes: ReadonlyMap<number, readonly string[]>,
304
+ ): string[] {
305
+ return lines.flatMap((line, i) => [line, ...(notes.get(i) ?? [])]);
306
+ }
307
+
308
+ // A table's header row is read once, then consulted, so it takes the
309
+ // smallest effective difference: faint, no rule (design.md, data-ink).
310
+ export const headerRow = (paint: Paint, cells: readonly string[]): string[] =>
311
+ cells.map((cell) => paint.faint(cell));
312
+
313
+ export const plural = (count: number, one: string, many = `${one}s`): string =>
314
+ `${count} ${count === 1 ? one : many}`;
package/src/help.ts ADDED
@@ -0,0 +1,172 @@
1
+ import { version } from "../package.json";
2
+ import type { Command } from "./args.ts";
3
+ import { type Paint, SEPARATOR } from "./format.ts";
4
+
5
+ // One status line, Usage, Commands, Options, Examples, then the agent
6
+ // section (cli.md, Help text), within 80 columns. Section heads are bold
7
+ // and defaults gray, so a reader scans for the flag, not the fine print.
8
+
9
+ // A flag's default goes in gray after the separator, so the eye finds
10
+ // the flag first.
11
+ const flag = (p: Paint, name: string, does: string, preset?: string) =>
12
+ ` ${name.padEnd(21)}${does}${preset === undefined ? "" : p.dim(`${SEPARATOR}${preset}`)}`;
13
+
14
+ // Examples carry their intent as a comment, as the README's do, so a
15
+ // reader picks one by what it's for.
16
+ const example = (p: Paint, intent: string, command: string) =>
17
+ ` ${p.dim(`# ${intent}`)}\n ${command}`;
18
+
19
+ const COMMON = (p: Paint) =>
20
+ ` ${p.dim("and --config, --format, --json, --color, as for every command")}`;
21
+
22
+ const BROWSER_FLAGS = (p: Paint, runs: string) =>
23
+ [
24
+ flag(p, "--browser <name>", "chrome or webkit", "default chrome"),
25
+ flag(p, "--throttle <preset>", "mobile, desktop or none", "default mobile"),
26
+ flag(
27
+ p,
28
+ "--runs <n>",
29
+ "runs to take the median of",
30
+ runs === "per command" ? "default per command" : `default ${runs}`,
31
+ ),
32
+ ].join("\n");
33
+
34
+ function top(p: Paint): string {
35
+ return `${p.bold("trivium")} ${version}${p.dim(`${SEPARATOR}a page's load, interactions and UX, in a real browser`)}
36
+
37
+ ${p.bold("Usage")}
38
+ trivium <command> [target] [options]
39
+
40
+ ${p.bold("Commands")}
41
+ load [url] cold-load vitals and bytes, median of --runs
42
+ compare <a> <b> two builds or URLs, alternating, with a noise column
43
+ interactions [url] latency, loader time and layout shift per config step
44
+ bundle [dir] raw, gzip and brotli per file, initial against lazy
45
+ cache [url] Cache-Control of the page and every asset it loads
46
+
47
+ ${p.bold("Options")}
48
+ ${BROWSER_FLAGS(p, "per command")}
49
+ ${flag(p, "--config <path>", "the config file", "trivium.config.ts, found walking up")}
50
+ ${flag(p, "--format <name>", "human, agent or json", "agent for a coding agent")}
51
+ ${flag(p, "--json", "same as --format json")}
52
+ ${flag(p, "--color, --no-color", "force color on or off", "on in a terminal")}
53
+ ${flag(p, "-h, --help", "help; <command> --help for a command's")}
54
+ ${flag(p, "-v, --version", "the version")}
55
+
56
+ ${p.bold("Examples")}
57
+ ${example(p, "cold-load vitals, median of 5", "trivium load https://example.com")}
58
+ ${example(p, "two builds, alternating, with a noise column", "trivium compare dist-main dist --repeat")}
59
+ ${example(p, "fail CI when hashed assets aren't immutable", "trivium cache https://example.com")}
60
+
61
+ ${p.bold("For agents")}
62
+ Run with --json; read ok and summary. Exit 0 done, 1 problems found,
63
+ 2 called wrong. Each command's fields and every error code are in
64
+ docs/agents.md.`;
65
+ }
66
+
67
+ const COMMAND_HELP: Record<Command, (p: Paint) => string> = {
68
+ load: (
69
+ p,
70
+ ) => `${p.bold("trivium load")}${p.dim(`${SEPARATOR}cold-load vitals and bytes, median of --runs`)}
71
+
72
+ ${p.bold("Usage")}
73
+ trivium load [url] [options]
74
+
75
+ TTFB, FCP, LCP, CLS, TBT, the longest task, the config's readyMark and
76
+ element, bytes by type, and how each request was answered. A fresh view
77
+ per run, with the HTTP cache off. The URL defaults to the config's url.
78
+
79
+ ${p.bold("Options")}
80
+ ${flag(p, "--repeat", "a second visit, with a warm cache")}
81
+ ${BROWSER_FLAGS(p, "5")}
82
+ ${COMMON(p)}
83
+
84
+ ${p.bold("Examples")}
85
+ ${example(p, "a deployed page on a phone profile", "trivium load https://example.com")}
86
+ ${example(p, "a returning visitor on desktop", "trivium load --repeat --throttle desktop")}`,
87
+
88
+ compare: (
89
+ p,
90
+ ) => `${p.bold("trivium compare")}${p.dim(`${SEPARATOR}two builds or URLs, with a noise column`)}
91
+
92
+ ${p.bold("Usage")}
93
+ trivium compare <a> <b> [options]
94
+
95
+ Each side is a build directory, served on a fresh port, or a URL.
96
+ Loads alternate, A B then B A, after one unrecorded load each.
97
+ ~ marks a difference within twice the run-to-run noise, under 2%,
98
+ or too small to show.
99
+
100
+ ${p.bold("Options")}
101
+ ${flag(p, "--repeat", "compare second visits, with a warm cache")}
102
+ ${flag(p, "--immutable", "serve B's hashed assets immutable for a year")}
103
+ ${BROWSER_FLAGS(p, "7")}
104
+ ${COMMON(p)}
105
+
106
+ ${p.bold("Examples")}
107
+ ${example(p, "a branch's build against main's", "trivium compare dist-main dist")}
108
+ ${example(p, "what immutable asset headers save on a repeat visit", "trivium compare dist dist --repeat --immutable")}`,
109
+
110
+ interactions: (
111
+ p,
112
+ ) => `${p.bold("trivium interactions")}${p.dim(`${SEPARATOR}latency, loader time and shift per step`)}
113
+
114
+ ${p.bold("Usage")}
115
+ trivium interactions [url] [options]
116
+
117
+ Runs the config's steps in order with native input, and reports each
118
+ one's Event Timing latency, the basis of INP; how long a config loader
119
+ stayed visible; and the layout it shifted, input-driven shifts too.
120
+
121
+ ${p.bold("Options")}
122
+ ${flag(p, "--early", "start at the ready mark, not once the page settles")}
123
+ ${BROWSER_FLAGS(p, "3")}
124
+ ${COMMON(p)}
125
+
126
+ ${p.bold("Examples")}
127
+ ${example(p, "the config's steps on a phone profile", "trivium interactions https://example.com")}
128
+ ${example(p, "clicking before idle-time work is done", "trivium interactions --early --runs 5")}`,
129
+
130
+ bundle: (
131
+ p,
132
+ ) => `${p.bold("trivium bundle")}${p.dim(`${SEPARATOR}raw, gzip and brotli per file`)}
133
+
134
+ ${p.bold("Usage")}
135
+ trivium bundle [dir] [options]
136
+
137
+ Every file in the build, by default dist, as initial (index.html and
138
+ what it links) or lazy, and what index.html carries inline. The 20
139
+ largest are listed. No browser.
140
+
141
+ ${p.bold("Options")}
142
+ ${flag(p, "--base <dir>", "a build to diff against; hashes are ignored")}
143
+ ${flag(p, "--all", "list every file, not only the 20 largest")}
144
+ ${COMMON(p)}
145
+
146
+ ${p.bold("Examples")}
147
+ ${example(p, "what the first load costs", "trivium bundle dist")}
148
+ ${example(p, "a branch's build against main's, for a review", "trivium bundle dist --base dist-main --json")}`,
149
+
150
+ cache: (
151
+ p,
152
+ ) => `${p.bold("trivium cache")}${p.dim(`${SEPARATOR}Cache-Control of a page and every asset it loads`)}
153
+
154
+ ${p.bold("Usage")}
155
+ trivium cache [url] [options]
156
+
157
+ Crawls the page and the same-origin assets it references, then those
158
+ files' references. A hashed asset fails without a year-long max-age,
159
+ and warns without immutable; the HTML fails if it's cached an hour or
160
+ more. Exits 1 on a failure. No browser.
161
+
162
+ ${p.bold("Options")}
163
+ ${COMMON(p)}
164
+
165
+ ${p.bold("Examples")}
166
+ ${example(p, "check a deploy", "trivium cache https://example.com")}
167
+ ${example(p, "gate CI on it", "trivium cache https://example.com --json")}`,
168
+ };
169
+
170
+ export function helpText(command: Command | undefined, paint: Paint): string {
171
+ return command === undefined ? top(paint) : COMMAND_HELP[command](paint);
172
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export type { Config, Step } from "./config.ts";
2
+ export { defineConfig } from "./config.ts";