Class: LcpRuby::Tasks::Doctor

Inherits:
Object
  • Object
show all
Defined in:
lib/lcp_ruby/tasks/doctor.rb

Overview

Diagnostic checker for an LCP-installed host app. Four sections:

  1. Install manifest replay — ‘tmp/lcp_ruby/install_manifest.json` from `lcp new`

  2. Feature state — registry × ‘config/lcp_ruby/models/`

  3. Environment — BUNDLE_GEMFILE leak, missing .envrc

  4. Seed hygiene — ‘db/seeds.rb` + `LcpRuby::Current.user`

  5. Agent affordances — CLAUDE.md/AGENTS.md managed block, lcp-* skills

Severity: :error (blocks install/runs), :warning (degraded), :info. Output formats: text (default), json, summary. Exit codes: 0 on no-error, 1 otherwise; ‘EXIT_ON=warning` upgrades warnings to errors.

JSON output schema (FORMAT=json) — stable for CI consumption:

{
  "findings": [
    {
      "severity": "error" | "warning" | "info",
      "section":  "install_manifest" | "feature_state" |
                  "environment" | "seeds_hygiene" |
                  "agent_affordances",
      "message":  String,           // human-readable description
      "hint":     String | null     // optional remediation step
    },
    …
  ],
  "summary": { "error": Integer, "warning": Integer, "info": Integer }
}

Stability contract: section names are stable, severity values are stable. New sections may be added; existing ones won’t be renamed without a manifest_version bump. Severity strings are JSON-friendly (the internal symbol form is converted at emit time).

Defined Under Namespace

Classes: Finding

Constant Summary collapse

VALID_FORMATS =
%i[text json summary].freeze
VALID_EXIT_ONS =
%i[error warning].freeze

Instance Method Summary collapse

Constructor Details

#initialize(destination_root: Dir.pwd, format: :text, exit_on: :error, output: $stdout) ⇒ Doctor

Returns a new instance of Doctor.



48
49
50
51
52
53
54
55
# File 'lib/lcp_ruby/tasks/doctor.rb', line 48

def initialize(destination_root: Dir.pwd, format: :text, exit_on: :error, output: $stdout)
  @destination_root = destination_root
  @format           = format.to_sym
  @exit_on          = exit_on.to_sym
  @output           = output
  @findings         = []
  validate_options!
end

Instance Method Details

#exit_codeObject



67
68
69
70
# File 'lib/lcp_ruby/tasks/doctor.rb', line 67

def exit_code
  threshold = @exit_on == :warning ? %i[error warning] : %i[error]
  @findings.any? { |f| threshold.include?(f.severity) } ? 1 : 0
end

#runObject



57
58
59
60
61
62
63
64
65
# File 'lib/lcp_ruby/tasks/doctor.rb', line 57

def run
  check_install_manifest
  check_feature_state
  check_environment
  check_seeds_hygiene
  check_agent_affordances
  emit
  exit_code
end