Skip to main content
Glama
README.md
# あ · AhGemiSmooth (`ags`)

> **A layered MCP router for Antigravity / Gemini and any MCP host.**
> Hot/Cold tool tiers with a frozen `tools/list`, a lazy downstream pool, an observable cross-group `tool_chain`, and built-in batch I/O tools. Plain standard MCP, no custom agent required. MIT licensed.

AhGemiSmooth 是一个跑在本机的外置 MCP 路由网关。宿主(Antigravity、Gemini CLI 或其他 MCP 客户端)只挂载它一个 MCP Server,它在背后管理你所有的下游 MCP,并对外只暴露一组小而稳定的顶层工具。

- npm 包名:`ah-gemi-smooth`
- CLI:`ags`(别名 `ah-gemi-smooth`)
- MCP ServerName:`ah-gemi-smooth`
- 运行环境:Node.js ≥ 20;Windows 优先打磨,macOS / Linux 同样可用(`wsl-bridge` 仅 Windows)
- 交互图鉴:[`docs/index.html`](docs/index.html)(浏览器直接打开)

---

## 解决什么问题

直接在宿主里挂 6 个 MCP,会出现这些情况(以下数字来自一台典型的 6 下游工作台,作为示例):

| 指标 | 直挂 6 个 MCP | 经 AhGemiSmooth |
| :--- | :--- | :--- |
| 每轮上下文里的顶层工具 | 324 个 | 12 个,会话内 `tools/list` 字节级不变 |
| 查一个 229 工具大组的参数 | 先冷启动该进程(约 3.7 s)或读大 JSON | `hub_help` 读磁盘目录缓存,约 9 ms,不唤醒进程 |
| 跨目录多路搜索 | 多次冷启 shell,每次 1–2 s | 一次 `batch_search` 并发返回 |
| 改多个文件 + 构建 + 测试 | 至少 3 轮模型往返 | 一次 `tool_chain`,拿到逐步回执 |
| 冷门 MCP 进程 | 随 IDE 常驻 | 首次调用才启动,空闲 600 s 回收 |

## 核心能力

**Hot/Cold 双层路由。** 当前 Profile 里的热组工具直接出现在 `tools/list` 中;其余下游折叠到三个元工具后面:`hub_help`(查目录与 Schema)、`hub_read`(只读调用)、`hub_exec`(有副作用的调用)。`tools/list` 在启动时计算一次,之后不发 `list_changed`,冷组唤醒或缓存刷新都不改变它,宿主的 Prompt Cache 不会因此失效。

**磁盘目录缓存。** 每个下游的工具目录落盘到 `~/.ah-gemi-smooth/catalog-cache/`,按下游配置签名自动失效。`hub_help {query}` 跨所有已缓存目录检索,不启动任何进程。

**Lazy Spawn + Idle GC + 熔断。** stdio 下游默认在第一次调用时才启动,空闲超时后整树结束(Windows 上用 `taskkill /T /F`)。30 s 内异常退出 3 次即熔断 60 s,之后半开重试。

**可观测的 `tool_chain` + `chain_job`。** 最多 8 步跨组串行调用,可混排内置工具、热工具和 `"<group>:<tool>"` 冷工具。所有步骤在执行前先过策略检查。每步回执带结构化判据 `judged`,优先级为 `exception > mcp-isError > exit-code > error-prefix > ok`。失败默认 `halt`,**不做自动回滚**:引擎负责给出账本,补偿由智能体决定。`background: true` 返回 `chain_id`,用 `chain_job` 查状态或中止。

**内置 `fast-io` 工具组(默认热)。**

