Skip to content

Commit 7a192ea

Browse files
committed
refactor(mcp): move config helpers to integrations
1 parent 190a4ac commit 7a192ea

7 files changed

Lines changed: 384 additions & 235 deletions

File tree

docs/architecture/core-decomposition.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ owner 边界,否则不要把一个 feature group 继续拆成更小的 crate
8686
`agent-tools` 没有引入重 runtime / concrete service 依赖。
8787
- 已迁移回 `bitfun-core` 的 legacy facade 只能 re-export owner crate 或做窄错误 / 路径注入映射;例如 Git 旧路径、
8888
remote SSH types/workspace path + unresolved-key helper facade、MCP tool contract facade、MCP protocol types / JSON-RPC
89-
request builder facade、MCP config location / cursor-format / JSON config helper facade、MCP server config facade、
90-
MCP OAuth auth facade 和 announcement types facade
89+
request builder facade、MCP config location / cursor-format / JSON config / config service helper facade、
90+
MCP server config facade、MCP OAuth auth facade 和 announcement types facade
9191
由边界脚本检查,不得重新承载实现逻辑。
9292
- 对仍嵌在 core runtime 文件中的旧公开类型,必须至少保留禁止回流检查;例如 MCP server
9393
type/status/config 已由 owner crate 拥有,`MCPServerProcess` 只保留 runtime 逻辑。

