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 — together with the event kinds
6//! and source names that logic writes ([`kinds`]), the one aggregate a
7//! caller and the agent both read, the print's context ([`context`]), and the
8//! persistence interfaces it needs, one per aggregate ([`store`]).
9//!
10//! May depend on: `printobserver-types` and the three port crates
11//! (`printobserver-printer-api`, `printobserver-vision-api`,
12//! `printobserver-supervisor-api`), and NO implementation crate. This is the
13//! rule the whole design rests on and `just check-repo` enforces it. The
14//! persistence interfaces this crate needs are its own ([`store`]), one trait
15//! per aggregate it persists, and the store implementation depends on this
16//! crate to implement them.
17//!
18//! # The policy, which is the reason this layer exists
19//!
20//! A failure detector can already see a failure and a printer can already
21//! drive the machine. What does not exist without this crate is the thing in between that
22//! decides what an agent is allowed to do about it, and its whole value is in
23//! being thin, bounded, and the **single** place that decision is made — so
24//! that an operator's own commands are bounded by exactly the same rules an
25//! agent's are.
26//!
27//! * **Effective bounds** are the configured [safety
28//! envelope](crate::records::SafetyEnvelope) intersected with the active
29//! print's manifest. A manifest may only narrow; a range wider than the
30//! envelope's is narrowed to the envelope's and the narrowing is recorded on
31//! the print. See [`bounds`].
32//! * **Every action from every actor passes one decision**, taken by
33//! [`decision::decide`] and issued by the one function named in
34//! [`supervisor`]. There is no path by which an action reaches the printer
35//! without it, and that is structural: no other item of this crate names an
36//! action method of the printer port, and no item outside that one module can
37//! obtain the handle to call one on.
38//! * **A request outside the bounds is rejected, not clamped**, and the
39//! rejection is persisted with the value asked for and the range allowed, so
40//! the caller can ask again inside the range.
41//! * **A bounded intervention expires on its own.** Core reads the current time
42//! through an injected [`Clock`] rather than the system's, so expiry is
43//! driven by time passing and by nothing else. See [`expiry`].
44//! * **Nothing in this crate, and nothing reachable from it, sends a command
45//! string to a printer.** The printer port declares no method that admits
46//! one: no method admits a byte sequence at all, and the only string anywhere
47//! in the closure its parameters reach is the one
48//! [`FileName`](printobserver_types::FileName) wraps.
49
50pub mod actions;
51pub mod block_on;
52pub mod bounds;
53pub mod clock;
54pub mod config;
55pub mod context;
56pub mod decision;
57pub mod error;
58pub mod events;
59pub mod expiry;
60pub mod kinds;
61pub mod listing;
62pub mod records;
63pub mod store;
64pub mod supervisor;
65pub mod turn_lock;
66
67pub use actions::{ActionOutcome, reported_value};
68pub use block_on::block_on;
69pub use bounds::{Bounds, effective_bounds};
70pub use clock::{Clock, SystemClock, plus_seconds, seconds_between, unix_seconds};
71pub use config::{CoreConfig, DEFAULT_EXPIRY_POLL, DEFAULT_RECENT_EVENTS, PRINT_ID_PLACEHOLDER};
72pub use context::PrintContext;
73pub use decision::{DecisionInput, adjustment, decide, valid_from};
74pub use error::CoreError;
75pub use events::TERMINAL_STATES;
76pub use expiry::{rejection_detail, restoring_action};
77pub use kinds::{
78 ActionExecutedPayload, ActionRejectedPayload, ActionRequestedPayload, AgentAssessmentPayload,
79 InterventionExpiredPayload, OperatorAcknowledgementPayload, PortFailurePayload,
80 PortFailureSite, agent_source, operator_source, system_source,
81};
82pub use records::{
83 AcknowledgementDisposition, ActionId, ActionKind, ActionRecord, ActionRequest, Actor,
84 ActorClass, EffectiveBounds, ExecutionOutcome, ImageRecord, Intervention, InterventionId,
85 InterventionOutcome, JobManifest, ManifestNarrowing, PolicyDecision, PrintAction, PrintRecord,
86 RejectionReason, SafetyEnvelope,
87};
88pub use store::{
89 ActionStore, AuditPage, DEFAULT_HISTORY_WINDOW, EventDraft, EventStore, HistoryQuery,
90 ImageLookup, ImageStore, MAX_HISTORY_LIMIT, PrintStore, SessionStore, SettleOutcome,
91 StoreError, Stores, resolve_history_limit,
92};
93pub use supervisor::{Issued, Supervisor};
94pub use turn_lock::{TurnGuard, TurnLocks};