From a5448b4002f28302b2972500dbb8fafda56ae7f5 Mon Sep 17 00:00:00 2001 From: GRayHook Date: Wed, 17 Jun 2026 12:46:44 +0700 Subject: [PATCH] =?UTF-8?q?Phase=2010:=20restore=20session=20state=20on=20?= =?UTF-8?q?session=5Ftree=20for=20branch=20switch=20=E2=80=94=20SPEC=20?= =?UTF-8?q?=C2=A76.3,=20=C2=A711.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract restoreSessionState for reload/resume/startup and reuse on session_tree so /tree branch navigation reloads persisted state or rescans like session_start. Co-authored-by: Cursor --- src/index.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 0b46f19..2eb9c26 100644 --- a/src/index.ts +++ b/src/index.ts @@ -64,6 +64,17 @@ export default function skillReinject(pi: ExtensionAPI): void { }); } + function restoreSessionState(ctx: ExtensionContext): void { + detectAndCachePiAutoCompact(pi, runtime); + const settings = readSettings(ctx); + const branch = ctx.sessionManager.getBranch(); + const loaded = loadStateFromBranch(branch); + applyExtensionState(state, loaded ?? createInitialState()); + if (!loaded) { + rescanSkillsFromBranch(state, branch, ctx.cwd, registeredSkills, settings.trackReadPaths); + } + } + function handleSessionCompact(event: SessionCompactEvent, ctx: ExtensionContext): void { const settings = readSettings(ctx); const shouldReinject = consumeCompactionOnSessionCompact( @@ -99,14 +110,11 @@ export default function skillReinject(pi: ExtensionAPI): void { } pi.on("session_start", async (_event, ctx) => { - detectAndCachePiAutoCompact(pi, runtime); - const settings = readSettings(ctx); - const branch = ctx.sessionManager.getBranch(); - const loaded = loadStateFromBranch(branch); - applyExtensionState(state, loaded ?? createInitialState()); - if (!loaded) { - rescanSkillsFromBranch(state, branch, ctx.cwd, registeredSkills, settings.trackReadPaths); - } + restoreSessionState(ctx); + }); + + pi.on("session_tree", async (_event, ctx) => { + restoreSessionState(ctx); }); pi.on("session_before_compact", async () => {