Skip to content

About

Hermes Agent plugin: wake the chat that started background work when it ends

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

16 Commits

Folders and files

Repository files navigation

hermes-wake

An agent in a chat (Telegram, Matrix, Discord, ...) often starts long work outside the chat, such as systemd-run, nohup or a script that writes a report, and says "I'll report back". Nothing re-enters the conversation when that work ends, so the human has to ask "any updates?".

With hermes-wake, the agent calls one tool right after it launches the work:

wake_me_when(unit="build-42.service", note="read /srv/out/report.md and summarise it")
wake_me_when(pid=81234, note="check the exit status in /tmp/job.log")
wake_me_when(path="/srv/out/report.md")

When the work ends, the agent gets a new turn in the same chat (and the same forum topic or thread) with the note and the outcome. It needs no polling and no further calls.

demo

Full-length demo video: demo/wake-demo-720.mp4

Install

hermes plugins install getaskclaw/hermes-wake
hermes plugins enable hermes-wake

Restart the gateway (or start a new session with /new); the wake_me_when and wake_list tools appear in the next session.

Why not a skill or the built-in notify_on_complete?

The built-in notify_on_complete only works for processes the agent started with its own terminal tool inside the gateway process. Work launched through systemd-run, nohup/setsid, a cron job, or on another host is detached from that tool, so nothing notices when it ends. A skill cannot help either: a skill is instructions the agent reads during a turn, and it cannot start a new turn in a chat on its own. Waking a session needs code that keeps running between turns, which is what this plugin adds.

How it works

  1. wake_me_when reads the current session's origin (platform, chat id, thread id, chat type, user id) through gateway.session_context.get_session_env.
  2. It parks a blocked, unassigned card on the kanban board hermes-wake, so the dispatcher never runs it. It then subscribes the origin with hermes kanban notify-subscribe <id> --delivery-mode wake.
  3. The watch is saved in SQLite under <HERMES_HOME>/plugin-data/hermes-wake/. A daemon thread in every Hermes process that loads the plugin checks pending watches every 15 s. Because the gateway loads the plugin at boot, watches survive a gateway restart.
  4. When the unit becomes inactive or failed (or is unloaded), the pid exits, the path is created (or its mtime or size changed, if it already existed at registration) and its mtime, size and ctime have held still for path_settle_s seconds (default 30 s, two polls), or max_wait_hours runs out, the watcher atomically claims the watch and runs hermes kanban complete <id>. The gateway's built-in kanban notifier then wakes the subscribed session.

One gateway process can serve several profiles. Each profile keeps its watches in its own home, and the watcher polls every home the process loaded the plugin for (Hermes calls the plugin's register() once per home, at boot) or took a wake_me_when call from, and no other. A home whose database cannot be opened is logged and skipped for that pass; the others are still polled. Settings, wake_list and cancelling stay inside one profile. The kanban board is shared by all profiles, as in Hermes itself, and each subscription names the profile whose session asked to be woken.

Completion happens at most once. The claim is a compare-and-set in SQLite, and a failed complete is released and retried on the next tick. A process only ever finishes or releases the claim it took itself.

One failure is not retried blindly. When complete answers "unknown id or terminal state", the watcher looks the card up with hermes kanban show <id> --json. A card that is already done or archived ends the watch, and the outcome says so. A card that does not exist also ends it, with a logged warning that this wake was not delivered. That last answer is only believed on the board the card was created on; a process pinned to another board (a kanban worker, for example) leaves the watch to the others. A watch saved by an older version does not record its board, so for it that answer is never believed: it is retried until its card is found (the board setting points at the card's board again) or you cancel it with wake_list. If the lookup itself fails, times out or prints something unreadable, or the card is still open, the watch is retried.

If systemctl fails, times out, or prints nothing usable, the unit state counts as unknown and the watch keeps waiting (a warning is logged once per unit). Only a successful systemctl show reporting LoadState=not-found or ActiveState=inactive|failed ends a unit watch.

A pid watch ends when /proc/<pid>/stat is gone, shows state Z (zombie: exited but not yet reaped by its parent), X or x (dead), or its start time no longer matches the one recorded at registration (the pid was reused).

The path settle window is measured in wall-clock time from when the current mtime+size+ctime was first observed, and that timestamp is stored with the watch in SQLite. Several Hermes processes ticking the same watch therefore share one window: back-to-back ticks from different processes cannot declare a file "stable" within milliseconds. Watches saved by an older version (no timestamp, or no ctime), or with a non-finite, non-positive or non-numeric timestamp, restart their window on the next tick. A process that stalls mid-tick cannot overwrite a window start another process stored in the meantime, nor complete the watch from a stored start that has been replaced since. If the file changes during its window and is restored with exactly the same mtime and size before the next look, only its ctime can show that, as far as the file system keeps one (see the limits below). If the system clock jumps forward, the window can be satisfied early.

After an upgrade, restart every Hermes process that loads this plugin (gateway, CLI and TUI sessions). While old and new versions share one database, the settle window is not guaranteed.

Tools: wake_me_when, and wake_list (list or cancel pending watches). wake_list only shows and cancels watches registered from the current chat (same platform, chat id and thread id). Cancelling unsubscribes the chat from the parked card and archives it, so no orphan subscription is left behind. Hook: transform_terminal_output. When a terminal command contains systemd-run, nohup or setsid, or ends with &, the hook adds a one-line hint after the output that suggests wake_me_when. The output itself is never changed. Turn it off with terminal_hint: false.

Recipe: keep work in the room it belongs to

hermes-wake brings the result back to the chat where the watch was registered. If the agent starts a job in the wrong room, every wake for it lands there too. A cheap guard is to check the room inside your own launch script when it runs, rather than trying to parse the agent's shell commands (quoting, globs and $() make that an endless game). Hermes exports the session origin to terminal commands, so the script can read it:

# top of a launch script, e.g. ~/bin/launch-job.sh
room="${HERMES_SESSION_PLATFORM}:${HERMES_SESSION_CHAT_ID}"
case "$HERMES_SESSION_PLATFORM" in ""|cli|local|cron) ;;   # not a chat: allow
  *) allowed=$(jq -r --arg r "$room" '.[$r].scopes // [] | join(" ")' ~/.hermes/room-scopes.json 2>/dev/null)
     if [ -n "$allowed" ] && [[ " $allowed " != *" ${ROOM_SCOPE:-} "* ]]; then
       echo "refused: ROOM_SCOPE='${ROOM_SCOPE:-}' is not handled in this room" >&2; exit 3
     fi ;;
