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 apply_patch;
9pub mod approval;
10pub mod atomic;
11pub mod checkpoint;
12pub mod daemon;
13pub mod hardening;
14mod pathguard;
15pub mod plugin;
16pub mod policy;
17pub mod redact;
18pub mod sandbox;
19pub mod storage;
20
21/// Lowercase hex encoding of a byte slice. Shared by the SHA-256 hashing sites
22/// (pairing-token hash, project hashes, plugin-source hash) that each used to
23/// carry an identical private copy.
24pub(crate) fn hex_lower(bytes: &[u8]) -> String {
25    const HEX: &[u8; 16] = b"0123456789abcdef";
26    let mut out = String::with_capacity(bytes.len() * 2);
27    for byte in bytes {
28        out.push(HEX[(byte >> 4) as usize] as char);
29        out.push(HEX[(byte & 0x0f) as usize] as char);
30    }
31    out
32}
33
34pub use atomic::{write_atomic, write_atomic_with_mode};
35
36pub use approval::{ApprovalReplayResult, approve_and_replay, deny_approval};
37pub use checkpoint::{
38    CheckpointFile, CheckpointManifest, CheckpointOrigin, create_checkpoint,
39    create_checkpoint_for_task, gc_old_checkpoint_dirs, restore_checkpoint,
40};
41pub use daemon::{
42    DEFAULT_PAIRING_TTL_DAYS, clamp_pairing_ttl_days, daemon_socket_path, generate_pairing_token,
43    hash_pairing_token, pairing_expiry_from_now, request_daemon_json, request_daemon_text,
44    subscribe_daemon_lines,
45};
46pub use pathguard::{
47    OpenIntent, create_dir_all_beneath, open_beneath, remove_file_beneath, write_atomic_beneath,
48};
49pub use plugin::{
50    HookDecision, HookGate, HookResponse, PluginCapabilityPreview, PluginManifest,
51    aggregate_hook_responses, install_plugin_from_path, plugin_capability_preview,
52    run_plugin_hooks, validate_plugin_manifest, write_plugin_lockfile,
53};
54pub use policy::{
55    ActionRequest, FloorLevel, PLAN_DENIAL_MARKER, PolicyDecision, PolicyEngine, PolicyOverride,
56    PolicyOverrideDecision, READ_ONLY_DENIAL_MARKER, RiskClass, SafetyMode, ToolCategory,
57    is_destructive_command, is_plan_file_only_write, is_plan_file_path, is_plan_safe_build_command,
58};
59pub use redact::{redact_json, redact_json_text, redact_secrets, sanitize_url_for_display};
60pub use sandbox::{
61    Enforcement, SandboxPolicy, enforce, fs_confinement_available, network_killswitch_available,
62};
63pub use storage::{
64    ApprovalRecord, ApprovalsRepo, CheckpointRecord, CheckpointsRepo, CompactionRecord,
65    CompactionsRepo, MessageRecord, MessagesRepo, NewApproval, NewCheckpoint, NewCompaction,
66    NewMessage, NewOutcome, NewPluginInstall, NewProcess, NewProviderProbe, NewSession, NewTask,
67    NewToolRun, OUTCOME_LABEL_ACCEPTED, OUTCOME_LABEL_FAILURE, OUTCOME_LABEL_PARTIAL,
68    OUTCOME_LABEL_REJECTED, OUTCOME_LABEL_SUCCESS, OUTCOME_LABEL_UNKNOWN, OUTCOME_SOURCE_MODEL,
69    OUTCOME_SOURCE_SYSTEM, OUTCOME_SOURCE_USER, OUTCOME_SOURCE_VERIFIER, OutcomeRecord,
70    OutcomesRepo, PairingTokenRecord, PairingTokensRepo, PluginInstallRecord, PluginsRepo,
71    ProcessRecord, ProcessStatus, ProcessesRepo, ProviderProbeRecord, ProviderProbesRepo,
72    RuntimeStore, SessionRecord, SessionsRepo, TaskPriority, TaskRecord, TaskStatus,
73    TaskTimelineEvent, TasksRepo, ToolRunRecord, ToolRunsRepo, data_dir,
74};
75// Unix-only: backs the `#[cfg(unix)]` daemon singleton via `flock`.
76#[cfg(unix)]
77pub use storage::try_exclusive_lock;