Skip to content

Finish the region split for Home and Session Chat on both platforms - #1017

Merged
ivanfenenko merged 36 commits into
mainfrom
chore/finish-region-split
Nov 10, 2026
Merged

ivanfenenko merged 36 commits into
mainfrom
chore/finish-region-split

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes the region split that docs/architecture.md describes for Home and Session Chat, on both platforms. The four Screen Models become facades: regions own behaviour and state, the facade composes one UI state, forwards actions, and logs analytics. This is a refactor; nothing a user sees is meant to change.

What changed

Home has one UI state. MainScreenViewModel exposed uiState plus ten more public flows, and ProjectListHomeViewModel many separate observable properties. Both now expose a single HomeUiState; the former content state is its content field, with servers chrome, snackbar, live status, refreshing, session actions, paging and requests beside it.

Home has regions (same names on both platforms, under ui/main/region and UI/Main/Region):

  • HomeProjectList: probe, cache-first paint, sections, live rows, first loads, paging, reorder, remove, opening a New session draft
  • HomeWorktrees: project grouping inputs, worktree marks and extra observations
  • HomeServers: the server switcher and its paint generation
  • HomeAddProject: the Add project sheet
  • HomeSessionActions and HomeArchivedMenu already existed; on iOS they move from @Observable to the state + onChange shape Session Chat regions use

Session Chat's facade hands more to regions:

  • New: SessionChatDictation, SessionChatTimelineOffers, SessionChatProjectHeader, SessionChatTurnStatus, SessionChatNewSessionDraft
  • SessionChatWorktreeMove grows on Android and is new on iOS
  • SessionChatTimeline takes the timeline presentation state on Android and the expanded paragraphs on iOS
Facade Before After
Android SessionChatViewModel.kt 3,437 2,506
iOS SessionChatViewModel.swift 2,783 2,174
Android MainScreenViewModel.kt 2,093 1,058
iOS ProjectListHomeViewModel.swift 2,474 988

What stays in the facades is constructor wiring, state composition, analytics, and the forwarders the views call. Views still talk only to the facade.

How to read it

35 commits, one per step, each compiling on its own:

  1. Session Chat (Android): … ×8
  2. Home (Android): … ×9
  3. Region split (Android): … review follow-ups
  4. Home (iOS): … ×8
  5. Session Chat (iOS): … ×8
  6. Home (iOS): publish the paging inputs … review follow-up

The moves are easiest to check with the old file beside the new region. No public facade API that a view calls was renamed, apart from Home's state reads.

Deliberately not done

  • Concrete collaborators stay in the constructors. The facades no longer use HomeProjectsSnapshot, WorktreeInventoryCache, HomeWorktreesFeed, NewSessionDraftStore and similar; they pass them to the region that does. Removing them from the signatures would need injected region factories, a new layer with no behaviour gain. No DI module changed.
  • ActiveConnectionManager stays in the facades: there is no capabilities interface to put it behind.
  • Send orchestration stays in the Session Chat facade: it coordinates six regions.
  • Display-preference observers stay in the facades, to keep the order collectors launch in.
  • The large view files, the timeline block builders, the composer component and protocol routing are untouched.

Checks

On the final head:

  • Android: ./gradlew :app:testDebugUnitTest — 3,508 tests, 0 failures, 1 skipped (a benchmark marked @Ignore). :app:assembleDebug and :app:compileDebugAndroidTestKotlin succeed. :screenshot:compileDebugKotlin succeeds on JDK 21.
  • iOS: unit test target — 3,474 Swift Testing tests in 334 suites and 124 XCTest tests, 0 failures. Release configuration builds for the simulator.
  • Each step's commit passed its screen's test classes when it was made (Android: 902 Session Chat tests, 223 Home tests; iOS: 318 Session Chat tests, 166 Home tests).
  • Each platform and screen was reviewed by reading the moved code against the previous version statement by statement (conditions, order of side effects, scope and task ownership, cancellation, emission count and order, log text). No behaviour change was found on Android or in iOS Session Chat. One difference was found in iOS Home and is fixed in the last commit: the load-more footer inputs had stopped notifying the view.
  • One bug fix rides along, from review of this pull request: on iOS, a server switch that did not stick left the other server's cached projects on Home until the server resolved each path again. main has the same gap; Android already cleared them. The last commit resets them and adds a test that fails without the reset.
  • Diagnostic log text and analytics events, parameters and conditions are unchanged.
  • No UI change. No screenshots: this is a refactor.

Tests changed in two files only, both mechanically, for the single Home state: MainScreenViewModelTest.kt and ProjectListHomeViewModelTests.swift read uiState.content, uiState.sessionActions and so on where they read separate properties before. No assertion or expected value changed, and no test was removed. Session Chat tests are unchanged on both platforms.

