Skip to main content

printobserver_core/
lib.rs

1//! `printobserver-core`.
2//!
3//! Owns: the supervision logic — the loop that turns printer state and vision
4//! observations into supervisory decisions, and the policy that decides which
5//! decisions are allowed to reach the printer.
6//!
7//! May depend on: `printobserver-types` and the four port crates
8//! (`printobserver-printer-api`, `printobserver-vision-api`,
9//! `printobserver-supervisor-api`, `printobserver-store-api`), and NO
10//! implementation crate. This is the rule the whole design rests on and `just
11//! check-repo` enforces it.
12//!
13//! # The policy, which is the reason this layer exists
14//!
15//! Obico can already see a failure and `OctoPrint` can already drive the
16//! machine. What does not exist without this crate is the thing in between that
17//! decides what an agent is allowed to do about it, and its whole value is in
18//! being thin, bounded, and the **single** place that decision is made — so
19//! that an operator's own commands are bounded by exactly the same rules an
20//! agent's are.
21//!
22//! * **Effective bounds** are the configured [safety
23//!   envelope](printobserver_types::SafetyEnvelope) intersected with the active
24//!   print's manifest. A manifest may only narrow; a range wider than the
25//!   envelope's is narrowed to the envelope's and the narrowing is recorded on
26//!   the print. See [`bounds`].
27//! * **Every action from every actor passes one decision**, taken by
28//!   [`decision::decide`] and issued by the one function named in
29//!   [`supervisor`]. There is no path by which an action reaches the printer
30//!   without it, and that is structural: no other item of this crate names an
31//!   action method of the printer port, and no item outside that one module can
32//!   obtain the handle to call one on.
33//! * **A request outside the bounds is rejected, not clamped**, and the
34//!   rejection is persisted with the value asked for and the range allowed, so
35//!   the caller can ask again inside the range.
36//! * **A bounded intervention expires on its own.** Core reads the current time
37//!   through an injected [`Clock`] rather than the system's, so expiry is
38//!   driven by time passing and by nothing else. See [`expiry`].
39//! * **Nothing in this crate, and nothing reachable from it, sends a command
40//!   string to a printer.** The printer port declares no method that admits
41//!   one: no method admits a byte sequence at all, and the only string anywhere
42//!   in the closure its parameters reach is the one
43//!   [`FileName`](printobserver_types::FileName) wraps.
44
45pub mod actions;
46pub mod block_on;
47pub mod bounds;
48pub mod clock;
49pub mod config;
50pub mod decision;
51pub mod error;
52pub mod events;
53pub mod expiry;
54pub mod supervisor;
55pub mod turn_lock;
56
57pub use actions::{ActionOutcome, reported_value};
58pub use block_on::block_on;
59pub use bounds::{Bounds, effective_bounds};
60pub use clock::{Clock, SystemClock, plus_seconds, seconds_between, unix_seconds};
61pub use config::{CoreConfig, DEFAULT_EXPIRY_POLL, DEFAULT_RECENT_EVENTS, PRINT_ID_PLACEHOLDER};
62pub use decision::{DecisionInput, adjustment, decide, valid_from};
63pub use error::CoreError;
64pub use events::TERMINAL_STATES;
65pub use expiry::{rejection_detail, restoring_action};
66pub use supervisor::{Issued, Supervisor};
67pub use turn_lock::{TurnGuard, TurnLocks};