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
5 changes: 3 additions & 2 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,9 @@ or removing a command fails until the table changes in the same commit.
| `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 |
| `agentProviders.read` | Read each agent's model, model providers, profiles and account label through its plugin, with secrets reported as variable names only |
| `agentProviders.apply` | Apply one model, provider or profile change the plugin declares, through a checked staged copy of the agent's file |
| `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}` |
| `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` |
| `agentProviders.restore` | Put an agent's files back as they were before Lithe's first change since the last restore; refused when a file changed after Lithe's last write unless `discardLaterChanges` |
| `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
7 changes: 6 additions & 1 deletion rust/crates/agent-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ pub const AGENT_LIBRARY_COMMANDS: &[&str] = &[
];

/// The commands of the `agentProviders.*` family.
pub const AGENT_PROVIDER_COMMANDS: &[&str] = &["agentProviders.read", "agentProviders.apply"];
pub const AGENT_PROVIDER_COMMANDS: &[&str] = &[
"agentProviders.read",
"agentProviders.apply",
"agentProviders.restore",
];

/// The agent catalog, the live sessions, the session records and the
/// agent library.
Expand Down Expand Up @@ -169,6 +173,7 @@ impl Runtime {
"agentLibrary.removeSkill" => self.library.remove_skill(self, payload),
"agentProviders.read" => self.library.read_providers(self, payload),
"agentProviders.apply" => self.library.apply_providers(self, payload),
"agentProviders.restore" => self.library.restore_providers(self, payload),
_ => Err(CoreError::new(
ErrorCode::NotSupported,
format!("Unknown agent command {command}."),
Expand Down
26 changes: 20 additions & 6 deletions rust/crates/agent-runtime/src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
//! Logs carry plugin and agent IDs, categories, counts and codes, never
//! names, commands, paths or text.

mod backups;
mod providers;
mod saved;

#[cfg(test)]
pub(crate) use providers::is_endpoint_for_test;
Expand Down Expand Up @@ -2120,19 +2122,22 @@ impl Library {
))
}
};
self.edit_staged(config, &target_path, edit_file, shows_change)
self.edit_staged(config, &target_path, None, edit_file, shows_change)
}

/// Changes the file at `target` through a plugin: copies it into
/// `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. Answers whether the file
/// changed.
/// The staged copy is removed whatever happens. With `backup` (the
/// agent's record key and the declared file's ID), the file's bytes are
/// backed up first and the change fails, unwritten, if they cannot be.
/// Answers whether the file changed.
fn edit_staged(
&self,
config: &Config,
target: &Path,
backup: Option<(&str, &str)>,
edit: impl FnOnce(&Path, bool) -> Result<bool, CoreError>,
shows_change: impl FnOnce(&Path) -> Result<(), CoreError>,
) -> Result<bool, CoreError> {
Expand Down Expand Up @@ -2160,10 +2165,19 @@ impl Library {
"The configuration file changed while it was being edited.",
));
}
if let Some(parent) = real.parent() {
ensure_directory(parent)?;
let taken = backup
.map(|(agent, file)| backups::take(config, agent, file, now.as_deref(), &edited))
.transpose()?;
let written = real
.parent()
.map_or(Ok(()), ensure_directory)
.and_then(|()| write_replacing(&real, &edited).map_err(|_| write_failed()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟥 Provider keys inherit shared permissions

When a provider edit adds a key to a readable CLI configuration, write_replacing preserves its existing permissions. Other local users with access to that file can read the key.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

if let Err(error) = written {
if let Some(taken) = taken {
backups::undo(taken);
}
return Err(error);
}
write_replacing(&real, &edited).map_err(|_| write_failed())?;
Ok(true)
})();
let _ = fs::remove_file(&staging);
Expand Down
Loading
Loading