Commit Graph

213 Commits

Author SHA1 Message Date
Ashish Huddar d956c52eef feat(web): add session-specific not-found.tsx for 404 handling
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 22:49:51 -07:00
Ashish Huddar 694332d789 feat(web): add global not-found.tsx for 404 handling
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 22:49:51 -07:00
Ashish Huddar fa73a9fb7f feat(web): add session loading.tsx with spinner for route transitions
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 22:49:51 -07:00
Ashish Huddar 6bfc239af0 feat(web): add global loading.tsx with spinner for route transitions
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 22:49:51 -07:00
Ashish Huddar c473088373 fix: prevent retry storms and stale refresh on project switch
- Update lastRefreshAtRef on non-OK /api/sessions responses to prevent
  infinite 5-second retry loops when the API is unhealthy
- Reset lastRefreshAtRef when project changes so each project gets its
  own immediate first refresh instead of inheriting the prior project's
  cooldown timestamp
- Add test for project-switch refresh behavior

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 22:49:51 -07:00
Ashish Huddar a63aaf0652 test: improve diff coverage for TTFB fast-path changes
Cover enriched done-card PR detail panel (SessionCard lines 361-377),
non-OK response timestamp update (useSessionEvents lines 180-181),
and enrichSessionsMetadataFast function (serialize lines 369-383).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 22:49:09 -07:00
Ashish Huddar 67371d2c6f fix: polish shimmer states, terminal PR inference, and gitignore .gstack
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 22:49:09 -07:00
Ashish Huddar a815fd1196 refactor: extract settlesWithin to shared async-utils module
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 22:48:50 -07:00
Ashish Huddar e38c7e947f Restore SSR metadata timeout 2026-04-06 22:48:50 -07:00
Ashish Huddar 5cb66a9b40 Infer terminal PR state without SCM 2026-04-06 22:48:50 -07:00
Ashish Huddar 27ce7d56db Restore parallel session metadata enrichment 2026-04-06 22:48:50 -07:00
Ashish Huddar e0b216c369 Add diff coverage for dashboard fast path 2026-04-06 22:48:50 -07:00
Ashish Huddar 1825e6a880 Improve dashboard fast-path session hydration
Treat unenriched PRs as a first-class state in the dashboard so SSR can
return fast-path session data without showing misleading PR status, size,
or alert states. Add shimmer placeholders for partial PR data, avoid
classifying unenriched PRs as merge/review/pending work, and ensure the
first SSE snapshot triggers an immediate refresh without failure loops.
2026-04-06 22:48:50 -07:00
harshitsinghbhandari 074b7f2ef0 fix: replicate terminal session filtering 2026-04-06 22:48:01 -07:00
harshitsinghbhandari 49426ccddb fix comments 2026-04-06 22:48:01 -07:00
harshitsinghbhandari 1116363a9b fix: clean up OrchestratorSelector tests and add spawn resilience
- Remove phantom `projects` prop from test setup (was dead code)
- Deduplicate test coverage: consolidate component tests into
  OrchestratorSelector.test.tsx, keep only page route tests in
  orchestrators.test.tsx
- Fix useRouter mock to capture and assert router.push calls
- Add finally block to handleSpawnNew for resilience (ensures
  isSpawning is reset even if router.push fails)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-06 22:48:01 -07:00
harshitsinghbhandari 9c0245a33a fix: correct tmux target fallback and deduplicate orchestrator listing
- Fix tmux target to use session ID when runtimeHandle is missing,
  preventing references to non-existent sessions
- Extract mapSessionsToOrchestrators helper to eliminate duplicate
  orchestrator listing logic between page.tsx and API route

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-06 22:48:01 -07:00
harshitsinghbhandari 63a796274a refactor: deduplicate Orchestrator interface
Export Orchestrator interface from OrchestratorSelector component
and import it in page.tsx to avoid silent divergence risk.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-06 22:48:01 -07:00
harshitsinghbhandari 6778c280e1 test: add edge case tests for formatRelativeTime
Add tests to verify proper handling of:
- Invalid date strings (returns "Unknown")
- Future timestamps (returns "Just now")
- Null dates (returns "Unknown")

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-06 22:48:01 -07:00
harshitsinghbhandari 672f2ad6f0 fix: remove unused projects prop from OrchestratorSelector
The projects prop was declared and passed but never used, causing
unnecessary data fetching and serialization. Removed the prop from
the component interface, page, and tests.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-06 22:48:01 -07:00
harshitsinghbhandari 81258468ce fix: handle invalid and future dates in formatRelativeTime
Guard against NaN timestamps from invalid ISO date strings and handle
future timestamps gracefully by returning "Just now" instead of
negative values.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-06 22:48:01 -07:00
harshitsinghbhandari 10163f0ec2 fix tests 2026-04-06 22:48:01 -07:00
harshitsinghbhandari 9d4d3412fa fix: prevent ao start from spawning duplicate orchestrators
When ao start is run and existing orchestrator sessions exist for the
project, the CLI now skips spawning a new one. Instead:

