@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.
Files changed (305) hide show
  1. package/.claude/settings.json +1 -0
  2. package/.claude/skills/add-compact/SKILL.md +135 -0
  3. package/.claude/skills/add-discord/SKILL.md +203 -0
  4. package/.claude/skills/add-gmail/SKILL.md +220 -0
  5. package/.claude/skills/add-image-vision/SKILL.md +94 -0
  6. package/.claude/skills/add-ollama-tool/SKILL.md +153 -0
  7. package/.claude/skills/add-parallel/SKILL.md +290 -0
  8. package/.claude/skills/add-pdf-reader/SKILL.md +104 -0
  9. package/.claude/skills/add-reactions/SKILL.md +117 -0
  10. package/.claude/skills/add-slack/SKILL.md +207 -0
  11. package/.claude/skills/add-telegram/SKILL.md +222 -0
  12. package/.claude/skills/add-telegram-swarm/SKILL.md +384 -0
  13. package/.claude/skills/add-voice-transcription/SKILL.md +148 -0
  14. package/.claude/skills/add-whatsapp/SKILL.md +372 -0
  15. package/.claude/skills/convert-to-apple-container/SKILL.md +175 -0
  16. package/.claude/skills/customize/SKILL.md +110 -0
  17. package/.claude/skills/debug/SKILL.md +349 -0
  18. package/.claude/skills/get-qodo-rules/SKILL.md +122 -0
  19. package/.claude/skills/get-qodo-rules/references/output-format.md +41 -0
  20. package/.claude/skills/get-qodo-rules/references/pagination.md +33 -0
  21. package/.claude/skills/get-qodo-rules/references/repository-scope.md +26 -0
  22. package/.claude/skills/qodo-pr-resolver/SKILL.md +326 -0
  23. package/.claude/skills/qodo-pr-resolver/resources/providers.md +329 -0
  24. package/.claude/skills/setup/SKILL.md +218 -0
  25. package/.claude/skills/update-nanoclaw/SKILL.md +235 -0
  26. package/.claude/skills/update-skills/SKILL.md +130 -0
  27. package/.claude/skills/use-local-whisper/SKILL.md +152 -0
  28. package/.claude/skills/x-integration/SKILL.md +417 -0
  29. package/.claude/skills/x-integration/agent.ts +243 -0
  30. package/.claude/skills/x-integration/host.ts +159 -0
  31. package/.claude/skills/x-integration/lib/browser.ts +148 -0
  32. package/.claude/skills/x-integration/lib/config.ts +62 -0
  33. package/.claude/skills/x-integration/scripts/like.ts +56 -0
  34. package/.claude/skills/x-integration/scripts/post.ts +66 -0
  35. package/.claude/skills/x-integration/scripts/quote.ts +80 -0
  36. package/.claude/skills/x-integration/scripts/reply.ts +74 -0
  37. package/.claude/skills/x-integration/scripts/retweet.ts +62 -0
  38. package/.claude/skills/x-integration/scripts/setup.ts +87 -0
  39. package/.env.example +1 -0
  40. package/.github/CODEOWNERS +10 -0
  41. package/.github/PULL_REQUEST_TEMPLATE.md +14 -0
  42. package/.github/workflows/bump-version.yml +32 -0
  43. package/.github/workflows/ci.yml +25 -0
  44. package/.github/workflows/merge-forward-skills.yml +160 -0
  45. package/.github/workflows/update-tokens.yml +42 -0
  46. package/.husky/pre-commit +1 -0
  47. package/.mcp.json +3 -0
  48. package/.nvmrc +1 -0
  49. package/.prettierrc +3 -0
  50. package/CHANGELOG.md +8 -0
  51. package/CLAUDE.md +64 -0
  52. package/CONTRIBUTING.md +23 -0
  53. package/CONTRIBUTORS.md +15 -0
  54. package/LICENSE +21 -0
  55. package/NanoClaw_with_Web-Support.md +290 -0
  56. package/README.md +261 -0
  57. package/README_zh.md +200 -0
  58. package/assets/nanoclaw-favicon.png +0 -0
  59. package/assets/nanoclaw-icon.png +0 -0
  60. package/assets/nanoclaw-logo-dark.png +0 -0
  61. package/assets/nanoclaw-logo.png +0 -0
  62. package/assets/nanoclaw-profile.jpeg +0 -0
  63. package/assets/nanoclaw-sales.png +0 -0
  64. package/assets/social-preview.jpg +0 -0
  65. package/config-examples/mount-allowlist.json +25 -0
  66. package/container/Dockerfile +70 -0
  67. package/container/agent-runner/package-lock.json +1524 -0
  68. package/container/agent-runner/package.json +21 -0
  69. package/container/agent-runner/src/index.ts +558 -0
  70. package/container/agent-runner/src/ipc-mcp-stdio.ts +338 -0
  71. package/container/agent-runner/tsconfig.json +15 -0
  72. package/container/build.sh +23 -0
  73. package/container/skills/agent-browser/SKILL.md +159 -0
  74. package/container/skills/capabilities/SKILL.md +100 -0
  75. package/container/skills/status/SKILL.md +104 -0
  76. package/dist/channels/index.d.ts +2 -0
  77. package/dist/channels/index.d.ts.map +1 -0
  78. package/dist/channels/index.js +9 -0
  79. package/dist/channels/index.js.map +1 -0
  80. package/dist/channels/registry.d.ts +13 -0
  81. package/dist/channels/registry.d.ts.map +1 -0
  82. package/dist/channels/registry.js +11 -0
  83. package/dist/channels/registry.js.map +1 -0
  84. package/dist/channels/registry.test.d.ts +2 -0
  85. package/dist/channels/registry.test.d.ts.map +1 -0
  86. package/dist/channels/registry.test.js +32 -0
  87. package/dist/channels/registry.test.js.map +1 -0
  88. package/dist/channels/web.d.ts +2 -0
  89. package/dist/channels/web.d.ts.map +1 -0
  90. package/dist/channels/web.js +1738 -0
  91. package/dist/channels/web.js.map +1 -0
  92. package/dist/cli.d.ts +11 -0
  93. package/dist/cli.d.ts.map +1 -0
  94. package/dist/cli.js +182 -0
  95. package/dist/cli.js.map +1 -0
  96. package/dist/config.d.ts +19 -0
  97. package/dist/config.d.ts.map +1 -0
  98. package/dist/config.js +36 -0
  99. package/dist/config.js.map +1 -0
  100. package/dist/container-runner.d.ts +44 -0
  101. package/dist/container-runner.d.ts.map +1 -0
  102. package/dist/container-runner.js +467 -0
  103. package/dist/container-runner.js.map +1 -0
  104. package/dist/container-runner.test.d.ts +2 -0
  105. package/dist/container-runner.test.d.ts.map +1 -0
  106. package/dist/container-runner.test.js +150 -0
  107. package/dist/container-runner.test.js.map +1 -0
  108. package/dist/container-runtime.d.ts +22 -0
  109. package/dist/container-runtime.d.ts.map +1 -0
  110. package/dist/container-runtime.js +96 -0
  111. package/dist/container-runtime.js.map +1 -0
  112. package/dist/container-runtime.test.d.ts +2 -0
  113. package/dist/container-runtime.test.d.ts.map +1 -0
  114. package/dist/container-runtime.test.js +93 -0
  115. package/dist/container-runtime.test.js.map +1 -0
  116. package/dist/credential-proxy.d.ts +21 -0
  117. package/dist/credential-proxy.d.ts.map +1 -0
  118. package/dist/credential-proxy.js +95 -0
  119. package/dist/credential-proxy.js.map +1 -0
  120. package/dist/credential-proxy.test.d.ts +2 -0
  121. package/dist/credential-proxy.test.d.ts.map +1 -0
  122. package/dist/credential-proxy.test.js +134 -0
  123. package/dist/credential-proxy.test.js.map +1 -0
  124. package/dist/db.d.ts +115 -0
  125. package/dist/db.d.ts.map +1 -0
  126. package/dist/db.js +549 -0
  127. package/dist/db.js.map +1 -0
  128. package/dist/db.test.d.ts +2 -0
  129. package/dist/db.test.d.ts.map +1 -0
  130. package/dist/db.test.js +360 -0
  131. package/dist/db.test.js.map +1 -0
  132. package/dist/env.d.ts +8 -0
  133. package/dist/env.d.ts.map +1 -0
  134. package/dist/env.js +42 -0
  135. package/dist/env.js.map +1 -0
  136. package/dist/formatting.test.d.ts +2 -0
  137. package/dist/formatting.test.d.ts.map +1 -0
  138. package/dist/formatting.test.js +183 -0
  139. package/dist/formatting.test.js.map +1 -0
  140. package/dist/group-folder.d.ts +5 -0
  141. package/dist/group-folder.d.ts.map +1 -0
  142. package/dist/group-folder.js +44 -0
  143. package/dist/group-folder.js.map +1 -0
  144. package/dist/group-folder.test.d.ts +2 -0
  145. package/dist/group-folder.test.d.ts.map +1 -0
  146. package/dist/group-folder.test.js +29 -0
  147. package/dist/group-folder.test.js.map +1 -0
  148. package/dist/group-queue.d.ts +34 -0
  149. package/dist/group-queue.d.ts.map +1 -0
  150. package/dist/group-queue.js +263 -0
  151. package/dist/group-queue.js.map +1 -0
  152. package/dist/group-queue.test.d.ts +2 -0
  153. package/dist/group-queue.test.d.ts.map +1 -0
  154. package/dist/group-queue.test.js +341 -0
  155. package/dist/group-queue.test.js.map +1 -0
  156. package/dist/index.d.ts +12 -0
  157. package/dist/index.d.ts.map +1 -0
  158. package/dist/index.js +518 -0
  159. package/dist/index.js.map +1 -0
  160. package/dist/ipc-auth.test.d.ts +2 -0
  161. package/dist/ipc-auth.test.d.ts.map +1 -0
  162. package/dist/ipc-auth.test.js +434 -0
  163. package/dist/ipc-auth.test.js.map +1 -0
  164. package/dist/ipc.d.ts +32 -0
  165. package/dist/ipc.d.ts.map +1 -0
  166. package/dist/ipc.js +311 -0
  167. package/dist/ipc.js.map +1 -0
  168. package/dist/logger.d.ts +3 -0
  169. package/dist/logger.d.ts.map +1 -0
  170. package/dist/logger.js +14 -0
  171. package/dist/logger.js.map +1 -0
  172. package/dist/mount-security.d.ts +34 -0
  173. package/dist/mount-security.d.ts.map +1 -0
  174. package/dist/mount-security.js +325 -0
  175. package/dist/mount-security.js.map +1 -0
  176. package/dist/remote-control.d.ts +32 -0
  177. package/dist/remote-control.d.ts.map +1 -0
  178. package/dist/remote-control.js +185 -0
  179. package/dist/remote-control.js.map +1 -0
  180. package/dist/remote-control.test.d.ts +2 -0
  181. package/dist/remote-control.test.d.ts.map +1 -0
  182. package/dist/remote-control.test.js +321 -0
  183. package/dist/remote-control.test.js.map +1 -0
  184. package/dist/router.d.ts +8 -0
  185. package/dist/router.d.ts.map +1 -0
  186. package/dist/router.js +37 -0
  187. package/dist/router.js.map +1 -0
  188. package/dist/routing.test.d.ts +2 -0
  189. package/dist/routing.test.d.ts.map +1 -0
  190. package/dist/routing.test.js +81 -0
  191. package/dist/routing.test.js.map +1 -0
  192. package/dist/sender-allowlist.d.ts +14 -0
  193. package/dist/sender-allowlist.d.ts.map +1 -0
  194. package/dist/sender-allowlist.js +79 -0
  195. package/dist/sender-allowlist.js.map +1 -0
  196. package/dist/sender-allowlist.test.d.ts +2 -0
  197. package/dist/sender-allowlist.test.d.ts.map +1 -0
  198. package/dist/sender-allowlist.test.js +186 -0
  199. package/dist/sender-allowlist.test.js.map +1 -0
  200. package/dist/session-commands.d.ts +47 -0
  201. package/dist/session-commands.d.ts.map +1 -0
  202. package/dist/session-commands.js +102 -0
  203. package/dist/session-commands.js.map +1 -0
  204. package/dist/session-commands.test.d.ts +2 -0
  205. package/dist/session-commands.test.d.ts.map +1 -0
  206. package/dist/session-commands.test.js +190 -0
  207. package/dist/session-commands.test.js.map +1 -0
  208. package/dist/task-scheduler.d.ts +22 -0
  209. package/dist/task-scheduler.d.ts.map +1 -0
  210. package/dist/task-scheduler.js +210 -0
  211. package/dist/task-scheduler.js.map +1 -0
  212. package/dist/task-scheduler.test.d.ts +2 -0
  213. package/dist/task-scheduler.test.d.ts.map +1 -0
  214. package/dist/task-scheduler.test.js +107 -0
  215. package/dist/task-scheduler.test.js.map +1 -0
  216. package/dist/timezone.d.ts +6 -0
  217. package/dist/timezone.d.ts.map +1 -0
  218. package/dist/timezone.js +17 -0
  219. package/dist/timezone.js.map +1 -0
  220. package/dist/timezone.test.d.ts +2 -0
  221. package/dist/timezone.test.d.ts.map +1 -0
  222. package/dist/timezone.test.js +23 -0
  223. package/dist/timezone.test.js.map +1 -0
  224. package/dist/types.d.ts +78 -0
  225. package/dist/types.d.ts.map +1 -0
  226. package/dist/types.js +2 -0
  227. package/dist/types.js.map +1 -0
  228. package/docs/APPLE-CONTAINER-NETWORKING.md +90 -0
  229. package/docs/DEBUG_CHECKLIST.md +143 -0
  230. package/docs/REQUIREMENTS.md +196 -0
  231. package/docs/SDK_DEEP_DIVE.md +643 -0
  232. package/docs/SECURITY.md +122 -0
  233. package/docs/SPEC.md +785 -0
  234. package/docs/docker-sandboxes.md +359 -0
  235. package/docs/nanoclaw-architecture-final.md +1063 -0
  236. package/docs/nanorepo-architecture.md +168 -0
  237. package/docs/skills-as-branches.md +662 -0
  238. package/groups/global/CLAUDE.md +58 -0
  239. package/groups/main/CLAUDE.md +246 -0
  240. package/launchd/com.nanoclaw.plist +32 -0
  241. package/package.json +45 -0
  242. package/repo-tokens/README.md +113 -0
  243. package/repo-tokens/action.yml +186 -0
  244. package/repo-tokens/badge.svg +23 -0
  245. package/repo-tokens/examples/green.svg +14 -0
  246. package/repo-tokens/examples/red.svg +14 -0
  247. package/repo-tokens/examples/yellow-green.svg +14 -0
  248. package/repo-tokens/examples/yellow.svg +14 -0
  249. package/scripts/run-migrations.ts +105 -0
  250. package/setup/container.ts +144 -0
  251. package/setup/environment.test.ts +121 -0
  252. package/setup/environment.ts +94 -0
  253. package/setup/groups.ts +229 -0
  254. package/setup/index.ts +58 -0
  255. package/setup/mounts.ts +115 -0
  256. package/setup/platform.test.ts +120 -0
  257. package/setup/platform.ts +132 -0
  258. package/setup/register.test.ts +257 -0
  259. package/setup/register.ts +177 -0
  260. package/setup/service.test.ts +187 -0
  261. package/setup/service.ts +362 -0
  262. package/setup/status.ts +16 -0
  263. package/setup/verify.ts +192 -0
  264. package/setup.sh +161 -0
  265. package/src/channels/index.ts +12 -0
  266. package/src/channels/registry.test.ts +42 -0
  267. package/src/channels/registry.ts +32 -0
  268. package/src/channels/web.ts +1856 -0
  269. package/src/cli.ts +209 -0
  270. package/src/config.ts +73 -0
  271. package/src/container-runner.test.ts +210 -0
  272. package/src/container-runner.ts +707 -0
  273. package/src/container-runtime.test.ts +149 -0
  274. package/src/container-runtime.ts +127 -0
  275. package/src/credential-proxy.test.ts +192 -0
  276. package/src/credential-proxy.ts +125 -0
  277. package/src/db.test.ts +484 -0
  278. package/src/db.ts +803 -0
  279. package/src/env.ts +42 -0
  280. package/src/formatting.test.ts +256 -0
  281. package/src/group-folder.test.ts +43 -0
  282. package/src/group-folder.ts +44 -0
  283. package/src/group-queue.test.ts +484 -0
  284. package/src/group-queue.ts +365 -0
  285. package/src/index.ts +731 -0
  286. package/src/ipc-auth.test.ts +679 -0
  287. package/src/ipc.ts +461 -0
  288. package/src/logger.ts +16 -0
  289. package/src/mount-security.ts +419 -0
  290. package/src/remote-control.test.ts +397 -0
  291. package/src/remote-control.ts +224 -0
  292. package/src/router.ts +52 -0
  293. package/src/routing.test.ts +170 -0
  294. package/src/sender-allowlist.test.ts +216 -0
  295. package/src/sender-allowlist.ts +128 -0
  296. package/src/session-commands.test.ts +247 -0
  297. package/src/session-commands.ts +163 -0
  298. package/src/task-scheduler.test.ts +129 -0
  299. package/src/task-scheduler.ts +295 -0
  300. package/src/timezone.test.ts +29 -0
  301. package/src/timezone.ts +16 -0
  302. package/src/types.ts +107 -0
  303. package/tsconfig.json +20 -0
  304. package/vitest.config.ts +7 -0
  305. package/vitest.skills.config.ts +7 -0
