fix: improve Windows compatibility and fix event listener issues (#1102)

Replace platform-specific 'which'/'where' commands with cross-platform Bun.which() API to fix Windows compatibility issues and simplify code.

Fixes:
- #1027: Comment-checker binary crashes on Windows (missing 'check' subcommand)
- #1036: Session-notification listens to non-existent events
- #1033: Infinite loop in session notifications
- #599: Doctor incorrectly reports OpenCode as not installed on Windows
- #1005: PowerShell path detection corruption on Windows

Changes:
- Use Bun.which() instead of spawning 'which'/'where' commands
- Add 'check' subcommand to comment-checker invocation
- Remove non-existent event listeners (session.updated, message.created)
- Prevent notification commands from resetting their own state
- Fix edge case: clear notifiedSessions if activity occurs during notification

All changes are cross-platform compatible and tested on Windows/Linux/macOS.
This commit is contained in:
Nguyễn Văn Tín
2026-02-01 17:13:54 +07:00
committed by GitHub
parent ffbca5e48e
commit 011eb48ffd
5 changed files with 18 additions and 40 deletions
+10 -3
View File
@@ -200,7 +200,9 @@ export function createSessionNotification(
function markSessionActivity(sessionID: string) {
cancelPendingNotification(sessionID)
notifiedSessions.delete(sessionID)
if (!executingNotifications.has(sessionID)) {
notifiedSessions.delete(sessionID)
}
}
async function executeNotification(sessionID: string, version: number) {
@@ -254,6 +256,11 @@ export function createSessionNotification(
} finally {
executingNotifications.delete(sessionID)
pendingTimers.delete(sessionID)
// Clear notified state if there was activity during notification
if (sessionActivitySinceIdle.has(sessionID)) {
notifiedSessions.delete(sessionID)
sessionActivitySinceIdle.delete(sessionID)
}
}
}
@@ -262,7 +269,7 @@ export function createSessionNotification(
const props = event.properties as Record<string, unknown> | undefined
if (event.type === "session.updated" || event.type === "session.created") {
if (event.type === "session.created") {
const info = props?.info as Record<string, unknown> | undefined
const sessionID = info?.id as string | undefined
if (sessionID) {
@@ -299,7 +306,7 @@ export function createSessionNotification(
return
}
if (event.type === "message.updated" || event.type === "message.created") {
if (event.type === "message.updated") {
const info = props?.info as Record<string, unknown> | undefined
const sessionID = info?.sessionID as string | undefined
if (sessionID) {