Risks / Follow-ups

  • Not exercised in the running apps. Everything above is unit tests, builds and code review. The ordering of live events against cache and REST is the main risk in this kind of move, and unit tests cover it only partly. A scenario-harness pass on both platforms (streaming, subagents, activity-card timeline style, moving a session to a worktree, first send from a New session draft, switching server on Home with Add project open) is worth doing before merge.
  • Android Session Chat timeline presentation sits on the busiest publish path. List identity reuse and the live-rail cache are unchanged by reading; a regression there would only show while streaming.
  • Home live connection status (Android) is now collected for the life of the view model. Before, it stopped while Home was off screen and could show the last value briefly on return. The upstream is shared eagerly, so this adds no work.
  • Two things differ in timing but not in result. On iOS Session Chat, revert events and worktree.updated are handled by two tasks where one loop handled both; they change separate state. In a few places an analytics call now follows the region call in the same synchronous turn where it preceded it.
  • Known flaky tests seen during the work, each passing when rerun alone and none in code this touches: MessageSyncTests.messagePartDelta_appendsStreamingText (iOS), MessageContentPreparerTest and SseRecoveryFaultOracleTest (Android, under heavy machine load).
  • Possible follow-ups, not part of this change: pass slices of HomeUiState to child views on iOS so SwiftUI can skip unchanged parts (the body already re-ran on these changes before); a capabilities interface so Screen Models stop taking ActiveConnectionManager; AppRootView builds a new Home view model on each body evaluation because its factory is not a singleton (same on main).

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Note

Medium Risk
Large, behavior-preserving Home refactor spanning live session paging, server switching, and worktree sync—subtle ordering or emission regressions are possible despite unit tests.

Overview
Android Home finishes the region split: MainScreenViewModel now exposes one HomeUiState (content plus servers, paging, session actions, archived menu, snackbar, refresh, and live connection status) instead of many separate StateFlows. Logic moves into HomeProjectList, HomeWorktrees, HomeServers, and HomeAddProject; existing HomeSessionActions and HomeArchivedMenu gain synchronous onChange hooks that patch that unified state. MainScreen collects home once and uses derivedStateOf for paging inputs to limit list recomposition.

iOS aligns HomeArchivedMenu with the same state + onChange pattern (replacing @Observable). SessionChatUiModels adds expandedStepParagraphs for chip-timeline step expansion state.

Reviewed by Cursor Bugbot for commit e5f677a. Bugbot is set up for automated code reviews on this repo. Configure here.

ivanfenenko and others added 30 commits November 10, 2026 16:58
The composer dictation card (phases, model download, partial transcript,
level, the delayed Insert and cancellation) moves out of the facade into
a new region. The facade keeps one-line forwarders, the
dictationFinishDelayMs test seam, and the transcript splice, which the
region calls back. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Offers

The one-time Chip timeline intro (OPE-270) and Timeline Style picker
(#805) move out of the facade: their visibility, picker options, shared
notice slot, settle and load timers, and preference writes. The facade
calls the region from the same places in the combine collector, keeps
the analytics (logged when the region reports the offer was up), and
keeps its companion constants as aliases. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eader

The header's project identity (seed from Home's cached inventories,
server refine, and the worktree.updated re-refine for the checkout's
projects) moves out of the facade. bind still seeds synchronously
before writing the initial UI state; the facade's single live-event
collector delegates worktree.updated to the region. Behaviour is
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The working footer (chrome, hold, wake-up and the workingLamp log), the
pending-prompts strip (gate, wake-up, steer/queue/cancel requests) and
the background work rows (finish times, seen Done rows) move out of the
facade. mergeUiState calls turnStatus.resolve where the footer was
resolved, and the region resolves footer, strip and rows in the same
order with the same clock reads. Analytics and the capability check stay
in the facade. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d rows

The Move to worktree region now owns the New worktree form, the composed
SessionChatWorktreeMoveUiState (availability, rows, form), opening the
form from the current checkout, the row lookup for a move, and the
branch Home knows for a moved-to checkout. It exposes the same five
flows the facade combined as `changes`, which the facade still collects
at the same position in init. The form keeps its own default dispatcher
until the facade's ioDispatcher seam is set. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
SessionChatNewSessionDraft now owns the #1004 draft before its first
send: claiming and adopting the profile's draft, mirroring the composer
into the store (paused while binding), the Run session in card and its
sheets, base branches, Add project, discard / leave / release, and the
create step (worktree, session, model seed). The facade keeps binding
the regions, promotion, and the send orchestration, and makes every
call at the point the code ran before, so nothing reads the new draft
earlier than it did. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…meline

How the built rows are presented moves from the facade into the timeline
region: the live step rail mark (with its identity cache), step entry
debounce and activity card footer holds with their wake-up, activity
card sheet and child-session observation, unfolded step rails, expanded
chip paragraphs, the image viewer, and server image previews.

