runner

package
v0.1.0-beta.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package runner orchestrates skill-run execution against the daemon's wired runtime, persisting the typed event ledger as it goes.

The runner sits between the API layer (POST /api/agent/runs) and the registry-server dispatch path. It opens a JSONL ledger via persist.Store, writes EventRunStarted synchronously, dispatches the skill asynchronously, and records EventRunCompleted (and an EventError on failure) when the dispatcher returns. The synchronous start lets the API return {run_id, started_at} before the run completes; SSE subscribers see the head of the ledger without racing the first event.

The runner is intentionally decoupled from pkg/registry: it accepts an Executor interface that any caller can satisfy. *registry.Server satisfies it via its existing CallTool method.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecorderFromContext

func RecorderFromContext(ctx context.Context) (*persist.Recorder, bool)

RecorderFromContext returns the active run's recorder, when one is in scope. Bindings that emit per-call events read it through this accessor rather than caching the recorder at install time, because the install* helpers run before the recorder is wired in.

func Run

func Run(ctx context.Context, store *persist.Store, exec Executor, opts StartOptions) (string, *mcp.ToolCallResult, error)

Run opens a new run ledger, writes EventRunStarted synchronously, dispatches the skill synchronously via exec, records the terminal event, and closes the recorder before returning. Unlike Start it blocks until dispatch completes and returns both the run ID and the tool-call result so callers (e.g. the MCP transport, which must put the result on the wire) can surface them together.

ctx is propagated as-is to the dispatcher — cancellation does flow through, so an interrupted MCP request records an error event and returns ctx.Err() to the caller.

func RunIDFromContext

func RunIDFromContext(ctx context.Context) (string, bool)

RunIDFromContext returns the run ID stashed on ctx by a parent runner.Run / runner.Start, plus a flag noting whether the value was present. The flag distinguishes "no parent run" from "parent run with empty id" (which should never happen but is structurally possible).

func Start

func Start(ctx context.Context, store *persist.Store, exec Executor, opts StartOptions) (string, time.Time, error)

Start opens a new run ledger, writes EventRunStarted synchronously, and dispatches the skill asynchronously via exec. Returns the run ID and the started_at timestamp from the recorded event. The async goroutine writes EventRunCompleted (and an EventError on failure) before closing the recorder.

The goroutine inherits ctx's values (trace span context, request IDs) but not its cancellation — the dispatch outlives the HTTP request that started it.

Types

type Executor

type Executor interface {
	CallTool(ctx context.Context, name string, arguments map[string]any) (*mcp.ToolCallResult, error)
}

Executor invokes a registered skill with the daemon's fully-wired bindings (tool/llm/approval). *registry.Server satisfies this via its CallTool method.

type StartOptions

type StartOptions struct {
	// Skill is the registered skill name to invoke.
	Skill string

	// Flavor is the skill's handler-language flavor ("ts" today).
	// Recorded in the ledger so the inspector can render it.
	Flavor string

	// Input is the parsed JSON input handed to the executor.
	Input map[string]any

	// RawInput is the original JSON bytes for the input, preserved
	// verbatim in EventRunStarted so resume can re-issue the run
	// without re-encoding through Go's map iteration order.
	RawInput json.RawMessage
}

StartOptions configures a single Start call.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL