Skip to main content

mermaid_runtime/
lib.rs

1//! Daemon-safe runtime services.
2//!
3//! The TUI reducer remains the correctness core, but durable concerns
4//! that a daemon or future remote client will also need live
5//! here. The first slice is SQLite-backed state for tasks, approvals,
6//! processes, and the future provider/memory/checkpoint tables.
7
8pub mod approval;
9pub mod atomic;
10pub mod checkpoint;
11pub mod daemon;
12mod pathguard;
13pub mod plugin;
14pub mod policy;
15pub mod storage;
16
17/// Lowercase hex encoding of a byte slice. Shared by the SHA-256 hashing sites
18/// (pairing-token hash, project hashes, plugin-source hash) that each used to
19/// carry an identical private copy.
20pub(crate) fn hex_lower(bytes: &[u8]) -> String {
21    const HEX: &[u8; 16] = b"0123456789abcdef";
22    let mut out = String::with_capacity(bytes.len() * 2);
23    for byte in bytes {
24        out.push(HEX[(byte >> 4) as usize] as char);
25        out.push(HEX[(byte & 0x0f) as usize] as char);
26    }
27    out
28}
29
30pub use atomic::write_atomic;
31
32pub use approval::{ApprovalReplayResult, approve_and_replay, deny_approval};
33pub use checkpoint::{
34    CheckpointFile, CheckpointManifest, create_checkpoint, create_checkpoint_for_task,
35    gc_old_checkpoint_dirs, restore_checkpoint,
36};
37pub use daemon::{
38    DEFAULT_PAIRING_TTL_DAYS, clamp_pairing_ttl_days, daemon_socket_path, generate_pairing_token,
39    hash_pairing_token, pairing_expiry_from_now, request_daemon_json, request_daemon_text,
40    snapshot_field_from_daemon,
41};
42pub use pathguard::{
43    OpenIntent, create_dir_all_beneath, open_beneath, remove_file_beneath, write_atomic_beneath,
44};
45pub use plugin::{
46    PluginCapabilityPreview, PluginManifest, install_plugin_from_path, plugin_capability_preview,
47    run_plugin_hooks, validate_plugin_manifest, write_plugin_lockfile,
48};
49pub use policy::{
50    ActionRequest, PolicyDecision, PolicyEngine, PolicyOverride, PolicyOverrideDecision, RiskClass,
51    SafetyMode, ToolCategory, is_destructive_command,
52};
53pub use storage::{
54    ApprovalRecord, ApprovalsRepo, CheckpointRecord, CheckpointsRepo, CompactionRecord,
55    CompactionsRepo, MessageRecord, MessagesRepo, NewApproval, NewCheckpoint, NewCompaction,
56    NewMessage, NewPluginInstall, NewProcess, NewProviderProbe, NewSession, NewTask, NewToolRun,
57    PairingTokenRecord, PairingTokensRepo, PluginInstallRecord, PluginsRepo, ProcessRecord,
58    ProcessStatus, ProcessesRepo, ProviderProbeRecord, ProviderProbesRepo, RuntimeStore,
59    SessionRecord, SessionsRepo, TaskPriority, TaskRecord, TaskStatus, TaskTimelineEvent,
60    TasksRepo, ToolRunRecord, ToolRunsRepo, data_dir,
61};
62// Unix-only: backs the `#[cfg(unix)]` daemon singleton via `flock`.
63#[cfg(unix)]
64pub use storage::try_exclusive_lock;