Introduces a new tool abstraction that runs in parallel to existing
command-mode. M1 is skeleton-only: Tool interface + builder DSL +
Flow-based executor + BashTool wrapping CommandExecutionService.
No UI wiring; command-mode untouched. Cutover planned for M5.
Tests: 7 ToolExecutorTest cases covering happy path, progress
forwarding, and validate/permission/execute/parse failure branches.
Docs:
- phase2-tools-refactor-brief.md — why (architecture-driven, not user-pain)
- phase2-tools-design-notes.md — how (Kotlin interface <-> Claude Code map)
- phase2-mvp-tool-specs.md — what (4 MVP tools across 3 families)
- phase2-milestone-1-summary.md — M1 delivery record
User description
Summary
Phase2 M1 — the skeleton of the new tool abstraction layer, running in parallel to existing command-mode. No UI wiring, command-mode completely untouched. Cutover is planned for M5.
What's new (under
com.github.codeplangui.tools):Tool.kt— genericTool<Input, Output>interface (4 required methods + defaults for ~10 more)ToolTypes.kt—ValidationResult/PermissionResult(Allow/Ask/Deny) /ToolResult/Progress/ToolUpdateToolExecutionContext.kt— narrow runtime context (4 fields; Claude Code's analog has 30+)ToolBuilder.kt—tool { }DSL (matches Claude Code'sbuildTool()factory)ToolExecutor.kt—runToolUsereturningFlow<ToolUpdate>(Claude Code's entry is an AsyncGenerator)bash/BashTool.kt— first concrete tool, wraps existingCommandExecutionService, includes destructive-command heuristicsDocs (
docs/phase2-*):phase2-tools-refactor-brief.md— why (architecture-driven, not user-pain-driven)phase2-tools-design-notes.md— how (Kotlin interface ↔ Claude Code mapping)phase2-mvp-tool-specs.md— what (4 MVP tools: Bash / FileRead / FileEdit / MCPProxy)phase2-milestone-1-summary.md— M1 delivery record + M2 handoff notesTest plan
./gradlew compileKotlinpasses (Corretto 17 — Java 25 crashes the Kotlin compiler, see~/.claude/projects/.../memory/project_java_home.md)./gradlew test --tests ToolExecutorTestpasses — 7 cases covering happy path, progress forwarding, and validate/permission/execute/parse failure branchesphase2-milestone-1-summary.md§"锁定的设计选择" and confirm the trade-offsExplicitly NOT in scope
ChatPanel/BridgeHandlerstill route through command-modePermissionResult.Ask(currently auto-approved as placeholder) → M3runToolUseBatch) → M2assembleToolPoolequivalent → M2Relation to existing code
Zero-touch.
execution/package (command-mode) is not modified.BashToolconsumesCommandExecutionServicevia its existing public API; no changes to the service itself.References
~/SourceLib/fishNotExist/claude-code-source/—src/Tool.ts,src/tools.ts,src/services/tools/toolExecution.tsPR Type
Enhancement, Tests
Description
Introduce Tool<Input, Output> interface with generic types, 4 required methods (parse/call/mapResult/checkPermissions), and default methods for metadata predicates
Add ToolBuilder DSL (
tool { }function) for declarative tool construction matching Claude Code's buildTool() patternImplement Flow-based ToolExecutor (
runToolUsereturning Flow) for streaming execution instead of suspend functionsCreate BashTool as first concrete tool wrapping existing CommandExecutionService with destructive-command heuristics
Add 7 test cases covering happy path, progress forwarding, validation/permission/execute/parse failure branches
Diagram Walkthrough
flowchart LR A[LLM tool_use] --> B[runToolUse Flow] B --> C{Parse Input} C -->|OK| D{Validate Input} C -->|Fail| E[Failed PARSE] D -->|OK| F{Check Permissions} D -->|Fail| G[Failed VALIDATE] F -->|Allow| H[Tool.call] F -->|Ask| I[PermissionAsked] F -->|Deny| J[Failed PERMISSION] I -->|auto-approve| H H --> K[Progress events] H --> L[ToolResult] L --> M[mapResultToApiBlock] M --> N[Completed]File Walkthrough
6 files
Define generic Tool interface with lifecycle methodsCreate DSL builder for tool constructionDefine runtime execution context data classImplement Flow-based tool execution engineDefine sealed types for validation/permission/resultsImplement first concrete BashTool wrapping service1 files
Add 7 test cases for executor flow4 files
Document M1 delivery record and design choicesSpecify MVP tool requirements and behaviorRecord architecture design decisions and rationaleOutline refactor motivation and scope