- Complete architectural overhaul of useUnifiedCompletion hook - Unified state management: 8 separate states → single CompletionState interface - Simplified core logic: getWordAtCursor 194 lines → 42 lines (78% reduction) - Fixed infinite React update loops with ref-based input tracking - Smart triggering mechanism replacing aggressive auto-completion - Integrated @agent and @file mention system with system reminders - Added comprehensive agent loading and mention processing - Enhanced Tab/Arrow/Enter key handling with clean event management - Maintained 100% functional compatibility across all completion types Key improvements: • File path completion (relative, absolute, ~expansion, @references) • Slash command completion (/help, /model, etc.) • Agent completion (@agent-xxx with intelligent descriptions) • System command completion (PATH scanning with fallback) • Terminal-style Tab cycling, Enter confirmation, Escape cancellation • Preview mode with boundary calculation • History navigation compatibility • Empty directory handling with user feedback Architecture: Event-driven @mention detection → system reminder injection → LLM tool usage Performance: Eliminated 7-layer nested conditionals, reduced state synchronization issues Reliability: Fixed maximum update depth exceeded warnings, stable state management
5.2 KiB
5.2 KiB
Subagent System Architecture Changes
Overview
Complete implementation of subagent system for Kode CLI, aligned with Claude Code's original Task tool design.
Core Changes
1. Task Tool Enhancement (src/tools/TaskTool/)
Before:
- Simple task execution with model_name parameter
- No subagent concept
- Fixed "Task" display name
- No agent-specific configurations
After:
- Full subagent system with subagent_type parameter
- Dynamic agent loading and configuration
- Agent-specific display names and colors
- Tool filtering based on agent configuration
- Default to 'general-purpose' agent when not specified
Key Files Modified:
TaskTool.tsx: Core implementation with subagent supportprompt.ts: Dynamic prompt generation with agent descriptions
2. Agent Configuration System (src/utils/agentLoader.ts)
New Component:
- Dynamic agent loading from multiple directories
- Priority system: built-in < user < project
- File watcher for hot reload
- Memoized caching for performance
Agent Configuration Structure:
interface AgentConfig {
agentType: string // Agent identifier
whenToUse: string // Usage description
tools: string[] | '*' // Tool permissions
systemPrompt: string // Agent-specific prompt
location: 'built-in' | 'user' | 'project'
color?: string // Optional UI color
model?: string // Optional model override
}
3. Agent Management UI (src/commands/agents.tsx)
New Command: /agents
- Interactive agent management interface
- Create, edit, delete, view agents
- Support for both
.claude/agentsand.kode/agentsdirectories - YAML frontmatter + markdown body format
4. UI Improvements
Before:
⏺ Taskfor all task executions- No visual distinction between agents
- Fixed display format
After:
⏺ [agent-name]with agent-specific colors- Dynamic color loading from configuration
- Clean display:
model: description - No emojis in tool display
Components Modified:
AssistantToolUseMessage.tsx: Support for dynamic agent namesTaskToolMessage.tsx(new): Dynamic color rendering for agents
5. AskExpertModel Tool Improvements
Enhanced:
- Better distinction from Task tool
- Dynamic model context in description
- Validation to prevent self-referential calls
- Improved error messages with available models
Agent Directory Structure
project/
├── .kode/agents/ # Project-level agents (highest priority)
│ ├── dao-qi-harmony-designer.md
│ ├── code-writer.md
│ └── search-specialist.md
└── ~/.kode/agents/ # User-level agents
└── custom-agent.md
Workflow Changes
Before Workflow:
- User requests task
- Task tool executes with specified model
- Fixed "Task" display
- No agent-specific behavior
After Workflow:
- User requests task (mentions agent or complex task)
- Model selects appropriate subagent_type
- Agent configuration loaded dynamically
- Agent-specific:
- System prompt applied
- Tools filtered based on configuration
- Display name and color shown
- Model override if configured
- Task executes with agent context
Example Agent Configurations
dao-qi-harmony-designer
---
name: dao-qi-harmony-designer
description: Architecture and design harmony specialist
tools: ["Read", "Grep", "Glob", "LS"]
color: red
---
[System prompt content]
code-writer
---
name: code-writer
description: Specialized in writing and modifying code
tools: ["Read", "Write", "Edit", "MultiEdit", "Bash"]
color: blue
---
[System prompt content]
Key Design Principles
- Model-Native Approach: No hardcoded triggers, natural agent selection
- Dynamic Configuration: All agent properties loaded at runtime
- Priority Hierarchy: Project > User > Built-in configurations
- Hot Reload: File watchers for immediate updates
- Backward Compatibility: Default to general-purpose when not specified
Integration Points
With Existing Systems:
- ModelManager for model resolution
- Permission system for tool access
- Theme system for UI colors
- Message system for display
- Tool registry for available tools
New Dependencies:
gray-matter: YAML frontmatter parsing- File system watchers for hot reload
- Memoization for performance
Performance Considerations
- Caching: Memoized agent loading functions
- Lazy Loading: Agents loaded on-demand
- File Watchers: Efficient change detection
- Async Operations: Non-blocking configuration loading
Testing Coverage
- Agent loading from multiple directories
- Priority override system
- Tool filtering
- Dynamic UI updates
- Error handling for missing agents
- Cache invalidation
Migration Path
- Existing Task tool calls continue to work (default to general-purpose)
- New subagent_type parameter is optional
- Gradual adoption of agent configurations
- No breaking changes to existing workflows
Future Enhancements
- Agent templates for common use cases
- Agent composition (agents using other agents)
- Performance metrics per agent
- Agent-specific settings UI
- Export/import agent configurations