Move pending approval derivation and thread visit tracking to shared session logic #16
Merged
juliusmarmingemerged 2 commits into
main fromcodething/68f0e731·merged by juliusmarminge View on GitHubSummary#
- Moved pending-approval derivation out of
ChatViewinto sharedapps/web/src/session-logic.tsand added a dedicatedPendingApprovaltype. - Added
derivePendingApprovalstests to cover request, decision, and turn-completion clearing behavior. - Added
lastVisitedAtto thread persistence (persistenceSchema.ts) and threaded it through hydration/serialization round-trip. - Updated sidebar threading status UX to support richer states (
Working,Connecting,Completed,Awaiting response) and derive completion visibility fromlatestTurnCompletedAtvslastVisitedAt. - Updated state reducer behavior so selecting a thread and completing the active thread mark it as visited (including persisted defaulting on import/create).
- Removed duplicated approval derivation helpers from
ChatViewand switched to derived session-logic path.
Testing#
- Added tests in
apps/web/src/session-logic.test.tsforderivePendingApprovals. - Added tests in
apps/web/src/persistenceSchema.test.tsforlastVisitedAthydration/persistence. - Added tests in
apps/web/src/store.test.tsfor active-thread visit updates and completion-seen timestamps. - Not run: lint/test command not executed in this context.
Summary by CodeRabbit#
New Features
- Sidebar now shows richer status pills (colored label, dot, pulse) including an “Awaiting response” state for threads with pending approvals.
Bug Fixes
- Thread visit and completion visibility improved: visits and completed turns are tracked so active threads show as seen.
Refactor
- Approval derivation and persistence of thread visit timestamps centralized for more consistent UI behavior.
- 1
Greptile Overview
Greptile Summary
Moved pending approval derivation logic from
ChatViewinto sharedsession-logic.tsmodule and addedlastVisitedAtthread tracking for improved UI state management.- Centralized
derivePendingApprovalsfunction with enhanced logic that clears pending approvals onturn/completedevents (improvement over original implementation) - Added
lastVisitedAttimestamp to Thread interface with full persistence support and test coverage - Updated Sidebar with richer thread status indicators: "Working", "Connecting", "Completed", and "Awaiting response" states
- Implemented automatic
lastVisitedAtupdates on thread selection and turn completion for active threads - Removed code duplication from ChatView and unused
terminalShortcutHintvariable - All changes include comprehensive test coverage for derivation logic, persistence round-trips, and state reducer behavior
Confidence Score: 5/5
- This PR is safe to merge with high confidence
- Well-structured refactoring with comprehensive test coverage, proper type safety, and logical improvements to approval clearing behavior. All changes follow established patterns and maintain backward compatibility through optional field handling.
- No files require special attention
Important Files Changed
Filename Overview apps/web/src/session-logic.ts Added derivePendingApprovalsfunction andPendingApprovaltype, moved from ChatView with improved logic to clear approvals on turn completionapps/web/src/persistenceSchema.ts Added lastVisitedAtto persisted thread schema and hydration/serialization logic with proper optional handlingapps/web/src/store.ts Updated reducer to set lastVisitedAton thread selection and turn completion for active thread, defaults tocreatedAton thread creationapps/web/src/components/Sidebar.tsx Enhanced thread status pills with richer states (Awaiting response, Completed) based on pending approvals and unseen completion tracking Sequence Diagram
Last reviewed commit: 1b7abe5sequenceDiagram participant User participant Sidebar participant Store participant Thread participant SessionLogic User->>Sidebar: Select thread Sidebar->>Store: SET_ACTIVE_THREAD Store->>Thread: Update lastVisitedAt (current timestamp) User->>ChatView: Send message / Turn starts ChatView->>Store: APPLY_EVENT (turn/started) Store->>Thread: Add event, update session status Note over Thread,SessionLogic: During turn execution ChatView->>Store: APPLY_EVENT (approval request) Store->>Thread: Add approval request event Sidebar->>SessionLogic: derivePendingApprovals(thread.events) SessionLogic-->>Sidebar: Returns pending approvals Sidebar->>Sidebar: Show "Awaiting response" pill User->>ChatView: Approve/Deny action ChatView->>Store: APPLY_EVENT (decision) Store->>Thread: Add decision event Note over Thread,SessionLogic: Turn completes ChatView->>Store: APPLY_EVENT (turn/completed) Store->>Thread: Update latestTurnCompletedAt Store->>Thread: Update lastVisitedAt (active thread only) Sidebar->>SessionLogic: derivePendingApprovals(thread.events) SessionLogic->>SessionLogic: Clear pending on turn/completed SessionLogic-->>Sidebar: Returns empty array Sidebar->>Sidebar: Check hasUnseenCompletion Note over Sidebar: completedAt > lastVisitedAt Sidebar->>Sidebar: Show "Completed" pill (if inactive) User->>Sidebar: Select thread again Sidebar->>Store: SET_ACTIVE_THREAD Store->>Thread: Update lastVisitedAt Sidebar->>Sidebar: Hide "Completed" pill- Centralized
Move pending approval derivation to
apps/web/src/session-logic.tsand add thread visit tracking withlastVisitedAtused by Sidebar status pills in Sidebar.tsx#Introduce
derivePendingApprovalsinsession-logicand update Sidebar to render status pills based on pending approvals, session state, and unseen completions; addlastVisitedAttoThread, persist it, hydrate it, and update it on thread activation and turn completion.📍Where to Start#
Start with
derivePendingApprovalsand related helpers in session-logic.ts, then review status pill rendering in Sidebar.tsx andlastVisitedAthandling in store.ts.
Macroscope summarized cab54fe.juliusmarminge merged this057770e
juliusmarminge closed this
Sign in to join this conversation.
Caution
Review failed#
The pull request is closed.
Walkthrough#
Adds thread visit-time tracking, moves pending-approval derivation into session-logic as a shared exported function, and replaces Sidebar's status label with a pill-based status UI; updates store and persistence to surface and persist
lastVisitedAt, plus tests for these behaviors.Changes#
apps/web/src/session-logic.ts,apps/web/src/session-logic.test.ts,apps/web/src/components/ChatView.tsxderivePendingApprovalsandPendingApprovalinterface insession-logic. Removed local approval helpers/typing fromChatView;ChatViewnow imports and usesderivePendingApprovals. Tests added/updated to cover pending-approval derivation.apps/web/src/components/Sidebar.tsxThreadStatusPillsystem and helpers (hasUnseenCompletion,threadStatusPill). Added per-thread memoized mapping of pending approvals and updated rendering to show colored pill, dot, pulse, and label states (e.g., “Awaiting response”).apps/web/src/types.ts,apps/web/src/store.ts,apps/web/src/store.test.ts,apps/web/src/persistenceSchema.ts,apps/web/src/persistenceSchema.test.ts,apps/web/src/persistenceSchema.test.tslastVisitedAt?: stringtoThread. Store initializes/updateslastVisitedAton ADD_THREAD, SET_ACTIVE_THREAD, and when aturn/completedevent applies to the active thread. Persistence schema and hydration now includelastVisitedAt. Tests added/updated to assert visit-time behavior and persisted shape.apps/web/src/components/ChatView.tsxSequence Diagram(s)#
Estimated code review effort#
🎯 4 (Complex) | ⏱️ ~45 minutes
🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
main✨ Finishing touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.