repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix(os-notifier): retain prompt across retries

6902f89092c0845bddf8ed201276bae449b50b85

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (4)

docs/super/specs/2026-07-12-os-notifier-design.md

Modified
82 82 Control characters are removed from all dynamic text.
83 83 Arguments are passed without shell interpolation.
84 84 Prompt and error text remain bounded so OS notification bodies cannot grow without limit.
85 +The accepted starting prompt is retained in memory as fallback when a retry's final low-level event omits user messages.
86 87 ## Native Delivery
132 133 Tests cover:
134 -- outcome, urgency, sanitization, bounds, and rich metadata formatting
135 +- outcome, urgency, sanitization, bounds, rich metadata formatting, and prompt retention across retries
135 136 - Linux, macOS, and Windows command arguments without shell interpolation
136 137 - native backend choice and Kitty/generic OSC fallback choice
137 138 - direct interactive TUI eligibility

extensions/os-notifier/README.md

Modified
58 58 ## Content
60 60 Notifications include outcome, duration, project, Git branch, session name, model, bounded user prompt, and bounded failure detail.
61 +The accepted starting prompt remains available when a retry's final event omits user messages.
61 62 Dynamic text is sanitized and passed without shell interpolation.
63 64 Focus tracking uses DECSET `?1004`, shared through `globalThis` and reference-counted.

extensions/os-notifier/__tests__/harness.test.ts

Modified
218 218 expect(notification.message).toContain("…");
221 + it("retains the accepted prompt when a final retry event has no user message", () => {
222 + const notification = agentDoneNotification(
223 + { messages: [{ role: "assistant", stopReason: "stop" }] },
224 + { prompt: "original interactive prompt" },
225 + );
226 + expect(notification.message).toContain("↳ original interactive prompt");
227 + });
221 229 it("classifies aborted runs as warnings", () => {
222 230 expect(
223 231 agentDoneNotification(

extensions/os-notifier/index.ts

Modified
126 126 durationMs?: number;
127 127 branch?: string;
128 128 sessionName?: string;
129 + prompt?: string;
130 131 ): AgentDoneNotification {
131 132 const messages = Array.isArray(event.messages) ? event.messages : [];
142 143 compact(meta.sessionName),
143 144 model,
144 145 ].filter(Boolean);
145 - const prompt = promptSnippet(messages);
146 + const prompt = promptSnippet(messages) || compact(meta.prompt, PROMPT_LIMIT);
147 148 for (let i = messages.length - 1; i >= 0; i--) {
148 149 const message = messages[i] as
373 374 export default function (pi: ExtensionAPI) {
374 375 const eligibility = new TurnEligibility();
375 376 let agentStartedAt: number | undefined;
377 + let candidatePrompt: string | undefined;
378 + let acceptedPrompt: string | undefined;
376 379 let lastAgentEnd: { messages?: unknown[] } | undefined;
377 380 let focusAttached = false;
386 389 pi.on("input", async (event) => {
387 390 eligibility.input(event.source, event.streamingBehavior);
391 + if (event.streamingBehavior === undefined) {
392 + candidatePrompt = event.source === "interactive" ? event.text : undefined;
390 396 pi.on("before_agent_start", async () => {
391 397 eligibility.prepare();
398 + acceptedPrompt = candidatePrompt;
399 + candidatePrompt = undefined;
394 402 pi.on("agent_start", async (_event, ctx) => {
417 425 : Date.now() - agentStartedAt,
418 426 branch: currentGitBranch(ctx.cwd),
419 427 sessionName: pi.getSessionName(),
428 + prompt: acceptedPrompt,
421 430 void deliverNative(
422 431 nativeCommand(
434 443 agentStartedAt = undefined;
444 + candidatePrompt = undefined;
445 + acceptedPrompt = undefined;
435 446 lastAgentEnd = undefined;
438 449 pi.on("session_shutdown", async () => {
439 450 eligibility.clear();
440 451 agentStartedAt = undefined;
452 + candidatePrompt = undefined;
453 + acceptedPrompt = undefined;
441 454 lastAgentEnd = undefined;
442 455 if (focusAttached) {
443 456 focus.detach();