pub struct Factory { /* private fields */ }Expand description
A running factory.
Implementations§
Source§impl Factory
impl Factory
Sourcepub fn new(config: Config, root: impl Into<PathBuf>) -> Result<Self>
pub fn new(config: Config, root: impl Into<PathBuf>) -> Result<Self>
Opens a factory rooted at root, which is where .layover/ lives.
§Errors
Returns an error when the state directory cannot be created.
Sourcepub fn serving_mcp(self, endpoint: impl Into<String>) -> Self
pub fn serving_mcp(self, endpoint: impl Into<String>) -> Self
Tells runs where Layover’s MCP endpoint is, so they can call back into it.
Without this a run is a one-shot: it reads its instructions, does the work and ends, and no
chain can be longer than the flight that started it. With it, layover_send reaches a real
queue and the route map means something at runtime rather than only at load.
Sourcepub fn tokens(&self) -> Arc<Tokens> ⓘ
pub fn tokens(&self) -> Arc<Tokens> ⓘ
The token registry, which the MCP endpoint resolves callers against.
Sourcepub const fn graph(&self) -> &RouteGraph
pub const fn graph(&self) -> &RouteGraph
The route map this factory is enforcing.
Sourcepub fn ground_stop_engaged(&self) -> bool
pub fn ground_stop_engaged(&self) -> bool
Whether a Ground Stop is engaged.
Read from disk on every check rather than cached: a kill switch whose state is a snapshot taken at startup is a kill switch that does not work while the thing is running.
Sourcepub fn run_flight(
&self,
itinerary: &mut Itinerary,
sender: Option<&AgentName>,
flight: &Flight,
) -> Dispatched
pub fn run_flight( &self, itinerary: &mut Itinerary, sender: Option<&AgentName>, flight: &Flight, ) -> Dispatched
Runs one flight to completion, recording what happened.
sender is None for a human trigger.
§Errors
Never returns Err; a failure is reported as Dispatched::Failed so that one bad flight
cannot stop a factory draining the rest of its queue.
Sourcepub fn history_dir(&self) -> PathBuf
pub fn history_dir(&self) -> PathBuf
Where history is written.
Sourcepub fn drain(
&self,
pending: Vec<Queued>,
unqueue: impl FnMut(&Flight),
report: impl FnMut(&Flight, &Dispatched),
) -> Drained
pub fn drain( &self, pending: Vec<Queued>, unqueue: impl FnMut(&Flight), report: impl FnMut(&Flight, &Dispatched), ) -> Drained
Runs every flight waiting in pending, and every flight those runs send, until nothing is
left.
Each is taken off the queue before it runs. A flight that crashes the factory mid-run must not come back on restart and run again: an agent that opened a pull request and was interrupted before its outcome was recorded would open a second one.
§Why this loops rather than iterating once
A run can send flights while it is running. Draining the list it started with would leave
those sitting until something else picked them up, which turns every chain into one hop per
invocation. refill is asked for whatever is queued now, after each pass.
The loop is bounded by the rails rather than by a count: each flight spends a Hop from a shared itinerary and each run spends Fuel and a slot against the run cap, so a chain that will not settle is cut by the same mechanism that bounds every other chain.
It also stops as soon as a whole pass starts nothing. Only a run can send a flight, so a pass in which every flight was refused cannot have produced new work, and asking for more would spin against a queue the rails have already closed.