Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(plugins): keep manifest validation inside the module LOC limit
v_wyxgwangf9adbff6d12b
diff --git a/crates/host-core/src/plugins/validation.rs b/crates/host-core/src/plugins/validation.rsindex e607399f6..193062350 100644--- a/crates/host-core/src/plugins/validation.rs+++ b/crates/host-core/src/plugins/validation.rs@@ -1,7 +1,9 @@use super::*;mod composer_transforms;mod contribution_ids;+mod global_shortcuts;mod launcher_triggers;+mod model_context;mod provider_catalog;use contribution_ids::is_contrib_id;@@ -122,68 +124,10 @@ pub(crate) fn validate_contributions(root: &Path, manifest: &PluginManifest) ->}}- if let Some(shortcuts) = map.get("globalShortcuts") {- let entries = array_of(shortcuts, "contributes.globalShortcuts")?;- if entries.len() > 8 {- bail!("PLUGIN_INVALID: contributes.globalShortcuts allows at most 8 entries");- }- // The gate is the permission, not the contribution: a declared shortcut- // without `keyboard.globalShortcut` would otherwise register silently.- if !entries.is_empty() {- require_permission(manifest, "keyboard.globalShortcut", "global shortcuts")?;- }- let command_ids: Vec<&str> = map- .get("commands")- .and_then(Value::as_array)- .map(|commands| {- commands- .iter()- .filter_map(|command| command.get("id").and_then(Value::as_str))- .collect()- })- .unwrap_or_default();- let mut seen: Vec<&str> = Vec::new();- for entry in entries {- let obj = entry.as_object().ok_or_else(|| {- anyhow!("PLUGIN_INVALID: contributes.globalShortcuts entry must be an object")- })?;- let id = obj- .get("id")- .and_then(Value::as_str)- .filter(|id| is_shortcut_id(id))- .ok_or_else(|| {- anyhow!("PLUGIN_INVALID: global shortcut id is missing or invalid")- })?;- if seen.contains(&id) {- bail!("PLUGIN_INVALID: duplicate global shortcut id {id}");- }- seen.push(id);- let command = obj- .get("command")- .and_then(Value::as_str)- .map(str::trim)- .filter(|command| !command.is_empty())- .ok_or_else(|| {- anyhow!("PLUGIN_INVALID: global shortcut {id} requires a command")- })?;- if !command_ids.contains(&command) {- bail!("PLUGIN_INVALID: global shortcut {id} references an undeclared command");- }- if let Some(default) = obj.get("default") {- if !is_shortcut_shape(default) {- bail!("PLUGIN_INVALID: global shortcut {id} has an invalid default");- }- }- }- }+ global_shortcuts::validate(map, manifest)?;launcher_triggers::validate(map, manifest)?;composer_transforms::validate(map, manifest)?;- if let Some(model_context) = map.get("modelContext") {- if model_context.as_bool() != Some(true) {- bail!("PLUGIN_INVALID: contributes.modelContext must be true");- }- require_permission(manifest, "agent.modelContext", "model context")?;- }+ model_context::validate(map, manifest)?;if let Some(skills) = map.get("skills") {let entries = array_of(skills, "contributes.skills")?;for entry in entries {diff --git a/crates/host-core/src/plugins/validation/global_shortcuts.rs b/crates/host-core/src/plugins/validation/global_shortcuts.rsnew file mode 100644index 000000000..8fadae2f3--- /dev/null+++ b/crates/host-core/src/plugins/validation/global_shortcuts.rs@@ -0,0 +1,59 @@+use anyhow::{anyhow, bail, Result};+use serde_json::{Map, Value};++use super::{array_of, is_shortcut_id, is_shortcut_shape, require_permission, PluginManifest};++pub(super) fn validate(map: &Map<String, Value>, manifest: &PluginManifest) -> Result<()> {+ let Some(shortcuts) = map.get("globalShortcuts") else {+ return Ok(());+ };+ let entries = array_of(shortcuts, "contributes.globalShortcuts")?;+ if entries.len() > 8 {+ bail!("PLUGIN_INVALID: contributes.globalShortcuts allows at most 8 entries");+ }+ // The gate is the permission, not the contribution: a declared shortcut+ // without `keyboard.globalShortcut` would otherwise register silently.+ if !entries.is_empty() {+ require_permission(manifest, "keyboard.globalShortcut", "global shortcuts")?;+ }+ let command_ids: Vec<&str> = map+ .get("commands")+ .and_then(Value::as_array)+ .map(|commands| {+ commands+ .iter()+ .filter_map(|command| command.get("id").and_then(Value::as_str))+ .collect()+ })+ .unwrap_or_default();+ let mut seen: Vec<&str> = Vec::new();+ for entry in entries {+ let obj = entry.as_object().ok_or_else(|| {+ anyhow!("PLUGIN_INVALID: contributes.globalShortcuts entry must be an object")+ })?;+ let id = obj+ .get("id")+ .and_then(Value::as_str)+ .filter(|id| is_shortcut_id(id))+ .ok_or_else(|| anyhow!("PLUGIN_INVALID: global shortcut id is missing or invalid"))?;+ if seen.contains(&id) {+ bail!("PLUGIN_INVALID: duplicate global shortcut id {id}");+ }+ seen.push(id);+ let command = obj+ .get("command")+ .and_then(Value::as_str)+ .map(str::trim)+ .filter(|command| !command.is_empty())+ .ok_or_else(|| anyhow!("PLUGIN_INVALID: global shortcut {id} requires a command"))?;+ if !command_ids.contains(&command) {+ bail!("PLUGIN_INVALID: global shortcut {id} references an undeclared command");+ }+ if let Some(default) = obj.get("default") {+ if !is_shortcut_shape(default) {+ bail!("PLUGIN_INVALID: global shortcut {id} has an invalid default");+ }+ }+ }+ Ok(())+}diff --git a/crates/host-core/src/plugins/validation/model_context.rs b/crates/host-core/src/plugins/validation/model_context.rsnew file mode 100644index 000000000..a6ac88d98--- /dev/null+++ b/crates/host-core/src/plugins/validation/model_context.rs@@ -0,0 +1,16 @@+use anyhow::{bail, Result};+use serde_json::{Map, Value};++use super::{require_permission, PluginManifest};++/// A model-context contribution is a grant, not a manifest-only capability:+/// declaring it without `agent.modelContext` would silently contribute nothing.+pub(super) fn validate(map: &Map<String, Value>, manifest: &PluginManifest) -> Result<()> {+ let Some(model_context) = map.get("modelContext") else {+ return Ok(());+ };+ if model_context.as_bool() != Some(true) {+ bail!("PLUGIN_INVALID: contributes.modelContext must be true");+ }+ require_permission(manifest, "agent.modelContext", "model context")+}diff --git a/docs/adr/README.md b/docs/adr/README.mdindex a2fac3700..f3e91394d 100644--- a/docs/adr/README.md+++ b/docs/adr/README.md@@ -423,3 +423,4 @@ git history.| plan-approval-session-permission | [Plan approval defaults to the owning Session's permission](plan-approval-session-permission.md) | Accepted; amends ADR 0053 and ADR 0158 || plugin-transcript-selection-views | [Docked views can accept transcript selections](plugin-transcript-selection-views.md) | Accepted (issue #2395) || opt-in-background-job-continuation | [Opt-in background job continuation](opt-in-background-job-continuation.md) | Proposed (#2143) |+| plugin-turn-observation-model-context-and-suggestion-targets | [Publish turn observations, scoped model context, and Composer suggestion targets](plugin-turn-observation-model-context-and-suggestion-targets.md) | Accepted (#2470) |diff --git a/docs/adr/plugin-turn-observation-model-context-and-suggestion-targets.md b/docs/adr/plugin-turn-observation-model-context-and-suggestion-targets.mdindex 51f0988c8..6cac0940d 100644--- a/docs/adr/plugin-turn-observation-model-context-and-suggestion-targets.md+++ b/docs/adr/plugin-turn-observation-model-context-and-suggestion-targets.md@@ -1,4 +1,4 @@-# Plugin turn observation, model context, and suggestion targets+# ADR plugin-turn-observation-model-context-and-suggestion-targets: Publish turn observations, scoped model context, and Composer suggestion targets## Status