trivium 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +152 -2
- package/docs/agents.md +71 -0
- package/docs/config.md +81 -0
- package/docs/glossary.md +105 -0
- package/docs/measuring.md +46 -0
- package/docs/name.md +62 -0
- package/index.d.ts +44 -0
- package/package.json +37 -4
- package/src/agent.ts +45 -0
- package/src/args.ts +297 -0
- package/src/bundle.ts +319 -0
- package/src/cache.ts +297 -0
- package/src/cli.ts +4 -0
- package/src/compare.ts +378 -0
- package/src/config.ts +49 -0
- package/src/env.ts +16 -0
- package/src/errors.ts +46 -0
- package/src/format.ts +314 -0
- package/src/help.ts +172 -0
- package/src/index.ts +2 -0
- package/src/interactions.ts +398 -0
- package/src/load-config.ts +208 -0
- package/src/load.ts +300 -0
- package/src/main.ts +241 -0
- package/src/page.ts +263 -0
- package/src/progress.ts +48 -0
- package/src/serve.ts +58 -0
- package/src/stats.ts +37 -0
- package/src/suggest.ts +44 -0
- package/src/vitals.ts +304 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Eric Liu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,153 @@
|
|
|
1
|
-
#
|
|
1
|
+
# trivium
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Measure a page's load, interactions and UX in a real browser, from Bun.
|
|
4
|
+
|
|
5
|
+
trivium is a command line for people and coding agents.
|
|
6
|
+
It drives Chrome, or WebKit on macOS, through `Bun.WebView`,
|
|
7
|
+
under Lighthouse's throttling, and reports medians with their run-to-run
|
|
8
|
+
noise, so two runs compare.
|
|
9
|
+
It needs no npm dependencies and no browser download.
|
|
10
|
+
When the page never gets ready, or the browser can't measure what you
|
|
11
|
+
asked for, it says which, and exits 2.
|
|
12
|
+
|
|
13
|
+
<picture>
|
|
14
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/metonym/trivium/master/.github/assets/load-dark.png">
|
|
15
|
+
<img alt="trivium load on TodoMVC's React example at mobile throttling: LCP 1.91 s, CLS 0.030 and TBT 76 ms, all good, with each median's noise, bytes by type and how each request was answered, ending Vitals pass" src="https://raw.githubusercontent.com/metonym/trivium/master/.github/assets/load-light.png">
|
|
16
|
+
</picture>
|
|
17
|
+
|
|
18
|
+
That's TodoMVC's React example, live,
|
|
19
|
+
loaded five times on a phone profile.
|
|
20
|
+
While a run is in flight, one line says where it is:
|
|
21
|
+
|
|
22
|
+
<picture>
|
|
23
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/metonym/trivium/master/.github/assets/progress-dark.png">
|
|
24
|
+
<img alt="trivium's progress line: a bar at load 4 of 5, LCP so far 1.92 s, 15 s in" src="https://raw.githubusercontent.com/metonym/trivium/master/.github/assets/progress-light.png">
|
|
25
|
+
</picture>
|
|
26
|
+
|
|
27
|
+
The same app's seven interactions, scripted in a config
|
|
28
|
+
and run with native input:
|
|
29
|
+
|
|
30
|
+
<picture>
|
|
31
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/metonym/trivium/master/.github/assets/interactions-dark.png">
|
|
32
|
+
<img alt="trivium interactions on TodoMVC: INP 88 ms, good, over seven steps, from focusing the input to clearing completed todos, each with its latency, noise and layout shift" src="https://raw.githubusercontent.com/metonym/trivium/master/.github/assets/interactions-light.png">
|
|
33
|
+
</picture>
|
|
34
|
+
|
|
35
|
+
## Quick start
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
bunx trivium load https://example.com
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Every setting is optional.
|
|
42
|
+
To script interactions, install trivium so a config can import
|
|
43
|
+
its types:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
bun add -d trivium
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
// trivium.config.ts
|
|
51
|
+
import { defineConfig } from "trivium";
|
|
52
|
+
|
|
53
|
+
export default defineConfig({
|
|
54
|
+
url: "http://localhost:4790/",
|
|
55
|
+
readyMark: "hydrated",
|
|
56
|
+
loaders: [".spinner"],
|
|
57
|
+
steps: [{ label: "open panel", run: (view) => view.click("#open") }],
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Then `bunx trivium interactions`.
|
|
62
|
+
It exits 0 once it has measured, 1 when `cache` finds a failing header,
|
|
63
|
+
and 2 when it's called wrong or can't measure.
|
|
64
|
+
|
|
65
|
+
## For agents
|
|
66
|
+
|
|
67
|
+
Run with `--json`, read `ok` and `summary`, change the code,
|
|
68
|
+
and run again.
|
|
69
|
+
Without `--json`, a coding agent gets one labeled line per row,
|
|
70
|
+
counts first:
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
1 of 4 files failed · 0 warned
|
|
74
|
+
https://example.com/
|
|
75
|
+
fail /assets/panel-hn4vc8xs.js: hashed but max-age=600: every visit asks again (cache-control: public, max-age=600)
|
|
76
|
+
ok: 3 more; --format human lists them
|
|
77
|
+
For hashed assets, send `Cache-Control: public, max-age=31536000, immutable`.
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Each command's JSON fields, the exit codes and the error codes are
|
|
81
|
+
in
|
|
82
|
+
[agents.md](https://github.com/metonym/trivium/blob/master/docs/agents.md).
|
|
83
|
+
|
|
84
|
+
## Common tasks
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
# cold-load vitals, median of 5
|
|
88
|
+
bunx trivium load https://example.com
|
|
89
|
+
# a second visit with a warm cache
|
|
90
|
+
bunx trivium load --repeat
|
|
91
|
+
# two builds against each other, alternating, with a noise column
|
|
92
|
+
bunx trivium compare dist-main dist
|
|
93
|
+
# what immutable asset headers would save on a repeat visit
|
|
94
|
+
bunx trivium compare dist dist --repeat --immutable
|
|
95
|
+
# latency, loader time and layout shift for each config step
|
|
96
|
+
bunx trivium interactions
|
|
97
|
+
# raw, gzip and brotli per file, against the last build
|
|
98
|
+
bunx trivium bundle dist --base dist-main
|
|
99
|
+
# fail CI when hashed assets aren't cached a year and immutable
|
|
100
|
+
bunx trivium cache https://example.com
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Commands
|
|
104
|
+
|
|
105
|
+
| Command | Measures | Browser |
|
|
106
|
+
| :--- | :--- | :--- |
|
|
107
|
+
| `load [url]` | TTFB, FCP, LCP, CLS, TBT, the longest task, the ready mark, the config's element, bytes by type, and how each request was answered | Chrome, WebKit |
|
|
108
|
+
| `compare <a> <b>` | the same for two build directories or URLs, alternating A B then B A; `~` marks a difference within twice the noise | Chrome, WebKit |
|
|
109
|
+
| `interactions [url]` | per config step: Event Timing latency, loader time, layout shift, and the element that moved most; INP | Chrome, WebKit |
|
|
110
|
+
| `bundle [dir]` | raw, gzip and brotli per file, initial against lazy, what `index.html` carries inline; `--base` adds a delta | none |
|
|
111
|
+
| `cache [url]` | `Cache-Control` of the page and every same-origin asset it can load | none |
|
|
112
|
+
|
|
113
|
+
On a Vite React starter, before and after swapping moment for
|
|
114
|
+
`Intl.DateTimeFormat`, `bundle` shows what the swap saved:
|
|
115
|
+
|
|
116
|
+
<picture>
|
|
117
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/metonym/trivium/master/.github/assets/bundle-dark.png">
|
|
118
|
+
<img alt="trivium bundle dist --base dist-main: 71.9 kB gzip on first load, the entry chunk 19.4 kB smaller" src="https://raw.githubusercontent.com/metonym/trivium/master/.github/assets/bundle-light.png">
|
|
119
|
+
</picture>
|
|
120
|
+
|
|
121
|
+
`compare` loads both builds in turns and marks what's within the noise:
|
|
122
|
+
|
|
123
|
+
<picture>
|
|
124
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/metonym/trivium/master/.github/assets/compare-dark.png">
|
|
125
|
+
<img alt="trivium compare dist-main dist: B is better on 2 of 8 metrics and worse on none, the rest marked as within the noise" src="https://raw.githubusercontent.com/metonym/trivium/master/.github/assets/compare-light.png">
|
|
126
|
+
</picture>
|
|
127
|
+
|
|
128
|
+
`cache` crawls the page and every asset it can load,
|
|
129
|
+
and passes when each hashed file is cached for good
|
|
130
|
+
and the HTML revalidates:
|
|
131
|
+
|
|
132
|
+
<picture>
|
|
133
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/metonym/trivium/master/.github/assets/cache-dark.png">
|
|
134
|
+
<img alt="trivium cache on the starter served with production headers: 6 of 6 files pass, every hashed asset immutable for a year" src="https://raw.githubusercontent.com/metonym/trivium/master/.github/assets/cache-light.png">
|
|
135
|
+
</picture>
|
|
136
|
+
|
|
137
|
+
WebKit has no DevTools protocol, so it can't throttle,
|
|
138
|
+
and it reports no layout shifts or long tasks: on WebKit, CLS, TBT,
|
|
139
|
+
the longest task and layout shift read `—` with the reason,
|
|
140
|
+
and `--throttle mobile` exits 2.
|
|
141
|
+
|
|
142
|
+
## Docs
|
|
143
|
+
|
|
144
|
+
- [agents.md](https://github.com/metonym/trivium/blob/master/docs/agents.md):
|
|
145
|
+
the loop, each command's JSON, exit and error codes
|
|
146
|
+
- [glossary.md](https://github.com/metonym/trivium/blob/master/docs/glossary.md):
|
|
147
|
+
each metric and term, and how trivium measures it
|
|
148
|
+
- [measuring.md](https://github.com/metonym/trivium/blob/master/docs/measuring.md):
|
|
149
|
+
how a run is made fair: fresh views, settling, alternation and noise
|
|
150
|
+
- [name.md](https://github.com/metonym/trivium/blob/master/docs/name.md):
|
|
151
|
+
three roads, one measure: what the name means for the tool
|
|
152
|
+
- [config.md](https://github.com/metonym/trivium/blob/master/docs/config.md):
|
|
153
|
+
every key, flag and environment variable
|
package/docs/agents.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# For agents
|
|
2
|
+
|
|
3
|
+
How a coding agent drives trivium: the loop,
|
|
4
|
+
the JSON each command prints, the exit codes and the errors.
|
|
5
|
+
|
|
6
|
+
## The loop
|
|
7
|
+
|
|
8
|
+
1. Run a command with `--json`; read `ok` and `summary`.
|
|
9
|
+
2. Read the per-item fields below to find what to change.
|
|
10
|
+
3. Change the code, rebuild, and run the same command again.
|
|
11
|
+
For a before and after, `compare` the two builds instead of reading
|
|
12
|
+
two `load` runs side by side: it alternates them and marks noise.
|
|
13
|
+
|
|
14
|
+
Without `--json`, a coding agent gets the `agent` format,
|
|
15
|
+
one labeled line per row, and stderr says so.
|
|
16
|
+
Neither it nor JSON is ever colored, `--color` included.
|
|
17
|
+
`--format human` or `TRIVIUM_FORMAT` sets another.
|
|
18
|
+
|
|
19
|
+
## Exit codes
|
|
20
|
+
|
|
21
|
+
| Code | Means |
|
|
22
|
+
| :--- | :--- |
|
|
23
|
+
| 0 | measured; for `cache`, nothing failed |
|
|
24
|
+
| 1 | `cache` found a failing header |
|
|
25
|
+
| 2 | called wrong, a bad config, or the browser couldn't measure |
|
|
26
|
+
|
|
27
|
+
## JSON
|
|
28
|
+
|
|
29
|
+
Every output is one object with `schemaVersion`, `ok` and `command`,
|
|
30
|
+
and `elapsedMs`, how long the command took.
|
|
31
|
+
A field is added without a bump; `schemaVersion` changes only
|
|
32
|
+
when one is dropped or retyped.
|
|
33
|
+
Times are milliseconds and sizes bytes,
|
|
34
|
+
as the names say (`inpMs`, `gzipBytes`);
|
|
35
|
+
a value the browser can't measure is `null` with a `reason`, never 0.
|
|
36
|
+
|
|
37
|
+
| Command | Fields |
|
|
38
|
+
| :--- | :--- |
|
|
39
|
+
| `load` | `url`, `browser`, `throttle`, `visit` (`cold`, `repeat`), `runs`, `config`; `metrics[]`: `key`, `label`, `unit` (`ms`, `score`), `median`, `noise`, `samples`, `rating` (`good`, `needs-improvement`, `poor`, where a threshold is published), `reason`; `bytesByType`, `transferredBytes`; `requests`: `network`, `revalidated`, `cache` |
|
|
40
|
+
| `compare` | `a` and `b`: `target`, `url`; `summary`: `compared`, `changed`; `metrics[]`: `key`, `a`, `b`, `delta`, `deltaPercent`, `noise`, `withinNoise`, `reason`; `transferredBytes` and `requests`, each by side |
|
|
41
|
+
| `interactions` | `url`, `inpMs`, `inpNoiseMs`, `inpRating`, `loaderBeforeFirstMs`; `steps[]`: `label`, `latencyMs`, `latencyNoiseMs`, `loaderMs`, `shift`, `movedMost` (`element`, `shift`); `unavailable` names what the browser lacks. A `latencyMs` of 0 is an interaction under 16 ms, which Event Timing doesn't report |
|
|
42
|
+
| `bundle` | `dir`, `base`; `summary`: `files`, `initialFiles`, `initialGzipBytes`, `lazyGzipBytes`; `assets[]`, every file, `--all` or not: `path`, `load` (`initial`, `lazy`), `rawBytes`, `gzipBytes`, `brotliBytes`, `baseGzipBytes`, `change` (`new`, `removed`, `changed`, `same`); `totals`, `baseTotals`, `inline[]` |
|
|
43
|
+
| `cache` | `url`; `summary`: `files`, `failed`, `warned`; `files[]`: `path`, `verdict` (`ok`, `warn`, `fail`), `status`, `cacheControl`, `encoding`, `edge`, `problems[]` |
|
|
44
|
+
|
|
45
|
+
`compare`'s `withinNoise: false` is a change worth reading;
|
|
46
|
+
`true` is noise, however large `delta` looks.
|
|
47
|
+
|
|
48
|
+
## Errors
|
|
49
|
+
|
|
50
|
+
Under `--json`, an error is JSON too:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{ "schemaVersion": 1, "ok": false, "error": { "kind": "usage", "code": "TV_USAGE", "message": "trivium load: unknown option --jsno (did you mean --json?); see trivium load --help" } }
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Branch on `code`; the message is for a person and can change.
|
|
57
|
+
|
|
58
|
+
| Code | Kind | Cause | Fix |
|
|
59
|
+
| :--- | :--- | :--- | :--- |
|
|
60
|
+
| `TV_USAGE` | `usage` | an unknown option or command, a missing argument, a bad value, or a flag another command takes | the message names it, with a suggestion |
|
|
61
|
+
| `TV_CONFIG` | `config` | the config didn't load, has an unknown key or bad value, or a step failed | the message names the file, the key or the step |
|
|
62
|
+
| `TV_UNSUPPORTED` | `browser` | the browser didn't start, or can't do what was asked, such as throttling on WebKit | pass `--browser chrome`, or install Chrome |
|
|
63
|
+
| `TV_TIMEOUT` | `browser` | the page never became ready | check the URL and `readyMark` |
|
|
64
|
+
| `TV_INPUT` | `input` | a build directory without `index.html`, or a URL that didn't answer | pass the build's output directory, or a reachable URL |
|
|
65
|
+
| `TV_INTERNAL` | `other` | a bug in trivium | report it with the command and output |
|
|
66
|
+
|
|
67
|
+
## Related
|
|
68
|
+
|
|
69
|
+
- [glossary.md](glossary.md): what each metric means
|
|
70
|
+
and how it's measured
|
|
71
|
+
- [config.md](config.md): every key, flag and environment variable
|
package/docs/config.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Config
|
|
2
|
+
|
|
3
|
+
`trivium.config.ts` holds what's specific to one page;
|
|
4
|
+
every key is optional, and a flag beats the config.
|
|
5
|
+
trivium finds the file by walking up from the working directory,
|
|
6
|
+
stopping at the first `package.json`; `--config <path>` names another.
|
|
7
|
+
A `trivium.config.json` works too, for keys that are plain data.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { defineConfig } from "trivium";
|
|
11
|
+
|
|
12
|
+
export default defineConfig({
|
|
13
|
+
url: "https://example.com/",
|
|
14
|
+
readyMark: "hydrated",
|
|
15
|
+
assets: { path: "/assets/", hash: /-[\w-]{8}(?=\.\w+$)/ },
|
|
16
|
+
element: { label: "results shown", selector: ".results li" },
|
|
17
|
+
loaders: [".spinner", "[aria-busy=true]"],
|
|
18
|
+
steps: [
|
|
19
|
+
{ label: "open menu", run: (view) => view.click("#menu") },
|
|
20
|
+
{ label: "type a letter", run: (view) => view.press("a") },
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
An unknown key is an error that names the closest known one,
|
|
26
|
+
and every problem in the file is reported at once.
|
|
27
|
+
|
|
28
|
+
## Keys
|
|
29
|
+
|
|
30
|
+
| Key | Type | Default | Used by |
|
|
31
|
+
| :--- | :--- | :--- | :--- |
|
|
32
|
+
| `url` | string | none: pass one | `load`, `interactions`, `cache` |
|
|
33
|
+
| `readyMark` | string | `load` | `load`, `compare`, `interactions` |
|
|
34
|
+
| `assets.path` | string | `/assets/` | `compare --immutable`, `cache` |
|
|
35
|
+
| `assets.hash` | RegExp | `/-[\w-]{8}(?=\.\w+$)/`, Vite's | `bundle`, `cache` |
|
|
36
|
+
| `element` | `{ label, selector }` | none | `load`, `compare` (Chrome) |
|
|
37
|
+
| `loaders` | CSS selectors | none | `interactions` |
|
|
38
|
+
| `steps` | `{ label, run(view) }[]` | none | `interactions` |
|
|
39
|
+
|
|
40
|
+
`readyMark` is the `performance.mark()` the page sets once it's
|
|
41
|
+
interactive, such as right after `hydrate()`;
|
|
42
|
+
without one, trivium waits for `load`.
|
|
43
|
+
A step's `run` gets the `Bun.WebView`, whose `click`,
|
|
44
|
+
`press` and `type` send native input,
|
|
45
|
+
so Event Timing records it as a person's.
|
|
46
|
+
|
|
47
|
+
## Flags
|
|
48
|
+
|
|
49
|
+
| Flag | Values | Default | Commands |
|
|
50
|
+
| :--- | :--- | :--- | :--- |
|
|
51
|
+
| `--browser` | `chrome`, `webkit` | `chrome` | `load`, `compare`, `interactions` |
|
|
52
|
+
| `--throttle` | `mobile`, `desktop`, `none` | `mobile` on Chrome, `none` on WebKit | `load`, `compare`, `interactions` |
|
|
53
|
+
| `--runs` | a whole number | 5, 7 for `compare`, 3 for `interactions` | `load`, `compare`, `interactions` |
|
|
54
|
+
| `--repeat` | | off | `load`, `compare` |
|
|
55
|
+
| `--immutable` | | off | `compare` |
|
|
56
|
+
| `--early` | | off | `interactions` |
|
|
57
|
+
| `--base` | a build directory | none | `bundle` |
|
|
58
|
+
| `--all` | | off: the 20 largest | `bundle` |
|
|
59
|
+
| `--config` | a path | found walking up | all |
|
|
60
|
+
| `--format` | `human`, `agent`, `json` | `human`, or `agent` for a coding agent | all |
|
|
61
|
+
| `--json` | | off | all |
|
|
62
|
+
| `--color`, `--no-color` | | on in a terminal, unless `NO_COLOR` is set; never in `agent` or `json` | all |
|
|
63
|
+
|
|
64
|
+
`mobile` is Lighthouse's mobile preset as its devtools throttling
|
|
65
|
+
applies it: 562.5 ms of request latency, 1,474.56 kbit/s down,
|
|
66
|
+
675 kbit/s up and a 4x slower CPU.
|
|
67
|
+
`desktop` is Lighthouse's Dense 4G through the same adjustment:
|
|
68
|
+
150 ms and 9,216 kbit/s each way, at full CPU speed.
|
|
69
|
+
A kbit is 1,024 bits, as Lighthouse counts it.
|
|
70
|
+
|
|
71
|
+
## Environment
|
|
72
|
+
|
|
73
|
+
| Variable | Does |
|
|
74
|
+
| :--- | :--- |
|
|
75
|
+
| `TRIVIUM_FORMAT` | the format when no flag names one |
|
|
76
|
+
| `NO_COLOR` | turns color off when set to anything but empty; `--color` still turns it on |
|
|
77
|
+
| `BUN_CHROME_PATH` | the Chrome binary, when Bun doesn't find it |
|
|
78
|
+
|
|
79
|
+
## Related
|
|
80
|
+
|
|
81
|
+
- [measuring.md](measuring.md): what each command waits for
|
package/docs/glossary.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Glossary
|
|
2
|
+
|
|
3
|
+
The terms trivium's output uses, what each means,
|
|
4
|
+
and how trivium measures it.
|
|
5
|
+
|
|
6
|
+
- [Web Vitals](#web-vitals)
|
|
7
|
+
- [Interactions](#interactions)
|
|
8
|
+
- [A fair run](#a-fair-run)
|
|
9
|
+
- [Bytes](#bytes)
|
|
10
|
+
- [Caching](#caching)
|
|
11
|
+
- [Browsers](#browsers)
|
|
12
|
+
|
|
13
|
+
## Web Vitals
|
|
14
|
+
|
|
15
|
+
| Term | Meaning | How trivium measures it |
|
|
16
|
+
| :--- | :--- | :--- |
|
|
17
|
+
| **Rating** | Whether a value is good, needs improvement or poor, by a published threshold. | web.dev's thresholds for TTFB (800 and 1,800 ms), FCP (1,800 and 3,000 ms), LCP (2,500 and 4,000 ms), CLS (0.1 and 0.25) and INP (200 and 500 ms), and Lighthouse's mobile scoring for TBT (200 and 600 ms). A metric without one, such as Load, has no rating. |
|
|
18
|
+
| **Core Web Vitals** | Google's three user-experience metrics: LCP for loading, INP for responsiveness, CLS for visual stability. "Good" is LCP ≤ 2.5 s, INP ≤ 200 ms and CLS ≤ 0.1, at the 75th percentile of real visits. | As lab measurements, the median of `--runs`. A lab median isn't a field p75: compare a change against the last run, not against the thresholds alone. |
|
|
19
|
+
| **LCP: Largest Contentful Paint** | When the largest image or text block in the viewport painted, from the start of navigation. | The last `largest-contentful-paint` entry, read once the page settles. The observer is in place before the page's own scripts, and nothing is clicked during a load, which would stop LCP early. |
|
|
20
|
+
| **FCP: First Contentful Paint** | When the browser first painted any text, image or SVG. | The `first-contentful-paint` paint entry. A load waits for it before it starts waiting for the page to settle. |
|
|
21
|
+
| **CLS: Cumulative Layout Shift** | A unitless score for content that moved without input: the worst burst of shifts under 1 s apart, at most 5 s long. | The same session windows over `layout-shift` entries, leaving out shifts within 500 ms of input. It covers the load until the page settles, so it reads lower than a whole visit's CLS. Chrome only. |
|
|
22
|
+
| **TTFB: Time to First Byte** | When the first byte of the page's response arrived, redirects and connection setup included. | The navigation entry's `responseStart`. Under `--throttle mobile` it includes the preset's 562.5 ms of request latency. |
|
|
23
|
+
| **TBT: Total Blocking Time** | A lab metric for startup work that would delay input: each main-thread task's time over 50 ms, summed. An 80 ms task adds 30 ms. | Over `longtask` entries from FCP until the page settles; Lighthouse stops at Time to Interactive, so the two can differ. Chrome only. |
|
|
24
|
+
| **Longest task** | The single longest main-thread task during the load. | The longest `longtask` entry, before FCP included. It names the one task to split when TBT is high. Chrome only. |
|
|
25
|
+
| **Ready** | When the page is interactive, which only the page knows: for an app, right after hydration. | The config's `readyMark`, a `performance.mark()` the page sets, by its `startTime`; without one, the `load` event's end. The row is named after the mark. |
|
|
26
|
+
| **Element** | When the config's `element` first matched its selector, such as the first search result. | A `MutationObserver` from before the page's scripts, stopping at the first match. It times when the element entered the DOM, not when it painted. Chrome only. |
|
|
27
|
+
| **Load** | When the `load` event finished: every image, script and stylesheet the HTML named had arrived. | The navigation entry's `loadEventEnd`. |
|
|
28
|
+
|
|
29
|
+
[Web Vitals](https://web.dev/articles/vitals) ·
|
|
30
|
+
[LCP](https://web.dev/articles/lcp) ·
|
|
31
|
+
[CLS](https://web.dev/articles/cls) ·
|
|
32
|
+
[TBT](https://web.dev/articles/tbt) ·
|
|
33
|
+
[TTFB](https://web.dev/articles/ttfb)
|
|
34
|
+
|
|
35
|
+
## Interactions
|
|
36
|
+
|
|
37
|
+
| Term | Meaning | How trivium measures it |
|
|
38
|
+
| :--- | :--- | :--- |
|
|
39
|
+
| **INP: Interaction to Next Paint** | A visit's responsiveness: its slowest click, tap or key press, from input to the next frame, input delay and event handlers included. Good is ≤ 200 ms; poor is over 500 ms. | The worst step's latency over the config's `steps`, as a page with under 50 interactions counts it. |
|
|
40
|
+
| **Event Timing** | The browser's own timing of each input event, the source of INP. It groups the events one input fires under an `interactionId`. | One `event` observer with a 16 ms threshold. A step's latency is the longest entry sharing an `interactionId`. The browser rounds durations to 8 ms and drops those under 16 ms, so `0 ms` means under 16 ms. |
|
|
41
|
+
| **Native input** | Input the browser treats as a person's (`isTrusted`), so Event Timing records it. Script-dispatched events and filling a field's value directly record nothing. | Steps run through `Bun.WebView`'s `click`, `press` and `type`, which send native input. |
|
|
42
|
+
| **Step** | One scripted interaction in the config, with a label. | Each Event Timing entry and layout shift goes to the step whose input came before it, once every step has run. Read per step, a late entry would count for the next one. |
|
|
43
|
+
| **Loader time** | How long a loading indicator stayed visible after a step. INP stops at the next frame, so a click that shows a spinner while a chunk loads can score well. | A `MutationObserver` on the config's `loaders`, counting the time any of them has a box on screen, within each step's window. |
|
|
44
|
+
| **Layout shift, per step** | How far content moved during a step, and which element moved most. | Every `layout-shift` in the step's window, the ones after input too, which CLS leaves out. The element that moved most is the shift source with the largest box, averaged over runs. Chrome only. |
|
|
45
|
+
|
|
46
|
+
[INP](https://web.dev/articles/inp) ·
|
|
47
|
+
[Event Timing](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEventTiming)
|
|
48
|
+
|
|
49
|
+
## A fair run
|
|
50
|
+
|
|
51
|
+
| Term | Meaning | How trivium measures it |
|
|
52
|
+
| :--- | :--- | :--- |
|
|
53
|
+
| **Lab and field data** | Lab data comes from controlled runs: one machine, a set network and CPU, a known cache. Field data comes from real visits. Lab runs find what changed; field data says how visitors fare. | Lab only. Every report names its browser, throttling, run count and whether the loads were cold or repeat visits. |
|
|
54
|
+
| **Throttling** | Slowing the network and CPU toward a target device. | Lighthouse's presets as it applies them with `--throttling-method=devtools`, so trivium's numbers match that run's: `mobile` is 562.5 ms of request latency, 1,474.56 kbit/s down, 675 kbit/s up and a 4x slower CPU. Lighthouse's default instead simulates a 150 ms round trip and 1,638.4 kbit/s from an unthrottled run, so its numbers differ. `desktop` is Lighthouse's Dense 4G through the same adjustment, 150 ms and 9,216 kbit/s each way at full CPU speed; Lighthouse itself applies no network throttling on desktop. The CPU slowdown divides this machine's speed, so a fast laptop at 4x isn't a phone. Chrome only. |
|
|
55
|
+
| **Cold load** | A first visit: nothing cached. | A new view each run, since a reused one keeps fonts and compiled code. Chrome shares one HTTP cache across views, so trivium also turns it off over CDP; WebKit gives each view its own. |
|
|
56
|
+
| **Repeat visit** | A second visit with a warm cache, as a returning visitor makes. | `--repeat` loads the page once in the view, waits for it to settle, then measures a second load in the same view. |
|
|
57
|
+
| **Settled** | When the page has stopped loading: no requests, and nothing scheduled for idle time. | No request in flight for 500 ms, then an idle callback; if that callback started a request, such as a prefetch, the wait starts again. It never sleeps a fixed time, and gives up after 15 s for a page that polls or streams. |
|
|
58
|
+
| **Median** | The middle value of the runs, which one slow run can't move. | Every metric is the median of `--runs`. |
|
|
59
|
+
| **Noise** | How much a metric moves between identical runs. | The median absolute deviation, shown as `±`. In `compare`, the larger of the two sides'. |
|
|
60
|
+
| **Within the noise (`~`)** | A difference too small to be the change. | `compare` marks one inside twice the noise, or under 2% of A. A same-build comparison reads 9 ms faster without the rule. |
|
|
61
|
+
| **Alternation** | Running A and B in turns, so drift in the machine or network hits both. | One unrecorded load of each side, then A B, B A, A B, …, so neither side always goes first. |
|
|
62
|
+
|
|
63
|
+
[Lab and field data](https://web.dev/articles/lab-and-field-data-differences)
|
|
64
|
+
·
|
|
65
|
+
[Lighthouse throttling](https://github.com/GoogleChrome/lighthouse/blob/main/docs/throttling.md)
|
|
66
|
+
|
|
67
|
+
## Bytes
|
|
68
|
+
|
|
69
|
+
| Term | Meaning | How trivium measures it |
|
|
70
|
+
| :--- | :--- | :--- |
|
|
71
|
+
| **Transferred** | What crossed the network for a load, compressed, headers included. | On Chrome, CDP's `encodedDataLength` per request, grouped by resource type. On WebKit, Resource Timing's `transferSize`, same-origin only, since a cross-origin entry without `Timing-Allow-Origin` reads 0. A kB is 1,000 bytes. |
|
|
72
|
+
| **Requests** | How each request was answered: downloaded, revalidated with a `304`, or from the cache with no request. | On Chrome, from CDP's response events. On WebKit, a same-origin entry with 0 bytes transferred came from the cache. |
|
|
73
|
+
| **Prefetched** | A file fetched at low priority for later, by `<link rel="prefetch">`. | A prefetch Chrome reports as type "Other" with a `.js` URL is counted as `Script (prefetched)`. |
|
|
74
|
+
| **Raw, gzip and brotli** | A file's size as built, and compressed as a server would send it. | `bundle` compresses each file at the highest settings, gzip level 9 and brotli quality 11. A server compressing on the fly uses lower settings and sends more. |
|
|
75
|
+
| **Initial and lazy** | Initial files load with the page; lazy ones load when something asks for them. | `index.html`, plus what it links with `<script src>` or `<link rel>` as `modulepreload`, `stylesheet` or `icon`, is initial. Every other file in the build is lazy, an `<img>` in the HTML included. |
|
|
76
|
+
| **Inline** | Styles and scripts inside `index.html`, which no file row counts. | `bundle` sizes each `<style>` and `<script>` block of 100 bytes or more. |
|
|
77
|
+
|
|
78
|
+
## Caching
|
|
79
|
+
|
|
80
|
+
| Term | Meaning | How trivium measures it |
|
|
81
|
+
| :--- | :--- | :--- |
|
|
82
|
+
| **Content hash** | A digest of a file's bytes in its name, such as `app-dq3rt9wz.js`, so a changed file gets a new URL. | The config's `assets.hash`, by default Vite's 8 characters before the extension. `bundle --base` strips it to match a file across two builds. |
|
|
83
|
+
| **Immutable asset** | A hashed file can be cached for good, as its URL never serves other bytes: `Cache-Control: public, max-age=31536000, immutable`. | `cache` fails a hashed file under a year's `max-age`, and warns on one without `immutable`, which a reload revalidates. |
|
|
84
|
+
| **Revalidation, ETag and `304`** | Asking whether a cached copy is still current: the browser sends the ETag it has, and the server answers `304 Not Modified` without the body. | Counted as revalidated in `load` and `compare`. `compare` serves a build directory with an ETag and `max-age=0`, so every repeat visit revalidates. |
|
|
85
|
+
| **HTML freshness** | The page itself has to revalidate, or a deploy stays hidden behind the cached copy. | `cache` fails HTML marked `immutable` or cached an hour or more. |
|
|
86
|
+
| **Compression** | `Content-Encoding: br` or `gzip` on text. | `cache` asks with `Accept-Encoding: br, gzip`, and warns on text sent without an encoding. |
|
|
87
|
+
| **Edge** | A CDN's copy of a response, which can differ from the origin's. | `cache` shows Cloudflare's `cf-cache-status`. It checks only the page's own origin, since a CDN's files follow that CDN's headers. |
|
|
88
|
+
|
|
89
|
+
[HTTP caching](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Caching)
|
|
90
|
+
|
|
91
|
+
## Browsers
|
|
92
|
+
|
|
93
|
+
| Term | Meaning | How trivium measures it |
|
|
94
|
+
| :--- | :--- | :--- |
|
|
95
|
+
| **`Bun.WebView`** | Bun's browser driver: macOS's WebKit, or an installed Chrome. | Every browser command opens one 1400 × 900 view per run. |
|
|
96
|
+
| **CDP: Chrome DevTools Protocol** | Chrome's instrumentation: network events, throttling, cache control. | trivium's Chrome runs use it for requests, bytes, throttling and the cache switch. WebKit has none. |
|
|
97
|
+
| **Init script** | Code that runs in each new document before the page's own scripts. | On Chrome, the observers go in as one, so nothing early is missed. WebKit can't run one, so they start right after navigation and read the entries the browser buffered; `element` can't be timed there. |
|
|
98
|
+
| **Buffered entries** | Performance entries the browser kept from before an observer started. | Every observer asks for them, which is what lets WebKit runs read paint, LCP and Event Timing at all. |
|
|
99
|
+
|
|
100
|
+
[CDP](https://chromedevtools.github.io/devtools-protocol/)
|
|
101
|
+
|
|
102
|
+
## Related
|
|
103
|
+
|
|
104
|
+
- [measuring.md](measuring.md): the rules a run follows, in prose
|
|
105
|
+
- [config.md](config.md): the keys and flags named here
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Measuring
|
|
2
|
+
|
|
3
|
+
Each rule here keeps a run from reading faster
|
|
4
|
+
or slower than the page is.
|
|
5
|
+
|
|
6
|
+
## A fresh view per run
|
|
7
|
+
|
|
8
|
+
Every run opens a new view, since a reused one keeps fonts
|
|
9
|
+
and compiled code.
|
|
10
|
+
Chrome is one process for every view, and so is its HTTP cache,
|
|
11
|
+
so a cold run also turns the cache off.
|
|
12
|
+
WebKit gives each view its own cache, so a fresh view is cold.
|
|
13
|
+
`--repeat` loads the page once in the view,
|
|
14
|
+
then measures the second visit.
|
|
15
|
+
|
|
16
|
+
## Waiting for the page to settle
|
|
17
|
+
|
|
18
|
+
Nothing waits a fixed time.
|
|
19
|
+
A page is settled when no request has been in flight for 500 ms
|
|
20
|
+
and an idle callback has run; if that callback started a request,
|
|
21
|
+
such as an idle-time prefetch, the wait starts again.
|
|
22
|
+
A page that polls or streams never settles, so the wait ends after 15 s.
|
|
23
|
+
On WebKit, which can't report requests in flight,
|
|
24
|
+
a new Resource Timing entry stands in for a request.
|
|
25
|
+
|
|
26
|
+
## Interactions
|
|
27
|
+
|
|
28
|
+
A step's input is native, so the browser times it as a person's.
|
|
29
|
+
Event Timing entries arrive late, so each is matched to its step by
|
|
30
|
+
when its input happened, once the last step has run.
|
|
31
|
+
Latency is the longest entry sharing an interaction;
|
|
32
|
+
INP, under 50 interactions, is the worst one.
|
|
33
|
+
Layout shift counts every shift, the ones after input too,
|
|
34
|
+
which CLS leaves out.
|
|
35
|
+
|
|
36
|
+
## Comparing
|
|
37
|
+
|
|
38
|
+
`compare` loads each side once unrecorded, then alternates,
|
|
39
|
+
A B then B A, so neither side always goes first.
|
|
40
|
+
A difference within twice the larger side's median absolute deviation,
|
|
41
|
+
or under 2% of A, is marked `~`, as noise.
|
|
42
|
+
|
|
43
|
+
## Related
|
|
44
|
+
|
|
45
|
+
- [glossary.md](glossary.md): each metric, and how it's measured
|
|
46
|
+
- [config.md](config.md): the keys and flags named here
|
package/docs/name.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# The name
|
|
2
|
+
|
|
3
|
+
*Trivium* is Latin for the place where three roads meet: *tri-*, three,
|
|
4
|
+
and *via*, road.
|
|
5
|
+
Its motto, *Tres viae, una mensura*, is "three roads, one measure",
|
|
6
|
+
and both halves describe the tool.
|
|
7
|
+
|
|
8
|
+
## Three roads
|
|
9
|
+
|
|
10
|
+
A page reaches a person by three roads, and trivium measures each:
|
|
11
|
+
|
|
12
|
+
| Road | What it measures | Commands |
|
|
13
|
+
| :--- | :--- | :--- |
|
|
14
|
+
| Loading | how soon the page appears, and what it costs | `load`, `compare`, `bundle` |
|
|
15
|
+
| Interacting | how fast it answers a click or a key | `interactions` |
|
|
16
|
+
| Delivery | whether it comes from the cache or the network | `cache` |
|
|
17
|
+
|
|
18
|
+
## One measure
|
|
19
|
+
|
|
20
|
+
Every road is measured the same way: a fresh view per run,
|
|
21
|
+
the same throttling, and the median of several runs with its run-to-run
|
|
22
|
+
noise beside it.
|
|
23
|
+
So a number from one run compares with a number from the next,
|
|
24
|
+
and `compare` can say when a difference is only noise.
|
|
25
|
+
|
|
26
|
+
## Three arts
|
|
27
|
+
|
|
28
|
+
In the medieval schools, the trivium was the first three of the liberal
|
|
29
|
+
arts: grammar, logic and rhetoric.
|
|
30
|
+
They map onto the three Core Web Vitals:
|
|
31
|
+
|
|
32
|
+
| Art | What it's about | Vital | Why it fits |
|
|
33
|
+
| :--- | :--- | :--- | :--- |
|
|
34
|
+
| Grammar | structure and form | CLS | things stay where the page put them |
|
|
35
|
+
| Logic | reasoning and response | INP, or TBT in a load | how the page thinks when asked something |
|
|
36
|
+
| Rhetoric | the case made to an audience | LCP | the page's main argument arriving |
|
|
37
|
+
|
|
38
|
+
The output keeps the vitals' own names,
|
|
39
|
+
which are what Lighthouse and the field data use;
|
|
40
|
+
the arts are a way to remember what each one means.
|
|
41
|
+
|
|
42
|
+
## Trivial
|
|
43
|
+
|
|
44
|
+
*Trivial* comes from *trivium*: what was talked over
|
|
45
|
+
where the roads met, so the everyday.
|
|
46
|
+
That's the aim for measuring a page: one command, no dependencies,
|
|
47
|
+
and a verdict on the first line.
|
|
48
|
+
|
|
49
|
+
## The inscription
|
|
50
|
+
|
|
51
|
+
The README's screenshots are framed like a Roman milestone.
|
|
52
|
+
TRIVIVM is spelled with a V, as inscriptions spelled it,
|
|
53
|
+
since classical Latin had no separate U.
|
|
54
|
+
TRES VIAE · VNA MENSVRA is the motto, and MMXXVI, 2026,
|
|
55
|
+
the year of the first release.
|
|
56
|
+
trivium has a sibling, bivium, where two roads meet:
|
|
57
|
+
it picks which tests a change needs to run.
|
|
58
|
+
|
|
59
|
+
## Related
|
|
60
|
+
|
|
61
|
+
- [glossary.md](glossary.md): each metric, and how trivium measures it
|
|
62
|
+
- [measuring.md](measuring.md): what makes one measure fair
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** What's specific to one page, from `trivium.config.ts`. */
|
|
2
|
+
export interface Config {
|
|
3
|
+
/** The page to measure when the command names none. */
|
|
4
|
+
url?: string;
|
|
5
|
+
/**
|
|
6
|
+
* The `performance.mark()` the page sets once it's interactive, such as
|
|
7
|
+
* right after `hydrate()`. Without one, trivium waits for `load`.
|
|
8
|
+
*/
|
|
9
|
+
readyMark?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Where the build puts content-hashed files, and how their names carry
|
|
12
|
+
* the hash.
|
|
13
|
+
*/
|
|
14
|
+
assets?: {
|
|
15
|
+
/** @default "/assets/" */
|
|
16
|
+
path?: string;
|
|
17
|
+
/** @default /-[\w-]{8}(?=\.\w+$)/ */
|
|
18
|
+
hash?: RegExp;
|
|
19
|
+
};
|
|
20
|
+
/** The interactions `trivium interactions` does, in order. */
|
|
21
|
+
steps?: readonly Step[];
|
|
22
|
+
/** An element whose first appearance `load` and `compare` time. */
|
|
23
|
+
element?: {
|
|
24
|
+
label: string;
|
|
25
|
+
selector: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Selectors for loading indicators; `interactions` times how long any
|
|
29
|
+
* is visible.
|
|
30
|
+
*/
|
|
31
|
+
loaders?: readonly string[];
|
|
32
|
+
}
|
|
33
|
+
/** One scripted interaction for `trivium interactions`. */
|
|
34
|
+
export interface Step {
|
|
35
|
+
/** Names the step in reports. */
|
|
36
|
+
label: string;
|
|
37
|
+
/** Does the interaction, through the view's native input. */
|
|
38
|
+
run: (view: Bun.WebView) => Promise<unknown>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns `config` as given, typed, for `export default`
|
|
42
|
+
* in `trivium.config.ts`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function defineConfig(config: Config): Config;
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trivium",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Measure a page's load, interactions and UX in a real browser, from Bun.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Eric Liu (https://github.com/metonym)",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/metonym/trivium.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/metonym/trivium",
|
|
12
|
+
"bugs": "https://github.com/metonym/trivium/issues",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"performance",
|
|
15
|
+
"web-vitals",
|
|
16
|
+
"lcp",
|
|
17
|
+
"cls",
|
|
18
|
+
"inp",
|
|
19
|
+
"bundle-size",
|
|
20
|
+
"cache-control",
|
|
21
|
+
"webview",
|
|
22
|
+
"bun",
|
|
23
|
+
"zero-dependency"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./index.d.ts",
|
|
29
|
+
"default": "./src/index.ts"
|
|
30
|
+
},
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
"bin": {
|
|
34
|
+
"trivium": "src/cli.ts"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"bun": ">=1.4.6"
|
|
38
|
+
}
|
|
39
|
+
}
|