fix(app): prefill new agent cwd with main repo for worktrees

This commit is contained in:
Mohamed Boudra
2026-02-18 20:35:49 +07:00
parent e22f183bb2
commit e8c4ae2024
2 changed files with 36 additions and 1 deletions
+24 -1
View File
@@ -32,11 +32,34 @@ export function resolveSelectedAgentForNewAgent(input: {
);
}
function inferMainRepoRootFromPaseoWorktreePath(cwd: string): string | null {
const normalizedPath = cwd.replace(/\\/g, "/");
const marker = "/.paseo/worktrees";
const markerIndex = normalizedPath.indexOf(marker);
if (markerIndex <= 0) {
return null;
}
const markerEnd = markerIndex + marker.length;
const nextChar = normalizedPath[markerEnd];
if (nextChar && nextChar !== "/") {
return null;
}
const inferred = cwd.slice(0, markerIndex).replace(/[\\/]+$/, "");
return inferred.trim() ? inferred : null;
}
export function resolveNewAgentWorkingDir(
cwd: string,
checkout: CheckoutStatusPayload | null
): string {
return (checkout?.isPaseoOwnedWorktree ? checkout.mainRepoRoot : null) ?? cwd;
const explicitMainRepoRoot = checkout?.isPaseoOwnedWorktree
? checkout.mainRepoRoot?.trim() || null
: null;
if (explicitMainRepoRoot) {
return explicitMainRepoRoot;
}
return inferMainRepoRootFromPaseoWorktreePath(cwd) ?? cwd;
}
export function buildNewAgentRoute(