picoclaw/pkg/tools
reusu 31afad6e87
feat: add load_image tool for local file vision (#2116)
* feat: add load_image tool for local file vision

* fix: address load_image PR review feedback

- Exclude load_image from sub-agent tools via Unregister after Clone,
  since RunToolLoop does not call resolveMediaRefs
- Add ToolRegistry.Unregister() method
- Fix scope collision: use channel:chatID instead of filename
- Add channel/chatID context resolution matching send_file pattern
- Add comment explaining iteration > 1 guard on resolveMediaRefs
- Remove emoji from ForUser for consistency with send_file
- Add load_image_test.go

* feat: enable load_image for subagents via MediaResolver in RunToolLoop

Instead of removing load_image from sub-agent tools (28f69e71), inject a
MediaResolver into the legacy RunToolLoop fallback path so media:// refs
are resolved to base64 before each LLM call — matching the main agent
loop behavior.

- Add MediaResolver field to ToolLoopConfig and call it on iteration > 1
- Add SubagentManager.SetMediaResolver() and wire it through runTask
- Remove ToolRegistry.Unregister() (no longer needed)
- Restore load_image in sub-agent tool set (revert Clone+Unregister)
- Add TestSubagentManager_SetMediaResolver_StoresResolver

* refactor(load_image): remove prompt parameter from tool schema

* test(tools): add success-path test for LoadImageTool

Add TestLoadImage_SuccessPath that creates a real PNG file with valid
magic bytes, calls Execute with WithToolContext, and verifies:
- result.IsError == false
- ToolResult.Media contains a media:// ref
- ToolResult.ForLLM contains the [image: marker
- media ref is resolvable in the store

Add explanatory comment in loop.go for why Media and ArtifactTags
coexist on non-ResponseHandled tool results (e.g. load_image).

* fix: preallocate slice in tests and add ResponseHandled guard in toolloop

Fix prealloc linter failure in load_image_test.go.

Prevent double-resolving media by checking ResponseHandled in toolloop.go.

* Register TTS tool if provider is available

---------

Co-authored-by: Reusu <admin@yumao.name>
Co-authored-by: 美電球 <hoshina@evaz.org>
2026-04-01 21:32:10 +08:00
..
base.go feat(tools): add reaction tool and reply-aware message sends (#2156) 2026-03-30 16:31:34 +08:00
cron.go refactor(cron): remove deliver and type params, unify agent execution path (#2147) 2026-03-29 22:52:34 +08:00
cron_test.go refactor(cron): remove deliver and type params, unify agent execution path (#2147) 2026-03-29 22:52:34 +08:00
edit.go fix(tools): allow /dev/null redirection and add read/write sandbox split (#967) 2026-03-02 12:22:02 +08:00
edit_test.go fix(security): workspace sandbox avoid time-of-check/time-of-use (TOCTOU) races (#464) 2026-02-23 20:09:53 +11:00
filesystem.go feat(tool): overwrite flag in write_file (#1761) 2026-03-19 11:22:52 +08:00
filesystem_test.go feat(tool): overwrite flag in write_file (#1761) 2026-03-19 11:22:52 +08:00
i2c.go refactor: cleanup dead code and turn on dead code detection in CI (#515) 2026-02-24 21:52:25 +08:00
i2c_linux.go feat(linter): Fix govet linter 2026-02-20 22:35:16 +02:00
i2c_other.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
load_image.go feat: add load_image tool for local file vision (#2116) 2026-04-01 21:32:10 +08:00
load_image_test.go feat: add load_image tool for local file vision (#2116) 2026-04-01 21:32:10 +08:00
mcp_tool.go fix(tool): route binary outputs through the media pipeline. 2026-03-22 12:05:28 +01:00
mcp_tool_test.go fix(tool): route binary outputs through the media pipeline. 2026-03-22 12:05:28 +01:00
message.go feat(tools): add reaction tool and reply-aware message sends (#2156) 2026-03-30 16:31:34 +08:00
message_test.go feat(tools): add reaction tool and reply-aware message sends (#2156) 2026-03-30 16:31:34 +08:00
normalization.go fix(tool): route binary outputs through the media pipeline. 2026-03-22 12:05:28 +01:00
reaction.go feat(tools): add reaction tool and reply-aware message sends (#2156) 2026-03-30 16:31:34 +08:00
reaction_test.go feat(tools): add reaction tool and reply-aware message sends (#2156) 2026-03-30 16:31:34 +08:00
registry.go Merge pull request #1889 from afjcjsbx/fix/binary-tool-output-handling 2026-03-24 15:37:06 +01:00
registry_test.go feat(tools): add reaction tool and reply-aware message sends (#2156) 2026-03-30 16:31:34 +08:00
result.go Merge branch 'main' into fix/binary-tool-output-handling 2026-03-22 23:08:27 +01:00
result_test.go fix(tool): route binary outputs through the media pipeline. 2026-03-22 12:05:28 +01:00
search_tool.go feat(mcp): tool search tools (#1243) 2026-03-09 18:21:49 +01:00
search_tools_test.go feat(mcp): tool search tools (#1243) 2026-03-09 18:21:49 +01:00
send_file.go Merge branch 'main' into fix/binary-tool-output-handling 2026-03-23 13:16:23 +01:00
send_file_test.go Merge branch 'main' into fix/binary-tool-output-handling 2026-03-23 13:16:23 +01:00
session.go feat(tools): add exec tool enhancement with background execution and PTY support (#1752) 2026-03-25 21:02:49 +08:00
session_process_unix.go feat(tools): add exec tool enhancement with background execution and PTY support (#1752) 2026-03-25 21:02:49 +08:00
session_process_windows.go feat(tools): add exec tool enhancement with background execution and PTY support (#1752) 2026-03-25 21:02:49 +08:00
session_test.go feat(tools): add exec tool enhancement with background execution and PTY support (#1752) 2026-03-25 21:02:49 +08:00
shell.go Merge pull request #1982 from Kathent/fix-deny-pattern 2026-03-30 14:24:17 +02:00
shell_process_unix.go fix(exec): terminate process tree on timeout 2026-02-18 02:01:29 +08:00
shell_process_windows.go fix(exec): terminate process tree on timeout 2026-02-18 02:01:29 +08:00
shell_test.go feat(tools): add exec tool enhancement with background execution and PTY support (#1752) 2026-03-25 21:02:49 +08:00
shell_timeout_unix_test.go feat(tools): add exec tool enhancement with background execution and PTY support (#1752) 2026-03-25 21:02:49 +08:00
skills_install.go refactor(pkg): move atomic file write to dedicated fileutil package 2026-02-24 23:57:13 +08:00
skills_install_test.go feat(fmt): Fix formatting 2026-02-20 20:03:11 +02:00
skills_search.go feat(fmt): Fix formatting 2026-02-20 20:03:11 +02:00
skills_search_test.go feat(fmt): Fix formatting 2026-02-20 20:03:11 +02:00
spawn.go refactor: improve code readability and consistency across multiple files 2026-03-21 17:12:45 +08:00
spawn_status.go feat(tools): add SpawnStatusTool for reporting subagent statuses (#1540) 2026-03-17 14:41:43 +08:00
spawn_status_test.go feat(tools): add SpawnStatusTool for reporting subagent statuses (#1540) 2026-03-17 14:41:43 +08:00
spawn_test.go fix(tools): prevent nil pointer dereference in spawn tools 2026-03-19 13:51:11 +08:00
spi.go refactor: cleanup dead code and turn on dead code detection in CI (#515) 2026-02-24 21:52:25 +08:00
spi_linux.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
spi_other.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
subagent.go feat: add load_image tool for local file vision (#2116) 2026-04-01 21:32:10 +08:00
subagent_tool_test.go fix(tools): prevent nil pointer dereference in spawn tools 2026-03-19 13:51:11 +08:00
sysproc_unix.go feat(tools): add exec tool enhancement with background execution and PTY support (#1752) 2026-03-25 21:02:49 +08:00
sysproc_windows.go feat(tools): add exec tool enhancement with background execution and PTY support (#1752) 2026-03-25 21:02:49 +08:00
toolloop.go feat: add load_image tool for local file vision (#2116) 2026-04-01 21:32:10 +08:00
tts_send.go Refactor/asr tts (#1939) 2026-04-01 12:21:21 +08:00
types.go feat(tools): add exec tool enhancement with background execution and PTY support (#1752) 2026-03-25 21:02:49 +08:00
validate.go feat(tools): add tool argument schema validation before execution (#1877) 2026-03-24 18:35:56 +08:00
validate_test.go feat(tools): add tool argument schema validation before execution (#1877) 2026-03-24 18:35:56 +08:00
web.go fix lint 2026-03-26 21:33:43 +01:00
web_test.go feat(tools) range in web_search 2026-03-26 21:02:46 +01:00