Skip to content

Commit 8013a62

Browse files
committed
fix: whitespace-only env var fallback, test env isolation, README wording
- OPENCODE_BELL_EVENTS with only spaces/commas now falls back to defaults - Clean env vars before top-level import to prevent external pollution - Change "Session-scoped debounce" to "Smart debounce" in features list
1 parent d09a47d commit 8013a62

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Never miss an OpenCode prompt again.
88
- Zero dependencies — single-file plugin
99
- Privacy-friendly — no message content, no external commands, no network calls
1010
- Configurable — choose which events trigger the bell
11-
- Session-scoped debounce — avoids bell spam during rapid events
11+
- Smart debounce — avoids bell spam for the same event type per session
1212

1313
## Install
1414

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// 读取需要响铃的事件类型,逗号分隔,默认四类
22
const DEFAULT_EVENTS = "permission.asked,question.asked,session.idle,session.error"
3-
// 空字符串也回退到默认值(用 || 而非 ??),避免用户设空串后全部静默
3+
// 空字符串或纯空白也回退到默认值,避免用户误设后全部静默
44
const rawEvents = process.env.OPENCODE_BELL_EVENTS || DEFAULT_EVENTS
5-
const ENABLED_EVENTS = new Set(rawEvents.split(",").map((s) => s.trim()).filter(Boolean))
5+
const parsed = rawEvents.split(",").map((s) => s.trim()).filter(Boolean)
6+
const ENABLED_EVENTS = new Set(parsed.length > 0 ? parsed : DEFAULT_EVENTS.split(","))
67

78
// 读取防抖毫秒数,解析失败或非正数则回退到 1200
89
const parsedDebounce = parseInt(process.env.OPENCODE_BELL_DEBOUNCE, 10)

test/plugin.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import test from "node:test"
22
import assert from "node:assert/strict"
33

4-
// 默认导入用于回归测试和 debounce/TTY 测试
5-
import { OpencodeBellPlugin } from "../index.js"
4+
// 确保顶层导入时 env var 是干净的,避免外部环境污染默认值
5+
delete process.env.OPENCODE_BELL_EVENTS
6+
delete process.env.OPENCODE_BELL_DEBOUNCE
7+
// 默认导入用于回归测试和 debounce/TTY 测试(依赖默认配置值)
8+
const { OpencodeBellPlugin } = await import("../index.js")
69

710
// ─── 1. 回归:event.properties 缺失不报错 ─────────────────────────────────────
811

0 commit comments

Comments
 (0)