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.6
Permissions in 0.2.6
Files
subagents.test.ts10.7 KB
// A subagent's answer as the CLI reports it. Run with
// `node --import ./testing/register.mjs --test claude/subagents.test.ts`.
import assert from "node:assert/strict";
import { mkdirSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { files, itemAs, required, run, tempDir, test } from "./testing.ts";
import { readSessionFile } from "./history.ts";
import { Mapper } from "./map.ts";
import { readAgent, spawnAnswer } from "./subagents.ts";
import type { Emission, TranscriptItem } from "./types.ts";
import type * as wire from "./wire.ts";
test("the CLI's note of the tools a subagent used is left out of its answer", () => {
const content = [{ type: "text", text: "<tools-used-before-summary>Bash</tools-used-before-summary> The `crates` folder contains these 11 folders." }];
assert.equal(spawnAnswer(null, content), "The `crates` folder contains these 11 folders.");
});
test("an answer with no note is kept as it is", () => {
assert.equal(spawnAnswer(null, [{ type: "text", text: "Done." }]), "Done.");
});
// What CLI 2.1.325 says in place of a report a subagent handed back
// through its `SubagentHandback` tool.
const note = (agent: string) =>
`This agent's report was delivered to you as a message from "${agent}" (its SubagentHandback call). Read it there; it is not repeated here.\n`;
const summaries = (events: Emission[]) =>
events.flatMap((event) => (event.kind.event === "task" ? [event.kind.summary] : []));
test("a subagent that hands its report back ends with the report, not the CLI's note that it was delivered", () => {
const mapper = new Mapper();
mapper.rememberTool("toolu_a", "Agent", { description: "Look", prompt: "Look around." });
mapper.rememberTool("toolu_n", "Agent", { description: "Nested", prompt: "Look deeper." });
const started = (task: string, tool: string) =>
mapper.handle({ type: "system", subtype: "task_started", task_id: task, tool_use_id: tool, task_type: "local_agent" });
const handback = (tool: string, message: string) =>
mapper.handle({
type: "assistant",
parent_tool_use_id: tool,
message: { id: `msg_${tool}`, content: [{ type: "tool_use", id: `hb_${tool}`, name: "SubagentHandback", input: { message } }] },
});
const notified = (task: string, tool: string, report: { text: string; warning?: string }) =>
mapper.handle({
type: "system",
subtype: "task_notification",
task_id: task,
tool_use_id: tool,
status: "completed",
summary: note(task),
handback: "send",
handback_report: report,
});
const returned = (tool: string, parent: string | null, structured: wire.Structured | undefined) =>
mapper.handle({
type: "user",
parent_tool_use_id: parent,
...(structured ? { tool_use_result: structured } : {}),
message: { content: [{ type: "tool_result", tool_use_id: tool, content: [{ type: "text", text: note("x") }] }] },
});
started("a1", "toolu_a");
mapper.handle({
type: "assistant",
parent_tool_use_id: "toolu_a",
message: { id: "msg_said", content: [{ type: "text", text: "Let me look." }] },
});
// A nested agent: its result reaches the agent that started it without
// the structured part, so only the notification carries its report.
started("n1", "toolu_n");
handback("toolu_n", "Nested report.");
assert.deepEqual(summaries(notified("n1", "toolu_n", { text: "Nested report." })), ["Nested report."]);
assert.deepEqual(summaries(returned("toolu_n", "toolu_a", undefined)), []);
handback("toolu_a", "The report.");
assert.deepEqual(summaries(notified("a1", "toolu_a", { text: "The report." })), ["The report."]);
const structured = {
status: "completed",
agentId: "a1",
handback: "send",
handbackReport: { text: "The report." },
content: [{ type: "text", text: note("a1") }],
};
assert.deepEqual(summaries(returned("toolu_a", null, structured)), []);
assert.equal(mapper.tasks.get("toolu_a")?.info.summary, "The report.");
assert.equal(mapper.tasks.get("toolu_n")?.info.summary, "Nested report.");
// A report auto mode flagged keeps its warning, above it.
const answer = spawnAnswer({ handbackReport: { text: "Report.", warning: "SECURITY WARNING: check this." } }, note("f1"));
assert.equal(answer, "SECURITY WARNING: check this.\n\nReport.");
});
function write(path: string, records: unknown[]) {
mkdirSync(dirname(path), { recursive: true });
writeFileSync(path, records.map((record) => JSON.stringify(record)).join("\n"));
}
const record = (uuid: string, parentUuid: string | null, fields: object) => ({
uuid,
parentUuid,
timestamp: "2026-11-15T10:00:00Z",
...fields,
});
const said = (role: "user" | "assistant", content: unknown) => ({ type: role, message: { role, content } });
const handedBack = (message: string) =>
said("assistant", [{ type: "tool_use", id: `hb_${message}`, name: "SubagentHandback", input: { message } }]);
test("a reopened chat shows the reports its subagents handed back, a background and a nested one too", async () => {
const home = tempDir();
const main = join(home, "s.jsonl");
const dir = join(home, "s", "subagents");
write(main, [
record("m1", null, said("user", "go")),
record(
"m2",
"m1",
said("assistant", [
{ type: "tool_use", id: "toolu_B", name: "Agent", input: { description: "In the background", prompt: "B", run_in_background: true } },
{ type: "tool_use", id: "toolu_C", name: "Agent", input: { description: "In the foreground", prompt: "C" } },
]),
),
record("m3", "m2", {
...said("user", [{ type: "tool_result", tool_use_id: "toolu_B", content: "Async agent launched successfully." }]),
toolUseResult: { isAsync: true, status: "async_launched", agentId: "bbb" },
}),
record("m4", "m3", {
...said("user", [{ type: "tool_result", tool_use_id: "toolu_C", content: note("ccc") }]),
toolUseResult: { status: "completed", agentId: "ccc", handback: "send", handbackReport: { text: "C's report." }, content: [{ type: "text", text: note("ccc") }] },
}),
// The background agent's report reaches the conversation as a message;
// its notification's result only says so.
record("m5", "m4", {
...said("user", 'Another Claude session sent a message:\n<agent-message from="bbb">…</agent-message>'),
origin: { kind: "peer", from: "bbb", senderTaskId: "bbb", body: "[Subagent hand-back] …", handback: true, handbackReportText: "B's report." },
}),
record("m6", "m5", {
type: "attachment",
attachment: {
type: "queued_command",
prompt: `<task-notification>\n<task-id>bbb</task-id>\n<status>completed</status>\n<result>${note("bbb")}</result>\n</task-notification>`,
},
}),
]);
const agent = (id: string, tool: string, records: unknown[], parent?: string) => {
write(join(dir, `agent-${id}.jsonl`), records);
write(join(dir, `agent-${id}.meta.json`), [{ agentType: "general-purpose", toolUseId: tool, ...(parent ? { parentAgentId: parent } : {}) }]);
};
agent("bbb", "toolu_B", [record("b1", null, said("user", "B")), record("b2", "b1", handedBack("B's report."))]);
agent("ccc", "toolu_C", [
record("c1", null, said("user", "C")),
record("c2", "c1", said("assistant", [{ type: "tool_use", id: "toolu_D", name: "Agent", input: { description: "Nested", prompt: "D" } }])),
// The result a nested agent's caller got is only the note.
record("c3", "c2", said("user", [{ type: "tool_result", tool_use_id: "toolu_D", content: note("ddd") }])),
record("c4", "c3", handedBack("C's report.")),
]);
agent("ddd", "toolu_D", [record("d1", null, said("user", "D")), record("d2", "d1", handedBack("D's report."))], "ccc");
const read = await run(readSessionFile(files(), main, { tasks: "all" }));
const task = (items: TranscriptItem[], id: string) => itemAs(required(items.find((item) => item.id === id)), "task");
assert.equal(task(read.items, "task-toolu_B").task.summary, "B's report.");
const foreground = task(read.items, "task-toolu_C");
assert.equal(foreground.task.summary, "C's report.");
assert.equal(task(required(foreground.items), "task-toolu_D").task.summary, "D's report.");
// Unread, the background agent still shows its report.
const lazy = await run(readSessionFile(files(), main, { tasks: new Set() }));
assert.equal(task(lazy.items, "task-toolu_B").task.summary, "B's report.");
});
test("a subagent given more work after a reload or a restart goes on in its own row and ends there", async () => {
// The new process never saw the agent start; its files say which call did.
const session = join(tempDir(), "s");
const folder = join(session, "subagents");
write(join(folder, "agent-a8e0.meta.json"), [{ agentType: "general-purpose", description: "Reply", toolUseId: "toolu_agent" }]);
write(join(folder, "agent-a8e0.jsonl"), [
record("a1", null, said("user", "Reply with FIRST RUN.")),
record("a2", "a1", handedBack("FIRST RUN")),
]);
const mapper = new Mapper();
mapper.rememberTool("toolu_send", "SendMessage", { to: "a8e0", message: "Reply with SECOND RUN." });
const frames: Record<string, unknown>[] = [
{ type: "system", subtype: "task_started", task_id: "a8e0", tool_use_id: "toolu_send", description: "Reply", task_type: "local_agent", is_backgrounded: true, prompt: "Reply with SECOND RUN." },
{ type: "user", parent_tool_use_id: null, message: { content: [{ type: "tool_result", tool_use_id: "toolu_send", content: '{"success":true,"message":"Resuming agent a8e0"}' }] } },
{ type: "user", parent_tool_use_id: "toolu_agent", agent_id: "a8e0", message: { content: [{ type: "text", text: "Reply with SECOND RUN." }] } },
{ type: "assistant", parent_tool_use_id: "toolu_agent", agent_id: "a8e0", message: { id: "msg_2", content: [{ type: "text", text: "SECOND RUN" }] } },
{ type: "system", subtype: "task_updated", task_id: "a8e0", patch: { status: "completed" } },
{ type: "system", subtype: "task_notification", task_id: "a8e0", tool_use_id: "toolu_send", status: "completed", summary: note("a8e0"), handback_report: { text: "SECOND RUN" } },
];
const published = new Map<string, Emission["kind"] & { event: "task" }>();
for (const frame of frames) {
const resumed = mapper.resumedUnknown(frame);
if (resumed !== null) mapper.adopt(resumed, required(await run(readAgent(files(), session, resumed))));
for (const event of mapper.handle(frame)) if (event.kind.event === "task") published.set(event.kind.id, event.kind);
}
assert.deepEqual([...published.keys()], ["toolu_agent"], "no row under the resuming call, none left running");
const task = required(published.get("toolu_agent"));
assert.equal(task.status, "completed");
assert.equal(task.summary, "SECOND RUN");
assert.equal(task.title, "Reply", "the row keeps what it was");
assert.equal(task.prompt, "Reply with FIRST RUN.");
});Versions
| Version | Published | Plugin API | Size | Permissions | Status |
|---|---|---|---|---|---|
| 0.2.7latest | Nov 21, 2026 | >=5 <6 | 207.5 KB | 4 permissions | Listed |
| 0.2.6 | Nov 16, 2026 | >=5 <6 | 206 KB | 4 permissions | Listed |
| 0.2.5 | Nov 11, 2026 | >=5 <6 | 168.3 KB | 4 permissions | Listed |
| 0.2.4 | Nov 9, 2026 | >=5 <6 | 166.1 KB | 4 permissions | Listed |
| 0.2.3 | Oct 27, 2026 | >=2 <4 | 151.6 KB | 4 permissions | Listed |
No comments yet.