ProcessInstance
A process instance handle: an opaque `instanceId` bound to the {@see ProcessDefinition} that governs it. Holds NO event data of its own — every state-reading method takes the {@see EventStoreInterface} explicitly and replays through the {@see Reducer}, so two `ProcessInstance` objects built from the same `instanceId` + `definition` against the same log always agree, and neither one ever caches a stale answer ("state is a projection", not a stored field). The constructor is the "attach to an existing instance" path — cheap, side-effect-free, usable any time a caller already knows an `instanceId` (e.g. a tool call carrying one). {@see self::start()} is the ONLY path that creates a brand-new instance (it is the one that writes to the store); calling it twice with the same `instanceId` would duplicate the bootstrap events, so callers resuming an existing instance must use `new self(...)` instead.
ProcessInstance::__construct()
public function __construct(string $instanceId, Milpa\Orchestrator\ProcessDefinition $definition):Parameters
| Name | Type | Description |
|---|---|---|
| $instanceId | string | |
| $definition | Milpa\Orchestrator\ProcessDefinition |
ProcessInstance::start()
public static function start(Milpa\EventStore\EventStoreInterface $store, Milpa\Orchestrator\ProcessDefinition $definition, array $inputs, ?string $instanceId = null): selfStarts a brand-new process instance: appends `ProcessStarted` (payload = `$inputs`), then `StateEntered` (payload = `{state: $definition->initialState()}`), to `$store`, and returns the resulting handle. `$instanceId` defaults to a freshly generated UUID (via {@see UuidGenerator}) when omitted — pass one explicitly for deterministic tests or caller-assigned ids.
Parameters
| Name | Type | Description |
|---|---|---|
| $store | Milpa\EventStore\EventStoreInterface | |
| $definition | Milpa\Orchestrator\ProcessDefinition | |
| $inputs | array<string, mixed> | the new instance's starting context (e.g. domain ids) |
| $instanceId | ?string |
ProcessInstance::state()
public function state(Milpa\EventStore\EventStoreInterface $store): Milpa\Orchestrator\ProcessStateThe full projection — current state and accumulated context — replayed fresh from `$store` on every call.
Parameters
| Name | Type | Description |
|---|---|---|
| $store | Milpa\EventStore\EventStoreInterface |
ProcessInstance::currentState()
public function currentState(Milpa\EventStore\EventStoreInterface $store): stringConvenience accessor for {@see self::state()}'s `currentState`.
Parameters
| Name | Type | Description |
|---|---|---|
| $store | Milpa\EventStore\EventStoreInterface |
ProcessInstance::context()
public function context(Milpa\EventStore\EventStoreInterface $store): arrayConvenience accessor for {@see self::state()}'s `context`.
Parameters
| Name | Type | Description |
|---|---|---|
| $store | Milpa\EventStore\EventStoreInterface |