mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-22 20:29:18 +01:00
fix(acpx): decouple host proxy spawn cwd from in-sandbox remoteCwd (#10122)
This commit is contained in:
1 parent
e41ba306c5
commit
b517b887ad
6 files changed
+356
-37
No files matched your search
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env node
|
||||
// A minimal ACP agent fixture that reports, on its stderr, the working
|
||||
// directory the host actually spawned it in (`process.cwd()`) and the `cwd`
|
||||
// advertised on the `session/new` request. Used by the remote-lane host-spawn
|
||||
// smoke test to prove the `spawnCwd` decoupling: the host `spawn()` chdir is
|
||||
// redirected to a host-valid dir while the advertised session cwd is unchanged.
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { createInterface } from "node:readline";
|
||||
|
||||
function writeMessage(message) {
|
||||
process.stdout.write(`${JSON.stringify(message)}\n`);
|
||||
}
|
||||
|
||||
// Emit the real spawn cwd as early as possible so a consumer capturing stderr
|
||||
// sees it even if the session never advances past initialize.
|
||||
process.stderr.write(`SPAWN_CWD=${process.cwd()}\n`);
|
||||
|
||||
async function handleRequest(request) {
|
||||
if (request.method === "initialize") {
|
||||
process.stderr.write("paperclip-acp-cwd-report-agent started\n");
|
||||
return {
|
||||
protocolVersion: 1,
|
||||
agentCapabilities: { loadSession: false, sessionCapabilities: { close: {} } },
|
||||
agentInfo: { name: "paperclip-acp-cwd-report-agent", version: "1.0.0" },
|
||||
};
|
||||
}
|
||||
if (request.method === "session/new") {
|
||||
process.stderr.write(`SESSION_NEW_CWD=${request.params?.cwd ?? ""}\n`);
|
||||
return { sessionId: randomUUID() };
|
||||
}
|
||||
if (request.method === "session/prompt") {
|
||||
writeMessage({
|
||||
jsonrpc: "2.0",
|
||||
method: "session/update",
|
||||
params: {
|
||||
sessionId: request.params.sessionId,
|
||||
update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text: "ok" } },
|
||||
},
|
||||
});
|
||||
return { stopReason: "end_turn" };
|
||||
}
|
||||
if (request.method === "session/close" || request.method === "session/set_mode" || request.method === "session/set_config_option") return {};
|
||||
if (request.method === "session/cancel") return null;
|
||||
throw new Error(`Unsupported ACP method: ${request.method}`);
|
||||
}
|
||||
|
||||
const lines = createInterface({ input: process.stdin });
|
||||
lines.on("line", async (line) => {
|
||||
let request;
|
||||
try {
|
||||
request = JSON.parse(line);
|
||||
const result = await handleRequest(request);
|
||||
if (request.id !== undefined && result !== null) writeMessage({ jsonrpc: "2.0", id: request.id, result });
|
||||
} catch (error) {
|
||||
if (request?.id !== undefined) {
|
||||
writeMessage({ jsonrpc: "2.0", id: request.id, error: { code: -32603, message: String(error?.message ?? error) } });
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user