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