easyclaw 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. easyclaw-0.1.0/.github/workflows/ci.yml +30 -0
  2. easyclaw-0.1.0/.github/workflows/publish.yml +53 -0
  3. easyclaw-0.1.0/.gitignore +37 -0
  4. easyclaw-0.1.0/CHANGELOG.md +16 -0
  5. easyclaw-0.1.0/CLAUDE.md +322 -0
  6. easyclaw-0.1.0/Dockerfile +33 -0
  7. easyclaw-0.1.0/EasyClaw 2.0 PRD.md +52 -0
  8. easyclaw-0.1.0/EasyClaw_Build_Plan.md +137 -0
  9. easyclaw-0.1.0/PKG-INFO +158 -0
  10. easyclaw-0.1.0/README.md +124 -0
  11. easyclaw-0.1.0/easyclaw-mcp-whitepaper.md +371 -0
  12. easyclaw-0.1.0/install.sh +441 -0
  13. easyclaw-0.1.0/mcp-server/Dockerfile +25 -0
  14. easyclaw-0.1.0/mcp-server/checklists.py +335 -0
  15. easyclaw-0.1.0/mcp-server/config_templates.py +517 -0
  16. easyclaw-0.1.0/mcp-server/db.py +402 -0
  17. easyclaw-0.1.0/mcp-server/error_patterns.py +643 -0
  18. easyclaw-0.1.0/mcp-server/knowledge/docs/configuration.md +39 -0
  19. easyclaw-0.1.0/mcp-server/knowledge/known-issues/connection-refused.md +41 -0
  20. easyclaw-0.1.0/mcp-server/knowledge/known-issues/dns-failure.md +37 -0
  21. easyclaw-0.1.0/mcp-server/knowledge/known-issues/heap-out-of-memory.md +46 -0
  22. easyclaw-0.1.0/mcp-server/knowledge/known-issues/session-bloat.md +32 -0
  23. easyclaw-0.1.0/mcp-server/models_catalog.py +446 -0
  24. easyclaw-0.1.0/mcp-server/n8n-knowledge-updater.json +406 -0
  25. easyclaw-0.1.0/mcp-server/requirements.txt +1 -0
  26. easyclaw-0.1.0/mcp-server/seed_knowledge.py +1294 -0
  27. easyclaw-0.1.0/mcp-server/server.py +778 -0
  28. easyclaw-0.1.0/pyproject.toml +58 -0
  29. easyclaw-0.1.0/src/easyclaw/__init__.py +3 -0
  30. easyclaw-0.1.0/src/easyclaw/__main__.py +6 -0
  31. easyclaw-0.1.0/src/easyclaw/agent.py +1031 -0
  32. easyclaw-0.1.0/src/easyclaw/alerts.py +194 -0
  33. easyclaw-0.1.0/src/easyclaw/capping.py +253 -0
  34. easyclaw-0.1.0/src/easyclaw/classifier.py +209 -0
  35. easyclaw-0.1.0/src/easyclaw/cli.py +258 -0
  36. easyclaw-0.1.0/src/easyclaw/config.py +166 -0
  37. easyclaw-0.1.0/src/easyclaw/context_monitor.py +236 -0
  38. easyclaw-0.1.0/src/easyclaw/daemon.py +531 -0
  39. easyclaw-0.1.0/src/easyclaw/dashboard.py +301 -0
  40. easyclaw-0.1.0/src/easyclaw/dep_auditor.py +194 -0
  41. easyclaw-0.1.0/src/easyclaw/discovery.py +207 -0
  42. easyclaw-0.1.0/src/easyclaw/env_validator.py +249 -0
  43. easyclaw-0.1.0/src/easyclaw/executor.py +169 -0
  44. easyclaw-0.1.0/src/easyclaw/healer.py +410 -0
  45. easyclaw-0.1.0/src/easyclaw/health.py +229 -0
  46. easyclaw-0.1.0/src/easyclaw/kpi.py +183 -0
  47. easyclaw-0.1.0/src/easyclaw/ledger.py +151 -0
  48. easyclaw-0.1.0/src/easyclaw/logging.py +83 -0
  49. easyclaw-0.1.0/src/easyclaw/mcp_client.py +266 -0
  50. easyclaw-0.1.0/src/easyclaw/remediation.py +276 -0
  51. easyclaw-0.1.0/src/easyclaw/resource_monitor.py +305 -0
  52. easyclaw-0.1.0/src/easyclaw/restart.py +238 -0
  53. easyclaw-0.1.0/src/easyclaw/sandbox.py +296 -0
  54. easyclaw-0.1.0/src/easyclaw/tailer.py +181 -0
  55. easyclaw-0.1.0/src/easyclaw/telegram.py +371 -0
  56. easyclaw-0.1.0/src/easyclaw/temp_cleaner.py +238 -0
  57. easyclaw-0.1.0/src/easyclaw/templates/easyclaw.service +22 -0
  58. easyclaw-0.1.0/src/easyclaw/updater.py +93 -0
  59. easyclaw-0.1.0/tests/__init__.py +0 -0
  60. easyclaw-0.1.0/tests/conftest.py +23 -0
  61. easyclaw-0.1.0/tests/test_agent.py +491 -0
  62. easyclaw-0.1.0/tests/test_alerts.py +106 -0
  63. easyclaw-0.1.0/tests/test_classifier.py +150 -0
  64. easyclaw-0.1.0/tests/test_kpi.py +100 -0
  65. easyclaw-0.1.0/tests/test_ledger.py +118 -0
  66. easyclaw-0.1.0/tests/test_remediation.py +74 -0
  67. easyclaw-0.1.0/tests/test_sandbox.py +174 -0
  68. easyclaw-0.1.0/tests/test_telegram.py +267 -0
