Skip to main content
Glama

SmartCLI

SmartCLI 是一个为了深入学习和探索 AI Agent 核心机制而开发的终端智能编程助手,面向真实项目开发场景,支持读写文件、搜索代码、执行命令、联网检索、调用 MCP 工具、保存记忆、生成快照与恢复现场,并通过 Runtime API 对外提供线程、turn、事件和后台任务能力。

项目定位

项目围绕 ReAct 推理、任务规划、Multi-Agent 协作、MCP 工具扩展、Memory、RAG 与安全执行等能力展开,旨在通过完整的工程实践理解 AI Agent 从模型调用到自主任务执行的核心链路。

SmartCLI 终端运行效果

它不是一个空壳 Demo:核心路径有自动化测试覆盖,也经过本地 smoke 和真实终端运行验证。

Related MCP server: mcp-server

功能特性

  • 交互式终端 Agent,基于 Rich 和 prompt-toolkit 渲染

  • 单次 prompt 模式,适合脚本、管道和自动化调用

  • OpenAI-compatible 流式 LLM 客户端,默认面向 DeepSeek 配置

  • 支持 DEEPSEEK_API_KEY 等 provider-specific API Key

  • ReAct 工具调用循环,支持 thinking、tool call、tool result、final output 和 usage 事件

  • Plan-and-Execute 模式,使用独立 Planner 生成 DAG,并按依赖批次执行可并行任务

  • Multi-Agent 协作模式,包含 Planner、Worker、Reviewer、依赖调度、并行 worker 和 review 重试

  • 内置文件、Shell、grep、glob、记忆、网页搜索、网页抓取、代码搜索等工具

  • HITL 人工确认、命令/路径安全策略和 JSONL 审计日志

  • MCP client,支持 stdio 和 Streamable HTTP MCP server

  • Skill 系统,支持内置、用户级和项目级 skill,支持启用/禁用和 load_skill 懒加载注入

  • Chrome DevTools MCP 配置助手

  • SmartCLI 自身也可以作为 MCP server 暴露内置工具

  • Runtime API,支持线程、turn、事件日志和持久化后台任务

  • SQLite 长期记忆和本地代码索引

  • Agent run 前后自动创建快照,支持恢复现场

  • 支持本地图片和远程图片输入,并根据模型能力自动降级

环境要求

  • Python 3.11 或更新版本

  • uv

  • 可选:rg,用于更快的本地搜索

  • 可选:Chrome DevTools MCP 需要 Node.js 20.19.0 LTS 或更新版本、npm/npx 和 Chrome

快速开始

git clone https://github.com/jiahuiwu944-hash/SmartCLI.git
cd SmartCLI
uv sync --extra dev
uv run smartcli --help

启动交互模式:

uv run smartcli

单次查询:

uv run smartcli -p "帮我总结这个项目"

检查当前环境:

uv run smartcli doctor --cwd .

配置

SmartCLI 的配置优先级如下:

  1. 内置默认配置

  2. ~/.paicli/config.json

  3. 项目级 .paicli/config.json

  4. 项目级 .env

  5. CLI 参数

  6. 当前进程环境变量

可以像 Java 项目一样,把 DeepSeek Key 写到项目 .env 里:

PAICLI_PROVIDER=deepseek
PAICLI_MODEL=deepseek-v4-flash
DEEPSEEK_API_KEY=your_key_here

也可以使用兼容的 PAICLI_API_KEY

PAICLI_PROVIDER=deepseek
PAICLI_MODEL=deepseek-v4-flash
PAICLI_API_KEY=your_key_here

当前支持的 provider-specific API Key 包括:

  • DEEPSEEK_API_KEY

  • GLM_API_KEY

  • STEP_API_KEY

  • KIMI_API_KEY

通过命令行临时覆盖 provider 和 model:

uv run smartcli --provider deepseek --model deepseek-v4-flash

连接本地 OpenAI-compatible 服务:

PAICLI_PROVIDER=openai-compatible \
PAICLI_BASE_URL=http://127.0.0.1:11434/v1 \
PAICLI_MODEL=qwen2.5-coder \
uv run smartcli -p "解释这个仓库"

交互命令

进入 uv run smartcli 后,可以使用这些 slash commands:

/help
/exit
/clear
/context
/memory
/memory search <query>
/memory clear
/save <fact>
/config
/tools
/hitl on|off|always|auto|never
/policy
/audit [N]
/index [path]
/search <query>
/plan <task>
/team <task>
/model
/skill
/skill list
/skill show <name>
/skill on <name>
/skill off <name>
/skill reload
/mcp
/task
/task add <task>
/task cancel <task_id>
/task log <task_id>
/snapshot
/snapshot clean
/restore <snapshot-id-or-index>

内置工具

