Spawn similar dropped the session's cwd into the free-text directory hatch, so the project picker showed nothing selected. For a worktree session that cwd was the daemon-made checkout, and the worktree toggle defaulted on, so the clone asked for a worktree of a worktree. It now seeds the picker: the cloned project's box selected, the same worktree decision, base repo plus '+ new' when the source had a worktree. A seeded path that matches no project falls back to the raw input showing that path instead of an empty picker.
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
// "Spawn similar" (#28): the seed a cloned session hands to a draft pane.
|
|
// Pure — the caller owns opening the pane.
|
|
|
|
import type { Draft } from "./layout.js";
|
|
import type { Session } from "./types.js";
|
|
|
|
/** Clone a session into draft values: same project, same command, same
|
|
* worktree decision, fresh name.
|
|
*
|
|
* A worktree session seeds its *base repository*, not the checkout the daemon
|
|
* made for it: "similar" is another session of that project, and the daemon
|
|
* never adopts an existing worktree (docs/WORKTREES.md), so seeding the
|
|
* checkout would ask it to build a worktree out of a worktree. The picker
|
|
* then lands on that repository's box with "+ new" active.
|
|
*
|
|
* `cwdRawVisible: false` keeps the two-step project picker on screen with the
|
|
* cloned project selected, instead of dropping the path into the free-text
|
|
* escape hatch.
|
|
*
|
|
* The name is left out on purpose: a clone is a new session and takes its own
|
|
* generated handle. */
|
|
export function spawnSimilarSeed(s: Session): Partial<Draft> {
|
|
const wt = s.worktree ?? null;
|
|
return {
|
|
command: s.command,
|
|
cwd: wt ? wt.base_repo : s.cwd,
|
|
worktreeEnabled: wt != null,
|
|
cwdRawVisible: false,
|
|
};
|
|
}
|