Official

claude

Claude Code agent provider: runs the Claude Code CLI headless for each account.

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/claude@0.2.7

Permissions in 0.2.7

  • Provide agents agents.provideMediumAdds agents to the app.Provide the Claude Code agent and pass its tool calls to plugin tools
  • Run named programs processMediumStarts the listed programs.Run the Claude Code CLI (sessions, sign-in, `claude update`), and ask the npm installation that owns it about a newer versionPrograms: claudenpm
  • Read files fs.readMediumReads files in the listed places.Read Claude Code's sessions, settings and skills (in ~/.claude, other accounts' ~/.claude-* folders, the shared skills and the folder you choose in Settings), the project's .claude folder, the administrator's skill policy, and once, what the previous provider keptPlaces: ~/.claude/**~/.claude*/**~/.agents/skills/**the open workspaceits own data folder/Library/Application Support/ClaudeCode/managed-settings.json/etc/claude-code/managed-settings.json${settings.configDir}
  • Environment variables envMediumReads the listed environment variables.Find Claude Code's configuration directory, and the launch settings you set in CLAUDE_* variables (extra arguments, MCP servers, setting sources, appended system prompt, extra folders)Variables: HOMECLAUDE_CONFIG_DIRCLAUDE_EXTRA_ARGSCLAUDE_MCP_CONFIGCLAUDE_STRICT_MCP_CONFIGCLAUDE_SETTING_SOURCESCLAUDE_APPEND_SYSTEM_PROMPTCLAUDE_ADD_DIRS

Files

audit.test.ts18 KB
// These fixtures follow Agent SDK 0.3.325's stream-json control shapes.
import assert from "node:assert/strict";
import { mkdirSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { test, run, resources, useApi, RecordingProcess, tempDir, eventAs, required } from "./testing.ts";
import type { Written } from "./testing.ts";
import type { AgentEvent, Values } from "./types.ts";
import { fakeApi, diskFs, memoryStorage, settle } from "../sdk/testing.ts";
import { Session, starts } from "./session.ts";
import { SessionStore } from "./state.ts";
import { ClaudeAgent } from "./agent.ts";
import { defaultAccount } from "./instances.ts";
import { apiFiles as files } from "./files.ts";
import { Catalog, DEFAULT, EFFORT, FAST_MODE, MODEL, PERMISSION_MODE, ULTRACODE } from "./options.ts";
import { Mapper } from "./map.ts";
import { sessionFile, readSession } from "./history.ts";
import { approvalRequest, approvalDecision } from "./approvals.ts";
import { elicitationQuestion, elicitationResult } from "./elicitation.ts";
import * as wire from "./wire.ts";

function harness(values: Values = {}) {
  const home = tempDir();
  const storage = memoryStorage();
  const api = useApi(fakeApi({ fs: diskFs(), onHost: (method, params) => storage(method, params) ?? {} }));
  const events: AgentEvent[] = [];
  const ctx = {
    ...resources(api),
    files: files(),
    store: new SessionStore(),
    instance: defaultAccount(),
    env: { HOME: home },
    agentId: "claude",
    emit: (event: AgentEvent) => events.push(event),
    report: () => {},
  };
  const s = new Session(ctx, { id: "host", workspace: home, values });
  const written: Written[] = [];
  const proc = new RecordingProcess(written);
  s.proc = proc;
  const feed = (frame: unknown) => run(s.onLine(JSON.stringify(frame)));
  const respond = (message: Written, response: unknown = {}, error?: string) =>
    s.onControlResponse(
      wire.readRecord({
        type: "control_response",
        response: { subtype: error ? "error" : "success", request_id: message.request_id, response, error },
      })!.record,
    );
  const acknowledge = (result: (request: Record<string, unknown>) => unknown = () => ({})) => {
    const send = proc.send.bind(proc);
    proc.send = (message) => {
      send(message);
      const frame = written.at(-1)!;
      if (frame.type === "control_request") respond(frame, result(wire.objectOf(frame.request)));
    };
  };
  return { s, ctx, events, storage, written, feed, respond, acknowledge, home };
}

const elicitation = (request: object, id = "ask") => ({
  type: "control_request",
  request_id: id,
  request: {
    subtype: "elicitation",
    mcp_server_name: "connector",
    message: "Provide the requested details.",
    ...request,
  },
});
const resultOf = (written: Written[]) => wire.objectOf(written.at(-1)?.response?.response);

test("Stop uses cancel_queued and fences every cancelled native input", async () => {
  const { s, written, feed, acknowledge, events } = harness();
  s.run = "run";
  s.inputs.set("queued", { runId: "run", consumed: false, answered: false });
  s.inputs.set("running", { runId: "run", consumed: true, answered: false });
  await feed({ type: "system", subtype: "init", capabilities: ["interrupt_cancel_queued_v1"] });
  acknowledge(() => ({ still_queued: [], cancelled: ["queued", "unknown"] }));
  await run(s.cancel());
  assert.equal(written.at(-1)?.request?.cancel_queued, true);
  assert.equal(s.inputs.get("queued")?.answered, true);
  assert.equal(s.inputs.get("running")?.answered, false);
  await feed({ type: "result", subtype: "success" });
  s.run = "next";
  await feed({
    type: "assistant",
    uuid: "late",
    user_message_uuid: "queued",
    message: { content: [{ type: "text", text: "Old work" }] },
  });
  assert.equal(s.run, "next");
  assert.ok(!events.some((event) => event.event === "text_delta"));
});

test("Stop awaits its receipt and withdraws known survivors on older CLIs", async () => {
  const { s, written, acknowledge, feed } = harness();
  s.run = "run";
  await feed({ type: "system", subtype: "init", capabilities: [] });
  s.inputs.set("queued", { runId: "run", consumed: false, answered: false });
  acknowledge((request) =>
    request.subtype === "interrupt" ? { still_queued: ["queued", "internal"] } : { cancelled: true },
  );
  await run(s.cancel());
  assert.equal(written[0]?.request?.cancel_queued, undefined);
  assert.equal(written[1]?.request?.subtype, "cancel_async_message");
  assert.equal(written[1]?.request?.message_uuid, "queued");
  assert.equal(s.inputs.get("queued")?.answered, true);
});

test("Stop during startup requests queued cancellation before init can advertise it", async () => {
  const { s, written, acknowledge } = harness();
  s.run = "startup";
  acknowledge(() => ({ still_queued: [], cancelled: [] }));
  await run(s.cancel());
  assert.equal(written.at(-1)?.request?.cancel_queued, true);
});

test("native command cancellation prevents late consumption without fabricating admission", async () => {
  const { s, feed, events } = harness();
  s.inputs.set("queued", { runId: "old", consumed: false, answered: false });
  s.finishedRuns.add("old");
  await feed({ type: "command_lifecycle", state: "cancelled", command_uuid: "queued" });
  await feed({ type: "assistant", user_message_uuid: "queued", message: { content: [] } });
  assert.equal(s.inputs.get("queued")?.answered, true);
  assert.equal(s.run, null);
  assert.equal(events.length, 0);
});

test("transcript write loss remains visible after a successful result and clean exit", async () => {
  const { s, feed, events } = harness();
  s.run = "run";
  await feed({ type: "result", subtype: "success" });
  await feed({
    type: "system",
    subtype: "session_writes_lost",
    error_code: "EDQUOT",
    lost: ["transcript", "global_config"],
    transcript_session_ids: ["native"],
  });
  s.onExit(s.proc, { code: 0, signal: null }, []);
  assert.deepEqual(
    events.filter((event) => event.event === "run_finished").map((event) => event.outcome),
    [{ status: "completed" }],
  );
  const notice = events.find((event) => event.event === "notice")!;
  assert.match(notice.message, /EDQUOT.*native/);
  assert.equal(notice.runId, undefined);
  assert.equal(notice.level, "warning");
});

test("conversation resets persist the new identity for resume and native history", async () => {
  const { s, ctx, feed, storage } = harness();
  s.sent = { old: "old-prompt" };
  s.rewound = "old-point";
  await run(ctx.store.save(s.id, { cli: "old", sent: s.sent, rewound: s.rewound, fork: { origin: "origin" } }));
  await feed({ type: "conversation_reset", new_conversation_id: "fresh", trigger: "plan_mode_exit" });
  assert.equal(s.cli, "fresh");
  assert.deepEqual(storage.values.get("session:host"), { cli: "fresh", sent: {} });
  assert.equal(storage.values.get("alias:fresh"), "host");
  const resumed = await run(Session.create(ctx, { id: s.id, workspace: s.workspace, start: starts.resume() }));
  assert.deepEqual(resumed.args().slice(resumed.args().indexOf("--resume"), resumed.args().indexOf("--resume") + 2), [
    "--resume",
    "fresh",
  ]);
  const path = sessionFile(s.configDir, s.workspace, "fresh")!;
  mkdirSync(dirname(path), { recursive: true });
  writeFileSync(
    path,
    JSON.stringify({
      type: "user",
      uuid: "new-prompt",
      parentUuid: null,
      message: { role: "user", content: "Fresh conversation" },
    }) + "\n",
  );
  const history = await run(readSession(s.files, s.configDir, s.workspace, await run(ctx.store.cliIdOf(s.id))));
  assert.equal(history.length, 1);
  assert.equal(history[0]?.id, "new-prompt");
  assert.equal(s.read?.path, path);
  await feed({ type: "conversation_reset", new_conversation_id: "next", trigger: "future_trigger" });
  assert.equal(await run(ctx.store.cliIdOf(s.id)), "next");
});

test("persistent approval suppression applies to both choices and stale answers", async () => {
  const { s, feed, events, written } = harness();
  const suggestions = [
    { type: "addRules", rules: [{ toolName: "Bash", ruleContent: "pwd" }], behavior: "allow", destination: "session" },
  ];
  await feed({
    type: "control_request",
    request_id: "permission",
    request: {
      subtype: "can_use_tool",
      tool_name: "Bash",
      input: { command: "pwd" },
      permission_suggestions: suggestions,
      suppress_always_allow_rule: true,
    },
  });
  const card = events.find((event) => event.event === "approval")!;
  assert.deepEqual(
    required(card.options).map((option) => option.id),
    ["allow_once", "reject"],
  );
  assert.equal(s.respondToApproval(card.id, "allow_always"), true);
  assert.equal(resultOf(written).behavior, "deny");
  assert.equal(resultOf(written).updatedPermissions, undefined);
  assert.equal(approvalDecision("allow_always", "Bash", null, true).behavior, "deny");
  assert.equal(approvalDecision("allow_once", "Bash", suggestions, true).behavior, "allow");
  assert.deepEqual(approvalDecision("allow_always", "Bash", suggestions).updatedPermissions, suggestions);
  assert.ok(
    required(approvalRequest("normal", { tool_name: "Bash" }).options).some((option) => option.id === "allow_always"),
  );
});

test("older task lifecycle frames cannot overwrite a resumed run", () => {
  for (const task_type of ["local_agent", "local_bash", "local_workflow"]) {
    const mapper = new Mapper();
    const frame = (subtype: string, run_id: string, extra = {}) => ({
      type: "system",
      subtype,
      task_id: "task",
      run_id,
      task_type,
      tool_use_id: "call",
      is_backgrounded: true,
      ...extra,
    });
    mapper.handle(frame("task_started", "001"));
    mapper.handle(frame("task_notification", "001", { status: "completed" }));
    mapper.handle(frame("task_started", "002"));
    for (const subtype of ["task_started", "task_progress", "task_updated", "task_notification"]) {
      assert.deepEqual(
        mapper.handle(frame(subtype, "001", { status: "failed", summary: "Old failure", patch: { status: "failed" } })),
        [],
      );
      assert.equal(mapper.tasks.get("call")?.done, false);
      assert.equal(mapper.tasks.get("call")?.info.status, "running");
    }
    assert.deepEqual(
      mapper.handle({
        type: "user",
        origin: { kind: "task-notification", runId: "001" },
        message: {
          content: "<task-notification><task-id>task</task-id><status>completed</status></task-notification>",
        },
      }),
      [],
    );
    assert.equal(mapper.tasks.get("call")?.done, false);
    mapper.handle(frame("task_notification", "002", { status: "completed" }));
    assert.equal(mapper.tasks.get("call")?.done, true);
  }
});

for (const [option, before, after] of [
  [MODEL, "old", "new"],
  [PERMISSION_MODE, "supervised", "full"],
  [FAST_MODE, false, true],
  [EFFORT, "low", "high"],
  [ULTRACODE, true, false],
] as const) {
  test(`the ${option} option changes only after native acceptance`, async () => {
    const { s, written, respond } = harness({ [option]: before });
    const setter = run(s.setOption(option, after));
    const rejected = assert.rejects(setter, /Refused by policy/);
    await settle();
    assert.equal(s.values[option], before);
    respond(written[0]!, {}, "Refused by policy");
    await rejected;
    assert.equal(s.values[option], before);
    const accepted = run(s.setOption(option, after));
    await settle();
    respond(written.at(-1)!);
    await accepted;
    assert.equal(s.values[option], after);
  });
}

test("effort explicitly preserves Ultracode and model default clears the native override", async () => {
  const { s, written, acknowledge } = harness({ [ULTRACODE]: true });
  acknowledge();
  await run(s.setOption(EFFORT, DEFAULT));
  assert.deepEqual(written.at(-1)?.request?.settings, { effortLevel: null, ultracode: true });
  s.values[ULTRACODE] = false;
  await run(s.setOption(MODEL, DEFAULT));
  assert.deepEqual(written.find((message) => message.request?.subtype === "set_model")?.request, {
    subtype: "set_model",
  });
});

const form = {
  type: "object",
  properties: {
    name: { type: "string", title: "Name" },
    count: { type: "integer", minimum: 1 },
    enabled: { type: "boolean" },
    color: { type: "string", oneOf: [{ const: "r", title: "Red" }] },
    tags: { type: "array", items: { anyOf: [{ const: "x", title: "Example" }] } },
  },
  required: ["name", "count"],
};

test("MCP forms publish existing question fields and return typed elicitation content", async () => {
  const { s, feed, events, written } = harness();
  await feed(elicitation({ requested_schema: form, property_order: ["count", "name", "enabled", "color", "tags"] }));
  const question = events.find((event) => event.event === "question")!;
  assert.deepEqual(
    question.fields.map((field) => field.kind),
    ["text", "text", "boolean", "select", "multi_select"],
  );
  assert.equal(question.fields[0]?.required, true);
  assert.equal(question.fields[3]?.options?.[0]?.label, "Red");
  assert.match(question.message!, /connector/);
  assert.equal(
    s.respondToQuestion(question.id, {
      values: { name: "Ada", count: "2", enabled: false, color: "r", tags: ["x"], extra: "ignored" },
    }),
    true,
  );
  assert.deepEqual(resultOf(written), {
    action: "accept",
    content: { name: "Ada", count: 2, enabled: false, color: "r", tags: ["x"] },
  });
});

test("invalid form answers keep the request pending and unsupported schemas surface an error", async () => {
  const { s, ctx, feed, events, written } = harness();
  await feed(elicitation({ requested_schema: form }));
  const agent = new ClaudeAgent(ctx);
  agent.sessions.set(s.id, s);
  await assert.rejects(
    run(agent.respondToQuestion({ questionId: "host::ask", answer: { values: { count: "NaN", name: "Ada" } } })),
    /integer/,
  );
  assert.throws(() => s.respondToQuestion("host::ask", { values: { count: "NaN", name: "Ada" } }), /integer/);
  assert.equal(s.pending.size, 1);
  s.respondToQuestion("host::ask", { cancelled: true });
  assert.deepEqual(resultOf(written), { action: "cancel" });
  await feed(elicitation({ requested_schema: { type: "object", properties: { nested: { type: "object" } } } }));
  assert.equal(written.at(-1)?.response?.subtype, "error");
  assert.ok(events.some((event) => event.event === "notice" && /unsupported/.test(event.message)));
});

test("URL elicitation completes only the matching server request and sends no form content", async () => {
  const { s, feed, events, written } = harness();
  await feed(elicitation({ mode: "url", url: "https://example.com/connect", elicitation_id: "url-1" }));
  const question = events.find((event) => event.event === "question")!;
  assert.equal(question.url, "https://example.com/connect");
  assert.deepEqual(question.fields, []);
  await feed({ type: "system", subtype: "elicitation_complete", mcp_server_name: "other", elicitation_id: "url-1" });
  assert.equal(s.pending.size, 1);
  await feed({
    type: "system",
    subtype: "elicitation_complete",
    mcp_server_name: "connector",
    elicitation_id: "url-1",
  });
  assert.equal(s.pending.size, 0);
  assert.deepEqual(resultOf(written), { action: "accept" });
  assert.ok(events.some((event) => event.event === "question_resolved" && event.id === question.id));
  await feed(elicitation({ mode: "url", url: "https://example.com/connect", elicitation_id: "url-2" }, "accepted"));
  s.respondToQuestion("host::accepted", {});
  const before = written.length;
  await feed({
    type: "system",
    subtype: "elicitation_complete",
    mcp_server_name: "connector",
    elicitation_id: "url-2",
  });
  assert.equal(written.length, before);
  assert.ok(events.some((event) => event.event === "notice" && /completed/.test(event.message)));
});

test("Stop, steering and native withdrawal settle elicitation requests with their own protocol", async () => {
  const { s, feed, written, acknowledge, events } = harness();
  acknowledge(() => ({ still_queued: [] }));
  await feed(elicitation({ requested_schema: form }));
  await run(s.cancel());
  const response = written.find((message) => message.type === "control_response")!;
  assert.deepEqual(wire.objectOf(response.response?.response), { action: "cancel" });
  assert.ok(events.some((event) => event.event === "question_resolved"));
  await feed(elicitation({ mode: "url", url: "https://example.com" }, "steer"));
  s.withdraw("host::steer", { behavior: "deny" });
  assert.deepEqual(resultOf(written), { action: "cancel" });
  await feed(elicitation({ requested_schema: form }, "withdraw"));
  const before = written.length;
  await feed({ type: "control_cancel_request", request_id: "withdraw" });
  assert.equal(s.pending.size, 0);
  assert.equal(written.length, before);
});

test("commands_changed replaces commands and refreshes skills even outside an active run", async () => {
  const { s, feed, events, home } = harness();
  s.catalog = new Catalog({ commands: [{ name: "old", description: "Old command" }] });
  const skill = join(home, ".claude", "skills", "new");
  mkdirSync(skill, { recursive: true });
  writeFileSync(
    join(skill, "SKILL.md"),
    "---\ndescription: A newly discovered skill.\n---\nFollow the instructions.\n",
  );
  await feed({
    type: "system",
    subtype: "commands_changed",
    commands: [{ name: "new", description: "New command", argumentHint: "<path>" }],
  });
  assert.deepEqual(
    s.commands().map((command) => command.name),
    ["new"],
  );
  assert.equal(s.commands()[0]?.inputHint, "<path>");
  assert.ok(events.some((event) => event.event === "skills" && event.skills.some((skill) => skill.name === "new")));
  await feed({ type: "system", subtype: "commands_changed", commands: [] });
  assert.deepEqual(eventAs(events.filter((event) => event.event === "commands").at(-1)!, "commands").commands, []);
  assert.equal(s.run, null);
});

test("legacy enum names and empty forms remain representable without invented defaults", () => {
  const request = {
    requested_schema: {
      type: "object",
      properties: { color: { type: "string", enum: ["r"], enumNames: ["Red"], default: "r" } },
    },
  };
  assert.equal(elicitationQuestion("id", request).fields[0]?.options?.[0]?.label, "Red");
  assert.deepEqual(elicitationResult(request, {}), { action: "accept", content: {} });
});

Versions

VersionPublishedPlugin APISizePermissionsStatus
0.2.7latestNov 21, 2026>=5 <6207.5 KB4 permissionsListed
0.2.6Nov 16, 2026>=5 <6206 KB4 permissionsListed
0.2.5Nov 11, 2026>=5 <6168.3 KB4 permissionsListed
0.2.4Nov 9, 2026>=5 <6166.1 KB4 permissionsListed
0.2.3Oct 27, 2026>=2 <4151.6 KB4 permissionsListed

Reviews and comments

0 threads · 0 reviews

No comments yet.