Skip to content

Add doctor lint for agent instruction drift - #441

Merged
mohanagy merged 3 commits into
nextfrom
issue-436-agent-instruction-lint
May 31, 2026
Merged

mohanagy merged 3 commits into
nextfrom
issue-436-agent-instruction-lint

Conversation

@mohanagy

@mohanagy mohanagy commented May 31, 2026 •

Copy link
Copy Markdown
Owner

Closes #436

Summary

  • extend madar doctor / madar status to validate optional Aider, Codex, and OpenCode instruction surfaces when those install artifacts are present
  • reuse the install-layer Codex/OpenCode helpers and document the checked surfaces in README
  • add regression coverage for configured and stale optional-agent profiles, plus the README wording

Verification

  • npm run typecheck
  • npm run build
  • CI=1 npm run test:run
  • npm pack --dry-run

Summary by CodeRabbit

  • New Features

    • madar doctor and madar status now detect and report Aider, Codex, and OpenCode wiring—marking agents as configured or partial and suggesting the appropriate madar <agent> install command when incomplete.
    • Linting extended to AGENTS-based instruction profiles so missing snippets, plugins, or MCP hooks are flagged.
  • Documentation

    • README updated with guidance and an expanded support table showing per-agent doctor/status lint surface and install recommendations.

Closes #436

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented May 31, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 509e746c-90a2-4a79-9535-69d8ea5174bb

📥 Commits

Reviewing files that changed from the base of the PR and between 038456e and 30087f7.

📒 Files selected for processing (2)
  • README.md
  • tests/unit/install-docs.test.ts
✅ Files skipped from review due to trivial changes (1)
  • README.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/unit/install-docs.test.ts

📝 Walkthrough

Walkthrough

This PR extends madar doctor/status to detect and report configuration for Aider, Codex CLI, and OpenCode (skill files, AGENTS.md snippets, Codex hooks, OpenCode plugin/MCP wiring), exports installer helpers for Codex/OpenCode, updates README guidance and support table, and adds unit tests verifying behavior.

Changes

Doctor/Status Extension for Additional Agents

Layer / File(s) Summary
Documentation & User Guidance Updates
README.md, tests/unit/getting-started-docs.test.ts, tests/unit/install-docs.test.ts
README clarifies what madar doctor and madar status verify and adds a lint surface column per agent in the support table. Tests validate these strings.
Public API Surface for Agent Configuration Helpers
src/infrastructure/install.ts
Exports Codex hook detector (isMadarCodexHook), OpenCode identifiers (OPENCODE_PLUGIN_RELATIVE_PATH, OPENCODE_MCP_SERVER_NAME), and OpenCode config readers (resolveOpencodeConfigPath, readOpencodeConfig) for use by doctor.ts.
Doctor Command Type Contracts & Configuration Constants
src/infrastructure/doctor.ts
Adds new agent labels (aider, codex, opencode), path constants for agent skill/config files, and instruction snippet arrays used to lint AGENTS.md and similar guidance.
Doctor Command Validation Helpers & Codex Hook Detection
src/infrastructure/doctor.ts
Implements readText/fileContainsSnippets and findCodexHookEntry to verify instruction snippets and Codex hook wiring.
OpenCode Configuration Detection & Validation
src/infrastructure/doctor.ts
Implements optionalAgentStatus and OpenCode checks for plugin registration, MCP entry presence, and MCP args resolving to the generated graph path.
Doctor Report Building & Agent Configuration Detection
src/infrastructure/doctor.ts
Extends buildDoctorReport to compute configuration states for Aider, Codex, and OpenCode and append agent entries with detail fields reflecting detected components.
Next Command Generation for Agent Install
src/infrastructure/doctor.ts
Adds recommendations for madar aider install, madar codex install, and madar opencode install when agents are incomplete.
Doctor Behavior Test Coverage for Codex & OpenCode
tests/unit/doctor.test.ts
Adds tests and sandbox helpers validating Codex hook detection, OpenCode plugin/MCP wiring, ignoring unrelated configs, partial-state reporting, and reinstall recommendations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • mohanagy/madar#439: README onboarding and getting-started test updates related to doctor/status verification flow.
  • mohanagy/madar#352: Related changes to managed-hook/sentinel logic used by Codex hook detection.

"🐰 A doctor and a hook meet a graph so fine,
Aider, Codex, OpenCode align.
Snippets peek in AGENTS with care,
MCP and plugins everywhere,
Partial states blink — ready to repair!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly describes the main change: adding doctor command linting for agent instruction drift detection.
Description check ✅ Passed Description includes issue reference, summary of changes, and verification steps matching the template structure.
Linked Issues check ✅ Passed Changes fully satisfy #436 requirements: extends doctor/status for optional agents, documents checked surfaces, adds test coverage, and provides actionable fixes.
Out of Scope Changes check ✅ Passed All changes are directly related to extending doctor/status linting for Aider, Codex, and OpenCode instruction validation per issue #436.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-436-agent-instruction-lint

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Comment @coderabbitai help to get the list of available commands and usage tips.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/infrastructure/doctor.ts (1)

