prototype
MAmattpocock/skills337k近 7 天新增 4,978 个 star
Terminal output design system for swamp CLI commands. Use when creating or modifying any CLI command output, render function, or presentation layer code. Ensures consistent formatting, coloring, and structure across all swamp commands in both "log" (human-readable) and "json" (structured) output modes. Triggers on output files in src/presentation/output/, render functions, writeOutput usage, OutputMode handling, or any CLI command that produces terminal output.
Consistent, human-readable terminal output for the swamp CLI.
Every command must support both modes, controlled by --json flag:
"log" (default) - Clean, colored, human-readable plain text"json" - Structured JSON for scripting and automationThe mode is available as ctx.outputMode from createContext() in
src/cli/context.ts.
stdout is the command's output. stderr is interaction and diagnostics.
| Goes to stdout | Goes to stderr |
|---|---|
writeOutput() prose (log mode) | Interactive prompts |
console.log(JSON…) (json mode) | Spinners and progress indicators |
| A command's bare value (see below) | LogTape records, warnings, errors |
A few commands put a value on stdout — something a caller pipes, captures or redirects, not prose about the result:
swamp invite link and swamp first-rule — the URL, for | pbcopyswamp vault read-secret — the secret bytes, for > key.pemThose commands are listed in src/cli/stdout_contract.ts, which runCli
consults to keep log records off their stdout. For them stdout is byte-exact:
swamp-club#1768 removed even the trailing newline. Anything else written there
is corruption, not clutter. Two bugs came from ignoring this — swamp-club#2254
(a log record ahead of the URL) and swamp-club#2260 (a confirmation prompt ahead
of the secret).
When adding output, ask what it is, not where it is convenient. A question
for the user is interaction: prompt through src/cli/prompt_helpers.ts, which
writes to stderr. A wizard's narration is interaction too. Only the result
belongs on stdout.
integration/prompt_stream_rules_test.ts pins every raw
Deno.stdout.write(...) in src/; a new one fails that test unless it is the
command's value. swamp-club#2259 tracks inverting the default so log-mode prose
goes to stderr as well.
src/cli/commands/<command>.ts → Command logic, builds data object
src/presentation/output/<name>_output.ts → Render function, formats output
src/infrastructure/logging/logger.ts → writeOutput() + LogTape loggers
Each command has a dedicated output file that exports:
OutputModeimport { bold, cyan, dim } from "@std/fmt/colors";
import { writeOutput } from "../../infrastructure/logging/logger.ts";
import type { OutputMode } from "./output.ts";
export interface ExampleData {
name: string;
type: string;
}
export function renderExample(data: ExampleData, mode: OutputMode): void {
if (mode === "json") {
console.log(JSON.stringify(data, null, 2));
} else {
const lines = [
`${bold(cyan("Name:"))} ${bold(data.name)} ${dim(`(${data.type})`)}`,
];
writeOutput(lines.join("\n"));
}
}
See references/logtape.md for details on how LogTape
and writeOutput() coexist and when to use each.
Key rule: Render functions use writeOutput() for user-facing output, never
LogTape. LogTape is for debug/operational logging only.
Escape every string a remote party supplied before it reaches the terminal: the
extension registry, swamp-club, a serve read with --server, workers, a shared
datastore, and output an extension's methods or reports produced. Raw control
characters can fake or hide output, set the window title, or write links.
escapeControlCharacters
from src/domain/control_characters.ts.escapeControlCharactersInText, which keeps newline and tab and turns CRLF
into newline.methodOutputLine
(src/presentation/output/method_output_line.ts), which keeps only a line's
last carriage-return redraw. command/shell execute in this process, never
over --server, also keeps its colour, reset at the end of each line; all
other method output is fully escaped.{prop} are already escaped. A
string passed as the message itself is not, so pass remote text as a value.renderError, logTextBlock and PipeWriter escape
their inputs already.model output data, vault read) is escaped
only when stdout is a terminal, so piped bytes stay exact.JSON.stringify. JSON shown in log
mode goes through escapeControlCharactersInText, since JSON.stringify
leaves DEL and C1 raw.src/presentation/output/serve_federation_output_property_test.ts).Import from @std/fmt/colors. Whether colors are emitted at all is decided once
per invocation by applyColorPolicy in src/cli/context.ts, called from the
top of runCli before the Cliffy command is constructed — early enough to
reach --version and --help, which Cliffy answers during parsing and which
never reach globalAction (swamp-club#2414). Colors are off when --no-color
is passed, when NO_COLOR is set to any value including empty, or when stdout
is not a terminal, so piped and redirected output carries no escape sequences.
The policy covers LogTape's pretty sink as well (see references/logtape.md), and it is process-wide, so a piped stdout also un-colors diagnostics on stderr.
| Element | Style | Example |
|---|---|---|
| Section headers/keys | bold(cyan(...)) | Created: Path: |
| Primary values | bold(...) | my-model |
| Sub-section headers | cyan(...) | Input Attributes: |
| Metadata/types | dim(...) | (string) *required |
| Enum values | dim(...) | [a, b, c] |
| Type annotations | dim(...) | (command/shell) |
| Pass indicator | green(...) | PASSED, checkmark |
| Fail indicator | red(...) | FAILED, cross |
| Separators | dim("-") | method - description |
Always build output as a string[] and join at the end:
const lines: string[] = [];
lines.push(`${bold(cyan("Header:"))} ${value}`);
// ...
writeOutput(lines.join("\n"));
Top-level key: value ← no indent
Second level (attributes, items) ← 2 spaces
Third level (sub-sections) ← 4 spaces
Fourth level (sub-items) ← 6 spaces
Reuse these exported functions from type_describe_output.ts:
formatSchemaAttributes(schema, indent) - JSON Schema to attribute linesformatMethodLines(methods) - Method descriptions with argument attributesReuse toMethodDescribeData(), buildDataOutputSpecs(), and
zodToJsonSchema() from src/cli/commands/type_describe.ts to convert domain
objects to presentation data. Data output specs are built at the type level via
buildDataOutputSpecs(resources, files), not per-method.
For pass/fail validation results:
const checkmark = "\u2713"; // ✓
const cross = "\u2717"; // ✗
const arrow = "\u2192"; // →
// Passing
lines.push(` ${green(checkmark)} ${name}`);
// Failing
lines.push(` ${red(cross)} ${name}`);
lines.push(` ${red(arrow)} ${errorMessage}`);
// Result
lines.push(
passed
? `${bold(cyan("Result:"))} ${green("PASSED")}`
: `${bold(cyan("Result:"))} ${red("FAILED")}`,
);
console.log(JSON.stringify(data, null, 2)) directly<name>_output_test.ts next to the output fileconsole.log output by stubbing itstripAnsiCode from @std/fmt/colors for color-aware assertions"json" and "log" modesimport { assertStringIncludes } from "@std/assert";
import { stripAnsiCode } from "@std/fmt/colors";
Deno.test("log mode shows expected content", () => {
const logs: string[] = [];
const originalLog = console.log;
console.log = (msg: string) => logs.push(msg);
try {
renderExample(testData, "log");
const combined = stripAnsiCode(logs.join("\n"));
assertStringIncludes(combined, "Expected:");
} finally {
console.log = originalLog;
}
});
MAmattpocock/skills337k近 7 天新增 4,978 个 star
AFaffaan-m/ECC315k近 7 天新增 4,381 个 star
FIfirecrawl/firecrawl215k近 7 天新增 5,595 个 star
ANanthropics/skills203k近 7 天新增 3,265 个 star
用 React、Tailwind 和 shadcn/ui 构建多组件页面。
ANanthropics/skills203k近 7 天新增 3,265 个 star