Skip to main content

octl_core/
lib.rs

1//! Core library for orchestratectl.
2//!
3//! See `issues/orchestratectl-mvp/design.md` for the canonical schema and
4//! protocol references. This crate provides:
5//!
6//! - The on-disk schema types ([`Manifest`], [`Node`], [`Event`]).
7//! - Atomic write helpers ([`atomic`]) and per-run advisory `flock`
8//!   ([`RunLock`]).
9//! - The canonical mutation entry point
10//!   ([`append_and_apply_event`]): append one
11//!   event and fold it into the projections under the run's `flock`.
12//!
13//! Higher-level supervisor and CLI logic live in their own crates / issues.
14//!
15//! `octl-core` is the canonical library surface, so public items are required
16//! to carry doc comments (`#![warn(missing_docs)]`). Lint-level policy
17//! otherwise lives in the workspace `[workspace.lints]` table (pedantic clippy).
18#![warn(missing_docs)]
19
20pub mod atomic;
21pub mod cancel;
22pub mod envelope;
23pub mod error;
24pub mod events;
25pub mod ids;
26pub mod lock;
27pub mod paths;
28pub mod plan;
29pub mod projections;
30pub mod reducer;
31pub mod report;
32pub mod schema;
33
34#[cfg(test)]
35mod stress_tests;
36
37pub use cancel::{
38    cancel_node, cancel_node_unlocked, cancel_run, cancel_run_unlocked, read_node_statuses,
39    CancelOutcome, NodeCancelOutcome,
40};
41pub use envelope::SCHEMA_VERSION;
42pub use error::{Error, Result};
43pub use events::{
44    append_and_apply_event, append_and_apply_idempotent, append_and_apply_unlocked,
45    find_prior_with_key, quarantine_corrupt_lines, quarantine_corrupt_lines_unlocked,
46    read_all_events, recover_last_seq, AppendOutcome, AppendResult, PriorEvent, Quarantine,
47};
48pub use ids::{format_node_id, new_op_id, new_run_id};
49pub use lock::{Exclusive, LockedRun, RunLock, Shared};
50pub use paths::{nofollow, run_dir, validate_run_id, RunPaths};
51pub use plan::{
52    parse_and_validate_plan, plan_v3_json_schema, validate_plan, Acceptance, Baseline, Check,
53    Chunk, Feature, Plan, PlanValidationError, Tier, PLAN_SCHEMA_VERSION, PLAN_V3_JSON_SCHEMA,
54    PROVENANCE_REQUIRED_SCHEMA, SUPPORTED_PLAN_SCHEMAS, TOLERATED_OPTIONAL_FIELDS,
55};
56pub use projections::{read_manifest, read_manifest_opt, read_node, read_node_opt, write_node};
57pub use reducer::{plan_projections, KIND_MERGE_ABORTED, KIND_MERGE_STARTED};
58pub use report::{
59    sanitize_report_advisory, validate_report_payload, AdvisoryWarning, ReportOrigin,
60    ReportValidationError, SanitizedReport, REPORT_ORIGIN_KEY, VIA_EXPLICIT_MERGE,
61};
62pub use schema::aggregate_terminal_status;
63pub use schema::{
64    is_run_id_prefix, ChildRef, Event, IdValidationError, Kind, Lifecycle, Manifest, MergeTxn,
65    Node, NodeId, RunId, Status, WorkerExit, STATE_SCHEMA_VERSION, SUPPORTED_STATE_SCHEMAS,
66};
67
68/// Ensure the orchestratectl root directory exists (`<root>/runs`,
69/// `<root>/logs`). Idempotent.
70pub fn ensure_root(root: &std::path::Path) -> Result<()> {
71    for sub in ["runs", "logs"] {
72        let p = root.join(sub);
73        std::fs::create_dir_all(&p).map_err(|e| Error::io(&p, e))?;
74    }
75    Ok(())
76}