picoclaw/pkg/agent
沈青川 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
..
context.go feat(channels): support multi-message sending via split marker (#2008) 2026-03-26 01:33:49 +08:00
context_budget.go merge: resolve conflicts between refactor/agent and main 2026-03-22 19:21:58 +08:00
context_budget_test.go merge: resolve conflicts between refactor/agent and main 2026-03-22 19:21:58 +08:00
context_cache_test.go merge: resolve conflicts between refactor/agent and main 2026-03-22 19:21:58 +08:00
context_test.go fix(provider): deduplicate tool results and merge consecutive tool_result blocks for Anthropic API (#1793) 2026-03-23 17:24:46 +08:00
definition.go merge: resolve conflicts between refactor/agent and main 2026-03-22 19:21:58 +08:00
definition_test.go merge: resolve conflicts between refactor/agent and main 2026-03-22 19:21:58 +08:00
eventbus.go merge: resolve conflicts between refactor/agent and main 2026-03-22 19:21:58 +08:00
eventbus_test.go Merge branch 'main' into version 2026-03-23 10:54:08 +08:00
events.go merge: resolve conflicts between refactor/agent and main 2026-03-22 19:21:58 +08:00
hook_mount.go merge: resolve conflicts between refactor/agent and main 2026-03-22 19:21:58 +08:00
hook_mount_test.go Merge branch 'main' into version 2026-03-23 10:54:08 +08:00
hook_process.go merge: resolve conflicts between refactor/agent and main 2026-03-22 19:21:58 +08:00
hook_process_test.go merge: resolve conflicts between refactor/agent and main 2026-03-22 19:21:58 +08:00
hooks.go merge: resolve conflicts between refactor/agent and main 2026-03-22 19:21:58 +08:00
hooks_test.go Merge branch 'main' into version 2026-03-23 10:54:08 +08:00
instance.go fix(agent): use light provider for routed model calls (#2038) 2026-03-28 15:25:23 +08:00
instance_test.go feat(tools): add exec tool enhancement with background execution and PTY support (#1752) 2026-03-25 21:02:49 +08:00
loop.go fix(cron): publish agent response to outbound bus for cron-triggered jobs (#2100) 2026-03-29 13:47:28 +08:00
loop_mcp.go feat(mcp): per server deferred mode (#1654) 2026-03-19 17:03:17 +08:00
loop_mcp_test.go feat(mcp): per server deferred mode (#1654) 2026-03-19 17:03:17 +08:00
loop_media.go resolve conflicts 2026-03-22 23:36:25 +01:00
loop_test.go fix: resolve typecheck errors in loop_test.go and dingtalk_test.go (#2122) 2026-03-28 18:58:09 +08:00
memory.go refactor(modernize): apply safe modernize fixes 2026-02-27 16:35:07 +08:00
mock_provider_test.go feat(fmt): Fix formatting 2026-02-19 22:05:15 +02:00
model_resolution.go fix(agent): rebind provider after /switch model to (#1769) 2026-03-19 21:44:01 +08:00
registry.go feat(session): integrate JSONL persistence into agent loop (#1170) 2026-03-10 15:14:09 +08:00
registry_test.go refactor Config to add Version and migratable 2026-03-12 13:52:55 +08:00
steering.go fix(agent): fix subturn panic result, hard abort rollback, and drain bus exit 2026-03-22 20:35:14 +08:00
steering_test.go Merge branch 'main' into version 2026-03-23 10:54:08 +08:00
subturn.go fix(agent): fix subturn panic result, hard abort rollback, and drain bus exit 2026-03-22 20:35:14 +08:00
subturn_test.go Merge branch 'main' into version 2026-03-23 10:54:08 +08:00
thinking.go feat: add extended thinking support for Anthropic models (#1076) 2026-03-05 09:51:18 +08:00
thinking_test.go feat: add extended thinking support for Anthropic models (#1076) 2026-03-05 09:51:18 +08:00
turn.go merge: resolve conflicts between refactor/agent and main 2026-03-22 19:21:58 +08:00