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