Loading...
Loading...
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.
npx skill4agent add jackwener/opencli opencli-autofixopencliAUTH_REQUIREDBROWSER_CONNECTopencli doctorRepairContext.adapter.sourcePathclis/<site>/~/.opencli/clis/<site>/src/extension/tests/package.jsontsconfig.jsonopencli doctor # Verify extension + daemon connectivityopencli <site> <command>OPENCLI_DIAGNOSTIC=1 opencli <site> <command> [args...] 2>diagnostic.jsonRepairContext___OPENCLI_DIAGNOSTIC___{
"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"
}# Extract JSON between markers from stderr output
cat diagnostic.json | sed -n '/___OPENCLI_DIAGNOSTIC___/{n;p;}'| 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 |
sourcesnapshotnetworkRequestsopencli operate# Open the page and inspect current DOM
opencli operate open https://example.com/target-page && opencli operate state
# Look for elements that match the adapter's intent
# Compare the snapshot with what the adapter expects# Open page with network interceptor, then trigger the action manually
opencli operate open https://example.com/target-page && opencli operate state
# Interact to trigger API calls
opencli operate click <N> && opencli operate network
# Inspect specific API response
opencli operate network --detail <index>RepairContext.adapter.sourcePathclis/~/.opencli/clis/# Read the adapter (use the exact path from diagnostic)
cat <RepairContext.adapter.sourcePath>// Before: page.evaluate('document.querySelector(".old-class")...')
// After: page.evaluate('document.querySelector(".new-class")...')// Before: const resp = await page.evaluate(`fetch('/api/v1/old-endpoint')...`)
// After: const resp = await page.evaluate(`fetch('/api/v2/new-endpoint')...`)// Before: const items = data.results
// After: const items = data.data.items // API now nests under "data"// Before: await page.waitForSelector('.loading-spinner', { hidden: true })
// After: await page.waitForSelector('[data-loaded="true"]')columns@jackwener/opencli/*# Run the command normally (without diagnostic mode)
opencli <site> <command> [args...]opencli-explorer1. 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 operate open https://www.zhihu.com/hot && opencli operate 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