Documentation
¶
Overview ¶
Package doctor implements the `aiwf doctor` verb. The bare verb runs a local health check (config presence, identity resolution, materialized-skill drift, id collisions, validator availability, hook drift, recommended-plugin presence). With --self-check it drives every aiwf verb against a throwaway repo to prove the binary works end-to-end; the --self-check entry point uses the in-process Dispatcher seam wired by cmd/aiwf/main.go.
Index ¶
- Variables
- func InContainer() (inContainer bool, label string)
- func NewCmd() *cobra.Command
- func Run(root string, selfCheck, checkLatest bool) int
- func RunCheckRituals(root string) int
- func WriteHealth(ctx context.Context, rootDir, generatedAt string, opts DoctorOptions) error
- type DoctorOptions
- type Problem
- type Severity
Constants ¶
This section is empty.
Variables ¶
var Dispatcher func(args []string) int
Dispatcher is the in-process verb dispatcher used by the --self-check mode to drive every aiwf verb end-to-end against a throwaway repo. It must be wired by cmd/aiwf/main.go's init at startup; the doctor package cannot import cmd/aiwf, so the seam is a package-level variable.
Default nil. Doctor's --self-check mode refuses with ExitInternal when the dispatcher is unset, naming the wiring step so the failure points at the right fix.
When cmd/aiwf/main.go itself moves to internal/cli/root in M-0118, the wiring becomes a `doctor.Dispatcher = cli.Execute` call inside the root package's init.
Functions ¶
func InContainer ¶
InContainer reports whether aiwf is running inside a containerised environment, and returns a human-readable label naming the detected signal(s). The two signals checked:
- `/.dockerenv` file existence (Docker convention; set by the Docker runtime regardless of orchestrator).
- `AIWF_DEVCONTAINER` env var with a truthy value (`1` / `true`, case-insensitive). Set by `.devcontainer/devcontainer.json`'s `containerEnv` map for repos using the M-0132 devcontainer.
Returns the boolean state plus the rendered label suitable for the `env:` line in `aiwf doctor` output:
- both signals → `devcontainer (/.dockerenv + AIWF_DEVCONTAINER)`
- only dockerenv → `devcontainer (/.dockerenv)`
- only env var → `devcontainer (AIWF_DEVCONTAINER)`
- neither → `host`
The detection is informational; consumers of this function never increment doctor's problem count based on the result.
M-0135/AC-1.
func NewCmd ¶
NewCmd builds `aiwf doctor`: version check, materialized-skill drift check, id-collision check. With --self-check, instead drives every mutating verb against a throwaway repo to prove the binary works end-to-end.
func Run ¶
Run is the exported entry point for `aiwf doctor`. Dispatches to the report-only path or --self-check based on the flag.
func RunCheckRituals ¶ added in v0.26.0
RunCheckRituals is the entry point for `aiwf doctor --check-rituals`: a terse, exit-code-meaningful check for automation (the M-0236 worktree-materialization hook script), distinct from the full `aiwf doctor` report where a missing ritual is advisory-only and never affects the exit code. Silent and ExitOK when every ritual artifact is present; a single actionable stderr line and ExitFindings otherwise.
func WriteHealth ¶ added in v0.22.0
func WriteHealth(ctx context.Context, rootDir, generatedAt string, opts DoctorOptions) error
WriteHealth writes .claude/health.aiwf.json from doctor's warnings and errors, in the fixed ai-dotfiles schema. The write is atomic and lands in the main checkout's .claude/ even when rootDir is a linked worktree, so one file serves every worktree. generatedAt (ISO 8601 UTC) is passed in so this stays wall-clock-free.
Types ¶
type DoctorOptions ¶
type DoctorOptions struct {
// CheckLatest, when true, performs a Go module proxy lookup for
// the latest published aiwf version and adds a `latest:` row to
// the report. Default false (offline).
CheckLatest bool
}
DoctorOptions carries flag-derived knobs into DoctorReport. Kept separate so DoctorReport stays flag-package-free and unit-testable.
type Problem ¶ added in v0.22.0
Problem is one doctor warning or error: a severity and a human message (the same text the report shows after its label). It is what aiwf writes to .claude/health.aiwf.json and what the doctor exit code counts; ok/info report lines produce no Problem.
func DoctorReport ¶
func DoctorReport(rootDir string, opts DoctorOptions) (lines []string, problems []Problem)
DoctorReport collects every doctor finding into a slice of human strings and returns the warnings and errors as []Problem — the report's problem states without the ok/info context. Pure for testability. The error count (what doctor's exit code weighs) is the number of SeverityError entries; warnings are advisory.
func Problems ¶ added in v0.22.0
func Problems(rootDir string, opts DoctorOptions) []Problem
Problems returns the warnings and errors doctor found for the repo at rootDir — the report's problem states without the ok/info context.