Expose AI sessions to apps/ui, grouped by owner site#3133
Merged
youknowriad merged 4 commits intotrunkfrom Apr 18, 2026
Merged
Conversation
Move the shared parts of the CLI's AI sessions module (types, file-naming, summary, store, paths) to tools/common/ai/sessions so the main process and the new apps/ui can read the same JSONL files the CLI writes. The CLI keeps thin wrappers that bind its appdata root; recorder/context/replay stay CLI-only. Derive an ownerSitePath/ownerSiteName on AiSessionSummary from the first site.selected event so each session has a stable project owner even when the CLI switches sites mid-session. Add listAiSessions / loadAiSession / deleteAiSession IPC handlers and wire them through preload. Extend the apps/ui Connector with matching methods, add a useSessions hook, and rework the sidebar into a ProjectList that shows each site as a top-level project with its sessions nested underneath, plus an "Unassigned" bucket for sessions with no owner. A /sessions/$sessionId placeholder route confirms the load path ahead of the AI chat UI. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collaborator
📊 Performance Test ResultsComparing 4bfe299 vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
… actions - Turn on ThemeProvider density="compact" so all @wordpress/ui components shrink their paddings in unison, instead of patching sizes per-component. - Drop orphaned sessions (owner site no longer exists) into the Unassigned bucket so they stay reachable instead of silently disappearing. - Rework the project row so the trigger button spans the full width and its focus ring wraps the whole row; the "new session" plus sits on top as an absolutely-positioned IconButton that fades in on hover or focus-within. - Tighten visual hierarchy: project titles use regular weight at 0.65 opacity, session links sit at full neutral foreground, sessions and the empty-state message share the same left padding so they line up past the chevron. - Collapse the Unassigned group by default and separate it from real projects with a divider. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Switch the chevron and the "Add site" plus from the raw @wordpress/icons
Icon (hardcoded sizes) to Button.Icon so they share the component-driven
layout inside a Button. Set both to size={16} to match the per-project
IconButton at size="small", and scale the SVG content to 0.75 so the
paths have visual padding inside their 16×16 box.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
apps/cli/ai/sessions/store.ts and the three functions in apps/studio/src/lib/ai-sessions.ts were just partial application - binding the sessions root directory before delegating to the @studio/common store. That indirection costs more than it saves: every caller now imports from @studio/common directly and passes getAiSessionsRootDirectory() explicitly. Flatter, more honest. Also sort the sidebar's project groups by the newest session's updatedAt so the most-recently-used project lands at the top and auto-expands on launch. Projects with no sessions drop to the bottom; Unassigned stays pinned at the end. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
How AI was used in this PR
Most of the scaffolding (shared-module move, IPC handlers, Connector plumbing, sidebar rewrite) was drafted by Claude under my direction. I reviewed each diff, made the design decisions below, and verified typecheck / lint / the full vitest suite locally. The Electron renderer itself was not booted as part of this change — the IPC contract is typed end-to-end but not runtime-exercised yet.
Proposed Changes
First step toward the new apps/ui: surface the AI sessions that the
studio codeCLI writes to disk, grouped by the site ("project") that owns them, instead of the current bottom-of-sidebar sites selector.apps/cli/ai/sessions/that don't depend on CLI-only types (types,file-naming,summary,store,paths) intotools/common/ai/sessions/, parameterized on the sessions root directory.recorder,contextandreplaystay CLI-only; the CLI exposes a thin wrapper that binds its appdata root so existing callers and tests are unchanged.SDKMessagebecomesunknownin the shared type sotools/commonstays SDK-free; the CLI casts at its boundaries.AiSessionSummarygainsownerSitePath/ownerSiteName, computed from the firstsite.selectedevent in the JSONL (pin-on-create). The existingselectedSiteNamekeeps its meaning (latest in-session site). The recorder is unchanged, so sessions with no site remain valid and land in an "Unassigned" bucket.apps/studio/src/lib/ai-sessions.tsresolves the root viaapp.getPath('userData')(physically the same dir the CLI writes to).listAiSessions,loadAiSession,deleteAiSessionexported fromipc-handlers.tsand wired throughpreload.ts.ConnectorgainsgetSessions/getSession/deleteSession, wired in the IPC connector. NewuseSessions/useSession/useDeleteSessionhooks. The sidebar'sSiteListis replaced byProjectList: sites render as collapsible top-level groups with their sessions nested underneath, plus an "Unassigned" group for sessions with no owner. Clicking a session routes to a/sessions/$sessionIdplaceholder that confirms the session loaded — the AI chat UI will land on top of this in a follow-up.Notable non-goals / deferred
session.projectevent — no schema lock-in.Testing Instructions
npm installif needed, thennpm run typecheckandnpm test— both should be green (1468 tests pass locally).npm run cli:build && node apps/cli/dist/cli/main.mjs code— send a prompt, select a site, then exit.npm start. The legacy UI is unaffected.apps/uionce it's wired into the dev flow. You should see each site as a top-level project in the sidebar with its sessions underneath. Clicking a session navigates to a placeholder detail screen showing the first prompt, owner site name, and event count.Pre-merge Checklist
🤖 Generated with Claude Code