Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Cerebro is a cloud-based personal knowledge store. It pairs a Supabase PostgreSQ

## Architecture

```
┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
```text
┌──────────────┐┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Teams Bot │ │ Discord Bot │ │ Alexa Skill │ │iMessage (BB) │
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ │ │ │
Expand Down Expand Up @@ -57,7 +57,7 @@ Cerebro is a cloud-based personal knowledge store. It pairs a Supabase PostgreSQ

## Repository Structure

```
```text
cerebro/
├── docs/ # Setup guides (01 through 10)
├── extensions/ # Feature extensions (future)
Expand All @@ -82,6 +82,7 @@ cerebro/
## Guard Rails

**DO:**

- Add new columns to the `thoughts` table when needed
- Use Supabase Secrets for all credentials (`npx supabase secrets set KEY=VALUE`)
- Deploy all server functions as Supabase Edge Functions
Expand All @@ -90,6 +91,7 @@ cerebro/
- Copy integration source to `supabase/functions/<name>/` before deploying (containers don't follow symlinks)

**DO NOT:**

- Alter, rename, or drop existing columns on the `thoughts` table — every integration depends on the current schema
- Commit secrets, API keys, or passwords to source
- Use `DROP TABLE`, `DROP DATABASE`, `TRUNCATE`, or unqualified `DELETE FROM` in SQL files
Expand All @@ -113,6 +115,7 @@ echo "SELECT * FROM thoughts LIMIT 5" | python3 scripts/dbsql.py
```

Credentials auto-load from `.env` in the project root. Connection details:

- **Host:** aws-0-us-west-2.pooler.supabase.com (session pooler)
- **Port:** 5432
- **User:** postgres.livdhnxdbnhxxxlgcoge
Expand Down Expand Up @@ -177,6 +180,7 @@ npx supabase secrets set KEY=VALUE
### DNS Resolution Workaround

When calling the Supabase REST API from environments with DNS issues, use:

```bash
curl --resolve livdhnxdbnhxxxlgcoge.supabase.co:443:172.64.149.246 \
"https://livdhnxdbnhxxxlgcoge.supabase.co/rest/v1/..."
Expand All @@ -185,20 +189,24 @@ curl --resolve livdhnxdbnhxxxlgcoge.supabase.co:443:172.64.149.246 \
## Capture Source Details

### Teams (cerebro-teams)

- Azure Bot Framework, single-tenant
- Entra ID app: `659c247e-0da5-48de-a158-c73c36929aa5`
- Tenant: `1e1cce84-0637-4693-99d9-27ff18dd65c8` (sudbringlab)

### Discord (cerebro-discord)

- Application ID: `1482865415733514351`
- Uses slash commands (`/capture`, `/search`, `/stats`, etc.)

### Alexa (cerebro-alexa)

- Custom skill, HTTPS endpoint
- Invocation: "my brain"
- 6 intents: CaptureThought, Search, Stats, BrowseRecent, CompleteTask, ReopenTask

### iMessage (cerebro-imessage)

- BlueBubbles Server on Mac → Cloudflare named tunnel → Edge Function
- Text-based commands (no slash commands): capture, `search <query>`, `stats`, `done <desc>`, `reopen <desc>`, `delete <desc>`, `help`
- Commands accept both colon and space delimiters: `done passport` or `done:passport`
Expand All @@ -209,30 +217,38 @@ curl --resolve livdhnxdbnhxxxlgcoge.supabase.co:443:172.64.149.246 \
- Self-chat creates TWO chat GUIDs (phone + email) — both must be in `BLUEBUBBLES_ALLOWED_CHATS`

### Daily Digest (cerebro-digest)

- Generates daily/weekly summaries via AI
- Delivers via email (Resend), Teams, Discord, and iMessage
- Email recipients: allen@sudbring.com, allensu@microsoft.com
- Email recipients: <allen@sudbring.com>, <allensu@microsoft.com>
- Scheduled via pg_cron in Supabase

## Known Issues & Workarounds

### psql / libpq Cannot Connect

All libpq-based tools (psql, psycopg2, psycopg3) fail with "server closed the connection unexpectedly" against Supabase's Supavisor pooler. **Use `scripts/dbsql.py` instead.**

### BlueBubbles macOS Automation Permission (-1743)

On macOS Sequoia 15, BlueBubbles cannot send AppleEvents to Messages (Electron TCC issue). Fix: manually insert into user-level TCC database from Terminal.app with Full Disk Access:

```bash
sqlite3 ~/Library/Application\ Support/com.apple.TCC/TCC.db "INSERT OR REPLACE INTO access (...) VALUES ('kTCCServiceAppleEvents', 'com.BlueBubbles.BlueBubbles-Server', 0, 2, 4, 1, <csreq_blob>, NULL, 0, 'com.apple.MobileSMS', NULL, 0, ...);"
```

Full script at `~/Desktop/fix-bluebubbles-tcc.sh` on mac-server. Must quit and reopen BlueBubbles after.

### BlueBubbles Webhook Replay

BlueBubbles replays old messages as new webhooks on restart. The Edge Function guards against this with a 5-minute message age check and source_message_id deduplication.

### Supabase Edge Function Route

Must use `app.post("*")` not `app.post("/")` — Supabase strips paths during routing.

### Supabase Deploy Directory

Files in `supabase/functions/<name>/` must be actual copies, not symlinks. The Supabase container doesn't follow symlinks.

## Environment Variables (Supabase Secrets)
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Inspired by the [Open Brain](https://github.com/NateBJones/OB1) project by Nate

## Repo Structure

```
```text
docs/ — Setup guides and documentation
extensions/ — Feature extensions that build on the core system
integrations/ — MCP server, capture sources, webhook receivers
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Inspired by the [Open Brain](https://github.com/NateBJones/OB1) project by Nate
**[→ Complete Setup Guide](docs/SETUP.md)** — Start here. Walks you through everything from core infrastructure to optional features, with verification tests at every step.

The setup guide covers:

1. **Core Infrastructure** — Supabase + OpenRouter + MCP server (~20 min)
2. **Capture Sources** — Discord, Teams, Alexa, and/or iMessage
3. **Calendar Reminders** — Auto-create O365/Google events from dates in thoughts
Expand Down Expand Up @@ -111,7 +112,7 @@ by describing them — Cerebro uses AI to match the right one.

## Project Structure

```
```text
docs/ — Setup guides and documentation
extensions/ — Feature extensions (coming soon)
integrations/ — MCP server, Teams capture, Discord capture, Alexa voice, iMessage capture, daily digest
Expand Down
22 changes: 14 additions & 8 deletions docs/02-teams-capture-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ https://YOUR_PROJECT_REF.supabase.co/functions/v1/cerebro-teams
1. Go back to your Azure Bot resource in the portal
2. Click **Configuration** in the left sidebar
3. Set **Messaging endpoint** to:
```

```text
https://YOUR_PROJECT_REF.supabase.co/functions/v1/cerebro-teams
```

4. Click **Apply**

---
Expand Down Expand Up @@ -172,17 +174,21 @@ zip cerebro-teams-app.zip manifest.json color.png outline.png
1. In Teams, find **Cerebro** in your apps or chat list
2. Start a 1:1 chat with the bot
3. Type a thought:
```

```text
Sarah mentioned she's thinking about leaving her job to start a consulting business
```

4. You should see a confirmation reply with the extracted metadata

### Channel @mention

1. In any Team channel where the app is installed, type:
```

```text
@Cerebro Just had a great architecture review meeting with the platform team
```

2. The bot captures the thought (stripping the @mention) and replies in the thread

### Verify in Supabase
Expand All @@ -193,28 +199,28 @@ Open Supabase Dashboard → Table Editor → `thoughts`. You should see new rows

## Troubleshooting

**Bot doesn't respond**
### Bot doesn't respond

- Check the messaging endpoint in Azure Bot Configuration — must be the exact Edge Function URL
- Verify secrets are set: `supabase secrets list` should show `TEAMS_BOT_APP_ID`, `TEAMS_BOT_APP_SECRET`, `OPENROUTER_API_KEY`
- Check Edge Function logs in Supabase Dashboard → Edge Functions → `cerebro-teams` → Logs

**Getting 401 errors in logs**
### Getting 401 errors in logs

- The App ID or Secret may be wrong. Double-check they match your Entra ID app registration
- Ensure the app registration is set to **Multitenant** (required for Bot Framework)

**Sideloading not available**
### Sideloading not available

- Admin must enable "Upload custom apps" in Teams Admin Center (Step 5)
- It can take up to 24 hours to propagate after enabling

**Bot appears but no reply**
### Bot appears but no reply

- Check that the Edge Function deployed successfully: visit `https://YOUR_PROJECT_REF.supabase.co/functions/v1/cerebro-teams` in a browser — should return `{"status":"ok","service":"cerebro-teams"}`
- Check Supabase Edge Function logs for errors

**Slow first response**
### Slow first response

- Cold start on Edge Functions takes a few seconds. Subsequent messages are faster.

Expand Down
18 changes: 10 additions & 8 deletions docs/03-discord-capture-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ https://YOUR_PROJECT_REF.supabase.co/functions/v1/cerebro-discord
1. Go back to the [Discord Developer Portal](https://discord.com/developers/applications) → your app
2. On **General Information**, find **Interactions Endpoint URL**
3. Paste your Edge Function URL:
```

```text
https://YOUR_PROJECT_REF.supabase.co/functions/v1/cerebro-discord
```

4. Click **Save Changes**

Discord will send a verification PING to your endpoint. If it saves successfully, your endpoint is working.
Expand Down Expand Up @@ -153,7 +155,7 @@ curl -X POST \

Build an invite URL using your Application ID:

```
```text
https://discord.com/api/oauth2/authorize?client_id=YOUR_APPLICATION_ID&scope=applications.commands%20bot
```

Expand All @@ -169,15 +171,15 @@ https://discord.com/api/oauth2/authorize?client_id=YOUR_APPLICATION_ID&scope=app

In any channel in your server (or a DM with the bot), type:

```
```text
/capture thought:Sarah mentioned she's thinking about leaving her job to start a consulting business
```

You should see a "thinking..." indicator followed by a confirmation with extracted metadata.

### Search Your Thoughts

```
```text
/search query:career changes
```

Expand All @@ -191,22 +193,22 @@ Open Supabase Dashboard → Table Editor → `thoughts`. New rows should have `m

## Troubleshooting

**Slash commands don't appear**
### Slash commands don't appear

- Global commands take up to 1 hour to propagate. Use guild-specific registration for instant testing.
- Make sure the bot is invited to your server with the `applications.commands` scope.

**Interactions endpoint verification fails**
### Interactions endpoint verification fails

- Check that `DISCORD_PUBLIC_KEY` is set correctly (it's the hex string from General Information, not the bot token).
- Verify the Edge Function is deployed: visit the URL in a browser — should return `{"status":"ok","service":"cerebro-discord"}`.

**Bot responds with error**
### Bot responds with error

- Check Supabase Edge Function logs for detailed error messages.
- Verify `OPENROUTER_API_KEY` is set and has credits.

**"Application did not respond" error**
### "Application did not respond" error

- The Edge Function must respond within 3 seconds. The deferred response pattern (type 5) handles this — if you see this error, the function may not be receiving requests at all. Check the interactions endpoint URL.

Expand Down
10 changes: 7 additions & 3 deletions docs/04-alexa-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Unlike the previous cerebro-oss design (which required AWS Lambda + 4 Zapier zap

## Architecture

```
```text
┌─────────────┐ ┌──────────────────────────┐ ┌──────────────┐
│ Alexa │────▶│ Supabase Edge Function │────▶│ Supabase DB │
│ Echo / App │◀────│ (alexa-capture) │◀────│ + pgvector │
Expand Down Expand Up @@ -100,7 +100,7 @@ supabase functions deploy cerebro-alexa --no-verify-jwt

After deploying, your function URL will be:

```
```text
https://<your-project-ref>.supabase.co/functions/v1/cerebro-alexa
```

Expand All @@ -111,9 +111,11 @@ https://<your-project-ref>.supabase.co/functions/v1/cerebro-alexa
1. In the Alexa Developer Console, go to **Build** → **Endpoint**
2. Select **HTTPS**
3. In the **Default Region** field, paste your Edge Function URL:
```

```text
https://<your-project-ref>.supabase.co/functions/v1/cerebro-alexa
```

4. For the SSL certificate type, select: **My development endpoint has a certificate from a trusted certificate authority**
(Supabase uses Let's Encrypt / trusted CA certificates)
5. Click **Save Endpoints**
Expand Down Expand Up @@ -143,6 +145,7 @@ https://<your-project-ref>.supabase.co/functions/v1/cerebro-alexa
Since the skill is in **Development** mode, it's automatically available on any Alexa device registered to the same Amazon account as your developer account. Just speak the commands above — no sideloading or publishing required.

Works on:

- **Echo devices** (all models)
- **Alexa app** (iOS / Android)
- **Fire tablets**
Expand All @@ -163,6 +166,7 @@ supabase secrets set ALEXA_SKILL_ID=amzn1.ask.skill.your-id-here
```

The Edge Function validates:

1. **Signature** — X.509 certificate chain from Amazon, RSA signature over request body
2. **Timestamp** — request must be within 150 seconds
3. **Skill ID** — must match your `ALEXA_SKILL_ID` (if set)
Expand Down
2 changes: 1 addition & 1 deletion docs/05-reminders-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ You can configure one or both calendar backends. If neither is configured, remin

## How It Works

```
```text
"Set a reminder for next Wednesday at 5AM to review the deployment"
AI extracts: has_reminder=true, reminder_title="Review the deployment"
Expand Down
Loading
Loading