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 — 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 accounting;
51pub mod actions;
52pub mod block_on;
53pub mod bounds;
54pub mod clock;
55pub mod config;
56pub mod context;
57pub mod decision;
58mod delay;
59pub mod detector;
60pub mod error;
61pub mod events;
62pub mod expiry;
63pub mod filament;
64pub mod inbox;
65pub mod kinds;
66pub mod listing;
67pub mod look;
68pub mod observation;
69pub mod preflight;
70pub mod records;
71pub mod spools;
72pub mod store;
73pub mod supervisor;
74pub mod turn_access;
75pub mod turn_lock;
76pub mod unobserved;
77
78pub use accounting::UNTRACKED_REASON;
79pub use actions::{ActionOutcome, reported_value};
80pub use block_on::block_on;
81pub use bounds::{Bounds, effective_bounds};
82pub use clock::{Clock, SystemClock, plus_seconds, seconds_between, unix_seconds};
83pub use config::{
84    CoreConfig, DEFAULT_DETECTOR_RESUME_GRACE, DEFAULT_EXPIRY_POLL, DEFAULT_OBSERVATION_INTERVAL,
85    DEFAULT_RECENT_EVENTS, MAX_LOOK_WAIT_S, PRINT_ID_PLACEHOLDER, PreflightMode, SpoolPolicy,
86};
87pub use context::PrintContext;
88pub use decision::{DecisionInput, adjustment, changes_the_machine, decide, valid_from};
89pub use error::CoreError;
90pub use events::{PendingTurn, Received, TERMINAL_STATES};
91pub use expiry::{rejection_detail, restoring_action};
92pub use filament::{
93    DEFAULT_DIAMETER_MM, MATERIAL_DENSITIES, MarkClearing, buffer_g, density_for, grams_for_length,
94    marks_cleared_by,
95};
96pub use inbox::{Arrival, Inboxes};
97pub use kinds::{
98    ActionExecutedPayload, ActionRejectedPayload, ActionRequestedPayload, AgentAssessmentPayload,
99    CameraLookPayload, ChargePendedPayload, FilamentChangeSignalledPayload,
100    FilamentConsumedPayload, FileTallyRebaselinedPayload, InterventionExpiredPayload,
101    OperatorAcknowledgementPayload, PeriodicObservationPayload, PortFailurePayload,
102    PortFailureSite, PreflightCheckedPayload, PrintEndedPayload, PrintStartedPayload,
103    PrintUntrackedPayload, RebaselineDisposition, SpoolAdjustedPayload,
104    SpoolCommandRejectedPayload, SpoolLoadedPayload, SpoolRegisteredPayload, SpoolRetiredPayload,
105    SpoolUnloadedPayload, SpoolUnverifiedPayload, TIMELINE_KINDS, UnaccountedPrintPayload,
106    agent_source, operator_source, system_source,
107};
108pub use look::Look;
109pub use observation::Observed;
110pub use preflight::ANALYSIS_POLL;
111pub use records::{
112    AcknowledgementDisposition, ActionId, ActionKind, ActionRecord, ActionRequest, Actor,
113    ActorClass, ChargeKey, ChargeMethod, ClearedMark, EffectiveBounds, ExecutionOutcome,
114    FilePosition, ImageRecord, Intervention, InterventionId, InterventionOutcome, JobManifest,
115    LoadedSpool, ManifestNarrowing, PendingCharge, PendingTaken, PolicyDecision, Preflight,
116    PreflightTool, PreflightVerdict, PrintAction, PrintOutcome, PrintRecord, RejectionReason,
117    SafetyEnvelope, SpoolCommand, SpoolId, SpoolRecord, SpoolTrust, UnverifiedMark,
118    UnverifiedReason, UnverifiedReasonKind,
119};
120pub use spools::SpoolCommandOutcome;
121pub use store::{
122    ActionStore, AuditPage, Charge, ChargeRecord, DEFAULT_HISTORY_WINDOW, EventDraft, EventStore,
123    FilamentStore, FileTally, HistoryQuery, ImageLookup, ImageStore, MAX_HISTORY_LIMIT, NewSpool,
124    Pend, PrintStore, SessionStore, SettleOutcome, Settlement, SpoolChange, SpoolMutation,
125    SpoolWrite, StoreError, Stores, TimelineQuery, TimelineStore, resolve_history_limit,
126};
127pub use supervisor::{Issued, Supervisor};
128pub use turn_access::{OpenedTurn, TurnAuthority};
129pub use turn_lock::{TurnGuard, TurnLocks};