diff --git a/apps/server/scripts/acp-mock-agent.mjs b/apps/server/scripts/acp-mock-agent.mjs deleted file mode 100644 index d7320b929e..0000000000 --- a/apps/server/scripts/acp-mock-agent.mjs +++ /dev/null @@ -1,315 +0,0 @@ -#!/usr/bin/env node -/** - * Minimal NDJSON JSON-RPC "agent" for ACP client tests. - * Reads stdin lines; writes responses/notifications to stdout. - */ -import * as readline from "node:readline"; -import { appendFileSync } from "node:fs"; - -const rl = readline.createInterface({ input: process.stdin, crlfDelay: Infinity }); -const requestLogPath = process.env.T3_ACP_REQUEST_LOG_PATH; -const emitToolCalls = process.env.T3_ACP_EMIT_TOOL_CALLS === "1"; -const sessionId = "mock-session-1"; -let currentModeId = "ask"; -let currentModelId = "auto"; -let nextRequestId = 1; - -function configOptions() { - return [ - { - id: "model", - name: "Model", - category: "model", - type: "select", - currentValue: currentModelId, - options: [ - { value: "auto", name: "Auto" }, - { value: "composer-2", name: "Composer 2" }, - { value: "composer-2-fast", name: "Composer 2 Fast" }, - { value: "gpt-5.3-codex", name: "Codex 5.3" }, - ], - }, - ]; -} - -const availableModes = [ - { - id: "ask", - name: "Ask", - description: "Request permission before making any changes", - }, - { - id: "architect", - name: "Architect", - description: "Design and plan software systems without implementation", - }, - { - id: "code", - name: "Code", - description: "Write and modify code with full tool access", - }, -]; -const pendingPermissionRequests = new Map(); - -function send(obj) { - process.stdout.write(`${JSON.stringify(obj)}\n`); -} - -function modeState() { - return { - currentModeId, - availableModes, - }; -} - -function sendSessionUpdate(update, session = sessionId) { - send({ - jsonrpc: "2.0", - method: "session/update", - params: { - sessionId: session, - update, - }, - }); -} - -rl.on("line", (line) => { - const trimmed = line.trim(); - if (!trimmed) return; - let msg; - try { - msg = JSON.parse(trimmed); - } catch { - return; - } - if (!msg || typeof msg !== "object") return; - if (requestLogPath) { - appendFileSync(requestLogPath, `${JSON.stringify(msg)}\n`, "utf8"); - } - - const id = msg.id; - const method = msg.method; - - if (method === undefined && id !== undefined && pendingPermissionRequests.has(id)) { - const pending = pendingPermissionRequests.get(id); - pendingPermissionRequests.delete(id); - sendSessionUpdate( - { - sessionUpdate: "tool_call_update", - toolCallId: pending.toolCallId, - title: "Terminal", - kind: "execute", - status: "completed", - rawOutput: { - exitCode: 0, - stdout: '{ "name": "t3" }', - stderr: "", - }, - }, - pending.sessionId, - ); - sendSessionUpdate( - { - sessionUpdate: "agent_message_chunk", - content: { type: "text", text: "hello from mock" }, - }, - pending.sessionId, - ); - send({ - jsonrpc: "2.0", - id: pending.promptRequestId, - result: { stopReason: "end_turn" }, - }); - return; - } - - if (method === "initialize" && id !== undefined) { - send({ - jsonrpc: "2.0", - id, - result: { - protocolVersion: 1, - agentCapabilities: { loadSession: true }, - }, - }); - return; - } - - if (method === "authenticate" && id !== undefined) { - send({ jsonrpc: "2.0", id, result: { authenticated: true } }); - return; - } - - if (method === "session/new" && id !== undefined) { - send({ - jsonrpc: "2.0", - id, - result: { - sessionId, - modes: modeState(), - configOptions: configOptions(), - }, - }); - return; - } - - if (method === "session/load" && id !== undefined) { - const requestedSessionId = msg.params?.sessionId ?? sessionId; - sendSessionUpdate( - { - sessionUpdate: "user_message_chunk", - content: { type: "text", text: "replay" }, - }, - requestedSessionId, - ); - send({ - jsonrpc: "2.0", - id, - result: { - modes: modeState(), - configOptions: configOptions(), - }, - }); - return; - } - - if (method === "session/set_config_option" && id !== undefined) { - const configId = msg.params?.configId; - const value = msg.params?.value; - if (configId === "model" && typeof value === "string") { - currentModelId = value; - } - send({ - jsonrpc: "2.0", - id, - result: { configOptions: configOptions() }, - }); - return; - } - - if (method === "session/prompt" && id !== undefined) { - const requestedSessionId = msg.params?.sessionId ?? sessionId; - if (emitToolCalls) { - const toolCallId = "tool-call-1"; - const permissionRequestId = nextRequestId++; - sendSessionUpdate( - { - sessionUpdate: "tool_call", - toolCallId, - title: "Terminal", - kind: "execute", - status: "pending", - rawInput: { - command: ["cat", "server/package.json"], - }, - }, - requestedSessionId, - ); - sendSessionUpdate( - { - sessionUpdate: "tool_call_update", - toolCallId, - status: "in_progress", - }, - requestedSessionId, - ); - pendingPermissionRequests.set(permissionRequestId, { - promptRequestId: id, - sessionId: requestedSessionId, - toolCallId, - }); - send({ - jsonrpc: "2.0", - id: permissionRequestId, - method: "session/request_permission", - params: { - sessionId: requestedSessionId, - toolCall: { - toolCallId, - title: "`cat server/package.json`", - kind: "execute", - status: "pending", - content: [ - { - type: "content", - content: { - type: "text", - text: "Not in allowlist: cat server/package.json", - }, - }, - ], - }, - options: [ - { optionId: "allow-once", name: "Allow once", kind: "allow_once" }, - { optionId: "allow-always", name: "Allow always", kind: "allow_always" }, - { optionId: "reject-once", name: "Reject", kind: "reject_once" }, - ], - }, - }); - return; - } - sendSessionUpdate( - { - sessionUpdate: "plan", - explanation: `Mock plan while in ${currentModeId}`, - entries: [ - { - content: "Inspect mock ACP state", - priority: "high", - status: "completed", - }, - { - content: "Implement the requested change", - priority: "high", - status: "in_progress", - }, - ], - }, - requestedSessionId, - ); - sendSessionUpdate( - { - sessionUpdate: "agent_message_chunk", - content: { type: "text", text: "hello from mock" }, - }, - requestedSessionId, - ); - send({ - jsonrpc: "2.0", - id, - result: { stopReason: "end_turn" }, - }); - return; - } - - if ((method === "session/set_mode" || method === "session/mode/set") && id !== undefined) { - const nextModeId = - typeof msg.params?.modeId === "string" - ? msg.params.modeId - : typeof msg.params?.mode === "string" - ? msg.params.mode - : undefined; - if (typeof nextModeId === "string" && nextModeId.trim()) { - currentModeId = nextModeId.trim(); - sendSessionUpdate({ - sessionUpdate: "current_mode_update", - currentModeId, - }); - } - send({ jsonrpc: "2.0", id, result: null }); - return; - } - - if (method === "session/cancel" && id !== undefined) { - send({ jsonrpc: "2.0", id, result: null }); - return; - } - - if (id !== undefined) { - send({ - jsonrpc: "2.0", - id, - error: { code: -32601, message: `Unhandled method: ${String(method)}` }, - }); - } -}); diff --git a/apps/server/scripts/cursor-acp-model-selection-probe.ts b/apps/server/scripts/cursor-acp-model-selection-probe.ts deleted file mode 100644 index 992502ae1e..0000000000 --- a/apps/server/scripts/cursor-acp-model-selection-probe.ts +++ /dev/null @@ -1,140 +0,0 @@ -import * as os from "node:os"; -import * as path from "node:path"; -import { chmod, mkdtemp, readFile, writeFile } from "node:fs/promises"; - -import * as NodeServices from "@effect/platform-node/NodeServices"; -import { Effect, Layer } from "effect"; - -import { ThreadId } from "@t3tools/contracts"; -import { resolveCursorDispatchModel } from "@t3tools/shared/model"; - -import { ServerConfig } from "../src/config.ts"; -import { ServerSettingsService } from "../src/serverSettings.ts"; -import { CursorAdapter } from "../src/provider/Services/CursorAdapter.ts"; -import { makeCursorAdapterLive } from "../src/provider/Layers/CursorAdapter.ts"; - -const scriptDir = import.meta.dir; -const mockAgentPath = path.join(scriptDir, "acp-mock-agent.mjs"); - -function parseArgs(argv: string[]) { - const args = new Map(); - for (let index = 0; index < argv.length; index += 1) { - const token = argv[index]; - if (!token?.startsWith("--")) continue; - const key = token.slice(2); - const next = argv[index + 1]; - if (!next || next.startsWith("--")) { - args.set(key, true); - continue; - } - args.set(key, next); - index += 1; - } - return args; -} - -async function makeProbeWrapper(requestLogPath: string, argvLogPath: string) { - const dir = await mkdtemp(path.join(os.tmpdir(), "cursor-acp-probe-script-")); - const wrapperPath = path.join(dir, "fake-agent.sh"); - const script = `#!/bin/sh -printf '%s\n' "$@" > ${JSON.stringify(argvLogPath)} -export T3_ACP_REQUEST_LOG_PATH=${JSON.stringify(requestLogPath)} -exec ${JSON.stringify(process.execPath)} ${JSON.stringify(mockAgentPath)} "$@" -`; - await writeFile(wrapperPath, script, "utf8"); - await chmod(wrapperPath, 0o755); - return wrapperPath; -} - -async function readJsonLines(filePath: string) { - const raw = await readFile(filePath, "utf8"); - return raw - .split("\n") - .map((line) => line.trim()) - .filter((line) => line.length > 0) - .map((line) => JSON.parse(line) as Record); -} - -const cliArgs = parseArgs(process.argv.slice(2)); -const model = - typeof cliArgs.get("model") === "string" ? String(cliArgs.get("model")) : "composer-2"; -const fastMode = cliArgs.get("fast") === true; - -const layer = makeCursorAdapterLive().pipe( - Layer.provideMerge(ServerSettingsService.layerTest()), - Layer.provideMerge(ServerConfig.layerTest(process.cwd(), process.cwd())), - Layer.provideMerge(NodeServices.layer), -); - -const program = Effect.gen(function* () { - const adapter = yield* CursorAdapter; - const serverSettings = yield* ServerSettingsService; - const tempDir = yield* Effect.promise(() => mkdtemp(path.join(os.tmpdir(), "cursor-acp-probe-"))); - const requestLogPath = path.join(tempDir, "requests.ndjson"); - const argvLogPath = path.join(tempDir, "argv.txt"); - yield* Effect.promise(() => writeFile(requestLogPath, "", "utf8")); - const wrapperPath = yield* Effect.promise(() => makeProbeWrapper(requestLogPath, argvLogPath)); - const threadId = ThreadId.makeUnsafe("cursor-acp-model-selection-probe"); - const cursorModelOptions = fastMode ? { fastMode: true as const } : undefined; - const dispatchedModel = resolveCursorDispatchModel(model, cursorModelOptions); - - yield* serverSettings.updateSettings({ providers: { cursor: { binaryPath: wrapperPath } } }); - - yield* adapter.startSession({ - threadId, - provider: "cursor", - cwd: process.cwd(), - runtimeMode: "full-access", - modelSelection: { - provider: "cursor", - model, - ...(cursorModelOptions ? { options: cursorModelOptions } : {}), - }, - }); - - yield* adapter.sendTurn({ - threadId, - input: "first turn with initial model", - attachments: [], - }); - - yield* adapter.sendTurn({ - threadId, - input: "second turn after model switch", - attachments: [], - modelSelection: { - provider: "cursor", - model: "composer-2", - options: { fastMode: true }, - }, - }); - - yield* adapter.stopSession(threadId); - - const argv = (yield* Effect.promise(() => readFile(argvLogPath, "utf8"))) - .split("\n") - .map((line) => line.trim()) - .filter((line) => line.length > 0); - const requests = yield* Effect.promise(() => readJsonLines(requestLogPath)); - const setConfigRequests = requests.filter( - (entry) => entry.method === "session/set_config_option", - ); - const promptRequests = requests.filter((entry) => entry.method === "session/prompt"); - - return { - input: { model, fastMode }, - dispatchedModel, - spawnedArgv: argv, - acpMethods: requests - .map((entry) => entry.method) - .filter((method): method is string => typeof method === "string"), - setConfigRequests: setConfigRequests.map((r) => r.params), - promptCount: promptRequests.length, - sessionRestartCount: requests.filter((entry) => entry.method === "session/new").length, - conclusion: - "Model switching uses session/set_config_option (in-session). No session restart needed.", - }; -}).pipe(Effect.provide(layer)); - -const result = await Effect.runPromise(program); -process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);