UNPKG

@code-yeongyu/senpi

Version:

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

33 lines • 1.54 kB
import { parseRepositoryIdentity, REPOSITORY_IDENTITY_ENTRY_TYPE, readRepositoryIdentity, sameRepositoryIdentity, } from "../../repository-identity.js"; // Records which git repository a session's cwd belongs to, so a session whose repository was later // moved can still be recognised as the same project from the new path (senpi#2181). export function createRepositoryIdentityExtension(run) { return (pi) => { let generation = 0; pi.on("session_start", async (_event, ctx) => { const current = ++generation; if (ctx.sessionManager.getSessionFile() === undefined) return; const identity = await readRepositoryIdentity(ctx.cwd, run); if (current !== generation || identity === undefined) return; if (sameRepositoryIdentity(latestRecordedIdentity(ctx.sessionManager), identity)) return; pi.appendEntry(REPOSITORY_IDENTITY_ENTRY_TYPE, identity, { startupBookkeeping: true }); }); pi.on("session_shutdown", () => { generation++; }); }; } function latestRecordedIdentity(sessionManager) { let recorded; for (const entry of sessionManager.getEntries()) { if (entry.type === "custom" && entry.customType === REPOSITORY_IDENTITY_ENTRY_TYPE) { recorded = parseRepositoryIdentity(entry.data) ?? recorded; } } return recorded; } export default createRepositoryIdentityExtension(); //# sourceMappingURL=repository-identity.js.map