diff --git a/src/notify.ts b/src/notify.ts index fb8b9f1..6381679 100644 --- a/src/notify.ts +++ b/src/notify.ts @@ -2,8 +2,8 @@ import { writeFileSync } from "fs" /** * Send a Warp notification via OSC 777 escape sequence. - * Only emits when Warp declares cli-agent protocol support, - * avoiding garbled output in other terminals (and working over SSH). + * Only emits when Warp declares cli-agent protocol support and the current + * terminal does not explicitly identify itself as another terminal. * * On Unix we write to /dev/tty so the sequence bypasses any * stdout redirection or terminal-multiplexer capture. @@ -13,6 +13,7 @@ import { writeFileSync } from "fs" */ function warpNotify(title: string, body: string): void { if (!process.env.WARP_CLI_AGENT_PROTOCOL_VERSION) return + if (process.env.TERM_PROGRAM && process.env.TERM_PROGRAM !== "WarpTerminal") return const sequence = `\x1b]777;notify;${title};${body}\x07` diff --git a/tests/notify.test.ts b/tests/notify.test.ts index 5f54001..5cb0514 100644 --- a/tests/notify.test.ts +++ b/tests/notify.test.ts @@ -12,6 +12,7 @@ const { warpNotify } = await import("../src/notify") describe("warpNotify", () => { const originalVersion = process.env.WARP_CLI_AGENT_PROTOCOL_VERSION + const originalTermProgram = process.env.TERM_PROGRAM afterEach(() => { writeSpy.mockClear() @@ -20,6 +21,11 @@ describe("warpNotify", () => { } else { process.env.WARP_CLI_AGENT_PROTOCOL_VERSION = originalVersion } + if (originalTermProgram === undefined) { + delete process.env.TERM_PROGRAM + } else { + process.env.TERM_PROGRAM = originalTermProgram + } }) it("skips when WARP_CLI_AGENT_PROTOCOL_VERSION is not set", () => { @@ -30,6 +36,7 @@ describe("warpNotify", () => { it("writes OSC 777 sequence when Warp declares protocol support", () => { process.env.WARP_CLI_AGENT_PROTOCOL_VERSION = "1" + delete process.env.TERM_PROGRAM warpNotify("warp://cli-agent", '{"event":"stop"}') expect(writeSpy).toHaveBeenCalledTimes(1) @@ -40,4 +47,18 @@ describe("warpNotify", () => { expect(data).toMatch(/^\x1b\]777;notify;/) expect(data).toMatch(/\x07$/) }) + + it("writes OSC 777 sequence inside Warp", () => { + process.env.WARP_CLI_AGENT_PROTOCOL_VERSION = "1" + process.env.TERM_PROGRAM = "WarpTerminal" + warpNotify("warp://cli-agent", '{"event":"stop"}') + expect(writeSpy).toHaveBeenCalledTimes(1) + }) + + it("skips when Warp variables were inherited by another terminal", () => { + process.env.WARP_CLI_AGENT_PROTOCOL_VERSION = "1" + process.env.TERM_PROGRAM = "zed" + warpNotify("warp://cli-agent", '{"event":"stop"}') + expect(writeSpy).not.toHaveBeenCalled() + }) })