Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion docs/architecture/core-decomposition.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Rust 编译和链接面。
| `bitfun-events` | 已有的传输层无关事件 DTO 和事件抽象 | done:既有基础 crate |
| `bitfun-ai-adapters` | 已有 AI provider adapter,以及 provider / protocol DTO 归属 | done:既有 adapter crate |
| `bitfun-agent-stream` | Stream 聚合和 stream-focused 测试 | done:stream 聚合已独立 |
| `bitfun-runtime-ports` | 面向 service/agent 边界的轻量跨层 DTO 和 trait | partial:DTO/trait-only 边界已建立,包含 agent submission/transcript/cancel、remote state、runtime eventremote image attachment 契约;不拥有 runtime 实现 |
| `bitfun-runtime-ports` | 面向 service/agent 边界的轻量跨层 DTO 和 trait | partial:DTO/trait-only 边界已建立,包含 agent submission/transcript/cancel、remote state、runtime eventremote image attachment、dialog submission policy/outcome、subagent context mode 与 delegation policy 契约;不拥有 runtime 实现 |
| `bitfun-agent-runtime` | Sessions、execution、coordination、agent system | target:crate 尚不存在,agent runtime 仍在 core |
| `bitfun-agent-tools` | 轻量 tool DTO / contract、portable tool context facts / provider、runtime restriction、host path normalization / runtime artifact URI / remote POSIX path pure contract、provider-neutral tool path resolution / absolute-path check / runtime artifact reference assembly、file guidance marker、file-read freshness comparison、oversized tool-result preview/rendering policy、tool execution result/error/invalid-call presentation policy、allowed-list / collapsed-tool execution gate policy、provider-neutral path policy root matching / denial message、pure manifest/exposure and GetToolSpec presentation/schema/static metadata/detail/result assembly / execution-plan contract、provider-backed tool catalog / GetToolSpec runtime facade、provider-backed GetToolSpec execution result helper / Tool-result vector adapter、generic contextual manifest resolver、generic catalog snapshot provider / GetToolSpec catalog provider、generic registry / static-provider / dynamic-provider / decorator-ref / snapshot-decorator adapter / runtime assembly container、generic readonly/enabled snapshot filter | partial:product registry snapshot access、`ToolUseContext` adapter、session file-read state storage、tool-result filesystem writes、`GetToolSpec` Tool impl 和 concrete tools 仍在 core,并由 core `tools/product_runtime.rs` 作为单一 product runtime owner 组装;core 当前从 `bitfun-tool-packs` provider plan 物化内置工具列表,static-provider 安装 assembly、decorator reference、generic snapshot decorator adapter、provider-backed catalog runtime facade、readonly/enabled 过滤规则、provider-neutral tool path resolution / runtime artifact reference assembly、file guidance/freshness policy、oversized result rendering、tool execution presentation 与 path policy 判定已委托给 `bitfun-agent-tools` |
| `bitfun-tool-packs` | 由 feature group 隔离的工具 provider plan | partial:提供 basic / git / mcp / browser-web / computer-use / image-analysis / miniapp / agent-control feature-group 元数据和 product provider group plan;不得声明 concrete tools 已迁移 |
Expand Down Expand Up @@ -195,6 +195,30 @@ owner 边界,否则不要把一个 feature group 继续拆成更小的 crate
assistant-only 大结果;workspace `related_paths` 会进入 workspace service、remote/local
validation 与 request context prompt;request-context policy、prompt compression 与 cache-stable
assembly 也属于 agent runtime 行为。迁移这些 owner 前必须先同步文档、补保护测试并保留旧路径。
- 2026-05-28 latest main 进一步把 Task/subagent runtime 变成 fork-aware 语义:
`Task.fork_context=true` 会复用父会话 agent/workspace/tools/prompt cache,但禁止
`subagent_type`、`workspace_path`、`model_id` 与 DeepReview retry 字段,并且不再是并发安全
Task 调用。迁移 agent scheduler、subagent runtime、session branch 或 prompt-cache owner 前,
必须保留 delegation policy、forked context seeding、prompt cache clone、已有上下文 dialog turn
持久化和递归 subagent 禁止语义。`DialogTriggerSource`、`DialogQueuePriority`、
`DialogSubmissionPolicy` 与 `DialogSubmitOutcome` 已作为 runtime-port 契约,`DelegationPolicy` 与 `SubagentContextMode` 也已作为
DTO/decision primitive 迁入 `bitfun-runtime-ports`,core 保留旧路径 re-export;当前
boundary check 已锁定 fork-aware Task 启动回执、child delegation policy 和
`<background_task status="started" ...>` 结构化标记,防止后续 owner 迁移误删
assistant-visible delivery contract。
- 2026-05-28 latest main 还强化了工具可靠性边界:Write 内容生成会拒绝/清理
tool-invocation syntax,AskUserQuestion / TodoWrite 支持受限 truncation recovery,
`ToolRuntimeRestrictions` 支持 per-tool denial message,`tool_result_storage` 在返回前显式
flush 持久化文件。迁移 tool pipeline、concrete Write/Edit/Read/Task、runtime artifact 或
tool-result persistence 时,必须把这些行为作为等价 baseline,而不能只看类型是否可移动。
- MCP local stdio runtime 的 initialize 现在有局部 timeout、`notifications/initialized`
发送和 pending waiter drain;该 timeout 不应被误推广成所有 MCP tool/resource request 的
默认 request timeout。后续 MCP owner 迁移或服务集成收敛必须保留 initialize/request timeout
作用域、channel close cleanup 和 remote/local transport 差异。
- CLI package workflow / Homebrew notifier 与 mobile-web session search、rename、delete 已进入主干。
它们扩大了产品矩阵验证范围,但不改变 contract crate 归属:CLI TUI / packaging 仍在
`src/apps/cli` 和 CI workflow,mobile session 操作仍是 mobile product surface + 既有 session
API 的组合,不应下沉到 `core-types`、`runtime-ports`、`agent-tools` 或 service owner crate。
- 最新 Web 启动优化把 startup trace、deferred background scheduler、narrow tool initializer
与历史会话 hydrate 放在 web app / Flow Chat surface。后续不能为了“共享启动能力”把
`startupTrace`、`backgroundTaskScheduler`、history hydration 或 tool warmup 下沉到 core contract
Expand Down
52 changes: 51 additions & 1 deletion docs/plans/core-decomposition-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,41 @@ git diff -- package.json scripts/dev.cjs scripts/desktop-tauri-build.mjs scripts
streaming 都提高了 agent runtime / AI adapter 边界门槛;HR-C 与 AI/stream 相关工作不得把
provider-specific reasoning/tool-call schema 写入 provider-neutral manifest。