- Detects existing orchestrator sessions before spawning
- Opens the dashboard to a new /orchestrators page for session selection
- Users can resume an existing orchestrator or start a new one

Changes:
- packages/cli/src/commands/start.ts: Check for existing orchestrators,
  redirect to selection page if found
- packages/web/src/app/api/orchestrators/route.ts: Add GET endpoint to
  list orchestrators for a project
- packages/web/src/app/orchestrators/page.tsx: New page for orchestrator
  selection
- packages/web/src/components/OrchestratorSelector.tsx: UI component for
  selecting or spawning orchestrators
- packages/web/src/components/__tests__/OrchestratorSelector.test.tsx:
  Tests for the selector component

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-06 22:48:01 -07:00
Harsh Batheja 7e53542f9d feat: support multiple concurrent orchestrators with isolated worktrees (#870)
* feat: support multiple concurrent orchestrators with isolated worktrees

- Each orchestrator session gets a numbered ID ({prefix}-orchestrator-N)
  and an isolated git worktree, replacing the single shared orchestrator
- reserveNextOrchestratorIdentity atomically reserves the next available
  number and detects conflicting project prefix configurations early
- isOrchestratorSession / isOrchestratorSessionName accept optional
  allSessionPrefixes for cross-project false-positive prevention
- getProjectPause and resolveGlobalPause track the longest active pause
  across all concurrent orchestrators instead of returning the first found
- cleanupWorktreeAndMetadata helper used consistently on all failure paths
  including post-launch; system prompt file included in cleanup
- pollBacklog, status.ts, ProjectSidebar, sessions page, global-pause,
  project-utils, serialize, and sessions API route all pass
  allSessionPrefixes to isOrchestratorSession
- Web sessions/[id]/page.tsx fetches project prefix map and passes it
  through prefixByProjectRef to avoid stale closure in fetchProjectSessions

* fix: seed sseAttentionLevels from fresh sessions on full refresh

When scheduleRefresh dispatches a reset action, derive sseAttentionLevels
from the freshly fetched sessions using getAttentionLevel. This clears
phantom entries for removed sessions and seeds correct levels for new
sessions, preventing stale favicon color and attention counts until the
next SSE snapshot.

* fix: merge duplicate @/lib/types imports into single import statement

Combining the separate import type and value import from @/lib/types
into one import to satisfy the no-duplicate-imports lint rule.
2026-04-06 22:48:01 -07:00
harshitsinghbhandari f9d991d4fd fix: handle optional plugin field in CLI and web packages
Update all usages of project.tracker.plugin and project.scm.plugin
to use optional chaining since the plugin field is now optional
when package or path fields are specified.

Files updated:
- CLI: doctor.ts, status.ts, verify.ts
- Web: issues/route.ts, verify/route.ts, scm-webhooks.ts,
       serialize.ts, services.ts

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola 87c661332e fix(web): restore local type defs in mux-websocket and add coverage tests
tsconfig.server.json sets rootDir:"server" so importing from
../src/lib/mux-protocol.ts violated the boundary and broke the CI
typecheck step. Reverted to local type definitions with a comment
linking to the canonical source.

Also adds tests to bring diff coverage above 80%:
- MuxProvider.test.tsx: 30 tests covering lifecycle, message handling,
  and all terminal operations (subscribeTerminal, write, open, close,
  resize, reconnect, cleanup)
- api-routes.test.ts: GET /api/sessions/patches coverage (success,
  field shape, project filter, error path)
- useSessionEvents.test.ts: mux-path tests (muxSessions snapshot
  dispatch, membership-change scheduleRefresh, mux-active SSE bypass,
  cleanup on unmount)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola 44acb6d1db fix(web): re-send terminal dimensions on mux reconnect
After a reconnect MuxProvider re-opens all terminals, but new PTYs spawn
at 80×24 default. DirectTerminal only sent the initial resize on mount.
Add a dedicated effect that fires whenever muxStatus transitions to
"connected": calls fit.fit() to measure the current container then sends
the live cols/rows to the server, keeping the PTY size in sync.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola 469382ccdc fix(web): remove muxStatus from fullscreen-resize effect deps
muxStatus was in the deps array solely for the guard check at the top of
the effect. This caused the entire RAF loop + transitionend + backup timers
to re-run on every mux status transition (e.g. reconnecting→connected),
even when no layout change occurred.

Fix: track muxStatus in a ref (updated on every render) and read the ref
inside the effect, so the guard always sees the current value without
muxStatus being a dependency.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola 3ae8c9d2bf fix(web): cap PTY re-attach attempts to prevent unbounded respawn loop
Add reattachAttempts counter to ManagedTerminal and MAX_REATTACH_ATTEMPTS
constant (3). The onExit handler only re-calls open() while the counter is
below the cap, resets it to 0 on a successful attach, and falls through to
notify exit callbacks once the limit is reached — preventing a crash-loop
where a PTY that exits immediately after spawn triggers infinite re-attaches.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola faa1bfa8d6 fix(web): isolate subscriber callbacks in pty.onData with try-catch
A throwing callback (e.g. ws.send on a closed socket) would abort the
for-of loop, causing remaining subscribers to miss the data chunk and
skipping the ring buffer update — corrupting replay history for future
reconnections. Wrapping each call in try-catch keeps all subscribers
independent and ensures the buffer update always runs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola 44ff40c0ca fix(web): remove duplicate cleanup from error handler
In the ws library, "error" is always followed by "close", so the close
handler's cleanup (clearInterval, unsubscribe sessions, unsubscribe all
terminals) was running twice. Reduced the error handler to just the
console.error log and let close handle cleanup exclusively.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola 5e39b55461 fix(web): import mux protocol types from shared file and guard error send
- Replace the duplicated ClientMessage/ServerMessage/SessionPatch local
  type definitions in mux-websocket.ts with a single import type from
  src/lib/mux-protocol.ts — eliminates the risk of the two copies drifting
  apart as the protocol evolves
