Skip to content
Open
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
423 changes: 423 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export interface AntigravityAdapterV2Options {
readonly onSessionEvent?: AcpAdapterV2Flavor["onSessionEvent"];
readonly nativeLogging?: Parameters<typeof makeAcpAdapterV2>[0]["nativeLogging"];
readonly continuationRequests?: Parameters<typeof makeAcpAdapterV2>[0]["continuationRequests"];
readonly samplePromptSuggestion?: AcpAdapterV2Flavor["samplePromptSuggestion"];
/** The agent's GEMINI_HOME. Its session logs show turns that ended on an upstream error. */
readonly profileDirectory?: string;
}
Expand Down Expand Up @@ -250,6 +251,9 @@ export function makeAntigravityAcpAdapterFlavor(
// `agy acp` reads a prompt sent mid-turn as a steer; cancel-and-restart killed its subagents.
steersWithPrompt: antigravitySteersWithPrompt,
...(options.onSessionEvent === undefined ? {} : { onSessionEvent: options.onSessionEvent }),
...(options.samplePromptSuggestion === undefined
? {}
: { samplePromptSuggestion: options.samplePromptSuggestion }),
applyModelSelection: Effect.fn("AntigravityAdapterV2.applyModelSelection")(function* ({
runtime,
modelSelection,
Expand Down
25 changes: 15 additions & 10 deletions apps/server/src/provider/Drivers/AntigravityDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import * as AcpErrors from "effect-acp/errors";
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
import {
isAntigravityTextGenerationAvailable,
makeAntigravityPromptSuggestionSampler,
makeAntigravityTextGeneration,
} from "../../textGeneration/AntigravityTextGeneration.ts";
import { makeAntigravityAuth, type AntigravityAuth } from "../AntigravityAuth.ts";
Expand Down Expand Up @@ -589,12 +590,25 @@ export const AntigravityDriver: ProviderDriver<
),
);
const defaultModel = currentCatalog.pipe(Effect.map((catalog) => catalog?.defaultChatModel));
const isolatedHelperOptions = {
profileDirectory,
defaultModel,
withProcess: authFlow.withProcess,
makeRuntime: (cwd: string) =>
makeRuntime({
cwd,
mcpServers: [],
}),
};
const samplePromptSuggestion =
yield* makeAntigravityPromptSuggestionSampler(isolatedHelperOptions);
const orchestrationAdapter = yield* makeAntigravityAdapterV2({
instanceId,
selfInvocation,
makeRuntime,
withProcess: authFlow.withProcess,
defaultModel,
samplePromptSuggestion,
supportsNativeGoals: provider.snapshot.getSnapshot.pipe(
Effect.map(
(snapshot) => snapshot.slashCommands?.some((command) => command.name === "goal") === true,
Expand All @@ -619,16 +633,7 @@ export const AntigravityDriver: ProviderDriver<
threadId,
}),
});
const textGeneration = yield* makeAntigravityTextGeneration({
profileDirectory,
defaultModel,
withProcess: authFlow.withProcess,
makeRuntime: (cwd) =>
makeRuntime({
cwd,
mcpServers: [],
}),
});
const textGeneration = yield* makeAntigravityTextGeneration(isolatedHelperOptions);

const refreshModels = Effect.fn("AntigravityDriver.refreshModels")(
function* () {
Expand Down
111 changes: 111 additions & 0 deletions apps/server/src/textGeneration/AntigravityTextGeneration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ import { removeAntigravitySessionFiles } from "../provider/acp/AntigravitySessio

import {
type AntigravityTextGenerationOptions,
buildAntigravityPromptSuggestionPrompt,
isAntigravityTextGenerationAvailable,
makeAntigravityPromptSuggestionSampler,
makeAntigravityTextGeneration,
sanitizeAntigravityPromptSuggestion,
selectLowestAntigravityThinkingLevel,
} from "./AntigravityTextGeneration.ts";

type TextRuntime = Effect.Success<ReturnType<AntigravityTextGenerationOptions["makeRuntime"]>>;
Expand Down Expand Up @@ -295,6 +299,11 @@ const makeFixture = Effect.fn("makeAntigravityTextGenerationFixture")(function*
makeRuntime,
withProcess,
});
const samplePromptSuggestion = yield* makeAntigravityPromptSuggestionSampler({
profileDirectory,
makeRuntime,
withProcess,
});
const titleInput = { cwd: projectDirectory, message: "Repair Google login", modelSelection };
const assertCleaned = Effect.gen(function* () {
expect(state.closed).toEqual(state.workspaces);
Expand All @@ -321,6 +330,7 @@ const makeFixture = Effect.fn("makeAntigravityTextGenerationFixture")(function*
incoming,
enteredPrompt,
textGeneration,
samplePromptSuggestion,
titleInput,
assertCleaned,
};
Expand Down Expand Up @@ -701,6 +711,107 @@ it.layer(NodeServices.layer)("AntigravityTextGeneration", (it) => {
expect(yield* fixture.fs.readFileString(`${fixture.sessionBase}.meta`)).toBe(metadata);
}),
);

it.effect("samples a next-prompt suggestion at the lowest thinking level and cleans up", () =>
Effect.gen(function* () {
const fixture = yield* makeFixture({
outputs: ['{"suggestion":" add tests for subtract\\n"}'],
});
const suggestion = yield* fixture.samplePromptSuggestion({
modelSelection: {
...modelSelection,
options: [{ id: "thinking_level", value: "high" }],
},
messages: [
{ role: "user", text: "Add a subtract function." },
{ role: "assistant", text: "Added subtract in math.ts." },
],
});
expect(suggestion).toBe("add tests for subtract");
expect(fixture.state.selectedModels).toEqual([modelSelection.model]);
expect(fixture.state.thinkingUpdates).toEqual(["low"]);
expect(fixture.state.promptThinkingLevels).toEqual(["low"]);
const sentText = JSON.stringify(fixture.state.prompts[0]?.prompt);
expect(sentText).toContain("Add a subtract function.");
expect(sentText).toContain("Added subtract in math.ts.");
yield* fixture.assertCleaned;
}),
);

it.effect.each([
{ name: "empty", output: '{"suggestion":""}', expected: null },
{
name: "delegated-task imitation",
output: '{"suggestion":"Delegated task finished with 2 findings"}',
expected: null,
},
{
name: "overlong",
output: JSON.stringify({ suggestion: "a".repeat(201) }),
expected: null,
},
{
name: "multiline normalized",
output: '{"suggestion":" run the\\n test suite "}',
expected: "run the test suite",
},
])("sanitizes $name prompt suggestions", ({ output, expected }) =>
Effect.gen(function* () {
const fixture = yield* makeFixture({ outputs: [output] });
expect(
yield* fixture.samplePromptSuggestion({
modelSelection,
messages: [
{ role: "user", text: "Fix the parser." },
{ role: "assistant", text: "Fixed the parser." },
],
}),
).toBe(expected);
yield* fixture.assertCleaned;
}),
);

it("picks the lowest available thinking level and preserves the tail of long transcripts", () => {
expect(
selectLowestAntigravityThinkingLevel([
{
id: "thinking_level",
name: "Thinking level",
category: "thought_level",
type: "select",
currentValue: "high",
options: [
{ value: "minimal", name: "Minimal" },
{ value: "low", name: "Low" },
{ value: "high", name: "High" },
],
},
]),
).toEqual({ id: "thinking_level", value: "minimal" });
expect(
selectLowestAntigravityThinkingLevel([
{
id: "thinking_level",
name: "Thinking level",
category: "thought_level",
type: "select",
currentValue: "low",
options: [
{ value: "low", name: "Low" },
{ value: "high", name: "High" },
],
},
]),
).toBeUndefined();
const longReply = `${"x".repeat(4_500)}Should I open a PR?`;
const prompt = buildAntigravityPromptSuggestionPrompt([
{ role: "user", text: "Implement the fix." },
{ role: "assistant", text: longReply },
]);
expect(prompt).toContain("[Earlier content truncated]");
expect(prompt).toContain("Should I open a PR?");
expect(sanitizeAntigravityPromptSuggestion(" ")).toBeNull();
});
});

it.effect("retains filesystem services supplied only during construction", () =>
Expand Down
Loading
Loading