Skip to content

Commit 5d394c8

Browse files
committed
fix: split comma-separated values for variadic flags
Previously, "Bash(git commit:*), Bash(git add:*)" was passed as a single --allowed-tools= value. Now comma-separated strings are split into multiple flags, properly handling tool patterns with spaces.
1 parent 920d623 commit 5d394c8

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

src/command-builder.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,17 @@ export function buildArgsFromFrontmatter(
152152
// String/number -> flag with value
153153
// Variadic flags need --flag=value syntax to not eat following args
154154
if (VARIADIC_FLAGS.has(key)) {
155-
args.push(`${toFlag(key)}=${String(value)}`);
155+
const strValue = String(value);
156+
// Split comma-separated values for variadic flags
157+
// Handle both "Read,Edit" and "Bash(git commit:*), Bash(git add:*)"
158+
const parts = strValue.includes(', ')
159+
? strValue.split(', ') // Split on ", " (comma + space)
160+
: strValue.includes(',')
161+
? strValue.split(',') // Split on just ","
162+
: [strValue]; // No commas, single value
163+
for (const part of parts) {
164+
args.push(`${toFlag(key)}=${part.trim()}`);
165+
}
156166
} else {
157167
args.push(toFlag(key), String(value));
158168
}

src/command.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,22 @@ describe("buildArgs", () => {
7878
]);
7979
});
8080

81-
test("variadic allowed-tools comma-separated string works", () => {
81+
test("variadic allowed-tools comma-separated string splits into multiple flags", () => {
8282
const result = buildArgs({ "allowed-tools": "Read,Edit,Bash" }, new Set());
83-
expect(result).toEqual(["--allowed-tools=Read,Edit,Bash"]);
83+
expect(result).toEqual([
84+
"--allowed-tools=Read",
85+
"--allowed-tools=Edit",
86+
"--allowed-tools=Bash"
87+
]);
88+
});
89+
90+
test("variadic allowed-tools comma-space-separated string splits correctly", () => {
91+
// Handle tool patterns with spaces like Bash(git commit:*)
92+
const result = buildArgs({ "allowed-tools": "Bash(git commit:*), Bash(git add:*)" }, new Set());
93+
expect(result).toEqual([
94+
"--allowed-tools=Bash(git commit:*)",
95+
"--allowed-tools=Bash(git add:*)"
96+
]);
8497
});
8598

8699
test("skips system keys (_inputs)", () => {

src/command.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,17 @@ export function buildArgs(
216216
// String/number → flag with value
217217
// Variadic flags need --flag=value syntax to not eat following args
218218
if (VARIADIC_FLAGS.has(key)) {
219-
args.push(`${toFlag(key)}=${String(value)}`);
219+
const strValue = String(value);
220+
// Split comma-separated values for variadic flags
221+
// Handle both "Read,Edit" and "Bash(git commit:*), Bash(git add:*)"
222+
const parts = strValue.includes(', ')
223+
? strValue.split(', ') // Split on ", " (comma + space)
224+
: strValue.includes(',')
225+
? strValue.split(',') // Split on just ","
226+
: [strValue]; // No commas, single value
227+
for (const part of parts) {
228+
args.push(`${toFlag(key)}=${part.trim()}`);
229+
}
220230
} else {
221231
args.push(toFlag(key), String(value));
222232
}

0 commit comments

Comments
 (0)