@rozek/nanoclaw 1.2.17
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.
- package/.claude/settings.json +1 -0
- package/.claude/skills/add-compact/SKILL.md +135 -0
- package/.claude/skills/add-discord/SKILL.md +203 -0
- package/.claude/skills/add-gmail/SKILL.md +220 -0
- package/.claude/skills/add-image-vision/SKILL.md +94 -0
- package/.claude/skills/add-ollama-tool/SKILL.md +153 -0
- package/.claude/skills/add-parallel/SKILL.md +290 -0
- package/.claude/skills/add-pdf-reader/SKILL.md +104 -0
- package/.claude/skills/add-reactions/SKILL.md +117 -0
- package/.claude/skills/add-slack/SKILL.md +207 -0
- package/.claude/skills/add-telegram/SKILL.md +222 -0
- package/.claude/skills/add-telegram-swarm/SKILL.md +384 -0
- package/.claude/skills/add-voice-transcription/SKILL.md +148 -0
- package/.claude/skills/add-whatsapp/SKILL.md +372 -0
- package/.claude/skills/convert-to-apple-container/SKILL.md +175 -0
- package/.claude/skills/customize/SKILL.md +110 -0
- package/.claude/skills/debug/SKILL.md +349 -0
- package/.claude/skills/get-qodo-rules/SKILL.md +122 -0
- package/.claude/skills/get-qodo-rules/references/output-format.md +41 -0
- package/.claude/skills/get-qodo-rules/references/pagination.md +33 -0
- package/.claude/skills/get-qodo-rules/references/repository-scope.md +26 -0
- package/.claude/skills/qodo-pr-resolver/SKILL.md +326 -0
- package/.claude/skills/qodo-pr-resolver/resources/providers.md +329 -0
- package/.claude/skills/setup/SKILL.md +218 -0
- package/.claude/skills/update-nanoclaw/SKILL.md +235 -0
- package/.claude/skills/update-skills/SKILL.md +130 -0
- package/.claude/skills/use-local-whisper/SKILL.md +152 -0
- package/.claude/skills/x-integration/SKILL.md +417 -0
- package/.claude/skills/x-integration/agent.ts +243 -0
- package/.claude/skills/x-integration/host.ts +159 -0
- package/.claude/skills/x-integration/lib/browser.ts +148 -0
- package/.claude/skills/x-integration/lib/config.ts +62 -0
- package/.claude/skills/x-integration/scripts/like.ts +56 -0
- package/.claude/skills/x-integration/scripts/post.ts +66 -0
- package/.claude/skills/x-integration/scripts/quote.ts +80 -0
- package/.claude/skills/x-integration/scripts/reply.ts +74 -0
- package/.claude/skills/x-integration/scripts/retweet.ts +62 -0
- package/.claude/skills/x-integration/scripts/setup.ts +87 -0
- package/.env.example +1 -0
- package/.github/CODEOWNERS +10 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +14 -0
- package/.github/workflows/bump-version.yml +32 -0
- package/.github/workflows/ci.yml +25 -0
- package/.github/workflows/merge-forward-skills.yml +160 -0
- package/.github/workflows/update-tokens.yml +42 -0
- package/.husky/pre-commit +1 -0
- package/.mcp.json +3 -0
- package/.nvmrc +1 -0
- package/.prettierrc +3 -0
- package/CHANGELOG.md +8 -0
- package/CLAUDE.md +64 -0
- package/CONTRIBUTING.md +23 -0
- package/CONTRIBUTORS.md +15 -0
- package/LICENSE +21 -0
- package/NanoClaw_with_Web-Support.md +290 -0
- package/README.md +261 -0
- package/README_zh.md +200 -0
- package/assets/nanoclaw-favicon.png +0 -0
- package/assets/nanoclaw-icon.png +0 -0
- package/assets/nanoclaw-logo-dark.png +0 -0
- package/assets/nanoclaw-logo.png +0 -0
- package/assets/nanoclaw-profile.jpeg +0 -0
- package/assets/nanoclaw-sales.png +0 -0
- package/assets/social-preview.jpg +0 -0
- package/config-examples/mount-allowlist.json +25 -0
- package/container/Dockerfile +70 -0
- package/container/agent-runner/package-lock.json +1524 -0
- package/container/agent-runner/package.json +21 -0
- package/container/agent-runner/src/index.ts +558 -0
- package/container/agent-runner/src/ipc-mcp-stdio.ts +338 -0
- package/container/agent-runner/tsconfig.json +15 -0
- package/container/build.sh +23 -0
- package/container/skills/agent-browser/SKILL.md +159 -0
- package/container/skills/capabilities/SKILL.md +100 -0
- package/container/skills/status/SKILL.md +104 -0
- package/dist/channels/index.d.ts +2 -0
- package/dist/channels/index.d.ts.map +1 -0
- package/dist/channels/index.js +9 -0
- package/dist/channels/index.js.map +1 -0
- package/dist/channels/registry.d.ts +13 -0
- package/dist/channels/registry.d.ts.map +1 -0
- package/dist/channels/registry.js +11 -0
- package/dist/channels/registry.js.map +1 -0
- package/dist/channels/registry.test.d.ts +2 -0
- package/dist/channels/registry.test.d.ts.map +1 -0
- package/dist/channels/registry.test.js +32 -0
- package/dist/channels/registry.test.js.map +1 -0
- package/dist/channels/web.d.ts +2 -0
- package/dist/channels/web.d.ts.map +1 -0
- package/dist/channels/web.js +1738 -0
- package/dist/channels/web.js.map +1 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +182 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +36 -0
- package/dist/config.js.map +1 -0
- package/dist/container-runner.d.ts +44 -0
- package/dist/container-runner.d.ts.map +1 -0
- package/dist/container-runner.js +467 -0
- package/dist/container-runner.js.map +1 -0
- package/dist/container-runner.test.d.ts +2 -0
- package/dist/container-runner.test.d.ts.map +1 -0
- package/dist/container-runner.test.js +150 -0
- package/dist/container-runner.test.js.map +1 -0
- package/dist/container-runtime.d.ts +22 -0
- package/dist/container-runtime.d.ts.map +1 -0
- package/dist/container-runtime.js +96 -0
- package/dist/container-runtime.js.map +1 -0
- package/dist/container-runtime.test.d.ts +2 -0
- package/dist/container-runtime.test.d.ts.map +1 -0
- package/dist/container-runtime.test.js +93 -0
- package/dist/container-runtime.test.js.map +1 -0
- package/dist/credential-proxy.d.ts +21 -0
- package/dist/credential-proxy.d.ts.map +1 -0
- package/dist/credential-proxy.js +95 -0
- package/dist/credential-proxy.js.map +1 -0
- package/dist/credential-proxy.test.d.ts +2 -0
- package/dist/credential-proxy.test.d.ts.map +1 -0
- package/dist/credential-proxy.test.js +134 -0
- package/dist/credential-proxy.test.js.map +1 -0
- package/dist/db.d.ts +115 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +549 -0
- package/dist/db.js.map +1 -0
- package/dist/db.test.d.ts +2 -0
- package/dist/db.test.d.ts.map +1 -0
- package/dist/db.test.js +360 -0
- package/dist/db.test.js.map +1 -0
- package/dist/env.d.ts +8 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +42 -0
- package/dist/env.js.map +1 -0
- package/dist/formatting.test.d.ts +2 -0
- package/dist/formatting.test.d.ts.map +1 -0
- package/dist/formatting.test.js +183 -0
- package/dist/formatting.test.js.map +1 -0
- package/dist/group-folder.d.ts +5 -0
- package/dist/group-folder.d.ts.map +1 -0
- package/dist/group-folder.js +44 -0
- package/dist/group-folder.js.map +1 -0
- package/dist/group-folder.test.d.ts +2 -0
- package/dist/group-folder.test.d.ts.map +1 -0
- package/dist/group-folder.test.js +29 -0
- package/dist/group-folder.test.js.map +1 -0
- package/dist/group-queue.d.ts +34 -0
- package/dist/group-queue.d.ts.map +1 -0
- package/dist/group-queue.js +263 -0
- package/dist/group-queue.js.map +1 -0
- package/dist/group-queue.test.d.ts +2 -0
- package/dist/group-queue.test.d.ts.map +1 -0
- package/dist/group-queue.test.js +341 -0
- package/dist/group-queue.test.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +518 -0
- package/dist/index.js.map +1 -0
- package/dist/ipc-auth.test.d.ts +2 -0
- package/dist/ipc-auth.test.d.ts.map +1 -0
- package/dist/ipc-auth.test.js +434 -0
- package/dist/ipc-auth.test.js.map +1 -0
- package/dist/ipc.d.ts +32 -0
- package/dist/ipc.d.ts.map +1 -0
- package/dist/ipc.js +311 -0
- package/dist/ipc.js.map +1 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +14 -0
- package/dist/logger.js.map +1 -0
- package/dist/mount-security.d.ts +34 -0
- package/dist/mount-security.d.ts.map +1 -0
- package/dist/mount-security.js +325 -0
- package/dist/mount-security.js.map +1 -0
- package/dist/remote-control.d.ts +32 -0
- package/dist/remote-control.d.ts.map +1 -0
- package/dist/remote-control.js +185 -0
- package/dist/remote-control.js.map +1 -0
- package/dist/remote-control.test.d.ts +2 -0
- package/dist/remote-control.test.d.ts.map +1 -0
- package/dist/remote-control.test.js +321 -0
- package/dist/remote-control.test.js.map +1 -0
- package/dist/router.d.ts +8 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +37 -0
- package/dist/router.js.map +1 -0
- package/dist/routing.test.d.ts +2 -0
- package/dist/routing.test.d.ts.map +1 -0
- package/dist/routing.test.js +81 -0
- package/dist/routing.test.js.map +1 -0
- package/dist/sender-allowlist.d.ts +14 -0
- package/dist/sender-allowlist.d.ts.map +1 -0
- package/dist/sender-allowlist.js +79 -0
- package/dist/sender-allowlist.js.map +1 -0
- package/dist/sender-allowlist.test.d.ts +2 -0
- package/dist/sender-allowlist.test.d.ts.map +1 -0
- package/dist/sender-allowlist.test.js +186 -0
- package/dist/sender-allowlist.test.js.map +1 -0
- package/dist/session-commands.d.ts +47 -0
- package/dist/session-commands.d.ts.map +1 -0
- package/dist/session-commands.js +102 -0
- package/dist/session-commands.js.map +1 -0
- package/dist/session-commands.test.d.ts +2 -0
- package/dist/session-commands.test.d.ts.map +1 -0
- package/dist/session-commands.test.js +190 -0
- package/dist/session-commands.test.js.map +1 -0
- package/dist/task-scheduler.d.ts +22 -0
- package/dist/task-scheduler.d.ts.map +1 -0
- package/dist/task-scheduler.js +210 -0
- package/dist/task-scheduler.js.map +1 -0
- package/dist/task-scheduler.test.d.ts +2 -0
- package/dist/task-scheduler.test.d.ts.map +1 -0
- package/dist/task-scheduler.test.js +107 -0
- package/dist/task-scheduler.test.js.map +1 -0
- package/dist/timezone.d.ts +6 -0
- package/dist/timezone.d.ts.map +1 -0
- package/dist/timezone.js +17 -0
- package/dist/timezone.js.map +1 -0
- package/dist/timezone.test.d.ts +2 -0
- package/dist/timezone.test.d.ts.map +1 -0
- package/dist/timezone.test.js +23 -0
- package/dist/timezone.test.js.map +1 -0
- package/dist/types.d.ts +78 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/docs/APPLE-CONTAINER-NETWORKING.md +90 -0
- package/docs/DEBUG_CHECKLIST.md +143 -0
- package/docs/REQUIREMENTS.md +196 -0
- package/docs/SDK_DEEP_DIVE.md +643 -0
- package/docs/SECURITY.md +122 -0
- package/docs/SPEC.md +785 -0
- package/docs/docker-sandboxes.md +359 -0
- package/docs/nanoclaw-architecture-final.md +1063 -0
- package/docs/nanorepo-architecture.md +168 -0
- package/docs/skills-as-branches.md +662 -0
- package/groups/global/CLAUDE.md +58 -0
- package/groups/main/CLAUDE.md +246 -0
- package/launchd/com.nanoclaw.plist +32 -0
- package/package.json +45 -0
- package/repo-tokens/README.md +113 -0
- package/repo-tokens/action.yml +186 -0
- package/repo-tokens/badge.svg +23 -0
- package/repo-tokens/examples/green.svg +14 -0
- package/repo-tokens/examples/red.svg +14 -0
- package/repo-tokens/examples/yellow-green.svg +14 -0
- package/repo-tokens/examples/yellow.svg +14 -0
- package/scripts/run-migrations.ts +105 -0
- package/setup/container.ts +144 -0
- package/setup/environment.test.ts +121 -0
- package/setup/environment.ts +94 -0
- package/setup/groups.ts +229 -0
- package/setup/index.ts +58 -0
- package/setup/mounts.ts +115 -0
- package/setup/platform.test.ts +120 -0
- package/setup/platform.ts +132 -0
- package/setup/register.test.ts +257 -0
- package/setup/register.ts +177 -0
- package/setup/service.test.ts +187 -0
- package/setup/service.ts +362 -0
- package/setup/status.ts +16 -0
- package/setup/verify.ts +192 -0
- package/setup.sh +161 -0
- package/src/channels/index.ts +12 -0
- package/src/channels/registry.test.ts +42 -0
- package/src/channels/registry.ts +32 -0
- package/src/channels/web.ts +1856 -0
- package/src/cli.ts +209 -0
- package/src/config.ts +73 -0
- package/src/container-runner.test.ts +210 -0
- package/src/container-runner.ts +707 -0
- package/src/container-runtime.test.ts +149 -0
- package/src/container-runtime.ts +127 -0
- package/src/credential-proxy.test.ts +192 -0
- package/src/credential-proxy.ts +125 -0
- package/src/db.test.ts +484 -0
- package/src/db.ts +803 -0
- package/src/env.ts +42 -0
- package/src/formatting.test.ts +256 -0
- package/src/group-folder.test.ts +43 -0
- package/src/group-folder.ts +44 -0
- package/src/group-queue.test.ts +484 -0
- package/src/group-queue.ts +365 -0
- package/src/index.ts +731 -0
- package/src/ipc-auth.test.ts +679 -0
- package/src/ipc.ts +461 -0
- package/src/logger.ts +16 -0
- package/src/mount-security.ts +419 -0
- package/src/remote-control.test.ts +397 -0
- package/src/remote-control.ts +224 -0
- package/src/router.ts +52 -0
- package/src/routing.test.ts +170 -0
- package/src/sender-allowlist.test.ts +216 -0
- package/src/sender-allowlist.ts +128 -0
- package/src/session-commands.test.ts +247 -0
- package/src/session-commands.ts +163 -0
- package/src/task-scheduler.test.ts +129 -0
- package/src/task-scheduler.ts +295 -0
- package/src/timezone.test.ts +29 -0
- package/src/timezone.ts +16 -0
- package/src/types.ts +107 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +7 -0
- package/vitest.skills.config.ts +7 -0
package/docs/SPEC.md
ADDED
|
@@ -0,0 +1,785 @@
|
|
|
1
|
+
# NanoClaw Specification
|
|
2
|
+
|
|
3
|
+
A personal Claude assistant with multi-channel support, persistent memory per conversation, scheduled tasks, and container-isolated agent execution.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
1. [Architecture](#architecture)
|
|
10
|
+
2. [Architecture: Channel System](#architecture-channel-system)
|
|
11
|
+
3. [Folder Structure](#folder-structure)
|
|
12
|
+
4. [Configuration](#configuration)
|
|
13
|
+
5. [Memory System](#memory-system)
|
|
14
|
+
6. [Session Management](#session-management)
|
|
15
|
+
7. [Message Flow](#message-flow)
|
|
16
|
+
8. [Commands](#commands)
|
|
17
|
+
9. [Scheduled Tasks](#scheduled-tasks)
|
|
18
|
+
10. [MCP Servers](#mcp-servers)
|
|
19
|
+
11. [Deployment](#deployment)
|
|
20
|
+
12. [Security Considerations](#security-considerations)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Architecture
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
┌──────────────────────────────────────────────────────────────────────┐
|
|
28
|
+
│ HOST (macOS / Linux) │
|
|
29
|
+
│ (Main Node.js Process) │
|
|
30
|
+
├──────────────────────────────────────────────────────────────────────┤
|
|
31
|
+
│ │
|
|
32
|
+
│ ┌──────────────────┐ ┌────────────────────┐ │
|
|
33
|
+
│ │ Channels │─────────────────▶│ SQLite Database │ │
|
|
34
|
+
│ │ (self-register │◀────────────────│ (messages.db) │ │
|
|
35
|
+
│ │ at startup) │ store/send └─────────┬──────────┘ │
|
|
36
|
+
│ └──────────────────┘ │ │
|
|
37
|
+
│ │ │
|
|
38
|
+
│ ┌─────────────────────────────────────────┘ │
|
|
39
|
+
│ │ │
|
|
40
|
+
│ ▼ │
|
|
41
|
+
│ ┌──────────────────┐ ┌──────────────────┐ ┌───────────────┐ │
|
|
42
|
+
│ │ Message Loop │ │ Scheduler Loop │ │ IPC Watcher │ │
|
|
43
|
+
│ │ (polls SQLite) │ │ (checks tasks) │ │ (file-based) │ │
|
|
44
|
+
│ └────────┬─────────┘ └────────┬─────────┘ └───────────────┘ │
|
|
45
|
+
│ │ │ │
|
|
46
|
+
│ └───────────┬───────────┘ │
|
|
47
|
+
│ │ spawns container │
|
|
48
|
+
│ ▼ │
|
|
49
|
+
├──────────────────────────────────────────────────────────────────────┤
|
|
50
|
+
│ CONTAINER (Linux VM) │
|
|
51
|
+
├──────────────────────────────────────────────────────────────────────┤
|
|
52
|
+
│ ┌──────────────────────────────────────────────────────────────┐ │
|
|
53
|
+
│ │ AGENT RUNNER │ │
|
|
54
|
+
│ │ │ │
|
|
55
|
+
│ │ Working directory: /workspace/group (mounted from host) │ │
|
|
56
|
+
│ │ Volume mounts: │ │
|
|
57
|
+
│ │ • groups/{name}/ → /workspace/group │ │
|
|
58
|
+
│ │ • groups/global/ → /workspace/global/ (non-main only) │ │
|
|
59
|
+
│ │ • data/sessions/{group}/.claude/ → /home/node/.claude/ │ │
|
|
60
|
+
│ │ • Additional dirs → /workspace/extra/* │ │
|
|
61
|
+
│ │ │ │
|
|
62
|
+
│ │ Tools (all groups): │ │
|
|
63
|
+
│ │ • Bash (safe - sandboxed in container!) │ │
|
|
64
|
+
│ │ • Read, Write, Edit, Glob, Grep (file operations) │ │
|
|
65
|
+
│ │ • WebSearch, WebFetch (internet access) │ │
|
|
66
|
+
│ │ • agent-browser (browser automation) │ │
|
|
67
|
+
│ │ • mcp__nanoclaw__* (scheduler tools via IPC) │ │
|
|
68
|
+
│ │ │ │
|
|
69
|
+
│ └──────────────────────────────────────────────────────────────┘ │
|
|
70
|
+
│ │
|
|
71
|
+
└───────────────────────────────────────────────────────────────────────┘
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Technology Stack
|
|
75
|
+
|
|
76
|
+
| Component | Technology | Purpose |
|
|
77
|
+
|-----------|------------|---------|
|
|
78
|
+
| Channel System | Channel registry (`src/channels/registry.ts`) | Channels self-register at startup |
|
|
79
|
+
| Message Storage | SQLite (better-sqlite3) | Store messages for polling |
|
|
80
|
+
| Container Runtime | Containers (Linux VMs) | Isolated environments for agent execution |
|
|
81
|
+
| Agent | @anthropic-ai/claude-agent-sdk (0.2.29) | Run Claude with tools and MCP servers |
|
|
82
|
+
| Browser Automation | agent-browser + Chromium | Web interaction and screenshots |
|
|
83
|
+
| Runtime | Node.js 20+ | Host process for routing and scheduling |
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Architecture: Channel System
|
|
88
|
+
|
|
89
|
+
The core ships with no channels built in — each channel (WhatsApp, Telegram, Slack, Discord, Gmail) is installed as a [Claude Code skill](https://code.claude.com/docs/en/skills) that adds the channel code to your fork. Channels self-register at startup; installed channels with missing credentials emit a WARN log and are skipped.
|
|
90
|
+
|
|
91
|
+
### System Diagram
|
|
92
|
+
|
|
93
|
+
```mermaid
|
|
94
|
+
graph LR
|
|
95
|
+
subgraph Channels["Channels"]
|
|
96
|
+
WA[WhatsApp]
|
|
97
|
+
TG[Telegram]
|
|
98
|
+
SL[Slack]
|
|
99
|
+
DC[Discord]
|
|
100
|
+
New["Other Channel (Signal, Gmail...)"]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
subgraph Orchestrator["Orchestrator — index.ts"]
|
|
104
|
+
ML[Message Loop]
|
|
105
|
+
GQ[Group Queue]
|
|
106
|
+
RT[Router]
|
|
107
|
+
TS[Task Scheduler]
|
|
108
|
+
DB[(SQLite)]
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
subgraph Execution["Container Execution"]
|
|
112
|
+
CR[Container Runner]
|
|
113
|
+
LC["Linux Container"]
|
|
114
|
+
IPC[IPC Watcher]
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
%% Flow
|
|
118
|
+
WA & TG & SL & DC & New -->|onMessage| ML
|
|
119
|
+
ML --> GQ
|
|
120
|
+
GQ -->|concurrency| CR
|
|
121
|
+
CR --> LC
|
|
122
|
+
LC -->|filesystem IPC| IPC
|
|
123
|
+
IPC -->|tasks & messages| RT
|
|
124
|
+
RT -->|Channel.sendMessage| Channels
|
|
125
|
+
TS -->|due tasks| CR
|
|
126
|
+
|
|
127
|
+
%% DB Connections
|
|
128
|
+
DB <--> ML
|
|
129
|
+
DB <--> TS
|
|
130
|
+
|
|
131
|
+
%% Styling for the dynamic channel
|
|
132
|
+
style New stroke-dasharray: 5 5,stroke-width:2px
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Channel Registry
|
|
136
|
+
|
|
137
|
+
The channel system is built on a factory registry in `src/channels/registry.ts`:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
export type ChannelFactory = (opts: ChannelOpts) => Channel | null;
|
|
141
|
+
|
|
142
|
+
const registry = new Map<string, ChannelFactory>();
|
|
143
|
+
|
|
144
|
+
export function registerChannel(name: string, factory: ChannelFactory): void {
|
|
145
|
+
registry.set(name, factory);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function getChannelFactory(name: string): ChannelFactory | undefined {
|
|
149
|
+
return registry.get(name);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function getRegisteredChannelNames(): string[] {
|
|
153
|
+
return [...registry.keys()];
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Each factory receives `ChannelOpts` (callbacks for `onMessage`, `onChatMetadata`, and `registeredGroups`) and returns either a `Channel` instance or `null` if that channel's credentials are not configured.
|
|
158
|
+
|
|
159
|
+
### Channel Interface
|
|
160
|
+
|
|
161
|
+
Every channel implements this interface (defined in `src/types.ts`):
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
interface Channel {
|
|
165
|
+
name: string;
|
|
166
|
+
connect(): Promise<void>;
|
|
167
|
+
sendMessage(jid: string, text: string): Promise<void>;
|
|
168
|
+
isConnected(): boolean;
|
|
169
|
+
ownsJid(jid: string): boolean;
|
|
170
|
+
disconnect(): Promise<void>;
|
|
171
|
+
setTyping?(jid: string, isTyping: boolean): Promise<void>;
|
|
172
|
+
syncGroups?(force: boolean): Promise<void>;
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Self-Registration Pattern
|
|
177
|
+
|
|
178
|
+
Channels self-register using a barrel-import pattern:
|
|
179
|
+
|
|
180
|
+
1. Each channel skill adds a file to `src/channels/` (e.g. `whatsapp.ts`, `telegram.ts`) that calls `registerChannel()` at module load time:
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
// src/channels/whatsapp.ts
|
|
184
|
+
import { registerChannel, ChannelOpts } from './registry.js';
|
|
185
|
+
|
|
186
|
+
export class WhatsAppChannel implements Channel { /* ... */ }
|
|
187
|
+
|
|
188
|
+
registerChannel('whatsapp', (opts: ChannelOpts) => {
|
|
189
|
+
// Return null if credentials are missing
|
|
190
|
+
if (!existsSync(authPath)) return null;
|
|
191
|
+
return new WhatsAppChannel(opts);
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
2. The barrel file `src/channels/index.ts` imports all channel modules, triggering registration:
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
import './whatsapp.js';
|
|
199
|
+
import './telegram.js';
|
|
200
|
+
// ... each skill adds its import here
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
3. At startup, the orchestrator (`src/index.ts`) loops through registered channels and connects whichever ones return a valid instance:
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
for (const name of getRegisteredChannelNames()) {
|
|
207
|
+
const factory = getChannelFactory(name);
|
|
208
|
+
const channel = factory?.(channelOpts);
|
|
209
|
+
if (channel) {
|
|
210
|
+
await channel.connect();
|
|
211
|
+
channels.push(channel);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Key Files
|
|
217
|
+
|
|
218
|
+
| File | Purpose |
|
|
219
|
+
|------|---------|
|
|
220
|
+
| `src/channels/registry.ts` | Channel factory registry |
|
|
221
|
+
| `src/channels/index.ts` | Barrel imports that trigger channel self-registration |
|
|
222
|
+
| `src/types.ts` | `Channel` interface, `ChannelOpts`, message types |
|
|
223
|
+
| `src/index.ts` | Orchestrator — instantiates channels, runs message loop |
|
|
224
|
+
| `src/router.ts` | Finds the owning channel for a JID, formats messages |
|
|
225
|
+
|
|
226
|
+
### Adding a New Channel
|
|
227
|
+
|
|
228
|
+
To add a new channel, contribute a skill to `.claude/skills/add-<name>/` that:
|
|
229
|
+
|
|
230
|
+
1. Adds a `src/channels/<name>.ts` file implementing the `Channel` interface
|
|
231
|
+
2. Calls `registerChannel(name, factory)` at module load
|
|
232
|
+
3. Returns `null` from the factory if credentials are missing
|
|
233
|
+
4. Adds an import line to `src/channels/index.ts`
|
|
234
|
+
|
|
235
|
+
See existing skills (`/add-whatsapp`, `/add-telegram`, `/add-slack`, `/add-discord`, `/add-gmail`) for the pattern.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Folder Structure
|
|
240
|
+
|
|
241
|
+
```
|
|
242
|
+
nanoclaw/
|
|
243
|
+
├── CLAUDE.md # Project context for Claude Code
|
|
244
|
+
├── docs/
|
|
245
|
+
│ ├── SPEC.md # This specification document
|
|
246
|
+
│ ├── REQUIREMENTS.md # Architecture decisions
|
|
247
|
+
│ └── SECURITY.md # Security model
|
|
248
|
+
├── README.md # User documentation
|
|
249
|
+
├── package.json # Node.js dependencies
|
|
250
|
+
├── tsconfig.json # TypeScript configuration
|
|
251
|
+
├── .mcp.json # MCP server configuration (reference)
|
|
252
|
+
├── .gitignore
|
|
253
|
+
│
|
|
254
|
+
├── src/
|
|
255
|
+
│ ├── index.ts # Orchestrator: state, message loop, agent invocation
|
|
256
|
+
│ ├── channels/
|
|
257
|
+
│ │ ├── registry.ts # Channel factory registry
|
|
258
|
+
│ │ └── index.ts # Barrel imports for channel self-registration
|
|
259
|
+
│ ├── ipc.ts # IPC watcher and task processing
|
|
260
|
+
│ ├── router.ts # Message formatting and outbound routing
|
|
261
|
+
│ ├── config.ts # Configuration constants
|
|
262
|
+
│ ├── types.ts # TypeScript interfaces (includes Channel)
|
|
263
|
+
│ ├── logger.ts # Pino logger setup
|
|
264
|
+
│ ├── db.ts # SQLite database initialization and queries
|
|
265
|
+
│ ├── group-queue.ts # Per-group queue with global concurrency limit
|
|
266
|
+
│ ├── mount-security.ts # Mount allowlist validation for containers
|
|
267
|
+
│ ├── whatsapp-auth.ts # Standalone WhatsApp authentication
|
|
268
|
+
│ ├── task-scheduler.ts # Runs scheduled tasks when due
|
|
269
|
+
│ └── container-runner.ts # Spawns agents in containers
|
|
270
|
+
│
|
|
271
|
+
├── container/
|
|
272
|
+
│ ├── Dockerfile # Container image (runs as 'node' user, includes Claude Code CLI)
|
|
273
|
+
│ ├── build.sh # Build script for container image
|
|
274
|
+
│ ├── agent-runner/ # Code that runs inside the container
|
|
275
|
+
│ │ ├── package.json
|
|
276
|
+
│ │ ├── tsconfig.json
|
|
277
|
+
│ │ └── src/
|
|
278
|
+
│ │ ├── index.ts # Entry point (query loop, IPC polling, session resume)
|
|
279
|
+
│ │ └── ipc-mcp-stdio.ts # Stdio-based MCP server for host communication
|
|
280
|
+
│ └── skills/
|
|
281
|
+
│ └── agent-browser.md # Browser automation skill
|
|
282
|
+
│
|
|
283
|
+
├── dist/ # Compiled JavaScript (gitignored)
|
|
284
|
+
│
|
|
285
|
+
├── .claude/
|
|
286
|
+
│ └── skills/
|
|
287
|
+
│ ├── setup/SKILL.md # /setup - First-time installation
|
|
288
|
+
│ ├── customize/SKILL.md # /customize - Add capabilities
|
|
289
|
+
│ ├── debug/SKILL.md # /debug - Container debugging
|
|
290
|
+
│ ├── add-telegram/SKILL.md # /add-telegram - Telegram channel
|
|
291
|
+
│ ├── add-gmail/SKILL.md # /add-gmail - Gmail integration
|
|
292
|
+
│ ├── add-voice-transcription/ # /add-voice-transcription - Whisper
|
|
293
|
+
│ ├── x-integration/SKILL.md # /x-integration - X/Twitter
|
|
294
|
+
│ ├── convert-to-apple-container/ # /convert-to-apple-container - Apple Container runtime
|
|
295
|
+
│ └── add-parallel/SKILL.md # /add-parallel - Parallel agents
|
|
296
|
+
│
|
|
297
|
+
├── groups/
|
|
298
|
+
│ ├── CLAUDE.md # Global memory (all groups read this)
|
|
299
|
+
│ ├── {channel}_main/ # Main control channel (e.g., whatsapp_main/)
|
|
300
|
+
│ │ ├── CLAUDE.md # Main channel memory
|
|
301
|
+
│ │ └── logs/ # Task execution logs
|
|
302
|
+
│ └── {channel}_{group-name}/ # Per-group folders (created on registration)
|
|
303
|
+
│ ├── CLAUDE.md # Group-specific memory
|
|
304
|
+
│ ├── logs/ # Task logs for this group
|
|
305
|
+
│ └── *.md # Files created by the agent
|
|
306
|
+
│
|
|
307
|
+
├── store/ # Local data (gitignored)
|
|
308
|
+
│ ├── auth/ # WhatsApp authentication state
|
|
309
|
+
│ └── messages.db # SQLite database (messages, chats, scheduled_tasks, task_run_logs, registered_groups, sessions, router_state)
|
|
310
|
+
│
|
|
311
|
+
├── data/ # Application state (gitignored)
|
|
312
|
+
│ ├── sessions/ # Per-group session data (.claude/ dirs with JSONL transcripts)
|
|
313
|
+
│ ├── env/env # Copy of .env for container mounting
|
|
314
|
+
│ └── ipc/ # Container IPC (messages/, tasks/)
|
|
315
|
+
│
|
|
316
|
+
├── logs/ # Runtime logs (gitignored)
|
|
317
|
+
│ ├── nanoclaw.log # Host stdout
|
|
318
|
+
│ └── nanoclaw.error.log # Host stderr
|
|
319
|
+
│ # Note: Per-container logs are in groups/{folder}/logs/container-*.log
|
|
320
|
+
│
|
|
321
|
+
└── launchd/
|
|
322
|
+
└── com.nanoclaw.plist # macOS service configuration
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
## Configuration
|
|
328
|
+
|
|
329
|
+
Configuration constants are in `src/config.ts`:
|
|
330
|
+
|
|
331
|
+
```typescript
|
|
332
|
+
import path from 'path';
|
|
333
|
+
|
|
334
|
+
export const ASSISTANT_NAME = process.env.ASSISTANT_NAME || 'Andy';
|
|
335
|
+
export const POLL_INTERVAL = 2000;
|
|
336
|
+
export const SCHEDULER_POLL_INTERVAL = 60000;
|
|
337
|
+
|
|
338
|
+
// Paths are absolute (required for container mounts)
|
|
339
|
+
const PROJECT_ROOT = process.cwd();
|
|
340
|
+
export const STORE_DIR = path.resolve(PROJECT_ROOT, 'store');
|
|
341
|
+
export const GROUPS_DIR = path.resolve(PROJECT_ROOT, 'groups');
|
|
342
|
+
export const DATA_DIR = path.resolve(PROJECT_ROOT, 'data');
|
|
343
|
+
|
|
344
|
+
// Container configuration
|
|
345
|
+
export const CONTAINER_IMAGE = process.env.CONTAINER_IMAGE || 'nanoclaw-agent:latest';
|
|
346
|
+
export const CONTAINER_TIMEOUT = parseInt(process.env.CONTAINER_TIMEOUT || '1800000', 10); // 30min default
|
|
347
|
+
export const IPC_POLL_INTERVAL = 1000;
|
|
348
|
+
export const IDLE_TIMEOUT = parseInt(process.env.IDLE_TIMEOUT || '1800000', 10); // 30min — keep container alive after last result
|
|
349
|
+
export const MAX_CONCURRENT_CONTAINERS = Math.max(1, parseInt(process.env.MAX_CONCURRENT_CONTAINERS || '5', 10) || 5);
|
|
350
|
+
|
|
351
|
+
export const TRIGGER_PATTERN = new RegExp(`^@${ASSISTANT_NAME}\\b`, 'i');
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
**Note:** Paths must be absolute for container volume mounts to work correctly.
|
|
355
|
+
|
|
356
|
+
### Container Configuration
|
|
357
|
+
|
|
358
|
+
Groups can have additional directories mounted via `containerConfig` in the SQLite `registered_groups` table (stored as JSON in the `container_config` column). Example registration:
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
setRegisteredGroup("1234567890@g.us", {
|
|
362
|
+
name: "Dev Team",
|
|
363
|
+
folder: "whatsapp_dev-team",
|
|
364
|
+
trigger: "@Andy",
|
|
365
|
+
added_at: new Date().toISOString(),
|
|
366
|
+
containerConfig: {
|
|
367
|
+
additionalMounts: [
|
|
368
|
+
{
|
|
369
|
+
hostPath: "~/projects/webapp",
|
|
370
|
+
containerPath: "webapp",
|
|
371
|
+
readonly: false,
|
|
372
|
+
},
|
|
373
|
+
],
|
|
374
|
+
timeout: 600000,
|
|
375
|
+
},
|
|
376
|
+
});
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
Folder names follow the convention `{channel}_{group-name}` (e.g., `whatsapp_family-chat`, `telegram_dev-team`). The main group has `isMain: true` set during registration.
|
|
380
|
+
|
|
381
|
+
Additional mounts appear at `/workspace/extra/{containerPath}` inside the container.
|
|
382
|
+
|
|
383
|
+
**Mount syntax note:** Read-write mounts use `-v host:container`, but readonly mounts require `--mount "type=bind,source=...,target=...,readonly"` (the `:ro` suffix may not work on all runtimes).
|
|
384
|
+
|
|
385
|
+
### Claude Authentication
|
|
386
|
+
|
|
387
|
+
Configure authentication in a `.env` file in the project root. Two options:
|
|
388
|
+
|
|
389
|
+
**Option 1: Claude Subscription (OAuth token)**
|
|
390
|
+
```bash
|
|
391
|
+
CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-...
|
|
392
|
+
```
|
|
393
|
+
The token can be extracted from `~/.claude/.credentials.json` if you're logged in to Claude Code.
|
|
394
|
+
|
|
395
|
+
**Option 2: Pay-per-use API Key**
|
|
396
|
+
```bash
|
|
397
|
+
ANTHROPIC_API_KEY=sk-ant-api03-...
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
Only the authentication variables (`CLAUDE_CODE_OAUTH_TOKEN` and `ANTHROPIC_API_KEY`) are extracted from `.env` and written to `data/env/env`, then mounted into the container at `/workspace/env-dir/env` and sourced by the entrypoint script. This ensures other environment variables in `.env` are not exposed to the agent. This workaround is needed because some container runtimes lose `-e` environment variables when using `-i` (interactive mode with piped stdin).
|
|
401
|
+
|
|
402
|
+
### Changing the Assistant Name
|
|
403
|
+
|
|
404
|
+
Set the `ASSISTANT_NAME` environment variable:
|
|
405
|
+
|
|
406
|
+
```bash
|
|
407
|
+
ASSISTANT_NAME=Bot npm start
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
Or edit the default in `src/config.ts`. This changes:
|
|
411
|
+
- The trigger pattern (messages must start with `@YourName`)
|
|
412
|
+
- The response prefix (`YourName:` added automatically)
|
|
413
|
+
|
|
414
|
+
### Placeholder Values in launchd
|
|
415
|
+
|
|
416
|
+
Files with `{{PLACEHOLDER}}` values need to be configured:
|
|
417
|
+
- `{{PROJECT_ROOT}}` - Absolute path to your nanoclaw installation
|
|
418
|
+
- `{{NODE_PATH}}` - Path to node binary (detected via `which node`)
|
|
419
|
+
- `{{HOME}}` - User's home directory
|
|
420
|
+
|
|
421
|
+
---
|
|
422
|
+
|
|
423
|
+
## Memory System
|
|
424
|
+
|
|
425
|
+
NanoClaw uses a hierarchical memory system based on CLAUDE.md files.
|
|
426
|
+
|
|
427
|
+
### Memory Hierarchy
|
|
428
|
+
|
|
429
|
+
| Level | Location | Read By | Written By | Purpose |
|
|
430
|
+
|-------|----------|---------|------------|---------|
|
|
431
|
+
| **Global** | `groups/CLAUDE.md` | All groups | Main only | Preferences, facts, context shared across all conversations |
|
|
432
|
+
| **Group** | `groups/{name}/CLAUDE.md` | That group | That group | Group-specific context, conversation memory |
|
|
433
|
+
| **Files** | `groups/{name}/*.md` | That group | That group | Notes, research, documents created during conversation |
|
|
434
|
+
|
|
435
|
+
### How Memory Works
|
|
436
|
+
|
|
437
|
+
1. **Agent Context Loading**
|
|
438
|
+
- Agent runs with `cwd` set to `groups/{group-name}/`
|
|
439
|
+
- Claude Agent SDK with `settingSources: ['project']` automatically loads:
|
|
440
|
+
- `../CLAUDE.md` (parent directory = global memory)
|
|
441
|
+
- `./CLAUDE.md` (current directory = group memory)
|
|
442
|
+
|
|
443
|
+
2. **Writing Memory**
|
|
444
|
+
- When user says "remember this", agent writes to `./CLAUDE.md`
|
|
445
|
+
- When user says "remember this globally" (main channel only), agent writes to `../CLAUDE.md`
|
|
446
|
+
- Agent can create files like `notes.md`, `research.md` in the group folder
|
|
447
|
+
|
|
448
|
+
3. **Main Channel Privileges**
|
|
449
|
+
- Only the "main" group (self-chat) can write to global memory
|
|
450
|
+
- Main can manage registered groups and schedule tasks for any group
|
|
451
|
+
- Main can configure additional directory mounts for any group
|
|
452
|
+
- All groups have Bash access (safe because it runs inside container)
|
|
453
|
+
|
|
454
|
+
---
|
|
455
|
+
|
|
456
|
+
## Session Management
|
|
457
|
+
|
|
458
|
+
Sessions enable conversation continuity - Claude remembers what you talked about.
|
|
459
|
+
|
|
460
|
+
### How Sessions Work
|
|
461
|
+
|
|
462
|
+
1. Each group has a session ID stored in SQLite (`sessions` table, keyed by `group_folder`)
|
|
463
|
+
2. Session ID is passed to Claude Agent SDK's `resume` option
|
|
464
|
+
3. Claude continues the conversation with full context
|
|
465
|
+
4. Session transcripts are stored as JSONL files in `data/sessions/{group}/.claude/`
|
|
466
|
+
|
|
467
|
+
---
|
|
468
|
+
|
|
469
|
+
## Message Flow
|
|
470
|
+
|
|
471
|
+
### Incoming Message Flow
|
|
472
|
+
|
|
473
|
+
```
|
|
474
|
+
1. User sends a message via any connected channel
|
|
475
|
+
│
|
|
476
|
+
▼
|
|
477
|
+
2. Channel receives message (e.g. Baileys for WhatsApp, Bot API for Telegram)
|
|
478
|
+
│
|
|
479
|
+
▼
|
|
480
|
+
3. Message stored in SQLite (store/messages.db)
|
|
481
|
+
│
|
|
482
|
+
▼
|
|
483
|
+
4. Message loop polls SQLite (every 2 seconds)
|
|
484
|
+
│
|
|
485
|
+
▼
|
|
486
|
+
5. Router checks:
|
|
487
|
+
├── Is chat_jid in registered groups (SQLite)? → No: ignore
|
|
488
|
+
└── Does message match trigger pattern? → No: store but don't process
|
|
489
|
+
│
|
|
490
|
+
▼
|
|
491
|
+
6. Router catches up conversation:
|
|
492
|
+
├── Fetch all messages since last agent interaction
|
|
493
|
+
├── Format with timestamp and sender name
|
|
494
|
+
└── Build prompt with full conversation context
|
|
495
|
+
│
|
|
496
|
+
▼
|
|
497
|
+
7. Router invokes Claude Agent SDK:
|
|
498
|
+
├── cwd: groups/{group-name}/
|
|
499
|
+
├── prompt: conversation history + current message
|
|
500
|
+
├── resume: session_id (for continuity)
|
|
501
|
+
└── mcpServers: nanoclaw (scheduler)
|
|
502
|
+
│
|
|
503
|
+
▼
|
|
504
|
+
8. Claude processes message:
|
|
505
|
+
├── Reads CLAUDE.md files for context
|
|
506
|
+
└── Uses tools as needed (search, email, etc.)
|
|
507
|
+
│
|
|
508
|
+
▼
|
|
509
|
+
9. Router prefixes response with assistant name and sends via the owning channel
|
|
510
|
+
│
|
|
511
|
+
▼
|
|
512
|
+
10. Router updates last agent timestamp and saves session ID
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
### Trigger Word Matching
|
|
516
|
+
|
|
517
|
+
Messages must start with the trigger pattern (default: `@Andy`):
|
|
518
|
+
- `@Andy what's the weather?` → ✅ Triggers Claude
|
|
519
|
+
- `@andy help me` → ✅ Triggers (case insensitive)
|
|
520
|
+
- `Hey @Andy` → ❌ Ignored (trigger not at start)
|
|
521
|
+
- `What's up?` → ❌ Ignored (no trigger)
|
|
522
|
+
|
|
523
|
+
### Conversation Catch-Up
|
|
524
|
+
|
|
525
|
+
When a triggered message arrives, the agent receives all messages since its last interaction in that chat. Each message is formatted with timestamp and sender name:
|
|
526
|
+
|
|
527
|
+
```
|
|
528
|
+
[Jan 31 2:32 PM] John: hey everyone, should we do pizza tonight?
|
|
529
|
+
[Jan 31 2:33 PM] Sarah: sounds good to me
|
|
530
|
+
[Jan 31 2:35 PM] John: @Andy what toppings do you recommend?
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
This allows the agent to understand the conversation context even if it wasn't mentioned in every message.
|
|
534
|
+
|
|
535
|
+
---
|
|
536
|
+
|
|
537
|
+
## Commands
|
|
538
|
+
|
|
539
|
+
### Commands Available in Any Group
|
|
540
|
+
|
|
541
|
+
| Command | Example | Effect |
|
|
542
|
+
|---------|---------|--------|
|
|
543
|
+
| `@Assistant [message]` | `@Andy what's the weather?` | Talk to Claude |
|
|
544
|
+
|
|
545
|
+
### Commands Available in Main Channel Only
|
|
546
|
+
|
|
547
|
+
| Command | Example | Effect |
|
|
548
|
+
|---------|---------|--------|
|
|
549
|
+
| `@Assistant add group "Name"` | `@Andy add group "Family Chat"` | Register a new group |
|
|
550
|
+
| `@Assistant remove group "Name"` | `@Andy remove group "Work Team"` | Unregister a group |
|
|
551
|
+
| `@Assistant list groups` | `@Andy list groups` | Show registered groups |
|
|
552
|
+
| `@Assistant remember [fact]` | `@Andy remember I prefer dark mode` | Add to global memory |
|
|
553
|
+
|
|
554
|
+
---
|
|
555
|
+
|
|
556
|
+
## Scheduled Tasks
|
|
557
|
+
|
|
558
|
+
NanoClaw has a built-in scheduler that runs tasks as full agents in their group's context.
|
|
559
|
+
|
|
560
|
+
### How Scheduling Works
|
|
561
|
+
|
|
562
|
+
1. **Group Context**: Tasks created in a group run with that group's working directory and memory
|
|
563
|
+
2. **Full Agent Capabilities**: Scheduled tasks have access to all tools (WebSearch, file operations, etc.)
|
|
564
|
+
3. **Optional Messaging**: Tasks can send messages to their group using the `send_message` tool, or complete silently
|
|
565
|
+
4. **Main Channel Privileges**: The main channel can schedule tasks for any group and view all tasks
|
|
566
|
+
|
|
567
|
+
### Schedule Types
|
|
568
|
+
|
|
569
|
+
| Type | Value Format | Example |
|
|
570
|
+
|------|--------------|---------|
|
|
571
|
+
| `cron` | Cron expression | `0 9 * * 1` (Mondays at 9am) |
|
|
572
|
+
| `interval` | Milliseconds | `3600000` (every hour) |
|
|
573
|
+
| `once` | ISO timestamp | `2024-12-25T09:00:00Z` |
|
|
574
|
+
|
|
575
|
+
### Creating a Task
|
|
576
|
+
|
|
577
|
+
```
|
|
578
|
+
User: @Andy remind me every Monday at 9am to review the weekly metrics
|
|
579
|
+
|
|
580
|
+
Claude: [calls mcp__nanoclaw__schedule_task]
|
|
581
|
+
{
|
|
582
|
+
"prompt": "Send a reminder to review weekly metrics. Be encouraging!",
|
|
583
|
+
"schedule_type": "cron",
|
|
584
|
+
"schedule_value": "0 9 * * 1"
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
Claude: Done! I'll remind you every Monday at 9am.
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
### One-Time Tasks
|
|
591
|
+
|
|
592
|
+
```
|
|
593
|
+
User: @Andy at 5pm today, send me a summary of today's emails
|
|
594
|
+
|
|
595
|
+
Claude: [calls mcp__nanoclaw__schedule_task]
|
|
596
|
+
{
|
|
597
|
+
"prompt": "Search for today's emails, summarize the important ones, and send the summary to the group.",
|
|
598
|
+
"schedule_type": "once",
|
|
599
|
+
"schedule_value": "2024-01-31T17:00:00Z"
|
|
600
|
+
}
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
### Managing Tasks
|
|
604
|
+
|
|
605
|
+
From any group:
|
|
606
|
+
- `@Andy list my scheduled tasks` - View tasks for this group
|
|
607
|
+
- `@Andy pause task [id]` - Pause a task
|
|
608
|
+
- `@Andy resume task [id]` - Resume a paused task
|
|
609
|
+
- `@Andy cancel task [id]` - Delete a task
|
|
610
|
+
|
|
611
|
+
From main channel:
|
|
612
|
+
- `@Andy list all tasks` - View tasks from all groups
|
|
613
|
+
- `@Andy schedule task for "Family Chat": [prompt]` - Schedule for another group
|
|
614
|
+
|
|
615
|
+
---
|
|
616
|
+
|
|
617
|
+
## MCP Servers
|
|
618
|
+
|
|
619
|
+
### NanoClaw MCP (built-in)
|
|
620
|
+
|
|
621
|
+
The `nanoclaw` MCP server is created dynamically per agent call with the current group's context.
|
|
622
|
+
|
|
623
|
+
**Available Tools:**
|
|
624
|
+
| Tool | Purpose |
|
|
625
|
+
|------|---------|
|
|
626
|
+
| `schedule_task` | Schedule a recurring or one-time task |
|
|
627
|
+
| `list_tasks` | Show tasks (group's tasks, or all if main) |
|
|
628
|
+
| `get_task` | Get task details and run history |
|
|
629
|
+
| `update_task` | Modify task prompt or schedule |
|
|
630
|
+
| `pause_task` | Pause a task |
|
|
631
|
+
| `resume_task` | Resume a paused task |
|
|
632
|
+
| `cancel_task` | Delete a task |
|
|
633
|
+
| `send_message` | Send a message to the group via its channel |
|
|
634
|
+
|
|
635
|
+
---
|
|
636
|
+
|
|
637
|
+
## Deployment
|
|
638
|
+
|
|
639
|
+
NanoClaw runs as a single macOS launchd service.
|
|
640
|
+
|
|
641
|
+
### Startup Sequence
|
|
642
|
+
|
|
643
|
+
When NanoClaw starts, it:
|
|
644
|
+
1. **Ensures container runtime is running** - Automatically starts it if needed; kills orphaned NanoClaw containers from previous runs
|
|
645
|
+
2. Initializes the SQLite database (migrates from JSON files if they exist)
|
|
646
|
+
3. Loads state from SQLite (registered groups, sessions, router state)
|
|
647
|
+
4. **Connects channels** — loops through registered channels, instantiates those with credentials, calls `connect()` on each
|
|
648
|
+
5. Once at least one channel is connected:
|
|
649
|
+
- Starts the scheduler loop
|
|
650
|
+
- Starts the IPC watcher for container messages
|
|
651
|
+
- Sets up the per-group queue with `processGroupMessages`
|
|
652
|
+
- Recovers any unprocessed messages from before shutdown
|
|
653
|
+
- Starts the message polling loop
|
|
654
|
+
|
|
655
|
+
### Service: com.nanoclaw
|
|
656
|
+
|
|
657
|
+
**launchd/com.nanoclaw.plist:**
|
|
658
|
+
```xml
|
|
659
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
660
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "...">
|
|
661
|
+
<plist version="1.0">
|
|
662
|
+
<dict>
|
|
663
|
+
<key>Label</key>
|
|
664
|
+
<string>com.nanoclaw</string>
|
|
665
|
+
<key>ProgramArguments</key>
|
|
666
|
+
<array>
|
|
667
|
+
<string>{{NODE_PATH}}</string>
|
|
668
|
+
<string>{{PROJECT_ROOT}}/dist/index.js</string>
|
|
669
|
+
</array>
|
|
670
|
+
<key>WorkingDirectory</key>
|
|
671
|
+
<string>{{PROJECT_ROOT}}</string>
|
|
672
|
+
<key>RunAtLoad</key>
|
|
673
|
+
<true/>
|
|
674
|
+
<key>KeepAlive</key>
|
|
675
|
+
<true/>
|
|
676
|
+
<key>EnvironmentVariables</key>
|
|
677
|
+
<dict>
|
|
678
|
+
<key>PATH</key>
|
|
679
|
+
<string>{{HOME}}/.local/bin:/usr/local/bin:/usr/bin:/bin</string>
|
|
680
|
+
<key>HOME</key>
|
|
681
|
+
<string>{{HOME}}</string>
|
|
682
|
+
<key>ASSISTANT_NAME</key>
|
|
683
|
+
<string>Andy</string>
|
|
684
|
+
</dict>
|
|
685
|
+
<key>StandardOutPath</key>
|
|
686
|
+
<string>{{PROJECT_ROOT}}/logs/nanoclaw.log</string>
|
|
687
|
+
<key>StandardErrorPath</key>
|
|
688
|
+
<string>{{PROJECT_ROOT}}/logs/nanoclaw.error.log</string>
|
|
689
|
+
</dict>
|
|
690
|
+
</plist>
|
|
691
|
+
```
|
|
692
|
+
|
|
693
|
+
### Managing the Service
|
|
694
|
+
|
|
695
|
+
```bash
|
|
696
|
+
# Install service
|
|
697
|
+
cp launchd/com.nanoclaw.plist ~/Library/LaunchAgents/
|
|
698
|
+
|
|
699
|
+
# Start service
|
|
700
|
+
launchctl load ~/Library/LaunchAgents/com.nanoclaw.plist
|
|
701
|
+
|
|
702
|
+
# Stop service
|
|
703
|
+
launchctl unload ~/Library/LaunchAgents/com.nanoclaw.plist
|
|
704
|
+
|
|
705
|
+
# Check status
|
|
706
|
+
launchctl list | grep nanoclaw
|
|
707
|
+
|
|
708
|
+
# View logs
|
|
709
|
+
tail -f logs/nanoclaw.log
|
|
710
|
+
```
|
|
711
|
+
|
|
712
|
+
---
|
|
713
|
+
|
|
714
|
+
## Security Considerations
|
|
715
|
+
|
|
716
|
+
### Container Isolation
|
|
717
|
+
|
|
718
|
+
All agents run inside containers (lightweight Linux VMs), providing:
|
|
719
|
+
- **Filesystem isolation**: Agents can only access mounted directories
|
|
720
|
+
- **Safe Bash access**: Commands run inside the container, not on your Mac
|
|
721
|
+
- **Network isolation**: Can be configured per-container if needed
|
|
722
|
+
- **Process isolation**: Container processes can't affect the host
|
|
723
|
+
- **Non-root user**: Container runs as unprivileged `node` user (uid 1000)
|
|
724
|
+
|
|
725
|
+
### Prompt Injection Risk
|
|
726
|
+
|
|
727
|
+
WhatsApp messages could contain malicious instructions attempting to manipulate Claude's behavior.
|
|
728
|
+
|
|
729
|
+
**Mitigations:**
|
|
730
|
+
- Container isolation limits blast radius
|
|
731
|
+
- Only registered groups are processed
|
|
732
|
+
- Trigger word required (reduces accidental processing)
|
|
733
|
+
- Agents can only access their group's mounted directories
|
|
734
|
+
- Main can configure additional directories per group
|
|
735
|
+
- Claude's built-in safety training
|
|
736
|
+
|
|
737
|
+
**Recommendations:**
|
|
738
|
+
- Only register trusted groups
|
|
739
|
+
- Review additional directory mounts carefully
|
|
740
|
+
- Review scheduled tasks periodically
|
|
741
|
+
- Monitor logs for unusual activity
|
|
742
|
+
|
|
743
|
+
### Credential Storage
|
|
744
|
+
|
|
745
|
+
| Credential | Storage Location | Notes |
|
|
746
|
+
|------------|------------------|-------|
|
|
747
|
+
| Claude CLI Auth | data/sessions/{group}/.claude/ | Per-group isolation, mounted to /home/node/.claude/ |
|
|
748
|
+
| WhatsApp Session | store/auth/ | Auto-created, persists ~20 days |
|
|
749
|
+
|
|
750
|
+
### File Permissions
|
|
751
|
+
|
|
752
|
+
The groups/ folder contains personal memory and should be protected:
|
|
753
|
+
```bash
|
|
754
|
+
chmod 700 groups/
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
---
|
|
758
|
+
|
|
759
|
+
## Troubleshooting
|
|
760
|
+
|
|
761
|
+
### Common Issues
|
|
762
|
+
|
|
763
|
+
| Issue | Cause | Solution |
|
|
764
|
+
|-------|-------|----------|
|
|
765
|
+
| No response to messages | Service not running | Check `launchctl list | grep nanoclaw` |
|
|
766
|
+
| "Claude Code process exited with code 1" | Container runtime failed to start | Check logs; NanoClaw auto-starts container runtime but may fail |
|
|
767
|
+
| "Claude Code process exited with code 1" | Session mount path wrong | Ensure mount is to `/home/node/.claude/` not `/root/.claude/` |
|
|
768
|
+
| Session not continuing | Session ID not saved | Check SQLite: `sqlite3 store/messages.db "SELECT * FROM sessions"` |
|
|
769
|
+
| Session not continuing | Mount path mismatch | Container user is `node` with HOME=/home/node; sessions must be at `/home/node/.claude/` |
|
|
770
|
+
| "QR code expired" | WhatsApp session expired | Delete store/auth/ and restart |
|
|
771
|
+
| "No groups registered" | Haven't added groups | Use `@Andy add group "Name"` in main |
|
|
772
|
+
|
|
773
|
+
### Log Location
|
|
774
|
+
|
|
775
|
+
- `logs/nanoclaw.log` - stdout
|
|
776
|
+
- `logs/nanoclaw.error.log` - stderr
|
|
777
|
+
|
|
778
|
+
### Debug Mode
|
|
779
|
+
|
|
780
|
+
Run manually for verbose output:
|
|
781
|
+
```bash
|
|
782
|
+
npm run dev
|
|
783
|
+
# or
|
|
784
|
+
node dist/index.js
|
|
785
|
+
```
|