Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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`

Expand Down
21 changes: 21 additions & 0 deletions tests/notify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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", () => {
Expand All @@ -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)

Expand All @@ -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()
})
})