Dashboard sessions: extract pure renderers from initSessions closure to module scope #71
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Background
assets/sessions.jsdefinesinitSessions(hooks)as a single ~327-line closure that wraps state (per-session sequence numbers, in-flight controllers, active session id) together with the entire render pipeline. The closure violates the project's function-size rule and makes per-helper unit testing impractical.Source: code review of branch
phase-8/dashboard-ui-pr3-sessionsFile:
crates/cognix-server/assets/sessions.js:44-370Branch:
phase-8/dashboard-ui-pr3-sessionsMotivation
buildDetailHeader,buildDetailTabs,renderFallback,renderThoughtCards,renderPaletteItems,applySearchFilter,isTypingTarget— and not on closure state. They can be lifted to module scope without behavior change.splitThoughtsText,parseThoughtCard,clearChildren,isTypingTarget) already demonstrate the pattern.sequenceById,inflightById,activeSessionId,listRefreshSequence,sessionFetch,selectSession,loadSessionList, palette open/close, key handler) and open the door to direct unit tests for the renderers.Why deferred from
phase-8/dashboard-ui-pr3-sessionsparseThoughtCard, theloadSessionListrace guard, and thesessionFetchcleanup, making review noisier.Proposed work
buildDetailHeader,buildDetailTabs,renderFallback,renderThoughtCards,renderPaletteItemsto module scope; passschemaFallbackTextand any required DOM nodes as parametersapplySearchFilter,isTypingTarget,setActiveRowif their parameter lists stay reasonable (≤ 3 args)sessionFetch,selectSession,loadSessionList, palette open/close, and the global keydown handler insideinitSessionsbecause they reference closure statecrates/cognix-server/src/transport/ui/assets.rsstatic contract tests still pass (test_session_bound_rpc_uses_session_fetch,test_dashboard_tool_contracts_for_session_calls,test_schema_check_fallback_for_session_renderers)Acceptance
assets/sessions.jsexceeds 50 linesinitSessionsclosure body shrinks to state-bound logic onlyReferences
phase-8/dashboard-ui-pr3-sessionsinitSessionsclosure size and helper extraction.claude/rules/coding-style.md— functions < 50 lines