Core 是一只完整的“手”,无需手写工具处理器:带进程组取消的 bash、限定在会话工作区内的文件工具、stdio MCP 监管器、按会话清理,以及可注册的能力。一个 core 可以同时服务 BMA 云端和本地的脑。仅 Go 提供;bash 不是沙箱:所有脑都以 executor 的操作系统用户身份运行。
由 bma-executor-sdk 1.12.2 及其契约(
contracts/bma/executor,协议 bma.executor.v1.1)生成。安装、凭据与快速开始见 bma-executor-sdk 概览;协议本身见 Executor 协议。NewCore
校验选项并创建工作根目录。// TypeScript SDK 1.12.2 中没有此接口。
# Python SDK 1.12.2 中没有此接口。
func NewCore(opts CoreOptions) (*Core, error)
type CoreOptions struct {
// WorkRoot holds every session workspace: WorkRoot/<brain>/<session>.
WorkRoot string
// Workspace overrides the per-session directory (for example a machine
// executor whose sessions all share one directory, or a desktop app
// mapping a brain to a project folder). Tools are confined to it.
Workspace func(brain, sessionID string) string
// MaxSessions bounds active sessions across all attached brains;
// MaxSessionsPerBrain bounds one brain (defaults to MaxSessions). A full
// core answers session.assign with executor_busy (-32009, retryable).
MaxSessions int
MaxSessionsPerBrain int
// MaxMCPServersPerSession bounds session.assign.mcp_servers (default 4).
MaxMCPServersPerSession int
// BashTimeout applies when neither tool.call deadline_ms nor the bash
// timeout_ms is set (default 10 minutes).
BashTimeout time.Duration
// MaxOutputBytes caps each captured bash stream (default 1 MiB).
MaxOutputBytes int
// InlineResultBytes is the largest bash output returned inline (default
// 48 KiB, under the 64 KiB control frame). Larger output is truncated.
InlineResultBytes int
// ComputerUse serves computer_observe and computer_action and advertises
// capabilities.computer_use (for example NewCuaDriver). Nil leaves
// computer use off: the harness then sends no computer_* tool.
ComputerUse ComputerUseBackend
// ComputerVision tells whether the model that reads a session's
// computer use results takes images. When it answers
// ComputerVisionTextOnly, an observation's screenshot is still taken
// (actions use its pixels) but not sent: the result carries its text and
// a note that the model cannot read images. Nil, or
// ComputerVisionUnknown, sends the screenshot.
ComputerVision func(ctx context.Context, q ComputerVisionQuery) ComputerVisionAnswer
// Env is set on every bash tool and process and cannot be overridden by
// a request (for example BMA_HOME).
Env map[string]string
// DenyEnv reports executor-private variables (credentials, state paths)
// that no bash tool, process or stdio MCP server may see: they are
// dropped from the inherited environment and a request setting one is
// rejected. NewCore rejects an Env entry it denies.
DenyEnv func(name string) bool
// RunAs, when set, is the OS identity every bash tool, process and stdio
// MCP server runs as, so a privileged executor (for example root) keeps
// its own credentials and state out of the workload's reach. HOME and
// USER in bash and process environments are the workload's. On Linux,
// the file tools (read, write, edit, glob, grep) use the workload's file
// identity. Unix only.
RunAs *RunAs
// Launch runs before each bash tool command starts (tool.call and
// LocalToolRoute, so also ACPAgent's own tools), with the semantics of
// ProcessOptions.Launch: it may change the directory, argv and
// environment, or refuse the start; see LaunchFunc. File tools run inside
// the executor and do not call it (they stay within the session
// workspace). Nil starts commands as before.
Launch LaunchFunc
// FileAccess runs before every file tool (read, write, edit, glob, grep)
// of this machine: a tool.call and the tools of a LocalToolRoute (so also
// ACPAgent's). It gets the session, the tool, the operation (read or
// write) and the workspace-relative path, and refuses by returning an
// error: an *RPCError (NewReasonError) gives its data.reason as the
// refusal code, any other error permission_denied. A LocalToolRoute call
// is then not_forwarded with the code as Code, recorded like a result (the
// same call id is answered with it again); a tool.call fails with
// "<code>: <message>". Nothing is read or written when it refuses. A host
// uses it for read-only sessions, protected paths, revoked grants and
// stopped turns. The tools stay within the workspace with or without it,
// unless OutsideFiles is set.
// Nil allows every file tool call as before. See FileAccessRequest.
FileAccess FileAccessFunc
// OutsideFiles lets a file tool use an absolute path outside the session
// workspace and mounts (as the user this executor runs as) when
// FileAccess allows that call: the request then has Outside set and the
// absolute path. FileAccess is required with it. Off, such a path fails
// without asking FileAccess, as before. A host sets it for a session
// that has full access to the computer; relative paths stay in the
// workspace either way.
OutsideFiles bool
// ToolOutputDir, when set, holds the output files of the bash commands
// of a LocalToolRoute (so also ACPAgent's own tools):
// ToolOutputDir/<short hash of the session>/, created 0700 (owned by
// RunAs when set). Empty keeps them in .bma-bash/ under the turn's
// working directory. A host whose Launch sandboxes commands sets it to a
// directory outside every folder a session may write, so the executor
// writes nothing into the user's folders. The read tool of the session
// may read its own output files there. tool.call bash keeps its output
// in memory and does not use it.
ToolOutputDir string
// EndAfterToolCall marks sessions that carry exactly one tool call: the
// core ends them (session.ended "completed") after the result is
// delivered. BMA's durable selfhost queue assigns such sessions.
EndAfterToolCall func(SessionAssignParams) bool
// OnAssign runs on every accepted session.assign of the core, the first
// one of a session (the session exists, workspace and MCP servers not yet
// prepared) and each replay (sent again before tool calls, on reconnect,
// to renew a grant). A host keeps per-session state from params.Metadata
// here: a replay carries the whole metadata again, a key it no longer
// holds is gone, and the session's Assignment shows the newest assign's
// once OnAssign returns. A returned error refuses the assign (invalid
// params naming it): a first assign creates no session, a replay leaves
// the previous metadata. End of the session is the session's Context.
// Nil does nothing.
OnAssign func(session *CoreSession, params SessionAssignParams) error
OnLog func(LogEvent)
}
Register
添加一项能力(一组位于能力位之后的方法);在Attach 之前调用。
// TypeScript SDK 1.12.2 中没有此接口。
# Python SDK 1.12.2 中没有此接口。
func (c *Core) Register(capability Capability) error
type Capability struct {
// Advertise sets the capability bits on the register capabilities.
Advertise func(*Capabilities)
Methods map[string]Handler
SessionScoped bool
OnSessionEnd func(*CoreSession)
}
Capabilities
挂接的客户端应声明的能力。// TypeScript SDK 1.12.2 中没有此接口。
# Python SDK 1.12.2 中没有此接口。
func (c *Core) Capabilities() Capabilities
Attach
在一个客户端上为一个脑处理session.assign、session.stop、tool.call 以及所有已注册的能力;在客户端 start 之前调用。同一个 core 中脑的名称必须唯一。
// TypeScript SDK 1.12.2 中没有此接口。
# Python SDK 1.12.2 中没有此接口。
func (c *Core) Attach(brain string, client *Client) error
Close
停止所有脑的所有会话,不报告session.ended。
// TypeScript SDK 1.12.2 中没有此接口。
# Python SDK 1.12.2 中没有此接口。
func (c *Core) Close()
Env
由 executor 的基础环境、请求的 env(有界;拒绝加载器变量和被禁止的变量)以及CoreOptions.Env 构建 bash 或进程环境。
// TypeScript SDK 1.12.2 中没有此接口。
# Python SDK 1.12.2 中没有此接口。
func (c *Core) Env(explicit map[string]string) ([]string, error)
NewProcessCapability
在 core 会话上处理process.start/read/write/interrupt/terminate/list 和 process.status:管道或 PTY、按游标寻址的输出、幂等的启动与写入、超时以及进程组信号;为 nil 的钩子不设置对应的能力位。
// TypeScript SDK 1.12.2 中没有此接口。
# Python SDK 1.12.2 中没有此接口。
func NewProcessCapability(core *Core, opts ProcessOptions) Capability
type ProcessOptions struct {
// Env is set on every process (not on bash tools) over the request env,
// for example a canonical skill root such as BMA_HOME.
Env map[string]string
FileTransfer FileTransferer
GitCredentials GitCredentialGranter
// PackageInstaller serves process.start package_install.
PackageInstaller PackageInstaller
// Launch runs before each new command process starts; see LaunchFunc.
Launch LaunchFunc
// SessionFiles syncs each agent session's files below its root, which
// is advertised as capabilities.session_files.root; see SessionFiles.
SessionFiles *SessionFiles
}
NewSkillInstallCapability
用你的安装器处理skill.install;安装一次只运行一个。
// TypeScript SDK 1.12.2 中没有此接口。
# Python SDK 1.12.2 中没有此接口。
func NewSkillInstallCapability(install SkillInstaller) (Capability, error)
CoreSession
某个脑的一个已分配会话,即能力所看到的会话。// TypeScript SDK 1.12.2 中没有此接口。
# Python SDK 1.12.2 中没有此接口。
func (s *CoreSession) ID() string
func (s *CoreSession) Brain() string
func (s *CoreSession) Workspace() string
func (s *CoreSession) Client() *Client
func (s *CoreSession) Context() context.Context
func (s *CoreSession) Assignment() SessionAssignParams
func (s *CoreSession) Value(key any, create func() any) any
func (s *CoreSession) ResolveCwd(cwd string) (string, error)