diff --git a/src/index.ts b/src/index.ts index 745211a..3564809 100644 --- a/src/index.ts +++ b/src/index.ts @@ -52,6 +52,18 @@ function sendPermissionNotification(perm: Permission, cwd: string): void { } export const WarpPlugin: Plugin = async ({ client, directory }) => { + if (!process.env.WARP_CLI_AGENT_PROTOCOL_VERSION) { + await client.app.log({ + body: { + service: "opencode-warp", + level: "warn", + message: + "⚠️ Detected unsupported Warp version. Please update Warp to use this pluginDetected unsupported Warp version. Please update Warp to use this plugin", + }, + }) + return {} + } + await client.app.log({ body: { service: "opencode-warp", diff --git a/src/notify.ts b/src/notify.ts index 4c8d4a3..e0086cd 100644 --- a/src/notify.ts +++ b/src/notify.ts @@ -2,10 +2,11 @@ import { writeFileSync } from "fs" /** * Send a Warp notification via OSC 777 escape sequence. - * Only emits when running inside Warp terminal to avoid garbled output in other terminals. + * Only emits when Warp declares cli-agent protocol support, + * avoiding garbled output in other terminals (and working over SSH). */ function warpNotify(title: string, body: string): void { - if (process.env.TERM_PROGRAM !== "WarpTerminal") return + if (!process.env.WARP_CLI_AGENT_PROTOCOL_VERSION) return try { // OSC 777 format: \033]777;notify;;<body>\007 diff --git a/tests/notify.test.ts b/tests/notify.test.ts index 358edbd..5f54001 100644 --- a/tests/notify.test.ts +++ b/tests/notify.test.ts @@ -11,31 +11,25 @@ mock.module("fs", () => ({ const { warpNotify } = await import("../src/notify") describe("warpNotify", () => { - const originalTermProgram = process.env.TERM_PROGRAM + const originalVersion = process.env.WARP_CLI_AGENT_PROTOCOL_VERSION afterEach(() => { writeSpy.mockClear() - if (originalTermProgram === undefined) { - delete process.env.TERM_PROGRAM + if (originalVersion === undefined) { + delete process.env.WARP_CLI_AGENT_PROTOCOL_VERSION } else { - process.env.TERM_PROGRAM = originalTermProgram + process.env.WARP_CLI_AGENT_PROTOCOL_VERSION = originalVersion } }) - it("skips when TERM_PROGRAM is not set", () => { - delete process.env.TERM_PROGRAM + it("skips when WARP_CLI_AGENT_PROTOCOL_VERSION is not set", () => { + delete process.env.WARP_CLI_AGENT_PROTOCOL_VERSION warpNotify("title", "body") expect(writeSpy).not.toHaveBeenCalled() }) - it("skips for other terminal programs", () => { - process.env.TERM_PROGRAM = "iTerm.app" - warpNotify("title", "body") - expect(writeSpy).not.toHaveBeenCalled() - }) - - it("writes OSC 777 sequence when inside Warp", () => { - process.env.TERM_PROGRAM = "WarpTerminal" + it("writes OSC 777 sequence when Warp declares protocol support", () => { + process.env.WARP_CLI_AGENT_PROTOCOL_VERSION = "1" warpNotify("warp://cli-agent", '{"event":"stop"}') expect(writeSpy).toHaveBeenCalledTimes(1)