tool folding

This commit is contained in:
Ian Gulliver
2026-10-16 11:26:15 -07:00
parent 4dff9b7471
commit ff7ce86cb5
5 changed files with 77 additions and 21 deletions
+31 -9
View File
@@ -313,12 +313,18 @@ export function mountChat(root, src, makeHead) {
};
const runHead = (run) => [subagentTag(run.parent, ctx), runSummary(run.calls)];
const addToRun = (el, call, parent) => {
const run = ctx.run;
if (!run || run.parent !== parent) {
ctx.run = { first: el, group: undefined, calls: call ? [call] : [], parent };
put(el);
const sub = ctx.subagents.get(parent);
if (sub) {
sub.run = extendRun(sub.run, el, call, parent, (e) => sub.body.append(e));
return;
}
ctx.run = extendRun(ctx.run, el, call, parent, put);
};
const extendRun = (run, el, call, parent, place) => {
if (!run || run.parent !== parent) {
place(el);
return { first: el, group: undefined, calls: call ? [call] : [], parent };
}
if (call) {
run.calls.push(call);
}
@@ -333,6 +339,7 @@ export function mountChat(root, src, makeHead) {
}
run.group.body.append(el);
replace(run.group.summary, ...runHead(run));
return run;
};
let stream;
const dropStream = () => {
@@ -429,9 +436,16 @@ export function mountChat(root, src, makeHead) {
markReview(button, r);
}
}
const sub = ctx.subagents.get(parent);
if (ev.kind === "agent.tool_call" && isSubagentCall(p)) {
const el = renderSubagent(p, ctx);
if (sub) {
sub.run = undefined;
sub.body.append(el);
continue;
}
ctx.run = undefined;
put(renderSubagent(p, ctx));
put(el);
continue;
}
if (ev.kind === "agent.tool_call") {
@@ -446,6 +460,11 @@ export function mountChat(root, src, makeHead) {
addToRun(el, undefined, parent);
continue;
}
if (sub) {
sub.run = undefined;
sub.body.append(el);
continue;
}
ctx.run = undefined;
if (ev.kind === "turn.ended") {
ctx.open = false;
@@ -785,8 +804,10 @@ function subagentTag(parent, ctx) {
if (!parent) {
return null;
}
const sub = ctx.subagents.get(parent);
return h("span", { class: "subagent-tag", title: sub?.description ?? "" }, `↳ ${sub?.type ?? "subagent"}`);
if (ctx.subagents.has(parent)) {
return null;
}
return h("span", { class: "subagent-tag" }, "↳ subagent");
}
function renderToolCall(p, ctx) {
const result = h("div", { class: "tool-result pending" }, "running…");
@@ -814,10 +835,11 @@ function renderSubagent(p, ctx) {
const description = String(input["description"] ?? "");
const status = h("span", { class: "subagent-status" }, "starting…");
const result = h("div", { class: "tool-result pending" }, "running…");
const body = h("div", { class: "subagent-body" });
const tag = subagentTag(parentOf(p), ctx);
ctx.tools.set(id, result);
ctx.subagents.set(id, { type, description, status });
return h("details", { class: "tool subagent" }, h("summary", {}, tag, h("span", { class: "tool-name" }, `${p["name"]} ${type}`), " ", h("span", { class: "tool-brief" }, description), " ", status), markdown(String(input["prompt"] ?? ""), "text md subagent-prompt", { taskId: ctx.taskId }), result);
ctx.subagents.set(id, { type, description, status, body, run: undefined });
return h("details", { class: "tool subagent" }, h("summary", {}, tag, h("span", { class: "tool-name" }, `${p["name"]} ${type}`), " ", h("span", { class: "tool-brief" }, description), " ", status), markdown(String(input["prompt"] ?? ""), "text md subagent-prompt", { taskId: ctx.taskId }), body, result);
}
function claudeTaskStatus(p, ctx) {
if (p["type"] !== "system") {
+1 -1
View File
File diff suppressed because one or more lines are too long