Skip to main content

lean_rs_worker/
lib.rs

1//! Worker-process boundary for `lean-rs` host workloads.
2//!
3//! `LeanWorker` is the public process-boundary supervisor. It hides child
4//! spawning, pipe management, protocol framing, child exit parsing, and cleanup
5//! behind a small lifecycle API. The protocol module is private; callers should
6//! not learn frame bytes or restart bookkeeping. `LeanWorkerRestartPolicy`
7//! cycles the child process for memory reset; it does not change the
8//! in-process `lean-rs-host` memory contract.
9
10mod capability;
11mod child;
12mod planning;
13mod pool;
14mod protocol;
15mod session;
16mod supervisor;
17mod types;
18
19pub use capability::{
20    LeanWorkerBootstrapCheck, LeanWorkerBootstrapDiagnosticCode, LeanWorkerBootstrapReport,
21    LeanWorkerBootstrapSeverity, LeanWorkerCapability, LeanWorkerCapabilityBuilder, LeanWorkerChild,
22};
23pub use planning::{
24    LeanWorkerBatchFingerprint, LeanWorkerImportPlanConfig, LeanWorkerImportPlanError, LeanWorkerImportPlanner,
25    LeanWorkerModuleWork, LeanWorkerPlanMetadataExpectation, LeanWorkerPlannedBatch,
26};
27pub use pool::{
28    LeanWorkerPool, LeanWorkerPoolConfig, LeanWorkerPoolSnapshot, LeanWorkerRestartPolicyClass, LeanWorkerSessionKey,
29    LeanWorkerSessionLease,
30};
31pub use session::{
32    LeanWorkerCancellationToken, LeanWorkerDataRow, LeanWorkerDataSink, LeanWorkerDiagnosticEvent,
33    LeanWorkerDiagnosticSink, LeanWorkerJsonCommand, LeanWorkerProgressEvent, LeanWorkerProgressSink,
34    LeanWorkerRuntimeMetadata, LeanWorkerSession, LeanWorkerSessionConfig, LeanWorkerStreamSummary,
35    LeanWorkerStreamingCommand, LeanWorkerTypedDataRow, LeanWorkerTypedDataSink, LeanWorkerTypedStreamSummary,
36};
37pub use supervisor::{
38    LEAN_WORKER_REQUEST_TIMEOUT_DEFAULT, LEAN_WORKER_REQUEST_TIMEOUT_LONG_RUNNING, LeanWorker, LeanWorkerConfig,
39    LeanWorkerError, LeanWorkerExit, LeanWorkerRestartPolicy, LeanWorkerRestartReason, LeanWorkerStats,
40    LeanWorkerStatus,
41};
42pub use types::{
43    LeanWorkerCapabilityFact, LeanWorkerCapabilityMetadata, LeanWorkerCommandInfo, LeanWorkerCommandMetadata,
44    LeanWorkerDeclarationFilter, LeanWorkerDeclarationRow, LeanWorkerDiagnostic, LeanWorkerDoctorDiagnostic,
45    LeanWorkerDoctorReport, LeanWorkerDoctorSeverity, LeanWorkerElabFailure, LeanWorkerElabOptions,
46    LeanWorkerElabResult, LeanWorkerKernelResult, LeanWorkerKernelStatus, LeanWorkerMetaResult,
47    LeanWorkerMetaTransparency, LeanWorkerNameRef, LeanWorkerProcessFileOutcome, LeanWorkerProcessModuleOutcome,
48    LeanWorkerProcessedFile, LeanWorkerSourceRange, LeanWorkerTacticInfo, LeanWorkerTermInfo,
49};
50
51/// Run the worker child process on stdin/stdout.
52///
53/// Production applications can expose a tiny app-owned child binary:
54///
55/// ```ignore
56/// fn main() -> std::process::ExitCode {
57///     lean_rs_worker::run_worker_child_stdio()
58/// }
59/// ```
60///
61/// Parent processes should still use [`LeanWorker`],
62/// [`LeanWorkerCapabilityBuilder`], or [`LeanWorkerPool`]. This function is
63/// only the child-side binary entry point.
64pub fn run_worker_child_stdio() -> std::process::ExitCode {
65    child::run_stdio()
66}
67
68#[doc(hidden)]
69pub fn __run_child_stdio() -> std::process::ExitCode {
70    run_worker_child_stdio()
71}
72
73#[doc(hidden)]
74pub mod __test_support;