Skip to main content
Glama
README.md
# Swallow-Anything / 新神·吞噬万物

> **Zero-LLM-Inside Universal Swallowing Workbench · 1-Call 0-Token Crystallizer · `<2.5 KB` Code-Mode MCP Bus**
>
> **零内置大模型 · 无枷锁吞噬工作台 · 一键 0-Token 永久结晶器 · `<2.5 KB` Code-Mode MCP 总线**

[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
[![Python 3.11+](https://img.shields.io/badge/Python-3.11%2B-blue.svg)](pyproject.toml)
[![Zero Dependencies](https://img.shields.io/badge/Dependencies-0%20(stdlib%20only)-brightgreen.svg)](pyproject.toml)
[![MCP 2025-06-18](https://img.shields.io/badge/MCP-2025--06--18-purple.svg)](runtime/code_mode_mcp.py)

[English](#english) | [简体中文](#简体中文)

---

## English

### Why Swallow-Anything?

Most agent tool frameworks fall into one of two traps:

1. **Tool-schema bloat**: Mounting dozens of servers dumps `200–700+` tool schemas (`50K–109K+` tokens) into every turn before the model even reads your prompt.
2. **LLM-inside-the-box caging**: Wrapping an internal mini-LLM (with bundled API keys and brittle prompt loops) inside a scraper/browser framework slows down smart external Agents (`Claude`, `Codex`, `Gemini`, `Cursor`, `Antigravity`) and repeats expensive reasoning on every single click.

**Swallow-Anything v2.0.0** takes the opposite stance — **Zero-LLM-Inside**:

- **Zero bundled LLMs, zero API keys, zero pip dependencies**: 100% pure Python 3.11+ standard library (`dependencies = []`, portable SSH/container kit is **`156.72 KB`** across `12` files). Your smart external Agent brings the brain; Swallow-Anything provides razor-sharp physical instruments and deterministic compilation.
- **Unshackled Swallowing Workbench (`SwallowWorkbench`)**: Inspect and probe live surfaces across Web (CDP / HAR / WebMCP / MAIN-world JS RPC), macOS (`osascript` JXA & AppleScript / `shortcuts` / `agent-desktop` AX), Android (`adb` / DeepLinks / device console), and Binary/Wire protocols (`OpenAPI`, `GraphQL`, `Protobuf`, `Parquet`, `SQLite`, `ASAR`, `Mach-O`, `APK`).
- **1-Call, 0-Token Crystallizer (`Crystallizer`)**: Explore once with your Agent, then crystallize the discovered API, MAIN-world RPC, macOS/Android semantic macro, or cross-surface workflow into a permanent **`causal-cap/1.0`** capability package. Every future call runs in **1 deterministic step at 0 LLM tokens** (real `POST`/`PUT` `DIRECT_WRITTEN` for non-monetary owner writes; HMAC two-phase `stage -> commit` for financial spend).
- **4-Way Output Emitter (`QuadEmitter`)**: Every crystallized or swallowed capability automatically emits:
  1. **Local JSON CLI** (`swallow <cap_id> <tool>` / `umcp <cap_id> <tool>`)
  2. **MCP `2025-06-18` Server** (`stdio` & Streamable HTTP)
  3. **Capability Card & Hand Projection** (Store-compatible JSON contract)
  4. **Concise `<2 KB` `SKILL.md`** (progressive disclosure for any Agent)
- **Constant `<2.5 KB` Code-Mode MCP Bus (`runtime/code_mode_mcp.py`)**: Exposes **exactly 4 meta-tools** (`search_capabilities`, `execute_workflow`, `workbench`, `crystallize`) — verified at **`2,426 B` compact / `2,626 B` full** (`< 4,096 B` hard budget) regardless of whether you mount 5 or 500 capabilities. Agents compose multi-capability parallel pipelines in a bounded Python sandbox (`umcp.parallel`, `umcp.call`, `umcp.read`) inside a single MCP round-trip.

### Architecture

```mermaid
flowchart LR
    Agent["External Smart Agent (Claude / Codex / Gemini / Cursor / Antigravity)"] -->|"MCP 2025-06-18 (4 tools, 2,426B) or JSON CLI"| Bus["Code-Mode MCP Bus & umcp/swallow CLI"]

    Bus --> WB["SwallowWorkbench (Zone A Physical Probe: CDP / HAR / JXA / AX / ADB / Wire)"]
    Bus --> CZ["Crystallizer (from_traffic / from_main_world_rpc / from_semantic_macro / from_workflow)"]
    Bus --> Triage["<0.1ms Triage + 5 Core Organs + Heavy Arsenal"]

    WB -->|"Observed Traffic / Macros"| CZ
    Triage --> IR["Canonical IR cap.manifest.json (causal-cap/1.0)"]
    CZ -->|"1-Call Compile"| IR

    IR --> Shell["QuintetRuntimeShell (C1 Coerce/Disambiguate · C2 Two-Zone Firewall · C3 Direct-Write / HMAC Financial Gate · C4 Precision Human-Gate · C5 L1 Drift Self-Heal)"]
    Shell --> Judge["8-Gate Adversarial Judge (incl. Gate 8 Live Mutation Integrity — rejects fake staged_preview stubs)"]

    Judge -->|"4-Way Emit"| Out1["1. JSON CLI (swallow / umcp)"]
    Judge -->|"4-Way Emit"| Out2["2. MCP 2025-06-18 (stdio / HTTP)"]
    Judge -->|"4-Way Emit"| Out3["3. Capability Card Projection"]
    Judge -->|"4-Way Emit"| Out4["4. <2 KB SKILL.md"]
```

### Evidence-Backed Comparison Matrix

All numbers below come directly from verified test runs, isolated benchmarks, and end-to-end execution receipts (no speculative estimates):

| Dimension | **Swallow-Anything v2.0.0** | **REA** (`morluto/rea`) | **OpenCLI** (`jackwener/OpenCLI`) | **Playwright-MCP** (`microsoft/playwright-mcp`) | **CLI-Anything** (`HKUDS/CLI-Anything`) |
|---|---|---|---|---|---|
| **Runtime Dependencies** | **0** (100% Python 3.11+ stdlib; portable kit `156.72 KB`, 12 files) | Node/TS heavy runtime (`1,047,462 B` static scan output) | Node/JS + Chrome MV3 extension (`174` sites / `1,225` commands) | Node + headless browser stack | Python CLI generation harness (`HARNESS.md` 7-step SOP) |
| **LLM Inside Runtime** | **0 (Zero-LLM-Inside)** — never cages external Agents | External MCP caller | 0 (hand-authored JS adapters) | External MCP caller (multi-turn per click) | Compile-time LLM generation, 0-token runtime |
| **MCP Context Budget** | **4 tools = `2,426 B` compact / `2,626 B` full** (`< 4 KB` constant) | `255` tools exposed | CLI-first (no native Code-Mode MCP bus) | Per-step AX browser tools (official README recommends CLI + `SKILL.md` to save tokens) | CLI-only (no MCP server or Code-Mode sandbox) |
| **Target Surfaces** | **All 10 species (`S1`–`S10`)**: CLI, OpenAPI/GraphQL, HAR, SPA/MAIN-world RPC, Wire/Protobuf/Parquet/SQLite, Electron ASAR, macOS `.app`/JXA/AX, Android ADB/APK, cross-surface workflows | Binary & Web static reverse engineering | Web sites (`PUBLIC -> COOKIE -> INTERCEPT -> UI`) | Web browser AX DOM | Local desktop software CLIs |
| **Compile & Audit Speed** | `<0.1 ms` direct triage; `0.026s–11.53s` cold swallow across `75/75` targets (`100% PASS`); portable isolated HTTP swallow `209.05 ms` / SQLite `252.20 ms` | `8,350.73 ms` on Test 1 static scan (`355x` slower than Rust `craft-anything`'s `23.51 ms`) | Instant pre-built adapter lookup; manual authoring for new sites | Multi-second browser navigation every turn | Offline multi-step generation per app |
| **Write Integrity & Firewall** | **Two-Zone Firewall (Zone A / Zone B)** + **Gate 8 Live Mutation Integrity** (statically & dynamically rejects fake `staged_preview` stubs) + **L1 Drift Self-Healing** | Read-only epistemic ledger (`observed/derived/inferred/unknown`) | POSIX exit codes + site adapters | Unbounded browser clicks | Real backend CLI invocations |
| **Verified Test Suite** | **`52/52` green** (`21/21` Core + `25/25` V2 Apex + `6/6` 8-Gate Judge self-test) + `9/9` Live E2E checks | Verified via isolated RE benchmark | Integrated as a weapon inside `SwallowWorkbench` & `organ_heavy_arsenal` | Referenced for AX tree patterns | Verified & swallowed directly in gauntlet |

### 60-Second Quickstart

#### 1. Install (Zero Dependencies)

```bash
git clone https://github.com/pjrpjr/swallow-anything.git
cd swallow-anything
pip install -e .
```

#### 2. Probe Your Local Workbench (0 LLM Tokens)

```bash
# Discover all available local instruments (CDP, HAR, JXA, Shortcuts, AX, ADB, Wire tools)
swallow workbench inventory --fast

# Parse a HAR traffic capture into clean, secret-stripped API endpoint templates
swallow workbench web_traffic_capture --har-path ./capture.har
```

#### 3. Crystallize a Live API into a Permanent 0-Token Capability

```bash
swallow crystallize from_traffic demo_posts --json '{
  "base_url": "https://jsonplaceholder.typicode.com",
  "endpoints": [
    {"method": "GET", "url": "https://jsonplaceholder.typicode.com/posts/1", "tool_name": "get_post", "description": "Fetch post 1"},
    {"method": "POST", "url": "https://jsonplaceholder.typicode.com/posts", "tool_name": "create_post", "description": "Create a post", "body_sample": {"title": "hello", "body": "world", "userId": 1}}
  ]
}'

# Invoke immediately via JSON CLI (1-step direct write, 0 LLM tokens)
swallow demo_posts get_post
swallow demo_posts create_post --title "crystallized" --body "zero tokens"

# Or compose parallel multi-capability pipelines in bounded Code Mode
swallow code "res = umcp.parallel([('demo_posts', 'get_post', {})]); result = {'count': len(res), 'ok': res[0]['ok']}"
```

#### 4. Connect the `<2.5 KB` Code-Mode MCP Bus to Any Agent

Start the MCP `2025-06-18` server over `stdio` or Streamable HTTP:

```bash
swallow serve-codemode --stdio
# or:
swallow serve-codemode --http 8765
```

Drop this into **Claude Desktop / Claude Code / Cursor / Antigravity / Codex** MCP config:

```json
{
  "mcpServers": {
    "swallow-anything": {
      "command": "swallow",
      "args": ["serve-codemode", "--stdio"],
      "env": {
        "PYTHONDONTWRITEBYTECODE": "1"
      }
    }
  }
}
```

#### 5. Run the Full Verification Suite & Security Scanner

```bash
python3 -B -m swallow_anything.security_scan .
python3 -B -m unittest tests/test_cap_ir_and_projector.py -v
python3 -B -m unittest tests/test_apex_v2.py -v
python3 -B tests/judge_audit_harness.py self-test
```

### Two-Zone Security Architecture & Responsible Use

Swallow-Anything enforces a strict architectural firewall between **personal owner automation** and **public/shared capability publishing**:

| Zone | Intended Use | PII Policy | Secrets / PAN / CVV | Write Policy | SSRF / LFI / Redlines |
|---|---|---|---|---|---|
| **Zone A (Owner-Private)** | Your own local machine, accounts, browser tabs, macOS apps, and personal devices | Owner PII (`email`, `phone`, `user_id`) preserved for your own workflows | **Always scrubbed** (`Bearer`, JWT, cookies, API keys, Luhn-valid card PANs, CVV) | 1-step `DIRECT_WRITTEN` for non-monetary writes; HMAC `stage -> commit` + budget caps + `HUMAN_GATE_REQUIRED` for financial spend | Personal devices & local tools allowed strictly for owner |
| **Zone B (Public-Safe)** | Shared / published read-only capabilities | **All PII scrubbed** | **Always scrubbed** | **Live mutations hard-blocked** (`allow_live_mutations=False`, `$0` enforced) | Strict DNS/IP anti-SSRF/LFI (`127.0.0.0/8`, RFC1918, `169.254.169.254`, CGNAT, `.local`/`.internal`/`.nip.io`/`.sslip.io`); **hard Charter Redline** blocks promoting `main_world_rpc`, `semantic_macro_local`, `mac_jxa`, `phone_control`, OTP relays, or personal browser sessions (`REDLINE_REJECTED`) |

**Responsible Use Charter**:
- **Zero Root CA MITM**: Never installs system root certificates to intercept TLS.
- **Zero Live Process Injection**: Never attaches Frida/LLDB to live applications.
- **Zero Credential Harvesting**: Never reads OS Keychains or browser `Login Data` password databases.
- **Zero Anti-Bot / CAPTCHA Bypass**: Genuine Cloudflare/Turnstile/reCAPTCHA/2FA challenges escalate cleanly to `HUMAN_GATE_REQUIRED` for human takeover.
- **Gate 8 Live Mutation Integrity**: Both static AST analysis and dynamic isolated execution reject deceptive drivers that return fake `staged_preview` responses when real commits are requested.

---

## 简体中文

### 为什么需要「新神·吞噬万物(Swallow-Anything)」?

现有 Agent 工具生态普遍陷入两大陷阱:

1. **工具 Schema 爆炸**:每挂载一批 MCP 服务就往上下文塞入 `200–700+` 个工具定义(瞬烧 `50K–109K+` tokens),还没开始干活上下文先被挤爆。
2. **盒内小模型套娃**:在爬虫或自动化框架内部再绑死一个小模型和 API Key,不仅拖慢外部强模型(`Claude`、`Codex`、`Gemini`、`Cursor`、`Antigravity`),还导致每次重复点击都在白烧推理 Token。

**Swallow-Anything v2.0.0(新神·吞噬万物)** 坚持 **Zero-LLM-Inside(零内置大模型)** 哲学:

- **零内置大模型、零 API Key、零第三方依赖**:100% 纯 Python 3.11+ 标准库(`dependencies = []`,SSH/Docker 便携包仅 **`156.72 KB`** / `12` 个文件)。外部强 Agent 负责思考与探索,Swallow-Anything 负责锋利的物理探针与确定性编译。
- **无枷锁吞噬工作台(`SwallowWorkbench`)**:直接统一调度 Web(Chrome CDP / HAR 流量采集 / WebMCP 检测 / 主世界 JS RPC)、macOS(`osascript` JXA & AppleScript / `shortcuts` / `agent-desktop` AX)、Android(`adb` / DeepLink / 设备控制)及二进制协议(OpenAPI / GraphQL / Protobuf / Parquet / SQLite / ASAR / Mach-O / APK)。
- **一键 0-Token 永久结晶器(`Crystallizer`)**:外部 Agent 探索一次,即可将真实流量(`from_traffic`)、主世界 RPC(`from_main_world_rpc`)、桌面/手机语义宏(`from_semantic_macro`)或跨表面编排流(`from_workflow`)一键编译为永久 `causal-cap/1.0` 能力包。之后每次调用均以 **1 步确定性执行、0 推理 Token** 完成(本人非金钱写操作 1 步 `DIRECT_WRITTEN` 直写;金钱动作强制 HMAC 双阶 `stage -> commit` 与预算门禁)。
- **四态自动产出(`QuadEmitter`)**:每次吞噬或结晶自动同步产出 ① 本机 JSON CLI(`swallow` / `umcp`)、② 标准 `MCP 2025-06-18` 服务、③ 能力卡投影、④ `<2 KB` 精简 `SKILL.md`。
- **恒定 `<2.5 KB` Code-Mode MCP 总线**:无论底层挂载 5 个还是 500 个能力,对外永远只暴露 **`4` 个元工具**(`search_capabilities`、`execute_workflow`、`workbench`、`crystallize`),实测 **`2,426 B` 紧凑 / `2,626 B` 完整**(严守 `< 4,096 B` 红线);支持 Agent 在受限 Python 沙箱内一次往返并发编排多能力流水线(`umcp.parallel`)。

### 60 秒上手

```bash
# 1. 零依赖安装
git clone https://github.com/pjrpjr/swallow-anything.git
cd swallow-anything
pip install -e .

# 2. 查看本机可用物理武器库(0 LLM Token)
swallow workbench inventory --fast

# 3. 将接口一键结晶为永久 0-Token 能力并直接调用
swallow crystallize from_traffic demo_posts --json '{
  "base_url": "https://jsonplaceholder.typicode.com",
  "endpoints": [
    {"method": "GET", "url": "https://jsonplaceholder.typicode.com/posts/1", "tool_name": "get_post", "description": "获取文章 1"},
    {"method": "POST", "url": "https://jsonplaceholder.typicode.com/posts", "tool_name": "create_post", "description": "发布文章", "body_sample": {"title": "hello", "body": "world", "userId": 1}}
  ]
}'
swallow demo_posts get_post
swallow demo_posts create_post --title "新神结晶" --body "零Token直写"

# 4. 启动 <2.5 KB Code-Mode MCP 服务(支持 stdio / Streamable HTTP)
swallow serve-codemode --stdio
```

### 双区安全防火墙与合规宪章

- **Zone A(本人私域)**:保留本人账号业务字段(邮箱/手机号/用户 ID),同时**全量脱敏一切凭据、Bearer、JWT、Cookie、Luhn 银行卡号与 CVV**;非金钱写 1 步 `DIRECT_WRITTEN`,金钱动作强制 HMAC 双阶确认与单次/单日预算红线。
- **Zone B(公开发布区)**:强制全量 PII + 密钥脱敏、严格 DNS/IP 反 SSRF/LFI、强制 `allow_live_mutations=False`;**宪章红线硬拦截**所有个人桌面宏、手机控制、主世界浏览器 RPC、接码/OTP 与个人登录态向外公开发布(`REDLINE_REJECTED`)。
- **Gate 8 真实写完整性裁判**:静态 AST + 动态隔离双校验,严厉打假只返回 `staged_preview` 的假写驱动,确保每一条实写能力名副其实。
- **工程红线**:零系统 Root CA MITM、零 Frida/LLDB 活体注入、零 Keychain / Chrome `Login Data` 凭据窃取、零绕过 CAPTCHA/2FA(真实风控挑战精准上抛 `HUMAN_GATE_REQUIRED` 交由人工接管)。

---

## License

Released under the [MIT License](LICENSE).