Skip to main content

runtime/turn/
boundary.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! What the executor supplies at a phase change, and what a phase
7//! change answers back.
8
9use kernel::EventRef;
10
11/// Boundary snapshot, supplied by the executor at every phase change.
12/// `Cancel` ends the turn at the boundary; `Steer` records and advances
13/// (the executor folds the text into its `Conversation`).
14#[derive(Debug, Clone, PartialEq, Eq)]
15pub enum Interrupt {
16    None,
17    Cancel,
18    Steer { source: String, text: String },
19}
20
21/// Whether the wave may start its next call, asked once before each of
22/// them.
23///
24/// Narrower than [`Interrupt`] on purpose. Between two calls of one
25/// wave, the only instruction this city can carry out at once is
26/// stopping: text that arrives to redirect the work belongs to the
27/// window the executor owns, and the executor folds it there before
28/// answering here.
29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub enum NextCall {
31    /// Nothing has stopped this run; the call goes ahead.
32    Allowed,
33    /// A halt reached this run, and the wave ends where it stands.
34    Halted,
35}
36
37/// A phase change either advances or ends the turn at the boundary.
38/// Exhaustive, as every enum in this workspace is: a new outcome
39/// must force every executor to decide, not fall through a catch-all.
40#[derive(Debug)]
41pub enum PhaseOutcome<Next> {
42    Advanced(Next),
43    Cancelled(TurnCancelled),
44}
45
46/// The turn ended at a boundary: `cancel_received` is on the ledger and
47/// its ref is the last entry. Freezing (handoff + run_frozen) is the run
48/// loop's move, not the turn's.
49#[derive(Debug, Clone, PartialEq, Eq)]
50pub struct TurnCancelled {
51    pub(super) refs: Vec<EventRef>,
52}
53
54impl TurnCancelled {
55    pub fn refs(&self) -> &[EventRef] {
56        &self.refs
57    }
58}