Metadata-Version: 2.5
Name: crabagent
Version: 0.19.9
Summary: CrabAgent - AI Agent Platform with dual-mode (CLI + Serve)
Project-URL: Homepage, https://github.com/xcl1989/CrabAgent
Project-URL: Repository, https://github.com/xcl1989/CrabAgent
Project-URL: Issues, https://github.com/xcl1989/CrabAgent/issues
Author-email: Xie Congling <xcl1989@live.com>
License: Commercial
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: Other/Proprietary License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.12
Requires-Dist: aiosqlite>=0.20
Requires-Dist: apscheduler>=3.10
Requires-Dist: bcrypt<5.0,>=4.0
Requires-Dist: ddgs>=7.0
Requires-Dist: fastapi>=0.110
Requires-Dist: httpx>=0.27
Requires-Dist: icalendar>=5.0
Requires-Dist: jieba>=0.42
Requires-Dist: litellm>=1.40
Requires-Dist: lxml>=6.1.1
Requires-Dist: mcp>=1.0
Requires-Dist: passlib[bcrypt]>=1.7
Requires-Dist: pillow>=10.0
Requires-Dist: prompt-toolkit>=3.0
Requires-Dist: pydantic-settings>=2.0
Requires-Dist: pydantic>=2.0
Requires-Dist: python-jose[cryptography]>=3.3
Requires-Dist: redis>=5.0
Requires-Dist: rich>=13.0
Requires-Dist: scrapling>=0.4.9
Requires-Dist: segno>=1.6
Requires-Dist: sqlalchemy>=2.0
Requires-Dist: uvicorn>=0.29
Provides-Extra: browser
Requires-Dist: playwright>=1.40; extra == 'browser'
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Provides-Extra: memory
Requires-Dist: sentence-transformers>=3.0; extra == 'memory'
Description-Content-Type: text/markdown

# 🦀 CrabAgent

**A local-first AI work assistant for conversations, files, browsers, and the desktop.**