@@ -0,0 +1,30 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.10", "3.11", "3.12"]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Set up Python ${{ matrix.python-version }}
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+
24
+ - name: Install dependencies
25
+ run: |
26
+ python -m pip install --upgrade pip
27
+ pip install -e ".[dev]"
28
+
29
+ - name: Run tests
30
+ run: pytest -v --tb=short
@@ -0,0 +1,53 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ test:
9
+ runs-on: ubuntu-latest
10
+ strategy:
11
+ matrix:
12
+ python-version: ["3.10", "3.11", "3.12"]
13
+
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - name: Set up Python ${{ matrix.python-version }}
18
+ uses: actions/setup-python@v5
19
+ with:
20
+ python-version: ${{ matrix.python-version }}
21
+
22
+ - name: Install dependencies
23
+ run: |
24
+ python -m pip install --upgrade pip
25
+ pip install -e ".[dev]"
26
+
27
+ - name: Run tests
28
+ run: pytest -v --tb=short
29
+
30
+ publish:
31
+ needs: test
32
+ runs-on: ubuntu-latest
33
+ environment: pypi
34
+ permissions:
35
+ contents: read # checkout private repo
36
+ id-token: write # trusted publishing
37
+
38
+ steps:
39
+ - uses: actions/checkout@v4
40
+
41
+ - name: Set up Python
42
+ uses: actions/setup-python@v5
43
+ with:
44
+ python-version: "3.12"
45
+
46
+ - name: Install build tools
47
+ run: pip install --upgrade build
48
+
49
+ - name: Build package
50
+ run: python -m build
51
+
52
+ - name: Publish to PyPI
53
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,37 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ *.egg
8
+
9
+ # Virtual environments
10
+ .venv/
11
+ venv/
12
+
13
+ # IDE
14
+ .vscode/
15
+ .idea/
16
+
17
+ # OS
18
+ .DS_Store
19
+ Thumbs.db
20
+
21
+ # EasyClaw runtime
22
+ *.log
23
+ *.pid
24
+ *.db
25
+
26
+ # Secrets — never commit
27
+ *.key
28
+ *.pem
29
+ GitHub Token.txt
30
+ OpenRouter API Key.txt
31
+
32
+ # Pytest
33
+ .pytest_cache/
34
+
35
+ # MCP server data
36
+ mcp-server/data/
37
+ mcp-server/tokens.json
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ All notable changes to EasyClaw will be documented in this file.
4
+
5
+ ## [0.1.0] - 2026-03-30
6
+
7
+ ### Added
8
+ - **Phase 0 — Foundation:** asyncio daemon, heartbeat, CLI (`start|stop|status|doctor`), auto-discovery, systemd/launchd service templates, `curl|bash` installer
9
+ - **Phase 1 — The Doctor:** real-time log tailing (file + journalctl), 13 built-in classification rules, alert pipeline with 5-min dedup, webhook notifications
10
+ - **Phase 2 — Self-Healing:** 11 built-in remediations, sandboxed command executor, OpenClaw restart manager, JSONL fix ledger, circuit breaker (3 restarts / 10 min)
11
+ - **Phase 3 — MCP Client:** HTTP client for proprietary MCP knowledge server (17 tools, 29+ articles), retry/backoff/cache, incident reporting, periodic update polling
12
+ - **Phase 4 — Personal Trainer:** context monitor (home dir size tracking), temp file cleaner, dependency auditor, environment validator (API keys, connectivity), CPU/RAM trend tracking with OOM projection
13
+ - **Phase 5 — Hardening:** security sandbox (command validation, path restrictions), resource capping (nice + systemd limits), async HTTP status dashboard on `localhost:18790`, KPI tracker (MTTR, uptime, auto-fix rate)
14
+ - **Phase 6 — Agent Brain:** LLM-powered reasoning loop via OpenRouter (GLM-4.7-Flash), 10 tools (4 local + 6 MCP), event-triggered with 10s batch window and 30s cooldown, graceful fallback to rules-based healer
15
+ - **Phase 7 — Telegram Bot:** two-way conversational interface via python-telegram-bot, `/status` `/logs` `/stats` `/help` commands, CRITICAL alert forwarding with 10-min dedup, chat authorization
16
+ - **MCP Server v2:** 17 tools, SQLite + FTS5 backend, 25+ seed articles, 20+ AI model catalog, 25+ error diagnostic patterns, 7 config templates, security audit checklists, n8n auto-update workflow (6h interval)
@@ -0,0 +1,322 @@
1
+ # EasyClaw 2.0
2
+
3
+ ## What It Is
4
+ EasyClaw is a **commercial subscription product** — an autonomous "doctor and personal trainer" sidecar for OpenClaw agents. It monitors, diagnoses, self-heals, and optimizes OpenClaw instances without user intervention. Sold via `easyclaw.help`.
5
+
6
+ ## Current State — Phase 8 In Progress (2026-03-30)
7
+ - **Version:** 0.1.0
8
+ - **Runtime:** Python 3.10+ asyncio daemon with 16 concurrent subsystems
9
+ - **Agent Brain:** GLM-4.7-Flash via OpenRouter — LLM-powered reasoning loop (Phase 6)
10
+ - **Telegram Bot:** Full conversational two-way communication via python-telegram-bot (Phase 7)
11
+ - **Package:** pip-installable via hatchling (`pyproject.toml`)
12
+ - **MCP Server:** Deployed to VPS at `http://31.220.49.171:8002` — 17 tools, 29+ articles, 19 models
13
+ - **n8n Workflow:** "EasyClaw Knowledge Updater" (ID: Bn29wDCN97tZRfiK) — auto-ingests from GitHub, HuggingFace, arXiv, Reddit, SearXNG every 6h
14
+ - **Dev venv:** `~/.easyclaw/venv/` in WSL2 (editable install from OneDrive source)
15
+ - **Test Suite:** 170 tests across 8 test files (classifier, sandbox, ledger, KPI, alerts, remediation, agent, telegram)
16
+ - **CI/CD:** GitHub Actions for test matrix (3.10/3.11/3.12) + PyPI trusted publishing
17
+ - **All 7 build phases complete** — Phase 8 distribution prep in progress
18
+
19
+ ## Architecture
20
+
21
+ ```
22
+ src/easyclaw/
23
+ ├── __init__.py # version (0.1.0)
24
+ ├── __main__.py # python -m easyclaw entry point
25
+ ├── cli.py # CLI: easyclaw start|stop|status|doctor
26
+ ├── config.py # loads ~/.easyclaw/config.yaml + discovers OpenClaw env
27
+ ├── agent.py # Phase 6: LLM agent brain (OpenRouter, tool calling, event reasoning)
28
+ ├── telegram.py # Phase 7: Telegram bot bridge (inbound chat + outbound alerts)
29
+ ├── daemon.py # asyncio event loop, orchestrates all subsystems (Phases 1-7)
30
+ ├── discovery.py # auto-discovers OpenClaw install (paths, PID, service, binary)
31
+ ├── logging.py # JSON file logs + colored console output
32
+ ├── tailer.py # async log tailing (file + journalctl) with LogAggregator
33
+ ├── classifier.py # rules-based event classification (13 built-in patterns)
34
+ ├── alerts.py # event queue, dedup filter, alert log, webhook notifications
35
+ ├── health.py # process health monitor (PID, CPU/RAM, stall, session bloat)
36
+ ├── remediation.py # remediation registry (11 built-in entries + user YAML overrides)
37
+ ├── executor.py # sandboxed command execution (timeout, output cap, no stdin)
38
+ ├── restart.py # OpenClaw restart manager (systemctl/SIGTERM/SIGKILL lifecycle)
39
+ ├── ledger.py # fix ledger (JSONL audit trail) + circuit breaker
40
+ ├── healer.py # orchestrator: events → registry → MCP fallback → execute → ledger
41
+ ├── mcp_client.py # HTTP client for proprietary MCP server (retry, backoff, cache)
42
+ ├── updater.py # periodic MCP polling for updates and hotfixes
43
+ ├── context_monitor.py # Phase 4: OpenClaw home dir size/growth tracking
44
+ ├── temp_cleaner.py # Phase 4: stale temp file cleanup + log rotation/gzip
45
+ ├── dep_auditor.py # Phase 4: dependency version audit (psutil, pyyaml, aiofiles)
46
+ ├── env_validator.py # Phase 4: API key + MCP + gateway connectivity checks
47
+ ├── resource_monitor.py # Phase 4: CPU/RAM trend tracking + OOM projection
48
+ ├── dashboard.py # Phase 5: async HTTP status dashboard (127.0.0.1:18790)
49
+ ├── kpi.py # Phase 5: KPI tracker (MTTR, uptime, auto-fix rate, intervention rate)
50
+ ├── sandbox.py # Phase 5: security sandbox (command validation, path restrictions)
51
+ ├── capping.py # Phase 5: resource capping (nice, self-monitoring, systemd unit gen)
52
+ └── templates/
53
+ └── easyclaw.service # systemd user service template
54
+
55
+ mcp-server/ # Deployable to Hostinger VPS (port 8002)
56
+ ├── server.py # FastMCP server v2 (17 tools — knowledge hub)
57
+ ├── db.py # SQLite + FTS5 full-text search database layer
58
+ ├── models_catalog.py # 20+ AI model catalog with pricing & recommendations
59
+ ├── error_patterns.py # 25+ regex-based error diagnostic patterns
60
+ ├── config_templates.py # 7 config templates + 20 validation checks + gateway config gen
61
+ ├── checklists.py # 14 security audit checks + deployment validation (linux/macos/wsl2) + gateway troubleshooting
62
+ ├── seed_knowledge.py # Seeds database with 25+ comprehensive articles on first run
63
+ ├── n8n-knowledge-updater.json # n8n workflow: auto-updates KB from GitHub, HuggingFace, arXiv, Reddit, SearXNG every 6h
64
+ ├── requirements.txt # mcp[cli], uvicorn
65
+ ├── Dockerfile
66
+ ├── tokens.json # Subscription token store (dev token: ec_dev_token_001)
67
+ ├── data/ # SQLite database (auto-created)
68
+ │ └── easyclaw_knowledge.db
69
+ └── knowledge/ # Legacy markdown (imported into SQLite on first run)
70
+ ├── known-issues/ # connection-refused, heap-out-of-memory, dns-failure, session-bloat
71
+ └── docs/ # configuration reference
72
+ ```
73
+
74
+ ### Supporting Files (project root)
75
+ - `pyproject.toml` — pip-installable package (hatchling build system)
76
+ - `Dockerfile` — EasyClaw client sidecar container
77
+ - `install.sh` — `curl | bash` installer for easyclaw.help
78
+ - `README.md` — Basic usage docs
79
+ - `EasyClaw 2.0 PRD.md` — Full product requirements document
80
+
81
+ ## Runtime Paths (on user's machine)
82
+ - **Config:** `~/.easyclaw/config.yaml`
83
+ - **Logs:** `~/.easyclaw/logs/easyclaw-YYYY-MM-DD.log` (JSON lines)
84
+ - **Alerts:** `~/.easyclaw/logs/alerts.log` (JSON lines, classified events)
85
+ - **State:** `~/.easyclaw/state/daemon.json`, `daemon.pid`, `fix-ledger.jsonl`
86
+ - **User remediations:** `~/.easyclaw/remediations.yaml` (optional, extends built-in rules)
87
+
88
+ ## OpenClaw Discovery
89
+ EasyClaw auto-discovers OpenClaw at runtime — no hardcoded paths. It checks:
90
+ - `~/.openclaw/` directory (home_dir, config, sessions, workspace, cron)
91
+ - `~/.openclaw_env` (API keys, env vars)
92
+ - `/tmp/openclaw/` (log directory)
93
+ - `which openclaw` + common npm global paths (binary)
94
+ - `systemctl --user` for `openclaw-gateway` service
95
+ - `psutil` process scan for running PID
96
+
97
+ ## Installation Methods
98
+ 1. **pip:** `pip install easyclaw` (PyPI — not yet published)
99
+ 2. **Docker:** `docker run` sidecar with volume mounts to host OpenClaw dirs
100
+ 3. **Installer:** `curl -sL easyclaw.help/install | bash` — detects OS, installs pip package, sets up systemd service
101
+
102
+ ## CLI Commands
103
+ ```bash
104
+ easyclaw start # start daemon (background)
105
+ easyclaw start -f # start in foreground
106
+ easyclaw stop # graceful SIGTERM shutdown
107
+ easyclaw status # show daemon + OpenClaw status
108
+ easyclaw doctor # run environment diagnostics (19 checks)
109
+ ```
110
+
111
+ ## Config (config.yaml defaults)
112
+ ```yaml
113
+ heartbeat_interval: 30 # seconds
114
+ health_check_interval: 60 # seconds
115
+ log_retention_days: 7
116
+ max_restart_attempts: 3 # circuit breaker
117
+ restart_window: 600 # circuit breaker window (10 min)
118
+ gateway_port: 18789
119
+ alert_webhook: null # n8n/Telegram webhook URL
120
+ mcp_endpoint: null # proprietary MCP server URL (e.g., http://31.220.49.171:8002)
121
+ mcp_token: null # MCP subscription token
122
+ update_check_interval: 21600 # 6 hours (seconds)
123
+
124
+ # Agent brain (Phase 6)
125
+ openrouter_api_key: null # OpenRouter API key for LLM agent brain
126
+ openrouter_model: "z-ai/glm-4.7-flash" # Model ID on OpenRouter
127
+ agent_enabled: true # enable/disable agent brain
128
+ agent_batch_window: 10 # seconds to batch events before invoking agent
129
+ agent_cooldown: 30 # minimum seconds between agent invocations
130
+ agent_max_turns: 10 # max tool-call round trips per invocation
131
+ agent_temperature: 0.1 # low for deterministic behavior
132
+
133
+ # Telegram bot (Phase 7)
134
+ telegram_bot_token: null # bot token from @BotFather
135
+ telegram_chat_ids: [] # authorized chat IDs (list of integers)
136
+ telegram_alert_severity: "CRITICAL" # minimum severity to push alerts
137
+ ```
138
+
139
+ ## Key Design Decisions
140
+ - **AI agent architecture:** Copies OpenClaw's agent loop pattern — system prompt -> model call -> parse tool_calls -> execute -> loop
141
+ - **LLM-powered reasoning:** GLM-4.7-Flash via OpenRouter reasons about problems, queries MCP knowledge base, generates and executes fixes
142
+ - **Event-triggered:** Agent brain activates on events (not continuous), with 10s batch window and 30s cooldown — typical cost <$0.02/day
143
+ - **Graceful fallback:** No API key or OpenRouter down -> degrades to rules-based healer automatically
144
+ - **Failsafe contract:** Top-level try/except wraps entire daemon — EasyClaw can never crash OpenClaw
145
+ - **No hardcoded paths:** Everything discovered dynamically for portability across customer installs
146
+ - **Platform-aware:** Detects Linux, macOS, WSL2, systemd vs launchd vs none
147
+ - **Resource-capped:** systemd service limits to 10% CPU, 256MB RAM
148
+ - **Commercial product:** All architecture decisions account for multi-user distribution
149
+ - **MCP is the brain's strength:** 17 tools, 29+ articles — the agent is lightweight, MCP does the heavy lifting
150
+
151
+ ## Dependencies
152
+ ```
153
+ aiofiles>=24.1.0 # async file I/O (log tailing)
154
+ pyyaml>=6.0 # config file parsing
155
+ psutil>=5.9 # process monitoring
156
+ python-telegram-bot>=21.0 # Telegram bot API (async-native)
157
+ ```
158
+
159
+ ## Build Phases (from PRD)
160
+ - [x] **Phase 0** — Foundation: daemon loop, heartbeat, discovery, CLI, installer
161
+ - [x] **Phase 1** — The Doctor: log tailing, error detection, event classification, alerts
162
+ - [x] **Phase 2** — Self-Healing: remediation registry, command executor, restart manager, circuit breaker
163
+ - [x] **Phase 3** — MCP Client: proprietary MCP server, knowledge retrieval, push-pull updates
164
+ - [x] **Phase 4** — Personal Trainer: context monitor, temp cleaner, dependency audit, env validation, resource monitor
165
+ - [x] **Phase 5** — Hardening: installer polish, resource capping, security sandbox, dashboard, KPIs
166
+ - [x] **Phase 6** — Agent Brain: LLM reasoning loop via OpenRouter (GLM-4.7-Flash), tool calling, event-triggered with batching, fallback to rules-based healer
167
+ - [x] **Phase 7** — Telegram Bot: full conversational two-way via python-telegram-bot, commands (/status /logs /stats), alert forwarding, LLM chat
168
+
169
+ ---
170
+
171
+ ## Session Handoff Notes — 2026-03-31 (Phase 8 — Test Coverage + Distribution Polish)
172
+
173
+ ### What Was Built This Session
174
+
175
+ #### Test Suite Expansion (170 tests, all passing)
176
+ - **`tests/test_agent.py`** — 43 tests: availability (4), event enqueue (4), tool definitions (5), event formatting (3), tool execution (11), chat interface (4), system prompt (4), fallback (2), history tracking (2), utilities (3), message cleaning (2)
177
+ - **`tests/test_telegram.py`** — 19 tests: configuration (5), authorization (3), alert forwarding (6), message splitting (3), run method (2)
178
+
179
+ #### Distribution Polish
180
+ - **`install.sh`** — config template now includes all Phase 6+7 fields (agent brain, Telegram bot settings)
181
+ - **`.github/workflows/publish.yml`** — now runs full test matrix (3.10/3.11/3.12) before publishing to PyPI (publish job `needs: test`)
182
+
183
+ ### What Still Needs Rick's Manual Action
184
+ - [ ] Create GitHub repo (`easyclaw/easyclaw`) and push code
185
+ - [ ] Configure PyPI trusted publishing (link GitHub repo to PyPI project)
186
+ - [ ] Create Telegram bot via @BotFather, add token + chat ID to `~/.easyclaw/config.yaml`
187
+ - [ ] Add OpenRouter API key to config.yaml for agent brain
188
+ - [ ] Re-install editable package: `pip install -e ".[dev]"` (picks up new test files)
189
+ - [ ] Run `easyclaw doctor` to verify all checks pass
190
+ - [ ] Production smoke test: run daemon 24h with agent brain + Telegram active
191
+ - [ ] Activate n8n knowledge updater workflow (ID: Bn29wDCN97tZRfiK)
192
+ - [ ] Test `install.sh` on clean Ubuntu VM
193
+ - [ ] Set up easyclaw.help landing page + payment integration
194
+
195
+ ---
196
+
197
+ ## Session Handoff Notes — 2026-03-30 (Phase 6 + 7 — Agent Brain + Telegram)
198
+
199
+ ### What Was Built This Session
200
+ Added the LLM agent brain and Telegram bot — the core missing pieces that make EasyClaw a true conversational AI agent.
201
+
202
+ #### Phase 7 — Telegram Bot (`telegram.py`, ~300 lines)
203
+ - **TelegramBridge** is daemon subsystem #16, connects directly to Telegram Bot API via polling (no n8n middleman)
204
+ - **Inbound**: free-form messages routed through `AgentBrain.chat()` for full LLM-powered conversational responses with tool calling
205
+ - **Commands**: `/status` (OpenClaw health), `/logs` (last 20 log lines), `/stats` (KPI summary), `/help`
206
+ - **Outbound**: CRITICAL alerts auto-forwarded to authorized chat IDs with 10-min dedup
207
+ - **Authorization**: only responds to chat IDs listed in `telegram_chat_ids` config (empty = allow all)
208
+ - **Graceful disable**: no bot token = subsystem doesn't start, zero impact
209
+ - **Agent chat()**: new public method on AgentBrain with conversational system prompt addendum
210
+ - **Library**: `python-telegram-bot>=21.0` (async-native, added to main dependencies)
211
+
212
+ #### Phase 6 — Agent Brain (`agent.py`, ~500 lines)
213
+ - **Agent loop** copies OpenClaw's architecture: system prompt -> call GLM-4.7-Flash via OpenRouter -> parse tool_calls -> execute tools -> loop
214
+ - **Event-triggered with batching**: events accumulate for 10s, agent invokes, 30s cooldown. NOT continuously running.
215
+ - **10 tools available to the agent**: 4 local (shell command, read file, restart OpenClaw, read logs) + 6 MCP (diagnose issue, search knowledge, get guide, troubleshoot gateway, web search, report incident)
216
+ - **Dynamic system prompt**: rebuilt each invocation with current OpenClaw status (PID/CPU/RAM), circuit breaker state, MCP status, KPIs, and last 5 intervention summaries
217
+ - **Security**: all shell commands validated through SecuritySandbox before execution. All actions recorded to fix ledger.
218
+ - **Graceful fallback**: no API key -> rules-based healer. OpenRouter down -> fallback to healer. Unexpected exception -> fallback to healer. Zero regression from Phase 5.
219
+ - **Cost**: ~$0.003/invocation worst case. Typical <$0.02/day. Model: `z-ai/glm-4.7-flash` via OpenRouter.
220
+
221
+ #### Integration Points
222
+ - **daemon.py**: Agent brain is subsystem #15. Events routed to agent if available, else to healer.
223
+ - **Healer**: always runs as fallback — agent calls `healer.enqueue()` when it can't handle events.
224
+ - **config.py**: 7 new config fields: `openrouter_api_key`, `openrouter_model`, `agent_enabled`, `agent_batch_window`, `agent_cooldown`, `agent_max_turns`, `agent_temperature`.
225
+
226
+ #### Daemon Subsystem Count: 16 concurrent tasks
227
+ 1. alert_pipeline, 2. log_aggregator, 3. health_monitor, 4. healer (fallback), 5. **agent_brain**, 6. update_checker,
228
+ 7. context_monitor, 8. temp_cleaner, 9. dep_auditor, 10. env_validator, 11. resource_monitor,
229
+ 12. kpi_tracker, 13. dashboard, 14. resource_cap, 15. **telegram_bot**, 16. heartbeat
230
+
231
+ ### TODO — Phase 8 (Distribution & Launch)
232
+ - [ ] Re-install editable package in WSL2 venv: `pip install -e .` (picks up Phase 6+7 files + new dependency)
233
+ - [ ] Install `python-telegram-bot`: `pip install python-telegram-bot>=21.0`
234
+ - [ ] Update `~/.easyclaw/config.yaml` with agent + Telegram + MCP config:
235
+ ```yaml
236
+ mcp_endpoint: "http://31.220.49.171:8002"
237
+ mcp_token: "ec_dev_token_001"
238
+ openrouter_api_key: "sk-or-v1-YOUR-KEY"
239
+ openrouter_model: "z-ai/glm-4.7-flash"
240
+ telegram_bot_token: "YOUR-BOT-TOKEN"
241
+ telegram_chat_ids: [YOUR_CHAT_ID]
242
+ ```
243
+ - [ ] Create Telegram bot via @BotFather, get token, get your chat ID
244
+ - [ ] Run `easyclaw doctor` to verify all checks pass including new config fields
245
+ - [ ] Test agent brain: `easyclaw start -f`, inject error `echo "FATAL ERROR: heap out of memory" >> /tmp/openclaw/test.log`, observe LLM reasoning in logs
246
+ - [ ] Test Telegram: send message to bot, verify LLM response comes back with tool usage
247
+ - [ ] Test fallback: start with invalid OpenRouter key, verify events route to healer
248
+ - [ ] Activate n8n workflow (ID: Bn29wDCN97tZRfiK) — currently inactive
249
+ - [ ] Test n8n workflow: verify articles land in MCP database via `search_knowledge`
250
+ - [ ] Production smoke test: run daemon for 24h with agent brain + Telegram, verify KPI data
251
+ - [ ] Publish to PyPI: `pip install easyclaw`
252
+ - [ ] Test `install.sh` on clean Ubuntu VM
253
+ - [ ] Set up easyclaw.help landing page and payment integration
254
+
255
+ ### How To Resume Development
256
+ ```bash
257
+ # In WSL2:
258
+ source ~/.easyclaw/venv/bin/activate
259
+ cd "/mnt/c/Users/me/OneDrive/Automation Projects/EasyClaw 2.0"
260
+ pip install -e ".[dev]" # reinstall with dev deps after code changes
261
+ pip install python-telegram-bot>=21.0 # new Phase 7 dependency
262
+ easyclaw doctor # verify environment
263
+ easyclaw start -f # test foreground (all 16 subsystems)
264
+ ```
265
+
266
+ ### Known Issues / Quirks
267
+ - **Phase 6+7 not yet tested at runtime** — code was written this session but daemon hasn't been started with an OpenRouter key or Telegram token yet. First runtime test will be needed.
268
+ - **python-telegram-bot not yet installed in venv** — needs `pip install python-telegram-bot>=21.0` after re-installing the editable package
269
+ - **config.yaml on disk may be stale** — was written with Phase 3 defaults. Delete it and restart daemon to regenerate with all new fields, or manually add the new fields.
270
+ - **Log file discovery is at startup only** — new `.log` files created after daemon starts won't be tailed until restart.
271
+ - **MCP server uses `/call-tool` HTTP endpoint** — plain HTTP transport on VPS port 8002.
272
+ - **pyproject.toml license field** — uses `LicenseRef-Proprietary` (SPDX format) because hatchling rejects plain `Proprietary`.
273
+ - **`easyclaw start` (background mode)** — re-execs via subprocess. Foreground mode (`-f`) is more reliable for debugging.
274
+ - **Alert forwarding dedup** — `_forward_alerts` reads `alert_pipeline.recent_alerts` which is an in-memory ring buffer. If the ring buffer field names differ from what `telegram.py` expects (e.g., `alert.line` vs `alert.details`), may need a small fix on first test.
275
+
276
+ ---
277
+
278
+ ## Session Handoff Notes — 2026-03-30 (Phase 8 — Distribution Prep)
279
+
280
+ ### What Was Built This Session
281
+
282
+ #### Distribution Infrastructure
283
+ - **README.md** — expanded from 20 lines to full product docs (features, install methods, config reference, architecture diagram)
284
+ - **CHANGELOG.md** — version history for 0.1.0 (all 7 phases + MCP server)
285
+ - **pyproject.toml** — added project URLs (homepage, docs, repo, issues, changelog), expanded classifiers (audience, topic, OS, framework), more keywords
286
+ - **Dockerfile** — added HEALTHCHECK probe hitting the dashboard `/health` endpoint
287
+ - **pytest config** — added `[tool.pytest.ini_options]` to pyproject.toml
288
+
289
+ #### Test Suite (108 tests, all passing)
290
+ - `tests/test_classifier.py` — 20 tests: pattern matching (all 13 rule types), no-match cases, priority ordering, error hash determinism, context buffering
291
+ - `tests/test_sandbox.py` — 30 tests: blocked commands (11 base + 11 patterns), allowed commands, sudo restrictions, kill restrictions, rm validation, file operations, restart targets
292
+ - `tests/test_ledger.py` — 12 tests: record/retrieve, file persistence, stats, restart window counting, ring buffer, circuit breaker (trip, threshold, auto-reset)
293
+ - `tests/test_kpi.py` — 10 tests: initial state, fix recording, MTTR average, auto-fix rate, uptime tracking, snapshot save/load, intervention rate
294
+ - `tests/test_alerts.py` — 8 tests: dedup filter (pass, suppress, cooldown, cleanup), pipeline queue, async event processing, INFO-only logging
295
+ - `tests/test_remediation.py` — 9 tests: builtin count, lookup by pattern/event type, missing lookup, priority, action validation, user YAML override, missing file handling
296
+ - `tests/conftest.py` — shared fixtures (tmp_easyclaw_home, tmp_openclaw_home)
297
+
298
+ #### GitHub Actions CI/CD
299
+ - `.github/workflows/ci.yml` — runs pytest on push/PR against Python 3.10, 3.11, 3.12
300
+ - `.github/workflows/publish.yml` — publishes to PyPI on GitHub release via trusted publishing (no API token needed)
301
+
302
+ ### What Needs To Happen Next (requires Rick's manual action)
303
+ - [ ] Create GitHub repo (`easyclaw/easyclaw`) and push code
304
+ - [ ] Configure PyPI trusted publishing (link GitHub repo to PyPI project)
305
+ - [ ] Create Telegram bot via @BotFather, add token + chat ID to config.yaml
306
+ - [ ] Test `install.sh` on clean Ubuntu VM
307
+ - [ ] Production smoke test: run daemon 24h with agent brain + Telegram active
308
+ - [ ] Activate n8n knowledge updater workflow (ID: Bn29wDCN97tZRfiK)
309
+ - [ ] Set up easyclaw.help landing page + payment integration
310
+
311
+ ---
312
+
313
+ ## Prior Session Handoff Notes (2026-03-29 and 2026-03-30 earlier sessions)
314
+
315
+ ### Phases 0-5 + MCP Server v2 + n8n Workflow
316
+ Built EasyClaw from zero to Phase 5 across two sessions. Full details in git history and prior CLAUDE.md versions. Key facts:
317
+ - Phases 0-3 (2026-03-29): foundation, detection, self-healing, MCP client + server v2 (17 tools)
318
+ - Phase 4 (2026-03-30 morning): personal trainer (5 modules — context monitor, temp cleaner, dep auditor, env validator, resource monitor)
319
+ - Phase 5 (2026-03-30 morning): hardening (dashboard, KPIs, sandbox, resource capping, installer)
320
+ - MCP server v2 deployed to VPS at port 8002 (Docker container `easyclaw-mcp`)
321
+ - n8n knowledge updater workflow created (ID: Bn29wDCN97tZRfiK, inactive, needs activation)
322
+ - 27/29 doctor checks passing, all 14 (now 16) subsystems start/stop cleanly
@@ -0,0 +1,33 @@
1
+ FROM python:3.12-slim
2
+
3
+ LABEL maintainer="EasyClaw Team"
4
+ LABEL description="EasyClaw — Autonomous doctor and personal trainer for OpenClaw"
5
+
6
+ # Create non-root user
7
+ RUN groupadd -r easyclaw && useradd -r -g easyclaw -m easyclaw
8
+
9
+ # Install system deps
10
+ RUN apt-get update && apt-get install -y --no-install-recommends \
11
+ procps \
12
+ && rm -rf /var/lib/apt/lists/*
13
+
14
+ # Install EasyClaw
15
+ WORKDIR /app
16
+ COPY pyproject.toml .
17
+ COPY src/ src/
18
+ RUN pip install --no-cache-dir .
19
+
20
+ # Runtime config
21
+ USER easyclaw
22
+ ENV EASYCLAW_HOME=/home/easyclaw/.easyclaw
23
+
24
+ # The sidecar needs access to the host's OpenClaw dirs via volume mounts:
25
+ # -v ~/.openclaw:/host/.openclaw:ro
26
+ # -v /tmp/openclaw:/host/tmp/openclaw:ro
27
+ # EasyClaw will auto-discover via OPENCLAW_HOME override or default paths.
28
+
29
+ HEALTHCHECK --interval=60s --timeout=10s --start-period=30s --retries=3 \
30
+ CMD ["python3", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:18790/health', timeout=5)"]
31
+
32
+ ENTRYPOINT ["easyclaw"]
33
+ CMD ["start", "--foreground"]
@@ -0,0 +1,52 @@
1
+ # Product Requirements Document (PRD): EasyClaw Autonomous Agent
2
+
3
+ ## 1. Executive Summary
4
+ **Project Name:** EasyClaw
5
+ **Product Vision:** To provide an invisible, autonomous "doctor and personal trainer" for the OpenClaw agent. EasyClaw runs in tandem with OpenClaw in the same environment, ensuring optimal health, maximum uptime, and seamless functionality. By connecting to a proprietary Model Context Protocol (MCP) containing up-to-date documentation, troubleshooting steps, and system fixes, EasyClaw drastically reduces user friction and technical overhead.
6
+
7
+ As this ecosystem is deployed to users—potentially acting as the core value proposition for onboarding portals like easyclaw.help—EasyClaw will ensure that non-technical users can maintain complex AI agents without needing developer-level intervention.
8
+
9
+ ## 2. Goals & Objectives
10
+ * **Zero-Touch Maintenance:** Automatically detect, diagnose, and resolve OpenClaw runtime errors, configuration drift, and dependency issues without user intervention.
11
+ * **Performance Optimization:** Act as a "personal trainer" by managing OpenClaw's memory, optimizing its context windows, and cleaning up temporary files or stalled background tasks.
12
+ * **Seamless Integration:** Install and operate alongside OpenClaw as a "sidecar" process, sharing the same environmental variables, file system, and permissions natively.
13
+ * **Real-Time Expertise:** Leverage a proprietary MCP to instantly access the latest OpenClaw documentation, GitHub issues, and patch notes to solve novel problems.
14
+
15
+ ## 3. User Personas
16
+ * **The Primary User:** Uses the main OpenClaw agent for daily tasks, automation, and communication. They want OpenClaw to "just work" and do not want to deal with terminal errors, environment configuration, or broken dependencies.
17
+ * **The System Administrator / Developer:** Needs a reliable way to push updates, hotfixes, and new documentation to remote OpenClaw instances. They will maintain the central proprietary MCP that EasyClaw talks to.
18
+
19
+ ## 4. System Architecture
20
+ EasyClaw will be built on the exact same underlying architecture as OpenClaw, ensuring perfect compatibility and eliminating the need for a separate tech stack.
21
+
22
+ * **Deployment Pattern:** Sidecar container or parallel background service. EasyClaw and OpenClaw exist in the same host environment/workspace.
23
+ * **Interaction Layer:** * **OpenClaw:** Front-facing, interacts with the User.
24
+ * **EasyClaw:** Backend-facing, interacts with OpenClaw's environment, logs, and processes. Communicates with the User *only* for critical alerts (e.g., "I need a system reboot to apply a critical patch").
25
+ * **Knowledge Layer:** EasyClaw securely authenticates to a remote, proprietary MCP server to fetch dynamic context (docs, fixes, updates).
26
+
27
+ ## 5. Core Features & Requirements
28
+
29
+ ### 5.1. The "Doctor" (Health & Remediation)
30
+ * **Log Ingestion & Analysis:** EasyClaw must continuously tail OpenClaw’s execution logs. If a crash, loop, or error is detected, EasyClaw intercepts it.
31
+ * **Automated Troubleshooting:** Upon detecting an error, EasyClaw queries the proprietary MCP with the stack trace to find the exact fix.
32
+ * **Self-Healing Execution:** EasyClaw must have the permission to execute shell commands, edit OpenClaw configuration files, and restart the OpenClaw process to apply fixes.
33
+
34
+ ### 5.2. The "Personal Trainer" (Optimization & Maintenance)
35
+ * **Context & Memory Management:** Monitor OpenClaw's token usage and memory footprint. If OpenClaw becomes sluggish, EasyClaw archives old context or clears cache.
36
+ * **Dependency Auditing:** Routinely check OpenClaw's tools, plugins, and libraries. If an update is available via the MCP, EasyClaw safely applies it during idle hours.
37
+ * **Environment Validation:** Ensure that API keys, database connections, and automation webhooks (such as connected n8n workflows) are valid and actively pinging.
38
+
39
+ ### 5.3. Proprietary MCP Integration
40
+ * **Dynamic Knowledge Retrieval:** The MCP will serve as EasyClaw's external brain. It must stream markdown docs, JSON schemas for new commands, and known issue registries.
41
+ * **Secure Authentication:** EasyClaw must use secure tokens to access the proprietary MCP, ensuring unauthorized agents cannot pull the proprietary documentation.
42
+ * **Push-Pull Updates:** The MCP should be able to broadcast "Hotfix Alerts" that EasyClaw can pull down and apply instantly.
43
+
44
+ ## 6. Non-Functional Requirements
45
+ * **Footprint:** Because EasyClaw runs alongside OpenClaw, its baseline CPU and RAM usage must be highly optimized (under 5-10% of total system resources) to avoid choking the main agent.
46
+ * **Security & Permissions:** EasyClaw requires elevated privileges to restart OpenClaw and edit files. Strict sandboxing is required so that if OpenClaw is compromised, EasyClaw cannot be used as an escalation vector.
47
+ * **Failsafe:** If EasyClaw crashes or fails to connect to the MCP, it must fail gracefully without taking OpenClaw down with it.
48
+
49
+ ## 7. Success Metrics (KPIs)
50
+ * **Mean Time to Recovery (MTTR):** How quickly EasyClaw detects an OpenClaw error and restarts/fixes it (Target: < 60 seconds).
51
+ * **Intervention Rate:** The percentage of errors EasyClaw fixes automatically vs. errors that require the user to step in.
52
+ * **Uptime:** Overall availability of the OpenClaw agent.