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