|
1 | 1 | # nuwa-cli |
2 | 2 |
|
3 | | -[English](README.md) | [简体中文](README.zh-CN.md) |
| 3 | +[English](#nuwa-cli) | [简体中文](#简体中文) |
4 | 4 |
|
5 | 5 | Headless multi-engine agent CLI. `nuwa-cli` bundles ACP runtimes for Codex and Claude. A locally installed CLI is optional: when present, nuwa-cli reuses its `~/.claude` / `~/.codex` history and configuration; otherwise the session can run entirely from model, environment, and MCP configuration delivered over ACP. |
6 | 6 |
|
@@ -226,3 +226,237 @@ See [`docs/serve-lifecycle.md`](docs/serve-lifecycle.md) for full lifecycle, aut |
226 | 226 | - **Prompt timeout**: 5 minutes per prompt; engine hangs produce an error instead of infinite wait. |
227 | 227 | - **MCP startup**: engines wait for MCP servers to initialize before first prompt; `npm exec` MCP servers may take minutes on first run. MCP servers are injected as raw stdio; both TS adapters handle ACP `mcpServers` natively at the adapter layer. `chrome-devtools` is always enabled by default as a raw stdio MCP (`npx -y chrome-devtools-mcp@latest`, one per session, no cross-session persistence, no `--isolated`). `@nuwax-ai/mcp-proxy-ts` remains a dependency for host adapter tool / default service merging, but is no longer used to inject a proxy entry for the engine. |
228 | 228 | - **Custom ACP engines** (pi-acp, hermes, kilo, etc.) not supported — only `claude` and `codex`. |
| 229 | + |
| 230 | +--- |
| 231 | + |
| 232 | +## 简体中文 |
| 233 | + |
| 234 | +[English](#nuwa-cli) | 简体中文 |
| 235 | + |
| 236 | +无界面(headless)的多引擎 Agent 命令行工具。`nuwa-cli` 已内置 Codex 与 Claude 的 ACP 运行时;本机无需预装对应 CLI。若本机已有 `claude` / `codex`,会复用 `~/.claude` / `~/.codex` 的历史和配置;否则可完全使用 ACP 下发的模型、环境变量与 MCP 配置运行。 |
| 237 | + |
| 238 | +--- |
| 239 | + |
| 240 | +### 安装 |
| 241 | + |
| 242 | +**一键安装**(S3 镜像,国内可达,自动配置 PATH): |
| 243 | + |
| 244 | +```bash |
| 245 | +# Windows (PowerShell) |
| 246 | +irm https://s3.nuwax.com:9443/nuwax-packages/agent-engines/nuwa-cli/install-from-s3.ps1 | iex |
| 247 | + |
| 248 | +# macOS / Linux |
| 249 | +curl -fsSL https://s3.nuwax.com:9443/nuwax-packages/agent-engines/nuwa-cli/install-from-s3.sh | bash |
| 250 | +``` |
| 251 | + |
| 252 | +或通过 npm 安装(需要 Node.js 22+): |
| 253 | + |
| 254 | +```bash |
| 255 | +npm install -g @nuwax-ai/nuwa-cli@beta --progress=true |
| 256 | +nuwa-cli doctor |
| 257 | +``` |
| 258 | + |
| 259 | +> npm 太慢?`NUWACLI_REGISTRY=https://registry.npmmirror.com`(bash)/ `$env:NUWACLI_REGISTRY='https://registry.npmmirror.com'`(PowerShell)。 |
| 260 | +
|
| 261 | +### 卸载 |
| 262 | + |
| 263 | +**一键卸载**(停止服务、移除系统服务(若已安装)、npm 卸载全局包): |
| 264 | + |
| 265 | +```bash |
| 266 | +# Windows (PowerShell) |
| 267 | +irm https://s3.nuwax.com:9443/nuwax-packages/agent-engines/nuwa-cli/uninstall-from-s3.ps1 | iex |
| 268 | + |
| 269 | +# macOS / Linux |
| 270 | +curl -fsSL https://s3.nuwax.com:9443/nuwax-packages/agent-engines/nuwa-cli/uninstall-from-s3.sh | bash |
| 271 | +``` |
| 272 | + |
| 273 | +用户数据(`~/.nuwa-cli`:凭证 / 会话 / 日志 / 工作空间)**默认保留**。一并清除: |
| 274 | + |
| 275 | +```bash |
| 276 | +# Windows |
| 277 | +$env:NUWACLI_PURGE='1'; irm https://s3.nuwax.com:9443/nuwax-packages/agent-engines/nuwa-cli/uninstall-from-s3.ps1 | iex |
| 278 | +# macOS / Linux |
| 279 | +curl -fsSL https://s3.nuwax.com:9443/nuwax-packages/agent-engines/nuwa-cli/uninstall-from-s3.sh | NUWACLI_PURGE=1 bash |
| 280 | +``` |
| 281 | + |
| 282 | +或通过 npm:`npm uninstall -g @nuwax-ai/nuwa-cli`(先用 `nuwa-cli stop` 停服务)。 |
| 283 | + |
| 284 | +--- |
| 285 | + |
| 286 | +### 快速开始 |
| 287 | + |
| 288 | +```bash |
| 289 | +nuwa-cli doctor # 检查环境 |
| 290 | +nuwa-cli doctor --fix # 检测并自动修复可处理的问题 |
| 291 | +nuwa-cli chat -p "列出当前目录下的文件" # 单次,claude 引擎 |
| 292 | +nuwa-cli chat --engine codex -p "hello" # 单次,codex 引擎 |
| 293 | +nuwa-cli console # Web 控制台(浏览器) |
| 294 | +nuwa-cli gateway --domain https://agent.nuwax.com --saved-key <key> # 云端隧道 |
| 295 | +``` |
| 296 | + |
| 297 | +--- |
| 298 | + |
| 299 | +### 命令 |
| 300 | + |
| 301 | +#### 核心 |
| 302 | + |
| 303 | +| 命令 | 说明 | |
| 304 | +|---|---| |
| 305 | +| `nuwa-cli doctor` | 检查 Node、引擎、登录态、lanproxy 健康;`--fix` 自动修自启与服务异常 | |
| 306 | +| `nuwa-cli chat` | 交互式 REPL 或单次模式(`-p`),支持 claude/codex | |
| 307 | +| `nuwa-cli console` | 本机 Web 控制台,流式聊天([文档](docs/console.md)) | |
| 308 | +| `nuwa-cli sessions` | 列出/续接本地 claude/codex 会话历史 | |
| 309 | +| `nuwa-cli workspaces` | 列出本地工作空间目录(云端会话生成的文件) | |
| 310 | +| `nuwa-cli context` | 跨引擎上下文引用(read/digest/handoff) | |
| 311 | + |
| 312 | +#### 云端与生命周期 |
| 313 | + |
| 314 | +| 命令 | 说明 | |
| 315 | +|---|---| |
| 316 | +| `nuwa-cli gateway` | 自动检测引擎 → 登录 → 启动 `serve --tunnel`([文档](docs/gateway.md)) | |
| 317 | +| `nuwa-cli serve` | 本机 HTTP API,供脚本/IM 集成([文档](docs/serve-lifecycle.md)) | |
| 318 | +| `nuwa-cli login` / `logout` / `status` | Nuwax 账号登录(无 UI) | |
| 319 | +| `nuwa-cli account` | 管理多个账号 | |
| 320 | +| `nuwa-cli config` | 获取/设置 domain、lanproxy 路径等 | |
| 321 | +| `nuwa-cli service` | 系统级开机自启(LaunchAgent / systemd / 计划任务) | |
| 322 | +| `nuwa-cli update` | 升级 npm 包 | |
| 323 | +| `nuwa-cli lang` | 查看或设置界面语言(`en` / `zh-CN` / `auto`) | |
| 324 | + |
| 325 | +#### 进程管理 |
| 326 | + |
| 327 | +```bash |
| 328 | +nuwa-cli start # 后台 Gateway |
| 329 | +nuwa-cli start --all # Gateway + 前台 Console |
| 330 | +nuwa-cli stop # 停止 Gateway |
| 331 | +nuwa-cli stop --all # 停止全部 |
| 332 | +nuwa-cli restart # 强制重启 Gateway(先杀所有旧进程) |
| 333 | +nuwa-cli restart --all # 强制重启 Gateway + Console |
| 334 | +nuwa-cli ps # 查看运行中的进程 |
| 335 | +``` |
| 336 | + |
| 337 | +开机后或脚本里跑 `start`:若已安装登录自启,Gateway 可能已在后台拉起,`start` 会先等待隧道就绪再复用。做 `start --force` / `restart` 重试时请等当前命令结束,或先 `nuwa-cli status` 确认 Gateway 与 lanproxy 已就绪,再决定是否再次强制启动。 |
| 338 | + |
| 339 | +--- |
| 340 | + |
| 341 | +### 核心特性 |
| 342 | + |
| 343 | +- **继承你的环境。** 默认不注入任何凭证——引擎看到的就是你已有的 `~/.claude` / `~/.codex` 配置、MCP server、skills 和模型偏好。 |
| 344 | +- **走 ACP 协议。** 两个引擎都通过 [Agent Client Protocol](https://agentclientprotocol.com) 驱动,不是 CLI 文本抓取。 |
| 345 | +- **模型协议路由。** 会话下发 `model_provider` 时,按协议自动选引擎:`api_protocol: openai` → codex,`api_protocol: anthropic` → claude。详见 [`docs/serve-lifecycle.md`](docs/serve-lifecycle.md)。 |
| 346 | +- **云端隧道。** `--tunnel` 注册到 Nuwax 后端,启动 file-server + lanproxy,把本机 Agent 暴露给云端。详见 [`docs/gateway.md`](docs/gateway.md)。 |
| 347 | +- **健康检查。** 启动后对 file-server HTTP `/health` 轮询 + lanproxy 云端隧道探测。详见 [`docs/serve-health-check.md`](docs/serve-health-check.md)。 |
| 348 | +- **跨平台。** Windows / macOS / Linux,arm64 / x64。所有子进程 spawn 使用 `windowsHide`;`.cmd` 脚本自动检测。 |
| 349 | +- **S3 分发。** 从 Nuwax S3 镜像一键安装,无需 GitHub 或 npm 登录。详见 [`docs/distribution-s3.md`](docs/distribution-s3.md)。 |
| 350 | +- **引擎日志。** 引擎 stderr 实时写入 `~/.nuwa-cli/logs/`,便于诊断。 |
| 351 | + |
| 352 | +--- |
| 353 | + |
| 354 | +### 语言 |
| 355 | + |
| 356 | +`nuwa-cli` **默认英文**。当系统 locale 为简体中文(`LANG` / `LC_ALL` / `LC_MESSAGES` / `LANGUAGE` 含 `zh`,如 `zh_CN.UTF-8`、`zh-Hans`)时自动显示简体中文;繁体中文(`zh-TW` / `zh-HK` / `zh-Hant`)回退英文。 |
| 357 | + |
| 358 | +随时可切换——优先级:`NUWACLI_LANG` 环境变量 > 配置 > 自动检测 > 英文: |
| 359 | + |
| 360 | +```bash |
| 361 | +nuwa-cli lang # 查看当前语言及解析来源 |
| 362 | +nuwa-cli lang zh-CN # 持久化简体中文到 ~/.nuwa-cli/config.json |
| 363 | +nuwa-cli lang en # 持久化英文 |
| 364 | +nuwa-cli lang auto # 重新跟随系统 locale |
| 365 | + |
| 366 | +NUWACLI_LANG=zh-CN nuwa-cli doctor # 临时覆盖(优先级最高) |
| 367 | +``` |
| 368 | + |
| 369 | +> ACP 协议响应(HTTP / SSE / permission 结果)**始终为英文**,与界面语言无关——它们是给客户端/引擎消费的协议数据,不是给人看的。只有终端输出会本地化。详见 [`docs/i18n.md`](docs/i18n.md)。 |
| 370 | +
|
| 371 | +--- |
| 372 | + |
| 373 | +### `nuwa-cli serve` API |
| 374 | + |
| 375 | +```bash |
| 376 | +nuwa-cli serve --port 60016 |
| 377 | +# POST /computer/chat → { session_id } |
| 378 | +# GET /computer/progress/:id SSE 流 |
| 379 | +# GET/POST /computer/agent/status |
| 380 | +# POST /computer/agent/stop |
| 381 | +# GET /health (无需鉴权) |
| 382 | +``` |
| 383 | + |
| 384 | +兼容 NuwaClaw 的 `model_provider` / `agent_config` / `context_servers`。优先级:会话配置 > Gateway 参数 > 本地环境。ACP 下发的 `mcpServers` / `context_servers` 作为原始 stdio MCP 交给引擎;`claude-code-acp-ts` / `@nuwax-ai/nuwax-codex-acp-ts` 两个 TS adapter 在 adapter 层原生处理 ACP `mcpServers`。 |
| 385 | + |
| 386 | +云端会话生成的本地文件位于: |
| 387 | + |
| 388 | +```text |
| 389 | +~/.nuwa-cli/workspaces/<user_id>/<agent_work_dir>/ |
| 390 | +``` |
| 391 | + |
| 392 | +运行 `nuwa-cli status` 可查看“我的电脑”名称和服务状态。 |
| 393 | + |
| 394 | +#### 查看本地会话文件 |
| 395 | + |
| 396 | +云端会话生成的文件写入工作空间目录 `~/.nuwa-cli/workspaces/<user_id>/<agent_work_dir>/`: |
| 397 | + |
| 398 | +- `<user_id>` 是你的 Nuwax 数字用户 ID; |
| 399 | +- `<agent_work_dir>` 是每次会话的项目 ID(数字目录)。 |
| 400 | + |
| 401 | +这两个 ID 可在 `nuwa-cli status` 输出或 `~/.nuwa-cli/logs/serve.*.log` 日志里找到。 |
| 402 | + |
| 403 | +也可直接在终端用 `nuwa-cli workspaces` 列出工作空间目录(支持 `--user <id>` 过滤、`--json`、`--long` 列文件树),无需手动拼路径: |
| 404 | + |
| 405 | +```bash |
| 406 | +nuwa-cli workspaces # 列出所有用户/项目 |
| 407 | +nuwa-cli workspaces --user <id> # 只看某个用户 |
| 408 | +nuwa-cli workspaces --long # 列出每个项目内的文件树 |
| 409 | +``` |
| 410 | + |
| 411 | +各平台打开工作空间目录: |
| 412 | + |
| 413 | +```bash |
| 414 | +# macOS(Finder) |
| 415 | +open ~/.nuwa-cli/workspaces |
| 416 | + |
| 417 | +# Windows(PowerShell,资源管理器) |
| 418 | +explorer "$env:USERPROFILE\.nuwa-cli\workspaces" |
| 419 | + |
| 420 | +# Linux |
| 421 | +xdg-open ~/.nuwa-cli/workspaces |
| 422 | +``` |
| 423 | + |
| 424 | +或命令行浏览某个用户下的所有会话目录: |
| 425 | + |
| 426 | +```bash |
| 427 | +ls -la ~/.nuwa-cli/workspaces/<user_id>/ |
| 428 | +``` |
| 429 | + |
| 430 | +nuwa-cli 还会启动本地**文件服务**(HTTP,默认端口 `60015`,`serve`/`gateway` 启动时打印)——它镜像相同的工作空间布局,提供文件列表 / 预览 / 上传 / 打包接口,路径与引擎写入的位置一致。serve 运行时可通过 `http://127.0.0.1:60015` 访问。 |
| 431 | + |
| 432 | +详见 [`docs/serve-lifecycle.md`](docs/serve-lifecycle.md)。 |
| 433 | + |
| 434 | +--- |
| 435 | + |
| 436 | +### 文档 |
| 437 | + |
| 438 | +| 文档 | 内容 | |
| 439 | +|---|---| |
| 440 | +| [`docs/gateway.md`](docs/gateway.md) | Gateway 架构、隧道、daemon、服务 | |
| 441 | +| [`docs/serve-lifecycle.md`](docs/serve-lifecycle.md) | serve 生命周期、鉴权、权限模型、模型路由 | |
| 442 | +| [`docs/console.md`](docs/console.md) | Web 控制台 | |
| 443 | +| [`docs/serve-health-check.md`](docs/serve-health-check.md) | file-server + lanproxy 健康探测 | |
| 444 | +| [`docs/distribution-s3.md`](docs/distribution-s3.md) | S3 分发、发布、安装 | |
| 445 | +| [`docs/acp-permission-guardrails.md`](docs/acp-permission-guardrails.md) | ACP 权限审批流程 | |
| 446 | +| [`docs/i18n.md`](docs/i18n.md) | 界面语言(英文默认、简体中文、切换) | |
| 447 | +| [`docs/local-debugging.md`](docs/local-debugging.md) | 本地开发调试 | |
| 448 | + |
| 449 | +--- |
| 450 | + |
| 451 | +### 运行要求 |
| 452 | + |
| 453 | +- Node.js >= 22 |
| 454 | +- `claude` 和/或 `codex` CLI,已安装并登录(ACP 下发模型配置时可省略) |
| 455 | + |
| 456 | +### 已知限制 |
| 457 | + |
| 458 | +- **进程树清理**:孙进程(如 `claude-code-acp-ts` 拉起的 `claude` 二进制)不会被信号通知,可能成为孤儿。 |
| 459 | +- **yolo 无路径限制**:`--approve auto` 对普通工具不论目标路径一律自动批准。 |
| 460 | +- **Prompt 超时**:每条 prompt 限时 5 分钟,引擎卡住时报错而非无限等待。 |
| 461 | +- **MCP 启动**:引擎等所有 MCP server 初始化后才处理首条消息;`npm exec` MCP server 首次可能需数分钟。MCP server 以原始 stdio 形式注入引擎,两个 TS adapter 在 adapter 层原生处理 ACP `mcpServers`。默认始终启用 `chrome-devtools`(`npx -y chrome-devtools-mcp@latest`,每 session 自启,无跨 session 持久化,无 `--isolated`)。注意:`@nuwax-ai/mcp-proxy-ts` 仍是依赖(host adapter 工具/默认服务合并),但不再用于给 engine 注入 proxy 入口。 |
| 462 | +- **自定义 ACP 引擎**(pi-acp、hermes、kilo 等)暂不支持——仅支持 `claude` 和 `codex`。 |
0 commit comments