feat(ai-profiles): add plugin profile SDK and Cline demo (#342)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 16:30:49 +01:00
parent 2a3c582ec8
commit 8faa860676
25 changed files with 5755 additions and 2 deletions

View File

@ -0,0 +1,52 @@
import assert from "node:assert/strict";
import test from "node:test";
import { validatePluginManifest } from "../dist/index.js";
function valid(args, env) {
return validatePluginManifest({
ideaPluginManifestVersion: 1, id: "test.limits", displayName: "Limits", version: "1.0.0",
main: "dist/index.js", trustLevel: "full", contributes: { agentAdapters: [{
id: "adapter", displayName: "Adapter", protocol: "idea-agent-session", protocolVersion: 1,
command: "bin/adapter", args, env,
configSchema: { type: "object", properties: {}, additionalProperties: false },
}] },
}).success;
}
const environment = (count, value) => Object.fromEntries(Array.from({ length: count }, (_, i) => [`FIELD_${i}`, value]));
test("argv count 128 inclusive", () => {
assert.equal(valid(Array(128).fill("x"), {}), true);
assert.equal(valid(Array(129).fill("x"), {}), false);
});
test("argv token 4096 UTF8 bytes inclusive", () => {
assert.equal(valid(["é".repeat(2048)], {}), true);
assert.equal(valid(["é".repeat(2048) + "a"], {}), false);
});
test("argv aggregate includes terminators", () => {
const args = Array(8).fill("x".repeat(4095));
assert.equal(valid(args, {}), true);
args[0] += "x";
assert.equal(valid(args, {}), false);
});
test("environment count 64 inclusive", () => {
assert.equal(valid([], environment(64, "x")), true);
assert.equal(valid([], environment(65, "x")), false);
});
test("environment name 128 bytes inclusive", () => {
assert.equal(valid([], { ["A".repeat(128)]: "x" }), true);
assert.equal(valid([], { ["A".repeat(129)]: "x" }), false);
});
test("environment value 4096 UTF8 bytes inclusive", () => {
assert.equal(valid([], { FIELD: "é".repeat(2048) }), true);
assert.equal(valid([], { FIELD: "é".repeat(2048) + "a" }), false);
});
test("environment aggregate includes equals and terminators", () => {
const env = environment(8, "x".repeat(4087));
assert.equal(valid([], env), true);
env.FIELD_0 += "x";
assert.equal(valid([], env), false);
});
test("NUL cannot be truncated in argv or env", () => {
assert.equal(valid(["x\0y"], {}), false);
assert.equal(valid([], { FIELD: "x\0y" }), false);
});

View File

@ -0,0 +1,80 @@
import assert from "node:assert/strict";
import { validatePluginManifest } from "../dist/index.js";
const base = {
ideaPluginManifestVersion: 1,
id: "dev.example.agent",
displayName: "Agent",
version: "1.0.0",
main: "dist/index.js",
trustLevel: "full",
contributes: {
agentAdapters: [{
id: "session",
displayName: "Session",
protocol: "idea-agent-session",
protocolVersion: 1,
command: "bin/agent",
configSchema: { type: "object", properties: {}, additionalProperties: false }
}],
aiProfiles: [{
id: "default",
adapterId: "session",
displayName: "Default",
profileType: "codingAgent",
providerLabel: "Example",
configDefaults: {}
}]
}
};
assert.equal(
validatePluginManifest(base).success,
true,
"valid agent adapter and AI profile contributions are accepted"
);
const unknownAdapter = structuredClone(base);
unknownAdapter.contributes.aiProfiles[0].adapterId = "missing";
assert.equal(
validatePluginManifest(unknownAdapter).success,
false,
"AI profiles cannot reference an unknown adapter"
);
const unsupportedProtocol = structuredClone(base);
unsupportedProtocol.contributes.agentAdapters[0].protocolVersion = 2;
assert.equal(
validatePluginManifest(unsupportedProtocol).success,
false,
"only agent session protocol version 1 is supported"
);
const protectedEnv = structuredClone(base);
protectedEnv.contributes.agentAdapters[0].env = { PATH: "/tmp/plugin-bin", API_TOKEN: "literal" };
const acceptance = [];
acceptance.push(["runtime-rejected env names", validatePluginManifest(protectedEnv).success]);
const excessiveArgs = structuredClone(base);
excessiveArgs.contributes.agentAdapters[0].args = Array.from({ length: 257 }, () => "x");
acceptance.push(["257 adapter args", validatePluginManifest(excessiveArgs).success]);
const excessiveArgBytes = structuredClone(base);
excessiveArgBytes.contributes.agentAdapters[0].args = ["x".repeat(64 * 1024 + 1)];
acceptance.push(["adapter args over 64 KiB", validatePluginManifest(excessiveArgBytes).success]);
const excessiveEnvEntries = structuredClone(base);
excessiveEnvEntries.contributes.agentAdapters[0].env = Object.fromEntries(
Array.from({ length: 129 }, (_, index) => [`PLUGIN_VALUE_${index}`, "x"]),
);
acceptance.push(["129 adapter env entries", validatePluginManifest(excessiveEnvEntries).success]);
const excessiveEnvBytes = structuredClone(base);
excessiveEnvBytes.contributes.agentAdapters[0].env = { PLUGIN_VALUE: "x".repeat(64 * 1024 + 1) };
acceptance.push(["adapter env over 64 KiB", validatePluginManifest(excessiveEnvBytes).success]);
assert.deepEqual(
acceptance,
acceptance.map(([label]) => [label, false]),
"SDK must reject runtime-incompatible env and oversized adapter args/env"
);