From 1a690f921f2acdb7843f09ab01a0e074d960cf9a Mon Sep 17 00:00:00 2001 From: GRayHook Date: Wed, 17 Jun 2026 12:40:33 +0700 Subject: [PATCH] =?UTF-8?q?Phase=2010:=20load=20persisted=20state=20and=20?= =?UTF-8?q?settings=20on=20session=5Fstart=20=E2=80=94=20SPEC=20=C2=A75.1,?= =?UTF-8?q?=20=C2=A76.3,=20=C2=A716.4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Restore skill-reinject:state from branch on startup/resume, read merged settings, and detect pi-auto-compact; reset to initial state when no entry exists. Co-authored-by: Cursor --- src/index.ts | 7 ++++++- src/state.ts | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 7ec42f5..aabd442 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,8 +24,10 @@ import { import { readSettings } from "./settings.js"; import { findRegisteredSkillByName, resolveRegisteredSkills } from "./skills-registry.js"; import { + applyExtensionState, createInitialState, createRuntimeFlags, + loadStateFromBranch, saveState, trackSkill, type TrackSkillInput, @@ -95,8 +97,11 @@ export default function skillReinject(pi: ExtensionAPI): void { persistState(); } - pi.on("session_start", async () => { + pi.on("session_start", async (_event, ctx) => { detectAndCachePiAutoCompact(pi, runtime); + readSettings(ctx); + const loaded = loadStateFromBranch(ctx.sessionManager.getBranch()); + applyExtensionState(state, loaded ?? createInitialState()); }); pi.on("session_before_compact", async () => { diff --git a/src/state.ts b/src/state.ts index e38fd26..fe167ee 100644 --- a/src/state.ts +++ b/src/state.ts @@ -82,6 +82,14 @@ export function createInitialState(): ExtensionState { }; } +/** Copy persisted fields into live session state (SPEC ยง6.3). */ +export function applyExtensionState(target: ExtensionState, loaded: ExtensionState): void { + target.sessionOverride = loaded.sessionOverride; + target.skills = loaded.skills; + target.lastCompactionSource = loaded.lastCompactionSource; + target.pendingReinject = loaded.pendingReinject; +} + export function createRuntimeFlags(): RuntimeFlags { return { autoCompactDetected: false,