mirror of
https://github.com/getpaseo/paseo.git
synced 2026-08-14 12:23:16 +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");
|
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", () => {
|
it("returns the main repo root for paseo-owned worktrees", () => {
|
||||||
const checkout = {
|
const checkout = {
|
||||||
isPaseoOwnedWorktree: true,
|
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(
|
export function resolveNewAgentWorkingDir(
|
||||||
cwd: string,
|
cwd: string,
|
||||||
checkout: CheckoutStatusPayload | null
|
checkout: CheckoutStatusPayload | null
|
||||||
): string {
|
): 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(
|
export function buildNewAgentRoute(
|
||||||
|
|||||||
Reference in New Issue
Block a user