@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
33 lines • 1.62 kB
JavaScript
import { loadEntriesFromFileAsync } from "../session-manager.js";
import { pathExists } from "../tools/path-utils.js";
import { SESSION_MOVED, SESSION_MOVED_IN, sessionOwnership } from "./ownership.js";
import { REVOKED } from "./revoke.js";
/** What a session file's entries record for the move: nothing, its import, or its import and then a revoke. */
export function outcomeIn(entries, moveId) {
let outcome = "absent";
for (const entry of entries) {
if (entry.type !== "custom")
continue;
const data = entry.data;
if (data?.move_id !== moveId)
continue;
if (entry.customType === SESSION_MOVED_IN)
outcome = "moved_in";
else if (outcome === "moved_in" && entry.customType === SESSION_MOVED && data.reason === REVOKED)
outcome = "revoked";
}
return outcome;
}
/** One read of the file at a move's landing target: what it records for the move, and where that puts the session. */
export async function readLanding(target, moveId) {
if (!(await pathExists(target)))
return { outcome: "absent", file: "gone" };
const entries = await loadEntriesFromFileAsync(target);
const outcome = outcomeIn(entries, moveId);
const header = entries.find((entry) => entry.type === "session");
if (outcome === "absent" || header === undefined || !header.id || !header.cwd)
return { outcome, file: "gone" };
const ownership = sessionOwnership(entries);
return { outcome, file: { sessionPath: target, sessionId: header.id, cwd: header.cwd, ownership } };
}
//# sourceMappingURL=landed-file.js.map