the runtime your coding agents live on
Rust agentagent-orchestrationaiai-agentsclaude-codeclicodexcoding-agentsdeveloper-toolsdevtoolsmultiplexerrustterminalterminal-multiplexerterminal-uitmuxtuiworkspace-manager
fix(pi): restrict state reporting to tui sessions (#2159)
Rhys5eab32da81b4
diff --git a/src/integration/assets/herdr-agent-state.test.ts b/src/integration/assets/herdr-agent-state.test.tsindex f54332ce2..94081e6d5 100644--- a/src/integration/assets/herdr-agent-state.test.ts+++ b/src/integration/assets/herdr-agent-state.test.ts@@ -171,6 +171,7 @@ for (const integration of integrations) {{ reason: "startup" },{hasUI: true,+ mode: "tui",isIdle: () => true,sessionManager: {getSessionFile: () => undefined,@@ -197,6 +198,7 @@ for (const integration of integrations) {{ reason: "reload" },{hasUI: true,+ mode: "tui",isIdle: () => false,sessionManager: {getSessionFile: () => undefined,@@ -268,6 +270,25 @@ test("Pi reports idle only after the agent settles", async () => {expect(requestStates(requests)).toEqual(["idle", "working", "idle"]);});+test("Pi ignores RPC sessions even when UI APIs are available", async () => {+ const requests = await startRecordingServer("pi-rpc");+ const { handlers, pi } = createExtensionHarness();+ const { default: install } = await importFresh("./pi/herdr-agent-state.ts");+ install(pi);++ const context = {+ ...piContext(() => true),+ hasUI: true,+ mode: "rpc",+ };+ await handlers.get("session_start")?.({ reason: "startup" }, context);+ handlers.get("agent_start")?.({}, context);+ handlers.get("agent_settled")?.({}, context);+ await Bun.sleep(25);++ expect(requests).toEqual([]);+});+test("Pi settlement preserves explicit blocked-state precedence", async () => {const requests = await startRecordingServer("pi-settled-blocked");const { eventHandlers, handlers, pi } = createExtensionHarness();@@ -307,6 +328,7 @@ test("Pi reports the session replacement source", async () => {{ reason: "new" },{hasUI: true,+ mode: "tui",isIdle: () => true,sessionManager: {getSessionFile: () => "/tmp/pi-new.jsonl",@@ -370,6 +392,7 @@ test("Pi waits for a replacement session report before publishing state", async{ reason: "new" },{hasUI: true,+ mode: "tui",isIdle: () => false,sessionManager: {getSessionFile: () => "/tmp/pi-new.jsonl",@@ -489,6 +512,7 @@ test("Pi retries working state after an unanswered socket attempt", async () =>{ reason: "startup" },{hasUI: true,+ mode: "tui",isIdle: () => false,sessionManager: {getSessionFile: () => undefined,@@ -524,6 +548,7 @@ function completionHandlers(handlers: Map<string, Handler>): string[] {function piContext(isIdle: () => boolean) {return {hasUI: true,+ mode: "tui",isIdle,sessionManager: {getSessionFile: () => undefined,diff --git a/src/integration/assets/pi/herdr-agent-state.ts b/src/integration/assets/pi/herdr-agent-state.tsindex 2e79c7c62..67bc41889 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=7+// HERDR_INTEGRATION_VERSION=8// @ts-nocheckimport net from "node:net";@@ -223,7 +223,9 @@ export default function (pi) {});pi.on("session_start", async (event, ctx) => {- if (ctx?.hasUI !== true) {+ // TUI only: RPC/JSON/print modes are headless (no PTY herdr can display),+ // and RPC still reports hasUI=true, so mode is the reliable gate.+ if (ctx?.mode !== "tui") {return;}rootSession = true;diff --git a/src/integration/mod.rs b/src/integration/mod.rsindex 9fc1886e1..8be54c840 100644--- a/src/integration/mod.rs+++ b/src/integration/mod.rs@@ -23,7 +23,7 @@ pub(crate) use types::{IntegrationRecommendation, IntegrationStatus, Integrationconst 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 = 7;+const PI_INTEGRATION_VERSION: u32 = 8;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 = 8;diff --git a/src/integration/tests.rs b/src/integration/tests.rsindex 7abf7be27..6827dae71 100644--- a/src/integration/tests.rs+++ b/src/integration/tests.rs@@ -2665,7 +2665,7 @@ fn bundled_integration_asset_versions_match_expected_versions() {fn bundled_integration_assets_report_session_refs() {assert!(PI_EXTENSION_ASSET.contains("agent_session_path"));assert!(PI_EXTENSION_ASSET.contains("agent_session_id"));- assert!(PI_EXTENSION_ASSET.contains("ctx?.hasUI !== true"));+ assert!(PI_EXTENSION_ASSET.contains("ctx?.mode !== \"tui\""));assert!(PI_EXTENSION_ASSET.contains("pane.report_agent_session"));assert!(PI_EXTENSION_ASSET.contains("pane.report_agent\""));assert!(PI_EXTENSION_ASSET.contains("pi.on(\"agent_start\""));diff --git a/tests/cli/sessions.rs b/tests/cli/sessions.rsindex ae7b83061..78b046809 100644--- a/tests/cli/sessions.rs+++ b/tests/cli/sessions.rs@@ -293,7 +293,7 @@ fn integration_commands_run_locally_when_server_is_missing() {.unwrap();assert_eq!(integration_status.status.code(), Some(0));let status_stdout = String::from_utf8_lossy(&integration_status.stdout);- assert!(status_stdout.contains("pi: current (v7)"));+ assert!(status_stdout.contains("pi: current (v8)"));assert!(status_stdout.contains("claude: not installed"));let integration_uninstall = Command::new(env!("CARGO_BIN_EXE_herdr"))