Skip to main content
Glama
README.md
# deepseek-worker (v2.0)

MCP Server chạy qua `stdio` giúp phối hợp an toàn giữa **Claude Code**, **Google Antigravity** và **DeepSeek API** (`deepseek-flash`, 1M context) trên nhiều **Git Worktree** — giữ gọn ngữ cảnh gói cá nhân, đồng bộ trạng thái xuyên nhánh không xung đột và tuân thủ nghiêm ngặt Điều khoản dịch vụ (ToS).

## Tại sao cần `deepseek-worker`?

Khi kết hợp nhiều AI coding agent trên cùng một dự án, bạn thường gặp 3 vấn đề:
1. **Lệch trạng thái giữa các Git Worktree:** File `HANDOFF.md` nằm trong nhánh Git bị cũ khi hai agent code song song ở hai nhánh khác nhau.
2. **Tốn ngược hạn mức (quota) gói cá nhân:** Nếu một tool MCP chỉ trả về hàng trăm dòng code/log dưới dạng văn bản, agent chính vẫn phải nuốt hết vào ngữ cảnh của mình.
3. **Rủi ro khóa tài khoản Pro:** Tự động bọc vòng lặp CLI gói cá nhân (`agy -p`, `claude -p`) hoặc chia sẻ OAuth token vi phạm ToS.

`deepseek-worker` giải quyết cả 3 vấn đề bằng thiết kế **Path-based I/O + Shared Board trong `.git/multi-agent/` + Human-in-the-loop**.

## Kiến trúc tổng thể

```mermaid
flowchart TD
    User["Người dùng (Giao việc, chuyển ca & duyệt Merge)"]

    subgraph Worktrees["Git Worktrees tách biệt"]
        Main["main (Chốt Contract & Bản ổn định)"]
        Arch["Worktree Claude Code (Kiến trúc & Backend)"]
        UI["Worktree Antigravity (UI & Browser Use)"]
    end

    subgraph SharedGit["Thư mục Git dùng chung (.git/multi-agent/)"]
        Board["board.json + HANDOFF.live.md (Khóa board.lock + rev)"]
    end

    subgraph MCP["MCP Server: deepseek-worker"]
        Analyze["deepseek_analyze_files (Đọc log/file từ đĩa -> tóm tắt <= 30 dòng)"]
        Generate["deepseek_generate_to_file (Ghi test/mock thẳng xuống đĩa)"]
        Sync["read_board / post_handoff"]
    end

    DS["DeepSeek API (deepseek-flash 1M)"]

    User --> Arch
    User --> UI
    Arch --> Main
    Main --> UI
    Arch --> MCP
    UI --> MCP
    Sync <--> Board
    Analyze --> DS
    Generate --> DS
    Generate --> Worktrees
```

## 4 MCP Tools cung cấp

| Tool | Mục đích | Điểm an toàn / tối ưu |
| :--- | :--- | :--- |
| `deepseek_analyze_files` | Đọc trực tiếp file/log lớn (>300 dòng) từ đĩa và hỏi `deepseek-flash` | Trả về tóm tắt **tối đa 30 dòng**; chặn `.env`, `.credentials.json`, khóa SSH/PEM, `.git/`. |
| `deepseek_generate_to_file` | Đọc file tham chiếu, gọi `deepseek-flash` sinh unit test / mock data / boilerplate | Ghi thẳng xuống đĩa trong biên `worktree_root` (chặn `..` và symlink thoát biên), bóc vỏ code fence, **không đẩy code thô về ngữ cảnh chính**. |
| `read_board` | Đọc bảng tin bàn giao mới nhất từ `<git-common-dir>/multi-agent/board.json` | Dùng chung tức thời giữa mọi Git Worktree của cùng dự án, tốn \$0 API. |
| `post_handoff` | Ghi trạng thái bàn giao (`changed_files`, `contracts_changed`, `next_tasks`, `blockers`) | Khóa file độc quyền `board.lock` + kiểm tra phiên bản lạc quan `rev` (`REV_CONFLICT`), tự xuất `HANDOFF.live.md`. |

## Cài đặt nhanh trong 3 bước

