fix: wire allowed_tools/disallowed_tools inputs through to Claude SDK

The disallowed tools env var read in run.ts was DISALLOWED_TOOLS_INPUT
(raw user input) instead of DISALLOWED_TOOLS (computed value including
WebSearch/WebFetch defaults). This meant default tool disallowance was
never enforced. Also removes orphaned ALLOWED_TOOLS env var export from
createPrompt() (tag mode passes allowed tools via claudeArgs instead),
extracts shared parseToolsInput utility to eliminate duplication, and
adds tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Vlad MocanuandClaude Opus 4.6 committed 2026-02-27 11:16:38 +02:00
1 parent 29a1032aa6
commit df7afc08d4
7 files changed
+112 -8

No files matched your search

+11 -8
View File
@@ -23,6 +23,7 @@ import { GITHUB_SERVER_URL } from "../github/api/config";
import { detectPlatform } from "../platform/detector";
import { getForgejoRunIndex } from "../forgejo/comment-logic";
import { extractUserRequest } from "../utils/extract-user-request";
import { parseToolsInput } from "../utils/parse-tools-input";
export type { CommonFields, PreparedContext } from "./types";
/** Filename for the user request file, read by the SDK runner */
@@ -993,17 +994,19 @@ export async function createPrompt(
console.log("========================");
}
// Set allowed tools
const hasActionsReadPermission = false;
// Compute disallowed tools — merge user inputs with defaults (fixes upstream #181, #287, #724)
// Note: Allowed tools are passed via claudeArgs in prepareTagMode(), not through env vars.
// DISALLOWED_TOOLS is consumed by run.ts and passed to runClaude().
const userAllowedTools = parseToolsInput(process.env.ALLOWED_TOOLS_INPUT);
const userDisallowedTools = parseToolsInput(
process.env.DISALLOWED_TOOLS_INPUT,
);
const allAllowedTools = buildAllowedToolsString(
[],
hasActionsReadPermission,
context.inputs.useCommitSigning,
const allDisallowedTools = buildDisallowedToolsString(
userDisallowedTools,
userAllowedTools,
);
const allDisallowedTools = buildDisallowedToolsString([], []);
core.exportVariable("ALLOWED_TOOLS", allAllowedTools);
core.exportVariable("DISALLOWED_TOOLS", allDisallowedTools);
} catch (error) {
throw new Error(`Create prompt failed with error: ${error}`);
+1
View File
@@ -245,6 +245,7 @@ async function run() {
const claudeResult: ClaudeRunResult = await runClaude(promptConfig.path, {
claudeArgs: prepareResult.claudeArgs,
disallowedTools: process.env.DISALLOWED_TOOLS || undefined,
appendSystemPrompt: process.env.APPEND_SYSTEM_PROMPT,
model: process.env.ANTHROPIC_MODEL,
pathToClaudeCodeExecutable:
+5
View File
@@ -19,6 +19,7 @@ import { isEntityContext } from "../../github/context";
import type { GitHubContext } from "../../github/context";
import type { Octokits } from "../../github/api/client";
import { parseAllowedTools } from "../agent/parse-tools";
import { parseToolsInput } from "../../utils/parse-tools-input";
/**
* Prepares the tag mode execution context.
@@ -124,6 +125,9 @@ export async function prepareTagMode({
tool.startsWith("mcp__github_"),
);
// Merge user-provided allowed_tools input (fixes upstream #181, #287, #724)
const userAllowedTools = parseToolsInput(process.env.ALLOWED_TOOLS_INPUT);
// Build claude_args for tag mode with required tools
// Tag mode REQUIRES these tools to function properly
const tagModeTools = [
@@ -139,6 +143,7 @@ export async function prepareTagMode({
"mcp__github_ci__get_workflow_run_details",
"mcp__github_ci__download_job_log",
...userAllowedMCPTools,
...userAllowedTools,
];
// Add git commands when using git CLI (no API commit signing, or SSH signing)
+10
View File
@@ -0,0 +1,10 @@
/**
* Parse a comma-separated tools string into a trimmed, non-empty array.
* Used for ALLOWED_TOOLS_INPUT and DISALLOWED_TOOLS_INPUT env vars.
*/
export function parseToolsInput(input: string | undefined): string[] {
return (input || "")
.split(",")
.map((t) => t.trim())
.filter(Boolean);
}