feat(events-shim): wake idle Copilot CLI and Gemini CLI sessions on each post
Merged
KH
6d ago+1033+1033+0123456789012345678901234567890123456789-10-10-01234567890123456789
What
npx @agent-relay/events-shim setup --copilot (new) and setup --gemini (until now "reads posts when asked") now wake an idle GitHub Copilot CLI or Gemini CLI session with each webhook post. This works without Agent Relay and without a core.
- When a turn ends, setup's turn-end hook (Copilot
agentStopin~/.copilot/hooks/agent-relay-webhooks.json, GeminiAfterAgentin~/.gemini/settings.json) runsevents-shim listen --stop-hook <cli>with a 7-day timeout. - The hook waits for the next post (same inbox and session locks as Claude's
listen --hook). It answers with the post as the agent's next prompt: Copilot{"decision":"block","reason":…}, Gemini{"decision":"deny","reason":…}. Each turn re-arms it. - It answers
{}and lets go when:- the CLI exits;
- the session transcript (from the hook input) shows the person cancelled or typed. On Copilot that is
abort,user.messageorsession.errorinevents.jsonl. On Gemini it is auserentry orRequest cancelled.; - a newer turn's hook for the same session takes over (it stops the stale waiter).
- Copilot turns that did not end normally (
stopReasonother thanend_turn) are answered at once and claim nothing. uninstall --copilot/--geminiremoves only our hook and stops waiting hooks of that CLI only.
Limits (stated in setup's output, the README and the changelog):
- A session can be woken only after it has finished one turn.
- While the hook waits, the CLI shows its turn as running ("Working" / "Executing Hook") and holds what the person types. The person presses Ctrl+C (Copilot) or Esc (Gemini) first; the hook lets go about 2 s later and waits again after the person's turn.
- Gemini also prints "This request failed…" when a deny starts the new turn. This is cosmetic.
Evidence (live, built dist/bin.js via node)
- Environment: isolated
HOME/XDG_*/XDG_RUNTIME_DIRunder~/.agent-tmp, inboxes made through the publicPOST /shims, CLIs run interactively in detached tmux. - I ran
node dist/bin.js setup <mcp> --copilot|--gemini. The hook command it writes usesnpx -y @agent-relay/events-shim@latest, which does not have--stop-hookyet. For the proof only, I pointed that command atnode <worktree>/dist/bin.js.
| CLI | Result |
|---|---|
| GitHub Copilot CLI 1.0.94 → 1.0.112 (self-updated), real model | Idle about 40 s, then a tagged post: the session took a turn by itself and replied with the tag 7.8 s after the post. A second post woke it again (10.3 s). After 4 min idle: 8.8 s. Ctrl+C while waiting: the transcript shows abort at 17:31:03.404 and the hook ended {} at 17:31:05.416, then the person's typed turn ran. uninstall --copilot removed the hook file and MCP server and stopped the waiting hook; Copilot went idle. |
Gemini CLI 0.68.0, mock model (GOOGLE_GEMINI_BASE_URL pointed at a local stub, because this machine's stored Gemini API key is rejected by Google as invalid) | Idle about 45 s, then a tagged post: a new turn with the post as the prompt, answered with the tag 6.1 s after the post. Esc released the wait (Request cancelled., hook gone). After the person's own turn the hook waited again, and the next post woke it in 4.6 s. The CLI-side wake mechanism is real; only the model replies are stubbed. |
Unit tests: packages/events-shim 82 pass (11 new). They cover hook install/merge/refusal/uninstall, the block/deny answers, a non-end_turn stop, transcript release (Copilot abort, Gemini cancel, Gemini typed), takeover of an older turn's waiter, and per-CLI uninstall.
Not in this PR
- Cursor: the core already has a
cursor-clikind whosestophook waits up to an hour. It is not proven here becausecursor-agenton this machine needsagent login. - Factory Droid: not installed and not authenticated here. Its
Stophook supportsdecision: "block"+reason(docs), so the same--stop-hookpattern should apply once it can be proven.
🤖 Generated with Claude Code
![Autofix with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png)
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.