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