GitHub
Skip to content

Diagnostics

The DiagnosticRecord fields, the out.error, warn, info and diagnostic calls, and how text and agent output print each finding and the verdict line.

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.

Every diagnostic is a DiagnosticRecord from src/types.ts. It follows the nostics shape and adds a location.

FieldTypeWhat it holds
severity"error" | "warn" | "info"Required. Errors fail the run.
codestringA stable rule or error code, such as ACME001.
messagestringRequired. One sentence about what is wrong.
whystringThe reason it matters.
fixstringWhat to change.
docsstringA URL that explains the code.
filestringPath of the file the finding is in.
line, columnnumberWhere it starts.
endLine, endColumnnumberWhere it ends. Only GitHub annotations use them.
sourcesstring[]Source locations, as nostics reports them.
dataunknownAnything else. json and jsonl carry it, text and agent don't print it.

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();
}
lint.ts

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.

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)
text

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.

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)
text

The cap applies only to the terminal reader on text. CI logs, pipes and --full get every row.

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)
text

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/ACME001
text

There is no row cap in agent. The budget decides how many lines fit.

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 says no problems.
  • Summary. Text after the counts, such as in 212 files (0.8s). Pass summary: (result, counts) => string | undefined to createOut, or a string to out.end({ summary }) for one run.
  • Status. failed when there is at least one error, else ok. Pass out.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)" });
lint.ts

The exit code is 0, and a coding agent gets:

acme lint: ok. 1 error (errors tolerated).
error Unused export
text

In text, that verdict shows a yellow ⚠, because the counts still hold an error. Only a failed status shows ✖.

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"],
  ]),
);
explain.ts

It prints:

ACME001 Route handler reads process.env
├▶ why: The value is fixed at build time
╰▶ fix: Read it inside the handler
text

Pass createStyle(true) from readerly/color as the third argument to make the headline and labels bold and the glyphs dim.

Next: Budget.