Repository navigation
feat(encounters): render Co-DM presence on the encounter runner (#2212) - #2213
Conversation
Slice 2 of #816 (Co-DM presence). The server foundation from #2209 broadcasts an `encounter.presence` snapshot over the campaign SSE stream and exposes GET/POST/DELETE /encounters/:id/presence; this is the web client that makes it visible. - `useEncounterPresence`: a DM on a running encounter declares presence on open, re-declares on a coarse activity change (viewing/editing), heartbeats every 30s while the tab is visible (well inside the 45s server TTL), and leaves via a keepalive DELETE on unmount / loss of eligibility. The roster is reconciled from POST responses and from `encounter.presence` SSE snapshots; `redeclare()` restores presence on SSE reconnect/recovery. - `EncounterPresenceIndicator`: a compact chip per other collaborator (name + coarse activity), self filtered out, hidden when nobody else is here. Names resolve from the membership roster every member reads. - `RunSessionPage` subscribes to `encounter.presence` frames for the current encounter, declares as a DM, and renders the indicator beside the AI-DM presence chip. - `isCampaignEvent` admits the `encounter.presence` variant (runtime shape guard for the SSE stream). Secrecy is unchanged and server-enforced (#2209): a non-DM on a hidden encounter never receives the frames; the client performs no hiding. Activity is intentionally coarse (viewing/editing); advisory intent is a later slice. Closes #2212
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5919484ee2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Adds the web-client UI layer for Co-DM encounter presence by consuming encounter.presence campaign SSE snapshots, maintaining a live roster, and rendering a compact “other collaborators” indicator on the encounter runner.
Changes:
- Introduces
useEncounterPresenceto declare/heartbeat/leave presence and reconcile snapshot rosters. - Adds
EncounterPresenceIndicatorand wires it intoRunSessionPagealongside SSE handling + reconnect re-declare. - Extends the campaign-event runtime guard, adds i18n strings (en/ar), and adds component-level coverage.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/web/src/features/encounters/useEncounterPresence.ts | New hook for declare/heartbeat/leave + roster reconciliation, with tests relying on its API surface. |
| apps/web/src/features/encounters/EncounterPresenceIndicator.tsx | New presentational indicator that renders “other collaborators” chips from the roster. |
| apps/web/src/features/encounters/RunSessionPage.tsx | Subscribes to encounter.presence SSE frames, re-declares on reconnect/recovery, and renders the indicator. |
| apps/web/src/lib/useCampaignEvents.ts | Updates isCampaignEvent to admit the encounter.presence event variant at runtime. |
| apps/web/src/i18n/locales/en/encounters.json | Adds presence-related strings for the indicator. |
| apps/web/src/i18n/locales/ar/encounters.json | Adds Arabic presence-related strings for the indicator. |
| apps/web/test/component/encounter-presence.spec.tsx | New component/hook tests covering roster rendering, snapshot reconciliation, heartbeats, and leave-on-unmount. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: deb7e43bbc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…x docs - Discard presence POST responses from an obsolete encounter: when navigating A -> B while A's POST is in flight, the response no longer overwrites B's roster (activeEncounterRef guard after the await). - Null-safe self filter: when selfUserId is null (me still loading), filter by a sentinel that matches nothing rather than an empty string that could match a real userId, so the caller never briefly sees themselves (AC #2212.5). - Fix enabled doc comment to match the actual keepalive-DELETE behavior. - Remove unused campaignId from UseEncounterPresenceOptions (the hook never read it; encounterId is sufficient for the REST endpoints). - The "include all encounter writes in editing signal" thread is out-of-scope by design: the coarse viewing/editing model is intentional for this slice (advisory intent is a subsequent slice).
deb7e43 to
6f1b5c1
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6f1b5c112d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
What
Slice 2 of #816 (Co-DM presence). The server foundation from #2209 (merged via #2210) broadcasts an
encounter.presencesnapshot over the campaign SSE stream and exposesGET/POST/DELETE /encounters/:id/presence. This PR is the web client that consumes those frames and renders human-collaborator presence on the encounter runner — the UI layer that makes the server-side foundation visible to DMs.Closes #2212.
Changes
useEncounterPresence(new hook): while a DM holds open a running encounter itPOST /encounters/:id/presence) on open and on every coarse-activity change (viewing↔editing), seeding the roster from the snapshot the server returns;keepaliveDELETEon unmount / navigate-away / loss of eligibility;encounter.presenceSSE snapshots (applySnapshot), and exposesredeclare()to restore presence on SSE reconnect/recovery.EncounterPresenceIndicator(new presentational component): a compact chip per other collaborator showing name + coarse activity, the current user filtered out, hidden when nobody else is here. Names resolve from the membership roster every member already reads.RunSessionPage: subscribes toencounter.presenceframes for the current encounter (handled before the encounter-type filter, like the other non-encounter.updatedsignals), declares as a DM on a running encounter (activity =editingwhile a cockpit write is in flight, elseviewing), re-declares on SSE reconnect/recovery, and renders the indicator beside the AI-DM presence chip.useCampaignEvents:isCampaignEventadmits theencounter.presencevariant (runtime shape guard for the SSE stream — the schema union already included it).encounters.presence.{viewing,editing,personLabel,groupTitle}inen+ar.Acceptance criteria (#2212)
encounter.presencefor the current encounter and maintains a live roster.apps/server/test/encounter-presence.e2e-spec.ts(Co-DM presence: ephemeral authenticated presence on the encounter SSE stream (#816 slice 1) #2209).Out of scope (later slices)
Advisory intent ("Bob is resolving this turn"), warnings/leases, tab-close/sleep detection beyond SSE disconnect + heartbeat, and presence on the AI driver panel — all called out in #2212.
Secrecy / invariants
No server change. Secrecy is unchanged and stays server-enforced (#2209): a non-DM on a hidden encounter never receives the frames, and the client performs no hiding.
userIdis the membership-roster identity space (no secret); the encounter id is the sensitive field and is gated server-side at emit time. Presence remains transport-level (in-memory, never audited) — no domain write, no proposal.Validation
npm run typecheck✅npm run lint✅ (0 errors)npm run check:i18n✅npm run test:component:web✅ (169 passed, incl. newencounter-presence.spec.tsx— 15 tests)npm run test:unit:web✅ (2674 passed)