Official

acp

ACP agents from the ACP registry (Gemini, Cursor, Droid, Kilo, pi, ...), Oh My Pi, and your own entries (custom.json in the plugin's data folder). Agents are discovered at runtime.

The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/acp@0.2.4

Permissions in 0.2.4

Take care. This plugin asks for permissions that can do anything your account can. The app asks you to hold Enable for two seconds or to type the plugin's name before it turns on.
  • Run any command process.anyDangerousStarts any program or shell command. This is as strong as your own account.Start the ACP agents, which the registry launches by path or through package runners such as npx and uvx, and run the terminal commands an agent asks for
  • Provide agents agents.provideMediumAdds agents to the app.Provide the agents of the ACP registry, and serve plugin tools to them through the host's loopback MCP server
  • Network access netMediumConnects to the listed hosts.Download the ACP registry and the agents' marks once a dayHosts: cdn.agentclientprotocol.com
  • Read files fs.readMediumReads files in the listed places.Read the files an agent asks for (ACP fs/read_text_file), only inside the chat's workspace, and your own agents from custom.json in this plugin's data folderPlaces: the open workspaceits own data folder
  • Write files fs.writeMediumCreates, changes and deletes files in the listed places.Write the files an agent asks to write (ACP fs/write_text_file), only inside the chat's workspace, and move the custom agents of the old ACP plugin into custom.json oncePlaces: the open workspaceits own data folder
  • Environment variables envMediumReads the listed environment variables.Sign Grok in with your xAI API key when you set one, and tell which Windows build of an agent to runVariables: XAI_API_KEYPROCESSOR_ARCHITECTURE

Files

v2.test.ts26.2 KB
import { test } from "node:test";
import assert from "node:assert/strict";
import { harness, acpPeer, next, present, replyTo, responseError } from "./testing.ts";
import { settle } from "../sdk/testing.ts";
import type { FakePeer } from "../sdk/testing.ts";
import type { PeerHandler } from "./testing.ts";
import { Session } from "./v2.ts";
import { Replay } from "./replay.ts";

const mode = {
  configId: "mode",
  name: "Mode",
  category: "mode",
  type: "select",
  currentValue: "ask",
  options: [
    {
      groupId: "g",
      name: "Modes",
      options: [
        { value: "ask", name: "Ask" },
        { value: "code", name: "Code" },
      ],
    },
  ],
};
function peer(
  handlers: Record<string, PeerHandler> = {},
  capabilities: Record<string, unknown> = { session: {} },
  authMethods: unknown[] = [],
) {
  return acpPeer({
    init: { protocolVersion: 2, info: { name: "scripted-v2", version: "2.0.0-alpha.16" }, capabilities, authMethods },
    handlers: {
      "session/new": () => ({
        sessionId: "v2",
        configOptions: [mode],
        availableCommands: [
          { type: "command", name: "review", description: "Review", input: { type: "text", hint: "Scope" } },
        ],
      }),
      "session/list": () => ({ sessions: [] }),
      "session/close": () => ({}),
      ...handlers,
    },
  });
}
function send(peer: FakePeer, update: Record<string, unknown>, sessionId = "v2") {
  peer.send({ jsonrpc: "2.0", method: "session/update", params: { sessionId, update } });
}

async function create(script = peer()) {
  const result = harness("test", { peer: script });
  result.agent.sessions.clear();
  result.agent.byLive.clear();
  await result.agent.createSession({ workspace: "/w" });
  return { ...result, peer: present(result.api.peers[0]) };
}

test("v2 negotiation selects v2 shapes, baseline session methods, commands, and config identifiers", async () => {
  const { agent, peer: native } = await create(
    peer({
      "session/set_config_option": (params) => ({ configOptions: [{ ...mode, currentValue: params.value }] }),
    }),
  );
  const init = present(native.received.find((message) => message.method === "initialize"));
  assert.equal(init.params.protocolVersion, 2);
  assert.deepEqual(init.params.capabilities, { elicitation: { form: {}, url: {} } });
  assert.equal((await agent.initialize()).capabilities?.sessionHistory, true);
  assert.equal(agent.optionsSnapshot("v2").find((option) => option.id === "mode")?.choices?.[0]?.group, "Modes");
  assert.equal((await agent.listCommands({ sessionId: "v2" })).commands[0]?.name, "review");
  await agent.setOption({ sessionId: "v2", optionId: "mode", value: "code" });
  assert.deepEqual(native.received.find((message) => message.method === "session/set_config_option")?.params, {
    sessionId: "v2",
    configId: "mode",
    type: "id",
    value: "code",
  });
  assert.equal(
    native.received.some((message) => message.method === "session/set_mode"),
    false,
  );
  await agent.listSessions({ workspace: "/w" });
  await agent.closeSession({ sessionId: "v2" });
  assert.ok(native.received.some((message) => message.method === "session/list"));
  assert.ok(native.received.some((message) => message.method === "session/close"));
});

test("a v2 prompt acknowledgement consumes input and waits for an active-to-idle transition", async () => {
  const {
    agent,
    events,
    peer: native,
  } = await create(
    peer({
      "session/prompt": (_params, message, native) => {
        send(native, { sessionUpdate: "state_update", state: "running" });
        native.reply(message, { messageId: "user-native" });
      },
    }),
  );
  await agent.prompt({
    sessionId: "v2",
    input: {
      blocks: [{ type: "text", text: "Inspect the file." }],
      delivery: { inputId: "i", attemptId: "a", intent: "send" },
    },
  });
  await next(events, "input_consumed");
  assert.equal(
    events.some((event) => event.event === "run_finished"),
    false,
  );
  send(native, { sessionUpdate: "agent_message_chunk", messageId: "answer", content: { type: "text", text: "Done." } });
  send(native, { sessionUpdate: "state_update", state: "idle", stopReason: "end_turn", background: [] });
  await next(events, "run_finished");
  assert.equal(events.filter((event) => event.event === "run_finished").length, 1);
  send(native, { sessionUpdate: "state_update", state: "idle", stopReason: "end_turn", background: [] });
  await settle();
  assert.equal(events.filter((event) => event.event === "run_finished").length, 1);
  assert.equal(
    events.find((event) => event.event === "input_consumed")?.event === "input_consumed"
      ? events.find((event) => event.event === "input_consumed")?.nativeInputId
      : null,
    "user-native",
  );
});

test("v2 completion before acknowledgement is retained and cancellation waits for idle", async () => {
  const early = await create(
    peer({
      "session/prompt": (_params, message, native) => {
        send(native, { sessionUpdate: "state_update", state: "running" });
        send(native, { sessionUpdate: "state_update", state: "idle", stopReason: "max_tokens" });
        native.reply(message, { messageId: "early" });
      },
    }),
  );
  await early.agent.prompt({ sessionId: "v2", input: { blocks: [{ type: "text", text: "Go." }] } });
  await next(early.events, "run_finished");
  assert.ok(early.events.some((event) => event.event === "notice" && event.message.includes("output limit")));
  const cancelled = await create(
    peer({
      "session/prompt": (_params, message, native) => {
        send(native, { sessionUpdate: "state_update", state: "running" });
        native.reply(message, { messageId: "cancel-me" });
      },
      "session/cancel": (_params, _message, native) => {
        send(native, { sessionUpdate: "state_update", state: "idle", stopReason: "cancelled" });
      },
    }),
  );
  await cancelled.agent.prompt({ sessionId: "v2", input: { blocks: [{ type: "text", text: "Go." }] } });
  await settle();
  await cancelled.agent.cancel({ sessionId: "v2" });
  assert.deepEqual((await next(cancelled.events, "run_finished")).outcome, { status: "cancelled" });
  assert.equal(cancelled.api.peers.length, 1);
});

test("v2 errors after insertion fail the run and update authentication without resubmitting", async () => {
  const {
    agent,
    events,
    peer: native,
  } = await create(
    peer({
      "session/prompt": (_params, message, native) => {
        send(native, { sessionUpdate: "state_update", state: "running" });
        native.reply(message, { messageId: "accepted" });
        send(native, {
          sessionUpdate: "state_update",
          state: "idle",
          stopReason: "error",
          error: { code: -32000, message: "Sign in again." },
        });
      },
    }),
  );
  await agent.prompt({ sessionId: "v2", input: { blocks: [{ type: "text", text: "Go." }] } });
  assert.deepEqual((await next(events, "run_finished")).outcome, { status: "failed", message: "Sign in again." });
  assert.equal((await agent.initialize()).status?.state, "auth_required");
  assert.equal(native.received.filter((message) => message.method === "session/prompt").length, 1);
});

test("v2 message entities keep independent identities, timeline positions, and patch metadata", () => {
  const session = new Session();
  session.push({ sessionUpdate: "agent_message_chunk", messageId: "same", content: { type: "text", text: "A" } });
  session.push({ sessionUpdate: "agent_thought", messageId: "same", content: [{ type: "text", text: "Thinking" }] });
  session.push({ sessionUpdate: "agent_message_chunk", messageId: "other", content: { type: "text", text: "B" } });
  session.push({
    sessionUpdate: "agent_message",
    messageId: "same",
    content: [{ type: "text", text: "Replaced" }],
    _meta: { a: { value: 1 }, b: true },
  });
  session.push({ sessionUpdate: "agent_message", messageId: "same", _meta: { a: { next: 2 }, b: null } });
  assert.deepEqual(session.messages.get("agent_message:same")?._meta, { a: { next: 2 } });
  session.push({ sessionUpdate: "agent_message", messageId: "same", content: null });
  session.push({ sessionUpdate: "agent_message_chunk", messageId: "same", content: { type: "text", text: "Final" } });
  assert.deepEqual(
    session
      .finish()
      .map((item) => [item.id, item.role, item.role === "assistant" || item.role === "reasoning" ? item.text : null]),
    [
      ["agent_message:same", "assistant", "Final"],
      ["agent_thought:same", "reasoning", "Thinking"],
      ["agent_message:other", "assistant", "B"],
    ],
  );
});

test("v2 tools are upserts with streamed content, explicit clears, renames, and structured diffs", () => {
  const session = new Session();
  const start = session.push({
    sessionUpdate: "tool_call_content_chunk",
    toolCallId: "t",
    content: { type: "content", content: { type: "text", text: "first" } },
  });
  assert.equal(start[0]?.event, "tool_call_started");
  session.push({
    sessionUpdate: "tool_call_update",
    toolCallId: "t",
    name: "edit",
    title: "Editing",
    rawInput: { path: "/w/a" },
    content: [
      {
        type: "diff",
        changes: [{ operation: "modify", path: "/w/a" }],
        patch: { format: "git_patch", text: "diff --git /w/a /w/a\n" },
      },
    ],
  });
  session.push({
    sessionUpdate: "tool_call_update",
    toolCallId: "t",
    name: "write_file",
    title: "",
    rawInput: null,
    locations: null,
    status: "cancelled",
  });
  const tool = session.finish()[0];
  assert.equal(tool?.role === "tool" ? tool.call.name : null, "write_file");
  assert.equal(tool?.role === "tool" ? tool.call.title : null, "");
  assert.equal(tool?.role === "tool" ? tool.call.input : "missing", null);
  assert.deepEqual(tool?.role === "tool" ? tool.call.content : [], [
    { type: "diff", path: "/w/a", diff: "diff --git /w/a /w/a\n" },
  ]);
  session.push({ sessionUpdate: "tool_call_update", toolCallId: "t", content: null });
  const cleared = session.finish()[0];
  assert.deepEqual(cleared?.role === "tool" ? cleared.call.content : null, []);
});

test("v2 terminal bytes decode independently across split UTF-8 and replace snapshots", () => {
  const session = new Session();
  session.push({
    sessionUpdate: "tool_call_update",
    toolCallId: "shell",
    content: [{ type: "terminal", terminalId: "terminal" }],
  });
  session.push({ sessionUpdate: "terminal_output_chunk", terminalId: "terminal", data: "4g==" });
  assert.equal(session.terminalViews.get("terminal")?.output, "");
  session.push({ sessionUpdate: "terminal_output_chunk", terminalId: "terminal", data: "gqw=" });
  assert.equal(session.terminalViews.get("terminal")?.output, "€");
  session.push({ sessionUpdate: "terminal_update", terminalId: "terminal", command: "echo", output: { data: "bmV3" } });
  session.push({ sessionUpdate: "terminal_output_chunk", terminalId: "terminal", data: "!invalid" });
  assert.equal(session.terminalViews.get("terminal")?.output, "new");
  session.push({
    sessionUpdate: "terminal_update",
    terminalId: "terminal",
    exitStatus: { exitCode: 0 },
    output: { data: "!invalid" },
  });
  assert.equal(session.terminalViews.get("terminal")?.exitCode, 0);
  assert.equal(session.terminalViews.get("terminal")?.output, "new");
  session.push({ sessionUpdate: "terminal_output_chunk", terminalId: "terminal", data: "IQ==" });
  assert.equal(session.terminalViews.get("terminal")?.output, "new!");
  const terminal = session.finish().find((item) => item.role === "task");
  assert.equal(terminal?.role === "task" ? terminal.task.toolCallId : null, "shell");
});

test("v2 resume replays until replay_complete, keeps child history, and receives current metadata", async () => {
  const {
    agent,
    events,
    peer: native,
  } = await create(
    peer({
      "session/resume": (_params, _message, native) => {
        send(native, {
          sessionUpdate: "agent_message",
          messageId: "old",
          content: [{ type: "text", text: "History" }],
        });
        send(native, {
          sessionUpdate: "subagent_update",
          sessionId: "child",
          title: "Worker",
          state: { state: "idle" },
        });
        send(
          native,
          { sessionUpdate: "agent_message", messageId: "result", content: [{ type: "text", text: "Child result" }] },
          "child",
        );
        send(native, { sessionUpdate: "replay_complete" }, "child");
        send(native, { sessionUpdate: "replay_complete" });
        send(native, { sessionUpdate: "session_info_update", title: "Native title" });
        send(native, { sessionUpdate: "state_update", state: "idle", stopReason: "end_turn", background: [] });
        return { configOptions: [], availableCommands: [] };
      },
    }),
  );
  const history = await agent.readSession({ sessionId: "v2", workspace: "/w" });
  assert.equal(history.items[0]?.role === "assistant" ? history.items[0].text : null, "History");
  assert.equal(history.items[1]?.role, "task");
  assert.equal(history.items[1]?.role === "task" ? history.items[1].items?.[0]?.role : null, "assistant");
  assert.ok(events.some((event) => event.event === "session_info" && event.title === "Native title"));
  assert.equal(
    events.some((event) => event.event === "run_finished"),
    false,
  );
  assert.equal(
    native.received.some((message) => message.method === "session/load"),
    false,
  );
  assert.deepEqual(native.received.find((message) => message.method === "session/resume")?.params.replayFrom, {
    type: "start",
  });
  assert.deepEqual((await agent.listCommands({ sessionId: "v2" })).commands, []);
});

test("v2 rejects removed client execution methods and renders permission subjects", async () => {
  const { agent, events, peer: native } = await create();
  for (const method of ["fs/read_text_file", "terminal/create"]) {
    native.send({ jsonrpc: "2.0", id: method, method, params: { sessionId: "v2", path: "/w/a", command: "true" } });
    assert.equal(responseError(await native.waitFor(replyTo(method))).code, -32601);
  }
  native.send({
    jsonrpc: "2.0",
    id: "permission",
    method: "session/request_permission",
    params: {
      sessionId: "v2",
      title: "Read this file?",
      subject: {
        type: "tool_call",
        toolCall: { toolCallId: "read", name: "read_file", title: "Reading", kind: "read" },
      },
      options: [{ optionId: "yes", name: "Allow once", kind: "allow_once" }],
    },
  });
  const approval = await next(events, "approval");
  assert.equal(approval.title, "Read this file?");
  assert.equal(approval.toolCall?.name, "read_file");
  assert.ok(events.some((event) => event.event === "tool_call_started" && event.id === "read"));
  native.send({ jsonrpc: "2.0", method: "$/cancel_request", params: { requestId: "permission" } });
  assert.deepEqual((await native.waitFor(replyTo("permission"))).result, { outcome: { outcome: "cancelled" } });
});

test("v2 login and logout use their native names and require advertised methods", async () => {
  const { agent, peer: native } = await create(
    peer({ "auth/login": () => ({}), "auth/logout": () => ({}) }, { session: {} }, [
      { type: "agent", methodId: "browser", name: "Sign in" },
    ]),
  );
  assert.equal((await agent.initialize()).authMethods?.[0]?.id, "browser");
  await agent.authenticate({ method: "browser" });
  await agent.logout();
  assert.ok(native.received.some((message) => message.method === "auth/login"));
  assert.ok(native.received.some((message) => message.method === "auth/logout"));
  assert.equal(
    native.received.some((message) => message.method === "authenticate" || message.method === "logout"),
    false,
  );
});

test("v2 plans replace by ID and unknown content types clear the previous plan", () => {
  const session = new Session();
  session.push({
    sessionUpdate: "plan_update",
    plan: { type: "items", planId: "p", entries: [{ content: "Old", status: "pending", priority: "medium" }] },
  });
  session.push({ sessionUpdate: "plan_update", plan: { type: "future", planId: "p", unknown: true } });
  const replaced = session.finish()[0];
  assert.deepEqual(replaced?.role === "plan" ? replaced.plan.entries : null, []);
});

test("unsupported negotiated versions fail before any session method is sent", async () => {
  const { agent, api } = harness("test", { peer: acpPeer({ init: { protocolVersion: 3 } }) });
  await assert.rejects(agent.createSession({ workspace: "/w" }), /unsupported ACP protocol version/);
  assert.equal(
    present(api.peers[0]).received.some((message) => message.method === "session/new"),
    false,
  );
});

test("v2 startup activity survives setup, and resumed running state is not reset to idle", async () => {
  const {
    agent,
    events,
    peer: native,
  } = await create(
    peer({
      "session/new": (_params, _message, native) => {
        send(native, { sessionUpdate: "state_update", state: "running" });
        return { sessionId: "v2" };
      },
      "session/resume": () => ({}),
    }),
  );
  assert.ok(events.some((event) => event.event === "run_started"));
  assert.equal(agent.projections.get("v2")?.state.state, "running");
  send(native, { sessionUpdate: "state_update", state: "idle", stopReason: "end_turn" });
  await next(events, "run_finished");
});

test("v2 unavailable method groups are rejected without sending native requests", async () => {
  const { agent, api } = harness("test", { peer: peer({}, {}) });
  await assert.rejects(agent.createSession({ workspace: "/w" }), /does not advertise session support/);
  await assert.rejects(agent.authenticate({ method: "unadvertised" }), /does not advertise authentication/);
  const native = present(api.peers[0]);
  assert.equal(
    native.received.some((message) => message.method === "session/new" || message.method === "auth/login"),
    false,
  );
});

test("v2 malformed known updates are ignored and unknown future updates remain harmless", async () => {
  const { agent, events, peer: native } = await create();
  send(native, { sessionUpdate: "agent_message_chunk", content: { type: "text", text: "Missing an ID" } });
  send(native, { sessionUpdate: "future_update", future: true });
  send(native, {
    sessionUpdate: "agent_message",
    messageId: "valid",
    content: [{ type: "text", text: "Valid" }],
    future: true,
  });
  await next(events, "text_delta");
  assert.deepEqual(
    events.filter((event) => event.event === "text_delta").map((event) => event.text),
    ["Valid"],
  );
});

test("v2 background permission requests stay pending when foreground work is cancelled", async () => {
  const {
    agent,
    events,
    peer: native,
  } = await create(
    peer({
      "session/prompt": (_params, message, native) => {
        send(native, {
          sessionUpdate: "tool_call_update",
          toolCallId: "watcher",
          name: "watch",
          status: "in_progress",
        });
        send(native, {
          sessionUpdate: "state_update",
          state: "running",
          background: [{ type: "tool_call", toolCallId: "watcher" }],
        });
        native.reply(message, { messageId: "user" });
      },
      "session/cancel": (_params, _message, native) =>
        send(native, {
          sessionUpdate: "state_update",
          state: "idle",
          stopReason: "cancelled",
          background: [{ type: "tool_call", toolCallId: "watcher" }],
        }),
    }),
  );
  await agent.prompt({ sessionId: "v2", input: { blocks: [{ type: "text", text: "Watch." }] } });
  await settle();
  native.send({
    jsonrpc: "2.0",
    id: "background",
    method: "session/request_permission",
    params: {
      sessionId: "v2",
      title: "Keep watching?",
      subject: { type: "tool_call", toolCall: { toolCallId: "watcher" } },
      options: [{ optionId: "allow", name: "Allow", kind: "allow_once" }],
    },
  });
  const approval = await next(events, "approval");
  await agent.cancel({ sessionId: "v2" });
  assert.equal(native.received.some(replyTo("background")), false);
  await agent.respondToApproval({ approvalId: approval.id, optionId: "allow" });
  assert.deepEqual((await native.waitFor(replyTo("background"))).result, {
    outcome: { outcome: "selected", optionId: "allow" },
  });
});

test("v2 replayed entity state remains available to live partial patches", async () => {
  const {
    agent,
    peer: native,
    events,
  } = await create(
    peer({
      "session/resume": (_params, _message, native) => {
        send(native, {
          sessionUpdate: "tool_call_update",
          toolCallId: "persisted",
          name: "read_file",
          content: [{ type: "content", content: { type: "text", text: "Stored output" } }],
        });
        send(native, { sessionUpdate: "replay_complete" });
        send(native, { sessionUpdate: "tool_call_update", toolCallId: "persisted", status: "completed" });
        send(native, { sessionUpdate: "state_update", state: "idle" });
        return {};
      },
    }),
  );
  await agent.readSession({ sessionId: "v2", workspace: "/w" });
  const patch = await next(events, "tool_call_updated");
  assert.deepEqual(patch.content, [{ type: "text", text: "Stored output" }]);
});

test("v2 session/options and setup use configId and typed initial values", async () => {
  const { agent, api } = harness("test", {
    peer: peer(
      {
        "session/options": () => ({
          configOptions: [mode, { configId: "safe", name: "Safe", type: "boolean", currentValue: true }],
        }),
        "session/new": () => ({
          sessionId: "v2",
          configOptions: [
            { ...mode, currentValue: "code" },
            { configId: "safe", name: "Safe", type: "boolean", currentValue: false },
          ],
        }),
      },
      { session: { options: {}, systemPrompt: {} } },
    ),
  });
  const options = await agent.listOptions({ workspace: "/w" });
  assert.equal(options.options.find((option) => option.id === "safe")?.kind, "toggle");
  await agent.createSession({
    workspace: "/w",
    options: { mode: "code", safe: false },
    instructions: "Trusted rules.",
  });
  const request = present(present(api.peers[0]).received.find((message) => message.method === "session/new"));
  assert.deepEqual(request.params.configOptions, [
    { configId: "mode", value: "code", type: "id" },
    { configId: "safe", type: "boolean", value: false },
  ]);
  assert.deepEqual(request.params.systemPrompt, {
    mode: "append",
    content: [{ type: "text", text: "Trusted rules." }],
  });
});

test("v2 session setup requires advertised MCP transports and explicit stdio discriminators", async () => {
  for (const supported of [false, true]) {
    const { agent, api } = harness("test", {
      agentEntry: {
        id: "test",
        name: "test",
        description: "",
        version: null,
        source: { kind: "custom", command: "agent", args: [], env: {}, install: null },
        directories: [],
        mcpServers: [{ name: "local", command: "/bin/tool", args: [], env: [] }],
        icon: null,
        iconUrl: null,
      },
      peer: peer({}, { session: { mcp: supported ? { stdio: {} } : {} } }),
    });
    if (supported) {
      await agent.createSession({ workspace: "/w" });
      const request = present(present(api.peers[0]).received.find((message) => message.method === "session/new"));
      assert.deepEqual(request.params.mcpServers, [
        { type: "stdio", name: "local", command: "/bin/tool", args: [], env: [] },
      ]);
    } else {
      await assert.rejects(agent.createSession({ workspace: "/w" }), /does not advertise the stdio MCP transport/);
      assert.equal(
        present(api.peers[0]).received.some((message) => message.method === "session/new"),
        false,
      );
    }
  }
});

test("v2 initial setup lists override buffered older config and command notifications", async () => {
  const { agent } = await create(
    peer({
      "session/new": (_params, _message, native) => {
        send(native, { sessionUpdate: "config_option_update", configOptions: [{ ...mode, currentValue: "stale" }] });
        send(native, {
          sessionUpdate: "available_commands_update",
          availableCommands: [{ type: "command", name: "stale", description: "Stale" }],
        });
        return { sessionId: "v2", configOptions: [mode] };
      },
    }),
  );
  assert.equal(agent.optionsSnapshot("v2").find((option) => option.id === "mode")?.value, "ask");
  assert.deepEqual((await agent.listCommands({ sessionId: "v2" })).commands, []);
});

test("v2 session listing treats an empty cursor as a valid next page", async () => {
  let pages = 0;
  const { agent } = await create(
    peer({
      "session/list": (params) => {
        pages++;
        if (pages === 1) return { sessions: [], nextCursor: "" };
        assert.equal(params.cursor, "");
        return { sessions: [{ sessionId: "saved", cwd: "/w", title: "Saved" }] };
      },
    }),
  );
  assert.equal((await agent.listSessions({ workspace: "/w" })).sessions[0]?.title, "Saved");
  assert.equal(pages, 2);
});

test("v2 rejects an empty prompt before opening a run", async () => {
  const { agent, peer: native } = await create();
  await assert.rejects(agent.prompt({ sessionId: "v2", input: { blocks: [] } }), /Enter a message/);
  assert.equal(agent.sessions.get("v2")?.run, null);
  assert.equal(
    native.received.some((message) => message.method === "session/prompt"),
    false,
  );
});

test("v2 unknown activity does not erase the completion boundary of observed work", async () => {
  const {
    agent,
    events,
    peer: native,
  } = await create(
    peer({
      "session/prompt": (_params, message, native) => {
        send(native, { sessionUpdate: "state_update", state: "running" });
        native.reply(message, { messageId: "input" });
      },
    }),
  );
  await agent.prompt({ sessionId: "v2", input: { blocks: [{ type: "text", text: "Go." }] } });
  send(native, { sessionUpdate: "state_update", state: "unknown" });
  await settle();
  assert.equal(
    events.some((event) => event.event === "run_finished"),
    false,
  );
  send(native, { sessionUpdate: "state_update", state: "idle", stopReason: "end_turn" });
  await next(events, "run_finished");
});

test("v2 plan entries preserve native cancellation rather than inventing pending work", () => {
  const session = new Session();
  session.push({
    sessionUpdate: "plan_update",
    plan: {
      type: "items",
      planId: "p",
      entries: [{ content: "Cancelled step", status: "cancelled", priority: "low" }],
    },
  });
  const item = session.finish()[0];
  assert.equal(item?.role === "plan" ? item.plan.entries?.[0]?.status : null, "cancelled");
});

Versions

VersionPublishedPlugin APISizePermissionsStatus
0.2.5latestNov 21, 2026>=5 <6134 KB6 permissionsListed
0.2.4Nov 16, 2026>=5 <6132.8 KB6 permissionsListed
0.2.3Nov 11, 2026>=5 <6108.9 KB6 permissionsListed
0.2.2Nov 9, 2026>=5 <6105.6 KB6 permissionsListed
0.2.1Oct 27, 2026>=2 <4105.3 KB6 permissionsListed

Reviews and comments

0 threads · 0 reviews

No comments yet.