Skip to content

feat(scripts): doctor.ps1 — health, updates, and self-repair in one command#29

Open
abdout wants to merge 1 commit into
mainfrom
feat/doctor
Open

feat(scripts): doctor.ps1 — health, updates, and self-repair in one command#29
abdout wants to merge 1 commit into
mainfrom
feat/doctor

Conversation

@abdout
Copy link
Copy Markdown
Contributor

@abdout abdout commented May 16, 2026

Summary

Implements spec #26. One command, three answers: is my config healthy, is it up to date, what's fixable?

& "$env:USERPROFILE\.claude\scripts\doctor.ps1"

Output (verified on a real machine):

🔄 1 updates available · unknown @ HOSTNAME · 2026-05-16 16:42

UPDATES
  🔄 claude CLI             v2.1.143 available (current 2.1.140) — winget upgrade Anthropic.ClaudeCode

What's in the PR

  • ~/.claude/scripts/doctor.ps1 — main entry point (188 lines)
  • 7 check modules under lib/:
    • Common.ps1 — shared New-CheckResult accumulator, role detection, file freshness
    • Check-Core.ps1 — CLAUDE.md, settings.json, mcp.json, .env, agent/command counts
    • Check-Shell.ps1c function in $PROFILE, ~/.claude/bin on PATH
    • Check-Identity.ps1gh auth status, claude CLI signed-in heuristic
    • Check-Repos.ps1 — org repos cloned, branch, dirtiness (reads repositories.json if present)
    • Check-Updates.ps1 — claude CLI vs latest GitHub release, kun + codebase ahead/behind
    • Check-Scheduled.ps1kun-maintain task armed (next-run + last-run + exit code)
    • Check-IDE.ps1 — WebStorm version + Claude Code [Beta] plugin loaded
  • 1 fix module: Fix-Shell.ps1 — idempotent $PROFILE block append, double-applies safely
  • health.ps1 demoted to a 5-line back-compat shim → doctor.ps1. Existing callers of health.ps1 -Report keep working unchanged.
  • install.ps1 updated to copy lib/ recursively and reference doctor in post-install steps

Flags

