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
12 changes: 6 additions & 6 deletions AGENTS-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ BitFun 是一个由 Rust workspace 与共享 React 前端组成的项目。
| 产品领域 crate | `src/crates/product-domains` | [AGENTS.md](src/crates/product-domains/AGENTS.md) |
| Transport 适配层 | `src/crates/transport` | (使用 core 指南) |
| API layer | `src/crates/api-layer` | (使用 core 指南) |
| ACP 集成 | `src/crates/acp` | [AGENTS.md](src/crates/acp/AGENTS.md) |
| AI adapters | `src/crates/ai-adapters` | [AGENTS.md](src/crates/ai-adapters/AGENTS.md) |
| 桌面应用 | `src/apps/desktop` | [AGENTS.md](src/apps/desktop/AGENTS.md) |
| Server | `src/apps/server` | (使用 core 指南) |
Expand Down Expand Up @@ -114,14 +115,13 @@ await api.invoke('your_command', { request: { ... } });
任何 `bitfun-core` 拆解、feature 边界、依赖边界或 Rust 构建提速重构,
都必须先阅读
[`docs/architecture/core-decomposition.md`](docs/architecture/core-decomposition.md)。
该文档定义产品行为不变量、crate 归属目标、禁止依赖方向、feature 安全规则和里程碑验证门禁
顶层文档只作为入口;模块级 ownership 细节应放到离代码最近的模块 `AGENTS.md`

### Tool 归属护栏
仓库级拆解规则:

- `src/crates/agent-tools` 拥有轻量 tool contract,以及 generic registry / dynamic-provider container。
- `src/crates/core/src/agentic/tools` 当前负责产品工具组装、`dyn Tool` 适配、snapshot decoration、tool exposure / manifest resolution,以及按需工具说明发现(`GetToolSpec`)。
- `ToolUseContext` 与具体工具实现继续留在 core,直到有已评审的 port/provider 设计和等价测试。
- Tool 迁移必须保持 expanded/collapsed exposure、prompt 可见 manifest、`ToolUseContext.unlocked_collapsed_tools`,以及 desktop/MCP/ACP tool catalog 行为等价。
- 不要把 DTO / contract 抽取误判为 runtime owner 已迁移。
- 产品表面可以有差异;共享稳定 facts 或 ports,不共享 UI、protocol、lifecycle 或平台实现。
- 迁移 runtime owner 必须有评审过的 port/provider 设计、旧路径兼容、行为等价测试;如果可能改变行为边界,还需要先确认。

### DeepReview 护栏

Expand Down
89 changes: 12 additions & 77 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Repository rule: **keep product logic platform-agnostic, then expose it through
| Product domains | `src/crates/product-domains` | [AGENTS.md](src/crates/product-domains/AGENTS.md) |
| Transport adapters | `src/crates/transport` | (use core guide) |
| API layer | `src/crates/api-layer` | (use core guide) |
| ACP integration | `src/crates/acp` | [AGENTS.md](src/crates/acp/AGENTS.md) |
| AI adapters | `src/crates/ai-adapters` | [AGENTS.md](src/crates/ai-adapters/AGENTS.md) |
| Desktop app | `src/apps/desktop` | [AGENTS.md](src/apps/desktop/AGENTS.md) |
| Server | `src/apps/server` | (use core guide) |
Expand Down Expand Up @@ -114,83 +115,17 @@ await api.invoke('your_command', { request: { ... } });
For any `bitfun-core` decomposition, feature-boundary, dependency-boundary, or
Rust build-speed refactor, read
[`docs/architecture/core-decomposition.md`](docs/architecture/core-decomposition.md)
before editing. The guardrail document defines product-behavior invariants,
crate ownership targets, forbidden dependency directions, feature safety rules,
and milestone verification gates.

### Tool ownership guardrails

- `src/crates/agent-tools` owns lightweight tool contracts, portable tool
context facts/provider contracts, pure manifest/exposure contracts, and
generic registry / static-provider / dynamic-provider container contracts.
- `src/crates/tool-packs` may expose planned tool-pack feature-group scaffold
metadata, but it must not own concrete tool implementations or product
manifest runtime until a reviewed provider migration exists.
- `src/crates/core/src/agentic/tools` owns product tool provider assembly
(`static_providers.rs`), `dyn Tool` adaptation, snapshot decoration, runtime
manifest assembly / context filtering, and on-demand tool spec discovery
execution (`GetToolSpec`) for now.
- Keep `ToolUseContext` and concrete tool implementations in core until a
reviewed port/provider design and equivalence tests exist. A portable
`ToolContextFacts` projection via `PortableToolContextProvider` may cross
crate boundaries, but runtime handles and service objects must stay in core.
- Tool migrations must preserve expanded/collapsed exposure, prompt-visible
manifests, `ToolUseContext.unlocked_collapsed_tools`, and desktop/MCP/ACP
tool catalog behavior.

