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")]
48pub mod acp_frontend;
49#[cfg(feature = "adapter-acp")]
50pub mod acp_server;
51mod agent;
52pub mod audit;
53pub mod background;
54pub mod catalog;
55pub mod checkpoint;
56pub mod claude_compat;
57pub mod claude_peer;
58pub mod claude_runtime_scheduler;
59pub mod claude_runtime_state;
60pub mod codex_peer;
61mod config;
62pub mod configfile;
63mod error;
64mod event;
65pub mod fidelity;
66pub mod formatters;
67#[cfg(feature = "adapter-api")]
68pub mod frontend;
69#[cfg(not(feature = "adapter-api"))]
70#[allow(dead_code)]
71mod frontend;
72#[allow(missing_docs)]
73mod frontend_contract_generated;
74pub mod git_metadata;
75#[cfg(feature = "adapter-api")]
76pub mod harness_service;
77#[cfg(not(feature = "adapter-api"))]
78#[allow(dead_code)]
79mod harness_service;
80pub mod human_export;
81pub mod interop_settings;
82pub mod live_runtime;
83pub mod lsp;
84pub mod mcp;
85pub mod mcp_oauth;
86mod message;
87pub mod model_catalog;
88pub mod model_change;
89pub mod modules;
90pub mod permissions;
91pub mod plugins;
92pub mod presets;
93pub mod pricing_ref;
94mod provider;
95pub mod reduce;
96pub mod runtime;
97pub mod runtime_lease;
98#[cfg(feature = "adapter-api")]
99pub mod runtime_registry;
100mod safe_path;
101pub mod sandbox;
102pub mod schema;
103pub mod sdk;
104#[cfg(feature = "adapter-api")]
105pub mod server;
106#[cfg(not(feature = "adapter-api"))]
107#[allow(dead_code, unused_imports)]
108mod server;
109pub mod session;
110pub mod session_activity;
111pub mod session_index;
112pub mod session_title;
113pub mod session_tree;
114pub mod sidecar;
115pub mod store;
116pub mod subagents;
117pub mod support;
118pub mod tokens;
119pub mod tools;
120pub mod tui;
121pub mod usage_log;
122pub mod watch;
123
124#[cfg(feature = "adapter-acp")]
125pub use acp_frontend::{AcpFrontendCheckpoint, AcpFrontendConnectOptions, AcpFrontendRuntime};
126pub use agent::Agent;
127pub use catalog::{
128    DiscoveryPage, DiscoveryQuery, HarnessCatalog, HarnessHomes, HarnessId, SessionDescriptor,
129    SessionLocator, StorageLocator,
130};
131pub use claude_peer::{
132    message_claude_peer, read_claude_peer_settings, read_registry as read_claude_peer_registry,
133    update_claude_peer_settings, user_settings_path as claude_user_settings_path,
134    write_claude_peer_settings, ClaudeCrossSessionInbound, ClaudePeerDelivery, ClaudePeerEndpoint,
135    ClaudePeerRefusal, ClaudePeerRefusalError, ClaudePeerSession, ClaudePeerSettings,
136    ClaudePeerSettingsError, ClaudePeerStatus, CourierRunner, ProcessCourierRunner,
137};
138pub use claude_runtime_scheduler::{
139    ClaudeCronScheduleState, ClaudeRuntimeDeliveryState, ClaudeRuntimeSchedulerState,
140    ClaudeRuntimeTrigger, ClaudeRuntimeTriggerKind, ClaudeWakeupScheduleState,
141};
142pub use claude_runtime_state::{
143    ClaudeBackgroundChild, ClaudeBackgroundState, ClaudeCronJob, ClaudeQueueState,
144    ClaudeRuntimeExecutionState, ClaudeRuntimeManifest, ClaudeRuntimePosture, ClaudeRuntimeResidue,
145    ClaudeWakeup, CLAUDE_RUNTIME_MANIFEST_VERSION,
146};
147pub use config::{
148    ApprovalPolicy, CachePlan, Config, ConfigBuilder, ConfigFile, ConfigProfile,
149    ContextInjectionBlock, SteeringMode, StopGateHook, ToolAdvertising, ToolOverride,
150    ToolOverrideProfile, DEFAULT_SYSTEM_PROMPT,
151};
152pub use configfile::HarnessConfig;
153pub use interop_settings::{
154    configure_harness_interop_settings, inspect_harness_interop_settings, HarnessAdvisorySeverity,
155    HarnessInteropAdvisory, HarnessInteropControl, HarnessInteropSettingsError,
156    HarnessInteropSettingsReport, HarnessSettingChange, HarnessSettingChoice,
157    HarnessSettingRecommendation, HarnessSettingScope, CLAUDE_CROSS_SESSION_INBOUND_KEY,
158    HARNESS_INTEROP_SETTINGS_SCHEMA,
159};
160pub use live_runtime::{
161    discover_live_runtime, find_live_runtime, forget_live_runtime, list_live_runtimes,
162    register_live_runtime, register_live_runtime_with_metadata, resolve_live_runtime,
163    LiveRuntimeEndpoint, LiveRuntimeMetadata, LiveRuntimeReceiptError, LiveRuntimeRecord,
164    LiveRuntimeRegistration, LiveRuntimeSource, LiveRuntimeSupervisor, ResolvedLiveRuntime,
165};
166pub use modules::{ModuleActivation, ModuleId};
167
168/// Format an agent's final reply for output. `json` wraps it as
169/// `{"result": "..."}`; otherwise the reply is returned as-is. The
170/// stream-json form is the live [`AgentEvent`] stream via an [`EventSink`].
171pub fn format_reply(reply: &str, json: bool) -> String {
172    if json {
173        serde_json::json!({ "result": reply }).to_string()
174    } else {
175        reply.to_string()
176    }
177}
178pub use error::{Error, Result};
179pub use event::{AgentEvent, EventSink};
180pub use fidelity::{
181    core_messages, measure_fidelity, messages_equal, messages_equal_multimodal, replay_eligible,
182    Fidelity, FidelityMetric, FidelityResidue,
183};
184#[cfg(feature = "adapter-api")]
185pub use frontend::HttpFrontendRuntime;
186pub use frontend::{
187    FrontendActions, FrontendApprovalDecision, FrontendAttachSnapshot, FrontendAttachment,
188    FrontendCommandDescriptor, FrontendConnectionState, FrontendDisplayCapabilities,
189    FrontendElicitationAction, FrontendEvent, FrontendOperationDescriptor,
190    FrontendOperationInvocation, FrontendOperationKind, FrontendOperationResult, FrontendRequest,
191    FrontendRequestKind, FrontendResponse, FrontendRuntime, FrontendRuntimeDescriptor,
192    FrontendRuntimeError, FrontendRuntimeMetadata, FrontendTurnState, FRONTEND_REPLAY_CAPACITY,
193    FRONTEND_RUNTIME_SCHEMA_VERSION,
194};
195pub use frontend_contract_generated::{
196    FrontendFacadeMethod, FrontendFacadeTransport, GeneratedFrontendClient,
197};
198pub use harness_service::{
199    HarnessSessionService, HARNESS_SERVICE_VERSION, RUNTIME_EVENT_METHOD,
200    SESSION_ACTIVITY_EVENT_METHOD, SESSION_EVENT_METHOD, SESSION_INDEX_EVENT_METHOD,
201};
202pub use message::{
203    is_tool_error, mark_tool_error, mark_tool_outcome_unknown, tool_outcome, ChatMessage,
204    FunctionCall, Role, ToolCall, ToolOutcome, TOOL_ERROR_METADATA_KEY,
205    TOOL_OUTCOME_UNKNOWN_METADATA_KEY,
206};
207pub use provider::{
208    model_context_limit, ChatRequest, OpenAiProvider, PromptTokensDetails, Provider, ToolSchema,
209    Usage, UNKNOWN_MODEL_CONTEXT_FLOOR,
210};
211#[cfg(feature = "adapter-api")]
212pub use runtime::SupercodeHttpRuntimeBackend;
213pub use runtime::{
214    AcpRuntimeBackend, ClaudeCodeRuntimeBackend, CodexRuntimeBackend, HarnessEvent,
215    OpenCodeRuntimeBackend, PiRuntimeBackend, RuntimeAttachRequest, RuntimeBackend,
216    RuntimeCapabilities, RuntimeConnection, RuntimeEndpoint, RuntimeHandle, RuntimeInput,
217    RuntimeLaunch, RuntimeStartRequest,
218};
219pub use runtime_lease::{
220    CoordinatedRuntime, CoordinatedRuntimeClient, RuntimeAuthorization, RuntimeClientId,
221    RuntimeControllerLease, RuntimeLeaseCoordinator, RuntimeLeaseError, RuntimeLeaseSnapshot,
222    RuntimeObserverLease, RuntimePermission, DEFAULT_RUNTIME_LEASE_TTL_MS,
223};
224#[cfg(feature = "adapter-api")]
225pub use runtime_registry::{
226    LocalRuntimeRegistry, RuntimeRegistryEntry, RuntimeRegistryEvent, RuntimeRegistryOwner,
227    RuntimeRegistryQuery, RuntimeRegistryState, RuntimeRegistryWatch,
228};
229pub use sandbox::{landlock_available, netns_available, SandboxEnvPolicy, SandboxEscalation};
230pub use sdk::{
231    create_agent, discover_session_page, discover_sessions, load_session, load_session_path,
232    resume_agent, submit_agent, submit_agent_with_images, RuntimeSubmitError, SdkAgent,
233    SdkCapabilities, SdkError, SdkErrorCode, SdkEvent, SdkOperation, SdkPromptSource, SdkRequest,
234    SdkRuntime, SdkRuntimeEvent, SdkService, SDK_SCHEMA_VERSION,
235};
236pub use server::RpcEngine;
237pub use session::{Session, SessionFormat, SessionMeta, SessionSource};
238pub use session_activity::{
239    SessionActivity, SessionActivityEvidence, SessionPresence, SessionTurnState,
240};
241pub use session_index::{SessionIndexChange, SessionIndexDelta, SessionIndexKey};
242pub use store::{SessionInfo, SessionStore};
243pub use support::{
244    harness_support, harness_support_registry, HarnessSupportDescriptor, ImplementationKind,
245    NativeSupport, RuntimeSupport, SupportRegistryReport, SUPPORT_REGISTRY_SCHEMA,
246};
247pub use tools::{
248    shell_sandbox_unenforceable, SandboxPolicy, SchemaTier, Tool, ToolContext, ToolRegistry,
249    WriteObserver,
250};
251pub use watch::{SessionFollower, SessionSnapshotReason, SessionWatchEvent};