Core は手書きのツールハンドラーなしで使える完全な「ハンド」です。プロセスグループ単位でキャンセルできる bash、セッションのワークスペースに限定されたファイルツール、stdio MCP スーパーバイザー、セッションごとのクリーンアップ、登録可能なケイパビリティを備えます。1 つのコアで BMA クラウドとローカルのブレインを同時に処理できます。Go のみで、bash はサンドボックスではありません。すべてのブレインが executor の OS ユーザーとして動きます。
bma-executor-sdk 1.12.2 とその契約(
contracts/bma/executor、プロトコル bma.executor.v1.1)から生成しています。インストール、認証情報、クイックスタートは bma-executor-sdk の概要、プロトコル自体は Executor Protocol を参照してください。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
1 つのクライアント上で 1 つのブレイン向けにsession.assign、session.stop、tool.call と登録済みのすべてのケイパビリティを処理します。クライアントの start の前に呼び出してください。ブレインの名前はコアごとに一意である必要があります。
// 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
コアのセッションで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 を処理します。インストールは 1 つずつ実行されます。
// TypeScript SDK 1.12.2 にはありません。
# Python SDK 1.12.2 にはありません。
func NewSkillInstallCapability(install SkillInstaller) (Capability, error)
CoreSession
ケイパビリティから見た、1 つのブレインに割り当てられた 1 つのセッション。// 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)