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 check_image;
55pub mod clock;
56pub mod closing;
57pub mod config;
58pub mod context;
59pub mod decision;
60mod delay;
61pub mod detector;
62pub mod error;
63pub mod events;
64pub mod expiry;
65pub mod filament;
66pub mod gcode_index;
67pub mod inbox;
68pub mod kinds;
69pub mod listing;
70pub mod look;
71pub mod observation;
72pub mod planned;
73pub mod preflight;
74pub mod records;
75pub mod recovery;
76pub mod scoring;
77pub mod spools;
78pub mod store;
79pub mod supervisor;
80pub mod toolpath;
81pub mod turn_access;
82pub mod turn_lock;
83pub mod unobserved;
84pub mod upgrade;
85pub mod watch;
86
87pub use accounting::{ChargeRule, UNTRACKED_REASON, charge_rule};
88pub use actions::{ActionOutcome, reported_value};
89pub use block_on::block_on;
90pub use bounds::{Bounds, effective_bounds};
91pub use check_image::{CheckImageRequest, CheckImages, ImageUse, PlanPosition, ShownImage};
92pub use clock::{Clock, SystemClock, plus_seconds, seconds_between, unix_seconds};
93pub use config::{
94    CoreConfig, DEFAULT_DETECTOR_RESUME_GRACE, DEFAULT_EXPIRY_POLL, DEFAULT_OBSERVATION_INTERVAL,
95    DEFAULT_RECENT_EVENTS, DEFAULT_SHEETS, MAX_LOOK_WAIT_S, PRINT_ID_PLACEHOLDER, PreflightMode,
96    SheetTable, SpoolPolicy,
97};
98pub use context::{
99    AgentContext, AgentEvent, AgentHeater, AgentPrint, AgentPrinter, PrintContext, Since,
100    newer_than,
101};
102pub use decision::{DecisionInput, adjustment, changes_the_machine, decide, valid_from};
103pub use error::CoreError;
104pub use events::{PendingTurn, Received, TERMINAL_STATES};
105pub use expiry::{rejection_detail, restoring_action};
106pub use filament::{
107    DEFAULT_DIAMETER_MM, MATERIAL_DENSITIES, MarkClearing, buffer_g, density_for, grams_for_length,
108    marks_cleared_by,
109};
110pub use gcode_index::{
111    BedArea, GcodeIndex, IndexBuilder, PLANNED_CHANGE_REACH_BYTES, PlanFact, PlanMismatch,
112    PlannedChange, PlannedChangeKind, PlannedChanges, PlannedSegment, Rise, SetValue, SlicerPlan,
113};
114pub use inbox::{AlertCameraFrame, Arrival, Inboxes};
115pub use kinds::{
116    ActionExecutedPayload, ActionRejectedPayload, ActionRequestedPayload, AgentAssessmentPayload,
117    AgentStopUnactedPayload, BedClearActor, BedClearAssertedPayload, CameraDegradedPayload,
118    CameraLookPayload, CameraRetryPayload, ChargePendedPayload, DetectorHealthChangedPayload,
119    DetectorStatus, FilamentChangePlannedReachedPayload, FilamentChangePlannedResumedPayload,
120    FilamentChangeSignalledPayload, FilamentConsumedPayload, FileTallyRebaselinedPayload,
121    FrameCause, GcodeIndexedPayload, HeatedTool, InterventionExpiredPayload,
122    OperatorAcknowledgementPayload, PeriodicObservationPayload, PlannedChangeTrigger,
123    PortFailurePayload, PortFailureSite, PositionFreshness, PreflightCheckedPayload,
124    PrintEndedPayload, PrintStartedPayload, PrintUntrackedPayload, PrinterConnectionChangedPayload,
125    PrinterResetPayload, RebaselineDisposition, RecoveryExecutedPayload, RecoveryRejectedPayload,
126    RecoveryRequestedPayload, SignalPosition, SpoolAdjustedPayload, SpoolCommandRejectedPayload,
127    SpoolLoadedPayload, SpoolRegisteredPayload, SpoolRetiredPayload, SpoolUnloadedPayload,
128    SpoolUnverifiedPayload, TIMELINE_KINDS, UnaccountedPrintPayload,
129    UnattendedPrinterActivityPayload, agent_source, operator_source, system_source,
130};
131pub use look::{CameraRetry, DEFAULT_CAMERA_RETRIES, DEFAULT_CAMERA_RETRY_BACKOFF, Look};
132pub use observation::Observed;
133pub use preflight::ANALYSIS_POLL;
134pub use records::{
135    AcknowledgementDisposition, ActionId, ActionKind, ActionRecord, ActionRequest, Actor,
136    ActorClass, ChargeKey, ChargeMethod, ChargedFilament, ClearedMark, DoubtedSpool,
137    EffectiveBounds, ExecutionOutcome, FilePosition, ImageRecord, Intervention, InterventionId,
138    InterventionOutcome, JobManifest, LoadedSpool, ManifestNarrowing, MaterialComparison,
139    MaterialName, MaterialObjection, MaterialResult, PendingCharge, PendingTaken, PolicyDecision,
140    Preflight, PreflightNeed, PreflightObjection, PreflightSegment, PreflightSpool, PreflightTool,
141    PreflightToolResult, PreflightVerdict, PrintAction, PrintOutcome, PrintRecord, PrintSegmentKey,
142    RejectionReason, SafetyEnvelope, SegmentSpool, SheetComparison, SheetId, SheetObjection,
143    SheetResult, ShortSpool, SpoolCommand, SpoolField, SpoolId, SpoolLifecycle, SpoolRecord,
144    SpoolRefusalCause, SpoolTrust, UnanalysedSpool, UncomparedMaterial, UnverifiedMark,
145    UnverifiedMarks, UnverifiedReason, UnverifiedReasonKind,
146};
147pub use records::{
148    ActionAllowance, AwayFromBed, BedTemperature, DEFAULT_CLEARANCE_MARGIN_MM, DEFAULT_MAX_LIFT_MM,
149    LastPrint, PausedPrint, RecoveryAction, RecoveryActionKind, RecoveryConfig, RecoveryDecision,
150    RecoveryField, RecoveryGrants, RecoveryPosition, RecoveryRejection, RecoveryStatus,
151    RecoveryTemperatures, ToolTemperature, ZHome, ZTrust,
152};
153pub use scoring::{EVIDENCE_INTERVALS, ScoringProbe, ScoringRead, ScoringReading};
154pub use spools::SpoolCommandOutcome;
155pub use store::{
156    ActionStore, AuditPage, Charge, ChargeIdentity, ChargeRecord, DEFAULT_HISTORY_WINDOW,
157    EventDraft, EventStore, FilamentStore, FileTally, HistoryQuery, ImageDraft, ImageLookup,
158    ImageStore, MAX_HISTORY_LIMIT, NewSpool, Pend, PrintStore, SessionStore, SettleOutcome,
159    Settlement, SpoolChange, SpoolMutation, SpoolWrite, StoreError, Stores, TimelineQuery,
160    TimelineStore, resolve_history_limit,
161};
162pub use supervisor::{Issued, RecoveryIssued, Supervisor};
163pub use toolpath::{
164    ExtrusionKind, LayerRef, LayerToolpath, ObjectOutline, SpoolError, ToolpathSegment, spool_path,
165};
166pub use turn_access::{OpenedTurn, TurnAuthority};
167pub use turn_lock::{TurnGuard, TurnLocks};
168pub use watch::{
169    ActiveJob, DEFAULT_PRINTER_POLL, DEFAULT_UNATTENDED_WINDOW, DetectorHealth,
170    DetectorHealthStatus, DetectorProbe, HeadPosition, PRINTER_WATCH_KINDS, PUSH_CHANNEL_DOWN,
171    PositionProbe, ScoringVerdict, Watched,
172};