- Add ws.readyState === WebSocket.OPEN guard to the ws.send call inside
  the terminal-operation catch block, consistent with all other sends in
  the file; prevents a throw that would bubble into the outer catch and
  replace the real error with a misleading "Invalid message format"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola a9ee9eac7b fix(web): fix abortController clobber, heartbeat off-by-one, and remove dead close()
- SessionBroadcaster.connect(): capture controller in a local variable and
  only clear this.abortController in finally if it still equals the local
  controller; prevents a concurrent connect() call's controller being
  nullified by an older connect()'s finally block
- Heartbeat: send ws.ping() before incrementing missedPongs so all
  MAX_MISSED_PONGS pings are actually transmitted before terminating
  (previously terminated after MAX_MISSED_PONGS-1 sent pings)
- Remove TerminalManager.close(): never called by the mux handler (which
  uses per-subscriber unsubscribe instead) and subtly broken — it killed
  the PTY without clearing subscribers, which would have triggered an
  immediate re-attach via onExit

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola 78e5712555 fix(web): prevent duplicate buffer replay on reconnect and remove stale terminals ref
- Move buffer send + subscribe inside !subscriptions.has(id) guard so
  reconnecting clients don't receive the history replay twice (once on
  first open, once after wsRef is reassigned on reconnect)
- Remove `terminals` field from MuxContextValue and useMemo — it was
  populated from a write-only ref and never consumed by any component

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola b04137f6bc fix(web): address eighth-pass bugbot review issues
- useSessionEvents: mux-active SSE cleanup now also resets
  pendingMembershipKeyRef and refreshingRef so the aborted fetch's
  .finally() handler cannot reschedule after unmount
- DirectTerminal: add distinct "Disconnected" label and error-coloured
  dot for muxStatus "disconnected" (WebSocket constructor failure with
  no reconnect), instead of the misleading "Connecting…" shown for
  transient states

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola 2da6906be8 fix(web): prevent SSE effect from re-running on every mux snapshot
The SSE effect had muxSessions (array reference) in its deps, causing
it to re-run on every snapshot and fire cleanup that cleared the
debounce timer the mux effect intentionally preserved.

- Derive muxActive = muxSessions !== undefined and use that in SSE
  effect deps — the effect now only re-runs when mux transitions
  between present/absent, not on every new array reference
