Commit Graph

14 Commits

Author SHA1 Message Date
yinwm
28734c3a2e feat: US-018 - Add SubagentTool with ToolResult support
Created new SubagentTool for synchronous subagent execution:
- Implements Tool interface with Name(), Description(), Parameters(), SetContext(), Execute()
- Returns ToolResult with ForUser (summary), ForLLM (full details), Silent=false, Async=false
- Registered in AgentLoop with context support
- Comprehensive test file subagent_tool_test.go with 9 passing tests

Acceptance criteria met:
- ForUser contains subagent output summary (truncated to 500 chars)
- ForLLM contains full execution details with label and result
- Typecheck passes (go build ./... succeeds)
- go test ./pkg/tools -run TestSubagentTool passes (all 9 tests pass)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 20:14:21 +08:00
yinwm
35fa64cde8 feat: US-015 - Add EditTool tests
Added comprehensive test coverage for EditTool (EditFileTool, AppendFileTool) with 10 test cases:
- TestEditTool_EditFile_Success: Verifies successful file editing
- TestEditTool_EditFile_NotFound: Verifies error handling for non-existent files
- TestEditTool_EditFile_OldTextNotFound: Verifies error when old_text not found
- TestEditTool_EditFile_MultipleMatches: Verifies error for multiple occurrences
- TestEditTool_EditFile_OutsideAllowedDir: Verifies directory restriction
- TestEditTool_EditFile_MissingPath: Verifies missing path parameter
- TestEditTool_EditFile_MissingOldText: Verifies missing old_text parameter
- TestEditTool_EditFile_MissingNewText: Verifies missing new_text parameter
- TestEditTool_AppendFile_Success: Verifies successful file appending
- TestEditTool_AppendFile_MissingPath: Verifies missing path for append
- TestEditTool_AppendFile_MissingContent: Verifies missing content for append

EditTool implementation already conforms to ToolResult specification:
- EditFile returns SilentResult('File edited: ...')
- AppendFile returns SilentResult('Appended to ...')
- Errors return ErrorResult with IsError=true

EditFileTool includes security feature: optional directory restriction to prevent editing files outside allowed paths.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 19:55:57 +08:00
yinwm
0ac93d4429 feat: US-014 - Add WebTool tests
Added comprehensive test coverage for WebTool (WebSearchTool, WebFetchTool) with 9 test cases:
- TestWebTool_WebFetch_Success: Verifies successful URL fetching
- TestWebTool_WebFetch_JSON: Verifies JSON content handling
- TestWebTool_WebFetch_InvalidURL: Verifies error handling for invalid URLs
- TestWebTool_WebFetch_UnsupportedScheme: Verifies only http/https allowed
- TestWebTool_WebFetch_MissingURL: Verifies missing URL parameter handling
- TestWebTool_WebFetch_Truncation: Verifies content truncation at maxChars
- TestWebTool_WebSearch_NoApiKey: Verifies API key requirement
- TestWebTool_WebSearch_MissingQuery: Verifies missing query parameter
- TestWebTool_WebFetch_HTMLExtraction: Verifies HTML tag removal and text extraction
- TestWebTool_WebFetch_MissingDomain: Verifies domain validation

WebTool implementation already conforms to ToolResult specification:
- WebFetch returns ForUser=fetched content, ForLLM=summary with byte count
- WebSearch returns ForUser=search results, ForLLM=result count
- Errors return ErrorResult with IsError=true

Tests use httptest.NewServer for mock HTTP servers, avoiding external API dependencies.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 19:54:44 +08:00
yinwm
88014ecaff feat: US-013 - Add FilesystemTool tests
Added comprehensive test coverage for FilesystemTool (ReadFileTool, WriteFileTool, ListDirTool) with 10 test cases:
- TestFilesystemTool_ReadFile_Success: Verifies file content goes to ForLLM
- TestFilesystemTool_ReadFile_NotFound: Verifies error handling for missing files
- TestFilesystemTool_ReadFile_MissingPath: Verifies missing parameter handling
- TestFilesystemTool_WriteFile_Success: Verifies SilentResult behavior
- TestFilesystemTool_WriteFile_CreateDir: Verifies automatic directory creation
- TestFilesystemTool_WriteFile_MissingPath: Verifies missing path parameter handling
- TestFilesystemTool_WriteFile_MissingContent: Verifies missing content parameter handling
- TestFilesystemTool_ListDir_Success: Verifies directory listing functionality
- TestFilesystemTool_ListDir_NotFound: Verifies error handling for invalid paths
- TestFilesystemTool_ListDir_DefaultPath: Verifies default to current directory

