Skip to main content

merry_runtime/
lib.rs

1//! Runtime session orchestration for Merry.
2//!
3//! This crate owns the MVP runtime facade for session execution:
4//!
5//! - [`Runtime`] and [`RuntimeBuilder`] construct a session-scoped runtime.
6//! - [`StepInput`], [`StepContext`], and [`RuntimeJournalEventStream`] drive one
7//!   provider-neutral runtime step at a time.
8//! - [`Tool`] defines the typed application-tool path; [`RegisteredTool`] and
9//!   [`ToolExecutor`] define the runtime-owned integration path.
10//! - [`Runtime::read_tool_output`] and [`Runtime::read_tool_output_preview`]
11//!   expose session-owned tool outputs without leaking provider wire formats.
12//!
13//! A few lower-level primitives are currently public because the in-memory MVP
14//! still needs explicit composition and tests around structured state:
15//! [`ContextCompiler`] and context entries.
16//! Treat these as unstable implementation-facing surfaces unless a [`Runtime`]
17//! method provides the same read or mutation path.
18//!
19//! Runtime state is structured and recorded before observable events are
20//! emitted. The crate boundary is intentionally provider-neutral. Provider
21//! adapters normalize requests and events in `merry-llm`/provider crates
22//! rather than storing provider response formats here.
23
24mod action_policy;
25mod agent_loop;
26mod bridge;
27mod checkpoint;
28mod compaction;
29mod context;
30mod durable_memory;
31mod error;
32mod events;
33mod final_output;
34mod interactive;
35mod memory;
36mod model_completion;
37mod model_config;
38mod permission;
39mod plan;
40mod process;
41mod process_background_tool;
42mod process_tool;
43mod profile;
44mod prompt;
45mod runtime;
46#[cfg(test)]
47mod schema_contract;
48mod session;
49mod session_projection;
50mod session_store;
51mod skill;
52mod step;
53mod subagent;
54mod text;
55mod todo;
56mod token_estimate;
57mod tool;
58mod tool_admission;
59mod tool_api;
60mod tool_catalog;
61mod tool_input;
62mod tool_input_validation;
63mod trajectory;
64mod user_input;
65mod workspace_scope;
66
67pub use agent_loop::{
68    AgentLoopBlockedReason, AgentLoopConfig, AgentLoopConfigError, AgentLoopError, AgentLoopResult,
69    AgentLoopStatus, AgentRun, AgentRunMessage, DEFAULT_AGENT_LOOP_MAX_MODEL_TURNS,
70    StructuredOutputRetryPolicy,
71};
72pub use checkpoint::{
73    CheckpointError, CheckpointId, CheckpointRef, CheckpointRefId, CheckpointRefManifest,
74    CheckpointSequenceRange, CheckpointSourceKind,
75};
76pub use compaction::{
77    CitationCompactionInput, CitationCompactionPolicy, CompactionError, CompactionOutcome,
78    ResolvedCitationCompactionBudget, citation_compaction_tail_directive,
79};
80pub use context::{
81    CheckpointDecision, CompactedCheckpoint, CompactedCheckpointSummary, CompiledContext,
82    CompiledContextSection, ContextBudget, ContextCompiler, ContextEntry, ContextError,
83    ContextSummary, DEFAULT_CONTEXT_WINDOW_FALLBACK_TOKENS, ProjectRules, ResolvedContextWindow,
84    SessionContextSnapshot, TaskAnchor, decide_checkpoint, resolve_context_window,
85};
86pub use durable_memory::{DurableMemory, DurableMemoryError, MemoryLayout, MemoryWriteKind};
87pub use error::RuntimeError;
88pub use events::{RuntimeEventStream, RuntimeJournalEventStream};
89pub use final_output::{
90    FINAL_OUTPUT_TOOL_NAME, FinalOutput, FinalOutputContract, FinalOutputContractError,
91};
92pub use interactive::{
93    AgentLoopControl, AgentLoopInput, InteractiveAgentRun, InteractiveError, InteractiveInputItem,
94    InteractiveInputSnapshot, InteractivePrimaryModel, InteractiveRunEventStream, InteractiveRunId,
95    InteractiveRunMessage, InteractiveSettingsUpdate, InteractiveSubagentSettings, InterruptReason,
96    QueuedInputId,
97};
98pub use merry_core::{
99    ContextWindowSource, ImageSummary, ToolOutput, ToolOutputKind, ToolOutputPreview,
100    ToolOutputStream, ToolSpec,
101};
102pub use model_config::RuntimeModelRole;
103pub use permission::{
104    ChannelPermissionAdmissionSource, HostFallbackReason, HostIntegration, PermissionActor,
105    PermissionAdmissionContext, PermissionAdmissionDecision, PermissionAdmissionError,
106    PermissionAdmissionFuture, PermissionAdmissionReview, PermissionAdmissionReviewSource,
107    PermissionAdmissionSource, PermissionRequest, PermissionReviewMode, PermissionReviewRequest,
108    PermissionReviewResponse, PermissionReviewResponseError, PermissionReviewRisk,
109    PermissionReviewRules, PermissionUserAuthorization, PermissionedAction, RequestedCapability,
110    RequestedPathCapability, RuntimeTrustLevel, parse_permission_request, request_permissions_tool,
111};
112pub use plan::PlanError;
113pub use process::{
114    AcceptedLocalWorkspaceProcessAdmission, BackgroundProcessControl, BackgroundProcessId,
115    BackgroundProcessLookupError, BackgroundProcessOutput, BackgroundProcessState,
116    BackgroundProcessStop, BackgroundProcessSummary, DEFAULT_PROCESS_WAIT_TIMEOUT_SECS,
117    LocalWorkspaceProcessSandboxProfile, MAX_PROCESS_ARG_BYTES, MAX_PROCESS_ARGV_ITEMS,
118    MAX_PROCESS_CWD_BYTES, MAX_PROCESS_OUTPUT_LIMIT_BYTES, MAX_PROCESS_STDIN_TEXT_BYTES,
119    MAX_PROCESS_WAIT_TIMEOUT_SECS, PermissionedProcessRunnerFactory, ProcessActionError,
120    ProcessActionIntent, ProcessEnvPolicy, ProcessExecutionEvidence, ProcessExitStatus,
121    ProcessOutputChunk, ProcessOutputEnvelope, ProcessOutputSink, ProcessOutputStream,
122    ProcessPermissionProfileId, ProcessRunner, ProcessRunnerContext, ProcessRunnerError,
123    ProcessRunnerFuture, ProcessRunnerOutput, ProcessRunnerResult,
124    StaticPermissionedProcessRunnerFactory, host_shell_chain_separator,
125    host_shell_has_unix_utilities, host_shell_name, is_low_risk_process_action_intent,
126    is_read_only_shell_process_action_intent, shell_command_for_argv,
127};
128pub use process::{
129    PreparedProcessPermission, ProcessPathGrant, ProcessPathGrantConstraint,
130    ProcessSessionPermissionSnapshot, ProcessSessionPermissionView, ProcessSessionPermissions,
131    SessionPermissionedProcessRunnerFactory,
132};
133pub use process_background_tool::{read_background_process_tool, stop_background_process_tool};
134pub use process_tool::{ProcessCommandToolError, process_command_tool};
135pub use profile::{
136    AcceptedLocalWorkspaceProcessRunnerProfile, PathAccess, PathAccessRule, PathAccessRuleSource,
137    RuntimeCapabilities, RuntimeProfile, RuntimeProfileBuilder, RuntimeProfileError,
138};
139pub use prompt::{PromptBlock, PromptError, PromptProfile, subagent_base_instructions};
140pub use runtime::{ArchiveConfig, CompactionConfig, HistoryRetention, Runtime, RuntimeBuilder};
141pub use session_projection::SessionTranscriptItem;
142pub use session_store::{FileSessionStore, SessionReservation, SessionStoreError};
143pub use skill::{
144    FrontmatterError, SkillCatalog, SkillError, SkillLoadWarning, SkillLoadWarningReason,
145    SkillMetadata,
146};
147pub use step::StepContext;
148pub use subagent::{
149    BackgroundHandoffNotice, BuiltChildRuntime, CancelSubagentsInput, ChildRuntimeFactory,
150    ChildRuntimeInput, ChildWorkspaceFinalization, ChildWorkspaceLifecycle, ChildWorkspaceScope,
151    ContextFileRef, DEFAULT_FOREGROUND_WAIT_BUDGET_SECS, DEFAULT_MAX_MODEL_TURNS,
152    DEFAULT_MIN_MODEL_TURNS, MAX_CONTEXT_FILE_REFS, MAX_CONTEXT_FILES_TOTAL_BYTES,
153    ParentPrimaryModel, PreloadedContextFile, RejectedSubagentView, ResumableChildSession,
154    SUBAGENT_HANDOFF_CONTEXT_ID, SendSubagentMessageInput, SendSubagentMessageOptions,
155    SendSubagentMessageOutcome, SendSubagentMessageOutput, SpawnSubagentTaskInput,
156    SpawnSubagentsInput, SpawnSubagentsOutput, SpawnWaitMode, SpawnedSubagentStatusLabel,
157    SpawnedSubagentView, SubagentActivityHub, SubagentActivityReceiver, SubagentConfig,
158    SubagentError, SubagentInspectSession, SubagentLimitBehavior, SubagentManager,
159    SubagentMessageDelivery, SubagentResultView, SubagentStatusLabel, SubagentStatusView,
160    SubagentTaskSpec, SubagentWorkspaceMode, SubagentWorktreeBase, SubagentWorktreeView, WaitMode,
161    WaitSubagentsInput, WaitSubagentsOutput, preload_context_files, render_subagent_handoff,
162    subagent_registered_tools, subagent_registered_tools_with_roles, subagent_tool_specs,
163    validate_no_write_scope_conflicts,
164};
165pub use tool::{
166    ActionExecutionEvidence, ActionProposal, ActionProposalError, ActionProposalEvidence,
167    RegisteredTool, ToolActionKind, ToolActionPreflight, ToolActionProposalFuture,
168    ToolActionProposalResult, ToolConcurrency, ToolExecutionContext, ToolExecutionError,
169    ToolExecutionOutcome, ToolExecutionResult, ToolExecutor, ToolExecutorFuture, ToolRunner,
170    WorkspacePatchChangeEvidence, WorkspacePatchExecutionEvidence, WorkspacePatchProposal,
171};
172pub use tool_admission::ToolAdmission;
173pub use tool_api::{Tool, ToolBuildError};
174pub use tool_catalog::LoadedSession;
175pub use user_input::{
176    MAX_USER_IMAGE_DIMENSION, MAX_USER_IMAGE_PIXELS, MAX_USER_IMAGE_PNG_BYTES,
177    MAX_USER_IMAGE_TOTAL_PNG_BYTES, MAX_USER_IMAGES, StepInput, UserImageInput, UserMessageInput,
178    user_image_label,
179};