Skip to main content

lattice_ai/
lib.rs

1//! `lattice-ai` — lattice's AI coding-agent integration layer.
2//!
3//! Owns both agent transports behind cargo features (default = both):
4//!   - `acp`: an Agent Client Protocol client. Spawns an agent (opencode, and
5//!     later claude-code-acp / gemini) as a stdio subprocess and drives it over
6//!     JSON-RPC. Architecturally a network peer like `lattice-lsp`.
7//!   - `mcp`: the Claude Code IDE peer (folded in by AG-4, see `mcp`). An
8//!     external `claude` CLI dials into a loopback WebSocket and drives the
9//!     editor over the same MCP contract as the VS Code / JetBrains plugins.
10//!
11//! Both share the protocol-neutral editor-capability port (`lattice-agent`) and
12//! the transport-neutral AI-log substrate (below). Runs no agent in-process.
13//! See `docs/dev/architecture/agent-integration.md`.
14
15// Transport-neutral: `:ai-log` + `register_ai_log_command` live here always;
16// the ACP lifecycle commands live in `acp::commands`.
17pub mod commands;
18
19// AG-5: the ACP adapter, gated on `feature = "acp"`. Symmetric with `mcp`: both
20// transport adapters are self-contained submodules under this crate. Drives
21// `opencode acp` headlessly and owns the conversation as a buffer -- kept for
22// the future IDE-native-review direction, reachable via `:opencode-acp`.
23#[cfg(feature = "acp")]
24pub mod acp;
25
26// The v1 opencode integration: `:opencode` runs the opencode **TUI** in a
27// terminal buffer + `opencode-mode` (the terminal topology, like the MCP peer).
28// Always compiled -- a terminal spawn + a marker minor mode, no heavy deps --
29// so opencode is available regardless of the `acp` transport feature.
30pub mod opencode;
31
32// The v1 pi (pi.dev) integration: `:pi` runs the pi **TUI** in a terminal
33// buffer + `pi-mode` (the terminal topology, like opencode and claude).
34// Always compiled -- same policy as opencode: a terminal spawn + marker minor
35// mode, no heavy deps, no feature gate.
36pub mod pi;
37
38// Unified boot entry point; wires the port-neutral log substrate always and
39// each transport behind its own `#[cfg(feature = …)]`.
40pub mod install;
41
42// AG-4: the MCP adapter (formerly the `lattice-claude-code` crate) folded in as
43// a submodule, gated on `feature = "mcp"`. The external `claude` CLI dials into
44// a loopback WebSocket; this half serves the shared editor-capability port
45// (`lattice-agent`) over that transport.
46#[cfg(feature = "mcp")]
47pub mod mcp;
48
49// AG-3: the per-process agent-log substrate (AiLogger, LogRing, SessionKey,
50// AiLogPushed, the `*ai:<provider>:<index>*` buffer names, and AiLogMode) lives
51// in the protocol-neutral `lattice-agent` port under `log/`. Re-exported here
52// verbatim so this crate's public API (and `lattice-host`, which reads
53// `lattice_ai::AiLogger` from the `ServiceRegistry`) is unchanged -- a re-export
54// does not change a type's identity, so the `TypeId`-keyed lookup still resolves
55// to what `install` registered. Transport-neutral -> unconditional.
56pub use install::install;
57pub use lattice_agent::AiLogMode;
58pub use lattice_agent::{
59    AiLogEventPublisher, AiLogLevel, AiLogPushed, AiLogRecord, AiLogSource, AiLogger, LogRing,
60    SessionKey, format_ai_log_line, level_tag,
61};
62pub use lattice_agent::{ai_log_name, parse_ai_log_name};
63
64// ACP-transport public surface (re-exported from the `acp` submodule so the
65// crate-root API -- `lattice_ai::AiClientHandle` etc. -- is unchanged).
66#[cfg(feature = "acp")]
67pub use acp::{
68    AiClientHandle, AiError, AiState, Connection, Result, SessionId, register_ai_ex_commands,
69};