CLI Doctoring Workflow - diagnostics that move users forward
Use this skill when designing or reviewing a CLI doctor, diagnose,
preflight, or health-check command. The command should explain what it checked,
what failed, how confident it is, what the user can do next, and what evidence is
safe to share in a support request.
The goal is not to prove every part of a system. The goal is to catch common
environment and configuration failures early, give precise repair hints, and
avoid sending users into vague troubleshooting loops.
Core Standard
A doctor command earns its place when it is:
- Actionable: every failure names the broken condition and the next useful
step.
- Bounded: each check says what it can and cannot prove.
- Safe: diagnostics avoid secrets, destructive writes, and surprise network
calls unless explicitly requested.
- Fast by default: the normal path should finish quickly; expensive checks
require a flag.
- Scriptable: machines get stable exit codes and structured output.
- Readable: humans get concise status, grouped causes, and repair hints.
When To Use This Skill
Use it for:
- Designing a new
doctor or diagnose command.
- Auditing existing CLI health-check output.
- Adding preflight checks before install, login, sync, deploy, test, or run
workflows.
- Turning recurring support issues into checks and repair hints.
- Reviewing whether diagnostics leak sensitive data or produce noisy advice.
Do not use it to hide real errors behind generic help text. If a primary command
can report a precise error directly, fix that command first and let doctor cover
cross-cutting environment checks.
Inputs To Gather
Read enough of the project to identify real failure modes:
- CLI command tree, help text, and exit-code conventions.
- Install, login, config, update, and first-run paths.
- Runtime dependencies such as binaries, services, credentials, sockets,
config files, ports, certificates, databases, and background daemons.
- Existing error messages, support tickets, issue reports, logs, and docs.
- CI, packaging, and release scripts that define supported environments.
Separate observed failures from guesses. A guessed check can be useful, but label
it as a proposed check until a real failure mode justifies it.
Design Procedure
- Name the workflow being protected. State the user task that doctor helps:
install, authenticate, sync, deploy, serve, connect to a device, or repair a
workspace.
- Map the failure chain. List prerequisites in the order the user encounters
them: binary present, version compatible, config readable, credentials valid,
service reachable, permissions sufficient, data shape accepted.
- Choose checks with clear evidence. Each check needs a probe, a pass
condition, a failure condition, and a reason the check matters.
- Classify failures. Use categories such as missing dependency,
incompatible version, unavailable service, invalid credentials, corrupt
config, permission denied, stale cache, unsupported platform, or unknown.
- Write repair hints. Prefer exact commands or file paths. If a repair is
risky, explain the risk and require user confirmation outside doctor.
- Define output modes. Human output should be compact and grouped.
Structured output should be stable JSON for automation and support bundles.
- Set exit semantics. A clean bill exits 0. User-fixable failures exit a
nonzero code distinct from internal doctor errors when the CLI already has an
exit-code convention.
- Verify with fixtures. Test passing, failing, partial, slow, offline, and
redacted-output cases. Include at least one regression check from a real bug
or support issue when available.
Check Contract
Define each health check with this shape:
| Field |
Purpose |
id |
Stable machine name, such as config.readable or auth.token.valid. |
scope |
Local, workspace, account, network, service, device, or update. |
probe |
What the command does to collect evidence. |
pass |
Exact condition that counts as healthy. |
fail |
Exact condition that counts as unhealthy. |
severity |
error, warning, or info; avoid more levels unless the CLI already uses them. |
confidence |
High when evidence proves the cause; lower when it is a symptom. |
repair |
User action, command, or documentation link that addresses the likely cause. |
redaction |
Data that must be hidden in human, JSON, logs, and support output. |
timeout |
Maximum wait time and fallback behavior for slow probes. |
If a check cannot produce a useful repair hint, reconsider whether it belongs in
the default doctor run.
Output Shape
Human output should answer four questions:
- What was checked?
- What failed?
- What should I do next?
- What can I share safely if I need help?
Recommended human shape:
Checking workspace
OK config.readable Loaded ./tool.yaml
FAIL auth.token.valid Token expired 2026-06-01
Fix: run `tool login` and retry `tool doctor`
Summary: 1 failure, 0 warnings, 3 passed
Next: fix the failed check above, then run `tool doctor` again
Recommended JSON shape:
{
"status": "fail",
"summary": {"passed": 3, "warnings": 0, "failed": 1},
"checks": [
{
"id": "auth.token.valid",
"status": "fail",
"severity": "error",
"confidence": "high",
"message": "Token is expired.",
"repair": {"command": "tool login"},
"redacted": true
}
]
}
Keep JSON stable. Add fields; do not rename existing fields casually once users
or support tooling depend on them.
Repair Hint Rules
- Give the shortest safe action that fixes the likely cause.
- Prefer commands the CLI owns over shell fragments that vary by platform.
- Include file paths only when they are relevant and safe to reveal.
- Do not print secrets, tokens, private URLs, full environment dumps, or raw
headers.
- Mark destructive repairs as manual instructions unless the command has an
explicit
--fix mode with confirmation and dry-run behavior.
- When multiple causes are possible, say what evidence would distinguish them.
Avoid vague hints such as "check your configuration" unless followed by a
specific file, key, command, or expected value.
Flags And Modes
Consider these modes when they fit the CLI:
--json for stable machine-readable output.
--verbose for extra evidence and timing.
--offline to skip network checks without failing the whole run.
--network or --deep for slower probes that are not safe as defaults.
--fix only for reversible, well-scoped repairs.
--support-bundle for redacted diagnostic evidence that users can attach to
a ticket.
Default mode should be safe, quiet, and fast. Expensive or privacy-sensitive
checks must be opt-in.
Audit Checklist
Use this checklist when reviewing an existing doctor command:
- The command starts with the workflow it is checking, not a wall of logs.
- Every failure has a stable check id, severity, cause, and repair hint.
- The output distinguishes warnings from failures.
- Checks are ordered in dependency order so early root causes do not cascade into
confusing secondary failures.
- Network probes have timeouts and offline behavior.
- Secret redaction is tested, including structured output and support bundles.
- Exit codes match the CLI's documented convention.
- The default run is fast enough for users to try repeatedly.
- JSON output is deterministic enough for tests and automation.
- Documentation shows when to run doctor and what a healthy result looks like.
Implementation Notes
- Build checks as small units with explicit inputs and outputs. This makes them
testable and lets the CLI reuse them for preflight warnings.
- Prefer dependency injection for filesystem, environment, clock, network, and
command execution probes.
- Treat probe failure as data. A probe that cannot run should produce a clear
doctor result, not crash the whole command unless doctor itself is broken.
- Capture durations for slow checks, but keep timing out of golden output unless
tests normalize it.
- Keep platform differences visible in the check contract instead of scattering
platform branches through presentation code.
Testing Strategy
Test at three levels:
- Unit tests: each check handles pass, fail, timeout, permission denied, and
redaction cases.
- Command tests: human and JSON output stay stable for representative
healthy and unhealthy fixtures.
- Workflow tests: at least one common support scenario ends with the repair
hint that would have helped the user.
Golden output is useful for doctor commands, but normalize timestamps, user
paths, home directories, hostnames, ports, and durations before comparing.
Output Specification
Return one of these artifacts:
- A doctor command design with check contracts, output modes, exit semantics,
repair hints, and tests.
- A diagnostic audit with concrete findings, severity, affected checks, and
suggested changes.
- A repair-hint plan that maps recurring symptoms to probes and safe next
actions.
Include the assumptions you could not verify from the codebase or support
evidence.
Quality Rubric
A CLI doctoring workflow passes when:
- A user can tell what failed and what to try next without reading source code.
- A maintainer can add or modify checks without rewriting presentation logic.
- Support can request structured output without receiving secrets.
- Automation can rely on stable JSON and meaningful exit codes.
- The command does not mask primary command errors that should be fixed at their
source.
1---2name: cli-doctoring-workflow3description: Use when designing or auditing CLI doctor commands, health checks, repair hints, and diagnostic UX. Triggers:4---5
6# CLI Doctoring Workflow - diagnostics that move users forward
7
8Use this skill when designing or reviewing a CLI `doctor`, `diagnose`,
9`preflight`, or health-check command. The command should explain what it checked,
10what failed, how confident it is, what the user can do next, and what evidence is
11safe to share in a support request.
12
13The goal is not to prove every part of a system. The goal is to catch common
14environment and configuration failures early, give precise repair hints, and
15avoid sending users into vague troubleshooting loops.
16
17## Core Standard
18
19A doctor command earns its place when it is:
20
21- **Actionable:** every failure names the broken condition and the next useful
22 step.
23- **Bounded:** each check says what it can and cannot prove.
24- **Safe:** diagnostics avoid secrets, destructive writes, and surprise network
25 calls unless explicitly requested.
26- **Fast by default:** the normal path should finish quickly; expensive checks
27 require a flag.
28- **Scriptable:** machines get stable exit codes and structured output.
29- **Readable:** humans get concise status, grouped causes, and repair hints.
30
31## When To Use This Skill
32
33Use it for:
34
35- Designing a new `doctor` or `diagnose` command.
36- Auditing existing CLI health-check output.
37- Adding preflight checks before install, login, sync, deploy, test, or run
38 workflows.
39- Turning recurring support issues into checks and repair hints.
40- Reviewing whether diagnostics leak sensitive data or produce noisy advice.
41
42Do not use it to hide real errors behind generic help text. If a primary command
43can report a precise error directly, fix that command first and let doctor cover
44cross-cutting environment checks.
45
46## Inputs To Gather
47
48Read enough of the project to identify real failure modes:
49
50- CLI command tree, help text, and exit-code conventions.
51- Install, login, config, update, and first-run paths.
52- Runtime dependencies such as binaries, services, credentials, sockets,
53 config files, ports, certificates, databases, and background daemons.
54- Existing error messages, support tickets, issue reports, logs, and docs.
55- CI, packaging, and release scripts that define supported environments.
56
57Separate observed failures from guesses. A guessed check can be useful, but label
58it as a proposed check until a real failure mode justifies it.
59
60## Design Procedure
61
621. **Name the workflow being protected.** State the user task that doctor helps:
63 install, authenticate, sync, deploy, serve, connect to a device, or repair a
64 workspace.
652. **Map the failure chain.** List prerequisites in the order the user encounters
66 them: binary present, version compatible, config readable, credentials valid,
67 service reachable, permissions sufficient, data shape accepted.
683. **Choose checks with clear evidence.** Each check needs a probe, a pass
69 condition, a failure condition, and a reason the check matters.
704. **Classify failures.** Use categories such as missing dependency,
71 incompatible version, unavailable service, invalid credentials, corrupt
72 config, permission denied, stale cache, unsupported platform, or unknown.
735. **Write repair hints.** Prefer exact commands or file paths. If a repair is
74 risky, explain the risk and require user confirmation outside doctor.
756. **Define output modes.** Human output should be compact and grouped.
76 Structured output should be stable JSON for automation and support bundles.
777. **Set exit semantics.** A clean bill exits 0. User-fixable failures exit a
78 nonzero code distinct from internal doctor errors when the CLI already has an
79 exit-code convention.
808. **Verify with fixtures.** Test passing, failing, partial, slow, offline, and
81 redacted-output cases. Include at least one regression check from a real bug
82 or support issue when available.
83
84## Check Contract
85
86Define each health check with this shape:
87
88| Field | Purpose |
89| --- | --- |
90| `id` | Stable machine name, such as `config.readable` or `auth.token.valid`. |
91| `scope` | Local, workspace, account, network, service, device, or update. |
92| `probe` | What the command does to collect evidence. |
93| `pass` | Exact condition that counts as healthy. |
94| `fail` | Exact condition that counts as unhealthy. |
95| `severity` | `error`, `warning`, or `info`; avoid more levels unless the CLI already uses them. |
96| `confidence` | High when evidence proves the cause; lower when it is a symptom. |
97| `repair` | User action, command, or documentation link that addresses the likely cause. |
98| `redaction` | Data that must be hidden in human, JSON, logs, and support output. |
99| `timeout` | Maximum wait time and fallback behavior for slow probes. |
100
101If a check cannot produce a useful repair hint, reconsider whether it belongs in
102the default doctor run.
103
104## Output Shape
105
106Human output should answer four questions:
107
1081. What was checked?
1092. What failed?
1103. What should I do next?
1114. What can I share safely if I need help?
112
113Recommended human shape:
114
115```text
116Checking workspace
117 OK config.readable Loaded ./tool.yaml
118 FAIL auth.token.valid Token expired 2026-06-01
119 Fix: run `tool login` and retry `tool doctor`
120
121Summary: 1 failure, 0 warnings, 3 passed
122Next: fix the failed check above, then run `tool doctor` again
123```
124
125Recommended JSON shape:
126
127```json
128{
129 "status": "fail",
130 "summary": {"passed": 3, "warnings": 0, "failed": 1},
131 "checks": [
132 {
133 "id": "auth.token.valid",
134 "status": "fail",
135 "severity": "error",
136 "confidence": "high",
137 "message": "Token is expired.",
138 "repair": {"command": "tool login"},
139 "redacted": true
140 }
141 ]
142}
143```
144
145Keep JSON stable. Add fields; do not rename existing fields casually once users
146or support tooling depend on them.
147
148## Repair Hint Rules
149
150- Give the shortest safe action that fixes the likely cause.
151- Prefer commands the CLI owns over shell fragments that vary by platform.
152- Include file paths only when they are relevant and safe to reveal.
153- Do not print secrets, tokens, private URLs, full environment dumps, or raw
154 headers.
155- Mark destructive repairs as manual instructions unless the command has an
156 explicit `--fix` mode with confirmation and dry-run behavior.
157- When multiple causes are possible, say what evidence would distinguish them.
158
159Avoid vague hints such as "check your configuration" unless followed by a
160specific file, key, command, or expected value.
161
162## Flags And Modes
163
164Consider these modes when they fit the CLI:
165
166- `--json` for stable machine-readable output.
167- `--verbose` for extra evidence and timing.
168- `--offline` to skip network checks without failing the whole run.
169- `--network` or `--deep` for slower probes that are not safe as defaults.
170- `--fix` only for reversible, well-scoped repairs.
171- `--support-bundle` for redacted diagnostic evidence that users can attach to
172 a ticket.
173
174Default mode should be safe, quiet, and fast. Expensive or privacy-sensitive
175checks must be opt-in.
176
177## Audit Checklist
178
179Use this checklist when reviewing an existing doctor command:
180
181- The command starts with the workflow it is checking, not a wall of logs.
182- Every failure has a stable check id, severity, cause, and repair hint.
183- The output distinguishes warnings from failures.
184- Checks are ordered in dependency order so early root causes do not cascade into
185 confusing secondary failures.
186- Network probes have timeouts and offline behavior.
187- Secret redaction is tested, including structured output and support bundles.
188- Exit codes match the CLI's documented convention.
189- The default run is fast enough for users to try repeatedly.
190- JSON output is deterministic enough for tests and automation.
191- Documentation shows when to run doctor and what a healthy result looks like.
192
193## Implementation Notes
194
195- Build checks as small units with explicit inputs and outputs. This makes them
196 testable and lets the CLI reuse them for preflight warnings.
197- Prefer dependency injection for filesystem, environment, clock, network, and
198 command execution probes.
199- Treat probe failure as data. A probe that cannot run should produce a clear
200 doctor result, not crash the whole command unless doctor itself is broken.
201- Capture durations for slow checks, but keep timing out of golden output unless
202 tests normalize it.
203- Keep platform differences visible in the check contract instead of scattering
204 platform branches through presentation code.
205
206## Testing Strategy
207
208Test at three levels:
209
210- **Unit tests:** each check handles pass, fail, timeout, permission denied, and
211 redaction cases.
212- **Command tests:** human and JSON output stay stable for representative
213 healthy and unhealthy fixtures.
214- **Workflow tests:** at least one common support scenario ends with the repair
215 hint that would have helped the user.
216
217Golden output is useful for doctor commands, but normalize timestamps, user
218paths, home directories, hostnames, ports, and durations before comparing.
219
220## Output Specification
221
222Return one of these artifacts:
223
224- A doctor command design with check contracts, output modes, exit semantics,
225 repair hints, and tests.
226- A diagnostic audit with concrete findings, severity, affected checks, and
227 suggested changes.
228- A repair-hint plan that maps recurring symptoms to probes and safe next
229 actions.
230
231Include the assumptions you could not verify from the codebase or support
232evidence.
233
234## Quality Rubric
235
236A CLI doctoring workflow passes when:
237
238- A user can tell what failed and what to try next without reading source code.
239- A maintainer can add or modify checks without rewriting presentation logic.
240- Support can request structured output without receiving secrets.
241- Automation can rely on stable JSON and meaningful exit codes.
242- The command does not mask primary command errors that should be fixed at their
243 source.