repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix(os-notifier): attribute follow-ups to active run

b22ccc6f90cdd3f07ed0274a0c91cfc7a3088f90

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (5)

docs/super/plans/2026-07-12-os-notifier.md

Modified
107 107 expect(state.end()).toBe(false);
110 -Add a queued-follow-up test proving input arriving during an active run applies to the next `agent_start`, not the active run.
110 +Add a queued-follow-up test proving interactive input arriving during an active lifecycle makes that lifecycle eligible and does not leak into the next run.
112 112 - [ ] **Step 3: Add failing metadata tests**
133 133 - encode Windows PowerShell script as UTF-16LE Base64 for `-EncodedCommand`
134 134 - pass macOS title/body through `osascript` argv to avoid shell interpolation
135 135 - add `oscBackend(env)`
136 -- add minimal active/pending eligibility bookkeeping driven by `input`, `agent_start`, and `agent_end`
136 +- add minimal active/pending eligibility bookkeeping driven by `input`, `agent_start`, and `agent_end`; steering and follow-ups stay within the active lifecycle
137 137 - remove `notify:send`, `notify:ui`, startup probes, backend caching, and warning notifications
139 139 - [ ] **Step 6: Run extension tests**

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

Modified
31 31 - The terminal is unfocused when `agent_end` fires.
33 33 The extension records input origin in extension-instance memory because `agent_end` does not expose it.
34 -It tracks the active run separately from queued follow-up origins so later input cannot reclassify an active run.
34 +It tracks pending pre-start input separately from the active agent lifecycle.
35 +Pi drains steering and queued follow-ups inside that active lifecycle, so direct interactive input received while active makes that lifecycle eligible without leaking into the next run.
35 36 Pi dispatches extension events serially, so this is event-order bookkeeping rather than cross-thread synchronization.
36 37 State is cleared on completion and session shutdown.
37 38 Nothing is written to disk or session history.
39 -Interactive steering makes the active run eligible.
40 -Interactive queued follow-up input makes its later run eligible.
40 +Interactive steering and queued follow-up input make the active agent lifecycle eligible.
41 41 RPC, SDK, extension, JSON, and print activity never makes a run eligible.
43 43 Every eligible unfocused completion notifies, regardless of duration.
131 131 - native backend choice and Kitty/generic OSC fallback choice
132 132 - direct interactive TUI eligibility
133 133 - suppression for RPC, JSON, print, SDK-style, and extension input
134 -- active-run versus queued-follow-up origin bookkeeping
134 +- pending versus active-lifecycle input-origin bookkeeping
135 135 - focused-terminal suppression
136 136 - native success and native failure through a controlled fake executable on the current platform
137 137 - loading through the real Pi extension harness

extensions/os-notifier/README.md

Modified
32 32 - terminal unfocused at `agent_end`
34 34 RPC, JSON, print, SDK-driven, extension-driven, and subagent-style turns stay silent.
35 -Interactive steering makes its active run eligible.
36 -Queued follow-up origins remain associated with their later run.
35 +Interactive steering and queued follow-ups make their active agent lifecycle eligible.
37 36 Focused completions are discarded rather than deferred.
39 38 ## Native delivery

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

Modified
104 104 expect(state.end()).toBe(false);
107 - it("keeps queued follow-up origin separate from the active run", () => {
107 + it("attributes queued follow-up input to the active lifecycle without leaking", () => {
108 108 const state = new TurnEligibility();
109 109 state.input("extension");
110 110 state.start("tui");
111 111 state.input("interactive", "followUp");
112 - expect(state.end()).toBe(false);
113 - state.start("tui");
114 112 expect(state.end()).toBe(true);
114 + state.input("extension");
115 + state.start("tui");
116 + expect(state.end()).toBe(false);
117 119 it("interactive steering makes the active run eligible", () => {

extensions/os-notifier/index.ts

Modified
316 316 private active = false;
317 317 private current = false;
318 318 private pending = false;
319 - private readonly queued: boolean[] = [];
321 - input(source: InputSource, behavior?: StreamingBehavior): void {
320 + input(source: InputSource, _behavior?: StreamingBehavior): void {
322 321 const eligible = source === "interactive";
323 - if (behavior === "followUp") {
324 - this.queued.push(eligible);
325 - return;
326 - }
327 - if (behavior === "steer" && this.active) {
322 + if (this.active) {
328 323 this.current ||= eligible;
329 324 return;
334 329 start(mode: string): void {
335 330 this.active = true;
336 - const origin =
337 - this.queued.length > 0 ? (this.queued.shift() ?? false) : this.pending;
331 + this.current = mode === "tui" && this.pending;
338 332 this.pending = false;
339 - this.current = mode === "tui" && origin;
342 335 end(): boolean {
350 343 this.active = false;
351 344 this.current = false;
352 345 this.pending = false;
353 - this.queued.length = 0;