All three investigations are done, and I verified the one suspicious join myself. Here's the synthesis.
TLDR
Yes — I'd build the foundation first, but the "foundation" is a modest extraction, not a framework. #1592 is already part of that foundation and should land first. #1616 should then be reworked on top of a small shared cell-routing package before merge: it currently inlines ~300 lines of generic multi-cell orchestration under codeSearch-prefixed names, mints tokens wastefully (once per cell instead of once per jurisdiction), and joins the repo index to the cluster catalog on a fragile key. Since it's gated behind ENTIRE_CODE_SEARCH=1 and has had no human review yet, now is the cheapest moment to fix the shape.
Why the timing question is real: three routing shapes are converging
The backend model (entiredb + entire-api) defines exactly three request shapes, and the BFF (entire.io/api/src) already has a named helper for each:
- Repo-scoped → one cell (BFF
resolve-cell.ts): a placement lives in exactly one cell; resolve it, mint a jurisdiction token, call that cell. The CLI's version is the experts path (resolveExpertsCellTarget in experts_cell_target.go).
- User-scoped
/me → home cell, never fan-out (BFF resolve-home.ts): activity is forwarded into the user's home region, so /me is a single point-to-point call routed by the home_jurisdiction JWT claim. That's what #1592 adds (entireapi_client.go, ErrNoCellForJurisdiction, the case-folded claim).
- Repo-set queries → fan out to every hosting cell, merge client-side (BFF
code-search.ts): no server-side aggregator exists anywhere — core returns catalogs, cells are strictly local. #1616 is the CLI's first instance of this shape.
The CLI is growing these one command at a time, each with its own seams. #1616 would make it three commands, three sets of plumbing.
Concrete problems with merging #1616 as-is
1. The generic layer is inlined and search-named. groupReposByCell, resolveRepoFilters, the ListRepos→ListClusters→CellTarget resolution, the WaitGroup fan-out with per-cell timeouts, and the partial-failure tracking (FailedJurisdictions) are all in search_cmd.go — none of it is search-specific. The next fan-out command (experts natural-language query is an obvious candidate: cells return 503 for it today precisely because it needs the search index) copies or refactors it. It also duplicates experts' patterns with different choices: a second interface+seam, different timeout constants, and no placement/active-mirror filtering.