### Latest-main runtime anchors

- Agent registry migration must preserve mode-scoped subagent availability,
hidden/custom/review grouping, desktop subagent API semantics, and CLI
mode-aware `/subagents` list/config behavior, including `Multitask` mode
and the built-in `GeneralPurpose` subagent.
- Background subagent task delivery remains core agent-runtime behavior:
`Task.run_in_background` must preserve parent metadata, workspace routing,
running-turn injection, and idle-session follow-up turn delivery.
- DeepResearch report finalization currently relies on the core citation
renumber hook; do not move it without preserving `report.md`,
`citations.md`, `display_map.json`, and rejected-citation handling.
- Workspace/search refactors must preserve remote workspace startup guards,
remote flashgrep fallback, and search preview/context mapping.
- ACP timeout handling and Web operation-diff fallback are product-surface
behavior; share facts through contracts, not UI/protocol implementation.
- Web startup trace, deferred background scheduling, narrow tool startup, and
non-blocking Flow Chat history hydration are Web product-surface behavior;
do not move those orchestration paths into core contract crates.
- Built-in MiniApp seeding, content-hash update markers, customization-update
metadata, and host dispatch execution remain core-owned runtime behavior
until a reviewed MiniApp runtime migration exists.

### Services/product owner closure

- Remote-SSH path, session identity, mirror path, and unresolved-session layout
helpers belong in `bitfun-services-integrations`; core may inject
`PathManager` and hold SSH manager / remote FS / terminal assembly.
- MiniApp storage/draft/import file shape, import fallback payload, lifecycle
state-transition helpers, runtime search-plan helpers, customization metadata
policy including built-in update/decline decisions, and function-agent pure
prompt/diff preparation helpers belong in `bitfun-product-domains`; core
keeps filesystem IO, worker runtime, built-in source-hash lookup,
`PathManager`, Git/AI calls, prompt templates, JSON extraction, error
mapping, and port adapters until reviewed runtime migrations exist.
Before moving those runtime owners, keep the core-owned MiniApp manager and
function-agent Git/AI boundary snapshots passing.
- Remote-connect port baselines live in `bitfun-runtime-ports` and
`bitfun-services-integrations`; tracker state and tracker event reduction
belong in `bitfun-services-integrations`. Remote command/response wire DTOs,
remote model catalog DTOs, poll-response assembly helpers, and model-catalog
poll delta policy also belong there. Pure remote image-context
fallback/preference, restore-target, cancel-decision, and remote file-transfer
size/chunk/name helpers also belong in `bitfun-services-integrations`, while
core still owns the adapter back to `ImageContextData`, dispatcher assembly,
session restore execution, file IO/path resolution, terminal pre-warm, and
product execution routing. Further remote runtime owner migration must
preserve the existing migration snapshots for command/response shape,
restore, active-turn polling, cancel decisions, image context
fallback/preference, tracker fanout, file transfer, and RemoteRelay/Bot queue
policy.
`AgentSubmissionPort` still rejects generic attachments until
image/multimodal equivalence tests and a runtime migration plan are reviewed.
before editing. Keep this file as an entry point; put module-specific ownership
details in the nearest module `AGENTS.md`.

Repository-level decomposition rules:

- Do not confuse DTO/contract extraction with runtime owner migration.
- Product surfaces may diverge; share stable facts or ports, not UI, protocol,
lifecycle, or platform implementation.
- Moving runtime ownership requires a reviewed port/provider design, old-path
compatibility, behavior equivalence tests, and explicit confirmation when a
behavior boundary could change.

### DeepReview guardrails