- `batch_search`:一次 1–20 条 `text` / `regex` / `glob` / 只读 `git` 查询并发执行。找到 `rg` 时用 ripgrep,否则用内置 Node 扫描器。多段输出超限时,按 max-min 注水分配预算,后面的查询不会被前面的大结果饿死。
- `quick_outline`:一次抽取最多 30 个文件的符号和行号(TS/JS、Python、GDScript、Go、Rust、C#、Markdown、JSON)。
- `apply_edits`:多文件 `oldText`/`newText` 精确替换或新建,默认全部预检通过才写入,可选写后 `verify` 命令。
- `run_checks`:最多 8 条命令并发,`pwsh` / `cmd` / `wsl` 可混跑,超时杀整个进程树,PowerShell 输出强制纯文本无 ANSI。

**内置 `wsl-bridge` 工具组(默认冷,仅 Windows)。** `wsl_exec` 在 WSL 中执行 bash,Windows 路径自动转换为 `/mnt/<drive>/...`;`wsl_read_info` 提供只读的 `git_status` / `git_diff_stat` / `git_log` / `ls` / `read_slice`,用户数据始终作为单个 argv 传递,不拼 shell 字符串。

**默认拒绝的读写分类。** 判定顺序:`deny_tools` > `exec_tools` > `read_tools` > 下游 `readOnlyHint` > 默认按写处理。`hub_read` 只放行判为只读的工具,可以放心加入宿主的免审批白名单。

**输出守卫与脱敏。** 超长输出按 UTF-16 代理对安全的位置截断,全文落盘到 spool 目录并附绝对路径。路由器自身打印的日志和错误信息会屏蔽密钥、URL 查询串和认证头。

## 1 倍原价友好

AhGemiSmooth 只用三样东西:标准 MCP、一份 `AGENTS.md` 规则文件、宿主的默认 Agent。它**不注入、也不要求创建任何自定义 Agent**。部分宿主对自定义 Agent 按更高倍率计费,这套用法只走默认 Agent 的 1 倍计费。

## 架构

```text
 MCP Host (Antigravity / Gemini CLI / ...)   ← 只挂载一个 MCP Server:ah-gemi-smooth
        │  stdio, tools/list frozen per session
        ▼
 ┌────────────────────── AhGemiSmooth (ags) ──────────────────────┐
 │ Hot tier (top-level)                                           │
 │   core-chain : tool_chain, chain_job                           │
 │   fast-io    : batch_search, quick_outline, apply_edits,       │
 │                run_checks                                      │
 │   profile hot_groups / hot_tools  (e.g. cu__windows ...)       │
 │ Meta: hub_help · hub_read [R] · hub_exec [W]                   │
 ├────────────────────────────────────────────────────────────────┤
 │ Policy: deny > exec > read > readOnlyHint > write (default)    │
 │ Catalog cache (disk) · Output guard + spool · Redactor         │
 ├────────────────────────────────────────────────────────────────┤
 │ Downstream pool                                                │
 │   stdio  : lazy spawn, idle GC, circuit breaker, tree kill     │
 │   http   : streamable-http / sse, loopback bypasses proxies,   │
 │            stale session dropped and reconnected on next call  │
 └───────┬───────────┬───────────┬───────────┬────────────────────┘
         ▼           ▼           ▼           ▼
     MCP (http)  MCP (stdio)  MCP (stdio)  wsl-bridge (internal, cold)
```

## 30 秒上手

```bash
# 1. 获取并构建
git clone https://github.com/johnx438-hub/AhGemiSmooth.git
cd AhGemiSmooth
npm install && npm run build
npm link                      # 可选:把 ags 放到 PATH;否则用 node dist/src/index.js 代替 ags

# 2. 从宿主现有的 mcp_config.json 生成下游配置(默认读 ~/.gemini/config/mcp_config.json,只读)
ags import-mcp --dry-run      # 预览,密钥打码,不写文件
ags import-mcp                # 写到 ~/.ah-gemi-smooth/downstream.imported.json

# 3. 建立配置:复制模板,把导入结果里的 "downstream" 合并进去,密钥移到 config.local.json
#    ~/.ah-gemi-smooth/config.json        ← templates/config.example.json
#    ~/.ah-gemi-smooth/config.local.json  ← 只放 token / key

# 4. 体检并预热目录缓存
ags doctor                    # 只读体检,不启动 stdio 进程
ags doctor --wake-all         # 逐个实连下游,写入并校验 catalog-cache
```

5. 在宿主的 `mcp_config.json` 里只保留 AhGemiSmooth(原来的下游条目移走,否则会重复挂载):

```json
{
  "mcpServers": {
    "ah-gemi-smooth": {
      "command": "node",
      "args": ["<repo-root>/dist/src/index.js", "serve"]
    }
  }
}
```

Windows 下 JSON 里的路径写成 `"C:\\path\\to\\AhGemiSmooth\\dist\\src\\index.js"` 或 `"C:/path/to/AhGemiSmooth/dist/src/index.js"`。

6. 把 [`templates/AGENTS.md`](templates/AGENTS.md) 复制到项目根目录(或宿主的全局规则文件),新会话即可按路由表自动选工具。

切换前请先读 [`docs/MIGRATION.md`](docs/MIGRATION.md):其中有备份与回滚命令,以及 `read_tools` 的安全红线。

## 命令行

```text
ags [serve]                          启动 MCP stdio 网关(默认)
ags doctor [--offline] [--config <path>] [--wake <group>]... [--wake-all]
ags import-mcp [--from <path>] [--dry-run] [--out <file>] [--force]
ags help | --help | --version
```

| 环境变量 | 作用 | 默认 |
| :--- | :--- | :--- |
| `AGS_HOME` | 状态目录(`catalog-cache/`、`spool/`) | `~/.ah-gemi-smooth` |
| `AGS_CONFIG` | 主配置文件 | `$AGS_HOME/config.json` |
| `AGS_LOG` | `debug` / `info` / `warn` / `error` / `silent`,只写 stderr | `info` |
| `AGS_RG` | ripgrep 可执行文件的显式路径 | PATH 上的 `rg` |

## 开发

```bash
npm install
npm run build
npm test        # 156 个用例,37 个套件;测试进程会清除代理环境变量,HTTP 只连 127.0.0.1
```

测试锁定了四条工程不变量:内置工具覆盖与重名检查、`hub_read` 默认拒绝、`tools/list` 会话内字节级不变、截断不拆 UTF-16 代理对。

## Non-Goals

- 不是 Agent,也不是宿主:不做规划,不改写模型的意图。
- `tool_chain` 没有步骤间数据流和条件分支,也不会自动回滚;需要判断的流程请拆成多轮。
- 会话中途不热更新 `tools/list`:改 Profile 或配置后,新开会话才生效。
- 不是沙箱:`hub_exec` 和热层写工具的安全性依赖宿主的审批机制与你的 `deny_tools` 配置。
- 只提供本机 stdio 入口,不对网络暴露服务。
- 不创建、不注入自定义 Agent。

## 文档

- [`docs/GUIDE.md`](docs/GUIDE.md):完整使用指南(配置字段、Profile、工具详解、实战范式、`AGENTS.md`、自定义工具组、ripgrep)
- [`docs/MIGRATION.md`](docs/MIGRATION.md):MCP 迁移注意事项与安全避坑清单
- [`docs/index.html`](docs/index.html):《デザインあ》风格交互图鉴
- [`templates/config.example.json`](templates/config.example.json)、[`templates/AGENTS.md`](templates/AGENTS.md):可直接套用的模板

## License

[MIT](LICENSE) © 2026 AhGemiSmooth Contributors

TDQS

A3.9/5.0

Scored across 9 tools

Disambiguation4/5

Most tools have sharply distinct purposes: quick_outline for structure, batch_search for searching, apply_edits for writes, run_checks for commands. The main fuzziness is between run_checks and tool_chain (which can dispatch tool calls including shell-ish steps), and the hub_read/hub_exec pair, though the read/write split is explicitly documented.

Naming Consistency3/5

A readable hub_* family exists, but the rest mix noun-first (quick_outline, tool_chain, chain_job, batch_search) with verb-first (apply_edits, run_checks) conventions. The names are meaningful but do not follow a single predictable verb_noun pattern.

Tool Count5/5

Nine tools is well within a healthy range, and the cold-group hub (hub_help/hub_read/hub_exec) lets breadth be folded away rather than bloating tools/list. Each tool covers a genuinely different capability: outline, search, edit, execute, orchestrate, inspect chains, and reach cold groups.

Completeness4/5

Core code-workflow lifecycle is covered: inspect structure, search, edit/create files, run commands, chain operations, and monitor/kill chains. The notable gap is direct file reading and directory listing, which are delegated to cold groups via hub_help + hub_read, adding an extra discovery step for common read operations.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues