Core Agent Guide
September 7, 2026 · View on GitHub
中文 | English
Core Agent Guide
Scope
This file applies to src/crates/assembly/core. Use the top-level AGENTS.md for
repository-wide rules and the nearest narrower guide when one exists.
Role
openbitfun-core is the shared product runtime facade. It still owns compatibility
paths and the product-full assembly boundary, but new decomposition work should
prefer the owner crates described in docs/architecture/product-architecture.md
and docs/architecture/agent-runtime-services-design.md.
Main areas:
src/agentic/: agents, prompts, tools, sessions, execution, persistencesrc/service/: config, filesystem, terminal, git, MCP, remote connect, AI memorysrc/infrastructure/: AI clients, app paths, event system, storage, debug log serversrc/product_runtime/: Core Agent Runtime compatibility adapters and runtime service provider wiring
Agent runtime mental model:
SessionManager -> Session -> DialogTurn -> ModelRound
Boundary Rules
- Keep shared core platform-agnostic. Avoid host-specific APIs such as
tauri::AppHandle; use shared abstractions such asopenbitfun_events::EventEmitter. - Desktop-only host adapters belong in
src/apps/desktop, then flow through typed capability interfaces; use the production transport adapter when event delivery is needed. - Do not add new cross-layer references from
servicetoagenticwithout a narrow port/interface boundary. - Do not move platform-specific logic, build-script behavior, product capability selection, or provider-specific AI serialization into shared core.
- When moving ownership out of core, preserve old import paths with facade or re-export code until downstream call sites are intentionally migrated.
Decomposition Rules
- Treat
openbitfun-coreas a compatibility facade plus full product assembly point, not as the preferred home for new stable contracts. - Put stable DTOs, facts, ports, and pure decisions in the matching owner crate where a clear owner exists. Keep concrete managers, IO, platform adapters, and product execution in core until a reviewed port/adapter/service design and behavior equivalence tests exist.
- Tool changes must preserve expanded/collapsed exposure, prompt-visible
manifests,
GetToolSpec, permission behavior,ToolUseContextsemantics, and desktop/MCP/ACP catalog behavior. - Workspace file tools select IO through
ToolUseContext::file_system_for_path. Read/Write/Edit/Delete/LS must not add per-tool SSH branches. Shared algorithms belong intool-execution; concrete filesystem/stream handling belongs in Services providers. Session artifacts stay host-local. A missing remote provider must fail without falling back to the controller filesystem. - Snapshot preparation/completion may fail independently of the file tool. Never replay a mutation to repair tracking. A recorded operation is not proof of complete Session coverage; remote Session Undo retains its coverage gate.
- Runtime-owner migrations must keep concrete lifecycle, IO, event delivery, permission orchestration, and remote/platform implementations in core until the target owner has a reviewed port/adapter/service design plus behavior-equivalence tests.
- Product-domain changes may move pure product-domain plans with equivalence coverage, but filesystem writes, worker/host side effects, Git/AI concrete calls, marker IO, and path-manager integration stay in core unless a reviewed owner design says otherwise.
plugin_sourcemay inject product-owned paths and keep compatibility exports; concrete managed-package discovery and trust persistence stay inservices-integrations, while ecosystem parsing and PluginRuntimeClient behavior remain in their adapter and execution owners.plugin_runtime,external_sources, andinstruction_sourcesare the reviewed owner-feature composition files allowed to select ecosystem adapters for their respective capability contracts. Product surfaces consume product-level views and must not import adapter or raw plugin runtime client types.- The managed OpenCode Plugin Host is an adapter/service resource. Core may
assemble its launch, retain opaque logical instance and PTY scope bindings,
and bridge matched requests to existing product owners. OpenCode route
matching, wire DTOs, serialization/error mapping, and physical process-tree
supervision stay in
opencode-plugin-hostandservices-core; Core route projections must not invent provider connectivity, VCS, permission, or other owner state. - External-source Desktop, TUI, Peer, and Server surfaces share the versioned 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.
- Remote/service changes must keep external protocol lifecycle, workspace projection, scheduler/session restore, terminal pre-warm, and product execution boundaries explicit.
- Feature work must keep
product-fullas the compatibility product assembly boundary unless a separate product matrix review changes default capability selection. agent-runtimeowns the Core Agent lifecycle baseline, native Hook runtime, basic filesystem/process tools, and Agent-control tools, including scheduled job execution. Concrete network and product capabilities stay explicitly selectable:model-catalog,mcp-runtime,remote-connect,workspace-search,browser-control,web-tools,deep-research, andscript-tool-runtime.model-catalogcomposes runtime services for catalog update events;mcp-runtimelayers the Core MCP tool bridge on the Agent lifecycle; andremote-connectlayers its phone relay on the Agent lifecycle and model catalog. None of these relationships may be hidden in theagent-runtimebaseline.scheduled-jobs,document-read, andsubscription-authare additive dependency/source modifiers, not standalone runtime profiles. The latter two use Cargo weak dependency forwarding so they refine an already selected tool or adapter owner without activating that owner by themselves. Product-owned managed worktree lifecycle is available only when the Agent lifecycle and Git service owners are both selected; it is not a tool-pack owner. Function Agent adapters use the independentfunction-agentsowner; MiniApp domain/runtime/market dependencies belong only totools-miniapp. Tool implementation groups use the matchingtools-*owner feature. Product Assembly supplies the exactProductToolPlan; Core materialization validates that requested owners were compiled and must not infer product capability from Cargo's feature union. The Agent Runtime baseline plan is exactlyBasicplusAgentControl, not a hidden delivery profile.external-sourcesadds third-party discovery/import adapters,plugin-runtimeadds executable plugin-client wiring,opencode-plugin-hostcomposes the managed Host and its reviewed route owners. None may enableproduct-full.- CLI/ACP closure checks keep Cargo resolver-v2 normal and host
(build/proc-macro) feature contexts separate, while treating all
target-specific declarations within each context as one reviewed architecture
boundary. Split a package/module owner when platforms genuinely differ; do
not hide an unreviewed Core capability behind mutually exclusive Cargo
cfgbranches. - Keep the light compatibility features independently compilable. Local service
profiles are
dispatch-store,terminal,workspace-runtime, andworkspace-watch;remote-workspaceadds only the remote workspace facade, whilessh-remoteadds concrete SSH transport. Integration facadesannouncement,file-watch,git, andreview-platformremain independent, withservice-integrationsonly their compatibility aggregate. None of these narrow features may enableproduct-fulldirectly or transitively. product-fullmust explicitly compose every capability it consumes, including product-onlyservices-corefeatures such aspermission,session-git, andruntime-ownership, every concrete service owner, and everytools-*group. Do not put those features on the dependency declaration, because Cargo feature union would force them into every core consumer.- Core's default feature set is empty.
product-fullis an explicit compatibility assembly selected by real product entrypoints, never the library's implicit default. Capability-local utility dependencies remain optional and are activated by their owner features; in particular,base64,futures,regex,tokio-util, andopenbitfun-agent-toolsbelong to the Agent Runtime, local-storage, or dispatch-store closures that use them. Core's direct feature-free Tokio edge keeps only filesystem and synchronization support required by config and app-path state; the selected Services Corejson-ioowner separately carries the runtime/time capabilities required for bounded atomic JSON writes. - Backend Fluent bundles and mutable translation state are owned by
i18n-runtime; locale ids, aliases, fallback facts, metadata, and model-facing language copy remain feature-free contracts. Hosts that callI18nServicemust selecti18n-runtimeexplicitly. - Reusable diagnostic redaction and local Diff implementations remain
compatibility facades under the exact
diagnosticsanddifffeatures. Agent Runtime selectsopenbitfun-services-core/workspace-text-runtimefor bounded asynchronous workspace reads; synchronous path normalization stays available to contract-only consumers without Tokio. - Platform transport emitters are host adapters. Desktop imports
openbitfun_transport::TransportEmitterdirectly; Core exposes only the stableopenbitfun_events::EventEmittercontract and must not re-export a host adapter. - Keep
cargo check -p openbitfun-core --no-default-featuresviable. Gate product-only modules at their owner feature; if a light facade operation cannot safely complete without a product owner, fail closed and preserve any durable recovery state instead of enablingproduct-fullimplicitly.
Owner References
Use these files for ownership details instead of expanding this guide:
docs/architecture/product-architecture.mddocs/architecture/agent-runtime-services-design.mdsrc/crates/execution/agent-runtime/AGENTS.mdsrc/crates/execution/tool-contracts/AGENTS.mdsrc/crates/execution/agent-workflows/AGENTS.mdsrc/crates/contracts/product-domains/AGENTS.mdsrc/crates/contracts/runtime-ports/andsrc/crates/execution/runtime-services/source docssrc/crates/services/services-core/AGENTS.mdsrc/crates/services/services-integrations/AGENTS.mdsrc/crates/execution/tool-provider-groups/AGENTS.md
Narrower local guides already exist for some subtrees:
src/crates/adapters/ai-adapters/AGENTS.mdsrc/crates/assembly/core/src/agentic/execution/AGENTS.mdsrc/crates/assembly/core/src/agentic/deep_review/AGENTS.md
Verification
This guide owns Core verification. Select one command pattern that matches the change; do not run every feature variant:
cargo check -p openbitfun-core --no-default-features
cargo check -p openbitfun-core --no-default-features --features <touched-owner-feature>
cargo test -p openbitfun-core --no-default-features --features <minimal-features> --lib <module>::<test>
Use the first command when the feature-free facade changed, the second when one
feature boundary changed, and the third for behavior. Run
pnpm run check:core-boundaries only for Cargo features, dependency direction,
or test-target layout. Workspace checks and product-wide tests are CI-backed and
are not the default Core precheck. For documentation-only changes, run
git diff --check.
Configuration persistence, account settings import, backup restore, legacy field/deletion compatibility, local-change notifications, and save/reload/model concurrency regressions have feature-free fixtures:
cargo test -p openbitfun-core --no-default-features --lib service::config::
The account sync adapter requires remote-connect, which also covers
Agent-profile canonicalization in the focused configuration suite:
cargo test -p openbitfun-core --no-default-features --features remote-connect --lib service::config::
cargo test -p openbitfun-core --no-default-features --features remote-connect --lib service::remote_connect::settings_sync::tests
Focused workspace-IO and snapshot regression entry points (use the matching filter rather than a product-wide build):
cargo test -p openbitfun-core --no-default-features --features agent-runtime,git,document-read --lib file_read_tool::tests
cargo test -p openbitfun-core --no-default-features --features agent-runtime,git --lib file_write_tool::tests
cargo test -p openbitfun-core --no-default-features --features agent-runtime,git --lib delete_file_tool::tests
cargo test -p openbitfun-core --no-default-features --features agent-runtime,remote-workspace,git --lib service::snapshot::
Skill discovery, installation provenance, and local/remote registry regressions:
cargo test --locked -p openbitfun-core --no-default-features --features agent-runtime,git --lib agentic::tools::implementations::skills::
Detached Dispatch controller, target query compatibility, and managed-baseline checks:
cargo test --locked -p openbitfun-core --no-default-features --features agent-runtime,dispatch-store,ssh-remote,git --lib service::dispatch::