From e389f61c7ca796dcb96df0097e7a675f78891afc Mon Sep 17 00:00:00 2001 From: jiman Date: Fri, 13 Nov 2026 15:44:42 +0900 Subject: [PATCH] fix(omp): restore ADHD mode after /new, /resume and /fork OMP emits session_start once per process. Opening a session with /new, /resume or /fork emits session_switch, which the extension ignored, so the new session never got the ruleset. Restore state on session_switch the same way as on session_start. Pi does not emit session_switch. The OMP smoke test now opens a new session and checks for the ruleset. Fixes #291 --- extensions/i-have-adhd.ts | 13 +++++++++++++ scripts/check_pi_extension.py | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/extensions/i-have-adhd.ts b/extensions/i-have-adhd.ts index cc73610a..aa6765aa 100644 --- a/extensions/i-have-adhd.ts +++ b/extensions/i-have-adhd.ts @@ -39,6 +39,13 @@ type AdhdConfig = { hideStatus?: boolean; }; +type OmpSessionSwitchAPI = { + on( + event: "session_switch", + handler: (event: unknown, ctx: ExtensionContext) => Promise, + ): unknown; +}; + function loadConfig(): AdhdConfig { try { return JSON.parse( @@ -235,6 +242,12 @@ export default function iHaveAdhdExtension(pi: ExtensionAPI) { }); pi.on("session_start", async (_event, ctx) => restoreState(ctx)); + // OMP emits session_switch instead of session_start for /new, /resume and + // /fork. Pi never emits it, and Pi's types do not declare it. + (pi as unknown as OmpSessionSwitchAPI).on( + "session_switch", + async (_event, ctx) => restoreState(ctx), + ); pi.on("session_tree", async (_event, ctx) => restoreState(ctx)); pi.on("session_compact", async (_event, ctx) => syncContext(ctx)); } diff --git a/scripts/check_pi_extension.py b/scripts/check_pi_extension.py index 1cd3fa6c..8b39e69c 100644 --- a/scripts/check_pi_extension.py +++ b/scripts/check_pi_extension.py @@ -295,6 +295,18 @@ def main() -> None: "ADHD ON" in (text or "") for text in status_texts(startup_events) ) + + new_session, _ = client.request("new-session", {"type": "new_session"}) + assert new_session["success"] is True + messages, _ = client.request( + "messages-new-session", + {"type": "get_messages"}, + ) + assert sum( + 1 + for message in messages["data"]["messages"] + if message.get("customType") == "i-have-adhd-rules" + ) == 1, "Rules were not injected into the session opened by /new" finally: client.close()