- 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>
- 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>
- 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>
- 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>
- 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>
- 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>
- 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>
Extract common file download and audio detection logic to utils package,
implement consistent temp file cleanup with defer, add allowlist checks
before downloading attachments, and improve context management across
Discord, Slack, and Telegram channels. Replace logging with structured
logger and prevent context leaks in transcription and thinking animations.
Update to latest major version of the official OpenAI Go SDK.
Fix breaking change: FunctionCallOutput.Output is now a union type
(ResponseInputItemFunctionCallOutputOutputUnionParam) instead of string.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add ClaudeProvider (anthropic-sdk-go) and CodexProvider (openai-go) that
use the correct subscription endpoints and API formats:
- CodexProvider: chatgpt.com/backend-api/codex/responses (Responses API)
with OAuth Bearer auth and Chatgpt-Account-Id header
- ClaudeProvider: api.anthropic.com/v1/messages (Messages API) with
Authorization: Bearer token auth
Update CreateProvider() routing to use new SDK-based providers when
auth_method is "oauth" or "token", removing the stopgap that sent
subscription tokens to pay-per-token endpoints.
Closes#18
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add Slack as a messaging channel using Socket Mode (WebSocket), bringing
the total supported channels to 8. Features include bidirectional
messaging, thread support with per-thread session context, @mention
handling, ack reactions (👀/✅), slash commands,
file/attachment support with Groq Whisper audio transcription, and
allowlist filtering by Slack user ID.
Closes#31
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add a new `picoclaw migrate` CLI command that detects an existing OpenClaw
installation and migrates workspace files and configuration to PicoClaw.
Workspace markdown files (SOUL.md, AGENTS.md, USER.md, TOOLS.md, HEARTBEAT.md,
memory/, skills/) are copied 1:1. Config keys are mapped from OpenClaw's
camelCase JSON format to PicoClaw's snake_case format with provider and channel
field mapping.
Supports --dry-run, --refresh, --config-only, --workspace-only, --force flags.
Existing PicoClaw files are never silently overwritten; backups are created.
Closes#27
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Run() and Stop() access the `running` field from different goroutines
without synchronization. Replace the bare `bool` with `sync/atomic.Bool`
to eliminate the data race.
Multiple packages had their own private truncate implementations:
- channels/telegram.go: truncateString (byte-based, no "...")
- channels/dingtalk.go: truncateStringDingTalk (byte-based, no "...")
- voice/transcriber.go: truncateText (byte-based, with "...")
All three are functionally equivalent to the existing utils.Truncate,
which already handles rune-safe truncation and appends "..." correctly.
Replace all private copies with utils.Truncate and delete the dead code.
- Remove duplicate truncate/truncateString functions from loop.go and cron.go
- Use utils.Truncate consistently across codebase
- Add Workspace Layout section to README
- Document cron/scheduled tasks functionality
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Code review fixes:
- Use map for O(n) job lookup in cron service (was O(n²))
- Set DeleteAfterRun=true for one-time cron tasks
- Restore context compression/summarization to prevent context overflow
- Add pkg/utils/string.go with Unicode-aware Truncate function
- Simplify setupCronTool to return only CronService
- Change Chinese comments to English in context.go
Refactoring:
- Replace toolsSummary callback with SetToolsRegistry setter pattern
- This makes dependency injection clearer and easier to test
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add at_seconds parameter for one-time reminders (e.g., "remind me in 10 minutes")
- Update every_seconds description to emphasize recurring-only usage
- Route cron delivery: deliver=true sends directly, deliver=false uses agent
- Fix cron data path from ~/.picoclaw/cron to workspace/cron
- Fix sessions path from workspace/../sessions to workspace/sessions
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add adhocore/gronx dependency for cron expression parsing
- Fix CronService race conditions and add cron expression support
- Add CronTool with add/list/remove/enable/disable actions
- Add ContextualTool interface for tools needing channel/chatID context
- Add ProcessDirectWithChannel to AgentLoop for cron job execution
- Register CronTool in gateway and wire up onJob handler
- Fix slice bounds panic in addJob for short messages
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add MemoryStore for persistent long-term and daily notes
- Add dynamic tool summary generation in system prompt
- Fix YAML frontmatter parsing for nanobot skill format
- Add GetSummaries() method to ToolRegistry
- Fix DebugCF logging to use structured metadata
- Improve web_search and shell tool descriptions
- Added Summary field to Session struct
- Implemented background summarization when history > 20 messages
- Included conversation summary in system prompt for long-term context
- Added thread-safety for concurrent summarization per session