Skip to main content

harn_vm/
lib.rs

1#![allow(clippy::result_large_err, clippy::cloned_ref_to_slice_refs)]
2
3pub mod agent_events;
4pub mod agent_sessions;
5pub mod bridge;
6pub mod checkpoint;
7mod chunk;
8mod compiler;
9pub mod events;
10mod http;
11pub mod jsonrpc;
12pub mod llm;
13pub mod llm_config;
14pub mod mcp;
15pub mod mcp_card;
16pub mod mcp_registry;
17pub mod mcp_server;
18pub mod metadata;
19pub mod orchestration;
20pub mod runtime_paths;
21pub mod schema;
22pub mod skills;
23pub mod stdlib;
24pub mod stdlib_modules;
25pub mod store;
26pub mod tool_annotations;
27pub mod tracing;
28pub mod value;
29pub mod visible_text;
30mod vm;
31pub mod workspace_path;
32
33pub use checkpoint::register_checkpoint_builtins;
34pub use chunk::*;
35pub use compiler::*;
36pub use http::{register_http_builtins, reset_http_state};
37pub use llm::register_llm_builtins;
38pub use mcp::{
39    connect_mcp_server, connect_mcp_server_from_json, connect_mcp_server_from_spec,
40    register_mcp_builtins,
41};
42pub use mcp_card::{fetch_server_card, load_server_card_from_path, CardError};
43pub use mcp_registry::{
44    active_handle as mcp_active_handle, ensure_active as mcp_ensure_active,
45    get_registration as mcp_get_registration, install_active as mcp_install_active,
46    is_registered as mcp_is_registered, register_servers as mcp_register_servers,
47    release as mcp_release, reset as mcp_reset_registry, snapshot_status as mcp_snapshot_status,
48    sweep_expired as mcp_sweep_expired, RegisteredMcpServer, RegistryStatus,
49};
50pub use mcp_server::{
51    take_mcp_serve_prompts, take_mcp_serve_registry, take_mcp_serve_resource_templates,
52    take_mcp_serve_resources, tool_registry_to_mcp_tools, McpServer,
53};
54pub use metadata::{register_metadata_builtins, register_scan_builtins};
55pub use stdlib::host::{clear_host_call_bridge, set_host_call_bridge, HostCallBridge};
56pub use stdlib::template::{
57    lookup_prompt_consumers, lookup_prompt_span, prompt_render_indices, record_prompt_render_index,
58    PromptSourceSpan, PromptSpanKind,
59};
60pub use stdlib::{
61    register_agent_stdlib, register_core_stdlib, register_io_stdlib, register_vm_stdlib,
62};
63pub use store::register_store_builtins;
64pub use value::*;
65pub use vm::*;
66
67/// Lex, parse, type-check, and compile source to bytecode in one call.
68/// Bails on the first type error. For callers that need diagnostics
69/// rather than early exit, use `harn_parser::check_source` directly
70/// and then call `Compiler::new().compile(&program)`.
71pub fn compile_source(source: &str) -> Result<Chunk, String> {
72    let program = harn_parser::check_source_strict(source).map_err(|e| e.to_string())?;
73    Compiler::new().compile(&program).map_err(|e| e.to_string())
74}
75
76/// Reset all thread-local state that can leak between test runs.
77pub fn reset_thread_local_state() {
78    llm::reset_llm_state();
79    llm_config::clear_user_overrides();
80    http::reset_http_state();
81    stdlib::reset_stdlib_state();
82    orchestration::clear_runtime_hooks();
83    events::reset_event_sinks();
84    agent_events::reset_all_sinks();
85    agent_sessions::reset_session_store();
86    mcp_registry::reset();
87}