From a7f9822fa005a5f93bdb4a85bed920b107461ff5 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Tue, 21 Apr 2026 12:34:09 +0100 Subject: [PATCH] feat(pi-turn-limit): add widget, /turn-limit command, and boundary confirmation - Live widget showing Turns: {current}/{max} - /turn-limit command to change max turns mid-session - Confirmation dialog at boundary turn (Yes resets counter, No aborts) - Widget visible on session reload and fresh start --- packages/pi-turn-limit/src/turn-limit.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/pi-turn-limit/src/turn-limit.ts b/packages/pi-turn-limit/src/turn-limit.ts index 97bfb72..f36a12e 100644 --- a/packages/pi-turn-limit/src/turn-limit.ts +++ b/packages/pi-turn-limit/src/turn-limit.ts @@ -36,12 +36,19 @@ export default function (pi: ExtensionAPI) { let turnCount = 0; let maxTurns = getMaxTurns(); + pi.on("session_start", async (event, ctx) => { + // On reload, show the widget immediately + if (event.reason === "reload" && ctx.hasUI) { + ctx.ui.setWidget("turn-limit", [`Turns: ${turnCount}/${maxTurns}`]); + } + }); + pi.on("agent_start", async (_event, ctx) => { // Reset counter for each new user prompt turnCount = 0; - // Clear widget on new session + // Show initial widget state on fresh session if (ctx.hasUI) { - ctx.ui.setWidget("turn-limit", undefined); + ctx.ui.setWidget("turn-limit", [`Turns: ${turnCount}/${maxTurns}`]); } });