Skip to main content
Glama

Diagnose and Self Heal System Runtime and Codebase Flaws

diagnose_and_heal_system

Diagnoses and repairs workspace health issues like Python syntax errors, missing standard imports, broken virtualenv paths, UTF-8 BOM artifacts, and stale bytecode, reporting before-and-after scores.

Instructions

Diagnoses and automatically repairs environment misconfigurations, virtualenv breakages, syntax errors, missing standard library imports, UTF-8 BOM artifacts, and orphaned bytecode across the workspace, distinguishing from 'heal_hallucinated_code' which strictly corrects phantom AST symbols in code snippets by instead performing holistic system-level health diagnostics and autonomous multi-category file healing.

Parameters:

  • workspace_dir (str, optional, default='.'): Target repository root directory containing source code and environment configurations to diagnose.

  • auto_repair (bool, optional, default=True): When True, applies surgical AST syntax patches, BOM sanitization, and cache cleanup to disk.

  • dry_run (bool, optional, default=False): When True, evaluates diagnostics and previews repair diffs without modifying files on disk.

Behavior:

  • Mutability: Modifies files only when auto_repair=True and dry_run=False; otherwise strictly read-only.

  • Idempotency: Multiple sequential executions converge to a 100% clean state without regressions.

  • Performance & Latency: Scans and repairs 250+ files in <400ms using local standard library AST.

  • Resources: Consumes <50MB RAM; local file system operations only.

  • Privacy: 100% offline local processing; zero external network transmission.

  • Auth & Limits: Zero external credentials or API keys required; zero rate limits.

  • Error Handling: Continues diagnostic sweep across entire workspace if individual files contain unrecoverable binary corruption.

Usage Guidelines:

  • When to use: Use when diagnosing overall workspace health, repairing Python syntax breakages (missing colons, Python 2 print), resolving missing standard imports, fixing virtualenv paths, or clearing stale cache bloat.

  • When NOT to use: Do not use for repairing hallucinated LLM method names in isolated code snippets (use 'heal_hallucinated_code' instead); do not use for static cyclomatic complexity code smell audits (use 'audit_code_quality' instead).

Returns: Formatted Markdown report detailing initial health score, detected defects, surgical patch actions, and final post-healing health score.

Tool call template

This tool declares no required parameters. Add optional parameters from the input schema as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {},
    "name": "diagnose_and_heal_system"
  }
}

Input Schema

NameRequiredDescriptionDefault
dry_runNoWhether to preview repairs without writing to disk (default: False).
auto_repairNoWhether to apply self-healing patches to disk (default: True).
workspace_dirNoTarget repository root directory (default: current directory)..

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv10.6.0

TDQS

A4.2/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The disclosure is otherwise unusually rich (conditional mutability tied to auto_repair/dry_run, error-tolerance on corrupt files, offline processing, no credentials), but it asserts 'Idempotency: Multiple sequential executions converge to a 100% clean state without regressions' while the annotations declare idempotentHint=false. That is a direct conflict on a hint agents may use to decide whether retrying the call is safe, and the description does not reconcile the two.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The identification sentence and the when/when-not guidance are front-loaded, and behavior is broken into labeled bullets, which makes scanning easy. It is longer than necessary in places, repeating schema parameter text verbatim and including performance and privacy metrics of limited use for invocation decisions.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutating, multi-mode tool with three parameters, the definition covers triggers, exclusions, flag interaction, failure behavior, and a return description, and it notes the field-level outcome of a run. Return formatting needs are also satisfied independently by the output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3; the description still adds value by naming the concrete repair classes auto_repair applies (AST syntax patches, BOM sanitization, cache cleanup) and by spelling out the interaction rule that mutation requires auto_repair=True and dry_run=False. All three parameters are also enumerated explicitly with defaults.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Names a specific verb pair and resource scope ('Diagnoses and automatically repairs environment misconfigurations, virtualenv breakages, syntax errors...') and explicitly distinguishes itself from 'heal_hallucinated_code' by contrasting snippet-level symbol repair with holistic system-level healing. An agent can identify the tool's domain without opening the schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides explicit 'When to use' triggers (workspace health, Python syntax breakages, missing imports, virtualenv paths, cache bloat) and an explicit 'When NOT to use' clause routing to two named alternatives, 'heal_hallucinated_code' and 'audit_code_quality'. Nothing about tool selection is left to inference.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.