Group `clai2` sessions by project and worktree, keeping removed worktrees under their repository
Part 35 of the clai2 web UI stack (… → #10334 → this PR). Based on #10334. No linked issue: requested by the CLAI maintainer.
Why. The web sidebar grouped sessions by project_identity(workspace), keyed by the Git common dir. That only works while the folder exists: a session from a removed worktree (or from <checkout>/src/pydantic_clai2 inside one) fell back to key=workspace, name=<folder>, so every such session became its own group, e.g. eight separate pydantic_clai2 groups. Sessions should be grouped by project (the Git repository), with each project's worktrees inside it.
What changes
ConversationSummarygains an optionalcheckout: GitCheckout | None(repository common dir, name, checkout root, branch). CLAI'sSessionrecords it when it saves a session, reading Git once per session off the event loop; a fork keeps its source's, a session resumed from another directory keeps what it saved. Old rows read asNone; older CLAIs ignore the field.runtime/project_identity.placementsdecides where each workspace belongs: an existing folder keeps its live identity (as before); a removed one takes the checkout saved with its newest session, else the innermost known checkout that held it, else a worktree layout (ROOT/.worktrees/NAMEfrom--worktree,.../worktrees/REPO/NAMEas herdr does, or a folder named after the repository beside its other worktrees); the rest go to one "Removed folders" group, never one group per session.- Project name stays the main checkout's folder (the common dir's parent): stable across worktrees, no extra Git call, and independent of the remote's name (
originis not always the upstream). /api/sessionsreturnsProject.worktrees[](root,label= branch or folder,current,missing,sessions). The sidebar shows project, then worktree, then sessions: both levels collapse, a lone checkout gets no heading unless it is removed, the current project and worktree come first, search shows every match whatever is collapsed, and a collapsed group still shows a running dot. Rebuilt bundle included.- The terminal
/resumebrowser sharesplacements: a removed worktree now sits under its repository asBRANCH (removed)instead of in "missing folders". - Docs: README web UI section,
PLUGINS.mdweb section,AGENTS.mdfile map, and the harness conversation-store docs.
Verification.
- New tests:
test_placements_of_removed_folders,test_removed_worktree_stays_in_its_repository(tests/clai2/test_session_browser.py),test_a_session_saved_in_a_git_checkout_records_it(tests/clai2/test_sessions.py),test_sidebar_groups_sessions_by_project_then_worktree(tests/clai2/test_web.py, real repo, linked and removed worktrees). 155 targeted tests pass, plus 1284 other session-relatedtests/clai2tests; branch coverage 100% forproject_identity.py,remote.py,protocol.py,conversations.pyand every changed line of_session.pyandsession_browser.py. Pyright and ruff clean,tsc --noEmitclean. - Headed Chromium against an isolated
clai2 --web -m testwith a scratch repo, two herdr-style worktrees, one removed worktree with saved checkouts and one removed before this change, a second repo, a plain folder, and a removed non-Git folder. Before: 5 groups, the removed worktree's root and itssrc/pkgas separate groups. After:alpha(feat-a current, feat-b, doomed-two removed, doomed removed, main),beta,plain,Removed folders; 13 sessions; collapse and search checked, dark and light.
What changes for existing users. The web sidebar and /resume group a removed worktree's sessions under its repository; new saves record the checkout.
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
- PR title is fit for the release changelog.