mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 01:39:51 +01:00
fix(antigravity): stop a swarm on a visible edit outside the task folder; stable record identity
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b004539d5e
commit
540b8decbb
3 files changed
+44
-2
No files matched your search
@@ -158,6 +158,18 @@ describe("Antigravity CLI swarm runtime", () => {
|
||||
await runtime.close({ reason: "done" });
|
||||
});
|
||||
|
||||
it("stops the swarm when a visible edit targets a file outside the task folder", async () => {
|
||||
const run = await runTurn("outside-edit");
|
||||
expect(run.result).toMatchObject({ status: "failed", error: { code: "ANTIGRAVITY_SWARM_WORKSPACE_ESCAPE" } });
|
||||
});
|
||||
|
||||
it("keeps a stable record identity while the CLI session id is per run", async () => {
|
||||
const { options } = setup("success");
|
||||
const runtime = await openAntigravitySwarmRuntime(options);
|
||||
expect((await runtime.identity()).acpxRecordId).toBe("antigravity-cli:key");
|
||||
await runtime.close({ reason: "done" });
|
||||
});
|
||||
|
||||
it("refuses a helper on its own workspace copy", async () => {
|
||||
const run = await runTurn("escape");
|
||||
expect(run.result).toMatchObject({ status: "failed", error: { code: "ANTIGRAVITY_SWARM_WORKSPACE_ESCAPE" } });
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ChildProcess, ChildProcessWithoutNullStreams } from "node:child_process";
|
||||
import { lstat, readdir } from "node:fs/promises";
|
||||
import { join, relative, sep } from "node:path";
|
||||
import { isAbsolute, join, relative, sep } from "node:path";
|
||||
import type { AcpRuntimeEvent, AcpRuntimeTurnResult } from "acpx/runtime";
|
||||
import { retireAntigravityProcess } from "./antigravity-process.js";
|
||||
import {
|
||||
@@ -211,6 +211,23 @@ function changedFiles(before: Map<string, string>, after: Map<string, string>):
|
||||
return [...changed, ...removed].sort();
|
||||
}
|
||||
|
||||
/**
|
||||
* A visible edit, delete or move whose location is outside the task folder.
|
||||
* Only the coordinator's calls reach the client; helper calls are confined by
|
||||
* the CLI's auto mode and are not visible here.
|
||||
*/
|
||||
function outsideEdit(update: Json, workspace: string): string | null {
|
||||
if (update.sessionUpdate !== "tool_call" && update.sessionUpdate !== "tool_call_update") return null;
|
||||
if (!["edit", "delete", "move"].includes(String(update.kind))) return null;
|
||||
const locations = Array.isArray(update.locations) ? update.locations.map(record) : [];
|
||||
for (const location of locations) {
|
||||
if (typeof location.path !== "string" || !isAbsolute(location.path)) continue;
|
||||
const inside = relative(workspace, location.path);
|
||||
if (inside.startsWith("..") || isAbsolute(inside)) return location.path;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function addUsage(total: Json | null, usage: unknown): Json | null {
|
||||
const value = record(usage);
|
||||
if (Object.keys(value).length === 0) return total;
|
||||
@@ -371,6 +388,12 @@ export async function openAntigravitySwarmRuntime(
|
||||
`Swarm stopped: helper ${escaped} was asked to work on its own copy of the task folder, which Paperclip does not allow.`));
|
||||
return;
|
||||
}
|
||||
const outside = outsideEdit(update, workspace);
|
||||
if (outside) {
|
||||
halt(new AntigravitySwarmError("ANTIGRAVITY_SWARM_WORKSPACE_ESCAPE",
|
||||
`Swarm stopped: it tried to change ${outside}, which is outside the task folder.`));
|
||||
return;
|
||||
}
|
||||
const args = { ...record(update.rawInput), ...record(update.args) };
|
||||
if (update.sessionUpdate === "tool_call" && update.name === "swarm" && args.action === "add" && typeof args.name === "string") {
|
||||
helpers.set(args.name, typeof args.brief === "string" ? args.brief : "");
|
||||
@@ -481,7 +504,8 @@ export async function openAntigravitySwarmRuntime(
|
||||
|
||||
const port: AcpxRuntimePort = {
|
||||
async identity(): Promise<AcpxRuntimePortIdentity> {
|
||||
return { mode: ANTIGRAVITY_SWARM_MODE, acpxRecordId: `antigravity-cli-${sessionId}`, backendSessionId: sessionId, agentSessionId: sessionId };
|
||||
// The record is stable per provider session key; the CLI session id is per run and never reloaded.
|
||||
return { mode: ANTIGRAVITY_SWARM_MODE, acpxRecordId: `antigravity-cli:${options.providerSessionKey}`, backendSessionId: sessionId, agentSessionId: sessionId };
|
||||
},
|
||||
async getStatus(): Promise<AcpxModelStatus> {
|
||||
return { ...structuredClone(status), models: { currentModelId: model, availableModelIds: [model] } };
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
// hang-helpers the follow-up wait never ends
|
||||
// mode-flip the CLI switches back to default mode right after the model is set
|
||||
// mode-flip-idle the CLI switches back to default mode after the session opened, between turns
|
||||
// outside-edit the coordinator edits a file outside the workspace
|
||||
// cautious-brief a helper brief says "Do not create debug.log"; the run is correct
|
||||
// FAKE_AGY_LOG (optional) appends every client message, one JSON per line.
|
||||
import { spawn } from "node:child_process";
|
||||
@@ -74,6 +75,11 @@ async function prompt(id, params) {
|
||||
update(state.sessionId, { sessionUpdate: "session_info_update", title: "Swarm" });
|
||||
if (scenario === "refusal") { say("\n⚠ agent executor error: Error 402 Your prepayment credits are depleted. Status: RESOURCE_EXHAUSTED\n"); return write({ jsonrpc: "2.0", id, result: { stopReason: "end_turn" } }); }
|
||||
if (scenario === "quota") { say("\n⚠ RESOURCE_EXHAUSTED (code 429): Resource has been exhausted (e.g. check quota).\n"); return write({ jsonrpc: "2.0", id, result: { stopReason: "end_turn" } }); }
|
||||
if (scenario === "outside-edit") {
|
||||
update(state.sessionId, { sessionUpdate: "tool_call", toolCallId: "call_out", name: "write_file", kind: "edit", status: "in_progress", title: "Write /etc/elsewhere.txt", locations: [{ path: "/etc/elsewhere.txt" }] });
|
||||
if (!state.cancelled) await new Promise(resolve => { state.cancel = resolve; });
|
||||
return write({ jsonrpc: "2.0", id, result: { stopReason: "cancelled" } });
|
||||
}
|
||||
if (scenario === "escape") { await tool("swarm", { action: "add", name: "writer-a", workspace: "branch", brief: "Write a.txt." }); if (!state.cancelled) await new Promise(resolve => { state.cancel = resolve; }); return write({ jsonrpc: "2.0", id, result: { stopReason: "end_turn" } }); }
|
||||
await addWriters();
|
||||
say("I have configured and launched the swarm.\n\nRun /swarm board (default shortcut alt+s) to open the live board.");
|
||||
|
||||
Reference in new issue
Block a user