design-cli-output
关于
This skill provides a template for designing CLI terminal output with features like colored text, Unicode icons, and multiple verbosity levels (human, JSON, quiet, verbose). It covers architecture for reporter functions, status indicators, and cross-terminal compatibility. Use it when building a new CLI reporter, adding narrative output to an existing tool, or standardizing output across commands.
快速安装
Claude Code
推荐npx skills add pjt222/agent-almanac -a claude-code/plugin add https://github.com/pjt222/agent-almanacgit clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/design-cli-output在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
設計 CLI 輸出
為命令行工具設一致多級終端輸出。
用
- 構 CLI 新報告者模組
- 加暖敘事輸出於標事務輸出
- 標準化多命令輸出格式
- 設並行機可讀 JSON+人可讀輸出
- 擇色、符、冗繁級予新終端工具
入
- 必:CLI 名+主受眾(開發者、運維、終用戶)
- 必:需格式化輸出之命令
- 可:是否欲「儀式」或敘事變體
- 可:品牌限(色板、調)
法
一:定色板
以 chalk 建名板對象:
標板(事務輸出):
let chalk;
try { chalk = (await import('chalk')).default; }
catch { chalk = new Proxy({}, { get: () => (s) => s }); }
// Status colors
const ok = chalk.green; // success
const fail = chalk.red; // errors
const warn = chalk.yellow; // warnings
const info = chalk.cyan; // identifiers, names
const dim = chalk.dim; // secondary info, paths
const bold = chalk.bold; // headers
暖板(儀式/敘事輸出):
const C = {
flame: chalk.hex('#FF6B35'), // active elements, fire
amber: chalk.hex('#FFB347'), // arriving items, warm highlights
spark: chalk.hex('#FFF4E0'), // individual items (sparks/skills)
ember: chalk.hex('#8B4513'), // cold/dormant states
warm: chalk.hex('#D4A574'), // neutral warm text
dim: chalk.dim, // background, secondary
fail: chalk.red, // errors stay red (honest)
};
色板設規:
- 常供無色退(上 Proxy 模式)
- 自定板用十六進(
chalk.hex('#FF6B35')) - 失敗/錯色無論板主題守紅
- 按語義角名非視外觀
得: 板對象含名項+無色退。
敗: chalk 不可用(管輸、CI)→Proxy 退返字串不變。以 NO_COLOR=1 環境變量測。
二:擇狀態指示符
擇 Unicode 符或 ASCII 字元傳狀態:
ASCII(最大相容):
+ created/installed (green)
- removed/deleted (red)
= skipped/unchanged (dim)
! error/warning (red)
Unicode(富,需 UTF-8 終端):
✦ item/skill/practice (spark)
◉ active/burning state
◎ cooling/embers state
○ cold/dormant state
◌ available/not installed
✗ failed item
✓ success (use sparingly — not all terminals render it well)
擇標:
- CI 或管式運行→ASCII
- 交互終端用戶→Unicode
- 以
--ascii旗或NO_COLOR檢供兩者 - 於此測:macOS Terminal、Windows Terminal、VS Code 終端、SSH 會話
得: 不賴色一目傳狀態之符集。
敗: 測中符示為 ? 或方框→替以 ASCII 等。+/-/=/! 集處處可。
三:設冗繁級
每命令當支四輸出級:
| Level | Flag | Audience | Content |
|---|---|---|---|
| Default | (none) | Human at terminal | Formatted, colored, informative |
| Verbose | --verbose or --ceremonial | Human wanting detail | Per-item breakdown, arrival sequences |
| Quiet | --quiet | Scripts, CI | Minimal lines, status icons, no decoration |
| JSON | --json | Machine consumers | Structured, parseable, complete |
實現模式:
function output(data, options) {
if (options.json) {
console.log(JSON.stringify(data, null, 2));
return;
}
if (options.quiet) {
for (const item of data.items) {
const icon = item.ok ? '+' : '!';
console.log(`${icon} ${item.id}`);
}
return;
}
// Default (or verbose) human output
printFormatted(data, { verbose: options.verbose });
}
JSON 輸出規:
- 常有效 JSON(無雜人文)
- 含人輸出所示諸數據+機有用字段
- 跨命令一致鍵命名
- 退出碼 0 成,1 錯(無論輸出模式)
得: 四清晰輸出級跨命令行為一致。
敗: verbose 過噪→改為選入(--ceremonial)而非分級冗繁。
四:立調規
定諸輸出函遵之調+風。防跨命令不一致。
調規例(由 campfire 報告者):
- 現在時主動語態:「mystic arrives」非「mystic has been installed」
- 無驚嘆:靜信。工具不喊。
- 喻替術語:「practices」非「dependencies」(僅儀式模式)
- 失誠非災:「A spark was lost」非「ERROR: installation failed with exit code 1」
- 結句反映狀:每操作以狀總結
- 無 emoji:Unicode 符有視覺重不裝飾
- 每字載信息:字不加解→除
標(非儀式)輸出調規:
- 簡事實行
- 狀圖+項 ID+脈絡
- 總結行含計
- 錯訊建議糾正動作
得: 書 3-7 調規,輸出函須遵。
敗: 規任意→測:同輸出以無此規書。除規不減質→規不需。
五:實作報告者函
組輸出入聚焦模組:
// reporter.js — standard output
export function printResults(results) { ... }
export function printItemTable(items) { ... }
export function printDetections(detections) { ... }
export function printAudit(auditResults) { ... }
export function printDryRun() { ... }
export function warn(msg) { ... }
export function error(msg) { ... }
export { chalk };
每函從同結構:
- 空/null 輸入優雅處
- 計布局(列寬、填充)
- 以板色輸出
- 底總結行
儀式輸出建分離模組:
// campfire-reporter.js — warm narrative output
export function printArrival({ teamId, agents, results, ceremonial }) { ... }
export function printScatter({ teamId, agents, results }) { ... }
export function printTend(fires) { ... }
export function printCampfireList({ teams, state, reg }) { ... }
export function printFireSummary({ team, fireData, reg }) { ... }
export function printJson(data) { ... }
得: 報告者函獨立可用——各自理格式不賴調用者狀。
敗: 函超 ~50 行→提助手。報告者函當易孤立審。
六:測諸環境輸出
驗諸上下文正確渲染:
# With colors (interactive terminal)
node cli/index.js list --domains
# Without colors (piped)
node cli/index.js list --domains | cat
# With NO_COLOR environment variable
NO_COLOR=1 node cli/index.js list --domains
# JSON mode (parseable)
node cli/index.js campfire --json | jq .
# In CI (typically no TTY)
CI=true node cli/index.js audit
查:
- 交互模色正顯
- 管/重定向輸出無 ANSI 轉義漏
- JSON 有效(管至
jq .驗) - 目標終端渲染 Unicode 符
- 內容寬變時列對齊守
得: 五上下文輸出皆正。
敗: ANSI 漏→確 chalk 尊 NO_COLOR。Unicode 壞→供 ASCII 退模。
驗
- 色板有無色退
- 狀態指示符於色+無色模式皆工作
- 四冗繁級生有用輸出
- JSON 有效可為
jq解 - 調規錄並一致遵
- 報告者函優雅處空/null
- 輸出於此測:終端、管、NO_COLOR、CI
忌
- 混人文於 JSON:
--json模式僅輸出有效 JSON。單雜行(如「DRY RUN」)破 JSON 解析。若命令須示兩者→明分或於 JSON 模抑人文。 - 硬編碼列寬:內容長變。用
Math.max(...items.map(i => i.id.length))動計填充。 - 僅色傳義:若色為唯一別成敗者→色盲用戶+管輸出失信息。常配色+文指示(
+、OK、ERR)。 - 儀式於錯脈絡:暖敘事輸出宜交互終端。CI、腳本、
--quiet模→加噪。儀式輸出門於明旗後。 - 忘總結行:用戶先掃末行。每操作當以一行總結結(成/敗/略計)。
參
scaffold-cli-commandtest-cli-applicationbuild-cli-plugin
GitHub 仓库
相关推荐技能
content-collections
元Content Collections 是一个 TypeScript 优先的构建工具,可将本地 Markdown/MDX 文件转换为类型安全的数据集合。它专为构建博客、文档站和内容密集型 Vite+React 应用而设计,提供基于 Zod 的自动模式验证。该工具涵盖从 Vite 插件配置、MDX 编译到生产环境部署的完整工作流。
polymarket
元这个Claude Skill为开发者提供完整的Polymarket预测市场开发支持,涵盖API调用、交易执行和市场数据分析。关键特性包括实时WebSocket数据流,可监控实时交易、订单和市场动态。开发者可用它构建预测市场应用、实施交易策略并集成实时市场预测功能。
creating-opencode-plugins
元该Skill帮助开发者创建OpenCode插件,用于接入命令、文件、LSP等25+种事件。它提供了插件结构、事件API规范和JavaScript/TypeScript实现模式,适合需要拦截操作、扩展功能或自定义事件处理的场景。开发者可通过它快速构建响应式模块来增强OpenCode AI助手的能力。
sglang
元SGLang是一个专为LLM设计的高性能推理框架,特别适用于需要结构化输出的场景。它通过RadixAttention前缀缓存技术,在处理JSON、正则表达式、工具调用等具有重复前缀的复杂工作流时,能实现极速生成。如果你正在构建智能体或多轮对话系统,并追求远超vLLM的推理性能,SGLang是理想选择。
