A command doesn't print. It tells out what it found, and out.end() renders the whole run once, in the format the reader gets. Only createOut writes to the streams.
createOut
Section titled "createOut"const out = createOut<{ files: number }>({
tool: "acme",
command: "check",
version: "1.2.0",
argv: process.argv.slice(2),
summary: (result) => (result.files === undefined ? undefined : `in ${result.files} files`),
});tool names the ACME_FORMAT variable and the schema, acme.check/v1 here. argv carries the reader flags. version goes in jsonl's first record. summary adds words after the counts on the verdict line.
maxRows sets how many rows a terminal shows before it hides the rest, 50 by default. io and detection replace the process and the detection, for tests.
Diagnostics
Section titled "Diagnostics"out.error({ code: "ACME001", message: "Route handler reads process.env at module scope", file: "src/app.ts", line: 14 });
out.warn("Alias shadows a workspace package");
out.diagnostic({ severity: "info", message: "Cache is cold" });A diagnostic takes code, message, why, fix, docs, a location (file, line, column, endLine, endColumn) and data. The counts and the status come from them: any error makes the run failed.
Result
Section titled "Result"out.set({ files: 212 });set merges fields into the one result. JSON carries it as result, jsonl as the data of its last record.
Next commands
Section titled "Next commands"out.next("acme explain <code>", "explains one code");Each next is a command the reader can run after this one, with the reason. A confirm that falls back to its default adds one too, such as acme check --fix.
Logs and answers
Section titled "Logs and answers"out.log("Applied 2 fixes.");
out.debug("cache hit"); // only with --verbose, on stderr
out.write(markdown);log is a line in the run. write is an answer the tool rendered itself, such as an explain page. JSON and jsonl carry it as answer.
Progress and prompts
Section titled "Progress and prompts"out.progress(label) shows progress to a person and does nothing for anyone else. out.confirm and out.ask ask a person, or take the answer from a flag, --input or the environment.
return out.end();end renders the run and returns the exit code: 0 when ok, 1 when failed, 2 when the caller has to change the command. end({ status, summary }) overrides the status or the summary. out.fail(error) renders a failure instead.
Profile
Section titled "Profile"out.profile is what readerly decided: format, color, interactive, budget, verbosity, detection, and why, one line per decision.
out.write(out.profile.format === "text" ? await renderAnsi(page, { colors: out.profile.color }) : page);