docs/plans/core-decomposition-plan.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ product-full = ["git", "mcp", "remote-ssh", "remote-connect", "announcement", "f
978978
**当前安全迁移状态(2026-05-12):**
979979

980980
- 已迁移到 `bitfun-services-integrations``service::file_watch`,通过 `file-watch` / `product-full` feature 启用,并保持 `core::service::file_watch` 旧路径。
981-
- `git` 已完成 DTO/params/graph/raw command output/text parser/arg builder、`GitError`、`GitService` runtime implementation 与 git utils 迁移;`bitfun-core::service::git::*` 仅保留 legacy facade re-export。`remote-ssh` 已迁移纯 contract/type、workspace path/identity helper 与 unresolved-session-key helper;SSH runtime manager / fs / terminal、password vault 与 PathManager-backed session mirror assembly 仍保留在 core。`mcp` 已迁移 tool-name / tool-info / protocol types / config location / server type-status、server config、cursor-format、JSON-RPC request builder、JSON config format/validation helper 与 OAuth credential vault / authorization bootstrap contract,并用 owner crate contract test 锁定 wire shape、transport default、validation message、Cursor 兼容格式与 OAuth vault 存储路径注入;config service save-load orchestration / transport / server process / adapter / dynamic tools 仍保留在 core;`announcement` 仅迁移了纯 types contract,scheduler / state store / content loader / remote fetch 仍保留在 core;`remote-connect` 尚未迁移。它们涉及 SSH runtime、MCP dynamic tool provider、remote agent submission 与 announcement config/path 边界,继续前需要单独确认端口方案与等价性测试。
981+
- `git` 已完成 DTO/params/graph/raw command output/text parser/arg builder、`GitError`、`GitService` runtime implementation 与 git utils 迁移;`bitfun-core::service::git::*` 仅保留 legacy facade re-export。`remote-ssh` 已迁移纯 contract/type、workspace path/identity helper 与 unresolved-session-key helper;SSH runtime manager / fs / terminal、password vault 与 PathManager-backed session mirror assembly 仍保留在 core。`mcp` 已迁移 tool-name / tool-info / protocol types / config location / server type-status、server config、cursor-format、JSON-RPC request builder、JSON config format/validation helper、config merge / remote authorization helper 与 OAuth credential vault / authorization bootstrap contract,并用 owner crate contract test 锁定 wire shape、transport default、validation message、Cursor 兼容格式、config precedence / dedup 语义与 OAuth vault 存储路径注入;config service save-load orchestration / transport / server process / adapter / dynamic tools 仍保留在 core;`announcement` 仅迁移了纯 types contract,scheduler / state store / content loader / remote fetch 仍保留在 core;`remote-connect` 尚未迁移。它们涉及 SSH runtime、MCP dynamic tool provider、remote agent submission 与 announcement config/path 边界,继续前需要单独确认端口方案与等价性测试。
982982
- 最新主干的 Deep Review capacity / cost / queue、context profile、evidence ledger、session manifest、stream dedupe、search remote/fallback 与 session rollback persistence 仍属于 core runtime 或对应产品 runtime,不在本轮 `services-integrations` 迁移范围内;如果后续迁移 remote-connect / MCP / search / session,需要先定义运行状态 port 合约和等价测试。
983983

984984
**验证:**
@@ -1508,7 +1508,7 @@ cargo check --workspace
15081508

15091509
- 已完成中等粒度 owner crate 成型的安全部分:`bitfun-services-core``bitfun-services-integrations``bitfun-agent-tools``bitfun-tool-packs``bitfun-product-domains` 均已加入 workspace。
15101510
- 已迁移的模块均由 core facade re-export,未改变产品默认 feature、构建脚本或 release 脚本。
1511-
- Git feature group 已闭环迁移到 `bitfun-services-integrations` 的 `git` feature:DTO/params/graph/raw command output/text parser/arg builder、`GitError`、`GitService` runtime implementation 与 git utils 均由 integrations owner crate 拥有,并通过 `bitfun-core::service::git::*` 保留旧路径兼容。`GitService` 所需的 Windows `libgit2` system-link 边界挂在该 crate 的 `git` feature 上;`bitfun-core` 仍因未迁移的 remote-connect runtime 保留其它 `git2` 使用。remote-ssh 本轮进一步外移 workspace path/identity 与 unresolved-session-key helper,并用 owner crate contract test 锁定 normalized path、mirror subpath、hostname sanitization、stable id 和 unresolved key 输出;PathManager-backed mirror root、global workspace registry、SSH manager/fs/terminal/runtime 仍留在 core。MCP 本轮进一步外移 server config、cursor-format、JSON-RPC request builder、JSON config format/validation helper 与 OAuth credential vault / authorization bootstrap contract,core 旧路径继续做兼容 facade、数据目录注入和 `BitFunError` 映射。
1511+
- Git feature group 已闭环迁移到 `bitfun-services-integrations` 的 `git` feature:DTO/params/graph/raw command output/text parser/arg builder、`GitError`、`GitService` runtime implementation 与 git utils 均由 integrations owner crate 拥有,并通过 `bitfun-core::service::git::*` 保留旧路径兼容。`GitService` 所需的 Windows `libgit2` system-link 边界挂在该 crate 的 `git` feature 上;`bitfun-core` 仍因未迁移的 remote-connect runtime 保留其它 `git2` 使用。remote-ssh 本轮进一步外移 workspace path/identity 与 unresolved-session-key helper,并用 owner crate contract test 锁定 normalized path、mirror subpath、hostname sanitization、stable id 和 unresolved key 输出;PathManager-backed mirror root、global workspace registry、SSH manager/fs/terminal/runtime 仍留在 core。MCP 本轮进一步外移 server config、cursor-format、JSON-RPC request builder、JSON config format/validation helper、config merge / remote authorization helper 与 OAuth credential vault / authorization bootstrap contract,core 旧路径继续做兼容 facade、数据目录注入和 `BitFunError` 映射。
15121512
- 未声明完成的 P2 剩余部分:remote-ssh runtime、MCP config service orchestration / server process / transport / adapter / dynamic tools、remote-connect 等重 service 迁移、concrete tool implementation 迁移、tool registry/provider 化、miniapp/function-agent 运行逻辑迁移。这些会触碰 `PathManager``BitFunError``ToolUseContext`、workspace service、snapshot wrapper、`AgentSubmissionPort` 或 AI service 边界,需要在继续前显式确认。
15131513
- 本次 rebase 后重新核对最新主干 Deep Review capacity/cost/queue、context profile、evidence ledger 与 session manifest 变更:当前 PR 已完成 Git feature group 的 owner crate 归属迁移,但未改动这些 Deep Review 行为路径;后续迁移必须补端口设计和等价测试后再推进。
15141514
- 本次 P2 后续复核结论:上述高耦合剩余项不是纯文件搬迁;若继续迁移会改变依赖方向或需要新增 port/provider 行为合约。因此当前 PR 将它们显式保留为 core-owned runtime,并通过 P3 boundary check 防止已拆 owner crate 回流依赖 core。
@@ -1549,18 +1549,18 @@ cargo check --workspace
15491549
- P3 只能在 P2 剩余迁移闭环后启动:重 service 迁移、concrete tool implementation 迁移、tool registry/provider 化、miniapp/function-agent 运行逻辑迁移都必须先完成或显式保留为 core-owned runtime。
15501550
- 最近 `origin/main` 的 Deep Review 变更增加了 context profile、evidence ledger、capacity/cost/queue 控制、`deep_review_run_manifest` / `deep_review_cache`、以及 review-team UI orchestration;最新主干还补充了 agent-stream tool-call dedupe、search remote/fallback、session rollback persistence 和 companion typewriter。P3 facade 收敛前必须确认这些行为要么仍由 core product runtime assembly 拥有,要么已有对应 owner crate + port/provider 合约和等价测试。
15511551
- 最新主干的 mode-scoped subagent visibility 将 `agentic::agents` 重组为 definitions / registry / visibility 边界,并扩展了 desktop subagent API 与 Review Team 可见性测试;后续若迁移 agent registry,不能只做路径 re-export,必须保留 mode 可见性过滤、hidden/custom/review 分组语义和前后端 API contract。
1552-
- 最新主干的 CLI 重构主要新增 TUI/theme/selector/dialog/chat-state 等 app-layer 代码,当前没有改变 `services-integrations` 的迁移归属后续若调整 shared crate 边界,必须继续把 `bitfun-cli``ratatui``crossterm``arboard``syntect-tui` 等 CLI-only 依赖限制在 app adapter / presentation layer。
1552+
- 最新主干的 CLI 重构主要新增 TUI/theme/selector/dialog/chat-state 等 app-layer 代码,后续又收敛预置 theme 并补充 desktop companion pet resize / Windows UX;这些当前没有改变 `services-integrations` 的迁移归属后续若调整 shared crate 边界,必须继续把 `bitfun-cli``ratatui``crossterm``arboard``syntect-tui` 等 CLI-only 依赖限制在 app adapter / presentation layer,desktop / web-ui presentation 修复也不应被误判为 core service 迁移前置条件
15531553
- `ToolUseContext` 的 shared-context / evidence checkpoint hook、`TaskTool` / `CodeReviewTool` 的 Deep Review capacity flow、session manifest/cache persistence、rollback persisted-turn cleanup、search fallback chain 与 stream finish/tool-call contract 不能在 P3 中只通过 re-export 消失;如果外移,需要先补 boundary contract、旧路径兼容和对应 regression。
15541554
- P3 的闭环检查应同时覆盖 Rust crate graph 与产品 runtime 行为:边界脚本只证明依赖方向,不能替代 Deep Review、MCP dynamic tools、remote connect、snapshot wrapping、miniapp/function-agent 的产品等价性验证。
15551555
- 当前 PR 的 P3 范围按“显式保留 core-owned runtime + 强制 owner crate 边界”闭环;后续如果要继续外移这些 runtime 路径,需要作为新的迁移批次先补 port 设计、等价测试和用户确认。
15561556

15571557
**阶段复核与后续拆分(2026-05-12 rebase 后):**
15581558

15591559
- 当前分支保持小粒度:只包含 boundary check、facade/product runtime 注释、阶段文档和 Git feature group 归属迁移;不继续混入 remote-connect、MCP dynamic tools、tool registry、miniapp 或 function-agent runtime 迁移。
1560-
- 本次 rebase `origin/main` 后,PR #680 的三颗等价提交已进入主干;新增 CLI 重构与 agent execution hardening 没有改变本轮 `services-integrations` / service facade 迁移内容,但会把后续 CLI 产品检查、agent registry/provider 与 session/tool runtime 外移的等价性门槛抬高。
1560+
- 本次 rebase 到最新 `upstream/main` 后,PR #680 的三颗等价提交已进入主干;新增 CLI 收敛、版本 bump 和 desktop companion pet UX 修复没有改变本轮 `services-integrations` / service facade 迁移内容,但会把后续 CLI 产品检查、agent registry/provider 与 session/tool runtime 外移的等价性门槛抬高。
15611561
- 质量边界:本阶段只证明已拆 owner crate 不依赖回 `bitfun-core`,并证明 Git 旧路径仍通过当前 Rust workspace 检查;不声明 remote connect、MCP dynamic tools、snapshot wrapping、miniapp/function-agent runtime 的外移完成。
15621562
- boundary check 已扩展到 `core-types``runtime-ports``agent-tools` 的轻量边界,并覆盖 Cargo inline 依赖和 dependency table 依赖声明,后续不能绕过脚本把重 runtime、concrete service、platform adapter 或 CLI/TUI presentation 依赖带入这些 contract crate。
1563-
- boundary check 也已锁定 `bitfun-core::service::git``bitfun-core::service::remote_ssh::types`、remote-ssh workspace path/identity/unresolved-key helper、`bitfun-core::service::mcp::{tool_info,tool_name}``bitfun-core::service::mcp::protocol::{types,jsonrpc}``bitfun-core::service::mcp::config::{location,cursor_format,json_config}``bitfun-core::service::mcp::server::config``bitfun-core::service::mcp::auth``bitfun-core::service::announcement::types` 的旧路径 facade-only / 禁止回流状态,并禁止在 `MCPServerProcess` runtime 文件重新定义已外移的 server type/status contract。
1563+
- boundary check 也已锁定 `bitfun-core::service::git``bitfun-core::service::remote_ssh::types`、remote-ssh workspace path/identity/unresolved-key helper、`bitfun-core::service::mcp::{tool_info,tool_name}``bitfun-core::service::mcp::protocol::{types,jsonrpc}``bitfun-core::service::mcp::config::{location,cursor_format,json_config,service_helpers}``bitfun-core::service::mcp::server::config``bitfun-core::service::mcp::auth``bitfun-core::service::announcement::types` 的旧路径 facade-only / 禁止回流状态,并禁止在 `MCPServerProcess` runtime 文件重新定义已外移的 server type/status contract。
15641564
- 后续迁移必须拆成可独立审核的提交:先补 port/provider 设计和等价测试,再按 `remote-ssh` runtime、MCP runtime、`remote-connect` 的顺序一次迁移一个 service feature group。
15651565
- tool registry / concrete tool implementation 外移必须先有工具清单等价测试,并保留 dynamic provider metadata;不能把注册名解析、snapshot wrapper 或 runtime restriction 行为改成隐式约定。
15661566
- 已新增并扩展内置工具清单基线测试,后续 registry/provider 外移必须先保持该清单、注册顺序、runtime collection 顺序、dynamic provider metadata 顺序和修改类工具 snapshot wrapper 等价,再评估 owner crate 边界。

scripts/check-core-boundaries.mjs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,31 @@ const forbiddenContentRules = [
248248
},
249249
],
250250
},
251+
{
252+
path: 'src/crates/core/src/service/mcp/config/service.rs',
253+
patterns: [
254+
{
255+
regex: /\bconst AUTHORIZATION_KEYS\b/,
256+
message: 'core MCP config service facade must not own authorization key constants; use the integrations helper',
257+
},
258+
{
259+
regex: /\bfn config_signature\b/,
260+
message: 'core MCP config service facade must not own merge signatures; use the integrations helper',
261+
},
262+
{
263+
regex: /\bfn precedence\b/,
264+
message: 'core MCP config service facade must not own merge precedence; use the integrations helper',
265+
},
266+
{
267+
regex: /\bfn config_authorization_from_map\b/,
268+
message: 'core MCP config service facade must not own authorization extraction; use the integrations helper',
269+
},
270+
{
271+
regex: /\bBTreeMap\b/,
272+
message: 'core MCP config service facade must not rebuild stable merge signatures; use the integrations helper',
273+
},
274+
],
275+
},
251276
{
252277
path: 'src/crates/core/src/service/mcp/auth.rs',
253278
patterns: [
@@ -520,6 +545,28 @@ function runManifestParserSelfTest() {
520545
}
521546
}
522547

548+
const mcpConfigServiceRule = forbiddenContentRules.find(
549+
(rule) => rule.path === 'src/crates/core/src/service/mcp/config/service.rs',
550+
);
551+
if (!mcpConfigServiceRule) {
552+
throw new Error('missing MCP config service boundary rule');
553+
}
554+
const mcpConfigServiceHelpers = [
555+
'AUTHORIZATION_KEYS',
556+
'config_signature',
557+
'precedence',
558+
'config_authorization_from_map',
559+
'BTreeMap',
560+
];
561+
const mcpConfigServiceRuleText = mcpConfigServiceRule.patterns
562+
.map((pattern) => pattern.regex.source)
563+
.join('\n');
564+
for (const helper of mcpConfigServiceHelpers) {
565+
if (!mcpConfigServiceRuleText.includes(helper)) {
566+
throw new Error(`MCP config service boundary rule must forbid helper: ${helper}`);
567+
}
568+
}
569+
523570
const mcpAuthRule = forbiddenContentRules.find(
524571
(rule) => rule.path === 'src/crates/core/src/service/mcp/auth.rs',
525572
);

0 commit comments

Comments
 (0)