The facade calls presentMessages, syncStepTiming, the footer and
debounce reads, the image viewer reconcile and syncActivityChildren at
the same points of mergeUiState and publishUiState. Presentation changes
stay partial writes of the published UI state through a host interface
and are kept out of the region's state flow, so emission order and
count do not change. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The constructor parameters that now only feed regions (connection
profile store, worktree and project repositories, Home projects
snapshot, worktree inventory cache, server file previews, new session
draft store, Home worktrees feed) become plain parameters, and the
imports the moved code needed go. The constructor signature, and so
the Hilt binding, does not change. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Both existing Home regions now report every state write through an
optional synchronous onChange callback, in the same call as the write.
Nothing uses it yet; their state flows stay. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Add project sheet session (opening, field typing and debounced
listing, folder navigation, row summaries, retry) and the validate and
save half of addProject move to region/HomeAddProject.kt. The facade
keeps analytics, the guards in front of them, and everything after a
path is added (dismiss, reload, draft, scope request, snackbar), in the
same order. Sheet changes still patch Empty/Loaded event-style.
Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The title / server switcher chrome, the pending switch id, the switch
paint generation, the profile switch call and abandoning a switch that
did not land move to region/HomeServers.kt. The facade keeps the
profile lifecycle subscriptions and, through onSwitchStarted and
onSwitchAbandoned, stopping observations, painting the switched server
and reloading, in the same order. serversChrome re-exports the region
flow for now. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Per added path project resolution (cache seeding and live), worktree
inventories, branch lookups, the v1 live lists of non-added worktrees,
and publishing Home's projects to Session Chat and the Worktrees screen
move to region/HomeWorktrees.kt. The facade launches the publish
collectors at the same init positions and patches index changes into
Loaded synchronously, as before. HomeDirectoryRows becomes internal so
the region can read it. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
First part of the HomeProjectList region. The region now owns Home's
content (the facade's uiState is written only through its synchronous
onChange) together with live observation of the added paths, building
Home rows, first loads of new projects, parked first server snapshots,
and paging. stopLiveObservations still cancels load-more, resets paging
and stops the worktree extras and reload in one place. The facade keeps
the load, probe and cache paint for the next step and re-exports every
public flow. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
runHomeLoad becomes HomeProjectList.load, with the cache-first paint,
the probe (which still asks the archived menu to recheck), loading the
sections, and the probe-failure wait on the address check. Painting a
switched-to server from cache moves too; it reads the switch generation
through an isCurrent lambda, so both checks see live values. The call
order of cache paint, probe, live observations and worktree reload is
unchanged, and so is behaviour.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Last part of the HomeProjectList region: opening the New session draft
(pending open and the reveal-newest token), the pending scope request,
Home hidden/revealed, project reorder and its save, project removal and
its confirm, the Add project sheet patch into Empty/Loaded, and the
project session create error. Analytics and the snackbar stay in the
facade, in the same order around each action; the facade re-exports
every public flow. Unused facade imports go. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
uiState becomes StateFlow<HomeUiState>: the content mode
(MainScreenUiState) plus servers chrome, live connection status,
refreshing, snackbar, session actions, archived menu entry, paging,
reveal-newest token and pending scope request. Every region reports
into it through a synchronous onChange in the same call as its write;
the live connection status is mapped by an always-on collector seeded
from the current chrome. The ten extra public flows are removed and the
MainScreen wrapper reads one state.

MainScreenViewModelTest is rewritten mechanically to read the same
values from uiState (content collectors map and dedupe the content);
no expected value changes. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Constructor collaborators the facade only hands to regions become plain
constructor parameters (the constructor signature and Hilt bindings do
not change). Dead logging helpers and the content setter go; content
writes go through HomeProjectList only. Region helpers used only inside
HomeProjectList become private. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…st host

Review follow-ups. Home reads the paging set through derived state so the
session list recomposes only when that set changes, as it did before Home
had one UI state. A timeline built without a facade gets its own stand-in
host instead of sharing one. Behaviour is unchanged.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Pure file move of AddProjectFolderItem, AddProjectBarTarget,
AddProjectRoot, AddProjectSuggestion, AddProjectSheetState and
AddProjectSheetInputs out of the Home view model file. Behaviour is
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…+ onChange

