feat(runner): 实现 Phase 2 本机 Runner 安全执行通道 (#555)#570
feat(runner): 实现 Phase 2 本机 Runner 安全执行通道 (#555)#570Cai-Tang-www wants to merge 9 commits into1024XEngineer:mainfrom
Conversation
实现从"飞书消息 → 云端 Gateway → 本机 Runner"的安全最小闭环。Runner 通过主动出站 WebSocket 长连接与云端 Gateway 通信,在本机执行工具并将 结果回传,无需暴露入站端口。 ## 新增文件 - `internal/runner/types.go` — Runner 类型定义(ToolExecutionRequest / Result / Config) - `internal/runner/runner.go` — Runner 守护进程主循环:WebSocket 连接、认证、 注册、事件循环、工具分发、心跳保活、指数退避重连 - `internal/runner/capability.go` — Runner 端安全校验:Workdir Allowlist 路径 验证、CapabilityToken 预留校验入口 - `internal/gateway/runner_registry.go` — RunnerRegistry:在线 Runner 注册/注销、 Session 绑定、连接断开自动清理 - `internal/gateway/runner_tool.go` — RunnerToolManager:工具请求分发、Capability Token 签发、异步结果收集、超时清理 - `internal/gateway/protocol/runner.go` — Runner JSON-RPC 协议类型 - `internal/config/runner.go` — RunnerConfig 配置模型(ApplyDefaults/Clone/Validate) - `internal/cli/runner_command.go` — `neocode runner` CLI 子命令 ## 修改文件 - `internal/gateway/types.go` — 新增 FrameAction: register_runner / execute_tool_result - `internal/gateway/errors.go` — 新增错误码: runner_offline / capability_denied / tool_execution_failed - `internal/gateway/security.go` — 新增 RequestSourceRunner + ACL 白名单 - `internal/gateway/protocol/jsonrpc.go` — 注册 runner 相关 JSON-RPC 方法路由 - `internal/gateway/bootstrap.go` — handler: registerRunner / executeToolResult - `internal/gateway/registry.go` — 注册 runner core handlers - `internal/gateway/connection_context.go` — RunnerRegistry/RunnerToolManager 上下文注入 - `internal/gateway/network_server.go` — 实例化并注入 RunnerRegistry/RunnerToolManager - `internal/config/config.go` / `loader.go` — 接入 RunnerConfig 9-step 配置接线 - `internal/feishuadapter/adapter.go` — translateRunnerError: runner 错误码 -> 中文提示 - `internal/cli/root.go` — 注册 runner 子命令 - `internal/session/sqlite_store.go` — 修复 schema v6→v7 迁移 case 缺失 ## 文档 - `docs/guides/feishu-adapter.md` — 新增第 9 节 Runner 架构说明 - `www/guide/feishu-remote-setup.md` — 新增 Local Runner 启动配置步骤 - `README.md` / `README.en.md` — 新增 Runner 功能特性与 CLI 速查 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
I found a few blocking issues in the new runner execution path. The main problems are that the gateway startup path still does not wire the runner components in, the runner cannot execute real tools yet, and the current implementation/documents overstate the security guarantees around capability tokens and transport handling.
- MultiWorkspaceRuntime 新增 InjectRunnerDispatcher,同时注入已有 和未来创建的 workspace bundle - gateway_commands 中创建 RunnerRegistry/RunnerToolManager 并传入 NetworkServerOptions 和 runtime dispatcher - network_server 在 WS 断连时自动清理 runner 注册记录 - runtime 新增 RunnerToolDispatcher 接口及设值方法,在工具执行前 优先尝试 runner 分发,handled=false 时回退本地执行 - 新增 runner_tool_bridge 适配 RunnerToolManager 到 runtime 接口 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Gateway 签发 CapabilityToken 并随工具请求下发给 Runner - Runner 验证 Token 签名/TTL/工具白名单 + 路径 allowlist 校验 - Token 从 URL query 迁移至 Authorization Header - 添加 WebSocket 并发写保护、工具注册、Shell 自动检测 - 路径判定排除 URL 等非路径字符串,相对路径基于 workdir 解析
|
/code 提升测试覆盖率到100%,完成任务后推送Pr到我的分支 |
结果补了 Runner 相关测试,并修了一个真实缺陷: 本次新增/补充测试覆盖了:
验证结果:
代码已提交并推送到当前 PR 分支 未完成项:这次没有把全仓库总覆盖率提升到 100%,但新增 Runner 链路的关键实现和回归路径已经补齐并通过全量测试。 |
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: Cai-Tang-www <106404101+Cai-Tang-www@users.noreply.github.com>
|
/code 提升测试覆盖率到100%,完成任务后推送Pr到我的分支 |
Result已补充并提交一轮 runner 相关覆盖测试,commit 为 本次新增测试主要覆盖:runner CLI 默认值与错误路径、gateway runner 注册/结果回传分支、JSON-RPC runner 参数校验、network server 的 runner 上下文接线、runtime runner 分流、sqlite v6→v7 初始化迁移,以及 runner capability / heartbeat / tool request 的异常路径。 已验证: 未完成:没有把覆盖率打到绝对 100%。剩余未覆盖点已经收敛到少量 OS/环境失败路径、长周期 ticker 分支,以及部分需要额外测试 seam 的底层错误路径;我没有继续为了数字引入更重的生产代码侵入。 |
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: Cai-Tang-www <106404101+Cai-Tang-www@users.noreply.github.com>
将 sessionBinding.ApprovalStatus 单值替换为 ApprovalRecords 列表, 状态卡片审批区从单行状态改为聚合摘要 + 逐条明细, 支持同一 run 内多次工具审批的完整追踪。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
将阿里云账号绑定从"失败时回退"改为引导流程中的显式必须步骤, 中英文 configuration.md 新增 ModelScope API Key 获取小节。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
概述
实现 Issue #555 "Phase 2: 本机 Runner 安全执行通道",打通"飞书消息 → 云端 Gateway → 本机 Runner 工具执行" 的安全最小闭环。
Close #555 Close #553
架构
Runner 通过主动出站 WebSocket 长连接与云端 Gateway 通信,无需暴露入站端口。Gateway 将工具请求通过 StreamRelay 推送到 Runner,Runner 验证 CapabilityToken 后在本机执行,结果通过 Gateway 回传飞书。
变更清单
新增 9 个文件
internal/runner/types.gointernal/runner/runner.gointernal/runner/capability.gointernal/gateway/runner_registry.gointernal/gateway/runner_tool.gointernal/gateway/runner_tool_bridge.gointernal/gateway/protocol/runner.gointernal/config/runner.gointernal/cli/runner_command.goneocode runnerCLI 子命令修改 16 个文件
internal/gateway/types.goFrameActionRegisterRunner, +FrameActionExecuteToolResultinternal/gateway/errors.goErrorCodeRunnerOffline, +ErrorCodeCapabilityDenied, +ErrorCodeToolExecutionFailedinternal/gateway/security.goRequestSourceRunner, +runnerControlPlaneMethods()ACLinternal/gateway/protocol/jsonrpc.gointernal/gateway/bootstrap.gohandleRegisterRunnerFrame+handleExecuteToolResultFrameinternal/gateway/registry.gointernal/gateway/connection_context.gointernal/gateway/network_server.gointernal/gateway/multi_workspace_runtime.goInjectRunnerDispatcher方法,注入已有及未来 workspace bundleinternal/cli/gateway_commands.gointernal/runtime/runtime.goRunnerToolDispatcher接口 +SetRunnerToolDispatcher设值方法internal/runtime/permission.gointernal/config/config.go/loader.gointernal/feishuadapter/adapter.gotranslateRunnerError:runner 错误码翻译为中文用户消息internal/cli/root.gonewRunnerCommand()internal/session/sqlite_store.go文档更新 4 个文件
docs/guides/feishu-adapter.mdwww/guide/feishu-remote-setup.mdREADME.mdREADME.en.md关键设计决策
/ws端点、JSON-RPC 协议、StreamRelay 路由、心跳和认证机制gateway.toolRequestnotification 推送到 Runner WebSocketinternal/security/capability.go的 HMAC-SHA256 签名 + TTL + AllowedTools + AllowedPathsRunnerToolDispatcher接口 +SetRunnerToolDispatcher方法注入,遵循项目现有模式(SetMemoExtractor / SetSkillsRegistry 等)runner_tool_bridge.go在 gateway 包实现 runtime 接口,避免循环导入数据流
验证
go build ./...编译通过go test ./...现有测试全部通过相关 Issue