Skip to main content

Crate lattice_ai

Crate lattice_ai 

Source
Expand description

lattice-ai — lattice’s AI coding-agent integration layer.

Owns both agent transports behind cargo features (default = both):

  • acp: an Agent Client Protocol client. Spawns an agent (opencode, and later claude-code-acp / gemini) as a stdio subprocess and drives it over JSON-RPC. Architecturally a network peer like lattice-lsp.
  • mcp: the Claude Code IDE peer (folded in by AG-4, see mcp). An external claude CLI dials into a loopback WebSocket and drives the editor over the same MCP contract as the VS Code / JetBrains plugins.

Both share the protocol-neutral editor-capability port (lattice-agent) and the transport-neutral AI-log substrate (below). Runs no agent in-process. See docs/dev/architecture/agent-integration.md.

Re-exports§

pub use install::install;
pub use acp::AiClientHandle;
pub use acp::AiError;
pub use acp::AiState;
pub use acp::Connection;
pub use acp::Result;
pub use acp::SessionId;
pub use acp::register_ai_ex_commands;

Modules§

acp
acp — lattice as an Agent Client Protocol client.
commands
The transport-neutral :ai-log ex-command.
install
AI-1b / AG‑4: the crate-owned install(boot) entry point.
mcp
mcp — lattice as the IDE side of the Claude Code agent protocol.
opencode
opencode — lattice drives the opencode agent’s native TUI in a terminal buffer (the v1 opencode integration).
pi
pi — lattice drives the pi agent’s native TUI in a terminal buffer (the v1 pi integration).

Structs§

AiLogMode
ai-log-mode – major mode for the per-session *ai:<provider>:<index>* buffer.
AiLogPushed
The typed event fired on every successful append. Analogue of lattice_lsp::events::LspLogPushed.
AiLogRecord
One log entry. Cheap to clone (Arc<str> for the session’s provider name; the message is a plain String).
AiLogger
Producer-side log facade. One per AI subsystem; each agent connection gets a clone (cheap – internal state is Arc<Mutex<...>>).
LogRing
Bounded ring of log records. Append-only; oldest is evicted when capacity is reached.
SessionKey
Per-process key for the per-session log ring – the (provider, index) pair that distinguishes concurrent agent processes of the same provider. A second opencode session (index = 2) is a distinct ring/buffer from the first, analogous to LSP’s InstanceKey(server_id, workspace). Cheap to clone (one Arc<str> + a Copy integer).

Enums§

AiLogLevel
Severity levels. Ordered low-to-high so the derived PartialOrd matches “Error > Warn > … > Trace”. Per-session min level filters records BELOW it (i.e. level < min drops; level >= min keeps).
AiLogSource
Where a log record originated.

Functions§

ai_log_name
Build the synthetic name for the per-session AI log buffer owned by super::modes::AiLogMode.
format_ai_log_line
Format one log record line for append to a synthetic AI log buffer. Shape: HH:MM:SS.mmm [<provider>:<index>] <level> <source>: <message>. Trailing newline is the caller’s responsibility (the drain batches many records into one buffer-append).
level_tag
Compact severity tag for AiLogPushed. Mirrors AiLogSource::tag’s shape for the level discriminator.
parse_ai_log_name
Recover the SessionKey from a per-session log buffer name. Returns None when name does not match the canonical *ai:<provider>:<index>* shape.

Type Aliases§

AiLogEventPublisher
Closure invoked on every successful append. Wired by the App (or test harness) to publish AiLogPushed onto the runtime event bus, which lets log buffers refresh live as records arrive. Optional: AiLogger::with_defaults() starts with no publisher; set_event_publisher installs one.