- Add reschedule in scheduleRefresh .finally() abort path: when a
  fetch is aborted mid-flight (by a new snapshot) and there is still
  a pending membership key, reschedule so the refresh isn't silently
  dropped

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola c418f852e2 fix(web): address seventh-pass bugbot review issues
- MuxProvider: handle exited and error terminal messages — exited
  removes the terminal from openedTerminalsRef (preventing re-open on
  reconnect) and writes a red notice into the xterm stream; error is
  logged to console
- MuxProvider: remove dead buffersRef/bufferBytesRef — client-side
  ring buffer was never read; the server already delivers history on
  open
- mux-websocket: use ws.terminate() instead of ws.close() on heartbeat
  timeout — an unresponsive peer won't complete the close handshake,
  so terminate() immediately destroys the socket and frees resources

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola 1f9fd03066 fix(web): process empty muxSessions array to detect session removal
Removing the muxSessions.length === 0 guard so an empty snapshot
triggers the membership-key comparison and scheduleRefresh(), which
fetches the full session list and dispatches a reset. Previously,
[] caused an early return that left removed sessions visible indefinitely.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola 5e8b67ca27 fix(web): address sixth-pass bugbot review issues
- MuxProvider: reset isDestroyedRef to false at the start of the
  effect so React StrictMode's double-invoke doesn't permanently break
  the connection (cleanup sets it true, re-run must reset it)
- DirectTerminal: remove dead status state — it was only set to "error"
  in a catch block but never read; displayStatus already derives the
  error indicator from the error string directly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola 926a235179 fix(web): address fifth-pass bugbot review issues
- mux-websocket: wire up the exited ServerMessage — add exitCallbacks
  to ManagedTerminal, pass onExit param through subscribe(), and fire
  callbacks when PTY exits and re-attach fails so clients get notified
- DirectTerminal: fix displayStatus to show "error" when there is a
  local error (e.g. xterm.js load failure) regardless of mux state
- useSessionEvents: SSE effect's mux early-return path now returns a
  cleanup function that clears refreshTimerRef and aborts in-flight
  requests on unmount, preventing post-unmount dispatch calls

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola 3eda33ea74 fix(web): address fourth-pass bugbot review issues
- DirectTerminal: remove stale muxStatus read from xterm setup effect
  (muxStatus was captured at mount, leaving reload button permanently
  disabled); reload button now checks muxStatus directly on each render
- TerminalManager: kill PTY and delete map entry when last subscriber
  unsubscribes, preventing orphaned node-pty processes when all mux
  clients disconnect

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola 1de9387465 fix(web): address third-pass bugbot review issues
- MuxProvider: assign wsRef.current immediately after construction so
  cleanup can close a WebSocket that is still in CONNECTING state;
  add isDestroyedRef to prevent the close handler from scheduling
  reconnects after the component unmounts
- mux-websocket: client "close" message now only unsubscribes that
  client — removed terminalManager.close() which killed the shared PTY
  for every other connected client
- useSessionEvents: mux effect cleanup no longer clears the debounce
  timer; only aborts in-flight requests, preventing rapid mux snapshots
  from starving the membership-change refresh

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola b9d21d1f18 fix(web): address bugbot review issues from second pass
- Replace Node.js Buffer.byteLength() with TextEncoder in MuxProvider
  (browser-safe UTF-8 byte counting for the ring buffer)
- Remove write-only sessionSubscribedRef from MuxProvider
- Remove dead DirectTerminalLocation, DirectTerminalWsUrlOptions,
  buildDirectTerminalWsUrl and their tests (superseded by mux)
- Call closeTerminal(sessionId) on DirectTerminal unmount so PTY
  processes are released and openedTerminalsRef stays accurate
- Add cleanup return to mux effect in useSessionEvents so pending
  refresh timers and abort controllers are cleared on unmount

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola f2986bf863 fix(web): address bugbot review — heartbeat, shutdown, runtime config, cleanup
- Use native WS ping frames for heartbeat so idle browser clients are not
  incorrectly disconnected (browser auto-responds to native ping with pong)
- Pass runtime config to buildMuxWsUrl() so dynamic port/proxy path set via
  TERMINAL_WS_PATH env var is actually used (was fetched but never consumed)
- Delay initial WS connect until runtime config fetch resolves, preventing
  race condition on first load
- shutdown() now terminates all mux clients and closes the WSS, preventing
  orphaned PTY processes on restart
- ws 'error' handler now unsubscribes terminal callbacks alongside session
  subscription to prevent leaks in edge cases where 'close' does not follow

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola 4684b75def feat(web): single-socket — multiplex terminals + sessions over one WebSocket
Replace three separate real-time channels (per-terminal WS, SSE, HTTP poll)
with a single persistent multiplexed WebSocket at /mux.