Both regions now follow the Session Chat region shape: a plain MainActor
class with one Equatable `state` and an `onChange` callback instead of
Observable properties. The Home view model mirrors each state into an
observable property, and gains refreshArchivedMenu(scopeID:worktreesEnabled:)
so the view no longer reaches into the region. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Add project sheet session (open, field typing with debounced
listing, folder navigation, row summaries, browser, retry, validating
and saving the chosen path) moves into HomeAddProject. The Home view
model keeps analytics, the reload after an add, the scope request, the
snackbar, and writing the sheet into its content when the region
publishes one. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The title / server switcher chrome, the pending switch id, its paint
generation and the serialized switch task move into HomeServers. The
Home view model handles the region's switch-started and
switch-abandoned callbacks (stop live updates, paint the cached server,
reload). Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Project resolutions, worktree inventories and directories, v1 extra
directories, branches, server project info, the worktree marks and
branch lookup helpers, and their tasks move into HomeWorktrees. Every
mutation reports through onChange, which the Home view model mirrors
so its projects stay current; the section patch for a worktree mark
stays in the view model through onSectionMark. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Probing, cache-first paint, sections, live observation of each added
path, first project loads, paging, reorder, remove, the pending
session open, scope request and reveal token, and painting a switched
server move into HomeProjectList. The region stops HomeWorktrees'
observations with its own, so no caller can stop only half. The Home
view model keeps analytics, the snackbar, connection lifecycle routing
and read-throughs for the view. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every region reports through onChange to publishUiState(), which
rebuilds HomeUiState synchronously and assigns it only when it changed.
uiState is the view model's only observable stored property; the
mirrors and read-throughs are gone, and ProjectListHomeView reads
viewModel.uiState. The live connection status keeps its equality guard.
The view model tests read uiState instead of the old properties; no
expected value changed. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The static projects and removable-directories helpers only served the
intermediate mirrors; the instance methods carry the logic again.
Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The composer dictation card, its insert generation, the finish task and
the finish delay move out of the Screen Model into a new region. The
facade keeps its dictation forwarders and the dictationFinishDelayNs test
seam, splices Insert's transcript through updateComposerText, and keeps
the level fast path that updates only uiState.dictation. Behaviour is
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The one-time Chip timeline intro (OPE-270) and Timeline Style picker
(#805), their notices, tasks and preference writes move into a new
region. Publish calls its silent updateTurnActive and
observeTimelineLoad; the facade keeps the analytics, logged when the
region reports an offer was hidden, and aliases for the constants tests
read. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eader

The header's project identity, its cached seed, the server refresh with
its inventory loads, the checkout project ids and the worktree.updated
observation move into a new region. The facade keeps a sessionEventTask
for live revert updates, which shared that task before. MainActor.run
hops became plain assignments inside the MainActor region; the
cancellation checks stay where they were. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…TurnStatus

The working footer (chrome, hold and its wake, the workingLamp log), the
pending-prompts gate and wake, the steer / queue / cancel calls, and the
background work rows (finish times, live-since, Done-tab seen ids) move
into SessionChatTurnStatus. Publish calls its silent resolve(_:) at the
same point; wakes republish through onWake. The facade keeps the
capability guard and analytics before each pending prompt call, and the
pure pendingPrompts(loaded:optimistic:) helper. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ivanfenenko and others added 5 commits November 10, 2026 17:19
Move to worktree (#785) leaves the Screen Model: the sheet flag, the
New worktree form, the move call with its notice and error, and the
session.moved observation with movedDirectory. The facade keeps the
capability and created-session guards, the screen-view analytics, and
exposes the form as worktreeCreate for the view. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The draft (#1004), its store and profile key, the Run-session-in
context, base branches, the protocol probe, and the create step of the
first send (worktree, session, model seeding) move into
SessionChatNewSessionDraft. The facade keeps binding regions to the
draft's checkout, the send orchestration around the composer, promotion
and the prompt send, in the same order as before. Behaviour is
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The chip-timeline paragraphs expanded past +N more move from the Screen
Model into the Timeline region's state, next to the other presentation
state it already owns. Expanding still republishes without a step timing
pass, and promoting a draft clears them silently at the same point as
before. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Groups the six region properties added by the split next to the
existing ones in the Screen Model. No code change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review follow-up. The load-more footer and trigger read which directories
have live lists and older sessions. Those were observable on the view model
before the split and private to HomeProjectList after it, so a change to
them alone no longer redrew Home. HomeProjectList now mirrors them into
HomeSessionPagingState on Home's UI state.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@ivanfenenko
ivanfenenko marked this pull request as ready for review November 10, 2026 19:24
@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

@cursor review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: no finding that 2+ of 2 passes agreed on.

opencode pr-review · passes: muse-spark-1.3-contributor, glm-5.3-flash, deepseek-v4.1-flash · $0.192 · 1 pass(es) failed

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e5f677a. Configure here.

…tick

A server switch paints the target server's cached projects before the
switch lands. When the switch did not stick, Home reloaded without
clearing them, and the reload keeps any project it already has for a
path, so the active server could show the other server's project ids
and names until the server resolved the path again. Android already
clears them.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@ivanfenenko
ivanfenenko merged commit fed66a2 into main Nov 10, 2026
@ivanfenenko
ivanfenenko deleted the chore/finish-region-split branch November 10, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant