Date: 2026-04-03
Status: Planning Complete — Ready for Implementation
Repository: /Users/a523034406/Documents/OpenCode/AIICU/
OpenClaw frequently becomes unusable due to:
- Configuration corruption or invalid settings
- Plugin installation failures or compatibility issues
- Version upgrades breaking existing setups
- Daemon/gateway crashes
- Credential problems
- Channel connectivity failures
When users have only one OpenClaw instance and it breaks, they cannot use another agent to fix it — resulting in a helpless situation. ClawICU solves this by providing a self-contained emergency rescue system.
ClawICU provides two rescue mechanisms:
-
One-line rescue:
curl -fsSL https://clawicu.ai/r | sh- Interactive, guided terminal script
- Downloads and runs on the broken machine
- No dependencies beyond basic UNIX tools
-
Offline package:
clawicu-rescue-v1.0.0.tar.gz- Downloadable complete rescue bundle
- Works on machines with limited connectivity
- Transfer via USB/scp when needed
Supports all installation methods: npm global, Docker, Podman, source build
┌──────────────────────────────────────────────────────────────────────────┐
│ ClawICU System │
│ │
│ ┌─────────────────────┐ ┌────────────────────┐ ┌──────────────────┐│
│ │ Cloudflare Pages │ │ Cloudflare Workers │ │ Cloudflare R2 ││
│ │ (Next.js SSG) │ │ (Edge Functions) │ │ (Asset Storage) ││
│ │ clawicu.ai │ │ /api/v1/ │ │ rescue.sh ││
│ │ │ │ rescue-script │ │ checksums.txt ││
│ │ │ │ check-version │ │ *.tar.gz ││
│ └─────────────────────┘ └────────────────────┘ └──────────────────┘│
└──────────────────────────────────────────────────────────────────────────┘
User's Broken Machine:
curl -fsSL https://clawicu.ai/r | sh
│
▼
┌─────────────────────────────────────────────────────┐
│ rescue.sh (POSIX sh, self-contained) │
│ │
│ Phase 1: Doctor Delegation (try openclaw doctor) │
│ Phase 2: Standalone Checks (17 check modules) │
│ Phase 3: Merge & Triage (FATAL/WARN/INFO) │
│ Phase 4: Interactive Repair Menu │
│ Phase 5: Execute Repairs (with rollback safety) │
│ Phase 6: Verify & Report │
└─────────────────────────────────────────────────────┘
- Detect OS (macOS/Linux), architecture (x86_64/arm64)
- Detect shell capabilities (POSIX sh / bash 3.x / bash 4+)
- Detect install method (npm global / Docker / Podman / source build)
- Detect Docker/Podman context (is OpenClaw running inside a container?)
- Create temp working directory with trap cleanup
- Initialize logging
- Download modules from CDN (or use bundled if offline)
- Try
openclaw doctor— if binary works, parse its output - Try
openclaw --version— record version for version-aware checks - On success: capture issues from doctor output
- On failure: record error, proceed to Phase 2
Run 17 independent check modules:
| Check | Severity | Detects |
|---|---|---|
check-binary |
🔴 Fatal | Binary missing or not executable |
check-node |
🔴 Fatal | Node.js < 22.12 |
check-install-method |
🟡 Warn | Installation type (npm/Docker/Podman/source) |
check-docker |
🟡 Warn | Docker/Podman container issues (if applicable) |
check-state-dir |
🔴 Fatal | ~/.openclaw/ missing or permissions broken |
check-config |
🔴 Fatal | config.json5 invalid JSON5 (must handle JSON5, not plain JSON) |
check-config-schema |
🟡 Warn | Config fields invalid (port, auth, etc.) |
check-credentials |
🟡 Warn | Provider API keys missing or empty |
check-gateway |
🔴 Fatal | Gateway not running on port 18789 |
check-daemon |
🟡 Warn | launchd/systemd service not installed |
check-plugins |
🟡 Warn | Plugin manifests broken or load errors |
check-port |
🔴 Fatal | Port 18789 occupied by another process |
check-disk |
🟡 Warn | < 100MB free disk |
check-sessions |
🔵 Info | Session files corrupted |
check-version |
🟡 Warn | OpenClaw version unsupported |
check-envvars |
🔵 Info | Conflicting OPENCLAW_* env vars |
check-exec-approvals |
🔵 Info | exec-approvals.json unparseable |
- Combine doctor output + standalone check results
- Deduplicate overlapping issues
- Cross-validate conflicting results
- Classify severity: 🔴 FATAL / 🟡 WARN / 🔵 INFO
- Prioritize: fatal first, then warnings
Interactive menu with repair options:
┌─────────────────────────────────────────────────────┐
│ ClawICU — Issues Found: 3 │
│ │
│ 🔴 FATAL: Config file has invalid JSON5 │
│ 🟡 WARN: Gateway not running │
│ 🟡 WARN: Daemon service not installed │
│ │
│ [a] Fix all automatically (recommended) │
│ [1] Fix: Config file │
│ [2] Fix: Gateway (restart) │
│ [3] Fix: Daemon service (reinstall) │
│ [s] Safe mode (disable all plugins) │
│ [r] Full state reset (preserve credentials) │
│ [R] Clean reinstall │
│ [e] Export diagnostic report │
│ [q] Quit │
└─────────────────────────────────────────────────────┘
For each selected repair:
- Describe what will happen (dry-run output)
- Prompt for confirmation
- Create timestamped backup (tar.gz)
- Execute repair
- Verify repair succeeded
- On failure: auto-rollback to previous state
- Re-run Phase 2 checks to confirm fix
- Generate summary report:
- What was broken
- What was fixed
- What still needs attention
- Backup location
- Rollback instructions
- Write report to
~/.openclaw/clawicu-report.*
| Repair | Risk | Preserves Data |
|---|---|---|
repair-config |
🟢 Low | Yes — restores from .bak |
repair-config-field |
🟢 Low | Yes — resets individual fields |
repair-gateway |
🟡 Medium | Yes — restart only |
repair-daemon |
🟡 Medium | Yes — reinstalls service |
repair-credentials |
🟢 Low | Yes — only prompts for missing |
repair-plugins |
🟢 Low | Yes — disables, records disabled |
repair-sessions |
🟡 Medium | Partial — removes corrupted only |
repair-downgrade |
🟡 Medium | Yes — reinstalls older version |
repair-nuclear |
🔴 High | Partial — preserves credentials |
repair-reinstall |
🔴 High | No — full backup first |
repair-port |
🟢 Low | Yes |
repair-docker |
🟡 Medium | Yes — restart container, recreate volumes |
| Route | Purpose |
|---|---|
/ |
Hero: one-click rescue command + common issues |
/rescue |
Interactive step-by-step rescue guide |
/docs |
Issue encyclopedia index |
/docs/[slug] |
Individual issue diagnosis + fix guide |
/download |
Offline package download |
/api/v1/rescue-script |
Edge: dynamic personalized script generation |
/api/v1/check-version |
Edge: version compatibility check |
AIICU/
├── CLAWICU_PLAN.md # This document
│
├── src/ # Next.js 15 website (Tailwind + shadcn/ui)
│ ├── app/
│ │ ├── page.tsx # Landing page
│ │ ├── rescue/page.tsx # Guided rescue
│ │ ├── docs/[slug]/page.tsx # Issue guides (MDX)
│ │ ├── download/page.tsx # Offline package
│ │ └── api/v1/
│ │ ├── rescue-script/route.ts
│ │ └── check-version/route.ts
│ ├── components/
│ │ ├── Hero.tsx
│ │ ├── RescueCommand.tsx
│ │ ├── OSDetector.tsx
│ │ └── ...
│ └── content/issues/ # 15 MDX docs
│
├── rescue/ # Rescue script source
│ ├── rescue.sh # Main entry point
│ ├── lib/
│ │ ├── bootstrap.sh # OS/shell detection
│ │ ├── log.sh # Structured logging
│ │ ├── ui.sh # Menu/prompt/spinner
│ │ ├── backup.sh # tar.gz backup engine
│ │ ├── state.sh # Rollback state machine
│ │ └── verify.sh # SHA256 verification
│ ├── checks/ # 17 check-*.sh modules
│ └── repairs/ # 12 repair-*.sh modules
│
├── scripts/
│ ├── build-rescue.sh # Bundle into single .sh
│ ├── package-offline.sh # Create .tar.gz
│ └── generate-checksums.sh # SHA256 checksums
│
└── tests/
├── unit/ # Per-module tests
├── integration/ # Multi-module flows
└── e2e/ # Docker-based scenarios
| Layer | Implementation |
|---|---|
| Transport | TLS 1.2+ enforced; curl --proto '=https' --tlsv1.2 |
| Integrity | SHA256 checksums published alongside every deliverable |
| Two-step pattern | Download → Verify checksum → Run |
| Backup before repair | Every destructive action creates timestamped tar.gz backup; leverage existing openclaw backup command when available |
| Install-method awareness | Rescue flow adapts based on npm/Docker/Podman/source install |
| Rollback on failure | State machine auto-rolls back if verification fails |
| Dry-run mode | --dry-run shows what would happen without executing |
| Credential protection | API keys never logged or reported |
| Minimal telemetry | Opt-in only, anonymous, no personal data |
| Level | Coverage | Approach |
|---|---|---|
| Unit | 80% | Per-module tests; POSIX shell assert helpers |
| Integration | 15% | Multi-module flows (diagnose → repair → verify) |
| E2E | 5% | Docker containers with intentionally broken setups |
| Scenario | What's Broken | Expected Fix |
|---|---|---|
test-broken-config |
Invalid JSON config | Restore from backup |
test-broken-plugin |
Malformed plugin manifest | Disable plugin |
test-no-gateway |
Gateway not started | Start gateway |
test-no-daemon |
No launchd/systemd plist | Install daemon |
test-port-conflict |
Port 18789 occupied | Resolve conflict |
test-clean-install |
Nothing broken | All checks pass |
Cloudflare Pages → clawicu.ai (Next.js SSG)
Cloudflare Workers → /api/v1/* edge functions
Cloudflare R2 → rescue.sh, checksums.txt, *.tar.gz
GitHub Actions
├── Push → CI (shellcheck + tests + build)
├── Tag → Release (publish to R2 + Pages)
└── Weekly → Test against latest OpenClaw version
- Scaffold Next.js project with Tailwind + shadcn/ui
- Landing page hero with copy-paste command
- Test framework and fixtures
- Bootstrap, logging, and UI modules
- Backup engine with create/restore/verify
- State machine for rollback tracking
check-binary+check-nodecheck-config+check-config-schemacheck-gateway+check-port+check-daemon- All remaining checks (credentials, plugins, disk, sessions, version, envvars, exec-approvals)
repair-config(restore from backup)repair-gateway+repair-daemonrepair-plugins+repair-credentialsrepair-nuclear+repair-reinstall+ remaining repairs
- Doctor delegation pipeline
- Full diagnostic engine with interactive menu
- Repair execution with rollback and verification
- Build scripts for bundling and checksums
- Offline package builder
- Docs pages with issue encyclopedia (MDX)
- Download page with OS detection
- Guided rescue page
- API routes for dynamic script and version check
- CI pipeline (lint, test, build)
- Release workflow and scheduled tests
| Decision | Choice | Rationale |
|---|---|---|
| Script language | POSIX sh + bash fallback | macOS has bash 3.2; strict POSIX = max compatibility |
| Hosting | Cloudflare Pages + Workers + R2 | Edge functions for dynamic script; free tier sufficient |
| Config validation | Embedded simplified JSON5 parser | OpenClaw uses JSON5 (not plain JSON); must handle trailing commas, comments, unquoted keys |
| Backup format | tar.gz + manifest | Standard, verifiable, restorable |
| Test framework | Custom POSIX assert helpers | No bats/shunit2 — fully self-contained |
| Install method detection | Early bootstrap check | Rescue flow must adapt (npm vs Docker vs Podman vs source) |
Leverage openclaw backup |
When binary works | Use existing backup command before custom backup logic |
detect_shell_capabilities()
│
├── bash >= 4.x → arrays, [[ ]], local, enhanced progress bars
├── bash 3.x → basic arrays, [[ ]], no mapfile (macOS default)
├── dash/POSIX sh → no arrays, [ ] test only, minimal UI
└── Unknown → treat as POSIX sh (safest fallback)
- If
openclaw doctorsucceeds → Use its diagnostics (most accurate) - If
openclaw doctorfails → Capture error, run standalone checks - If
openclawbinary missing → Standalone checks only - Merge results into unified triage view
clawicu-rescue-v1.0.0.tar.gz
├── rescue.sh # Main script (works offline)
├── lib/ # All utility modules
├── checks/ # All check modules
├── repairs/ # All repair modules
├── VERSION # Package version
└── SHA256SUMS # Self-integrity check
| Component | Path/Command | Key Details |
|---|---|---|
| State directory | ~/.openclaw/ |
Configurable via OPENCLAW_STATE_DIR |
| Config file | config.json5 |
JSON5 format with Zod schema validation |
| Credentials | ~/.openclaw/credentials/ + secrets subsystem |
Provider API keys via OpenClaw's secret resolution pipeline |
| Gateway | Port 18789 | Health check endpoint |
| Daemon (macOS) | ~/Library/LaunchAgents/ |
launchd plist |
| Daemon (Linux) | ~/.config/systemd/user/ |
systemd unit |
| CLI commands | openclaw doctor, onboard, gateway, plugins |
Diagnostic tools |
| Node requirement | >= 22.12 | OpenClaw minimum |
To begin implementation:
- User confirms plan — approve or request modifications
- Phase A begins — scaffold Next.js project, create landing page
- Parallel workstreams — shell scripts + website developed simultaneously
- Continuous testing — TDD approach throughout
Plan created through deep analysis of OpenClaw source code (github.com/openclaw/openclaw) and official documentation (docs.openclaw.ai).