Skip to content

feat: Self-Repair protocol for automatic adapter fixing#866

Merged
jackwener merged 7 commits intomainfrom
feat/self-repair-protocol
Apr 7, 2026
Merged

feat: Self-Repair protocol for automatic adapter fixing#866
jackwener merged 7 commits intomainfrom
feat/self-repair-protocol

Conversation

@jackwener
Copy link
Copy Markdown
Owner

Summary

When an AI agent uses opencli and a command fails due to a site change, the agent automatically diagnoses the failure, fixes the adapter, and retries — without human intervention or pre-written spec files.

This is the Self-Repair MVP, a simpler alternative to the spec/runner framework in PR #863. Instead of requiring pre-authored command specs, the command itself is the spec — the agent just retries it after fixing.

Supersedes the direction of #863 (which is deferred to Phase 2 as an "asset/hardening layer").

Changes

  • CLAUDE.md (new) — Project-level agent instructions with Self-Repair protocol. Auto-loaded by Claude Code sessions.
  • designs/self-repair-protocol.md (new) — Design document explaining the approach.
  • skills/opencli-repair/SKILL.md (updated) — Added Safety Boundaries section: AUTH/BROWSER → STOP, sourcePath-only scope, max 3 repair rounds. Fixed AUTH_REQUIRED guidance.
  • skills/opencli-usage/SKILL.md (updated) — Added Self-Repair section + reference to repair skill.

Key design decisions

  • Repair target is always RepairContext.adapter.sourcePath (works for both repo-local clis/ and user-local ~/.opencli/clis/)
  • Only adapter files may be modified, never core src/
  • Max 3 repair rounds per failure
  • AUTH_REQUIRED and BROWSER_CONNECT are hard stops (report to user, don't modify code)
  • No new runtime code — leverages existing diagnostic infrastructure (src/diagnostic.ts)

Scope clarification

This PR establishes the Self-Repair protocol as a repo-local workflow for Claude agents working in the opencli repo. For the broader "any AI agent using opencli anywhere" scenario, the updated opencli-repair skill serves as the portable mechanism (agents can load it explicitly). A runtime trigger layer (e.g., --auto-repair flag in execution.ts) is a potential Phase 2 addition.

Test plan

  • Verify CLAUDE.md loads automatically in a new Claude Code session in the opencli repo
  • Verify opencli-repair skill Safety Boundaries section is consistent with CLAUDE.md
  • Verify RepairContext.adapter.sourcePath resolves correctly for both repo and ~/.opencli/clis/ adapters

When an AI agent uses opencli and a command fails, the agent
automatically diagnoses the failure, fixes the adapter, and retries.

- Add CLAUDE.md with Self-Repair protocol (auto-loaded by Claude Code)
- Add designs/self-repair-protocol.md documenting the approach
- Update opencli-repair skill: add Safety Boundaries (AUTH/BROWSER → STOP,
  sourcePath-only scope, max 3 rounds), fix AUTH_REQUIRED guidance
- Update opencli-usage skill: add Self-Repair section

Key design decisions:
- Repair target is always RepairContext.adapter.sourcePath (works for both
  repo-local clis/ and user-local ~/.opencli/clis/)
- Only adapter files may be modified, never core src/
- Max 3 repair rounds per failure
- AUTH_REQUIRED and BROWSER_CONNECT are hard stops (report, don't modify)
- Remove "Auth changed (AUTH_REQUIRED)" exploration section from
  opencli-repair skill — contradicted the hard stop rule above it
- Update design doc: scope language matches repo-local + explicit skill
  delivery model, not universal product behavior
- Update usage skill: reference sourcePath instead of "files under clis/"
CLAUDE.md was wrong — users don't work inside the opencli repo, and
the protocol shouldn't assume Claude Code. The skill is the portable
delivery mechanism for any AI agent.

- Rename skills/opencli-repair → skills/opencli-autofix
- Remove CLAUDE.md (not the right delivery mechanism)
- Update all references in usage skill and design doc
- Design doc rewritten to reflect skill-first approach
When a command fails with a repairable error (SELECTOR, EMPTY_RESULT,
COMMAND_EXEC, or generic http/not-found), the error output now includes
a hint telling agents to re-run with OPENCLI_DIAGNOSTIC=1 for repair
context. This is the trigger mechanism that bridges the gap between
"command failed" and "agent enters autofix loop".

Non-repairable errors (AUTH_REQUIRED, BROWSER_CONNECT, ARGUMENT) do not
emit the hint — these require user action, not adapter fixes.
Remove hint from CommandExecutionError (covers env/launcher/runtime
issues, not adapter drift) and generic http errors (often temporary
site issues). Keep hint only for SelectorError, EmptyResultError,
and generic not-found — clear adapter-drift signals.
@jackwener jackwener merged commit 56d15d1 into main Apr 7, 2026
11 checks passed
@jackwener jackwener deleted the feat/self-repair-protocol branch April 7, 2026 15:00
@jackwener jackwener mentioned this pull request Apr 8, 2026
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