repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix session startup races

1601903b5319889948d6c1e896333e244ad801ac

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (2)

+27 / −9 text lines

Diff layout

extensions/git-safe/index.ts

Modified

+19 / −8 text lines

6161export default function gitSafeExtension(pi: ExtensionAPI) {
6262 // Session-scoped spotlight markers
6363 const spotlightMarkers = createMarkers({ preamble: GIT_PREAMBLE });
64 let generation = 0;
6566 // ── session_start: recover tracked paths ─────────────────────────────
67 pi.on("session_start", async (_event, ctx) => {
68 const paths = await recoverTrackedPaths(ctx.cwd);
69 for (const p of paths) {
70 addTrackedPath(p);
71 }
72 if (paths.length > 0 && ctx.hasUI) {
73 ctx.ui.notify(`git-safe: recovered ${paths.length} tracked clone(s)`, "info");
74 }
68 pi.on("session_start", (_event, ctx) => {
69 const ticket = ++generation;
70 setTimeout(() => {
71 void (async () => {
72 const paths = await recoverTrackedPaths(ctx.cwd);
73 if (ticket !== generation) return;
74 for (const p of paths) {
75 addTrackedPath(p);
76 }
77 if (paths.length > 0 && ctx.hasUI) {
78 ctx.ui.notify(`git-safe: recovered ${paths.length} tracked clone(s)`, "info");
79 }
80 })();
81 }, 0);
82 });
84 pi.on("session_shutdown", async () => {
85 generation++;
7586 });
7788 // ── tool_result hook on "read": spotlight-wrap cloned content ────────

extensions/pulse/index.ts

Modified

+8 / −1 text lines

466466// ============================================================================
468468export default function (pi: ExtensionAPI) {
469 let generation = 0;
469470 const state: PulseState = {
470471 config: { documents: [] },
471472 cwd: "",
11691170 });
11711172 pi.on("session_start", async (_event, ctx) => {
1173 const ticket = ++generation;
11721174 stopConfigWatcher();
11731175 stopTimer();
11741176 state.cwd = getCwd(pi, ctx);
11851187 state.workspaceDirty = false;
11861188 state.maybeWorkspaceDirty = false;
11871189 state.lastMutationAt = 0;
1188 state.lastGitFingerprint = gitFingerprint(state.cwd);
1190 state.lastGitFingerprint = null;
1191 setTimeout(() => {
1192 if (ticket !== generation) return;
1193 state.lastGitFingerprint = gitFingerprint(state.cwd);
1194 }, 0);
11891195 state.isPaused = false;
11901196 restoreState(ctx);
11971203 });
11991205 pi.on("session_shutdown", async (_event, ctx) => {
1206 generation++;
12001207 stopConfigWatcher();
12011208 stopTimer();
12021209 });