From 7dd07ecc62e4d630d6b71ebb8211d3c21b672d53 Mon Sep 17 00:00:00 2001 From: Bob Lee Date: Tue, 10 Nov 2026 11:06:47 +0800 Subject: [PATCH 1/4] docs(agents): complete the layer guide crate tables Each layer guide owns its crate table. Bring the tables in line with the workspace: - adapters: add opencode-plugin-host. - adapters (CN): add miniapp-ipc, opencode-plugin-host, dsh-adapter, pi-adapter, claude-code-adapter, codex-adapter, zcode-adapter and static-hook-support; refresh opencode-adapter and transport. - services (CN): add legacy-migration-adapters, miniapp-market-service and skin-market-service; refresh services-core, services-integrations and the legacy-migration guide link. - contracts (CN): add config-contracts. --- src/crates/adapters/AGENTS-CN.md | 12 ++++++++++-- src/crates/adapters/AGENTS.md | 1 + src/crates/contracts/AGENTS-CN.md | 1 + src/crates/services/AGENTS-CN.md | 9 ++++++--- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/crates/adapters/AGENTS-CN.md b/src/crates/adapters/AGENTS-CN.md index df795e0ad6..46bfd09e9c 100644 --- a/src/crates/adapters/AGENTS-CN.md +++ b/src/crates/adapters/AGENTS-CN.md @@ -9,10 +9,18 @@ | Crate | 职责 | 本地文档 | |---|---|---| | `agent-runtime-ipc` | 不发布的私有本机 IPC adapter,为可选的第一方 Shared TUI Runtime 提供封闭交互操作 | [AGENTS.md](agent-runtime-ipc/AGENTS.md) | +| `miniapp-ipc` | Desktop 与轻量 MiniApp Shell 共用的私有本机启动记录、有界分帧和发现;不承载执行 owner | [AGENTS.md](miniapp-ipc/AGENTS.md) | | `ai-adapters` | AI provider 请求/响应 adapter 与 stream protocol glue | [AGENTS.md](ai-adapters/AGENTS.md) | -| `opencode-adapter` | OpenCode Command、standalone Tool 和 Subagent 实时 provider 的生态语义;受管包静态预览 | [AGENTS.md](opencode-adapter/AGENTS.md) | +| `opencode-adapter` | OpenCode 用户 Instructions 的来源语义,以及实时 Command、standalone Tool、Subagent、MCP 和静态 Hook provider;受管包静态预览 | [AGENTS.md](opencode-adapter/AGENTS.md) | +| `opencode-plugin-host` | 连接 OpenCode extension-host 进程的私有分帧 loopback JSON-RPC transport,以及 OpenCode Client 路由匹配、wire DTO 和协议错误映射;不负责产品配置选择、workspace/session 策略或插件信任决策 | [AGENTS.md](opencode-plugin-host/AGENTS.md) | +| `dsh-adapter` | DeepSeek Harness(`dsh`)bundle/profile 投影、静态 Hook bridge 发现和显式 MCP 声明 | [AGENTS.md](dsh-adapter/AGENTS.md) | +| `pi-adapter` | PI settings/package 扩展选择和静态原生事件发现;不执行 | [AGENTS.md](pi-adapter/AGENTS.md) | +| `claude-code-adapter` | 不含 runtime 的 Claude Code 用户 Instructions、Command、Subagent、MCP 和 Hook 来源语义,投影经脱敏 | [AGENTS.md](claude-code-adapter/AGENTS.md) | +| `codex-adapter` | 不含 runtime 的 Codex 用户 Instructions、Subagent、MCP 和 Hook 来源语义,投影经脱敏 | [AGENTS.md](codex-adapter/AGENTS.md) | | `cursor-adapter` | 只读 Cursor CLI 快照、Desktop composer 和回退 JSONL 会话历史 | [AGENTS.md](cursor-adapter/AGENTS.md) | -| `transport` | Event transport emitter 与宿主 transport adapter | [AGENTS.md](transport/AGENTS.md) | +| `zcode-adapter` | 只读 Zcode SQLite 任务发现和会话历史转换 | [AGENTS.md](zcode-adapter/AGENTS.md) | +| `static-hook-support` | 各生态 adapter 共用的有界、脱敏静态来源工具和 JSON/TOML Hook 解析器;不含生态策略或 runtime | 继承本指南 | +| `transport` | Event transport adapter,以及当前各宿主共用的协议中立有界 JSON 编码和 TypeScript message/JSON-RPC 机制 | [AGENTS.md](transport/AGENTS.md) | | `webdriver` | Embedded WebDriver protocol 与浏览器自动化 adapter | [AGENTS.md](webdriver/AGENTS.md) | ## 放置规则 diff --git a/src/crates/adapters/AGENTS.md b/src/crates/adapters/AGENTS.md index d114c3f974..14fa9d9dc2 100644 --- a/src/crates/adapters/AGENTS.md +++ b/src/crates/adapters/AGENTS.md @@ -15,6 +15,7 @@ services. | `miniapp-ipc` | Private local launch records, bounded framing and discovery shared by Desktop and the lightweight MiniApp Shell; no execution owners | [AGENTS.md](miniapp-ipc/AGENTS.md) | | `ai-adapters` | AI provider request/response adapters and stream protocol glue | [AGENTS.md](ai-adapters/AGENTS.md) | | `opencode-adapter` | OpenCode source semantics for user Instructions plus the live Command, standalone Tool, Subagent, MCP, and static Hook providers; managed-package static preview | [AGENTS.md](opencode-adapter/AGENTS.md) | +| `opencode-plugin-host` | Private framed loopback JSON-RPC transport to the OpenCode extension-host process, plus OpenCode Client route matching, wire DTOs, and protocol error mapping; no product configuration selection, workspace/session policy, or plugin trust decisions | [AGENTS.md](opencode-plugin-host/AGENTS.md) | | `dsh-adapter` | DeepSeek Harness (`dsh`) bundle/profile projection, static Hook bridge discovery and explicit MCP declarations | [AGENTS.md](dsh-adapter/AGENTS.md) | | `pi-adapter` | PI settings/package extension selection and static native event discovery; no execution | [AGENTS.md](pi-adapter/AGENTS.md) | | `claude-code-adapter` | Runtime-free Claude Code user Instructions, Command, Subagent, MCP, and Hook source semantics with redacted projection | [AGENTS.md](claude-code-adapter/AGENTS.md) | diff --git a/src/crates/contracts/AGENTS-CN.md b/src/crates/contracts/AGENTS-CN.md index 1ed5ce489b..200a60d0e0 100644 --- a/src/crates/contracts/AGENTS-CN.md +++ b/src/crates/contracts/AGENTS-CN.md @@ -9,6 +9,7 @@ | Crate | 职责 | 本地文档 | |---|---|---| | `core-types` | 共享 DTO、错误、session/surface 数据和小型 value type | [AGENTS.md](core-types/AGENTS.md) | +| `config-contracts` | 持久化配置记录、默认值、校验和纯模型转换 | [AGENTS.md](config-contracts/AGENTS.md) | | `events` | 事件 payload 和 emitter 契约 | [AGENTS.md](events/AGENTS.md) | | `product-domains` | 产品领域 DTO、规则、策略和窄 port | [AGENTS.md](product-domains/AGENTS.md) | | `runtime-ports` | runtime owner crate 使用的 trait 和 port | [AGENTS.md](runtime-ports/AGENTS.md) | diff --git a/src/crates/services/AGENTS-CN.md b/src/crates/services/AGENTS-CN.md index 96d9a53f66..cf6d9980be 100644 --- a/src/crates/services/AGENTS-CN.md +++ b/src/crates/services/AGENTS-CN.md @@ -9,9 +9,12 @@ | Crate | 职责 | 本地文档 | |---|---|---| | `computer-use` | Desktop 与 CLI 共用的原生截图、无障碍、输入、权限和控制会话服务 | [AGENTS.md](computer-use/AGENTS.md) | -| `services-core` | 不包含产品组装决策的本地 service primitive,包括 session storage、metadata store CRUD/index rebuild、metadata 构造/计数/索引/字段 mutation、lineage 规则和 JSON file IO | [AGENTS.md](services-core/AGENTS.md) | -| `services-integrations` | MCP、git、remote、file watch、MiniApp runtime、产品领域 port 具体实现,以及平台无关的 Remote Connect primitives | [AGENTS.md](services-integrations/AGENTS.md) | -| `legacy-migration` | 离线旧产品发现、加锁、一致性 SQLite 快照、暂存、journal 恢复和 owner adapter 编排 | — | +| `services-core` | 不包含产品组装决策的可复用本地 service primitive,包括进程级 TLS provider 选择、受管进程树生命周期、filesystem helper、session storage 布局/索引/删除、metadata store CRUD/index rebuild、metadata 构造/计数/索引/字段 mutation/lineage 规则和 JSON file IO | [AGENTS.md](services-core/AGENTS.md) | +| `services-integrations` | MCP、git、remote、file watch、MiniApp runtime、review-platform provider service、产品领域 port 具体实现,以及平台无关的 Remote Connect primitives | [AGENTS.md](services-integrations/AGENTS.md) | +| `legacy-migration-adapters` | 面向共享配置/存储 owner 的离线旧数据转换器,不依赖 Core | [AGENTS.md](legacy-migration-adapters/AGENTS.md) | +| `legacy-migration` | 离线旧产品发现、加锁、一致性 SQLite 快照、暂存、journal 恢复和 owner adapter 编排 | [AGENTS.md](legacy-migration/AGENTS.md) | +| `miniapp-market-service` | MiniApp market 的具体 SQLite、artifact 存储、GitHub OAuth、包校验和 HTTP 行为 | [README.md](miniapp-market-service/README.md) | +| `skin-market-service` | Skin market 的具体 SQLite、artifact 存储、Appearance 包校验、审核和 HTTP 行为 | [README.md](skin-market-service/README.md) | | `relay-service` | standalone 与 embedded 宿主共享的 Remote Connect relay 状态、存储及 HTTP/WebSocket 路由 | [AGENTS.md](relay-service/AGENTS.md) | | `page-function-runtime` | OpenBitFun Pages 嵌入式 JS Page Function runtime(rquickjs) | [AGENTS.md](page-function-runtime/AGENTS.md) | | `terminal` | PTY、shell integration 与 terminal session infrastructure | [AGENTS.md](terminal/AGENTS.md) | From da3fe6395514f26b8f02cbb1947396c4f5ea68d7 Mon Sep 17 00:00:00 2001 From: Bob Lee Date: Tue, 10 Nov 2026 11:06:47 +0800 Subject: [PATCH 2/4] docs(agents): slim the root guide and move hook ownership to its owners The root guide is loaded into every agent conversation, so it now keeps only cross-cutting rules and stable entry points (384 -> 193 lines). - The layer table drops its per-layer crate list, which had drifted from the workspace, and gains a "Must not" column that replaces the separate boundary-rule list. Layer guides own the crate tables. - Rust dependency rules move from "Quick start" into their own section. - The architecture guardrail sections become one "Read before changing" list with the hard constraints attached to each entry. - Surface-specific detail already owned by a nearer guide is removed, such as the Web UI i18n namespace rule. - AGENTS-CN.md now mirrors AGENTS.md line for line. Native hook engine, registry, hook-source and dispatch ownership moves to the agent-runtime and core guides, next to the code. They name the actual RuntimeHookRegistry type and describe the separate remote-workspace registry. The root guide keeps the Codex contract rule and one pointer. Also close an unterminated code fence in the agent-runtime guide. --- AGENTS-CN.md | 366 ++++++--------- AGENTS.md | 461 ++++++------------- src/crates/assembly/core/AGENTS-CN.md | 7 + src/crates/assembly/core/AGENTS.md | 16 + src/crates/execution/agent-runtime/AGENTS.md | 24 + 5 files changed, 314 insertions(+), 560 deletions(-) diff --git a/AGENTS-CN.md b/AGENTS-CN.md index 3d42b0a173..728091f1fb 100644 --- a/AGENTS-CN.md +++ b/AGENTS-CN.md @@ -2,119 +2,68 @@ # AGENTS-CN.md -OpenBitFun 是一个由 Rust workspace 与 React 前端组成的项目。 +OpenBitFun 由 Rust workspace 与 React 前端组成,通过多种宿主交付(Desktop/Tauri、CLI/TUI、server、mobile、mobile-web、installer)。 仓库核心原则:**先保持产品逻辑平台无关,再通过平台适配层对外暴露能力**。 -## 快速开始 +## 规则在哪里 -1. 在修改架构敏感代码前,先阅读 `README.md` 和 `CONTRIBUTING.md`。 -2. 日常开发使用下方主要产品循环;surface 专属的替代命令由最近的应用指南维护。 -3. 修改 Rust 文件后,优先使用 `pnpm run fmt:rs`,只格式化已改动或已暂存的 `.rs` 文件。只有在你明确需要更大范围格式化时才使用 `cargo fmt`。 -4. 改完后从离改动最近的 `AGENTS.md` 选择 focused 验证命令;下方仓库级验证章节只维护跨模块检查原则。 -5. Rust workspace 依赖应在根清单中统一版本,而由消费 crate 按自身职责声明所需 feature;仅测试所需的 feature 应放入 `dev-dependencies`,受 crate feature 控制的服务能力应只在对应 feature 中启用。第三方依赖的默认 feature 若不是所有 consumer 的稳定契约,应在 `[workspace.dependencies]` 统一关闭,成员只增加自身需要的切片。仓内 crate 的 `default` 已由边界契约保证为空时,不在每条依赖边重复写 `default-features = false`;ACP 这类有意保留兼容默认的 crate 仍由窄 consumer 显式关闭。被单独复制到 Docker 构建上下文的 manifest 无法继承 workspace 根,必须继续维护显式版本和默认策略。禁止使用 `tokio/full` 绕过依赖边界设计。 +- 本文件维护仓库级规则。离改动文件最近的 `AGENTS.md` 负责局部边界、命令和 focused 验证;与本文件冲突时,以更近的指南为准。 +- 提交与 PR 约定见 [`CONTRIBUTING_CN.md`](CONTRIBUTING_CN.md)。 -## 分层模块索引 +## 分层 -依赖关系按自上而下读取。下表是物理 crate 布局,不是完整概念架构;Product Surface、Product Assembly、 -Product Feature、Agent Kernel、Execution、Extension、Cross-platform Adapter、 -Stable Contracts and Security Control Plane 的边界以 -[`docs/architecture/product-architecture.md`](docs/architecture/product-architecture.md) -为准。同层 crate 也应保持最小依赖。 +依赖方向自上而下:crate 可以依赖更低层,不得依赖更高层,同层依赖保持最小。各层指南列出该层的 crate 和确切允许的依赖边。下表是物理 crate 布局;概念架构(4+1 视图)见 [`docs/architecture/product-architecture.md`](docs/architecture/product-architecture.md)。 -| # | 层级 | 路径 | 职责 | 模块 / 入口 | 层级文档 | +| # | 层级 | 路径 | 负责 | 不得 | 指南 | |---|---|---|---|---|---| -| 1 | 接口与入口层 | `src/apps/*`, `src/web-ui`, `src/mobile-web`, `OpenBitFun-Installer`, `tests/e2e`, `src/crates/interfaces` | 产品宿主、命令、UI 入口、协议接口和跨形态测试 | desktop、CLI、server、relay、Web UI、mobile web、installer、E2E、`acp`、`sdk-host` | 最近的本地 `AGENTS.md`;[interfaces](src/crates/interfaces/AGENTS.md) | -| 2 | 产品组装层 | `src/crates/assembly` | 兼容导出、产品能力选择、product-full 接线、不可变内置 Agent 内容、adapter/service 注册和生态无关的来源协调 | `agent-content`, `core`, `external-sources`, `product-capabilities` | [AGENTS.md](src/crates/assembly/AGENTS.md) | -| 3 | 适配层 | `src/crates/adapters` | AI/transport/WebDriver 协议 adapter、外部 AI work source adapter(OpenCode/Claude Code/Codex/Zcode)和外部 provider 转换 | `agent-runtime-ipc`、`ai-adapters`, `opencode-adapter`, `claude-code-adapter`, `codex-adapter`, `zcode-adapter`, `static-hook-support`, `transport`, `webdriver` | [AGENTS.md](src/crates/adapters/AGENTS.md) | -| 4 | 服务实现层 | `src/crates/services` | 可复用 OS、filesystem、terminal、MCP、remote、git、watch、process、session persistence primitives、network 和 MiniApp runtime IO 实现 | `services-core`, `services-integrations`, `computer-use`, `relay-service`, `page-function-runtime`, `terminal` | [AGENTS.md](src/crates/services/AGENTS.md) | -| 5 | 执行原语层 | `src/crates/execution` | 可移植 Agent Runtime、命名工作流策略、stream、插件运行时客户端、typed-service、tool-contract、tool-group 和 tool-execution 构件 | `agent-runtime`, `agent-workflows`, `agent-stream`, `tool-contracts`, `plugin-runtime-client`, `runtime-services`, `tool-provider-groups`, `tool-execution` | [AGENTS.md](src/crates/execution/AGENTS.md) | -| 6 | 稳定契约与产品领域层 | `src/crates/contracts` | 跨层共享 DTO、事件形状、runtime port、产品领域契约和策略 | `core-types`, `events`, `runtime-ports`, `product-domains` | [AGENTS.md](src/crates/contracts/AGENTS.md) | +| 1 | 接口与入口层 | `src/apps/*`, `src/web-ui`, `src/mobile-web`, `src/*-market-web`, `OpenBitFun-Installer`, `tests/e2e`, `src/crates/interfaces` | 产品宿主、命令、UI 入口、协议接口和跨形态测试 | 保留可复用行为;应下移 | 最近的本地 `AGENTS.md`;[interfaces](src/crates/interfaces/AGENTS.md) | +| 2 | 产品组装层 | `src/crates/assembly` | 兼容导出、产品能力选择、product-full 接线、不可变内置 Agent 内容、adapter/service 注册和生态无关的来源协调 | 实现具体 adapter、OS 或 service 细节 | [AGENTS.md](src/crates/assembly/AGENTS.md) | +| 3 | 适配层 | `src/crates/adapters` | 协议、transport、本地 IPC、WebDriver、AI provider 和外部 AI work source 的 adapter;外部 provider 转换 | 拥有产品能力选择或可复用 OS service 行为 | [AGENTS.md](src/crates/adapters/AGENTS.md) | +| 4 | 服务实现层 | `src/crates/services` | 可复用的 OS、filesystem、terminal、MCP、remote、git、watch、process、network、session persistence 和 MiniApp runtime IO 实现 | 拥有协议/transport 投影或产品能力选择 | [AGENTS.md](src/crates/services/AGENTS.md) | +| 5 | 执行原语层 | `src/crates/execution` | 可移植 Agent Runtime、命名工作流策略、stream、插件运行时客户端、typed-service、tool-contract、tool-group 和 tool-execution 构件 | 拥有宿主专属或交付形态行为 | [AGENTS.md](src/crates/execution/AGENTS.md) | +| 6 | 稳定契约与产品领域层 | `src/crates/contracts` | 跨层共享 DTO、事件形状、runtime port、产品领域契约和策略 | 承载运行时行为或向上依赖 | [AGENTS.md](src/crates/contracts/AGENTS.md) | -边界规则: +- 产品特性只组装用户侧命令、UI contribution、设置和默认策略。长程任务、scheduler、permission、session/workspace、memory、DFX、hook 和 event 事实留在各自既有的 owner。 +- 外部系统是边界资源,不是层级。只有已注册的 adapter、service 或 app-local provider 可以调用它们;其他代码消费 port 和稳定契约。 -- 接口与入口层暴露选定产品行为;可复用行为应下移。 -- 组装层只接线下层并选择产品能力事实,不实现具体 adapter、OS 或 service 细节。 -- 产品特性只在内核能力之上组装用户侧命令、UI contribution、设置和默认策略;长程任务、scheduler、permission、session/workspace、memory、DFX、hook 和 event 事实属于 Agent Kernel owner。 -- 适配层翻译协议和外部 provider 形状,不拥有产品能力选择或可复用 OS service 行为。 -- 服务实现层负责可复用的 OS、process、terminal、MCP、remote、git、filesystem、session persistence primitives 和 MiniApp runtime IO 能力。 -- 外部系统是边界外资源,不是仓库内层级。只有已注册的 adapter、service 或 app-local provider 应调用它们;其他层消费 port 和稳定契约。 -- 执行原语层只放可移植运行时构件,不拥有宿主或交付形态。 -- 契约层保持轻行为,不得向上依赖。 - -## 常用命令 - -这里只保留稳定的仓库级入口。具体 surface/crate 的测试命令由最近的本地 `AGENTS.md` 维护, -不要在根文档重复抄写。 +## 命令 ```bash -# 安装与主要产品开发循环 pnpm install -pnpm run desktop:dev # 完整热更新:Vite HMR + Rust 自动重编译并重启 - -# 仓库级检查 -pnpm run fmt:rs # 只格式化已改动 / 已暂存的 Rust 文件 +pnpm run desktop:dev # 主要开发循环:Vite HMR + Rust 自动重编译并重启 +pnpm run fmt:rs # 修改 Rust 后运行;只格式化已改动 / 已暂存的 .rs 文件 pnpm run check:repo-hygiene # 仓库内容与文件名规则 pnpm run check:github-config # GitHub workflow / 配置规则 -pnpm run check:core-boundaries # Cargo / 模块 owner 边界 +pnpm run check:core-boundaries # Cargo feature、依赖方向、模块 owner ``` -Web UI、mobile、CLI、Desktop、Installer、打包及 focused test 命令由最近的本地指南维护; -完整脚本注册表仍见 [`package.json`](package.json)。 - -## 全局规则 - -### 修复 bug 前先检查已有修复 +只有明确需要更大范围格式化时才使用 `cargo fmt`。各 surface、打包及 focused test 命令见最近的指南;完整脚本注册表见 [`package.json`](package.json)。 -修改 bug 相关代码前,只检查相关的本地代码和本地 Git 提交历史。结合已知的反馈版本和 -复现条件,判断已有修复是否覆盖该问题。开始新修复前先说明检查结论。若本地已有修复, -应给出对应的代码或提交依据,避免重复实现。 - -### 流程产物 - -- 不要新增或更新 `docs/superpowers/**` 下的文件。临时计划、设计和实现过程文档仅保留在本地; - 需要长期维护的架构或功能事实应合并到对应的已有文档,用户使用说明应放到所属应用的 README。 +## 验证 -### 国际化 +验证范围由 owner 决定,不使用全仓测试矩阵: -- Locale id、alias、fallback 和各形态默认语言统一由 - `src/shared/i18n/contract/locales.json` 管理;修改后运行 - `pnpm run i18n:generate`。 -- 跨形态稳定标签放在 - `src/shared/i18n/resources/shared//terms.json`;流程文案留在所属 - 产品形态资源中。 -- 不要把 Web UI locale 资源导入 `src/mobile-web`、`OpenBitFun-Installer` 等较小形态; - 完整规则见 `docs/architecture/i18n.md`。 -- 静态自包含页面只能使用生成的 page-scoped shared-term 文件,不得导入 Web UI locale catalog。 -- Web UI 只急切加载 bootstrap namespace;路由或功能文案使用 - `useI18n(namespace)`,直接 `i18nService.t(...)` 只用于 bootstrap namespace。 -- 用户可见的日期、时间和数字应通过共享 i18n 格式化 helper 处理,避免在产品代码中直接 - 使用 `Intl.*` 或 `toLocale*`。 -- `pnpm run i18n:audit` 会检查 key / 占位符一致性、直接静态 key、dynamic key - source proof、literal fallback / locale-format 零增长基线、shared-term / l10n - 治理基线、非阻断 same-text locale 盘点,以及 source 中不再新增硬编码 CJK 文案。 +1. 运行最近的 `AGENTS.md` 中能覆盖该行为的最窄命令。 +2. 优先选择单 package、单 test target 或 module filter,并使用最小 feature。不要把 `product-full`、`all-features` 或 workspace 全量测试当成捷径。 +3. 只有对应契约变化时才运行仓库级检查:布局/内容规则用 `check:repo-hygiene`,workflow 用 `check:github-config`,Cargo feature、依赖方向或 test-target 布局用 `check:core-boundaries`。 +4. 大范围 build、workspace suite、打包和平台矩阵交给 CI,除非改动影响这些路径或需要复现 CI 故障。 -### 主题与颜色 Token +## 每次改动都适用的规则 -- 主题与颜色 baseline 是 ratchet 契约,不是可随意修改的测试期望。不得通过提高 - `scripts/theme-color-governance-baseline*.json`、放宽 fixture/assertion、扩大 allowlist - 或移除 CI 审计来让失败检查通过。 -- 实际债务减少时应同步下调 baseline。确需新增颜色或 key 时,只增加最小 owner contract, - 并说明现有 semantic、component 或专用域 Token 为什么不能覆盖。 -- 修改 theme、CSS variable、widget payload、mobile、installer 或 CLI/TUI 颜色时,运行 - `pnpm run theme:color-audit:all`。 +### 修复 bug -### 日志 +修改 bug 相关代码前,只检查相关的本地代码和本地 Git 历史中是否已有修复,并结合已知的反馈版本和复现条件判断。开始前先说明检查结论。若已有修复,给出对应的代码或提交依据,不要重复实现。 -日志必须只用英文,且不能使用 emoji。 +### 平台边界 -- 前端:[src/web-ui/LOGGING.md](src/web-ui/LOGGING.md) -- 后端:[src/crates/LOGGING.md](src/crates/LOGGING.md) +- UI 组件不直接调用 Tauri API;通过 adapter / infrastructure 层访问。 +- 桌面端专属宿主 adapter 放在 `src/apps/desktop`,经类型化能力接口回流;需要事件投递时使用生产 transport adapter。 +- 共享 core 避免使用 `tauri::AppHandle` 等宿主专属 API;使用 `openbitfun_events::EventEmitter` 等共享抽象。 ### Tauri command -- command 名称:`snake_case` -- TypeScript 可以用 `camelCase` 包装,但调用 Rust 时要传结构化 `request` +command 名称使用 `snake_case`,并接收一个结构化 `request`。TypeScript 包装可以使用 `camelCase`。 ```rust #[tauri::command] @@ -128,16 +77,53 @@ pub async fn your_command( await api.invoke('your_command', { request: { ... } }); ``` -### 平台边界 +### 非交互子进程 + +- 可能运行在 GUI、无界面、后台或重定向宿主下的非交互子进程(包括可被其他宿主调用的 CLI 模式),不得直接使用裸 `std::process::Command` 或 `tokio::process::Command`。使用 `openbitfun_services_core::process_manager::{create_command, create_tokio_command}` 或该层既有的 facade。 +- 确实无法避免直接创建命令时,Windows 代码必须显式设置 `CREATE_NO_WINDOW`,Node 子进程必须设置 `windowsHide: true`。 +- 测试 fixture 遵循同样的策略,避免测试时闪现控制台窗口。 -- 不要在 UI 组件里直接调用 Tauri API;应通过 adapter / infrastructure 层访问。 -- 桌面端专属集成应放在 `src/apps/desktop`,再通过类型化能力接口回流;需要事件投递时,使用已有生产 transport adapter。 -- 在共享 core 中避免使用 `tauri::AppHandle` 等宿主 API;优先使用 `openbitfun_events::EventEmitter` 等共享抽象。 +### Rust 依赖 -### 远程场景 +- `[workspace.dependencies]` 只统一兼容版本,不提供宽泛的能力并集。每个 crate 只选择自身实际使用的 feature,仅测试所需的 feature 放入 `[dev-dependencies]`,受 feature 控制的服务能力挂在所属 crate 的 feature 上。 +- 第三方依赖的默认 feature 若不是所有 consumer 的契约,在 `[workspace.dependencies]` 统一关闭;成员继承该策略,只增加自身需要的切片。 +- 仓内 crate 的受保护 `default` 为空时,不在每条依赖边重复写 `default-features = false`。ACP 这类有意保留兼容默认的 crate,窄 consumer 仍需显式关闭。 +- 被复制到独立 Docker 构建上下文的 manifest 无法继承 workspace 根,必须保留显式版本和默认策略。 +- 根 workspace 和 workspace 成员禁止使用 `tokio/full`。 +- 细则见 [`docs/architecture/rust-build-dependency-boundaries.md`](docs/architecture/rust-build-dependency-boundaries.md)。修改 manifest 后用 `pnpm run check:core-boundaries` 验证。 -OpenBitFun 不是只在本地运行的桌面应用:工作区、执行这一轮的 runtime、以及正在操作的人, -可能分别位于三台机器。下面四种场景是每次改动都要一并覆盖的一等目标,不是事后再补的适配。 +### 日志 + +日志只用英文,且不使用 emoji。前端:[`src/web-ui/LOGGING.md`](src/web-ui/LOGGING.md)。后端:[`src/crates/LOGGING.md`](src/crates/LOGGING.md)。 + +### 国际化 + +- `src/shared/i18n/contract/locales.json` 统一管理 locale id、alias、fallback 规则和各形态默认语言。修改后运行 `pnpm run i18n:generate`。 +- 跨形态稳定标签放在 `src/shared/i18n/resources/shared//terms.json`;流程文案留在所属产品形态。 +- 任何形态都不得导入其他形态的 locale catalog。`src/mobile-web`、`OpenBitFun-Installer` 和静态页面不得导入 Web UI locale 资源;静态自包含页面使用生成的 page-scoped shared-term 文件。 +- 用户可见的日期、时间和数字使用共享 i18n 格式化 helper,不直接调用 `Intl.*` 或 `toLocale*`。 +- 修改 locale 资源或用户可见文案后运行 `pnpm run i18n:audit`。它检查 key / 占位符一致性、静态与动态 key 证明,以及 literal fallback、直接 locale 格式化和源码硬编码 CJK 文案的零增长基线。 +- 细则见 [`docs/architecture/i18n.md`](docs/architecture/i18n.md)。 + +### 主题与颜色 Token + +- 主题与颜色 baseline(`scripts/theme-color-governance-baseline*.json`)是 ratchet 契约,不是可随意修改的测试期望。不得通过提高 baseline、放宽 fixture/assertion 数量、增加宽泛 allowlist 或移除 CI 审计来让失败的审计通过。 +- 实际债务减少时同步下调 baseline。确需新增颜色或 key 时,只增加最小 owner contract,并说明现有 semantic、component 或专用域 Token 为什么不能覆盖。 +- 修改 theme、CSS variable、widget payload、mobile、installer 或 CLI/TUI 颜色后,运行 `pnpm run theme:color-audit:all`。 +- 细则见 [`docs/architecture/theme-token-optimization.md`](docs/architecture/theme-token-optimization.md)。 + +### Agent loop + +不要把硬编码限制或模式判断作为处理 agent loop 循环问题的第一反应,例如仅按字符串或次数阻止重复工具调用;这会把 agent loop 变成脆弱的 workflow 引擎。应先定位根因:工具行为、模型交互、会话上下文封装、prompt/tool schema 设计,或状态同步问题。 + +### 文档与流程产物 + +- 不要新增或更新 `docs/superpowers/**` 下的文件;`pnpm run check:repo-hygiene` 会拒绝它们。 +- 临时计划、设计和实现过程文档仅保留在本地。需要长期维护的架构或功能事实合并到对应的已有文档,用户使用说明放到所属应用的 README。 + +## 远程场景 + +工作区、执行这一轮的 runtime、以及正在操作的人,可能分别位于不同机器。下面四种场景是每次改动都要一并覆盖的一等目标,不是事后再补的适配。 | 场景 | 含义 | 设计入口 | |---|---|---| @@ -148,148 +134,60 @@ OpenBitFun 不是只在本地运行的桌面应用:工作区、执行这一轮 四种场景共同适用的规则: -- 远程路径要和功能一起设计。默认 UI、进程和文件系统在同一台机器上的能力属于未完成, - 而不是“第一阶段”。 -- 不支持要显式暴露。确实无法支持时,应屏蔽入口或返回明确的不支持状态;静默回落本地、 - 假成功、空载荷和通用错误都算回归,其中回落本地还会把本地内容泄露给远端控制方。 -- 阻塞式交互必须可以远程应答。新增的权限确认、对话框和选择器都要经既有的 dialog / - 权限信箱编排送达当前操作端;只能靠桌面窗口解除的阻塞会让远程控制和 Dispatch 任务死锁。 -- 要能扛断线。远程形态会重连、按 cursor 重放并重新 hydrate,因此优先使用可恢复 cursor - 和幂等变更,不要依赖“客户端恰好在线”才存在的状态。 -- 远程工作区路径在任何客户端 OS 上都是 POSIX 路径。不得用宿主 `std::path` 语义切分或 - 拼接,也不得把控制端的路径直接拿到 peer 宿主上复用。 +- **远程路径要和功能一起设计。** 默认 UI、进程和文件系统在同一台机器上的能力属于未完成,而不是“第一阶段”。 +- **不支持要显式暴露。** 无法支持某个场景时,屏蔽入口或返回明确的不支持状态。静默回落本地、假成功、空载荷和通用错误都算回归;回落本地还会把本地内容泄露给远端控制方。 +- **阻塞式交互必须可以远程应答。** 新增的权限确认、对话框和选择器都要经既有的 dialog / 权限信箱编排送达当前操作端。只能靠桌面窗口解除的阻塞会让远程控制和 Dispatch 任务死锁。 +- **要能扛断线。** 远程形态会重连、按 cursor 重放并重新 hydrate;优先使用可恢复 cursor 和幂等变更,不要依赖“客户端恰好在线”才存在的状态。 +- **远程工作区路径在任何客户端 OS 上都是 POSIX 路径。** 不得用宿主 `std::path` 语义切分或拼接,也不得把控制端的路径直接拿到 peer 宿主上复用。 各场景的具体约束: -- **远程工作区**:每个桌面端 Tauri 命令在 Product Operation Registry - ([`remote_surface/table.rs`](src/crates/contracts/product-domains/src/remote_surface/table.rs)) - 中有且只有一行,声明其远程工作区立场。桌面端闭包测试与能力生成器会拒绝没有对应行的 - 新命令,注册表的 ratchet 禁止 `Unaudited` 存量清单增长。见 - [remote-surface-contract.md](docs/architecture/remote-surface-contract.md)。 -- **远程控制**:mobile web 和 IM Bot 是通过 `RemoteCommand` wire 协议和 bot command - router / menu 触达会话的,不走 Web UI。新增或迁移会话级能力时——工作区与助手选择、 - 会话生命周期、模式、模型、审批、附件——要同步扩展这些形态,或让它们给出明确的 - 不支持回复。 -- **多端互控**:产品命令默认代理到 peer 执行。必须留在控制端的命令(窗口装饰、更新器、 - 账号身份、本地 OS 自动化)在同一注册表行中声明为 `ControllerLocal`;桌面端 peer host、 - CLI peer host 和 Web UI transport adapter 都从它派生拒绝集合, - `pnpm run check:core-boundaries` 会拒绝手写清单。CLI host 要执行的命令需要处理分支加 - 行内 `cli_peer: HANDLED`(`src/apps/cli/src/peer_host/commands/mod.rs` 的闭包测试保持 - 两者一致)。Peer 能力是类型化的 `PeerHostCapability`,由注册表发布。改动 session、 - account 或 hydrate 路径前,先读 peer-device README 的 invariants。 -- **Dispatch 分离任务**:任务在目标端以 CLI delivery profile 无界面运行,没有交互宿主, - 也不保证控制端在线。控制端只是观察者,不是 runtime 或文件系统代理。不要引入依赖提交方 - 常驻的行为;dispatch 协议版本和目标端必备 capability 属于兼容契约——新的目标端要求要走 - 协商 capability,而不是默认假设。 - -改动说明中要写清楚在哪些远程场景下验证过。只跑本地测试不能作为远程行为的证据。 - -### 升级兼容性 - -用户是原地升级的,而上述远程场景经常让两个不同版本的 OpenBitFun 连在同一条链路上。 -任何改动都必须保证已有安装在升级后无需手工修复即可继续工作。 - -- **落盘结构会被新旧两侧代码同时读取。** 配置、设置、会话、连接配置、worktree 和 - dispatch 记录:新增字段要带默认值,反序列化要保持容错,绝不重新定义或收窄已经落盘 - 字段的语义。旧数据给不出的字段,不能变成必填。 -- **不要用删除或重置用户数据的方式来“恢复”解析不了的内容。** 应保留记录、降级功能并 - 给出明确状态。凭证缺失、配置读不出、超时或主机离线,都不构成丢弃会话、工作区或连接 - 的理由;销毁性删除只能是用户的显式操作。 -- **跨版本边界要协商,不能假设。** Peer HostInvoke、dispatch 协议、relay 与 mobile web、 - IM Bot,对面都是你控制不了的构建版本。要先声明 capability 再使用——包版本相同不等于 - 行为相同——并且要让旧版本一侧留在可用路径上,而不是直接判失败。 -- **改名就是一次迁移。** 在所有受支持的对端都不可能再发送旧名称、旧 id 或旧结构之前, - 必须继续兼容读取;被改名对象所引用的数据(vault 条目、工作区指针)要一并迁移。 -- **用测试证明。** 要覆盖旧数据反序列化和旧载荷往返,而不只是新结构。只验证当前代码 - 自己写出的数据,不算升级兼容性覆盖。 - -### Agent loop 行为 - -- 不要把硬编码限制或模式判断作为处理 agent loop 循环问题的第一反应,例如仅按字符串或次数阻止重复工具调用。 -- 过多硬编码会把 agent loop 变成脆弱的 workflow。应先定位根因:工具行为、模型交互、会话上下文封装、prompt/tool schema 设计,或状态同步问题。 - -### Agent Hooks - -- OpenBitFun 的原生用户 Hooks 实现 Codex Hook 契约,因此 是其事件、载荷字段与决策结构的参考来源,不要另起炉灶。[`docs/features/agent-hooks.zh-CN.md`](docs/features/agent-hooks.zh-CN.md)([English](docs/features/agent-hooks.md))只覆盖 OpenBitFun 特有部分 —— 文件位置、`app.hooks` 开关和差异表 —— 新增或消除差异时必须同步更新。 -- 可移植引擎(配置解析、载荷构造、进程执行、决策合并)位于 `openbitfun-agent-runtime::native_hooks`。`openbitfun-core::native_hooks` 负责配置发现、开关门控和按事件的分发辅助函数;各分发点调用这些辅助函数,不要就地执行 Hook。 -- 可执行 Hooks 可以来自原生用户配置、生态插件或 OpenBitFun 内置实现(包括当前编译期 `post_call_hooks`)。这些来源保持各自的信任、配置、契约和执行策略语义,但可以统一注册到共享的 `HookRegistry`,并由 `AgentHookEngine` 调度。其他 AI 应用的外部 Hook 目录(`external_hooks`)仍只用于只读发现,不得进入可执行 Registry。 - -## 架构 - -### 产品架构护栏 - -任何 `openbitfun-core` 拆解、feature 边界、依赖边界或 Rust 构建提速重构, -都必须先阅读 -[`docs/architecture/product-architecture.md`](docs/architecture/product-architecture.md)。 -顶层文档只作为入口;模块级 ownership 细节应放到离代码最近的模块 `AGENTS.md`。 - -仓库级拆解规则: - -- 不要把 DTO / contract 抽取误判为 runtime owner 已迁移。 -- 产品表面可以有差异;共享稳定 facts 或 ports,不共享 UI、protocol、lifecycle 或平台实现。 -- 迁移 runtime owner 必须有评审过的 port/provider 设计、旧路径兼容、行为等价测试;如果可能改变行为边界,还需要先确认。 - -涉及 Agent Runtime 部署、多 GUI/TUI/Remote 实例、共享 Session 控制或进程拓扑时,还必须阅读 -[`docs/architecture/agent-runtime-deployment-design.md`](docs/architecture/agent-runtime-deployment-design.md)。 -Rust Runtime 或 Node/Bun Plugin Host 不得默认按 Client、workspace、session 或 plugin 分进程;进程边界必须来自真实状态 -owner、execution/security domain、可兼容的安全条件和测量后的容量事实。 - -### CLI 产品线护栏 - -涉及 CLI/TUI 能力对齐、非交互输出契约、外部配置导入、插件管理体验、CLI Agent 行为或 CLI -白标发行时,先阅读 -[`docs/architecture/cli-product-line-design.md`](docs/architecture/cli-product-line-design.md) 和 -[`src/apps/cli/AGENTS.md`](src/apps/cli/AGENTS.md)。CLI/TUI 展示留在 app;可复用产品行为通过 -Product Assembly、Agent Runtime、Tool/Harness、Runtime Services 或既有扩展边界承接。 - -### HarmonyOS PC CLI/TUI 护栏 - -涉及 HarmonyOS PC CLI/TUI 支持时,还必须阅读 -[`docs/architecture/platform-portability-design.md`](docs/architecture/platform-portability-design.md)。 -这是未来平台目标,不是已实现支持。目标是真实 PC 系统终端;HAP、`hdc shell`、 -手机 Remote App 和远端代执行都不能替代。具体适配必须另立专题,现有移动端能力保持不变。 - -### 产品定制护栏 - -涉及产品定义、品牌发行、GUI/TUI 布局选择、产品内置扩展或定制构建任务时,先阅读 -[`docs/architecture/product-customization-blueprint.md`](docs/architecture/product-customization-blueprint.md)。 -产品定制必须与用户运行时配置和插件分开;GUI/TUI 只共享稳定产品事实,不共享布局、组件、主题键、键位、 -renderer schema。产品组装结果和布局选择只能携带少量不可变的产品身份、数据隔离、故障恢复、升级完整性或 -法律保护项 ID;不得承载用户/来源级插件策略、安装、激活、更新、权限或动态健康状态。Product Profile、 -Brand Pack、GUI/TUI Surface Blueprint 和 Resolved Product Manifest 是已退役的设计术语,并非当前生产对象; -不得为这些术语新建兼容格式,只实现被真实构建和运行时消费的最小产品定义与组装结果字段。 - -涉及 OpenCode 实时配置或插件执行时,还要阅读 -[`docs/architecture/extensions/opencode-extension-compatibility.md`](docs/architecture/extensions/opencode-extension-compatibility.md)。 -在对应 OC-R 阶段实现并通过验证前,当前 P0 适配器仍只是受管包/静态预览路径。不得继续把旧受管包路径扩张为 -OpenCode 目标运行模型,也不得把设计目标描述成已可用能力。 - -### SDLC 质量护栏 - -涉及生命周期证据、门禁、Artifact Graph、Project Profile、Deep Review 策略、 -OpenCode 兼容或目标项目治理的变更,先阅读 -[`docs/sdlc-harness/README.md`](docs/sdlc-harness/README.md),再阅读 -[`docs/sdlc-harness/design.md`](docs/sdlc-harness/design.md)。如果变更影响模块边界或行为, -继续参考 `docs/sdlc-harness/architecture/` 或 `docs/sdlc-harness/features/` 下的对应设计。 - -不要把 OpenBitFun 自身验证假设硬编码成目标项目通用规则;质量保护行为必须保持面向目标项目、 -基于证据、按风险分级、成本可控并可审计。 - -## 验证 - -验证范围由 owner 决定,不在根文档维护全仓测试矩阵: - -1. 阅读离改动最近的本地 `AGENTS.md`,运行能够覆盖该行为的最窄命令。 -2. 优先选择单 package、单 test target 或 module filter,并使用最小 feature;不要把 - `product-full`、`all-features` 或 workspace 全量测试当成捷径。 -3. 只有对应契约变化时才运行仓库级检查:布局/内容规则使用 repository hygiene, - workflow 变更使用 GitHub config,Cargo feature、依赖方向或 test-target 布局使用 core boundaries。 -4. 大范围 build、workspace suite、打包和平台矩阵默认交给现有 CI;只有改动影响这些路径或需要复现 - CI 故障时才在本地运行。 - -如果某个模块缺少有效的 focused 命令,应补充到该模块自己的指南,而不是继续扩张根文档。 -不要预先对齐所有模块的 test 清单;只有真实开发流程需要时才记录命令。 - -## Agent 文档优先级 - -进入具体目录后,优先遵循离目标文件最近的 `AGENTS.md` / `AGENTS-CN.md`。如果局部文档与本文件冲突,以更具体、更近的文档为准。 +- **远程工作区**:每个桌面端 Tauri 命令在 Product Operation Registry([`remote_surface/table.rs`](src/crates/contracts/product-domains/src/remote_surface/table.rs))中有且只有一行,声明其远程工作区立场。桌面端闭包测试与能力生成器会拒绝没有对应行的命令,新行不得使用 `Unaudited`(该存量清单只减不增)。修改该表后运行 `pnpm run capabilities:generate`。见 [remote-surface-contract.md](docs/architecture/remote-surface-contract.md)。 +- **远程控制**:mobile web 和 IM Bot 通过 `RemoteCommand` wire 协议和 bot command router / menu 触达会话,不走 Web UI。新增或迁移会话级能力时(工作区或助手选择、会话生命周期、模式、模型、审批、附件),要同步扩展这些形态,或让它们给出明确的不支持回复。 +- **多端互控**:产品命令默认代理到 peer 执行。必须留在控制端的命令(窗口装饰、更新器、账号身份、本地 OS 自动化)在同一注册表行中声明为 `ControllerLocal`;桌面端 peer host、CLI peer host 和 Web UI transport adapter 都从它派生拒绝集合,`pnpm run check:core-boundaries` 会拒绝手写清单。CLI host 要执行的命令需要处理分支加行内 `cli_peer: HANDLED`;`src/apps/cli/src/peer_host/commands/mod.rs` 的闭包测试保持两者一致。Peer 能力是类型化的 `PeerHostCapability`,由注册表发布。改动 session、account 或 hydrate 路径前,先读 peer-device README 的 invariants。 +- **Dispatch 分离任务**:任务在目标端以 CLI delivery profile 无界面运行,没有交互宿主,也不保证控制端在线。控制端只是观察者,不是 runtime 或文件系统代理。不要引入依赖提交方常驻的行为。dispatch 协议版本和目标端必备 capability 属于兼容契约:新的目标端要求要走协商 capability,而不是默认假设。 + +说明改动在哪些远程场景下验证过。只跑本地测试不能作为远程行为的证据。 + +## 升级兼容性 + +用户是原地升级的,而上述远程场景经常让两个不同版本的 OpenBitFun 连在同一条链路上。任何改动都必须保证已有安装无需手工修复即可继续工作。 + +- **落盘结构会被新旧两侧代码同时读取。** 对配置、设置、会话、连接配置、worktree 和 dispatch 记录:新增字段要带默认值,反序列化保持容错,绝不重新定义或收窄已落盘字段的语义,也绝不把旧数据给不出的字段变成必填。 +- **不要用删除或重置用户数据的方式来“恢复”解析不了的内容。** 保留记录、降级功能并给出明确状态。凭证缺失、配置读不出、超时或主机离线,都不构成丢弃会话、工作区或连接的理由。销毁性删除只能是用户的显式操作。 +- **跨版本边界要协商,不能假设。** Peer HostInvoke、dispatch 协议、relay 与 mobile web、IM Bot,对面都是你控制不了的构建版本。先声明 capability 并在使用前检查(包版本相同不等于行为相同),并让旧版本一侧留在可用路径上,而不是直接判失败。 +- **改名就是一次迁移。** 在所有受支持的对端都不可能再发送旧名称、旧 id 或旧结构之前,必须继续兼容读取;被改名对象所引用的数据(vault 条目、工作区指针)要一并迁移。 +- **用测试证明。** 覆盖旧数据反序列化和旧载荷往返,而不只是新结构。只验证当前代码自己写出的数据,不算升级兼容性覆盖。 + +## 修改前必读 + +在下列范围修改前,先阅读所列文档。子项是硬性约束。 + +- **`openbitfun-core` 拆解、feature 或依赖边界、Rust 构建提速**:[`docs/architecture/product-architecture.md`](docs/architecture/product-architecture.md) 和 [`docs/architecture/rust-build-dependency-boundaries.md`](docs/architecture/rust-build-dependency-boundaries.md)。 + - 不要把 DTO / contract 抽取误判为 runtime owner 已迁移。 + - 产品表面可以有差异;共享稳定 facts 或 ports,不共享 UI、protocol、lifecycle 或平台实现。 + - 迁移 runtime owner 必须有评审过的 port/provider 设计、旧路径兼容、行为等价测试;可能改变行为边界时还需要明确确认。 +- **Agent Runtime 部署、多 GUI/TUI/Remote 实例、共享 Session 控制、进程拓扑**:[`docs/architecture/agent-runtime-deployment-design.md`](docs/architecture/agent-runtime-deployment-design.md)。 + - Rust Runtime 或 Node/Bun Plugin Host 不得默认按 client、workspace、session 或 plugin 分进程;依据负责的状态模块、执行与安全条件以及测量后的容量来决定。 +- **CLI/TUI 能力对齐、非交互输出契约、外部配置导入、插件管理体验、CLI Agent 行为、CLI 白标发行**:[`docs/architecture/cli-product-line-design.md`](docs/architecture/cli-product-line-design.md) 和 [`src/apps/cli/AGENTS.md`](src/apps/cli/AGENTS.md)。 + - CLI/TUI 展示留在 app;可复用产品行为通过 Product Assembly、Agent Runtime、Tool/Harness、Runtime Services 或既有扩展边界承接。 +- **HarmonyOS PC CLI/TUI**:[`docs/architecture/platform-portability-design.md`](docs/architecture/platform-portability-design.md)。 + - 这是未来平台目标,不是已实现支持。产品目标是真实 PC 系统终端;HAP、`hdc shell`、手机 Remote App 和远端代执行都不能替代。每项具体适配另立专题设计,现有移动端能力保持不变。 +- **产品定义、品牌发行、GUI/TUI 布局选择、产品内置扩展、定制构建任务**:[`docs/architecture/product-customization-blueprint.md`](docs/architecture/product-customization-blueprint.md)。 + - 产品定制与用户运行时配置和插件分开。GUI 和 TUI 可以共享稳定产品事实,但不共享布局、组件、主题键、键位或 renderer schema。 + - 产品组装结果和布局选择可以携带少量不可变的产品身份、数据隔离、故障恢复、升级完整性或法律保护项 ID。不得承载用户/来源级插件策略、安装、激活、更新、权限或动态健康状态。 + - Product Profile、Brand Pack、GUI/TUI Surface Blueprint 和 Resolved Product Manifest 是已退役的设计术语,不是生产对象。不要为它们新建兼容格式;只实现被真实构建和运行时消费方使用的最小产品定义与组装结果字段。 +- **OpenCode 实时配置或插件执行**:[`docs/architecture/extensions/opencode-extension-compatibility.md`](docs/architecture/extensions/opencode-extension-compatibility.md) 和 [`src/crates/adapters/opencode-adapter/AGENTS.md`](src/crates/adapters/opencode-adapter/AGENTS.md)。 + - 兼容矩阵描述的是目标与差距;不要把设计目标当成已可用能力。 + - 不要把旧受管包路径(P0 静态预览入口)扩张为 OpenCode 目标运行模型。 +- **Agent Hooks**:[`docs/features/agent-hooks.zh-CN.md`](docs/features/agent-hooks.zh-CN.md)([English](docs/features/agent-hooks.md))。 + - 原生用户 Hooks 实现 Codex Hook 契约,因此 是事件、载荷字段与决策结构的参考来源。不要另起炉灶。功能文档只覆盖 OpenBitFun 特有部分(文件位置、`app.hooks` 开关和差异表),新增或消除差异时必须同步更新。 + - 引擎、Registry、Hook 来源与分发的归属见 [`agent-runtime`](src/crates/execution/agent-runtime/AGENTS.md) 和 [`core`](src/crates/assembly/core/AGENTS.md) 指南。 +- **生命周期证据、门禁、Artifact Graph、Project Profile、Deep Review 策略、OpenCode 兼容、目标项目治理**:先读 [`docs/sdlc-harness/README.md`](docs/sdlc-harness/README.md),再读 [`docs/sdlc-harness/design.md`](docs/sdlc-harness/design.md)。变更影响模块边界或行为时,继续遵循 `docs/sdlc-harness/architecture/` 或 `docs/sdlc-harness/features/` 下的对应设计。 + - 不要把 OpenBitFun 仓库自身的假设硬编码成目标项目规则;质量保护行为保持面向目标项目、基于证据、按风险分级、成本可控并可审计。 + +## 维护这些指南 + +- 本文件只保留跨模块规则和稳定的仓库级入口。模块 ownership 细节、surface 或 crate 专属命令和 focused test 清单属于最近的指南;只有真实开发流程需要时才在那里补充命令。 +- crate 清单由各层指南维护;不要在这里枚举 crate。 +- `AGENTS.md` 与 `AGENTS-CN.md` 在同一次改动中同步更新。 diff --git a/AGENTS.md b/AGENTS.md index 2704ec7ac3..66b20d783f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2,145 +2,68 @@ # AGENTS.md -OpenBitFun is a Rust workspace plus React frontends. +OpenBitFun is a Rust workspace plus React frontends, delivered through several hosts (Desktop/Tauri, CLI/TUI, server, mobile, mobile-web, installer). Repository rule: **keep product logic platform-agnostic, then expose it through platform adapters**. -## Quick start - -1. Read `README.md` and `CONTRIBUTING.md` before architecture-sensitive changes. -2. Use the primary product loop below for normal development. Surface-specific - alternatives belong in the nearest app guide. -3. After Rust file changes, prefer `pnpm run fmt:rs` to format only changed or staged `.rs` files. Use `cargo fmt` only when you intentionally want broader formatting coverage. -4. After changes, use the nearest local `AGENTS.md` for the focused verification - command. The repository-level verification section below only covers - cross-cutting checks. -5. Workspace Rust dependencies own compatible versions, not broad capability - unions. Each crate must select the dependency features it actually uses; - keep test-only features in dev-dependencies and attach feature-gated service - capabilities to the owning crate feature. Disable third-party defaults in - `[workspace.dependencies]` when they are not part of every consumer's - contract; members inherit that policy and add only their needed slices. For - internal crates whose guarded `default` is empty, do not repeat - `default-features = false` on every edge. Narrow consumers of an intentional - compatibility default, such as ACP, must still disable it explicitly. - Manifests copied into a standalone Docker build context must keep explicit - versions and default policy because they cannot inherit the workspace root. - `tokio/full` is forbidden in the root workspace and workspace members. - -## Layered Module Index - -Dependencies flow top to bottom. This table is the physical crate layout, not -the full conceptual architecture. For Product Surface / Product Assembly / -Product Feature / Agent Kernel / Execution / Extension / Cross-platform Adapter / -Stable Contracts and Security Control Plane boundaries, read -[`docs/architecture/product-architecture.md`](docs/architecture/product-architecture.md). -Keep crate dependencies inside each layer to the smallest set needed. - -| # | Layer | Path | Owns | Modules / entries | Layer doc | -|---|---|---|---|---|---| -| 1 | Interfaces and entrypoints | `src/apps/*`, `src/web-ui`, `src/mobile-web`, `OpenBitFun-Installer`, `tests/e2e`, `src/crates/interfaces` | Product hosts, commands, UI entrypoints, protocol interfaces, and cross-surface tests | desktop, CLI, server, relay, Web UI, mobile web, installer, E2E, `acp`, `app-server`, `sdk-host` | nearest local `AGENTS.md`; [interfaces](src/crates/interfaces/AGENTS.md) | -| 2 | Product assembly | `src/crates/assembly` | Compatibility exports, product capability selection, product-full wiring, immutable built-in Agent content, adapter/service registration, and ecosystem-neutral source coordination | `agent-content`, `core`, `external-sources`, `product-capabilities` | [AGENTS.md](src/crates/assembly/AGENTS.md) | -| 3 | Adapters | `src/crates/adapters` | AI/transport/WebDriver protocol adapters, external AI work source adapters (OpenCode/Claude Code/Codex/Zcode), and external-provider translation | `agent-runtime-ipc`, `ai-adapters`, `opencode-adapter`, `claude-code-adapter`, `codex-adapter`, `zcode-adapter`, `static-hook-support`, `transport`, `webdriver` | [AGENTS.md](src/crates/adapters/AGENTS.md) | -| 4 | Services | `src/crates/services` | Reusable OS, filesystem, terminal, MCP, remote, git, watch, process, session persistence primitives, MiniApp runtime IO, and network implementations | `services-core`, `services-integrations`, `computer-use`, `miniapp-market-service`, `relay-service`, `page-function-runtime`, `terminal` | [AGENTS.md](src/crates/services/AGENTS.md) | -| 5 | Execution primitives | `src/crates/execution` | Portable Agent Runtime, named-workflow policy, stream, plugin runtime client, typed-service, tool-contract, tool-group, and tool-execution building blocks | `agent-runtime`, `agent-workflows`, `agent-stream`, `tool-contracts`, `plugin-runtime-client`, `runtime-services`, `tool-provider-groups`, `tool-execution` | [AGENTS.md](src/crates/execution/AGENTS.md) | -| 6 | Stable contracts and product domains | `src/crates/contracts` | Shared DTOs, event shapes, runtime ports, and product domain contracts/policies | `core-types`, `events`, `runtime-ports`, `product-domains` | [AGENTS.md](src/crates/contracts/AGENTS.md) | +## Where rules live + +- This file holds repository-wide rules. The nearest `AGENTS.md` to the files you change owns local boundaries, commands, and focused verification; if it conflicts with this file, the nearer guide wins. +- Commit and PR conventions: [`CONTRIBUTING.md`](CONTRIBUTING.md). -Boundary rules: +## Layers -- Interfaces and app entrypoints expose selected product behavior; reusable behavior moves down. -- Assembly wires lower layers and selects product capability facts; it must not implement concrete adapter, OS, or service details. -- Product features assemble user-facing commands, UI contributions, settings, and default policy on top of kernel capabilities; long-running task, scheduler, permission, session/workspace, memory, DFX, hook, and event facts stay in Agent Kernel owners. -- Adapters translate protocols and external-provider shapes; they should not own product capability selection or reusable OS service behavior. -- Services implement reusable concrete OS, process, terminal, MCP, remote, git, filesystem, and MiniApp runtime IO capabilities. -- External systems are boundary resources, not repository layers. Only registered adapters/services/app-local providers should call them; other layers consume ports and stable contracts. -- Execution crates are portable runtime building blocks, not host-specific or delivery-profile owners. -- Contracts stay behavior-light and must not depend upward. +Dependencies point downward: a crate may depend on lower layers, not on higher ones, and same-layer dependencies stay minimal. Layer guides list their crates and the exact allowed edges. This table is the physical crate layout; the conceptual architecture (4+1 views) is in [`docs/architecture/product-architecture.md`](docs/architecture/product-architecture.md). +| # | Layer | Path | Owns | Must not | Guide | +|---|---|---|---|---|---| +| 1 | Interfaces and entrypoints | `src/apps/*`, `src/web-ui`, `src/mobile-web`, `src/*-market-web`, `OpenBitFun-Installer`, `tests/e2e`, `src/crates/interfaces` | Product hosts, commands, UI entrypoints, protocol interfaces, and cross-surface tests | Keep reusable behavior; move it down | nearest local `AGENTS.md`; [interfaces](src/crates/interfaces/AGENTS.md) | +| 2 | Product assembly | `src/crates/assembly` | Compatibility exports, product capability selection, product-full wiring, immutable built-in Agent content, adapter/service registration, and ecosystem-neutral source coordination | Implement concrete adapter, OS, or service details | [AGENTS.md](src/crates/assembly/AGENTS.md) | +| 3 | Adapters | `src/crates/adapters` | Protocol, transport, local IPC, WebDriver, AI-provider, and external AI work-source adapters; external-provider translation | Own product capability selection or reusable OS service behavior | [AGENTS.md](src/crates/adapters/AGENTS.md) | +| 4 | Services | `src/crates/services` | Reusable OS, filesystem, terminal, MCP, remote, git, watch, process, network, session persistence, and MiniApp runtime IO implementations | Own protocol/transport projection or product capability selection | [AGENTS.md](src/crates/services/AGENTS.md) | +| 5 | Execution primitives | `src/crates/execution` | Portable Agent Runtime, named-workflow policy, stream, plugin runtime client, typed-service, tool-contract, tool-group, and tool-execution building blocks | Own host-specific or delivery-profile behavior | [AGENTS.md](src/crates/execution/AGENTS.md) | +| 6 | Stable contracts and product domains | `src/crates/contracts` | Shared DTOs, event shapes, runtime ports, and product-domain contracts/policies | Carry runtime behavior or depend upward | [AGENTS.md](src/crates/contracts/AGENTS.md) | -## Common commands +- Product features only assemble user-facing commands, UI contributions, settings, and default policy. Long-running task, scheduler, permission, session/workspace, memory, DFX, hook, and event facts stay with their existing owners. +- External systems are boundary resources, not layers. Only registered adapters, services, or app-local providers call them; other code consumes ports and stable contracts. -Keep this list to stable repository entry points. Surface- and crate-specific -test commands belong in the nearest local `AGENTS.md` and must not be copied here. +## Commands ```bash -# Setup and primary product loop pnpm install -pnpm run desktop:dev # full hot-reload: Vite HMR + Rust auto-rebuild & restart - -# Repository checks -pnpm run fmt:rs # format only changed / staged Rust files +pnpm run desktop:dev # primary dev loop: Vite HMR + Rust auto-rebuild and restart +pnpm run fmt:rs # run after Rust edits; formats only changed / staged .rs files pnpm run check:repo-hygiene # repository content and filename rules -pnpm run check:github-config # GitHub workflow/configuration rules -pnpm run check:core-boundaries # Cargo/module ownership boundaries +pnpm run check:github-config # GitHub workflow / configuration rules +pnpm run check:core-boundaries # Cargo features, dependency direction, module ownership ``` -For Web UI, mobile, CLI, Desktop, Installer, packaging, and focused test -commands, use the nearest local guide. The full script registry remains in -[`package.json`](package.json). - -## Global rules +Use `cargo fmt` only when broader formatting is intended. Surface, packaging, and focused test commands live in the nearest guide; the full script registry is [`package.json`](package.json). -### Check for existing bug fixes before editing - -Before changing code for a bug, check only the relevant local code and local Git -commit history. Use the reported version and reproduction conditions when -available to determine whether an existing fix covers the report. Record the -result before starting a new fix. If a fix already exists locally, cite the -supporting code or commit to avoid duplicating it. - -### Process artifacts - -- Do not add or update files under `docs/superpowers/**`. Keep temporary - planning, design, and implementation-process artifacts local. Move durable - architecture or feature facts into the existing document for that area, and - put user-facing guidance in the owning app README. +## Verification -### Internationalization +Verify at the owner, not with a repository-wide matrix: -- Locale ids, aliases, fallback rules, and surface defaults are owned by - `src/shared/i18n/contract/locales.json`. Run `pnpm run i18n:generate` - after editing it. -- Shared stable labels live in - `src/shared/i18n/resources/shared//terms.json`; workflow copy stays - in the owning product surface. -- Do not import Web UI locale resources into smaller product surfaces such as - `src/mobile-web` or `OpenBitFun-Installer`. See `docs/architecture/i18n.md`. -- Static self-contained pages may use generated page-scoped shared-term files; - they must not import Web UI locale catalogs. -- Web UI loads only bootstrap namespaces eagerly; use `useI18n(namespace)` for - route or feature copy and keep direct `i18nService.t(...)` calls in bootstrap - namespaces. -- Use shared i18n formatting helpers for user-visible dates, times, and - numbers instead of direct `Intl.*` or `toLocale*` calls. -- `pnpm run i18n:audit` enforces key/placeholder parity, direct static key - existence, dynamic key source proofs, literal fallback and locale-format - no-growth baselines, shared-term/l10n governance baselines, non-blocking - same-text locale inventory, and the no-hardcoded-CJK source budget. +1. Run the narrowest command from the nearest `AGENTS.md` that covers the changed behavior. +2. Prefer one package, one test target or module filter, and the minimum feature set. Do not use `product-full`, `all-features`, or a workspace-wide suite as a shortcut. +3. Run a repository check only when its contract changed: `check:repo-hygiene` for layout/content rules, `check:github-config` for workflows, `check:core-boundaries` for Cargo features, dependency direction, or test-target layout. +4. Leave broad builds, workspace suites, packaging, and platform matrices to CI unless the change affects those paths or reproduces a CI failure. -### Theme and color tokens +## Rules for every change -- Theme and color-token baselines are ratchet contracts, not editable test - expectations. Do not make a failing theme audit pass by raising values in - `scripts/theme-color-governance-baseline*.json`, loosening fixture/assertion - counts, adding broad allowlist entries, or removing CI audit coverage. -- Lower theme baselines when measured debt is removed. If a change truly needs a - new color or key, add the smallest owner contract and document why existing - semantic, component, or specialized-domain tokens cannot cover it. -- For theme, CSS variable, widget payload, mobile, installer, or CLI/TUI color - changes, run `pnpm run theme:color-audit:all`. +### Bug fixes -### Logging +Before changing code for a bug, check only the relevant local code and local Git history for an existing fix, using the reported version and reproduction conditions when available. State the result before starting. If a fix already exists, cite the code or commit instead of duplicating it. -Logs must be English-only, with no emojis. +### Platform boundaries -- Frontend: [`src/web-ui/LOGGING.md`](src/web-ui/LOGGING.md) -- Backend: [`src/crates/LOGGING.md`](src/crates/LOGGING.md) +- UI components do not call Tauri APIs directly; go through the adapter/infrastructure layer. +- Desktop-only host adapters live in `src/apps/desktop` and flow through typed capability interfaces, plus the production transport adapter when events must be delivered. +- Shared core avoids host-specific APIs such as `tauri::AppHandle`; use shared abstractions such as `openbitfun_events::EventEmitter`. ### Tauri commands -- Command names: `snake_case` -- TypeScript may wrap with `camelCase`, but invoke Rust with a structured `request` +Command names are `snake_case` and take one structured `request`. TypeScript wrappers may be `camelCase`. ```rust #[tauri::command] @@ -154,29 +77,53 @@ pub async fn your_command( await api.invoke('your_command', { request: { ... } }); ``` -### Platform boundaries +### Non-interactive child processes -- Do not call Tauri APIs directly from UI components; go through the adapter/infrastructure layer. -- Desktop-only host adapters belong in `src/apps/desktop`, then flow through typed capability interfaces and, when event delivery is needed, the production transport adapter. -- In shared core, avoid host-specific APIs such as `tauri::AppHandle`; use shared abstractions such as `openbitfun_events::EventEmitter`. +- A non-interactive child process that may run under a GUI, headless, background, or redirected host (including CLI modes another host can invoke) must not use bare `std::process::Command` or `tokio::process::Command`. Use `openbitfun_services_core::process_manager::{create_command, create_tokio_command}` or the existing facade for that layer. +- If a direct command is unavoidable, Windows code applies `CREATE_NO_WINDOW` explicitly and Node child processes set `windowsHide: true`. +- Test fixtures follow the same policy, so tests do not flash console windows. -#### Non-interactive child processes +### Rust dependencies -- Any non-interactive child process that may run under a GUI, headless, - background, or redirected host must not use bare `std::process::Command` or - `tokio::process::Command`, including CLI modes that another host can invoke. - Prefer - `openbitfun_services_core::process_manager::{create_command, create_tokio_command}` - or the existing facade for that layer. If a direct command is unavoidable, - Windows code must explicitly apply `CREATE_NO_WINDOW`; Node child processes - must set `windowsHide: true`. Apply the same policy to test fixtures so tests - do not flash console windows either. +- `[workspace.dependencies]` owns compatible versions, not broad capability unions. Each crate selects the features it actually uses, keeps test-only features in `[dev-dependencies]`, and attaches feature-gated service capabilities to the owning crate feature. +- Disable third-party defaults in `[workspace.dependencies]` when they are not part of every consumer's contract; members inherit that policy and add only the slices they need. +- For internal crates whose guarded `default` is empty, do not repeat `default-features = false` on every edge. Narrow consumers of an intentional compatibility default, such as ACP, still disable it explicitly. +- Manifests copied into a standalone Docker build context keep explicit versions and default policy, because they cannot inherit the workspace root. +- `tokio/full` is forbidden in the root workspace and in workspace members. +- Details: [`docs/architecture/rust-build-dependency-boundaries.md`](docs/architecture/rust-build-dependency-boundaries.md). Verify manifest changes with `pnpm run check:core-boundaries`. -### Remote scenarios +### Logging + +Logs are English-only, with no emojis. Frontend: [`src/web-ui/LOGGING.md`](src/web-ui/LOGGING.md). Backend: [`src/crates/LOGGING.md`](src/crates/LOGGING.md). + +### Internationalization -OpenBitFun is not a local-only desktop app. The workspace, the runtime that executes -a turn, and the person driving it can each sit on a different machine. Treat the -four scenarios below as first-class targets of every change, not as a later port. +- `src/shared/i18n/contract/locales.json` owns locale ids, aliases, fallback rules, and surface defaults. Run `pnpm run i18n:generate` after editing it. +- Shared stable labels live in `src/shared/i18n/resources/shared//terms.json`; workflow copy stays in the owning product surface. +- No surface imports another surface's locale catalog. Web UI locale resources must not be imported by `src/mobile-web`, `OpenBitFun-Installer`, or static pages; static self-contained pages use generated page-scoped shared-term files. +- Format user-visible dates, times, and numbers with the shared i18n helpers, not direct `Intl.*` or `toLocale*` calls. +- Run `pnpm run i18n:audit` after changing locale resources or user-visible copy. It enforces key/placeholder parity, static and dynamic key proofs, and no-growth baselines for literal fallbacks, direct locale formatting, and hard-coded CJK source text. +- Details: [`docs/architecture/i18n.md`](docs/architecture/i18n.md). + +### Theme and color tokens + +- Theme and color-token baselines (`scripts/theme-color-governance-baseline*.json`) are ratchet contracts, not editable test expectations. Never make a failing audit pass by raising baseline values, loosening fixture/assertion counts, adding broad allowlist entries, or removing CI audit coverage. +- Lower a baseline when measured debt is removed. If a change truly needs a new color or key, add the smallest owner contract and document why existing semantic, component, or specialized-domain tokens cannot cover it. +- Run `pnpm run theme:color-audit:all` after theme, CSS variable, widget payload, mobile, installer, or CLI/TUI color changes. +- Details: [`docs/architecture/theme-token-optimization.md`](docs/architecture/theme-token-optimization.md). + +### Agent loop + +Do not add hard-coded limits or pattern checks to the agent loop as a first response to looping behavior, such as blocking repeated tool calls by string or count alone; that turns the loop into a brittle workflow engine. Investigate the root cause first: tool behavior, model interaction, session context packaging, prompt/tool schema design, or state synchronization. + +### Docs and process artifacts + +- Do not add or update files under `docs/superpowers/**`; `pnpm run check:repo-hygiene` rejects them. +- Keep temporary planning, design, and implementation-process artifacts local. Move durable architecture or feature facts into the existing document for that area, and put user-facing guidance in the owning app README. + +## Remote scenarios + +The workspace, the runtime that executes a turn, and the person driving it can each sit on a different machine. Treat these four scenarios as first-class targets of every change, not as a later port. | Scenario | What it means | Design entry point | |---|---|---| @@ -185,200 +132,62 @@ four scenarios below as first-class targets of every change, not as a later port | Peer Device Mode | One same-account device becomes the data plane of another: the controller shell stays local, invokes and events come from the peer | [peer-device-mode.md](docs/architecture/peer-device-mode.md), [peer-device README](src/web-ui/src/infrastructure/peer-device/README.md) | | Detached Dispatch | A controller submits a durable job to another OpenBitFun host and may then disconnect; the target owns the job, session, worktree, event log, and permission mailbox | [detached-task-dispatch.md](docs/architecture/detached-task-dispatch.md) | -Rules that apply to all four: - -- Design the remote path together with the feature. A capability that assumes UI, - process, and filesystem share one machine is incomplete, not "phase one". -- Degrade loudly. When a scenario cannot be supported, gate the entry point or - return a clear unsupported state. Silent local fallback, fake success, empty - payloads, and generic errors are all regressions; local fallback additionally - leaks local content to a remote controller. -- Keep blocking interaction answerable from a distance. New permission prompts, - dialogs, and pickers must reach the driving surface through the existing dialog - and permission-mailbox orchestration. A turn that only the desktop window can - unblock deadlocks remote control and dispatch jobs. -- Survive disconnect. Remote surfaces reconnect, replay by cursor, and re-hydrate, - so prefer resumable cursors and idempotent mutations over state that exists only - while a client happens to be attached. -- Remote workspace paths are POSIX on every client OS. Do not split or join them - with host `std::path` semantics, and do not reuse a controller-side path on a - peer host. +Rules for all four: -Per-scenario obligations: - -- **Remote workspace**: every desktop Tauri command has one row in the Product - Operation Registry - ([`remote_surface/table.rs`](src/crates/contracts/product-domains/src/remote_surface/table.rs)) - declaring its remote-workspace stance. The desktop closure test and the - capability generator reject new commands without a row, and the registry's - ratchet forbids growing the `Unaudited` backlog. See - [remote-surface-contract.md](docs/architecture/remote-surface-contract.md). -- **Remote control**: mobile web and IM bots reach sessions through the - `RemoteCommand` wire protocol and the bot command router / menu, not through the - Web UI. When a session-level capability is added or moved — workspace or - assistant selection, session lifecycle, mode, model, approval, attachment — - extend those surfaces or make them answer with an explicit unsupported reply. -- **Peer Device Mode**: product commands are proxied to the peer by default. A - command that must stay on the controller (window chrome, updater, account - identity, local OS automation) is declared `ControllerLocal` in the same - registry row; the desktop peer host, the CLI peer host, and the Web UI - transport adapter all derive their deny sets from it, and - `pnpm run check:core-boundaries` rejects a hand-written table. A command the - CLI host runs needs a handler plus `cli_peer: HANDLED` in its row (the - closure test in `src/apps/cli/src/peer_host/commands/mod.rs` keeps both in - step). Peer capabilities are typed (`PeerHostCapability`) and advertised - from the registry. Read the peer-device README invariants before changing - session, account, or hydrate paths. -- **Detached Dispatch**: jobs run headless on the target under the CLI delivery - profile, with no interactive host and no guaranteed controller connection. The - controller is an observer, never a runtime or filesystem proxy. Do not add - behavior that requires a live submitter, and treat the dispatch protocol version - and required target capabilities as a compatibility contract — a new target-side - requirement needs a negotiated capability, not an assumption. - -State which remote scenarios a change was exercised in. Local-only tests are not -evidence of remote behavior. - -### Upgrade compatibility - -Users upgrade in place, and the remote scenarios above routinely put two -different OpenBitFun versions on the same connection. Every change must keep -existing installs working without manual repair. - -- **Persisted shapes are read by older and newer code.** Config, settings, - sessions, connection profiles, worktree and dispatch records: add fields with - defaults, keep deserialization tolerant, and never repurpose or narrow the - meaning of a field that is already on disk. A field old data cannot supply - must not become required. -- **Never delete or reset user data to recover from something you cannot - parse.** Keep the record, degrade the feature, and surface a clear state. - Missing credentials, an unreadable profile, a timeout, or an offline host are - not reasons to drop a session, workspace, or connection. Destructive removal - stays an explicit user action. -- **Cross-version boundaries negotiate; they do not assume.** Peer HostInvoke, - the dispatch protocol, relay and mobile web, and IM bots all talk to a build - you do not control. Advertise a capability and check it before using it — - package version equality is not evidence of behavior — and keep the older - side on a working path instead of failing it. -- **A rename is a migration.** Keep reading the old name, id, or record shape - until no supported peer can still send it, and migrate referenced data - (vault entries, workspace pointers) together with the thing being renamed. -- **Prove it with tests.** Cover legacy deserialization and an old-payload - round trip, not just the new shape. A test that only exercises data written - by the current code is not upgrade coverage. - -### Agent loop behavior - -- Do not add hard-coded limits or pattern checks to the agent loop as a first response to looping behavior, such as blocking repeated tool calls by string or count alone. -- Excessive hard-coding turns the agent loop into a brittle workflow engine. Investigate the root cause first: tool behavior, model interaction, session context packaging, prompt/tool schema design, or state synchronization issues. - -### Agent hooks - -- OpenBitFun native user hooks implement the Codex hook contract, so is the reference for their events, payload fields, and decision schema. Do not fork that contract. [`docs/features/agent-hooks.md`](docs/features/agent-hooks.md) ([中文](docs/features/agent-hooks.zh-CN.md)) covers only the OpenBitFun-specific parts — file locations, the `app.hooks` gates, and the deviations table — and must be updated whenever a deviation is added or closed. -- The portable engine (settings parsing, payload construction, process execution, decision merging) lives in `openbitfun-agent-runtime::native_hooks`. `openbitfun-core::native_hooks` owns config discovery, gating, and per-event dispatch helpers; dispatch sites call those helpers instead of executing hooks inline. -- Executable hooks may come from native user configuration, ecosystem plugins, or OpenBitFun built-ins (including the current compiled-in `post_call_hooks`). These sources keep distinct trust, configuration, contract, and execution-policy semantics, but may register through the shared `HookRegistry` and be dispatched by `AgentHookEngine`. The external hook catalog of other AI applications (`external_hooks`) remains read-only discovery data and must not enter the executable registry. - -## Architecture - -### Product architecture guardrails - -For any `openbitfun-core` decomposition, feature-boundary, dependency-boundary, or -Rust build-speed refactor, read both -[`docs/architecture/product-architecture.md`](docs/architecture/product-architecture.md) -and -[`docs/architecture/rust-build-dependency-boundaries.md`](docs/architecture/rust-build-dependency-boundaries.md) -before editing. Keep these files as entry points; 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. - -For Agent Runtime deployment, multi-GUI/TUI/Remote instances, shared Session -control, or process-topology changes, also read -[`docs/architecture/agent-runtime-deployment-design.md`](docs/architecture/agent-runtime-deployment-design.md). -Do not key Rust Runtime or Node/Bun Plugin Host processes by client, workspace, -session, or plugin by default; use the responsible state module, execution and -security conditions, and measured capacity. - -### CLI product-line guardrails - -For CLI/TUI parity work, non-interactive output contracts, external config -imports, plugin management UX, CLI Agent behavior, or branded CLI distributions, -read [`docs/architecture/cli-product-line-design.md`](docs/architecture/cli-product-line-design.md) -and [`src/apps/cli/AGENTS.md`](src/apps/cli/AGENTS.md). Keep CLI/TUI presentation -in the app; move reusable product behavior through Product Assembly, Agent -Runtime, Tool/Harness, Runtime Services, or the existing extension boundaries. - -### HarmonyOS PC CLI/TUI guardrails - -For changes that affect HarmonyOS PC CLI/TUI support, also read -[`docs/architecture/platform-portability-design.md`](docs/architecture/platform-portability-design.md). -This is a future platform target, not implemented support. The product target is -the real PC system terminal; HAP, `hdc shell`, the phone Remote App, and remote -execution are not substitutes. Design each concrete adaptation as a separate -topic and keep the current mobile capability unchanged. - -### Product customization guardrails - -For product definitions, branded distributions, GUI/TUI layout selection, -bundled product extensions, or customization build tasks, read -[`docs/architecture/product-customization-blueprint.md`](docs/architecture/product-customization-blueprint.md). -Keep product customization separate from user runtime configuration and plugins. -GUI and TUI may share stable product facts, but not layout, component, theme-key, -keybinding, or renderer schemas. Product assembly results and layout selections -may carry a small immutable list of product identity, data-isolation, recovery, -upgrade-integrity, or legal protection IDs. They must not carry user/source-level -plugin policy, installation, activation, update, permission, or dynamic health state. -Product Profile, Brand Pack, GUI/TUI Surface Blueprint, and Resolved Product Manifest are retired -design terms, not current production objects. Do not create compatibility formats -for them; implement only the smallest product-definition and assembly-result fields -used by a real build and runtime consumer. - -For OpenCode live configuration or plugin execution, also read -[`docs/architecture/extensions/opencode-extension-compatibility.md`](docs/architecture/extensions/opencode-extension-compatibility.md). -The current P0 adapter remains a managed-package/static-preview path until the matching -OC-R phase is implemented and verified. Do not extend the legacy managed-package -path as the target OpenCode runtime model, and do not treat a design target as an -already available capability. - -### SDLC quality guardrails - -For lifecycle evidence, gates, Artifact Graph, Project Profile, Deep Review -policy, OpenCode compatibility, or target-project governance changes, read -[`docs/sdlc-harness/README.md`](docs/sdlc-harness/README.md) -first, then [`docs/sdlc-harness/design.md`](docs/sdlc-harness/design.md). If -module boundaries or behavior change, follow the matching design under -`docs/sdlc-harness/architecture/` or `docs/sdlc-harness/features/`. - -Do not hard-code OpenBitFun repository assumptions as target-project rules; keep -quality protection behavior target-aware, evidence-backed, risk-tiered, -cost-aware, and auditable. - -## Verification +- **Design the remote path together with the feature.** A capability that assumes UI, process, and filesystem share one machine is incomplete, not "phase one". +- **Degrade loudly.** When a scenario cannot be supported, gate the entry point or return a clear unsupported state. Silent local fallback, fake success, empty payloads, and generic errors are regressions; local fallback also leaks local content to a remote controller. +- **Keep blocking interaction answerable from a distance.** New permission prompts, dialogs, and pickers reach the driving surface through the existing dialog and permission-mailbox orchestration. A turn that only the desktop window can unblock deadlocks remote control and dispatch jobs. +- **Survive disconnect.** Remote surfaces reconnect, replay by cursor, and re-hydrate; prefer resumable cursors and idempotent mutations over state that exists only while a client is attached. +- **Remote workspace paths are POSIX on every client OS.** Do not split or join them with host `std::path` semantics, and do not reuse a controller-side path on a peer host. -Choose verification at the owner, not from a repository-wide test matrix: - -1. Read the nearest local `AGENTS.md` and run its narrowest command that covers - the changed behavior. -2. Prefer one package, one test target or module filter, and the minimum feature - set. Do not use `product-full`, `all-features`, or a workspace-wide suite as a - shortcut. -3. Run a repository check only when its contract changed: repository hygiene for - layout/content rules, GitHub config for workflow changes, and core boundaries - for Cargo features, dependency direction, or test-target layout. -4. Leave broad builds, workspace suites, packaging, and platform matrices to - existing CI unless the change affects those paths or reproduces a CI failure. - -If a module lacks a useful focused command, add it to that module's guide rather -than expanding this file. Do not pre-emptively align every module's test list; -document a command only when a real workflow needs it. - -## Agent-doc priority +Per-scenario obligations: -Prefer the nearest matching `AGENTS.md` / `AGENTS-CN.md` for the directory you are changing. If local guidance conflicts with this file, follow the more specific, nearer document. +- **Remote workspace**: every desktop Tauri command has exactly one row in the Product Operation Registry ([`remote_surface/table.rs`](src/crates/contracts/product-domains/src/remote_surface/table.rs)) declaring its remote-workspace stance. The desktop closure test and the capability generator reject a command without a row, and new rows may not use `Unaudited` (that backlog only shrinks). Run `pnpm run capabilities:generate` after editing the table. See [remote-surface-contract.md](docs/architecture/remote-surface-contract.md). +- **Remote control**: mobile web and IM bots reach sessions through the `RemoteCommand` wire protocol and the bot command router / menu, not through the Web UI. When a session-level capability is added or moved (workspace or assistant selection, session lifecycle, mode, model, approval, attachment), extend those surfaces or make them answer with an explicit unsupported reply. +- **Peer Device Mode**: product commands are proxied to the peer by default. A command that must stay on the controller (window chrome, updater, account identity, local OS automation) is declared `ControllerLocal` in the same registry row; the desktop peer host, the CLI peer host, and the Web UI transport adapter derive their deny sets from it, and `pnpm run check:core-boundaries` rejects a hand-written table. A command the CLI host runs needs a handler plus `cli_peer: HANDLED` in its row; the closure test in `src/apps/cli/src/peer_host/commands/mod.rs` keeps both in step. Peer capabilities are typed (`PeerHostCapability`) and advertised from the registry. Read the peer-device README invariants before changing session, account, or hydrate paths. +- **Detached Dispatch**: jobs run headless on the target under the CLI delivery profile, with no interactive host and no guaranteed controller connection. The controller is an observer, never a runtime or filesystem proxy. Do not add behavior that requires a live submitter. The dispatch protocol version and required target capabilities are a compatibility contract: a new target-side requirement needs a negotiated capability, not an assumption. + +State which remote scenarios a change was exercised in. Local-only tests are not evidence of remote behavior. + +## Upgrade compatibility + +Users upgrade in place, and the remote scenarios above routinely put two different OpenBitFun versions on the same connection. Every change must keep existing installs working without manual repair. + +- **Persisted shapes are read by older and newer code.** For config, settings, sessions, connection profiles, worktree and dispatch records: add fields with defaults, keep deserialization tolerant, never repurpose or narrow the meaning of a field already on disk, and never make required a field that old data cannot supply. +- **Never delete or reset user data to recover from something you cannot parse.** Keep the record, degrade the feature, and surface a clear state. Missing credentials, an unreadable profile, a timeout, or an offline host are not reasons to drop a session, workspace, or connection. Destructive removal stays an explicit user action. +- **Cross-version boundaries negotiate; they do not assume.** Peer HostInvoke, the dispatch protocol, relay and mobile web, and IM bots all talk to a build you do not control. Advertise a capability and check it before using it (package version equality is not evidence of behavior), and keep the older side on a working path instead of failing it. +- **A rename is a migration.** Keep reading the old name, id, or record shape until no supported peer can still send it, and migrate referenced data (vault entries, workspace pointers) together with the thing being renamed. +- **Prove it with tests.** Cover legacy deserialization and an old-payload round trip, not just the new shape. A test that only exercises data written by the current code is not upgrade coverage. + +## Read before changing + +Read the listed documents before editing in these areas. The sub-bullets are hard constraints. + +- **`openbitfun-core` decomposition, feature or dependency boundaries, Rust build speed**: [`docs/architecture/product-architecture.md`](docs/architecture/product-architecture.md) and [`docs/architecture/rust-build-dependency-boundaries.md`](docs/architecture/rust-build-dependency-boundaries.md). + - 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. +- **Agent Runtime deployment, multi-GUI/TUI/Remote instances, shared Session control, process topology**: [`docs/architecture/agent-runtime-deployment-design.md`](docs/architecture/agent-runtime-deployment-design.md). + - Do not key Rust Runtime or Node/Bun Plugin Host processes by client, workspace, session, or plugin by default; use the responsible state module, execution and security conditions, and measured capacity. +- **CLI/TUI parity, non-interactive output contracts, external config imports, plugin management UX, CLI Agent behavior, branded CLI distributions**: [`docs/architecture/cli-product-line-design.md`](docs/architecture/cli-product-line-design.md) and [`src/apps/cli/AGENTS.md`](src/apps/cli/AGENTS.md). + - Keep CLI/TUI presentation in the app; move reusable product behavior through Product Assembly, Agent Runtime, Tool/Harness, Runtime Services, or the existing extension boundaries. +- **HarmonyOS PC CLI/TUI**: [`docs/architecture/platform-portability-design.md`](docs/architecture/platform-portability-design.md). + - This is a future platform target, not implemented support. The product target is the real PC system terminal; HAP, `hdc shell`, the phone Remote App, and remote execution are not substitutes. Design each concrete adaptation as a separate topic and keep the current mobile capability unchanged. +- **Product definitions, branded distributions, GUI/TUI layout selection, bundled product extensions, customization build tasks**: [`docs/architecture/product-customization-blueprint.md`](docs/architecture/product-customization-blueprint.md). + - Keep product customization separate from user runtime configuration and plugins. GUI and TUI may share stable product facts, but not layout, component, theme-key, keybinding, or renderer schemas. + - Product assembly results and layout selections may carry a small immutable list of product identity, data-isolation, recovery, upgrade-integrity, or legal protection IDs. They must not carry user/source-level plugin policy, installation, activation, update, permission, or dynamic health state. + - Product Profile, Brand Pack, GUI/TUI Surface Blueprint, and Resolved Product Manifest are retired design terms, not production objects. Do not create compatibility formats for them; implement only the smallest product-definition and assembly-result fields used by a real build and runtime consumer. +- **OpenCode live configuration or plugin execution**: [`docs/architecture/extensions/opencode-extension-compatibility.md`](docs/architecture/extensions/opencode-extension-compatibility.md) and [`src/crates/adapters/opencode-adapter/AGENTS.md`](src/crates/adapters/opencode-adapter/AGENTS.md). + - The compatibility matrix describes targets and gaps; do not treat a design target as an already available capability. + - Do not extend the legacy managed-package path (the P0 static-preview entry) as the target OpenCode runtime model. +- **Agent hooks**: [`docs/features/agent-hooks.md`](docs/features/agent-hooks.md) ([中文](docs/features/agent-hooks.zh-CN.md)). + - Native user hooks implement the Codex hook contract, so is the reference for events, payload fields, and decision schema. Do not fork that contract. The feature doc covers only the OpenBitFun-specific parts (file locations, the `app.hooks` gates, and the deviations table) and must be updated whenever a deviation is added or closed. + - Engine, registry, hook-source, and dispatch ownership: the [`agent-runtime`](src/crates/execution/agent-runtime/AGENTS.md) and [`core`](src/crates/assembly/core/AGENTS.md) guides. +- **Lifecycle evidence, gates, Artifact Graph, Project Profile, Deep Review policy, OpenCode compatibility, target-project governance**: [`docs/sdlc-harness/README.md`](docs/sdlc-harness/README.md) first, then [`docs/sdlc-harness/design.md`](docs/sdlc-harness/design.md). If module boundaries or behavior change, follow the matching design under `docs/sdlc-harness/architecture/` or `docs/sdlc-harness/features/`. + - Do not hard-code OpenBitFun repository assumptions as target-project rules; keep quality protection behavior target-aware, evidence-backed, risk-tiered, cost-aware, and auditable. + +## Maintaining these guides + +- Keep this file to cross-cutting rules and stable repository entry points. Module ownership details, surface- or crate-specific commands, and focused test lists belong in the nearest guide; add a command there only when a real workflow needs it. +- Layer guides own the crate tables; do not enumerate crates here. +- Update `AGENTS.md` and `AGENTS-CN.md` in the same change. diff --git a/src/crates/assembly/core/AGENTS-CN.md b/src/crates/assembly/core/AGENTS-CN.md index 7c65793f65..38ea004a40 100644 --- a/src/crates/assembly/core/AGENTS-CN.md +++ b/src/crates/assembly/core/AGENTS-CN.md @@ -47,6 +47,13 @@ SessionManager -> Session -> DialogTurn -> ModelRound - `plugin_source` 只注入产品目录并保留兼容接口;受管插件包发现与信任持久化归 `services-integrations`,生态适配解析与 `PluginRuntimeClient` 行为分别归对应的适配器层和执行层。 - `plugin_runtime`、`external_sources` 与 `instruction_sources` 是经过评审、可分别为对应能力契约选择生态适配器的 owner-feature 组装文件。产品入口只消费产品级视图,不得导入适配器或原始插件运行时 client 类型。 +- `native_hooks` 是可移植 Hook 引擎(`openbitfun_agent_runtime::native_hooks`)的产品接线,负责 `hooks.json` 发现、 + `app.hooks` 开关、进程级 `RuntimeHookRegistry` 和按事件的类型化分发辅助函数;各分发点调用这些辅助函数,不要就地执行 Hook。 + 内置、用户、项目、导入、技能和插件 Hook 都通过 `RuntimeHookRegistry` 注册并由 `AgentHookEngine` 调度,同时各自保持信任、 + 配置、契约和执行策略语义。远程工作区使用独立的 Registry,只包含从目标端读取的项目 Hook,并在目标工作区 shell 中执行; + 用户、导入和技能命令 Hook 不会在远程工作区运行。`external_hooks` 是其他 AI 应用 Hook 的只读目录,不得进入可执行 + Registry:查看它不得加载代码;条目只有经显式 `external_hook_import` plan/apply 写成已评审快照后才可执行,不得实时读取来源。 + 契约参考与差异见 `docs/features/agent-hooks.zh-CN.md`。 - Remote/service 改动必须保持 external protocol lifecycle、workspace projection、scheduler/session restore、 terminal pre-warm 和 product execution 边界清晰。 - Feature 改动必须保持 `product-full` 作为兼容产品组装边界;默认能力选择只有在单独的 product matrix review 后才能变化。 diff --git a/src/crates/assembly/core/AGENTS.md b/src/crates/assembly/core/AGENTS.md index a39efaec5b..182bbf9897 100644 --- a/src/crates/assembly/core/AGENTS.md +++ b/src/crates/assembly/core/AGENTS.md @@ -89,6 +89,22 @@ SessionManager -> Session -> DialogTurn -> ModelRound product-domain control DTO and closed generic actions. Capability-specific approvals and conflict choices remain typed owner operations; do not add a second surface-specific lifecycle model or arbitrary control payload. +- `native_hooks` is the product wiring for the portable hook engine in + `openbitfun_agent_runtime::native_hooks`. It owns `hooks.json` discovery, the + `app.hooks` gates, the process-wide `RuntimeHookRegistry`, and typed + per-event dispatch helpers; dispatch sites call those helpers instead of + executing hooks inline. Built-in, user, project, imported, skill, and plugin + hooks register through a `RuntimeHookRegistry` and run through + `AgentHookEngine` while keeping distinct trust, configuration, contract, and + execution-policy semantics. A remote workspace gets a separate registry that + holds only the project hooks read from the target and runs them in the target + workspace shell; user, imported, and skill command hooks never run there. + `external_hooks` is the read-only catalog of other AI + applications' hooks and must not enter the executable registry: inspecting it + must not load code, and an entry becomes executable only as the reviewed + snapshot written by the explicit `external_hook_import` plan/apply, never by + reading the source live. Contract reference and deviations: + `docs/features/agent-hooks.md`. - Remote/service changes must keep external protocol lifecycle, workspace projection, scheduler/session restore, terminal pre-warm, and product execution boundaries explicit. diff --git a/src/crates/execution/agent-runtime/AGENTS.md b/src/crates/execution/agent-runtime/AGENTS.md index de515b07e3..9344ae29d6 100644 --- a/src/crates/execution/agent-runtime/AGENTS.md +++ b/src/crates/execution/agent-runtime/AGENTS.md @@ -100,6 +100,7 @@ in `config-contracts`. Focused verification: ```bash cargo test --locked -p openbitfun-agent-runtime --no-default-features --features agent-runtime --lib model_pool +``` `account_routing` owns pure fixed/ordered account selection and switch admission. Assembly injects immutable membership, host/model/policy/cache scope, current @@ -133,6 +134,29 @@ Focused check: cargo test --locked -p openbitfun-agent-runtime --no-default-features --features account-routing --lib account_routing ``` +## Native Hooks + +`native_hooks` owns the portable hook engine: Codex-compatible settings +parsing and validation, payload construction, command process execution, +decision merging, the shared `RuntimeHookRegistry`, and `AgentHookEngine` +dispatch. The hook contract and OpenBitFun's deviations from it are in +`docs/features/agent-hooks.md`. + +- The engine is host-independent. It receives already-loaded settings layers + and fully built payloads and never resolves OpenBitFun config paths. Config + discovery, the `app.hooks` gates, and per-event dispatch helpers belong to + `openbitfun-core::native_hooks`. +- Every executable hook registers through `RuntimeHookRegistry` under one + `RuntimeHookSource`: `Builtin`, `UserCommand`, `ProjectCommand`, + `ImportedCommand`, `SkillCommand`, or `Plugin`. The declaration order is the + stable source precedence. Sources share the registry and the engine but keep + distinct trust, configuration, contract, and execution-policy semantics. +- `post_call_hooks` holds routing decisions for compiled-in hooks; it is not + user configuration. +- The external hook catalog of other AI applications is read-only discovery + data owned by `openbitfun-product-domains`. It must not enter the executable + registry; this crate neither reads it nor registers from it. + ## Test Target Layout Integration contracts use six explicit Cargo targets so package-level checks From a50defe57c0e412f45783bbedb646cc9b737d71f Mon Sep 17 00:00:00 2001 From: Bob Lee Date: Tue, 10 Nov 2026 11:06:47 +0800 Subject: [PATCH 3/4] docs(architecture): correct module inventory and Computer Use ownership product-architecture.md: the Level 0 development-view diagram and the module inventory now cover every Cargo and pnpm workspace member, and the Computer Use notes name services/computer-use as the owner of the native implementation. computer-use-control.md: "Ownership and execution" still said that Desktop owns the native resources and Core owns the host port. That contradicted "Native provider ownership", added when the provider moved to services/computer-use. The section now lists what each owner holds and must not do, and points the module paths at the service. --- docs/architecture/computer-use-control.md | 65 ++++++++++++++--------- docs/architecture/product-architecture.md | 39 +++++++------- 2 files changed, 61 insertions(+), 43 deletions(-) diff --git a/docs/architecture/computer-use-control.md b/docs/architecture/computer-use-control.md index 7934ab4164..9098006907 100644 --- a/docs/architecture/computer-use-control.md +++ b/docs/architecture/computer-use-control.md @@ -156,19 +156,35 @@ background input. ## Ownership and execution -Portable DTOs and `AppInputAction` live in `tool-contracts`; the host port lives in -Core. Desktop owns native resources and platform adapters. Assembly must not own -OS APIs, native focus workarounds or concrete capture implementations. - -The shared action catalog and structural target validation live in -`tool-contracts`. Desktop's `control_session/admission.rs` is a deterministic -owner/mode/lease state machine; its facade alone performs native cleanup and -carries tokens across workers. `desktop_host/observation.rs` coordinates native -reads, while `observation_cache.rs` stores bounded references without owning input -permission. `computer_use_geometry` adapts the independent `computer-use-rust` -project's image/content/surface mapping for all three platforms. The reference -project's macOS-only capture/input and standalone MCP/session shell are not a -replacement for the existing Windows, Linux or product runtime providers. +This section details the split stated in +[Native provider ownership](#native-provider-ownership). Core does not depend on +`services/computer-use`; it reaches the provider only through the injected port. + +| Owner | Owns | Must not | +|---|---|---| +| `tool-contracts` (`computer_use*` modules) | Portable DTOs, `AppInputAction` and its structural target validation, the shared action catalog (`ControlActionPolicy`), control and permission facts, `CaptureGeometry`, the settle decision and the `ComputerUseHost` port | Hold OS handles or make permission decisions | +| `services/computer-use` | Native resources and platform adapters for Windows, macOS and Linux: capture, AX/UIA/AT-SPI, input, OS permission probes and requests, remembered grants, the control session and `NativeComputerUseHost`; `host_runtime` holds CLI graphical-session admission and the macOS main run loop | Import Core, Tauri or the CLI, or discover Core config | +| Core (Assembly) | The ComputerUse tool and its permission policy, the `computer_use_program` executor, the `ai.computer_use_enabled`, missing-provider and remote-workspace gates, and release of a turn's control through the port; its `computer_use_host` module only re-exports that port | Own OS APIs, native focus workarounds or concrete capture implementations | +| Desktop | Provider injection and its diagnostic directory, the Tauri status, permission, sharing and preview commands, and the devtools-only full Tool fixtures | Reintroduce a native implementation | +| CLI | Provider injection and its diagnostic directory for chat/exec inside a graphical login session, the main-thread run-loop adapter and the `computer-use` command | Reintroduce a native implementation, or infer a provider for Dispatch, ACP or the stdio server | + +Service paths below are relative to +`src/crates/services/computer-use/src/computer_use/`. +`control_session/admission.rs` is a deterministic owner/mode/lease state machine +with no OS handles; its facade `control_session.rs` alone performs native +cleanup and carries tokens across workers. `desktop_host/` implements the port +for `NativeComputerUseHost`. The directory kept its name when it moved out of +the Desktop app; Desktop and CLI share it. `desktop_host/observation.rs` +coordinates native reads, while `observation_cache.rs` stores bounded references +without owning input permission. The +[Native Computer Use guide](../../src/crates/services/computer-use/AGENTS.md) +has the full module map. + +`tool-contracts::computer_use_geometry` adapts the independent +`computer-use-rust` project's image/content/surface mapping for all three +platforms. The reference project's macOS-only capture/input and standalone +MCP/session shell are not a replacement for the existing Windows, Linux or +product runtime providers. ### Reference implementation migration @@ -178,8 +194,8 @@ runtime, build, test or filesystem dependency of OpenBitFun. | Area | Reference source | OpenBitFun owner and adaptation | |---|---|---| -| Permission query/request | `src/native/permissions.rs`, native permission probes | `computer_use_permissions` contracts, Desktop `permissions.rs`, `ComputerUsePermissions.tsx`; four separate read-only probes and explicit request receipts; Windows capability/UIPI facts and Linux AT-SPI/session consent replace macOS-specific assumptions | -| App sharing and control grants | `src/sharing.rs`, `src/grants.rs`, sharing controls in `src/gui.rs` | Admission state machine plus Desktop `sharing.rs`, `shared_preview.rs`, `process_identity.rs`, `grants.rs`, `share_grants.rs`; user-selected native window, observe first, separate revocable grant, executable-bound remembered preference, manual preview gestures | +| Permission query/request | `src/native/permissions.rs`, native permission probes | `computer_use_permissions` contracts, native service `permissions.rs`, Web `ComputerUsePermissions.tsx`; four separate read-only probes and explicit request receipts; Windows capability/UIPI facts and Linux AT-SPI/session consent replace macOS-specific assumptions | +| App sharing and control grants | `src/sharing.rs`, `src/grants.rs`, sharing controls in `src/gui.rs` | Admission state machine plus native service `sharing.rs`, `shared_preview.rs`, `process_identity.rs`, `grants.rs`, `share_grants.rs`; user-selected native window, observe first, separate revocable grant, executable-bound remembered preference, manual preview gestures | | Coordinate conversion | `CoordinateMap` in `src/sharing.rs` | Portable `CaptureGeometry` and Web `previewGeometry.ts`; image/content/global/preview round trips, aspect fit, negative origins, independent X/Y scales, strict padding rejection and immutable screenshot identity | | Virtual mouse | `src/cursor.rs`, GUI cursor rendering | Web `VirtualCursor.ts` ports the deterministic physical model, rendered by `PreviewCursor.tsx`; 63 Rust-generated reference samples cover movement, retargeting, immediate placement, resize and visibility. Existing passive native overlays remain platform adapters | | Background control | Native directed/semantic input and desktop-state comparison | Existing AX/UIA/AT-SPI and directed-input providers plus `background_guard.rs`; diagnostic focus/pointer/window-order evidence, explicit unsupported routes, no restore or replay. Concurrent human input does not revoke Agent control. The reference's implicit Command modifier is not copied because it changes the requested click | @@ -407,15 +423,16 @@ until the next information boundary and reuses the returned observation. It does not reduce the user's selected reasoning effort or impose step/retry-count caps. `get_app_state`, `app_batch` and single app-input aliases accept optional -`include_image` (default `true`). With `false`, Desktop reads AX and refreshes -observation/node identities without retrieving or encoding a model screenshot. -This is suitable for sufficient semantic state or known keyboard flows. Canvas, -visual verification and selecting image coordinates still need an image-bearing -observation. Target preparation, control leases, cancellation and native consent -remain unchanged; AX-only is not a different input route. Legacy port providers -can retain their old capture path and omit the image from its result. Existing -callers/persisted tool calls omit the field and retain their previous behavior. -The option is local tool presentation, not a new remote GUI capability. +`include_image` (default `true`). With `false`, the native provider reads AX and +refreshes observation/node identities without retrieving or encoding a model +screenshot. This is suitable for sufficient semantic state or known keyboard +flows. Canvas, visual verification and selecting image coordinates still need an +image-bearing observation. Target preparation, control leases, cancellation and +native consent remain unchanged; AX-only is not a different input route. Legacy +port providers can retain their old capture path and omit the image from its +result. Existing callers/persisted tool calls omit the field and retain their +previous behavior. The option is local tool presentation, not a new remote GUI +capability. Program receipts include `observation_elapsed_ms` alongside per-step and total elapsed time. These measure host execution, not model reasoning or end-to-end diff --git a/docs/architecture/product-architecture.md b/docs/architecture/product-architecture.md index d00d7b5081..c6eac87e5e 100644 --- a/docs/architecture/product-architecture.md +++ b/docs/architecture/product-architecture.md @@ -150,23 +150,23 @@ block-beta end block:AdaptersLayer - columns 7 - AdaptersTitle["3 · Adapters"] RuntimeIPC["Runtime
IPC"] AIAdapters["AI
Adapters"] SourceAdapters["Source
Adapters"] HookSupport["Hook
Support"] Transport["Transport"] WebDriver["WebDriver"] + columns 9 + AdaptersTitle["3 · Adapters"] RuntimeIPC["Runtime
IPC"] MiniAppIPC["MiniApp
IPC"] AIAdapters["AI
Adapters"] SourceAdapters["Source
Adapters"] PluginHost["Plugin
Host"] HookSupport["Hook
Support"] Transport["Transport"] WebDriver["WebDriver"] end block:ServicesLayer - columns 6 - ServicesTitle["4 · Services"] CoreServices["Core
Services"] Integrations["Integrations"] RelayService["Relay
Service"] PageRuntime["Page
Runtime"] Terminal["Terminal"] + columns 8 + ServicesTitle["4 · Services"] CoreServices["Core
Services"] Integrations["Integrations"] ComputerUse["Computer
Use"] LegacyMigration["Legacy
Migration"] RelayService["Relay
Service"] PageRuntime["Page
Runtime"] Terminal["Terminal"] end block:ExecutionLayer columns 10 - ExecutionTitle["5 · Execution"] AgentRuntime["Agent
Runtime"] AgentWorkflows["Agent
Workflows"] AgentStream["Agent
Stream"] PluginClient["Plugin
Client"] RuntimeServices["Runtime
Services"] ToolContracts["Tool
Contracts"] ToolGroups["Tool
Groups"] ToolExecution["Tool
Execution"] JSONRepair["JSON
Repair"] + ExecutionTitle["5 · Execution"] AgentRuntime["Agent
Runtime"] AgentWorkflows["Agent
Workflows"] AgentStream["Agent
Stream"] PluginClient["Plugin
Client"] RuntimeServices["Runtime
Services"] ToolContracts["Tool
Contracts"] ToolGroups["Tool
Groups"] ToolExecution["Tool
Execution"] OfficeDocuments["Office
Documents"] end block:ContractsLayer - columns 5 - ContractsTitle["6 · Contracts"] CoreTypes["Core Types"] Events["Events"] RuntimePorts["Runtime
Ports"] ProductDomains["Product
Domains"] + columns 6 + ContractsTitle["6 · Contracts"] CoreTypes["Core Types"] ConfigContracts["Config
Contracts"] Events["Events"] RuntimePorts["Runtime
Ports"] ProductDomains["Product
Domains"] end AppsLayer --> AssemblyLayer @@ -177,7 +177,7 @@ block-beta classDef module fill:#ffffff,stroke:#737373,stroke-width:1.3px,color:#171717 classDef sectionTitle fill:transparent,stroke:transparent,color:#171717,font-size:12px,font-weight:600 - class ProductApps,WebUI,MobileUI,Interfaces,AgentContent,CoreAssembly,ExternalSources,ProductCaps,RuntimeIPC,AIAdapters,SourceAdapters,HookSupport,Transport,WebDriver,CoreServices,Integrations,RelayService,PageRuntime,Terminal,AgentRuntime,AgentWorkflows,AgentStream,PluginClient,RuntimeServices,ToolContracts,ToolGroups,ToolExecution,JSONRepair,CoreTypes,Events,RuntimePorts,ProductDomains module + class ProductApps,WebUI,MobileUI,Interfaces,AgentContent,CoreAssembly,ExternalSources,ProductCaps,RuntimeIPC,MiniAppIPC,AIAdapters,SourceAdapters,PluginHost,HookSupport,Transport,WebDriver,CoreServices,Integrations,ComputerUse,LegacyMigration,RelayService,PageRuntime,Terminal,AgentRuntime,AgentWorkflows,AgentStream,PluginClient,RuntimeServices,ToolContracts,ToolGroups,ToolExecution,OfficeDocuments,CoreTypes,ConfigContracts,Events,RuntimePorts,ProductDomains module class AppsTitle,AssemblyTitle,AdaptersTitle,ServicesTitle,ExecutionTitle,ContractsTitle sectionTitle style AppsLayer fill:#f8fafc,stroke:#334155,stroke-width:2px @@ -192,32 +192,33 @@ block-beta | Development area | Repository scope | Current modules | |---|---|---| -| Apps | `src/apps/*` | `desktop`、`cli`、`server`、`relay-server`、`sdk-host`、`miniapp-market-server`、`skin-market-server` | -| Web and delivery | product roots | `src/web-ui`、`src/mobile-web`、`src/miniapp-market-web`、`src/skin-market-web`、`src/apps/mobile`、`OpenBitFun-Installer`、`tests/e2e` | +| Apps | `src/apps/*` | `desktop`、`cli`、`server`、`relay-server`、`sdk-host`、`miniapp-shell`、`data-tools`、`miniapp-market-server`、`skin-market-server`、`extension-host`(Bun Plugin Host 进程) | +| Web and delivery | product roots | `src/web-ui`、`src/mobile-web`、`src/miniapp-market-web`、`src/skin-market-web`、`src/apps/mobile`、`OpenBitFun-Installer`、`website`、`tests/e2e` | | SDK | `sdk/*` | `typescript` | -| Shared frontend | `src/shared` | `shared` | +| Shared frontend | `src/shared`、`packages/flow-chat-presentation` | `shared`、`flow-chat-presentation` | +| Design system | `design-system/*` | `packages/design-tokens`、`packages/theme-openbitfun`、`packages/ui`、`tooling/package-contract`、`tooling/token-engine`、`apps/design-lab` | | Interfaces | `src/crates/interfaces/*` | `acp`、`app-server`、`app-server-client`、`app-server-protocol`、`sdk-host` | | Assembly | `src/crates/assembly/*` | `agent-content`、`core`、`external-sources`、`product-capabilities` | -| Adapters | `src/crates/adapters/*` | `agent-runtime-ipc`、`ai-adapters`、`claude-code-adapter`、`codex-adapter`、`zcode-adapter`、`dsh-adapter`、`opencode-adapter`、`static-hook-support`、`transport`、`webdriver` | -| Services | `src/crates/services/*` | `services-core`、`services-integrations`、`miniapp-market-service`、`skin-market-service`、`relay-service`、`page-function-runtime`、`terminal` | -| Execution | `src/crates/execution/*` | `agent-runtime`、`agent-workflows`、`agent-stream`、`plugin-runtime-client`、`runtime-services`、`tool-contracts`、`tool-provider-groups`、`tool-execution` | -| Contracts | `src/crates/contracts/*` | `core-types`、`events`、`runtime-ports`、`product-domains` | +| Adapters | `src/crates/adapters/*` | `agent-runtime-ipc`、`miniapp-ipc`、`ai-adapters`、`opencode-adapter`、`opencode-plugin-host`、`dsh-adapter`、`pi-adapter`、`claude-code-adapter`、`codex-adapter`、`cursor-adapter`、`zcode-adapter`、`static-hook-support`、`transport`、`webdriver` | +| Services | `src/crates/services/*` | `services-core`、`services-integrations`、`computer-use`、`legacy-migration`、`legacy-migration-adapters`、`miniapp-market-service`、`skin-market-service`、`relay-service`、`page-function-runtime`、`terminal` | +| Execution | `src/crates/execution/*` | `agent-runtime`、`agent-workflows`、`agent-stream`、`plugin-runtime-client`、`runtime-services`、`tool-contracts`、`tool-provider-groups`、`tool-execution`、`office-documents` | +| Contracts | `src/crates/contracts/*` | `core-types`、`config-contracts`、`events`、`runtime-ports`、`product-domains` | -Installer、E2E 以及 MiniApp/Skin market server 和对应 service 在 Level 0 图中分别归入交付入口、测试范围或 Services 家族,不作为独立架构模块。 +图中子项与上表的对应:Product Apps 对应 Apps 行,Source Adapters 对应各外部生态来源 adapter,Legacy Migration 对应 `legacy-migration` 与 `legacy-migration-adapters`。Installer、E2E 以及 MiniApp/Skin market server 和对应 service 在 Level 0 图中分别归入交付入口、测试范围或 Services 家族,不作为独立架构模块;SDK、Shared frontend 与 Design system 在图中不单列。未进入 Cargo workspace 或 pnpm workspace 的其余目录(如 `packages/dsh-acp`、`extensions/`、`products/`、`MiniApp/`、`third_party/`)不计入本表。 Logical 与 Development 的主要映射如下,映射是多对多关系: | Development area | Logical coverage | |---|---| -| Apps & Interfaces | Application、Cross-platform 的宿主入口,Extensions 的用户控制面,以及 Desktop Computer Use 的平台实现 | +| Apps & Interfaces | Application、Cross-platform 的宿主入口,Extensions 的用户控制面,以及 Computer Use 原生 provider 的宿主注入 | | Assembly | Application、Agent Core、Tools & Execution 和 Extensions 的能力选择、产品编排与装配 | | Adapters | Tool Protocols 和外部生态接入所需的协议转换;adapter 本身不是逻辑层 | -| Services | Tools & Execution 的具体执行支持,以及 Cross-platform 的操作系统能力实现 | +| Services | Tools & Execution 的具体执行支持(含 Computer Use 的原生平台实现),以及 Cross-platform 的操作系统能力实现 | | Execution | Agent Core、Tools & Execution 的可移植原语与 Computer Use 契约,以及 Custom Agents、Tool Extensions、Hooks 的运行支持 | | Contracts | 为多个逻辑职责提供稳定事实与 port;不构成独立逻辑模块 | Assembly 是唯一组装根,只选择下层能力和实现,不能反向依赖 app。每个生态 adapter 独立保留外部格式和顺序语义,再映射到 OpenBitFun owner;生态 adapter 之间不能形成兄弟依赖。 -Computer Use 的控制会话、系统共享提示、后台输入边界与 macOS / Windows / Ubuntu 原生实现见 [Computer Use control-session SPEC](computer-use-control.md)。平台资源由 Desktop 持有,模式、状态和动作契约保持可移植;共享 Core 通过 host port 管理任务结束与取消时的释放。 +Computer Use 的控制会话、系统共享提示、后台输入边界与 macOS / Windows / Ubuntu 原生实现见 [Computer Use control-session SPEC](computer-use-control.md)。原生实现归 `services/computer-use`,由 Desktop 与图形会话中的 CLI 注入同一个 `NativeComputerUseHost`;模式、状态和动作契约保持可移植;共享 Core 通过 host port 管理任务结束与取消时的释放。 各层的静态职责按下表执行。层间只允许由上向下依赖;同层依赖必须有明确的单向 owner 关系,不能为了复用方便形成环。 From 2f0dd22be82f69ad8a34937b7e0b3ffc16e2a865 Mon Sep 17 00:00:00 2001 From: Bob Lee Date: Tue, 10 Nov 2026 11:06:47 +0800 Subject: [PATCH 4/4] docs(contributing): point at the current agent guide and checks CONTRIBUTING referred to a verification matrix and an i18n row in AGENTS.md that the guide does not have. State the i18n commands directly, name the Rust dependency boundary doc beside the product architecture doc, and link AGENTS-CN.md from the Chinese guide. --- CONTRIBUTING.md | 11 ++++++----- CONTRIBUTING_CN.md | 10 ++++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1b5e81838d..e3dd1e4da5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -96,9 +96,8 @@ in end-user `release` builds. ## Code Standards and Architecture Constraints -Use [`AGENTS.md`](AGENTS.md) as the canonical source for architecture-sensitive -rules, module boundaries, and the verification matrix. In contributor-facing -terms: +Use [`AGENTS.md`](AGENTS.md) as the canonical source for repository-wide rules, +layer boundaries, and how to choose verification. In contributor-facing terms: - Logs are English-only and should stay useful, not noisy. - User-visible copy should use the project i18n flow; do not share Web UI @@ -109,7 +108,8 @@ terms: - Tauri commands use `snake_case` command names and structured `request` payloads. - Product architecture, feature-boundary, dependency-boundary, and build-speed - work must follow `docs/architecture/product-architecture.md`. + work must follow `docs/architecture/product-architecture.md` and + `docs/architecture/rust-build-dependency-boundaries.md`. - Feature-specific rules belong in the nearest module `AGENTS.md`. ## Key Contribution Focus Areas @@ -190,7 +190,8 @@ Common local checks: | Mobile web | `pnpm --dir src/mobile-web run type-check` | | Rust shared runtime or services | Follow the nearest module `AGENTS.md`: one package/test target and the minimum required features | | Desktop/Tauri integration | `cargo check -p openbitfun-desktop` | -| i18n resources or contract | use the matching i18n row in `AGENTS.md` | +| i18n resources | `pnpm run i18n:audit` | +| i18n contract or shared terms | `pnpm run i18n:generate && pnpm run i18n:contract:test && pnpm run i18n:audit` | For UI changes, include screenshots or a short recording when helpful. If you cannot run a relevant check, explain why in the PR and provide a lower-risk diff --git a/CONTRIBUTING_CN.md b/CONTRIBUTING_CN.md index 1319bd06b5..2ed6461f19 100644 --- a/CONTRIBUTING_CN.md +++ b/CONTRIBUTING_CN.md @@ -80,7 +80,7 @@ pnpm run e2e:test `.openbitfun/desktop-dev/` 下。显式设置的数据目录环境变量仍优先生效; `--shared-data` 保留为默认模式的兼容写法。 -> 完整脚本列表见 [`package.json`](package.json)。agent 专用命令、验证与架构规则见 [`AGENTS.md`](AGENTS.md)。 +> 完整脚本列表见 [`package.json`](package.json)。agent 专用命令、验证与架构规则见 [`AGENTS-CN.md`](AGENTS-CN.md)。 ### 桌面端调试工具 @@ -90,14 +90,15 @@ DevTools;`Cmd/Ctrl + Shift + I` 切换 OpenBitFun 元素检查器,`Cmd/Ctrl ## 代码规范与架构约束 -架构敏感规则、模块边界和验证矩阵以 [`AGENTS.md`](AGENTS.md) 为准。面向贡献者只需把握: +仓库级规则、分层边界和验证选择方式以 [`AGENTS-CN.md`](AGENTS-CN.md) 为准。面向贡献者只需把握: - 日志只使用英文,并保持必要、可读。 - 用户可见文案走项目 i18n 流程;不要把 Web UI locale catalog 共享给较小产品形态。 - shared core 必须保持平台无关;Desktop/Tauri 细节属于 app adapter,并通过类型化能力接口回流;需要事件投递时使用已有生产 transport adapter。 - Tauri command 使用 `snake_case` 命令名和结构化 `request` 参数。 - core 拆解、feature 边界、依赖边界和构建提速重构必须遵循 - `docs/architecture/product-architecture.md`。 + `docs/architecture/product-architecture.md` 和 + `docs/architecture/rust-build-dependency-boundaries.md`。 - 功能级规则应放在离代码最近的模块 `AGENTS.md` 中。 ## 重点关注的贡献方向 @@ -174,7 +175,8 @@ Repository Object Sizes 检查会拒绝超过 5 MiB 的 Git 文件对象,包 | Mobile web | `pnpm --dir src/mobile-web run type-check` | | Rust 共享 runtime 或 services | 遵循最近模块的 `AGENTS.md`,选择单个包/测试目标和最小所需 feature | | Desktop/Tauri 集成 | `cargo check -p openbitfun-desktop` | -| i18n 资源或契约 | 使用 `AGENTS.md` 中匹配的 i18n 验证行 | +| i18n 资源 | `pnpm run i18n:audit` | +| i18n 契约或共享术语 | `pnpm run i18n:generate && pnpm run i18n:contract:test && pnpm run i18n:audit` | UI 改动在有帮助时附截图或短录屏。无法运行相关检查时,在 PR 中说明原因,并提供风险更低的手动验证路径。