Skip to content

Commit ac17db4

Browse files
committed
fix(antigravity): use managed prompt file and update tests
1 parent aa70080 commit ac17db4

2 files changed

Lines changed: 29 additions & 16 deletions

File tree

apps/daemon/src/runtimes/defs/antigravity.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
writeFileSync,
66
} from 'node:fs';
77
import { readFile as fsReadFile } from 'node:fs/promises';
8-
import { homedir, tmpdir } from 'node:os';
8+
import { homedir } from 'node:os';
99
import { dirname, join } from 'node:path';
1010

1111
import { DEFAULT_MODEL_OPTION } from './shared.js';
@@ -217,22 +217,22 @@ export const antigravityAgentDef = {
217217
}
218218
// We no longer use `-p -` because recent `agy` versions treat `-` as a literal
219219
// prompt string instead of reading from stdin (see issue #5495).
220-
// Instead, we write the full transcript to a temporary file and instruct
221-
// `agy` to read and execute it, avoiding Windows command-line length limits.
222-
// We use a PID-bound filename so it safely overwrites itself on each turn
223-
// without bloating the OS temp directory over time.
224-
const tempFile = join(tmpdir(), `od_agy_prompt_${process.pid}.md`);
225-
writeFileSync(tempFile, _prompt);
220+
// Instead, we use `promptViaFile: true` so the daemon securely prepares a
221+
// managed temp file per-run and cleans it up after the agent exits.
222+
if (!runtimeContext.promptFilePath) {
223+
throw new Error('antigravity requires runtimeContext.promptFilePath when promptViaFile is true');
224+
}
226225

227226
const args: string[] = [];
228227
if (runtimeContext.agentLogFilePath) {
229228
args.push('--log-file', runtimeContext.agentLogFilePath);
230229
}
231230
args.push('-p');
232-
args.push(`Read the system instructions, conversation history, and user request from the file ${tempFile}. Follow the instructions strictly and provide the final response to the user's latest request.`);
231+
args.push(`Read the system instructions, conversation history, and user request from the file ${runtimeContext.promptFilePath}. Follow the instructions strictly and provide the final response to the user's latest request.`);
233232
return args;
234233
},
235234
promptViaStdin: false,
235+
promptViaFile: true,
236236
streamFormat: 'plain',
237237
installUrl: 'https://antigravity.google/cli',
238238
docsUrl: 'https://antigravity.google/docs/cli-overview',

apps/daemon/tests/runtimes/agent-args.test.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -534,18 +534,28 @@ test('qwen args check promptViaStdin, base args, model args and exclude `-` sent
534534
// the daemon would render the resulting empty reply as a "successful"
535535
// agent response — exactly the failure mode the auth/quota guard at
536536
// server.ts ~12090 is meant to catch but for the wrong reason.
537-
test('antigravity pipes prompt via stdin via -p flag (print mode)', () => {
537+
test('antigravity delivers prompt via managed temp file instead of stdin', () => {
538538
assert.equal(antigravity.bin, 'agy');
539539
assert.equal(antigravity.streamFormat, 'plain');
540-
assert.equal(antigravity.promptViaStdin, true);
540+
assert.equal(antigravity.promptViaStdin, false);
541+
assert.equal(antigravity.promptViaFile, true);
541542

542-
const args = antigravity.buildArgs('write hello world', [], [], {}, {});
543-
assert.deepEqual(args, ['-p', '-']);
543+
assert.throws(() => {
544+
antigravity.buildArgs('hello', [], [], {}, {});
545+
}, /requires runtimeContext\.promptFilePath/);
546+
547+
const expectedFileText = 'Read the system instructions, conversation history, and user request from the file /tmp/managed-prompt.md. Follow the instructions strictly and provide the final response to the user\'s latest request.';
548+
549+
const args = antigravity.buildArgs('write hello world', [], [], {}, {
550+
promptFilePath: '/tmp/managed-prompt.md'
551+
});
552+
assert.deepEqual(args, ['-p', expectedFileText]);
544553

545554
const argsWithLog = antigravity.buildArgs('write hello world', [], [], {}, {
546555
agentLogFilePath: '/tmp/od-agy-test.log',
556+
promptFilePath: '/tmp/managed-prompt.md'
547557
});
548-
assert.deepEqual(argsWithLog, ['--log-file', '/tmp/od-agy-test.log', '-p', '-']);
558+
assert.deepEqual(argsWithLog, ['--log-file', '/tmp/od-agy-test.log', '-p', expectedFileText]);
549559

550560
// No `--model` flag exists upstream, so buildArgs argv must stay the
551561
// same regardless of which label the user picks.
@@ -558,9 +568,10 @@ test('antigravity pipes prompt via stdin via -p flag (print mode)', () => {
558568
}, {
559569
agentLogFilePath: '/tmp/od-agy-test.log',
560570
antigravitySettingsPath: join(settingsDir, 'settings.json'),
571+
promptFilePath: '/tmp/managed-prompt.md'
561572
});
562573
assert.equal(withModel.includes('--model'), false);
563-
assert.deepEqual(withModel, ['--log-file', '/tmp/od-agy-test.log', '-p', '-']);
574+
assert.deepEqual(withModel, ['--log-file', '/tmp/od-agy-test.log', '-p', expectedFileText]);
564575
} finally {
565576
rmSync(settingsDir, { recursive: true, force: true });
566577
}
@@ -575,14 +586,16 @@ test('antigravity pipes prompt via stdin via -p flag (print mode)', () => {
575586
// same regression.
576587
const followUp = antigravity.buildArgs('next message', [], [], {}, {
577588
hasPriorAssistantTurn: true,
589+
promptFilePath: '/tmp/managed-prompt.md'
578590
});
579-
assert.deepEqual(followUp, ['-p', '-']);
591+
assert.deepEqual(followUp, ['-p', expectedFileText]);
580592
assert.equal(followUp.includes('-c'), false);
581593

582594
const firstTurn = antigravity.buildArgs('first', [], [], {}, {
583595
hasPriorAssistantTurn: false,
596+
promptFilePath: '/tmp/managed-prompt.md'
584597
});
585-
assert.deepEqual(firstTurn, ['-p', '-']);
598+
assert.deepEqual(firstTurn, ['-p', expectedFileText]);
586599
assert.equal(antigravity.resumesSessionViaCli, undefined);
587600

588601
assert.equal(antigravity.maxPromptArgBytes, undefined);

0 commit comments

Comments
 (0)