refactor: extract an internal session broker boundary#199
Conversation
Greptile SummaryThis PR extracts a generic session broker namespace ( Confidence Score: 5/5Safe to merge — all findings are P2 style/architecture suggestions with no functional impact. No P0 or P1 issues found. The refactor is functionally correct: wire parsing, command dispatch, snapshot lifecycle, and test coverage all work as intended. The P2 comments flag that SessionBrokerState and SessionBrokerClient still import Hunk-specific types despite living in the generic broker namespace — a clean-up for a follow-up PR rather than a blocker here. src/session-broker/brokerState.ts warrants the most attention: it drives all the broker/Hunk coupling concerns called out in the review. Important Files Changed
Sequence DiagramsequenceDiagram
participant App as Hunk App (UI)
participant Reg as hunk-session/sessionRegistration
participant Client as session-broker/brokerClient
participant Server as session-broker/brokerServer
participant State as session-broker/brokerState
participant Wire as hunk-session/wire
participant Bridge as hunk-session/bridge
App->>Reg: createSessionRegistration(bootstrap)
Reg-->>App: HunkSessionRegistration
App->>Client: new SessionBrokerClient(registration, snapshot)
App->>Client: start()
Client->>Server: WebSocket connect + register
Server->>Wire: parseSessionRegistration(payload)
Wire-->>Server: HunkSessionRegistration
Server->>State: registerSession(socket, reg, snapshot)
Note over Client,Server: Snapshot updates
App->>Client: updateSnapshot(snapshot)
Client->>Server: snapshot message
Server->>State: updateSnapshot(sessionId, snapshot)
Note over Server,Bridge: Inbound agent command
Server->>Client: command message
Client->>Bridge: dispatchCommand(message)
Bridge->>App: handler call
App-->>Bridge: HunkSessionCommandResult
Bridge-->>Client: result
Client->>Server: command-result message
Server->>State: handleCommandResult()
State-->>State: resolve pending promise
|
Summary
src/session-broker/*src/hunk-session/*Testing
bun run typecheckbun testThis PR description was generated by Pi using OpenAI GPT-5