| name | qiaomu-opencli-autofix |
| description | Automatically fix broken OpenCLI adapters when commands fail. Load this skill when an opencli command fails โ it guides you through diagnosing the failure via OPENCLI_DIAGNOSTIC, patching the adapter, and retrying. Works with any AI agent. |
| author | joeseesun |
| upstream | jackwener/opencli |
| allowed-tools | Bash(opencli:*), Read, Edit, Write |
OpenCLI AutoFix โ Automatic Adapter Self-Repair
When an opencli command fails because a website changed its DOM, API, or response schema, automatically diagnose, fix the adapter, and retry โ don't just report the error.
Safety Boundaries
Before starting any repair, check these hard stops:
AUTH_REQUIRED (exit code 77) โ STOP. Do not modify code. Tell the user to log into the site in Chrome.
BROWSER_CONNECT (exit code 69) โ STOP. Do not modify code. Tell the user to run opencli doctor.
- CAPTCHA / rate limiting โ STOP. Not an adapter issue.
Scope constraint:
- Only modify the file at
RepairContext.adapter.sourcePath โ this is the authoritative adapter location (may be clis/<site>/ in repo or ~/.opencli/clis/<site>/ for npm installs)
- Never modify
src/, extension/, tests/, package.json, or tsconfig.json
Retry budget: Max 3 repair rounds per failure. If 3 rounds of diagnose โ fix โ retry don't resolve it, stop and report what was tried.
Prerequisites
opencli doctor
When to Use This Skill
Use when opencli <site> <command> fails with repairable errors:
- SELECTOR โ element not found (DOM changed)
- EMPTY_RESULT โ no data returned (API response changed)
- API_ERROR / NETWORK โ endpoint moved or broke
- PAGE_CHANGED โ page structure no longer matches
- COMMAND_EXEC โ runtime error in adapter logic
- TIMEOUT โ page loads differently, adapter waits for wrong thing
Before Entering Repair: "Empty" โ "Broken"
EMPTY_RESULT โ and sometimes a structurally-valid SELECTOR that returns nothing โ is often not an adapter bug. Platforms actively degrade results under anti-scrape heuristics, and a "not found" response from the site doesn't mean the content is actually missing. Rule this out before committing to a repair round:
- Retry with an alternative query or entry point. If
opencli xiaohongshu search "X" returns 0 but opencli xiaohongshu search "X ๆป็ฅ" returns 20, the adapter is fine โ the platform was shaping results for the first query.
- Spot-check in a normal Chrome tab. If the data is visible in the user's own browser but the adapter comes back empty, the issue is usually authentication state, rate limiting, or a soft block โ not a code bug. The fix is
opencli doctor / re-login, not editing source.
- Look for soft 404s. Sites like xiaohongshu / weibo / douyin return HTTP 200 with an empty payload instead of a real 404 when an item is hidden or deleted. The snapshot will look structurally correct. A retry 2-3 seconds later often distinguishes "temporarily hidden" from "actually gone".
- "0 results" from a search is an answer. If the adapter successfully reached the search endpoint, got an HTTP 200, and the platform returned
results: [], that is a valid answer โ report it to the user as "no matches for this query" rather than patching the adapter.
Only proceed to Step 1 if the empty/selector-missing result is reproducible across retries and alternative entry points. Otherwise you're patching a working adapter to chase noise, and the patched version will break the next working path.
Step 1: Collect Diagnostic Context
Run the failing command with diagnostic mode enabled:
OPENCLI_DIAGNOSTIC=1 opencli <site> <command> [args...] 2>diagnostic.json
This outputs a RepairContext JSON between ___OPENCLI_DIAGNOSTIC___ markers in stderr:
{
"error": {
"code": "SELECTOR",
"message": "Could not find element: .old-selector",
"hint": "The page UI may have changed."
},
"adapter": {
"site": "example",
"command": "example/search",
"sourcePath": "/path/to/clis/example/search.ts",
"source": "// full adapter source code"
},
"page": {
"url": "https://example.com/search",
"snapshot": "// DOM snapshot with [N] indices",
"networkRequests": [],
"consoleErrors": []
},
"timestamp": "2025-01-01T00:00:00.000Z"
}
Parse it:
cat diagnostic.json | sed -n '/___OPENCLI_DIAGNOSTIC___/{n;p;}'
Step 2: Analyze the Failure
Read the diagnostic context and the adapter source. Classify the root cause:
| Error Code | Likely Cause | Repair Strategy |
|---|
| SELECTOR | DOM restructured, class/id renamed | Explore current DOM โ find new selector |
| EMPTY_RESULT | API response schema changed, or data moved | Check network โ find new response path |
| API_ERROR | Endpoint URL changed, new params required | Discover new API via network intercept |
| AUTH_REQUIRED | Login flow changed, cookies expired | STOP โ tell user to log in, do not modify code |
| TIMEOUT | Page loads differently, spinner/lazy-load | Add/update wait conditions |
| PAGE_CHANGED | Major redesign | May need full adapter rewrite |
Key questions to answer:
- What is the adapter trying to do? (Read the
source field)
- What did the page look like when it failed? (Read the
snapshot field)
- What network requests happened? (Read
networkRequests)
- What's the gap between what the adapter expects and what the page provides?
Step 3: Explore the Current Website
Use opencli browser to inspect the live website. Never use the broken adapter โ it will just fail again.
DOM changed (SELECTOR errors)
opencli browser open https://example.com/target-page && opencli browser state
API changed (API_ERROR, EMPTY_RESULT)
opencli browser open https://example.com/target-page && opencli browser state
opencli browser click <N> && opencli browser network
opencli browser network --detail <index>
Step 4: Patch the Adapter
Read the adapter source file at the path from RepairContext.adapter.sourcePath and make targeted fixes. This path is authoritative โ it may be in the repo (clis/) or user-local (~/.opencli/clis/).
cat <RepairContext.adapter.sourcePath>
Common Fixes
Selector update:
API endpoint change:
Response schema change:
Wait condition update:
Rules for Patching
- Make minimal changes โ fix only what's broken, don't refactor
- Keep the same output structure โ
columns and return format must stay compatible
- Prefer API over DOM scraping โ if you discover a JSON API during exploration, switch to it
- Use
@jackwener/opencli/* imports only โ never add third-party package imports
- Test after patching โ run the command again to verify
Step 5: Verify the Fix
opencli <site> <command> [args...]
If it still fails, go back to Step 1 and collect fresh diagnostics. You have a budget of 3 repair rounds (diagnose โ fix โ retry). If the same error persists after a fix, try a different approach. After 3 rounds, stop and report what was tried.
When to Stop
Hard stops (do not modify code):
- AUTH_REQUIRED / BROWSER_CONNECT โ environment issue, not adapter bug
- Site requires CAPTCHA โ can't automate this
- Rate limited / IP blocked โ not an adapter issue
Soft stops (report after attempting):
- 3 repair rounds exhausted โ stop, report what was tried and what failed
- Feature completely removed โ the data no longer exists
- Major redesign โ needs full adapter rewrite via
opencli-explorer skill
In all stop cases, clearly communicate the situation to the user rather than making futile patches.
Example Repair Session
1. User runs: opencli zhihu hot
โ Fails: SELECTOR "Could not find element: .HotList-item"
2. AI runs: OPENCLI_DIAGNOSTIC=1 opencli zhihu hot 2>diag.json
โ Gets RepairContext with DOM snapshot showing page loaded
3. AI reads diagnostic: snapshot shows the page loaded but uses ".HotItem" instead of ".HotList-item"
4. AI explores: opencli browser open https://www.zhihu.com/hot && opencli browser state
โ Confirms new class name ".HotItem" with child ".HotItem-content"
5. AI patches: Edit adapter at RepairContext.adapter.sourcePath โ replace ".HotList-item" with ".HotItem"
6. AI verifies: opencli zhihu hot
โ Success: returns hot topics