diff --git a/rust/contracts/rust-core-api.md b/rust/contracts/rust-core-api.md index 09aafe33..9d80a80b 100644 --- a/rust/contracts/rust-core-api.md +++ b/rust/contracts/rust-core-api.md @@ -487,6 +487,7 @@ or removing a command fails until the table changes in the same commit. | `agents.prompt` | Send the user's prompt to a live agent session | | `agents.cancel` | Ask the agent backend to cancel the turn in progress | | `agents.respondPermission` | Answer a pending agent permission request | +| `agents.setConfigOption` | Pick a value of a session setting the agent backend reported | | `agents.close` | End a live agent session | | `agents.waitEvents` | Wait, bounded, for agent session events after a sequence | | `agentSessions.configure` | Open the agent session record cache | diff --git a/rust/crates/agent-runtime/src/events.rs b/rust/crates/agent-runtime/src/events.rs index 8ddf6fd5..d8498d90 100644 --- a/rust/crates/agent-runtime/src/events.rs +++ b/rust/crates/agent-runtime/src/events.rs @@ -38,6 +38,12 @@ const MAX_PLAN_ENTRIES: usize = 256; /// Most windows of a rate-limit snapshot. pub(crate) const MAX_RATE_WINDOWS: usize = 8; +/// Most settings a session reports at once. +const MAX_CONFIG_OPTIONS: usize = 16; + +/// Most values of one setting. +const MAX_CONFIG_VALUES: usize = 128; + /// Most events the host queue keeps. The host reads continuously; when it /// falls this far behind, the oldest events are dropped and the next read /// says so. @@ -62,6 +68,7 @@ pub(crate) enum SessionEvent { RateLimits(RateLimits), TurnEnded(TurnEnded), Notice(Notice), + ConfigOptions(ConfigOptions), } /// What the agent says about its session. @@ -308,6 +315,53 @@ pub(crate) struct Notice { pub code: Option, } +/// What a setting means to the host, so it can place the setting where users +/// expect it. The names are ACP's categories: ACP's `thought_level` is +/// `thoughtLevel`. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub(crate) enum ConfigCategory { + /// The model the session uses. + Model, + /// How hard the model thinks, its values listed from least to most. + ThoughtLevel, + /// The agent's mode, for example asking before edits or planning only. + Mode, +} + +/// One value a setting may take. +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +pub(crate) struct ConfigValue { + pub value: String, + pub name: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub description: Option, +} + +/// A setting of the session the user may change, as ACP's session config +/// option: the value it has now and the values it may take. +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +pub(crate) struct ConfigOption { + pub id: String, + pub name: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub description: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub category: Option, + pub current_value: String, + pub options: Vec, +} + +/// The settings of the session the user may change. Each report replaces the +/// last; an empty list means there are none. +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +pub(crate) struct ConfigOptions { + pub config_options: Vec, +} + /// Why Core refused a report: a stable code for `error.data.code` and a /// message that names the event by index, never its content. #[derive(Debug, Clone, PartialEq, Eq)] @@ -328,6 +382,8 @@ pub(crate) struct TurnState { pub pending: BTreeMap)>, /// The agent CLI's own session ID, once reported. pub agent_session_id: Option, + /// The settings the backend last reported: ID to the values it may take. + pub config: BTreeMap>, } impl TurnState { @@ -395,6 +451,16 @@ impl TurnState { } } SessionEvent::RateLimits(_) | SessionEvent::Notice(_) => {} + SessionEvent::ConfigOptions(options) => { + self.config = options + .config_options + .iter() + .map(|option| { + let values = option.options.iter().map(|v| v.value.clone()).collect(); + (option.id.clone(), values) + }) + .collect(); + } SessionEvent::TurnEnded(ended) => { self.require_active(ended.turn)?; self.active_turn = None; @@ -428,6 +494,19 @@ impl TurnState { self.pending.remove(permission); Ok(turn) } + + /// Checks a value the user picked for a setting: the setting and the + /// value must be ones the backend last reported. + pub fn check_config(&self, option: &str, value: &str) -> Result<(), &'static str> { + let Some(values) = self.config.get(option) else { + return Err("agents.unknownConfigOption"); + }; + if values.iter().any(|candidate| candidate == value) { + Ok(()) + } else { + Err("agents.unknownConfigValue") + } + } } const INVALID_PARAMS: &str = lithe_plugin_rpc::codes::HOST_INVALID_PARAMS; @@ -523,6 +602,52 @@ fn check_bounds(event: &SessionEvent) -> Result<(), String> { text(¬ice.text, "text")?; optional_label(¬ice.code, "code")?; } + SessionEvent::ConfigOptions(options) => check_config_options(options)?, + } + Ok(()) +} + +/// Checks the settings a session reports: bounded labels, IDs and values +/// unique, and each current value one of the setting's values. +fn check_config_options(options: &ConfigOptions) -> Result<(), String> { + let label = |value: &str| !value.is_empty() && value.len() <= MAX_LABEL_BYTES; + let optional = |value: &Option| value.as_deref().is_none_or(label); + if options.config_options.len() > MAX_CONFIG_OPTIONS { + return Err("has more than 16 settings".to_string()); + } + let mut ids = Vec::with_capacity(options.config_options.len()); + for option in &options.config_options { + if !label(&option.id) + || !label(&option.name) + || !optional(&option.description) + || !label(&option.current_value) + { + return Err("has a setting with an empty or overlong label".to_string()); + } + if option.options.is_empty() || option.options.len() > MAX_CONFIG_VALUES { + return Err("has a setting without 1 to 128 values".to_string()); + } + let mut values = Vec::with_capacity(option.options.len()); + for value in &option.options { + if !label(&value.value) || !label(&value.name) || !optional(&value.description) { + return Err("has a setting value with an empty or overlong label".to_string()); + } + values.push(value.value.as_str()); + } + if !values.contains(&option.current_value.as_str()) { + return Err("has a setting whose current value is not one of its values".to_string()); + } + values.sort_unstable(); + values.dedup(); + if values.len() != option.options.len() { + return Err("repeats a setting value".to_string()); + } + ids.push(option.id.as_str()); + } + ids.sort_unstable(); + ids.dedup(); + if ids.len() != options.config_options.len() { + return Err("repeats a setting ID".to_string()); } Ok(()) } diff --git a/rust/crates/agent-runtime/src/lib.rs b/rust/crates/agent-runtime/src/lib.rs index d02559f9..f1b6aa89 100644 --- a/rust/crates/agent-runtime/src/lib.rs +++ b/rust/crates/agent-runtime/src/lib.rs @@ -18,8 +18,9 @@ //! //! Security rules this crate enforces: //! -//! - Only a request the user started may start a session, send a prompt or -//! answer a permission request. Sessions run only in trusted local +//! - Only a request the user started may start a session, send a prompt, +//! answer a permission request or change a session setting. Sessions run +//! only in trusted local //! workspaces, at most four per agent. //! - The executable is always the agent's declared tool, as the host resolved //! it. The plugin chooses arguments only, never the environment. @@ -60,6 +61,7 @@ pub const AGENT_COMMANDS: &[&str] = &[ "agents.prompt", "agents.cancel", "agents.respondPermission", + "agents.setConfigOption", "agents.close", "agents.waitEvents", ]; @@ -115,6 +117,7 @@ impl Runtime { "agents.prompt" => live::prompt(self, payload), "agents.cancel" => live::cancel(self, payload), "agents.respondPermission" => live::respond_permission(self, payload), + "agents.setConfigOption" => live::set_config_option(self, payload), "agents.close" => live::close(self, payload), "agents.waitEvents" => live::wait_events(self, payload), "agentSessions.configure" => self.records.configure(payload), diff --git a/rust/crates/agent-runtime/src/live.rs b/rust/crates/agent-runtime/src/live.rs index da419923..a36eac08 100644 --- a/rust/crates/agent-runtime/src/live.rs +++ b/rust/crates/agent-runtime/src/live.rs @@ -18,7 +18,7 @@ use lithe_lsp_engine::agent_host::{AgentBackend, AgentHostFailure}; use lithe_lsp_transport::process::{LspProcessHandle, LspProcessSpec}; use lithe_plugin_rpc::{ codes, AGENTS_DID_CANCEL, AGENTS_DID_DECIDE_PERMISSION, AGENTS_DID_EXIT, AGENTS_DID_OUTPUT, - AGENTS_DID_PROMPT, AGENTS_DID_START, + AGENTS_DID_PROMPT, AGENTS_DID_SET_CONFIG_OPTION, AGENTS_DID_START, }; use lithe_protocol::{CoreError, ErrorCode}; use lithe_request_context::Source; @@ -1014,6 +1014,54 @@ pub(crate) fn respond_permission( Ok(json!({ "turn": turn })) } +/// `agents.setConfigOption`: the value the user picked for one of the +/// session's settings. The backend applies it when the agent can take it, +/// which may be the next turn, and reports the settings again. +pub(crate) fn set_config_option( + runtime: &Arc, + payload: Value, +) -> Result { + #[derive(Deserialize)] + #[serde(deny_unknown_fields)] + struct ConfigAnswer { + session: String, + option: String, + value: String, + } + let request: ConfigAnswer = crate::decode(payload)?; + require_user("change a setting of")?; + let session = runtime.live.session(&request.session)?; + session + .lock_turns() + .check_config(&request.option, &request.value) + .map_err(|code| { + refusal( + ErrorCode::InvalidRequest, + code, + "The agent did not offer this setting or value.", + ) + })?; + runtime + .link + .notify( + &session.backend, + AGENTS_DID_SET_CONFIG_OPTION, + json!({ + "session": session.id, + "option": request.option, + "value": request.value, + }), + ) + .map_err(|_| { + refusal( + ErrorCode::ProcessFailed, + "agents.backendUnavailable", + "The agent plugin's backend did not take the setting.", + ) + })?; + Ok(json!({})) +} + /// `agents.close`: closes the CLI's input, then ends it if it does not exit. pub(crate) fn close(runtime: &Arc, payload: Value) -> Result { let request: SessionRequest = crate::decode(payload)?; diff --git a/rust/crates/agent-runtime/src/tests.rs b/rust/crates/agent-runtime/src/tests.rs index f4bd5117..c035c19a 100644 --- a/rust/crates/agent-runtime/src/tests.rs +++ b/rust/crates/agent-runtime/src/tests.rs @@ -14,7 +14,8 @@ use lithe_lsp_transport::process::{LspProcessLauncher, LspProcessSpec, LspProces use lithe_lsp_transport::scripted::ScriptedServer; use lithe_plugin_rpc::{ codes, AGENTS_DID_CANCEL, AGENTS_DID_DECIDE_PERMISSION, AGENTS_DID_EXIT, AGENTS_DID_OUTPUT, - AGENTS_DID_PROMPT, AGENTS_DID_START, AGENTS_REPORT, AGENTS_USAGE, AGENTS_WRITE, + AGENTS_DID_PROMPT, AGENTS_DID_SET_CONFIG_OPTION, AGENTS_DID_START, AGENTS_REPORT, AGENTS_USAGE, + AGENTS_WRITE, }; use lithe_protocol::{CoreError, ErrorCode}; use lithe_request_context::{trace, Source}; @@ -1079,6 +1080,142 @@ fn a_prompt_the_backend_does_not_take_ends_its_turn() { ); } +#[test] +fn session_settings_are_checked_and_reach_the_backend() { + let mut harness = Harness::new("settings", ALL_GRANTS); + let session = harness.start(); + let set = + |option: &str, value: &str| json!({ "session": session, "option": option, "value": value }); + // Nothing is offered before the backend reports its settings. + assert_eq!( + harness.refused("agents.setConfigOption", set("model", "fast")), + "agents.unknownConfigOption" + ); + + let settings = json!({ + "kind": "configOptions", + "configOptions": [ + { + "id": "model", + "name": "Model", + "category": "model", + "currentValue": "fast", + "options": [ + { "value": "fast", "name": "Fast" }, + { "value": "deep", "name": "Deep", "description": "Slower, more careful" } + ] + }, + { + "id": "effort", + "name": "Reasoning", + "category": "thoughtLevel", + "currentValue": "medium", + "options": [ + { "value": "low", "name": "Low" }, + { "value": "medium", "name": "Medium" }, + { "value": "high", "name": "High" } + ] + } + ] + }); + harness + .report(&session, json!([settings.clone()])) + .expect("settings are not bound to a turn"); + assert_eq!(harness.next_event(&session, "configOptions"), settings); + + assert_eq!( + harness.refused("agents.setConfigOption", set("mode", "plan")), + "agents.unknownConfigOption" + ); + assert_eq!( + harness.refused("agents.setConfigOption", set("effort", "max")), + "agents.unknownConfigValue" + ); + assert_eq!( + harness.run("agents.setConfigOption", set("effort", "high")), + json!({}) + ); + assert_eq!( + harness + .link + .await_notice(AGENTS_DID_SET_CONFIG_OPTION, |_| true), + json!({ "session": session, "option": "effort", "value": "high" }) + ); + + // A setting may change while a turn runs; the backend decides when the + // agent takes it. + assert_eq!( + harness.run("agents.prompt", json!({ "session": session, "text": "Hi" })), + json!({ "turn": 1 }) + ); + assert_eq!( + harness.run("agents.setConfigOption", set("model", "deep")), + json!({}) + ); + + // Each report replaces the settings; an empty list withdraws them. + harness + .report( + &session, + json!([{ "kind": "configOptions", "configOptions": [] }]), + ) + .expect("no settings"); + assert_eq!( + harness.refused("agents.setConfigOption", set("model", "fast")), + "agents.unknownConfigOption" + ); + + // Malformed settings are refused and leave the last ones in place. + let option = |current: &str, values: Value| { + json!([{ + "kind": "configOptions", + "configOptions": [{ "id": "model", "name": "Model", "currentValue": current, "options": values }] + }]) + }; + for bad in [ + option("other", json!([{ "value": "fast", "name": "Fast" }])), + option("fast", json!([])), + option( + "fast", + json!([{ "value": "fast", "name": "Fast" }, { "value": "fast", "name": "Again" }]), + ), + option("fast", json!([{ "value": "fast", "name": "" }])), + json!([{ + "kind": "configOptions", + "configOptions": [ + { "id": "model", "name": "Model", "currentValue": "fast", "options": [{ "value": "fast", "name": "Fast" }] }, + { "id": "model", "name": "Model", "currentValue": "fast", "options": [{ "value": "fast", "name": "Fast" }] } + ] + }]), + json!([{ + "kind": "configOptions", + "configOptions": [{ "id": "model", "name": "Model", "type": "select", "currentValue": "fast", "options": [{ "value": "fast", "name": "Fast" }] }] + }]), + ] { + let refusal = harness + .report(&session, bad) + .expect_err("malformed settings"); + assert_eq!(refusal.code, codes::HOST_INVALID_PARAMS); + } + assert_eq!( + harness.refused("agents.setConfigOption", set("model", "fast")), + "agents.unknownConfigOption" + ); + + // A backend that does not take the setting is reported. + harness + .report( + &session, + option("fast", json!([{ "value": "fast", "name": "Fast" }])), + ) + .expect("settings again"); + harness.link.refuse(Some(AGENTS_DID_SET_CONFIG_OPTION)); + assert_eq!( + harness.refused("agents.setConfigOption", set("model", "fast")), + "agents.backendUnavailable" + ); +} + #[test] fn only_a_user_request_prompts_or_answers_permissions() { let harness = Harness::new("background", ALL_GRANTS); @@ -1092,9 +1229,14 @@ fn only_a_user_request_prompts_or_answers_permissions() { "agents.respondPermission", json!({ "session": session, "permission": "p1", "option": "allow" }), ); + let setting = harness.refused( + "agents.setConfigOption", + json!({ "session": session, "option": "model", "value": "fast" }), + ); trace::replace(previous); assert_eq!(prompt, "agents.userActionRequired"); assert_eq!(permission, "agents.userActionRequired"); + assert_eq!(setting, "agents.userActionRequired"); assert!(harness.link.notices_of(AGENTS_DID_PROMPT).is_empty()); } diff --git a/rust/crates/core/src/protocol/command.rs b/rust/crates/core/src/protocol/command.rs index b0c998d1..60ba8657 100644 --- a/rust/crates/core/src/protocol/command.rs +++ b/rust/crates/core/src/protocol/command.rs @@ -235,6 +235,8 @@ pub enum AgentsCommand { Cancel, /// Answers a pending permission request (`agents.respondPermission`). RespondPermission, + /// Picks a value of a session setting the backend reported (`agents.setConfigOption`). + SetConfigOption, /// Ends a live session (`agents.close`). Close, /// Waits, bounded, for session events after a sequence (`agents.waitEvents`). @@ -266,6 +268,7 @@ impl AgentsCommand { Self::Prompt => "agents.prompt", Self::Cancel => "agents.cancel", Self::RespondPermission => "agents.respondPermission", + Self::SetConfigOption => "agents.setConfigOption", Self::Close => "agents.close", Self::WaitEvents => "agents.waitEvents", Self::RecordsConfigure => "agentSessions.configure", @@ -1256,6 +1259,7 @@ impl CoreCommand { "agents.prompt" => Some(Self::Agents(AgentsCommand::Prompt)), "agents.cancel" => Some(Self::Agents(AgentsCommand::Cancel)), "agents.respondPermission" => Some(Self::Agents(AgentsCommand::RespondPermission)), + "agents.setConfigOption" => Some(Self::Agents(AgentsCommand::SetConfigOption)), "agents.close" => Some(Self::Agents(AgentsCommand::Close)), "agents.waitEvents" => Some(Self::Agents(AgentsCommand::WaitEvents)), "agentSessions.configure" => Some(Self::Agents(AgentsCommand::RecordsConfigure)), diff --git a/rust/crates/plugin-rpc/src/host_notifications.rs b/rust/crates/plugin-rpc/src/host_notifications.rs index 9e004907..e56f1e54 100644 --- a/rust/crates/plugin-rpc/src/host_notifications.rs +++ b/rust/crates/plugin-rpc/src/host_notifications.rs @@ -91,6 +91,8 @@ pub const AGENTS_DID_PROMPT: &str = "lithe/host/agents/didPrompt"; pub const AGENTS_DID_CANCEL: &str = "lithe/host/agents/didCancel"; /// The user answered a permission request the backend reported. pub const AGENTS_DID_DECIDE_PERMISSION: &str = "lithe/host/agents/didDecidePermission"; +/// The user picked a value of a session setting the backend reported. +pub const AGENTS_DID_SET_CONFIG_OPTION: &str = "lithe/host/agents/didSetConfigOption"; /// The agent CLI exited. pub const AGENTS_DID_EXIT: &str = "lithe/host/agents/didExit"; @@ -166,6 +168,12 @@ pub(crate) const HOST_NOTIFICATIONS: &[HostNotification] = &[ grant: Some(AGENTS_WRITE), params: NotificationParams::Agent, }, + HostNotification { + method: AGENTS_DID_SET_CONFIG_OPTION, + service: HOST_SERVICE_AGENTS, + grant: Some(AGENTS_WRITE), + params: NotificationParams::Agent, + }, HostNotification { method: AGENTS_DID_EXIT, service: HOST_SERVICE_AGENTS, diff --git a/shared/plugins/contract/v1/README.md b/shared/plugins/contract/v1/README.md index 41364cbc..b1368697 100644 --- a/shared/plugins/contract/v1/README.md +++ b/shared/plugins/contract/v1/README.md @@ -3780,14 +3780,15 @@ terminalArguments?, update?, sessionRootVariables?}`: `modes` lists | `agents.prompt` | `{session, text}` | `{turn}` | | `agents.cancel` | `{session}` | `{turn}` | | `agents.respondPermission` | `{session, permission, option}` | `{turn}` | +| `agents.setConfigOption` | `{session, option, value}` | `{}` | | `agents.close` | `{session}` | `{}` | | `agents.sessions` | `{}` | `{sessions}`: the live sessions | | `agents.waitEvents` | `{after?, timeoutMilliseconds?, limit?}` | `{events: [{sequence, session, event}], next, missed}` | -- `agents.start`, `agents.prompt` and `agents.respondPermission` run only - for a request whose origin is the user (`agents.userActionRequired`): a - plugin cannot start a session, send a prompt or answer a permission - request. +- `agents.start`, `agents.prompt`, `agents.respondPermission` and + `agents.setConfigOption` run only for a request whose origin is the user + (`agents.userActionRequired`): a plugin cannot start a session, send a + prompt, answer a permission request or change a session setting. - `agents.start` refuses, in this order: a request not from the user; a remote workspace (`agents.remoteWorkspace`); an untrusted one (`agents.untrustedWorkspace`); an agent no configured plugin declares @@ -3809,9 +3810,12 @@ terminalArguments?, update?, sessionRootVariables?}`: `modes` lists `agents.cancel` refuses when no turn runs (`agents.noTurnInProgress`); `agents.respondPermission` refuses a request that is not pending or an option it does not offer (`agents.permissionNotPending`, - `agents.unknownPermissionOption`). A prompt, cancel or answer the backend - does not take is `agents.backendUnavailable`. An unknown session is - `agents.unknownSession`. + `agents.unknownPermissionOption`). `agents.setConfigOption` picks a value + of a setting the backend last reported with `configOptions`, also while a + turn runs; it refuses a setting the backend did not report or a value it + does not list (`agents.unknownConfigOption`, `agents.unknownConfigValue`). + A prompt, cancel, answer or setting the backend does not take is + `agents.backendUnavailable`. An unknown session is `agents.unknownSession`. - `agents.close` closes the CLI's standard input and ends the process after three seconds. - `agents.waitEvents` waits at most `timeoutMilliseconds` (default 0, at @@ -3848,9 +3852,10 @@ plugin backend only translates between the CLI's lines and Lithe's events: `didOutput`; the backend translates them and reports events with `lithe/host/agents/report`. It writes to the CLI's standard input with `lithe/host/agents/write`. -4. A prompt, cancel or permission decision of the user reaches the backend - as `didPrompt`, `didCancel` or `didDecidePermission`; the backend writes - what the CLI expects. `didExit` follows the end of the process. +4. A prompt, cancel, permission decision or setting change of the user + reaches the backend as `didPrompt`, `didCancel`, `didDecidePermission` or + `didSetConfigOption`; the backend writes what the CLI expects. `didExit` + follows the end of the process. Notifications Core sends (the host may not send them): @@ -3861,12 +3866,18 @@ Notifications Core sends (the host may not send them): | `lithe/host/agents/didPrompt` | `{session, turn, text}` | | `lithe/host/agents/didCancel` | `{session, turn}` | | `lithe/host/agents/didDecidePermission` | `{session, turn, permission, option}` | +| `lithe/host/agents/didSetConfigOption` | `{session, option, value}` | | `lithe/host/agents/didExit` | `{session, exitCode?}` | - `didOutput` carries at most 64 lines or 4 MiB per notification, in order. A line longer than 16 MiB is dropped and the host receives the event `outputLineDropped`; a notification the backend does not take ends the session as failed. +- `didSetConfigOption` carries a setting and value the backend last + reported. The backend applies it when the CLI can take it, which may be + the next turn, and reports `configOptions` again with the new current + value; when the CLI refuses it, the backend reports the unchanged settings + and a `notice`. - `didExit` is not sent when the session ended because the backend did. - The official SDKs route these notifications to one handler per session, in order, and report `turnEnded` with reason `failed` when the handler @@ -3914,8 +3925,17 @@ Session events (`report`'s `events[]`, each tagged by `kind`): | `rateLimits` | `windows`: 1–8 `{id, label?, usedPercent (0–100), windowMinutes?, resetsAtMs?}`, `plan?` | | `turnEnded` | `turn, reason` (`completed`, `cancelled`, `maxTokens`, `maxTurns`, `refused`, `failed`), `message?` | | `notice` | `level` (`info`, `warning`, `error`), `text, code?` | +| `configOptions` | `configOptions`: at most 16 `{id, name, description?, category?, currentValue, options}`, `category` one of `model`, `thoughtLevel`, `mode`, `options` 1–128 `{value, name, description?}` | - Labels and IDs are 1 byte to 1 KiB; texts at most 1 MiB. +- `configOptions` lists the settings of the session the user may change, + as the session config options of the Agent Client Protocol (ACP's + `thought_level` is `thoughtLevel`). Setting IDs are unique, values unique + within a setting, and `currentValue` is one of the setting's values; a + `thoughtLevel` setting lists its values from least to most. Each report + replaces the last; an empty list withdraws them. The event names no turn + and may come at any time. The host shows `model` and `thoughtLevel` + settings by the model picker and the others as menus. - `message`, `toolCall`, `plan`, `permissionRequested` and `turnEnded` name the active turn; a `usage` turn is at most the latest one. `turnEnded` ends the turn and drops its pending permission requests. diff --git a/shared/plugins/contract/v1/fixtures/agents/native-session.json b/shared/plugins/contract/v1/fixtures/agents/native-session.json index 28555fcd..2c38679b 100644 --- a/shared/plugins/contract/v1/fixtures/agents/native-session.json +++ b/shared/plugins/contract/v1/fixtures/agents/native-session.json @@ -9,6 +9,7 @@ { "method": "lithe/host/agents/didOutput", "params": { "session": "agent-2", "lines": ["other"] } }, { "method": "lithe/host/agents/didOutput", "params": { "session": "agent-1", "lines": ["three"] } }, { "method": "lithe/host/agents/didDecidePermission", "params": { "session": "agent-1", "turn": 1, "permission": "permission-1", "option": "allow" } }, + { "method": "lithe/host/agents/didSetConfigOption", "params": { "session": "agent-1", "option": "effort", "value": "high" } }, { "method": "lithe/host/agents/didCancel", "params": { "session": "agent-1", "turn": 1 } }, { "method": "lithe/host/agents/didOutput", "params": { "session": "agent-9", "lines": ["never started"] } }, { "method": "lithe/host/agents/didExit", "params": { "session": "agent-1", "exitCode": 0 } }, @@ -21,6 +22,7 @@ ["prompt", 1, "hello"], ["output", ["three"]], ["decidePermission", 1, "permission-1", "allow"], + ["setConfigOption", "effort", "high"], ["cancel", 1], ["exited", 0] ], @@ -66,6 +68,7 @@ "session": "agent-1", "events": [ { "kind": "session", "agentSessionID": "cli-session-1", "model": "example-model" }, + { "kind": "configOptions", "configOptions": [{ "id": "effort", "name": "Reasoning", "category": "thoughtLevel", "currentValue": "medium", "options": [{ "value": "medium", "name": "Medium" }, { "value": "high", "name": "High" }] }] }, { "kind": "message", "turn": 1, "role": "assistant", "messageID": "m1", "text": "Hi", "delta": false } ], "request": { @@ -74,6 +77,7 @@ "session": "agent-1", "events": [ { "kind": "session", "agentSessionID": "cli-session-1", "model": "example-model" }, + { "kind": "configOptions", "configOptions": [{ "id": "effort", "name": "Reasoning", "category": "thoughtLevel", "currentValue": "medium", "options": [{ "value": "medium", "name": "Medium" }, { "value": "high", "name": "High" }] }] }, { "kind": "message", "turn": 1, "role": "assistant", "messageID": "m1", "text": "Hi", "delta": false } ] } diff --git a/shared/plugins/reference/api-catalog.md b/shared/plugins/reference/api-catalog.md index 53b0ea53..5cb586c9 100644 --- a/shared/plugins/reference/api-catalog.md +++ b/shared/plugins/reference/api-catalog.md @@ -167,7 +167,7 @@ Lithe 的插件公共 API 按 [API 实施计划](https://github.com/1lck/Lithe-I | API-38 | `network/request` | 使用宿主代理策略发送有界 HTTP 请求 | `network.request` | 0 | | API-40 | `workspace/getHostPaths` | 远程上下文的根目录在远端主机上的绝对路径 `hostPath`,可用 `rootIDs` 指定根目录和顺序;只用在远端运行的进程参数、工作目录和语言服务器、调试器配置里;本地上下文返回 `plugin.host.authorityUnsupported` | `workspace.metadata`,单独的方法授权(只有服务授权得到 `permissionDenied`) | 0 | | API-45 | `agents/write` | 写本插件原生会话里 CLI 的标准输入:1–256 行,合计不超过 16 MiB,不含换行符,由 Core 补上;Core 直接回答 | `agents.native`,单独的方法授权 | 0 | -| API-45 | `agents/report` | 报告本插件原生会话的事件(会话、消息、工具调用、计划、权限请求、用量、额度、回合结束、提示):1–256 个,一起校验,一个被拒就全部不生效;Core 直接回答 | `agents.native`,单独的方法授权 | 0 | +| API-45 | `agents/report` | 报告本插件原生会话的事件(会话、消息、工具调用、计划、权限请求、用量、额度、回合结束、提示、用户可改的会话设置):1–256 个,一起校验,一个被拒就全部不生效;Core 直接回答 | `agents.native`,单独的方法授权 | 0 | | API-45 | `agents/usage` | 按天、Agent 或模型汇总用户已开启记录的 Agent 的用量,带最近的额度窗口;只有数字和模型名,不含对话正文、标题、会话 ID 和目录;Core 直接回答 | `agents.usage.read`,单独的方法授权 | 0 | 快捷键导入提供者另有 `lithe/host/keymapImport/listInputs`、`lithe/host/keymapImport/readChunk` 两个方法,属于 `litheKeymapImport` 协议,不在 API-01–45 内,见[快捷键导入](domains/keymap-import.md)。 @@ -187,6 +187,7 @@ Lithe 的插件公共 API 按 [API 实施计划](https://github.com/1lck/Lithe-I | API-45 | `agents/didPrompt` | 用户在会话里发了提示,开始新回合 `turn`,带提示正文 | `agents.native` | | API-45 | `agents/didCancel` | 用户取消了当前回合 | `agents.native` | | API-45 | `agents/didDecidePermission` | 用户回答了权限请求,带所选的 `option`;后端照此回复 CLI,自己不做决定 | `agents.native` | +| API-45 | `agents/didSetConfigOption` | 用户为后端报告的会话设置(模型、推理等级、模式等)选了一个值,带 `option` 和 `value`;后端在 CLI 能接受时应用,再报告一次设置 | `agents.native` | | API-45 | `agents/didExit` | CLI 进程退出,可能带 `exitCode`;会话因后端结束而结束时不发 | `agents.native` | ### 限制 @@ -386,7 +387,7 @@ Requests a backend sends to the host, all prefixed `lithe/host/`; the tables omi | API-38 | `network/request` | Send a bounded HTTP request with host proxy policy | `network.request` | 0 | | API-40 | `workspace/getHostPaths` | Gives the absolute paths `hostPath` of a remote context's root folders on the remote host, optionally for the roots `rootIDs` names, in that order; used only in the arguments, working directories, and language server or debugger configuration of what runs on that host; a local context gets `plugin.host.authorityUnsupported` | `workspace.metadata`, as a method grant of its own (the service grant alone gets `permissionDenied`) | 0 | | API-45 | `agents/write` | Writes the standard input of the CLI in one of this plugin's native sessions: 1–256 lines of at most 16 MiB together, without line breaks, which Core adds; answered by Core | `agents.native`, as a method grant of its own | 0 | -| API-45 | `agents/report` | Reports the events of one of this plugin's native sessions (session, message, tool call, plan, permission request, usage, rate limits, turn end, notice): 1–256, checked together, so when one is refused none applies; answered by Core | `agents.native`, as a method grant of its own | 0 | +| API-45 | `agents/report` | Reports the events of one of this plugin's native sessions (session, message, tool call, plan, permission request, usage, rate limits, turn end, notice, session settings the user may change): 1–256, checked together, so when one is refused none applies; answered by Core | `agents.native`, as a method grant of its own | 0 | | API-45 | `agents/usage` | Sums the usage of the agents whose records the user enabled, by day, agent, or model, with the latest quota windows; only numbers and model names, never conversation text, titles, session IDs, or directories; answered by Core | `agents.usage.read`, as a method grant of its own | 0 | Shortcut import providers also have two methods, `lithe/host/keymapImport/listInputs` and `lithe/host/keymapImport/readChunk`. They belong to the `litheKeymapImport` protocol, outside API-01–45; see [Shortcut import](domains/keymap-import.md). @@ -406,6 +407,7 @@ Notifications the host sends to a backend (the backend answers none), also prefi | API-45 | `agents/didPrompt` | The user sent a prompt in the session, starting the new turn `turn`, with the prompt text | `agents.native` | | API-45 | `agents/didCancel` | The user cancelled the active turn | `agents.native` | | API-45 | `agents/didDecidePermission` | The user answered a permission request with `option`; the backend relays it to the CLI and decides nothing itself | `agents.native` | +| API-45 | `agents/didSetConfigOption` | The user picked a value, `value`, for a session setting the backend reported, `option` (a model, reasoning level, mode, and so on); the backend applies it when the CLI can take it and reports the settings again | `agents.native` | | API-45 | `agents/didExit` | The CLI process exited, with `exitCode` when there is one; not sent when the session ended because the backend did | `agents.native` | ### Limits diff --git a/shared/plugins/reference/domains/agents.md b/shared/plugins/reference/domains/agents.md index 93ee8051..a56c93ac 100644 --- a/shared/plugins/reference/domains/agents.md +++ b/shared/plugins/reference/domains/agents.md @@ -4,7 +4,7 @@ ## 中文 -插件可以把用户自己安装、自己登录的 Agent 命令行工具接进 Lithe。插件只声明这个 CLI 是哪个工具、可以用哪几种形式运行、会话文件放在哪里;Core 启动和回收 CLI 进程,插件后端只在 CLI 自己的协议和 Lithe 的会话事件之间翻译。插件拿不到 CLI 的凭据,启动结果不能带环境变量;只有用户的操作能开始会话、发送提示和回答权限请求。 +插件可以把用户自己安装、自己登录的 Agent 命令行工具接进 Lithe。插件只声明这个 CLI 是哪个工具、可以用哪几种形式运行、会话文件放在哪里;Core 启动和回收 CLI 进程,插件后端只在 CLI 自己的协议和 Lithe 的会话事件之间翻译。插件拿不到 CLI 的凭据,启动结果不能带环境变量;只有用户的操作能开始会话、发送提示、回答权限请求和修改会话设置。 | 项目 | 内容 | | --- | --- | @@ -22,7 +22,7 @@ | 形式 | 谁做什么 | | --- | --- | -| `native` | Core 调用后端函数拿到命令行(只能是 `{executable: {kind: "tool", tool}, arguments}`,不能带环境变量),自己启动 CLI;CLI 的标准输出经 `lithe/host/agents/didOutput` 交给后端,后端用 `lithe/host/agents/report` 报告会话事件,用 `lithe/host/agents/write` 写 CLI 的标准输入 | +| `native` | Core 调用后端函数拿到命令行(只能是 `{executable: {kind: "tool", tool}, arguments}`,不能带环境变量),自己启动 CLI;CLI 的标准输出经 `lithe/host/agents/didOutput` 交给后端,后端用 `lithe/host/agents/report` 报告会话事件,用 `lithe/host/agents/write` 写 CLI 的标准输入;后端报告的 `configOptions`(模型、推理等级、模式)由用户在宿主里切换,经 `lithe/host/agents/didSetConfigOption` 交回后端 | | `terminal` | 宿主在终端里用声明的参数运行 CLI,用的是 CLI 自己的交互界面 | | `acp` | 版本 0 只校验、列入审查和目录,不运行 Agent Client Protocol 客户端;只提供 ACP 的 Agent 应同时声明 `terminal` | | `update` | 用户确认命令行后,用声明的参数运行 CLI 的自更新命令 | @@ -62,7 +62,7 @@ ## English -A plugin can connect an agent command-line tool that the user installed and signed in to themselves. The plugin declares only which tool the CLI is, the forms it can run in, and where it keeps its session files. Core starts and reaps the CLI process; the plugin backend only translates between the CLI's own protocol and Lithe's session events. The plugin never gets the CLI's credentials, and a launch answer cannot carry environment variables. Only the user's actions start a session, send a prompt, or answer a permission request. +A plugin can connect an agent command-line tool that the user installed and signed in to themselves. The plugin declares only which tool the CLI is, the forms it can run in, and where it keeps its session files. Core starts and reaps the CLI process; the plugin backend only translates between the CLI's own protocol and Lithe's session events. The plugin never gets the CLI's credentials, and a launch answer cannot carry environment variables. Only the user's actions start a session, send a prompt, answer a permission request, or change a session setting. | Item | Value | | --- | --- | @@ -80,7 +80,7 @@ A plugin can connect an agent command-line tool that the user installed and sign | Form | Who does what | | --- | --- | -| `native` | Core calls a backend function for the command line (only `{executable: {kind: "tool", tool}, arguments}`, no environment variables) and starts the CLI itself. The CLI's standard output reaches the backend through `lithe/host/agents/didOutput`; the backend reports session events with `lithe/host/agents/report` and writes the CLI's standard input with `lithe/host/agents/write` | +| `native` | Core calls a backend function for the command line (only `{executable: {kind: "tool", tool}, arguments}`, no environment variables) and starts the CLI itself. The CLI's standard output reaches the backend through `lithe/host/agents/didOutput`; the backend reports session events with `lithe/host/agents/report` and writes the CLI's standard input with `lithe/host/agents/write`. The user switches the `configOptions` the backend reports (model, reasoning level, mode) in the host, and the choice reaches the backend through `lithe/host/agents/didSetConfigOption` | | `terminal` | The host runs the CLI with the declared arguments in a terminal: the CLI's own interactive interface | | `acp` | Version 0 validates it and lists it in the review and the catalog, but runs no Agent Client Protocol client; an agent that offers only ACP should also declare `terminal` | | `update` | After the user confirms the command line, runs the CLI's self-update command with the declared arguments | diff --git a/shared/plugins/reference/protocol-changelog.md b/shared/plugins/reference/protocol-changelog.md index b3b67b62..e27e62de 100644 --- a/shared/plugins/reference/protocol-changelog.md +++ b/shared/plugins/reference/protocol-changelog.md @@ -14,7 +14,7 @@ ## 待合入 -- [#219](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/219)(待合入),[@xiaoyumuxi](https://github.com/xiaoyumuxi),`agents` 0 内补充(API-45):宿主命令 `agentSessions.list` 新增 `cwdUnder`(最多 64 个目录,会话的 `cwd` 是其中之一或在它下面才保留,末尾的 `/`、`\` 不影响匹配,没有 `cwd` 的会话不在任何目录下)、`order`(`updated` 最近活动在前,默认;`started` 最近开始在前)和 `counts`;`counts: true` 时回答多出 `total`(不受 `offset`、`limit` 影响)、`groups`(每个目录 `{cwd?, count, updatedAtMs?}`,最近活动在前,最多 500 组)和 `groupsTruncated`。每个会话多出 `messageCount`(插件后端在会话自己文件里报的可搜索片段数,子代理文件不计)、`lastMessageRange`(最后一个片段的范围,用 `agentSessions.read` 读出该条消息,Core 不缓存正文)、`subagentCount`(调用里不同 `threadID` 的个数)和 `model`(最近一次主线程调用的 `model`,没有时用 `requestedModel`;全部调用都带 `threadID` 时取最近一次调用的)。旧 Core 以未知字段拒绝三个新参数,也不回答四个新字段,宿主应显示不带它们的列表。没有新增宿主方法、通知、错误码或能力版本。 +- [#220](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/220)(待合入),[@xiaoyumuxi](https://github.com/xiaoyumuxi),`agents` 0 内补充(API-45):原生会话可以报告用户可改的会话设置,用户在宿主里切换模型、推理等级或模式。会话事件新增 `configOptions`(对应 ACP 的 session config options,ACP 的 `thought_level` 写作 `thoughtLevel`):最多 16 个 `{id, name, description?, category?, currentValue, options}`,`category` 为 `model`、`thoughtLevel`、`mode` 之一,`options` 为 1–128 个 `{value, name, description?}`;设置 ID 唯一、同一设置的值唯一、`currentValue` 必须在 `options` 里,`thoughtLevel` 的值从低到高排列;每次报告替换上一次,空列表撤回全部设置;这个事件不属于任何回合,随时可以报告。新增宿主命令 `agents.setConfigOption {session, option, value}` → `{}`:只接受用户发起的请求(`agents.userActionRequired`),回合进行中也可以调用;设置或值不在后端最近一次报告里时分别拒绝为新错误码 `agents.unknownConfigOption`、`agents.unknownConfigValue`,后端没有接收时为 `agents.backendUnavailable`。`litheFunctions` 0 内新增通知 `agents/didSetConfigOption {session, option, value}`(`agents.native`),后端在 CLI 能接受时应用,再报告一次 `configOptions`;CLI 拒绝时报告未改变的设置和一条 `notice`。fixture `agents/native-session.json` 补充这条通知和一个 `configOptions` 报告,四种官方 SDK 新增会话处理器方法(Rust `set_config_option`、Go `SetConfigOption`、Node `setConfigOption`、Java `setConfigOption`,默认什么都不做),Go SDK 的宿主通知改为统一走 Agent 通知分发。旧 Core 以未知事件拒绝 `configOptions` 报告(`-32602`),插件在旧宿主上应忽略这次拒绝、照常运行。没有新增能力版本、协议版本或宿主方法。 - [#207](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/207)(待合入),[@1lck](https://github.com/1lck),`debugAdapters` 0(API-30)增加可选 `launch.executableSetting`。命令型适配器可读取用户全局文件路径,留空沿用原命令查找;旧宿主会拒绝包含该声明的清单。无新增方法、通知或能力版本。 @@ -224,6 +224,7 @@ | API-40 | `workspace/getHostPaths` | 0 | 待合入 | [#151](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/151) | | API-45 | `agents/write` | 0 | 2026-11-27 | [#216](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/216) | | API-45 | `agents/report` | 0 | 2026-11-27 | [#216](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/216) | +| API-45 | `agents/report` | 0(事件新增 `configOptions`) | 待合入 | [#220](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/220) | | API-45 | `agents/usage` | 0 | 2026-11-27 | [#216](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/216) | | API-45 | `agents/usage` | 0(回答新增 `speeds`) | 2026-11-28 | [#217](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/217) | | API-45 | `agents/didStart`(通知) | 0 | 2026-11-27 | [#216](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/216) | @@ -231,6 +232,7 @@ | API-45 | `agents/didPrompt`(通知) | 0 | 2026-11-27 | [#216](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/216) | | API-45 | `agents/didCancel`(通知) | 0 | 2026-11-27 | [#216](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/216) | | API-45 | `agents/didDecidePermission`(通知) | 0 | 2026-11-27 | [#216](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/216) | +| API-45 | `agents/didSetConfigOption`(通知) | 0 | 待合入 | [#220](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/220) | | API-45 | `agents/didExit`(通知) | 0 | 2026-11-27 | [#216](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/216) | | — | `keymapImport/listInputs` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | — | `keymapImport/readChunk` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | @@ -241,6 +243,7 @@ | PR | 修改人 | API 编号 | 协议 / 能力 | 改动 | | --- | --- | --- | --- | --- | +| [#219](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/219) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-45 | `agents` 0 | 宿主命令 `agentSessions.list` 新增 `cwdUnder`(最多 64 个目录,会话的 `cwd` 是其中之一或在它下面才保留,末尾的 `/`、`\` 不影响匹配,没有 `cwd` 的会话不在任何目录下)、`order`(`updated` 最近活动在前,默认;`started` 最近开始在前)和 `counts`;`counts: true` 时回答多出 `total`(不受 `offset`、`limit` 影响)、`groups`(每个目录 `{cwd?, count, updatedAtMs?}`,最近活动在前,最多 500 组)和 `groupsTruncated`。每个会话多出 `messageCount`(插件后端在会话自己文件里报的可搜索片段数,子代理文件不计)、`lastMessageRange`(最后一个片段的范围,用 `agentSessions.read` 读出该条消息,Core 不缓存正文)、`subagentCount`(调用里不同 `threadID` 的个数)和 `model`(最近一次主线程调用的 `model`,没有时用 `requestedModel`;全部调用都带 `threadID` 时取最近一次调用的)。旧 Core 以未知字段拒绝三个新参数,也不回答四个新字段,宿主应显示不带它们的列表。没有新增宿主方法、通知、错误码或能力版本。 | | [#217](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/217) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-45、API-23 | `agents` 0 / `commandInstallers` 0 | `agents/usage` 与 `agentSessions.stats` 的回答新增 `speeds`,按模型列出同一批调用首个令牌之后输出速度的中位数(`{model, calls, medianTokensPerSecond, lowerBound}`,最快的在前),四种官方 SDK 的说明同步。旧宿主不返回该字段,插件应按缺失处理。契约同时写明 `scan` 的一个既有行为:之后的扫描可以用同一个 `key` 再报一次调用(`range` 在它自己的块里),后报的替换先报的,所以到一轮结束才知道计时的后端可以那时补上 `firstTokenMs` 和 `durationMs`;自 #199 起的 Core 都这样处理。同一 PR 里,会话记录的读取支持分页:`agentSessions.list` 可按 `sessionID` 查找、每个会话带 `readBytes`,`agentSessions.read` 回答 `end`(下一页的起点);读取范围在行中间结束时,Core 只把完整的行交给插件后端的 `read`,并说明后端 `messages` 回答整体不能超过 1 MiB 的函数结果上限。旧 Core 不认 `sessionID`、不回答 `readBytes` 和 `end`,并可能把被截断的行交给后端,后端应跳过不是完整 JSON 的行。同一 PR 里,`commandInstallers` 0 内补充(API-23):[命令安装](../contract/v1/README.md#command-installers)也服务 Agent 的命令行工具:安装声明的 `commands` 可以由本插件某个 Agent 的 `tool` 所指工具定义的 `commands` 提供,`plugins.commandInstallers.requirements` 在 `systemCommand` 启动之后按声明顺序列出 `kind: "agent"`、`id` 为 Agent ID 的使用方;宿主把插件的受管命令目录和记录的默认目录也用于解析 Agent 工具的 `kind: "command"` 候选(先查 `PATH`)。旧 Core 以 `plugin.manifest.invalid`(`commandInstallers[].commands[]`)拒绝只有 Agent 工具用到的安装声明;需要它的插件同时要求 `agents` 0。同一 PR 里,[IDE 连接](../../../rust/contracts/ide-api/v1.md#agent-sessions)新增两个只读 MCP 工具 `lithe_sessions_search`、`lithe_sessions_read`(API-45),让 MCP 客户端搜索和分页读取用户同意读取的 Agent 会话;宿主只在用户打开 IDE 连接、打开“允许 MCP 客户端搜索本地会话”并同意读取至少一个 Agent 的会话时声明它们,没有声明工具清单的宿主不提供这两个工具。它们是 IDE 连接的工具,不是插件宿主方法。没有新增宿主方法、通知或错误码。 | ### 2026-11-27 diff --git a/shared/plugins/sdk/go/README.md b/shared/plugins/sdk/go/README.md index 12c6159d..777c5c30 100644 --- a/shared/plugins/sdk/go/README.md +++ b/shared/plugins/sdk/go/README.md @@ -617,13 +617,14 @@ func main() { `AgentSessionStart` carries `Session`, `AgentID`, `Cwd` and `Resume` (the CLI's own session ID when the user resumes one, or nil). Embed -`AgentSessionBase` for empty `Cancel` and `Exited`. `Host().Agents()` offers +`AgentSessionBase` for empty `Cancel`, `SetConfigOption` and `Exited`. `Host().Agents()` offers the same `Write` and `Report` for any session ID, and `Usage(params)` for usage totals. - Each session has its own worker. `didStart` makes the session's handler; - the session's `didOutput`, `didPrompt`, `didCancel`, `didDecidePermission` - and `didExit` then reach it one at a time, in the order Core sent them, so + the session's `didOutput`, `didPrompt`, `didCancel`, `didDecidePermission`, + `didSetConfigOption` and `didExit` then reach it one at a time, in the order + Core sent them, so a handler may wait for host requests. Other sessions keep running. - When making the handler fails, or a prompt fails, the SDK reports `turnEnded` with reason `failed` for the turn and logs the failure. Other diff --git a/shared/plugins/sdk/go/lithe/agents.go b/shared/plugins/sdk/go/lithe/agents.go index 4994ffdf..5512e755 100644 --- a/shared/plugins/sdk/go/lithe/agents.go +++ b/shared/plugins/sdk/go/lithe/agents.go @@ -4,8 +4,9 @@ package lithe // // Core starts an agent's CLI and relays it through the plugin backend: the // CLI's standard output arrives as lithe/host/agents/didOutput, the user's -// prompts, cancellations and permission decisions as didPrompt, didCancel and -// didDecidePermission, and the backend answers with lithe/host/agents/write +// prompts, cancellations, permission decisions and setting changes as +// didPrompt, didCancel, didDecidePermission and didSetConfigOption, and the +// backend answers with lithe/host/agents/write // (the CLI's standard input) and lithe/host/agents/report (session events). A // translation is only right when it sees the CLI's lines in order, so the SDK // gives every session one goroutine that runs its handler's methods one at a @@ -26,13 +27,14 @@ const ( methodAgentsDidPrompt = "lithe/host/agents/didPrompt" methodAgentsDidCancel = "lithe/host/agents/didCancel" methodAgentsDidDecide = "lithe/host/agents/didDecidePermission" + methodAgentsDidConfig = "lithe/host/agents/didSetConfigOption" methodAgentsDidExit = "lithe/host/agents/didExit" ) func isAgentNotification(method string) bool { switch method { case methodAgentsDidStart, methodAgentsDidOutput, methodAgentsDidPrompt, - methodAgentsDidCancel, methodAgentsDidDecide, methodAgentsDidExit: + methodAgentsDidCancel, methodAgentsDidDecide, methodAgentsDidConfig, methodAgentsDidExit: return true } return false @@ -68,16 +70,24 @@ type AgentSession interface { // DecidePermission says the user answered permission request permission // with option. DecidePermission(turn uint64, permission, option string) error + // SetConfigOption says the user picked value for the session setting + // option, one the backend reported in a configOptions event. Apply it when + // the CLI can take it and report the settings again. + SetConfigOption(option, value string) error // Exited says the CLI ended; the session gets no further calls. Exited(exitCode *int64) } -// AgentSessionBase answers Cancel and Exited without doing anything. +// AgentSessionBase answers Cancel, SetConfigOption and Exited without doing +// anything. type AgentSessionBase struct{} // Cancel does nothing. func (AgentSessionBase) Cancel(uint64) error { return nil } +// SetConfigOption does nothing. +func (AgentSessionBase) SetConfigOption(string, string) error { return nil } + // Exited does nothing. func (AgentSessionBase) Exited(*int64) {} @@ -160,6 +170,7 @@ type agentNotice struct { text string permission string option string + value string exitCode *int64 } @@ -261,6 +272,7 @@ func (b *Backend) routeAgentNotification(method string, params map[string]any) { notice.text, _ = params["text"].(string) notice.permission, _ = params["permission"].(string) notice.option, _ = params["option"].(string) + notice.value, _ = params["value"].(string) if lines, ok := params["lines"].([]any); ok { for _, line := range lines { text, _ := line.(string) @@ -360,6 +372,8 @@ func deliverAgentNotice(handler AgentSession, notice agentNotice) (err error) { return handler.Cancel(notice.turn) case methodAgentsDidDecide: return handler.DecidePermission(notice.turn, notice.permission, notice.option) + case methodAgentsDidConfig: + return handler.SetConfigOption(notice.option, notice.value) default: handler.Exited(notice.exitCode) return nil diff --git a/shared/plugins/sdk/go/lithe/agents_test.go b/shared/plugins/sdk/go/lithe/agents_test.go index 0ba668f2..f21620bb 100644 --- a/shared/plugins/sdk/go/lithe/agents_test.go +++ b/shared/plugins/sdk/go/lithe/agents_test.go @@ -80,6 +80,11 @@ func (r *recorder) DecidePermission(turn uint64, permission, option string) erro return nil } +func (r *recorder) SetConfigOption(option, value string) error { + r.record("setConfigOption", option, value) + return nil +} + func (r *recorder) Exited(exitCode *int64) { r.record("exited", exitCode) if r.session == "agent-2" { diff --git a/shared/plugins/sdk/go/lithe/backend.go b/shared/plugins/sdk/go/lithe/backend.go index 04000a6d..20d797ed 100644 --- a/shared/plugins/sdk/go/lithe/backend.go +++ b/shared/plugins/sdk/go/lithe/backend.go @@ -522,12 +522,13 @@ func (b *Backend) hostNotification(method string, params any) { if !s.functionsNegotiated() || !ok { return } + if isAgentNotification(method) { + b.routeAgentNotification(method, object) + return + } switch method { case methodNotify: s.deliver(object) - case methodAgentsDidStart, methodAgentsDidOutput, methodAgentsDidPrompt, - methodAgentsDidCancel, methodAgentsDidDecide, methodAgentsDidExit: - b.routeAgentNotification(method, object) case methodCommandRan: commandID, _ := object["commandID"].(string) handler := b.commands[commandID] diff --git a/shared/plugins/sdk/java/README.md b/shared/plugins/sdk/java/README.md index 98686e29..8052d2b8 100644 --- a/shared/plugins/sdk/java/README.md +++ b/shared/plugins/sdk/java/README.md @@ -585,13 +585,14 @@ backend.onAgentSessions((start, session) -> new AgentSession() { `map` stands for a helper that builds a `LinkedHashMap` from key-value pairs. `AgentSessionStart` carries `session()`, `agentId()`, `cwd()` and `resume()` -(the CLI's own session ID when the user resumes one, or null). `cancel` and -`exited` have empty defaults. `host().agents()` offers the same `write` and +(the CLI's own session ID when the user resumes one, or null). `cancel`, +`setConfigOption` and `exited` have empty defaults. `host().agents()` offers the same `write` and `report` for any session ID, and `usage(params)` for usage totals. - Each session has its own worker. `didStart` makes the session's handler; - the session's `didOutput`, `didPrompt`, `didCancel`, `didDecidePermission` - and `didExit` then reach it one at a time, in the order Core sent them, so + the session's `didOutput`, `didPrompt`, `didCancel`, `didDecidePermission`, + `didSetConfigOption` and `didExit` then reach it one at a time, in the order + Core sent them, so a handler may wait for host requests. Other sessions keep running. - When making the handler fails, or a prompt fails, the SDK reports `turnEnded` with reason `failed` for the turn and logs the failure. Other diff --git a/shared/plugins/sdk/java/plugin-sdk/src/main/java/io/github/litheidea/plugin/sdk/AgentSession.java b/shared/plugins/sdk/java/plugin-sdk/src/main/java/io/github/litheidea/plugin/sdk/AgentSession.java index e55bade9..720252ef 100644 --- a/shared/plugins/sdk/java/plugin-sdk/src/main/java/io/github/litheidea/plugin/sdk/AgentSession.java +++ b/shared/plugins/sdk/java/plugin-sdk/src/main/java/io/github/litheidea/plugin/sdk/AgentSession.java @@ -24,6 +24,14 @@ default void cancel(long turn) throws Exception {} /** The user answered permission request {@code permission} with {@code option}. */ void decidePermission(long turn, String permission, String option) throws Exception; + /** + * The user picked {@code value} for the session setting {@code option}, + * one the backend reported in a {@code configOptions} event. Apply it when + * the CLI can take it and report the settings again. Does nothing unless + * overridden. + */ + default void setConfigOption(String option, String value) throws Exception {} + /** * The CLI ended, with its exit code when it had one; the session gets no * further calls. Does nothing unless overridden. diff --git a/shared/plugins/sdk/java/plugin-sdk/src/main/java/io/github/litheidea/plugin/sdk/AgentSessions.java b/shared/plugins/sdk/java/plugin-sdk/src/main/java/io/github/litheidea/plugin/sdk/AgentSessions.java index b24993f6..b51b50dd 100644 --- a/shared/plugins/sdk/java/plugin-sdk/src/main/java/io/github/litheidea/plugin/sdk/AgentSessions.java +++ b/shared/plugins/sdk/java/plugin-sdk/src/main/java/io/github/litheidea/plugin/sdk/AgentSessions.java @@ -15,9 +15,10 @@ /** * Native agent sessions (plan API-45). Core starts an agent's CLI and relays * it through the plugin backend: the CLI's standard output arrives as - * {@code lithe/host/agents/didOutput}, the user's prompts, cancellations and - * permission decisions as {@code didPrompt}, {@code didCancel} and - * {@code didDecidePermission}, and the backend answers with + * {@code lithe/host/agents/didOutput}, the user's prompts, cancellations, + * permission decisions and setting changes as {@code didPrompt}, + * {@code didCancel}, {@code didDecidePermission} and + * {@code didSetConfigOption}, and the backend answers with * {@code lithe/host/agents/write} (the CLI's standard input) and * {@code lithe/host/agents/report} (session events). A translation is only * right when it sees the CLI's lines in order, so every session gets one @@ -28,7 +29,7 @@ final class AgentSessions { static final Set NOTIFICATIONS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( Protocol.HOST_AGENTS_DID_START, Protocol.HOST_AGENTS_DID_OUTPUT, Protocol.HOST_AGENTS_DID_PROMPT, Protocol.HOST_AGENTS_DID_CANCEL, Protocol.HOST_AGENTS_DID_DECIDE_PERMISSION, - Protocol.HOST_AGENTS_DID_EXIT))); + Protocol.HOST_AGENTS_DID_SET_CONFIG_OPTION, Protocol.HOST_AGENTS_DID_EXIT))); private static final String OPERATION = "notification"; private final Backend backend; @@ -153,6 +154,9 @@ private static void deliver(AgentSession handler, Notice notice) throws Exceptio case Protocol.HOST_AGENTS_DID_DECIDE_PERMISSION: handler.decidePermission(notice.turn, notice.permission, notice.option); return; + case Protocol.HOST_AGENTS_DID_SET_CONFIG_OPTION: + handler.setConfigOption(notice.option, notice.value); + return; default: handler.exited(notice.exitCode); } @@ -193,7 +197,7 @@ private static Notice notice(String method, Map params) { return new Notice(method, Collections.unmodifiableList(lines), turn instanceof Long && (Long) turn >= 0 ? (Long) turn : 0L, string(params, "text"), string(params, "permission"), string(params, "option"), - exit instanceof Long ? (Long) exit : null); + string(params, "value"), exit instanceof Long ? (Long) exit : null); } private static String string(Map params, String key) { @@ -203,7 +207,7 @@ private static String string(Map params, String key) { /** One notification for a session's worker. */ private static final class Notice { - static final Notice CLOSED = new Notice("", Collections.emptyList(), 0, "", "", "", null); + static final Notice CLOSED = new Notice("", Collections.emptyList(), 0, "", "", "", "", null); final String method; final List lines; @@ -211,16 +215,18 @@ private static final class Notice { final String text; final String permission; final String option; + final String value; final Long exitCode; Notice(String method, List lines, long turn, String text, String permission, String option, - Long exitCode) { + String value, Long exitCode) { this.method = method; this.lines = lines; this.turn = turn; this.text = text; this.permission = permission; this.option = option; + this.value = value; this.exitCode = exitCode; } } diff --git a/shared/plugins/sdk/java/plugin-sdk/src/main/java/io/github/litheidea/plugin/sdk/Backend.java b/shared/plugins/sdk/java/plugin-sdk/src/main/java/io/github/litheidea/plugin/sdk/Backend.java index 0908cef2..4e07cbd9 100644 --- a/shared/plugins/sdk/java/plugin-sdk/src/main/java/io/github/litheidea/plugin/sdk/Backend.java +++ b/shared/plugins/sdk/java/plugin-sdk/src/main/java/io/github/litheidea/plugin/sdk/Backend.java @@ -482,8 +482,9 @@ public Backend onHostNotification(String method, NotificationHandler handler) { * For each {@code lithe/host/agents/didStart}, {@code starter} makes the * session's {@link AgentSession} on a worker of the session's own, which * then gets the session's {@code didOutput}, {@code didPrompt}, - * {@code didCancel}, {@code didDecidePermission} and {@code didExit} one - * at a time, in the order Core sent them. When the start fails, or a + * {@code didCancel}, {@code didDecidePermission}, + * {@code didSetConfigOption} and {@code didExit} one at a time, in the + * order Core sent them. When the start fails, or a * prompt fails, the SDK reports {@code turnEnded} with reason * {@code failed} for the turn. A later registration replaces the earlier * one. diff --git a/shared/plugins/sdk/java/plugin-sdk/src/main/java/io/github/litheidea/plugin/sdk/Protocol.java b/shared/plugins/sdk/java/plugin-sdk/src/main/java/io/github/litheidea/plugin/sdk/Protocol.java index 242964d7..c8cf7032 100644 --- a/shared/plugins/sdk/java/plugin-sdk/src/main/java/io/github/litheidea/plugin/sdk/Protocol.java +++ b/shared/plugins/sdk/java/plugin-sdk/src/main/java/io/github/litheidea/plugin/sdk/Protocol.java @@ -133,6 +133,7 @@ public final class Protocol { public static final String HOST_AGENTS_DID_PROMPT = "lithe/host/agents/didPrompt"; public static final String HOST_AGENTS_DID_CANCEL = "lithe/host/agents/didCancel"; public static final String HOST_AGENTS_DID_DECIDE_PERMISSION = "lithe/host/agents/didDecidePermission"; + public static final String HOST_AGENTS_DID_SET_CONFIG_OPTION = "lithe/host/agents/didSetConfigOption"; public static final String HOST_AGENTS_DID_EXIT = "lithe/host/agents/didExit"; /** JSON-RPC and LSP error codes the SDK answers with. */ diff --git a/shared/plugins/sdk/java/plugin-sdk/src/test/java/io/github/litheidea/plugin/sdk/AgentsTest.java b/shared/plugins/sdk/java/plugin-sdk/src/test/java/io/github/litheidea/plugin/sdk/AgentsTest.java index b32a2721..ab17d139 100644 --- a/shared/plugins/sdk/java/plugin-sdk/src/test/java/io/github/litheidea/plugin/sdk/AgentsTest.java +++ b/shared/plugins/sdk/java/plugin-sdk/src/test/java/io/github/litheidea/plugin/sdk/AgentsTest.java @@ -102,6 +102,11 @@ public void decidePermission(long turn, String permission, String option) { record(id, "decidePermission", turn, permission, option); } + @Override + public void setConfigOption(String option, String value) { + record(id, "setConfigOption", option, value); + } + @Override public void exited(Long exitCode) { record(id, "exited", exitCode); diff --git a/shared/plugins/sdk/node/README.md b/shared/plugins/sdk/node/README.md index fa010501..629667dc 100644 --- a/shared/plugins/sdk/node/README.md +++ b/shared/plugins/sdk/node/README.md @@ -598,13 +598,15 @@ backend.onAgentSessions((start, session) => { ``` `start` carries `session`, `agentID`, `cwd` and `resume` (the CLI's own -session ID when the user resumes one). `cancel` and `exited` are optional. +session ID when the user resumes one). `cancel`, `setConfigOption` and +`exited` are optional. `backend.host.agents` offers the same `write` and `report` for any session ID, and `usage(params)` for usage totals. - Each session has its own worker. `didStart` makes the session's handler; - the session's `didOutput`, `didPrompt`, `didCancel`, `didDecidePermission` - and `didExit` then reach it one at a time, in the order Core sent them, so + the session's `didOutput`, `didPrompt`, `didCancel`, `didDecidePermission`, + `didSetConfigOption` and `didExit` then reach it one at a time, in the order + Core sent them, so a handler may wait for host requests. Other sessions keep running. - When making the handler fails, or a prompt fails, the SDK reports `turnEnded` with reason `failed` for the turn and logs the failure. Other diff --git a/shared/plugins/sdk/node/src/backend.mjs b/shared/plugins/sdk/node/src/backend.mjs index 7b70e065..15a1d9f0 100644 --- a/shared/plugins/sdk/node/src/backend.mjs +++ b/shared/plugins/sdk/node/src/backend.mjs @@ -310,11 +310,12 @@ class Backend { * Translates the native sessions of the plugin's agents (plan API-45). For * each `lithe/host/agents/didStart`, `start({ session, agentID, cwd, * resume }, handle)` makes the session's handler, which then gets the - * session's `didOutput`, `didPrompt`, `didCancel`, `didDecidePermission` - * and `didExit` one at a time, in the order Core sent them: each call - * waits for the promise of the one before. The handler has + * session's `didOutput`, `didPrompt`, `didCancel`, `didDecidePermission`, + * `didSetConfigOption` and `didExit` one at a time, in the order Core sent + * them: each call waits for the promise of the one before. The handler has * `output(lines)`, `prompt(turn, text)` and `decidePermission(turn, - * permission, option)`, and may have `cancel(turn)` and `exited(exitCode)`. + * permission, option)`, and may have `cancel(turn)`, + * `setConfigOption(option, value)` and `exited(exitCode)`. * `handle` has `id`, `host`, `write(lines)` and `report(events)`. When * `start` fails, or a prompt fails, the SDK reports `turnEnded` with reason * `failed` for the turn. A later registration replaces the earlier one. @@ -1130,6 +1131,8 @@ async function deliverAgentNotification(handler, method, params, turn) { return handler.cancel?.(turn); case AGENT_NOTIFICATIONS.didDecidePermission: return handler.decidePermission(turn, text(params.permission), text(params.option)); + case AGENT_NOTIFICATIONS.didSetConfigOption: + return handler.setConfigOption?.(text(params.option), text(params.value)); default: return handler.exited?.(Number.isSafeInteger(params.exitCode) ? params.exitCode : null); } diff --git a/shared/plugins/sdk/node/src/index.d.ts b/shared/plugins/sdk/node/src/index.d.ts index e83f6ecf..1583d272 100644 --- a/shared/plugins/sdk/node/src/index.d.ts +++ b/shared/plugins/sdk/node/src/index.d.ts @@ -945,6 +945,12 @@ export interface AgentSession { cancel?(turn: number): unknown; /** The user answered permission request `permission` with `option`. */ decidePermission(turn: number, permission: string, option: string): unknown; + /** + * The user picked `value` for the session setting `option`, one the backend + * reported in a `configOptions` event. Apply it when the CLI can take it and + * report the settings again. + */ + setConfigOption?(option: string, value: string): unknown; /** The CLI ended; the session gets no further calls. */ exited?(exitCode: number | null): unknown; } diff --git a/shared/plugins/sdk/node/src/protocol.mjs b/shared/plugins/sdk/node/src/protocol.mjs index d2200936..760e4d55 100644 --- a/shared/plugins/sdk/node/src/protocol.mjs +++ b/shared/plugins/sdk/node/src/protocol.mjs @@ -126,6 +126,7 @@ export const AGENT_NOTIFICATIONS = Object.freeze({ didPrompt: 'lithe/host/agents/didPrompt', didCancel: 'lithe/host/agents/didCancel', didDecidePermission: 'lithe/host/agents/didDecidePermission', + didSetConfigOption: 'lithe/host/agents/didSetConfigOption', didExit: 'lithe/host/agents/didExit', }); diff --git a/shared/plugins/sdk/node/test/agents.test.mjs b/shared/plugins/sdk/node/test/agents.test.mjs index bb36e03a..8b24ac71 100644 --- a/shared/plugins/sdk/node/test/agents.test.mjs +++ b/shared/plugins/sdk/node/test/agents.test.mjs @@ -47,6 +47,9 @@ function recordingBackend() { decidePermission(turn, permission, option) { record('decidePermission', turn, permission, option); }, + setConfigOption(option, value) { + record('setConfigOption', option, value); + }, exited(exitCode) { record('exited', exitCode); if (start.session === 'agent-2') otherExited.open(); diff --git a/shared/plugins/sdk/rust/README.md b/shared/plugins/sdk/rust/README.md index 22c5bceb..bf1dd464 100644 --- a/shared/plugins/sdk/rust/README.md +++ b/shared/plugins/sdk/rust/README.md @@ -709,13 +709,14 @@ fn main() { ``` `AgentSessionStart` carries `session`, `agent_id`, `cwd` and `resume` (the -CLI's own session ID when the user resumes one). `cancel` and `exited` have -empty defaults. `handle.host().agents()` offers the same `write` and `report` +CLI's own session ID when the user resumes one). `cancel`, +`set_config_option` and `exited` have empty defaults. `handle.host().agents()` offers the same `write` and `report` for any session ID, and `usage(params)` for usage totals. - Each session has its own worker. `didStart` makes the session's handler; - the session's `didOutput`, `didPrompt`, `didCancel`, `didDecidePermission` - and `didExit` then reach it one at a time, in the order Core sent them, so + the session's `didOutput`, `didPrompt`, `didCancel`, `didDecidePermission`, + `didSetConfigOption` and `didExit` then reach it one at a time, in the order + Core sent them, so a handler may wait for host requests. Other sessions keep running. - When making the handler fails, or a prompt fails, the SDK reports `turnEnded` with reason `failed` for the turn and logs the failure. Other diff --git a/shared/plugins/sdk/rust/plugin-sdk/src/agents.rs b/shared/plugins/sdk/rust/plugin-sdk/src/agents.rs index 6670d694..9ecf1920 100644 --- a/shared/plugins/sdk/rust/plugin-sdk/src/agents.rs +++ b/shared/plugins/sdk/rust/plugin-sdk/src/agents.rs @@ -2,8 +2,9 @@ //! //! Core starts an agent's CLI and relays it through the plugin backend: the //! CLI's standard output arrives as `lithe/host/agents/didOutput`, the user's -//! prompts, cancellations and permission decisions as `didPrompt`, -//! `didCancel` and `didDecidePermission`, and the backend answers with +//! prompts, cancellations, permission decisions and setting changes as +//! `didPrompt`, `didCancel`, `didDecidePermission` and `didSetConfigOption`, +//! and the backend answers with //! `lithe/host/agents/write` (the CLI's standard input) and //! `lithe/host/agents/report` (session events). A translation is only right //! when it sees the CLI's lines in order, so the SDK gives every session one @@ -57,6 +58,12 @@ pub trait AgentSession: Send { permission: String, option: String, ) -> Result<(), FunctionError>; + /// The user picked `value` for the session setting `option`, one the + /// backend reported in a `configOptions` event. Apply it when the CLI can + /// take it and report the settings again. Does nothing unless overridden. + fn set_config_option(&mut self, _option: String, _value: String) -> Result<(), FunctionError> { + Ok(()) + } /// The CLI ended; the session gets no further calls. fn exited(&mut self, _exit_code: Option) {} } @@ -145,6 +152,7 @@ enum Notice { Prompt(u64, String), Cancel(u64), Decide(u64, String, String), + Configure(String, String), Exit(Option), } @@ -163,6 +171,7 @@ pub(crate) fn is_agent_notification(method: &str) -> bool { methods::AGENTS_DID_PROMPT, methods::AGENTS_DID_CANCEL, methods::AGENTS_DID_DECIDE_PERMISSION, + methods::AGENTS_DID_SET_CONFIG_OPTION, methods::AGENTS_DID_EXIT, ] .contains(&method) @@ -221,6 +230,9 @@ impl AgentWorkers { text(¶ms["permission"]), text(¶ms["option"]), ), + methods::AGENTS_DID_SET_CONFIG_OPTION => { + Notice::Configure(text(¶ms["option"]), text(¶ms["value"])) + } _ => Notice::Exit(params["exitCode"].as_i64()), }; let exit = matches!(notice, Notice::Exit(_)); @@ -306,6 +318,7 @@ fn deliver(handler: &mut dyn AgentSession, notice: Notice) -> Result<(), Functio Notice::Decide(turn, permission, option) => { handler.decide_permission(turn, permission, option) } + Notice::Configure(option, value) => handler.set_config_option(option, value), Notice::Exit(code) => { handler.exited(code); Ok(()) diff --git a/shared/plugins/sdk/rust/plugin-sdk/src/backend.rs b/shared/plugins/sdk/rust/plugin-sdk/src/backend.rs index 89a6fa11..0bd740a4 100644 --- a/shared/plugins/sdk/rust/plugin-sdk/src/backend.rs +++ b/shared/plugins/sdk/rust/plugin-sdk/src/backend.rs @@ -487,7 +487,8 @@ impl Backend { /// For each `lithe/host/agents/didStart`, `start` makes the session's /// [`AgentSession`] on a thread of the session's own, which then gets the /// session's `didOutput`, `didPrompt`, `didCancel`, - /// `didDecidePermission` and `didExit` one at a time, in the order Core + /// `didDecidePermission`, `didSetConfigOption` and `didExit` one at a + /// time, in the order Core /// sent them. When `start` fails, or a prompt fails, the SDK reports /// `turnEnded` with reason `failed` for the turn. A later registration /// replaces the earlier one. diff --git a/shared/plugins/sdk/rust/plugin-sdk/src/protocol.rs b/shared/plugins/sdk/rust/plugin-sdk/src/protocol.rs index db182c9a..f887012a 100644 --- a/shared/plugins/sdk/rust/plugin-sdk/src/protocol.rs +++ b/shared/plugins/sdk/rust/plugin-sdk/src/protocol.rs @@ -113,6 +113,7 @@ pub(crate) mod methods { pub const AGENTS_DID_PROMPT: &str = "lithe/host/agents/didPrompt"; pub const AGENTS_DID_CANCEL: &str = "lithe/host/agents/didCancel"; pub const AGENTS_DID_DECIDE_PERMISSION: &str = "lithe/host/agents/didDecidePermission"; + pub const AGENTS_DID_SET_CONFIG_OPTION: &str = "lithe/host/agents/didSetConfigOption"; pub const AGENTS_DID_EXIT: &str = "lithe/host/agents/didExit"; pub const FUNCTIONS_INVOKE: &str = "lithe/host/functions/invoke"; pub const BUILD_MODEL: &str = "lithe/build/model"; diff --git a/shared/plugins/sdk/rust/plugin-sdk/tests/agents.rs b/shared/plugins/sdk/rust/plugin-sdk/tests/agents.rs index bc7fc86a..ba222521 100644 --- a/shared/plugins/sdk/rust/plugin-sdk/tests/agents.rs +++ b/shared/plugins/sdk/rust/plugin-sdk/tests/agents.rs @@ -90,6 +90,11 @@ impl AgentSession for Recorder { Ok(()) } + fn set_config_option(&mut self, option: String, value: String) -> Result<(), FunctionError> { + self.record(json!(["setConfigOption", option, value])); + Ok(()) + } + fn exited(&mut self, exit_code: Option) { self.record(json!(["exited", exit_code])); if self.session == "agent-2" {