Commit Graph

117 Commits

Author SHA1 Message Date
gavrielc
fb5dbcbc12 Update README.md 2026-02-02 02:42:42 +02:00
gavrielc
40d41542d2 Update README.md 2026-02-02 01:39:37 +02:00
gavrielc
98f82b7645 Update README.md 2026-02-02 01:08:59 +02:00
gavrielc
d20df2e785 Update README.md 2026-02-02 00:56:01 +02:00
Gavriel
4711ec435a Add register_group IPC command for dynamic group registration
Main agent can now register new groups via MCP tool without restart.
Host updates both in-memory state and JSON file, creates group folders.
Authorization enforced at both agent and host level.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 00:08:40 +02:00
gavrielc
05a29d562f Security improvements: per-group session isolation, remove built-in Gmail
- Isolate Claude sessions per-group (data/sessions/{group}/.claude/)
  to prevent cross-group access to conversation history
- Remove Gmail MCP from built-in (now available via /add-gmail skill)
- Add SECURITY.md documenting the security model
- Move docs to docs/ folder (SPEC.md, REQUIREMENTS.md, SECURITY.md)
- Update documentation to reflect changes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 00:07:59 +02:00
Gavriel
22eb525805 Add Qwibit Ops context and NanoClaw Testing group
- Update main group CLAUDE.md with Qwibit Ops folder access docs
- Add WhatsApp formatting guidelines
- Create NanoClaw Testing group folder

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 23:53:15 +02:00
gavrielc
17f7b84420 Add /add-gmail skill for Gmail integration
Skill guides users through adding Gmail to NanoClaw with two modes:
- Tool Mode: Agent can read/send emails when triggered from WhatsApp
- Channel Mode: Emails can trigger the agent and receive replies

