Commit Graph

7 Commits

Author SHA1 Message Date
lxowalle
878650c459 * fix: heartbeat/service_test.go test failed 2026-02-13 22:19:18 +08:00
yinwm
4dfa133cb8 refactor(heartbeat): add configurable interval and channel-aware routing
feat(config): add heartbeat interval configuration with default 30 minutes

feat(state): migrate state file from workspace root to state directory

feat(channels): skip internal channels in outbound dispatcher

feat(agent): record last active channel for heartbeat context

refactor(subagent): use configurable default model instead of provider default
2026-02-13 11:13:32 +08:00
yinwm
8fbbb67f70 refactor(heartbeat): simplify service with single handler and direct bus usage
- Remove redundant ChannelSender interface, use *bus.MessageBus directly
- Consolidate two handlers (onHeartbeat, onHeartbeatWithTools) into one
- Move HEARTBEAT.md and heartbeat.log to workspace root
- Simplify NewHeartbeatService signature (remove handler param)
- Add SetBus and SetHandler methods for dependency injection

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 09:51:51 +08:00
yinwm
474f3dbf90 fix: resolve code review issues in tool-result-refactor
1. Remove duplicate ToolResult definition in heartbeat package
   - Import tools.ToolResult instead of local definition
   - Add nil check for handler before execution

2. Fix SpawnTool to return AsyncResult and implement AsyncTool
   - Add callback field and SetCallback method
   - Return AsyncResult instead of NewToolResult

3. Add context cancellation support to SubagentManager
   - Check ctx.Done() before and during task execution
   - Set task status to "cancelled" on cancellation
   - Call callback with result on completion

4. Fix data race window in CronTool.addJob
   - Use Lock instead of RLock for channel/chatID access
   - Ensure consistent snapshot during job creation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 01:59:50 +08:00
yinwm
e7e086155e feat: merge heartbeat service improvements from feat-heartbeat branch
- Add ChannelSender interface for sending heartbeat results to users
- Add sendResponse() to automatically deliver results to last channel
- Add createDefaultHeartbeatTemplate() for first-run setup
- Support HEARTBEAT_OK silent response (legacy compatibility)
- Add structured logging with INFO/ERROR levels
- Move integration tests to separate file with build tag

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 01:42:22 +08:00
yinwm
e63f96794f feat: US-020 - Move heartbeat log to memory directory
Verified and tested that heartbeat log is written to memory directory:
- Current code uses workspace/memory/heartbeat.log (correct)
- Added TestLogPath test verifying log is in memory directory
- All acceptance criteria met

Note: US-020 was already implemented (log path was already memory/heartbeat.log).
This commit adds the missing test to verify the requirement.

Acceptance criteria met:
- Log path is workspace/memory/heartbeat.log (not workspace/heartbeat.log)
- Directory auto-created if missing (os.MkdirAll)
- Log format unchanged (timestamped messages)
- Typecheck passes (go build ./... succeeds)
- go test ./pkg/heartbeat -run TestLogPath passes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 20:16:36 +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