@@ -0,0 +1,349 @@
1
+ ---
2
+ name: debug
3
+ description: Debug container agent issues. Use when things aren't working, container fails, authentication problems, or to understand how the container system works. Covers logs, environment variables, mounts, and common issues.
4
+ ---
5
+
6
+ # NanoClaw Container Debugging
7
+
8
+ This guide covers debugging the containerized agent execution system.
9
+
10
+ ## Architecture Overview
11
+
12
+ ```
13
+ Host (macOS) Container (Linux VM)
14
+ ─────────────────────────────────────────────────────────────
15
+ src/container-runner.ts container/agent-runner/
16
+ │ │
17
+ │ spawns container │ runs Claude Agent SDK
18
+ │ with volume mounts │ with MCP servers
19
+ │ │
20
+ ├── data/env/env ──────────────> /workspace/env-dir/env
21
+ ├── groups/{folder} ───────────> /workspace/group
22
+ ├── data/ipc/{folder} ────────> /workspace/ipc
23
+ ├── data/sessions/{folder}/.claude/ ──> /home/node/.claude/ (isolated per-group)
24
+ └── (main only) project root ──> /workspace/project
25
+ ```
26
+
27
+ **Important:** The container runs as user `node` with `HOME=/home/node`. Session files must be mounted to `/home/node/.claude/` (not `/root/.claude/`) for session resumption to work.
28
+
29
+ ## Log Locations
30
+
31
+ | Log | Location | Content |
32
+ |-----|----------|---------|
33
+ | **Main app logs** | `logs/nanoclaw.log` | Host-side WhatsApp, routing, container spawning |
34
+ | **Main app errors** | `logs/nanoclaw.error.log` | Host-side errors |
35
+ | **Container run logs** | `groups/{folder}/logs/container-*.log` | Per-run: input, mounts, stderr, stdout |
36
+ | **Claude sessions** | `~/.claude/projects/` | Claude Code session history |
37
+
38
+ ## Enabling Debug Logging
39
+
40
+ Set `LOG_LEVEL=debug` for verbose output:
41
+
42
+ ```bash
43
+ # For development
44
+ LOG_LEVEL=debug npm run dev
45
+
46
+ # For launchd service (macOS), add to plist EnvironmentVariables:
47
+ <key>LOG_LEVEL</key>
48
+ <string>debug</string>
49
+ # For systemd service (Linux), add to unit [Service] section:
50
+ # Environment=LOG_LEVEL=debug
51
+ ```
52
+
53
+ Debug level shows:
54
+ - Full mount configurations
55
+ - Container command arguments
56
+ - Real-time container stderr
57
+
58
+ ## Common Issues
59
+
60
+ ### 1. "Claude Code process exited with code 1"
61
+
62
+ **Check the container log file** in `groups/{folder}/logs/container-*.log`
63
+
64
+ Common causes:
65
+
66
+ #### Missing Authentication
67
+ ```
68
+ Invalid API key · Please run /login
69
+ ```
70
+ **Fix:** Ensure `.env` file exists with either OAuth token or API key:
71
+ ```bash
72
+ cat .env # Should show one of:
73
+ # CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-... (subscription)
74
+ # ANTHROPIC_API_KEY=sk-ant-api03-... (pay-per-use)
75
+ ```
76
+
77
+ #### Root User Restriction
78
+ ```
79
+ --dangerously-skip-permissions cannot be used with root/sudo privileges
80
+ ```
81
+ **Fix:** Container must run as non-root user. Check Dockerfile has `USER node`.
82
+
83
+ ### 2. Environment Variables Not Passing
84
+
85
+ **Runtime note:** Environment variables passed via `-e` may be lost when using `-i` (interactive/piped stdin).
86
+
87
+ **Workaround:** The system extracts only authentication variables (`CLAUDE_CODE_OAUTH_TOKEN`, `ANTHROPIC_API_KEY`) from `.env` and mounts them for sourcing inside the container. Other env vars are not exposed.
88
+
89
+ To verify env vars are reaching the container:
90
+ ```bash
91
+ echo '{}' | docker run -i \
92
+ -v $(pwd)/data/env:/workspace/env-dir:ro \
93
+ --entrypoint /bin/bash nanoclaw-agent:latest \
94
+ -c 'export $(cat /workspace/env-dir/env | xargs); echo "OAuth: ${#CLAUDE_CODE_OAUTH_TOKEN} chars, API: ${#ANTHROPIC_API_KEY} chars"'
95
+ ```
96
+
97
+ ### 3. Mount Issues
98
+
99
+ **Container mount notes:**
100
+ - Docker supports both `-v` and `--mount` syntax
101
+ - Use `:ro` suffix for readonly mounts:
102
+ ```bash
103
+ # Readonly
104
+ -v /path:/container/path:ro
105
+
106
+ # Read-write
107
+ -v /path:/container/path
108
+ ```
109
+
110
+ To check what's mounted inside a container:
111
+ ```bash
112
+ docker run --rm --entrypoint /bin/bash nanoclaw-agent:latest -c 'ls -la /workspace/'
113
+ ```
114
+
115
+ Expected structure:
116
+ ```
117
+ /workspace/
118
+ ├── env-dir/env # Environment file (CLAUDE_CODE_OAUTH_TOKEN or ANTHROPIC_API_KEY)
119
+ ├── group/ # Current group folder (cwd)
120
+ ├── project/ # Project root (main channel only)
121
+ ├── global/ # Global CLAUDE.md (non-main only)
122
+ ├── ipc/ # Inter-process communication
123
+ │ ├── messages/ # Outgoing WhatsApp messages
124
+ │ ├── tasks/ # Scheduled task commands
125
+ │ ├── current_tasks.json # Read-only: scheduled tasks visible to this group
126
+ │ └── available_groups.json # Read-only: WhatsApp groups for activation (main only)
127
+ └── extra/ # Additional custom mounts
128
+ ```
129
+
130
+ ### 4. Permission Issues
131
+
132
+ The container runs as user `node` (uid 1000). Check ownership:
133
+ ```bash
134
+ docker run --rm --entrypoint /bin/bash nanoclaw-agent:latest -c '
135
+ whoami
136
+ ls -la /workspace/
137
+ ls -la /app/
138
+ '
139
+ ```
140
+
141
+ All of `/workspace/` and `/app/` should be owned by `node`.
142
+
143
+ ### 5. Session Not Resuming / "Claude Code process exited with code 1"
144
+
145
+ If sessions aren't being resumed (new session ID every time), or Claude Code exits with code 1 when resuming:
146
+
147
+ **Root cause:** The SDK looks for sessions at `$HOME/.claude/projects/`. Inside the container, `HOME=/home/node`, so it looks at `/home/node/.claude/projects/`.
148
+
149
+ **Check the mount path:**
150
+ ```bash
151
+ # In container-runner.ts, verify mount is to /home/node/.claude/, NOT /root/.claude/
152
+ grep -A3 "Claude sessions" src/container-runner.ts
153
+ ```
154
+
155
+ **Verify sessions are accessible:**
156
+ ```bash
157
+ docker run --rm --entrypoint /bin/bash \
158
+ -v ~/.claude:/home/node/.claude \
159
+ nanoclaw-agent:latest -c '
160
+ echo "HOME=$HOME"
161
+ ls -la $HOME/.claude/projects/ 2>&1 | head -5
162
+ '
163
+ ```
164
+
165
+ **Fix:** Ensure `container-runner.ts` mounts to `/home/node/.claude/`:
166
+ ```typescript
167
+ mounts.push({
168
+ hostPath: claudeDir,
169
+ containerPath: '/home/node/.claude', // NOT /root/.claude
170
+ readonly: false
171
+ });
172
+ ```
173
+
174
+ ### 6. MCP Server Failures
175
+
176
+ If an MCP server fails to start, the agent may exit. Check the container logs for MCP initialization errors.
177
+
178
+ ## Manual Container Testing
179
+
180
+ ### Test the full agent flow:
181
+ ```bash
182
+ # Set up env file
183
+ mkdir -p data/env groups/test
184
+ cp .env data/env/env
185
+
186
+ # Run test query
187
+ echo '{"prompt":"What is 2+2?","groupFolder":"test","chatJid":"test@g.us","isMain":false}' | \
188
+ docker run -i \
189
+ -v $(pwd)/data/env:/workspace/env-dir:ro \
190
+ -v $(pwd)/groups/test:/workspace/group \
191
+ -v $(pwd)/data/ipc:/workspace/ipc \
192
+ nanoclaw-agent:latest
193
+ ```
194
+
195
+ ### Test Claude Code directly:
196
+ ```bash
197
+ docker run --rm --entrypoint /bin/bash \
198
+ -v $(pwd)/data/env:/workspace/env-dir:ro \
199
+ nanoclaw-agent:latest -c '
200
+ export $(cat /workspace/env-dir/env | xargs)
201
+ claude -p "Say hello" --dangerously-skip-permissions --allowedTools ""
202
+ '
203
+ ```
204
+
205
+ ### Interactive shell in container:
206
+ ```bash
207
+ docker run --rm -it --entrypoint /bin/bash nanoclaw-agent:latest
208
+ ```
209
+
210
+ ## SDK Options Reference
211
+
212
+ The agent-runner uses these Claude Agent SDK options:
213
+
214
+ ```typescript
215
+ query({
216
+ prompt: input.prompt,
217
+ options: {
218
+ cwd: '/workspace/group',
219
+ allowedTools: ['Bash', 'Read', 'Write', ...],
220
+ permissionMode: 'bypassPermissions',
221
+ allowDangerouslySkipPermissions: true, // Required with bypassPermissions
222
+ settingSources: ['project'],
223
+ mcpServers: { ... }
224
+ }
225
+ })
226
+ ```
227
+
228
+ **Important:** `allowDangerouslySkipPermissions: true` is required when using `permissionMode: 'bypassPermissions'`. Without it, Claude Code exits with code 1.
229
+
230
+ ## Rebuilding After Changes
231
+
232
+ ```bash
233
+ # Rebuild main app
234
+ npm run build
235
+
236
+ # Rebuild container (use --no-cache for clean rebuild)
237
+ ./container/build.sh
238
+
239
+ # Or force full rebuild
240
+ docker builder prune -af
241
+ ./container/build.sh
242
+ ```
243
+
244
+ ## Checking Container Image
245
+
246
+ ```bash
247
+ # List images
248
+ docker images
249
+
250
+ # Check what's in the image
251
+ docker run --rm --entrypoint /bin/bash nanoclaw-agent:latest -c '
252
+ echo "=== Node version ==="
253
+ node --version
254
+
255
+ echo "=== Claude Code version ==="
256
+ claude --version
257
+
258
+ echo "=== Installed packages ==="
259
+ ls /app/node_modules/
260
+ '
261
+ ```
262
+
263
+ ## Session Persistence
264
+
265
+ Claude sessions are stored per-group in `data/sessions/{group}/.claude/` for security isolation. Each group has its own session directory, preventing cross-group access to conversation history.
266
+
267
+ **Critical:** The mount path must match the container user's HOME directory:
268
+ - Container user: `node`
269
+ - Container HOME: `/home/node`
270
+ - Mount target: `/home/node/.claude/` (NOT `/root/.claude/`)
271
+
272
+ To clear sessions:
273
+
274
+ ```bash
275
+ # Clear all sessions for all groups
276
+ rm -rf data/sessions/
277
+
278
+ # Clear sessions for a specific group
279
+ rm -rf data/sessions/{groupFolder}/.claude/
280
+
281
+ # Also clear the session ID from NanoClaw's tracking (stored in SQLite)
282
+ sqlite3 store/messages.db "DELETE FROM sessions WHERE group_folder = '{groupFolder}'"
283
+ ```
284
+
285
+ To verify session resumption is working, check the logs for the same session ID across messages:
286
+ ```bash
287
+ grep "Session initialized" logs/nanoclaw.log | tail -5
288
+ # Should show the SAME session ID for consecutive messages in the same group
289
+ ```
290
+
291
+ ## IPC Debugging
292
+
293
+ The container communicates back to the host via files in `/workspace/ipc/`:
294
+
295
+ ```bash
296
+ # Check pending messages
297
+ ls -la data/ipc/messages/
298
+
299
+ # Check pending task operations
300
+ ls -la data/ipc/tasks/
301
+
302
+ # Read a specific IPC file
303
+ cat data/ipc/messages/*.json
304
+
305
+ # Check available groups (main channel only)
306
+ cat data/ipc/main/available_groups.json
307
+
308
+ # Check current tasks snapshot
309
+ cat data/ipc/{groupFolder}/current_tasks.json
310
+ ```
311
+
312
+ **IPC file types:**
313
+ - `messages/*.json` - Agent writes: outgoing WhatsApp messages
314
+ - `tasks/*.json` - Agent writes: task operations (schedule, pause, resume, cancel, refresh_groups)
315
+ - `current_tasks.json` - Host writes: read-only snapshot of scheduled tasks
316
+ - `available_groups.json` - Host writes: read-only list of WhatsApp groups (main only)
317
+
318
+ ## Quick Diagnostic Script
319
+
320
+ Run this to check common issues:
321
+
322
+ ```bash
323
+ echo "=== Checking NanoClaw Container Setup ==="
324
+
325
+ echo -e "\n1. Authentication configured?"
326
+ [ -f .env ] && (grep -q "CLAUDE_CODE_OAUTH_TOKEN=sk-" .env || grep -q "ANTHROPIC_API_KEY=sk-" .env) && echo "OK" || echo "MISSING - add CLAUDE_CODE_OAUTH_TOKEN or ANTHROPIC_API_KEY to .env"
327
+
328
+ echo -e "\n2. Env file copied for container?"
329
+ [ -f data/env/env ] && echo "OK" || echo "MISSING - will be created on first run"
330
+
331
+ echo -e "\n3. Container runtime running?"
332
+ docker info &>/dev/null && echo "OK" || echo "NOT RUNNING - start Docker Desktop (macOS) or sudo systemctl start docker (Linux)"
333
+
334
+ echo -e "\n4. Container image exists?"
335
+ echo '{}' | docker run -i --entrypoint /bin/echo nanoclaw-agent:latest "OK" 2>/dev/null || echo "MISSING - run ./container/build.sh"
336
+
337
+ echo -e "\n5. Session mount path correct?"
338
+ grep -q "/home/node/.claude" src/container-runner.ts 2>/dev/null && echo "OK" || echo "WRONG - should mount to /home/node/.claude/, not /root/.claude/"
339
+
340
+ echo -e "\n6. Groups directory?"
341
+ ls -la groups/ 2>/dev/null || echo "MISSING - run setup"
342
+
343
+ echo -e "\n7. Recent container logs?"
344
+ ls -t groups/*/logs/container-*.log 2>/dev/null | head -3 || echo "No container logs yet"
345
+
346
+ echo -e "\n8. Session continuity working?"
347
+ SESSIONS=$(grep "Session initialized" logs/nanoclaw.log 2>/dev/null | tail -5 | awk '{print $NF}' | sort -u | wc -l)
348
+ [ "$SESSIONS" -le 2 ] && echo "OK (recent sessions reusing IDs)" || echo "CHECK - multiple different session IDs, may indicate resumption issues"
349
+ ```
@@ -0,0 +1,122 @@
1
+ ---
2
+ name: get-qodo-rules
3
+ description: "Loads org- and repo-level coding rules from Qodo before code tasks begin, ensuring all generation and modification follows team standards. Use before any code generation or modification task when rules are not already loaded. Invoke when user asks to write, edit, refactor, or review code, or when starting implementation planning."
4
+ version: 2.0.0
5
+ allowed-tools: ["Bash"]
6
+ triggers:
7
+ - "get.?qodo.?rules"
8
+ - "get.?rules"
9
+ - "load.?qodo.?rules"
10
+ - "load.?rules"
11
+ - "fetch.?qodo.?rules"
12
+ - "fetch.?rules"
13
+ - "qodo.?rules"
14
+ - "coding.?rules"
15
+ - "code.?rules"
16
+ - "before.?cod"
17
+ - "start.?coding"
18
+ - "write.?code"
19
+ - "implement"
20
+ - "create.*code"
21
+ - "build.*feature"
22
+ - "add.*feature"
23
+ - "fix.*bug"
24
+ - "refactor"
25
+ - "modify.*code"
26
+ - "update.*code"
27
+ ---
28
+
29
+ # Get Qodo Rules Skill
30
+
31
+ ## Description
32
+
33
+ Fetches repository-specific coding rules from the Qodo platform API before code generation or modification tasks. Rules include security requirements, coding standards, quality guidelines, and team conventions that must be applied during code generation.
34
+ **Use** before any code generation or modification task when rules are not already loaded. Invoke when user asks to write, edit, refactor, or review code, or when starting implementation planning.
35
+ **Skip** if "Qodo Rules Loaded" already appears in conversation context
36
+
37
+ ---
38
+
39
+ ## Workflow
40
+
41
+ ### Step 1: Check if Rules Already Loaded
42
+
43
+ If rules are already loaded (look for "Qodo Rules Loaded" in recent messages), skip to step 6.
44
+
45
+ ### Step 2: Verify working in a git repository
46
+
47
+ - Check that the current directory is inside a git repository. If not, inform the user that a git repository is required and exit gracefully.
48
+ - Extract the repository scope from the git `origin` remote URL. If no remote is found, exit silently. If the URL cannot be parsed, inform the user and exit gracefully.
49
+ - Detect module-level scope: if inside a `modules/*` subdirectory, use it as the query scope; otherwise use repository-wide scope.
50
+
51
+ See [repository scope detection](references/repository-scope.md) for details.
52
+
53
+ ### Step 3: Verify Qodo Configuration
54
+
55
+ Check that the required Qodo configuration is present. The default location is `~/.qodo/config.json`.
56
+
57
+ - **API key**: Read from `~/.qodo/config.json` (`API_KEY` field). If not found, inform the user that an API key is required and provide setup instructions, then exit gracefully.
58
+ - **Environment name**: Read from `~/.qodo/config.json` (`ENVIRONMENT_NAME` field), with `QODO_ENVIRONMENT_NAME` environment variable taking precedence. If not found, inform the user that an API key is required and provide setup instructions, then exit gracefully.
59
+
60
+ ### Step 4: Fetch Rules with Pagination
61
+
62
+ - Fetch all pages from the API (50 rules per page) until no more results are returned.
63
+ - On each page, handle HTTP errors and exit gracefully with a user-friendly message.
64
+ - Accumulate all rules across pages into a single list.
65
+ - Stop after 100 pages maximum (safety limit).
66
+ - If no rules are found after all pages, inform the user and exit gracefully.
67
+
68
+ See [pagination details](references/pagination.md) for the full algorithm and error handling.
69
+
70
+ ### Step 5: Format and Output Rules
71
+
72
+ - Print the "📋 Qodo Rules Loaded" header with repository scope, scope context, and total rule count.
73
+ - Group rules by severity and print each non-empty group: ERROR, WARNING, RECOMMENDATION.
74
+ - Each rule is formatted as: `- **{name}** ({category}): {description}`
75
+ - End output with `---`.
76
+
77
+ See [output format details](references/output-format.md) for the exact format.
78
+
79
+ ### Step 6: Apply Rules by Severity
80
+
81
+ | Severity | Enforcement | When Skipped |
82
+ |---|---|---|
83
+ | **ERROR** | Must comply, non-negotiable. Add comment documenting compliance (e.g., `# Following Qodo rule: No Hardcoded Credentials`) | Explain to user and ask for guidance |
84
+ | **WARNING** | Should comply by default | Briefly explain why in response |
85
+ | **RECOMMENDATION** | Consider when appropriate | No action needed |
86
+
87
+ ### Step 7: Report
88
+
89
+ After code generation, inform the user about rule application:
90
+ - **ERROR rules applied**: List which rules were followed
91
+ - **WARNING rules skipped**: Explain why
92
+ - **No rules applicable**: Inform: "No Qodo rules were applicable to this code change"
93
+ - **RECOMMENDATION rules**: Mention only if they influenced a design decision
94
+
95
+ ---
96
+
97
+ ## How Scope Levels Work
98
+
99
+ Determines scope from git remote and working directory (see [Step 2](#step-2-verify-working-in-a-git-repository)):
100
+
101
+ **Scope Hierarchy**:
102
+ - **Universal** (`/`) - applies everywhere
103
+ - **Org Level** (`/org/`) - applies to organization
104
+ - **Repo Level** (`/org/repo/`) - applies to repository
105
+ - **Path Level** (`/org/repo/path/`) - applies to specific paths
106
+
107
+ ---
108
+
109
+ ## Configuration
110
+
111
+ See `~/.qodo/config.json` for API key setup. Set `QODO_ENVIRONMENT_NAME` env var or `ENVIRONMENT_NAME` in config to select environment.
112
+
113
+ ---
114
+
115
+ ## Common Mistakes
116
+
117
+ - **Re-running when rules are loaded** - Check for "Qodo Rules Loaded" in context first
118
+ - **Missing compliance comments on ERROR rules** - ERROR rules require a comment documenting compliance
119
+ - **Forgetting to report when no rules apply** - Always inform the user when no rules were applicable, so they know the rules system is active
120
+ - **Not in git repo** - Inform the user that a git repository is required and exit gracefully; do not attempt code generation
121
+ - **No API key** - Inform the user with setup instructions; set `QODO_API_KEY` or create `~/.qodo/config.json`
122
+ - **No rules found** - Inform the user; set up rules at app.qodo.ai
@@ -0,0 +1,41 @@
1
+ # Formatting and Outputting Rules
2
+
3
+ ## Output Structure
4
+
5
+ Print the following header:
6
+
7
+ ```
8
+ # 📋 Qodo Rules Loaded
9
+
10
+ Scope: `{QUERY_SCOPE}`
11
+ Rules loaded: **{TOTAL_RULES}** (universal, org level, repo level, and path level rules)
12
+
13
+ These rules must be applied during code generation based on severity:
14
+ ```
15
+
16
+ ## Grouping by Severity
17
+
18
+ Group rules into three sections and print each non-empty section:
19
+
20
+ **ERROR** (`severity == "error"`):
21
+ ```
22
+ ## ❌ ERROR Rules (Must Comply) - {count}
23
+
24
+ - **{name}** ({category}): {description}
25
+ ```
26
+
27
+ **WARNING** (`severity == "warning"`):
28
+ ```
29
+ ## ⚠️ WARNING Rules (Should Comply) - {count}
30
+
31
+ - **{name}** ({category}): {description}
32
+ ```
33
+
34
+ **RECOMMENDATION** (`severity == "recommendation"`):
35
+ ```
36
+ ## 💡 RECOMMENDATION Rules (Consider) - {count}
37
+
38
+ - **{name}** ({category}): {description}
39
+ ```
40
+
41
+ End output with `---`.
@@ -0,0 +1,33 @@
1
+ # Fetching Rules with Pagination
2
+
3
+ The API returns rules in pages of 50. All pages must be fetched to ensure no rules are missed.
4
+
5
+ ## Algorithm
6
+
7
+ 1. Start with `page=1`, `page_size=50`, accumulate results in an empty list
8
+ 2. Request: `GET {API_URL}/rules?scopes={ENCODED_SCOPE}&state=active&page={PAGE}&page_size=50`
9
+ - Header: `Authorization: Bearer {API_KEY}`
10
+ 3. On non-200 response, handle the error and exit gracefully:
11
+ - `401` — invalid/expired API key
12
+ - `403` — access forbidden
13
+ - `404` — endpoint not found (check `QODO_ENVIRONMENT_NAME`)
14
+ - `429` — rate limit exceeded
15
+ - `5xx` — API temporarily unavailable
16
+ - connection error — check internet connection
17
+ 4. Parse `rules` array from JSON response body
18
+ 5. Append page rules to accumulated list
19
+ 6. If rules returned on this page < 50 → last page, stop
20
+ 7. Otherwise increment page and repeat from step 2
21
+ 8. Safety limit: stop after 100 pages (5000 rules max)
22
+
23
+ ## API URL
24
+
25
+ Construct `{API_URL}` from `ENVIRONMENT_NAME` (read from `~/.qodo/config.json`):
26
+
27
+ | `ENVIRONMENT_NAME` | `{API_URL}` |
28
+ |---|---|
29
+ | set (e.g. `staging`) | `https://qodo-platform.staging.qodo.ai/rules/v1` |
30
+
31
+ ## After Fetching
32
+
33
+ If total rules == 0, inform the user no rules are configured for the repository scope and exit gracefully.
@@ -0,0 +1,26 @@
1
+ # Repository Scope Detection
2
+
3
+ ## Extracting Repository Scope from Git Remote URL
4
+
5
+ Parse the `origin` remote URL to derive the scope path. Both URL formats are supported:
6
+
7
+ - SSH: `git@github.com:org/repo.git` → `/org/repo/`
8
+ - HTTPS: `https://github.com/org/repo.git` → `/org/repo/`
9
+
10
+ If no remote is found, exit silently. If the URL cannot be parsed, inform the user and exit gracefully.
11
+
12
+ ## Module-Level Scope Detection
13
+
14
+ If the current working directory is inside a `modules/*` subdirectory relative to the repository root, use it as the query scope:
15
+
16
+ - `modules/rules/src/service.py` → query scope: `/org/repo/modules/rules/`
17
+ - repository root or any other path → query scope: `/org/repo/`
18
+
19
+ ## Scope Hierarchy
20
+
21
+ The API returns all rules matching the query scope via prefix matching:
22
+
23
+ | Query scope | Rules returned |
24
+ |---|---|
25
+ | `/org/repo/modules/rules/` | universal + org + repo + path-level rules |
26
+ | `/org/repo/` | universal + org + repo-level rules |