supercode-harness 0.4.8

The optional native Supercode agent and tool harness
Documentation
//! Canonical implementation inventory for external coding harnesses.
//!
//! This registry describes wiring that exists in the compiled core. It does
//! not claim that a harness has passed a real executable smoke test; the
//! autonomy audit joins this inventory with behavioral probe receipts and
//! tracker state before it calls anything verified.

use std::collections::BTreeMap;

use serde::{Deserialize, Serialize};

use crate::{
    AcpRuntimeBackend, ClaudeCodeRuntimeBackend, CodexRuntimeBackend, HarnessId,
    OpenCodeRuntimeBackend, PiRuntimeBackend, RuntimeBackend, RuntimeCapabilities, RuntimeLaunch,
};

/// Schema emitted by [`harness_support_registry`].
pub const SUPPORT_REGISTRY_SCHEMA: &str = "supercode.support-registry.v1";

/// How a primitive is wired into the compiled core.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ImplementationKind {
    /// A harness-specific implementation is registered.
    BuiltIn,
    /// A protocol-generic implementation is usable with a known launch.
    GenericProtocol,
    /// No implementation is present.
    Absent,
}

/// Persisted-session and translation implementation facts.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct NativeSupport {
    /// Whether the catalog can discover this harness's sessions.
    pub discover: ImplementationKind,
    /// Whether the core can load this harness's native persisted format.
    pub load: ImplementationKind,
    /// Whether the generic follower can open this harness's native storage.
    pub follow: ImplementationKind,
    /// Whether the canonical session can import this native format.
    pub import: ImplementationKind,
    /// Whether the canonical session can export this native format.
    pub export: ImplementationKind,
}

/// Live runtime wiring known without launching the real executable.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RuntimeSupport {
    /// Harness-specific or protocol-generic adapter registration.
    pub implementation: ImplementationKind,
    /// Protocol spoken by the adapter.
    pub protocol: String,
    /// Command used when callers do not provide an override.
    pub default_launch: Option<RuntimeLaunch>,
    /// Static adapter capabilities. Optional protocol features are only true
    /// for known agents that advertise them; the adapter validates them again
    /// during the live handshake.
    pub capabilities: RuntimeCapabilities,
}

/// One compiled harness implementation descriptor.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct HarnessSupportDescriptor {
    /// Stable harness identifier.
    pub id: HarnessId,
    /// Human-readable name.
    pub display_name: String,
    /// Native persistence/translation implementation.
    pub native: NativeSupport,
    /// Live runtime implementation.
    pub runtime: RuntimeSupport,
}

/// Machine-readable compiled support inventory.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SupportRegistryReport {
    /// Report schema.
    pub schema: String,
    /// Harness descriptors, in stable product order.
    pub harnesses: Vec<HarnessSupportDescriptor>,
}

fn built_in_native() -> NativeSupport {
    NativeSupport {
        discover: ImplementationKind::BuiltIn,
        load: ImplementationKind::BuiltIn,
        follow: ImplementationKind::BuiltIn,
        import: ImplementationKind::BuiltIn,
        export: ImplementationKind::BuiltIn,
    }
}

fn built_in_runtime(
    backend: &dyn RuntimeBackend,
    protocol: &str,
    launch: RuntimeLaunch,
) -> RuntimeSupport {
    RuntimeSupport {
        implementation: ImplementationKind::BuiltIn,
        protocol: protocol.into(),
        default_launch: Some(launch),
        capabilities: backend.capabilities(),
    }
}

