feat(cli): let `trigger` carry a payload

Merged
KH
3mo ago
+299-13

The gap

agentworkforce trigger could only fire blanks. The endpoint behind it accepts any JSON object and hands it to the handler as the event payload — that is the entire point of an app-triggered agent — but the CLI sent no body, so every manual run looked exactly like a schedule firing.

That is not cosmetic. Verifying app-signal's Slack write after narrowing its mount was impossible from the CLI: the bare trigger took the agent's contentless path, which by design stays silent. Proving the payload path meant a hand-rolled curl with a separately minted token — and scripts/trigger-agent.mjs exists in the watchdog repo for exactly this reason.

agentworkforce trigger app-signal '{"accountId":"acme","reason":"usage_spike"}'
agentworkforce trigger app-signal --payload-file ./signal.json
echo '{"accountId":"acme"}' | agentworkforce trigger app-signal --payload-file -

Also adds --idempotency-key, which the endpoint already honours: retrying with the same key returns the original run instead of starting a second one.

Details worth knowing

  • A body-less POST and a {} body are not the same to cloud. The first is a contentless fire; the second is an app trigger carrying an empty object. Content-Type and body are attached only when a payload exists, never defaulted. buildTriggerRequest is split out as a pure function so a test pins that distinction, including that an explicit {} still sends {}.
  • The payload must be a JSON object. Cloud wraps it as {source:'app.trigger', payload:<body>} and handlers read named fields off it, so an array or scalar would earn a 202 and then a run that silently does nothing. Rejected before the request, with the reason.
  • Parsing stays synchronous and side-effect free. --payload-file reading is deferred to resolvePayload, so argument handling remains testable without a filesystem or stdin. --payload-file - (stdin) needed its own value guard so the lone dash isn't read as a missing value.
  • A trailing {...} positional is the payload. Unambiguous — no agent id, deployed name, persona slug or persona id starts with a brace — and a non-JSON extra positional still errors exactly as before.

Verification

typecheck clean · 19/19 in trigger-command.test.ts (9 new).

Full packages/cli suite locally: 342 tests, 311 pass, 31 fail — all pre-existing. Same 31 runInvoke failures on untouched main before this change (303/334 there), which are local-environment issues; CI is the gate.

🤖 Generated with Claude Code