Unified session list: backend service + endpoint#139
Open
aakhter wants to merge 2 commits into
Open
Conversation
First increment of the read-only "complete + searchable session list".
- New src/services/unified-session-service.ts: mergeUnifiedSessions() combines
live + persisted (state.json) + lifecycle + ~/.claude transcript history + mux
stats into one list de-duped by sessionId, with precedence
history < lifecycle < persisted < live, a meaningfulness floor that drops bare
lifecycle/mux-only noise, and a stable newest-first sort. Plus
filterAndPaginate() (case-insensitive q over name/firstPrompt/workingDir/
sessionId; total before paging; limit clamped [1,500]). No IO — unit-testable.
- New GET /api/sessions/unified in session-routes.ts: gathers the five sources
from ctx (sessions/store/lifecycle/scanProjectDir/mux, each try/caught), feeds
the pure service, returns { sessions, total } (ApiResponse envelope). testMode
short-circuits to empty.
Tests: unified-session-service.test.ts (12, pure) + unified-sessions-routes.test.ts
(4, app.inject).
createInitialRalphTrackerState() stamps lastActivity: Date.now(). The 'should create fresh instances each time' test deep-equaled two factory results, so two calls straddling a millisecond boundary differed by 1ms and failed intermittently (e.g. PR Ark0N#139 CI: 1782927694581 vs ...580). Exclude the dynamic lastActivity from the equality check and assert it is a number separately, preserving the test's intent (distinct instances with identical initial field values) without the timing race.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First increment of a read-only "complete + searchable session list" — the backend half. Frontend (rich list UI, persistent modal, live refresh) and polish (pinning, cross-device ordering, name/prompt retention) follow in stacked PRs.
What this adds
src/services/unified-session-service.ts— pure, IO-free, unit-testable:mergeUnifiedSessions()combines five sources — live sessions + persisted (state.json) + lifecycle log +~/.claudetranscript history + mux stats — into one list de-duped bysessionId, with precedencehistory < lifecycle < persisted < live, a meaningfulness floor that drops bare lifecycle/mux-only noise, and a stable newest-first sort.filterAndPaginate()— case-insensitiveqover name/firstPrompt/workingDir/sessionId;totalcomputed before paging;limitclamped to[1, 500].GET /api/sessions/unifiedinsession-routes.ts— gathers the five sources from ctx (eachtry/caught so one bad source can't fail the request), feeds the pure service, returns{ sessions, total }in the standardApiResponseenvelope. Short-circuits to empty in test mode.Tests
test/services/unified-session-service.test.ts— 12, pure (merge precedence, de-dup, meaningfulness floor, sort, filter, pagination, limit-clamp).test/routes/unified-sessions-routes.test.ts— 4, viaapp.inject(envelope, pagination, q-search, limit-clamp).Verification
tsc --noEmitclean · new tests 16/16 · existingsession-routessuite 53/53 (no regression) · prettier + eslint clean · build clean.Read-only and additive — no existing route or behavior changes.