Skip to main content

harn_hostlib/
lib.rs

1//! `harn-hostlib`: opt-in host builtins for code intelligence (tree-sitter,
2//! repo scanning, deterministic indexing) and tool execution (search, file
3//! I/O, git, process lifecycle, file watcher).
4//!
5//! This crate is the Rust home of two classes of code that previously lived
6//! in `burin-labs/burin-code`'s Swift `BurinCore`:
7//!
8//! 1. **Code intelligence** — `ast/`, `code_index/`, `scanner/`, `fs_watch/`.
9//! 2. **Deterministic tools** — `tools/` (search, fs, git, process).
10//!
11//! These don't belong inside `harn-vm` — pulling tree-sitter grammars,
12//! ripgrep, and `notify` into the VM would balloon the footprint of every
13//! pipeline that doesn't index host code. Instead, this crate exposes a
14//! single [`HostlibCapability`] trait. Embedders (today: `harn-cli`'s ACP
15//! server) compose the modules they need via [`HostlibRegistry`] and wire
16//! the resulting builtins into the VM through [`harn_vm::Vm::register_builtin`]
17//! / [`harn_vm::Vm::register_async_builtin`].
18//!
19//! ## Status
20//!
21//! This crate is a scaffold (issue #563). Every host method here returns
22//! [`HostlibError::Unimplemented`] until the implementation lands in
23//! follow-up issues B2/B3/B4/C1/C2/C3. The public surface — module names,
24//! method names, and JSON schemas under `schemas/` — is the source of truth
25//! for `burin-code`'s schema-drift tests, so it must stay stable across the
26//! follow-up PRs.
27
28#![deny(rust_2018_idioms)]
29#![warn(missing_docs)]
30
31pub mod ast;
32pub mod code_index;
33pub mod error;
34pub mod fs_watch;
35pub mod scanner;
36pub mod schemas;
37pub mod tools;
38
39mod registry;
40
41pub use error::HostlibError;
42pub use registry::{BuiltinRegistry, HostlibCapability, HostlibRegistry, RegisteredBuiltin};
43
44/// Convenience: build a `HostlibRegistry` populated with every capability
45/// the crate ships, register them on the supplied VM, and return the
46/// registry so callers can introspect (e.g. for schema-drift tests).
47///
48/// This is the canonical entry point for embedders that want the full
49/// hostlib surface; pick-and-choose embedders should construct
50/// [`HostlibRegistry`] directly.
51pub fn install_default(vm: &mut harn_vm::Vm) -> HostlibRegistry {
52    let mut registry = HostlibRegistry::new()
53        .with(ast::AstCapability)
54        .with(code_index::CodeIndexCapability)
55        .with(scanner::ScannerCapability)
56        .with(fs_watch::FsWatchCapability)
57        .with(tools::ToolsCapability);
58    registry.register_into_vm(vm);
59    registry
60}