pnpm add readerlynpm install readerlyyarn add readerlybun add readerlyRequires Node 22.12 or later. readerly is ESM only and has no dependencies.
Note
readerly is not on npm yet. Until it is, clone the repository, run pnpm install and pnpm build to write dist/, and depend on it by path, such as "readerly": "file:../readerly" in your package.json, or as a workspace package in a monorepo.
First command
Section titled "First command"Wrap a command with
Section titled "Wrap a command with createOut"createOutcreateOuttakes the tool's name, the command and itsargv. The command reports throughoutand returnsout.end(), the exit code.import { createOut } from "readerly"; export async function check(argv: string[]): Promise<number> { const out = createOut<{ files: number }>({ tool: "acme", command: "check", argv, summary: (result) => (result.files === undefined ? undefined : `in ${result.files} files`), }); for (const finding of await scan()) out.diagnostic(finding); out.set({ files: 212 }); const fix = await out.confirm({ name: "fix", flag: "--fix", default: false, message: "Apply 2 safe fixes?", reason: "applies 2 safe fixes", }); if (fix) out.log("Applied 2 fixes."); out.next("acme explain <code>", "explains one code"); return out.end(); } process.exitCode = await check(process.argv.slice(2));scan()stands for your tool's own work. Here it returns two errors and one warning.Run it in a terminal
Section titled "Run it in a terminal"A person at a terminal gets the findings, then the prompt on stderr. After Enter, the rest prints:
✖ 2 errors, 1 warning in 212 files 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 ? Apply 2 safe fixes? (y/N) next: acme explain <code> (explains one code)In a color terminal,
✖anderrorare red,warnyellow and the tree glyphs dim.Run it as an agent would
Section titled "Run it as an agent would"Set
AI_AGENT, as a coding agent's shell does:AI_AGENT=claude-code acme checkA coding agent gets one line per finding and no prompt. The prompt it skipped becomes a
next:line with the flag:acme check: failed. 2 errors, 1 warning in 212 files. 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)Piped with
acme check | cat, the command prints the terminal'stextwithout the prompt, and the samenext: acme check --fixline.Ask for JSON
Section titled "Ask for JSON"acme check --format jsonA program gets one document on stdout:
{ "schema": "acme.check/v1", "status": "failed", "summary": { "error": 2, "warn": 1, "info": 0 }, "diagnostics": [ { "severity": "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", "file": "src/app.ts", "line": 14, "column": 3 }, { "severity": "error", "code": "ACME004", "message": "Top-level await in a server entry", "fix": "Move the call into the plugin setup", "file": "src/db.ts", "line": 3, "column": 1 }, { "severity": "warn", "code": "ACME010", "message": "Alias shadows a workspace package", "file": "vite.config.ts", "line": 8, "column": 5 } ], "result": { "files": 212 }, "next": [ { "command": "acme check --fix", "reason": "applies 2 safe fixes" }, { "command": "acme explain <code>", "reason": "explains one code" } ] }Every run exits
1, because the run has errors.
Next: Readers explains how readerly told these runs apart.