feat: session refactor (#30)

This commit is contained in:
Carlos Florêncio
2026-01-17 19:02:22 +00:00
committed by GitHub
parent 91a4e0551f
commit fb042e4c59
106 changed files with 4100 additions and 2582 deletions
+24 -5
View File
@@ -33,7 +33,7 @@ make -C apps/backend lint
## Backend Architecture (High Level)
- **Transport**: WebSocket-only for client <-> backend.
- **Transport**: WebSocket for realtime updates; HTTP for CRUD + SSR fetches.
- **Gateway**: Single WS endpoint at `ws://localhost:8080/ws`.
- **Orchestrator**: Starts/stops/resumes tasks, manages sessions.
- **Agent lifecycle**:
@@ -92,7 +92,11 @@ Client (WS) Backend Runtime agentctl
### Subscription Strategy
TODO
- Components subscribe to the channels they need (task, session, repo), using hooks.
- WebSocket client deduplicates subscriptions with reference counting.
- Reconnects re-subscribe all active channels automatically.
- Event handlers update store slices; components only read from store.
- URL params set active task/session in store for consistent view state.
**Why This Works**
@@ -111,15 +115,30 @@ Layer 3: Components (subscribe + render)
### Store Structure
TODO
- Task/session scoped data is keyed in store:
- `messages.bySession[sessionId]`
- `messages.metaBySession[sessionId]`
- `gitStatus` keyed by `sessionId`
- `shell.outputs` keyed by `sessionId`
- Active selection state lives in store:
- `tasks.activeTaskId`
- `tasks.activeSessionId`
### Custom Hooks Pattern
TODO
- Hooks own subscriptions and return data from store:
- `useSessionMessages(sessionId)` → messages + loading/meta
- `useLazyLoadMessages(sessionId)` → pagination
- `useSessionGitStatus(sessionId)` → git state
- `useSessionShellOutput(sessionId)` → shell output
- Hooks subscribe on mount, cleanup on unmount; no manual dedup in components.
### Page-Level Responsibilities
TODO
- SSR fetches initial task/session + board snapshot, hydrates store.
- Page reads URL `sessionId`, resolves task via session, and calls `setActiveSession(taskId, sessionId)` after load.
- Page coordinates task list + session list loading (e.g., `listTaskSessions`).
- Components render from store and trigger hooks for live updates.
## Agents and ACP