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 hooks;
35mod interactive;
36mod memory;
37mod model_completion;
38mod model_config;
39mod permission;
40mod plan;
41mod process;
42mod process_background_tool;
43mod process_tool;
44mod profile;
45mod prompt;
46mod runtime;
47#[cfg(test)]
48mod schema_contract;
49mod session;
50mod session_projection;
51mod session_store;
52mod skill;
53mod step;
54mod subagent;
55mod text;
56mod todo;
57mod token_estimate;
58mod tool;
59mod tool_admission;
60mod tool_api;
61mod tool_catalog;
62mod tool_input;
63mod tool_input_validation;
64mod trajectory;
65mod user_input;
66mod workspace_scope;
67
68pub use agent_loop::{
69    AgentLoopBlockedReason, AgentLoopConfig, AgentLoopConfigError, AgentLoopError, AgentLoopResult,
70    AgentLoopStatus, AgentRun, AgentRunMessage, DEFAULT_AGENT_LOOP_MAX_MODEL_TURNS,
71    StructuredOutputRetryPolicy,
72};
73pub use checkpoint::{
74    CheckpointError, CheckpointId, CheckpointRef, CheckpointRefId, CheckpointRefManifest,
75    CheckpointSequenceRange, CheckpointSourceKind,
76};
77pub use compaction::{
78    CitationCompactionInput, CitationCompactionPolicy, CompactionError, CompactionOutcome,
79    CompactionPrompt, ResolvedCitationCompactionBudget, citation_compaction_tail_directive,
80};
81pub use context::{
82    AUTO_COMPACT_THRESHOLD_PERCENT, CheckpointDecision, CompactedCheckpoint,
83    CompactedCheckpointSummary, CompiledContext, CompiledContextSection, ContextBudget,
84    ContextCompiler, ContextEntry, ContextError, ContextSummary,
85    DEFAULT_CONTEXT_WINDOW_FALLBACK_TOKENS, ProjectRules, ResolvedContextWindow,
86    SessionContextSnapshot, TaskAnchor, bundled_model_context_window, decide_checkpoint,
87    resolve_context_window,
88};
89pub use durable_memory::{DurableMemory, DurableMemoryError, MemoryLayout, MemoryWriteKind};
90pub use error::RuntimeError;
91pub use events::{RuntimeEventStream, RuntimeJournalEventStream};
92pub use final_output::{
93    FINAL_OUTPUT_TOOL_NAME, FinalOutput, FinalOutputContract, FinalOutputContractError,
94};
95pub use hooks::{
96    AfterModelDecision, AfterModelStepContext, AfterToolCallContext, AfterToolDecision,
97    BeforeModelDecision, BeforeModelStepContext, BeforeToolCallContext, BeforeToolDecision,
98    HookDecision, HookError, HookFuture, HookInvocation, HookInvocationId, HookPoint, HookRegistry,
99    HookRequest, HookSubscriptions, RuntimeHookHandler, ToolHookFilter,
100};
101pub use interactive::{
102    AgentLoopControl, AgentLoopInput, InteractiveAgentRun, InteractiveError, InteractiveInputItem,
103    InteractiveInputSnapshot, InteractivePrimaryModel, InteractiveProcessExecutionUpdate,
104    InteractiveRunEventStream, InteractiveRunId, InteractiveRunMessage, InteractiveSettingsUpdate,
105    InteractiveSubagentSettings, InterruptReason, QueuedInputId,
106};
107pub use merry_core::{
108    ContextWindowSource, ImageSummary, ToolOutput, ToolOutputKind, ToolOutputPreview,
109    ToolOutputStream, ToolSpec,
110};
111pub use model_config::RuntimeModelRole;
112pub use permission::{
113    ChannelPermissionAdmissionSource, HostFallbackReason, HostIntegration, PermissionActor,
114    PermissionAdmissionContext, PermissionAdmissionDecision, PermissionAdmissionError,
115    PermissionAdmissionFuture, PermissionAdmissionReview, PermissionAdmissionReviewSource,
116    PermissionAdmissionSource, PermissionRequest, PermissionReviewMode, PermissionReviewRequest,
117    PermissionReviewResponse, PermissionReviewResponseError, PermissionReviewRisk,
118    PermissionReviewRules, PermissionUserAuthorization, PermissionedAction, RequestedCapability,
119    RequestedPathCapability, RuntimeTrustLevel, parse_permission_request, request_permissions_tool,
120};
121pub use plan::PlanError;
122pub use process::{
123    AcceptedLocalWorkspaceProcessAdmission, BackgroundProcessControl, BackgroundProcessId,
124    BackgroundProcessLookupError, BackgroundProcessOutput, BackgroundProcessState,
125    BackgroundProcessStop, BackgroundProcessSummary, DEFAULT_PROCESS_WAIT_TIMEOUT_SECS,
126    LocalWorkspaceProcessSandboxProfile, MAX_PROCESS_ARG_BYTES, MAX_PROCESS_ARGV_ITEMS,
127    MAX_PROCESS_CWD_BYTES, MAX_PROCESS_OUTPUT_LIMIT_BYTES, MAX_PROCESS_STDIN_TEXT_BYTES,
128    MAX_PROCESS_WAIT_TIMEOUT_SECS, PermissionedProcessRunnerFactory, ProcessActionError,
129    ProcessActionIntent, ProcessEnvPolicy, ProcessExecutionEvidence, ProcessExitStatus,
130    ProcessOutputChunk, ProcessOutputEnvelope, ProcessOutputSink, ProcessOutputStream,
131    ProcessPermissionProfileId, ProcessRunner, ProcessRunnerContext, ProcessRunnerError,
132    ProcessRunnerFuture, ProcessRunnerOutput, ProcessRunnerResult,
133    StaticPermissionedProcessRunnerFactory, host_shell_chain_separator,
134    host_shell_has_unix_utilities, host_shell_name, is_low_risk_process_action_intent,
135    is_read_only_shell_process_action_intent, shell_command_for_argv,
136};
137pub use process::{
138    PreparedProcessPermission, ProcessPathGrant, ProcessPathGrantConstraint,
139    ProcessSessionPermissionSnapshot, ProcessSessionPermissionView, ProcessSessionPermissions,
140    SessionPermissionedProcessRunnerFactory,
141};
142pub use process_background_tool::{read_background_process_tool, stop_background_process_tool};
143pub use process_tool::{ProcessCommandToolError, process_command_tool};
144pub use profile::{
145    AcceptedLocalWorkspaceProcessRunnerProfile, PathAccess, PathAccessRule, PathAccessRuleSource,
146    RuntimeCapabilities, RuntimeProfile, RuntimeProfileBuilder, RuntimeProfileError,
147};
148pub use prompt::{PromptBlock, PromptError, PromptProfile, subagent_base_instructions};
149pub use runtime::{ArchiveConfig, CompactionConfig, HistoryRetention, Runtime, RuntimeBuilder};
150pub use session_projection::SessionTranscriptItem;
151pub use session_store::{FileSessionStore, SessionReservation, SessionStoreError};
152pub use skill::{
153    FrontmatterError, SkillCatalog, SkillError, SkillLoadWarning, SkillLoadWarningReason,
154    SkillMetadata,
155};
156pub use step::StepContext;
157pub use subagent::{
158    BackgroundHandoffNotice, BuiltChildRuntime, CancelSubagentsInput, ChildRuntimeFactory,
159    ChildRuntimeInput, ChildWorkspaceFinalization, ChildWorkspaceLifecycle, ChildWorkspaceScope,
160    ContextFileRef, DEFAULT_FOREGROUND_WAIT_BUDGET_SECS, DEFAULT_MAX_MODEL_TURNS,
161    DEFAULT_MIN_MODEL_TURNS, MAX_CONTEXT_FILE_REFS, MAX_CONTEXT_FILES_TOTAL_BYTES,
162    ParentPrimaryModel, PreloadedContextFile, RejectedSubagentView, ResumableChildSession,
163    SUBAGENT_HANDOFF_CONTEXT_ID, SendSubagentMessageInput, SendSubagentMessageOptions,
164    SendSubagentMessageOutcome, SendSubagentMessageOutput, SpawnSubagentTaskInput,
165    SpawnSubagentsInput, SpawnSubagentsOutput, SpawnWaitMode, SpawnedSubagentStatusLabel,
166    SpawnedSubagentView, SubagentActivityHub, SubagentActivityReceiver, SubagentConfig,
167    SubagentError, SubagentInspectSession, SubagentLimitBehavior, SubagentManager,
168    SubagentMessageDelivery, SubagentResultView, SubagentStatusLabel, SubagentStatusView,
169    SubagentTaskSpec, SubagentWorkspaceMode, SubagentWorktreeBase, SubagentWorktreeView, WaitMode,
170    WaitSubagentsInput, WaitSubagentsOutput, preload_context_files, render_subagent_handoff,
171    subagent_registered_tools, subagent_registered_tools_with_roles, subagent_tool_specs,
172    validate_no_write_scope_conflicts,
173};
174pub use tool::{
175    ActionExecutionEvidence, ActionProposal, ActionProposalError, ActionProposalEvidence,
176    RegisteredTool, ToolActionKind, ToolActionPreflight, ToolActionProposalFuture,
177    ToolActionProposalResult, ToolConcurrency, ToolExecutionContext, ToolExecutionError,
178    ToolExecutionOutcome, ToolExecutionResult, ToolExecutor, ToolExecutorFuture, ToolRunner,
179    WorkspacePatchChangeEvidence, WorkspacePatchExecutionEvidence, WorkspacePatchProposal,
180};
181pub use tool_admission::ToolAdmission;
182pub use tool_api::{Tool, ToolBuildError};
183pub use tool_catalog::LoadedSession;
184pub use user_input::{
185    MAX_USER_IMAGE_DIMENSION, MAX_USER_IMAGE_PIXELS, MAX_USER_IMAGE_PNG_BYTES,
186    MAX_USER_IMAGE_TOTAL_PNG_BYTES, MAX_USER_IMAGES, StepInput, UserImageInput, UserMessageInput,
187    normalize_line_endings, sanitize_freeform_text, user_image_label,
188};