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
24 changes: 21 additions & 3 deletions apps/server/src/provider/acp/AntigravityProtocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,24 +535,42 @@ describe("Antigravity tool results", () => {
);
});

it("keeps the start of a long command line, where the program and target are", () => {
const head = "cat > notes.md <<'EOF'";
const commandLine = `${head}\n${"note line\n".repeat(1_000)}EOF`;
const toolCall = normalizeAntigravityToolCall(
parseToolUpdate({
...commandStarted,
update: { ...commandStarted.update, rawInput: { CommandLine: commandLine } },
}).toolCall,
);
expect(toolCall.command?.startsWith(head)).toBe(true);
expect(toolCall.command).not.toContain("[Earlier output truncated]");
expect((toolCall.data.rawInput as { CommandLine: string }).CommandLine.startsWith(head)).toBe(
true,
);
});

it("keeps 1.5 command input and output valid Unicode when cut", () => {
const tail = `${"x".repeat(7_982)}build completed\r\n`;
const output = `Command output:\nprefix\r\n🚀${tail}`;
const expected = `[Earlier output truncated]\n\n${tail}`;
const head = "x".repeat(7_999);
const expectedCommand = `${head}\n\n[Command truncated]`;
const toolCall = normalizeAntigravityToolCall(
parseToolUpdate({
...commandCompleted,
update: {
...commandCompleted.update,
rawInput: { CommandLine: output },
rawInput: { CommandLine: `${head}🚀 --flag` },
rawOutput: { output, exit_code: 0 },
content: [{ type: "content", content: { type: "text", text: output } }],
},
}).toolCall,
);
expect(toolCall.command).toBe(expected.trimEnd());
expect(toolCall.command).toBe(expectedCommand);
expect(toolCall.data).toMatchObject({
rawInput: { CommandLine: expected },
rawInput: { CommandLine: expectedCommand },
rawOutput: { output: expected },
content: [{ content: { text: expected.trimEnd() } }],
});
Expand Down
29 changes: 23 additions & 6 deletions apps/server/src/provider/acp/AntigravityProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {

const TOOL_TEXT_LIMIT = 8_000;
const TOOL_TEXT_TRUNCATED = "[Earlier output truncated]\n\n";
const COMMAND_LINE_TRUNCATED = "\n\n[Command truncated]";
const QUESTION_LABEL_LIMIT = 512;

const NativeToolFields = Schema.Struct({
Expand Down Expand Up @@ -194,11 +195,21 @@ function boundCommandText(text: string, limit = TOOL_TEXT_LIMIT): string {
return copyBoundedText(`${TOOL_TEXT_TRUNCATED}${tail}`);
}

// A command line's program and target are at its start, so it keeps its head.
function boundCommandLine(text: string, limit = TOOL_TEXT_LIMIT): string {
if (
text.length <= limit ||
(text.length <= limit + COMMAND_LINE_TRUNCATED.length && text.endsWith(COMMAND_LINE_TRUNCATED))
) {
return text;
}
const head = text.slice(0, limit).replace(/[\uD800-\uDBFF]$/u, "");
return copyBoundedText(`${head}${COMMAND_LINE_TRUNCATED}`);
}

const COMMAND_LINE_FIELDS = new Set(["CommandLine", "command_line", "commandLine", "command"]);

const COMMAND_TEXT_FIELDS = new Set([
"CommandLine",
"command_line",
"commandLine",
"command",
"aggregatedOutput",
"combinedOutput",
"combined_output",
Expand Down Expand Up @@ -231,7 +242,13 @@ function sanitizeToolValue(
return undefined;
}
const bound =
field !== undefined && COMMAND_TEXT_FIELDS.has(field) ? boundCommandText : boundText;
field === undefined
? boundText
: COMMAND_LINE_FIELDS.has(field)
? boundCommandLine
: COMMAND_TEXT_FIELDS.has(field)
? boundCommandText
: boundText;
const text = bound(value, Math.min(TOOL_TEXT_LIMIT, budget.text));
budget.text -= text.length;
return text;
Expand Down Expand Up @@ -468,7 +485,7 @@ export function normalizeAntigravityToolCall(
output?.commandLine ??
output?.command_line ??
toolCall.command;
const command = nativeCommand?.trim() ? boundCommandText(nativeCommand.trim()) : undefined;
const command = nativeCommand?.trim() ? boundCommandLine(nativeCommand.trim()) : undefined;
const nativeCwd =
input?.Cwd ??
input?.WorkingDirectory ??
Expand Down
Loading