Flag What
(none) Full audit, exit 0/1/2/3
-Report Post result as a comment on databayt/kun#config-health
-Fix Repair fixable issues (right now: $PROFILE c function append)
-Update Pull ~/.claude + ~/codebase; prints (doesn't run) winget upgrade for claude CLI
-Json JSON output instead of table
-Quiet Suppress passes, show only warn/fail/update/paused rows
-Deep Reserved for future expensive checks (no-op today)

Exit codes

Code Meaning
0 All green
1 At least one error
2 Warnings only
3 Updates available, no errors or warnings

Precedence: errors > warnings > updates.

Test plan

  • doctor runs on a configured machine and exits 0
  • doctor on this machine (no ~/.claude/) exits 1 and surfaces every missing piece
  • doctor -Fix on a machine with no c function appends the block to $PROFILE; second run is no-op
  • doctor -Json | ConvertFrom-Json parses correctly
  • health.ps1 -Report still posts to databayt/kun#config-health (back-compat shim works)
  • install.ps1 copies lib/ to ~/.claude/scripts/lib/ on a fresh install
  • All 11 PowerShell files parse cleanly (Parser::ParseFile) — verified locally

Open items not blocking this PR

These are noted in spec #26 and don't block merge:

  • repositories.json is read if present; today's install.ps1 already creates it. Migrating sync-repos.ps1 to use the same JSON instead of the hardcoded hashtable is a follow-up.
  • macOS/Linux equivalents are follow-up work (Windows-only for v1).
  • databayt/codebase/.claude/scripts/install.ps1 tombstone is a separate cross-repo PR.

Sample run

This is real output captured against a machine that hasn't run install.ps1 yet — every error/warning is accurate:

❌ 13 errors · unknown @ HOSTNAME · 2026-05-16 16:42

CORE FILES
  ❌ CLAUDE.md              missing — run install.ps1
  ❌ mcp.json               missing — run install.ps1
  ⚠️  .env                  missing — run secrets.ps1
  ❌ agents/                empty
  ❌ commands/              empty

IDE
  ⚠️  Claude Code [Beta]    not loaded — install from Marketplace or bootstrap.ps1

ORG REPOS
  ❌ codebase               not cloned
  ... (11 repos)

SCHEDULED
  ⏸  kun-maintain           not armed — install via maintain -Install or bootstrap.ps1

SHELL
  ❌ $PROFILE               missing — run doctor -Fix

UPDATES
  🔄 claude CLI             v2.1.143 available (current 2.1.140) — winget upgrade Anthropic.ClaudeCode

Run 'doctor -Fix' to repair 13 fixable issue(s).
Run 'doctor -Update' to apply 1 update(s).

Closes #26

🤖 Generated with Claude Code

Implements spec #26. One command, three answers: is the config healthy,
is it up to date, what's fixable?

- New ~/.claude/scripts/doctor.ps1 — main entry point with -Fix, -Update,
  -Report, -Json, -Quiet, -Deep flags and 4-level exit codes (0/1/2/3)
- 7 check modules in .claude/scripts/lib/:
  Common, Check-Core, Check-Shell, Check-Identity, Check-Repos,
  Check-Updates, Check-Scheduled, Check-IDE
- 1 fix module in lib/: Fix-Shell (idempotent $PROFILE repair)
- health.ps1 demoted to 5-line back-compat shim → doctor.ps1
- install.ps1 updated to copy lib/ recursively + mention doctor in
  post-install steps

Exit codes (precedence errors > warnings > updates):
  0 all green   1 errors   2 warnings only   3 updates available

Verified end-to-end on this machine — surfaces missing config, dirty
repos, scheduled-task absence, and a real claude CLI update.

Closes #26

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
kun Ready Ready Preview, Comment May 16, 2026 3:18pm

abdout added a commit that referenced this pull request May 16, 2026
Resolves the spec #26 acceptance criterion 'repositories.json becomes
the source of truth (both doctor.ps1 and sync-repos.ps1 read it)'.

- repositories.json gains a top-level 'repos' map keyed by repo name,
  values as $env:USERPROFILE-expanded paths. Sits alongside the richer
  'repositories' object (untouched, for other tooling).
- sync-repos.ps1 reads repositories.json's 'repos' map at runtime,
  expands env vars via ExpandString. Falls back to the previously-
  hardcoded hashtable when the JSON isn't yet at the install location
  (cold-bootstrap edge case).
- Path expansion verified end-to-end on this machine —
  '$env:USERPROFILE\codebase' resolves to 'C:\Users\osman\codebase'.

doctor.ps1's Check-Repos.ps1 already reads the same shape (shipped in
PR #29). Both scripts now share a single source of truth, so adding a
new active repo means editing one JSON file.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
abdout added a commit that referenced this pull request May 16, 2026
Reflects the reality on the ground after PRs #29/#30/#31 land the
v2 scripts:

onboarding.mdx:
- Promotes 'irm https://kun.databayt.org/install | iex' to the
  recommended path (one paste, one UAC, three OAuth sign-ins)
- Demotes Cowork-driven flow to "Alternative" — still works for
  Pro/Max users who want narration over a bare paste
- Manual fallback updated to use databayt/kun raw URL (the codebase
  one is now tombstoned in databayt/codebase#2)
- Adds 'doctor' to Daily entry points and 'maintain -Install' to
  the manual fallback chain
- "What you end up with" mentions the scheduled task

onboarding-reference.mdx:
- Scripts contract table flipped: bootstrap, doctor, maintain are
  now Shipping (no longer 'Planned v2'); health.ps1 marked Deprecated;
  finish.ps1 reduced to 'Planned (alias for bootstrap)'
- Source-of-truth URL changed from databayt/codebase to databayt/kun
- Migration order section refreshed — 4 of 6 items checked off,
  fresh-VM test + team comms remaining

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spec: doctor.ps1 — health, updates, and self-repair in one command

1 participant