repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by admin

feat(os-notifier): publish Pi pane context

cbdb59d8977ae0dcdaa8471a5f087f4428097d0b

Oliver Krylow <o.krylow@isp-insoft.de> ·

SSH signature · not checked

Browse filesCompare with HEAD

Changed files (4)

extensions/os-notifier/CHANGELOG.md

Modified
7 7 - Notify only for direct interactive TUI runs completed while unfocused.
8 8 - Preserve rich metadata with natural urgency and bounded sanitized text.
9 9 - Remove the unused extension notification event bridge.
10 -- Publish pane-scoped Pi identity through OSC 1337 during TUI sessions.
10 +- Publish pane-scoped Pi identity, session name, and project through OSC 1337 during TUI sessions.
12 12 ## 0.0.3

extensions/os-notifier/README.md

Modified
62 62 Dynamic text is sanitized and passed without shell interpolation.
64 64 Focus tracking uses DECSET `?1004`, shared through `globalThis` and reference-counted.
65 -TUI sessions publish `agent=pi` as an OSC 1337 pane user variable and clear it on shutdown.
65 +TUI sessions publish agent identity, session name, and project as OSC 1337 pane user variables and clear them on shutdown.

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

Modified
6 6 agentDoneNotification,
7 7 deliverNative,
8 8 nativeCommand,
9 - oscAgentIdentity,
10 9 oscBackend,
10 + oscUserVar,
11 11 TurnEligibility,
12 12 } from "../index";
64 64 expect(oscBackend({})).toBe("osc777");
67 - it("encodes pane-scoped agent identity as an OSC user variable", () => {
68 - expect(oscAgentIdentity("pi")).toBe(
67 + it("encodes pane-scoped metadata as OSC user variables", () => {
68 + expect(oscUserVar("agent", "pi")).toBe(
69 69 "\u001b]1337;SetUserVar=agent=cGk=\u0007",
71 - expect(oscAgentIdentity("")).toBe("\u001b]1337;SetUserVar=agent=\u0007");
71 + expect(oscUserVar("agent_session", "")).toBe(
72 + "\u001b]1337;SetUserVar=agent_session=\u0007",
73 + );
74 76 it("falls back exactly once only when native delivery fails", async () => {

extensions/os-notifier/index.ts

Modified
264 264 return env.KITTY_WINDOW_ID ? "osc99" : "osc777";
267 -export function oscAgentIdentity(value: string): string {
268 - return `\x1b]1337;SetUserVar=agent=${Buffer.from(value).toString("base64")}\x07`;
267 +export function oscUserVar(name: string, value: string): string {
268 + return `\x1b]1337;SetUserVar=${name}=${Buffer.from(value).toString("base64")}\x07`;
271 -function writeAgentIdentity(value: string): void {
271 +function writeUserVar(name: string, value: string): void {
273 - process.stdout.write(oscAgentIdentity(value));
273 + process.stdout.write(oscUserVar(name, value));
274 274 } catch {
275 275 // Terminal metadata is best-effort.
394 394 pi.on("session_start", async (_event, ctx) => {
395 395 if (ctx.mode === "tui") {
396 396 focus.attach();
397 - writeAgentIdentity("pi");
397 + writeUserVar("agent", "pi");
398 + writeUserVar("agent_session", pi.getSessionName() ?? "");
399 + writeUserVar("agent_project", basename(ctx.cwd));
398 400 focusAttached = true;
404 + pi.on("session_info_changed", async (event) => {
405 + if (focusAttached) writeUserVar("agent_session", event.name ?? "");
406 + });
402 408 pi.on("input", async (event) => {
403 409 eligibility.input(event.source, event.streamingBehavior);
404 410 if (event.streamingBehavior === undefined) {
466 472 acceptedPrompt = undefined;
467 473 lastAgentEnd = undefined;
468 474 if (focusAttached) {
469 - writeAgentIdentity("");
475 + writeUserVar("agent", "");
476 + writeUserVar("agent_session", "");
477 + writeUserVar("agent_project", "");
470 478 focus.detach();
471 479 focusAttached = false;