esac

~/.hermes/room-scopes.json maps "<platform>:<chat_id>" to {"scopes": ["..."]}; unregistered rooms are allowed. The agent then launches with ROOM_SCOPE=<project>. This is a guard against slips (forgetting which room you are in), not a security boundary: the agent declares the scope itself.

Requirements and limits

  • The wake is delivered by a running messaging gateway with kanban.notify_in_gateway on (the default). In CLI or TUI sessions there is no chat to wake, so the tool returns an error.
  • delegate_task subagents cannot change the kanban board, so they cannot register wakes. The tool says so; the parent agent should make the call.
  • On a file system that does not maintain ctime (or only coarsely), a file that changes and is then restored with exactly the same mtime and size can still be completed by its old settle window.
  • Operations that only touch metadata (chmod, a new hard link, an xattr) restart the settle window; if they never stop, the wake is held back until max_wait_hours runs out.
  • A path is looked at once more right after the claim; a write between that verdict and the delivery of the wake cannot be ruled out.
  • The watcher runs only while some Hermes process with the plugin loaded is alive, normally the gateway. If no such process is running, the completion is late, not lost: it fires on the next start.
  • If a process dies after kanban complete succeeds but before it records the result, the watch is taken over when its 5-minute lease expires. The board refuses to complete the card a second time, so the watch ends without a second wake.
  • A process that serves several profiles from one shared (pip-installed) module polls their homes one after another, so a hung hermes call for one of them (60 s timeout each) delays the others. A plugin installed in each profile has one thread per profile.

Settings (plugins.entries.hermes-wake.settings)

key default meaning
board hermes-wake kanban board for parked cards
hermes_bin "" hermes executable; default hermes on PATH
terminal_hint true add the hint after detached terminal commands
path_settle_s 30 seconds a watched path's mtime+size+ctime must stay unchanged before it fires (2 × the 15 s poll). Must be a finite number ≥ 0; 0 means two matching observations are enough. A negative, NaN, infinite, boolean, null or non-numeric value is replaced by the default, with one warning per process

Disclosure

  • Shell commands. The plugin runs hermes kanban ... (board create, create, notify-subscribe, notify-unsubscribe, complete, show, archive) and systemctl [--user] show <unit>. It runs no other commands.
  • Reads outside its own data. It reads /proc/<pid>/stat for pid watches and stats the given path (existence, mtime, size, ctime) for path watches.
  • Background process. A daemon thread polls every 15 s in each Hermes process that loads the plugin.
  • No network calls, no credentials, no telemetry, and it never updates itself.

Live evidence

On 2026-11-11 the plugin was tested end to end in a real Telegram forum topic:

  • A transient unit wake-e2e.service running sleep 60 was started with systemd-run.
  • The agent called wake_me_when(unit="wake-e2e.service", ...) at 11:20:06 UTC.
  • At 11:21:03 UTC the gateway log showed kanban notifier: woke agent for t_7c9537b8 on telegram.
  • At 11:21:07 UTC the agent replied in the same topic without any human prompt.

Six further real wakes were delivered the same day on Matrix.

Tests

python -m pytest -q tests
hermes plugins validate . --install-deps

Author

BlueBirdBack - https://github.com/getaskclaw/hermes-wake

License

MIT

About

Hermes Agent plugin: wake the chat that started background work when it ends

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages