Skip to main content

build

Function build 

Source
pub async fn build(
    resolved: &ResolvedModel,
    args: &Args,
    cwd: &Path,
    project_trusted: bool,
) -> Result<(AgentHarness, Receiver<AgentEvent>, ReloadContext), BuildError>
Expand description

Build the AgentHarness from the resolved model + parsed args + cwd.

This is the v1 equivalent of TS createAgentSession. It:

  1. Builds the OsExecutionEnv rooted at cwd.
  2. Constructs the built-in tools (optionally filtered by --tools/ --exclude-tools/--no-tools/--no-builtin-tools).
  3. Resolves the session storage (ephemeral vs fresh JSONL vs restore-error).
  4. Assembles AgentHarnessOptions and calls AgentHarness::create.

Returns the harness plus a broadcast::Receiver<AgentEvent> carrying the live AgentEvent stream from every run (backed by a BroadcastEmitter installed on the harness). Interactive mode drains this to render streaming responses; the non-interactive modes simply drop it. Returns the harness, the live AgentEvent broadcast receiver, and a ReloadContext the interactive TUI holds to drive /reload (and a plugin’s runtime_action(Reload) via the mailbox). Non-interactive modes drop the context (no /reload surface in print/json mode).