Expand description
Daemon-safe runtime services.
The TUI reducer remains the correctness core, but durable concerns that a daemon or future remote client will also need live here. The first slice is SQLite-backed state for tasks, approvals, processes, and the future provider/memory/checkpoint tables.
Re-exports§
pub use atomic::write_atomic;pub use atomic::write_atomic_with_mode;pub use approval::ApprovalReplayResult;pub use approval::approve_and_replay;pub use approval::deny_approval;pub use checkpoint::CheckpointFile;pub use checkpoint::CheckpointManifest;pub use checkpoint::CheckpointOrigin;pub use checkpoint::create_checkpoint;pub use checkpoint::create_checkpoint_for_task;pub use checkpoint::gc_old_checkpoint_dirs;pub use checkpoint::restore_checkpoint;pub use daemon::DEFAULT_PAIRING_TTL_DAYS;pub use daemon::clamp_pairing_ttl_days;pub use daemon::generate_pairing_token;pub use daemon::hash_pairing_token;pub use daemon::pairing_expiry_from_now;pub use daemon::request_daemon_json;pub use daemon::request_daemon_text;pub use daemon::subscribe_daemon_lines;pub use plugin::HookDecision;pub use plugin::HookGate;pub use plugin::HookResponse;pub use plugin::PluginCapabilityPreview;pub use plugin::PluginManifest;pub use plugin::aggregate_hook_responses;pub use plugin::install_plugin_from_path;pub use plugin::plugin_capability_preview;pub use plugin::run_plugin_hooks;pub use plugin::validate_plugin_manifest;pub use plugin::write_plugin_lockfile;pub use policy::PolicyEngine;pub use policy::is_destructive_command;pub use policy::is_plan_file_only_write;pub use policy::is_plan_file_path;pub use policy::is_plan_safe_build_command;pub use sandbox::Enforcement;pub use sandbox::SandboxPolicy;pub use sandbox::enforce;pub use sandbox::fs_confinement_available;pub use sandbox::network_killswitch_available;pub use storage::RuntimeStore;pub use worktree::AgentWorktree;pub use worktree::MergeOutcome;pub use worktree::gc_orphaned_worktrees;pub use storage::try_exclusive_lock;
Modules§
- apply_
patch - Pure
apply_patchengine — parser, graduated fuzzy matcher, and applier — adapted from OpenAI Codex’sapply-patchcrate. - approval
- atomic
- Atomic file writes.
- checkpoint
- daemon
- git
- Hardened
gitinvocation. - hardening
- Best-effort process hardening, applied as early in
mainas possible. - plugin
- policy
- Safety policy for tool actions: the engine (
engine), the shell classifier (shell/), and the plan-mode carve-outs (plan_gate). The VOCABULARY (modes, risk classes, requests, decisions) lives inmermaid_model::safetyso the pure domain crate can speak it without a dependency on this crate; it is re-exported here because it is this module’s API surface –PolicyEngine::decidetakesActionRequestand answersPolicyDecision. - redact
- Re-export: the single redaction implementation lives in
mermaid_model::utils::redact(the bottom crate), so it is available below the store. Same names, same rules; this module keeps thecrate::redact::/mermaid_runtime::paths every repository and caller always used. - sandbox
- Optional OS sandboxing for model-driven shell commands.
- storage
- worktree
- Isolated git worktrees for subagents.
Structs§
- Action
Request - Approval
Record - Checkpoint
Record - Compaction
Record - Message
Record - One transcript row on the daemon wire.
- NewApproval
- NewCheckpoint
- NewCompaction
- NewOutcome
- NewPlugin
Install - NewProcess
- NewProvider
Probe - NewSession
- NewTask
- NewTool
Run - Pairing
Token Record - Plugin
Install Record - Policy
Override - Process
Record - Provider
Probe Record - Session
Record - Task
Record - Task
Timeline Event - Tool
RunRecord
Enums§
- Floor
Level - Enforcement floor for actions whose blast radius exceeds the project:
write-shaped MCP tools (
external_writes) and machine-scoped package operations (system_installs). Safety mode alone never authorizes them: the mode’s decision is strengthened to at least this level (severity orderAllow < Auto < Ask < Deny). DefaultAuto: the intent classifier vets the call against the user’s request — aligned runs silently, off-task escalates — even infull_access.allowrestores the old unconditional-allow behavior per knob. - Host
Shell - Which shell
execute_commandhands model commands to on this host. - Open
Intent - What kind of access an
open_beneathcall needs. - Policy
Decision - Policy
Override Decision - Process
Status - Risk
Class - Safety
Mode - Task
Priority - Task
Status - Durable task state. A task is the daemon-level work unit; a chat transcript is just one artifact linked to it.
- Tool
Category
Constants§
- OUTCOME_
LABEL_ FAILURE - OUTCOME_
LABEL_ SUCCESS - Graded result of an outcome. Stored as free-form
TEXT(liketool_runs.status) so the taxonomy can grow without a migration; these constants are the canonical spellings so callers don’t drift. - OUTCOME_
LABEL_ UNKNOWN - OUTCOME_
SOURCE_ SYSTEM - PLAN_
DENIAL_ MARKER - Marker embedded verbatim in every plan-mode policy-denial
reason(the policy gate rewrites the read-only mode-default deny to a plan-flavored one while a plan is being drafted). Sibling ofREAD_ONLY_DENIAL_MARKER: the message-history layer matches"blocked by policy: "+ this marker to neutralize denials once plan mode ends. - READ_
ONLY_ DENIAL_ MARKER - Marker embedded verbatim in every read-only policy-denial
reason(see the runtime engine’sPolicyEngine::decide). Exposed so the message-history layer can detect a denial that a since-loosened safety mode has superseded, without re-hardcoding the wording in a second place.
Functions§
- create_
dir_ all_ beneath - Confined
mkdir -pfor aroot-relative directory path: creates each missing component beneathroot, refusing to descend through a symlink that escapes (#77). On Linux:mkdirat+openat2(RESOLVE_BENEATH)per component; otherwise thecontain_within_canonical+std::fsfallback. - data_
dir - The app data dir:
DATA_DIR_ENVwhen set, else the platform location, or~/.local/share/mermaidwhen the platform has none. - open_
beneath - Open
root-relativerelforintentwithout ever traversing out ofroot— closing the check-then-write TOCTOU where an intermediate directory is swapped for a symlink after a lexical path check but before the operation (#77). The returnedFileis bound to the exact inode the confinement resolved, so subsequent reads/writes can’t be redirected. - redact_
json - Redact every string leaf of a cloned structured payload in place.
- redact_
json_ text - Redact a serialized JSON payload. Malformed input is treated as ordinary text and still receives shape-based scrubbing; persistence never fails open.
- redact_
secrets - Replace credential-shaped substrings while preserving surrounding context.
- remove_
file_ beneath - Confined unlink of a
root-relative file (#77): opens the parent underRESOLVE_BENEATHandunlinkats the leaf, so a swapped-in symlink parent can’t redirect the delete outsideroot. - sanitize_
url_ for_ display - Sanitize a URL for display or storage without changing the transport URL.
- write_
atomic_ beneath - Atomically write
bytestoroot-relativerelwithout ever traversing out ofroot. The temp file is created andrenameat-swapped beneath the same confined directory fd as the destination (Linuxopenat2(RESOLVE_BENEATH)), so a parent dir swapped for an escaping symlink after a path check can’t redirect the write (#77), AND a crash/kill/disk-full mid-write leaves the previous file intact instead of a truncated one —open_beneath+WriteTruncategives the first guarantee but not the second. Falls back tocontain_within_canonical+ by-pathcrate::write_atomicon non-Linux / pre-openat2kernels (the same best-effort posture as the other helpers).