Skip to content

Commit 54c5fa5

Browse files
authored
feat(server): add Antigravity CLI provider protocol spike (#2)
Establish the wire contract for driving the Antigravity (agy) CLI as a T3 provider: bounded plan-mode launch and resume argument construction, unavailable/unauthenticated/available classification, stream-json event parsing, and terminal-outcome normalization covering cancellation and missing terminal results. Protocol functions only. Nothing spawns a process or registers a provider, so the live provider catalog is unchanged. Verified against agy 1.1.22 by bounded read-only probe: init, step_update, and result envelopes match the fixtures, and --conversation resume continues step_index and reuses cached context. Spike authored by Desktop_Codex; recovered from a disposable checkout, independently re-verified, and committed by Laptop_Cursor. Task pingdotgg#642.
1 parent 18d281e commit 54c5fa5

2 files changed

Lines changed: 490 additions & 0 deletions

File tree

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
import * as NodeAssert from "node:assert/strict";
2+
3+
import { describe, it } from "vite-plus/test";
4+
5+
import {
6+
buildAntigravityPrintArgs,
7+
classifyAntigravityAvailability,
8+
normalizeAntigravityCliEvent,
9+
normalizeAntigravityProcessExit,
10+
parseAntigravityStreamLine,
11+
} from "./AntigravityCliProtocol.ts";
12+
13+
describe("buildAntigravityPrintArgs", () => {
14+
it("builds a bounded read-only stream-json launch", () => {
15+
NodeAssert.deepStrictEqual(
16+
buildAntigravityPrintArgs({
17+
prompt: "Inspect the repository without changing files.",
18+
model: "gemini-3.7-flash-low",
19+
effort: "low",
20+
}),
21+
[
22+
"--print",
23+
"Inspect the repository without changing files.",
24+
"--output-format",
25+
"stream-json",
26+
"--mode",
27+
"plan",
28+
"--sandbox",
29+
"--model",
30+
"gemini-3.7-flash-low",
31+
"--effort",
32+
"low",
33+
],
34+
);
35+
});
36+
37+
it("resumes an existing conversation without weakening safeguards", () => {
38+
NodeAssert.deepStrictEqual(
39+
buildAntigravityPrintArgs({
40+
prompt: "Continue the inspection.",
41+
conversationId: "conversation-123",
42+
}),
43+
[
44+
"--print",
45+
"Continue the inspection.",
46+
"--output-format",
47+
"stream-json",
48+
"--mode",
49+
"plan",
50+
"--sandbox",
51+
"--conversation",
52+
"conversation-123",
53+
],
54+
);
55+
});
56+
});
57+
58+
describe("Antigravity stream-json protocol", () => {
59+
it("normalizes session initialization", () => {
60+
const event = parseAntigravityStreamLine(
61+
JSON.stringify({
62+
event: "init",
63+
conversation_id: "conversation-123",
64+
init: {
65+
model: "gemini-3.7-flash-low",
66+
cwd: "/workspace",
67+
permission_mode: "request-review",
68+
tools: [],
69+
},
70+
}),
71+
);
72+
73+
NodeAssert.deepStrictEqual(normalizeAntigravityCliEvent(event), {
74+
type: "session.started",
75+
conversationId: "conversation-123",
76+
model: "gemini-3.7-flash-low",
77+
cwd: "/workspace",
78+
permissionMode: "request-review",
79+
});
80+
});
81+
82+
it("normalizes assistant text deltas", () => {
83+
const event = parseAntigravityStreamLine(
84+
JSON.stringify({
85+
event: "step_update",
86+
step_update: {
87+
step_index: 1,
88+
step_type: "agent_response",
89+
state: "ACTIVE",
90+
text_delta: "AGY_OK",
91+
},
92+
}),
93+
);
94+
95+
NodeAssert.deepStrictEqual(normalizeAntigravityCliEvent(event), {
96+
type: "content.delta",
97+
stepIndex: 1,
98+
text: "AGY_OK",
99+
});
100+
});
101+
102+
it("normalizes terminal results", () => {
103+
const event = parseAntigravityStreamLine(
104+
JSON.stringify({
105+
event: "result",
106+
result: {
107+
conversation_id: "conversation-123",
108+
status: "SUCCESS",
109+
response: "AGY_OK\n",
110+
duration_seconds: 0.806,
111+
num_turns: 1,
112+
usage: { input_tokens: 12, output_tokens: 3 },
113+
},
114+
}),
115+
);
116+
117+
NodeAssert.deepStrictEqual(normalizeAntigravityCliEvent(event), {
118+
type: "turn.completed",
119+
response: "AGY_OK\n",
120+
durationSeconds: 0.806,
121+
numTurns: 1,
122+
usage: { input_tokens: 12, output_tokens: 3 },
123+
});
124+
});
125+
126+
it("ignores blank, malformed, and non-assistant step lines", () => {
127+
NodeAssert.equal(parseAntigravityStreamLine(""), null);
128+
NodeAssert.equal(parseAntigravityStreamLine("not-json"), null);
129+
130+
const event = parseAntigravityStreamLine(
131+
JSON.stringify({
132+
event: "step_update",
133+
step_update: {
134+
step_index: 0,
135+
step_type: "user_input",
136+
state: "DONE",
137+
},
138+
}),
139+
);
140+
NodeAssert.equal(normalizeAntigravityCliEvent(event), null);
141+
});
142+
143+
it("maps a failed result to a terminal abort", () => {
144+
const event = parseAntigravityStreamLine(
145+
JSON.stringify({
146+
event: "result",
147+
result: {
148+
conversation_id: "conversation-123",
149+
status: "FAILED",
150+
response: "Provider failed",
151+
},
152+
}),
153+
);
154+
155+
NodeAssert.deepStrictEqual(normalizeAntigravityCliEvent(event), {
156+
type: "turn.aborted",
157+
status: "FAILED",
158+
response: "Provider failed",
159+
});
160+
});
161+
});
162+
163+
describe("Antigravity capability probes", () => {
164+
it("distinguishes unavailable, unauthenticated, and available states", () => {
165+
NodeAssert.deepStrictEqual(
166+
classifyAntigravityAvailability({
167+
version: { exitCode: 127, stdout: "", stderr: "agy: command not found" },
168+
models: null,
169+
}),
170+
{ status: "unavailable", reason: "agy: command not found" },
171+
);
172+
173+
NodeAssert.deepStrictEqual(
174+
classifyAntigravityAvailability({
175+
version: { exitCode: 0, stdout: "1.1.22\n", stderr: "" },
176+
models: { exitCode: 1, stdout: "", stderr: "authentication required" },
177+
}),
178+
{
179+
status: "unauthenticated",
180+
version: "1.1.22",
181+
reason: "authentication required",
182+
},
183+
);
184+
185+
NodeAssert.deepStrictEqual(
186+
classifyAntigravityAvailability({
187+
version: { exitCode: 0, stdout: "1.1.22\n", stderr: "" },
188+
models: { exitCode: 0, stdout: "models", stderr: "" },
189+
}),
190+
{ status: "available", version: "1.1.22" },
191+
);
192+
});
193+
194+
it("maps process cancellation and missing terminal results", () => {
195+
NodeAssert.deepStrictEqual(
196+
normalizeAntigravityProcessExit({
197+
exitCode: null,
198+
signal: "SIGTERM",
199+
terminalResultSeen: false,
200+
}),
201+
{
202+
type: "turn.aborted",
203+
status: "CANCELLED",
204+
response: "Agy process terminated by SIGTERM",
205+
},
206+
);
207+
208+
NodeAssert.deepStrictEqual(
209+
normalizeAntigravityProcessExit({
210+
exitCode: 0,
211+
signal: null,
212+
terminalResultSeen: false,
213+
}),
214+
{
215+
type: "turn.aborted",
216+
status: "PROTOCOL_ERROR",
217+
response: "Agy exited without a terminal result event",
218+
},
219+
);
220+
221+
NodeAssert.equal(
222+
normalizeAntigravityProcessExit({
223+
exitCode: 0,
224+
signal: null,
225+
terminalResultSeen: true,
226+
}),
227+
null,
228+
);
229+
});
230+
});

0 commit comments

Comments
 (0)