Skip to content
Draft
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
8 changes: 5 additions & 3 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,17 @@ or removing a command fails until the table changes in the same commit.
| `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, with the agent's `backup: {savedAtMs, modifiedSince}` while Core keeps one; an agent's `instructions` is `{path, state, ownLines?}`, `state` comparing Lithe's block in the file with the library (`absent`, `noBlock`, `current`, `stale`, `edited`, `tooLarge`, `unreadable`) and `ownLines` counting the user's own lines outside it; a library saved with `active` reads as that set `on`; optional `query`, `agent` with `presence`, and `sort` add the keys of the matching items as `matches` |
| `agentLibrary.save` | Replace the library the user edited if it is still at the revision read (instruction sets each with `on` and `agents`; `active` is refused), then write Lithe's block in the instruction file of every agent that follows the library, never over a block edited outside Lithe, and answer each agent's `written`, `unchanged`, `skipped` or `failed` with its reason in `instructions` |
| `agentLibrary.apply` | Apply one library change the user chose to one agent's configuration, backing up the configuration or instruction file it replaces first; an instruction `write` changes only Lithe's block and needs `replace` over an edited one, and `import` moves the user's own text outside the block into a new or existing set at the library revision read, leaving only the block, and answers `{changed, revision, instructions}` |
| `agentLibrary.apply` | Apply one library change the user chose to one agent's configuration, backing up the configuration or instruction file it replaces first; a server or hook goes through the plugin's `edit` on a checked staged copy, and an edit that reports no change is checked against the file as it is (`editNotApplied` when the change is not there); an instruction `write` changes only Lithe's block and needs `replace` over an edited one, and `import` moves the user's own text outside the block into a new or existing set at the library revision read, leaving only the block, and answers `{changed, revision, instructions}` |
| `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 |
| `agentProviders.read` | Read each agent's model, model providers, profiles and account label through its plugin, with a key reported only as `keySet` and other secrets as variable names; adds the providers Lithe saved (`listKeptBy: "lithe"`) and the agent's `backup: {savedAtMs, modifiedSince}`; always answers `models`, the models the plugin lists (none when it lists none), each with `shown`, beside the `efforts`, `speeds`, `effort` and `speed` it reports |
| `agentProviders.apply` | Apply one model, provider or profile change the plugin declares, through a checked staged copy of the agent's file backed up first; `addProvider`/`updateProvider` may carry a write-only `key` (or `clearKey`), handed only to the plugin's `edit`; `setModel` (which may carry `effort` and `speed`), `setEffort` and `setSpeed` are refused with `unknownModel`, `unknownEffort`, `unknownSpeed` or `unsupportedCombination` when the listed models do not take them, and `setModelMenu` is Core's own |
| `agentProviders.read` | Read each agent's model, model providers, profiles and account label through its plugin, with a key reported only as `keySet` and other secrets as variable names; adds the providers Lithe saved (`listKeptBy: "lithe"`) and the agent's `backup: {savedAtMs, modifiedSince}`; always answers `models`, the models the plugin lists (none when it lists none), each with `shown`, beside the `efforts`, `speeds`, `effort` and `speed` it reports; always answers `presets`, the providers the plugin offers to add (none when it lists none), and the manifest's `editsHeaders` and `probes`; a provider reported with `headers` (names with `valueSet`, never values) also has `headerNames` |
| `agentProviders.apply` | Apply one model, provider or profile change the plugin declares, through a checked staged copy of the agent's file backed up first (an edit that reports no change is checked against the file as it is, `editNotApplied` when the change is not there); `addProvider`/`updateProvider` may carry a write-only `key` (or `clearKey`) and, for a plugin that declares `editsHeaders`, the provider's whole list of `headers` `{name, value?}` (a header without a value keeps the provider's), all handed only to the plugin's `edit`; `setModel` (which may carry `effort` and `speed`), `setEffort` and `setSpeed` are refused with `unknownModel`, `unknownEffort`, `unknownSpeed` or `unsupportedCombination` when the listed models do not take them, and `setModelMenu` is Core's own |
| `agentProviders.restore` | Put every file of any configurable agent, with or without providers, back as it was before Lithe's first change since the last restore, whether `agentProviders.apply` or `agentLibrary.apply` changed it, and forget what Core last wrote to a restored instruction file and stop the agent following the library's instructions (`unfollowed`); refused when a file changed after Lithe's last write unless `discardLaterChanges` |
| `agentProviders.showModels` | Show or hide listed models of an agent in Lithe's pickers (user requests only), keeping the hidden ones in `models.json` in the library directory; when the plugin declares `setModelMenu`, also has it write the shown models into the CLI's own model menu, putting the switches back when it fails; answers `{changed}` |
| `agentProviders.readModelSettings` | Read an agent's model settings as one group, `{settings: {hidden, model?, effort?, speed?}}`, for saving as a plan |
| `agentProviders.applyModelSettings` | Write a group from `agentProviders.readModelSettings` back (user requests only): checks every model, effort and speed change first and changes nothing when one is refused, then makes them, replaces the hidden models and has the CLI's menu follow; answers `{changed}` |
| `agentProviders.fetchModels` | List the models one provider serves (user requests only), through the plugin's declared `probe` function, which makes the request with its own HTTP client: Core checks the provider, fills in what the agent has, hands a key and headers the user typed only to the plugin with a 20-second budget and an 8 MiB answer limit, waits at most 30 seconds, and answers `{agent, result: {category, status?, code?, durationMs}, models?}` with a closed category and no text; nothing is kept |
| `agentProviders.testConnection` | Send one provider the smallest request of its protocol (user requests only) through the plugin's declared `probe` function, as `agentProviders.fetchModels` does, with a 64 KiB answer limit; answers `{agent, result: {category, status?, code?, durationMs, model?}}`, a failed connection being a result and not a refusal |
| `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
6 changes: 5 additions & 1 deletion rust/crates/agent-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
//! covers Lithe's library of MCP servers, hooks, skills and instructions and
//! applies them to the agents' own configuration (the `library` module);
//! `agentProviders.*` reads and changes an agent's model, model providers
//! and profiles through the same staged copy. Backends reach it with
//! and profiles through the same staged copy, and has the agent's plugin
//! reach a provider over the network when the user asks for its models or a
//! connection test. Backends reach it with
//! `lithe/host/agents/*` requests, which the engine hands to the installed
//! [`AgentHost`] and which never reach the host application.
//!
Expand Down Expand Up @@ -141,6 +143,8 @@ impl Runtime {
"agentProviders.showModels" => self.library.show_models(self, payload),
"agentProviders.readModelSettings" => self.library.read_model_settings(self, payload),
"agentProviders.applyModelSettings" => self.library.apply_model_settings(self, payload),
"agentProviders.fetchModels" => self.library.fetch_models(self, payload),
"agentProviders.testConnection" => self.library.test_connection(self, payload),
_ => Err(CoreError::new(
ErrorCode::NotSupported,
format!("Unknown agent command {command}."),
Expand Down
22 changes: 17 additions & 5 deletions rust/crates/agent-runtime/src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2330,10 +2330,14 @@ impl Library {
/// `staging/`, lets `edit` change only the copy and report whether it
/// changed, lets `shows_change` confirm the copy holds the change, and
/// replaces the file with the copy if the file is unchanged meanwhile.
/// The staged copy is removed whatever happens. Before the file is
/// replaced its bytes are backed up under `backup` (the agent's record
/// key and the file's backup ID), and the change fails, unwritten, if
/// they cannot be. Answers whether the file changed.
/// When `edit` reports no change, or leaves the copy as the file was,
/// nothing is written, but `shows_change` must still confirm that the
/// file as it is holds the change: a plugin that ignores part of a
/// change cannot pass it off as already made. The staged copies are
/// removed whatever happens. Before the file is replaced its bytes are
/// backed up under `backup` (the agent's record key and the file's
/// backup ID), and the change fails, unwritten, if they cannot be.
/// Answers whether the file changed.
fn edit_staged(
&self,
config: &Config,
Expand All @@ -2347,12 +2351,20 @@ impl Library {
let staging = self.stage(config, &real, original.as_deref())?;
let outcome = (|| {
if !edit(&staging, original.is_some())? {
return Ok(false);
// Whatever the plugin left in its copy is dropped: the
// plugin reads a fresh copy of the file, which must already
// hold the change.
let fresh = self.stage(config, &real, original.as_deref())?;
let shown = shows_change(&fresh);
remove_leftover(&fresh, Leftover::Staging);
return shown.map(|()| false);
}
let edited = read_bounded(&staging, MAX_CONFIGURATION_FILE_BYTES)
.map_err(read_failure)?
.unwrap_or_default();
if original.as_deref() == Some(edited.as_slice()) {
// The copy is the file byte for byte.
shows_change(&staging)?;
return Ok(false);
}
shows_change(&staging)?;
Expand Down
Loading