feat: show queued prompt count badge in the task sidebar (#2354)
This commit is contained in:
@@ -134,3 +134,21 @@ describe("toSheetItem", () => {
|
||||
).toBe(ERROR_PREVIEW);
|
||||
});
|
||||
});
|
||||
|
||||
describe("toSheetItem queued prompt count", () => {
|
||||
it("carries the queued prompt count from the task status summary", () => {
|
||||
const item = toSheetItem(
|
||||
task({ statusSummary: { revision: 3, updated_at: UPDATED_AT, queued_prompt_count: 2 } }),
|
||||
emptyCtx(),
|
||||
);
|
||||
expect(item.queuedCount).toBe(2);
|
||||
});
|
||||
|
||||
it("leaves queuedCount undefined when nothing is queued", () => {
|
||||
const item = toSheetItem(
|
||||
task({ statusSummary: { revision: 4, updated_at: UPDATED_AT } }),
|
||||
emptyCtx(),
|
||||
);
|
||||
expect(item.queuedCount).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -126,6 +126,9 @@ export function toSheetItem(
|
||||
isRemoteExecutor: task.isRemoteExecutor,
|
||||
remoteExecutorType: task.primaryExecutorType ?? undefined,
|
||||
remoteExecutorName: task.primaryExecutorName ?? undefined,
|
||||
// Queued prompt count badge — same status summary source as the desktop
|
||||
// sidebar mapper (buildSidebarItem) so both surfaces agree.
|
||||
queuedCount: task.statusSummary?.queued_prompt_count,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,31 +1,42 @@
|
||||
"use client";
|
||||
|
||||
import { useAppStore } from "@/components/state-provider";
|
||||
import { IconMail } from "@tabler/icons-react";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip";
|
||||
import { cn, formatRelativeTime } from "@/lib/utils";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useAppStore } from "@/components/state-provider";
|
||||
import { isDebugUI } from "@/lib/config";
|
||||
import type { SessionPollMode } from "@/lib/state/slices/session-runtime/types";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { cn, formatRelativeTime } from "@/lib/utils";
|
||||
|
||||
/** Debug-overlay-only poll-mode legend. `label` stays English on purpose: the
|
||||
* row is gated behind `isDebugUI()`, so these are developer diagnostics rather
|
||||
* than user copy — and a SCREAMING_CASE const is invisible to
|
||||
* `i18next/no-literal-string`, so nothing would have flagged it either way. */
|
||||
const POLL_MODE_CONFIG: Record<SessionPollMode, { letter: string; color: string; label: string }> =
|
||||
{
|
||||
fast: { letter: "F", color: "text-emerald-500", label: "focused, 2s polling" },
|
||||
slow: { letter: "S", color: "text-yellow-500", label: "subscribed, 30s polling" },
|
||||
paused: { letter: "P", color: "text-muted-foreground/40", label: "no subscribers" },
|
||||
};
|
||||
/** Debug-overlay-only poll-mode legend. Labels resolve through `t()` so the
|
||||
* pseudo-locale stays complete; the row itself is gated behind `isDebugUI()`. */
|
||||
const POLL_MODE_CONFIG: Record<
|
||||
SessionPollMode,
|
||||
{ letter: string; color: string; labelKey: string }
|
||||
> = {
|
||||
fast: { letter: "F", color: "text-emerald-500", labelKey: "sidebar:pollModeFastLabel" },
|
||||
slow: { letter: "S", color: "text-yellow-500", labelKey: "sidebar:pollModeSlowLabel" },
|
||||
paused: {
|
||||
letter: "P",
|
||||
color: "text-muted-foreground/40",
|
||||
labelKey: "sidebar:pollModePausedLabel",
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* The sidebar row's metadata line: relative last-update time, PR number,
|
||||
* queued-prompt mail badge, and (debug UI only) the session poll-mode letter.
|
||||
*/
|
||||
export function TaskItemStatsRow({
|
||||
updatedAt,
|
||||
prInfo,
|
||||
primarySessionId,
|
||||
queuedCount,
|
||||
}: {
|
||||
updatedAt?: string;
|
||||
prInfo?: { number: number; state: string; aggregateState?: string };
|
||||
primarySessionId?: string | null;
|
||||
queuedCount?: number;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const pollMode = useAppStore((s) =>
|
||||
@@ -34,9 +45,10 @@ export function TaskItemStatsRow({
|
||||
: null,
|
||||
);
|
||||
|
||||
if (!updatedAt && !prInfo && !pollMode) return null;
|
||||
if (!updatedAt && !prInfo && !pollMode && !queuedCount) return null;
|
||||
|
||||
const modeConfig = pollMode ? POLL_MODE_CONFIG[pollMode] : null;
|
||||
const modeLabel = modeConfig ? t(modeConfig.labelKey) : "";
|
||||
|
||||
return (
|
||||
<span className="flex items-center gap-1.5 text-[11px]">
|
||||
@@ -44,6 +56,17 @@ export function TaskItemStatsRow({
|
||||
<span className="text-muted-foreground/50">{formatRelativeTime(updatedAt)}</span>
|
||||
)}
|
||||
{prInfo && <span className="text-muted-foreground/50">#{prInfo.number}</span>}
|
||||
{queuedCount ? (
|
||||
<span
|
||||
data-testid="sidebar-task-queued-count"
|
||||
aria-label={t("sidebar:queuedPromptCount", { count: queuedCount })}
|
||||
title={t("sidebar:queuedPromptCount", { count: queuedCount })}
|
||||
className="inline-flex shrink-0 items-center gap-0.5 text-muted-foreground/60"
|
||||
>
|
||||
<IconMail className="h-3 w-3" aria-hidden="true" />
|
||||
{queuedCount}
|
||||
</span>
|
||||
) : null}
|
||||
{modeConfig && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
@@ -52,7 +75,7 @@ export function TaskItemStatsRow({
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="right">
|
||||
{t("task:gitPollMode", { mode: pollMode, label: modeConfig.label })}
|
||||
{t("task:gitPollMode", { mode: pollMode, label: modeLabel })}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
|
||||
@@ -391,3 +391,38 @@ describe("TaskItem background-running lifecycle", () => {
|
||||
expect(screen.queryByTestId(RUNNING_ICON_TEST_ID)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("TaskItem queued prompt count badge", () => {
|
||||
const QUEUED_BADGE_TEST_ID = "sidebar-task-queued-count";
|
||||
|
||||
it("shows a mail badge with the count when prompts are queued", () => {
|
||||
renderTaskItem({ queuedCount: 3 });
|
||||
|
||||
const badge = screen.getByTestId(QUEUED_BADGE_TEST_ID);
|
||||
expect(badge.textContent).toBe("3");
|
||||
expect(badge.querySelector("svg")).not.toBeNull();
|
||||
});
|
||||
|
||||
it("hides the badge when nothing is queued", () => {
|
||||
renderTaskItem({ queuedCount: 0 });
|
||||
expect(screen.queryByTestId(QUEUED_BADGE_TEST_ID)).toBeNull();
|
||||
|
||||
renderTaskItem({ queuedCount: undefined });
|
||||
expect(screen.queryByTestId(QUEUED_BADGE_TEST_ID)).toBeNull();
|
||||
});
|
||||
|
||||
it("renders the metadata line for a row whose only metadata is the queued count", () => {
|
||||
renderTaskItem({ queuedCount: 2, updatedAt: undefined });
|
||||
|
||||
const badge = screen.getByTestId(QUEUED_BADGE_TEST_ID);
|
||||
expect(badge.textContent).toBe("2");
|
||||
});
|
||||
|
||||
it("localizes the accessible label with the count", () => {
|
||||
renderTaskItem({ queuedCount: 1 });
|
||||
|
||||
expect(screen.getByTestId(QUEUED_BADGE_TEST_ID).getAttribute("aria-label")).toContain(
|
||||
"queued prompt",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -85,6 +85,8 @@ type TaskItemProps = {
|
||||
onToggleSubtasks?: () => void;
|
||||
repositories?: string[];
|
||||
prInfo?: { number: number; state: string; aggregateState?: string };
|
||||
/** Number of prompts currently en-queued for this task (mail badge). */
|
||||
queuedCount?: number;
|
||||
issueInfo?: { url: string; number: number };
|
||||
isPinned?: boolean;
|
||||
agentErrorMessage?: string | null;
|
||||
@@ -324,6 +326,7 @@ function TaskItemContent({
|
||||
repositories,
|
||||
updatedAt,
|
||||
prInfo,
|
||||
queuedCount,
|
||||
issueInfo,
|
||||
agentErrorMessage,
|
||||
}: {
|
||||
@@ -338,6 +341,7 @@ function TaskItemContent({
|
||||
repositories?: string[];
|
||||
updatedAt?: string;
|
||||
prInfo?: { number: number; state: string; aggregateState?: string };
|
||||
queuedCount?: number;
|
||||
issueInfo?: { url: string; number: number };
|
||||
agentErrorMessage?: string | null;
|
||||
}) {
|
||||
@@ -375,7 +379,12 @@ function TaskItemContent({
|
||||
{repositories.join(" · ")}
|
||||
</span>
|
||||
)}
|
||||
<TaskItemStatsRow updatedAt={updatedAt} prInfo={prInfo} primarySessionId={primarySessionId} />
|
||||
<TaskItemStatsRow
|
||||
updatedAt={updatedAt}
|
||||
prInfo={prInfo}
|
||||
primarySessionId={primarySessionId}
|
||||
queuedCount={queuedCount}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -428,6 +437,7 @@ export const TaskItem = memo(function TaskItem({
|
||||
onToggleSubtasks,
|
||||
repositories,
|
||||
prInfo,
|
||||
queuedCount,
|
||||
issueInfo,
|
||||
isPinned,
|
||||
agentErrorMessage,
|
||||
@@ -474,6 +484,7 @@ export const TaskItem = memo(function TaskItem({
|
||||
repositories={repositories}
|
||||
updatedAt={updatedAt}
|
||||
prInfo={prInfo}
|
||||
queuedCount={queuedCount}
|
||||
issueInfo={issueInfo}
|
||||
agentErrorMessage={agentErrorMessage}
|
||||
/>
|
||||
|
||||
@@ -92,4 +92,22 @@ describe("buildSidebarItem", () => {
|
||||
|
||||
expect(item.isArchived).toBe(true);
|
||||
});
|
||||
|
||||
it("carries the queued prompt count from the status summary", () => {
|
||||
const item = buildSidebarItem(
|
||||
task({ statusSummary: { revision: 4, updated_at: UPDATED_AT, queued_prompt_count: 3 } }),
|
||||
emptyContext(),
|
||||
);
|
||||
|
||||
expect(item.queuedCount).toBe(3);
|
||||
});
|
||||
|
||||
it("leaves queuedCount undefined when the summary has no queued prompts", () => {
|
||||
const item = buildSidebarItem(
|
||||
task({ statusSummary: { revision: 5, updated_at: UPDATED_AT } }),
|
||||
emptyContext(),
|
||||
);
|
||||
|
||||
expect(item.queuedCount).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -104,6 +104,7 @@ function sidebarStatus(
|
||||
hasPendingPermission: pending.permission,
|
||||
prInfo: summaryPRInfo(summary),
|
||||
issueInfo: issueInfoForTask(task),
|
||||
queuedCount: summary?.queued_prompt_count,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -154,6 +154,7 @@ function TaskRowItem({
|
||||
updatedAt={task.updatedAt}
|
||||
repositories={task.repositories}
|
||||
prInfo={task.prInfo}
|
||||
queuedCount={task.queuedCount}
|
||||
issueInfo={task.issueInfo}
|
||||
agentErrorMessage={task.agentErrorMessage}
|
||||
isSubTask={isSubTask}
|
||||
|
||||
@@ -39,6 +39,8 @@ export type TaskSwitcherItem = {
|
||||
parentTaskId?: string;
|
||||
workspaceMode?: "inherit_parent" | "new_workspace" | "shared_group";
|
||||
prInfo?: { number: number; state: string; aggregateState?: string };
|
||||
/** Number of prompts currently en-queued for this task (mail badge). */
|
||||
queuedCount?: number;
|
||||
isPRReview?: boolean;
|
||||
isIssueWatch?: boolean;
|
||||
issueInfo?: { url: string; number: number };
|
||||
|
||||
@@ -2141,6 +2141,11 @@ export class ApiClient {
|
||||
});
|
||||
}
|
||||
|
||||
/** Removes every pending queued message for a session (message.queue.cancel). */
|
||||
async clearQueue(sessionId: string): Promise<void> {
|
||||
await this.wsRequest("message.queue.cancel", { session_id: sessionId });
|
||||
}
|
||||
|
||||
// --- Integration config seeding (real API, not mock) ---
|
||||
|
||||
async setJiraConfig(payload: {
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Mobile parity for the sidebar queued prompt count badge.
|
||||
*
|
||||
* The mobile task-switcher sheet renders through the same TaskItem rows as
|
||||
* the desktop sidebar, so the mail badge must appear there too, without any
|
||||
* hover dependency. Lives in `mobile-*.spec.ts` so the `mobile-chrome`
|
||||
* Playwright project applies the mobile device automatically.
|
||||
*/
|
||||
import { test, expect } from "../../fixtures/test-base";
|
||||
import { SessionPage } from "../../pages/session-page";
|
||||
|
||||
test.describe("Mobile sidebar — queued prompt count", () => {
|
||||
test("shows the queued count badge in the task switcher sheet", async ({
|
||||
testPage,
|
||||
apiClient,
|
||||
seedData,
|
||||
}) => {
|
||||
const task = await apiClient.createTask(seedData.workspaceId, "Mobile Queued Badge Task", {
|
||||
workflow_id: seedData.workflowId,
|
||||
workflow_step_id: seedData.startStepId,
|
||||
repository_ids: [seedData.repositoryId],
|
||||
});
|
||||
const { session_id: sessionId } = await apiClient.seedTaskSession(task.id, {
|
||||
state: "IDLE",
|
||||
agentProfileId: seedData.agentProfileId,
|
||||
});
|
||||
await apiClient.queueMessage(task.id, sessionId, "Mobile queued prompt");
|
||||
|
||||
await testPage.goto(`/t/${task.id}`);
|
||||
const session = new SessionPage(testPage);
|
||||
await session.waitForLoad();
|
||||
|
||||
// Open the task switcher sheet from the mobile session top bar.
|
||||
await testPage.getByTestId("mobile-session-menu").click();
|
||||
const sheet = testPage.getByRole("dialog");
|
||||
await expect(sheet.getByText("Mobile Queued Badge Task")).toBeVisible({ timeout: 10_000 });
|
||||
|
||||
const badge = sheet
|
||||
.locator(`[data-testid='sortable-task-block'][data-task-id='${task.id}']`)
|
||||
.getByTestId("sidebar-task-queued-count");
|
||||
await expect(badge).toBeVisible({ timeout: 10_000 });
|
||||
await expect(badge).toHaveText("1");
|
||||
|
||||
await testPage.screenshot({
|
||||
path: "e2e/test-results/screenshots/sidebar-queued-count-mobile.png",
|
||||
fullPage: false,
|
||||
});
|
||||
|
||||
// No horizontal overflow from the badge on a phone viewport: the badge
|
||||
// stays within the sheet's horizontal bounds.
|
||||
const [sheetBox, badgeBox] = await Promise.all([sheet.boundingBox(), badge.boundingBox()]);
|
||||
expect(sheetBox).not.toBeNull();
|
||||
expect(badgeBox).not.toBeNull();
|
||||
expect(badgeBox!.x).toBeGreaterThanOrEqual(sheetBox!.x);
|
||||
expect(badgeBox!.x + badgeBox!.width).toBeLessThanOrEqual(sheetBox!.x + sheetBox!.width);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* E2E for the sidebar queued prompt count badge.
|
||||
*
|
||||
* Every task and subtask row in the left task view shows a mail badge with
|
||||
* the number of prompts en-queued for that task. Covers:
|
||||
* - Badge appears with the right count after prompts are queued
|
||||
* - Badge disappears live (no reload) when the queue is cleared
|
||||
* - No badge on a task with an empty queue
|
||||
* - Subtask rows get the same badge treatment
|
||||
*/
|
||||
import { test, expect } from "../../fixtures/test-base";
|
||||
import { SessionPage } from "../../pages/session-page";
|
||||
|
||||
const stepOpts = (seedData: { workflowId: string; startStepId: string }) => ({
|
||||
workflow_id: seedData.workflowId,
|
||||
workflow_step_id: seedData.startStepId,
|
||||
});
|
||||
|
||||
function queuedBadge(page: SessionPage, taskId: string) {
|
||||
return page.sidebar
|
||||
.locator(`[data-testid='sortable-task-block'][data-task-id='${taskId}']`)
|
||||
.getByTestId("sidebar-task-queued-count");
|
||||
}
|
||||
|
||||
test.describe("Sidebar queued prompt count", () => {
|
||||
test("shows a mail badge with the queued count and clears live", async ({
|
||||
testPage,
|
||||
apiClient,
|
||||
seedData,
|
||||
}) => {
|
||||
const task = await apiClient.createTask(seedData.workspaceId, "Queued Badge Task", {
|
||||
...stepOpts(seedData),
|
||||
repository_ids: [seedData.repositoryId],
|
||||
});
|
||||
const { session_id: sessionId } = await apiClient.seedTaskSession(task.id, {
|
||||
state: "IDLE",
|
||||
agentProfileId: seedData.agentProfileId,
|
||||
});
|
||||
for (let index = 0; index < 3; index++) {
|
||||
await apiClient.queueMessage(task.id, sessionId, `Queued prompt ${index + 1}`);
|
||||
}
|
||||
|
||||
await testPage.goto(`/t/${task.id}`);
|
||||
const session = new SessionPage(testPage);
|
||||
await session.waitForLoad();
|
||||
await expect(session.sidebar).toBeVisible({ timeout: 10_000 });
|
||||
|
||||
const badge = queuedBadge(session, task.id);
|
||||
await expect(badge).toBeVisible({ timeout: 10_000 });
|
||||
await expect(badge).toHaveText("3");
|
||||
await expect(badge.locator("svg")).toHaveCount(1);
|
||||
|
||||
await testPage.screenshot({
|
||||
path: "e2e/test-results/screenshots/sidebar-queued-count-desktop.png",
|
||||
fullPage: false,
|
||||
});
|
||||
|
||||
// Clearing the queue must remove the badge without a reload (live path
|
||||
// through the status-summary broadcast).
|
||||
await apiClient.clearQueue(sessionId);
|
||||
await expect(badge).not.toBeVisible({ timeout: 10_000 });
|
||||
});
|
||||
|
||||
test("shows no badge for a task with an empty queue", async ({
|
||||
testPage,
|
||||
apiClient,
|
||||
seedData,
|
||||
}) => {
|
||||
const task = await apiClient.createTask(seedData.workspaceId, "Empty Queue Task", {
|
||||
...stepOpts(seedData),
|
||||
repository_ids: [seedData.repositoryId],
|
||||
});
|
||||
|
||||
await testPage.goto(`/t/${task.id}`);
|
||||
const session = new SessionPage(testPage);
|
||||
await session.waitForLoad();
|
||||
|
||||
await expect(session.sidebar.getByText("Empty Queue Task")).toBeVisible({ timeout: 10_000 });
|
||||
await expect(queuedBadge(session, task.id)).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("shows the badge on a subtask row", async ({ testPage, apiClient, seedData }) => {
|
||||
const parent = await apiClient.createTask(seedData.workspaceId, "Badge Parent Task", {
|
||||
...stepOpts(seedData),
|
||||
repository_ids: [seedData.repositoryId],
|
||||
});
|
||||
const child = await apiClient.createTask(seedData.workspaceId, "Badge Child Task", {
|
||||
...stepOpts(seedData),
|
||||
parent_id: parent.id,
|
||||
});
|
||||
const { session_id: sessionId } = await apiClient.seedTaskSession(child.id, {
|
||||
state: "IDLE",
|
||||
agentProfileId: seedData.agentProfileId,
|
||||
});
|
||||
await apiClient.queueMessage(child.id, sessionId, "Subtask queued prompt");
|
||||
|
||||
await testPage.goto(`/t/${parent.id}`);
|
||||
const session = new SessionPage(testPage);
|
||||
await session.waitForLoad();
|
||||
|
||||
const badge = queuedBadge(session, child.id);
|
||||
await expect(badge).toBeVisible({ timeout: 10_000 });
|
||||
await expect(badge).toHaveText("1");
|
||||
});
|
||||
});
|
||||
@@ -10,6 +10,8 @@ export type TaskStatusSummary = {
|
||||
foreground_activity?: ForegroundActivity;
|
||||
active_subagent_count?: number;
|
||||
pending_action?: TaskPendingAction;
|
||||
/** Number of prompts currently en-queued for the task (all sessions). */
|
||||
queued_prompt_count?: number;
|
||||
active_error?: {
|
||||
session_id: string;
|
||||
stamp: string;
|
||||
|
||||
@@ -54,9 +54,14 @@
|
||||
"offline": "Offline",
|
||||
"openStatus": "Open status",
|
||||
"pausedBadge": "paused",
|
||||
"pollModeFastLabel": "focused, 2s polling",
|
||||
"pollModePausedLabel": "no subscribers",
|
||||
"pollModeSlowLabel": "subscribed, 30s polling",
|
||||
"preferences": "Preferences",
|
||||
"profileAndPassword": "Profile & Password",
|
||||
"projects": "Projects",
|
||||
"queuedPromptCount_one": "{{count}} queued prompt",
|
||||
"queuedPromptCount_other": "{{count}} queued prompts",
|
||||
"quickChat": "Quick Chat",
|
||||
"quickTerminal": "Quick terminal",
|
||||
"quickChatTerminals": "Terminals",
|
||||
|
||||
@@ -54,9 +54,14 @@
|
||||
"offline": "Ōƒƒĺĩńē",
|
||||
"openStatus": "Ōƥēń śţàţũś",
|
||||
"pausedBadge": "ƥàũśēď",
|
||||
"pollModeFastLabel": "ƒōćũśēď, 2ś ƥōĺĺĩńĝ",
|
||||
"pollModePausedLabel": "ńō śũƀśćŕĩƀēŕś",
|
||||
"pollModeSlowLabel": "śũƀśćŕĩƀēď, 30ś ƥōĺĺĩńĝ",
|
||||
"preferences": "Ƥŕēƒēŕēńćēś",
|
||||
"profileAndPassword": "Ƥŕōƒĩĺē & Ƥàśśŵōŕď",
|
||||
"projects": "Ƥŕōĵēćţś",
|
||||
"queuedPromptCount_one": "{{count}} qũēũēď ƥŕōḿƥţ",
|
||||
"queuedPromptCount_other": "{{count}} qũēũēď ƥŕōḿƥţś",
|
||||
"quickChat": "Qũĩćķ Ćĥàţ",
|
||||
"quickTerminal": "Qũĩćķ ţēŕḿĩńàĺ",
|
||||
"quickChatTerminals": "Ţēŕḿĩńàĺś",
|
||||
|
||||
Reference in New Issue
Block a user