Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,13 @@ or removing a command fails until the table changes in the same commit.
| `agentSessions.search` | Search recorded agent session text |
| `agentSessions.read` | Read one recorded range as messages and where the next page starts |
| `agentSessions.stats` | Sum recorded agent usage with the latest rate limits |
| `agentSessions.calls` | List a page of recorded agent calls, most recent first, with their cost, cache hit rate and speed |
| `agentLibrary.configure` | Open the agent library in the platform's application data |
| `agentLibrary.read` | Read the library and what each configurable agent's instructions, skills, MCP servers and hooks hold |
| `agentLibrary.save` | Replace the library the user edited if it is still at the revision read |
| `agentLibrary.apply` | Apply one library change the user chose to one agent's configuration |
| `agentLibrary.importSkill` | Copy a skill from an agent or a directory the user chose into the library |
| `agentLibrary.removeSkill` | Remove a library skill and its links from agents |
| `plugins.declarative.validate` | Validate and normalize a declarative plugin manifest |
| `plugins.ui.applyResult` | Check a backend result for a plugin view and return the whole view to draw |
| `plugins.web.open` | Register a plugin page for a web tool window |
Expand Down
2 changes: 2 additions & 0 deletions rust/crates/agent-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ lithe-agent-sessions = { path = "../agent-sessions" }
lithe-diagnostics = { path = "../diagnostics" }
lithe-lsp-engine = { path = "../lsp-engine" }
lithe-lsp-transport = { path = "../lsp-transport" }
lithe-platform = { path = "../platform" }
lithe-plugin-agents = { path = "../plugin-agents" }
lithe-plugin-manifest = { path = "../plugin-manifest" }
lithe-plugin-model = { path = "../plugin-model" }
Expand All @@ -20,6 +21,7 @@ lithe-request-context = { path = "../request-context" }
lithe-workspace = { path = "../workspace" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sha2 = "0.10"

[dev-dependencies]
lithe-diagnostics = { path = "../diagnostics", features = ["test-support"] }
Expand Down
35 changes: 34 additions & 1 deletion rust/crates/agent-runtime/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
//! session only ever runs what a valid manifest declares.

use lithe_plugin_agents::{
catalog_entry, AgentDeclaration, PERMISSION_AGENTS_RUN, PERMISSION_AGENTS_SESSIONS,
catalog_entry, AgentDeclaration, PERMISSION_AGENTS_CONFIGURATION, PERMISSION_AGENTS_RUN,
PERMISSION_AGENTS_SESSIONS,
};
use lithe_protocol::{CoreError, ErrorCode};
use serde::Deserialize;
Expand All @@ -32,6 +33,10 @@ impl PluginAgents {
pub fn may_read_sessions(&self) -> bool {
self.granted.contains(PERMISSION_AGENTS_SESSIONS)
}

pub fn may_configure(&self) -> bool {
self.granted.contains(PERMISSION_AGENTS_CONFIGURATION)
}
}

/// An agent found in the catalog.
Expand All @@ -41,6 +46,7 @@ pub(crate) struct CatalogAgent {
pub agent: AgentDeclaration,
pub may_run: bool,
pub may_read_sessions: bool,
pub may_configure: bool,
}

impl CatalogAgent {
Expand Down Expand Up @@ -147,6 +153,9 @@ impl Catalog {
let mut entry = catalog_entry(plugin_id, agent);
entry["mayRun"] = json!(plugin.may_run());
entry["mayReadSessions"] = json!(plugin.may_read_sessions());
if agent.configuration.is_some() {
entry["mayConfigure"] = json!(plugin.may_configure());
}
entry
})
})
Expand All @@ -163,6 +172,7 @@ impl Catalog {
agent: agent.clone(),
may_run: plugin.may_run(),
may_read_sessions: plugin.may_read_sessions(),
may_configure: plugin.may_configure(),
})
}

Expand All @@ -184,9 +194,32 @@ impl Catalog {
agent: agent.clone(),
may_run: plugin.may_run(),
may_read_sessions: true,
may_configure: plugin.may_configure(),
})
})
.filter(|agent| !agent.agent.session_sources.is_empty())
.collect()
}

