Skip to content

Commit 51e5728

Browse files
committed
🔧 chore: restore openSync/writeSync/closeSync and simplify event handler
Revert notify.ts to openSync/writeSync/closeSync (matching 1f116ad which was confirmed working). Remove tool_complete and prompt_submit notifications from the bus event handler - these were added in the bus events migration but are not needed and may cause notification floods that interfere with session.idle delivery. Keep question_asked via message.part.updated (the core feature from PR warpdotdev#9).
1 parent 9023e74 commit 51e5728

File tree

3 files changed

+20
-30
lines changed

3 files changed

+20
-30
lines changed

‎src/index.ts‎

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -141,35 +141,15 @@ export const WarpPlugin: Plugin = async ({ client, directory }) => {
141141
}
142142
if (part?.type !== "tool" || !part?.state) return
143143

144-
const sessionId = part.sessionID || ""
145-
146144
if (part.tool === "question" && part.state.status === "running") {
145+
const sessionId = part.sessionID || ""
147146
const body = buildPayload("question_asked", sessionId, cwd, {
148147
tool_name: part.tool,
149148
})
150149
warpNotify(NOTIFICATION_TITLE, body)
151150
return
152151
}
153152

154-
if (part.state.status === "completed") {
155-
const body = buildPayload("tool_complete", sessionId, cwd, {
156-
tool_name: part.tool || "unknown",
157-
})
158-
warpNotify(NOTIFICATION_TITLE, body)
159-
return
160-
}
161-
return
162-
}
163-
164-
case "message.updated": {
165-
const info = (event.properties as { info: { role?: string; sessionID?: string } }).info
166-
if (info?.role !== "user") return
167-
168-
const sessionId = info.sessionID || ""
169-
const body = buildPayload("prompt_submit", sessionId, cwd, {
170-
query: "",
171-
})
172-
warpNotify(NOTIFICATION_TITLE, body)
173153
return
174154
}
175155

‎src/notify.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { writeFileSync } from "fs"
1+
import { openSync, writeSync, closeSync } from "fs"
22

33
const MAX_OSC_LENGTH = 4096
44

@@ -14,7 +14,9 @@ function warpNotify(title: string, body: string): void {
1414
let lastError: Error | null = null
1515
for (let attempt = 0; attempt < 3; attempt++) {
1616
try {
17-
writeFileSync("/dev/tty", sequence)
17+
const fd = openSync("/dev/tty", "w")
18+
writeSync(fd, sequence)
19+
closeSync(fd)
1820
return
1921
} catch (err) {
2022
lastError = err as Error

‎tests/notify.test.ts‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ import { describe, it, afterEach, mock } from "bun:test"
22
import { expect } from "bun:test"
33
import fs from "fs"
44

5-
const writeFileSyncSpy = mock(() => {})
5+
const writeSyncSpy = mock(() => {})
6+
const openSyncSpy = mock(() => 42)
7+
const closeSyncSpy = mock(() => {})
68

79
mock.module("fs", () => ({
810
...fs,
9-
writeFileSync: writeFileSyncSpy,
11+
openSync: openSyncSpy,
12+
writeSync: writeSyncSpy,
13+
closeSync: closeSyncSpy,
1014
}))
1115

1216
const { warpNotify } = await import("../src/notify")
@@ -15,7 +19,9 @@ describe("warpNotify", () => {
1519
const originalVersion = process.env.WARP_CLI_AGENT_PROTOCOL_VERSION
1620

1721
afterEach(() => {
18-
writeFileSyncSpy.mockClear()
22+
openSyncSpy.mockClear()
23+
writeSyncSpy.mockClear()
24+
closeSyncSpy.mockClear()
1925
if (originalVersion === undefined) {
2026
delete process.env.WARP_CLI_AGENT_PROTOCOL_VERSION
2127
} else {
@@ -26,16 +32,18 @@ describe("warpNotify", () => {
2632
it("skips when WARP_CLI_AGENT_PROTOCOL_VERSION is not set", () => {
2733
delete process.env.WARP_CLI_AGENT_PROTOCOL_VERSION
2834
warpNotify("title", "body")
29-
expect(writeFileSyncSpy).not.toHaveBeenCalled()
35+
expect(openSyncSpy).not.toHaveBeenCalled()
3036
})
3137

3238
it("writes OSC 777 sequence when Warp declares protocol support", () => {
3339
process.env.WARP_CLI_AGENT_PROTOCOL_VERSION = "1"
3440
warpNotify("warp://cli-agent", '{"event":"stop"}')
35-
expect(writeFileSyncSpy).toHaveBeenCalledTimes(1)
41+
expect(openSyncSpy).toHaveBeenCalledTimes(1)
42+
expect(openSyncSpy).toHaveBeenCalledWith("/dev/tty", "w")
43+
expect(writeSyncSpy).toHaveBeenCalledTimes(1)
44+
expect(closeSyncSpy).toHaveBeenCalledTimes(1)
3645

37-
const [path, data] = writeFileSyncSpy.mock.calls[0] as [string, string]
38-
expect(path).toBe("/dev/tty")
46+
const [, data] = writeSyncSpy.mock.calls[0] as [number, string]
3947
expect(data).toContain("warp://cli-agent")
4048
expect(data).toContain('{"event":"stop"}')
4149
expect(data).toMatch(/^\x1b\]777;notify;/)

0 commit comments

Comments
 (0)