#!/usr/bin/env node import process from "node:process"; import readline from "node:readline"; const args = process.argv.slice(2); if (args.includes("about")) { process.stdout.write( `${JSON.stringify({ cliVersion: "tutti-perf-fixture", subscriptionTier: "Fixture", userEmail: "performance-fixture@localhost" })}\n` ); } else if (args.includes("--version") || args.includes("version")) { process.stdout.write("cursor-agent tutti-perf-fixture\n"); } else if (args.includes("acp")) { runACPFixture(); } else { process.stdout.write("Logged in as performance-fixture@localhost\n"); } function runACPFixture() { const input = readline.createInterface({ input: process.stdin }); let canceled = false; let activeSessionId = "tutti-perf-cursor-session"; input.on("line", (line) => { void handleMessage(line).catch((error) => { process.stderr.write(`${error.stack ?? error.message}\n`); process.exitCode = 1; }); }); async function handleMessage(line) { const message = JSON.parse(line); switch (message.method) { case "initialize": respond(message.id, { protocolVersion: 1, agentInfo: { name: "tutti-perf-cursor", title: "Tutti Perf Cursor" }, agentCapabilities: { loadSession: true } }); return; case "session/new": activeSessionId = message.params?.sessionId?.trim?.() || activeSessionId; respond(message.id, { configOptions: [], sessionId: activeSessionId }); return; case "session/load": case "session/resume": activeSessionId = message.params?.sessionId?.trim?.() || activeSessionId; respond(message.id, { configOptions: [] }); return; case "session/set_mode": case "session/set_config_option": respond(message.id, { configOptions: [] }); return; case "session/cancel": canceled = true; return; case "session/prompt": activeSessionId = message.params?.sessionId?.trim?.() || activeSessionId; canceled = false; await streamPrompt(message.id, fixtureExpectedToken(message.params)); return; default: if (message.id !== undefined) { write({ jsonrpc: "2.0", id: message.id, error: { code: -32601, message: `method not found: ${message.method}` } }); } } } async function streamPrompt(promptID, expectedToken) { const oversizedToolCallCount = Number.parseInt( process.env.TUTTI_PERF_OVERSIZED_TOOL_CALLS ?? "", 10 ); if (Number.isFinite(oversizedToolCallCount) && oversizedToolCallCount > 0) { await streamOversizedToolCalls(promptID, oversizedToolCallCount); return; } for (let index = 0; index < 48 && !canceled; index += 1) { notify("session/update", { sessionId: activeSessionId, update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text: `Virtualized streaming fixture chunk ${String(index + 1).padStart(2, "0")}: ${"layout-safe-content ".repeat(8)}\n\n` } } }); await new Promise((resolve) => setTimeout(resolve, 30)); } if (expectedToken && !canceled) { notify("session/update", { sessionId: activeSessionId, update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text: expectedToken } } }); } respond(promptID, { stopReason: canceled ? "canceled" : "end_turn" }); } async function streamOversizedToolCalls(promptID, toolCallCount) { for (let index = 0; index < toolCallCount && !canceled; index += 1) { const toolCallId = `tutti-perf-oversized-tool-${index}`; const title = `Inspect fixture path ${index + 1}`; notify("session/update", { sessionId: activeSessionId, update: { sessionUpdate: "tool_call", toolCallId, title, kind: "execute", status: "pending", rawInput: { command: `printf oversized-tool-${index + 1}` } } }); notify("session/update", { sessionId: activeSessionId, update: { sessionUpdate: "tool_call_update", toolCallId, title, kind: "execute", status: "completed", rawOutput: { output: `oversized tool ${index + 1} completed` } } }); await new Promise((resolve) => setTimeout(resolve, 12)); } for (let index = 0; index < 100 && !canceled; index += 1) { await new Promise((resolve) => setTimeout(resolve, 100)); } respond(promptID, { stopReason: canceled ? "canceled" : "end_turn" }); } } function fixtureExpectedToken(params) { const prefix = "Reply with exactly this text: "; const text = collectText(params?.prompt ?? params?.content); const index = text.indexOf(prefix); return index < 0 ? "" : text.slice(index + prefix.length).trim(); } function collectText(value) { if (typeof value === "string") return value; if (Array.isArray(value)) return value.map(collectText).join(""); if (!value || typeof value !== "object") return ""; if (typeof value.text === "string") return value.text; return Object.values(value).map(collectText).join(""); } function respond(id, result) { write({ jsonrpc: "2.0", id, result }); } function notify(method, params) { write({ jsonrpc: "2.0", method, params }); } function write(value) { process.stdout.write(`${JSON.stringify(value)}\n`); }