Expand Down
23 changes: 21 additions & 2 deletions docs/architecture/core-decomposition.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,26 @@ owner 边界,否则不要把一个 feature group 继续拆成更小的 crate
- ACP startup timeout 和 operation diff fallback 属于 ACP/Web product surface 行为;后续只能通过
stable contract 共享事实,不得把 ACP timeout、tool diff fallback 或 Web diff rendering 下沉到
core-types、runtime-ports、agent-tools 等 contract crate。
- 最新主干的 remote ACP agents config 继续强化 ACP/app adapter owner:remote workspace
复用 local ACP config,并通过 ACP client manager、remote shell、remote capability store 与
workspace menu 串联。后续只能把 environment / capability facts 抽成 contract;ACP config
persistence、remote probing 和 workspace surface selection 仍留在 ACP/app surface。
- 最新主干的 usage/cache 与 OpenAI Responses 修复提高了 AI adapter / stream 迁移门槛。
`cached_content_token_count` 表示 cache reads / hits,`cache_creation_token_count` 与
DeepSeek `prompt_cache_hit_tokens` mapping 必须保留为独立语义,不能在 `agent-stream`、
`session_usage` 或 runtime budget 迁移中重新合并为 total usage。OpenAI Responses /
Codex ChatGPT flat tool schema 是 provider adapter serialization,不应写死进
`bitfun-agent-tools` 的 provider-neutral manifest contract。
- 最新 Web 启动优化把 startup trace、deferred background scheduler、narrow tool initializer
与历史会话 hydrate 放在 web app / Flow Chat surface。后续不能为了“共享启动能力”把
`startupTrace`、`backgroundTaskScheduler`、history hydration 或 tool warmup 下沉到 core contract
crate;只能通过 product checks 证明 app 仍可组装。
- 最新 CLI 重构新增大量 TUI、theme、selector、dialog 和 chat-state 代码,但仍位于
`src/apps/cli`。后续 core decomposition 只能通过产品 check 验证 CLI 仍可组装,不应把
CLI presentation 依赖迁入 core-types、runtime-ports 或 agent-tools。
- 最新 desktop close button 默认最小化到 system tray 是 desktop lifecycle surface 行为;
后续若调整 desktop app lifecycle / window state,只能用 desktop product check 验证,
不应把 close/minimize 策略抽入 shared core service。
- Tool framework crate 不得依赖 concrete service implementation。
- 产品 crate 可以通过显式 product feature 组装完整 runtime。
- 后续迁移必须先按风险分层处理:
Expand Down Expand Up @@ -223,11 +236,11 @@ owner 边界,否则不要把一个 feature group 继续拆成更小的 crate
- 已合入的 semantic baseline 已补 config failure、catalog replacement invalidation、沿用既有 list-changed
helper baseline、dynamic manifest order/metadata、tool manifest / `GetToolSpec`、MiniApp storage layout
adapter 等价和 remote search fallback gate;这些都是 behavior-locking tests,不移动 runtime owner。
- 当前 tool manifest contract closure PR 只把 `ToolExposure`、`GetToolSpec` 名称、纯 manifest
- 已合入的 tool manifest contract closure 只把 `ToolExposure`、`GetToolSpec` 名称、纯 manifest
policy、collapsed prompt stub 与 prompt-visible ordering 归入 `bitfun-agent-tools`,并让 core
runtime manifest resolver 委托这些纯 helper;不迁移 `ToolUseContext`、registry snapshot、
context-aware schema/description、`GetToolSpecTool` 执行、unlock state 或 concrete tool implementation。
该 PR 闭环后,后续不应再插入 baseline-only PR 才开始 runtime owner 迁移;下一组 PR 应直接以
该阶段闭环后,后续不应再插入 baseline-only PR 才开始 runtime owner 迁移;下一组 PR 应直接以
单一 owner 为单位移动实际 runtime,并沿用本节等价测试和边界脚本。
- 已合入的 `Services/Product Runtime Owner Closure` 只收口已经有 port/contract 保护的低风险 owner:
remote-SSH session identity / mirror path / unresolved-session layout 归属
Expand All @@ -241,6 +254,12 @@ owner 边界,否则不要把一个 feature group 继续拆成更小的 crate
function-agent staged diff snapshot、AI response JSON extraction 与 error mapping
仍被记录为 core-owned 行为。后续若继续移动这些 runtime owner,必须以这些快照为
行为等价基线。
- 当前 `product-domains` runtime port/facade closure 只迁移 port-backed owner
orchestration:MiniApp 的 deps/restart/recompile/sync/rollback 状态持久化可经
storage facade 执行,function-agent commit / work-state facade 可基于 Git/AI port
组装结果。core 仍持有 MiniApp filesystem IO、compiler 调度、worker process、host
dispatch、built-in seed/update,以及 function-agent Git/AI service、prompt template、
JSON extraction 和 error mapping;现有 function-agent 产品路径尚未切到新 facade。

## 产品表面边界(Product Surface Boundary)

Expand Down
Loading
Loading