mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
fix(app): prefill new agent cwd with main repo for worktrees
This commit is contained in:
@@ -26,6 +26,18 @@ describe("resolveNewAgentWorkingDir", () => {
|
||||
expect(resolveNewAgentWorkingDir("/repo/path", null)).toBe("/repo/path");
|
||||
});
|
||||
|
||||
it("falls back to repo root when checkout metadata is unavailable", () => {
|
||||
expect(resolveNewAgentWorkingDir("/repo/.paseo/worktrees/feature", null)).toBe(
|
||||
"/repo"
|
||||
);
|
||||
});
|
||||
|
||||
it("supports windows-style paseo worktree paths without checkout metadata", () => {
|
||||
expect(
|
||||
resolveNewAgentWorkingDir("C:\\Users\\me\\repo\\.paseo\\worktrees\\feature", null)
|
||||
).toBe("C:\\Users\\me\\repo");
|
||||
});
|
||||
|
||||
it("returns the main repo root for paseo-owned worktrees", () => {
|
||||
const checkout = {
|
||||
isPaseoOwnedWorktree: true,
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user