A diagnostic is one finding your command reports, such as a lint error or a config warning. You add diagnostics while the command runs, and readerly prints them once, at the end, in the shape the reader needs.
The record
Section titled "The record"Every diagnostic is a DiagnosticRecord from src/types.ts. It follows the nostics shape and adds a location.
| Field | Type | What it holds |
|---|---|---|
severity | "error" | "warn" | "info" | Required. Errors fail the run. |
code | string | A stable rule or error code, such as ACME001. |
message | string | Required. One sentence about what is wrong. |
why | string | The reason it matters. |
fix | string | What to change. |
docs | string | A URL that explains the code. |
file | string | Path of the file the finding is in. |
line, column | number | Where it starts. |
endLine, endColumn | number | Where it ends. Only GitHub annotations use them. |
sources | string[] | Source locations, as nostics reports them. |
data | unknown | Anything else. json and jsonl carry it, text and agent don't print it. |
Adding diagnostics
Section titled "Adding diagnostics"out.error, out.warn and out.info take a message string or a record without severity. out.diagnostic takes a full record, which helps when the severity comes from your own rule table.
import { createOut } from "readerly";
export async function lint(argv: string[]): Promise<number> {
const out = createOut({ tool: "acme", command: "lint", argv });
out.error({
code: "ACME001",
message: "Route handler reads process.env at module scope",
why: "The value is fixed at build time",
fix: "Read it inside the handler",
docs: "https://acme.dev/rules/ACME001",
file: "src/app.ts",
line: 14,
column: 3,
});
out.warn({ code: "ACME010", message: "Alias shadows a workspace package", file: "vite.config.ts", line: 8, column: 5 });
out.info("Cache was cold");
return out.end();
}In text, agent and json, nothing prints when you call them. readerly collects the records, counts them by severity and renders them when you call out.end(), or earlier when a prompt needs the screen. jsonl writes each record as you add it. With --quiet, text drops infos and logs from the report but still counts them.
How text prints them
Section titled "How text prints them"A person at a terminal gets the acme check example from test/golden like this, without the color:
✖ 2 errors, 1 warning in 212 files (0.8s)
error ACME001 src/app.ts:14:3 Route handler reads process.env at module scope
├▶ why: The value is fixed at build time
╰▶ fix: Read it inside the handler
error ACME004 src/db.ts:3:1 Top-level await in a server entry
╰▶ fix: Move the call into the plugin setup
warn ACME010 vite.config.ts:8:5 Alias shadows a workspace package
next: acme explain <code> (explains one code)The first line is the verdict. Its glyph comes from the status: a red ✖ when the run failed, a yellow ⚠ for action_required or for errors and warnings in a run that didn't fail, and a green ✔ otherwise. A clean run prints ✔ no problems.
Rows are sorted errors first, then warnings, then infos. Each row starts with the severity padded to five characters (error, warn , info ), in red, yellow or cyan. Then come the code, the location as file:line:column and the message, separated by two spaces.
Below a row, tree() draws one branch per field: why:, fix:, and see: with the docs URL when you pass --full. The last branch gets ╰▶, the others ├▶. The glyphs are dim and the labels bold. See Color and glyphs for the full vocabulary.
The row cap
Section titled "The row cap"A terminal shows at most 50 rows. Set maxRows in createOut to change it. The rows past the cap collapse into one dim line with the command that shows them all. With maxRows: 3, the person at the terminal gets:
✖ 1 error, 4 warnings, 1 info
error ACME001 src/app.ts:14:3 Route handler reads process.env at module scope
├▶ why: The value is fixed at build time
╰▶ fix: Read it inside the handler
warn ACME010 packages/p1/vite.config.ts:8:5 Alias shadows a workspace package
warn ACME010 packages/p2/vite.config.ts:8:5 Alias shadows a workspace package
… 3 more (rerun: acme lint --full)The cap applies only to the terminal reader on text. CI logs, pipes and --full get every row.
How agent prints them
Section titled "How agent prints them"A coding agent gets each diagnostic on one line: severity, code, location, message, and the fix as a second sentence.
acme check: failed. 2 errors, 1 warning in 212 files (0.8s).
error ACME001 src/app.ts:14:3 Route handler reads process.env at module scope. fix: Read it inside the handler
error ACME004 src/db.ts:3:1 Top-level await in a server entry. fix: Move the call into the plugin setup
warn ACME010 vite.config.ts:8:5 Alias shadows a workspace package
next: acme check --fix (applies 2 safe fixes)
next: acme explain <code> (explains one code)why: and docs: join the line only with --full. With --full, the agent gets this line for the lint example above:
error ACME001 src/app.ts:14:3 Route handler reads process.env at module scope. why: The value is fixed at build time. fix: Read it inside the handler. docs: https://acme.dev/rules/ACME001There is no row cap in agent. The budget decides how many lines fit.
The verdict
Section titled "The verdict"The verdict is the counts, an optional summary and a status.
- Counts.
2 errors, 1 warning. Severities with no records are left out, and a run with none saysno problems. - Summary. Text after the counts, such as
in 212 files (0.8s). Passsummary: (result, counts) => string | undefinedtocreateOut, or a string toout.end({ summary })for one run. - Status.
failedwhen there is at least one error, elseok. Passout.end({ status })to decide it yourself.
A tool that tolerates errors can end with ok:
out.error("Unused export");
return out.end({ status: "ok", summary: "(errors tolerated)" });The exit code is 0, and a coding agent gets:
acme lint: ok. 1 error (errors tolerated).
error Unused exportIn text, that verdict shows a yellow ⚠, because the counts still hold an error. Only a failed status shows ✖.
Using tree on its own
Section titled "Using tree on its own"tree() from readerly/tree draws the same shape for any headline and branches. It returns a string with no trailing newline and no color unless you pass a Style.
import { tree } from "readerly/tree";
console.log(
tree("ACME001 Route handler reads process.env", [
["why", "The value is fixed at build time"],
["fix", "Read it inside the handler"],
]),
);It prints:
ACME001 Route handler reads process.env
├▶ why: The value is fixed at build time
╰▶ fix: Read it inside the handlerPass createStyle(true) from readerly/color as the third argument to make the headline and labels bold and the glyphs dim.
Next: Budget.