Skip to main content

supercode_harness/
lib.rs

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