Skip to content

Commit c030b30

Browse files
authored
fix(agent-core): preserve empty prompt arguments (#96405)
1 parent 770b19f commit c030b30

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Agent Core tests cover prompt template argument parsing behavior.
2+
import { describe, expect, it } from "vitest";
3+
import { parseCommandArgs, substituteArgs } from "./prompt-template-arguments.js";
4+
5+
describe("prompt template arguments", () => {
6+
it("preserves quoted empty arguments so positional placeholders stay aligned", () => {
7+
expect(parseCommandArgs('first "" third')).toEqual(["first", "", "third"]);
8+
expect(parseCommandArgs("first '' third")).toEqual(["first", "", "third"]);
9+
expect(substituteArgs("$1|$2|$3", parseCommandArgs('first "" third'))).toBe("first||third");
10+
});
11+
});

packages/agent-core/src/harness/prompt-template-arguments.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,31 @@ export function parseCommandArgs(argsString: string): string[] {
55
const args: string[] = [];
66
let current = "";
77
let inQuote: string | null = null;
8+
let hasToken = false;
89

910
for (const char of argsString) {
1011
if (inQuote) {
1112
if (char === inQuote) {
1213
inQuote = null;
1314
} else {
15+
hasToken = true;
1416
current += char;
1517
}
1618
} else if (char === '"' || char === "'") {
19+
hasToken = true;
1720
inQuote = char;
1821
} else if (/\s/.test(char)) {
19-
if (current) {
22+
if (hasToken) {
2023
args.push(current);
2124
current = "";
25+
hasToken = false;
2226
}
2327
} else {
28+
hasToken = true;
2429
current += char;
2530
}
2631
}
27-
if (current) {
32+
if (hasToken) {
2833
args.push(current);
2934
}
3035
return args;

0 commit comments

Comments
 (0)