**2026-05-28 latest-main resync:**

- `TaskTool` 已支持 `fork_context=true`。该模式复用父会话 agent/workspace/tools/prompt cache,
但禁止 `subagent_type`、`workspace_path`、`model_id` 和 DeepReview retry 字段,并且
forked Task 不是并发安全调用。HR-C 迁移 scheduler/coordinator/subagent runtime/session branch
前,必须保护 delegation policy、forked context seeding、prompt cache clone、
`start_dialog_turn_with_existing_context` 和递归 subagent 禁止语义。
- `DialogTriggerSource` 已复用 `AgentSubmissionSource` 的 `bitfun-runtime-ports`
契约;`DialogQueuePriority`、`DialogSubmissionPolicy` 与 `DialogSubmitOutcome`
也已迁入 `bitfun-runtime-ports`。
`DelegationPolicy` 与 `SubagentContextMode` 已迁入 `bitfun-runtime-ports`,core
`agentic::subagent_runtime` 只保留旧路径 re-export 和 core-owned `queue_timing`。这一步
只移动 portable DTO/decision primitive,不移动 scheduler、coordinator、session branch、
prompt cache 或 background delivery runtime。
- 工具可靠性最新变化必须纳入 HR-A 或任何 tool pipeline 迁移 baseline:Write 内容生成会拒绝
tool-invocation syntax;AskUserQuestion / TodoWrite 只在安全边界恢复 truncation;
`ToolRuntimeRestrictions` 支持 per-tool denial message;`tool_result_storage` 写 runtime
artifact 后显式 flush,不能在 owner 迁移中退化为仅依赖 drop。
- MCP local stdio initialize timeout 已限定在 initialize 阶段,并补充
`notifications/initialized` 与 pending waiter drain。后续 MCP/service-integrations 迁移不得把
initialize timeout 扩散为普通 tool/resource request timeout,也不得丢失 channel close cleanup。
- CLI package workflow / Homebrew notifier 和 mobile-web session search / rename / delete
已进入产品矩阵。H5 或产品形态验证需要覆盖 `bitfun-cli`、CLI packaging 影响面和
`pnpm run build:mobile-web`;但 CLI TUI/packaging 与 mobile session UI 仍是 app surface,
不作为 core/service owner 外移前置条件。
- `scripts/check-core-boundaries.mjs` 已同步 latest-main 的 fork-aware Task 保护锚点:
`fork_context`、`SubagentContextMode::Fork`、child `DelegationPolicy` 传递、
`background_task_id` 与 `<background_task status="started" ...>` 启动回执均在 core
侧锁定,并禁止 core 重新定义已迁入 `runtime-ports` 的 dialog/subagent portable contract;
后续迁移 agent runtime 前必须先保留或替换这些等价保护。
- 同一 guardrail PR 也已把 prompt cache clone、existing-context dialog turn、tool-call
truncation recovery、per-tool denial message、tool-result file flush、MCP
initialize-scoped timeout、`notifications/initialized` 和 pending waiter drain 纳入
boundary check。后续 HR-A / HR-C / MCP 迁移不得绕过这些 latest-main 行为基线。

