package execution import "../agent" import "../conversation" import "../provider" import "../sessionstore" import "../tool" import "core:mem" import "core:sync" import "core:time" // Injected test/host clock. Monotonic coordinates are process-local durations; // wall time is Unix nanoseconds for persistence. Neither callback allocates. Clock :: struct { data: rawptr, monotonic: proc(data: rawptr) -> time.Duration, wall: proc(data: rawptr) -> i64, } // Borrowed services with composition-root lifetime. WP2 supplies immediate step; // WP3 dispatches injected services on workers. No real store/adapter yet. Volatile is an explicit // child policy, never a fake successful durable save. Services :: struct { model: provider.Adapter, tools: ^tool.Registry, store: sessionstore.Store, clock: Clock, checkpoint_policy: agent.Checkpoint_Policy, identities: ^agent.Identity_Issuer, // Shared root lifetime, never reset by runtime teardown. identity_mutex: ^sync.Mutex, // Required by Executor; shared by every root/child owner. } // A single headless owner, held by app or a headless driver. Only the owner may // mutate these states. Executor workers receive independent immutable snapshots. Runtime :: struct { services: Services, agent: agent.State, conversation: conversation.Session, executor: ^Executor, // Non-nil until executor is closed and destroyed. } init :: proc(value: ^Runtime, services: Services, allocator: mem.Allocator) { value^ = {services = services} agent.init(&value.agent, allocator, services.checkpoint_policy) // max_tool_rounds == 0 is unlimited. Positive caps work; config wiring is future. } // Valid for zero/empty/initialized runtime. Caller must close/destroy any attached // executor first; services and their adapter state are borrowed, not destroyed. destroy :: proc(value: ^Runtime) { assert(value.executor == nil) // Never free mutable state while a worker is retained. agent.destroy(&value.agent) conversation.destroy(&value.conversation) value^ = {} }