# Niemand-Molty Memory Sync

Daily filtered memory synchronization from main Niemand to the sandboxed Moltbook agent.

## Overview

This project implements a privacy-preserving memory sync workflow that:
- Runs daily at 3:00 AM
- Reads the previous day's memory files from the main Niemand agent
- Redacts PII and sensitive information
- Writes filtered memories to the sandboxed Molty agent workspace

## Why Filtered Sync?

The Molty agent operates on Moltbook — a public social network for AI agents. While we want Molty to maintain continuity with Niemand's personality and recent context, we must protect:
- Personal information (family names, addresses)
- Contact details (phone numbers, emails)
- Credentials and API keys
- Internal system paths
- Private communications

## Filter Rules

### Redacted Information

| Category | Examples | Replacement |
|----------|----------|-------------|
| **Names** | Martin, Anna, Logan, Quinn | "the human", "spouse", "children" |
| **Contact** | Emails, phone numbers | `[EMAIL_REDACTED]`, `[PHONE_REDACTED]` |
| **IDs** | API keys, tokens, membership numbers | `[ID_REDACTED]` |
| **Paths** | `/home/art/...`, `~/...` | `[PATH_REDACTED]` |
| **Locations** | Specific addresses, cities | `[LOCATION_REDACTED]` |
| **Dates** | January 18, 2025 | "winter" (seasonal approximation) |

### Excluded Content

- Therapy/journaling sections
- Session keys and chat IDs
- Private notes sections

### Preserved Content

- Activities and work context (general)
- Technical projects and learnings
- Tool preferences and workflows
- General knowledge and patterns

## Installation

### 1. Clone and Setup

```bash
cd /home/art/niemand
git clone <private-repo-url> niemand-molty-sync
cd niemand-molty-sync
```

### 2. Create Output Directory

```bash
mkdir -p ~/.openclaw/workspace-molty/memory
mkdir -p ~/logs
```

### 3. Test the Filter

```bash
# Test with today's date (if memory files exist)
python3 filter-memory.py --date $(date +%Y-%m-%d)

# Or test with specific file
python3 filter-memory.py /path/to/memory.md /path/to/output-filtered.md
```

### 4. Install Systemd Timer (Optional)

```bash
# Copy service files
cp systemd/niemand-molty-sync.service ~/.config/systemd/user/
cp systemd/niemand-molty-sync.timer ~/.config/systemd/user/

# Reload and enable
systemctl --user daemon-reload
systemctl --user enable --now niemand-molty-sync.timer

# Verify
systemctl --user list-timers | grep niemand-molty
journalctl --user -u niemand-molty-sync -f
```

### 5. Lobster Workflow (Alternative)

If using Lobster instead of systemd:

```bash
# Copy workflow to Lobster workflows
cp workflows/sync-memory.lobster ~/projects/lobster-workflows/workflows/

# Add to systemd/cron as needed
```

## Usage

### Manual Sync

```bash
# Sync specific date
python3 filter-memory.py --date 2026-01-31

# Sync single file
python3 filter-memory.py input.md output-filtered.md
```

### Automated Daily Sync

The systemd timer runs automatically at 3:00 AM daily. Logs are written to:
- `~/logs/niemand-molty-sync.log`

## Security Considerations

1. **Private Repository**: This code should remain in a private repository as it contains filtering rules specific to your data.

2. **No Credential Storage**: The filter script does not store credentials — it only redacts them from logs.

3. **One-Way Sync**: This is a one-way sync from main → Molty. Molty cannot write back to main's memory.

4. **Sandboxed Target**: Molty operates in a Docker sandbox with restricted tool access, providing defense in depth.

5. **Review Output**: Periodically review the filtered output to ensure no sensitive information leaks through.

## Filter Script Architecture

```
filter-memory.py
├── MemoryFilter class
│   ├── _exclude_sections()     # Remove therapy/private sections
│   ├── _redact_names()         # Replace names with generics
│   ├── _redact_contact_info()  # Remove emails/phones
│   ├── _redact_ids()           # Remove API keys/IDs
│   ├── _redact_paths()         # Remove file paths
│   ├── _redact_addresses()     # Remove addresses
│   └── _fuzz_dates()           # Convert dates to seasons
└── process_memory_file()       # Main entry point
```

## Customization

To add new redaction rules, edit `REDACTION_RULES` in `filter-memory.py`:

```python
REDACTION_RULES = {
    "names": {
        r"\bNewName\b": "generic_reference",
    },
    # ... add more categories
}
```

## Troubleshooting

### No memory files found

Ensure the input directory exists and contains memory files:
```bash
ls -la /home/art/niemand/memory/
```

### Permission denied

Ensure the script has execute permissions:
```bash
chmod +x filter-memory.py
```

### Systemd timer not running

Check timer status:
```bash
systemctl --user status niemand-molty-sync.timer
systemctl --user status niemand-molty-sync.service
```

## License

Private - Not for public distribution.

## Related

- [OpenClaw](https://openclaw.ai) - The AI agent platform
- [Moltbook](https://moltbook.com) - Social network for AI agents
- Niemand (main agent) - Full-context personal assistant
- Niemand-Molty (sandboxed agent) - Public-facing Moltbook presence
