-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add doctor command for project health checks #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
da41695
feat(color): add red color utility export
rafa-thayto cc4113c
feat(doctor): add doctor command for project health checks
rafa-thayto aad17a3
feat(cli): register doctor command
rafa-thayto 7666de8
docs: add doctor command to CLI help output
rafa-thayto a2aa71f
refactor(doctor): remove git availability check
rafa-thayto 4cac338
refactor(doctor): DRY check functions with defineCheck builder and im…
rafa-thayto 29b6c0d
fix: align doctor command with centralized error handling patterns
rafa-thayto e939180
refactor(doctor): improve check names and messages for clarity
rafa-thayto 1d72531
fix(doctor): restore Instance IDs prefix in check messages
rafa-thayto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # Doctor Command | ||
|
|
||
| Runs a series of diagnostic checks on your Clerk CLI setup and reports | ||
| the status of each check. The command is read-only and never modifies | ||
| any state (unless `--fix` is used). | ||
|
|
||
| ## Usage | ||
|
|
||
| ```sh | ||
| clerk doctor # Run all checks | ||
| clerk doctor --verbose # Show detailed output | ||
| clerk doctor --json # Output results as JSON | ||
| clerk doctor --spotlight # Only show warnings and failures | ||
| clerk doctor --fix # Offer to auto-fix issues | ||
| ``` | ||
|
|
||
| ## Options | ||
|
|
||
| | Flag | Description | | ||
| | ------------- | ----------------------------------------------------- | | ||
| | `--verbose` | Show detailed diagnostic info for each check | | ||
| | `--json` | Output results as machine-readable JSON | | ||
| | `--spotlight` | Only show warnings and failures (hide passing checks) | | ||
| | `--fix` | Offer to auto-fix issues with known remedies | | ||
|
|
||
| ## Checks | ||
|
|
||
| | Check | Category | What it verifies | | ||
| | --------------------- | -------------- | ------------------------------------------------------------------ | | ||
| | Authentication token | Authentication | Credential store has a stored token | | ||
| | Token validity | Authentication | Token is still valid (calls `/oauth/userinfo`) | | ||
| | Project linkage | Project | Current directory is linked to a Clerk app | | ||
| | Linked application | Project | Linked application ID is accessible via the API | | ||
| | Instances | Project | Configured dev/prod instance IDs match the application's instances | | ||
| | Environment variables | Environment | .env.local or .env has Clerk keys | | ||
| | CLI configuration | Configuration | ~/.clerk/config.json exists and parses | | ||
|
|
||
| ## Auto-Fix (`--fix`) | ||
|
|
||
| When `--fix` is passed in human mode, the command prompts to fix each | ||
| issue after all checks complete. After applying fixes, all checks are | ||
| re-run to verify the results. | ||
|
|
||
| `--fix` only works in human mode because the underlying fix actions are | ||
| interactive (`clerk auth login` opens a browser, `clerk link` shows a | ||
| picker). It is ignored in `--json` mode and agent mode. | ||
|
|
||
| Fixable issues: | ||
|
|
||
| | Issue | Fix action | | ||
| | ---------------------------------- | ----------------------------------- | | ||
| | Not logged in / expired token | Log in with `clerk auth login` | | ||
| | Not linked to an app / stale app | Link project with `clerk link` | | ||
| | Missing environment variables | Pull env vars with `clerk env pull` | | ||
| | Missing or corrupt CLI config file | Log in with `clerk auth login` | | ||
|
|
||
| Duplicate fix actions (e.g., multiple checks suggesting `clerk auth login`) | ||
| are deduplicated. | ||
|
|
||
| ## Agent / CI Usage | ||
|
|
||
| AI agents and CI pipelines should use `--json` to get structured output: | ||
|
|
||
| ```sh | ||
| clerk doctor --json # Diagnose, output JSON | ||
| clerk doctor --json --spotlight # JSON with only warnings/errors | ||
| ``` | ||
|
|
||
| Each result includes `name`, `status` (`pass` / `warn` / `fail`), | ||
| `message`, and optionally `detail` (extra diagnostic info), `remedy` | ||
| (a human-readable fix instruction), and `fix` (a label describing | ||
| the auto-fix action). | ||
|
|
||
| Agents cannot use `--fix` directly because the fix actions are interactive. | ||
| Instead, agents should read the `remedy` field from the JSON output and | ||
| orchestrate fixes themselves (e.g., ask the user to run `clerk auth login`, | ||
| or call `clerk link --app <id>` with a known app ID). | ||
|
|
||
| Exit code 1 signals one or more checks failed. | ||
|
|
||
| ## Exit Codes | ||
|
|
||
| | Code | Meaning | | ||
| | ---- | ---------------------------------------- | | ||
| | 0 | All checks passed (warnings are allowed) | | ||
| | 1 | One or more checks failed | | ||
|
|
||
| ## API Endpoints | ||
|
|
||
| | Method | Endpoint | Description | | ||
| | ------ | ----------------------------------- | ----------------------------------------------- | | ||
| | `GET` | `/oauth/userinfo` | Validates the stored auth token | | ||
| | `GET` | `/v1/platform/applications/{appId}` | Verifies the linked app and its instances exist | | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still find "Linked application" and "Project linkage" a little confusing. The definition of "Project linkage" doesn't use the term "project" but just uses "Clerk app".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let me think better on this
do you have any name suggestions?