feat(model-proxy): 提供基于 CLI 的模型代理模式与标准调用入口 - #1428
Merged
Merged
Conversation
|
🚀 Released in v3.26.0 |
deepcoldy
added a commit
to kingchao1024/botmux
that referenced
this pull request
Sep 22, 2026
主干 deepcoldy#1428 在本分支切出后新增 Record<CliId, ModelOnlyAssessment> 穷举表, 新增 CliId 必须显式评估。MiMoCode 为 OpenCode 1.x fork 且无可运行原生程序 验证模型-only 隔离,按 opencode2/mtr 同例判 verification_required,不启用执行路径。 Co-Authored-By: Claude Code <noreply@anthropic.com>
deepcoldy
added a commit
to kingchao1024/botmux
that referenced
this pull request
Sep 22, 2026
主干 deepcoldy#1428 在本分支切出后新增 Record<CliId, ModelOnlyAssessment> 穷举表, 新增 CliId 必须显式评估。MiMoCode 为 OpenCode 1.x fork 且无可运行原生程序 验证模型-only 隔离,按 opencode2/mtr 同例判 verification_required,不启用执行路径。 Co-Authored-By: Claude Code <noreply@anthropic.com>
deepcoldy
pushed a commit
that referenced
this pull request
Sep 22, 2026
## 改动 新增小米 MiMoCode CLI(`mimo`)适配器,`bots.json` 配 `cliId: "mimocode"` 即可接入。 - 将 `opencode.ts` 重构为 `createOpenCodeLikeAdapter` 工厂(OpenCode 对外行为不变),MiMoCode 复用其 SQLite v1 会话存储、writeInput 提交验证、会话续接与 ask-hook 插件;新增 `mimocode.ts`(二进制 `mimo`、XDG 数据根、目录级 authPaths、`--trust` 跳过工作目录信任提示)与 `services/mimocode-paths.ts`(XDG 兼容路径)。 - 接入全部注册点:CliId、registry、显示名、setup 序号、模型候选、启动带 model 集合、ask-hook、能力矩阵、本地打开器、skill 安装、session-discovery 等;README 中英同步;删除 i18n 中从未被引用的 setup.supported_clis 死代码。 - setup 数字序号:'30'=minimax 已随 v3.21.0 发布,保持原位;mimocode 追加为 '31',并在 resolveCliId 测试锁定已发布序号,防止后续插位。 - 合并主干 #1428 后新增的模型-only 穷举评估表:mimocode 作为 OpenCode fork 且尚无原生程序验证零工具隔离,按 opencode2/mtr 同例登记为 verification_required,不启用执行路径。 ## 影响面 工厂重构仅搬运代码组织,OpenCode 字段与 buildArgs/writeInput/isSessionBusy 行为逐项不变,opencode2 复用的导出未动;其余 20+ CLI 仅共用表各增一键,不受影响。MiMoCode 走通用 Pty/Tmux 后端,话题/群/adopt 会话无差异;CliId 联合类型为纯增量。 ## 测试 bun run build 全绿;cli-adapters、cli-id-roster-derivation、launch-model-capability、zellij 检测、bot-config-editor(含已发布序号锁定断言)、model-only-print(穷举键)、opencode/opencode2 resume、ask-hook、sandbox 等相关用例通过;新适配器/序号断言均经变异验证。作者已在实际 daemon 长期 live 验证会话创建、输入投递与重启后续接。 Co-authored-by: kingchao1024 <kingchao1024@users.noreply.github.com> Co-Authored-By: Claude Code <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景 / 动机
本次迭代的出发点是增强 Bot 的业务能力。Botmux 当前主要通过桥接 Coding CLI,让 Bot 提供编程助手能力;面向实际业务,Bot 还需要组合代码评审、监控排查等多种专业能力,逐步成为能够承担不同任务的复合型数字员工。
这些能力的提供方式各不相同:有些可以直接调用一个 CLI,有些则由完整的 Agent 框架提供。后者已经负责上下文管理、业务工具、权限和任务编排,能够自行完成“请求模型、执行工具、回填结果、继续处理”的多轮流程,接入时只需要模型能力。要让 Bot 复用这类框架,需要为它们提供模型调用入口,并保留框架自身的工具执行与流程控制。
为此,Botmux 增加模型透明代理模式(Model Proxy Mode),复用所适配 CLI 的模型调用能力与原生认证,将模型结果或工具调用建议返回给外部框架,由框架执行业务工具并决定后续步骤。同时,由 Botmux 提供统一的模型接入协议,首版支持非流式 Chat Completions 协议子集,使外部应用可通过模型 SDK 配置 endpoint、访问凭据和模型别名接入,无需为每种能力分别维护私有推理适配。这为 Bot 组合更多专业能力提供了公共接入基础。
使用场景与调用链
以下两个例子说明为什么外部应用需要保留自己的工具和任务流程,只把模型请求交给 Botmux:
外部应用(如 OCR、监控与故障排查系统)→ 模型 SDK → Botmux 公共 Chat Completions 适配 → 既有签名 IPC 和受约束执行层 → CLI 原生模型调用。 公共适配层负责消息和工具协议翻译;执行层负责鉴权、deadline、幂等、并发、结果记录与进程回收;CLI 保留原生认证和模型传输路径。工具调用建议沿原路径返回外部应用,由外部应用执行业务工具并回填结果;Botmux 和被调用 CLI 不执行外部业务工具。
实现与分组
实现基础:复用 CLI 已有的模型调用与工具控制能力。 Claude Code 可组合原生 print/stream-json 与空 tools;Codex 通过 app-server,组合执行环境、工具配置和临时模型目录来关闭工具。各 CLI 的接口与约束不同,需要分别适配和验证。
botmux model-proxy serve --config,固定监听127.0.0.1,要求 Bearer 访问凭据。服务端把客户端权限和模型别名映射到专用 Bot、原生模型及 deadline;客户端不能指定身份目录、原生程序或上游 endpoint。兼容范围与部署条件
GET /v1/models、非流式POST /v1/chat/completions;未知参数明确报错max_completion_tokens传入原生生成设置,已验证 1、4096、16384;作用于原生生成请求,包含序列化开销,不是整次 CLI 调用的总费用上限。其他 CLI 明确拒绝usage:null;扩展字段保留原生真实计数、来源与整次调用范围,未知值为 null,不估算或伪造单次 API 账单完整配置、模型 SDK 调用方式与 OCR 应用接入示例、schema 子集、取消与幂等语义见公共模型协议说明;底层契约见受约束推理执行层。
CLI 适配状态
claude-code、codex、codex-app、gemini、opencode、pi、minimaxseed、relay、aiden、coco、cursor、genius、opencode2、antigravity、mtr、hermes、mira、mir、traex、copilot、oh-my-pi、ebsd、kimi、grok、kiro-cli、riff、reasonix、dsh、dsh-tui、mojo本次验证
bun run test -- --configLoader runner test/model-proxy.test.ts test/model-proxy-ipc.test.ts test/constrained-invocation.test.ts test/ipc-constrained-invocation.test.ts test/model-only-print.test.ts test/capabilities.test.ts test/session-command.test.ts test/headless-command.test.ts test/codex-rpc-engine.test.ts test/claude-code-cwd.test.ts test/bot-registry.test.ts:274 项通过。bun x vitest run --configLoader runner --project e2e test/constrained-codex.e2e.ts test/model-only-claude.e2e.ts test/model-only-print.e2e.ts test/model-only-gemini.e2e.ts test/model-only-opencode.e2e.ts test/model-proxy.e2e.ts(按文档设置原生 CLI、SDK 和 OCR 路径):34 项通过,包含 Claude 的 1 / 4096 / 16384 预算边界。bun run build、git diff --check通过;编译后model-proxy --help可用;Bun 1.4.2 构建模块的实际 HTTP 请求 smoke 通过。影响范围与后续验收
新增前台公共协议服务,复用 Bot admission、签名 IPC 和执行层;普通 PTY/tmux/IM 会话保持原路径,本次已回归普通 Codex RPC、Claude、headless/session 命令与 Bot 注册。未新增依赖或修改版本号。新公共入口本次在 macOS 验证,Linux 尚未做本轮端到端验收。
剩余验收包括专用身份的真实订阅调用、OCR + Codex 的输出上限兼容,以及领域集成中的完整 MR 对比与生产切换。本次未合并、未发版、未重启既有生产服务、未发送 IM 或 MR 评论。