GitHub
Skip to content

Installation

Install readerly, wrap one command with createOut, and run it as a person, as a coding agent and as a JSON consumer to see each output.
pnpm
pnpm add readerly
npm
npm install readerly
yarn
yarn add readerly
bun
bun add readerly

Requires 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.

  1. createOut takes the tool's name, the command and its argv. The command reports through out and returns out.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));
    check.ts

    scan() stands for your tool's own work. Here it returns two errors and one warning.

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

    In a color terminal, ✖ and error are red, warn yellow and the tree glyphs dim.

  3. Set AI_AGENT, as a coding agent's shell does:

    AI_AGENT=claude-code acme check

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

    Piped with acme check | cat, the command prints the terminal's text without the prompt, and the same next: acme check --fix line.

  4. acme check --format json

    A 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"
        }
      ]
    }
    text

    Every run exits 1, because the run has errors.

Next: Readers explains how readerly told these runs apart.