@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
32 lines • 1.71 kB
JavaScript
import { resolvePath } from "../utils/paths.js";
import { resolveMovedPath } from "./extensions/builtin/moved-path-guard/resolve.js";
import { readRepositoryIdentity } from "./repository-identity.js";
import { classifySessionRepository, readSessionCwd, rebindSessionFile } from "./session-rebind.js";
async function sessionCwdOf(sessionPath) {
try {
return await readSessionCwd(sessionPath);
}
catch (error) {
if (error instanceof Error)
return undefined;
throw error;
}
}
/**
* Where a session picked for resuming should be opened from. A session of the current repository
* recorded at another path is offered the in-place rebind; declining, another repository, or the
* current directory's own session open the picked file unchanged. Rebind failures propagate
* (`SessionHeldError` names the process still holding the session).
*/
export async function resolveResumeTarget(choice) {
const unchanged = { path: choice.sessionPath, rebound: false };
const sessionCwd = await sessionCwdOf(choice.sessionPath);
// A session whose cwd the OmO desktop moved here is this directory's own session, not one to rebind (senpi#2990).
if (sessionCwd === undefined || resolvePath(resolveMovedPath(sessionCwd)) === resolvePath(choice.cwd))
return unchanged;
const match = await classifySessionRepository(choice.sessionPath, sessionCwd, choice.cwd, choice.readIdentity ?? readRepositoryIdentity);
if (match !== "same" || !(await choice.confirm(sessionCwd)))
return unchanged;
return { path: await rebindSessionFile(choice.sessionPath, choice.cwd, choice.sessionDir), rebound: true };
}
//# sourceMappingURL=resume-target.js.map