picoclaw/pkg/tools
Guoguo cb1e1a3595
fix(feishu): fix image download with API fallback and post image support (#2708)
* fix(feishu): fix image download with API fallback and post image support

- Add Image.Get API fallback when MessageResource.Get fails (different
  permission scope: im:resource vs im:message:readonly)
- Extract and download images from post (rich text) messages
- Extract images from interactive card messages
- Deduplicate post image keys across locales
- Add comprehensive tests for new helpers

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(media): add image path tags alongside base64 for LLM file access

Images are still base64-encoded into msg.Media for multimodal LLMs,
but now also get [image:path] tags injected into message content so
the LLM knows the local file path for save/forward operations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor(media): only auto-inject images for tool results, not user messages

Channel-received images (role=user) now get path tags only, letting
the LLM decide whether to view via load_image or just operate on
the file. Tool result images (role=tool, e.g. load_image) are
base64-encoded into a synthetic user message appended after the tool
message, since many LLM APIs don't support image_url in tool messages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(media): preserve tool-message ordering for multi-tool-call scenarios

Move synthetic user message (carrying base64 tool images) to after the
entire contiguous tool-message block instead of immediately after each
tool message. This preserves the assistant→tool→tool ordering required
by OpenAI-compatible APIs.

Also fix load_image to use generic [image: photo] placeholder so
injectPathTags can properly replace it with the actual path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(test): update load_image test for [image: photo] placeholder

The test was checking ForLLM for the media:// ref, but load_image now
emits the generic [image: photo] placeholder instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(media): match all channel image placeholders in injectPathTags

Different channels emit different placeholder formats — Telegram/Feishu
use [image: photo], WeCom/WeChat/Line use bare [image], QQ/Discord use
[image: <filename>]. The previous string-match code only handled
[image: photo], so for the other channels the path tag was appended as
a duplicate, producing content like "[image] [image:/path]".

Switch to per-type regex that matches all generic placeholder shapes
while leaving path tags ([image:/path]) untouched. Also fixes the same
issue for [audio], [video], [file] tags. Added test coverage for the
various placeholder shapes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(media): skip path tag append for JSON content (Feishu cards/posts)

When content is structured JSON (interactive cards, post messages),
injectPathTags now skips the fallback append — only placeholder
replacement is attempted. This prevents corrupting JSON payloads
like {"schema":"2.0",...} with appended [image:/path] tags.

Adds looksLikeJSON() helper and three test cases covering JSON
objects, arrays, and an end-to-end resolveMediaRefs scenario with
Feishu card content.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(media): prepend path tags for JSON content, narrow looksLikeJSON

Two fixes from code review:

1. looksLikeJSON now only checks for '{' prefix (not '['), avoiding
   false positives on regular text like "[update] see attached".

2. For JSON content (Feishu cards/posts), path tags are prepended
   before the JSON instead of being silently dropped. This ensures
   the LLM can discover attached images via the path tag while the
   JSON payload stays valid for downstream parsing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-30 11:08:00 +08:00
..
fs fix(feishu): fix image download with API fallback and post image support (#2708) 2026-04-30 11:08:00 +08:00
hardware fix(serial_windows): remove unused import (#2697) 2026-04-28 16:19:59 +08:00
integration feat(agent): migrate tool prompts to capability slots 2026-04-24 19:36:46 +08:00
shared feat(agent): migrate tool prompts to capability slots 2026-04-24 19:36:46 +08:00
cron.go fix(cron): propagate sessionKey to prevent duplicate tool responses 2026-04-27 13:17:25 +02:00
cron_test.go fix(cron): propagate sessionKey to prevent duplicate tool responses 2026-04-27 13:17:25 +02:00
facade_compat_test.go feat(tools): add cross-platform serial hardware tool 2026-04-28 12:54:28 +08:00
fs_facade.go fix(providers,tools): address linter issues after reorg 2026-04-17 14:16:18 +08:00
fs_registry_compat_test.go refactor(tools): reorganize tool packages and facades 2026-04-17 13:44:31 +08:00
hardware_facade.go feat(tools): add cross-platform serial hardware tool 2026-04-28 12:54:28 +08:00
identifier_compat.go refactor(tools): reorganize tool packages and facades 2026-04-17 13:44:31 +08:00
integration_facade.go Keep launcher locale changes from mutating shared web-search routing (#2573) 2026-04-24 13:45:25 +08:00
load_image_compat_test.go refactor(tools): reorganize tool packages and facades 2026-04-17 13:44:31 +08:00
normalization.go fix(tool): route binary outputs through the media pipeline. 2026-03-22 12:05:28 +01:00
path_compat.go refactor(tools): reorganize tool packages and facades 2026-04-17 13:44:31 +08:00
registry.go feat(agent): migrate tool prompts to capability slots 2026-04-24 19:36:46 +08:00
registry_test.go feat(agent): migrate tool prompts to capability slots 2026-04-24 19:36:46 +08: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(agent): migrate tool prompts to capability slots 2026-04-24 19:36:46 +08:00
search_tools_test.go feat(mcp): tool search tools (#1243) 2026-03-09 18:21:49 +01:00
session.go refactor(tools): reorganize tool packages and facades 2026-04-17 13:44:31 +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
shared_facade.go feat(agent): migrate tool prompts to capability slots 2026-04-24 19:36:46 +08:00
shell.go Feat/support isolation (#2423) 2026-04-08 18:15:42 +08: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
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
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
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