import { type AgentId } from '../agents/registry'; import { type AgentFeatureVersions } from '../lib/lock'; export type CheckStatus = 'ok' | 'missing' | 'invalid'; export interface Check { status: CheckStatus; /** One-line human-readable note: what is/isn't there, or why it failed. */ note: string; /** Suggested mswai command to resolve a non-ok status. Set only when the * fix is unambiguous (e.g. `mswai mcp -a claude-code`). UI consumers may * render this verbatim. */ fix?: string; /** Free-form extras for JSON consumers (counts, observed values, etc.). */ [key: string]: unknown; } /** * Versioning info for a single agent. Read from `.mswai/lock.json#agents`. * - `features`: per-feature (instruction/hooks/mcp) installed mswai version. * Each feature has its own entry because partial updates (`mswai update * -a claude-code` without all features) can leave them out of sync. * - `summary`: one-line label for prose output. Single version if all * features match; `"0.5.0 / 0.5.1"` style for intra-agent drift. * - `intraAgentDrift`: features have different versions inside this agent. * - `behind`: installed version is older than the current mswai package. */ export interface InstalledVersionInfo { features: AgentFeatureVersions; summary: string; intraAgentDrift: boolean; behind: boolean; } export interface AgentDoctorResult { agent: AgentId; displayName: string; /** Per-agent installed-version stamps from .mswai/lock.json. Absent when * the workspace was never installed by mswai. */ installed?: InstalledVersionInfo; pluginDir?: Check & { path: string; }; /** Per-agent instruction file (agent.linkPath). Omitted for agents that * read AGENTS.md natively (codex). */ instructionFile?: Check & { path: string; }; hooksDir?: Check & { path: string; }; skillsDir: Check & { path: string; }; mcpFile: Check & { path: string; }; /** Skipped (status undefined) when the mcp file itself is missing/invalid. */ mswMakerMcp: Check; mswMcp: Check; mswMcpKey: Check; } /** Workspace-level lock metadata. Populated from `.mswai/lock.json`. * Surfaces in the doctor header so users see at a glance whether the * workspace was ever touched by mswai. */ export interface LockHealth { /** True when `.mswai/lock.json` exists and is v3. */ present: boolean; /** packageVersion stamp from the lock — last mswai version that wrote here. */ packageVersion?: string; /** ISO timestamp of the last write. */ lastUpdated?: string; /** Number of agents that have at least one feature stamp in `lock.agents`. * Equal to `agentsTotal` for a full install; less means partial (e.g. * `mswai init -a claude-code`). */ agentsStamped: number; /** Equal to `ALL_AGENT_IDS.length`. Exposed for JSON consumers so they * don't have to know the constant. */ agentsTotal: number; /** One-line note suitable for prose output. */ note: string; /** Suggested mswai command when the lock is absent. */ fix?: string; } /** Workspace mlua-lsp vendored runtime status. Probes * `/.mswai/runtime/mlua-lsp//` for a valid package.json. * `missing` is reported as informational (the user may have opted out via * `--no-mlua-lsp`) and does NOT count toward `issues`. `invalid` (a different * version dir exists, or the expected dir is corrupt) DOES count — that's an * unambiguous "rerun update" signal. */ export interface MluaLspRuntimeStatus extends Check { /** Filesystem path inspected (`.mswai/runtime/mlua-lsp`). */ path: string; /** Version bundled with this mswai release — the dir we expect on disk. */ expectedVersion: string; /** Version actually found on disk when different from `expectedVersion`. */ observedVersion?: string; } /** A single audit-log failure summarized for doctor's output. */ export interface RecentFailure { ts: string; command: string; args: string[]; step?: string; message: string; /** errno-style code (`'ENOENT'`, `'EACCES'`, ...) when available. */ code?: string; /** mswai version that produced the failed entry. */ version?: string; } /** Aggregated view over `.mswai/logs/cli.jsonl` for the doctor banner. * Scans the trailing window of the audit log and reports failures within * the last `windowDays` days. Purely informational — does not affect the * doctor exit code. */ export interface RecentFailures { /** Sliding window length in days. */ windowDays: number; /** True when `.mswai/logs/cli.jsonl` exists at all. */ logPresent: boolean; /** Failure count inside the window. */ count: number; /** Most recent failure entry, if any. */ latest?: RecentFailure; } export interface DoctorResult { /** mswai package version that produced this report. */ version: string; /** Workspace lock status. */ lockHealth: LockHealth; /** AGENTS.md (workspace-root instruction file shared by all agents). */ agentsMd: Check & { path: string; }; /** Vendored mlua-lsp runtime check (banner — `missing` is info-only). */ mluaLspRuntime: MluaLspRuntimeStatus; /** Recent audit-log failures (banner — info-only). */ recentFailures: RecentFailures; agents: AgentDoctorResult[]; /** Total count of non-`ok` checks across all selected agents plus the * shared `agentsMd` row. mluaLspRuntime contributes only when status is * `invalid`; `recentFailures` never contributes. */ issues: number; /** True when two selected agents have different installed versions * (the canonical "user updated only one agent" scenario). Computed * across all known feature×agent stamps, ignoring agents with no * installed entry. */ crossAgentDrift: boolean; /** Distinct installed versions observed across the selected agents. * Empty when no agent has an installed entry. */ installedVersions: string[]; } export interface DoctorOptions { cwd: string; agents: AgentId[]; json: boolean; silent: boolean; /** Disable ANSI colors even when stdout is a TTY. NO_COLOR env var also disables. */ noColor: boolean; } export declare function runDoctor(opts: DoctorOptions): DoctorResult; export declare function parseDoctorArgs(args: string[]): DoctorOptions | { help: true; }; export declare function printDoctorHelp(): void; export declare function doctorCommand(args: string[]): number;