crabagent 0.5.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.
- crabagent-0.5.0/.gitignore +24 -0
- crabagent-0.5.0/AGENTS.md +111 -0
- crabagent-0.5.0/Dockerfile +29 -0
- crabagent-0.5.0/LICENSE +670 -0
- crabagent-0.5.0/Makefile +31 -0
- crabagent-0.5.0/PKG-INFO +499 -0
- crabagent-0.5.0/README.md +454 -0
- crabagent-0.5.0/README.zh-CN.md +454 -0
- crabagent-0.5.0/docker-compose.yml +18 -0
- crabagent-0.5.0/frontend/index.html +12 -0
- crabagent-0.5.0/frontend/package-lock.json +4052 -0
- crabagent-0.5.0/frontend/package.json +29 -0
- crabagent-0.5.0/frontend/src/App.tsx +22 -0
- crabagent-0.5.0/frontend/src/api/agents.ts +32 -0
- crabagent-0.5.0/frontend/src/api/auth.ts +19 -0
- crabagent-0.5.0/frontend/src/api/client.ts +65 -0
- crabagent-0.5.0/frontend/src/api/events.ts +32 -0
- crabagent-0.5.0/frontend/src/api/files.ts +26 -0
- crabagent-0.5.0/frontend/src/api/mcpServers.ts +93 -0
- crabagent-0.5.0/frontend/src/api/notifications.ts +26 -0
- crabagent-0.5.0/frontend/src/api/providers.ts +56 -0
- crabagent-0.5.0/frontend/src/api/scheduledTasks.ts +51 -0
- crabagent-0.5.0/frontend/src/api/sessions.ts +136 -0
- crabagent-0.5.0/frontend/src/api/settings.ts +13 -0
- crabagent-0.5.0/frontend/src/api/time.ts +20 -0
- crabagent-0.5.0/frontend/src/components/AgentTeamPanel.tsx +118 -0
- crabagent-0.5.0/frontend/src/components/BranchSelector.tsx +81 -0
- crabagent-0.5.0/frontend/src/components/ChatPanel.tsx +805 -0
- crabagent-0.5.0/frontend/src/components/FileBrowser.tsx +87 -0
- crabagent-0.5.0/frontend/src/components/FileTree.tsx +95 -0
- crabagent-0.5.0/frontend/src/components/McpServerPanel.tsx +582 -0
- crabagent-0.5.0/frontend/src/components/McpStatusBar.tsx +80 -0
- crabagent-0.5.0/frontend/src/components/MoltTimeline.tsx +103 -0
- crabagent-0.5.0/frontend/src/components/NotificationBell.tsx +160 -0
- crabagent-0.5.0/frontend/src/components/ProviderPanel.tsx +171 -0
- crabagent-0.5.0/frontend/src/components/ScheduledTaskPanel.tsx +249 -0
- crabagent-0.5.0/frontend/src/components/SessionList.tsx +143 -0
- crabagent-0.5.0/frontend/src/components/TodoWidget.tsx +177 -0
- crabagent-0.5.0/frontend/src/hooks/useAuth.ts +49 -0
- crabagent-0.5.0/frontend/src/hooks/useSSE.ts +34 -0
- crabagent-0.5.0/frontend/src/index.css +60 -0
- crabagent-0.5.0/frontend/src/main.tsx +10 -0
- crabagent-0.5.0/frontend/src/pages/ChatPage.tsx +844 -0
- crabagent-0.5.0/frontend/src/pages/LoginPage.tsx +108 -0
- crabagent-0.5.0/frontend/src/vite-env.d.ts +1 -0
- crabagent-0.5.0/frontend/tsconfig.json +21 -0
- crabagent-0.5.0/frontend/tsconfig.tsbuildinfo +1 -0
- crabagent-0.5.0/frontend/vite.config.ts +12 -0
- crabagent-0.5.0/pyproject.toml +76 -0
- crabagent-0.5.0/src/crabagent/__init__.py +7 -0
- crabagent-0.5.0/src/crabagent/__main__.py +3 -0
- crabagent-0.5.0/src/crabagent/cli/__init__.py +0 -0
- crabagent-0.5.0/src/crabagent/cli/__main__.py +1317 -0
- crabagent-0.5.0/src/crabagent/core/__init__.py +13 -0
- crabagent-0.5.0/src/crabagent/core/agent/__init__.py +0 -0
- crabagent-0.5.0/src/crabagent/core/agent/agents.py +207 -0
- crabagent-0.5.0/src/crabagent/core/agent/compress.py +100 -0
- crabagent-0.5.0/src/crabagent/core/agent/context.py +35 -0
- crabagent-0.5.0/src/crabagent/core/agent/loop.py +310 -0
- crabagent-0.5.0/src/crabagent/core/agent/skill/__init__.py +3 -0
- crabagent-0.5.0/src/crabagent/core/agent/skill/loader.py +141 -0
- crabagent-0.5.0/src/crabagent/core/agent/token_limits.py +111 -0
- crabagent-0.5.0/src/crabagent/core/agent/tools/__init__.py +3 -0
- crabagent-0.5.0/src/crabagent/core/agent/tools/agent.py +92 -0
- crabagent-0.5.0/src/crabagent/core/agent/tools/bash.py +57 -0
- crabagent-0.5.0/src/crabagent/core/agent/tools/browser.py +429 -0
- crabagent-0.5.0/src/crabagent/core/agent/tools/edit.py +47 -0
- crabagent-0.5.0/src/crabagent/core/agent/tools/glob.py +37 -0
- crabagent-0.5.0/src/crabagent/core/agent/tools/grep.py +54 -0
- crabagent-0.5.0/src/crabagent/core/agent/tools/read.py +59 -0
- crabagent-0.5.0/src/crabagent/core/agent/tools/registry.py +134 -0
- crabagent-0.5.0/src/crabagent/core/agent/tools/sandbox.py +92 -0
- crabagent-0.5.0/src/crabagent/core/agent/tools/scheduled_task.py +327 -0
- crabagent-0.5.0/src/crabagent/core/agent/tools/web.py +190 -0
- crabagent-0.5.0/src/crabagent/core/agent/tools/write.py +32 -0
- crabagent-0.5.0/src/crabagent/core/config.py +102 -0
- crabagent-0.5.0/src/crabagent/core/database.py +332 -0
- crabagent-0.5.0/src/crabagent/core/event.py +75 -0
- crabagent-0.5.0/src/crabagent/core/mcp/__init__.py +1 -0
- crabagent-0.5.0/src/crabagent/core/mcp/client.py +258 -0
- crabagent-0.5.0/src/crabagent/core/mcp/tools.py +63 -0
- crabagent-0.5.0/src/crabagent/core/molt/__init__.py +0 -0
- crabagent-0.5.0/src/crabagent/core/molt/rollback.py +42 -0
- crabagent-0.5.0/src/crabagent/core/molt/snapshot.py +82 -0
- crabagent-0.5.0/src/crabagent/core/molt/store.py +136 -0
- crabagent-0.5.0/src/crabagent/core/molt/tools.py +74 -0
- crabagent-0.5.0/src/crabagent/core/provider_store.py +195 -0
- crabagent-0.5.0/src/crabagent/core/todo/__init__.py +0 -0
- crabagent-0.5.0/src/crabagent/core/todo/store.py +57 -0
- crabagent-0.5.0/src/crabagent/core/todo/tools.py +92 -0
- crabagent-0.5.0/src/crabagent/core/tool_loader.py +95 -0
- crabagent-0.5.0/src/crabagent/serve/__init__.py +0 -0
- crabagent-0.5.0/src/crabagent/serve/api/__init__.py +0 -0
- crabagent-0.5.0/src/crabagent/serve/api/agent.py +90 -0
- crabagent-0.5.0/src/crabagent/serve/api/auth.py +54 -0
- crabagent-0.5.0/src/crabagent/serve/api/branch.py +158 -0
- crabagent-0.5.0/src/crabagent/serve/api/confirm.py +72 -0
- crabagent-0.5.0/src/crabagent/serve/api/event.py +88 -0
- crabagent-0.5.0/src/crabagent/serve/api/files.py +90 -0
- crabagent-0.5.0/src/crabagent/serve/api/input.py +60 -0
- crabagent-0.5.0/src/crabagent/serve/api/mcp_server.py +359 -0
- crabagent-0.5.0/src/crabagent/serve/api/message.py +25 -0
- crabagent-0.5.0/src/crabagent/serve/api/molt.py +86 -0
- crabagent-0.5.0/src/crabagent/serve/api/notification.py +86 -0
- crabagent-0.5.0/src/crabagent/serve/api/prompt.py +369 -0
- crabagent-0.5.0/src/crabagent/serve/api/provider.py +156 -0
- crabagent-0.5.0/src/crabagent/serve/api/replay.py +137 -0
- crabagent-0.5.0/src/crabagent/serve/api/scheduled_task.py +193 -0
- crabagent-0.5.0/src/crabagent/serve/api/session.py +101 -0
- crabagent-0.5.0/src/crabagent/serve/api/settings.py +66 -0
- crabagent-0.5.0/src/crabagent/serve/api/todo.py +72 -0
- crabagent-0.5.0/src/crabagent/serve/app.py +140 -0
- crabagent-0.5.0/src/crabagent/serve/auth/__init__.py +0 -0
- crabagent-0.5.0/src/crabagent/serve/deps.py +42 -0
- crabagent-0.5.0/src/crabagent/serve/scheduler.py +315 -0
- crabagent-0.5.0/src/crabagent/serve/services/__init__.py +0 -0
- crabagent-0.5.0/src/crabagent/serve/services/auth.py +78 -0
- crabagent-0.5.0/src/crabagent/serve/services/conversation.py +67 -0
- crabagent-0.5.0/src/crabagent/serve/services/knowledge/__init__.py +0 -0
- crabagent-0.5.0/src/crabagent/serve/services/memory/__init__.py +0 -0
- crabagent-0.5.0/src/crabagent/serve/services/message.py +125 -0
- crabagent-0.5.0/src/crabagent/serve/services/persistence.py +51 -0
- crabagent-0.5.0/src/crabagent/skills/python-debugger/SKILL.md +54 -0
- crabagent-0.5.0/src/crabagent/skills/python-debugger/references/common-fixes.md +27 -0
- crabagent-0.5.0/src/crabagent/static/assets/index-5bAQB-0t.css +1 -0
- crabagent-0.5.0/src/crabagent/static/assets/index-B0o08zja.js +95 -0
- crabagent-0.5.0/src/crabagent/static/assets/index-BHlp0_2I.css +1 -0
- crabagent-0.5.0/src/crabagent/static/assets/index-BOLDBZVI.js +91 -0
- crabagent-0.5.0/src/crabagent/static/assets/index-BTKnQ5Dr.js +115 -0
- crabagent-0.5.0/src/crabagent/static/assets/index-Bfw8-osw.js +115 -0
- crabagent-0.5.0/src/crabagent/static/assets/index-C6oEaTLR.js +115 -0
- crabagent-0.5.0/src/crabagent/static/assets/index-DR9sBvBT.css +1 -0
- crabagent-0.5.0/src/crabagent/static/assets/index-Dqarhpb1.css +1 -0
- crabagent-0.5.0/src/crabagent/static/assets/index-DtFwBs8h.js +115 -0
- crabagent-0.5.0/src/crabagent/static/assets/index-uVBKyDCh.js +91 -0
- crabagent-0.5.0/src/crabagent/static/index.html +13 -0
- crabagent-0.5.0/src/crabagent/web/__init__.py +0 -0
- crabagent-0.5.0/tests/__init__.py +0 -0
- crabagent-0.5.0/tests/conftest.py +6 -0
- crabagent-0.5.0/tests/test_branching.py +77 -0
- crabagent-0.5.0/tests/test_sandbox.py +55 -0
- crabagent-0.5.0/tests/test_token_limits.py +25 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
*.egg-info/
|
|
4
|
+
dist/
|
|
5
|
+
build/
|
|
6
|
+
.eggs/
|
|
7
|
+
*.egg
|
|
8
|
+
.env
|
|
9
|
+
.venv/
|
|
10
|
+
venv/
|
|
11
|
+
*.db
|
|
12
|
+
*.sqlite3
|
|
13
|
+
.pytest_cache/
|
|
14
|
+
.ruff_cache/
|
|
15
|
+
htmlcov/
|
|
16
|
+
.coverage
|
|
17
|
+
node_modules/
|
|
18
|
+
frontend/dist/
|
|
19
|
+
.DS_Store
|
|
20
|
+
*.swp
|
|
21
|
+
*.swo
|
|
22
|
+
.crabagent/
|
|
23
|
+
.opencode/
|
|
24
|
+
AGENT.md
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# Project Rules
|
|
2
|
+
|
|
3
|
+
## Version
|
|
4
|
+
- Current: **0.5.0** (agent team + multi-agent delegation)
|
|
5
|
+
- Version in 3 places: `pyproject.toml`, `src/crabagent/serve/app.py` (`create_app` + `/health`), CLI banner in `src/crabagent/cli/__main__.py` (`_print_banner`)
|
|
6
|
+
- Bump all three when changing version
|
|
7
|
+
|
|
8
|
+
## Commands
|
|
9
|
+
|
|
10
|
+
### Install (full, with frontend)
|
|
11
|
+
```
|
|
12
|
+
make install # builds frontend -> copies to static -> pip install -e '.[serve,dev]'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Install (backend only, no frontend)
|
|
16
|
+
```
|
|
17
|
+
pip install -e '.[serve,dev]'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Run
|
|
21
|
+
```
|
|
22
|
+
crabagent # interactive CLI
|
|
23
|
+
crabagent "query" # single-shot
|
|
24
|
+
crabagent --serve # web UI on :5210
|
|
25
|
+
crabagent --serve --port 8080
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Lint / Format
|
|
29
|
+
```
|
|
30
|
+
ruff check src/ tests/
|
|
31
|
+
ruff format src/ tests/
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Test
|
|
35
|
+
```
|
|
36
|
+
pytest # all tests (asyncio_mode=auto in pyproject.toml)
|
|
37
|
+
pytest tests/test_sandbox.py # single file
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Frontend
|
|
41
|
+
```
|
|
42
|
+
cd frontend && npm ci && npm run build # build React+Vite+Tailwind SPA
|
|
43
|
+
```
|
|
44
|
+
Built assets go to `frontend/dist/` and are copied to `src/crabagent/static/` by `make static`.
|
|
45
|
+
|
|
46
|
+
## Architecture
|
|
47
|
+
|
|
48
|
+
Dual-mode Python agent platform: **CLI** (`src/crabagent/cli/`) and **Serve** (`src/crabagent/serve/`), sharing core logic in `src/crabagent/core/`.
|
|
49
|
+
|
|
50
|
+
### Key directories
|
|
51
|
+
| Path | Purpose |
|
|
52
|
+
|------|---------|
|
|
53
|
+
| `src/crabagent/core/agent/loop.py` | Agent loop — litellm calls, tool execution, context compression |
|
|
54
|
+
| `src/crabagent/core/agent/context.py` | `AgentContext` dataclass (workspace, messages, event_bus, tool_registry) |
|
|
55
|
+
| `src/crabagent/core/agent/tools/` | Built-in tools: bash, read, write, edit, glob, grep, web, browser, agent, sandbox, scheduled_task |
|
|
56
|
+
| `src/crabagent/core/agent/agents.py` | Multi-agent delegation — loads `AgentProfile` from DB |
|
|
57
|
+
| `src/crabagent/core/agent/compress.py` | Context window compression (threshold 0.8) |
|
|
58
|
+
| `src/crabagent/core/agent/token_limits.py` | Model token limit registry |
|
|
59
|
+
| `src/crabagent/core/config.py` | `Settings` (pydantic-settings, env prefix `CRAB_`, reads `.env`) |
|
|
60
|
+
| `src/crabagent/core/database.py` | SQLAlchemy async models + `init_db()` with ALTER TABLE migrations |
|
|
61
|
+
| `src/crabagent/core/provider_store.py` | LLM provider CRUD (API keys encrypted with Fernet) |
|
|
62
|
+
| `src/crabagent/core/mcp/` | MCP (Model Context Protocol) client + tool registration |
|
|
63
|
+
| `src/crabagent/core/molt/` | Snapshot/rollback system (stores diffs in `.crabagent/molts/`) |
|
|
64
|
+
| `src/crabagent/core/tool_loader.py` | Discovers user tools from `.crabagent/tools/*.py` |
|
|
65
|
+
| `src/crabagent/serve/api/` | FastAPI routers — prompt, session, message, agent, provider, MCP, etc. |
|
|
66
|
+
| `src/crabagent/serve/services/` | Business logic — auth, conversation, message, persistence |
|
|
67
|
+
| `src/crabagent/skills/` | Bundled skills (e.g. `python-debugger/`) |
|
|
68
|
+
|
|
69
|
+
### Tool registration flow
|
|
70
|
+
1. Built-in tools self-register on `import` via decorators in `tools/registry.py`
|
|
71
|
+
2. Browser/agent/scheduled_task tools are optionally imported (wrapped in `try/except`)
|
|
72
|
+
3. `discover_skills()` + `register_skill_tool()` load from `.crabagent/skills/` and `.opencode/skills/`
|
|
73
|
+
4. `discover_and_register_tools()` loads user `.py` files from `.crabagent/tools/`
|
|
74
|
+
5. `register_mcp_tools()` registers tools from MCP servers
|
|
75
|
+
|
|
76
|
+
### Serve mode flow
|
|
77
|
+
- Entry: `create_app()` in `serve/app.py` — mounts all `/api` routers + SPA fallback
|
|
78
|
+
- Lifespan: `init_db()` -> start MCP clients -> start scheduler
|
|
79
|
+
- Prompt handling: `serve/api/prompt.py` creates `AgentContext` per request, runs agent in `asyncio.Task`
|
|
80
|
+
|
|
81
|
+
## Database Schema Changes
|
|
82
|
+
- NEVER delete `crabagent.db` when adding new columns/tables
|
|
83
|
+
- SQLAlchemy `create_all()` only creates new tables, it does NOT alter existing ones
|
|
84
|
+
- When adding a column to an existing table, add ALTER TABLE logic in `init_db()` in `src/crabagent/core/database.py`
|
|
85
|
+
- Example pattern:
|
|
86
|
+
```python
|
|
87
|
+
result = await conn.execute(text("PRAGMA table_info(conversations)"))
|
|
88
|
+
columns = [row[1] for row in result.fetchall()]
|
|
89
|
+
if "tokens" not in columns:
|
|
90
|
+
await conn.execute(text("ALTER TABLE conversations ADD COLUMN tokens INTEGER DEFAULT 0"))
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Browser Automation (v0.3.0)
|
|
94
|
+
- Playwright is an **optional dependency**: `pip install 'crabagent[browser]'`
|
|
95
|
+
- Tools only register if playwright is importable — `PLAYWRIGHT_AVAILABLE` flag in `browser.py`
|
|
96
|
+
- `BrowserManager` stored in `context.metadata["_browser_manager"]`, lazily initialized on first call
|
|
97
|
+
- Headless by default; set `CRAB_BROWSER_HEADLESS=false` for headed mode
|
|
98
|
+
- Cleanup: `browser_mgr.close()` called in `finally` blocks of both CLI and serve prompt handlers
|
|
99
|
+
|
|
100
|
+
## Config
|
|
101
|
+
- All settings use env prefix `CRAB_` (e.g. `CRAB_DB_URL`, `CRAB_SERVE_PORT`, `CRAB_JWT_SECRET`)
|
|
102
|
+
- `.env` file is auto-loaded by pydantic-settings
|
|
103
|
+
- API keys are encrypted at rest with Fernet (key auto-generated in `~/.crabagent/encryption_key`)
|
|
104
|
+
- Encryption key migration runs in `init_db()` via `migrate_plaintext_keys()`
|
|
105
|
+
|
|
106
|
+
## General
|
|
107
|
+
- Provider configs are user data stored in `crabagent.db` — never delete the DB without explicit user approval
|
|
108
|
+
- Default admin user created on first `init_db()` (username: `admin`, password: `xcl1989`)
|
|
109
|
+
- 4 default agent profiles seeded: researcher, analyst, coder, writer
|
|
110
|
+
- Requires Python >=3.12
|
|
111
|
+
- When in doubt, ask the user before any destructive operation
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
FROM node:20-alpine AS frontend
|
|
2
|
+
WORKDIR /app/frontend
|
|
3
|
+
COPY frontend/package.json frontend/package-lock.json ./
|
|
4
|
+
RUN npm ci
|
|
5
|
+
COPY frontend/ ./
|
|
6
|
+
RUN npm run build
|
|
7
|
+
|
|
8
|
+
FROM python:3.12-slim
|
|
9
|
+
WORKDIR /app
|
|
10
|
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
11
|
+
curl \
|
|
12
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
13
|
+
|
|
14
|
+
COPY pyproject.toml Makefile ./
|
|
15
|
+
COPY src/ ./src/
|
|
16
|
+
COPY --from=frontend /app/frontend/dist /app/src/crabagent/static
|
|
17
|
+
|
|
18
|
+
RUN pip install --no-cache-dir '.[serve]'
|
|
19
|
+
|
|
20
|
+
EXPOSE 5210
|
|
21
|
+
|
|
22
|
+
VOLUME ["/data"]
|
|
23
|
+
ENV CRAB_DB_URL=sqlite+aiosqlite:////data/crabagent.db
|
|
24
|
+
|
|
25
|
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
26
|
+
CMD curl -f http://localhost:5210/health || exit 1
|
|
27
|
+
|
|
28
|
+
ENTRYPOINT ["crabagent"]
|
|
29
|
+
CMD ["--serve"]
|