mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-27 11:40:00 +01:00
feat(antigravity): swarms use the CLI's own default channel, and say which Google account they run on
Google's app and CLI use Google's default channel, where Gemini 4 Neon is offered; Paperclip forced the stable endpoint, which offers no Neon and bills a separately exhausted pool. The swarm route now passes no endpoint override by default. The deployment can pin Google's stable channel with the server env PAPERCLIP_ANTIGRAVITY_SWARM_CHANNEL (provider_default | stable); a Neon refusal on stable names that fix. The start step names the channel, and the Runner compares the CLI's own sign-in (from its log) with the agent's connection as digests only, showing a plain notice when they differ. Also: a resent accepted /swarm returns its original receipt before any availability check, and the request text is used verbatim (the composer removes the one /swarm the user typed). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
22913aed7a
commit
48caed2d3a
19 files changed
+284
-45
No files matched your search
@@ -593,6 +593,8 @@ export async function prepareManagedAiRuntime(
|
||||
attribution,
|
||||
accountName: selection.connection.name,
|
||||
accountOwnerUserId: selection.grant.subjectUserId,
|
||||
// The Google account a subscription grant signs in with; the Runner compares only its digest.
|
||||
...(antigravitySubscription && selection.grant.providerTenant?.name ? { accountEmail: selection.grant.providerTenant.name } : {}),
|
||||
identity,
|
||||
home,
|
||||
cleanup: cleanupRuntime,
|
||||
|
||||
@@ -374,10 +374,14 @@ describe.skipIf(!support.supported)("trusted /swarm run selection (database)", (
|
||||
expect(await automatic(f, run.id, "issue_commented")).toEqual({ commentId: f.comment.id, request: "two helpers" });
|
||||
});
|
||||
|
||||
it("strips a /swarm prefix the request comment may still carry", async () => {
|
||||
it("uses the recorded comment as the request verbatim: the composer already removed the one /swarm the user typed", async () => {
|
||||
// `/swarm /swarm explain this command` arrives as the body `/swarm explain this command`.
|
||||
const f = await seed();
|
||||
await db.update(issueComments).set({ body: "/swarm write a.txt" }).where(eq(issueComments.id, f.comment.id));
|
||||
expect(await resolve(f, { runId: (await insertRun(f, {})).id })).toMatchObject({ request: "write a.txt" });
|
||||
await db.update(issueComments).set({ body: "/swarm explain this command" }).where(eq(issueComments.id, f.comment.id));
|
||||
expect(await resolve(f, { runId: (await insertRun(f, {})).id })).toMatchObject({ request: "/swarm explain this command" });
|
||||
const g = await seed();
|
||||
await db.update(issueComments).set({ body: "/swarm" }).where(eq(issueComments.id, g.comment.id));
|
||||
expect(await resolve(g, { runId: (await insertRun(g, {})).id })).toMatchObject({ request: "/swarm" });
|
||||
});
|
||||
|
||||
it("lets a later user /swarm replace the request with its own text", async () => {
|
||||
@@ -484,7 +488,7 @@ describe.skipIf(!support.supported)("trusted /swarm run selection (database)", (
|
||||
const ids: Record<string, string> = {};
|
||||
for (const [index, label] of order.entries()) {
|
||||
const [comment] = await db.insert(issueComments).values({ companyId: f.company.id, issueId: f.issue.id, authorType: "user",
|
||||
authorUserId: USER, body: label.startsWith("S") ? `/swarm request ${label}` : `ordinary ${label}`,
|
||||
authorUserId: USER, body: label.startsWith("S") ? `request ${label}` : `ordinary ${label}`,
|
||||
createdAt: new Date(base + index * 1000) }).returning();
|
||||
ids[label] = comment!.id;
|
||||
if (label.startsWith("S")) await recordAntigravitySwarmRequest(db, { companyId: f.company.id, issueId: f.issue.id, commentId: comment!.id, userId: USER });
|
||||
@@ -537,8 +541,8 @@ describe.skipIf(!support.supported)("trusted /swarm run selection (database)", (
|
||||
|
||||
it.each([
|
||||
["no request", " ", /no request/],
|
||||
["only the command", "/swarm ", /no request/],
|
||||
["a request longer than the swarm accepts", `/swarm ${"x".repeat(16_001)}`, /too long/],
|
||||
["no request after the command", " ", /no request/],
|
||||
["a request longer than the swarm accepts", "x".repeat(16_001), /too long/],
|
||||
])("refuses a recorded /swarm with %s instead of running ordinary work", async (_name, body, message) => {
|
||||
const f = await seed();
|
||||
await db.update(issueComments).set({ body }).where(eq(issueComments.id, f.comment.id));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { and, desc, eq, gt, inArray, isNotNull, isNull, ne, or, sql } from "drizzle-orm";
|
||||
import { parseLeadingUserCommand, SWARM_REQUEST_MAX_CHARS } from "@paperclipai/shared";
|
||||
import { SWARM_REQUEST_MAX_CHARS } from "@paperclipai/shared";
|
||||
import { activityLog, agentWakeupRequests, agents, heartbeatRuns, issueComments, issues, type Db } from "@paperclipai/db";
|
||||
import { logActivity } from "./activity-log.js";
|
||||
import { instanceSettingsService } from "./instance-settings.js";
|
||||
@@ -55,9 +55,14 @@ export function requestedAntigravitySwarmCommentId(context: unknown): string | n
|
||||
return typeof value === "string" && /^[0-9a-f-]{36}$/i.test(value) ? value : null;
|
||||
}
|
||||
|
||||
/** The swarm's instruction from a recorded request comment: its text, without a leading /swarm it may still carry. */
|
||||
/**
|
||||
* The swarm's instruction from a recorded request comment: its text, verbatim.
|
||||
* With `nativeCommand: "swarm"` the comment body IS the request; the composer
|
||||
* removes the one leading `/swarm` the user typed, and nothing strips another
|
||||
* (`/swarm /swarm explain this` asks the swarm about `/swarm explain this`).
|
||||
*/
|
||||
export function antigravitySwarmRequestFromComment(body: string): string {
|
||||
return (parseLeadingUserCommand(body, ["swarm"])?.argument ?? body).trim();
|
||||
return body.trim();
|
||||
}
|
||||
|
||||
/** A request the swarm cannot run: nothing to do, or longer than the swarm accepts. */
|
||||
|
||||
@@ -726,6 +726,8 @@ export async function executeHeartbeatRuntime(db: Db, input: HeartbeatRuntimeExe
|
||||
billingIdentity: managedAiRuntime ? { provider: managedAiRuntime.attribution.provider, biller: managedAiRuntime.attribution.provider === "openai" ? resolveManagedOpenAiBilling(managedAiRuntime.config.managedAiRouting)?.biller ?? managedAiRuntime.attribution.provider : managedAiRuntime.attribution.provider, billingType: managedAiRuntime.attribution.method === "subscription" ? "subscription_included" : "metered_api" } : undefined,
|
||||
managedAiCredentialIdentity: managedAiRuntime?.identity,
|
||||
managedAiAccountIdentity: managedAiRuntime?.sessionIdentity,
|
||||
...(managedAiRuntime && "accountEmail" in managedAiRuntime && typeof managedAiRuntime.accountEmail === "string"
|
||||
? { managedAiAccountEmail: managedAiRuntime.accountEmail } : {}),
|
||||
managedAiCredentialWriteback: managedAiRuntime?.credentialWriteback,
|
||||
managedAiCredentialHome: managedAiRuntime ? String((managedAiRuntime.config.env as Record<string, unknown>).CODEX_HOME) : undefined,
|
||||
outputSecrets: [...identityRedactor.secretSources, ...observabilitySecretValues(observability)],
|
||||
|
||||
@@ -3,7 +3,8 @@ import { constants } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { antigravityCredentialTurn, bindAntigravityCredentialTurn, bindAntigravityTransportRetirement, prepareAntigravityRunnerCredentials } from "./antigravity-runner-credentials.js";
|
||||
import { antigravityAccountDigest, antigravityCredentialTurn, antigravitySwarmChannel, bindAntigravityCredentialTurn, bindAntigravityTransportRetirement, prepareAntigravityRunnerCredentials } from "./antigravity-runner-credentials.js";
|
||||
import { sanitizeAntigravityCredential } from "../../vendor/paperclip-runner/index.js";
|
||||
import { completeManagedNativeCredentialTurn } from "./managed-native-credentials.js";
|
||||
import type { NativeSession, createRunnerdCodexTransport } from "../../vendor/paperclip-runner/index.js";
|
||||
import { bindRetainedGoogleCredentialHome } from "../retained-google-credential-cleanup.js";
|
||||
@@ -99,12 +100,34 @@ describe("Antigravity managed Runner credentials", () => {
|
||||
GOOGLE_CLOUD_ACCESS_TOKEN: "ambient", PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET: "spoofed",
|
||||
} })).toEqual({ home: null, environment: { GEMINI_API_KEY: "fixture-selected" } });
|
||||
});
|
||||
it("binds the deployment's swarm channel and only a digest of the connection account to the credential", async () => {
|
||||
const managedHome = await home();
|
||||
await writeFile(join(managedHome, "antigravity-acp", "acp_token.json"), credential("fixture-selected"), { mode: 0o600 });
|
||||
const previous = process.env.PAPERCLIP_ANTIGRAVITY_SWARM_CHANNEL;
|
||||
process.env.PAPERCLIP_ANTIGRAVITY_SWARM_CHANNEL = "stable";
|
||||
try {
|
||||
const { environment } = await prepareAntigravityRunnerCredentials({ remote: false, managedHome, environment: {}, accountEmail: "Owner@Example.test" });
|
||||
const secret = environment.PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET!;
|
||||
expect(JSON.parse(secret).paperclip).toEqual({ swarmChannel: "stable", accountSha256: antigravityAccountDigest("owner@example.test") });
|
||||
expect(secret).not.toMatch(/example\.test/i);
|
||||
// Pinned: the Runner's antigravityAccountDigest pins the same value for the CLI's sign-in.
|
||||
expect(antigravityAccountDigest("OWNER@example.test")).toBe("0fde1d32467703827f511884b66298187e2944f4bfe260303f893a0af908f81e");
|
||||
} finally {
|
||||
if (previous === undefined) delete process.env.PAPERCLIP_ANTIGRAVITY_SWARM_CHANNEL; else process.env.PAPERCLIP_ANTIGRAVITY_SWARM_CHANNEL = previous;
|
||||
}
|
||||
expect(antigravitySwarmChannel({})).toBe("provider_default");
|
||||
expect(antigravitySwarmChannel({ PAPERCLIP_ANTIGRAVITY_SWARM_CHANNEL: "daily" })).toBe("provider_default");
|
||||
});
|
||||
it("projects only the selected private token and rejects remote subscription delivery", async () => {
|
||||
const managedHome = await home();
|
||||
await writeFile(join(managedHome, "antigravity-acp", "acp_token.json"), credential("fixture-selected"), { mode: 0o600 });
|
||||
expect(await prepareAntigravityRunnerCredentials({ remote: false, managedHome, environment: { GEMINI_HOME: "/untrusted" } })).toEqual({
|
||||
home: managedHome, credential: credential("fixture-selected"), environment: { PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET: credential("fixture-selected") },
|
||||
});
|
||||
const projected = await prepareAntigravityRunnerCredentials({ remote: false, managedHome, environment: { GEMINI_HOME: "/untrusted" } });
|
||||
expect(projected).toMatchObject({ home: managedHome, credential: credential("fixture-selected") });
|
||||
expect(Object.keys(projected.environment)).toEqual(["PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET"]);
|
||||
// The selected token, plus the swarm route's run facts, which the Runner's sanitizer drops before any write.
|
||||
expect(JSON.parse(projected.environment.PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET!)).toEqual({
|
||||
...JSON.parse(credential("fixture-selected")), paperclip: { swarmChannel: "provider_default" } });
|
||||
expect(sanitizeAntigravityCredential(projected.environment.PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET!)).toBe(credential("fixture-selected"));
|
||||
for (const [input, code] of [[{ remote: true, environment: {} }, "antigravity_remote_sign_in_unsupported"],
|
||||
[{ remote: false, lifecycleMode: "warm" as const, environment: {} }, "antigravity_warm_unsupported"],
|
||||
[{ remote: false, lifecycleMode: "warm" as const, environment: { GEMINI_API_KEY: "fixture-selected" } }, "antigravity_warm_unsupported"]] as const) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { constants } from "node:fs";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { createHash, randomUUID } from "node:crypto";
|
||||
import { mkdir, mkdtemp, realpath, rename, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
@@ -35,12 +35,30 @@ export function bindAntigravityTransportRetirement(bundle: RunnerdTransport): Ru
|
||||
return bundle.transport;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Google channel a trusted /swarm's Antigravity CLI talks to, owned by the
|
||||
* deployment: `provider_default` (the default; Google's daily channel, which
|
||||
* Google's own app and CLI use and which can change with less notice) or
|
||||
* `stable` (Google's stable endpoint, which may offer fewer models).
|
||||
*/
|
||||
export const ANTIGRAVITY_SWARM_CHANNEL_ENV = "PAPERCLIP_ANTIGRAVITY_SWARM_CHANNEL";
|
||||
export function antigravitySwarmChannel(env: NodeJS.ProcessEnv = process.env): "provider_default" | "stable" {
|
||||
return env[ANTIGRAVITY_SWARM_CHANNEL_ENV]?.trim().toLowerCase() === "stable" ? "stable" : "provider_default";
|
||||
}
|
||||
|
||||
/** Same digest as the Runner's antigravityAccountDigest: a one-way, non-identifying account comparison. */
|
||||
export function antigravityAccountDigest(email: string): string {
|
||||
return createHash("sha256").update(`paperclip.antigravity-account.v1:${email.trim().toLowerCase()}`, "utf8").digest("hex");
|
||||
}
|
||||
|
||||
/** Only explicit run credentials may enter Antigravity's isolated runtime. */
|
||||
export async function prepareAntigravityRunnerCredentials(input: {
|
||||
environment: NodeJS.ProcessEnv;
|
||||
remote: boolean;
|
||||
managedHome?: string;
|
||||
lifecycleMode?: "per_turn" | "warm";
|
||||
/** The connection's Google account; only its digest reaches the Runner. */
|
||||
accountEmail?: string;
|
||||
}): Promise<{ environment: NodeJS.ProcessEnv; home: string | null; credential?: string }> {
|
||||
const environment = { ...input.environment };
|
||||
for (const key of [AUTH_SECRET, "GEMINI_HOME", "GOOGLE_API_KEY", "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_CLOUD_ACCESS_TOKEN"]) delete environment[key];
|
||||
@@ -59,7 +77,13 @@ export async function prepareAntigravityRunnerCredentials(input: {
|
||||
} catch {
|
||||
throw new Error("The selected Google Antigravity account is unavailable. Reconnect the Google account, then retry.");
|
||||
}
|
||||
environment[AUTH_SECRET] = credential;
|
||||
// Run facts bound to this credential for the swarm route (channel, account
|
||||
// digest). The Runner's credential sanitizer drops them before any write, so
|
||||
// the staged token and its writeback comparison are unchanged.
|
||||
environment[AUTH_SECRET] = JSON.stringify({ ...JSON.parse(credential) as Record<string, unknown>, paperclip: {
|
||||
swarmChannel: antigravitySwarmChannel(),
|
||||
...(input.accountEmail ? { accountSha256: antigravityAccountDigest(input.accountEmail) } : {}),
|
||||
} });
|
||||
return { environment, home, credential };
|
||||
}
|
||||
|
||||
|
||||
@@ -10662,6 +10662,8 @@ export async function executePaperclipNativeSession(input: {
|
||||
managedAiCredentialHome?: string;
|
||||
managedAiCredentialIdentity?: string;
|
||||
managedAiAccountIdentity?: string;
|
||||
/** The Google account of an Antigravity subscription grant (Runner compares only its digest). */
|
||||
managedAiAccountEmail?: string;
|
||||
managedAiCredentialWriteback?: ManagedAiCredentialWritebackBinding;
|
||||
billingIdentity?: Pick<AdapterExecutionResult, "provider" | "biller" | "billingType">;
|
||||
onTaskDispatched?: () => Promise<void> | void;
|
||||
@@ -16487,6 +16489,8 @@ export async function createRunnerdBackend(input: {
|
||||
managedAiCredentialHome?: string;
|
||||
managedAiCredentialIdentity?: string;
|
||||
managedAiAccountIdentity?: string;
|
||||
/** The Google account of an Antigravity subscription grant (Runner compares only its digest). */
|
||||
managedAiAccountEmail?: string;
|
||||
managedAiCredentialWriteback?: ManagedAiCredentialWritebackBinding;
|
||||
onTaskDispatched?: () => Promise<void> | void;
|
||||
runnerExecutionTarget?: AdapterExecutionTarget | null;
|
||||
@@ -18615,7 +18619,7 @@ async function createRunnerdBackendWithinSessionClaim(
|
||||
if (grokCredential) effectiveRunnerEnvironmentBase = grokCredential.environment;
|
||||
const antigravityCredential = isAntigravity ? await prepareAntigravityRunnerCredentials({
|
||||
environment: effectiveRunnerEnvironmentBase, remote: Boolean(remoteTarget), managedHome: input.managedAiCredentialHome,
|
||||
lifecycleMode: input.execution.session.lifecyclePolicy.mode,
|
||||
lifecycleMode: input.execution.session.lifecyclePolicy.mode, accountEmail: input.managedAiAccountEmail,
|
||||
}) : null;
|
||||
if (antigravityCredential) effectiveRunnerEnvironmentBase = antigravityCredential.environment;
|
||||
// The server-held tool authority owns this credential. Do not deliver a
|
||||
|
||||
Reference in new issue
Block a user