Includes step-by-step GCP OAuth setup, code integration instructions,
and troubleshooting guidance.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 23:52:05 +02:00
gavrielc
d000f33928 Add container output size limiting to prevent memory issues (#18)
* Fix potential memory DoS via unbounded container output

Add CONTAINER_MAX_OUTPUT_SIZE (default 10MB) to limit accumulated
stdout/stderr from container processes. Without this limit, a malicious
or buggy container could emit huge output leading to host memory
exhaustion.

Changes:
- Add configurable CONTAINER_MAX_OUTPUT_SIZE in config.ts
- Implement size-limited output buffering in runContainerAgent
- Log warnings when truncation occurs
- Include truncation status in container logs

https://claude.ai/code/session_01TjVDwwaGwbcFDdmrFF2y8B

* Update package-lock.json

https://claude.ai/code/session_01TjVDwwaGwbcFDdmrFF2y8B

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-01 23:09:50 +02:00
gavrielc
33ef0c68d3 Fix message cursor to only advance on successful processing (#17)
Previously, lastTimestamp was unconditionally advanced after each message,
even if processMessage failed. This caused transient errors to permanently
drop messages since they would never be retried.

Now the cursor only advances after successful processing, implementing
at-least-once delivery semantics. On failure, the loop breaks and the
failed message will be retried on the next poll iteration.

https://claude.ai/code/session_01SEQDWxXeZHe7t1bb5cw2CA

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-01 23:05:37 +02:00
gavrielc
c45f0efcdb Escape regex metacharacters in ASSISTANT_NAME for trigger pattern (#16)
ASSISTANT_NAME was interpolated directly into a regex without escaping.
If the name contained regex metacharacters (e.g., @A.*), the trigger
would match unintended patterns. This adds escapeRegex() to properly
escape special characters before building the TRIGGER_PATTERN.

https://claude.ai/code/session_01Lvuxq73qa9S4rtmGpX1WsP

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-01 23:05:13 +02:00
gavrielc
e5b436ab48 Fix group metadata sync setting epoch timestamp for new groups (#15)
updateChatName() was inserting new groups with last_message_time set to
Unix epoch (1970-01-01), causing newly discovered groups to appear at
the bottom of activity-ordered listings. Changed to use current time
for new groups while preserving existing timestamps for known groups.

https://claude.ai/code/session_018rcZvALfF3ND2jfcvBaFo2

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-01 23:04:49 +02:00
gavrielc
df52232763 Pre-launch fixes: error handling, cleanup, consistency
- Remove unused claude-agent-sdk from host deps (only used in container)
- Remove dead scheduler MCP config (built into IPC)
- Remove unused eslint script
- Add clear error message when Apple Container fails to start
- Auto-generate launchd plist with real paths in setup skill
- Standardize Node.js version to 20+ everywhere

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 23:01:04 +02:00
gavrielc
48822ff67d Add mount security allowlist for external directory access (#14)
* Add secure mount allowlist validation

Addresses arbitrary host mount vulnerability by validating additional
mounts against an external allowlist stored at ~/.config/nanoclaw/.
This location is never mounted into containers, making it tamper-proof.

Security measures:
- Allowlist cached in memory (edits require process restart)
- Real path resolution (blocks symlink and .. traversal attacks)
- Blocked patterns for sensitive paths (.ssh, .gnupg, .aws, etc.)
- Non-main groups forced to read-only when nonMainReadOnly is true
- Container path validation prevents /workspace/extra escape

https://claude.ai/code/session_01BPqdNy4EAHHJcdtZ27TXkh

* Add mount allowlist setup to /setup skill

Interactive walkthrough that asks users:
- Whether they want agents to access external directories
- Which directories to allow (with paths)
- Read-write vs read-only for each
- Whether non-main groups should be restricted to read-only

Creates ~/.config/nanoclaw/mount-allowlist.json based on answers.

https://claude.ai/code/session_01BPqdNy4EAHHJcdtZ27TXkh

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-01 22:55:08 +02:00
Gavriel
5760b75fa9 Fix timezone handling and message filtering
- Add TIMEZONE config using system timezone for cron expressions
- Filter bot messages by content prefix instead of is_from_me
  (user shares WhatsApp account with bot)
- Format messages as XML for cleaner agent parsing
- Update schedule_task tool to clarify local time usage

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 22:54:44 +02:00
gavrielc
066eeb9646 Make OpenClaw critique specific with actual numbers
52+ modules, 8 config files, 45+ deps, 15 channel providers.
Security is application-level (allowlists) vs actual container isolation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 22:36:45 +02:00
gavrielc
016a1a0e31 Add group metadata sync for easier group activation
- Sync group names from WhatsApp via groupFetchAllParticipating()
- Store group names in chats table (jid -> name mapping)
- Daily sync with 24h cache, on-demand refresh via IPC
- Write available_groups.json snapshot for agent (main group only)
- Agent can request refresh_groups via IPC if group not found
- Update documentation in main CLAUDE.md and debug skill

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 22:25:29 +02:00
Gavriel
572338b9a6 Add context_mode option for scheduled tasks
Scheduled tasks can now run in either:
- "group" mode: uses the group's conversation session for context
- "isolated" mode: runs with a fresh session (previous behavior)

The tool description guides the agent on when to use each mode and
prompts them to ask the user if unclear. Group mode is now the default.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 22:23:50 +02:00
gavrielc
f6e7f7aca9 Make main group respond to all messages without trigger prefix
Other groups still require @Andy prefix to trigger the agent.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 21:49:39 +02:00
gavrielc
6745a1c54b Apply fixes from closed PRs: sentinel markers, JID lookup, schedule validation
- PR #10: Add sentinel markers for robust JSON parsing between container
  and host. Fallback to last-line parsing for backwards compatibility.

- PR #5: Look up target JID from registeredGroups instead of trusting
  IPC payload, fixing cross-group scheduled tasks getting wrong chat_jid.

- PR #8: Add lightweight schedule validation in container MCP that
  returns errors to agents (cron syntax, positive interval, valid ISO
  timestamp). Also defensive validation on host side.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 20:49:57 +02:00
gavrielc
ade9f2d323 Merge pull request #3 from gavrielc/claude/secure-ipc-access-Ni9l4
Secure IPC with per-group namespaces to prevent privilege escalation
2026-02-01 20:40:27 +02:00
gavrielc
febf90f3c8 Merge pull request #12 from gavrielc/claude/fix-agent-failure-timestamp-yiOZt
Fix: only update lastAgentTimestamp on agent success
2026-02-01 20:40:15 +02:00
gavrielc
8f89f67c4b Merge pull request #11 from gavrielc/claude/fix-message-loss-error-DJwye
Fix message loss when processMessage throws
2026-02-01 20:40:13 +02:00
gavrielc
7310c5ba04 Merge pull request #9 from gavrielc/claude/fix-sensitive-log-data-xb0E8
Remove message content from info-level logs
2026-02-01 20:40:05 +02:00
gavrielc
069bc76016 Merge pull request #7 from gavrielc/claude/fix-home-directory-fallback-FF5Tr
Fix hardcoded home directory fallback in container runner
2026-02-01 20:40:02 +02:00
gavrielc
30bc2262e9 Merge pull request #2 from gavrielc/claude/fix-dotenv-exposure-LEzJ8
Fix security: only expose auth vars to containers, not full .env
2026-02-01 20:39:59 +02:00
Claude
7aa051fa8a Fix: only update lastAgentTimestamp on agent success
Previously, lastAgentTimestamp was updated regardless of whether
runAgent succeeded or failed. This caused messages to be skipped
on retry after a failure since they were already marked as processed.

Now the timestamp is only advanced when the agent returns a valid
response, ensuring failed messages will be included in the next retry.

https://claude.ai/code/session_0118wNAJCKY2Asr17Lb91TE2
2026-02-01 18:13:34 +00:00
Claude
a904c65975 Fix message loss when processMessage throws
Previously, lastTimestamp was advanced before processing messages.
If processMessage threw an error, those messages would be skipped
on the next tick since the timestamp had already moved past them.

Now we advance lastTimestamp after each message is successfully
processed (or after catching an error), ensuring no messages are
lost on retry.

https://claude.ai/code/session_01LgHSAs9XbcvZckCe8xPipj
2026-02-01 18:12:59 +00:00
Claude
092411dd22 Remove message content from info-level logs
Previously logged first 50 chars of message text at info level, which
could expose sensitive user content in production logs. Now logs only
message length instead.

https://claude.ai/code/session_01V9b7PCAVA7LoyrR89t3GTG
2026-02-01 17:58:57 +00:00
Claude
a8155e2bbc Fix hardcoded home directory fallback in container runner
Replace environment-specific fallback '/Users/gavriel' with os.homedir()
and proper error handling. The new getHomeDir() helper function:
- First checks process.env.HOME
- Falls back to os.homedir() for cross-platform support
- Throws a clear error if home directory cannot be determined

https://claude.ai/code/session_011Cs2FWxXMvAdAh4w9A6AZC
2026-02-01 17:56:15 +00:00
Claude
6a94aec5da Secure IPC with per-group namespaces to prevent privilege escalation
Each container now gets its own IPC directory (/data/ipc/{groupFolder}/)
instead of a shared global directory. Identity is determined by which
directory a request came from, not by self-reported data in IPC files.

Authorization enforced:
- send_message: only to chatJids belonging to the source group
- schedule_task: only for the source group (main can target any)
- pause/resume/cancel_task: only for tasks owned by source group

https://claude.ai/code/session_018nmxNEbtgJH7cKDyBSQGAw
2026-02-01 17:44:25 +00:00
Claude
49e7875e67 Fix security: only expose auth vars to containers, not full .env
Previously, the entire .env file was copied and mounted into containers,
exposing all environment variables to the agent. Now only the specific
authentication variables needed by Claude Code (CLAUDE_CODE_OAUTH_TOKEN
and ANTHROPIC_API_KEY) are extracted and mounted.

https://claude.ai/code/session_01Y6Az5oUPkYmJhA1N9MUd67
2026-02-01 17:42:29 +00:00
gavrielc
c255451ac3 Move Quick Start section above Philosophy
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 17:53:54 +02:00
gavrielc
1699dfc3d1 Update README.md 2026-02-01 17:51:59 +02:00
gavrielc
479ca166ca Add NanoClaw logo and branding assets
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 17:45:05 +02:00
gavrielc
17e7b469f4 Refactor: delete dead code, extract utils, rename files for clarity
- Delete scheduler-mcp.ts (285 lines of dead code, unused)
- Extract loadJson/saveJson to utils.ts (generic utilities)
- Rename auth.ts → whatsapp-auth.ts (more specific)
- Rename scheduler.ts → task-scheduler.ts (more specific)
- Update all references in docs and imports

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 17:35:03 +02:00
Gavriel
847032d41e Fix task deletion FK constraint error
Delete child records (task_run_logs) before parent (scheduled_tasks) to avoid foreign key constraint violation when cancelling tasks.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 17:31:32 +02:00
Gavriel
2dedd18491 Fix scheduled tasks and improve task scheduling UX
- Fix Apple Container mount issue: move groups/CLAUDE.md to groups/global/
  directory (Apple Container only supports directory mounts, not file mounts)
- Fix scheduled tasks for main group: properly detect isMain based on
  group_folder instead of always setting false
- Add isScheduledTask flag so agent knows when running as scheduled task
- Improve schedule_task tool description with clear format examples for
  cron, interval, and once schedule types
- Update global CLAUDE.md with instructions for scheduled tasks to use
  mcp__nanoclaw__send_message when needed

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 17:24:12 +02:00
gavrielc
f25e0f9a10 Remove redundant comments throughout codebase
Keep only comments that explain non-obvious behavior or add context
not apparent from reading the code.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 16:00:44 +02:00
gavrielc
732c624e6b Fix security issues: IPC auth, message logging, container logs
- Add authorization checks to IPC task operations (pause/resume/cancel)
  to prevent cross-group task manipulation
- Only store message content for registered groups; unregistered chats
  only get metadata stored for group discovery
- Container logs now only include full input/output in debug mode;
  default logging omits sensitive message content

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 15:51:53 +02:00
gavrielc
552b26cc95 Add PreCompact hook for conversation archiving, remove /clear command
- Add PreCompact hook in agent-runner that archives conversations before
  compaction, using session summary from sessions-index.json for filename
- Remove /clear command (programmatic compaction not supported by SDK)
- Add /add-clear to RFS for future implementation
- Update CLAUDE.md templates with memory system instructions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 15:37:13 +02:00
Gavriel
aa6dcf39d7 Add typing indicator while agent is processing
Shows "typing..." in WhatsApp while the agent container is running.
Uses Baileys sendPresenceUpdate with 'composing' and 'paused' states.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 15:10:42 +02:00
gavrielc
2026eaf53d Clean up README prose and add contribution FAQ
- Remove dash-as-em-dash patterns throughout
- Add FAQ about what changes are accepted (security, bugs, clear fixes)
- Clarify that enhancements should be skills, not PRs
- Fix "Leverage" → "Use" in REQUIREMENTS.md

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 13:43:11 +02:00
Gavriel
e9c5187a9e Rewrite README intro with balanced OpenClaw comparison
Acknowledge OpenClaw's vision and usefulness while explaining the
personal motivation: inability to understand or trust a complex
codebase. Emphasize NanoClaw's 8-minute comprehensibility with
Claude Code assistance.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 13:10:29 +02:00
Gavriel
fb4ce8dce9 Update project and agent context files
- CLAUDE.md: Concise dev context, references README/REQUIREMENTS
- groups/CLAUDE.md: Proper agent identity for Andy
- groups/main/CLAUDE.md: Add agent identity, keep admin context
- package.json: Update description
- setup skill: Note to update name in multiple places

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 13:03:51 +02:00
Gavriel
dbf39a9484 Rewrite documentation with project philosophy and RFS
- Add "Why This Exists" section contrasting with OpenClaw
- Document core philosophy: small, secure, AI-native, skills over features
- Add RFS (Request for Skills) for community contributions
- Rewrite README with proper structure, examples, and FAQ
- Emphasize Claude Agent SDK benefits and ToS compliance

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 12:47:40 +02:00
Gavriel
1d4cf51917 Support OAuth token authentication as alternative to API key
- Setup skill now asks subscription vs API key, can auto-grab token
- Debug skill updated for both auth methods
- SPEC.md documents both authentication options

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 12:03:06 +02:00
Gavriel
8ca4c95517 Fix session persistence and auto-start container system
- Fix session mount path: ~/.claude/ now mounts to /home/node/.claude/
  (container runs as 'node' user with HOME=/home/node, not root)
- Fix ~/.gmail-mcp/ mount path similarly
- Use absolute paths for GROUPS_DIR and DATA_DIR (required for container mounts)
- Auto-start Apple Container system on NanoClaw startup
- Update debug skill with session troubleshooting guide
- Update spec.md with startup sequence and troubleshooting

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 11:31:52 +02:00
Gavriel
67e0295d82 Fix container execution and add debug tooling
Container fixes:
- Run as non-root 'node' user (required for --dangerously-skip-permissions)
- Add allowDangerouslySkipPermissions: true to SDK options
- Mount .env file to work around Apple Container -i env var bug
- Use --mount for readonly, -v for read-write (Apple Container quirk)
- Bump SDK to 0.2.29, zod to v4
- Install Claude Code CLI globally in container

Logging improvements:
- Write per-run logs to groups/{folder}/logs/container-*.log
- Add debug-level logging for mounts and container args

Documentation:
- Add /debug skill with comprehensive troubleshooting guide
- Update /setup skill with API key configuration step
- Update SPEC.md with container details, mount syntax, security notes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 10:35:08 +02:00
gavrielc
0ccdaaac48 Mount project root for main channel
- Main gets /workspace/project with full project access
- Main can query SQLite database and edit configs
- Updated main CLAUDE.md with container paths
- Added docs for configuring additional mounts per group

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 23:01:45 +02:00