---

## 1. 当前问题与风险合集
Expand Down Expand Up @@ -1825,6 +1860,15 @@ contract、product-domain facade 与 H4 boundary closure 已分别闭环;后
`bitfun-core default = []`、per-product feature set、构建矩阵和 release 能力调整仍作为 H5 的独立评估;
不得与 HR-A/HR-B/HR-C 的 runtime owner 迁移混合。

2026-05-28 最新主干复核后,后续队列不新增零散 PR,但每个高风险主题的保护范围需要扩大:

- HR-A 若继续深迁 tool runtime,必须同时覆盖 Write sanitizer、AskUserQuestion/TodoWrite
truncation recovery、per-tool denial message 和 tool-result flush 行为。
- HR-C 若继续迁移 service/agent runtime,必须把 `fork_context`、prompt cache clone、
existing-context dialog turn、MCP initialize timeout scope 与 pending waiter drain 纳入等价测试。
- H5 若进入 feature/build-benefit 评估,必须把 CLI package workflow 和 mobile-web session
search/rename/delete 作为产品矩阵影响面,而不是只检查 desktop/server/core。

**低风险准备 PR 合并锁定(2026-05-19):**

后续不再把低风险准备工作拆成 4 个小 PR。当前 product-domain owner-helper PR
Expand Down Expand Up @@ -2143,7 +2187,7 @@ HR3:service / agent runtime deep owner migration 的主要风险和控制点
- 本次 rebase 到最新 `gcwing/main` 后,PR #719 remote workspace guard、#721 companion preset、#715/#722 ACP fallback/timeout、PR #766 ACP config reuse、PR #774 usage/cache 与 Responses schema 修复、PR #776 desktop close-to-tray 默认值、per-mode subagent availability、DeepResearch citation renumber hook 和 search fallback/context 修复均已进入主干;它们不改变当前文档护栏 PR 的代码行为,但会把后续 workspace/search、agent registry/runtime、ACP/Web surface、AI usage/adapter 与 tool runtime 外移的等价性门槛抬高。
- 质量边界:本阶段证明已拆 owner crate 不依赖回 `bitfun-core`,并新增关键语义 baseline 约束 MCP config failure / catalog replacement invalidation / dynamic manifest、tool manifest / `GetToolSpec` collapsed exposure、MiniApp storage layout adapter 等价和 remote search scan-fallback retry gate;不声明 remote connect、`ToolUseContext`、concrete tool implementation、MiniApp IO / worker runtime 或 function-agent runtime 的外移完成。
- boundary check 已扩展到 `core-types`、`runtime-ports` 和 `agent-tools` 的轻量边界,并覆盖 Cargo inline 依赖和 dependency table 依赖声明,后续不能绕过脚本把重 runtime、concrete service、platform adapter 或 CLI/TUI presentation 依赖带入这些 contract crate。
- boundary check 现在锁定已纳入脚本的 latest-main owner anchor:mode-scoped subagent availability、`Multitask` / `GeneralPurpose` registration、background subagent delivery、CLI subagent management surface、DeepResearch citation renumber hook、remote workspace startup guard、local/remote search fallback、ACP startup timeout、Web startup/history hydration、Web operation diff fallback 和 built-in MiniApp seed/update path。2026-05-19 新增识别的 remote ACP config reuse、AI usage/cache semantics、Responses flat tool schema adapter boundary 与 desktop close-to-tray surface 先作为后续迁移的复核清单;真正迁移这些 owner 时必须补 port/provider 或 surface contract 设计,并同步更新脚本与等价测试。
- boundary check 现在锁定已纳入脚本的 latest-main owner anchor:mode-scoped subagent availability、`Multitask` / `GeneralPurpose` registration、fork-aware Task start acknowledgement / delegation policy、background subagent delivery、CLI subagent management surface、DeepResearch citation renumber hook、remote workspace startup guard、local/remote search fallback、ACP startup timeout、Web startup/history hydration、Web operation diff fallback 和 built-in MiniApp seed/update path。2026-05-19 新增识别的 remote ACP config reuse、AI usage/cache semantics、Responses flat tool schema adapter boundary 与 desktop close-to-tray surface 先作为后续迁移的复核清单;真正迁移这些 owner 时必须补 port/provider 或 surface contract 设计,并同步更新脚本与等价测试。
- boundary check 也已锁定 `bitfun-core::service::git`、`bitfun-core::service::remote_ssh::types`、remote-SSH workspace path/identity/unresolved-key helper、MiniApp storage layout、`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、auth error classifier 和 legacy remote header fallback helper,也禁止在 remote transport 重新实现 Authorization 归一化、client capability 构造和 rmcp result mapping;本轮新增禁止 core registry 重新拥有 `IndexMap` 工具容器或 dynamic metadata map。
- 后续迁移必须拆成可独立审核的提交:先补 port/provider 设计和等价测试;`remote-connect` 完整 runtime、`ToolUseContext` / concrete tool implementation、product-domain runtime 必须一次迁移一个 owner 主题。
- concrete tool implementation 或 product registry / manifest assembly 外移必须先有工具清单和 manifest 等价测试,并保留 dynamic provider metadata;不能把注册名解析、snapshot wrapper 或 runtime restriction 行为改成隐式约定。
Expand All @@ -2159,8 +2203,10 @@ HR3:service / agent runtime deep owner migration 的主要风险和控制点
```powershell
node scripts/check-core-boundaries.mjs
cargo check -p bitfun-core --features product-full
cargo check -p bitfun-cli
cargo test --workspace
cargo build -p bitfun-desktop
pnpm run build:mobile-web
pnpm run desktop:build:fast
pnpm run desktop:build:release-fast
git diff -- package.json scripts/dev.cjs scripts/desktop-tauri-build.mjs scripts/ensure-openssl-windows.mjs scripts/ci/setup-openssl-windows.ps1 BitFun-Installer
Expand Down Expand Up @@ -2372,6 +2418,10 @@ subagent visibility、background delivery、DeepResearch citation renumber hook

- 可迁移只读 facts、queue/restore decision、remote workspace DTO、workspace/session response
assembly helper、port/provider contract 和 core adapter binding。
- 已迁移的低风险 contract:dialog submission source / priority / policy / outcome、
subagent context mode 与 delegation policy 归属 `bitfun-runtime-ports`;core 旧路径只作为兼容 re-export。queue wait timer 因依赖
`Instant` / `Duration` 且服务 DeepReview admission timing,仍保留 core-owned,后续若外移需
单独证明不是把 runtime state 放入 DTO/trait crate。
- concrete scheduler/session restore、workspace-root source、persistence/workspace service reads、
`ImageContextData` concrete impl、remote-SSH runtime、terminal adapter、agent registry/scheduler、
goal-mode coordinator binding、request-context assembly 与 prompt compression runtime 继续
Expand Down
Loading
Loading