cli-logging-ux
Original:🇺🇸 English
Translated
Use this skill when editing or creating CLI output, logging, warnings, error messages, progress indicators, or diagnostic summaries in the APM codebase. Activate whenever code touches console helpers (_rich_success, _rich_warning, _rich_error, _rich_info, _rich_echo), DiagnosticCollector, STATUS_SYMBOLS, CommandLogger, or any user-facing terminal output — even if the user doesn't mention "logging" or "UX" explicitly.
1installs
Sourcemicrosoft/apm
Added on
NPX Install
npx skill4agent add microsoft/apm cli-logging-uxTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →CLI Logging UX expert persona
CLI Logging & Developer Experience
Decision framework
Apply these three tests to every piece of user-facing output. If a message fails any test, redesign it.
1. The "So What?" Test
Every warning must answer: what should the user do about this?
# Fails — not actionable, user can't do anything
Sub-skill 'my-skill' from 'my-package' overwrites existing skill
# Passes — tells the user exactly what to do
Skipping my-skill — local file exists (not managed by APM). Use 'apm install --force' to overwrite.If the user can't act on it, it's not a warning — it's noise. Demote to or remove.
--verbose2. The Traffic Light Rule
Use color semantics consistently. Never use a warning color for an informational state.
| Color | Helper | Meaning | When to use |
|---|---|---|---|
| Green | | Success / completed | Operation finished as expected |
| Yellow | | User action needed | Something requires user decision |
| Red | | Error / failure | Operation failed, cannot continue |
| Blue | | Informational | Status updates, progress, summaries |
| Dim | | Secondary detail | Verbose-mode details, grouping headers |
3. The Newspaper Test
Can the user scan output like headlines? Top-level = what happened. Details = drill down.
# Bad — warnings break the visual flow between status and summary
[checkmark] package-name
[warning] something happened
[warning] something else happened
[tree] 3 skill(s) integrated
# Good — clean tree, diagnostics at the end
[checkmark] package-name
[tree] 3 skill(s) integrated
── Diagnostics ──
[warning] 2 skills replaced by a different package (last installed wins)
Run with --verbose to see detailsInline output vs deferred diagnostics
Use inline output for:
- Success confirmations ()
_rich_success - Progress updates (with indented
_rich_infoprefix)└─ - Errors that halt the current operation ()
_rich_error
Use DiagnosticCollector for:
- Warnings that apply across multiple packages (collisions, overwrites)
- Issues the user should know about but that don't stop the operation
- Anything that would repeat N times in a loop
python
# Bad — inline warning repeated per file, clutters output
for file in files:
if collision:
_rich_warning(f"Skipping {file}...")
# Good — collect during loop, render grouped summary at the end
for file in files:
if collision:
diagnostics.skip(file, package=pkg_name)
# Later, after the loop:
if diagnostics.has_diagnostics:
diagnostics.render_summary()DiagnosticCollector categories: for collisions, for cross-package replacements, for general warnings, for failures.
skip()overwrite()warn()error()Console helper conventions
Always use the helpers from — never raw or bare .
apm_cli.utils.consoleprint()click.echo()Emojis are banned. Never use emoji characters anywhere in CLI output — not in messages, symbols, help text, or status indicators. Use ASCII text symbols exclusively via .
STATUS_SYMBOLSpython
from apm_cli.utils.console import (
_rich_success, _rich_error, _rich_warning, _rich_info, _rich_echo
)
_rich_success("Installed 3 APM dependencies") # green, bold
_rich_info(" └─ 2 prompts integrated → .github/prompts/") # blue
_rich_warning("Config drift detected — re-run apm install") # yellow
_rich_error("Failed to download package") # red
_rich_echo(" [pkg-name]", color="dim") # dim, for verbose detailsUse dict with parameter for consistent ASCII prefixes:
STATUS_SYMBOLSsymbol=python
_rich_info("Starting operation...", symbol="gear") # renders as "[*] Starting operation..."Output structure pattern
Follow this visual hierarchy for multi-package operations:
[checkmark] package-name-1 # _rich_success — download/copy ok
[tree] 2 prompts integrated → .github/prompts/ # _rich_info — indented summary
[tree] 1 skill(s) integrated → .github/skills/
[checkmark] package-name-2
[tree] 1 instruction(s) integrated → .github/instructions/
── Diagnostics ── # Only if diagnostics.has_diagnostics
[warning] N files skipped — ... # Grouped by category
Run with --verbose to see details
Installed 2 APM dependencies # _rich_success — final summaryContent-awareness principle
Before reporting changes, check if anything actually changed. Don't report no-ops.
python
# Bad — always copies and reports, even when content is identical
shutil.rmtree(target)
shutil.copytree(source, target)
_rich_info(f" └─ Skill updated")
# Good — skip when content matches
if SkillIntegrator._dirs_equal(source, target):
continue # Nothing changed, nothing to reportCommandLogger Architecture
APM is a large and growing CLI with 10+ commands, 8+ integrators, and dozens of output sites. The logging architecture enforces Separation of Concerns: commands declare what happened; the logger decides how to render it. This keeps output consistent, testable, and evolvable without shotgun surgery across command files.
The three layers
┌─────────────────────────────────────────────────────┐
│ Command layer (install.py, pack.py, audit.py …) │
│ Calls: logger.success(), logger.tree_item(), … │
│ NEVER calls: _rich_*, click.echo(), print() │
├─────────────────────────────────────────────────────┤
│ Logger layer (command_logger.py) │
│ CommandLogger ← InstallLogger, future subclasses │
│ Owns: verbose gating, symbol choice, indentation │
│ Delegates to: _rich_* helpers │
├─────────────────────────────────────────────────────┤
│ Rendering layer (console.py) │
│ _rich_echo, _rich_success, _rich_error, … │
│ Owns: Rich/colorama fallback, color, STATUS_SYMBOLS │
└─────────────────────────────────────────────────────┘Changes to output style (colors, symbols, indentation) happen in the logger or rendering layer only — command code is untouched. New output patterns (e.g. a tree sub-item, a package metadata line) become new logger methods, not ad-hoc format strings in commands.
Base class: CommandLogger
CommandLoggersrc/apm_cli/core/command_logger.py| Method | Purpose | When to use |
|---|---|---|
| Operation start | Beginning of a command |
| Status update with | Mid-operation phase changes |
| Green success | Operation completed |
| Yellow warning | User action needed |
| Red error | Operation failed |
| Dim text, verbose-only | Internal details (paths, hashes) |
| Green text, no symbol prefix | |
| Yellow text, verbose-only | Per-package diagnostic hints |
| | Dry-run explanation |
| Auth resolution step | Verbose auth tracing |
| Render DiagnosticCollector | End of command |
Subclass: InstallLogger(CommandLogger)
InstallLogger(CommandLogger)Install-specific phases. Commands that don't need these use directly.
CommandLogger| Method | Purpose | Output |
|---|---|---|
| Start validation | |
| Package OK | |
| Package bad | |
| Start resolution | Context-aware install/update message |
| Package installed | |
| Download error | |
| Lockfile verbose line | |
| Auth source verbose | |
| Package type verbose | |
| Final summary | |
When to add a new logger method
If a command needs a new output pattern (new indentation level, new semantic meaning, new verbose gate), add a method to CommandLogger or a subclass. Signs you need a new method:
- You're writing in a command file
_rich_echo(f" Something: {value}", color="dim") - You're checking before calling
if logger.verbose:in a command_rich_echo - You're formatting a string with specific indentation that other commands might reuse
- Multiple commands emit the same kind of line (e.g., file lists, auth info)
Rule: No direct _rich_*
in commands
_rich_*Command functions must NOT call , , etc. directly. Use , , etc. instead. The helpers are internal to the logger and rendering layers.
_rich_info()_rich_error()logger.progress()logger.error()_rich_*Exception: Rich tables and panels for display (not lifecycle logging) may use directly — these are data presentation, not status reporting.
console.print()Rule: Every command gets a CommandLogger
CommandLoggerEvery Click command function must instantiate a (or subclass) and pass it to helpers:
CommandLoggerpython
@cli.command()
@click.option("--verbose", "-v", is_flag=True)
@click.option("--dry-run", is_flag=True)
def my_command(verbose, dry_run):
logger = CommandLogger("my-command", verbose=verbose, dry_run=dry_run)
logger.start("Starting operation...")
_do_work(logger=logger)
logger.render_summary()Rule: Verbose gating lives in the logger
Never check in command code. Use methods that gate internally:
if verbose:python
# Bad — manual verbose check in command
if verbose:
_rich_echo(f" Auth: {source}", color="dim")
# Good — logger handles the gate
logger.package_auth(source, token_type) # No-ops when not verbose
logger.verbose_detail(f" Path: {path}") # No-ops when not verboseDiagnosticCollector integration
Access via (lazy-initialized). The collector owns the collect-then-render lifecycle:
logger.diagnosticspython
# During operation — collect
diagnostics.skip(file, package=pkg_name) # Collision
diagnostics.overwrite(file, package=pkg_name) # Cross-package replacement
diagnostics.error(msg, package=pkg_name) # Failure
diagnostics.auth(msg, package=pkg_name) # Auth issue
# Query during operation (e.g., for inline verbose hints)
count = diagnostics.count_for_package(pkg_name, category="collision")
if count > 0:
logger.package_inline_warning(f" [!] {count} files skipped")
# After operation — render grouped summary
logger.render_summary() # Delegates to diagnostics.render_summary()Visual hierarchy contract
Multi-package operations follow this tree structure:
[+] package-name #v1.0 @b0cbd3df # download_complete
Auth: git-credential-fill (oauth) # package_auth (verbose)
Package type: Skill (SKILL.md detected) # package_type_info (verbose)
└─ 3 skill(s) integrated -> .github/skills/ # tree_item
└─ 1 prompt integrated -> .github/prompts/ # tree_item
[!] 2 files skipped (local files exist) # package_inline_warning (verbose)
[+] another-package (cached) # download_complete
── Diagnostics ── # render_summary
[!] 2 files skipped -- local files exist # Grouped by category
Use 'apm install --force' to overwrite
[*] Installed 2 APM dependencies. # install_summaryKey rules:
- package lines are the top-level anchors (green, no indent beyond 2-space)
[+] - Verbose metadata (Auth, Package type) uses 4-space indent, dim color
- Tree items () use 4-space indent, green color, no symbol prefix
└─ - Inline warnings use 4-space indent, yellow color, verbose-only
- Diagnostics summary appears AFTER all packages, not inline (except verbose hints)
Scaling guidance
As the CLI grows, this architecture scales by:
- New commands: Instantiate , use existing methods. Add subclass only if the command has distinct phases (like
CommandLogger).InstallLogger - New output patterns: Add methods to . Every command benefits.
CommandLogger - New integrators: Accept param, push to collector. No direct output.
diagnostics= - Theme changes: Modify rendering layer (). Zero command changes.
console.py - Testing: Mock in tests to assert semantic calls without parsing output strings.
CommandLogger
Anti-patterns
-
Warning for non-actionable state — If the user can't do anything about it, useor defer to
_rich_info, not--verbose._rich_warning -
Inline warnings in loops — Useto collect, then render a grouped summary after the loop.
DiagnosticCollector -
Missingparameter — When calling integrators, always pass
diagnosticsso warnings route to the deferred summary.diagnostics=diagnostics -
No emojis, ever — Emojis are completely banned from all CLI output. Use ASCII text symbols fromexclusively. This applies to messages, help text, status indicators, and table titles.
STATUS_SYMBOLS -
Inconsistent symbols — Always usedict with
STATUS_SYMBOLSparam, not inline characters.symbol= -
Walls of text — Use Rich tables for structured data, panels for grouped content. Break up long output with visual hierarchy (indentation,tree connectors).
└─ -
Directcalls in commands — Use
_rich_*,logger.start(),logger.progress()etc. Thelogger.tree_item()helpers are internal to CommandLogger and console.py. Adding a_rich_*call in a command file is a SoC violation._rich_echo -
Manualchecks — Use
if verbose:,logger.verbose_detail(), or other verbose-gated methods. The logger owns the gate.logger.package_auth() -
Manualchecks — Use
if dry_run:orlogger.should_execute.logger.dry_run_notice() -
Format strings for indentation in commands — Don't writein command code. Use
f" Auth: {source}"which owns the indent level. When a new indentation pattern is needed, add a method to CommandLogger.logger.package_auth(source) -
Re-creating shared objects per iteration — Expensive objects likeshould be created once before loops and reused per-package. The logger and diagnostics collector are already singletons per command invocation.
AuthResolver -
Usingfor tree sub-items —
logger.progress()adds aprogress()symbol prefix. Tree continuation lines ([i]) should use└─which renders with no symbol.logger.tree_item()