Yêu cầu: **Node.js >= 22**, **Git**, và API key từ [DeepSeek Platform](https://platform.deepseek.com).

### Bước 1: Clone & cài đặt phụ thuộc

```bash
git clone https://github.com/nguyentronghieutl2k6-art/deepseek-worker.git
cd deepseek-worker
npm install
npm test
```

### Bước 2: Chạy trình cài đặt không phá hủy

Xem trước các thay đổi (mặc định `--dry-run`, không ghi đĩa):

```bash
node scripts/install-customizations.js --dry-run
```

Áp dụng cài đặt (chép skill/lệnh `/handoff` cho Antigravity & Claude Code và gộp `deepseek-worker` vào `~/.gemini/config/mcp_config.json` mà giữ nguyên mọi MCP server và khóa sẵn có):

```bash
node scripts/install-customizations.js --apply
```

Sau đó:
1. Mở `~/.gemini/config/mcp_config.json`, thay `YOUR_DEEPSEEK_API_KEY` bằng khóa DeepSeek thật của bạn (`chmod 600 ~/.gemini/config/mcp_config.json`).
2. Đăng ký cho Claude Code bằng lệnh mà trình cài đặt in ra (thay đường dẫn và khóa thật của bạn):
   ```bash
   claude mcp add-json --scope user deepseek-worker '{"command":"node","args":["/path/to/deepseek-worker/src/index.js"],"env":{"DEEPSEEK_API_KEY":"YOUR_DEEPSEEK_API_KEY","DEEPSEEK_MODEL":"deepseek-flash"}}'
   ```

### Bước 3: Gắn quy tắc vào dự án của bạn

Sao chép (hoặc nối vào cuối file sẵn có) các mẫu trong `templates/`:
- `templates/AGENTS.multi-agent.md` → `AGENTS.md`
- `templates/CLAUDE.multi-agent.md` → `CLAUDE.md` *(nếu `CLAUDE.md` đã chứa `@AGENTS.md` thì chỉ cần nối vào `AGENTS.md`)*

## Cách dùng hằng ngày (đơn giản, không cần nhớ đường dẫn)

- Mở dự án ở chế độ **Worktree** trên **Claude Desktop (tab Code)** và **Antigravity**.
- Khi làm xong một chặng ở Claude → gõ `/handoff` (Claude tự test → commit nhánh → ghi bảng tin bàn giao).
- Sang Antigravity → nhắn *"Đọc board làm tiếp"* → xong việc nhắn *"handoff"*.
- Khi gặp log lỗi dài hoặc cần viết nhiều test → nhắn *"Nhờ DeepSeek đọc file lỗi này"* hoặc *"Nhờ DeepSeek viết unit test cho file này"*.

## Nguyên tắc An toàn & Bảo mật

- **Không bọc CLI gói cá nhân:** Không tự động chạy `agy -p` hay `claude -p`.
- **Không đụng chạm OAuth / Bí mật:** Sandbox tự động chặn đọc/ghi `.env` (cho phép `.env.example`, `.env.sample`, `.env.template`), `.credentials.json`, `*.pem`, `*.key`, `id_rsa`, `id_ed25519`, `.git/*`, cũng như chặn ghi ra ngoài `worktree_root` kể cả qua symlink treo.
- **Kiểm thử tự động:** `npm test` (27 bài kiểm thử gồm Git Worktree thật, symlink, sandbox, API engine, giao thức MCP qua `InMemoryTransport` + `StdioClientTransport` và trình cài đặt).

## Giấy phép

[MIT](./LICENSE)

TDQS

A3.6/5.0

Scored across 4 tools

Disambiguation4/5

The two DeepSeek tools overlap in that both read files, but their outputs differ clearly: one returns a capped summary, the other generates artifacts to a file. read_board and post_handoff are cleanly separated into read and write operations on the same resource.

Naming Consistency3/5

All names use snake_case and mostly follow verb_noun structure, but the prefix convention is inconsistent: two tools use deepseek_ while the board tools do not. This is readable but not fully predictable.

Tool Count5/5

Four tools is well-scoped for a focused worker that analyzes files, generates outputs, and participates in a handoff board. Each tool has a clear role with no redundant surface area.

Completeness4/5

The surface covers analysis, generation, and reading/writing the handoff board, which are the core workflows. Minor gaps exist around board lifecycle operations such as listing or clearing handoffs, but agents can work around them.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues