harn-vm 0.7.4

Async bytecode virtual machine for the Harn programming language
Documentation
#![allow(clippy::result_large_err, clippy::cloned_ref_to_slice_refs)]

pub mod agent_events;
pub mod agent_sessions;
pub mod bridge;
pub mod checkpoint;
mod chunk;
mod compiler;
pub mod events;
mod http;
pub mod jsonrpc;
pub mod llm;
pub mod llm_config;
pub mod mcp;
pub mod mcp_server;
pub mod metadata;
pub mod orchestration;
pub mod runtime_paths;
pub mod schema;
pub mod stdlib;
pub mod stdlib_modules;
pub mod store;
pub mod tool_annotations;
pub mod tracing;
pub mod value;
pub mod visible_text;
mod vm;

pub use checkpoint::register_checkpoint_builtins;
pub use chunk::*;
pub use compiler::*;
pub use http::{register_http_builtins, reset_http_state};
pub use llm::register_llm_builtins;
pub use mcp::{
    connect_mcp_server, connect_mcp_server_from_json, connect_mcp_server_from_spec,
    register_mcp_builtins,
};
pub use mcp_server::{
    take_mcp_serve_prompts, take_mcp_serve_registry, take_mcp_serve_resource_templates,
    take_mcp_serve_resources, tool_registry_to_mcp_tools, McpServer,
};
pub use metadata::{register_metadata_builtins, register_scan_builtins};
pub use stdlib::{
    register_agent_stdlib, register_core_stdlib, register_io_stdlib, register_vm_stdlib,
};
pub use store::register_store_builtins;
pub use value::*;
pub use vm::*;

/// Lex, parse, type-check, and compile source to bytecode in one call.
/// Bails on the first type error. For callers that need diagnostics
/// rather than early exit, use `harn_parser::check_source` directly
/// and then call `Compiler::new().compile(&program)`.
pub fn compile_source(source: &str) -> Result<Chunk, String> {
    let program = harn_parser::check_source_strict(source).map_err(|e| e.to_string())?;
    Compiler::new().compile(&program).map_err(|e| e.to_string())
}

/// Reset all thread-local state that can leak between test runs.
pub fn reset_thread_local_state() {
    llm::reset_llm_state();
    http::reset_http_state();
    stdlib::reset_stdlib_state();
    events::reset_event_sinks();
    agent_events::reset_all_sinks();
    agent_sessions::reset_session_store();
}