repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix(os-notifier): confirm accepted interactive input

012635e0253f925b17ce376f7a8d14e8b5515d4c

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (5)

+40 / −7 text lines

Diff layout

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

Modified

+1 / −1 text lines

133133- encode Windows PowerShell script as UTF-16LE Base64 for `-EncodedCommand`
134134- pass macOS title/body through `osascript` argv to avoid shell interpolation
135135- add `oscBackend(env)`
136- add minimal active/pending eligibility bookkeeping driven by `input`, `agent_start`, and `agent_settled`; steering, retries, and follow-ups stay within the active lifecycle
136- add minimal candidate/prepared/active eligibility bookkeeping driven by `input`, `before_agent_start`, `agent_start`, and `agent_settled`; handled input cannot leak, while steering, retries, and follow-ups stay within the active lifecycle
137137- remove `notify:send`, `notify:ui`, startup probes, backend caching, and warning notifications
139139- [ ] **Step 6: Run extension tests**

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

Modified

+4 / −3 text lines

3131- The terminal is unfocused when `agent_settled` fires.
3333The extension records input origin in extension-instance memory because `agent_end` does not expose it.
34It tracks pending pre-start input separately from the active agent lifecycle.
35Pi 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.
34It records idle `input` as a candidate, then confirms it at `before_agent_start` only when Pi accepts the prompt.
35This prevents handled input from leaking eligibility into extension-triggered runs that start without an `input` event.
36Pi drains steering and queued follow-ups inside the active agent lifecycle, so direct interactive input received while active makes that lifecycle eligible without leaking into the next run.
3637Pi dispatches extension events serially, so this is event-order bookkeeping rather than cross-thread synchronization.
3738State is cleared on completion and session shutdown.
3839Nothing is written to disk or session history.
133134- native backend choice and Kitty/generic OSC fallback choice
134135- direct interactive TUI eligibility
135136- suppression for RPC, JSON, print, SDK-style, and extension input
136- pending versus active-lifecycle input-origin bookkeeping
137- candidate, accepted, and active-lifecycle input-origin bookkeeping
137138- focused-terminal suppression and no notification before `agent_settled`
138139- native success and native failure through a controlled fake executable on the current platform
139140- loading through the real Pi extension harness

extensions/os-notifier/README.md

Modified

+2 / −1 text lines

1818Hooks:
2020- `session_start` attaches terminal focus tracking in TUI mode.
21- `input` records direct interactive input origin.
21- `input` records candidate direct interactive input origin.
22- `before_agent_start` confirms accepted prompt input.
2223- `agent_start` starts duration measurement for the active lifecycle.
2324- `agent_end` records the latest low-level outcome.
2425- `agent_settled` sends the final eligible notification while unfocused.

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

Modified

+20 / −0 text lines

9292 it("allows direct interactive TUI runs only", () => {
9393 const state = new TurnEligibility();
9494 state.input("interactive");
95 state.prepare();
9596 state.start("tui");
9697 expect(state.settle()).toBe(true);
9899 state.input("rpc");
100 state.prepare();
99101 state.start("tui");
100102 expect(state.settle()).toBe(false);
102104 state.input("interactive");
105 state.prepare();
103106 state.start("rpc");
104107 state.input("interactive", "followUp");
105108 expect(state.settle()).toBe(false);
108111 it("attributes queued follow-up input to the active lifecycle without leaking", () => {
109112 const state = new TurnEligibility();
110113 state.input("extension");
114 state.prepare();
111115 state.start("tui");
112116 state.input("interactive", "followUp");
113117 expect(state.settle()).toBe(true);
115119 state.input("extension");
120 state.prepare();
116121 state.start("tui");
117122 expect(state.settle()).toBe(false);
118123 });
120125 it("interactive steering makes the active run eligible", () => {
121126 const state = new TurnEligibility();
122127 state.input("extension");
128 state.prepare();
123129 state.start("tui");
124130 state.input("interactive", "steer");
125131 expect(state.settle()).toBe(true);
128134 it("preserves eligibility across low-level retries until settlement", () => {
129135 const state = new TurnEligibility();
130136 state.input("interactive");
137 state.prepare();
131138 state.start("tui");
132139 state.start("tui");
133140 expect(state.settle()).toBe(true);
134141 });
143 it("does not consume handled interactive input for an extension-triggered run", () => {
144 const state = new TurnEligibility();
145 state.input("interactive");
146 state.start("tui");
147 expect(state.settle()).toBe(false);
148 });
135149});
137151describe("os-notifier payload", () => {
272286 text: "test notification",
273287 source,
274288 } as never);
289 await t.session.extensionRunner.emitBeforeAgentStart(
290 "test notification",
291 undefined,
292 "BASE",
293 {} as never,
294 );
275295 await t.session.extensionRunner.emit({ type: "agent_start" } as never);
276296 await t.session.extensionRunner.emit({
277297 type: "agent_end",

extensions/os-notifier/index.ts

Modified

+13 / −2 text lines

320320 private activeTui = false;
321321 private current = false;
322322 private pending = false;
323 private prepared = false;
324325 input(source: InputSource, _behavior?: StreamingBehavior): void {
325326 const eligible = source === "interactive";
330331 this.pending = eligible;
331332 }
334 prepare(): void {
335 this.prepared = this.pending;
336 this.pending = false;
337 }
333339 start(mode: string): void {
334340 if (this.active) return;
335341 this.active = true;
336342 this.activeTui = mode === "tui";
337 this.current = this.activeTui && this.pending;
338 this.pending = false;
343 this.current = this.activeTui && this.prepared;
344 this.prepared = false;
339345 }
341347 settle(): boolean {
351357 this.activeTui = false;
352358 this.current = false;
353359 this.pending = false;
360 this.prepared = false;
354361 }
371378 eligibility.input(event.source, event.streamingBehavior);
372379 });
381 pi.on("before_agent_start", async () => {
382 eligibility.prepare();
383 });
374385 pi.on("agent_start", async (_event, ctx) => {
375386 eligibility.start(ctx.mode);
376387 agentStartedAt ??= Date.now();