Agent Skills › openchamber/openchamber › clack-cli-patterns

clack-cli-patterns

GitHub

提供 OpenChamber CLI 开发规范,涵盖基于 @clack/prompts 的交互 UX、多模式(TTY/Non-TTY/--quiet/--json)输出契约及错误处理标准,确保策略优先与脚本安全。

.agents/skills/clack-cli-patterns/SKILL.md openchamber/openchamber

触发场景

创建或修改 CLI 命令 实现终端交互提示 处理 --quiet 或 --json 输出

安装

npx skills add openchamber/openchamber --skill clack-cli-patterns -g -y
更多选项

非标准路径

npx skills add https://github.com/openchamber/openchamber/tree/main/.agents/skills/clack-cli-patterns -g -y

不安装直接使用

npx skills use openchamber/openchamber@clack-cli-patterns

指定 Agent (Claude Code)

npx skills add openchamber/openchamber --skill clack-cli-patterns -a claude-code -g -y

安装 repo 全部 skill

npx skills add openchamber/openchamber --all -g -y

预览 repo 内 skill

npx skills add openchamber/openchamber --list

SKILL.md

Frontmatter
{
    "name": "clack-cli-patterns",
    "license": "MIT",
    "description": "Use when creating or modifying OpenChamber CLI commands, prompts, terminal output, non-TTY behavior, `--quiet`, or `--json` behavior.",
    "compatibility": "opencode"
}

Overview

OpenChamber terminal CLI uses @clack/prompts for interactive UX, but command policy and validation must be mode-agnostic.

Core principle: policy-first, UX-second. Clack is presentation, not enforcement.

Scope

