Files
hapi/cli/src/claude/utils/getToolName.ts
T
06b71dbe98 feat: Add Claude Code Agent Teams support (#258)
* feat: Add Claude Code Agent Teams support

- Add TeamState schemas and types for team collaboration
- Extract team state from TeamCreate, SendMessage, Task tools
- Add database migration V3→V4 for team_state storage
- Add TeamPanel component to display team members, tasks, messages
- Add team tool icons and presentation rules
- Support vite proxy configuration via VITE_HUB_PROXY env var

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <noreply@hapi.run>

* fix: Add timestamp protection for team_state updates

Prevent old messages from overwriting newer team state by checking
team_state_updated_at before updating.

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <noreply@hapi.run>

* fix: Extract team tasks from Task/TaskCreate/TaskUpdate tools

- Enhance processTaskToolWithTeam to also generate task entries from
  the Task tool's description field when spawning teammates
- Add processTaskCreate handler for TaskCreate tool calls
- Add processTaskUpdate handler for TaskUpdate tool calls
- Register both new tools in the extraction switch statement

This fixes the gap where the Tasks section in TeamPanel could never
populate because team task data was not being extracted from the
message stream.

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <noreply@hapi.run>

* fix: Skip orphan TaskUpdate without title to prevent schema validation failure

When TaskUpdate arrives before TaskCreate (message ordering), skip inserting
incomplete tasks that lack required title field, preventing entire teamState
from being dropped by schema validation.

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <noreply@hapi.run>

* test: Add unit tests for orphan TaskUpdate handling

Verify that applyTeamStateDelta correctly skips inserting tasks without
title field (orphan TaskUpdate) while still allowing normal task creation
and updates to existing tasks.

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <noreply@hapi.run>

---------

Co-authored-by: tfq <tfq@gmail.com>
Co-authored-by: HAPI <noreply@hapi.run>
2026-03-08 11:26:11 +08:00

81 lines
2.3 KiB
TypeScript

/**
* Converts tool names to human-readable format for UI display
*
* Handles standard Claude tools, MCP tools, and special cases to provide
* user-friendly tool names in notifications and permission requests.
*/
// Mapping for standard Claude Code tools
const STANDARD_TOOLS: Record<string, string> = {
// File operations
'Read': 'Read File',
'Write': 'Write File',
'Edit': 'Edit File',
'MultiEdit': 'Edit File',
'NotebookEdit': 'Edit Notebook',
// Search and navigation
'Glob': 'Find Files',
'Grep': 'Search in Files',
'LS': 'List Directory',
// Command execution
'Bash': 'Run Command',
'BashOutput': 'Check Command Output',
'KillBash': 'Stop Command',
// Task management
'TodoWrite': 'Update Tasks',
'TodoRead': 'Read Tasks',
'Task': 'Launch Agent',
// Team management
'TeamCreate': 'Create Team',
'TeamDelete': 'Delete Team',
'SendMessage': 'Send Message',
'EnterWorktree': 'Enter Worktree',
// Web tools
'WebFetch': 'Fetch Web Page',
'WebSearch': 'Search Web',
// Special cases
'exit_plan_mode': 'Execute Plan',
'ExitPlanMode': 'Execute Plan'
};
/**
* Converts snake_case or camelCase to Title Case
*/
function toTitleCase(str: string): string {
return str
// Handle camelCase - insert space before uppercase letters
.replace(/([a-z])([A-Z])/g, '$1 $2')
// Handle snake_case - replace underscores with spaces
.replace(/_/g, ' ')
// Capitalize first letter of each word
.replace(/\b\w/g, char => char.toUpperCase());
}
/**
* Converts tool name to human-readable format
*/
export function getToolName(toolName: string): string {
// Check if it's a standard tool
if (STANDARD_TOOLS[toolName]) {
return STANDARD_TOOLS[toolName];
}
// Check if it's an MCP tool (format: mcp__server__action)
if (toolName.startsWith('mcp__')) {
const parts = toolName.split('__');
if (parts.length >= 3) {
const server = toTitleCase(parts[1]);
const action = toTitleCase(parts.slice(2).join('_'));
return `${server}: ${action}`;
}
}
// For unknown tools, try to make them more readable
return toTitleCase(toolName);
}