// "Spawn similar" (#28): the seed a cloned session hands to the spawn modal. // Pure — the caller owns opening the dialog. import type { SpawnFormSeed } from "./spawnForm.js"; import type { Session } from "./types.js"; /** Clone a session into form 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): SpawnFormSeed { const wt = s.worktree ?? null; return { command: s.command, cwd: wt ? wt.base_repo : s.cwd, worktreeEnabled: wt != null, cwdRawVisible: false, }; } /** The project half of a clone: the session's repository, nothing else. * * The plain spawn modal opens on this so the picker is already parked on the * project you were last looking at — one Enter spawns there — while the * command, worktree decision and name stay at the form's own defaults. Same * base-repository rule as `spawnSimilarSeed`. */ export function spawnSimilarProjectSeed(s: Session): SpawnFormSeed { const wt = s.worktree ?? null; return { cwd: wt ? wt.base_repo : s.cwd, cwdRawVisible: false, }; }