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

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ import {
ANTIGRAVITY_SUBAGENT_BATCH_TITLE,
antigravitySubagentLaunches,
describeAntigravitySubagentLaunches,
resolveAntigravityStepToolCallId,
} from "../../provider/acp/AntigravityChildWork.ts";
import { readAntigravityClientTextFile } from "../../provider/acp/AntigravityClientFiles.ts";
import { watchAntigravityPromptOutcome } from "../../provider/acp/AntigravityTurnOutcome.ts";
import {
antigravityApprovalOptions,
antigravitySubagentOutput,
classifyAntigravitySubagentToolCall,
extractAntigravityBackgroundWorkTask,
extractAntigravityUserInputQuestion,
makeAntigravityReadRepair,
makeAntigravityUserInputResponse,
Expand Down Expand Up @@ -272,6 +274,16 @@ export function makeAntigravityAcpAdapterFlavor(
},
normalizeToolCall: normalizeAntigravityToolCall,
extractSubagentUpdate: extractAntigravitySubagentUpdate,
extractBackgroundWorkTask: extractAntigravityBackgroundWorkTask,
...(profileDirectory === undefined
? {}
: {
resolveBackgroundTaskId: ({ sessionId, taskId }) =>
resolveAntigravityStepToolCallId({ profileDirectory, sessionId, taskId }),
}),
backgroundTasksEndWithProcess: true,
enablePostSettleContinuation: true,
reactiveBackgroundWakes: true,
supportsImagePrompts: true,
// ACP 1.3.0 treats /compact as ordinary model input.
supportsCompaction: false,
Expand Down
47 changes: 47 additions & 0 deletions apps/server/src/provider/acp/AntigravityChildWork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
antigravitySubagentLaunches,
describeAntigravitySubagentLaunches,
readAntigravityChildWork,
resolveAntigravityStepToolCallId,
} from "./AntigravityChildWork.ts";
import { sanitizeAntigravityToolPayload } from "./AntigravityProtocol.ts";
import {
Expand Down Expand Up @@ -341,4 +342,50 @@ it.layer(NodeServices.layer)("readAntigravityChildWork", (it) => {
expect(JSON.stringify(children).length).toBeLessThan(600 * 1024);
}),
);

it.effect("resolves background task step IDs to their ACP toolCallId", () =>
Effect.gen(function* () {
const { profile } = yield* makeProfile({
steps: (logUri) => [
[
50,
132,
invokeStep({
callId: "call_10484616887436816983",
launches: [LAUNCH],
children: [{ id: CHILD, logUri }],
}),
],
],
});
expect(
yield* resolveAntigravityStepToolCallId({
profileDirectory: profile,
sessionId: ROOT,
taskId: `${ROOT}/task-50`,
}),
).toBe("call_10484616887436816983");
expect(
yield* resolveAntigravityStepToolCallId({
profileDirectory: profile,
sessionId: ROOT,
taskId: "task-50",
}),
).toBe("call_10484616887436816983");
expect(
yield* resolveAntigravityStepToolCallId({
profileDirectory: profile,
sessionId: ROOT,
taskId: "other-session/task-50",
}),
).toBeUndefined();
expect(
yield* resolveAntigravityStepToolCallId({
profileDirectory: profile,
sessionId: ROOT,
taskId: `${ROOT}/task-999`,
}),
).toBeUndefined();
}),
);
});
56 changes: 56 additions & 0 deletions apps/server/src/provider/acp/AntigravityChildWork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,62 @@ class AntigravityChildWorkReadError extends Schema.TaggedError<AntigravityChildW
}
}

const decodeStepToolCallId = safely((payload): string | undefined =>
text(message(message(payload, STEP_METADATA), METADATA_TOOL_CALL), 1),
);

const ANTIGRAVITY_BACKGROUND_TASK_ID = /^(?:([A-Za-z0-9-]{1,64})\/)?task-(\d+)$/;

/**
* Resolves an Antigravity background task ID (`<sessionId>/task-<stepIdx>` or `task-<stepIdx>`)
* to the ACP `toolCallId` stored on that step in the session's own unlinked SQLite log.
*/
export const resolveAntigravityStepToolCallId = Effect.fn("resolveAntigravityStepToolCallId")(
function* (input: {
readonly profileDirectory: string;
readonly sessionId: string;
readonly taskId: string;
}): Effect.fn.Return<string | undefined> {
if (!NATIVE_ID.test(input.sessionId)) return undefined;
const match = ANTIGRAVITY_BACKGROUND_TASK_ID.exec(input.taskId.trim());
if (match === null) return undefined;
const [, prefixSessionId, stepIndexText] = match;
if (prefixSessionId !== undefined && prefixSessionId !== input.sessionId) return undefined;
const stepIndex = Number(stepIndexText);
if (!Number.isSafeInteger(stepIndex) || stepIndex < 0) return undefined;
return yield* Effect.tryPromise({
try: async (): Promise<string | undefined> => {
const profileRoot = await antigravityProfileRoot(input.profileDirectory);
const databasePath =
profileRoot === undefined
? undefined
: (
await antigravityManagedPath(
profileRoot,
["antigravity-acp", "conversations", `${input.sessionId}.db`],
"file",
)
)?.path;
if (profileRoot === undefined || databasePath === undefined) return undefined;
const database = new NodeSqlite.DatabaseSync(databasePath, { readOnly: true });
try {
database.exec("PRAGMA busy_timeout = 100");
const row = database
.prepare(
"SELECT step_payload FROM steps WHERE idx = ? AND step_format = 0 AND length(step_payload) <= ?",
)
.get(stepIndex, MAX_STEP_BYTES);
const payload = payloadOf(row);
return payload === undefined ? undefined : decodeStepToolCallId(payload);
} finally {
database.close();
}
},
catch: () => undefined,
}).pipe(Effect.orElseSucceed(() => undefined));
},
);

