A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
[RSI, bug] Fix: gate the bundled websearch skill on its Serper credential (#3677)
Seth Karten75ec606135c9
diff --git a/crates/pa-cli/src/mcp_login.rs b/crates/pa-cli/src/mcp_login.rsindex 9c18c1064b..1fe6f95370 100644--- a/crates/pa-cli/src/mcp_login.rs+++ b/crates/pa-cli/src/mcp_login.rs@@ -193,7 +193,14 @@ impl TerminalMcpAuth {if let Some(error) = auth.drain_errors().pop() {return Err(anyhow!(error)).context("could not save the API key");}- Ok(format!("Saved API key for {label}. Web search is ready."))+ // The skill gate follows this credential (unset+ // `bundledSkills.websearch` resolves with the key), but the skill+ // list resolves at session build — the same moment the key reaches+ // the kernel — so the message carries the activation state like the+ // MCP login flow's wording.+ Ok(format!(+ "Saved API key for {label}. Its skill activates in new sessions (/new)."+ ))}fn logout_inner(&self, server: &str) -> Result<String> {@@ -515,7 +522,7 @@ mod tests {.expect("the reply lands");assert_eq!(flow.await.expect("the flow ran")?,- "Saved API key for Serper (web search). Web search is ready."+ "Saved API key for Serper (web search). Its skill activates in new sessions (/new).");// The stored credential is the EXACT contract the websearch runtimediff --git a/crates/pa-core/src/packages/manager.rs b/crates/pa-core/src/packages/manager.rsindex e9806a4f82..5f19d10380 100644--- a/crates/pa-core/src/packages/manager.rs+++ b/crates/pa-core/src/packages/manager.rs@@ -170,14 +170,44 @@ impl PackageManager {.unwrap_or(true)}- /// Settings flag: the bundled websearch skill (default true).+ /// Settings flag for the bundled websearch skill: an explicit+ /// `bundledSkills.websearch` value wins; unset rides with the credential+ /// (see [`Self::websearch_enabled_by_credential`]).pub(super) fn bundled_websearch_enabled(&self) -> bool {self.settings.settings().bundled_skills.as_ref().and_then(|bundled| bundled.websearch)- .unwrap_or(true)+ .unwrap_or_else(|| {+ Self::websearch_enabled_by_credential(+ self.agent_dir(),+ std::env::var("SERPER_API_KEY").ok().as_deref(),+ )+ })+ }++ /// The unset-setting default: the skill follows its credential, so it is+ /// enabled exactly when the machine carries a Serper key (the stored+ /// `serper` auth slot or a nonblank ambient `SERPER_API_KEY`) and stays+ /// off on keyless installs. Existing logged-in users keep the skill, and+ /// removing the credential (or overriding with+ /// `bundledSkills.websearch: false`) drops it.+ fn websearch_enabled_by_credential(+ agent_dir: &std::path::Path,+ ambient_api_key: Option<&str>,+ ) -> bool {+ if ambient_api_key.is_some_and(|value| !value.trim().is_empty()) {+ return true;+ }+ let stored = std::fs::read_to_string(agent_dir.join("auth.json"))+ .ok()+ .and_then(|content| {+ crate::auth::parse_storage_data(Some(&content))+ .ok()+ .and_then(|data| data.credential(crate::auth::SERPER_CREDENTIAL_ID))+ });+ stored.is_some()}/// Extra force-exclude patterns for built-in skills.@@ -658,6 +688,51 @@ mod tests {pkg}+ #[test]+ fn websearch_credential_presence_gates_the_skill() {+ let (dir, _manager) = setup();+ let agent_dir = dir.path().join("agent");++ // Keyless install: no stored credential, no ambient key.+ assert!(!PackageManager::websearch_enabled_by_credential(+ &agent_dir, None+ ));++ // A nonblank ambient key is enough; a blank one is not a key.+ assert!(PackageManager::websearch_enabled_by_credential(+ &agent_dir,+ Some("the-key")+ ));+ assert!(!PackageManager::websearch_enabled_by_credential(+ &agent_dir,+ Some(" ")+ ));++ // A stored serper credential rides; another provider's does not.+ std::fs::write(+ agent_dir.join("auth.json"),+ r#"{ "serper": { "type": "api_key", "key": "stored" } }"#,+ )+ .unwrap();+ assert!(PackageManager::websearch_enabled_by_credential(+ &agent_dir, None+ ));+ std::fs::write(+ agent_dir.join("auth.json"),+ r#"{ "other": { "type": "api_key", "key": "x" } }"#,+ )+ .unwrap();+ assert!(!PackageManager::websearch_enabled_by_credential(+ &agent_dir, None+ ));++ // An unparseable store is no credential, not an error.+ std::fs::write(agent_dir.join("auth.json"), "{ not json").unwrap();+ assert!(!PackageManager::websearch_enabled_by_credential(+ &agent_dir, None+ ));+ }+#[test]fn install_and_remove_local_round_trip() {let (dir, mut manager) = setup();diff --git a/crates/pa-core/src/packages/resolve/auto.rs b/crates/pa-core/src/packages/resolve/auto.rsindex 688eb2d48a..dca2db06d5 100644--- a/crates/pa-core/src/packages/resolve/auto.rs+++ b/crates/pa-core/src/packages/resolve/auto.rs@@ -142,7 +142,9 @@ impl PackageManager {}let mut builtin_skill_overrides = user_overrides[0].clone();if !self.bundled_websearch_enabled() {- // Web search stays disabled until explicitly enabled.+ // No Serper credential on the machine (and no explicit+ // settings override): web search stays off so the prompt+ // never advertises a tool that errors on use.builtin_skill_overrides.push("-websearch/SKILL.md".to_string());}builtin_skill_overridesdiff --git a/crates/pa-core/src/packages/resolve/tests.rs b/crates/pa-core/src/packages/resolve/tests.rsindex af67249f54..8ca96ec9cd 100644--- a/crates/pa-core/src/packages/resolve/tests.rs+++ b/crates/pa-core/src/packages/resolve/tests.rs@@ -894,6 +894,7 @@ fn bundled_skills_collect_with_websearch_excluded_until_enabled() {skill_md(&bundled, "websearch", "Search the web");skill_md(&bundled, "other-skill", "Other");let settings_path = fixture.agent_dir.join("settings.json");+ let auth_path = fixture.agent_dir.join("auth.json");std::fs::create_dir_all(&fixture.agent_dir).unwrap();std::fs::write(&settings_path, serde_json::json!({}).to_string()).unwrap();@@ -910,7 +911,13 @@ fn bundled_skills_collect_with_websearch_excluded_until_enabled() {.iter().find(|r| r.path.to_string_lossy().contains("websearch")).expect("websearch collected");- assert!(websearch.enabled, "websearch enabled by default");+ // Unset settings ride with the credential: a keyless machine stays off,+ // a machine carrying an ambient key rides with it.+ let ambient_key = std::env::var("SERPER_API_KEY").is_ok_and(|value| !value.trim().is_empty());+ assert_eq!(+ websearch.enabled, ambient_key,+ "unset settings ride with the serper credential"+ );assert_eq!(websearch.metadata.source, MetadataSource::Builtin);let other = result.skills@@ -918,7 +925,55 @@ fn bundled_skills_collect_with_websearch_excluded_until_enabled() {.find(|r| r.path.to_string_lossy().contains("other-skill")).expect("other collected");assert!(!other.enabled, "extra builtin overrides apply");+ if !ambient_key {+ assert!(+ !result+ .skills+ .iter()+ .filter(|r| r.enabled)+ .any(|r| r.path.to_string_lossy().contains("websearch")),+ "websearch is absent from the enabled skill list on a keyless install"+ );++ // A stored Serper key enables the skill with no settings entry: the+ // upgrade path for users who already have a key.+ std::fs::write(+ &auth_path,+ r#"{ "serper": { "type": "api_key", "key": "stored" } }"#,+ )+ .unwrap();+ let result = manager.resolve().unwrap();+ let websearch = result+ .skills+ .iter()+ .find(|r| r.path.to_string_lossy().contains("websearch"))+ .expect("websearch still collected");+ assert!(+ websearch.enabled,+ "a stored serper key enables the skill with no settings entry"+ );+ }++ std::fs::write(+ &settings_path,+ serde_json::json!({"bundledSkills": {"websearch": true}}).to_string(),+ )+ .unwrap();+ manager.reload_settings().unwrap();+ let result = manager.resolve().unwrap();+ let websearch = result+ .skills+ .iter()+ .find(|r| r.path.to_string_lossy().contains("websearch"))+ .expect("websearch still collected");+ assert!(+ websearch.enabled,+ "websearch resolves when explicitly enabled"+ );+ assert_eq!(websearch.metadata.source, MetadataSource::Builtin);+ // The explicit override beats the credential: a stored key stays silent+ // under `bundledSkills.websearch: false`.std::fs::write(&settings_path,serde_json::json!({"bundledSkills": {"websearch": false}}).to_string(),@@ -931,7 +986,10 @@ fn bundled_skills_collect_with_websearch_excluded_until_enabled() {.iter().find(|r| r.path.to_string_lossy().contains("websearch")).expect("websearch still collected");- assert!(!websearch.enabled, "websearch excluded until enabled");+ assert!(+ !websearch.enabled,+ "explicit false overrides a stored credential"+ );}#[test]diff --git a/crates/pa-core/src/prompts/layers/core.md b/crates/pa-core/src/prompts/layers/core.mdindex 3ffd237ce3..68ac9d2a6a 100644--- a/crates/pa-core/src/prompts/layers/core.md+++ b/crates/pa-core/src/prompts/layers/core.md@@ -22,7 +22,6 @@ The harness often sends messages to the agent. These are user messages starting- `.output: str`- `.duration: float`- `edit.run(path: str, old_str: str, new_str: str) -> str`: the primary method for editing files. async, exact-unique-match; the `edit` module is callable with the same arguments (`await edit(path=..., old_str=..., new_str=...)`)-- `websearch.run(query: str, *, max_output: int = 8192, timeout: int | None, num_results: int | None) -> str`: search the web; the `websearch` module is callable with the same arguments- `attach_image(*paths: str) -> str`: loads images directly into context if the agent's model is vision-capable, errors otherwise## Subagentsdiff --git a/crates/pa-core/tests/prompt_guards.rs b/crates/pa-core/tests/prompt_guards.rsindex 810af9b759..341db28bfd 100644--- a/crates/pa-core/tests/prompt_guards.rs+++ b/crates/pa-core/tests/prompt_guards.rs@@ -362,10 +362,21 @@ fn auth_gated_bundled_skills() -> BTreeSet<String> {.collect()}+/// Conditionally-available bundled skills: the websearch skill rides with its+/// credential (an unset `bundledSkills.websearch` resolves with the stored or+/// ambient Serper key), so keyless installs exclude it — it must never be+/// documented as static core-tool surface; the dynamic skills inventory+/// renders it only on installs where it resolves enabled.+fn settings_gated_bundled_skills() -> BTreeSet<String> {+ ["websearch".to_string()].into_iter().collect()+}+/// (import name, public functions) for every bundled Python skill that is-/// always available (auth-gated integrations excluded).+/// always available (auth-gated integrations and the conditionally-available+/// websearch skill excluded).fn bundled_python_skills() -> Vec<(String, Vec<String>)> {let gated = auth_gated_bundled_skills();+ let settings_gated = settings_gated_bundled_skills();sorted_bundled_skills().into_iter().filter(|skill| {@@ -374,6 +385,7 @@ fn bundled_python_skills() -> Vec<(String, Vec<String>)> {.as_ref().is_none_or(|python| !gated.contains(&python.import_name))})+ .filter(|skill| !settings_gated.contains(&skill.name)).filter_map(|skill| {let python = skill.python?;let mut functions = python_skill_functions(&python.package_path)