fix(maestro): fast-forward spawn prefers the focused session's project
N picked the globally freshest project by git-mtime, ignoring the session the operator was actually on. Plain n's spawn form already seeds from the focused session (spawnSimilarProjectSeed); fast-forward now matches that, falling back to recency only when nothing is focused.
This commit is contained in:
@@ -47,6 +47,30 @@ describe("resolveFastForward (#67)", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("prefers the focused session's project over the freshest one", () => {
|
||||
const projects = [
|
||||
project({ path: "/repos/fresh", name: "fresh", last_command: "claude" }),
|
||||
project({
|
||||
path: "/repos/current",
|
||||
name: "current",
|
||||
last_activity: "2020-01-01T00:00:00Z",
|
||||
last_command: "zsh",
|
||||
}),
|
||||
];
|
||||
const res = resolveFastForward(projects, presets, "n", "/repos/current");
|
||||
expect(res.project?.path).toBe("/repos/current");
|
||||
expect(res.command).toBe("zsh");
|
||||
});
|
||||
|
||||
it("falls back to the freshest project when the focused cwd is unknown", () => {
|
||||
const projects = [
|
||||
project({ path: "/repos/old", name: "old", last_activity: "2020-01-01T00:00:00Z" }),
|
||||
project({ path: "/repos/fresh", name: "fresh" }),
|
||||
];
|
||||
const res = resolveFastForward(projects, presets, "n", "/repos/gone");
|
||||
expect(res.project?.path).toBe("/repos/fresh");
|
||||
});
|
||||
|
||||
it("falls back to the first non-custom preset when there is no last command", () => {
|
||||
const res = resolveFastForward([project({ last_command: undefined })], presets, "n");
|
||||
expect(res.command).toBe("claude");
|
||||
|
||||
@@ -13,15 +13,20 @@ export interface FastForwardResolution {
|
||||
name?: string;
|
||||
}
|
||||
|
||||
/** The defaults: most recent project (fresh-first, same ordering the picker
|
||||
* shows), its last command falling back to the first non-custom preset, and
|
||||
* a freshly generated name when the daemon supplied one. */
|
||||
/** The defaults: the currently focused session's project when it's still a
|
||||
* known project, else the most recent one (fresh-first, same ordering the
|
||||
* picker shows) — so `N` lands where the operator currently is, matching
|
||||
* what plain `n` seeds from `spawnSimilarProjectSeed`. Its last command
|
||||
* falls back to the first non-custom preset, and the name is freshly
|
||||
* generated when the daemon supplied one. */
|
||||
export function resolveFastForward(
|
||||
projects: Project[],
|
||||
presets: SpawnPreset[],
|
||||
name?: string,
|
||||
focusedCwd?: string,
|
||||
): FastForwardResolution {
|
||||
const project = sortProjects(projects, new Date())[0];
|
||||
const project =
|
||||
projects.find((p) => p.path === focusedCwd) ?? sortProjects(projects, new Date())[0];
|
||||
const lastCommand = project?.last_command?.trim();
|
||||
const command =
|
||||
lastCommand || presets.find((p) => p.command !== "")?.command || undefined;
|
||||
|
||||
+18
-3
@@ -257,13 +257,28 @@ function requestOpenSpawn(): void {
|
||||
// beside it is the point.
|
||||
// The session you were last on preselects its project: `n` then Enter spawns
|
||||
// another session there without touching the picker.
|
||||
const focused = mv?.focusedSessionId() ?? null;
|
||||
const current = focused ? store.snapshot().sessions.get(focused) : undefined;
|
||||
const current = focusedSession();
|
||||
openSpawnModal({
|
||||
seed: current ? spawnSimilarProjectSeed(current) : undefined,
|
||||
onSuccess: (session) => mountSpawned(session, { newTab: true }),
|
||||
});
|
||||
}
|
||||
|
||||
/** The session the operator was last on, if any. Shared by the plain spawn
|
||||
* modal seed and fast-forward's project pick: both should land on "where I
|
||||
* currently am". */
|
||||
function focusedSession(): Session | undefined {
|
||||
const focused = mv?.focusedSessionId() ?? null;
|
||||
return focused ? store.snapshot().sessions.get(focused) : undefined;
|
||||
}
|
||||
|
||||
/** The focused session's project — its base repo for a worktree session, its
|
||||
* cwd otherwise (same rule as spawnSimilarProjectSeed). */
|
||||
function focusedProjectCwd(): string | undefined {
|
||||
const s = focusedSession();
|
||||
if (!s) return undefined;
|
||||
return s.worktree ? s.worktree.base_repo : s.cwd;
|
||||
}
|
||||
document.addEventListener(OPEN_SPAWN_EVENT, () => requestOpenSpawn());
|
||||
document.addEventListener(SPAWN_SIMILAR_EVENT, (ev) => {
|
||||
const s = (ev as CustomEvent<Session>).detail;
|
||||
@@ -298,7 +313,7 @@ async function requestFastForward(): Promise<void> {
|
||||
} catch {
|
||||
/* keep fallbacks */
|
||||
}
|
||||
const resolved = resolveFastForward(discovered, presets, name);
|
||||
const resolved = resolveFastForward(discovered, presets, name, focusedProjectCwd());
|
||||
const req = buildFastForwardRequest(resolved);
|
||||
if (req) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user