Files
hermes-agent/apps/shared/src
unsupportedpastels 18dcf1472f feat(desktop): tell the backend when the user is active in a session
A report is a claim that the user is at this computer and this window
can show them this session's reply. A false claim silences a phone for
a reply nobody sees, so the reporter corrects whatever it last told a
connection the moment it stops being true, and claims nothing whenever
it is not sure. The backend ages a record by itself; silence is safe.

The shared channel remembers `client_activity` from this connection's
own `client.capabilities` answer and forgets it on detach and attach;
the gateway client exposes it as `clientActivity`.

What is in view, and where to report it (`store/presence-view.ts`): the
chat on this window's HashRouter route, only when its runtime binding
is the one the composer would send to (route, selection and the
runtime's own stored id agree), and only on the connection a submit for
it would use (the composer's owner ladder and the registry's passive
route, never a dial). A draft, another page (Settings), a stale binding
or a profile riding a shared socket is nothing in view. Nothing is ever
created, resumed or bound to report.

Evidence (`store/presence.ts`): with main's OS idle clock, input
anywhere on the computer (`basis: system`); without it, pointer/key/
wheel/touch input inside this document while visible (`basis: page`).
Elapsed time is monotonic; a snapshot older than the newest adopted one
is ignored, a late delivery is aged from when main sampled it, and page
input from before a suspend is dropped on resume.

The reporter keeps what it last told each connection. It reports only
on an open, negotiated connection that advertised the feature, checked
at the moment of sending and never queued; at most once per 45 seconds
while active, and at once when the user becomes active, the session in
view changes or `can_alert` changes. When the session leaves view, the
owner moves, or nothing is in view, it sends `sessions: []` there; when
`can_alert` turns false on stale evidence, also `sessions: []`. Lock
or suspend sends one `away: true` per episode on every connection that
holds a statement or owns the session in view.

`can_alert` is the session in view in a visible, focused window whose
chat is the tab in front (another tab of its zone, a second
conversation, a preview or a tool, can cover it while the route and the
main session stay, and its zone can be minimized), or this client's
turn-done notification for it firing if the turn ended now: one non-consuming check shared with the notification dispatch
(preference and kind, the post-connect quiet interval, the background
and active-session condition, and in a browser the live permission).
The dispatch throttle cannot be predicted and is not.

A route move reaches the reporter at once through `usePresenceRoute`
(a location effect in the app shell): HashRouter pushes history without
a `hashchange` event, so opening Settings over a chat would otherwise
stay claimed until the next 15 second tick. The `hashchange` listener
stays for a hash edited from outside the router.

Input in this window that ends an idle spell is reported at once, not
at main's next 15 second poll. Without an OS clock the input is the
evidence. With one, that clock stays the only evidence: main is asked
for a fresh sample a quarter of a second later, once the OS has counted
the input, and at most once a second for input the OS does not count.

Page listeners are passive and capture-phase and only record a
timestamp. A refused report is swallowed. The gateway boot hook starts
one reporter per window; it lives in timers and listeners and never
renders.
2026-11-23 11:47:46 -05:00
..
…
2026-10-20 21:04:30 -04:00
…
…
…
…