/// Return the single compiled inventory used by product surfaces and audits.
pub fn harness_support_registry() -> SupportRegistryReport {
    let claude = ClaudeCodeRuntimeBackend::new();
    let codex = CodexRuntimeBackend::new();
    let opencode = OpenCodeRuntimeBackend::new();
    let pi = PiRuntimeBackend::new();
    let grok_launch = RuntimeLaunch {
        program: "grok".into(),
        arguments: vec![
            "--sandbox".into(),
            "workspace".into(),
            "agent".into(),
            "--no-leader".into(),
            "stdio".into(),
        ],
        env: BTreeMap::from([("GROK_AGENT_DASHBOARD".into(), "0".into())]),
    };
    let grok = AcpRuntimeBackend::new(HarnessId::from(HarnessId::GROK), grok_launch.clone())
        .with_resume_support(true);
    let gemini_launch = RuntimeLaunch {
        program: "gemini".into(),
        arguments: vec!["--acp".into()],
        env: BTreeMap::new(),
    };
    let gemini = AcpRuntimeBackend::new(HarnessId::from(HarnessId::GEMINI), gemini_launch.clone())
        .with_resume_support(true);
    let goose_launch = RuntimeLaunch {
        program: "goose".into(),
        arguments: vec!["acp".into()],
        env: BTreeMap::new(),
    };
    let goose = AcpRuntimeBackend::new(HarnessId::from(HarnessId::GOOSE), goose_launch.clone())
        .with_resume_support(true);
    let supercode_launch = RuntimeLaunch {
        program: "supercode".into(),
        arguments: vec!["acp".into()],
        env: BTreeMap::new(),
    };
    let supercode = AcpRuntimeBackend::new(
        HarnessId::from(HarnessId::SUPERCODE),
        supercode_launch.clone(),
    )
    .with_resume_support(true);

    SupportRegistryReport {
        schema: SUPPORT_REGISTRY_SCHEMA.into(),
        harnesses: vec![
            HarnessSupportDescriptor {
                id: HarnessId::from(HarnessId::CLAUDE_CODE),
                display_name: "Claude Code".into(),
                native: built_in_native(),
                runtime: built_in_runtime(
                    &claude,
                    "claude-stream-json",
                    RuntimeLaunch {
                        program: "claude".into(),
                        arguments: Vec::new(),
                        env: BTreeMap::new(),
                    },
                ),
            },
            HarnessSupportDescriptor {
                id: HarnessId::from(HarnessId::CODEX),
                display_name: "Codex".into(),
                native: built_in_native(),
                runtime: built_in_runtime(
                    &codex,
                    "codex-app-server-jsonl",
                    RuntimeLaunch {
                        program: "codex".into(),
                        arguments: vec!["app-server".into()],
                        env: BTreeMap::new(),
                    },
                ),
            },
            HarnessSupportDescriptor {
                id: HarnessId::from(HarnessId::OPENCODE),
                display_name: "OpenCode".into(),
                native: built_in_native(),
                runtime: built_in_runtime(
                    &opencode,
                    "opencode-http-sse",
                    RuntimeLaunch {
                        program: "opencode".into(),
                        arguments: vec!["serve".into()],
                        env: BTreeMap::new(),
                    },
                ),
            },
            HarnessSupportDescriptor {
                id: HarnessId::from(HarnessId::PI),
                display_name: "Pi".into(),
                native: built_in_native(),
                runtime: built_in_runtime(
                    &pi,
                    "pi-rpc-jsonl",
                    RuntimeLaunch {
                        program: "pi".into(),
                        arguments: vec!["--mode".into(), "rpc".into()],
                        env: BTreeMap::new(),
                    },
                ),
            },
            HarnessSupportDescriptor {
                id: HarnessId::from(HarnessId::GROK),
                display_name: "Grok".into(),
                native: built_in_native(),
                runtime: RuntimeSupport {
                    implementation: ImplementationKind::GenericProtocol,
                    protocol: "acp-v1-jsonrpc".into(),
                    default_launch: Some(grok_launch),
                    capabilities: grok.capabilities(),
                },
            },
            HarnessSupportDescriptor {
                id: HarnessId::from(HarnessId::GEMINI),
                display_name: "Gemini CLI".into(),
                native: built_in_native(),
                runtime: RuntimeSupport {
                    implementation: ImplementationKind::GenericProtocol,
                    protocol: "acp-v1-jsonrpc".into(),
                    default_launch: Some(gemini_launch),
                    capabilities: gemini.capabilities(),
                },
            },
            HarnessSupportDescriptor {
                id: HarnessId::from(HarnessId::GOOSE),
                display_name: "Goose".into(),
                native: built_in_native(),
                runtime: RuntimeSupport {
                    implementation: ImplementationKind::GenericProtocol,
                    protocol: "acp-v1-jsonrpc".into(),
                    default_launch: Some(goose_launch),
                    capabilities: goose.capabilities(),
                },
            },
            HarnessSupportDescriptor {
                id: HarnessId::from(HarnessId::SUPERCODE),
                display_name: "Supercode".into(),
                native: built_in_native(),
                runtime: RuntimeSupport {
                    implementation: ImplementationKind::GenericProtocol,
                    protocol: "acp-v1-jsonrpc".into(),
                    default_launch: Some(supercode_launch),
                    capabilities: supercode.capabilities(),
                },
            },
        ],
    }
}

/// Look up one harness in the compiled registry.
pub fn harness_support(id: &str) -> Option<HarnessSupportDescriptor> {
    harness_support_registry()
        .harnesses
        .into_iter()
        .find(|harness| harness.id.as_str() == id)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn registry_is_unique_and_reports_all_native_support() {
        let report = harness_support_registry();
        assert_eq!(report.schema, SUPPORT_REGISTRY_SCHEMA);
        assert_eq!(report.harnesses.len(), 8);
        let ids = report
            .harnesses
            .iter()
            .map(|harness| harness.id.as_str())
            .collect::<std::collections::BTreeSet<_>>();
        assert_eq!(ids.len(), report.harnesses.len());

        let grok = report
            .harnesses
            .iter()
            .find(|harness| harness.id.as_str() == HarnessId::GROK)
            .unwrap();
        assert_eq!(grok.native.discover, ImplementationKind::BuiltIn);
        assert_eq!(grok.native.load, ImplementationKind::BuiltIn);
        assert_eq!(grok.native.follow, ImplementationKind::BuiltIn);
        assert_eq!(grok.native.import, ImplementationKind::BuiltIn);
        for id in [HarnessId::GEMINI, HarnessId::SUPERCODE] {
            let harness = report
                .harnesses
                .iter()
                .find(|harness| harness.id.as_str() == id)
                .unwrap();
            assert_eq!(harness.native.discover, ImplementationKind::BuiltIn);
            assert_eq!(harness.native.load, ImplementationKind::BuiltIn);
            assert_eq!(harness.native.follow, ImplementationKind::BuiltIn);
        }
        assert_eq!(grok.native.export, ImplementationKind::BuiltIn);
        assert_eq!(
            grok.runtime.implementation,
            ImplementationKind::GenericProtocol
        );
        assert_eq!(
            grok.runtime.default_launch.as_ref().unwrap().arguments,
            ["--sandbox", "workspace", "agent", "--no-leader", "stdio"]
        );
        assert!(!grok
            .runtime
            .default_launch
            .as_ref()
            .unwrap()
            .arguments
            .iter()
            .any(|argument| argument == "--always-approve"));
        assert!(grok.runtime.capabilities.resume_session);
    }
}