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)
}