feat(coding-agent): prioritize project resources over global

This commit is contained in:
Mario Zechner 2026-02-24 23:50:55 +01:00
parent 380236a003
commit f0379384fe
8 changed files with 271 additions and 63 deletions

View file

@ -234,6 +234,42 @@ describe("ExtensionRunner", () => {
expect(tools.length).toBe(2);
expect(tools.map((t) => t.definition.name).sort()).toEqual(["tool_a", "tool_b"]);
});
it("keeps first tool when two extensions register the same name", async () => {
const first = `
import { Type } from "@sinclair/typebox";
export default function(pi) {
pi.registerTool({
name: "shared",
label: "shared",
description: "first",
parameters: Type.Object({}),
execute: async () => ({ content: [{ type: "text", text: "ok" }], details: {} }),
});
}
`;
const second = `
import { Type } from "@sinclair/typebox";
export default function(pi) {
pi.registerTool({
name: "shared",
label: "shared",
description: "second",
parameters: Type.Object({}),
execute: async () => ({ content: [{ type: "text", text: "ok" }], details: {} }),
});
}
`;
fs.writeFileSync(path.join(extensionsDir, "a-first.ts"), first);
fs.writeFileSync(path.join(extensionsDir, "b-second.ts"), second);
const result = await discoverAndLoadExtensions([], tempDir, tempDir);
const runner = new ExtensionRunner(result.extensions, result.runtime, tempDir, sessionManager, modelRegistry);
const tools = runner.getAllRegisteredTools();
expect(tools).toHaveLength(1);
expect(tools[0]?.definition.description).toBe("first");
});
});
describe("command collection", () => {
@ -377,6 +413,36 @@ describe("ExtensionRunner", () => {
expect(flags.has("my-flag")).toBe(true);
});
it("keeps first flag when two extensions register the same name", async () => {
const first = `
export default function(pi) {
pi.registerFlag("shared-flag", {
description: "first",
type: "boolean",
default: true,
});
}
`;
const second = `
export default function(pi) {
pi.registerFlag("shared-flag", {
description: "second",
type: "boolean",
default: false,
});
}
`;
fs.writeFileSync(path.join(extensionsDir, "a-first.ts"), first);
fs.writeFileSync(path.join(extensionsDir, "b-second.ts"), second);
const result = await discoverAndLoadExtensions([], tempDir, tempDir);
const runner = new ExtensionRunner(result.extensions, result.runtime, tempDir, sessionManager, modelRegistry);
const flags = runner.getFlags();
expect(flags.get("shared-flag")?.description).toBe("first");
expect(result.runtime.flagValues.get("shared-flag")).toBe(true);
});
it("can set flag values", async () => {
const extCode = `
export default function(pi) {