agentibridge 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. agentibridge-0.2.0/LICENSE +21 -0
  2. agentibridge-0.2.0/PKG-INFO +422 -0
  3. agentibridge-0.2.0/README.md +386 -0
  4. agentibridge-0.2.0/agentibridge/__init__.py +3 -0
  5. agentibridge-0.2.0/agentibridge/__main__.py +5 -0
  6. agentibridge-0.2.0/agentibridge/claude_runner.py +327 -0
  7. agentibridge-0.2.0/agentibridge/cli.py +1218 -0
  8. agentibridge-0.2.0/agentibridge/collector.py +148 -0
  9. agentibridge-0.2.0/agentibridge/config.py +105 -0
  10. agentibridge-0.2.0/agentibridge/data/docker-compose.yml +109 -0
  11. agentibridge-0.2.0/agentibridge/dispatch.py +278 -0
  12. agentibridge-0.2.0/agentibridge/dispatch_bridge.py +333 -0
  13. agentibridge-0.2.0/agentibridge/embeddings.py +368 -0
  14. agentibridge-0.2.0/agentibridge/llm_client.py +147 -0
  15. agentibridge-0.2.0/agentibridge/logging.py +51 -0
  16. agentibridge-0.2.0/agentibridge/oauth_provider.py +356 -0
  17. agentibridge-0.2.0/agentibridge/parser.py +484 -0
  18. agentibridge-0.2.0/agentibridge/pg_client.py +100 -0
  19. agentibridge-0.2.0/agentibridge/redis_client.py +68 -0
  20. agentibridge-0.2.0/agentibridge/server.py +632 -0
  21. agentibridge-0.2.0/agentibridge/store.py +436 -0
  22. agentibridge-0.2.0/agentibridge/transport.py +439 -0
  23. agentibridge-0.2.0/agentibridge.egg-info/PKG-INFO +422 -0
  24. agentibridge-0.2.0/agentibridge.egg-info/SOURCES.txt +29 -0
  25. agentibridge-0.2.0/agentibridge.egg-info/dependency_links.txt +1 -0
  26. agentibridge-0.2.0/agentibridge.egg-info/entry_points.txt +2 -0
  27. agentibridge-0.2.0/agentibridge.egg-info/requires.txt +15 -0
  28. agentibridge-0.2.0/agentibridge.egg-info/top_level.txt +1 -0
  29. agentibridge-0.2.0/pyproject.toml +69 -0
  30. agentibridge-0.2.0/setup.cfg +4 -0
  31. agentibridge-0.2.0/tests/test_docker.py +744 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 The Cloud Clock Work
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,422 @@
1
+ Metadata-Version: 2.4
2
+ Name: agentibridge
3
+ Version: 0.2.0
4
+ Summary: Claude CLI transcript indexer and MCP server
5
+ Author: The Cloud Clock Work
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/The-Cloud-Clock-Work/agentibridge
8
+ Project-URL: Repository, https://github.com/The-Cloud-Clock-Work/agentibridge
9
+ Project-URL: Issues, https://github.com/The-Cloud-Clock-Work/agentibridge/issues
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: fastmcp>=2.0
22
+ Requires-Dist: redis>=7.0
23
+ Requires-Dist: uvicorn[standard]>=0.30
24
+ Requires-Dist: httpx>=0.25
25
+ Requires-Dist: anthropic>=0.40
26
+ Requires-Dist: psycopg[binary]>=3.1
27
+ Requires-Dist: psycopg-pool>=3.1
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=8.0; extra == "dev"
30
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
31
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
32
+ Requires-Dist: fakeredis>=2.21; extra == "dev"
33
+ Requires-Dist: numpy; extra == "dev"
34
+ Requires-Dist: ruff>=0.4; extra == "dev"
35
+ Dynamic: license-file
36
+
37
+ # AgentiBridge
38
+
39
+ **Memory for your AI agents.** AgentiBridge indexes your Claude Code sessions and makes them searchable by any AI client through 10 MCP tools.
40
+
41
+ **Use cases:**
42
+ - 🔍 Search past sessions: "What did I work on last week?"
43
+ - 🤖 Cross-session context: Let one agent learn from another's work
44
+ - 📊 Session analytics: Track tool usage and patterns
45
+ - 🔄 Resume work: Restore session context and continue
46
+
47
+ **Connect from:** Claude Code CLI, ChatGPT, Claude Web, Grok, or any MCP client
48
+
49
+ ## Quick Start
50
+
51
+ ### Option 1: Local Only (Same Machine)
52
+
53
+ ```bash
54
+ pip install agentibridge
55
+ agentibridge run
56
+ curl http://localhost:8100/health
57
+ ```
58
+
59
+ Add to `~/.mcp.json`:
60
+
61
+ ```json
62
+ {
63
+ "mcpServers": {
64
+ "agentibridge": { "url": "http://localhost:8100/sse" }
65
+ }
66
+ }
67
+ ```
68
+
69
+ Done. Your Claude Code sessions are now searchable.
70
+
71
+ ### Option 2: Public Access via Cloudflare
72
+
73
+ If you want a persistent URL like `https://mcp.yourdomain.com`, set up the Cloudflare Tunnel **first**, then start the bridge:
74
+
75
+ ```bash
76
+ pip install agentibridge
77
+ agentibridge tunnel setup # 1. interactive wizard: install cloudflared, auth, DNS
78
+ agentibridge run # 2. starts the bridge on :8100
79
+ curl https://mcp.yourdomain.com/health
80
+ ```
81
+
82
+ Add to `~/.mcp.json`:
83
+
84
+ ```json
85
+ {
86
+ "mcpServers": {
87
+ "agentibridge": { "url": "https://mcp.yourdomain.com/mcp" }
88
+ }
89
+ }
90
+ ```
91
+
92
+ The domain is **not** configured in the bridge itself — it lives in the Cloudflare Tunnel config (`~/.cloudflared/config.yml`), which the setup wizard writes for you. The bridge just listens on `localhost:8100` and the tunnel routes your domain to it.
93
+
94
+ See [Cloudflare Tunnel Setup](#cloudflare-tunnel-setup) for detailed configuration.
95
+
96
+ ## Core Concepts
97
+
98
+ ### MCP Tools (10 total)
99
+
100
+ **Phase 1 — Foundation** (6 tools)
101
+ - `list_sessions` — Browse all indexed sessions
102
+ - `get_session` — Retrieve full session with transcript
103
+ - `get_session_segment` — Get paginated transcript chunks
104
+ - `get_session_actions` — Analyze tool usage patterns
105
+ - `search_sessions` — Keyword search across transcripts
106
+ - `collect_now` — Force immediate index update
107
+
108
+ **Phase 2 — AI-Powered** (2 tools)
109
+ - `search_semantic` — Natural language search with embeddings
110
+ - `generate_summary` — AI-generated session summaries
111
+
112
+ **Phase 4 — Write-back** (2 tools)
113
+ - `restore_session` — Load past session context
114
+ - `dispatch_task` — Start new task with context from past sessions
115
+
116
+ > **Note:** Phase 3 is the transport layer (SSE/HTTP), not exposed as tools.
117
+
118
+ ### CLI Commands
119
+
120
+ **Docker Stack:**
121
+ ```bash
122
+ agentibridge run # Start the stack (detects state, shows status)
123
+ agentibridge run --rebuild # Force pull + rebuild before starting
124
+ agentibridge stop # Stop the stack
125
+ agentibridge restart # Restart the stack
126
+ agentibridge logs # View logs (last 100 lines)
127
+ agentibridge logs --follow # Stream logs live
128
+ ```
129
+
130
+ **Status & Info:**
131
+ ```bash
132
+ agentibridge status # Service health, per-container health checks, Redis, sessions
133
+ agentibridge version # Print version
134
+ agentibridge config # View current configuration
135
+ agentibridge config --generate-env # Generate .env template
136
+ ```
137
+
138
+ **Dispatch Bridge (host-side Claude CLI proxy):**
139
+ ```bash
140
+ agentibridge bridge start # Start dispatch bridge in background
141
+ agentibridge bridge stop # Stop dispatch bridge
142
+ agentibridge bridge logs # Tail dispatch bridge log
143
+ ```
144
+
145
+ **Cloudflare Tunnel:**
146
+ ```bash
147
+ agentibridge tunnel # Show tunnel status and URL
148
+ agentibridge tunnel setup # Interactive wizard: install, auth, DNS, config, systemd
149
+ ```
150
+
151
+ **Client & Service Setup:**
152
+ ```bash
153
+ agentibridge connect # Get connection configs for all clients
154
+ agentibridge install --docker # Set up systemd service (Docker)
155
+ agentibridge install --native # Set up systemd service (native Python)
156
+ agentibridge locks # View/clear Redis locks
157
+ ```
158
+
159
+ See `agentibridge help` for the full tool and configuration reference.
160
+
161
+ ### Architecture
162
+
163
+ ```
164
+ ┌─────────────────────────────────────┐
165
+ │ MCP Server (server.py) │
166
+ │ 10 tools across 4 phases │
167
+ │ │
168
+ │ Phase 1: list/get/search sessions │
169
+ │ Phase 2: semantic search + summary │
170
+ │ Phase 3: SSE/HTTP transport + auth │
171
+ │ Phase 4: restore context + dispatch│
172
+ └─────────────┬───────────────────────┘
173
+
174
+ ┌─────────┴─────────┐
175
+ │ │
176
+ ▼ ▼
177
+ ┌──────────┐ ┌──────────────┐
178
+ │ Collector│ │ SessionStore │
179
+ │ (daemon) │───▶│ Redis + file │
180
+ │ polls │ │ fallback │
181
+ │ ~/.claude│ └──────────────┘
182
+ └──────────┘
183
+ ```
184
+
185
+ ## Installation Options
186
+
187
+ ### Docker Stack via CLI (Recommended)
188
+
189
+ ```bash
190
+ pip install agentibridge
191
+ agentibridge run
192
+ ```
193
+
194
+ `agentibridge run` copies the bundled `docker-compose.yml` and `.env` template to `~/.config/agentibridge/` on first run, validates required env vars, detects current stack state, then runs `docker compose up -d`. Separate containers for app, Redis, and Postgres.
195
+
196
+ ### pip Install (Local/Development)
197
+
198
+ ```bash
199
+ pip install -e .
200
+ python -m agentibridge # stdio transport (local MCP)
201
+
202
+ # Or with SSE for remote clients:
203
+ AGENTIBRIDGE_TRANSPORT=sse python -m agentibridge
204
+ ```
205
+
206
+ ### systemd Service (Auto-start on Boot)
207
+
208
+ ```bash
209
+ pip install -e .
210
+ agentibridge install --docker # Docker-based
211
+ # or
212
+ agentibridge install --native # Native Python
213
+ ```
214
+
215
+ ## Connect Your AI Client
216
+
217
+ ### Claude Code CLI
218
+
219
+ Add to `~/.mcp.json`:
220
+
221
+ ```json
222
+ {
223
+ "mcpServers": {
224
+ "agentibridge": {
225
+ "url": "http://localhost:8100/sse",
226
+ "headers": {"X-API-Key": "your-key"}
227
+ }
228
+ }
229
+ }
230
+ ```
231
+
232
+ ### Other Clients
233
+
234
+ Run `agentibridge connect` for ready-to-paste configs for ChatGPT, Claude Web, Grok, and generic MCP clients.
235
+
236
+ See [Connecting Clients](docs/getting-started/connecting-clients.md) for detailed setup instructions.
237
+
238
+ ## Configuration
239
+
240
+ ### Essential Variables
241
+
242
+ **For Basic Setup (Docker Compose):**
243
+ ```bash
244
+ # No configuration needed - Docker Compose sets defaults
245
+ # Redis, ports, and volumes are pre-configured
246
+ ```
247
+
248
+ **For Remote Access (SSE Transport):**
249
+ ```bash
250
+ AGENTIBRIDGE_TRANSPORT=sse
251
+ AGENTIBRIDGE_HOST=0.0.0.0
252
+ AGENTIBRIDGE_PORT=8100
253
+ AGENTIBRIDGE_API_KEYS=your-secret-key # Optional: comma-separated
254
+ ```
255
+
256
+ **For Semantic Search (Phase 2):**
257
+ ```bash
258
+ POSTGRES_URL=postgresql://user:pass@localhost:5432/agentibridge
259
+ LLM_API_BASE=http://localhost:11434/v1
260
+ LLM_EMBED_MODEL=text-embedding-3-small
261
+ ```
262
+
263
+ **For AI Summaries:**
264
+ ```bash
265
+ ANTHROPIC_API_KEY=sk-ant-... # Preferred for summaries
266
+ # OR
267
+ LLM_CHAT_MODEL=gpt-4o-mini # Fallback if no Anthropic key
268
+ ```
269
+
270
+ ### All Configuration Options
271
+
272
+ See [Configuration Reference](docs/reference/configuration.md) for the complete list of 20+ environment variables.
273
+
274
+ **Quick config commands:**
275
+ ```bash
276
+ agentibridge config # View current config
277
+ agentibridge config --generate-env # Generate .env template
278
+ ```
279
+
280
+ ## Cloudflare Tunnel Setup
281
+
282
+ AgentiBridge can be exposed via Cloudflare Tunnel for remote access with zero configuration and automatic TLS.
283
+
284
+ ### Quick Tunnel (No Account Needed)
285
+
286
+ Temporary `*.trycloudflare.com` URL that changes on restart. Good for testing.
287
+
288
+ ```bash
289
+ agentibridge run
290
+ docker compose --profile tunnel up -d # adds the cloudflared sidecar
291
+ agentibridge tunnel # prints the temporary public URL
292
+ ```
293
+
294
+ ### Named Tunnel (Persistent URL)
295
+
296
+ For a stable URL like `https://mcp.yourdomain.com` that survives restarts.
297
+
298
+ **Prerequisites:** A [Cloudflare account](https://dash.cloudflare.com/sign-up) with at least one domain added.
299
+
300
+ **Run the interactive wizard:**
301
+
302
+ ```bash
303
+ agentibridge tunnel setup
304
+ ```
305
+
306
+ The wizard walks you through 10 steps:
307
+ 1. Installs `cloudflared` binary (Linux amd64/arm64/arm, macOS via Homebrew)
308
+ 2. Authenticates with Cloudflare (opens browser)
309
+ 3. Prompts for tunnel name (default: `agentibridge`)
310
+ 4. Creates the tunnel (idempotent — skips if it already exists)
311
+ 5. Prompts for subdomain (e.g., `mcp`)
312
+ 6. Prompts for domain (e.g., `yourdomain.com`)
313
+ 7. Creates DNS CNAME route automatically
314
+ 8. Writes `~/.cloudflared/config.yml` (backs up any existing file)
315
+ 9. Optionally installs and enables a systemd service (Linux)
316
+ 10. Runs a health check against your public hostname
317
+
318
+ **After the wizard finishes**, start the bridge:
319
+
320
+ ```bash
321
+ agentibridge run
322
+ curl https://mcp.yourdomain.com/health
323
+ # {"status": "ok", "service": "agentibridge"}
324
+ ```
325
+
326
+ **Check tunnel status at any time:**
327
+
328
+ ```bash
329
+ agentibridge tunnel # shows container status + URL
330
+ ```
331
+
332
+ **Alternative (Docker-only):** If you already created a tunnel in the [Cloudflare Zero Trust dashboard](https://one.dash.cloudflare.com/), pass the token directly:
333
+
334
+ ```bash
335
+ CLOUDFLARE_TUNNEL_TOKEN=xxx docker compose --profile tunnel-named up -d
336
+ ```
337
+
338
+ See [Cloudflare Tunnel Guide](docs/deployment/cloudflare-tunnel.md) for detailed instructions and troubleshooting.
339
+
340
+ > **How it works:** Cloudflare Tunnel routes your domain → `localhost:8100`. The bridge has no domain config — it's all in `~/.cloudflared/config.yml`.
341
+
342
+ ## Dispatch Bridge (Docker → Host Claude CLI)
343
+
344
+ When AgentiBridge runs in Docker, the `claude` CLI binary and auth credentials aren't available inside the container. The dispatch bridge solves this — a lightweight HTTP server running on the **host** that the container calls to execute Claude CLI commands.
345
+
346
+ ```
347
+ Docker Container Host Machine
348
+ ┌──────────────────────┐ HTTP POST ┌────────────────────────┐
349
+ │ MCP Server │ /dispatch │ dispatch_bridge.py │
350
+ │ → claude_runner.py │ ──────────────>│ → claude CLI (local) │
351
+ │ (HTTP mode) │ <──────────────│ → returns result JSON │
352
+ └──────────────────────┘ └────────────────────────┘
353
+ ```
354
+
355
+ ### Setup
356
+
357
+ **1. Configure `.env`** (already done if you followed Quick Start):
358
+
359
+ ```bash
360
+ CLAUDE_DISPATCH_URL=http://host.docker.internal:8101
361
+ DISPATCH_SECRET=your-secret-here
362
+ ```
363
+
364
+ **2. Start the bridge on the host:**
365
+
366
+ ```bash
367
+ DISPATCH_BRIDGE_SECRET=your-secret-here python -m agentibridge.dispatch_bridge
368
+ ```
369
+
370
+ The bridge binds to `0.0.0.0:8101` by default so Docker containers can reach it via `host.docker.internal`.
371
+
372
+ **3. Verify:**
373
+
374
+ ```bash
375
+ curl http://localhost:8101/health
376
+ # {"status": "ok"}
377
+ ```
378
+
379
+ The `dispatch_task` MCP tool will now route through the bridge automatically when `CLAUDE_DISPATCH_URL` is set.
380
+
381
+ ### Bridge Environment Variables
382
+
383
+ | Variable | Where | Default | Purpose |
384
+ |----------|-------|---------|---------|
385
+ | `CLAUDE_DISPATCH_URL` | Container (`.env`) | *(empty = local mode)* | Bridge URL for container to call |
386
+ | `DISPATCH_SECRET` | Container (`.env`) | *(empty)* | Shared secret sent to bridge |
387
+ | `DISPATCH_BRIDGE_SECRET` | Host shell | *(required)* | Secret the bridge validates against |
388
+ | `DISPATCH_BRIDGE_HOST` | Host shell | `0.0.0.0` | Bridge bind address |
389
+ | `DISPATCH_BRIDGE_PORT` | Host shell | `8101` | Bridge listen port |
390
+ | `CLAUDE_DISPATCH_TIMEOUT` | Host shell | `600` | Max timeout cap (seconds) |
391
+
392
+ ### Using with compose.sh
393
+
394
+ The interactive compose manager includes dispatch bridge management:
395
+
396
+ ```bash
397
+ ./automation/compose.sh
398
+ # Select "Start dispatch bridge" or "Stop dispatch bridge" from the menu
399
+ ```
400
+
401
+ ## What's Next
402
+
403
+ **Getting Started:**
404
+ - [Connecting Clients](docs/getting-started/connecting-clients.md) — Setup for Claude Code, ChatGPT, Claude Web, Grok
405
+ - [Configuration Reference](docs/reference/configuration.md) — All environment variables explained
406
+
407
+ **Advanced Features:**
408
+ - [Semantic Search](docs/architecture/semantic-search.md) — Embedding backends and natural language search
409
+ - [Session Dispatch](docs/architecture/session-dispatch.md) — Restore context and dispatch tasks
410
+ - [Remote Access](docs/architecture/remote-access.md) — SSE/HTTP transport and authentication
411
+
412
+ **Deployment:**
413
+ - [Cloudflare Tunnel](docs/deployment/cloudflare-tunnel.md) — Expose to internet securely
414
+ - [Reverse Proxy](docs/deployment/reverse-proxy.md) — Nginx, Caddy, Traefik configs
415
+
416
+ **Contributing:**
417
+ - See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, testing, and CI/CD
418
+ - [Internal Architecture](docs/architecture/internals.md) — Deep dive into key modules and patterns
419
+
420
+ ## License
421
+
422
+ MIT