58-80: ⚡ Quick win

Consider co-locating instruction snippets with templates or adding alignment tests.

The instruction snippet constants here must stay synchronized with the template strings in install.ts (e.g., AIDER_AGENTS_MD_SECTION, CODEX_AGENTS_MD_SECTION, OPENCODE_AGENTS_MD_SECTION). If someone updates the template wording, they must remember to update these snippets manually. This coupling creates a maintenance risk.

Consider one of these approaches:

  1. Export the snippets from install.ts alongside the templates
  2. Add a test that verifies each snippet is present in its corresponding template
  3. Add a comment documenting this dependency
Example: export snippets from install.ts

In install.ts, add exports near the template definitions:

export const AIDER_INSTRUCTION_SNIPPETS = [
  '### Aider profile',
  'Use a strict context-pack-first workflow',
  'Before broad code search or manual file expansion',
  'madar pack "<task or question>" --task explain',
] as const

Then import in doctor.ts:

 import {
+  AIDER_INSTRUCTION_SNIPPETS,
+  CODEX_INSTRUCTION_SNIPPETS,
   OPENCODE_MCP_SERVER_NAME,
+  OPENCODE_INSTRUCTION_SNIPPETS,
   OPENCODE_PLUGIN_RELATIVE_PATH,
   isMadarCodexHook,
   readOpencodeConfig,
   resolveOpencodeConfigPath,
 } from './install.js'
-
-const AIDER_INSTRUCTION_SNIPPETS = [...]
-const CODEX_INSTRUCTION_SNIPPETS = [...]
-const OPENCODE_INSTRUCTION_SNIPPETS = [...]
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/infrastructure/doctor.ts` around lines 58 - 80, The instruction snippets
in doctor.ts (AIDER_INSTRUCTION_SNIPPETS, CODEX_INSTRUCTION_SNIPPETS,
OPENCODE_INSTRUCTION_SNIPPETS) must be kept in sync with the template strings in
install.ts (AIDER_AGENTS_MD_SECTION, CODEX_AGENTS_MD_SECTION,
OPENCODE_AGENTS_MD_SECTION); to fix, move/export the snippet arrays from
install.ts alongside those template constants and import them into
src/infrastructure/doctor.ts instead of declaring duplicate arrays there (update
any references around AIDER_SKILL_PATH, CODEX_SKILL_PATH, OPENCODE_SKILL_PATH to
use the imported snippet constants), or alternatively add a unit test that
asserts each snippet element exists in its corresponding template constant to
prevent drift.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Around line 237-240: Table cells contain literal pipe characters (e.g., in the
command strings like "madar claude <install|uninstall> [--profile
core|full|strict]", "madar cursor <install|uninstall> [--profile
core|full|strict]", "madar copilot <install|uninstall> [--profile
core|full|strict]", and "madar gemini <install|uninstall> [--profile
core|full|strict]") which break Markdown table parsing (MD056); fix by escaping
each '|' inside those cells (replace '|' with '\|') so the entries render as a
single cell and update the rows referencing CLAUDE.md, .cursor/rules/madar.mdc,
.vscode/mcp.json, and GEMINI.md as needed.

---

Nitpick comments:
In `@src/infrastructure/doctor.ts`:
- Around line 58-80: The instruction snippets in doctor.ts
(AIDER_INSTRUCTION_SNIPPETS, CODEX_INSTRUCTION_SNIPPETS,
OPENCODE_INSTRUCTION_SNIPPETS) must be kept in sync with the template strings in
install.ts (AIDER_AGENTS_MD_SECTION, CODEX_AGENTS_MD_SECTION,
OPENCODE_AGENTS_MD_SECTION); to fix, move/export the snippet arrays from
install.ts alongside those template constants and import them into
src/infrastructure/doctor.ts instead of declaring duplicate arrays there (update
any references around AIDER_SKILL_PATH, CODEX_SKILL_PATH, OPENCODE_SKILL_PATH to
use the imported snippet constants), or alternatively add a unit test that
asserts each snippet element exists in its corresponding template constant to
prevent drift.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1cfe848e-4fbd-4357-94e5-778194305618

📥 Commits

Reviewing files that changed from the base of the PR and between aeb59cc and 00deadf.

📒 Files selected for processing (6)
  • README.md
  • src/infrastructure/doctor.ts
  • src/infrastructure/install.ts
  • tests/unit/doctor.test.ts
  • tests/unit/getting-started-docs.test.ts
  • tests/unit/install-docs.test.ts

Comment thread README.md Resolved
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.

1 participant