Compare commits

..
2 changed files with 160 additions and 0 deletions
@@ -0,0 +1,56 @@
import { test, expect } from "vitest";
import { mkdtemp, rm } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { createDaemonTestContext } from "../test-utils/index.js";
test("reports the provider's thinking level after an explicit live ACP mode change", async () => {
const root = await mkdtemp(path.join(os.tmpdir(), "paseo-acp-live-mode-"));
const options = {
paseoHomeRoot: root,
staticDir: path.join(root, "static"),
cleanup: false,
mcpEnabled: false,
pluginsEnabled: false,
providerOverrides: {
"thinking-fixture": {
extends: "acp" as const,
label: "Thinking fixture",
env: { ACP_TEST_LOAD_MODEL: "second-model", ACP_TEST_SAVED_MODE: "plan" },
command: [
process.execPath,
path.join(import.meta.dirname, "acp-thinking-resume-fixture.cjs"),
],
},
},
};
try {
const first = await createDaemonTestContext(options);
let agentId: string;
try {
const agent = await first.client.createAgent({
provider: "thinking-fixture",
cwd: root,
model: "second-model",
modeId: "agent",
thinkingOptionId: "low",
});
agentId = agent.id;
} finally {
await first.cleanup();
}
const reopened = await createDaemonTestContext(options);
try {
await reopened.client.fetchAgentTimeline(agentId, { limit: 40 });
const before = (await reopened.client.fetchAgent(agentId))?.agent.runtimeInfo;
expect(before).toMatchObject({ modeId: "agent", thinkingOptionId: "low" });
await reopened.client.setAgentMode(agentId, "plan");
const after = (await reopened.client.fetchAgent(agentId))?.agent.runtimeInfo;
expect(after).toMatchObject({ modeId: "plan", thinkingOptionId: "high" });
} finally {
await reopened.cleanup();
}
} finally {
await rm(root, { recursive: true, force: true });
}
}, 60_000);
@@ -0,0 +1,104 @@
// ACP peer that accepts a thinking level on creation but rejects it after load.
const readline = require("node:readline");
const sessionId = "thinking-resume-session";
let model = "startup-model";
let effort = "low";
let mode = "agent";
let loaded = false;
const send = (message) =>
process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\n");
function select(id, category, currentValue, values) {
return {
id,
name: id,
category,
type: "select",
currentValue,
options: values.map((value) => ({ value, name: value })),
};
}
function configOptions() {
return [
select("mode", "mode", mode, ["agent", "plan"]),
select("model", "model", model, ["startup-model", "second-model"]),
select(
"effort",
"thought_level",
effort,
loaded && model === "second-model"
? ["minimal", "low", "medium", "high", "xhigh"]
: ["low", "high", "max"],
),
];
}
function assistantMessage(text) {
send({
method: "session/update",
params: {
sessionId,
update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text } },
},
});
}
readline.createInterface({ input: process.stdin }).on("line", (line) => {
const { id, method, params } = JSON.parse(line);
if (id === undefined) return;
let result;
switch (method) {
case "initialize":
result = {
protocolVersion: 1,
agentCapabilities: { loadSession: true, sessionCapabilities: { close: {} } },
};
break;
case "session/new":
result = { sessionId, configOptions: configOptions() };
break;
case "session/load":
loaded = true;
model = process.env.ACP_TEST_LOAD_MODEL;
effort = model === "second-model" && !process.env.ACP_TEST_SAVED_MODE ? "high" : "low";
assistantMessage("Response from the saved session");
result = { configOptions: configOptions() };
break;
case "session/set_config_option":
if (params.configId === "model") {
model = params.value;
if (loaded && model === "second-model") effort = "high";
} else if (params.configId === "mode") {
mode = params.value;
if (loaded && mode === process.env.ACP_TEST_SAVED_MODE) effort = "high";
} else if (loaded && params.value === "max") {
send({
id,
error: {
code: -32602,
message: "Invalid params",
data: "This model does not support that thinking level",
},
});
return;
} else {
effort = params.value;
}
result = { configOptions: configOptions() };
break;
case "session/prompt":
assistantMessage("Response from the saved session");
result = { stopReason: "end_turn" };
break;
case "session/close":
result = {};
break;
default:
send({ id, error: { code: -32601, message: "Method not found" } });
return;
}
send({ id, result });
});