diff --git a/src/integration/assets/pi/herdr-agent-state.ts b/src/integration/assets/pi/herdr-agent-state.ts index 0e620f1f74d..f9adf5bfdcf 100644 --- a/src/integration/assets/pi/herdr-agent-state.ts +++ b/src/integration/assets/pi/herdr-agent-state.ts @@ -2,7 +2,7 @@ // managed by herdr; reinstalling or updating the integration overwrites this file. // add custom hooks/plugins beside this file instead of editing it. // HERDR_INTEGRATION_ID=pi -// HERDR_INTEGRATION_VERSION=2 +// HERDR_INTEGRATION_VERSION=3 // @ts-nocheck import { createConnection } from "node:net"; @@ -73,6 +73,18 @@ function parseDurationEnv(name: string, fallback: number): number { return parsed; } +function flushSessionBeforeReport(ctx: any): void { + try { + // Pi normally defers creating a session file until the first assistant + // response. External resume needs the initial model/thinking state on disk + // before we advertise the path to Herdr. Optional for older Pi versions. + ctx?.sessionManager?.flush?.(); + } catch { + // Session reporting must remain best-effort; an unsupported or failed flush + // must not break Pi startup or Herdr state reporting. + } +} + function updateSessionRef(ctx: any): void { try { const file = ctx?.sessionManager?.getSessionFile?.(); @@ -251,6 +263,7 @@ export default function (pi) { } pi.on("session_start", (_event, ctx) => { + flushSessionBeforeReport(ctx); updateSessionRef(ctx); publishState(true); }); diff --git a/src/integration/mod.rs b/src/integration/mod.rs index 31197318577..c389c840a7f 100644 --- a/src/integration/mod.rs +++ b/src/integration/mod.rs @@ -12,7 +12,7 @@ use crate::layout::PaneId; pub(crate) const HERDR_PANE_ID_ENV_VAR: &str = "HERDR_PANE_ID"; const PI_EXTENSION_INSTALL_NAME: &str = "herdr-agent-state.ts"; const PI_EXTENSION_ASSET: &str = include_str!("assets/pi/herdr-agent-state.ts"); -const PI_INTEGRATION_VERSION: u32 = 2; +const PI_INTEGRATION_VERSION: u32 = 3; const OMP_EXTENSION_INSTALL_NAME: &str = "herdr-omp-agent-state.ts"; const OMP_EXTENSION_ASSET: &str = include_str!("assets/omp/herdr-agent-state.ts"); const OMP_INTEGRATION_VERSION: u32 = 2; @@ -2113,6 +2113,8 @@ mod tests { assert_eq!(path, ext_dir.join(PI_EXTENSION_INSTALL_NAME)); assert_eq!(content, PI_EXTENSION_ASSET); + assert!(content.contains("sessionManager?.flush?.()")); + assert!(content.contains("HERDR_INTEGRATION_VERSION=3")); std::env::remove_var("HOME"); let _ = fs::remove_dir_all(base);