Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/create-prompt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,27 @@ export function buildAllowedToolsString(

export function buildDisallowedToolsString(
customDisallowedTools?: string,
allowedTools?: string,
): string {
let allDisallowedTools = DISALLOWED_TOOLS.join(",");
let disallowedTools = [...DISALLOWED_TOOLS];

// If user has explicitly allowed some hardcoded disallowed tools, remove them from disallowed list
if (allowedTools) {
const allowedToolsArray = allowedTools
.split(",")
.map((tool) => tool.trim());
disallowedTools = disallowedTools.filter(
(tool) => !allowedToolsArray.includes(tool),
);
}

let allDisallowedTools = disallowedTools.join(",");
if (customDisallowedTools) {
allDisallowedTools = `${allDisallowedTools},${customDisallowedTools}`;
if (allDisallowedTools) {
allDisallowedTools = `${allDisallowedTools},${customDisallowedTools}`;
} else {
allDisallowedTools = customDisallowedTools;
}
}
return allDisallowedTools;
}
Expand Down Expand Up @@ -648,6 +665,7 @@ export async function createPrompt(
);
const allDisallowedTools = buildDisallowedToolsString(
preparedContext.disallowedTools,
preparedContext.allowedTools,
);

core.exportVariable("ALLOWED_TOOLS", allAllowedTools);
Expand Down
47 changes: 47 additions & 0 deletions test/create-prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,4 +722,51 @@ describe("buildDisallowedToolsString", () => {
expect(parts).toContain("BadTool1");
expect(parts).toContain("BadTool2");
});

test("should remove hardcoded disallowed tools if they are in allowed tools", () => {
const customDisallowedTools = "BadTool1,BadTool2";
const allowedTools = "WebSearch,SomeOtherTool";
const result = buildDisallowedToolsString(
customDisallowedTools,
allowedTools,
);

// WebSearch should be removed from disallowed since it's in allowed
expect(result).not.toContain("WebSearch");

// WebFetch should still be disallowed since it's not in allowed
expect(result).toContain("WebFetch");

// Custom disallowed tools should still be present
expect(result).toContain("BadTool1");
expect(result).toContain("BadTool2");
});

test("should remove all hardcoded disallowed tools if they are all in allowed tools", () => {
const allowedTools = "WebSearch,WebFetch,SomeOtherTool";
const result = buildDisallowedToolsString(undefined, allowedTools);

// Both hardcoded disallowed tools should be removed
expect(result).not.toContain("WebSearch");
expect(result).not.toContain("WebFetch");

// Result should be empty since no custom disallowed tools provided
expect(result).toBe("");
});

test("should handle custom disallowed tools when all hardcoded tools are overridden", () => {
const customDisallowedTools = "BadTool1,BadTool2";
const allowedTools = "WebSearch,WebFetch";
const result = buildDisallowedToolsString(
customDisallowedTools,
allowedTools,
);

// Hardcoded tools should be removed
expect(result).not.toContain("WebSearch");
expect(result).not.toContain("WebFetch");

// Only custom disallowed tools should remain
expect(result).toBe("BadTool1,BadTool2");
});
});