mirror of
https://github.com/zhukunpenglinyutong/jetbrains-cc-gui.git
synced 2026-08-29 00:41:38 +08:00
7462a91544
This commit implements comprehensive support for the new structured Task management
API (TaskCreate/TaskUpdate/TaskGet/TaskList) introduced in Claude Code SDK, with
enhanced agent workflow visualization through a collapsible group UI.
## Core Implementation
### 1. Tool Constants & Classification (toolConstants.ts)
- Add TASK_MANAGE_TOOL_NAMES set: taskcreate/taskupdate/taskget/tasklist
- Add AGENT_TOOL_NAMES set: task/agent/spawn_agent
- Enable unified tool name normalization for agent-related tools
### 2. AgentGroupBlock Component
A collapsible visualization component for agent/task tool invocations:
- **State Management**: Persist expand/collapse state via expandedState utility
- **Metadata Display**: Show agent type, description (truncated to 120 chars), completion status
- **Subagent Integration**: Load and render subagent conversation history on expansion
- **Statistics**: Display execution metrics (totalDurationMs/totalTokens/toolUseCount)
- **Nested Content**: Render absorbed following tool_use blocks within the group
- **Auto-refresh**: Poll subagent session every 2s during streaming
### 3. Task Extraction Logic (todoToolNormalization.ts)
Implement extractAccumulatedTasks() with two-pass algorithm:
**Pass 1 - Task ID Resolution**:
- Scan user tool_result messages to extract real numeric task IDs
- Primary source: raw.toolUseResult.task.id (from SDK metadata)
- Fallback: Parse task ID from content text
- Build tool_use_id → taskId mapping for subsequent resolution
**Pass 2 - Task Accumulation**:
- Process TaskCreate/TaskUpdate blocks in assistant messages
- Resolve real task IDs using the mapping from Pass 1
- Normalize to TodoItem format with: id/content/status/blockedBy
- Support both subject (title) and description fields
- Deduplicate by task ID (later TaskUpdate overwrites earlier TaskCreate)
### 4. MessageItem Grouping Logic (MessageItem.tsx)
Dynamic agent_group formation with block absorption:
**Detection**:
- Identify agent tool blocks (AGENT_TOOL_NAMES) as group anchors
- TaskCreate/TaskUpdate blocks without accumulated tasks also form agent groups
**Absorption Rules**:
- Absorb subsequent tool_use blocks until hitting:
* Another agent/task tool (new group start)
* Text content block (group boundary)
* End of message
- Absorbed blocks render inside AgentGroupBlock's expanded content
**UI Hiding**:
- Hide standalone tool cards for Task management tools (similar to todowrite/update_plan)
- Only show accumulated tasks in StatusPanel TodoList
### 5. Expand/Collapse State Persistence (expandedState.ts, new)
- getPersistedExpanded(key): Read state from localStorage
- setPersistedExpanded(key, value): Persist state with fallback
- Key format: "agent-group-{toolUseId}" or "agent-group-{messageIndex}"
### 6. Type Extensions
- RawTodoItem: Add optional subject/description fields for TaskCreate/TaskUpdate
- Support both legacy (content/step/title) and new (subject/description) field names
### 7. Styling (task.less)
- .agent-group-container: Container for agent group blocks
- .agent-group-content: Nested content area with padding
- Reuse existing task header/expansion styles
## Integration Points
- **StatusPanel/TodoList**: Receive accumulated tasks from new Task API
- **SubagentContext**: Load subagent history for agent blocks
- **ContentBlockRenderer**: Conditionally render AgentGroupBlock vs standard tool blocks
- **useChatComputations**: Call extractAccumulatedTasks() for task aggregation
## Behavior Changes
- Task management tools (TaskCreate/TaskUpdate/TaskGet/TaskList) no longer show
individual tool cards in the message stream
- Agent/task invocations now appear as collapsible groups with nested tool calls
- Task list in StatusPanel includes both legacy todowrite and new Task API tasks
- Expand/collapse state persists across page reloads
Refs: https://github.com/zhukunpenglinyutong/jetbrains-cc-gui/pull/1220
Co-authored-by: zhuzhihang <zhuzhihang@corp.netease.com>