SmartCLI 内置了一组 Agent 可以调用的本地工具和联网工具:

  • read_file

  • write_file

  • list_dir

  • glob / glob_files

  • grep / grep_code

  • bash / execute_command

  • web_search

  • web_fetch

  • save_memory

  • load_skill

  • search_code

  • revert_turn

写文件、执行命令、远程 MCP 写操作、恢复快照等危险动作,会经过 policy、HITL 和 audit 处理。

联网工具

web_search 使用 DuckDuckGo HTML 搜索,返回标题、URL 和摘要。

web_fetch 可以抓取公开 HTTP/HTTPS 页面,并做基础正文提取。它会拒绝 file://、loopback、私有网络和内网地址,降低 SSRF 风险。

如果需要登录态、浏览器状态或 JS 渲染页面,建议使用 Chrome DevTools MCP。

MCP

SmartCLI 可以连接 MCP server,并把远端工具动态注册为:

mcp__<server-name>__<tool-name>

初始化项目级 Chrome DevTools MCP 配置:

uv run smartcli mcp init-chrome --scope project

它会写入 .paicli/mcp.json,内容类似:

{
  "mcpServers": {
    "chrome-devtools": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "chrome-devtools-mcp@latest",
        "--no-usage-statistics"
      ]
    }
  }
}

连接已有 remote-debugging Chrome:

uv run smartcli mcp init-chrome \
  --scope project \
  --browser-url http://127.0.0.1:9222

查看已配置的 MCP server:

uv run smartcli mcp list

把 SmartCLI 自身作为 MCP server 暴露:

uv run smartcli mcp serve --transport stdio
uv run smartcli mcp serve --transport http --port 3000

HTTP smoke:

curl -sS -X POST http://127.0.0.1:3000 \
  -H 'content-type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'

Chrome DevTools MCP 会把浏览器页面和 DevTools 状态暴露给 Agent。不要随意把包含个人账号、敏感数据或生产后台的 Chrome 会话授权给 Agent。

Runtime API

SmartCLI 内置轻量 Runtime API,适合外部系统接入线程、turn、事件和后台任务。

启动服务:

PAICLI_RUNTIME_API_KEY=dev-key \
uv run smartcli serve --http --port 8080

创建线程:

curl -sS -X POST http://127.0.0.1:8080/v1/threads \
  -H 'x-api-key: dev-key'

发送 turn:

curl -sS -X POST http://127.0.0.1:8080/v1/threads/<thread_id>/turns \
  -H 'content-type: application/json' \
  -H 'x-api-key: dev-key' \
  -d '{"message":"总结这个项目"}'

读取事件:

curl -sS http://127.0.0.1:8080/v1/threads/<thread_id>/events \
  -H 'x-api-key: dev-key'

创建并查看后台任务:

curl -sS -X POST http://127.0.0.1:8080/v1/tasks \
  -H 'content-type: application/json' \
  -H 'x-api-key: dev-key' \
  -d '{"message":"后台总结这个仓库"}'

curl -sS http://127.0.0.1:8080/v1/tasks \
  -H 'x-api-key: dev-key'

图片输入

SmartCLI 支持在 prompt 里引用图片:

分析这张截图 @image:./screenshots/page.png

也支持绝对路径和远程图片:

解释这张图 @image:/Users/me/Desktop/diagram.png
看看这个图片 @image:https://example.com/image.png

本地图片会自动压缩、缩放,并在需要时把透明底铺成白底,再转为 data URL。如果当前 provider/model 不支持多模态输入,SmartCLI 会自动降级为文本元信息,不会把不支持的图片 payload 发给模型。

快照

每次 Agent run 都会尽力创建项目快照:

  • pre-turn

  • post-turn

快照保存在 ~/.paicli/snapshots/,不会写入项目 .git

REPL 中可以使用:

/snapshot
/restore 1
/snapshot clean

SDK

from paicli.sdk import create_default_engine

engine = create_default_engine(cwd=".")
result = engine.ask_complete("解释这个项目")
print(result.text)

plan_result = engine.plan_complete("先读取 README,再总结项目结构")
team_result = engine.team_complete("让多个 Agent 并行检查核心模块")

开发

安装开发依赖:

uv sync --extra dev

运行检查:

uv run python -m ruff check .
uv run python -m ruff format --check .
uv run python -m pytest
uv build

常用 smoke:

uv run smartcli --version
uv run smartcli --help
uv run smartcli doctor --cwd .
uv run smartcli --plain -p hello

License

MIT. See LICENSE.

A
license - permissive license
-
quality - not tested
C
maintenance

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

View all related MCP servers

Related MCP Connectors

  • MCP server exposing the Backtest360 engine API as tools for AI agents.

  • Agent-native MCP server over the public saagarpatel.dev corpus. Read-only, stateless.

  • Personal assistant MCP server with search, execute, packages, jobs, secrets, and integrations.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jiahuiwu944-hash/SmartCLI'

If you have feedback or need assistance with the MCP directory API, please join our Discord server