# Getting started

```sh pm
pnpm add readerly
```

readerly needs Node 22.12 or later and has no dependencies.

> **Note**

readerly is private while it is in development, and not on npm yet.

## Send output through createOut

```ts [src/check.ts]
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 });
  if (
    await out.confirm({
      name: "fix",
      flag: "--fix",
      default: false,
      message: "Apply 2 safe fixes?",
      reason: "applies 2 safe fixes",
    })
  )
    await applyFixes();
  out.next("acme explain <code>", "explains one code");
  return out.end();
}
```

The command says what it found. `createOut` works out who reads it, and `out.end()` writes the answer for that reader and returns the exit code.

## What each reader gets

The same `acme check`, as each reader sees it on stdout:

::code-group
```txt [Terminal]
✖ 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)
```

```txt [GitHub Actions]
✖ 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 check --fix   (applies 2 safe fixes)
next: acme explain <code>   (explains one code)
```

```txt [Agent]
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)
```

```json [--format json]
{
  "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,
    "durationMs": 840
  },
  "next": [
    {
      "command": "acme check --fix",
      "reason": "applies 2 safe fixes"
    },
    {
      "command": "acme explain <code>",
      "reason": "explains one code"
    }
  ]
}
```

```jsonl [--format jsonl]
{"type":"version","schema":"acme.check/v1","tool":"acme@1.2.0"}
{"type":"diagnostic","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}
{"type":"diagnostic","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}
{"type":"diagnostic","severity":"warn","code":"ACME010","message":"Alias shadows a workspace package","file":"vite.config.ts","line":8,"column":5}
{"type":"next","message":"acme check --fix","reason":"applies 2 safe fixes"}
{"type":"next","message":"acme explain <code>","reason":"explains one code"}
{"type":"result","status":"failed","message":"2 errors, 1 warning in 212 files (0.8s)","data":{"files":212,"durationMs":840}}
```
::

At the terminal, the command also asks `? Apply 2 safe fixes? (y/N)` on stderr. Everyone else gets the `acme check --fix` line instead. In GitHub Actions, stderr carries the annotations:

```txt [stderr]
::error title=ACME001,file=src/app.ts,line=14,col=3::Route handler reads process.env at module scope
::error title=ACME004,file=src/db.ts,line=3,col=1::Top-level await in a server entry
::warning title=ACME010,file=vite.config.ts,line=8,col=5::Alias shadows a workspace package
```

Try it in the [playground](https://readerly.loadsheet.dev/playground).

<!-- vitehub-docs:section-links -->
## In this section

- [Getting started](https://readerly.loadsheet.dev/raw/guide.md) (this page)
- [Output](https://readerly.loadsheet.dev/raw/guide/output.md)
- [Flags](https://readerly.loadsheet.dev/raw/guide/flags.md)
- [Prompts and input](https://readerly.loadsheet.dev/raw/guide/prompts.md)
- [Progress](https://readerly.loadsheet.dev/raw/guide/progress.md)
- [Failures](https://readerly.loadsheet.dev/raw/guide/failures.md)
- [Custom renderers](https://readerly.loadsheet.dev/raw/guide/renderers.md)
- [Modules](https://readerly.loadsheet.dev/raw/guide/modules.md)

Next: [Output](https://readerly.loadsheet.dev/raw/guide/output.md)

All pages: [llms.txt](https://readerly.loadsheet.dev/llms.txt)
