Skip to main content

supercode_harness/
lib.rs

1//! # Volter Harness
2//!
3//! A lightweight, fully-customizable AI coding-agent SDK in Rust.
4//!
5//! `supercode` is a native agent loop — it talks directly to any model through
6//! [OpenRouter](https://openrouter.ai) (or any other OpenAI-compatible endpoint),
7//! drives a configurable set of tools, and is designed to be a superset of what
8//! tools like Claude Code and Codex can do: every prompt, every tool description,
9//! and every tool's on/off state is yours to control.
10//!
11//! ## Quick start
12//!
13//! ```no_run
14//! use supercode_harness::{Agent, Config};
15//!
16//! # async fn run() -> supercode_harness::Result<()> {
17//! // Reads OPENROUTER_API_KEY from the environment by default.
18//! let config = Config::builder()
19//!     .model("anthropic/claude-opus-4-8")
20//!     .system_prompt("You are a terse, expert pair programmer.")
21//!     .build();
22//!
23//! let mut agent = Agent::new(config)?;
24//! let reply = agent.send("List the files in the current directory.").await?;
25//! println!("{reply}");
26//! # Ok(())
27//! # }
28//! ```
29//!
30//! ## Design
31//!
32//! - [`Config`] — the single knob box: model, endpoint, credentials, sampling,
33//!   the system prompt, and per-tool overrides (enable/disable + custom
34//!   descriptions).
35//! - [`Provider`] — the model transport. [`OpenAiProvider`] speaks the
36//!   OpenAI chat-completions wire format and defaults to OpenRouter, so it
37//!   reaches Claude, GPT, Gemini, Llama, and anything else OpenRouter exposes.
38//! - [`Tool`] / [`ToolRegistry`] — the capability surface. Built-ins cover
39//!   file read/write/edit, directory listing, glob, content search, and shell
40//!   execution. Register your own to extend it.
41//! - [`Agent`] — the loop that ties it together: it streams a turn, runs any
42//!   tool calls the model requests, feeds results back, and repeats until the
43//!   model produces a final answer.
44
45#![warn(missing_docs)]
46
47#[cfg(feature = "adapter-acp")]
48/// The supercode ontology (`docs/ONTOLOGY.md`): the one model under sessions and the
49/// orchestration.
50pub use supercode_interchange::ontology;
51/// The orchestration piece of the ontology: a harness's operational home as one typed value.
52pub use supercode_interchange::orchestration;
53
54#[cfg(feature = "adapter-acp")]
55pub mod acp_frontend;
56#[cfg(feature = "adapter-acp")]
57pub mod acp_server;
58mod agent;
59pub mod agent_package;
60pub mod approvals;
61pub mod audit;
62pub mod channels;
63pub mod checkpoint;
64pub mod claude_compat;
65pub mod claude_peer;
66pub mod claude_relay;
67pub mod claude_runtime_state;
68pub mod codex_peer;
69mod config;
70pub mod config_schema;
71pub mod configfile;
72pub mod context_injection;
73mod error;
74pub mod formatters;
75#[cfg(feature = "adapter-api")]
76pub mod frontend;
77#[cfg(not(feature = "adapter-api"))]
78#[allow(dead_code)]
79mod frontend;
80#[allow(missing_docs)]
81mod frontend_contract_generated;
82pub mod git_metadata;
83pub mod goals;
84pub mod harness_auth;
85pub mod harness_command;
86#[cfg(feature = "adapter-api")]
87pub mod harness_service;
88#[cfg(not(feature = "adapter-api"))]
89#[allow(dead_code)]
90mod harness_service;
91pub mod hermes_import;
92pub mod human_export;
93pub mod interop_settings;
94pub mod jobs;
95pub mod jobs_control;
96pub mod jobs_notepad;
97pub mod live_runtime;
98pub mod lsp;
99#[cfg(feature = "adapter-api")]
100pub mod mail_mcp;
101#[cfg(feature = "adapter-api")]
102pub mod mail_route;
103#[cfg(feature = "adapter-api")]
104pub mod mail_send;
105#[cfg(feature = "adapter-api")]
106pub mod mail_watch;
107pub mod mailbox;
108pub mod mcp;
109pub mod mcp_oauth;
110pub mod memory;
111pub mod model_catalog;
112pub mod model_change;
113pub mod modules;
114mod native_materialize;
115pub mod orchestration_doors;
116pub mod orchestrator;
117pub mod orchestrator_door;
118pub mod output_style;
119pub mod parity;
120pub mod path_rules;
121pub mod permissions;
122pub mod plugins;
123pub mod presets;
124pub mod pricing;
125pub mod pricing_ref;
126pub mod profiles;
127pub mod profiles_control;
128mod provider;
129pub mod reduce;
130#[cfg(feature = "adapter-api")]
131pub mod relay_endpoint;
132mod residue_store;
133pub mod routes;
134pub mod runs;
135pub mod runtime;
136pub mod runtime_lease;
137#[cfg(feature = "adapter-api")]
138pub mod runtime_mail;
139#[cfg(feature = "adapter-api")]
140pub mod runtime_registry;
141mod safe_path;
142pub mod sandbox;
143pub mod schema;
144pub mod sdk;
145#[cfg(feature = "adapter-api")]
146pub mod server;
147#[cfg(not(feature = "adapter-api"))]
148#[allow(dead_code, unused_imports)]
149mod server;
150pub mod session_activity;
151pub mod session_index;
152pub mod session_journal;
153pub mod session_title;
154pub mod sessions_control;
155pub mod skills;
156pub mod skills_control;
157pub mod store;
158pub mod subagents;
159pub mod support;
160pub mod teams;
161pub mod tools;
162pub mod triggers;
163pub mod trust;
164pub mod tui;
165pub mod turn_record;
166pub mod usage_log;
167pub mod workflow_doors;
168
169#[cfg(feature = "adapter-acp")]
170pub use acp_frontend::{AcpFrontendCheckpoint, AcpFrontendConnectOptions, AcpFrontendRuntime};
171pub use agent::{Agent, ContextUsage};
172pub use approvals::{
173    approval_harnesses, lists_approvals, plan_reply, ApprovalChoice, ApprovalDecision,
174    ApprovalDoor, ApprovalKind, ApprovalOption, ApprovalRegistry, ApprovalResolution,
175    ApprovalResolveError, ApprovalRow, ApprovalStatus, ApprovalsQuery, ApprovalsResolveParams,
176};
177pub use channels::{
178    channel_status, list_channels, ChannelError, ChannelRow, ChannelStatus, CHANNELS_SCHEMA,
179    CHANNEL_HARNESSES,
180};
181pub use claude_peer::{
182    read_claude_peer_settings, read_registry as read_claude_peer_registry, resolve_live_session,
183    update_claude_peer_settings, user_settings_path as claude_user_settings_path,
184    write_claude_peer_settings, ClaudeCrossSessionInbound, ClaudePeerRefusal,
185    ClaudePeerRefusalError, ClaudePeerSession, ClaudePeerSettings, ClaudePeerSettingsError,
186    ClaudePeerStatus,
187};
188pub use claude_runtime_state::{
189    ClaudeBackgroundChild, ClaudeBackgroundState, ClaudeCronJob, ClaudeQueueState,
190    ClaudeRuntimeManifest, ClaudeRuntimePosture, ClaudeRuntimeResidue, ClaudeWakeup,
191    CLAUDE_RUNTIME_MANIFEST_VERSION,
192};
193pub use config::{
194    project_root_for, ApprovalPolicy, CachePlan, Config, ConfigBuilder, ConfigFile, ConfigProfile,
195    ContextInjectionBlock, HookDecision, LifecycleEvent, LifecycleHook, PreToolOutcome,
196    SteeringMode, StopGateHook, ToolAdvertising, ToolOverride, ToolOverrideProfile,
197    DEFAULT_SYSTEM_PROMPT,
198};
199pub use configfile::HarnessConfig;
200pub use interop_settings::{
201    configure_harness_interop_settings, inspect_harness_interop_settings, HarnessAdvisorySeverity,
202    HarnessInteropAdvisory, HarnessInteropControl, HarnessInteropSettingsError,
203    HarnessInteropSettingsReport, HarnessSettingChange, HarnessSettingChoice,
204    HarnessSettingRecommendation, HarnessSettingScope, CLAUDE_CROSS_SESSION_INBOUND_KEY,
205    HARNESS_INTEROP_SETTINGS_SCHEMA,
206};
207pub use jobs::{
208    get_job, list_jobs, supports_jobs, JobDeliver, JobPayload, JobSchedule, JobScope, JobSource,
209    JobsListing, JobsQuery, ScheduledJob, CLAUDE_SESSION_SCAN_LIMIT, JOB_HARNESSES,
210};
211pub use jobs_control::{
212    harness_program, mutate, supports_job_control, JobControlError, JobDeliverSpec, JobMutation,
213    JobMutationOutcome, JobPayloadSpec, JobScheduleSpec, JobVerb, CONTROLLED_JOB_HARNESSES,
214};
215pub use jobs_notepad::{JobNotepad, JobNotepadEntry, JobNotepadRequest};
216pub use live_runtime::{
217    discover_live_runtime, find_live_runtime, forget_live_runtime, list_live_runtimes,
218    register_live_runtime, register_live_runtime_with_metadata, resolve_live_runtime,
219    LiveRuntimeEndpoint, LiveRuntimeMetadata, LiveRuntimeReceiptError, LiveRuntimeRecord,
220    LiveRuntimeRegistration, LiveRuntimeSource, LiveRuntimeSupervisor, ResolvedLiveRuntime,
221};
222pub use memory::{
223    search_memory, show_memory, supports_memory, MemoryDocument, MemoryError, MemoryMatch,
224    MemoryQuery, MemoryScope, MemorySearchQuery, MEMORY_HARNESSES, MEMORY_SCHEMA,
225};
226pub use modules::{ModuleActivation, ModuleId};
227pub use orchestrator::{
228    clear_lease, daemon_entry, install_service, live_lease, lock_path, read_lease, resolve_program,
229    service_name, service_status, service_unit, uninstall_service, write_lease, write_unit, Lease,
230    OrchestratorError, ServiceState, ServiceUnit, DAEMON_ENTRY, LOCK_FILE, SERVICE_DIR,
231    SERVICE_NAME,
232};
233pub use orchestrator_door::{
234    daemon_is_live, socket_path, Door, DoorAnswer, DoorError, NODE_BIN_ENV, SOCKET_FILE,
235};
236pub use profiles::{
237    get_profile, list_profiles, ProfileError, ProfileKind, ProfileRow, HERMES_DEFAULT_PROFILE,
238    PROFILES_SCHEMA, PROFILE_HARNESSES,
239};
240pub use profiles_control::{
241    supports_profile_control, ProfileControlError, ProfileMutation, ProfileMutationOutcome,
242    ProfileVerb, CONTROLLED_PROFILE_HARNESSES,
243};
244pub use routes::{list_routes, RouteError, RouteMatch, RouteRow, ROUTES_SCHEMA, ROUTE_HARNESSES};
245pub use runs::{
246    get_run, list_runs, supports_runs, HarnessRun, RunDelivery, RunSource, RunsListing, RunsQuery,
247    RUN_HARNESSES,
248};
249pub use sessions_control::{
250    controlled_verbs, supports_session_control, SessionControlError, SessionDoor, SessionMutation,
251    SessionMutationOutcome, SessionVerb, CONTROLLED_SESSION_HARNESSES,
252};
253pub use supercode_interchange::catalog::{
254    orchestrator_profile_dirs, DiscoveryPage, DiscoveryQuery, HarnessCatalog, HarnessHomes,
255    HarnessId, SessionDescriptor, SessionLocator, StorageLocator,
256};
257pub use teams::{
258    connector_service_binary as teams_connector_service_binary,
259    connector_service_name as teams_connector_service_name,
260    connector_service_status as teams_connector_service_status,
261    connector_service_unit as teams_connector_service_unit,
262    install_connector_service as install_teams_connector_service,
263    install_service as install_teams_service, service_status as teams_service_status,
264    service_unit as teams_service_unit, teams_entry, teams_home,
265    uninstall_connector_service as uninstall_teams_connector_service,
266    uninstall_service as uninstall_teams_service, write_unit as write_teams_unit, TeamsError,
267    SERVICE_DIR as TEAMS_SERVICE_DIR, SERVICE_NAME as TEAMS_SERVICE_NAME, TEAMS_ENTRY,
268    TEAMS_PACKAGE,
269};
270pub use triggers::{
271    list_triggers, TriggerError, TriggerKind, TriggerRow, TRIGGERS_SCHEMA, TRIGGER_HARNESSES,
272};
273
274/// Format an agent's final reply for output. `json` wraps it as
275/// `{"result": "..."}`; otherwise the reply is returned as-is. The
276/// stream-json form is the live [`AgentEvent`] stream via an [`EventSink`].
277pub fn format_reply(reply: &str, json: bool) -> String {
278    if json {
279        serde_json::json!({ "result": reply }).to_string()
280    } else {
281        reply.to_string()
282    }
283}
284pub use error::{Error, Result};
285#[cfg(feature = "adapter-api")]
286pub use frontend::HttpFrontendRuntime;
287pub use frontend::{
288    FrontendActions, FrontendApprovalDecision, FrontendAttachSnapshot, FrontendAttachment,
289    FrontendCommandDescriptor, FrontendConnectionState, FrontendDisplayCapabilities,
290    FrontendElicitationAction, FrontendEvent, FrontendOperationDescriptor,
291    FrontendOperationInvocation, FrontendOperationKind, FrontendOperationResult, FrontendRequest,
292    FrontendRequestKind, FrontendResponse, FrontendRuntime, FrontendRuntimeDescriptor,
293    FrontendRuntimeError, FrontendRuntimeMetadata, FrontendTurnState, FRONTEND_REPLAY_CAPACITY,
294    FRONTEND_RUNTIME_SCHEMA_VERSION,
295};
296pub use frontend_contract_generated::{
297    FrontendFacadeMethod, FrontendFacadeTransport, GeneratedFrontendClient,
298};
299pub use harness_auth::{
300    harness_authentication_methods, harness_authentication_plan, inspect_harness_authentication,
301    HarnessAuthenticationEnvironment, HarnessAuthenticationError, HarnessAuthenticationInteraction,
302    HarnessAuthenticationLaunch, HarnessAuthenticationMethod, HarnessAuthenticationMethodId,
303    HarnessAuthenticationPlan, HarnessAuthenticationReport, HarnessAuthenticationState,
304    HarnessBrowserBehavior, HARNESS_AUTHENTICATION_SCHEMA,
305};
306pub use harness_service::{
307    DetachedAnswer, DetachedCall, HarnessSessionService, OpenedRuntime, ReturnedRuntime,
308    RuntimeOpen, DETACHED_CALL_DEADLINE, DETACHED_METHODS, HARNESS_SERVICE_VERSION,
309    RUNTIME_CONTROL_DEADLINE, RUNTIME_EVENT_METHOD, RUNTIME_OPEN_DEADLINE, RUNTIME_OPEN_METHODS,
310    SESSION_ACTIVITY_EVENT_METHOD, SESSION_DISCOVER_DEADLINE, SESSION_EVENT_METHOD,
311    SESSION_INDEX_EVENT_METHOD,
312};
313pub use provider::{
314    model_context_limit, ChatRequest, OpenAiProvider, PromptTokensDetails, Provider, RetryLog,
315    RetryNotice, ToolSchema, Usage, SERVED_MODEL_KEY, UNKNOWN_MODEL_CONTEXT_FLOOR,
316};
317#[cfg(feature = "adapter-api")]
318pub use runtime::SupercodeHttpRuntimeBackend;
319pub use runtime::{
320    AcpRuntimeBackend, BearerToken, ClaudeCodeRuntimeBackend, CodexRuntimeBackend, HarnessEvent,
321    McpServerLaunch, OpenCodeRuntimeBackend, PiRuntimeBackend, ResolvedRuntimeConnection,
322    RuntimeAttachRequest, RuntimeBackend, RuntimeCapabilities, RuntimeConnectLaunch,
323    RuntimeConnection, RuntimeEndpoint, RuntimeHandle, RuntimeInput, RuntimeLaunch,
324    RuntimeStartRequest,
325};
326pub use runtime_lease::{
327    CoordinatedRuntime, CoordinatedRuntimeClient, RuntimeAuthorization, RuntimeClientId,
328    RuntimeControllerLease, RuntimeLeaseCoordinator, RuntimeLeaseError, RuntimeLeaseSnapshot,
329    RuntimeObserverLease, RuntimePermission, DEFAULT_RUNTIME_LEASE_TTL_MS,
330};
331#[cfg(feature = "adapter-api")]
332pub use runtime_registry::{
333    LocalRuntimeRegistry, RuntimeRegistryEntry, RuntimeRegistryEvent, RuntimeRegistryOwner,
334    RuntimeRegistryQuery, RuntimeRegistryState, RuntimeRegistryWatch,
335};
336pub use sandbox::{landlock_available, netns_available, SandboxEnvPolicy, SandboxEscalation};
337pub use sdk::{
338    create_agent, discover_session_page, discover_sessions, load_session, load_session_path,
339    resume_agent, show_model_input, submit_agent, submit_agent_with_images, RuntimeSubmitError,
340    SdkAgent, SdkCapabilities, SdkError, SdkErrorCode, SdkEvent, SdkOperation, SdkPromptSource,
341    SdkRequest, SdkRuntime, SdkRuntimeEvent, SdkService, SDK_SCHEMA_VERSION,
342};
343pub use server::RpcEngine;
344pub use session_activity::{
345    SessionActivity, SessionActivityEvidence, SessionPresence, SessionTurnState,
346};
347pub use session_index::{SessionIndexChange, SessionIndexDelta, SessionIndexKey};
348pub use skills::{
349    declared_skill_name, list_skills, skill_roots, writable_skill_roots, SkillHomes, SkillRow,
350    SkillScope, SkillsQuery, SKILL_HARNESSES,
351};
352pub use skills_control::{
353    mutate_skill, supports_skill_control, SkillControlError, SkillMutation, SkillMutationOutcome,
354    SkillVerb, CONTROLLED_SKILL_HARNESSES,
355};
356pub use store::{SessionInfo, SessionStore};
357pub use supercode_interchange::session::{
358    CrossSurface, OrchestrationNouns, Recurrence, Session, SessionFormat, SessionMeta,
359    SessionSource, SurfaceKey, Trigger, WorkspaceKind, WorkspaceRef,
360};
361pub use supercode_interchange::watch::{SessionFollower, SessionSnapshotReason, SessionWatchEvent};
362pub use supercode_interchange::{
363    core_messages, measure_fidelity, messages_equal, messages_equal_multimodal, replay_eligible,
364    Fidelity, FidelityMetric, FidelityResidue,
365};
366pub use supercode_interchange::{
367    is_tool_error, mark_tool_error, mark_tool_outcome_unknown, tool_outcome, ChatMessage,
368    FunctionCall, Role, ToolCall, ToolOutcome, TOOL_ERROR_METADATA_KEY,
369    TOOL_OUTCOME_UNKNOWN_METADATA_KEY,
370};
371pub use supercode_runtime::{AgentEvent, EventSink};
372pub use support::{
373    harness_support, harness_support_registry, HarnessSupportDescriptor, ImplementationKind,
374    NativeSupport, RuntimeSupport, SupportRegistryReport, SUPPORT_REGISTRY_SCHEMA,
375};
376pub use tools::{
377    shell_sandbox_unenforceable, SandboxPolicy, SchemaTier, Tool, ToolContext, ToolRegistry,
378    WriteObserver,
379};