fix(coding-agent): make prompt snippets opt in closes #2285
This commit is contained in:
@@ -74,4 +74,50 @@ describe("AgentSession dynamic tool registration", () => {
|
||||
|
||||
session.dispose();
|
||||
});
|
||||
|
||||
it("keeps custom tools active but omits them from available tools when promptSnippet is not provided", async () => {
|
||||
const settingsManager = SettingsManager.create(tempDir, agentDir);
|
||||
const sessionManager = SessionManager.inMemory();
|
||||
|
||||
const resourceLoader = new DefaultResourceLoader({
|
||||
cwd: tempDir,
|
||||
agentDir,
|
||||
settingsManager,
|
||||
extensionFactories: [
|
||||
(pi) => {
|
||||
pi.on("session_start", () => {
|
||||
pi.registerTool({
|
||||
name: "hidden_tool",
|
||||
label: "Hidden Tool",
|
||||
description: "Description should not appear in available tools",
|
||||
parameters: Type.Object({}),
|
||||
execute: async () => ({
|
||||
content: [{ type: "text", text: "ok" }],
|
||||
details: {},
|
||||
}),
|
||||
});
|
||||
});
|
||||
},
|
||||
],
|
||||
});
|
||||
await resourceLoader.reload();
|
||||
|
||||
const { session } = await createAgentSession({
|
||||
cwd: tempDir,
|
||||
agentDir,
|
||||
model: getModel("anthropic", "claude-sonnet-4-5")!,
|
||||
settingsManager,
|
||||
sessionManager,
|
||||
resourceLoader,
|
||||
});
|
||||
|
||||
await session.bindExtensions({});
|
||||
|
||||
expect(session.getAllTools().map((tool) => tool.name)).toContain("hidden_tool");
|
||||
expect(session.getActiveToolNames()).toContain("hidden_tool");
|
||||
expect(session.systemPrompt).not.toContain("hidden_tool");
|
||||
expect(session.systemPrompt).not.toContain("Description should not appear in available tools");
|
||||
|
||||
session.dispose();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -39,7 +39,7 @@ describe("buildSystemPrompt", () => {
|
||||
});
|
||||
|
||||
describe("custom tool snippets", () => {
|
||||
test("includes custom tools in available tools section", () => {
|
||||
test("includes custom tools in available tools section when promptSnippet is provided", () => {
|
||||
const prompt = buildSystemPrompt({
|
||||
selectedTools: ["read", "dynamic_tool"],
|
||||
toolSnippets: {
|
||||
@@ -51,6 +51,16 @@ describe("buildSystemPrompt", () => {
|
||||
|
||||
expect(prompt).toContain("- dynamic_tool: Run dynamic test behavior");
|
||||
});
|
||||
|
||||
test("omits custom tools from available tools section when promptSnippet is not provided", () => {
|
||||
const prompt = buildSystemPrompt({
|
||||
selectedTools: ["read", "dynamic_tool"],
|
||||
contextFiles: [],
|
||||
skills: [],
|
||||
});
|
||||
|
||||
expect(prompt).not.toContain("dynamic_tool");
|
||||
});
|
||||
});
|
||||
|
||||
describe("prompt guidelines", () => {
|
||||
|
||||
Reference in New Issue
Block a user