Commit graph

24 commits

Author SHA1 Message Date
dj-oyu
c0dc00ec12 perf: optimize LLM iteration hot path
- Cache ToProviderDefs() with version-based invalidation (2865x speedup,
  0 allocs on cache hit). Invalidate on Register/PromoteTools/TickTTL.
- Remove defensive copy in GetHistory() (read-only contract).
- Merge sanitizeHistoryForProvider 2-pass into 1-pass with forward-looking
  tool-call completeness check, eliminating intermediate allocation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 19:47:40 +09:00
dj-oyu
1772a1ccbd fix: resolve post-merge type mismatches and duplicate declarations
Fix FunctionCall.Arguments (map[string]any) and Parameters
(json.RawMessage) type usage in new upstream providers (antigravity,
codex). Remove duplicate FallbackCandidate/StreamEvent from types.go.
Add cloneToolArgs, fix session Close signature, remove duplicate
functions from loop.go, and fix test type assertions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 13:14:57 +09:00
dj-oyu
9f93158218 refactor: replace moderate-diff Go files with upstream, add fork extensions
Replace ~30 more Go source files with upstream versions and re-add
fork-only functionality via appended code or _ext.go files.

Key files aligned: providers/types.go, state/state.go, tools/base.go,
tools/registry.go, channels/*, config/defaults.go, providers/*.

Conflict metrics: 105 → 34 files, 646 → 315 markers (-51%)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 09:48:58 +09:00
dj-oyu
c14e3769e2 refactor: adopt upstream ToolEntry pattern and structural changes
- base.go: merge base_ext.go back to match upstream layout (context helpers,
  AsyncExecutor in base.go; StatusProvider + ContextualTool + AsyncTool as
  fork-only additions)
- registry.go: adopt upstream's ToolEntry struct with IsCore/TTL, hidden tools,
  RegisterHidden, PromoteTools, TickTTL, Version, SnapshotHiddenTools; merge
  ExecuteWithContext/ToProviderDefs/GetSummaries from registry_ext.go
- registry_ext.go: reduced to fork-only GetRuntimeStatus + buildParamHint
- config.go: add upstream-only types and fields (VoiceConfig, BuildInfo,
  ToolDiscoveryConfig, ReadFileToolConfig, MergeAPIKeys, MessageFormat,
  AllowRemote, APIKeys on search configs, Minimax/LongCat providers,
  UnmarshalText, QQ MaxMessageLength/SendMarkdown); merge SubagentsConfig
  and PeerMatch back from config_ext.go
- Delete base_ext.go and config_ext.go (contents merged back)
- Fix pre-existing anthropic provider build error (FunctionCall.Arguments
  is now map[string]any, not string)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 01:28:39 +09:00
dj-oyu
77c4f69d2e refactor: split loop.go and tools into upstream-friendly file layout
Reduce upstream merge friction by extracting fork-specific code from
files that upstream also modifies. loop.go is reduced from 6522 to 3165
lines by moving self-contained functions to dedicated files:

- loop_task.go: activeTask, status display, tool log formatting
- loop_plan.go: plan mode, interview filtering, worktree commands
- loop_orch.go: orchestration reporting, system messages, peer extraction
- loop_commands.go: slash commands, session commands, skill commands
- loop_streaming.go: streaming display, repetition detection, reasoning
- loop_session.go: session locks, GC, summarization
- loop_info.go: getters (startup info, plan info, context info)

Similarly for tools/:
- base.go → base.go (Tool interface only) + base_ext.go (AsyncExecutor, StatusProvider, context helpers)
- registry.go → registry.go (core CRUD) + registry_ext.go (ExecuteWithContext, ToProviderDefs, GetSummaries)

config/:
- SubagentsConfig, PeerMatch moved to config_ext.go
- Fix missing "strings" import (pre-existing bug)

No behavior changes. All code stays in the same Go packages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 00:56:40 +09:00
dj-oyu
fa546ad733 style: fix gci import ordering across pkg/{tools,agent,session}
Auto-fix via golangci-lint --fix to satisfy gci formatter rules
(standard → default → localmodule import grouping).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 01:37:13 +09:00
dj-oyu
346fd5d3df feat(task1): implement memory and performance optimizations 2026-03-04 23:54:01 +09:00
dj-oyu
3827fa8942 fix: include available tool names in "tool not found" error message
When the LLM calls a non-existent tool, the error message now lists all
available tools so the LLM can self-correct on the next iteration instead
of blindly guessing names (observed 7+ wasted iterations in heartbeat).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 04:23:04 +09:00
dj-oyu
e92ff7d3e6 fix(orch): improve spawn/subagent tool calling adoption for less capable models
Replace pseudo-syntax examples with JSON Tool:/Arguments: format in system
prompt and orchestration reminders. Add parameter hints to tool summaries,
improve error messages with usage examples, and strengthen delegation nudges.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 01:59:54 +09:00
dj-oyu
36c3345816 Merge upstream/main: cobra CLI, channel refactoring, media store, reasoning support
Merge upstream changes including:
- Cobra-based CLI command structure migration
- Channel system refactoring (flat files -> subdirectories for telegram, slack)
- Media store abstraction for file handling
- Reasoning channel support for LLM thinking output
- Prompt caching infrastructure (BuildSystemPromptWithCache)
- Bug fixes: goroutine leaks, error propagation, PublishInbound/Outbound context

Resolved 27 merge conflicts, combining HEAD's orchestration system
(AgentReporter, Broadcaster, spawn/subagent, plan mode) with upstream's
architectural changes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 21:18:40 +09:00
dj-oyu
5bd09ba2ee feat: add background process support to exec tool and bg_monitor tool
Enable long-running processes (dev servers, builds) to run in the background
without blocking the agent loop. Background processes are tracked with ring
buffers, auto-killed after 45min, and injected into the system prompt.

- Add StatusProvider interface and GetRuntimeStatus to ToolRegistry
- Extend exec tool with background=true, bg_action=output/kill
- Add bg_monitor tool with list/watch/tail actions
- Inject active bg process info into system prompt automatically
- Add dev-preview skill documentation
- Add comprehensive tests for all new functionality

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 21:00:21 +09:00
dj-oyu
46d06ff131 Merge remote-tracking branch 'upstream/main' into merge-upstream-2026-02-22
# Conflicts:
#	README.ja.md
#	README.zh.md
#	cmd/picoclaw/main.go
#	config/config.example.json
#	pkg/agent/context.go
#	pkg/agent/instance.go
#	pkg/agent/loop.go
#	pkg/agent/memory.go
#	pkg/channels/telegram.go
#	pkg/config/config.go
#	pkg/providers/factory.go
#	pkg/providers/http_provider.go
#	pkg/tools/edit.go
#	pkg/tools/filesystem.go
2026-02-22 01:00:27 +09:00
dj-oyu
9c4968e2cc refactor: unify normalization to alpha-only, simplify XML block detection
- normalizeAlpha / NormalizeToolName: keep only lowercase a-z
- Replace findToolCallOpenTag + findToolCallCloseTag with single
  findToolCallBlock using regex + greedy close tag matching
- Both XML extraction and stripping use the same findToolCallBlock
- Edit distance still used for fuzzy "toolcall" tag identification

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 03:29:44 +09:00
dj-oyu
ee15656e6c fix: fuzzy tool name resolution for LLM tool call mismatches
LLMs (e.g. MiniMax) sometimes call "readfile" instead of "read_file".
Add NormalizeToolName to strip underscores/hyphens and lowercase, with
fuzzy fallback in ToolRegistry.Get(). Also normalize the interview
tool allow-list so blocked tools aren't bypassed by name variants.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 02:56:05 +09:00
Artem Yadelskyi
9ac60c60f1 feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
yinwm
d905cd7eec refactor(tools): extract shared logic for internal channels and tool definitions
- Add constants package with IsInternalChannel helper to centralize internal channel checks across agent, channels, and heartbeat services
- Add ToProviderDefs method to ToolRegistry to consolidate tool definition conversion logic used in agent loop and tool loop
- Refactor SubagentTool.Execute to use RunToolLoop for consistent tool execution with iteration tracking
- Remove duplicate inline map definitions and type assertion code throughout codebase
2026-02-13 15:05:16 +08:00
yinwm
8ad7d740c2 chore: Clean up Ralph agent tracking files
Remove .ralph/ directory files from git tracking.
These are no longer needed as the tool-result-refactor is complete.

Also removes root-level prd.json and progress.txt.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 23:51:52 +08:00
yinwm
23add6bc02 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
419af2f745 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
yinwm
af2221b221 feat: add cron tool integration with agent
- 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>
2026-02-11 20:28:46 +08:00
yinwm
724053b865 Add memory system, dynamic tool loading, and fix logging issues
- 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
2026-02-11 00:14:33 +08:00
yinwm
4ddffe5cfa Add memory system, debug mode, and tools 2026-02-11 00:14:23 +08:00
yinwm
d33f273941 Add logging to agent loop and tool execution 2026-02-11 00:11:39 +08:00
lxowalle
e17693b17c * First commit 2026-02-09 19:20:19 +08:00