Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ qdrant_storage/
plans/

roo-cli-*.tar.gz*
.zoocode/
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { render } from "ink-testing-library"

import type { TUIMessage } from "../../types.js"
import { extractToolData } from "../../utils/tools.js"
import ChatHistoryItem from "../ChatHistoryItem.js"
import { resetNerdFontCache } from "../Icon.js"

describe("ChatHistoryItem parallel subtasks row", () => {
beforeEach(() => {
// Use fallback icons in tests so they render as visible characters
process.env.ROOCODE_NERD_FONT = "0"
resetNerdFontCache()
})

afterEach(() => {
delete process.env.ROOCODE_NERD_FONT
resetNerdFontCache()
})

it("shows the tool label and delegation icon instead of the generic fallback", () => {
const payload = {
tool: "parallelSubtasks",
tasks: [{ label: "api", mode: "architect", message: "Map the REST surface" }],
}
const message: TUIMessage = {
id: "1",
role: "tool",
content: JSON.stringify(payload),
toolName: "parallelSubtasks",
toolData: extractToolData(payload),
}

const { lastFrame } = render(<ChatHistoryItem message={message} />)
const output = lastFrame()

expect(output).toContain("Parallel Subtasks")
expect(output).not.toContain("⚙")
expect(output).not.toContain("parallelSubtasks")
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { IconName } from "../../Icon.js"
import type { ToolCategory } from "../types.js"
import { getToolCategory } from "../types.js"
import { getToolDisplayName, getToolIconName } from "../utils.js"

describe("parallel subtasks display mapping", () => {
it.each(["parallelSubtasks", "parallel_subtasks"])("returns a friendly display name for %s", (toolName) => {
expect(getToolDisplayName(toolName)).toBe("Parallel Subtasks")
})

it.each(["parallelSubtasks", "parallel_subtasks"])("returns the delegation icon for %s", (toolName) => {
expect(getToolIconName(toolName)).toBe("switch")
})

it.each(["parallelSubtasks", "parallel_subtasks"])("routes %s to the generic renderer", (toolName) => {
// ModeTool renders only an icon for tools whose name lacks "switch", so the
// label would disappear if this row were routed to the mode category.
expect(getToolCategory(toolName)).toBe("other")
})
})

describe("existing tool display mapping", () => {
const cases: Array<{ tool: string; displayName: string; icon: IconName; category: ToolCategory }> = [
{ tool: "newTask", displayName: "New Task", icon: "switch", category: "mode" },
{ tool: "new_task", displayName: "New Task", icon: "switch", category: "mode" },
{ tool: "finishTask", displayName: "Finish Task", icon: "check", category: "mode" },
{ tool: "switchMode", displayName: "Switch Mode", icon: "switch", category: "mode" },
{ tool: "switch_mode", displayName: "Switch Mode", icon: "switch", category: "mode" },
{ tool: "attempt_completion", displayName: "Task Complete", icon: "check", category: "completion" },
]

it.each(cases)("keeps the $tool mapping intact", ({ tool, displayName, icon, category }) => {
expect(getToolDisplayName(tool)).toBe(displayName)
expect(getToolIconName(tool)).toBe(icon)
expect(getToolCategory(tool)).toBe(category)
})
})
8 changes: 8 additions & 0 deletions apps/cli/src/ui/components/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export function getToolDisplayName(toolName: string): string {
new_task: "New Task",
finishTask: "Finish Task",

// Parallel subtask operations
parallelSubtasks: "Parallel Subtasks",
parallel_subtasks: "Parallel Subtasks",

// Completion operations
attempt_completion: "Task Complete",
attemptCompletion: "Task Complete",
Expand Down Expand Up @@ -122,6 +126,10 @@ export function getToolIconName(toolName: string): IconName {
new_task: "switch",
finishTask: "check",

// Parallel subtask operations
parallelSubtasks: "switch",
parallel_subtasks: "switch",

// Completion operations
attempt_completion: "check",
attemptCompletion: "check",
Expand Down
13 changes: 13 additions & 0 deletions apps/cli/src/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ export interface ToolData {
}>
}>

// Parallel subtask fields
/** Child rows reported by the parallel_subtasks tool (approval asks use `tasks`, progress rows use `subtasks`) */
subtasks?: Array<{
taskId?: string
label?: string
mode?: string
message?: string
status?: string
reportPath?: string
summary?: string
error?: string
}>

// Question/completion fields
/** Question text for ask_followup_question */
question?: string
Expand Down
83 changes: 83 additions & 0 deletions apps/cli/src/ui/utils/__tests__/tools.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { extractToolData } from "../tools.js"

describe("extractToolData for parallel subtasks", () => {
it("extracts the approval rows sent under tasks", () => {
const toolData = extractToolData({
tool: "parallelSubtasks",
tasks: [
{ label: "api", mode: "architect", message: "Map the REST surface" },
{ label: "tests", mode: "ask", message: "Find untested modules" },
],
})

expect(toolData.tool).toBe("parallelSubtasks")
expect(toolData.subtasks).toHaveLength(2)
expect(toolData.subtasks?.[0]).toMatchObject({
label: "api",
mode: "architect",
message: "Map the REST surface",
})
expect(toolData.subtasks?.[1]).toMatchObject({
label: "tests",
mode: "ask",
message: "Find untested modules",
})
})

it("extracts the terminal progress rows sent under subtasks", () => {
const toolData = extractToolData({
tool: "parallelSubtasks",
subtasks: [
{
taskId: "child-1",
label: "api",
mode: "architect",
status: "completed",
reportPath: "/workspace/.zoocode/subtask-reports/parent/api-child-1.md",
summary: "3 endpoints mapped",
},
{
taskId: "child-2",
label: "tests",
mode: "ask",
status: "failed",
error: "denied write_to_file",
},
],
})

expect(toolData.subtasks).toHaveLength(2)
expect(toolData.subtasks?.[0]).toMatchObject({
taskId: "child-1",
label: "api",
mode: "architect",
status: "completed",
reportPath: "/workspace/.zoocode/subtask-reports/parent/api-child-1.md",
summary: "3 endpoints mapped",
})
expect(toolData.subtasks?.[1]).toMatchObject({
taskId: "child-2",
status: "failed",
error: "denied write_to_file",
})
})

it("prefers subtasks over tasks when both are present", () => {
const toolData = extractToolData({
tool: "parallelSubtasks",
tasks: [{ label: "stale", mode: "code", message: "approval row" }],
subtasks: [{ label: "live", mode: "code", status: "running" }],
})

expect(toolData.subtasks).toHaveLength(1)
expect(toolData.subtasks?.[0]).toMatchObject({ label: "live", status: "running" })
})

it.each([
{ name: "a missing tasks array", payload: { tool: "parallelSubtasks" }, expected: undefined },
{ name: "a non-array tasks value", payload: { tool: "parallelSubtasks", tasks: "nope" }, expected: undefined },
{ name: "an empty tasks array", payload: { tool: "parallelSubtasks", tasks: [] }, expected: [] },
])("tolerates $name", ({ payload, expected }) => {
expect(extractToolData(payload).subtasks).toEqual(expected)
})
})
16 changes: 16 additions & 0 deletions apps/cli/src/ui/utils/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ export function extractToolData(toolInfo: Record<string, unknown>): ToolData {
}))
}

// Extract parallel subtask rows (approval asks send "tasks", progress rows send "subtasks")
const subtaskRows = Array.isArray(toolInfo.subtasks) ? toolInfo.subtasks : toolInfo.tasks

if (Array.isArray(subtaskRows)) {
toolData.subtasks = (subtaskRows as Array<Record<string, unknown>>).map((s) => ({
taskId: s.taskId as string | undefined,
label: s.label as string | undefined,
mode: s.mode as string | undefined,
message: s.message as string | undefined,
status: s.status as string | undefined,
reportPath: s.reportPath as string | undefined,
summary: s.summary as string | undefined,
error: s.error as string | undefined,
}))
}

// Extract question/completion fields
if (toolInfo.question !== undefined) {
toolData.question = toolInfo.question as string
Expand Down
Loading
Loading