# Subagent Guidance for Niemand-Molty

## Overview

This document provides guidance for subagents working on the Niemand-Molty project - the sandboxed Moltbook agent.

## Project Structure

```
niemand-molty-sync/
├── filter-memory.py          # PII redaction script
├── workflows/
│   └── sync-memory.lobster   # Daily sync workflow
├── systemd/
│   ├── niemand-molty-sync.service
│   └── niemand-molty-sync.timer
├── skills/
│   └── http-request/         # HTTP client for Moltbook API
│       ├── http_request.py
│       └── SKILL.md
└── docs/
    └── SUBAGENT_GUIDANCE.md  # This file
```

## Agent Architecture

### Niemand-Molty (Sandboxed Agent)

**Location:** `~/.openclaw/workspace-molty/`

**Purpose:** Public-facing Moltbook presence with filtered memory access

**Capabilities:**
- web_fetch (GET requests)
- web_search
- browser
- read/write/edit (own workspace only)
- exec (limited to http_request.py)
- sessions_list/session_status

**Restrictions:**
- No shell commands (process denied)
- No messaging channels (whatsapp, telegram, etc. denied)
- No infrastructure tools (cron, gateway, nodes denied)
- No image generation
- Sandbox mode: all (Docker container)
- Model: minimax (cost-effective, lower capability)
- Thinking: low (default)

### Memory Sync

**Daily at 3:00 AM:**
1. Reads main Niemand's memory files from `/home/art/niemand/memory/`
2. Filters PII using `filter-memory.py`
3. Writes filtered version to `~/.openclaw/workspace-molty/memory/`

**Filter Rules:**
- Names: Martin → "the human", Anna → "spouse", Logan/Quinn → "children"
- Contact: Emails/phones → [REDACTED]
- IDs: API keys/tokens → [REDACTED]
- Paths: File paths → [PATH_REDACTED]
- Addresses: Locations → [LOCATION_REDACTED]
- Dates: Specific → seasonal (January → "winter")
- Excludes: Therapy sections, private notes

## Moltbook API Integration

### HTTP Request Skill

Located at: `~/.openclaw/workspace-molty/skills/http-request/`

**Usage:**
```bash
python3 skills/http-request/http_request.py \
  "https://www.moltbook.com/api/v1/endpoint" \
  POST \
  '{"Authorization":"Bearer API_KEY"}' \
  '{"field":"value"}'
```

**Supported Methods:** GET, POST, PATCH, PUT, DELETE

**Response Format:**
```json
{
  "success": true,
  "status_code": 200,
  "headers": {...},
  "data": {...}
}
```

### Moltbook API Endpoints

**Base URL:** `https://www.moltbook.com/api/v1`

| Endpoint | Method | Purpose |
|----------|--------|---------|
| `/agents/register` | POST | Register new agent |
| `/agents/me` | GET | Get profile |
| `/posts` | POST | Create post |
| `/posts/{id}/comments` | POST | Add comment |
| `/posts/{id}/upvote` | POST | Upvote |
| `/posts/{id}/downvote` | POST | Downvote |
| `/feed` | GET | Get personalized feed |
| `/search` | GET | Semantic search |
| `/submolts` | GET/POST | List/create communities |
| `/agents/{name}/follow` | POST | Follow agent |

### Credential Storage

API keys stored in:
`~/.openclaw/agents/molty/agent/auth-profiles.json`

Format:
```json
{
  "moltbook:default": {
    "provider": "moltbook",
    "mode": "token",
    "token": "moltbook_xxx"
  }
}
```

**Security:** File permissions 600 (user read/write only)

## Working with This Repo

### Adding Features

1. **HTTP Tools:** Extend `skills/http-request/http_request.py`
2. **Filter Rules:** Update `filter-memory.py` REDACTION_RULES
3. **Workflows:** Add to `workflows/` directory
4. **Documentation:** Update relevant SKILL.md or this file

### Testing Changes

```bash
# Test filter script
python3 filter-memory.py --date 2026-01-31

# Test HTTP request
python3 skills/http-request/http_request.py \
  "https://www.moltbook.com/api/v1/agents/me" \
  GET \
  '{"Authorization":"Bearer TEST_TOKEN"}'

# Test service
systemctl --user start niemand-molty-sync.service
journalctl --user -u niemand-molty-sync.service -f
```

### Git Workflow

```bash
git add -A
git commit -m "type(scope): description"
git push origin master
```

**Commit Types:**
- `feat`: New feature
- `fix`: Bug fix
- `docs`: Documentation
- `refactor`: Code refactoring
- `test`: Tests

## Security Considerations

### What Molty CAN Access
- His own workspace files
- Public web content
- Moltbook API (with stored credentials)
- Filtered memory from main Niemand

### What Molty CANNOT Access
- Main Niemand's personal files
- Your messaging channels
- Shell commands beyond http_request.py
- Infrastructure (cron, gateway config)
- Unfiltered personal data

### Blast Radius Containment
- Docker sandbox isolates filesystem
- Tool policy restricts available actions
- Filtered memory prevents PII leakage
- Separate credentials from main agent

## Common Tasks

### Adding New Moltbook API Support

1. Test endpoint with curl:
```bash
curl -X POST https://www.moltbook.com/api/v1/endpoint \
  -H "Authorization: Bearer TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"field":"value"}'
```

2. Document in SKILL.md

3. Add example to AGENTS.md in Molty's workspace

### Debugging Filter Issues

```bash
# Run with verbose output
python3 filter-memory.py --date 2026-01-31 2>&1 | head -50

# Check specific file
head -50 ~/.openclaw/workspace-molty/memory/2026-01-31-XXXX-filtered.md
```

### Checking Sync Status

```bash
# Timer status
systemctl --user status niemand-molty-sync.timer

# Recent runs
journalctl --user -u niemand-molty-sync.service -n 20

# Output files
ls -lt ~/.openclaw/workspace-molty/memory/ | head
```

## References

- [Moltbook API Docs](https://www.moltbook.com/skill.md)
- [OpenClaw Sandboxing](https://docs.openclaw.ai/gateway/sandboxing)
- [OpenClaw Multi-Agent](https://docs.openclaw.ai/concepts/multi-agent)

## Contact

For issues or questions about this setup, contact the human operator.
