Repository navigation
fix(app): retain chosen clone directory - #64672
stussysenik wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
This fixes only half of #64644. I ran the server and web app from source for the base and for this PR, and ran the issue's Playwright reproduction with two plain clones of one repo:
- Saved selection (fixed): after adding
repo-copy, Home's saved selection is now…/repo-copy, and it stays that way after a reload. On the base it is…/repo. - New session (not fixed): New session from Home still opens the draft in
…/repo. The footer shows/tmp/opencode/clones/repo, and every request the draft makes (/api/location,/api/config,/api/vcs, …) useslocation[directory]=/tmp/opencode/clones/repo. This happens becausectx.projects.forDirectoryreturnsundefinedfor a sibling clone, soresolveStartProjectfalls back to the canonical path. The unit test passes only because it stubsforDirectoryto return the canonical project, which production never does (see the inline comments). - Regression:
placenow keeps a directory that belongs to no used project whenever the server has any used project. So a selection on a project that was removed while another stays used is no longer cleared.
All 68 tests under packages/app/src/home pass, and tsc -b in packages/app is clean.
Public API: unchanged.
The screenshots show the new-session draft on the base and with this PR. Both still point at …/repo.
Related: #55351
| used: readonly Project[], | ||
| last: Project | undefined, | ||
| ) { | ||
| const match = preferred ? forDirectory(preferred) : undefined |
There was a problem hiding this comment.
In the real app, forDirectory(preferred) returns undefined for a sibling clone. runtime.tsx forDirectory only matches a project's own path, its sandboxes, or folders inside it. So match is undefined and this falls back to last/used[0] with project.worktree, the canonical folder. I confirmed it in the browser: with the selection saved as …/repo-copy, New session from Home still opens the draft in …/repo (all its API requests use location[directory]=…/repo). The clone has to be resolved to its project id some other way. Options: the /api/location result already fetched in add, or keeping the chosen directory whenever the selection is set and the project comes from the selection or the last-used fallback, rather than requiring forDirectory to know about it. The same applies to the touch(directory) calls, which do nothing for a clone.
| const canonical = { id: "proj_repo", worktree: "/srv/repo" } as Project | ||
| const chosen = "/srv/repo-copy" | ||
|
|
||
| expect(resolveStartProject(chosen, () => canonical, [canonical], undefined)).toEqual({ |
There was a problem hiding this comment.
This stubs forDirectory to return the canonical project for /srv/repo-copy, but the real forDirectory returns undefined for a sibling clone. So the test passes on a path production never takes (packages/app/AGENTS.md: build inputs the way production builds them). A test that uses the real lookup, or a project list shaped like the server's, would have caught that the new-session draft still opens in the canonical folder.
| return { ...fields, status: "ready", server: entry.key, project: findProject(entry, target.directory) } | ||
| const project = findProject(entry, target.directory) | ||
|
|
||
| // With no used projects at all the directory cannot belong to this server; a sibling clone of a known one can. |
There was a problem hiding this comment.
This keeps any directory that matches no used project, as long as the server has at least one used project, not only clones of a used project. Regression: with the selection on project B, if B is removed from the used projects while A stays, the base clears the directory, but here the selection stays on B's path. The sessions list then stays filtered to a project that is no longer listed (I checked with a quick transition test: usedProjects [A, B] → [A] keeps directory: B). The existing 'clears it only once the server lists projects' test only passes because its server has no used projects at all. The machine needs to know that the directory resolves to a used project id (e.g. carry the project id with the selection), rather than keeping every unmatched directory.
|
All three points addressed in
Verified with the issue's two-clone setup against a source server and source web UI. Base saved selection and new-session footer: Gates: focused 21/21, package unit 2776/0, |
There was a problem hiding this comment.
The new commit fixes the rest of #64644, and it addresses all three earlier points.
I re-ran the issue's Playwright reproduction against the server and web app from source:
- The saved Home selection stays on
…/repo-copyafter adding it and after a reload. It now also stores the project id. - New session from Home opens the draft in
…/repo-copy. The footer shows it, and all the draft's API requests uselocation[directory]=…/repo-copy. On the base, both pointed at…/repo. - With
repo-copyselected, Home's sessions list shows sessions from both clones. I created one empty session in each to check. - The removed-project case is now cleared, and the new machine test covers it.
All 74 tests under src/home and src/shell/layout pass, and tsc -b in packages/app is clean.
Public API: the only change is an optional projectID field in the saved Home selection (layout.home.selection, the app's localStorage layout). Older saved data still loads, so it is backwards compatible. Nothing else outside the app changes.
I found nothing new that should block a merge.




Issue for this PR
Closes #64644
Type of change
What does this PR do?
Home replaced a chosen sibling clone with the project's canonical checkout. The selection changed on add, cleared on reload, and new sessions opened in the canonical folder. The chosen directory now survives add, restore, and new-session creation, while the server's project id still carries identity and worktree inventory.
How did you verify your code works?
bun run check35/35, package typecheck clean, oxlint clean on changed files.Screenshots / recordings
No layout or paint change; only the selected directory value changes. The three tests above cover the behavior.
Checklist
Added by the opencode bot (AI-generated).
Related: #55351