UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

35 lines • 2.09 kB
/** * The one comparison the target's `prepare` and the `import` both make (senpi#6435): is this folder a checkout of the * repository the session recorded? Two paths deciding it apart would refuse a move at one step and take it at the next. */ import { resolvePath } from "../../utils/paths.js"; import { compareRepositoryIdentities, readRepositoryIdentity, } from "../repository-identity.js"; import { pathExists } from "../tools/path-utils.js"; export class MoveRefusedError extends Error { constructor(targetCwd, sourceCwd) { super(`${targetCwd} is not the same repository the session was recorded in${sourceCwd === undefined ? "" : ` (${sourceCwd})`}. Pick a checkout of the same repository, or copy the session into this folder instead.`); this.code = "move_repository_mismatch"; this.name = "MoveRefusedError"; } } /** * A folder that does not exist on this device. It has no repository identity either, but it is * told apart from a mismatch: only this device can say which, and the client words the two differently. */ class MoveTargetMissingError extends Error { constructor(targetCwd) { super(`${targetCwd} does not exist on this device. Clone the repository there, or pick a folder that holds it, then send the session again.`); this.code = "workspace_missing"; this.name = "MoveTargetMissingError"; } } /** `cwd` is resolved the way the import resolves it, so both steps read the identity of the same folder. */ export async function checkoutVerdict(cwd, repository, read = readRepositoryIdentity) { const folder = resolvePath(cwd); if (compareRepositoryIdentities(repository, await read(folder)) === "same") return "same"; return (await pathExists(folder)) ? "other" : "missing"; } /** The refusal for a folder that is not a checkout of the session's repository. */ export const checkoutRefusal = (verdict, targetCwd, sourceCwd) => verdict === "missing" ? new MoveTargetMissingError(targetCwd) : new MoveRefusedError(targetCwd, sourceCwd); //# sourceMappingURL=repository-check.js.map