Skip to content

feat: structured diagnostic output for AI adapter repair#802

Merged
jackwener merged 7 commits intomainfrom
feat/diagnostic-repair
Apr 5, 2026
Merged

feat: structured diagnostic output for AI adapter repair#802
jackwener merged 7 commits intomainfrom
feat/diagnostic-repair

Conversation

@jackwener
Copy link
Copy Markdown
Owner

Summary

Implements the auto-fix mechanism (Phase 1 + Phase 2) discussed in the team thread:

  • Phase 1: Structured diagnostic output — When OPENCLI_DIAGNOSTIC=1, failed commands emit a RepairContext JSON to stderr containing error details, adapter source code, and browser state (DOM snapshot, network requests, console errors). This gives AI Agents the context they need to diagnose and fix broken adapters.

  • Phase 2: Repair skillskills/opencli-repair/SKILL.md guides AI Agents through the 5-step repair workflow: collect diagnostic → analyze failure → explore current website → patch adapter → verify fix.

Key design decisions

  • Runtime only collects context, AI does all judgment — no classifiers, no repairable flags, no auto-retry logic in runtime
  • Diagnostic output uses stderr JSON with delimiters (___OPENCLI_DIAGNOSTIC___) — AI can parse it directly from command output
  • Page state captured inside browserSession — before the session closes, so DOM snapshot and network requests are still available
  • Non-browser commands also emit diagnostic — just without the page state section

Files changed

File Change
src/diagnostic.ts New — RepairContext type, collectDiagnostic(), emitDiagnostic()
src/diagnostic.test.ts New — 8 unit tests for diagnostic module
src/execution.ts Modified — collect and emit diagnostic on failure
skills/opencli-repair/SKILL.md New — AI repair skill guide

Test plan

  • npx tsc --noEmit passes
  • npm test — 523 passed, 1 skipped (44 test files)
  • New diagnostic.test.ts — 8 tests covering isDiagnosticEnabled, buildRepairContext, emitDiagnostic
  • Manual verification: run OPENCLI_DIAGNOSTIC=1 opencli <site> <cmd> on a failing adapter and confirm JSON output

When OPENCLI_DIAGNOSTIC=1 is set, failed commands emit a RepairContext
JSON to stderr containing the error, adapter source, and browser state
(DOM snapshot, network requests, console errors). AI Agents consume
this to diagnose and fix adapters when websites change.

Also adds the opencli-repair skill guide for AI Agents.
The e2e helpers pointed to dist/main.js but the actual build output
is at dist/src/main.js (matching package.json "main" field). This
caused all e2e-headed tests to fail with "Cannot find module".
When browser connection fails before the session callback runs
(e.g., BrowserConnectError), the inner diagnostic catch never fires.
Use a flag to ensure the outer catch emits diagnostic as a fallback.
The Bloomberg Businessweek RSS feed is intermittently unavailable,
causing CI failures unrelated to code changes.
@jackwener jackwener merged commit 664a971 into main Apr 5, 2026
11 of 13 checks passed
@jackwener jackwener deleted the feat/diagnostic-repair branch April 5, 2026 10:06
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