summaryrefslogtreecommitdiff
path: root/AI_AGENT_SETUP.md
blob: acf2da4540dc4080c29c94f1e20d79bffe7039cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# AI Agent Access Setup Guide

## Quick Start

### 1. Generate API Key
```bash
# Generate a secure 64-character API key
openssl rand -hex 32
```

Example output: `a1b2c3d4e5f6...`

### 2. Add to Environment
Add to your `.env` file:
```bash
AI_AGENT_API_KEY=a1b2c3d4e5f6...
```

### 3. Start the Dashboard
```bash
go run cmd/dashboard/main.go
```

You should see:
```
AI agent access enabled at /api/claude/snapshot
Starting server on http://localhost:8080
```

### 4. Test the Endpoint
```bash
curl -H "Authorization: Bearer a1b2c3d4e5f6..." \
     http://localhost:8080/api/claude/snapshot | jq .
```

## Usage from Claude.ai

### Method 1: Direct WebFetch
When conversing with Claude, share:

**URL:** `http://localhost:8080/api/claude/snapshot`
**Token:** `a1b2c3d4e5f6...` (share separately, not in chat history)

Claude can then fetch your dashboard:
```
User: "What tasks do I have today?"

Claude: [Calls WebFetch with Authorization header]
Claude: "You have 3 tasks due today:
1. Review PRs (Work, Priority 4)
2. Buy groceries (Personal, Priority 1)
3. Call dentist (Health, Priority 2)"
```

### Method 2: MCP Server (Advanced)
If you have Claude Desktop with MCP support:

Add to your MCP config:
```json
{
  "mcpServers": {
    "personal-dashboard": {
      "command": "curl",
      "args": [
        "-H",
        "Authorization: Bearer YOUR_TOKEN_HERE",
        "-s",
        "http://localhost:8080/api/claude/snapshot"
      ]
    }
  }
}
```

## Response Format

### Successful Response (200 OK)
```json
{
  "generated_at": "2026-01-09T15:30:00Z",
  "tasks": {
    "today": [
      {
        "id": "task_123",
        "content": "Review PRs",
        "priority": 4,
        "due": "2026-01-09T17:00:00Z",
        "project": "Work",
        "completed": false
      }
    ],
    "overdue": [],
    "next_7_days": []
  },
  "meals": {
    "today": {
      "date": "2026-01-09",
      "breakfast": "Oatmeal with protein powder",
      "lunch": "Chicken salad",
      "dinner": "Salmon with veggies"
    },
    "next_7_days": []
  },
  "notes": {
    "recent": [
      {
        "title": "Sprint planning notes",
        "modified": "2026-01-09T10:15:00Z",
        "preview": "Discussed Q1 goals and team capacity...",
        "path": "work/sprint-planning.md"
      }
    ]
  },
  "trello_boards": [
    {
      "id": "board_123",
      "name": "Work Projects",
      "cards": [
        {
          "id": "card_456",
          "name": "Complete project proposal",
          "list": "In Progress",
          "due": "2026-01-15T00:00:00Z",
          "url": "https://trello.com/c/card456"
        }
      ]
    }
  ]
}
```

### Error Response (401 Unauthorized)
```json
{
  "error": "unauthorized",
  "message": "Invalid or missing token"
}
```

## Security Best Practices

### ✅ Do
- Generate a long, random key (32+ bytes)
- Store key in `.env` file (gitignored)
- Use HTTPS in production
- Rotate key periodically (change in `.env`)
- Share token with Claude separately from URL

### ❌ Don't
- Commit API key to git
- Share key in chat history
- Use simple/guessable keys
- Expose over HTTP in production
- Include key in URL query parameters

## Data Limits

The endpoint is optimized for AI consumption:

- **Tasks**: Today + overdue + next 7 days only
- **Notes**: 10 most recent, 150 char preview each
- **Meals**: Today + next 7 days
- **Trello**: All boards and cards
- **Total Response**: < 100KB (typically 10-50KB)

## Caching

- Responses are cached for 5 minutes
- Same cache as web dashboard
- Reduces load on external APIs (Todoist, Trello, etc.)

## Troubleshooting

### "Invalid or missing token"
- Check `Authorization: Bearer` prefix is included
- Verify token matches `.env` file exactly
- No extra spaces or newlines in token

### "AI agent access not configured"
- Ensure `AI_AGENT_API_KEY` is set in `.env`
- Restart the server after changing `.env`

### Empty response sections
- Trello/Todoist/PlanToEat APIs may be down
- Check dashboard web UI to see if data loads there
- Review server logs for API errors

## Production Deployment

### With Caddy (Automatic HTTPS)
```caddyfile
dashboard.yourdomain.com {
    reverse_proxy localhost:8080
}
```

### With nginx
```nginx
server {
    listen 443 ssl http2;
    server_name dashboard.yourdomain.com;

    ssl_certificate /path/to/cert.pem;
    ssl_certificate_key /path/to/key.pem;

    location / {
        proxy_pass http://localhost:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}
```

Then share with Claude:
- **URL**: `https://dashboard.yourdomain.com/api/claude/snapshot`
- **Token**: (your API key)

## Example Claude Conversations

### Check Today's Tasks
```
User: "What do I need to do today?"

Claude: [Fetches /api/claude/snapshot]

Claude: "Here's what you have for today:

Tasks:
- Review PRs (Work, Priority 4, due 5pm)
- Buy groceries (Personal, Priority 1)

Meals:
- Breakfast: Oatmeal
- Lunch: Chicken salad
- Dinner: Salmon with veggies"
```

### Check Overdue Items
```
User: "Do I have anything overdue?"

Claude: [Fetches snapshot]

Claude: "You have 2 overdue tasks:
1. Submit expense report (Work, was due Jan 5)
2. Schedule dentist appointment (Health, was due Jan 7)"
```

### Review Recent Notes
```
User: "What notes have I created recently?"

Claude: [Fetches snapshot]

Claude: "Your 3 most recent notes:
1. Sprint planning notes (modified today at 10:15am)
2. Customer feedback summary (modified Jan 8)
3. Architecture decision record (modified Jan 6)"
```

## Rate Limiting (Future)

Currently no rate limiting. For production use, consider adding:
- 100 requests/hour per token
- Implement using middleware
- Return 429 status when exceeded

## Next Steps

1. ✅ Generate API key
2. ✅ Add to .env
3. ✅ Test with curl
4. ✅ Share URL + token with Claude
5. ✅ Start conversing!

Enjoy your AI-powered personal dashboard! 🚀