English | [中文](README.zh-CN.md) · [Python 3.12+](https://www.python.org/downloads/) · [License](LICENSE)

CrabAgent brings AI chat, task execution, and a live workspace together. Ask an agent to research a question, edit code or Office documents, navigate a browser, or operate an authorized native macOS app. Use Chat Mode for discussion and Work Mode to inspect documents, code, and prototypes as you work.

## Highlights

- **Chat and workspace**: multiple conversations and workspaces, with Markdown, code editing, document preview, and prototypes. Responses can include Mermaid diagrams, charts, and KPI cards. Sessions can be renamed, pinned, archived, or duplicated together with the active branch history.
- **Agent team and project memory**: delegate research, analysis, coding, or writing when useful; run parallel tasks or pipelines, hand off work, and retain project knowledge and preferences across sessions.
- **Goals and tasks**: track objectives, acceptance criteria, and progress alongside tasks, calendars, scheduled jobs, and meeting action items.
- **Files and documents**: work with local files and create, edit, or preview Word, Excel, and PowerPoint documents. Snapshots support rollback.
- **Browser and macOS control**: the collaboration browser shares login state; opt-in macOS control operates allowlisted native apps. You handle CAPTCHA, MFA, and other human-only steps.
- **Integrations**: MCP, custom tools, email, WeChat, remote access through Tailscale, and task notifications via Bark or ntfy are available with their respective configuration.
- **Project collaboration**: editing intentions are advisory; shared files show current intentions and saved changes, while version checks prevent stale saves.
- **iOS companion (`ios/`)**: a standalone iPhone app built around a **Today** screen — calendar, one-tap system reminders, and conversations flagged for follow-up — with on-device agent execution, approval-gated write tools, and a personal memory you confirm. Calendar data never leaves the device. It pairs with the desktop over your own network (QR code; LAN or Tailscale, whichever answers) and hands work to the Mac when a request needs the computer — the assistant decides, you tap which machine on an inline card. A Share Extension brings text, PDFs and images in from other apps, with on-device OCR.

## Two Work Modes

| | Chat Mode | Work Mode |
|---|---|---|
| Best for | Questions, discussion, search, and planning | Creating or changing files while inspecting results |
| Layout | Session list and conversation | AI sidebar with a document, code, or prototype workspace |
| Typical actions | Switch models, use tools, delegate to agents | Preview Office files, edit Markdown, inspect code and meeting notes |

Switch modes in the interface; opening or creating a file can also bring up the workspace. The conversation remains available throughout.

**For example**, ask an agent to summarize a spreadsheet and create a report, or inspect a codebase, explain changes, and run tests. Check sources and results when working with real business data.

## Quick Start

Requires Python 3.12 or later.

```bash
pip install crabagent
crabagent init

crabagent                         # interactive TUI
crabagent --serve                 # Web UI: http://localhost:5210
crabagent "organize this directory"  # single CLI request
```

Configure a model provider when prompted, or use Settings for ChatGPT subscription login, MCP, and other integrations. For Gemini models, add a provider with a Google AI Studio API key. Optional browser automation dependencies:

```bash
pip install 'crabagent[browser]'
playwright install chromium
```

The Web server listens on `0.0.0.0:5210` by default and may be reachable from other devices. Review authentication, network access, and firewall settings before remote use.

## Desktop App

The desktop app supports macOS and Windows. After installing CrabAgent, build it with:

```bash
crabagent --build-desktop
```

From source, use `make desktop` on macOS or `scripts/build-desktop.ps1` on Windows. The desktop app also includes an optional status pet controlled from the tray or app menu.

## iOS App (Source)

`ios/` contains a standalone personal-assistant app for iPhone (Swift packages + an xcodegen project). It does not need the Mac app at runtime: the agent loop, tools, approvals and storage run on the device, and the model is reached through the same provider catalog as desktop (API key or subscription).

- **Today** is the home screen: the day's calendar (off / busy blocks only / details shown on device — details are privacy-sensitive and never sent to a model), a one-tap **system reminder** saved to iOS Reminders, and **Continue working** for conversations you flagged.
- **Assistant → desktop**: when a request needs the computer, the assistant calls `handoff_to_desktop`; an inline card lists the paired Macs and tapping one sends the work. One phone conversation maps to one desktop session; the reply comes back into the chat. Pair from desktop **Settings → 手机联动** with a QR code — the phone probes both the Tailscale and LAN addresses and keeps whichever answers.
- **Share Extension**: share text, a PDF or an image from any app; it lands in its own conversation with the attachment ready. Images and scanned pages are OCR'd on device.
- **Assistant** is the natural-language entry point. Starter chips only fill the draft. The model can read documents you imported into the current conversation and can create artifacts or reminders only after you approve a dialog that shows what will be written.
- **Memory** about you is stored on the device, proposed into a pending inbox, and only sent to the model after you confirm it.

Build and test it with `swift test` inside `ios/Packages/CrabAgentCore` and `xcodebuild -project ios/App/CrabAgent.xcodeproj -scheme CrabAgent -destination 'generic/platform=iOS Simulator' CODE_SIGNING_ALLOWED=NO build`; the Swift package tests and simulator build also run in `.github/workflows/ios.yml`.

## Agent Team, Goals, and Memory

Built-in agents include a researcher, data analyst, coding expert, writer, and planner. Choose a role in conversation or let the agent delegate, run independent work in parallel, or connect steps in a pipeline. For straightforward tasks, the current agent can work alone. When a synchronously delegated sub-agent hits an action that needs approval, the confirmation card appears in the current conversation labelled with its origin, and the sub-agent continues once approved; it can also ask you questions.

Goal Mode tracks ongoing work: use the target button or `/goal <objective>` to create a goal with acceptance criteria, constraints, and checkpoints. Pause, resume, or inspect progress as needed. Auto Continue is bounded by the goal state and configured budgets. The agent may only declare completion with criterion-by-criterion evidence, or declare the goal unmet with a concrete blocker — pausing and giving up stay with you, and each continuation first audits the evidence for every criterion before doing new work. Questions support a recommended answer: the agent's suggestion is listed first and highlighted for one-click acceptance.

Project memory retains workspace context, shared knowledge, preferences, and lessons for later sessions. Relevant memories are injected automatically with each user turn: Chinese queries are segmented into whole words, generic terms are filtered by corpus frequency, and keyword hits are fused with semantic (embedding) hits so paraphrases recall as well as exact identifiers. Every memory is recalled on relevance only — nothing is injected unconditionally — and the same memory is not repeated within a session; knowledge that must be known on every turn belongs in the workspace `AGENTS.md`. Use the task board, calendar, and scheduled tasks for ongoing work; meeting notes can be used to extract action items.

## Browser and Desktop Control

The **collaboration browser** shares its embedded browser login state with you. An agent can navigate, fill non-sensitive fields, and inspect pages; you handle logins, CAPTCHA, and MFA. Sensitive input and high-risk actions remain subject to safeguards.

**macOS control** is opt-in and requires application authorization. Grant Accessibility and Screen Recording permissions when prompted; the agent can inspect windows and controls and use keyboard and mouse input in allowed apps. Availability depends on the operating system and target application.

## Project Collaboration and Safety

Conversations belonging to the same user can share collaboration records. A session with an explicit valid workspace can automatically join its project; unlinking opts the session out. An editing intention describes a file or directory and what you plan to change. Overlap is shown but never blocks editing. File reads and editor panels show relevant intentions and saved-change summaries, with text diffs available on demand. Managed saves check the version and reject stale writes; reread before reapplying a change. Sessions without a project do not send project collaboration tools to the model.

This is **cooperative coordination, not an operating-system file lock**. Bash no longer automatically claims the entire working directory, but shell commands, background processes, and external editors are not forcibly excluded from writing; version checks detect only some external changes. Records are isolated by user, not shared across accounts.

## Remote Access and Integrations

- **Remote access**: use a controlled network such as Tailscale to reach the Web UI. Check the listening address, authentication, and firewall rules first; do not expose the service directly to the public internet.
- **Notifications and channels**: configure Bark or ntfy in Settings for task events. WeChat and email integrations require separate configuration and authorization.
- **Extensions**: connect MCP servers in Settings or add custom tools under `.crabagent/tools/`. Configure tool and external-service permissions for your use case.

## Configuration and Commands

Environment variables use the `CRAB_` prefix and can be supplied through the environment or `.env`. Model providers and integrations can also be managed in Settings.

| Setting | Default | Purpose |
|---|---|---|
| `CRAB_SERVE_HOST` / `CRAB_SERVE_PORT` | `0.0.0.0` / `5210` | Web server listening address and port |
| `CRAB_DB_URL` | SQLite URL for `~/.crabagent/crabagent.db` | Database connection |
| `CRAB_MAX_ITERATIONS` / `CRAB_MAX_TOKENS` | `200` / `16384` | Agent iteration and response token limits |
| `CRAB_WEB_PROXY` | empty | Proxy for web search and scraping |

Use `/help` in the TUI to list commands. Common commands include `/model`, `/sessions`, `/new`, `/agents`, `/memory`, `/skills`, `/molt`, and `/todo`.

## Development

```bash
make install                  # build the frontend and install in editable mode
ruff check src/ tests/
pytest tests/

cd frontend && npm run build  # build the frontend
```

Key directories: `src/crabagent/core/` (agent and core services), `src/crabagent/serve/` (API), `frontend/` (web UI), and `src/crabagent/electron/` (desktop app).

## License

Non-commercial use is covered by AGPL-3.0; commercial use requires a separate license. See [LICENSE](LICENSE) for the full terms.
