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