picoclaw/pkg
沈青川 e414b82ac3
fix(cron): publish agent response to outbound bus for cron-triggered jobs (#2100)
* fix(cron): publish agent response to outbound bus for cron-triggered jobs

When a cron job triggers agent execution via ProcessDirectWithChannel,
the agent response was silently discarded — the code assumed AgentLoop
would auto-publish it, but SendResponse is false on this path.

Delegate to PublishResponseIfNeeded (exported from AgentLoop) so the
response reaches the originating channel (e.g. Telegram) only when the
message tool did not already deliver content in the same round.

Also adds a "directive" message type to CronPayload, allowing cron jobs
to instruct the agent to execute a task rather than echo static text.

* fix(cron): add type validation and directive test coverage

Address reviewer blocking feedback:

1. Server-side whitelist for `type` parameter — the `enum` in
   Parameters() is only an LLM schema hint; any string was persisted.
   Now `addJob` rejects values other than "message" and "directive".

2. Comprehensive test coverage for the directive code path:
   - directive adds prompt prefix to ProcessDirectWithChannel
   - deliver=true + directive routes through agent (not direct publish)
   - directive prompt content, sessionKey, channel, chatID are correct
   - invalid type is rejected; valid types ("", "message", "directive") pass
   - deliver=true message type goes directly to bus (regression)
   - agent error path does not trigger publish (regression)

Also merge the two UpdateJob calls in addJob into one to avoid
redundant disk I/O (non-blocking suggestion from review).

* fix(cron): remove omitempty from CronPayload.Type for consistent JSON

Empty string and "message" are semantically equivalent defaults;
always serializing the field avoids asymmetric JSON output.

* test(cron): remove redundant test, strengthen error path coverage

- Remove ExecuteJobDirectivePassesCorrectContent: its assertions on
  sessionKey/channel/chatID duplicate ExecuteJobPublishesAgentResponse;
  its prompt check duplicates DirectiveAddsPromptPrefix.
- Strengthen DirectiveAddsPromptPrefix with exact prompt match and
  publish response assertion.
- Fix ReturnsErrorWithoutPublish: set non-empty stub response so the
  test verifies the error branch early-return, not the response==""
  guard.

* fix(ci): satisfy golines and gosmopolitan in cron code
2026-03-29 13:47:28 +08:00
..
agent fix(cron): publish agent response to outbound bus for cron-triggered jobs (#2100) 2026-03-29 13:47:28 +08:00
auth simplified duplicated code (#1935) 2026-03-28 20:28:24 +08:00
bus feat(telegram): stream LLM responses via sendMessageDraft (#1101) 2026-03-20 21:04:14 +08:00
channels fix(weixin): persist context tokens to disk to survive restarts (#2124) 2026-03-28 20:23:14 +08:00
commands resolve conflicts 2026-03-22 23:36:25 +01:00
config feat(web): protect launcher dashboard with token and SPA login (#1953) 2026-03-29 13:11:43 +08:00
constants refactor: replace bool map with set-style map for internal channels (#472) 2026-02-19 11:48:17 +01:00
credential refactor config and security to simplified the structure (#2068) 2026-03-28 00:03:34 +08:00
cron fix(cron): publish agent response to outbound bus for cron-triggered jobs (#2100) 2026-03-29 13:47:28 +08:00
devices refactor: cleanup dead code and turn on dead code detection in CI (#515) 2026-02-24 21:52:25 +08:00
fileutil Merge pull request #1829 from perhapzz/test/add-fileutil-health-tests 2026-03-26 10:42:13 +01:00
gateway fix gateway reload will cause pico stop working issue (#2082) 2026-03-28 11:30:31 +08:00
health fix gateway reload will cause pico stop working issue (#2082) 2026-03-28 11:30:31 +08:00
heartbeat fix(heartbeat): ignore untouched default template 2026-03-15 21:58:21 +08:00
identity fix(identity): support negative integers in isNumeric for Telegram group IDs 2026-03-21 17:09:02 +07:00
logger fix gateway reload will cause pico stop working issue (#2082) 2026-03-28 11:30:31 +08:00
mcp Feat/add tool enable or disable configuration (#1071) 2026-03-05 14:53:26 +08:00
media Fix 1886 media cleanup policy (#1887) 2026-03-23 12:13:59 +08:00
memory refactor Config to add Version and migratable 2026-03-12 13:52:55 +08:00
migrate refactor config and security to simplified the structure (#2068) 2026-03-28 00:03:34 +08:00
providers chore(provider): use openai responses api for azure openai endpoints (#2110) 2026-03-28 20:50:24 +08:00
routing refactor Config to add Version and migratable 2026-03-12 13:52:55 +08:00
session refactor Config to add Version and migratable 2026-03-12 13:52:55 +08:00
skills enhance skill installer (#1252) 2026-03-13 14:04:02 +08:00
state refactor Config to add Version and migratable 2026-03-12 13:52:55 +08:00
tools fix(cron): publish agent response to outbound bus for cron-triggered jobs (#2100) 2026-03-29 13:47:28 +08:00
utils Merge pull request #1891 from RussellLuo/audio-transcription 2026-03-23 00:23:30 +01:00
voice refactor config and security to simplified the structure (#2068) 2026-03-28 00:03:34 +08:00
env.go Merge branch 'main' into version 2026-03-19 18:04:58 +08:00