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_route;
101#[cfg(feature = "adapter-api")]
102pub mod mail_send;
103#[cfg(feature = "adapter-api")]
104pub mod mail_watch;
105pub mod mailbox;
106pub mod mcp;
107pub mod mcp_oauth;
108pub mod memory;
109pub mod model_catalog;
110pub mod model_change;
111pub mod modules;
112mod native_materialize;
113pub mod orchestration_doors;
114pub mod orchestrator;
115pub mod orchestrator_door;
116pub mod output_style;
117pub mod parity;
118pub mod path_rules;
119pub mod permissions;
120pub mod plugins;
121pub mod presets;
122pub mod pricing;
123pub mod pricing_ref;
124pub mod profiles;
125pub mod profiles_control;
126mod provider;
127pub mod reduce;
128#[cfg(feature = "adapter-api")]
129pub mod relay_endpoint;
130mod residue_store;
131pub mod routes;
132pub mod runs;
133pub mod runtime;
134pub mod runtime_lease;
135#[cfg(feature = "adapter-api")]
136pub mod runtime_mail;
137#[cfg(feature = "adapter-api")]
138pub mod runtime_registry;
139mod safe_path;
140pub mod sandbox;
141pub mod schema;
142pub mod sdk;
143#[cfg(feature = "adapter-api")]
144pub mod server;
145#[cfg(not(feature = "adapter-api"))]
146#[allow(dead_code, unused_imports)]
147mod server;
148pub mod session_activity;
149pub mod session_index;
150pub mod session_journal;
151pub mod session_title;
152pub mod sessions_control;
153pub mod skills;
154pub mod skills_control;
155pub mod store;
156pub mod subagents;
157pub mod support;
158pub mod teams;
159pub mod tools;
160pub mod triggers;
161pub mod trust;
162pub mod tui;
163pub mod turn_record;
164pub mod usage_log;
165pub mod workflow_doors;
166
167#[cfg(feature = "adapter-acp")]
168pub use acp_frontend::{AcpFrontendCheckpoint, AcpFrontendConnectOptions, AcpFrontendRuntime};
169pub use agent::{Agent, ContextUsage};
170pub use approvals::{
171    approval_harnesses, lists_approvals, plan_reply, ApprovalChoice, ApprovalDecision,
172    ApprovalDoor, ApprovalKind, ApprovalOption, ApprovalRegistry, ApprovalResolution,
173    ApprovalResolveError, ApprovalRow, ApprovalStatus, ApprovalsQuery, ApprovalsResolveParams,
174};
175pub use channels::{
176    channel_status, list_channels, ChannelError, ChannelRow, ChannelStatus, CHANNELS_SCHEMA,
177    CHANNEL_HARNESSES,
178};
179pub use claude_peer::{
180    read_claude_peer_settings, read_registry as read_claude_peer_registry, resolve_live_session,
181    update_claude_peer_settings, user_settings_path as claude_user_settings_path,
182    write_claude_peer_settings, ClaudeCrossSessionInbound, ClaudePeerRefusal,
183    ClaudePeerRefusalError, ClaudePeerSession, ClaudePeerSettings, ClaudePeerSettingsError,
184    ClaudePeerStatus,
185};
186pub use claude_runtime_state::{
187    ClaudeBackgroundChild, ClaudeBackgroundState, ClaudeCronJob, ClaudeQueueState,
188    ClaudeRuntimeManifest, ClaudeRuntimePosture, ClaudeRuntimeResidue, ClaudeWakeup,
189    CLAUDE_RUNTIME_MANIFEST_VERSION,
190};
191pub use config::{
192    project_root_for, ApprovalPolicy, CachePlan, Config, ConfigBuilder, ConfigFile, ConfigProfile,
193    ContextInjectionBlock, HookDecision, LifecycleEvent, LifecycleHook, PreToolOutcome,
194    SteeringMode, StopGateHook, ToolAdvertising, ToolOverride, ToolOverrideProfile,
195    DEFAULT_SYSTEM_PROMPT,
196};
197pub use configfile::HarnessConfig;
198pub use interop_settings::{
199    configure_harness_interop_settings, inspect_harness_interop_settings, HarnessAdvisorySeverity,
200    HarnessInteropAdvisory, HarnessInteropControl, HarnessInteropSettingsError,
201    HarnessInteropSettingsReport, HarnessSettingChange, HarnessSettingChoice,
202    HarnessSettingRecommendation, HarnessSettingScope, CLAUDE_CROSS_SESSION_INBOUND_KEY,
203    HARNESS_INTEROP_SETTINGS_SCHEMA,
204};
205pub use jobs::{
206    get_job, list_jobs, supports_jobs, JobDeliver, JobPayload, JobSchedule, JobScope, JobSource,
207    JobsListing, JobsQuery, ScheduledJob, CLAUDE_SESSION_SCAN_LIMIT, JOB_HARNESSES,
208};
209pub use jobs_control::{
210    harness_program, mutate, supports_job_control, JobControlError, JobDeliverSpec, JobMutation,
211    JobMutationOutcome, JobPayloadSpec, JobScheduleSpec, JobVerb, CONTROLLED_JOB_HARNESSES,
212};
213pub use jobs_notepad::{JobNotepad, JobNotepadEntry, JobNotepadRequest};
214pub use live_runtime::{
215    discover_live_runtime, find_live_runtime, forget_live_runtime, list_live_runtimes,
216    register_live_runtime, register_live_runtime_with_metadata, resolve_live_runtime,
217    LiveRuntimeEndpoint, LiveRuntimeMetadata, LiveRuntimeReceiptError, LiveRuntimeRecord,
218    LiveRuntimeRegistration, LiveRuntimeSource, LiveRuntimeSupervisor, ResolvedLiveRuntime,
219};
220pub use memory::{
221    search_memory, show_memory, supports_memory, MemoryDocument, MemoryError, MemoryMatch,
222    MemoryQuery, MemoryScope, MemorySearchQuery, MEMORY_HARNESSES, MEMORY_SCHEMA,
223};
224pub use modules::{ModuleActivation, ModuleId};
225pub use orchestrator::{
226    clear_lease, daemon_entry, install_service, live_lease, lock_path, read_lease, service_status,
227    service_unit, uninstall_service, write_lease, write_unit, Lease, OrchestratorError,
228    ServiceState, ServiceUnit, DAEMON_ENTRY, LOCK_FILE, SERVICE_DIR, SERVICE_NAME,
229};
230pub use orchestrator_door::{
231    daemon_is_live, socket_path, Door, DoorAnswer, DoorError, NODE_BIN_ENV, SOCKET_FILE,
232};
233pub use profiles::{
234    get_profile, list_profiles, ProfileError, ProfileKind, ProfileRow, HERMES_DEFAULT_PROFILE,
235    PROFILES_SCHEMA, PROFILE_HARNESSES,
236};
237pub use profiles_control::{
238    supports_profile_control, ProfileControlError, ProfileMutation, ProfileMutationOutcome,
239    ProfileVerb, CONTROLLED_PROFILE_HARNESSES,
240};
241pub use routes::{list_routes, RouteError, RouteMatch, RouteRow, ROUTES_SCHEMA, ROUTE_HARNESSES};
242pub use runs::{
243    get_run, list_runs, supports_runs, HarnessRun, RunDelivery, RunSource, RunsListing, RunsQuery,
244    RUN_HARNESSES,
245};
246pub use sessions_control::{
247    controlled_verbs, supports_session_control, SessionControlError, SessionDoor, SessionMutation,
248    SessionMutationOutcome, SessionVerb, CONTROLLED_SESSION_HARNESSES,
249};
250pub use supercode_interchange::catalog::{
251    orchestrator_profile_dirs, DiscoveryPage, DiscoveryQuery, HarnessCatalog, HarnessHomes,
252    HarnessId, SessionDescriptor, SessionLocator, StorageLocator,
253};
254pub use teams::{
255    connector_service_name as teams_connector_service_name,
256    connector_service_status as teams_connector_service_status,
257    connector_service_unit as teams_connector_service_unit,
258    install_connector_service as install_teams_connector_service,
259    install_service as install_teams_service, service_status as teams_service_status,
260    service_unit as teams_service_unit, teams_entry, teams_home,
261    uninstall_connector_service as uninstall_teams_connector_service,
262    uninstall_service as uninstall_teams_service, write_unit as write_teams_unit, TeamsError,
263    SERVICE_DIR as TEAMS_SERVICE_DIR, SERVICE_NAME as TEAMS_SERVICE_NAME, TEAMS_ENTRY,
264};
265pub use triggers::{
266    list_triggers, TriggerError, TriggerKind, TriggerRow, TRIGGERS_SCHEMA, TRIGGER_HARNESSES,
267};
268
269/// Format an agent's final reply for output. `json` wraps it as
270/// `{"result": "..."}`; otherwise the reply is returned as-is. The
271/// stream-json form is the live [`AgentEvent`] stream via an [`EventSink`].
272pub fn format_reply(reply: &str, json: bool) -> String {
273    if json {
274        serde_json::json!({ "result": reply }).to_string()
275    } else {
276        reply.to_string()
277    }
278}
279pub use error::{Error, Result};
280#[cfg(feature = "adapter-api")]
281pub use frontend::HttpFrontendRuntime;
282pub use frontend::{
283    FrontendActions, FrontendApprovalDecision, FrontendAttachSnapshot, FrontendAttachment,
284    FrontendCommandDescriptor, FrontendConnectionState, FrontendDisplayCapabilities,
285    FrontendElicitationAction, FrontendEvent, FrontendOperationDescriptor,
286    FrontendOperationInvocation, FrontendOperationKind, FrontendOperationResult, FrontendRequest,
287    FrontendRequestKind, FrontendResponse, FrontendRuntime, FrontendRuntimeDescriptor,
288    FrontendRuntimeError, FrontendRuntimeMetadata, FrontendTurnState, FRONTEND_REPLAY_CAPACITY,
289    FRONTEND_RUNTIME_SCHEMA_VERSION,
290};
291pub use frontend_contract_generated::{
292    FrontendFacadeMethod, FrontendFacadeTransport, GeneratedFrontendClient,
293};
294pub use harness_auth::{
295    harness_authentication_methods, harness_authentication_plan, inspect_harness_authentication,
296    HarnessAuthenticationEnvironment, HarnessAuthenticationError, HarnessAuthenticationInteraction,
297    HarnessAuthenticationLaunch, HarnessAuthenticationMethod, HarnessAuthenticationMethodId,
298    HarnessAuthenticationPlan, HarnessAuthenticationReport, HarnessAuthenticationState,
299    HarnessBrowserBehavior, HARNESS_AUTHENTICATION_SCHEMA,
300};
301pub use harness_service::{
302    DetachedAnswer, DetachedCall, HarnessSessionService, OpenedRuntime, ReturnedRuntime,
303    RuntimeOpen, DETACHED_CALL_DEADLINE, DETACHED_METHODS, HARNESS_SERVICE_VERSION,
304    RUNTIME_CONTROL_DEADLINE, RUNTIME_EVENT_METHOD, RUNTIME_OPEN_DEADLINE, RUNTIME_OPEN_METHODS,
305    SESSION_ACTIVITY_EVENT_METHOD, SESSION_DISCOVER_DEADLINE, SESSION_EVENT_METHOD,
306    SESSION_INDEX_EVENT_METHOD,
307};
308pub use provider::{
309    model_context_limit, ChatRequest, OpenAiProvider, PromptTokensDetails, Provider, RetryLog,
310    RetryNotice, ToolSchema, Usage, SERVED_MODEL_KEY, UNKNOWN_MODEL_CONTEXT_FLOOR,
311};
312#[cfg(feature = "adapter-api")]
313pub use runtime::SupercodeHttpRuntimeBackend;
314pub use runtime::{
315    AcpRuntimeBackend, BearerToken, ClaudeCodeRuntimeBackend, CodexRuntimeBackend, HarnessEvent,
316    McpServerLaunch, OpenCodeRuntimeBackend, PiRuntimeBackend, ResolvedRuntimeConnection,
317    RuntimeAttachRequest, RuntimeBackend, RuntimeCapabilities, RuntimeConnectLaunch,
318    RuntimeConnection, RuntimeEndpoint, RuntimeHandle, RuntimeInput, RuntimeLaunch,
319    RuntimeStartRequest,
320};
321pub use runtime_lease::{
322    CoordinatedRuntime, CoordinatedRuntimeClient, RuntimeAuthorization, RuntimeClientId,
323    RuntimeControllerLease, RuntimeLeaseCoordinator, RuntimeLeaseError, RuntimeLeaseSnapshot,
324    RuntimeObserverLease, RuntimePermission, DEFAULT_RUNTIME_LEASE_TTL_MS,
325};
326#[cfg(feature = "adapter-api")]
327pub use runtime_registry::{
328    LocalRuntimeRegistry, RuntimeRegistryEntry, RuntimeRegistryEvent, RuntimeRegistryOwner,
329    RuntimeRegistryQuery, RuntimeRegistryState, RuntimeRegistryWatch,
330};
331pub use sandbox::{landlock_available, netns_available, SandboxEnvPolicy, SandboxEscalation};
332pub use sdk::{
333    create_agent, discover_session_page, discover_sessions, load_session, load_session_path,
334    resume_agent, show_model_input, submit_agent, submit_agent_with_images, RuntimeSubmitError,
335    SdkAgent, SdkCapabilities, SdkError, SdkErrorCode, SdkEvent, SdkOperation, SdkPromptSource,
336    SdkRequest, SdkRuntime, SdkRuntimeEvent, SdkService, SDK_SCHEMA_VERSION,
337};
338pub use server::RpcEngine;
339pub use session_activity::{
340    SessionActivity, SessionActivityEvidence, SessionPresence, SessionTurnState,
341};
342pub use session_index::{SessionIndexChange, SessionIndexDelta, SessionIndexKey};
343pub use skills::{
344    declared_skill_name, list_skills, skill_roots, writable_skill_roots, SkillHomes, SkillRow,
345    SkillScope, SkillsQuery, SKILL_HARNESSES,
346};
347pub use skills_control::{
348    mutate_skill, supports_skill_control, SkillControlError, SkillMutation, SkillMutationOutcome,
349    SkillVerb, CONTROLLED_SKILL_HARNESSES,
350};
351pub use store::{SessionInfo, SessionStore};
352pub use supercode_interchange::session::{
353    CrossSurface, OrchestrationNouns, Recurrence, Session, SessionFormat, SessionMeta,
354    SessionSource, SurfaceKey, Trigger, WorkspaceKind, WorkspaceRef,
355};
356pub use supercode_interchange::watch::{SessionFollower, SessionSnapshotReason, SessionWatchEvent};
357pub use supercode_interchange::{
358    core_messages, measure_fidelity, messages_equal, messages_equal_multimodal, replay_eligible,
359    Fidelity, FidelityMetric, FidelityResidue,
360};
361pub use supercode_interchange::{
362    is_tool_error, mark_tool_error, mark_tool_outcome_unknown, tool_outcome, ChatMessage,
363    FunctionCall, Role, ToolCall, ToolOutcome, TOOL_ERROR_METADATA_KEY,
364    TOOL_OUTCOME_UNKNOWN_METADATA_KEY,
365};
366pub use supercode_runtime::{AgentEvent, EventSink};
367pub use support::{
368    harness_support, harness_support_registry, HarnessSupportDescriptor, ImplementationKind,
369    NativeSupport, RuntimeSupport, SupportRegistryReport, SUPPORT_REGISTRY_SCHEMA,
370};
371pub use tools::{
372    shell_sandbox_unenforceable, SandboxPolicy, SchemaTier, Tool, ToolContext, ToolRegistry,
373    WriteObserver,
374};