Architecture:
- Browser ↔ MuxProvider owns one WS connection per tab (/mux)
- Terminal I/O, resize, open/close all flow over mux channels
- Session status patches delivered via a shared SSE relay:
  mux server subscribes once to Next.js /api/events (SSE) and
  broadcasts to all connected browser clients — no per-client polling
- Manual WS upgrade routing fixes ws library limitation with multiple
  WebSocketServer instances on the same HTTP server

Remove:
- terminal-websocket.ts (legacy ttyd-based per-session server, port 14800)
- Per-terminal WebSocket connections from DirectTerminal
- Per-client 5 s HTTP polling for session patches

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola 82581fa040 refactor(web): migrate DirectTerminal to use multiplexed WebSocket
Replace direct WebSocket connections with mux channel subscriptions:
- Add useMux() hook to DirectTerminal component
- Replace WebSocket creation with openTerminal() call
- Use subscribeTerminal() for receiving terminal data
- Use writeTerminal() for sending user input
- Use resizeTerminal() for handling window resize
- Remove WebSocket reconnection logic (handled by MuxProvider)
- Remove runtime config fetching (handled by MuxProvider)
- Preserve all existing features:
  - XDA (Extended Device Attributes) handler for clipboard support
  - OSC 52 clipboard handler
  - Keyboard copy handler (Cmd+C/Ctrl+Shift+C)
  - Selection buffering during output
  - Theme switching
  - Fullscreen mode
  - Resize handling

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola 9458c83849 feat(web): add MuxProvider React context for persistent WebSocket
Implements client-side multiplexed WebSocket context:
- Create MuxProvider component with persistent connection management
- Implement exponential backoff reconnection (1s to 30s)
- Add subscribeTerminal/writeTerminal/resizeTerminal/openTerminal methods
- Manage per-terminal ring buffers (50KB max) for background output
- Track session patches from server
- Create useMux() hook for easy access in components
- Mount MuxProvider in app root layout via Providers wrapper
- Support dynamic runtime config from /api/runtime/terminal

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Gaurav Bhola 2e5ee30fcf feat(web): add multiplexed WebSocket protocol and mux server
Implements backend multiplexed WebSocket server on /mux endpoint:
- Add mux-protocol.ts with ClientMessage and ServerMessage types
- Create TerminalManager class for managing PTY processes independently
- Implement mux-websocket.ts with attachMuxWebSocket() function
- Wire mux server into existing direct-terminal-ws server
- Support multiple terminals over single persistent WebSocket connection
- Implement 50KB ring buffer for background terminal output
- Add heartbeat and reconnection logic

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 22:46:29 -07:00
Harsh Batheja 8625137702 feat: event-driven live tab titles and favicons via SSE (#848)
* feat: event-driven live tab titles and favicons via SSE

Switch tab titles and favicons from polling to real-time SSE updates:

- Extend useSessionEvents to expose sseAttentionLevels map from SSE
  snapshots (server-computed, includes full PR state)
- Refactor DynamicFavicon to use SSE attention levels instead of
  recomputing from the full sessions array (which has stale PR data
  between refreshes)
- Add useSSESessionActivity hook for session detail page to update
  document.title emoji immediately on activity change
- Add live dashboard title showing count of sessions needing attention
- Update PullRequestsPage to use new DynamicFavicon API

Closes #115

* fix: seed initial attention levels to avoid stale favicon/title on first render

Accept initialAttentionLevels parameter in useSessionEvents so callers
can seed the attention map from initialSessions via getAttentionLevel().
This prevents the favicon and dashboard title from briefly showing
"all clear" before the first SSE snapshot arrives.

* fix: add EventSource mock to session page test for SSE hook compatibility

* fix: reset stale activity state when sessionId changes in useSSESessionActivity

Add sessionId to the effect dependency array and reset state to null at
the start of each effect run so callers that reuse the hook with a
different sessionId don't see the previous session's activity.

* fix: reset sseAttentionLevels on initialSessions change to prevent stale data on project switch

The reset action now accepts an optional sseAttentionLevels field. When
initialSessions changes (e.g., project switch via sidebar), the dispatch
passes the current initialAttentionLevels via ref so the favicon and
dashboard title reflect the new project immediately rather than showing
stale attention data until the first SSE snapshot.
2026-04-06 22:46:29 -07:00
Tanuu 95ca1c1e21 fix: return 400 for invalid verify API payloads 2026-04-06 22:46:29 -07:00