Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions components/ComposerPanels.subagents.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import "../tests/setup-dom.mjs";
import assert from "node:assert/strict";
import test, { afterEach, beforeEach } from "node:test";
import React from "react";
const { cleanup, render, screen } = await import("@testing-library/react/pure.js");

const { ComposerPanels } = await import("./ComposerPanels.tsx");

beforeEach(() => {
window.matchMedia = () => ({ matches: false, addEventListener() {}, removeEventListener() {} });
// Collapsible headers scroll their active row into view.
window.HTMLElement.prototype.scrollIntoView = () => {};
});
afterEach(() => {
cleanup();
localStorage.clear();
delete window.matchMedia;
delete window.HTMLElement.prototype.scrollIntoView;
});

function makeSubagent(index, status) {
return { id: `s${index}`, agent: "explore", index, status, task: `task ${index}`, source: "live" };
}

function renderPanels(subagents) {
render(React.createElement(ComposerPanels, {
todoPhases: [],
subagents,
onSelectSubagent() {},
defaultExpanded: true,
}));
}

test("subagents header shows the completed count once nothing is running (#352)", () => {
renderPanels(Array.from({ length: 6 }, (_, i) => makeSubagent(i, "completed")));
const counter = screen.getByLabelText("6/6 complete");
assert.equal(counter.textContent, "6/6 complete");
});

test("subagents header counts only truly completed runs, not failed ones (#352)", () => {
renderPanels([
...Array.from({ length: 4 }, (_, i) => makeSubagent(i, "completed")),
...Array.from({ length: 2 }, (_, i) => makeSubagent(i + 4, "failed")),
]);
const counter = screen.getByLabelText("4/6 complete");
assert.equal(counter.textContent, "4/6 complete");
});

test("subagents header still shows the running count while any subagent runs", () => {
renderPanels([
...Array.from({ length: 2 }, (_, i) => makeSubagent(i, "started")),
...Array.from({ length: 4 }, (_, i) => makeSubagent(i + 2, "completed")),
]);
const counter = screen.getByLabelText("2 running · 6 total");
assert.equal(counter.textContent, "2/6");
});
15 changes: 12 additions & 3 deletions components/ComposerPanels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ function SubagentsPanel({ subagents, onSelectSubagent, defaultExpanded = false,
(subagent.source !== "history" && subagent.status === "started" ? running : completed).push(subagent);
}
const runningCount = running.length;
// Once nothing runs, the header counts finished subagents instead of
// showing 0/N (#352): "0/6" reads as if nothing finished. Only
// status === "completed" counts: the `completed` bucket above also holds
// failed/aborted runs, and "6/6 complete" must not claim those.
const completedCount = subagents.filter((subagent) => subagent.status === "completed").length;
const headerCount = runningCount === 0 ? completedCount : runningCount;
const headerSummary = runningCount === 0
? t("chatWindow.subagentCompletedSummary", { completed: completedCount, total: subagents.length })
: t("chatWindow.subagentSummary", { running: runningCount, total: subagents.length });

function renderChip(subagent: SubagentInfo) {
const stateLabel = t(SUBAGENT_STATE_KEYS[subagent.status]);
Expand Down Expand Up @@ -252,10 +261,10 @@ function SubagentsPanel({ subagents, onSelectSubagent, defaultExpanded = false,
) : null}
<span
className={`${liveStatus ? "" : "ml-auto "}inline-flex items-center gap-1.5`}
aria-label={t("chatWindow.subagentSummary", { running: runningCount, total: subagents.length })}
title={t("chatWindow.subagentSummary", { running: runningCount, total: subagents.length })}
aria-label={headerSummary}
title={headerSummary}
>
<span>{runningCount}/{subagents.length}</span>
<span>{runningCount === 0 ? headerSummary : `${headerCount}/${subagents.length}`}</span>
</span>
<ChevronDown
size={14}
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@
"chatWindow.subagentState.failed": "Failed",
"chatWindow.subagentState.started": "Running",
"chatWindow.subagentSummary": "{running} running · {total} total",
"chatWindow.subagentCompletedSummary": "{completed}/{total} complete",
"chatWindow.completedSubagents": "Completed ({count})",
"chatWindow.subagentsPanel": "Subagents",
"chatWindow.subagentRetrying": "retrying {attempt}/{max}",
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@
"chatWindow.subagentState.failed": "失敗",
"chatWindow.subagentState.started": "実行中",
"chatWindow.subagentSummary": "{running} 実行中 · {total} 件",
"chatWindow.subagentCompletedSummary": "{completed}/{total} 完了",
"chatWindow.completedSubagents": "完了 ({count})",
"chatWindow.subagentsPanel": "サブエージェント",
"chatWindow.subagentRetrying": "再試行中 {attempt}/{max}",
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@
"chatWindow.subagentState.failed": "失败",
"chatWindow.subagentState.started": "运行中",
"chatWindow.subagentSummary": "{running} 运行中 · 共 {total} 个",
"chatWindow.subagentCompletedSummary": "已完成 {completed}/{total}",
"chatWindow.completedSubagents": "已完成 ({count})",
"chatWindow.subagentsPanel": "子代理",
"chatWindow.subagentRetrying": "重试 {attempt}/{max}",
Expand Down