/// Every agent that declares configuration, granted or not, in catalog
/// order.
pub fn configurable(&self) -> Vec<CatalogAgent> {
let plugins = self.plugins.read().unwrap_or_else(PoisonError::into_inner);
plugins
.iter()
.flat_map(|(plugin_id, plugin)| {
plugin
.agents
.iter()
.filter(|agent| agent.configuration.is_some())
.map(move |agent| CatalogAgent {
plugin_id: plugin_id.clone(),
agent: agent.clone(),
may_run: plugin.may_run(),
may_read_sessions: plugin.may_read_sessions(),
may_configure: plugin.may_configure(),
})
})
.collect()
}
}
38 changes: 33 additions & 5 deletions rust/crates/agent-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
//! Core knows no agent: every agent-specific name, argument, protocol and file
//! layout comes from a plugin manifest and its backend.
//!
//! The host drives the runtime with two command families. `agents.*` covers
//! the catalog of declared agents and the live sessions; `agentSessions.*`
//! covers the local session records. Backends reach it with
//! The host drives the runtime with three command families. `agents.*`
//! covers the catalog of declared agents and the live sessions;
//! `agentSessions.*` covers the local session records; `agentLibrary.*`
//! covers Lithe's library of MCP servers, hooks, skills and instructions and
//! applies them to the agents' own configuration (the `library` module). Backends reach it with
//! `lithe/host/agents/*` requests, which the engine hands to the installed
//! [`AgentHost`] and which never reach the host application.
//!
Expand All @@ -27,12 +29,16 @@
//! - Session records are read only for agents the user granted
//! `agents.sessions.read`. Plugins granted `agents.usage.read` see totals
//! and rate limits, never text, titles, session IDs or directories.
//! - An agent's configuration changes only for a request the user started,
//! only for plugins granted `agents.configuration`, and MCP servers and
//! hooks only through a staged copy the plugin edits and Core checks.
//! - Logs carry opaque IDs and stable codes, never what flows through a
//! session.

mod backend;
mod catalog;
mod events;
mod library;
mod live;
mod records;

Expand All @@ -41,6 +47,7 @@ mod tests;

use backend::{BackendLink, EngineLink};
use catalog::Catalog;
use library::Library;
use lithe_lsp_engine::agent_host::{install_agent_host, AgentBackend, AgentHost, AgentHostFailure};
use lithe_plugin_rpc::{codes, AGENTS_REPORT, AGENTS_USAGE, AGENTS_WRITE};
use lithe_protocol::{CoreError, ErrorCode};
Expand Down Expand Up @@ -75,14 +82,27 @@ pub const AGENT_SESSION_COMMANDS: &[&str] = &[
"agentSessions.search",
"agentSessions.read",
"agentSessions.stats",
"agentSessions.calls",
];

/// The agent catalog, the live sessions and the session records.
/// The commands of the `agentLibrary.*` family.
pub const AGENT_LIBRARY_COMMANDS: &[&str] = &[
"agentLibrary.configure",
"agentLibrary.read",
"agentLibrary.save",
"agentLibrary.apply",
"agentLibrary.importSkill",
"agentLibrary.removeSkill",
];

/// The agent catalog, the live sessions, the session records and the
/// agent library.
pub(crate) struct Runtime {
pub link: Arc<dyn BackendLink>,
pub catalog: Catalog,
pub live: Live,
pub records: Records,
pub library: Library,
}

impl Runtime {
Expand All @@ -92,6 +112,7 @@ impl Runtime {
catalog: Catalog::default(),
live: Live::default(),
records: Records::default(),
library: Library::default(),
})
}

Expand Down Expand Up @@ -127,6 +148,13 @@ impl Runtime {
"agentSessions.search" => self.records.search(self, payload),
"agentSessions.read" => self.records.read(self, payload),
"agentSessions.stats" => self.records.stats(self, payload),
"agentSessions.calls" => self.records.calls(self, payload),
"agentLibrary.configure" => self.library.configure(payload),
"agentLibrary.read" => self.library.read(self, payload),
"agentLibrary.save" => self.library.save(payload),
"agentLibrary.apply" => self.library.apply(self, payload),
"agentLibrary.importSkill" => self.library.import_skill(self, payload),
"agentLibrary.removeSkill" => self.library.remove_skill(self, payload),
_ => Err(CoreError::new(
ErrorCode::NotSupported,
format!("Unknown agent command {command}."),
Expand Down Expand Up @@ -172,7 +200,7 @@ fn runtime() -> &'static Arc<Runtime> {
})
}

/// Runs one `agents.*` or `agentSessions.*` command.
/// Runs one `agents.*`, `agentSessions.*` or `agentLibrary.*` command.
pub fn execute(command: &str, payload: Value) -> Result<Value, CoreError> {
runtime().execute(command, payload)
}
Expand Down
Loading
Loading