Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(plugins): validate contributed thinking level fields

vastsae45a9e9bd1b4
diff --git a/crates/host-core/src/plugins/providers/tests.rs b/crates/host-core/src/plugins/providers/tests.rs
index dbe622200..d721a4af1 100644
--- a/crates/host-core/src/plugins/providers/tests.rs
+++ b/crates/host-core/src/plugins/providers/tests.rs
@@ -658,10 +658,21 @@ fn a_default_outside_the_declared_list_is_dropped() {
}
#[test]
-fn a_malformed_thinking_levels_field_is_ignored() {
+fn malformed_thinking_level_fields_are_rejected_by_manifest_validation() {
+ let dir = tempfile::tempdir().unwrap();
+ let root = dir.path().join("plugin");
let mut value = serde_json::to_value(manifest()).unwrap();
+
value["contributes"]["providers"][0]["models"][0]["thinkingLevels"] = json!("high");
- let manifest: PluginManifest = serde_json::from_value(value).unwrap();
- let declared = declared_providers(&manifest);
- assert!(declared[0].models[0].thinking_levels.is_empty());
+ write_plugin(&root, value.clone());
+ assert!(read_manifest_err(&root).contains("thinkingLevels must be an array of strings"));
+
+ value["contributes"]["providers"][0]["models"][0]["thinkingLevels"] = json!(["high", 7]);
+ write_plugin(&root, value.clone());
+ assert!(read_manifest_err(&root).contains("thinkingLevels must be an array of strings"));
+
+ value["contributes"]["providers"][0]["models"][0]["thinkingLevels"] = json!(["high"]);
+ value["contributes"]["providers"][0]["models"][0]["defaultThinkingLevel"] = json!(7);
+ write_plugin(&root, value);
+ assert!(read_manifest_err(&root).contains("defaultThinkingLevel must be a string"));
}
diff --git a/crates/host-core/src/plugins/validation.rs b/crates/host-core/src/plugins/validation.rs
index 7ca7537d6..ccdc041a5 100644
--- a/crates/host-core/src/plugins/validation.rs
+++ b/crates/host-core/src/plugins/validation.rs
@@ -301,6 +301,25 @@ pub(crate) fn validate_contributions(root: &Path, manifest: &PluginManifest) ->
.ok_or_else(|| {
anyhow!("PLUGIN_INVALID: provider {id} has a model without a valid id")
})?;
+ if let Some(levels) = model.get("thinkingLevels") {
+ let levels = levels.as_array().ok_or_else(|| {
+ anyhow!(
+ "PLUGIN_INVALID: provider {id} model {model_id} thinkingLevels must be an array of strings"
+ )
+ })?;
+ if levels.iter().any(|level| !level.is_string()) {
+ bail!(
+ "PLUGIN_INVALID: provider {id} model {model_id} thinkingLevels must be an array of strings"
+ );
+ }
+ }
+ if let Some(default_level) = model.get("defaultThinkingLevel") {
+ if !default_level.is_string() {
+ bail!(
+ "PLUGIN_INVALID: provider {id} model {model_id} defaultThinkingLevel must be a string"
+ );
+ }
+ }
if seen_models.contains(&model_id) {
bail!("PLUGIN_INVALID: provider {id} declares model {model_id} twice");
}
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index a6b7685ad..219fbccca 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -13756,7 +13756,9 @@ plugin-form fixtures in an isolated temporary directory at runtime.
re-enable it. 6) Uninstall the plugin; reinstall and enable it, then remove
the declaration from its manifest and reload. 7) Load a manifest that
declares providers without `provider.register`. 8) Load a manifest that
- declares an `oauth` block and `authKind: "oauth"`.
+ declares an `oauth` block and `authKind: "oauth"`. 9) Load manifests whose
+ model uses a non-array `thinkingLevels`, a non-string entry, or a non-string
+ `defaultThinkingLevel`.
- **Expected**: Step 1 shows one row in the native provider list with
`ownerPluginId` set to the plugin and the row id
`plugin:<pluginId>:<declaredId>`. Its model binding contains the normalized
@@ -13773,6 +13775,8 @@ plugin-form fixtures in an isolated temporary directory at runtime.
8 fail manifest validation as `PLUGIN_INVALID` — the missing-permission
message and `plugin OAuth providers are not supported in this release` /
`unsupported authKind oauth` — and neither failure changes plugin enablement.
+ Step 9 rejects each malformed thinking-level field with `PLUGIN_INVALID` and
+ leaves plugin enablement unchanged.
- **Specs linked**: `07-plugins/02-plugin-manifest-schema.md` §4, §5.4, §7;
`07-plugins/13-plugin-permissions-matrix.md`; `03-runtime/04-data-storage.md`
§4.3, §7; `03-runtime/11-provider-model-system.md` §6.2;
diff --git a/docs/spec/07-plugins/02-plugin-manifest-schema.md b/docs/spec/07-plugins/02-plugin-manifest-schema.md
index da470a80e..aef30b3d5 100644
--- a/docs/spec/07-plugins/02-plugin-manifest-schema.md
+++ b/docs/spec/07-plugins/02-plugin-manifest-schema.md
@@ -304,6 +304,9 @@ names, removes duplicates, and preserves the remaining declaration order. An
absent or unusable list becomes an empty binding. `defaultThinkingLevel` is kept
only when it names a normalized level in that model's list; otherwise it is
dropped and normal binding normalization selects the first available level.
+Manifest validation rejects a non-array `thinkingLevels`, any non-string entry, or
+an explicitly non-string `defaultThinkingLevel`; unknown string names are
+accepted and dropped during normalization.
## 5. permissions enum
diff --git a/docs/zh-CN/spec/07-plugins/02-plugin-manifest-schema.md b/docs/zh-CN/spec/07-plugins/02-plugin-manifest-schema.md
index 239cdea51..79abb088c 100644
--- a/docs/zh-CN/spec/07-plugins/02-plugin-manifest-schema.md
+++ b/docs/zh-CN/spec/07-plugins/02-plugin-manifest-schema.md
@@ -256,6 +256,8 @@ type PluginProviderModelContrib = {
`thinkingLevels` 可选。宿主会裁剪条目、丢弃未知规范档位、去重,并保留剩余的声明顺序。
缺失或不可用的列表会变成空绑定。只有当 `defaultThinkingLevel` 命中该模型列表中的归一化档位
时才会保留;否则会被丢弃,普通绑定归一化会选择第一个可用档位。
+清单校验会拒绝非数组的 `thinkingLevels`、其中任何非字符串条目,或非字符串的
+`defaultThinkingLevel`;未知的字符串档位则会被接受并在归一化时丢弃。
## 5. 权限枚举
diff --git a/packages/plugin-sdk/src/index.test.ts b/packages/plugin-sdk/src/index.test.ts
index 805d7729b..5b2dc1a8f 100644
--- a/packages/plugin-sdk/src/index.test.ts
+++ b/packages/plugin-sdk/src/index.test.ts
@@ -760,6 +760,40 @@ describe("contributes.providers", () => {
).toMatch(/without a valid id/);
});
+ it("rejects malformed thinking-level field shapes", () => {
+ const perm = { ...base, permissions: ["provider.register"] };
+ expect(
+ validateManifest({
+ ...perm,
+ contributes: {
+ providers: [
+ { ...provider, models: [{ ...provider.models[0], thinkingLevels: "high" as never }] },
+ ],
+ },
+ }).error,
+ ).toMatch(/thinkingLevels must be an array of strings/);
+ expect(
+ validateManifest({
+ ...perm,
+ contributes: {
+ providers: [
+ { ...provider, models: [{ ...provider.models[0], thinkingLevels: ["high", 7] as never }] },
+ ],
+ },
+ }).error,
+ ).toMatch(/thinkingLevels must be an array of strings/);
+ expect(
+ validateManifest({
+ ...perm,
+ contributes: {
+ providers: [
+ { ...provider, models: [{ ...provider.models[0], defaultThinkingLevel: 7 as never }] },
+ ],
+ },
+ }).error,
+ ).toMatch(/defaultThinkingLevel must be a string/);
+ });
+
it("rejects oauth, which needs a Host-owned login flow", () => {
expect(
validateContributions({ providers: [{ ...provider, authKind: "oauth" as never }] }),
diff --git a/packages/plugin-sdk/src/index.ts b/packages/plugin-sdk/src/index.ts
index c4230defc..e11db4baa 100644
--- a/packages/plugin-sdk/src/index.ts
+++ b/packages/plugin-sdk/src/index.ts
@@ -1678,6 +1678,15 @@ export function validateContributions(
if (model.supportsImages !== undefined && typeof model.supportsImages !== "boolean") {
return `provider "${provider.id}" model ${modelId} supportsImages must be a boolean`;
}
+ if (
+ model.thinkingLevels !== undefined &&
+ (!Array.isArray(model.thinkingLevels) || model.thinkingLevels.some((level) => typeof level !== "string"))
+ ) {
+ return `provider "${provider.id}" model ${modelId} thinkingLevels must be an array of strings`;
+ }
+ if (model.defaultThinkingLevel !== undefined && typeof model.defaultThinkingLevel !== "string") {
+ return `provider "${provider.id}" model ${modelId} defaultThinkingLevel must be a string`;
+ }
}
}