Skip to main content

harness/
lib.rs

1//! Compose's neutral agent-harness core.
2//!
3//! The library you depend on to drive — or build — an agent harness,
4//! independent of any specific backend. It provides:
5//!   * the [`Harness`] trait + the neutral request/metadata types
6//!     ([`RunRequest`] / [`RunTuning`] / [`HarnessInfo`] / …),
7//!   * the normalized [`RunEvent`] vocabulary every adapter parses into
8//!     ([`normalize_process_event`] + [`ParsedLine`]),
9//!   * the generic streaming subprocess engine ([`spawn_streaming`] +
10//!     [`ProcessEvent`] + [`ProcessHandle`]) + the install/login event
11//!     shape ([`InstallEvent`]), and
12//!   * the shared interactive-login helper ([`run_login_command`]).
13//!
14//! The built-in per-CLI adapters live here as modules ([`claude`]
15//! / [`codex`]), re-exported as [`Claude`] / [`Codex`]. The
16//! [`Registry`] is open: a third party adds their own provider by
17//! implementing [`Harness`] in their crate and registering it — no fork.
18//!
19//! Wire shapes derive `Serialize` so every transport emits identical
20//! JSON — keep their field names stable; the TypeScript front-end
21//! consumes them verbatim.
22
23pub mod events;
24pub mod harness;
25pub mod raw;
26pub mod models_dev;
27
28pub use events::{
29    normalize_process_event, run_events_from_parsed, ByteRange, ParsedLine, PlanEntry,
30    PlanEntryPriority, PlanEntryStatus, Question, QuestionOption, RunEvent, SessionInfo,
31    SuggestedEdit, ToolCallEnd, ToolCallStart, ToolKind, ToolLocation, UsageInfo,
32};
33pub use raw::parse_raw_line;
34pub use harness::{
35    run_login_command, BoxError, CredentialSpec, Harness, HarnessCapabilities, HarnessError,
36    HarnessInfo, HarnessModel, HarnessReadiness, InstallCallback, InstalledModel, InstallHint,
37    ModelManagement,
38    PullProgress, PullProgressAggregator, PullProgressCallback, ReasoningEffort, RunCallback,
39    RunControl, RunHandle, RunMode, RunRequest, RunTuning,
40};
41// The generic subprocess engine + the install/process event shapes live in
42// the `cli-stream` leaf; re-export them so adapters + consumers reach them
43// through the framework (e.g. `use harness::spawn_streaming`). `StreamError`
44// is re-exported too so a consumer can `downcast_ref` a `HarnessError`'s
45// source back to the typed spawn/cancel error.
46pub use cli_stream::{
47    augmented_node_path, hidden_command, spawn_streaming, InstallEvent, ProcessEvent,
48    ProcessHandle, StreamError,
49};
50
51#[cfg(feature = "claude")]
52pub mod claude;
53#[cfg(feature = "codex")]
54pub mod codex;
55/// The ACP-client adapter (drives an external Agent Client Protocol agent:
56/// OpenCode, Gemini, Goose, …).
57#[cfg(feature = "acp")]
58pub mod acp;
59/// The OpenAI-compatible / local-model runtime ("we are the agent" — owns the
60/// loop + tool surface, unlike the CLI/ACP adapters that wrap an external agent).
61#[cfg(feature = "openai-compatible")]
62pub mod openai_compatible;
63pub mod registry;
64
65// The built-in adapters, re-exported as short names so consumers write
66// `use harness::{Claude, Codex}` — each gated behind its feature.
67#[cfg(feature = "claude")]
68pub use claude::{ClaudeHarness as Claude, CLAUDE_HARNESS_ID};
69#[cfg(feature = "codex")]
70pub use codex::{CodexHarness as Codex, CODEX_HARNESS_ID};
71#[cfg(feature = "acp")]
72pub use acp::{AcpHarness, AcpHarnessConfig};
73// The OpenAI-compatible / local-model runtime + its public surface (permission
74// rules, MCP config, named subagents, model pricing, sessions).
75#[cfg(feature = "openai-compatible")]
76pub use openai_compatible::{
77    AgentDef, McpPrompt, McpPromptArg, McpServer, McpTransport, ModelCost, OpenHarness,
78    OpenHarnessConfig, Permission, PermissionPrompt, PermissionRequest, PermissionRule,
79    PromptMessage, SessionRecord,
80};
81// The open registry + convenience constructors over the built-ins.
82pub use registry::{
83    default_registry, harness_by_id, harness_catalog, Registry, DEFAULT_HARNESS_ID,
84};