/** Children a subagent tool call launched, proven by the parent's own session record. */
export const readAntigravityChildWork = Effect.fn("readAntigravityChildWork")(function* (input: {
readonly profileDirectory: string;
Expand Down
148 changes: 148 additions & 0 deletions apps/server/src/provider/acp/AntigravityProtocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type * as EffectAcpSchema from "effect-acp/compat";
import * as AcpWireSchema from "effect-acp/schema-v1";

import {
extractAntigravityBackgroundWorkTask,
extractAntigravityUserInputQuestion,
antigravityApprovalOptions,
antigravitySubagentOutput,
Expand Down Expand Up @@ -623,3 +624,150 @@ describe("Antigravity served reads", () => {
});
});
});

describe("Antigravity background work classification", () => {
it("classifies awaited commands, daemons, schedules, workflows, and async subagents", () => {
expect(
extractAntigravityBackgroundWorkTask({
toolCallId: "call_cmd",
kind: "execute",
title: "sleep 5",
command: "sleep 5",
status: "inProgress",
data: { name: "run_command", rawInput: { CommandLine: "sleep 5", WaitMsBeforeAsync: 500 } },
}),
).toEqual({
taskId: "call_cmd",
kind: "command",
awaited: true,
description: "sleep 5",
});

expect(
extractAntigravityBackgroundWorkTask({
toolCallId: "call_daemon",
kind: "execute",
title: "vp run dev",
command: "vp run dev",
status: "inProgress",
data: {
name: "run_command",
rawInput: { CommandLine: "vp run dev", IsDaemon: true, WaitMsBeforeAsync: 500 },
},
}),
).toEqual({
taskId: "call_daemon",
kind: "command",
description: "vp run dev",
});

expect(
extractAntigravityBackgroundWorkTask({
toolCallId: "call_timer",
kind: "other",
title: "Run schedule",
status: "inProgress",
data: { name: "schedule", rawInput: { DurationSeconds: 10, Prompt: "Check build" } },
}),
).toEqual({
taskId: "call_timer",
kind: "background_task",
description: "Check build",
});

expect(
extractAntigravityBackgroundWorkTask({
toolCallId: "call_cron_daemon",
kind: "other",
title: "Run schedule",
status: "inProgress",
data: {
name: "schedule",
rawInput: { CronExpression: "*/5 * * * *", IsDaemon: true },
},
}),
).toEqual({
taskId: "call_cron_daemon",
kind: "monitor",
description: "Schedule (*/5 * * * *)",
});

expect(
extractAntigravityBackgroundWorkTask({
toolCallId: "call_workflow",
kind: "other",
title: "Run run_workflow",
status: "inProgress",
data: { name: "run_workflow", rawInput: { Description: "Fan out audit" } },
}),
).toEqual({
taskId: "call_workflow",
kind: "background_task",
description: "Fan out audit",
});

expect(
extractAntigravityBackgroundWorkTask({
toolCallId: "call_subagent_v15",
kind: "other",
title: "Run invoke_subagent",
status: "inProgress",
data: { name: "invoke_subagent", rawInput: { Role: "Codebase Researcher" } },
}),
).toEqual({
taskId: "call_subagent_v15",
kind: "subagent",
description: "Codebase Researcher",
});

// Legacy subagent titles stay owned by extractSubagentUpdate; MCP and ordinary reads are ignored.
expect(
extractAntigravityBackgroundWorkTask({
toolCallId: "call_legacy_subagent",
kind: "other",
title: "Running invoke_subagent",
status: "inProgress",
data: { name: "invoke_subagent" },
}),
).toBeUndefined();
expect(
extractAntigravityBackgroundWorkTask({
toolCallId: "call_mcp",
kind: "execute",
title: "run_command",
status: "inProgress",
data: { name: "run_command", meta: { is_mcp_tool_call: true } },
}),
).toBeUndefined();
expect(
extractAntigravityBackgroundWorkTask({
toolCallId: "call_read",
kind: "read",
title: "Read file",
status: "inProgress",
data: { name: "read_file" },
}),
).toBeUndefined();
});

it("extracts rawOutput.output into command aggregatedOutput", () => {
const normalized = normalizeAntigravityToolCall({
toolCallId: "call_out",
kind: "execute",
title: "sleep 5 && echo DONE",
status: "completed",
data: {
rawInput: { CommandLine: "sleep 5 && echo DONE" },
rawOutput: {
output: "Command exited with code 0.\n\nCommand output:\nDONE\n",
exit_code: 0,
},
},
});
expect(normalized.data.item).toEqual({
command: "sleep 5 && echo DONE",
aggregatedOutput: "Command exited with code 0.\n\nCommand output:\nDONE\n",
exitCode: 0,
});
});
});
Loading
Loading