Skip to content
Closed
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
1 change: 1 addition & 0 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"diff": "8.0.3",
"effect": "catalog:",
"ffi-rs": "1.3.2",
"koffi": "3.3.6",
"node-pty": "^1.2.0-beta.15",
"playwright-core": "1.64.1",
"proper-lockfile": "4.1.2",
Expand Down
18 changes: 18 additions & 0 deletions apps/server/scripts/acp-mock-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ import * as AcpError from "effect-acp/errors";
import * as AcpSchema from "effect-acp/schema";
import type * as AcpCompat from "effect-acp/compat";

import { startDetachedCommand } from "./acpMockDetachedCommand.ts";

import { beginAcpMockPrompt } from "./acpMockCancellationState.ts";

const requestLogPath = process.env.T3_ACP_REQUEST_LOG_PATH;
const detachedReceipt = process.env.T3_ACP_DETACHED_COMMAND_RECEIPT;
const antigravityProfile = process.env.T3_ACP_ANTIGRAVITY === "1";
// GitHub Copilot CLI advertises URL-shaped session mode ids.
const copilotModesProfile = process.env.T3_ACP_COPILOT_MODES === "1";
Expand Down Expand Up @@ -888,6 +891,21 @@ const program = Effect.gen(function* () {
}
beginAcpMockPrompt(cancelledSessions, requestedSessionId);
promptCount += 1;
if (detachedReceipt !== undefined) {
yield* Effect.promise(() => startDetachedCommand(detachedReceipt));
yield* agent.client.sessionUpdate({
sessionId: requestedSessionId,
update: {
sessionUpdate: "tool_call_update",
toolCallId: "watcher",
title: "Running run_command",
kind: "execute",
status: "in_progress",
rawInput: { CommandLine: "sleep 53" },
},
});
return yield* finishPrompt(requestedSessionId, "end_turn");
}
if (idleError === "grok-background" && promptCount === 1) {
// The structured completion lands before the prompt settles, so it is buffered.
const taskId = "call-idle-error-background";
Expand Down
74 changes: 74 additions & 0 deletions apps/server/scripts/acpMockDetachedCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// @effect-diagnostics nodeBuiltinImport:off -- the fixture captures real Linux process identities.
import * as NodeChildProcess from "node:child_process";
import * as NodeFS from "node:fs";
import * as NodeReadline from "node:readline";
import * as NodeURL from "node:url";

const identity = (pid: number | undefined) => {
if (pid === undefined) throw new Error("Command did not spawn");
const stat = NodeFS.readFileSync(`/proc/${pid}/stat`, "utf8");
const fields = stat
.slice(stat.lastIndexOf(")") + 2)
.trim()
.split(/\s+/);
return {
pid,
ppid: Number(fields[1]),
pgid: Number(fields[2]),
sid: Number(fields[3]),
startTime: fields[19],
};
};

const writeReceipt = (
pidFile: string,
receipt: { processes: Array<ReturnType<typeof identity>> },
) => {
NodeFS.writeFileSync(`${pidFile}.tmp`, JSON.stringify(receipt));
NodeFS.renameSync(`${pidFile}.tmp`, pidFile);
};

if (process.argv[2] === "command") {
const pidFile = process.argv[3];
if (pidFile === undefined) throw new Error("Missing process receipt path");
const sleep = NodeChildProcess.spawn("/bin/sleep", ["53"], { stdio: "ignore" });
await new Promise<void>((resolve, reject) => {
sleep.once("spawn", resolve);
sleep.once("error", reject);
});
const receipt = {
processes: [identity(process.ppid), identity(process.pid), identity(sleep.pid)],
};
writeReceipt(pidFile, receipt);
process.stdout.on("error", (error: NodeJS.ErrnoException) => {
if (error.code !== "EPIPE") throw error;
});
process.stdout.write(JSON.stringify(receipt) + "\n");
await new Promise<void>((resolve) => sleep.once("exit", () => resolve()));
process.exit(0);
}

// Readiness follows the command's atomic receipt, independently of the ACP reader.
export async function startDetachedCommand(pidFile: string) {
const shell = NodeChildProcess.spawn(
"/bin/sh",
[
"-c",
'read -r start || exit 0; "$1" "$2" command "$3" & wait',
"fixture",
process.execPath,
NodeURL.fileURLToPath(import.meta.url),
pidFile,
],
{ detached: true, stdio: ["pipe", "pipe", "ignore"] },
);
writeReceipt(pidFile, { processes: [identity(shell.pid)] });
shell.stdin.end("start\n");
const lines = NodeReadline.createInterface({ input: shell.stdout });
try {
const ready = await lines[Symbol.asyncIterator]().next();
if (ready.done) throw new Error("Command exited before acknowledging child readiness");
} finally {
lines.close();
}
}
Loading
Loading