FilesystemTool implementation already conforms to ToolResult specification:
- ReadFile/ListDir return NewToolResult (ForLLM only, ForUser empty)
- WriteFile returns SilentResult (Silent=true, ForUser empty)
- Errors return ErrorResult with IsError=true

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 19:53:00 +08:00
yinwm
e7e3f95ebe feat: US-012 - Add ShellTool tests
Added comprehensive test coverage for ShellTool (ExecTool) with 9 test cases:
- TestShellTool_Success: Verifies successful command execution
- TestShellTool_Failure: Verifies failed command execution with IsError flag
- TestShellTool_Timeout: Verifies command timeout handling
- TestShellTool_WorkingDir: Verifies custom working directory support
- TestShellTool_DangerousCommand: Verifies safety guard blocks dangerous commands
- TestShellTool_MissingCommand: Verifies error handling for missing command
- TestShellTool_StderrCapture: Verifies stderr is captured and included
- TestShellTool_OutputTruncation: Verifies long output is truncated
- TestShellTool_RestrictToWorkspace: Verifies workspace restriction

ShellTool implementation already conforms to ToolResult specification:
- Success returns ForUser = command output
- Failure returns IsError = true
- ForLLM contains full output and exit code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 19:52:16 +08:00
yinwm
2989c391e3 feat: US-011 - Add MessageTool tests
- Added comprehensive test suite for MessageTool (message_test.go)
- 10 test cases covering all acceptance criteria:
  - Success returns SilentResult with proper ForLLM status
  - ForUser is empty (user receives message directly)
  - Failure returns ErrorResult with IsError=true
  - Custom channel/chat_id parameter handling
  - Error scenarios (missing content, no target, not configured)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 19:50:53 +08:00
yinwm
feba44ecf0 feat: US-010 - Add RecordLastChannel to AgentLoop with atomic state save
- Add state *state.Manager field to AgentLoop struct
- Initialize stateManager in NewAgentLoop using state.NewManager
- Implement RecordLastChannel method that calls state.SetLastChannel
- Implement RecordLastChatID method for chat ID tracking
- Add comprehensive tests for state persistence
- Verify state survives across AgentLoop instances

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 19:49:36 +08:00
yinwm
b94941da4a feat: US-009 - Add state save atomicity with SetLastChannel
- Create pkg/state package with State and Manager structs
- Implement SetLastChannel with atomic save using temp file + rename
- Implement SetLastChatID with same atomic save pattern
- Add GetLastChannel, GetLastChatID, and GetTimestamp getters
- Use sync.RWMutex for thread-safe concurrent access
- Add comprehensive tests for atomic save, concurrent access, and persistence
- Cleanup temp file if rename fails

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 19:46:10 +08:00
yinwm
4c4c10c915 feat: US-008 - Inject callback into async tools in AgentLoop
- Update ToolRegistry.ExecuteWithContext to accept asyncCallback parameter
- Check if tool implements AsyncTool and set callback if provided
- Define asyncCallback in AgentLoop.runLLMIteration
- Callback uses bus.PublishOutbound to send async results to user
- Update Execute method to pass nil for backward compatibility
- Add debug logging for async callback injection

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 19:42:24 +08:00
yinwm
7bcd8b284f feat: US-007 - Add heartbeat async task execution support
- Add local ToolResult struct definition to avoid circular dependencies
- Define HeartbeatHandler function type for tool-supporting callbacks
- Add SetOnHeartbeatWithTools method to configure new handler
- Add ExecuteHeartbeatWithTools public method
- Add internal executeHeartbeatWithTools implementation
- Update checkHeartbeat to prefer new tool-supporting handler
- Detect and handle async tasks (log and return immediately)
- Handle error results with proper logging
- Add comprehensive tests for async, error, sync, and nil result cases

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 19:39:57 +08:00
yinwm
56ac18ab70 feat: US-006 - Add AsyncCallback type and AsyncTool interface
- Define AsyncCallback function type for async tool completion notification
- Define AsyncTool interface with SetCallback method
- Add comprehensive godoc comments with usage examples
- This enables tools like SpawnTool to notify completion asynchronously

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 19:35:41 +08:00
yinwm
b573d61a58 feat: US-005 - Update AgentLoop tool result processing logic
- Modify runLLMIteration to return lastToolResult for later decisions
- Send tool.ForUser content to user immediately when Silent=false
- Use tool.ForLLM for LLM context
- Implement Silent flag check to suppress user messages
- Add lastToolResult tracking for async callback support (US-008)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 19:34:32 +08:00
yinwm
c6c61b4e9d feat: US-004 - Delete isToolConfirmationMessage function
The isToolConfirmationMessage function was already removed in commit 488e7a9.
This update marks US-004 as complete with a note.

The migration to ToolResult.Silent will be completed in US-005.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 19:30:47 +08:00
yinwm
ca781d4b37 feat: US-002 - Modify Tool interface to return *ToolResult
- Update all Tool implementations to return *ToolResult instead of (string, error)
- ShellTool: returns UserResult for command output, ErrorResult for failures
- SpawnTool: returns NewToolResult on success, ErrorResult on failure
- WebTool: returns ToolResult with ForUser=content, ForLLM=summary
- EditTool: returns SilentResult for silent edits, ErrorResult on failure
- FilesystemTool: returns SilentResult/NewToolResult for operations, ErrorResult on failure
- Temporarily disable cronTool in main.go (will be re-enabled in US-016)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 19:28:56 +08:00