Use this skill for terminal CLI work only (for example packages/web/bin/*).

Do not use this skill for web UI or VS Code webview styling work.

Mode Contract

Run safety and correctness validation before presentation in every mode. Prompts collect missing input; they never enforce policy alone.

Mode Prompt Output Failure
Interactive TTY Allowed when input is missing Framed human output Concise human error, non-zero exit
Fully specified flags None required Human output Same policy and exit semantics
Non-TTY/piped Never Deterministic script-safe output Non-zero without hanging
--quiet Never Essential result only Concise error, non-zero exit
--json Never JSON only, including warnings/errors JSON failure payload, non-zero exit

Handle prompt cancellation with isCancel + cancel(...) and SIGINT with consistent exit semantics.

Clack Primitive Standard

  • Flow framing: intro, outro, cancel
  • Status lines: log.info, log.success, log.warn, log.error, log.step
  • Guidance blocks:
    • default: note
    • high-severity warnings only: box
  • Prompts: select, confirm, text, password
  • Long-running feedback:
    • unknown duration: spinner
    • known duration: progress
    • multi-stage: tasks

Preferred Pattern

Presentation goes through packages/web/bin/cli-output.js; validation never moves into it.

Output Contracts by Mode

--quiet contract

--quiet should still return essential result data.

  • Read/list commands: emit concise machine-friendly lines (not framed Clack blocks).
  • Action commands: emit one minimal success line and concise errors.
  • Do not suppress required outcomes entirely.

Quiet output should still be complete enough for scripts and quick human scanning.

  • Status-like commands should list all active items, not only running/ok.
  • Prefer compact stable key tokens in quiet lines (for example port 3000 pass:yes).

--json contract (strict)

  • Warnings/info should be represented in JSON fields (for example status, messages).

Human UX Consistency

Framing completeness

  • If human flow uses intro, close with outro (or outro('') when you want structure without text).
  • Avoid orphan frame/spinner artifacts (prefer spinner.clear() when a trailing spinner line is not wanted).
  • If a structured summary section immediately follows a spinner, prefer spinner.clear() to avoid duplicate success lines.

Progress feedback for visible operations

  • For operations users wait on (start/stop/restart/tunnel lifecycle), show in-progress spinner in interactive mode.
  • Resolve each spinner explicitly to done/error so users can see completion state at the same visual location.
  • Keep quiet/json modes non-animated.

Prompt flow design

  • Ask required inputs in dependency order (for example hostname before token when token depends on chosen host/mode context).
  • When offering save-vs-run flows, ask intent before collecting optional metadata (for example profile name only if user chooses save).
  • Prefill editable values with initialValue (not only placeholder) so users can accept or edit quickly.
  • Reuse latest relevant values when safe (for example last managed-local config path, last managed-remote hostname).

Readability on narrow terminals

  • Prefer short lines.
  • Split long guidance into multiple detail lines.
  • Use warning/info codes ([CODE]) when the message has follow-up docs or repeat use.

Guidance tone

  • Use Optional Tips for non-required next actions.
  • Avoid wording that implies mandatory follow-up unless it is truly required.

Guidance rendering style (preferred)

  • Prefer structured status lines for reusable hints:
    • logStatus('info', '[CODE]', '<actionable command or short guidance>')
  • Use short, stable codes (for example [START_PROFILE], [PORT_MISMATCH]) so users can quickly scan and recognize repeated guidance.
  • Prefer this style over boxed notes for routine follow-up actions.
  • Reserve note/boxed callouts for rare, high-context guidance where a long paragraph is truly necessary.

Completion Criteria

Every command/subcommand must have a tested answer for:

  1. default interactive TTY output
  2. --quiet output (minimal but informative)
  3. --json output (JSON-only)
  4. non-TTY behavior (e.g. piped)
  5. error path in both human and json modes

Test with the suite in packages/web/bin/lib/DOCUMENTATION.md, Verification.

Reusable Snippets

Load references/snippets.md when implementing prompt guards, non-interactive fallback, spinner lifecycle, or JSON/human output branching.

Implementation is complete when validators run before every mode branch and interactive Clack UX is only an enhancement.

References

  • This skill is the canonical CLI parity and safety policy.
  • Terminal CLI precedent: packages/web/bin/cli.js
  • Output adapter precedent: packages/web/bin/cli-output.js

版本历史

  • 6cd8058 当前 2026-11-03 06:03

    统一 Agent 文档规则,消除重复内容并修复矛盾,精简上下文负载。

  • 2db90f7 2026-08-20 04:54

    重构为基于模式的合同规范,细化各模式下的输出契约与校验逻辑,移除旧版强制规则列表。

  • 74b1bd8 2026-07-25 10:36

同 Skill 集合

.agents/skills/changelog-authoring/SKILL.md
.agents/skills/communication-style/SKILL.md
.agents/skills/desktop-shell/SKILL.md
.agents/skills/drag-to-reorder/SKILL.md
.agents/skills/enterprise-boundary/SKILL.md
.agents/skills/isolated-space-boundary/SKILL.md
.agents/skills/locale-ui-patterns/SKILL.md
.agents/skills/openchamber-change-discipline/SKILL.md
.agents/skills/opencode-v2/SKILL.md
.agents/skills/pr-review/SKILL.md
.agents/skills/relay-transport/SKILL.md
.agents/skills/rtl-layout/SKILL.md
.agents/skills/serve-sim/SKILL.md
.agents/skills/settings-ui-patterns/SKILL.md
.agents/skills/sync-state-invariants/SKILL.md
.agents/skills/theme-system/SKILL.md
.agents/skills/triage-issues/SKILL.md
.agents/skills/triage-prs/SKILL.md
.agents/skills/ui-api-decoupling/SKILL.md
.agents/skills/update-changelog/SKILL.md
.agents/skills/writing-for-agents/SKILL.md
.agents/skills/performance-engineering/SKILL.md

元信息

文件数
0
版本
6cd8058
Hash
a42d503e
收录时间
2026-07-25 10:36

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.156.0. UTC+08:00, 2026-11-06 02:07
浙ICP备14020137号-1