Skip to content
Merged
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
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions src/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;<title>;<body>\007
Expand Down
22 changes: 8 additions & 14 deletions tests/notify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading