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()