Skip to main content

harn_vm/
lib.rs

1#![allow(clippy::result_large_err, clippy::cloned_ref_to_slice_refs)]
2
3pub mod bridge;
4pub mod checkpoint;
5mod chunk;
6mod compiler;
7pub mod events;
8mod http;
9pub mod jsonrpc;
10pub mod llm;
11pub mod llm_config;
12pub mod mcp;
13pub mod mcp_server;
14pub mod metadata;
15pub mod orchestration;
16pub mod runtime_paths;
17pub mod schema;
18pub mod stdlib;
19pub mod stdlib_modules;
20pub mod store;
21pub mod tracing;
22pub mod value;
23pub mod visible_text;
24mod vm;
25
26pub use checkpoint::register_checkpoint_builtins;
27pub use chunk::*;
28pub use compiler::*;
29pub use http::{register_http_builtins, reset_http_state};
30pub use llm::register_llm_builtins;
31pub use mcp::{
32    connect_mcp_server, connect_mcp_server_from_json, connect_mcp_server_from_spec,
33    register_mcp_builtins,
34};
35pub use mcp_server::{
36    take_mcp_serve_prompts, take_mcp_serve_registry, take_mcp_serve_resource_templates,
37    take_mcp_serve_resources, tool_registry_to_mcp_tools, McpServer,
38};
39pub use metadata::{register_metadata_builtins, register_scan_builtins};
40pub use stdlib::{
41    register_agent_stdlib, register_core_stdlib, register_io_stdlib, register_vm_stdlib,
42};
43pub use store::register_store_builtins;
44pub use value::*;
45pub use vm::*;
46
47// ── Source pipeline (compile tier) ───────────────────────────────────
48
49/// Lex, parse, type-check, and compile source to bytecode in one call.
50/// Bails on the first type error. For callers that need diagnostics
51/// rather than early exit, use `harn_parser::check_source` directly
52/// and then call `Compiler::new().compile(&program)`.
53pub fn compile_source(source: &str) -> Result<Chunk, String> {
54    let program = harn_parser::check_source_strict(source).map_err(|e| e.to_string())?;
55    Compiler::new().compile(&program).map_err(|e| e.to_string())
56}
57
58/// Reset all thread-local state that can leak between test runs.
59/// Call this before each test execution for proper isolation.
60pub fn reset_thread_local_state() {
61    llm::reset_llm_state();
62    http::reset_http_state();
63    stdlib::reset_stdlib_state();
64    events::reset_event_sinks();
65}