dsh-watch-together 0.2.14 → 0.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,1823 +1,1860 @@
1
- # Changelog
2
-
3
- All notable changes to **dsh-watch-together** are documented here.
4
- This package starts its own version line at `0.0.7` — it is not a continuation of `dsh-video-storyboard`.
5
-
6
- ## [0.2.14] - 2026-11-06
7
-
8
- ### Added — 悬浮窗样式预设:多一档「静态磨砂」,设置页里能选
9
-
10
- 社区反馈实时玻璃在低配机/高分屏上卡。实测同机同尺寸(760×560、背景在播视频):
11
-
12
- | 样式 | 3 秒内 CPU | 占单核 |
13
- |---|---|---|
14
- | `live` 实时玻璃 | 5.17 s | **172%** |
15
- | `frost` 静态磨砂(新) | 0.03 s | **1%** |
16
-
17
- 不是把模糊调小,而是换了一条路径:`frost` **完全不抓屏**,只画一张预生成的
18
- 底板(对角冷色渐变 + 两团极淡光晕 + 细噪点 + 每块玻璃 1px 亮边),尺寸或气泡
19
- 形状变了才重画(约 11ms),其余时间一帧都不算 —— 静态样式连渲染线程都不起。
20
- `live` 那条路径一行没动,只是把线程的启停抽成了 `_start_worker` / `_stop_worker`。
21
-
22
- 样式写在 `~/.dsh/watch-window.json` 的 `glass`:`auto`(默认,远程/录屏 →
23
- solid)/ `live` / `frost` / `solid`。窗口每 250ms 看一次这个文件的 mtime,
24
- 所以**从设置页改完立刻切换**,不用重开窗口;从 `live` 切走时真的把抓屏线程
25
- 停掉(只换渲染器不停线程 = 用户切过去还是卡,只是看不见画面在变)。
26
-
27
- 设置页(浏览器版与 DSH 设置里的原生表单)都多了一栏「悬浮窗样式」。
28
-
29
- ### Changed — 心跳从"空文件戳一下"变成带可见性的 JSON
30
-
31
- 插件侧以前只能看心跳的 mtime,那只能回答"进程还在画吗",回答不了"用户能不能看见"。
32
- 于是出现最难查的一种:配置文件写 `hidden:false`、进程活着、心跳在跳,屏幕上什么都没有,
33
- 而插件 `status` 说"显示中"(see-now issue #32 第 3 点)。
34
-
35
- 现在每秒写的是:
36
-
37
- ```json
38
- {"at":1793886026.33,"visible":true,"hidden":false,"state":"normal"}
39
- ```
40
-
41
- `hidden` 是意图,`visible` 是事实(Tk 的 `state()` + `winfo_ismapped()` 说了算),
42
- 两个都写 —— 只写事实的话插件分不清"用户故意藏的"和"想显示但没 map 出来"。
43
- 原子写(`.tmp` + `replace`):插件每秒都可能读,读到半行 JSON 会退回读配置文件,
44
- 那正好是这一版要修的东西。
45
-
46
- mtime 照旧更新,老版本插件不受影响。
47
-
48
- ## [0.2.13] - 2026-11-04
49
-
50
- ### Changed — 语音改成抢占式:新的一句直接顶掉没念完的
51
-
52
- 以前是纯串行链:三句排队,第三句要等前两句念完才开口 —— 那时候画面早换了,
53
- 听到的是"它在说上一段的事"。`MAX_QUEUE_LAG_MS` 只能做"排太久就放弃",救不了"一直在排"。
54
-
55
- 现在每一句带代际(`speakGen`),新句一到立刻做两件事:
56
-
57
- 1. **截断正在念的那一句**
58
- - 常驻通道:走 daemon 新增的 `interrupt` op,只杀播放管道那个 ffplay(daemon 还活着,
59
- 下一句从新进程开始,多花一次 demuxer 探测 ~200ms);
60
- - 没有 edge-tts 的机器走 SAPI:kill 掉那个 PowerShell 进程 ——
61
- `SpVoice.Speak()` 是阻塞调用,**只有杀进程才能让它闭嘴**。
62
- 2. **清空排队**:那些句子配的是已经过去的画面,念出来只会让人困惑。
63
-
64
- 代价:被截断的那句后面几个字听不到。这个取舍是明确的 —— 追上画面比句子完整重要。
65
-
66
- **新增协议**:`{"op":"interrupt"}` → `{"ev":"interrupted"}`。
67
- 它和 `stop` 不是一回事:`stop` 是 `SystemExit(0)`,整个常驻合成器没了,下一句要重新预热 1~2 秒。
68
-
69
- ### Added — 适配器能"拉"了:`api.upcoming()` / `api.position()`
70
-
71
- 此前核心只会**推**(`due` / `scheduled`),适配器想知道"再往后还有什么、现在播到哪"
72
- 只能自己读 `watch.json` 和 `position.json` —— 那是两份内部格式,还各自带着一套
73
- "哪条位置可信"的判断,第三方适配器重写一遍必然走样。
74
-
75
- 现在 `attach(api)` 多两个**只读**方法(issue #4 定下的形状,实现没偏离):
76
-
77
- ```js
78
- await api.upcoming({ horizonSec: 20 }) // → [{ at, text, segment }],按 at 升序,不消费
79
- api.position() // → { pos, dur, confidence, staleMs }
80
- ```
81
-
82
- - `upcoming()` 读同一份台词槽,**只给未来窗口内、带 `at` 的句子**;念掉的不在里面。
83
- 窗口 1~120 秒(越界钳住),没在陪看 / 位置不知道时是空数组。
84
- - `position()` 走 `position.js` 那套锚点逻辑(扩展上报 / CDP 探针 / 用户自报三条来路),
85
- `confidence` 分 `fresh` / `extrapolated` / `unknown`。**`unknown` 时 `pos` 是 `null`,不是 0** ——
86
- 给 0 会让"我合成的音频晚了三百秒"这种判断成立,然后默默丢光音频,还没有任何报错。
87
- - 停表 / 换片即清空,不会让适配器拿着上一支片子的位置去丢音频。
88
-
89
- 边界没变:核心**不做合成、不缓存音频、不重试**。给到"下一两句是什么、现在播到哪"就够了,
90
- 预取几段、seek 之后丢哪些,全在适配器自己(core #27)。
91
-
92
- 实现:新增 `src/playhead.js`(循环把锚点推过来,避免 `watch-loop → runtime-ports →
93
- voice-adapter → companion-api` 反向 import 成环)和 `src/companion-api.js`(纯读)。
94
-
95
- ### Fixed — 悬浮窗拖得到副屏,抓屏按虚拟桌面钳位(#8)
96
-
97
- 副屏在主屏左边时坐标是负的,而拖动 / 缩放 / 恢复位置 / 抓屏外扩四处都拿主屏当边界:
98
- 窗口拖不出去、放到副屏后玻璃停在旧帧、下次启动又被拉回主屏。
99
-
100
- - `virtual_bounds()` 用 `GetSystemMetrics(76..79)` 取虚拟桌面,取不到才退回主屏;
101
- 按下时重新 `_sync_screens()`,插拔显示器不用重开窗。
102
- - 抓屏同理:`CaptureSource(bounds=…)`。**窗口整个在主屏里时仍按主屏钳** —— 单屏逐像素不变。
103
- - `scripts/check-multimonitor.py`:单屏等价网格对比 + 副屏/跨屏正面积校验。
104
-
105
- ### Fixed — 缺 `mss` / `numpy` / `pillow` 时弹窗说明,不再静默退出(#76 附带)
106
-
107
- pythonw 没有控制台,`import mss` 失败时 Python 直接退出,用户看到的只有"窗口没出来"。
108
- 现在在 import 重依赖之前先检查一遍:缺包就弹 MessageBox 写明缺哪个、装什么,
109
- 并把原因落到 `~/.dsh/watch-window-error.log`。README 也改了口径 ——
110
- 原来写"不装任何第三方包",下一段又说要 Pillow + numpy + mss,把 `pip install` 提到最前面。
111
-
112
- ## [0.2.12] - 2026-11-04
113
-
114
- ### Fixed
115
-
116
- - **在悬浮窗打字不再往宿主的「排队消息」里塞一条**(`wakeOnChat` 默认 `true` → `false`)。
117
- 每打一句话,输入框上方就多一条排队消息 —— 而窗口里明明已经有气泡显示过了,
118
- 队列里再来一条既是噪音、又占住输入框。根因是 `wakeSession` 走宿主的 `agent.followup()`,
119
- 而 DSH 的 QueueDock 不过滤来源,绕不开,只能不投。
120
- **关掉不会丢话**:钟那一拍整个跳过、聊天通道不消费,消息留在里面,模型下次调
121
- `watch_together` 时 poll 得到;真正的阻塞等待(`wait` / `nextLine`)走另一条路,
122
- 照旧能随时打断。
123
-
124
- ### Added — 气泡底板
125
-
126
- 聊天气泡内部铺一层 `#07111d`、alpha 0.50 的圆角底板(`glass_geometry.BUBBLE_PLATE`),
127
- 文字的对比度不再跟着画面走。底板在玻璃合成层做(`_overlay` 的 tint),CPU / GPU 两条
128
- 路径共用同一份实现;气泡宽度变了跟着一起重算;空态不铺(四个占位框铺深色会像四个空洞)。
129
-
130
- 实测:760×560、同一段消息、同一位置,只切 `DSH_GLASS_PLATE` 拍两版,取气泡内
131
- 「底板中位灰度 / 文字笔画 p97」算 WCAG 对比度。
132
-
133
- | 背景 | 改动前 | 改动后 |
134
- |---|---|---|
135
- | 纯白(最坏情况) | 1.26–1.53:1 | 3.83–4.25:1 |
136
- | 深蓝黑 | 16.3–17.7:1 | 17.0–17.2:1 |
137
-
138
- alpha 0.40 时纯白背景只有 2.88–3.31:1(试过),0.50 才到 4.2。
139
-
140
- `TextLayer.draw(shadow=True)` 给每个字先落一层 `+1px` 的深色副本。Tk 的 text item 没有
141
- stroke / outline,只能多建一层 item;只在气泡正文开,`refresh()` 用 `tshadow` 标签把
142
- 它排除在翻色之外(目前暂存)。
143
-
144
- ### Changed — 声音延迟 2.4 秒 → 0.2 秒(常驻合成器)
145
-
146
- > 台词几分钟前就写好了,第一声却要等两秒多 —— 听起来不像它在说,像在等我念。
147
-
148
- 老路是**每句起两个进程**:一个 `edge-tts.exe` 合成到临时 mp3,一个 `ffplay` 播放。
149
- 实测(Win11 / i9-12900HX,短句与长句各三次取均值)端到端 **2.4~3.0 秒**,
150
- 而且这四笔开销**每句都要重付一次**:
151
-
152
- | 段 | 耗时 |
153
- |---|---|
154
- | pip 的 exe shim 拉起 python | ~600ms |
155
- | python 解释器冷启动 | ~600ms |
156
- | `import edge_tts` | ~700ms |
157
- | WebSocket 建连(DNS+TCP+TLS+token) | 620~760ms |
158
- | 首块合成 | 200~300ms |
159
- | 剩余音频块 | 30~130ms |
160
- | ffplay 启动 + demuxer 探测 | 380~410ms |
161
-
162
- `examples/voice-edge-tts/stream/daemon.py` 把三件事搬进一个常驻进程:
163
-
164
- 1. **常驻 python**:`import edge_tts` 只做一次。
165
- 2. **长连接复用**:一条 WebSocket 上连发多个 SSML 请求(Azure 协议本来就支持)。
166
- 实测连续 20 句首块 **min 182 / avg 200 / max 235ms**,没有退化。
167
- 服务端在 `turn.end` 之后约 **30 秒**关连接(30s 还活着、35s 已死;发 ping 保不住),
168
- 所以空闲超 25s 主动断、下次用时重建(620~760ms)。
169
- 3. **常驻 ffplay**:一个进程从 stdin 连续吃 mp3 帧。实测三段音频拼着写进去,
170
- 时间码一路涨到 7.3s、进程没退 —— 每句起进程要付 380ms 首声。
171
-
172
- 同一条 `due` 事件、同一台机器上的对照:
173
-
174
- | 场景 | 老路 | 现在 |
175
- |---|---|---|
176
- | 预取命中(`scheduled` 已合成) | 1009~1674ms | **1ms** |
177
- | 没赶上预取(`see-now` 的 `at:null`) | 2485ms | **230ms** |
178
- | 连续第三句 | 排队 4.9s 后被丢弃 | 1ms |
179
-
180
- 预取队列也不再"满 6 句就丢弃":常驻通道按 text 在内存里缓存(上限 80 句),
181
- 老路那个 `MAX_PREFETCH = 6` 是文件缓存 + 串行 CLI 逼出来的,这里不用照抄。
182
-
183
- **兜底**:python 找不到、`daemon.py` 不存在、进程起不来 —— 任何一步失败都退回老路
184
- (每句一个 CLI 进程),没有一行 throw。`DSH_TTS_STREAM=0` 可强制走老路排查。
185
- 调试时 `DSH_TTS_FFPLAY_LOG=info` 会把 ffplay 的时间码放出来。
186
-
187
- `test/tts-stream.test.mjs` 覆盖协议(first/done 顺序、error 后通道继续可用、进程死掉后不挂在超时上),
188
- 不依赖网络和 ffplay。
189
-
190
-
191
- > Issue #44 第 2 条:文字直接压在实时视频上,对比度每秒都在变,连看 5–10 分钟眼睛发酸。
192
-
193
- 有底板之后底色恒定,`TextLayer.adapt()` 对气泡正文已经没有意义,反而会在过渡帧翻错
194
- (白字被翻成深色,压在深色底板上更看不见)。给 `draw()` 加了 `adapt=False`:这些 item
195
- 不参与采样。标题栏、输入框、空态提示仍走逐字翻色 —— 它们确实直接压在玻璃上。
196
-
197
- - 跟 `dsh-video-storyboard` 0.6.6 一起发。依赖范围 `^0.6.0` 不用改。
198
- 上游这次是排布与计费对齐(同素材 token -9.3%),**本包自己的代码没有改动**。
199
-
200
- ### 调试开关
201
-
202
- `DSH_GLASS_PLATE=0` 关掉底板和描边,回到 0.2.11 的行为 —— 只用来拍新旧对比图。
203
-
204
- ## [0.2.11] - 2026-11-03
205
-
206
- > 悬浮窗从头拆了一遍(单文件 1931 行 → 五层),顺带修掉 GPU 路径三个真 bug。
207
-
208
- ### Changed — 玻璃拆成四层,去掉全部模块级可变全局
209
-
210
- `window.py` 原来 1931 行,`W / H / SHAPES / MASK / MASK_HARD / OVERLAY /
211
- OVERLAY_2X / WARP_X / WARP_Y / BOX_MAPS / HW / HH / BOX_UNION_2X / MIC_POS`
212
- 十几个模块级全局靠 `global` 在 `rebuild_geometry()` 里一次性改写;GPU 伴生
213
- 文件还得 `import glass_window as G` 去读它们,窗口一缩放就可能拿到上一帧的坐标。
214
-
215
- | 文件 | 职责 |
216
- |---|---|
217
- | `glass_geometry.py` | 一套尺寸的全部贴图。`Geometry` 是不可变值对象,气泡变宽用 `with_shapes()` 换新对象,尺寸相关的遮罩/折射图直接复用 |
218
- | `glass_capture.py` | 抓屏、`MotionTracker`、麦克风贴图、圆角收尾 —— CPU/GPU 共用一份 |
219
- | `glass_cpu.py` | CPU 合成管线 |
220
- | `glass_gpu.py` | 同一件事在 moderngl 上做 |
221
- | `window.py` | 编排 + Tk 窗口 + 交互 |
222
- | `window_widgets.py` | `Fonts` / `ChatFeed` / `TextLayer` |
223
-
224
- 顺手清掉的死代码和重复逻辑:
225
-
226
- - `_add_text_shadows()` 是空实现,`_text_shadows` 有 11 处引用但永远是空的;
227
- - `_hide_window()` 定义了但没有任何调用点;`EDGE_MASK` 算出来没人用;
228
- - `_fit_lines` / `_text` 对每个字重新 `measure()` 一遍前缀 —— O(n²) 次 Tcl 调用,
229
- 改成累积宽度;
230
- - 每来一条消息就 `Entry.destroy()` 重建(丢输入法状态和光标),改成复用一个;
231
- - `_preview_resize` / `_rebuild` / `_refresh_feed` 三份几乎相同的「清状态 + 重排 +
232
- 贴图」;
233
- - `tkfont.Font(...)` 每帧新建几百个 Tcl 对象 → `Fonts` 按尺寸缓存。
234
-
235
- ### Fixed — 录屏模式下桌面图标被沿上下方向拉成竖条
236
-
237
- `capturable: true` 时 mss 会抓到窗口自己,所以要把那块刷平。`fill_own_rect()`
238
- 当时的做法是「取窗口上下各一行像素做纵向插值」:窗口上方紧挨着的那一行里如果
239
- 正好有桌面图标或文字,**每个像素会被整列往下抹开** —— 用户看到的就是「东西被
240
- 沿上下方向拉成长条」。0.2.7 的 CHANGELOG 写的是「周边均值」,代码里却是纵向
241
- 插值,那次改动把方案退回去了。
242
-
243
- 现在改成四条边各自分段抹平高频 + Coons patch 融合:边界贴合真实背景,内部只有
244
- 大尺度色彩过渡,没有方向性条纹。填充区的列内/行内标准差从 **28.0 / 35.9**(有
245
- 方向性)变成 **12.7 / 7.1**(各向同性)。
246
-
247
- 算法本身要降到 1/8 粗网格再放大 —— 全分辨率算一次 **80 ms**,粗网格 **4.2 ms**,
248
- 而这块最后还要被高斯糊一遍,8px 的色阶看不出来。
249
-
250
- 同一个问题 GPU 侧本来没有(它压根没调 `fill_own_rect`),0.2.11 给 GPU 补上这
251
- 一步之后两边一致。
252
-
253
- ### Fixed — GPU 版的 OpenGL context 建在错误的线程上(每帧 `cannot create texture`)
254
-
255
- `GpuRenderer` 原来在主线程构造。`moderngl.create_standalone_context()` 绑在创建
256
- 它的线程上,而 `render()` 跑在抓屏 worker 线程 —— 每帧抛 `cannot create texture`,
257
- 被 `_work()` 吞掉后只打印一行、窗口始终没有玻璃(截图里只剩文字浮在桌面上)。
258
-
259
- 改成首次 `render()` 时惰性创建(那时已经在 worker 线程);真起不来就打印原因并
260
- 回落 CPU,不刷屏。
261
-
262
- ### Fixed — GPU 版在录屏模式下没挖掉自己(`moved` 恒真、永不跳帧)
263
-
264
- `CaptureSource.to_image()` 会 `fill_own_rect()`,但 GPU 直接吃 `shot.bgra`、
265
- 绕过了那一步 —— 背景里永远带着本窗口,`moved` 每帧为真:静态跳帧一次都不触发,
266
- 还叠出自我反馈的拖尾(0.2.7 修过同一个坑,只修了 CPU 侧)。补了数组版
267
- `fill_own_rect_array()`。
268
-
269
- 实测 700×665 / 150% DPI / 同一桌面、同一条消息:
270
-
271
- | | CPU 版 | GPU 版(修前) | GPU 版(修后) |
272
- |---|---|---|---|
273
- | CPU | 43.2% 单核 | 87.9% | **32.1%** |
274
- | 内存 | 93 MB | 195 MB | 193 MB |
275
-
276
- ### Fixed — `DSH_GLASS_NATIVE=1` 一直是个假开关
277
-
278
- `run-glass.cmd` 写着「走 GPU 路径」,但 `window.py` 从来没 import 过
279
- `glass_window_gpu` —— 设了只是让 CPU 路径去读一个没人用的变量。现在
280
- `DSH_GLASS_GPU=1` / `DSH_GLASS_NATIVE=1` 真的选后端;`glass_window_gpu.py`
281
- 仍可单独起窗(等价于 `DSH_GLASS_GPU=1`)。
282
-
283
- ### Fixed — GPU 版拖动窗口没有运动模糊、反而做静止才该做的色散
284
-
285
- 0.2.9 修的 `box_changed → moved` 只落在 CPU 路径上,GPU 那份还是老判断。现在
286
- 两条路径共用 `MotionTracker`,同一个判断只有一处实现。
287
-
288
- ### Fixed — GPU 版形状变化后混入上一帧残影
289
-
290
- `_invalidate_glass()` 只清了 CPU 的 `_prev_out`,GPU 的 `_prev_valid` 还留着。
291
- 现在几何一变统一走 `renderer.invalidate()`,两边一起清。
292
-
293
- ### Fixed — 折叠时 `slabs_for()` 算出负高度矩形
294
-
295
- 折叠后窗口只有 78px,`bot = (o, h-o-70, ...)` 的 y0 大于 y1,PIL 直接抛
296
- `y1 must be greater than or equal to y0` —— 点一下 ▾ 就 traceback。高度不够时
297
- 只返回标题栏那一块。
298
-
299
- ### Performance
300
-
301
- - 高斯从 PIL `ImageFilter.GaussianBlur` 换成 `cv2.GaussianBlur`(有 OpenCV 时);
302
- - GPU 首次渲染 **1137 ms → 79 ms**(几何贴图改用 cv2 缩放,不再 PIL 逐通道);
303
- - 静止时的探针从 60fps 降到 30fps —— 单次 `grab()` 就要 7ms,空转等于白烧
304
- 40% 单核;有变化时 `idle` 立刻归零、下一拍恢复全速;
305
- - 文字翻色从「每个字 `crop()` + `np.percentile`」改成整帧转一次灰度再切片。
306
-
307
- ### 验证
308
-
309
- - 视觉:同一背景同一消息,新旧玻璃帧逐像素对比 **均差 0.068、99% 像素差 ≤1**;
310
- - 交互:折叠 / 展开 / 拖动 / 边缘缩放 / 滚轮 / 改名 / 发送 / 新消息增量 / 关闭
311
- 全部实跑通过(810×625 与 760×560、折叠 78px 三种尺寸);
312
- - `node scripts/check-syntax.mjs` 56 files ok;`node --test` **317 pass / 0 fail**。
313
-
314
- ## [0.2.10] - 2026-11-03
315
-
316
- > GPU 路径其实一直是坏的,顺便量了一下它到底省不省。
317
-
318
- ### Fixed — GPU 路径的 GLSL 用了保留字,着色器从来没编译成功过
319
-
320
- `glass_window_gpu.py` 的 FRAG 里有一行 `vec3 patch = mix(edgep, strong, e);`。
321
- `patch` 是 GLSL 1.5 起保留的 tessellation 关键字,编译直接失败:
322
-
323
- ```
324
- GLSL Compiler failed
325
- ERROR: 0:24: 'patch' : syntax error
326
- ```
327
-
328
- `_work()` 里那句 `except` 把异常吞掉、每帧打一行 `GPU capture failed, falling back to CPU`,
329
- 然后继续走 CPU —— **所以 `glass_window_gpu.py` 从来没真正跑起来过**,用户能看到的最大线索
330
- 就是一句每帧刷屏的日志。更糟的是它每帧重建一次 program/FBO 又失败,实测内存涨到 **2.3 GB**。
331
-
332
- 改个名(`patch` → `tile`)。修完日志干净、内存 200 MB、画面和 CPU 版一致。
333
-
334
- ### 实测 — GPU 不比 CPU 省(这台机器上)
335
-
336
- i9-12900HX / RTX 4060 Laptop / 窗口 700×665 / 150% DPI / 静态桌面:
337
-
338
- | 路径 | CPU(单核) | 内存 |
339
- |---|---|---|
340
- | CPU(正常模式) | **49.6%** | 100 MB |
341
- | GPU(`glass_window_gpu.py`) | 115.6% | 200 MB |
342
- | CPU(`GLASS_FORCE=1`,调试) | 146% | 111 MB |
343
-
344
- 两边都有静态跳帧,GPU 多出来的是每帧把 BGRA 上传成纹理(约 2.6 MB/帧)+ moderngl 的
345
- Python 层调用开销;而 CPU 版在这么小的窗口上本来就够快。GPU 路径更适合「窗口很大 + CPU 较弱」,
346
- 不是无脑更优 —— **默认继续用 CPU**。
347
-
348
- ## [0.2.9] - 2026-11-03
349
-
350
- > 一条根因修得很漂亮的 bug:拖动窗口时的动态模糊。
351
-
352
- ### Fixed — 拖动窗口没有动态模糊(合 PR #49,作者 @ggfgfgf-on,对应 #48)
353
-
354
- 现象是「`GLASS_FORCE=1` 下能看到那种黏黏的拖尾,正常启动看不到」,我一开始以为是
355
- `_motion_blur` 的衰减公式问题 —— 猜错了。
356
-
357
- 真正的原因在这行:
358
-
359
- ```python
360
- if self._sig is not None and box == self._sig_bbox and sig.shape == self._sig.shape:
361
- ```
362
-
363
- 拖动窗口时抓取区域 `box = (gl, gt, gr, gb)` 每帧都在变,`box == self._sig_bbox` 永远不成立,
364
- `moved` 一直是 `False`。于是:
365
-
366
- - `_motion_blur` 一路乘 0.55 衰减到 0,混合那步一次都不执行;
367
- - 反而每帧都在做 `apply_chroma(panel, 1.7)`(那是「没在动」时的色散补偿)。
368
-
369
- `FORCE` 之所以看起来有效,只是因为它跳过静态跳帧、帧数更多,更容易凑出连续可混合的帧 ——
370
- 它并没有修掉这个判断。
371
-
372
- 现在 `_sig_bbox` 已存在且 `box` 变了,就把这一帧标成 `moved = True`:抓取区域变了,
373
- 旧区域的像素本来也不能直接做差,但这确实是运动。静止窗口仍走原来的像素差判断,
374
- 不会变成常驻拖影。和 #42 不冲突 —— `_invalidate_glass()` 会把 `_sig_bbox` 清成 `None`,
375
- 形状变化后的第一帧不会误判成 `box_changed`。
376
-
377
- ### 说明 — 静止画面下没有动态模糊是设计
378
-
379
- 同一轮确认:`if moved` 这层是故意留的,运动模糊不是常驻滤镜。静止时混上一帧只会把文字和边缘
380
- 永久糊一层,还会让 `_motion_blur` 维持在高位,停下后回不到清晰;CPU 每帧做一次 `Image.blend` 也不便宜。
381
-
382
- 想要「低速拖尾」可以做配置项(类似 `motionBlurFloor`,默认 0),但不改默认行为。
383
-
384
- ## [0.2.8] - 2026-11-03
385
-
386
- > 三个社区 PR(都是 @ggfgfgf-on)+ 一批失效入口的清理。
387
-
388
- ### Fixed — 多 P / 选集页面读错 `<video>`(合 PR #45,对应 #44)
389
-
390
- 旧实现按 `duration` 挑播放器,遇到 B 站多语言版本这种页面,会挑中一个隐藏的 13 分钟长视频,
391
- 上报的 `pos` 直接跳到 13:42,插件判定「换片了」,陪看中断。
392
-
393
- 新逻辑:先排除不可见 / 零尺寸 / `opacity: 0` 的候选,再按在视口里占据的面积排序;
394
- 播放中只加一档权重(不能压过更大的主播放器);认画中画和全屏;整页都不可见才退回全部。
395
-
396
- ### Fixed — 气泡形状变化后不重合成(合 PR #42)
397
-
398
- 静态跳帧只看 `_sig_bbox`,只清 `_sig` 不够。气泡/内框形状变了之后,如果桌面本身静止,
399
- worker 会一直 `return None`,新遮罩和新色散要等用户动一下鼠标才出现。
400
- `FORCE` 模式下看不出来,只在真机静置时暴露。
401
-
402
- ### Fixed — `_tick` 每 4ms 重读一次配置(合 PR #47,fixes #46)
403
-
404
- `not capturable()` 每拍读一次 `watch-window.json` —— `__init__` 早就把结果缓存在
405
- `self._cappable` 了,这里纯属白花。0.2.7 引入的疏漏,谢谢抓出来。
406
-
407
- ### Fixed — 删掉失效的 `run-glass*.cmd`,并去掉里面的本机绝对路径(#43)
408
-
409
- 玻璃渲染重写之后 `DSH_WATCH_GLASS_TTL/FPS/CHROMA/BLUR/SAT` 和 `DSH_GLASS_ACRYLIC`
410
- 已经没有任何代码读取,但那几个脚本还在设置它们:双击 `run-glass-acrylic.cmd` 以为开了
411
- 亚克力,实际还是普通软件模糊。静默失效比报错更糟。
412
-
413
- 现在只留一个 `run-glass.cmd`,开头列清哪些变量废弃、哪些真正有效;解释器也不再写死
414
- 本机路径(先找 PATH 上的 `pythonw`,再退 `py -3`)—— 这个仓库是公开的。
415
-
416
- ## [0.2.7] - 2026-11-03
417
-
418
- > 五个社区 PR 一起收(都是 @ggfgfgf-on 提的),外加录屏模式的两个真 bug。
419
-
420
- ### Fixed — 录屏/截图根本拍不到窗口
421
-
422
- 窗口一直开着 `WDA_EXCLUDEFROMCAPTURE`(防截图/直播泄露,这是对的),
423
- 但社区贡献者要调玻璃管线就必须能录。原来只有环境变量 `DSH_GLASS_WDA=0` 一个入口,
424
- **而插件拉起窗口时不会传环境变量** —— 于是用户在 `~/.dsh/watch-window.json` 里写了
425
- `"capturable": true` 也没人读,录出来永远是空桌面。
426
-
427
- 现在 `capturable()` 真的读配置:环境变量(临时)→ 配置项(持久)→ 默认排除。
428
-
429
- ### Fixed — 录屏模式下"字一直在闪"、拖尾越滚越浓
430
-
431
- `capturable: true` 关掉 WDA 之后,**mss 抓背景时把窗口自己也抓进去了**。玻璃拿它当背景
432
- 等于"透过自己看自己",形成反馈回路:背景里带着上一帧的字 → 亮度判据一直抖 → 字色来回翻;
433
- 背景一直在变 → `moved` 一直为真 → 一直混合上一帧 → 越滚越浓的假拖尾(静止画面也在"动")。
434
-
435
- 现在录屏模式下把窗口矩形用**周边均值**刷平(试过按上下边缘插值,相邻列颜色不同会变成
436
- 一根根竖条,更难看)。窗口外 PAD 一圈仍是真背景,边缘透镜照常。
437
- 实测同一位置连续 6 帧:帧差从"每次都在变"降到 **0.00**。
438
-
439
- ### Added — 窗口心跳
440
-
441
- `<cache>/window-heartbeat`,`_tick` 里每秒最多写一次。宿主那侧靠它区分"进程还在"和
442
- "窗口真的在画"——只看 pid 的话,pid 被复用或界面卡死时永远认为窗还开着,于是再也不重开。
443
-
444
- ### Fixed — GPU 抓屏越界(合 PR #40,作者 @ggfgfgf-on,fixes #39)
445
-
446
- GPU 路径的 `capture_gpu()` 有自己一份 `sct.grab()`,没做 `gr-gl/gb-gt` 守卫;
447
- 窗口被拖出屏幕时每帧抛 `Region has zero or negative size`,被 `_work()` 吞掉后背景永久停在旧帧。
448
- 补上和 CPU 路径一样的检查。
449
-
450
- ### Fixed — 台词 `at: null` 被存成第 0 秒(合 PR #38,作者 @ggfgfgf-on)
451
-
452
- `Number(null) === 0`,显式写 `at: null` 的台词全被当成"第 0 秒",回读时挤在片头。
453
-
454
- ### Fixed — 本机 API 的 CORS 与聊天游标(合 PR #35,作者 @ggfgfgf-on,fixes #33 #34)
455
-
456
- - 聊天/位置 API 原来对**任意网页**放开 CORS,可被跨站写入;改成只认白名单。
457
- - `chat.jsonl` 被清短之后,聊天页的游标永久卡在越界位置;改成越界自动归零。
458
- - 新增 `test/chat-server-guards.test.mjs`。
459
-
460
- ### Fixed — 卸载时没 detach voice adapter(合 PR #31,作者 @ggfgfgf-on,fixes #30)
461
-
462
- 适配器订阅了 speech bus,插件卸载却没退订 —— `speechSubscribers()` 一直 > 0,
463
- 重载后循环误以为"有人会念",模型再也不会被叫醒。
464
-
465
- ### Added — 设置页自动保存(合 PR #32,作者 @ggfgfgf-on)
466
-
467
- 改一项存一项,不用再点保存;顺带补了声音环境变量提示与连接状态。
468
-
469
- ## [0.2.6] - 2026-11-02
470
-
471
- > 陪看的声音还差最后一步:到点才开始合成。这一轮把"合成"从关键路径上挪开。
472
-
473
- ### Added — `scheduled` 事件(合 PR #36,作者 @ggfgfgf-on)
474
-
475
- - 循环每一拍把**未来 60 秒内、已经写好且带 `at`** 的台词以 `scheduled` 广播一次(每句一次;
476
- 只在有会出声的订阅者时发)。它不参与"该不该念"的判断,只给适配器时间预合成。
477
- - `upcomingLines(input, { after, before })`:只读的"未来台词"查询,不消费稿件。
478
-
479
- ### Changed — 示例适配器预合成
480
-
481
- - `examples/voice-edge-tts`:`speakEdge` 拆成 `synthEdge`(只合成)+ `playEdge`(播放并删临时文件);
482
- `scheduled` 到达即合成,按 `input|segment|text` 缓存(上限 6 条,满时踢 `at` 最远的一条),
483
- `due` 优先播缓存。日志多出 `prefetched` / `synth`、`ready Nms`、`wait Nms`。
484
- - `MAX_QUEUE_LAG_MS` 的计时从 `due` **到达**起算,合成时间本来就算在里面 ——
485
- 预取因此还降低了"排队太久被丢弃"的概率,不只是首声早一点。
486
-
487
- ### Fixed — 评审补丁(`5fa1307`、`bd5b3c7`)
488
-
489
- - **跨段时缓存 key 对不上**:`dueLine` 跨段挑 `at` 最小的一句,选中上一段的句子时 `due` 报的却是
490
- 当前段,和 `scheduled` 的 `segment` 不一致 → 缓存白做、首声又晚回 0.6~2 秒。
491
- `dueLine({ meta: true })` 现在多返回 `from`,`speak()` 用它。
492
- - **`Number(null) === 0`**:没写 `at` 的台词会被当成"at=0"挤进预取窗口;适配器 `prefetch()` 同理,
493
- 6 个槽位被 at=0 占满后永久失效。两处都改成显式判空。
494
-
495
- ## [0.2.5] - 2026-11-02
496
-
497
- > 0.2.4 里 PR #28 留下的两个 GPU 尾巴,作者当天补了 PR #29 收掉,外加气泡留白微调。
498
-
499
- ### Fixed — GPU 内框边缘(合 PR #29,作者 @ggfgfgf-on)
500
-
501
- - **底部输入/发送框发黑**:内框边缘原来直接拿 `small` 的 render target 当 sampler,
502
- 贴边小框会采到边界外。现在单独拷一份 blur(1.45) 到 `edgeblur` FBO 再采样
503
- (注释里写明「直接当 sampler 会触发驱动崩溃」,所以宁可多一次 copy)。
504
- - **内框边缘的折射/扭曲丢了**:CPU 里 `edge_w=0` 是边缘(取折射样本)、`=1` 是中心
505
- (取强模糊),Shader 里方向是反的。改成 `mix(edgep, strong, e)` 后恢复。
506
-
507
- ### Changed — 气泡留白
508
-
509
- - 横向 14→18,纵向 `+4`→`+16`,正文按 `(bh - lines*ls)/2` 垂直居中。
510
- 字不再贴着气泡边,短消息也不会挤成一条。
511
-
512
- ## [0.2.4] - 2026-11-02
513
-
514
- > 0.2.3 发出去 20 分钟就发了这个 —— 因为它带着一个肉眼可见的毛病:
515
- > **气泡里的字会一直黑白闪**。另外收了社区 PR #28。
516
-
517
- ### Fixed — 字一直在黑白闪
518
-
519
- 气泡是透明的,背后就是桌面/视频/网页。`_adapt_text` 每 0.12 秒按
520
- `p50 < 0.50` **硬切**白字 `#f2f8ff` / 深字 `#07111d`,画面一动亮度就在阈值附近
521
- 来回穿 —— 同一段抖动序列 **16 次采样翻 15 次**,肉眼就是"字一直在闪"。
522
- (这段逻辑 0.2.1 就在,只是 0.2.3 的气泡更透、更容易撞上。)
523
-
524
- - **滞回**:白的要暗到 0.38 才翻深,深的要亮到 0.62 才翻白,中间的 0.38~0.62 保持现状。
525
- - **连续两次同向才切**:单帧跳变忽略,最坏 0.24 秒换一次色。
526
- - 顶部细条同样处理(0.48 硬切 → 0.36/0.60 滞回),并在 `_build_ui` 重建时把
527
- `_bar_color` 归位,免得条和缓存对不上。
528
- - 结果:同样 16 次抖动翻 **0 次**;真·明暗切换仍然生效(慢一个采样周期)。
529
-
530
- ### Changed — 玻璃合成管线(合 PR #28,作者 @ggfgfgf-on)
531
-
532
- - **小框边缘不再硬切**:气泡/输入框边缘原来直接用未模糊的 raw、中心却是
533
- blur(2.6),中间二值 edge 一刀切,有一圈"割裂"。现在边缘走 blur 1.45 的帧,
534
- 再用 smoothstep 过渡。GPU 侧同步;贴边小框仍从 raw 取(用 warped 会采到边界外
535
- 的黑边,底部输入/发送框会发黑)。
536
- - **CPU 补齐 GPU 才有的效果**:外缘 R/B 径向色散(2x 合成图上做,索引图按尺寸缓存,
537
- 缩放重建时释放)、上一帧运动混合。GPU 的 `blend` 改成只在检测到移动时混,
538
- 停下立刻干净;移动帧跳过色散,先保住拖动/滚动响应。
539
- - **麦克风回到玻璃帧合成**(`MIC_POS` / `MIC_LIGHT` / `MIC_DARK`),不再在 Canvas
540
- 上单独建图。这是回退 0.2.3 里 #22 的 Canvas 方案 —— 好处是位置与上游仓库对齐、
541
- 会被玻璃一起处理;代价是依赖合成帧。
542
- - **消息气泡改成自适应宽高**:按正文实测折行,时间戳移到气泡上方不再进框,
543
- 替掉 #22 的固定 88px 四框。短消息不再撑满整行。
544
- - 兼容层改动态代理,GPU 能看到缩放/气泡的新坐标;缩放重建时释放色散索引缓存。
545
-
546
- > 验证:311 测试全绿;清空 `chat.jsonl` 冷启动实跑,1 条短消息 / 4 条混合长度
547
- > (含多行、超长)都正常渲染,输入/发送框无发黑。
548
-
549
- ## [0.2.3] - 2026-11-02
550
-
551
- > 主题:**悬浮窗这一轮收口** —— 社区提的 #22 / #23 / #25 / #26 / #27 全部合进来,
552
- > 核心与 TTS / 悬浮窗之间的依赖收成 `runtime-ports`。
553
- > 播放位置、台词锚点、语音调度这些**一处没动**;变的只有窗口和它下面那层接口。
554
-
555
- ### Added — 核心只认 runtime-ports(合 PR #22)
556
-
557
- - 新增 `src/runtime-ports.js`:**唯一**给出 TTS / 悬浮窗适配器的地方。
558
- `chat-store` / `watch-loop` / `watch-actions` / `input-surface` 不再直接
559
- `import` `voice.js` / `floating-window.js` / `window-protocol.js`。
560
- - `installPorts()` / `resetPorts()` / `getTtsPort()` / `getWindowPort()` 从 `public-api` 导出,
561
- 宿主或测试可以注入自己的实现;裸 `import` 仍拿历史默认(speech bus + 内置窗口),
562
- CLI 和老测试照旧能跑。
563
- - `test/decoupling.test.mjs` 守这条线:核心模块一旦直接依赖实现就红。
564
-
565
- ### Changed — 悬浮窗气泡与折叠重做(合 PR #22)
566
-
567
- - **气泡改成「时间头 + 正文折行」**:`_fit_lines()` 按框宽/框高折行,标点不落行首,
568
- 超长截断加省略号;四条气泡统一 88px 并吃满内容宽度,不再为了塞下文字把字号压到 9。
569
- - **折叠不再重建整窗几何**:只缩窗口 + 只画标题栏。原来 `rebuild_geometry(78)` 会在
570
- `rounded_mask` 抛 `y1 must be >= y0`,**折叠直接异常**(main 上可复现)。
571
- - **每 1.8 秒重新置顶一次**:DSH 抢焦点后浮窗不再被压下去。
572
- - **麦克风改 Canvas 矢量图标**,不再往合成帧上贴第二层;GPU 路径同步去掉。
573
- - 补三处收尾:空态分支还在用已删掉的 `bh` → 清空 `chat.jsonl` 冷启动直接 `NameError`,
574
- 窗口起不来;标题改回**双击**改名(单击要留给按住拖动);折叠态跳过抓屏,
575
- 否则遮罩尺寸不符会每帧刷一条 `images do not match`。
576
-
577
- ### Fixed
578
-
579
- - **拖到屏幕外不再花屏**(合 PR #23)—— `_x` / `_y` 只在启动时读一次,拖动后已过期;
580
- 加上越界钳位后仍可能算出 0 或负的抓屏尺寸,`mss` 抛 `Region has zero or negative size`,
581
- 异常在 `_work()` 里被吞掉只打一行的结果是:每帧一条日志、背景永远画不出来。
582
- 现在拖动/缩放分支都钳位,并在抓屏前直接挡掉非正尺寸。
583
- - **`window` 接口的 hide/show 兼容只返回布尔的实现**(合 PR #25)—— 以前拿返回值当对象解构,
584
- 实现只回 `true` 时 `hide` 变成静默失败。
585
- - **snapshot 模式不再被 `_tick` 重新打开 WDA**(合 PR #26)—— worker 已暂停,
586
- 下一拍却把 WDA 开回来,窗口再次从截图/录屏里消失,`_snapshot_mode` 等于没做。
587
- - **折叠不再跳回原位、折叠背景有圆角、标题栏排版收紧**(合 PR #27)——
588
- `_sync_pos()` 在 `_release` 与 `toggle_collapse` 前同步真实坐标(`_x/_y` 过期会让窗口弹回启动位置);
589
- 折叠态按 78px 重新贴圆角遮罩,不再直接裁 `_last_frame` 留一条硬边;
590
- `_save_geometry` 存**展开高度**,否则下次启动按 78px 恢复;折叠时 `_tick` 不再消费旧队列,
591
- 避免 560px 的帧贴回 78px 画布闪一下;状态点/名字/计数统一到 y=38 中线,字号 21→16。
592
- 实测对照 main:拖到 (300,220) 折叠后停在 (300,220)、配置写 `760x560+300+220`,
593
- main 会跳回 (1720,480) 并写 `760x78`。
594
-
595
- ### Docs
596
-
597
- - **README 挂上赞赏码**(微信,`docs/images/reward-qr.png`)。写法上明确一句:
598
- 打赏**不解锁任何东西**,也不影响这个项目以后的授权方式 —— 它仍然是 Apache-2.0。
599
-
600
- ## [0.2.2] - 2026-11-01
601
-
602
- 只改元数据,不动行为。
603
-
604
- - `package.json` 补 `dsh.catalog`(category / 中英双语 summary / capabilities)——
605
- 社区插件市场直接读 npm 上带 `dsh-plugin` 关键词的包,每天同步一次、没有提交入口;
606
- 有 `dsh.catalog` 时市场页面展示的是这里写的分类和摘要,没有就退回 npm description。
607
-
608
- ## [0.2.1] - 2026-11-01
609
-
610
- 两项都是从社区审计(#18 / #16)来的,各配了回归用例。
611
-
612
- ### Added — 插件设置页(合 PR #11, closes #10)
613
-
614
- 设置直接渲染在 DSH 插件详情页(`plugins.bundle.config`),不再用 iframe / 内嵌滚动窗口;
615
- 「设置 → 内置插件」的 tab 也还在。
616
-
617
- - 表单:`browserPort`(共享 `video.json`)、`chatPort`(`watch.json`)、语音适配器(`voice.json`)。
618
- - **依赖自检**:ffmpeg/ffprobe、Python、`dsh-video-storyboard`、浏览器扩展、悬浮窗脚本;
619
- 缺什么就直接给官方下载入口,已装的显示「已安装」。插件**不会**静默安装或替你执行下载。
620
- - 修核心包误报:`dsh-video-storyboard/package.json` 不在 `exports` 里,改成解析 `dist` 信息。
621
-
622
- ### Changed — 悬浮窗换成实时捕获管线,模块拆成接口(合 PR #20)
623
-
624
- - **窗口实现换代**:`examples/floating-chat/window.py` 以 PR #15 的实时捕获管线为底稿重写
625
- (1454 行,原 3372 行)。每帧抓屏 → 1/4 尺度模糊 → SDF 边缘折射 → 透镜采样 → 合成,
626
- 静帧时整条管线跳过。**依赖变化**:`mss` 和 `numpy` 从可选变必需,缺了窗口起不来。
627
- - **保留并补齐交互**:双击标题改名、▾ 折叠/展开、系统行(meta)、发送回写、位置保存、
628
- 麦克风图标、滑入动画。输入框仍是"画布上画字 + 2×2 的 Entry 只收 IME/键盘"。
629
- - **模块解耦**:`src/interfaces.js` 组合识别 / TTS / 悬浮窗三个接口,`handler.js` 与
630
- `watch-loop.js` 只调接口、不再直接 import 实现(`docs/INTERFACES.zh.md`)。
631
- - **窗口线协议**:插件写 `window-events.jsonl`、窗口写 `window-outbox.jsonl`,
632
- Python 侧 `window_protocol.py` 只共享线格式;旧版只写 `chat.jsonl` 时窗口继续兼容。
633
-
634
- ### Fixed — 无音轨视频不再卡在"缺台词"门槛(fixes #18)
635
-
636
- `noListen` 之前只改了文案,**没有参与 `hasLines`** —— 无可等台词时 `segLines` 为空,
637
- `hasLines` 恒为 false,于是 `spoken` / `lastDelivered` 都不写,每次调用都落回同一段、
638
- 永远带 `[DELIVERY INCOMPLETE]`。这不是"模型不肯写台词",是状态机不推进。
639
-
640
- - `noLinesNeeded = Boolean(noListen)` 参与 `hasLines`:没音轨 / 没配 ASR / 连不上 / 这段真静音时,
641
- 画面这一半就算交付完成。
642
- - 没有台词可等时**不再提示"先取字幕"**(取了也不会有),也不说"本段台词已就绪"。
643
- - `[听音]` 段补一句"这一段也没有台词可等,用你看见的画面说一句即可,别编对白"。
644
- - **普通视频的台词门槛保持原样**:有声有字幕但没写台词,仍然 `complete=false`。
645
-
646
- ### Fixed — 叫醒失败不再刷屏,确定性失败不再空等(fixes #16)
647
-
648
- `no-session-controller`(当前进程没有 DSH 会话控制器)和 `no-session-id` 是**确定性**失败,
649
- 以前每次都要等 800ms 再重试,并且每次都往 `chat.jsonl` 写一条 `[一起看] 叫醒失败`;
650
- 持续故障时悬浮窗会被几十条一样的 meta 刷满。
651
-
652
- - 这两类失败**不重试**;其他偶发失败仍重试一次。
653
- - 失败提示按 `(sessionId, reason)` 节流:**60 秒内只显示第一条**,静默期里折叠掉的次数
654
- 在下一次显示时带上("同类失败另有 19 次已折叠")。
655
- - `no-session-controller` 的提示补一句可行动的说明(从 DSH 里启动,或先关掉陪看循环)。
656
-
657
- ## [0.2.0] - 2026-11-01
658
-
659
- 这一版把悬浮窗的玻璃重做了。三块独立玻璃、底色真正跟着背景走、静帧不空转、
660
- 边缘不再是"放大贴纸"而是把框外画面折进来;同时把「听不到声音」这件事从
661
- "模型答不上来"变成"能直接说清原因"。
662
-
663
- ### 听不到声音,不再只有一个答案
664
-
665
- 用户反馈(2026-11-01,B 站评论区):「能看视频,但是听不了」「没有音轨」。
666
- 文档里写清楚了要装 ASR,但**运行时没有任何地方告诉用户这件事** —— 模型只能回一句"我听不到",
667
- 用户于是以为插件坏了(同一个问题在评论区被问了十几遍)。
668
-
669
- - `explainCuesFailure()`:把每种原因翻成**一句能直接说给用户听的话**(没配 ASR / 装了连不上 /
670
- 这份副本没音轨 / 听了但没说话 / 字幕要登录)。`transcriptOnly` 的返回和陪看交付共用这一份文案,
671
- 不再各写一遍。
672
- - `asrCues` **不再把"没配 key"和"服务连不上"糊成 `asr-empty`**(那是"这片子没人说话",
673
- 一个会误导人的结论)。没配 key 时连请求都不发 —— 以前会照发,401 被吞掉。
674
- - 陪看交付新增 `[听音]` 段(同一部片子只详说一次,之后一句短的):用户问"你怎么听不到声音"时,
675
- 模型手里终于有依据。**没句子时门槛改成"用画面说一句、别编对白"**,而不是硬逼出一段台词。
676
- - 修 `findCachedMedia`:拿不到 BV 号时原来会 `return video` —— 返回媒体目录里碰到的**第一个**
677
- `video.mp4`,于是拿**另一部片子**的音轨去转写。台词全错,而且一句都不报。
678
-
679
- ### 玻璃底色跟着背景走
680
-
681
- 用户原话:「太卡顿,而且刷新很慢……经常是背景换了,液态玻璃还没动,还没变颜色。」
682
-
683
- 根因不在渲染算法,在**缓存永不过期**:整屏截图只在开窗那一刻做一次(`_stage` 的注释还写着
684
- "之后无论拖到哪儿都是裁一刀"),所以对面视频换场景、桌面换壁纸,这块玻璃永远是开窗时的颜色。
685
- 拖动结束后那个"8 秒才值得重截"的判定也救不了**静止**的窗口 —— 而陪看时窗口恰恰是静止的。
686
-
687
- 现在:
688
-
689
- - **按 TTL 定时重截**(`DSH_WATCH_GLASS_TTL`,默认 **600ms**,0 = 关掉回到旧行为)。
690
- - **截屏在子线程**(抓屏 + 1/4 缩放 + 模糊 + 色散 + 提饱和),主线程只做裁片 + 贴图(1~2ms)。
691
- Tk 对象一个都不在子线程碰 —— 屏幕尺寸、缩放系数都在主线程读好再传。
692
- - **优先用 `mss` 抓屏**(可选依赖,见 `examples/floating-chat/requirements-glass.txt`):
693
- 整屏 38ms vs ImageGrab 71ms,全管线从 ~200ms 降到 ~98ms,所以 TTL 才敢压到 600ms。
694
- 没装就自动退回 ImageGrab。
695
- - **新增 `_repaint_glass()`:只换玻璃不动内容**。`_paint()` 末尾会 `_reflow()` 重排所有气泡,
696
- 为了换一层底色付这个代价不值得;现在只 `delete("panel")` 再贴一张。
697
- - `_glass_busy` 防重入:上一发没回来就跳过这一拍;窗口隐藏/折叠时根本不截。
698
-
699
- 实测(本机 2560×1600 / 150% 缩放,TTL=500ms):3 秒内 6 次截屏,底板时间戳推进 3.3 秒,稳定。
700
- 抓屏基准:mss 38.3ms / ImageGrab 71.0ms;mss 全管线(抓 + 1/4 缩 + 模糊)98.6ms。
701
-
702
- **依赖**:Pillow + 可选 `mss`(**0.1MB**、纯 Python 无编译)。numpy 不需要。
703
-
704
- **踩到的坑**:第一版把 `_glass_ttl_start()` 插进了 `poll()` 末尾(那个方法每 200ms 自己再排一次),
705
- 于是每拍都重启一条定时链 —— 实测 3.2 秒触发 16 次、截屏频率飙到 9Hz。加了 `_glass_started` 锁。
706
-
707
- ### 液态玻璃重做(本轮)
708
-
709
- 三块**分离**的玻璃(标题栏 / 主体 / 输入栏,中间 10px 真缝,缝里透出桌面),
710
- 滚动条移到主体右侧外面,不占消息区。
711
-
712
- - **`WDA_EXCLUDEFROMCAPTURE`**:让窗口从屏幕捕获里消失,于是抓"自己背后"时
713
- **不用把 `-alpha` 设 0 再恢复** —— 那个来回会逼 DWM 把整个桌面重排两次,
714
- 视频在播时最贵,肉眼就是"松手闪一下"。`DSH_GLASS_WDA=0` 可关(录屏要用)。
715
- - **静帧跳帧**:用未模糊的原图缩到 48×30 比灰度差,`mean>0.8` 才算动了;
716
- 没动且运动已停 0.3 秒就直接复用上一帧,整条管线(抓屏 17ms + 糊 + 色散)全跳过。
717
- 慢速滚动不会先停一两帧 —— 阈值比"定时到点就重算"灵敏。
718
- - **边缘折射换成 SDF 法线向外采样**:老做法是"整图放大一点、再按边缘权重把放大版盖回",
719
- 边缘看到的是**自己被放大的内容**,像贴了层凸透镜贴纸。现在沿圆角矩形 signed distance
720
- field 的梯度法线**向外**取样本,边上一窄条里塞的是**框外**的画面,被压扁折进来。
721
- - **底板 1/8 → 1/4**:1/8 放大 8 倍时边缘和背景细节都发虚。
722
- - **文字可读性**:新增 `text_on_glass()`(整段文字 + 右下 1px 深色影子)和
723
- `on_glass_fill()`(按那个点的背景亮度决定用浅字还是深字)。影子用在气泡正文、
724
- 标题栏名字、系统行、输入槽;翻色用在标题栏名字。
725
- **没有逐字建 item** —— 玻璃上几十像素内明暗本来就不变,整段取一次样就够,
726
- 长列表滚动时 item 数不翻倍。
727
-
728
- **依赖**:Pillow + 可选 `mss`;**numpy 也是可选**(只给 SDF 折射用,没装自动退回老折射)。
729
-
730
- ### 参考并移植了上游的 PR
731
-
732
- - **#13 `feat/liquid-glass-speed`**:O(n²) → O(n) 的追加优化(只 layout 新气泡、resize debounce 70ms、
733
- Configure 合并到 16ms、after_idle 批量、mtime 缓存、玻璃尺寸没变不重画、拖动只画边框)。
734
- 它的数据是 210 条消息从 14.22s 降到 605ms(23×)。**这次没合**:那个 PR 基于 1314 行的旧
735
- `window.py`,我们这边已经 2632 行(液态玻璃二版 + 本轮改动),冲突面太大;但思路(尤其
736
- "玻璃尺寸没变不重画")以后可以逐条移植。
737
- - **#15 `feat/live-glass-window`**:独立一套 `glass_window.py` / `glass_window_gpu.py`。
738
- **没有整包拿过来**(它是第二套 UI,切过去会丢掉气泡、meta、入场动画、折叠、改名这些交互),
739
- 而是逐项移植了它的机制:`WDA_EXCLUDEFROMCAPTURE`、静帧跳帧、SDF 法线折射、1/4 底板、
740
- 文字影子与按背景翻色。GPU 合成(moderngl)没有采用 —— 需要额外依赖且仅限 Windows/OpenGL 3.3+。
741
-
742
- ## [0.1.1] - 2026-11-01
743
- **依赖升到 `dsh-video-storyboard@^0.6.0`。** 分镜从"固定宫格"改成"档位排布"——
744
- 一格 = 一个镜头、格子大小跟切点密度走,`boardOptions()` 返回的参数从
745
- `cells / sheets / minGap` 换成 `maxFrames / maxSheets / minFrames`。旧的参数名在 0.6.0 里已经不存在,
746
- 所以这一版**必须**配 0.6.0 及以上,不能和 0.5.x 混装。
747
-
748
- ### 台词写完之后不再递整段清单(防剧透)
749
-
750
- 用户反馈"老是剧透后面的"。根因不是提示词不够狠:写台词时必须把整段 5 分钟的清单交出去,
751
- 写完它仍然留在上下文里,模型就会把它当成"我知道后面"的凭据 —— 光说"不许提"压不住真实内容。
752
- 现在台词一就绪就换成一句简报("台词已就绪,清单不再提供"),模型手里真的没有后面的信息。
753
-
754
- 顺带在提示词里加了一句自问:「这句话是不是只有已经看过 xx 秒之后的人才写得出来?」
755
- 不确定的事用"现在"而不是"接下来"。
756
-
757
- ### Liquid glass, second pass — the window was still ugly (2026-11-01, later)
758
-
759
- Verbatim feedback: "看一下 watch-together 的悬浮窗设计,太丑了现在" — the first liquid-glass pass
760
- had the vocabulary right and the physics wrong. Five defects, all of them visible in a screenshot:
761
-
762
- **The corners were not round.** `round_rect` and `squircle_mask` both used a superellipse with
763
- `n = 5`, and at `n = 5` the curve is within 0.6% of the straight edge until the last few pixels —
764
- a 22px radius rendered as a near-square corner with a tiny fillet. `squircle_mask` had a second,
765
- independent bug: the row-solve was inverted (`x` grew from 0 instead of `r`), which cut the corners
766
- out as *squares*. Both now use `n ≈ 2.2` and solve each row's span directly (O(h) instead of O(w·h),
767
- and it buys 2× supersampling for free).
768
-
769
- **The chrome was opaque.** The header was a `tk.Frame` and the composer a second one; Tk widgets
770
- must have an opaque background, so the top and bottom strips of a "glass" window were dead black.
771
- Both are now drawn on the canvas (status dot, title, count, `▾`/`✕` as hit-tested canvas items,
772
- the input well as a rounded polygon). Only the `Entry` stays a real widget — it has to be opaque, so
773
- it lives inside a deliberate *inset* well.
774
-
775
- **Bubbles were paper.** Each one was filled with a flat `#3a4459`. They are now cut from the same
776
- blurred backdrop as the panel (`plate()`), with only a white/blue wash on top — they transmit what
777
- is behind them.
778
-
779
- **Tint was global and blue.** One tint for the whole window, and a blue-grey `#171a21`, which fights
780
- every colourful frame it sits on. Tint is now per-plate and *neutral*: measure that plate's mean
781
- luminance and solve for "how opaque does the ink need to be to land under 84" (`a = (L-84)/(L-12)`).
782
- Over a white page it darkens itself; over a dark scene it stays transparent.
783
-
784
- **The sheen was made of lines.** Diagonals stacked with a 3px step left a visible weave across the
785
- panel. Every gradient is now computed on a 16×16 canvas and upscaled bicubically.
786
-
787
- Also added: **dispersion** (warm outside, cool inside, full strength around the whole chamfer and
788
- stronger at the four corners, because a fillet has curvature everywhere but compound curvature at
789
- the corners), **edge fading** in the message list (rows fade in/out across a 30px band instead of
790
- popping at the clip boundary — suppressed on the side that has no more content, otherwise the newest
791
- message is permanently the faintest), a **200ms entrance** per new bubble (8 frames: 10px rise +
792
- alpha ramp + text colour lerp), and **smooth scrolling** (5 frames × 16ms) so the fade band has
793
- something to fade across. The scrollbar moved out into the margin beside the panel.
794
-
795
- Two long-standing bugs fell out of this: `Meta.paint` ended with a leftover `self.cv.tag_lower("bg")`
796
- from the pre-canvas version — `Meta` has no `cv`, so the exception aborted `_reflow` mid-list and only
797
- the newest message was ever visible; and the backdrop image was created after the messages without
798
- `tag_lower`, so any repaint buried them.
799
-
800
- ### Performance — the glass was re-baked on every frame (2026-11-01, same session)
801
-
802
- "背景的模糊还是很卡" — measured, not guessed. One panel plate cost **520ms**, a slab 90ms,
803
- a bubble 28ms. The culprit was `_ring`: it built **two full-size fill masks and subtracted them**,
804
- and every plate needs five or six rings (rim, soft rim, bottom shade, warm, cool, edge weight), so
805
- a 665×594 panel spent ~100ms in that one function plus ~15ms per `squircle_mask`.
806
-
807
- Three fixes, in order of payoff:
808
-
809
- - **Ring solved per row, no intermediate images.** A ring's row is just two short segments — left
810
- and right — so the inner and outer x are solved directly (`_ring`), and middle rows are skipped
811
- entirely. O(h) instead of O(w·h), and no subtraction allocations. 100ms → 3.7ms.
812
- - **Everything smooth is computed at ¼ scale.** `_corner_weight`, `_edge_weight` and `refract`'s
813
- bevel weight are soft blobs, not features: build them at 665/4 and upscale bilinearly. Gaussian
814
- blur cost drops 16×, and the bevel mask (14 rectangle outlines over the full image) went from
815
- ~20ms to ~1ms.
816
- - **Supersampled masks now downsample with `Image.BOX`** instead of LANCZOS. For an exact 2×
817
- reduction BOX *is* the 2×2 average — same result, ~4× faster. `squircle_mask` 15ms → 4.9ms.
818
-
819
- Result: panel 520 → **50ms**, slab 90 → **6.8ms**, bubble 28 → **8ms**; `_paint` with a warm cache
820
- **1.3ms**, `_reflow` **0.5ms**, cold repaint (backdrop changed) **76ms**, window open **387ms**.
821
-
822
- Also: the R/B channel-scaled displacement (`chroma_edge`) is now **off by default**
823
- (`DSH_WATCH_CHROMA_EDGE=1` turns it back on). It cost two full-size channel resizes per plate
824
- (+18ms) and was invisible — the backdrop is already blurred and inked, so there is no contrast left
825
- at the rim to disperse. The visible dispersion is the warm-outside/cool-inside tint pair, which stays.
826
-
827
- Finally, resizing no longer re-bakes: while the resize grip is held the panel is a bilinear scale of
828
- the last baked plate (1.2ms instead of 50ms), and a precise re-bake happens 300ms after release.
829
-
830
- ### Performance, second pass — the backdrop was recomputed on every mouse release (2026-11-01)
831
-
832
- "超级卡,绝对不止一两百毫秒" … "拖动根本不会刷新" … "碰到屏幕边缘松手百分百闪一下".
833
-
834
- Measured, the picture was different from the first pass: `_paint` was already fast (1.3ms warm),
835
- but **every time a drag or resize settled**, `_refresh_backdrop` cost **165ms** — and during the drag
836
- the backdrop never updated at all, because refresh was debounced to 420ms after release.
837
-
838
- What was actually slow, in order of payoff:
839
-
840
- - **`_ring` built two full-size fill masks and subtracted them**, and every plate needs five or six
841
- rings. Rewritten to solve each row's inner and outer x directly and draw two short segments —
842
- O(h), no intermediate allocations. 100ms → 3.7ms per plate. (While rewriting it I dropped the
843
- `width` argument on the floor: the band came out as "from the edge to `inset`", which made a
844
- 1px highlight vanish entirely and pushed the inner shade line onto the rim, darkening it. The
845
- tell was "the glass has no edge and looks grey". Fixed by solving both boundaries properly.)
846
- - **Everything smooth is now built at ¼ scale and upscaled**: curvature weight, dispersion weight,
847
- and the bevel weight in `refract`. They are blobs, not detail. Gaussian cost drops 16×.
848
- - **The "light" layers are pure geometry** — sheen, rim, inner shade, warm/cool fringes do not
849
- depend on the backdrop at all. They are composed once per size into `_light_overlay` and cached;
850
- a re-bake now pays one `alpha_composite` instead of six.
851
- - Tint and wash are both flat colours over flat colours, so they are blended into a single colour
852
- and applied once. Mean luminance is measured on a 48×48 copy (the mean does not care about
853
- resolution). 2× supersampled masks downsample with `Image.BOX` instead of LANCZOS.
854
- - **The stage is now one full-screen capture at ¼ resolution**, taken at open while the window is
855
- still withdrawn. Any later position is a *crop*, never a re-grab — the old "window + margin"
856
- stage ran out of bounds whenever the widget was near a screen edge, and falling out of bounds
857
- is exactly the "release → hitch → flash" the user was seeing.
858
- - **Dragging refreshes live**: `_live_backdrop()` crops from the stage and `_paint_glass_only()`
859
- swaps only the panel and the two slabs — the header, bubbles and composer do not move relative
860
- to the window and are not redrawn. Throttled to 30ms (the mouse is 120Hz). Two hidden costs fell
861
- out of this: `_window_rect()` calls `update_idletasks()`, which silently ran a *full* repaint on
862
- every frame (+17ms), and position-only `<Configure>` events repainted the entire window.
863
- - Bubble plates are invalidated by their own counter (`chat_glass_ver`), so a small drag no longer
864
- re-bakes six bubbles per frame; only panel/slab caches are dropped.
865
- - Edge-of-screen windows now only need to *overlap* the stage, not sit inside it; the off-screen
866
- part is cropped short and padded. And a settle within 8s of the last capture does not re-capture
867
- at all — the stage is refreshed for free while the window is hidden.
868
-
869
- Numbers (665×594 panel, 150% DPI): a panel plate 520ms → **7.7ms**, slab 90 → **0.9ms**, bubble
870
- 28 → **0.9ms**; `_paint` warm 1.3ms, `_reflow` 0.5ms; **dragging costs 24–28ms per frame (~38fps)
871
- where it used to be frozen**; window open 510ms including the full-screen stage.
872
-
873
- ### Fixed — optional services must go through `ctx.get()`
874
-
875
- `ctx?.attachments?.saveImage` looks like a runtime probe but throws in a real host: cordis's `ctx`
876
- is a Proxy whose `get` trap **throws** `cannot get property "xxx" without inject` when a service was
877
- not declared in `inject`. `?.` only guards `null`/`undefined`, not exceptions.
878
-
879
- All optional-service lookups now go through `serviceOf(ctx, name)` (in `src/timer.js`): it prefers
880
- `ctx.get(name)` — cordis's documented way to ask for an optional dependency, returning `undefined`
881
- when absent — and only falls back to property access inside a `try`.
882
-
883
- ### Liquid-glass window, one stream, and a name you can change (2026-11-01)
884
-
885
- Reported as: the scripted lines (warm amber, with a "台词" label) and the assistant's replies (cool
886
- grey, labelled "陪看") read like two different people talking in one stream — and the window itself
887
- looked like a plain dark panel.
888
-
889
- **One stream, one look.** `ROLE` now maps `line` and `assistant` to the *same* colours, and the head
890
- line shows **only the timestamp** — no "台词", no "陪看". Only the user's own messages keep a tint
891
- (so you can still tell which side you are on).
892
-
893
- **Timestamps are wall-clock now** (`HH:MM:SS`), for every role. Scripted lines used to show their
894
- playback position (`01:26.0`) while everything else showed local time — two time bases in one
895
- stream, so reading it meant converting in your head. Seconds are included because a segment runs
896
- 2–5 minutes and several messages share the same minute; `HH:MM` alone would make the stamps useless
897
- for telling them apart. A message with no `at` gets no head line at all (an empty label still eats
898
- a full line of height).
899
-
900
- **Liquid glass.** Three things carry the effect, because tkinter cannot blur what is behind it:
901
-
902
- - **24px+ radius** — and `round_rect` no longer uses `smooth=True`, which renders a 22px radius as
903
- roughly 14px (it smooths a polygon rather than following an arc). It now samples each corner arc
904
- directly.
905
- - **A refractive edge**: a 1px inner highlight along the top, plus an outer border split into a lit
906
- upper half and a shadowed lower half — what a real piece of glass does.
907
- - **Slight window transparency** (`-alpha 0.975`, `DSH_WATCH_GLASS_ALPHA` to tune, ≥1 disables).
908
- The desktop shows through just enough to read as glass without competing with the text.
909
-
910
- Buttons and the input field are **pills** now (`Pill` class + a Canvas-backed field): a square
911
- "发送" button next to a 24px-rounded panel was the most obviously un-Apple thing left.
912
-
913
- **The title is editable.** Click the name in the header, type, press Enter — saved as `name` in
914
- `~/.dsh/watch-window.json` and restored next launch. Committing uses an explicit `_editing` flag
915
- rather than `winfo_ismapped()`, which is still `False` on the frame right after `pack()` and would
916
- silently swallow a fast Enter.
917
-
918
- **Fixed:** `meta` entries (wake failures, mic status) were falling through to the assistant bubble
919
- style — a screenful of `[一起看] 叫醒失败` rendered as full-size cards. They now use the grey
920
- one-line `Meta` row that already existed for exactly this.
921
-
922
- **Fixed:** the saved geometry was clamped against `sw - 120` instead of the window's own width, so a
923
- 700px-wide window could be restored 580px off the right edge.
924
-
925
- ### No more self-made "queued messages", one reminder per interjection, and a hideable window (2026-11-01)
926
-
927
- Reported as three things that turned out to be one root cause plus two design gaps.
928
-
929
- **The queue strip.** `wakeSession` delivers through `agent.followup()`, which lands in the host
930
- inbox's `next-turn`. DSH's `QueueDock` renders **every** row of `next-turn` and does not filter by
931
- `source.kind` — so the plugin's own instructions showed up in the input box as pending messages the
932
- user never typed ("插话栏自动出现"). Two consequences fixed here:
933
-
934
- - **The hangup note no longer goes through `followup`.** Closing the window is still a hangup (clock
935
- stops, nothing is rebuilt, no lines are spoken), but the explanation is now written into
936
- `watch.json` and handed to the model on its next tool result (`takeHangupNote`). The watch loop
937
- already has the model blocked inside an interrupted tool call, so nothing is lost — and the queue
938
- strip stays empty. `markHungUp(input, env, note)` carries the text; taking it clears it.
939
- - **`[未回应]` is emitted once per interjection.** It used to be appended to *every* tool result
940
- until the model answered with `say`, so one message from the user could be read as three separate
941
- events ("大肥鱼已经重复了"). `noteInterjected` also no longer restarts the clock when the same
942
- sentence arrives twice inside the 3-minute TTL.
943
- - **The interjection prompt is two sentences, not a wall of ⚠️.** Same requirements
944
- (`say` first, `speakNow`, lines in the same call), a fifth of the length — it is rendered in the
945
- queue strip, so its size is user-visible.
946
-
947
- ### `window: "hide" | "show"` — put the window away without ending the watch
948
-
949
- Closing the window means "I am done watching". Hiding it does not: the process stays alive, the
950
- clock keeps running, lines keep being spoken, nothing is marked as hung up. Reported as
951
- "如果有其他功能隐藏悬浮窗会更好".
952
-
953
- - `watch_together({ window: "hide" })` writes `hidden: true` into `~/.dsh/watch-window.json`;
954
- `window.py` polls its config every 200 ms (`_sync_visible`) and does `withdraw()` / `deiconify()`.
955
- `withdraw` rather than `iconify`: an always-on-top floating window should leave no taskbar entry
956
- behind.
957
- - `openFloatingWindow` clears `hidden` **before any early return**, so a window that was hidden when
958
- the process died does not come back invisible.
959
-
960
- ### Two-track prefetch (2026-11-01) — subtitles no longer wait for the pictures
961
-
962
- The picture side is the slow one: a segment costs a download plus a scan (10–20 s, 20–90 s for the
963
- first), while the text for the same window arrives in a few seconds (site CC: instant; local ASR
964
- RTF 0.019 ≈ 6 s per 5-minute segment). They used to be produced and delivered as one package, so
965
- the text sat in the slow batch's shadow. Now they are two independent tracks over the **same**
966
- batch table and the **same** look-ahead window.
967
-
968
- - **New subtitle track** (`transcribe` → `dsh-video-storyboard/transcript-pass`). Mirrors the picture
969
- track line for line: same `plan.indexAt` / `windowAt`, its own `transcribed` set. "Whoever's window
970
- is full stops first" falls out of `find()` returning `undefined` — no extra rule.
971
- - **Two-part delivery.** When the text lands before its pictures, it is sent on its own
972
- (`[一起来看·台词] 03:00–06:00` + one timestamped sentence per line). When the picture batch
973
- arrives later it is built with `omitTranscript`, so the cells carry only times and the sentences are
974
- not repeated (measured: 17k vs 26k tokens per 2 hours, +50% when repeated).
975
- - **`feedTranscriptLeadMs`** (default 0 = send as soon as it lands). Raise it to ~20000 if the
976
- two-part delivery feels chatty and you would rather wait for one combined message.
977
- - **`transcriptTrack: false`** turns the whole track off.
978
- - **Failures don't sink the loop.** A failed transcription is not marked as done, so the next tick
979
- retries; three failures in a row blacklist that segment for 10 minutes (a missing ASR service
980
- should not be hit every 2 seconds). The picture track is never blocked by it.
981
- - **Cross-track timestamps now share one clock.** `transcribedAt` / blacklist times were stamped with
982
- `Date.now()` while the tick compares against the injectable `deps.now()`; the difference was
983
- negative by a trillion milliseconds, so the "skip for 10 minutes" and "wait N ms before feeding"
984
- gates were both permanently bypassed (feeding never fired at all).
985
-
986
- ### Experience pass (2026-11-01) — the minutes spent staring at nothing
987
-
988
- Same code, same contract; what changes is what the user sees (or hears) while waiting.
989
-
990
- - **A slow build now says something.** The first batch of a film needs a download plus a scan
991
- (20–90 s) and a tool call cannot speak — so the window stayed empty and the only signal was
992
- silence. After 4 s of building (`DSH_WATCH_SLOW_BUILD_MS`) one `meta` line is appended to the
993
- stream: 「正在取 03:00–06:00 这一段…」. Fast segments write nothing.
994
- - **The measured latency is finally used on the main path.** `latency.js` has been calibrating
995
- "read position → result ready" for a while, but only the background clock (`shouldSpeak`) spent it;
996
- the blocking call still waited until `segment end - lead`, so on the same machine the clock spoke
997
- early and the tool call spoke late. `deliveryState` now uses `lead + aheadSeconds`, while the text
998
- still reports `lead` (what is pulled earlier is the work, not the sentence).
999
- - **Calibration only counts deliveries.** Not-yet calls take tens of milliseconds and are not samples;
1000
- recording them dragged the EWMA towards zero (and wrote `latency.json` on every poll).
1001
- - **The last batch is delivered at the tail.** The final segment's due point is `end - lead`, which for
1002
- the last batch sits past the end of the film — the position never reaches it, so the user watched
1003
- the ending and got nothing. Reaching/passing `dur - 1` now counts as due.
1004
- - **`speech` only lists lines that are still ahead.** It used to echo the whole draft, including the
1005
- lines the same call had just pruned as past — the model read them as "still going to be spoken".
1006
- - **Delivery guidance trimmed ~45%** (≈1150 → ≈640 chars). It is resent every batch; the loop/pacing
1007
- rules already live in the tool description, so only the hard rules stay here: write the lines,
1008
- no spoilers, one sentence, `say` is the only visible channel.
1009
-
1010
- ### Reading pass over the loop (2026-11-01) — six real bugs, one hot path
1011
-
1012
- No new features. Everything below was found by reading the code against its own comments and then
1013
- reproducing it; each fix carries a regression test that fails on the old code.
1014
-
1015
- - **`lastDelivered: null` was read as batch 0.** A delivery blocked by the "no lines yet" gate writes
1016
- `lastDelivered: null`, and `Number(null)` is `0` — exactly the first batch's start. That batch then
1017
- counted as already delivered forever: `wait: true` woke up and answered "already delivered", image
1018
- and manifest never handed over. Empty now stays `NaN`.
1019
- - **Same film, two URL forms → the loop restarted.** `samePlan` compared the raw `input` string, but the
1020
- extension reports `…/BV1g3xN6hEuw/?trackid=…&spm_id_from=…` while the model usually holds the clean
1021
- link. Every second call therefore looked like a new source, wiping `spoken` and re-waking segments
1022
- that had already been delivered. It now compares `sessionKey()`.
1023
- - **`dur: null` became `0 s` on the bridge path.** `Number.isFinite(Number(s.dur))` passes for `null`,
1024
- so a report without a duration set the baseline to 0; the next real reading (600 s) then differed by
1025
- more than a second and was judged "video changed" — the clock stopped mid-film. `num()` in
1026
- `position-bridge.js` and the baseline update now treat empty as empty.
1027
- - **`waitForVideo` lost the hangup.** The input surface is prepared once (`prepared ??=`), and the
1028
- early pre-warm for `waitForVideo` passed no arguments — so `input`/`open` never reached it. Without
1029
- `input` the recorded hangup could not be matched, the window was re-opened, and the call went off to
1030
- wait for a video instead of returning `[hangup]`.
1031
- - **`dueLine` rewrote `watch.json` on every tick.** Its `dirty` flag was shared across segments: once one
1032
- batch had pinned its un-timed lines, every later batch was written back unchanged — a full state write
1033
- every 2 s for the rest of the film. The flag is per segment now.
1034
- - **`waitUntil` / `waitForRefill` lied about why they stopped.** Breaking out because the user paused (or
1035
- the film ended) still produced "waited to the cap". The text now names the real reason.
1036
-
1037
- Hot path, same area:
1038
-
1039
- - `cachedCues()` re-read and re-parsed the whole subtitle file on every tick (`dueLine` asks several
1040
- times per tick). It is memoised on `path + size + mtime` now, and returns the **same array** so that
1041
- `makeLagFn`'s memo can be keyed on array identity. `makeLagFn` additionally sorts once and looks up
1042
- by binary search instead of a linear scan of every cue. 2000 cues × 5400 lookups: **66.7 ms → 0.8 ms**
1043
- (×83), and the disk read/parse per tick is gone.
1044
- - `lines-util.js` had its own `cacheDir()` that fell back to `~/AppData/Local` on every platform, so on
1045
- Linux/macOS the subtitle cache landed in a directory that does not exist; it now uses the storyboard's
1046
- `cacheDir()`. `findCachedMedia()` likewise uses `tmpdir()` instead of `LOCALAPPDATA/Temp`.
1047
- - Dead exports removed: `plan.starts` (a 513-element array allocated on every `makePlan`),
1048
- `legacySessionKey`, `wasWritten`, `MATERIAL_PARTS`. The input surface failing to start no longer fails
1049
- the whole call — it is reported in the result instead.
1050
-
1051
- Three rounds on 2026-10-31. The through-line: the plugin knew something, and the model (or the user)
1052
- never found out — plus one window that needed to look like something people want to keep on screen.
1053
-
1054
- ### Long-video recap — merged, but opt-in
1055
-
1056
- PR #2, after one round of review. Its first shape prepended a 420-character `[前情]` to **every**
1057
- delivery, partly built from the model's own scripted lines: second-hand context in a package whose
1058
- contract is "raw material only — never retell what the user just watched", at ~200 tokens per
1059
- segment, with no evidence it helped.
1060
-
1061
- What shipped instead: off unless `recap: true` or `DSH_WATCH_RECAP=1` (`recap: false` beats the env
1062
- var); only **cached subtitle sentences**, never the model's lines; `recapSegments` 1–3 (default 2),
1063
- `recapMaxChars` 80–1200 (default 420); never reads past the current segment, never trims the live
1064
- transcript, no ASR, no network. Whether it actually reduces retelling is still **unmeasured** — it
1065
- stays opt-in until somebody measures it.
1066
-
1067
- ### Observability: `statusOnly` can now answer "why is it slow"
1068
-
1069
- Promised in issue #4. `pos + reason` says *what* the clock thinks, not *where it is stuck*.
1070
-
1071
- - `segment { index, from, to, delivered, total }` — which batch, its bounds, how many were delivered
1072
- this session, how many the film has (`total` is `null` when the duration is unknown). The last batch
1073
- index is taken at `dur - 1 ms`, because a duration that lands exactly on a boundary would otherwise
1074
- report one batch too many.
1075
- - `speech { queued, lastLateSec, busyUntil }` — lines still waiting, how late the previous line was
1076
- (from `dueLine`'s new `meta: true`, which also keeps the plain-string return for old callers), and
1077
- when the serial voice engine frees up.
1078
- - `build { inflight, cached, lastMs }` — which batch is being built, how many are cached, how long the
1079
- last build took. The cache is passed into the loop for reporting only; it never influences a decision.
1080
- - `queued` needs a disk read, so it is filled in `statusOnly` only, and a failure there is reported as
1081
- `speech.queueError` instead of being swallowed (the first version of this swallowed a `ReferenceError`
1082
- from a missing import and looked exactly like "there are no lines").
1083
-
1084
- ### The floating window, rebuilt
1085
-
1086
- "这个悬浮窗太丑了" — fair. The old one was a borderless frame with a `Text` widget that painted
1087
- role-coloured **full-width stripes**, on a window Windows stretched from 96 dpi, reading the whole
1088
- `chat.jsonl` every 200 ms.
1089
-
1090
- - **Real bubbles.** Each message is its own rounded card (Canvas background + wrapped Label), sized
1091
- to its content: script lines in amber with a left rule, the model in slate, the user's own words
1092
- right-aligned in blue. Above each one, a muted line saying who and when (`台词 04:12.3` for a
1093
- scripted line, `我 21:16` for chat).
1094
- - **Per-monitor DPI awareness** before the window exists, and every size/font derived from the real
1095
- scale factor. Unaware Tk windows are bitmap-stretched at 125/150%, which reads as "blurry and wrong".
1096
- - **Rounded window** via `-transparentcolor` (Windows only; falls back to square corners), a 1 px
1097
- border, and a hand-drawn 6 px scrollbar that only appears when the list actually scrolls.
1098
- - **Does not steal focus.** `focus_force()` at startup meant pressing space to pause the video landed
1099
- in the chat box; now the entry only takes focus inside the window.
1100
- - **Does not fight your scrolling.** New lines auto-scroll only if you were already at the bottom.
1101
- - **Incremental read.** Only the bytes appended since the last tick are parsed, and the first paint
1102
- replays just the last 60 entries.
1103
- - Resizable from the bottom-right grip; position and size persist in `~/.dsh/watch-window.json`.
1104
-
1105
- ### Stop when the signal says stop: hangup, dead source, switched video
1106
-
1107
- Reported as "换片或者我都关浏览器了还在念台词" and "关了悬浮窗 AI 还是会自动调出来,根本不会自动结束".
1108
- Both were the same shape: the plugin knew the source was gone, and kept talking anyway.
1109
-
1110
- - **Speech now requires a believable position.** The line queue only fired when the position was
1111
- `fresh`, or `extrapolated` within `SAFETY_AFTER_MS` (20 s — the normal gap between probes).
1112
- Before, the only thing excluded was `paused`; `estimate()` happily extrapolates a dead source
1113
- forward and `pos` stays finite, so closing the browser kept reading lines out for minutes.
1114
- Nothing is spoken on an `unknown` position, and the position-unknown give-up dropped from
1115
- 10 min to 5 min (the watch should not sit there pretending).
1116
- - **Closing the floating window is a hangup, treated like an interjection.** The window is the only
1117
- way to talk mid-watch, so closing it means "I'm done":
1118
- - the clock stops and **really wakes the model** — `wake:false` (the default) used to silence this
1119
- too, because it shared the `wake` path with the segment-end reminder. User actions (hangup,
1120
- video changed, video ended, seek, unreadable position, high-frequency mode) now use a separate
1121
- always-real channel (`wakeSignal`), and the message says **do not call watch_together again and
1122
- do not read out any more lines**;
1123
- - the guard is stored on the loop and can be turned on later (`resumed` path used to freeze it,
1124
- so a window opened by an earlier call was never guarded);
1125
- - the next tool call **does nothing at all**: no frame, no clock, no window (`[hangup]` result).
1126
- `sameWatch` previously required `args.input`, which the model never sends — so every call looked
1127
- like "a new watch" and re-opened the window the user had just closed.
1128
- - `wakeWithRetry` called an undefined `note()` in its failure branch (a `ReferenceError` swallowed by
1129
- the ticker). Real wakes can fail, so it was reachable; now it records into `loop.logs`.
1130
-
1131
- Tests: 247 pass, +4 in `test/hangup-guard.test.mjs` (dead source sends nothing, live source still
1132
- speaks, hangup wakes with the right wording, post-hangup call is inert).
1133
-
1134
- ### Interjections: speak first, then look
1135
-
1136
- Reported as "它一声不吭先去 zoom,回来才说话". The root cause was not the model: a normal reply
1137
- never reaches the floating window — only `say` does and only `say` is spoken. So "think, then look,
1138
- then answer" was, from the user's side, complete silence for tens of seconds.
1139
-
1140
- - One wording, one place (`src/interject.js`) for all five entry points (during a build, during the
1141
- lookahead fill, during a blocking wait, `waitUntil`, `nextLine`). It now says exactly what to do:
1142
- `watch_together({ say: "我看一眼", speakNow: true })` — one call, words written before any frame
1143
- is built. `lines` and `say` can ride in the same call, so "台词优先" no longer means "stay silent".
1144
- - Unanswered interjections are **tracked**: the next tool result ends with `[未回应] …你还没回`,
1145
- until a call actually carries `say` (expires after 3 min). Previously the reminder existed only
1146
- inside the message that woke the model, which it had already scrolled past.
1147
- - `waitUntil` / `nextLine` called a function that **did not exist** (`chatResult`) — an interjection
1148
- during either wait threw `ReferenceError` and the tool failed. Defined, and it reuses the same wording.
1149
- - Waiting for a video to appear returned a result **without `text`**, which the host's `output.schema`
1150
- requires. That path now returns a proper result.
1151
-
1152
- ### Reply vs. scripted line: 12-second guard
1153
-
1154
- Reported as "说话和插话的回复离太近,把后面那句改一下". Two lines spoken back to back on a serial
1155
- TTS chain means the second one either drifts or is dropped by the adapter (queue > 3.5 s → `skipped`).
1156
-
1157
- - `say` now marks the voice engine busy for its full spoken length (`src/reply-guard.js`), so the
1158
- loop stops feeding scripted lines while a reply is still playing. Previously only the loop's own
1159
- lines updated that clock — a reply was invisible to it.
1160
- - Lines scheduled within 12 s of a reply are **withdrawn from the batch and handed back** to the
1161
- model (`[lines·太近]`) with instructions to rewrite them around what was just said, or drop them.
1162
- Withdrawn, not silently deleted: the user asked for "改一下", not "少一句".
1163
-
1164
- ### Switching videos is noticed in ~2 s, not ~15 s
1165
-
1166
- - The per-tick bridge read (every 2 s) now does the switch / end-of-video / big-jump checks, and
1167
- keeps the `dur`/`url` baseline up to date. Before, all three lived in the 15-second CDP probe
1168
- branch only, so a switch could go unnoticed for a quarter of a minute — while the clock kept
1169
- computing segment boundaries against the old film.
1170
- - The blocking wait in `watch-run` now compares each read against the film it started with and
1171
- returns `[video-changed]` immediately. **This was the only reliable path**: the loop's wake goes
1172
- through `followup()`, which is delivered *after* the current tool call returns — and that call was
1173
- busy waiting.
1174
- - `sourceSwitched()` centralises the test, and `Number(null) === 0` is explicitly guarded: a
1175
- not-yet-known duration used to look like a "0-second film" and stop the watch instantly.
1176
-
1177
- ### Cold start: don't wait a full minute for a video we can already identify
1178
-
1179
- - The extension only reports while the tab is **visible** — and "一起看" is usually typed in another
1180
- window. The position went stale after 5 s, the plugin concluded "no video", and sat in the 60 s
1181
- wait. It now falls back to a **stale** sample (up to 2 min) to identify the film, marks the
1182
- position `stale`, and lets the next fresh reading correct it.
1183
- - Automatic waiting (no `waitForVideo`) dropped from 60 s to **20 s**; explicit `waitForVideo: true`
1184
- stays at 120 s.
1185
- - `probeBrowser()` is skipped when the extension already reports: one probe is `listTargets`
1186
- (1.2 s) plus up to 8×1.5 s of CDP round-trips — pure overhead for a `browser:` line the extension
1187
- just answered. The line now reads `browser: extension reporting <title> playing 03:20`.
1188
-
1189
- Tests: 243 pass (`node --test`), 6 of them new in `test/interject-reply.test.mjs`.
1190
-
1191
- ## [0.1.0] - 2026-11-01
1192
- 首个发布版本。要求 `dsh-video-storyboard@^0.5.11`(字幕轨用到它的 `./transcript-pass` 子路径)。
1193
-
1194
- ## [0.0.7] — 2026-10-31 (first release)
1195
- The first published version. One tool, `watch_together`: it follows the user's real playback
1196
- position, hands the model one storyboard + transcript per segment just before that segment ends,
1197
- and speaks the scripted lines at the second they belong to.
1198
-
1199
- **Licence: Apache-2.0** (the package was developed under MIT and switched before the first
1200
- public release, to match `dsh-video-storyboard`). `LICENSE` is the full text, `NOTICE` states
1201
- what the project deliberately does **not** do — no hosted video, no uploaded position, no DRM or
1202
- paywall bypass, no bundled TTS engine.
1203
-
1204
- ### Repo hygiene — the extension's manifest and icons were never committed
1205
-
1206
- `.gitignore` carried `manifest*.json` and `*.png` (meant for CLI artifacts). Those two rules also
1207
- swallowed `extension/manifest.json` and `extension/icons/*.png`, so a clone would have shipped an
1208
- extension **with no manifest** — completely broken, and nothing would have failed until someone tried
1209
- to load it. Both are now force-added, and the ignore rules are anchored (`/*.png`, `/*.meta.json`) so
1210
- they can only ever catch files at the repo root. Also: `* cookies*.txt` (a pattern with a space, which
1211
- never matched anything) is gone, `__pycache__` is out of the npm tarball via a new `.npmignore`, and
1212
- `npm test` no longer requires the sibling `dsh-video-storyboard` checkout — it falls back to the
1213
- installed copy, so a clone can run the suite.
1214
-
1215
- ### Docs — one page per service, and the stale one is gone
1216
-
1217
- `docs/WATCH.zh.md` still explained how to configure things around the **OS media session (SMTC)**,
1218
- which was deleted a while ago: wrong rationale, wrong `confidence` values, wrong defaults. Deleted.
1219
- Replaced by [`docs/CONFIG.zh.md`](docs/CONFIG.zh.md): ffmpeg → yt-dlp + cookies → subtitles/ASR →
1220
- browser extension (9377) → debug port (9333) → voice (`voice.json` + `tts.json`) → floating window →
1221
- cache locations → a one-page troubleshooting table. Every entry says **what breaks if you skip it**.
1222
-
1223
- `README.md` got a 30-second start, a "what to configure" table, a corrected parameter table
1224
- (`depth` is auto-by-time now, `lookahead` was missing), a CLI table that matches the 15 real
1225
- subcommands, a privacy note for the extension, and a dev section. `docs/VOICE.zh.md` gained
1226
- `state: 'skipped'` and a correction: `at` is a **playback second**, not a wall-clock timestamp.
1227
-
1228
- ### `doctor` — three levels, because "not configured" is not "broken"
1229
-
1230
- `FAIL` used to be printed for things that are merely "not set up yet": a missing cookie file (only
1231
- needed for Bilibili), a closed debug port (the extension is the recommended channel), an extension
1232
- that is loaded but has no video playing. First-run users read that as "something is broken" and went
1233
- to reinstall the extension. Now: **OK / WAIT / FAIL**, only `plugin` and `ffmpeg` are fatal, and when
1234
- the extension has checked in but nothing is playing, `doctor` says `READY — 播个视频就能读到位置`
1235
- instead of "both position channels are down".
1236
-
1237
- ### Performance — the chat watcher no longer re-reads the whole log every 150 ms
1238
-
1239
- The blocking-wait loop polls `chat.jsonl` every 150 ms. Each poll re-read `readChat()` and parsed
1240
- every line, so a two-hour session (thousands of entries) was decoding hundreds of KB several times a
1241
- second, and getting slower the longer the session ran. `makeChatWatcher()` now keeps a byte offset
1242
- and reads **only what was appended since last time** (falling back to a full re-read if the file
1243
- shrank, i.e. it was cleared). Measured on a 5000-line log: **0.061 ms per poll, independent of file
1244
- size**. `appendChat()` also stopped parsing the whole log to keep `at` monotonic — it reads the last
1245
- 4 KB instead.
1246
-
1247
- ### Tool description — pacing is now a rule the model can follow
1248
-
1249
- `watch_together`'s description tells the model to keep lines **≥ 6 s apart** and why: speech is
1250
- serialized, so a denser draft is thinned at runtime (engine busy → next line held; past the late
1251
- grace → dropped). The three previous rounds of "台词太早 / 太密" all came from the model not knowing
1252
- this budget.
1253
-
1254
- ### Fixed — speech piled up in the engine queue, and an interjection could no longer break a blocked wait
1255
-
1256
- Two reports in one message: "吐字太快,台词会挤到一起,只有上一句念完才到下一句,话太密会导致语音越来越
1257
- 滞后" and "悬浮窗插话不能让他从等待中出来 —— 这个功能之前是好的".
1258
-
1259
- **The voice queue.** `examples/voice-edge-tts` chains every `due` event onto an unbounded serial promise
1260
- ("two lines never overlap"). Lines are now scheduled at the right second, so when they arrive faster
1261
- than the engine can speak them the chain simply grows: speech drifts further from the picture with
1262
- every line, and the caption (written on `spoken`) drifts with it.
1263
-
1264
- - `src/watch-loop.js` — the clock now keeps a **voice budget**: after handing out a line it records
1265
- `voiceBusyUntil = now + speechSeconds(len)` and will not hand out the next one while the engine is
1266
- still talking. A line that misses its window by more than the late grace is dropped by `dueLine`
1267
- as usual: **speak one line less rather than one line later**.
1268
- - `src/speech.js` — `speechSeconds(chars)`: full spoken duration (`0.35 + chars/5`, 0.8–30 s).
1269
- `speechLag()` stays as it was — that one answers "when may I start talking", this one answers
1270
- "how long is the engine busy".
1271
- - `examples/voice-edge-tts` — safety net: if a queued line has been waiting more than 3.5 s it is
1272
- **abandoned** (logged) instead of spoken, and the queue empties immediately.
1273
- - `src/speech-bus.js` / `src/chat-store.js` — a fourth state, `skipped`: the adapter reports that it
1274
- gave up on a line, and `attachSpeechToChat` cancels the pending fallback timer for it. Without this
1275
- the 2.5 s fallback would paint a caption for a line that was never spoken.
1276
-
1277
- **The interjection.** `chat.jsonl` is a **consuming** channel: `poll()` marks a message read. The
1278
- blocking wait and the watch loop share one watcher, and the loop's handler is `followup()` — which
1279
- cannot interrupt a session that is sitting inside a tool call (the message is only processed when
1280
- the turn ends). So whichever polled first decided the outcome, and the loop (every 2 s) sometimes
1281
- won: the interjection was swallowed, the wait's `poll()` never saw it, and the user's "stop, I have a
1282
- question" did nothing until the segment ended.
1283
-
1284
- - `src/interrupt.js` — `enterChatWait()` / `chatWaiterCount()`: whoever is blocking on purpose
1285
- **owns** the channel. `raceChat()` (storyboard build, prefetch) registers too.
1286
- - `src/watch-loop.js` — `wakeOnChat` is skipped entirely while `chatWaiterCount() > 0`. The wake path
1287
- still works when the model is idle (no waiter), which is its whole purpose.
1288
- - `src/watch-run.js` (the `wait: true` loop), `src/watch-modes.js` (`waitUntil` / `waitForRefill` /
1289
- `nextLine`), `src/watch-source.js` (`waitForVideo`) — all register as waiters for the duration of
1290
- their loop.
1291
-
1292
- Tests: `test/lines-timing.test.mjs` (engine busy → next line is not handed out; the overdue one is
1293
- dropped), `test/chat.test.mjs` (`skipped` writes nothing, not even the fallback),
1294
- `test/interject-anywhere.test.mjs` (the loop must not consume while a waiter is active; counter
1295
- cannot go negative).
1296
-
1297
- ### Fixed — scripted lines came out like a machine gun, and minutes before the picture
1298
-
1299
- Reported as: "台词出现时间早了很多,而且和机关枪一样突突突一下出来一大堆,时间点都比视频早了".
1300
-
1301
- The line queue is ordered by `at` (the second of the video this line is *for*) and fired by playback
1302
- position, so the pacing is only as good as the `at` values. When a line was written **without** `at`
1303
- (the model wrote prose only), `pinTimes()` decided when it would be said — and it took *the first N
1304
- subtitle sentence starts of the segment*. Sixteen lines written for a 3-minute segment were therefore
1305
- all packed into its first 62 seconds (181.6 → 244.2, measured on the live queue), i.e. one every
1306
- 2–3 seconds: the clock ticks every 2 s and hands out at most one line per tick, which is exactly the
1307
- "machine gun". The last 14 of them ran one to two minutes ahead of the picture they describe.
1308
-
1309
- - `src/watch-lines.js` `pinTimes()` — each line now aims at its **even share of the segment**
1310
- (`from + i*size/n`) and snaps to the nearest subtitle start within half a slot, so the queue is
1311
- spread over the whole segment instead of stacked at its head. Falls back to the even share when no
1312
- start is close enough, and **never goes backwards** (the old tail fallback could emit 152.8 → 150).
1313
- - `src/watch-lines.js` `dueLine()` — pinning uses **the segment that line belongs to** (`sizeOf`),
1314
- not the segment the user happens to be in. With the 1/2/3/4/5-minute ramp, a 60-second slot pinned
1315
- with a 300-second size put its last lines outside the segment entirely.
1316
- - `src/watch-lines.js` `saveLines()` — `at` given as **subtitle text** was resolved only against
1317
- `recallSegments()`, which is a 4-entry in-process cache (empty in a fresh process, and lines are
1318
- usually written in a different turn). A miss silently became "no `at`", i.e. the head of the
1319
- segment — the other half of "the line is way too early". Now it reads the on-disk
1320
- `subs-<key>.json` cache first, then falls back to memory, then to a fuzzy match (≥60 % of the
1321
- characters), and only then warns.
1322
- - `src/watch-run.js` — the delivery note pruned "past" lines with `Number(l.at)`, and
1323
- `Number(null) === 0`: **every line without `at` was judged as second 0 and deleted** at delivery.
1324
- The note now previews the same pinning the clock will use, so the reported "earliest …" time is the
1325
- real one, and only lines whose *actual* time has passed are dropped (by text).
1326
- - `src/watch-run.js` — the note now lists the landing times it will use (`[lines] 落点:…`) and warns
1327
- when the average gap is under 6 s, instead of leaving the model to guess its own pacing.
1328
- - `src/watch-loop.js` — with the extension as the position source, the anchor is now re-read **every
1329
- tick** (a small local JSON, not CDP). Between the 15-second probes the clock extrapolated blindly,
1330
- so after a pause the lines up to 15 s ahead were spoken **early** — extrapolation is bounded for
1331
- lateness but nothing guarded earliness.
1332
- - `src/latency.js` `aheadSeconds()` — returns 0 instead of `NaN` when `ms` is missing. `NaN` made
1333
- `pos` `NaN`, every comparison false, and `shouldSpeak()` reported "due" for the first unspoken
1334
- segment at every tick.
1335
-
1336
- Tests: `test/pin-times.test.mjs` (the 16-line packing regression, monotonic fallback, cues bunched at
1337
- the head), `test/watch-lines.test.mjs` (per-segment size, `at` from the on-disk subtitle cache),
1338
- `test/lines-timing.test.mjs` (a stuck video must not speak the next line early).
1339
-
1340
- ### Fixed — the caption appeared before the voice, because it waited on `due` instead of "actually speaking"
1341
-
1342
- `attachSpeechToChat` wrote a line into `chat.jsonl` the moment `due` fired. But `due` only means
1343
- "it is time to say this": synthesis still has to happen (edge-tts does a network round trip, then a
1344
- fresh `ffplay` process — 0.6–2 s even for a short sentence). The floating window polls that file, so
1345
- the text was already on screen a beat before anything was heard.
1346
-
1347
- Delaying the voice instead (`speechLag`) would align the two, but push the voice further from the
1348
- picture, which is the one thing this plugin cannot trade away. So the **caption** moves:
1349
-
1350
- - `src/speech-bus.js` — a third state, `spoken`, plus `emitSpoken(event)` for engines to report
1351
- "audio is starting now". The adapter API gains `emitSpoken`.
1352
- - `src/chat-store.js` — writes on `spoken` when a `voice: true` subscriber exists; still writes on
1353
- `due` when nobody will speak (the zero-dependency path must not go mute); falls back after
1354
- `fallbackMs` (2.5 s, `DSH_WATCH_CAPTION_FALLBACK_MS`) for adapters that never report.
1355
- Pairing is by `at|text`, not by `seq` — `spoken` is a **new** event, so `emitSpeech` gives it a
1356
- new sequence number.
1357
- - `examples/voice-edge-tts` — reports `spoken` right before playback starts (i.e. after synthesis).
1358
- - `examples/floating-chat/window.py` — polls every 200 ms instead of 400 ms; the poll interval is
1359
- the residual "text lags the voice" gap.
1360
-
1361
- `test/chat.test.mjs` covers both new paths (waits for `spoken`; falls back when nobody reports, and
1362
- does not write twice if `spoken` arrives afterwards).
1363
-
1364
- ### Fixed — scripted lines never reached the chat window without a voice engine
1365
-
1366
- `watch-loop.js` consumed the due line inside `if (speechSubscribers() > 0)`. That helper counts only
1367
- `voice: true` subscribers (real engines), while `attachSpeechToChat` — the one that writes lines into
1368
- `chat.jsonl`, which is exactly what the floating window reads — subscribes with `voice: false`.
1369
- So with no voice adapter, or one that failed to load, a scripted line was **never taken from the
1370
- queue at all**: not spoken, not displayed, and the queue silently accumulated.
1371
-
1372
- Display and speaking are two separate things. The line is now handed out at its due moment
1373
- regardless: `emitSpeech` delivers it to every subscriber, and only a real `voice: true` subscriber
1374
- counts as "said" (`if (speechSubscribers() > 0) return;` still stops the wake, so nothing changes
1375
- when a voice engine *is* attached).
1376
-
1377
- `test/lines-to-chat.test.mjs` covers both sides. The test was checked against the bug: restoring the
1378
- old condition makes the no-voice case fail while the with-voice case still passes.
1379
-
1380
- ### Changed — `say` no longer reads as "only to answer an interjection"
1381
-
1382
- It always worked at any moment: it writes the sentence into the shared stream and hands it to
1383
- whoever listens for speech, exactly like a scripted line. But the description ended with
1384
- "use it to answer an interjection", which reads as "only after the user speaks". A model follows
1385
- that literally, so the one path for saying something **unprompted** went unused.
1386
-
1387
- The description now says any time, and says it explicitly: something in the picture strikes you,
1388
- the user asks something, a thought lands while waiting for the next batch — plus
1389
- "do not wait for the user to speak first". It also states the cost, because that is what makes it
1390
- usable mid-wait: no position read, no frame built, no batch advanced, one round trip.
1391
-
1392
- `test/say.test.mjs` pins the wiring — parameter → stream (one `assistant` row with `say: true`) →
1393
- speech event with `origin: 'chat'`, no image, no state advanced. The store layer was already covered
1394
- by `test/chat.test.mjs`; the uncovered part was the parameter entry itself.
1395
-
1396
- ### Added — an end-to-end test for "talk while the frame is building"
1397
-
1398
- The mechanism already existed (`raceChat(buildSegment(...))` in `runWatchPass`), and
1399
- `test/interrupt.test.mjs` covered `raceChat` itself — but the `built.kind === 'interrupted'`
1400
- branch had **no** coverage. If a refactor ever dropped the wrapper, or `chatWatcherShared()` got
1401
- replaced with a fresh watcher per call, every existing test would still pass.
1402
-
1403
- `test/interject-build.test.mjs` builds a segment that takes 1.2 s, writes a user message at 0.2 s,
1404
- and asserts all four things at once: the call returns before the build finishes, it carries that
1405
- exact message, it carries no image, and the build still completes into the cache afterwards.
1406
-
1407
- ### Changed — three implicit couplings now have exactly one source each
1408
-
1409
- A pass over the module boundaries. Same behaviour except the `lead` fix at the end, which was a
1410
- real bug: the parameter only worked on one of the three paths that used it.
1411
-
1412
- - **`handler.js` stopped preparing UI.** The floating window, the chat service and the "where do I
1413
- type" note moved to `input-surface.js` (`createInputSurface()`). `handler` is a router again —
1414
- three exits: quick action, one pass, start the loop. The `widgetNote` variable no longer travels
1415
- from the top of the function to the bottom.
1416
- - **`watch-run.js` has one return shape.** Eleven exits each used to build their own ten-field
1417
- object; now they all call one `pass()` closure. Adding a field is one edit instead of eleven, and
1418
- a branch can no longer quietly forget one.
1419
- - **One segment length.** `watch-state.js` exported `WATCH_SEGMENT = 120` while `batches.js`
1420
- declared `DEFAULT_SEGMENT = 300`; whichever fallback fired first decided how long a segment was.
1421
- `batches.js` is now the only source, and `WATCH_SEGMENT` is gone.
1422
- - **One lead.** The delivery lead was hardcoded in three places: `batches.from()` produced
1423
- `sayAt = to - 15`, `watch-loop.js` passed `lead: 15` to `shouldSpeak`, and only `watch-run.js`
1424
- actually read `args.lead`. Segments no longer carry `sayAt`; `shouldSpeak` computes `to - lead`,
1425
- and `startWatchLoop` takes `lead` from the caller. `lead: 60` now really moves the trigger point
1426
- (checked against a 300 s segment: at 241 s, `lead=15` stays quiet, `lead=60` fires).
1427
-
1428
- ### Removed — no more auto-launched browsers, no more browser widget
1429
-
1430
- Both were early paths from before the browser extension existed. Neither could produce a position
1431
- for the tab the user is actually watching, so both are gone rather than kept as fallbacks.
1432
-
1433
- - **Auto-launching a browser**: `ensureWatchBrowser()` (`launchBrowser` + `waitForPort`), the
1434
- `autoLaunch` flag on `runWatchPass`, the `attachOnly` parameter, and the `launchBrowser: true`
1435
- branch in `~/.dsh/video.json`. The extension already reports `currentTime` every second from the
1436
- page the user is on; opening a second Edge with its own profile never helped that page. When no
1437
- position can be read the tool now asks "how far are you" instead of starting a program.
1438
- - **The browser widget page**: `GET /widget`, `WIDGET_PAGE`, `openWidgetInBrowser()`, `widgetUrl()`,
1439
- and the `documentPictureInPicture` button in the chat page. The input box is the native tkinter
1440
- window (`examples/floating-chat/window.py`); the HTML page stays as a read-only fallback at `/`
1441
- (`chatPageUrl()`), and is never opened automatically.
1442
- - **Dead parameters**: `wakeOnLinesEmpty` (the handler never passed it, so its 30-line branch in
1443
- `watch-loop.js` could never run), `title` (nothing in `src/` or in storyboard read it), and
1444
- `segmentStart()` (every caller uses `plan.segmentAt()`). Parameter count 36 → 34.
1445
-
1446
- ### Fixed — interjections used to get swallowed (four different ways)
1447
-
1448
- The interjection path was the one place where losing user input was silent: nothing crashed, nothing
1449
- logged, the words just never arrived. All four ways of losing them are now closed, and each one has
1450
- a regression test (`test/cli-interrupt.test.mjs` — the CLI had **no** test coverage before this).
1451
-
1452
- - **Between two `cue` runs.** Every `cue` is a fresh process, and the watcher took "however many
1453
- lines exist right now" as its baseline — so anything the user typed while the model was thinking,
1454
- building a segment or replying was never read by anyone. The read position now lives in
1455
- `<watch>/chat-cursor.json`: a `cue` starts from where the last one stopped, and delivers what it
1456
- finds the moment it enters the wait. Baseline is persisted as soon as it is established, because a
1457
- `cue` that hears nothing (the common case) otherwise leaves no cursor for the next one.
1458
- - **Two messages arriving in the same poll.** Both watchers (chat box and host session file) marked
1459
- the whole batch as read and reported only the first, so the second was gone. They now consume up
1460
- to the message they hand over and no further — "reply first, then take the next one".
1461
- - **Wrong conversation.** `findActiveSessionFile()` took the most recently modified session jsonl
1462
- across *all* projects, so a chat in another window could interrupt the watch session. It now
1463
- prefers the project matching the current directory and only falls back to global when that one has
1464
- no active session.
1465
- - **The host writing old messages late.** WorkBuddy flushes a user's message into the session file
1466
- *after* the reply to it. The watcher saw new bytes and treated them as a fresh interjection —
1467
- interrupting the current turn with the message that started it. Messages whose `timestamp`
1468
- predates the watcher are now ignored.
1469
-
1470
- Also in this path: interjections heard via the host input box are appended to the chat stream too
1471
- (they used to appear only in `cue`'s stdout, so the page showed a stream with a hole in it); the
1472
- chat page puts the words back in the input box when a send fails instead of losing them; and
1473
- `POST /api/say` answers `ok:false` for requests it did not write, which is what makes that recovery
1474
- possible.
1475
-
1476
- ### Fixed — `cue` and `say`
1477
-
1478
- - `cue` no longer waits forever when the video changes underneath it. It compared against the
1479
- segment delivery point of the *old* video, and if the new one was shorter, `deliverAt` was a
1480
- position that would never be reached. It now detects a changed URL or duration and exits with
1481
- `VIDEO-CHANGED` (pending lines are saved under the old source), and exits with `REWIND` when the
1482
- user drags the progress bar back more than a minute — the model should hear about that instead of
1483
- sitting on lines written for a position the user left.
1484
- - Two `cue` processes can no longer run at once: a state file saying `blocking` with a **live** pid
1485
- is refused with `BUSY` (exit 1). A dead pid is taken for what it is — the residue of a killed run —
1486
- and does not block anything. `check` mode is read-only and never takes the lock.
1487
- - `check` mode no longer leaves `cue-state.json` at `blocking`, which used to make the next run
1488
- report "last wait was killed externally" for a run that was never waiting.
1489
- - `say` called edge-tts once by hand and then again inside `speak()` (twice the synthesis, and the
1490
- manual attempt passed the raw configured voice, so a SAPI-style name like `Huihui` never matched
1491
- and silently fell back). It now calls `speak()` once, which does the mapping and the fallback.
1492
- - `voices` was advertised in `help` and crashed with `cmdVoices is not defined` when called. It now
1493
- lists the SAPI voices plus whether edge-tts is present and which voice is configured — the first
1494
- place to look when "why am I still hearing the navigation lady" comes up.
1495
-
1496
- ### Added — talk instead of type: a microphone button in the floating window
1497
-
1498
- `examples/floating-chat/mic.py` is a separate process the window starts from its `麦` button. It
1499
- listens, cuts what you say into utterances with the Silero VAD already sitting in `models-sherpa/`,
1500
- transcribes each one, and writes it into the **same** `chat.jsonl` the typing path uses — so a
1501
- running `cue` picks it up through the interjection cursor and the model answers without anyone
1502
- typing a character. Measured end to end on this machine (i9-12900HX, int8 paraformer):
1503
-
1504
- - one model instance ≈ **284 MB** working set, loads in ~2 s
1505
- - a 3 s utterance transcribes in **0.15 s**; a 45 s one in ~1.2–3.3 s (RTF ≈ 0.05, 20× realtime)
1506
- - concurrent transcription barely queues: a 3 s short request takes 0.14 s even while a 45 s
1507
- transcription is running
1508
-
1509
- **It runs its own model by default** (`--engine local`), which is the answer to "can ASR run twice":
1510
- yes, and it is cheap. It also means the microphone never waits behind a video transcription. The
1511
- existing service cannot offer that yet — see the note below. `--engine http` shares port 8000
1512
- instead, saving 284 MB at the cost of queuing behind long audio.
1513
-
1514
- **It refuses to hear itself.** The agent speaks through speakers; the microphone hears it; without a
1515
- guard that gets transcribed as if the user had said it, and the model answers its own line forever.
1516
- Every utterance is checked against `quiet-until.json` (the same window `say` and `cue` already take
1517
- before speaking) and dropped if the agent is talking.
1518
-
1519
- ### Added — acoustic echo cancellation, so the microphone hears you and not the computer
1520
-
1521
- `examples/floating-chat/aec.py`: the microphone picks up whatever the speakers are playing, which
1522
- means the video's narration gets transcribed as if you had said it. Since neither `speexdsp` nor
1523
- `webrtc-audio-processing` builds on this machine (no C compiler, no wheels), this is a frequency-domain
1524
- adaptive filter (overlap-save FDAF, power-normalised NLMS) in numpy — one FFT per 32 ms frame.
1525
-
1526
- It captures the **loopback** channel (what the computer is playing, auto-detected as the
1527
- speaker/loopback device, never "stereo mix" — that one can contain the microphone too) and subtracts
1528
- the estimated echo from the microphone. On top of that, an utterance whose energy drops below
1529
- `--echo-gate` (default 30 %) after cancellation is discarded outright: that is the hard guarantee
1530
- that pure-echo segments are never transcribed, whatever the filter is doing.
1531
-
1532
- Two things that mattered more than the filter itself:
1533
-
1534
- - **Double-talk detection cannot compare against the echo estimate.** At startup the filter is zero,
1535
- so the estimate is zero, so "mic > 2 × estimate" is always true, so the filter freezes and never
1536
- converges (first version: 498 frames frozen, 0 dB). It now compares against the **reference**
1537
- signal (Geigel-style), which does not depend on the filter's state.
1538
- - **Measured on a synthetic but honest mixture** (real speech as the video, a different real speech
1539
- segment as you, through a 150 ms-delayed reverberant echo path):
1540
- ERLE **13.6 dB** during echo-only passage; the video's words in the transcript went from **25 % →
1541
- 0 %**, and an 8 s passage with nothing but video audio produced **no transcription at all**.
1542
-
1543
- Tunables: `--dt-ratio` (1.4 — mic peak vs reference peak before the filter freezes), `--taps`
1544
- (8192 ≈ 512 ms of reverb tail), `--echo-gate`, `--no-aec`, `--loopback`.
1545
-
1546
- Honest limits: it is a software AEC, not magic. The first second or two of your speech, right as the
1547
- filter re-converges after you start talking, is where the damage shows (a few characters in the test
1548
- above). Speaker loudness and room reverb both make it harder. **Headphones remove the problem
1549
- entirely** — with headphones there is no echo to cancel, and everything above is unnecessary.
1550
-
1551
- ### Added — a browser extension, so you never open a special window again
1552
-
1553
- Position used to require a browser started with `--remote-debugging-port`, and Chromium 136+ refuses
1554
- that flag on the default profile — so users had to keep a second, separate browser window open just
1555
- for watching. That was the whole reason this package felt like it needed a "special browser".
1556
-
1557
- `extension/` is an MV3 extension that reads `<video>.currentTime` from the page you are actually
1558
- watching and POSTs it to the plugin's own localhost server (`127.0.0.1:9377/api/position`). After a
1559
- one-time install it works in **your normal browser**, with your bookmarks and your logins.
1560
-
1561
- - `src/position-bridge.js` — the receiving end: writes each report to
1562
- `<cache>/position.json` (temp file + atomic rename) and treats anything older than 5 s as absent.
1563
- It goes through a file rather than memory because the CLI is a **different process** and has to
1564
- be able to read it too.
1565
- - `POST /api/position` and `GET /api/position` on the existing chat server, with CORS and a
1566
- Private-Network-Access opt-in (a page on https://bilibili.com talking to 127.0.0.1 needs both).
1567
- - `readPositionOrNull()` now tries the extension report when CDP is not configured or returns
1568
- nothing, so every existing call site gets the new channel for free.
1569
- - `doctor` grew an `extension` row and now treats "either channel works" as ready instead of
1570
- insisting on the debug port.
1571
- - `docs/BRIDGE.zh.md` — step-by-step install guide written for someone who has never heard of a
1572
- manifest file, including the eight failure modes people actually hit.
1573
- - `node watch.mjs install-extension` (and `scripts/install-extension.cmd`) does everything that
1574
- *can* be automated: copies the extension to `%LOCALAPPDATA%\\dsh-watch-together\\extension` so it
1575
- survives moving the repo, puts that path on the clipboard, and opens `edge://extensions`.
1576
- The last three clicks cannot be automated — Chrome 137 removed `--load-extension` from branded
1577
- builds and extension installs are HMAC-protected, deliberately, because silent install is the
1578
- malware channel. The guide says so plainly instead of pretending otherwise.
1579
- - **The extension now says hello on load** (`POST /api/hello`, persisted as `extension.json`).
1580
- Without it, "extension not installed" and "installed but no video playing" look identical from the
1581
- outside — both are silence. `doctor` and `bridge` can now tell them apart.
1582
- - `extension/welcome.html` opens on install/update: the three verification steps, plus what each
1583
- popup state means. Install is the one moment the user has no idea what to expect.
1584
- - `install-extension` no longer just prints and quits: it keeps the window open and **watches until
1585
- the extension proves it is loaded** (`✓ 扩展装上了`), then until a real position arrives
1586
- (`✅ 全部完成`). One double-click now covers install *and* verification, and the window cannot
1587
- vanish mid-instruction because it is still polling.
1588
- - `node watch.mjs install-extension --steps` re-prints just the three clicks without touching any
1589
- file — for when the window scrolled past or was closed.
1590
- - `install-extension` now waits for Enter when it has a TTY, so the instructions cannot vanish
1591
- before being read (running it from an IDE "Run" button has no TTY, which is the common way this
1592
- happened).
1593
- - `ensureWatchBrowser(port, url)` now passes the film through: with `launchBrowser: true`, saying
1594
- "陪我看这个 <link>" opens the dedicated window **at that link** instead of the Bilibili homepage.
1595
- That is the zero-install path — no extension, no port config, at the cost of watching in that
1596
- window. Both paths coexist; neither requires the other.
1597
- - `node watch.mjs bridge` (and `scripts/bridge.cmd`) starts just the position receiver and says
1598
- "✓ 收到上报" on the first report. Without it, a user who installs the extension and immediately
1599
- looks at the popup sees "not connected" — because the server only runs during `watch_together`
1600
- or `watch.mjs chat`, and concludes the install failed.
1601
-
1602
- ### Added — closing the remaining "no one is listening" dead ends
1603
-
1604
- - **Idle stop now wakes the model too.** Video-ended and video-changed already did; idle ("no movement
1605
- for two segments") did not — and since the loop is stopped, nothing polls the chat box afterwards,
1606
- so anything the user said next went nowhere. Now it wakes and says where it stopped.
1607
- - **Waiting is polled, not slept through.** The 500 ms tick in the blocking wait now uses
1608
- `sleepWithChat`, so a message is noticed within ~150 ms instead of up to 500 ms later.
1609
- - **The tool description now tells the model what an interruption is:** a result carrying `chat` means
1610
- "answer them first, then call again with the same arguments — the wait resumes, nothing is lost, and
1611
- the image is already in the cache". Without this the model had no way to know.
1612
- - **`doctor` distinguishes "nobody is receiving" from "extension not connected".** Both look like
1613
- silence, and the old wording told the user to reinstall the extension — but if no server is running
1614
- on 9377 the extension cannot report at all, and reinstalling would have changed nothing.
1615
- - Stale SMTC-era wording removed from the strings the *model* reads (`input`/`cursor`/`title`
1616
- descriptions, and the `browser:` line), which still talked about the OS media session.
1617
-
1618
- ### Added — you can interrupt almost any wait, and it picks up where it left off
1619
-
1620
- Every blocking wait in `watch_together` can now be interrupted by a message in the chat box, and in
1621
- all cases the answer is "reply to them, then call again with the same arguments" — the tool resumes:
1622
-
1623
- - **Building a segment** (8–10 s, longer with ASR) and **filling the lookahead buffer** (up to 4
1624
- segments serially, 30 s+) — the most pointless kind of waiting, now interruptible.
1625
- - **Waiting for the video to appear** (`waitForVideo`, up to 2 min).
1626
- - **Waiting for a condition** (`waitUntil`) and **waiting for the next line** (`nextLine`).
1627
- - Waiting to the delivery point and `cue` already listened; they now share one watcher (below).
1628
-
1629
- The interrupted work is **not cancelled**: the storyboard keeps building in the background and lands
1630
- in the cache, so the follow-up call returns it immediately instead of rebuilding it.
1631
-
1632
- New `src/interrupt.js`:
1633
- - `raceChat(promise)` — polls the chat while a slow promise runs; returns `interrupted` with the
1634
- message, or `done`. Wakes on whichever happens first (the promise settling, or the next poll tick).
1635
- The first version slept a fixed 500 ms per tick, which added half a second to *every* build —
1636
- enough that playback passed the delivery point and the blocking wait returned instantly.
1637
- - `sleepWithChat(ms)` — sleep that can be cut short by a message.
1638
- - `chatWatcherShared()` — **one watcher for the whole process.** `makeChatWatcher()` baselines at
1639
- creation time, so a fresh one per wait silently dropped anything the user said while the model was
1640
- thinking, in the gap between two waits.
1641
-
1642
- ### Added — it now reacts to what you do mid-video
1643
-
1644
- Auditing the whole flow against the user's checklist surfaced three gaps where the plugin behaved
1645
- correctly but **never told the model**, leaving it silent until the user poked it:
1646
-
1647
- - **Video ended / video changed now wake the model once.** Previously they only stopped the loop, so
1648
- the model sat blocked on the previous segment with no idea the film was over or had been replaced.
1649
- - **Large seeks (>60 s, forward or backward) wake the model once** with where the user jumped to and
1650
- from, with a 3-minute cooldown. Position tracking was already correct — it was the model that had
1651
- no idea. Rewatching does not re-speak already-spoken segments (no immediate-repeat chatter).
1652
- - **Only the visible tab reports** (`document.visibilityState`), plus a report on `visibilitychange`.
1653
- Every tab with a `<video>` reports once per second; with two such tabs open the server received
1654
- alternating positions and the plugin interpreted it as the user scrubbing wildly.
1655
- - The simulator can now jump the playhead (`seeks: [{at, to}]`), and there are four new scenario
1656
- tests covering: video changed wakes once, video ended wakes once, seek forward wakes once, rewatch
1657
- wakes once and does not re-speak.
1658
-
1659
- Note the jump check must run **before** the anchor is refreshed — comparing the new reading against
1660
- the already-updated anchor measures zero. That was the first (failed) version.
1661
-
1662
- ### Fixed
1663
-
1664
- - **`bin/watch.mjs chat` ran its own copy of the chat server** — an inline `http.createServer` plus
1665
- duplicated copies of both HTML templates (92 lines). The copies had drifted: it served `/`,
1666
- `/widget`, `/api/messages`, `/api/say` but **not `/api/position` or `/api/hello`**. So running
1667
- only `watch.mjs chat` (instead of `bridge`) meant extension reports hit 404 and the CLI path could
1668
- never read a position. It also never called `attachSpeechToChat()`, so that chat box showed user
1669
- messages but no script lines. It now uses `startChatServer()` + `attachSpeechToChat()` like the
1670
- plugin and `bridge` do, and the duplicated templates are deleted.
1671
- - **`watch.mjs reply` wrote straight to the stream** with `appendChat('assistant', …)`, so the text
1672
- appeared in the chat box but was never handed to speech subscribers — a TTS adapter stayed silent
1673
- while the page showed the words. It now uses `appendAssistantSay()`, which writes the stream *and*
1674
- emits the speech event, matching what `watch_together({say})` does.
1675
-
1676
- ### Fixed
1677
-
1678
- - **The plugin passed the browser's debug port to `ensureChatSession()`**, so the chat server tried
1679
- to bind 9333 — the port the browser is already using. The bind failed, the error was swallowed,
1680
- and the chat box silently never came up in DSH. It now uses the chat port (9377) as intended.
1681
- This also mattered for the extension: that server is where reports land.
1682
-
1683
- ### Removed — the OS media session (SMTC) backend is gone
1684
-
1685
- Position used to have two sources: the browser's DevTools port, and Windows' system media controls
1686
- (read by a bundled `watch_smtc.py`). **SMTC is deleted**, along with everything that only existed
1687
- because of it:
1688
-
1689
- - `src/watch-probe.js` (121 lines) and `src/watch_smtc.py` (62 lines)
1690
- - `src/resolve-playing.js` (153 lines) — it reversed a *title* into a source by searching filenames
1691
- and then Bilibili. With CDP the page URL is the source, so this whole "guess the film" path is
1692
- gone (it was also the thing most likely to pick the wrong video)
1693
- - the `winrt` Python dependency (three packages) and the interpreter search
1694
- - most of the extrapolation policy in `position.js`: the cap drops 180 s → 60 s, `FRESH_MS`
1695
- becomes 5 s, and the safety margin now only applies after a *missed* read
1696
- - `pickSession` / `probePlayback` / `describeStatus` and the `probe` injection point
1697
-
1698
- Rationale: SMTC's `Position` only refreshes on player events (measured gaps of 143 s and 216 s), so
1699
- treating it as a live position required extrapolating, and extrapolating over a wrong pause means
1700
- every later segment is built on a wrong cursor. The benefit — "watch in whatever player you like" —
1701
- did not survive contact with how it actually behaved.
1702
-
1703
- What you give up: you now watch inside the dedicated browser window
1704
- (`scripts/start-edge-debug.cmd`). Chromium 136+ refuses to open a DevTools port on the default
1705
- profile, so that window necessarily has its own profile and needs a one-time login.
1706
-
1707
- ### Fixed
1708
-
1709
- - **`loop.built` / `loop.dur` / `loop.sourceUrl` leaked across films.** Starting a second watch
1710
- session reused the previous film's duration, so the first read of the new film looked like a
1711
- "video changed" event and stopped the loop immediately; `built` made prefetch skip segments it had
1712
- built for the old film. Both are now reset when the source changes.
1713
- - **`startWatchLoop` used `Date.now()` for the anchor while pricing time off its injected clock**,
1714
- which made every simulated read look minutes old. It now uses the injected clock.
1715
- - **The CLI's `pos()` never read SMTC at all**, so the CLI was browser-only even while the plugin
1716
- had a fallback. Moot now that SMTC is gone, but it is why the tool seemed to demand a special
1717
- browser.
1718
-
1719
- ### Removed — dead code trimmed so there is one decision path
1720
-
1721
- Two functions that duplicated live logic and were never called in production are gone:
1722
-
1723
- - `dueDecision` (in `src/timer.js`) — a pure "should I speak now" decision that shadowed
1724
- `position.shouldSpeak`. Nothing in the loop ever called it; only a test exercised the abandoned
1725
- design. The "pause too long → stop" intent it carried is now not implemented (see note below).
1726
- - `depthForBuffer` (in `src/batches.js`) — a count-based lookahead that duplicated `windowFor`,
1727
- which the loop actually uses (position-based, so the invariant holds at every position, not just
1728
- at segment starts). Its tests were redundant guards of that same invariant.
1729
-
1730
- Net: 13 tests removed (8 for `dueDecision`, 5 for `depthForBuffer`); `windowFor`'s existing tests
1731
- already cover "lookahead ≥ N seconds at every position", so no coverage was lost.
1732
-
1733
- ### Changed — idle auto-stop now also covers a paused-and-abandoned video
1734
-
1735
- The loop used to only stop itself on "no movement" when the last reading was a *playing* sample
1736
- (`why === 'recent-refresh'`). A paused video reports a frozen position forever — `estimate` returns
1737
- `why: 'paused'`, never stale — so pausing and walking away left the loop polling indefinitely. The
1738
- idle check now also fires on a frozen *paused* position, after the same `2 × segment` grace period,
1739
- and wakes you with "停了一会儿" so you can resume by calling `watch_together` again.
1740
-
1741
- ### Fixed — voice adapter no longer hard-codes a voice
1742
-
1743
- `examples/voice-edge-tts/index.mjs` used to fall back to `zh-CN-XiaoxuanNeural` when
1744
- `~/.dsh/tts.json` had no `voice`. That baked one person's voice into the example, so shipping it
1745
- would have dragged that choice into everyone's install. It now falls back to the neutral
1746
- `zh-CN-YunxiNeural` and prints a one-line hint telling you to set `voice` in `~/.dsh/tts.json`
1747
- (e.g. `"voice": "zh-CN-XiaoxuanNeural"`). Nothing about the voice ships in the package — you mount
1748
- the adapter via `~/.dsh/voice.json` (or `DSH_VOICE_ADAPTER`) and pick the voice yourself.
1749
-
1750
- ## Earlier — 0.1.0 draft, never published (2026-10-30)
1751
-
1752
- The first cut as a standalone plugin. It was not published under this number; the version line now
1753
- starts at 0.0.7, so this section is kept purely as a record of how the feature set got here. The feature existed inside `dsh-video-storyboard` 0.4.x as
1754
- `src/watch/`; it is now its own package with its own entry point, its own version, and a one-way
1755
- dependency on `dsh-video-storyboard`.
1756
-
1757
- ### Added
1758
-
1759
- - **`watch_together`** — watch a video together with a text-only agent. Instead of one whole-film
1760
- storyboard, it follows the user's **real playback position** and hands over one segment at a time,
1761
- `lead` seconds before the segment ends. The next segment is built while the user is still watching
1762
- the current one, so delivery is perceived as instant (4/4 measured deliveries at 0.0 s).
1763
- - **Ramp-up start.** Segment lengths grow `[60, 120, 180, 240]` → `segment`, so the first line lands
1764
- around 45 s instead of after a full 5-minute batch. `ramp: []` disables the ladder.
1765
- - **Double buffering.** `depth: 2` keeps the current batch plus the next one built, and starts the
1766
- one after that while the user watches.
1767
- - **Playback position straight from the page.** It reads `<video>.currentTime` over the DevTools
1768
- protocol, so the value is exact, and the page URL becomes the source (`file:///D:/x.mp4` → local
1769
- path) — no searching, no downloading, no asking. Never released with the OS media session (SMTC)
1770
- backend documented below: SMTC's `Position` only refreshes on events, so using it as a live
1771
- position meant extrapolating, and a wrong position poisons every later segment.
1772
- - **Honest confidence levels.** The plugin reads every 15 s and extrapolates in between, which is
1773
- normal and self-correcting. What it refuses to do is keep extrapolating after it has *missed* a
1774
- read: past 20 s it demands an extra 5 s of margin before speaking, and past 60 s it stops
1775
- guessing and asks for `cursor` instead.
1776
- - **The speech seam, with no engine.** `src/speech-bus.js` exposes `onSpeech(handler, { voice })`,
1777
- `emitSpeech()`, `speechEvents()` and `lastSpeech()`. The plugin ships no engine, no default
1778
- adapter and no voice parameters; `watch_together` results carry `speech: [{ at, text, state }]`
1779
- and the loop emits `state: 'due'` when a line is actually due.
1780
- - **Adapters loaded by path.** `~/.dsh/voice.json` `{ "adapter": "<path or module>" }` (or
1781
- `DSH_VOICE_ADAPTER`) is `import()`ed once at startup; the module exports `attach(api)` and returns
1782
- a detach. Nothing is bundled, and a failure only logs a warning.
1783
- - **`examples/voice-edge-tts/`** — a working adapter (edge-tts → `ffplay` → system-voice fallback).
1784
- It prints `[voice 03:11.4] <line>` to stderr for every line that comes due; that log, not the
1785
- audio, is what you want when checking *when* text fires.
1786
- - **One text stream for the chat box.** `chat.jsonl` carries `line` (scripted), `assistant`
1787
- (interjection) and `user`, with `say: true` marking the speakable ones.
1788
- `watch_together({ say: "…" })` is how the model gets its interjection in — the plugin cannot read a
1789
- normal reply. `attachSpeechToChat()` subscribes with `voice: false`, so a display-only consumer can
1790
- never silence the loop.
1791
- - **A localhost chat page** (`/` full view, `/widget` capsule) with an `/api/messages` long-poll and
1792
- an `/api/say` callback. This is the only channel that actually reaches a blocked `watch_together`
1793
- call — messages typed into the host's own input box are appended to the session log *after* the
1794
- blocking call returns (measured: 42 s of polling, 0 bytes written).
1795
- - **`examples/floating-chat/window.py`** — a real floating window without a browser: frameless,
1796
- always-on-top, translucent, stdlib tkinter only. Reads the same `chat.jsonl`.
1797
- - **`bin/watch.mjs`** — a CLI shell for sessions that have no `watch_together` tool. It imports the
1798
- same `src/`, so behaviour cannot drift from the plugin.
1799
-
1800
- ### Fixed
1801
-
1802
- - **The CLI imported pre-refactor paths** (`src/browser-time.js`, `src/pipeline.js`, …) that no
1803
- longer exist, so `bin/watch.mjs` could not even start. All imports now resolve through the
1804
- `dsh-video-storyboard` package name.
1805
-
1806
- ### Changed
1807
-
1808
- - `detachAdapters()` no longer reaches into the bus's private subscriber map; it calls
1809
- `__resetSpeech()` from `speech-bus.js`.
1810
- - `watch-run.js` imported `./watch.js` twice; merged into one import.
1811
-
1812
- ### Known limits
1813
-
1814
- - **Speaker separation is not attempted.** Measured on the reference machine: per-sentence cam++
1815
- embeddings split single-speaker material into 6 speakers; demucs pre-separation made no difference
1816
- (median similarity 0.62 → 0.61); FunASR's `ClusterBackend` returns "one speaker" outright below 20
1817
- speech segments — short clips are outside its operating range by design.
1818
- - **Interjection audio can collide with a line already being spoken.** Windows mixes both SAPI
1819
- instances, so `say` occupies `quiet-until.json` before speaking and `cue` skips lines inside that
1820
- window (it skips rather than defers — deferring desynchronises from the picture). The remaining
1821
- gap is the 3–8 s while a line is mid-speech, which cannot be cut short.
1822
- - **CRLF-less assumption.** The chat page replaces `__PORT__` in the templates per start; changing
1823
- the port while a browser tab is already open requires a reload.
1
+ # Changelog
2
+
3
+ ## [0.2.15] - 2026-11-06
4
+
5
+ ### Fixed — 有些机器上装完一个工具都不出现(社区实报)
6
+
7
+ `import('@deepseek-ai/dsh-tools')` 拿 `defineTool`,而宿主的这份**被打进 `app.asar`**,
8
+ 插件从自己的 `node_modules` 往上解析不到 → 抛 → `apply()` 的 catch 吞掉 →
9
+ **整个插件静默不注册任何工具**(日志里只留一行 `failed to load`)。
10
+
11
+ - 新增 `src/define-tool.js`:内置一份 `defineTool` 兼容实现(author spec → JSON Schema,
12
+ 规则照抄宿主 `runSchemaCompiler` 的语义;只少了运行时参数校验)。
13
+ - `loadDefineTool()` 改成三跳:`import` → `DSH_TOOLS_PATH`(包了 try,路径写错也不会崩)→ 内置兜底。
14
+ - 走兜底的情况下工具照常注册,`schema-audit` 那套静态审计仍然是第一道防线。
15
+ - 测试 +6:`type:'json'` 退化成注解、`required:true` 提升到父级、真实 spec 全部能编译出来。
16
+ All notable changes to **dsh-watch-together** are documented here.
17
+ This package starts its own version line at `0.0.7` — it is not a continuation of `dsh-video-storyboard`.
18
+
19
+ ## [Unreleased]
20
+
21
+ ### Fixed — 悬浮窗在 macOS/Linux 上必崩(see-now #40)
22
+
23
+ `window.py` 顶层无条件摸 `ctypes.windll`(DPI 感知、`timeBeginPeriod`),
24
+ 非 Windows 上直接 `AttributeError`,而且死在依赖预检之前 —— 用户看到的是
25
+ "启动后 700ms 退出,code=1"。
26
+
27
+ - 所有 `ctypes.windll` / `wintypes` / WDA 调用按 `IS_WIN` 收口;
28
+ - 没有 WDA 的平台一律按"能抓到自己"处理(`_cappable` 强制打开),
29
+ 改走 `fill_own_rect` 那条路,不会递归拍到自己;
30
+ - `_bbox()` 在非 Windows 上退回 Tk 的屏幕坐标(Retina 缩放对齐仍是已知问题,
31
+ 那类机器建议用 `frost`/`solid`,两者都不抓屏)。
32
+ - 启动失败弹窗的标题跟着 `DSH_WINDOW_BRAND` 走(see-now 的用户不会再看到
33
+ "dsh-watch-together",issue #32 第 1 条)。
34
+
35
+ ### Fixed — 麦克风永远起不来:`aec.py` 没打进包(see-now #36)
36
+
37
+ `mic.py` 顶层 `from aec import ...`,但 `aec.py` 既没进 see-now 的同步清单,
38
+ 发布包里的 stderr 又被丢进 DEVNULL —— 界面只剩"录音中"。
39
+
40
+ - 导入改成可缺省:没有 `aec.py` 时回声消除关掉、麦克风照常可用(并打一行原因);
41
+ - see-now 的 `sync-window.mjs` ASSETS 补上 `aec.py`。
42
+
43
+ ## [0.2.14] - 2026-11-06
44
+
45
+ ### Added — 悬浮窗样式预设:多一档「静态磨砂」,设置页里能选
46
+
47
+ 社区反馈实时玻璃在低配机/高分屏上卡。实测同机同尺寸(760×560、背景在播视频):
48
+
49
+ | 样式 | 3 秒内 CPU | 占单核 |
50
+ |---|---|---|
51
+ | `live` 实时玻璃 | 5.17 s | **172%** |
52
+ | `frost` 静态磨砂(新) | 0.03 s | **1%** |
53
+
54
+ 不是把模糊调小,而是换了一条路径:`frost` **完全不抓屏**,只画一张预生成的
55
+ 底板(对角冷色渐变 + 两团极淡光晕 + 细噪点 + 每块玻璃 1px 亮边),尺寸或气泡
56
+ 形状变了才重画(约 11ms),其余时间一帧都不算 —— 静态样式连渲染线程都不起。
57
+ `live` 那条路径一行没动,只是把线程的启停抽成了 `_start_worker` / `_stop_worker`。
58
+
59
+ 样式写在 `~/.dsh/watch-window.json` 的 `glass`:`auto`(默认,远程/录屏 →
60
+ solid)/ `live` / `frost` / `solid`。窗口每 250ms 看一次这个文件的 mtime,
61
+ 所以**从设置页改完立刻切换**,不用重开窗口;从 `live` 切走时真的把抓屏线程
62
+ 停掉(只换渲染器不停线程 = 用户切过去还是卡,只是看不见画面在变)。
63
+
64
+ 设置页(浏览器版与 DSH 设置里的原生表单)都多了一栏「悬浮窗样式」。
65
+
66
+ ### Changed — 心跳从"空文件戳一下"变成带可见性的 JSON
67
+
68
+ 插件侧以前只能看心跳的 mtime,那只能回答"进程还在画吗",回答不了"用户能不能看见"。
69
+ 于是出现最难查的一种:配置文件写 `hidden:false`、进程活着、心跳在跳,屏幕上什么都没有,
70
+ 而插件 `status` 说"显示中"(see-now issue #32 第 3 点)。
71
+
72
+ 现在每秒写的是:
73
+
74
+ ```json
75
+ {"at":1793886026.33,"visible":true,"hidden":false,"state":"normal"}
76
+ ```
77
+
78
+ `hidden` 是意图,`visible` 是事实(Tk 的 `state()` + `winfo_ismapped()` 说了算),
79
+ 两个都写 —— 只写事实的话插件分不清"用户故意藏的"和"想显示但没 map 出来"。
80
+ 原子写(`.tmp` + `replace`):插件每秒都可能读,读到半行 JSON 会退回读配置文件,
81
+ 那正好是这一版要修的东西。
82
+
83
+ mtime 照旧更新,老版本插件不受影响。
84
+
85
+ ## [0.2.13] - 2026-11-04
86
+
87
+ ### Changed — 语音改成抢占式:新的一句直接顶掉没念完的
88
+
89
+ 以前是纯串行链:三句排队,第三句要等前两句念完才开口 —— 那时候画面早换了,
90
+ 听到的是"它在说上一段的事"。`MAX_QUEUE_LAG_MS` 只能做"排太久就放弃",救不了"一直在排"。
91
+
92
+ 现在每一句带代际(`speakGen`),新句一到立刻做两件事:
93
+
94
+ 1. **截断正在念的那一句**
95
+ - 常驻通道:走 daemon 新增的 `interrupt` op,只杀播放管道那个 ffplay(daemon 还活着,
96
+ 下一句从新进程开始,多花一次 demuxer 探测 ~200ms);
97
+ - 没有 edge-tts 的机器走 SAPI:kill 掉那个 PowerShell 进程 ——
98
+ `SpVoice.Speak()` 是阻塞调用,**只有杀进程才能让它闭嘴**。
99
+ 2. **清空排队**:那些句子配的是已经过去的画面,念出来只会让人困惑。
100
+
101
+ 代价:被截断的那句后面几个字听不到。这个取舍是明确的 —— 追上画面比句子完整重要。
102
+
103
+ **新增协议**:`{"op":"interrupt"}` → `{"ev":"interrupted"}`。
104
+ 它和 `stop` 不是一回事:`stop` 是 `SystemExit(0)`,整个常驻合成器没了,下一句要重新预热 1~2 秒。
105
+
106
+ ### Added — 适配器能"拉"了:`api.upcoming()` / `api.position()`
107
+
108
+ 此前核心只会**推**(`due` / `scheduled`),适配器想知道"再往后还有什么、现在播到哪"
109
+ 只能自己读 `watch.json` 和 `position.json` —— 那是两份内部格式,还各自带着一套
110
+ "哪条位置可信"的判断,第三方适配器重写一遍必然走样。
111
+
112
+ 现在 `attach(api)` 多两个**只读**方法(issue #4 定下的形状,实现没偏离):
113
+
114
+ ```js
115
+ await api.upcoming({ horizonSec: 20 }) // → [{ at, text, segment }],按 at 升序,不消费
116
+ api.position() // → { pos, dur, confidence, staleMs }
117
+ ```
118
+
119
+ - `upcoming()` 读同一份台词槽,**只给未来窗口内、带 `at` 的句子**;念掉的不在里面。
120
+ 窗口 1~120 秒(越界钳住),没在陪看 / 位置不知道时是空数组。
121
+ - `position()` 走 `position.js` 那套锚点逻辑(扩展上报 / CDP 探针 / 用户自报三条来路),
122
+ `confidence` 分 `fresh` / `extrapolated` / `unknown`。**`unknown` 时 `pos` 是 `null`,不是 0** ——
123
+ 给 0 会让"我合成的音频晚了三百秒"这种判断成立,然后默默丢光音频,还没有任何报错。
124
+ - 停表 / 换片即清空,不会让适配器拿着上一支片子的位置去丢音频。
125
+
126
+ 边界没变:核心**不做合成、不缓存音频、不重试**。给到"下一两句是什么、现在播到哪"就够了,
127
+ 预取几段、seek 之后丢哪些,全在适配器自己(core #27)。
128
+
129
+ 实现:新增 `src/playhead.js`(循环把锚点推过来,避免 `watch-loop → runtime-ports →
130
+ voice-adapter → companion-api` 反向 import 成环)和 `src/companion-api.js`(纯读)。
131
+
132
+ ### Fixed — 悬浮窗拖得到副屏,抓屏按虚拟桌面钳位(#8)
133
+
134
+ 副屏在主屏左边时坐标是负的,而拖动 / 缩放 / 恢复位置 / 抓屏外扩四处都拿主屏当边界:
135
+ 窗口拖不出去、放到副屏后玻璃停在旧帧、下次启动又被拉回主屏。
136
+
137
+ - `virtual_bounds()` 用 `GetSystemMetrics(76..79)` 取虚拟桌面,取不到才退回主屏;
138
+ 按下时重新 `_sync_screens()`,插拔显示器不用重开窗。
139
+ - 抓屏同理:`CaptureSource(bounds=…)`。**窗口整个在主屏里时仍按主屏钳** —— 单屏逐像素不变。
140
+ - `scripts/check-multimonitor.py`:单屏等价网格对比 + 副屏/跨屏正面积校验。
141
+
142
+ ### Fixed — 缺 `mss` / `numpy` / `pillow` 时弹窗说明,不再静默退出(#76 附带)
143
+
144
+ pythonw 没有控制台,`import mss` 失败时 Python 直接退出,用户看到的只有"窗口没出来"。
145
+ 现在在 import 重依赖之前先检查一遍:缺包就弹 MessageBox 写明缺哪个、装什么,
146
+ 并把原因落到 `~/.dsh/watch-window-error.log`。README 也改了口径 ——
147
+ 原来写"不装任何第三方包",下一段又说要 Pillow + numpy + mss,把 `pip install` 提到最前面。
148
+
149
+ ## [0.2.12] - 2026-11-04
150
+
151
+ ### Fixed
152
+
153
+ - **在悬浮窗打字不再往宿主的「排队消息」里塞一条**(`wakeOnChat` 默认 `true` → `false`)。
154
+ 每打一句话,输入框上方就多一条排队消息 —— 而窗口里明明已经有气泡显示过了,
155
+ 队列里再来一条既是噪音、又占住输入框。根因是 `wakeSession` 走宿主的 `agent.followup()`,
156
+ 而 DSH 的 QueueDock 不过滤来源,绕不开,只能不投。
157
+ **关掉不会丢话**:钟那一拍整个跳过、聊天通道不消费,消息留在里面,模型下次调
158
+ `watch_together` 时 poll 得到;真正的阻塞等待(`wait` / `nextLine`)走另一条路,
159
+ 照旧能随时打断。
160
+
161
+ ### Added — 气泡底板
162
+
163
+ 聊天气泡内部铺一层 `#07111d`、alpha 0.50 的圆角底板(`glass_geometry.BUBBLE_PLATE`),
164
+ 文字的对比度不再跟着画面走。底板在玻璃合成层做(`_overlay` 的 tint),CPU / GPU 两条
165
+ 路径共用同一份实现;气泡宽度变了跟着一起重算;空态不铺(四个占位框铺深色会像四个空洞)。
166
+
167
+ 实测:760×560、同一段消息、同一位置,只切 `DSH_GLASS_PLATE` 拍两版,取气泡内
168
+ 「底板中位灰度 / 文字笔画 p97」算 WCAG 对比度。
169
+
170
+ | 背景 | 改动前 | 改动后 |
171
+ |---|---|---|
172
+ | 纯白(最坏情况) | 1.26–1.53:1 | 3.83–4.25:1 |
173
+ | 深蓝黑 | 16.3–17.7:1 | 17.0–17.2:1 |
174
+
175
+ alpha 0.40 时纯白背景只有 2.88–3.31:1(试过),0.50 才到 4.2。
176
+
177
+ `TextLayer.draw(shadow=True)` 给每个字先落一层 `+1px` 的深色副本。Tk 的 text item 没有
178
+ stroke / outline,只能多建一层 item;只在气泡正文开,`refresh()` 用 `tshadow` 标签把
179
+ 它排除在翻色之外(目前暂存)。
180
+
181
+ ### Changed — 声音延迟 2.4 秒 → 0.2 秒(常驻合成器)
182
+
183
+ > 台词几分钟前就写好了,第一声却要等两秒多 —— 听起来不像它在说,像在等我念。
184
+
185
+ 老路是**每句起两个进程**:一个 `edge-tts.exe` 合成到临时 mp3,一个 `ffplay` 播放。
186
+ 实测(Win11 / i9-12900HX,短句与长句各三次取均值)端到端 **2.4~3.0 秒**,
187
+ 而且这四笔开销**每句都要重付一次**:
188
+
189
+ | 段 | 耗时 |
190
+ |---|---|
191
+ | pip 的 exe shim 拉起 python | ~600ms |
192
+ | python 解释器冷启动 | ~600ms |
193
+ | `import edge_tts` | ~700ms |
194
+ | WebSocket 建连(DNS+TCP+TLS+token) | 620~760ms |
195
+ | 首块合成 | 200~300ms |
196
+ | 剩余音频块 | 30~130ms |
197
+ | ffplay 启动 + demuxer 探测 | 380~410ms |
198
+
199
+ `examples/voice-edge-tts/stream/daemon.py` 把三件事搬进一个常驻进程:
200
+
201
+ 1. **常驻 python**:`import edge_tts` 只做一次。
202
+ 2. **长连接复用**:一条 WebSocket 上连发多个 SSML 请求(Azure 协议本来就支持)。
203
+ 实测连续 20 句首块 **min 182 / avg 200 / max 235ms**,没有退化。
204
+ 服务端在 `turn.end` 之后约 **30 秒**关连接(30s 还活着、35s 已死;发 ping 保不住),
205
+ 所以空闲超 25s 主动断、下次用时重建(620~760ms)。
206
+ 3. **常驻 ffplay**:一个进程从 stdin 连续吃 mp3 帧。实测三段音频拼着写进去,
207
+ 时间码一路涨到 7.3s、进程没退 —— 每句起进程要付 380ms 首声。
208
+
209
+ 同一条 `due` 事件、同一台机器上的对照:
210
+
211
+ | 场景 | 老路 | 现在 |
212
+ |---|---|---|
213
+ | 预取命中(`scheduled` 已合成) | 1009~1674ms | **1ms** |
214
+ | 没赶上预取(`see-now` 的 `at:null`) | 2485ms | **230ms** |
215
+ | 连续第三句 | 排队 4.9s 后被丢弃 | 1ms |
216
+
217
+ 预取队列也不再"满 6 句就丢弃":常驻通道按 text 在内存里缓存(上限 80 句),
218
+ 老路那个 `MAX_PREFETCH = 6` 是文件缓存 + 串行 CLI 逼出来的,这里不用照抄。
219
+
220
+ **兜底**:python 找不到、`daemon.py` 不存在、进程起不来 —— 任何一步失败都退回老路
221
+ (每句一个 CLI 进程),没有一行 throw。`DSH_TTS_STREAM=0` 可强制走老路排查。
222
+ 调试时 `DSH_TTS_FFPLAY_LOG=info` 会把 ffplay 的时间码放出来。
223
+
224
+ `test/tts-stream.test.mjs` 覆盖协议(first/done 顺序、error 后通道继续可用、进程死掉后不挂在超时上),
225
+ 不依赖网络和 ffplay。
226
+
227
+
228
+ > Issue #44 第 2 条:文字直接压在实时视频上,对比度每秒都在变,连看 5–10 分钟眼睛发酸。
229
+
230
+ 有底板之后底色恒定,`TextLayer.adapt()` 对气泡正文已经没有意义,反而会在过渡帧翻错
231
+ (白字被翻成深色,压在深色底板上更看不见)。给 `draw()` 加了 `adapt=False`:这些 item
232
+ 不参与采样。标题栏、输入框、空态提示仍走逐字翻色 —— 它们确实直接压在玻璃上。
233
+
234
+ - 跟 `dsh-video-storyboard` 0.6.6 一起发。依赖范围 `^0.6.0` 不用改。
235
+ 上游这次是排布与计费对齐(同素材 token -9.3%),**本包自己的代码没有改动**。
236
+
237
+ ### 调试开关
238
+
239
+ `DSH_GLASS_PLATE=0` 关掉底板和描边,回到 0.2.11 的行为 —— 只用来拍新旧对比图。
240
+
241
+ ## [0.2.11] - 2026-11-03
242
+
243
+ > 悬浮窗从头拆了一遍(单文件 1931 行 → 五层),顺带修掉 GPU 路径三个真 bug。
244
+
245
+ ### Changed — 玻璃拆成四层,去掉全部模块级可变全局
246
+
247
+ `window.py` 原来 1931 行,`W / H / SHAPES / MASK / MASK_HARD / OVERLAY /
248
+ OVERLAY_2X / WARP_X / WARP_Y / BOX_MAPS / HW / HH / BOX_UNION_2X / MIC_POS`
249
+ 十几个模块级全局靠 `global` 在 `rebuild_geometry()` 里一次性改写;GPU 伴生
250
+ 文件还得 `import glass_window as G` 去读它们,窗口一缩放就可能拿到上一帧的坐标。
251
+
252
+ | 文件 | 职责 |
253
+ |---|---|
254
+ | `glass_geometry.py` | 一套尺寸的全部贴图。`Geometry` 是不可变值对象,气泡变宽用 `with_shapes()` 换新对象,尺寸相关的遮罩/折射图直接复用 |
255
+ | `glass_capture.py` | 抓屏、`MotionTracker`、麦克风贴图、圆角收尾 —— CPU/GPU 共用一份 |
256
+ | `glass_cpu.py` | CPU 合成管线 |
257
+ | `glass_gpu.py` | 同一件事在 moderngl 上做 |
258
+ | `window.py` | 编排 + Tk 窗口 + 交互 |
259
+ | `window_widgets.py` | `Fonts` / `ChatFeed` / `TextLayer` |
260
+
261
+ 顺手清掉的死代码和重复逻辑:
262
+
263
+ - `_add_text_shadows()` 是空实现,`_text_shadows` 有 11 处引用但永远是空的;
264
+ - `_hide_window()` 定义了但没有任何调用点;`EDGE_MASK` 算出来没人用;
265
+ - `_fit_lines` / `_text` 对每个字重新 `measure()` 一遍前缀 —— O(n²) 次 Tcl 调用,
266
+ 改成累积宽度;
267
+ - 每来一条消息就 `Entry.destroy()` 重建(丢输入法状态和光标),改成复用一个;
268
+ - `_preview_resize` / `_rebuild` / `_refresh_feed` 三份几乎相同的「清状态 + 重排 +
269
+ 贴图」;
270
+ - `tkfont.Font(...)` 每帧新建几百个 Tcl 对象 → `Fonts` 按尺寸缓存。
271
+
272
+ ### Fixed — 录屏模式下桌面图标被沿上下方向拉成竖条
273
+
274
+ `capturable: true` 时 mss 会抓到窗口自己,所以要把那块刷平。`fill_own_rect()`
275
+ 当时的做法是「取窗口上下各一行像素做纵向插值」:窗口上方紧挨着的那一行里如果
276
+ 正好有桌面图标或文字,**每个像素会被整列往下抹开** —— 用户看到的就是「东西被
277
+ 沿上下方向拉成长条」。0.2.7 的 CHANGELOG 写的是「周边均值」,代码里却是纵向
278
+ 插值,那次改动把方案退回去了。
279
+
280
+ 现在改成四条边各自分段抹平高频 + Coons patch 融合:边界贴合真实背景,内部只有
281
+ 大尺度色彩过渡,没有方向性条纹。填充区的列内/行内标准差从 **28.0 / 35.9**(有
282
+ 方向性)变成 **12.7 / 7.1**(各向同性)。
283
+
284
+ 算法本身要降到 1/8 粗网格再放大 —— 全分辨率算一次 **80 ms**,粗网格 **4.2 ms**,
285
+ 而这块最后还要被高斯糊一遍,8px 的色阶看不出来。
286
+
287
+ 同一个问题 GPU 侧本来没有(它压根没调 `fill_own_rect`),0.2.11 给 GPU 补上这
288
+ 一步之后两边一致。
289
+
290
+ ### Fixed — GPU 版的 OpenGL context 建在错误的线程上(每帧 `cannot create texture`)
291
+
292
+ `GpuRenderer` 原来在主线程构造。`moderngl.create_standalone_context()` 绑在创建
293
+ 它的线程上,而 `render()` 跑在抓屏 worker 线程 —— 每帧抛 `cannot create texture`,
294
+ 被 `_work()` 吞掉后只打印一行、窗口始终没有玻璃(截图里只剩文字浮在桌面上)。
295
+
296
+ 改成首次 `render()` 时惰性创建(那时已经在 worker 线程);真起不来就打印原因并
297
+ 回落 CPU,不刷屏。
298
+
299
+ ### Fixed — GPU 版在录屏模式下没挖掉自己(`moved` 恒真、永不跳帧)
300
+
301
+ `CaptureSource.to_image()` 会 `fill_own_rect()`,但 GPU 直接吃 `shot.bgra`、
302
+ 绕过了那一步 —— 背景里永远带着本窗口,`moved` 每帧为真:静态跳帧一次都不触发,
303
+ 还叠出自我反馈的拖尾(0.2.7 修过同一个坑,只修了 CPU 侧)。补了数组版
304
+ `fill_own_rect_array()`。
305
+
306
+ 实测 700×665 / 150% DPI / 同一桌面、同一条消息:
307
+
308
+ | | CPU 版 | GPU 版(修前) | GPU 版(修后) |
309
+ |---|---|---|---|
310
+ | CPU | 43.2% 单核 | 87.9% | **32.1%** |
311
+ | 内存 | 93 MB | 195 MB | 193 MB |
312
+
313
+ ### Fixed — `DSH_GLASS_NATIVE=1` 一直是个假开关
314
+
315
+ `run-glass.cmd` 写着「走 GPU 路径」,但 `window.py` 从来没 import 过
316
+ `glass_window_gpu` —— 设了只是让 CPU 路径去读一个没人用的变量。现在
317
+ `DSH_GLASS_GPU=1` / `DSH_GLASS_NATIVE=1` 真的选后端;`glass_window_gpu.py`
318
+ 仍可单独起窗(等价于 `DSH_GLASS_GPU=1`)。
319
+
320
+ ### Fixed — GPU 版拖动窗口没有运动模糊、反而做静止才该做的色散
321
+
322
+ 0.2.9 修的 `box_changed → moved` 只落在 CPU 路径上,GPU 那份还是老判断。现在
323
+ 两条路径共用 `MotionTracker`,同一个判断只有一处实现。
324
+
325
+ ### Fixed — GPU 版形状变化后混入上一帧残影
326
+
327
+ `_invalidate_glass()` 只清了 CPU 的 `_prev_out`,GPU 的 `_prev_valid` 还留着。
328
+ 现在几何一变统一走 `renderer.invalidate()`,两边一起清。
329
+
330
+ ### Fixed — 折叠时 `slabs_for()` 算出负高度矩形
331
+
332
+ 折叠后窗口只有 78px,`bot = (o, h-o-70, ...)` 的 y0 大于 y1,PIL 直接抛
333
+ `y1 must be greater than or equal to y0` —— 点一下 ▾ 就 traceback。高度不够时
334
+ 只返回标题栏那一块。
335
+
336
+ ### Performance
337
+
338
+ - 高斯从 PIL `ImageFilter.GaussianBlur` 换成 `cv2.GaussianBlur`(有 OpenCV 时);
339
+ - GPU 首次渲染 **1137 ms → 79 ms**(几何贴图改用 cv2 缩放,不再 PIL 逐通道);
340
+ - 静止时的探针从 60fps 降到 30fps —— 单次 `grab()` 就要 7ms,空转等于白烧
341
+ 40% 单核;有变化时 `idle` 立刻归零、下一拍恢复全速;
342
+ - 文字翻色从「每个字 `crop()` + `np.percentile`」改成整帧转一次灰度再切片。
343
+
344
+ ### 验证
345
+
346
+ - 视觉:同一背景同一消息,新旧玻璃帧逐像素对比 **均差 0.068、99% 像素差 ≤1**;
347
+ - 交互:折叠 / 展开 / 拖动 / 边缘缩放 / 滚轮 / 改名 / 发送 / 新消息增量 / 关闭
348
+ 全部实跑通过(810×625 与 760×560、折叠 78px 三种尺寸);
349
+ - `node scripts/check-syntax.mjs` 56 files ok;`node --test` **317 pass / 0 fail**。
350
+
351
+ ## [0.2.10] - 2026-11-03
352
+
353
+ > GPU 路径其实一直是坏的,顺便量了一下它到底省不省。
354
+
355
+ ### Fixed — GPU 路径的 GLSL 用了保留字,着色器从来没编译成功过
356
+
357
+ `glass_window_gpu.py` 的 FRAG 里有一行 `vec3 patch = mix(edgep, strong, e);`。
358
+ `patch` 是 GLSL 1.5 起保留的 tessellation 关键字,编译直接失败:
359
+
360
+ ```
361
+ GLSL Compiler failed
362
+ ERROR: 0:24: 'patch' : syntax error
363
+ ```
364
+
365
+ `_work()` 里那句 `except` 把异常吞掉、每帧打一行 `GPU capture failed, falling back to CPU`,
366
+ 然后继续走 CPU —— **所以 `glass_window_gpu.py` 从来没真正跑起来过**,用户能看到的最大线索
367
+ 就是一句每帧刷屏的日志。更糟的是它每帧重建一次 program/FBO 又失败,实测内存涨到 **2.3 GB**。
368
+
369
+ 改个名(`patch` → `tile`)。修完日志干净、内存 200 MB、画面和 CPU 版一致。
370
+
371
+ ### 实测 — GPU 不比 CPU 省(这台机器上)
372
+
373
+ i9-12900HX / RTX 4060 Laptop / 窗口 700×665 / 150% DPI / 静态桌面:
374
+
375
+ | 路径 | CPU(单核) | 内存 |
376
+ |---|---|---|
377
+ | CPU(正常模式) | **49.6%** | 100 MB |
378
+ | GPU(`glass_window_gpu.py`) | 115.6% | 200 MB |
379
+ | CPU(`GLASS_FORCE=1`,调试) | 146% | 111 MB |
380
+
381
+ 两边都有静态跳帧,GPU 多出来的是每帧把 BGRA 上传成纹理(约 2.6 MB/帧)+ moderngl 的
382
+ Python 层调用开销;而 CPU 版在这么小的窗口上本来就够快。GPU 路径更适合「窗口很大 + CPU 较弱」,
383
+ 不是无脑更优 —— **默认继续用 CPU**。
384
+
385
+ ## [0.2.9] - 2026-11-03
386
+
387
+ > 一条根因修得很漂亮的 bug:拖动窗口时的动态模糊。
388
+
389
+ ### Fixed — 拖动窗口没有动态模糊(合 PR #49,作者 @ggfgfgf-on,对应 #48)
390
+
391
+ 现象是「`GLASS_FORCE=1` 下能看到那种黏黏的拖尾,正常启动看不到」,我一开始以为是
392
+ `_motion_blur` 的衰减公式问题 —— 猜错了。
393
+
394
+ 真正的原因在这行:
395
+
396
+ ```python
397
+ if self._sig is not None and box == self._sig_bbox and sig.shape == self._sig.shape:
398
+ ```
399
+
400
+ 拖动窗口时抓取区域 `box = (gl, gt, gr, gb)` 每帧都在变,`box == self._sig_bbox` 永远不成立,
401
+ `moved` 一直是 `False`。于是:
402
+
403
+ - `_motion_blur` 一路乘 0.55 衰减到 0,混合那步一次都不执行;
404
+ - 反而每帧都在做 `apply_chroma(panel, 1.7)`(那是「没在动」时的色散补偿)。
405
+
406
+ `FORCE` 之所以看起来有效,只是因为它跳过静态跳帧、帧数更多,更容易凑出连续可混合的帧 ——
407
+ 它并没有修掉这个判断。
408
+
409
+ 现在 `_sig_bbox` 已存在且 `box` 变了,就把这一帧标成 `moved = True`:抓取区域变了,
410
+ 旧区域的像素本来也不能直接做差,但这确实是运动。静止窗口仍走原来的像素差判断,
411
+ 不会变成常驻拖影。和 #42 不冲突 —— `_invalidate_glass()` 会把 `_sig_bbox` 清成 `None`,
412
+ 形状变化后的第一帧不会误判成 `box_changed`。
413
+
414
+ ### 说明 — 静止画面下没有动态模糊是设计
415
+
416
+ 同一轮确认:`if moved` 这层是故意留的,运动模糊不是常驻滤镜。静止时混上一帧只会把文字和边缘
417
+ 永久糊一层,还会让 `_motion_blur` 维持在高位,停下后回不到清晰;CPU 每帧做一次 `Image.blend` 也不便宜。
418
+
419
+ 想要「低速拖尾」可以做配置项(类似 `motionBlurFloor`,默认 0),但不改默认行为。
420
+
421
+ ## [0.2.8] - 2026-11-03
422
+
423
+ > 三个社区 PR(都是 @ggfgfgf-on)+ 一批失效入口的清理。
424
+
425
+ ### Fixed — 多 P / 选集页面读错 `<video>`(合 PR #45,对应 #44)
426
+
427
+ 旧实现按 `duration` 挑播放器,遇到 B 站多语言版本这种页面,会挑中一个隐藏的 13 分钟长视频,
428
+ 上报的 `pos` 直接跳到 13:42,插件判定「换片了」,陪看中断。
429
+
430
+ 新逻辑:先排除不可见 / 零尺寸 / `opacity: 0` 的候选,再按在视口里占据的面积排序;
431
+ 播放中只加一档权重(不能压过更大的主播放器);认画中画和全屏;整页都不可见才退回全部。
432
+
433
+ ### Fixed — 气泡形状变化后不重合成(合 PR #42)
434
+
435
+ 静态跳帧只看 `_sig_bbox`,只清 `_sig` 不够。气泡/内框形状变了之后,如果桌面本身静止,
436
+ worker 会一直 `return None`,新遮罩和新色散要等用户动一下鼠标才出现。
437
+ `FORCE` 模式下看不出来,只在真机静置时暴露。
438
+
439
+ ### Fixed — `_tick` 每 4ms 重读一次配置(合 PR #47,fixes #46)
440
+
441
+ `not capturable()` 每拍读一次 `watch-window.json` —— `__init__` 早就把结果缓存在
442
+ `self._cappable` 了,这里纯属白花。0.2.7 引入的疏漏,谢谢抓出来。
443
+
444
+ ### Fixed — 删掉失效的 `run-glass*.cmd`,并去掉里面的本机绝对路径(#43)
445
+
446
+ 玻璃渲染重写之后 `DSH_WATCH_GLASS_TTL/FPS/CHROMA/BLUR/SAT` 和 `DSH_GLASS_ACRYLIC`
447
+ 已经没有任何代码读取,但那几个脚本还在设置它们:双击 `run-glass-acrylic.cmd` 以为开了
448
+ 亚克力,实际还是普通软件模糊。静默失效比报错更糟。
449
+
450
+ 现在只留一个 `run-glass.cmd`,开头列清哪些变量废弃、哪些真正有效;解释器也不再写死
451
+ 本机路径(先找 PATH 上的 `pythonw`,再退 `py -3`)—— 这个仓库是公开的。
452
+
453
+ ## [0.2.7] - 2026-11-03
454
+
455
+ > 五个社区 PR 一起收(都是 @ggfgfgf-on 提的),外加录屏模式的两个真 bug。
456
+
457
+ ### Fixed — 录屏/截图根本拍不到窗口
458
+
459
+ 窗口一直开着 `WDA_EXCLUDEFROMCAPTURE`(防截图/直播泄露,这是对的),
460
+ 但社区贡献者要调玻璃管线就必须能录。原来只有环境变量 `DSH_GLASS_WDA=0` 一个入口,
461
+ **而插件拉起窗口时不会传环境变量** —— 于是用户在 `~/.dsh/watch-window.json` 里写了
462
+ `"capturable": true` 也没人读,录出来永远是空桌面。
463
+
464
+ 现在 `capturable()` 真的读配置:环境变量(临时)→ 配置项(持久)→ 默认排除。
465
+
466
+ ### Fixed — 录屏模式下"字一直在闪"、拖尾越滚越浓
467
+
468
+ `capturable: true` 关掉 WDA 之后,**mss 抓背景时把窗口自己也抓进去了**。玻璃拿它当背景
469
+ 等于"透过自己看自己",形成反馈回路:背景里带着上一帧的字 → 亮度判据一直抖 → 字色来回翻;
470
+ 背景一直在变 → `moved` 一直为真 → 一直混合上一帧 → 越滚越浓的假拖尾(静止画面也在"动")。
471
+
472
+ 现在录屏模式下把窗口矩形用**周边均值**刷平(试过按上下边缘插值,相邻列颜色不同会变成
473
+ 一根根竖条,更难看)。窗口外 PAD 一圈仍是真背景,边缘透镜照常。
474
+ 实测同一位置连续 6 帧:帧差从"每次都在变"降到 **0.00**。
475
+
476
+ ### Added — 窗口心跳
477
+
478
+ `<cache>/window-heartbeat`,`_tick` 里每秒最多写一次。宿主那侧靠它区分"进程还在"和
479
+ "窗口真的在画"——只看 pid 的话,pid 被复用或界面卡死时永远认为窗还开着,于是再也不重开。
480
+
481
+ ### Fixed — GPU 抓屏越界(合 PR #40,作者 @ggfgfgf-on,fixes #39)
482
+
483
+ GPU 路径的 `capture_gpu()` 有自己一份 `sct.grab()`,没做 `gr-gl/gb-gt` 守卫;
484
+ 窗口被拖出屏幕时每帧抛 `Region has zero or negative size`,被 `_work()` 吞掉后背景永久停在旧帧。
485
+ 补上和 CPU 路径一样的检查。
486
+
487
+ ### Fixed — 台词 `at: null` 被存成第 0 秒(合 PR #38,作者 @ggfgfgf-on)
488
+
489
+ `Number(null) === 0`,显式写 `at: null` 的台词全被当成"第 0 秒",回读时挤在片头。
490
+
491
+ ### Fixed — 本机 API 的 CORS 与聊天游标(合 PR #35,作者 @ggfgfgf-on,fixes #33 #34)
492
+
493
+ - 聊天/位置 API 原来对**任意网页**放开 CORS,可被跨站写入;改成只认白名单。
494
+ - `chat.jsonl` 被清短之后,聊天页的游标永久卡在越界位置;改成越界自动归零。
495
+ - 新增 `test/chat-server-guards.test.mjs`。
496
+
497
+ ### Fixed — 卸载时没 detach voice adapter(合 PR #31,作者 @ggfgfgf-on,fixes #30)
498
+
499
+ 适配器订阅了 speech bus,插件卸载却没退订 —— `speechSubscribers()` 一直 > 0,
500
+ 重载后循环误以为"有人会念",模型再也不会被叫醒。
501
+
502
+ ### Added — 设置页自动保存(合 PR #32,作者 @ggfgfgf-on)
503
+
504
+ 改一项存一项,不用再点保存;顺带补了声音环境变量提示与连接状态。
505
+
506
+ ## [0.2.6] - 2026-11-02
507
+
508
+ > 陪看的声音还差最后一步:到点才开始合成。这一轮把"合成"从关键路径上挪开。
509
+
510
+ ### Added — `scheduled` 事件(合 PR #36,作者 @ggfgfgf-on)
511
+
512
+ - 循环每一拍把**未来 60 秒内、已经写好且带 `at`** 的台词以 `scheduled` 广播一次(每句一次;
513
+ 只在有会出声的订阅者时发)。它不参与"该不该念"的判断,只给适配器时间预合成。
514
+ - `upcomingLines(input, { after, before })`:只读的"未来台词"查询,不消费稿件。
515
+
516
+ ### Changed — 示例适配器预合成
517
+
518
+ - `examples/voice-edge-tts`:`speakEdge` 拆成 `synthEdge`(只合成)+ `playEdge`(播放并删临时文件);
519
+ `scheduled` 到达即合成,按 `input|segment|text` 缓存(上限 6 条,满时踢 `at` 最远的一条),
520
+ `due` 优先播缓存。日志多出 `prefetched` / `synth`、`ready Nms`、`wait Nms`。
521
+ - `MAX_QUEUE_LAG_MS` 的计时从 `due` **到达**起算,合成时间本来就算在里面 ——
522
+ 预取因此还降低了"排队太久被丢弃"的概率,不只是首声早一点。
523
+
524
+ ### Fixed — 评审补丁(`5fa1307`、`bd5b3c7`)
525
+
526
+ - **跨段时缓存 key 对不上**:`dueLine` 跨段挑 `at` 最小的一句,选中上一段的句子时 `due` 报的却是
527
+ 当前段,和 `scheduled` 的 `segment` 不一致 → 缓存白做、首声又晚回 0.6~2 秒。
528
+ `dueLine({ meta: true })` 现在多返回 `from`,`speak()` 用它。
529
+ - **`Number(null) === 0`**:没写 `at` 的台词会被当成"at=0"挤进预取窗口;适配器 `prefetch()` 同理,
530
+ 6 个槽位被 at=0 占满后永久失效。两处都改成显式判空。
531
+
532
+ ## [0.2.5] - 2026-11-02
533
+
534
+ > 0.2.4 里 PR #28 留下的两个 GPU 尾巴,作者当天补了 PR #29 收掉,外加气泡留白微调。
535
+
536
+ ### Fixed — GPU 内框边缘(合 PR #29,作者 @ggfgfgf-on)
537
+
538
+ - **底部输入/发送框发黑**:内框边缘原来直接拿 `small` 的 render target 当 sampler,
539
+ 贴边小框会采到边界外。现在单独拷一份 blur(1.45) 到 `edgeblur` FBO 再采样
540
+ (注释里写明「直接当 sampler 会触发驱动崩溃」,所以宁可多一次 copy)。
541
+ - **内框边缘的折射/扭曲丢了**:CPU 里 `edge_w=0` 是边缘(取折射样本)、`=1` 是中心
542
+ (取强模糊),Shader 里方向是反的。改成 `mix(edgep, strong, e)` 后恢复。
543
+
544
+ ### Changed — 气泡留白
545
+
546
+ - 横向 14→18,纵向 `+4`→`+16`,正文按 `(bh - lines*ls)/2` 垂直居中。
547
+ 字不再贴着气泡边,短消息也不会挤成一条。
548
+
549
+ ## [0.2.4] - 2026-11-02
550
+
551
+ > 0.2.3 发出去 20 分钟就发了这个 —— 因为它带着一个肉眼可见的毛病:
552
+ > **气泡里的字会一直黑白闪**。另外收了社区 PR #28。
553
+
554
+ ### Fixed — 字一直在黑白闪
555
+
556
+ 气泡是透明的,背后就是桌面/视频/网页。`_adapt_text` 每 0.12 秒按
557
+ `p50 < 0.50` **硬切**白字 `#f2f8ff` / 深字 `#07111d`,画面一动亮度就在阈值附近
558
+ 来回穿 —— 同一段抖动序列 **16 次采样翻 15 次**,肉眼就是"字一直在闪"。
559
+ (这段逻辑 0.2.1 就在,只是 0.2.3 的气泡更透、更容易撞上。)
560
+
561
+ - **滞回**:白的要暗到 0.38 才翻深,深的要亮到 0.62 才翻白,中间的 0.38~0.62 保持现状。
562
+ - **连续两次同向才切**:单帧跳变忽略,最坏 0.24 秒换一次色。
563
+ - 顶部细条同样处理(0.48 硬切 → 0.36/0.60 滞回),并在 `_build_ui` 重建时把
564
+ `_bar_color` 归位,免得条和缓存对不上。
565
+ - 结果:同样 16 次抖动翻 **0 次**;真·明暗切换仍然生效(慢一个采样周期)。
566
+
567
+ ### Changed — 玻璃合成管线(合 PR #28,作者 @ggfgfgf-on)
568
+
569
+ - **小框边缘不再硬切**:气泡/输入框边缘原来直接用未模糊的 raw、中心却是
570
+ blur(2.6),中间二值 edge 一刀切,有一圈"割裂"。现在边缘走 blur 1.45 的帧,
571
+ 再用 smoothstep 过渡。GPU 侧同步;贴边小框仍从 raw 取(用 warped 会采到边界外
572
+ 的黑边,底部输入/发送框会发黑)。
573
+ - **CPU 补齐 GPU 才有的效果**:外缘 R/B 径向色散(2x 合成图上做,索引图按尺寸缓存,
574
+ 缩放重建时释放)、上一帧运动混合。GPU 的 `blend` 改成只在检测到移动时混,
575
+ 停下立刻干净;移动帧跳过色散,先保住拖动/滚动响应。
576
+ - **麦克风回到玻璃帧合成**(`MIC_POS` / `MIC_LIGHT` / `MIC_DARK`),不再在 Canvas
577
+ 上单独建图。这是回退 0.2.3 里 #22 的 Canvas 方案 —— 好处是位置与上游仓库对齐、
578
+ 会被玻璃一起处理;代价是依赖合成帧。
579
+ - **消息气泡改成自适应宽高**:按正文实测折行,时间戳移到气泡上方不再进框,
580
+ 替掉 #22 的固定 88px 四框。短消息不再撑满整行。
581
+ - 兼容层改动态代理,GPU 能看到缩放/气泡的新坐标;缩放重建时释放色散索引缓存。
582
+
583
+ > 验证:311 测试全绿;清空 `chat.jsonl` 冷启动实跑,1 条短消息 / 4 条混合长度
584
+ > (含多行、超长)都正常渲染,输入/发送框无发黑。
585
+
586
+ ## [0.2.3] - 2026-11-02
587
+
588
+ > 主题:**悬浮窗这一轮收口** —— 社区提的 #22 / #23 / #25 / #26 / #27 全部合进来,
589
+ > 核心与 TTS / 悬浮窗之间的依赖收成 `runtime-ports`。
590
+ > 播放位置、台词锚点、语音调度这些**一处没动**;变的只有窗口和它下面那层接口。
591
+
592
+ ### Added — 核心只认 runtime-ports(合 PR #22)
593
+
594
+ - 新增 `src/runtime-ports.js`:**唯一**给出 TTS / 悬浮窗适配器的地方。
595
+ `chat-store` / `watch-loop` / `watch-actions` / `input-surface` 不再直接
596
+ `import` `voice.js` / `floating-window.js` / `window-protocol.js`。
597
+ - `installPorts()` / `resetPorts()` / `getTtsPort()` / `getWindowPort()` 从 `public-api` 导出,
598
+ 宿主或测试可以注入自己的实现;裸 `import` 仍拿历史默认(speech bus + 内置窗口),
599
+ CLI 和老测试照旧能跑。
600
+ - `test/decoupling.test.mjs` 守这条线:核心模块一旦直接依赖实现就红。
601
+
602
+ ### Changed — 悬浮窗气泡与折叠重做(合 PR #22)
603
+
604
+ - **气泡改成「时间头 + 正文折行」**:`_fit_lines()` 按框宽/框高折行,标点不落行首,
605
+ 超长截断加省略号;四条气泡统一 88px 并吃满内容宽度,不再为了塞下文字把字号压到 9。
606
+ - **折叠不再重建整窗几何**:只缩窗口 + 只画标题栏。原来 `rebuild_geometry(78)` 会在
607
+ `rounded_mask` 抛 `y1 must be >= y0`,**折叠直接异常**(main 上可复现)。
608
+ - **每 1.8 秒重新置顶一次**:DSH 抢焦点后浮窗不再被压下去。
609
+ - **麦克风改 Canvas 矢量图标**,不再往合成帧上贴第二层;GPU 路径同步去掉。
610
+ - 补三处收尾:空态分支还在用已删掉的 `bh` → 清空 `chat.jsonl` 冷启动直接 `NameError`,
611
+ 窗口起不来;标题改回**双击**改名(单击要留给按住拖动);折叠态跳过抓屏,
612
+ 否则遮罩尺寸不符会每帧刷一条 `images do not match`。
613
+
614
+ ### Fixed
615
+
616
+ - **拖到屏幕外不再花屏**(合 PR #23)—— `_x` / `_y` 只在启动时读一次,拖动后已过期;
617
+ 加上越界钳位后仍可能算出 0 或负的抓屏尺寸,`mss` 抛 `Region has zero or negative size`,
618
+ 异常在 `_work()` 里被吞掉只打一行的结果是:每帧一条日志、背景永远画不出来。
619
+ 现在拖动/缩放分支都钳位,并在抓屏前直接挡掉非正尺寸。
620
+ - **`window` 接口的 hide/show 兼容只返回布尔的实现**(合 PR #25)—— 以前拿返回值当对象解构,
621
+ 实现只回 `true` 时 `hide` 变成静默失败。
622
+ - **snapshot 模式不再被 `_tick` 重新打开 WDA**(合 PR #26)—— worker 已暂停,
623
+ 下一拍却把 WDA 开回来,窗口再次从截图/录屏里消失,`_snapshot_mode` 等于没做。
624
+ - **折叠不再跳回原位、折叠背景有圆角、标题栏排版收紧**(合 PR #27)——
625
+ `_sync_pos()` 在 `_release` 与 `toggle_collapse` 前同步真实坐标(`_x/_y` 过期会让窗口弹回启动位置);
626
+ 折叠态按 78px 重新贴圆角遮罩,不再直接裁 `_last_frame` 留一条硬边;
627
+ `_save_geometry` 存**展开高度**,否则下次启动按 78px 恢复;折叠时 `_tick` 不再消费旧队列,
628
+ 避免 560px 的帧贴回 78px 画布闪一下;状态点/名字/计数统一到 y=38 中线,字号 21→16。
629
+ 实测对照 main:拖到 (300,220) 折叠后停在 (300,220)、配置写 `760x560+300+220`,
630
+ main 会跳回 (1720,480) 并写 `760x78`。
631
+
632
+ ### Docs
633
+
634
+ - **README 挂上赞赏码**(微信,`docs/images/reward-qr.png`)。写法上明确一句:
635
+ 打赏**不解锁任何东西**,也不影响这个项目以后的授权方式 —— 它仍然是 Apache-2.0。
636
+
637
+ ## [0.2.2] - 2026-11-01
638
+
639
+ 只改元数据,不动行为。
640
+
641
+ - `package.json` 补 `dsh.catalog`(category / 中英双语 summary / capabilities)——
642
+ 社区插件市场直接读 npm 上带 `dsh-plugin` 关键词的包,每天同步一次、没有提交入口;
643
+ 有 `dsh.catalog` 时市场页面展示的是这里写的分类和摘要,没有就退回 npm description。
644
+
645
+ ## [0.2.1] - 2026-11-01
646
+
647
+ 两项都是从社区审计(#18 / #16)来的,各配了回归用例。
648
+
649
+ ### Added — 插件设置页(合 PR #11, closes #10)
650
+
651
+ 设置直接渲染在 DSH 插件详情页(`plugins.bundle.config`),不再用 iframe / 内嵌滚动窗口;
652
+ 「设置 → 内置插件」的 tab 也还在。
653
+
654
+ - 表单:`browserPort`(共享 `video.json`)、`chatPort`(`watch.json`)、语音适配器(`voice.json`)。
655
+ - **依赖自检**:ffmpeg/ffprobe、Python、`dsh-video-storyboard`、浏览器扩展、悬浮窗脚本;
656
+ 缺什么就直接给官方下载入口,已装的显示「已安装」。插件**不会**静默安装或替你执行下载。
657
+ - 修核心包误报:`dsh-video-storyboard/package.json` 不在 `exports` 里,改成解析 `dist` 信息。
658
+
659
+ ### Changed — 悬浮窗换成实时捕获管线,模块拆成接口(合 PR #20)
660
+
661
+ - **窗口实现换代**:`examples/floating-chat/window.py` 以 PR #15 的实时捕获管线为底稿重写
662
+ (1454 行,原 3372 行)。每帧抓屏 → 1/4 尺度模糊 → SDF 边缘折射 → 透镜采样 → 合成,
663
+ 静帧时整条管线跳过。**依赖变化**:`mss` 和 `numpy` 从可选变必需,缺了窗口起不来。
664
+ - **保留并补齐交互**:双击标题改名、▾ 折叠/展开、系统行(meta)、发送回写、位置保存、
665
+ 麦克风图标、滑入动画。输入框仍是"画布上画字 + 2×2 的 Entry 只收 IME/键盘"。
666
+ - **模块解耦**:`src/interfaces.js` 组合识别 / TTS / 悬浮窗三个接口,`handler.js` 与
667
+ `watch-loop.js` 只调接口、不再直接 import 实现(`docs/INTERFACES.zh.md`)。
668
+ - **窗口线协议**:插件写 `window-events.jsonl`、窗口写 `window-outbox.jsonl`,
669
+ Python 侧 `window_protocol.py` 只共享线格式;旧版只写 `chat.jsonl` 时窗口继续兼容。
670
+
671
+ ### Fixed — 无音轨视频不再卡在"缺台词"门槛(fixes #18)
672
+
673
+ `noListen` 之前只改了文案,**没有参与 `hasLines`** —— 无可等台词时 `segLines` 为空,
674
+ `hasLines` 恒为 false,于是 `spoken` / `lastDelivered` 都不写,每次调用都落回同一段、
675
+ 永远带 `[DELIVERY INCOMPLETE]`。这不是"模型不肯写台词",是状态机不推进。
676
+
677
+ - `noLinesNeeded = Boolean(noListen)` 参与 `hasLines`:没音轨 / 没配 ASR / 连不上 / 这段真静音时,
678
+ 画面这一半就算交付完成。
679
+ - 没有台词可等时**不再提示"先取字幕"**(取了也不会有),也不说"本段台词已就绪"。
680
+ - `[听音]` 段补一句"这一段也没有台词可等,用你看见的画面说一句即可,别编对白"。
681
+ - **普通视频的台词门槛保持原样**:有声有字幕但没写台词,仍然 `complete=false`。
682
+
683
+ ### Fixed — 叫醒失败不再刷屏,确定性失败不再空等(fixes #16)
684
+
685
+ `no-session-controller`(当前进程没有 DSH 会话控制器)和 `no-session-id` 是**确定性**失败,
686
+ 以前每次都要等 800ms 再重试,并且每次都往 `chat.jsonl` 写一条 `[一起看] 叫醒失败`;
687
+ 持续故障时悬浮窗会被几十条一样的 meta 刷满。
688
+
689
+ - 这两类失败**不重试**;其他偶发失败仍重试一次。
690
+ - 失败提示按 `(sessionId, reason)` 节流:**60 秒内只显示第一条**,静默期里折叠掉的次数
691
+ 在下一次显示时带上("同类失败另有 19 次已折叠")。
692
+ - `no-session-controller` 的提示补一句可行动的说明(从 DSH 里启动,或先关掉陪看循环)。
693
+
694
+ ## [0.2.0] - 2026-11-01
695
+
696
+ 这一版把悬浮窗的玻璃重做了。三块独立玻璃、底色真正跟着背景走、静帧不空转、
697
+ 边缘不再是"放大贴纸"而是把框外画面折进来;同时把「听不到声音」这件事从
698
+ "模型答不上来"变成"能直接说清原因"。
699
+
700
+ ### 听不到声音,不再只有一个答案
701
+
702
+ 用户反馈(2026-11-01,B 站评论区):「能看视频,但是听不了」「没有音轨」。
703
+ 文档里写清楚了要装 ASR,但**运行时没有任何地方告诉用户这件事** —— 模型只能回一句"我听不到",
704
+ 用户于是以为插件坏了(同一个问题在评论区被问了十几遍)。
705
+
706
+ - `explainCuesFailure()`:把每种原因翻成**一句能直接说给用户听的话**(没配 ASR / 装了连不上 /
707
+ 这份副本没音轨 / 听了但没说话 / 字幕要登录)。`transcriptOnly` 的返回和陪看交付共用这一份文案,
708
+ 不再各写一遍。
709
+ - `asrCues` **不再把"没配 key"和"服务连不上"糊成 `asr-empty`**(那是"这片子没人说话",
710
+ 一个会误导人的结论)。没配 key 时连请求都不发 —— 以前会照发,401 被吞掉。
711
+ - 陪看交付新增 `[听音]` 段(同一部片子只详说一次,之后一句短的):用户问"你怎么听不到声音"时,
712
+ 模型手里终于有依据。**没句子时门槛改成"用画面说一句、别编对白"**,而不是硬逼出一段台词。
713
+ - 修 `findCachedMedia`:拿不到 BV 号时原来会 `return video` —— 返回媒体目录里碰到的**第一个**
714
+ `video.mp4`,于是拿**另一部片子**的音轨去转写。台词全错,而且一句都不报。
715
+
716
+ ### 玻璃底色跟着背景走
717
+
718
+ 用户原话:「太卡顿,而且刷新很慢……经常是背景换了,液态玻璃还没动,还没变颜色。」
719
+
720
+ 根因不在渲染算法,在**缓存永不过期**:整屏截图只在开窗那一刻做一次(`_stage` 的注释还写着
721
+ "之后无论拖到哪儿都是裁一刀"),所以对面视频换场景、桌面换壁纸,这块玻璃永远是开窗时的颜色。
722
+ 拖动结束后那个"8 秒才值得重截"的判定也救不了**静止**的窗口 —— 而陪看时窗口恰恰是静止的。
723
+
724
+ 现在:
725
+
726
+ - **按 TTL 定时重截**(`DSH_WATCH_GLASS_TTL`,默认 **600ms**,0 = 关掉回到旧行为)。
727
+ - **截屏在子线程**(抓屏 + 1/4 缩放 + 模糊 + 色散 + 提饱和),主线程只做裁片 + 贴图(1~2ms)。
728
+ Tk 对象一个都不在子线程碰 —— 屏幕尺寸、缩放系数都在主线程读好再传。
729
+ - **优先用 `mss` 抓屏**(可选依赖,见 `examples/floating-chat/requirements-glass.txt`):
730
+ 整屏 38ms vs ImageGrab 71ms,全管线从 ~200ms 降到 ~98ms,所以 TTL 才敢压到 600ms。
731
+ 没装就自动退回 ImageGrab。
732
+ - **新增 `_repaint_glass()`:只换玻璃不动内容**。`_paint()` 末尾会 `_reflow()` 重排所有气泡,
733
+ 为了换一层底色付这个代价不值得;现在只 `delete("panel")` 再贴一张。
734
+ - `_glass_busy` 防重入:上一发没回来就跳过这一拍;窗口隐藏/折叠时根本不截。
735
+
736
+ 实测(本机 2560×1600 / 150% 缩放,TTL=500ms):3 秒内 6 次截屏,底板时间戳推进 3.3 秒,稳定。
737
+ 抓屏基准:mss 38.3ms / ImageGrab 71.0ms;mss 全管线(抓 + 1/4 缩 + 模糊)98.6ms。
738
+
739
+ **依赖**:Pillow + 可选 `mss`(**0.1MB**、纯 Python 无编译)。numpy 不需要。
740
+
741
+ **踩到的坑**:第一版把 `_glass_ttl_start()` 插进了 `poll()` 末尾(那个方法每 200ms 自己再排一次),
742
+ 于是每拍都重启一条定时链 —— 实测 3.2 秒触发 16 次、截屏频率飙到 9Hz。加了 `_glass_started` 锁。
743
+
744
+ ### 液态玻璃重做(本轮)
745
+
746
+ 三块**分离**的玻璃(标题栏 / 主体 / 输入栏,中间 10px 真缝,缝里透出桌面),
747
+ 滚动条移到主体右侧外面,不占消息区。
748
+
749
+ - **`WDA_EXCLUDEFROMCAPTURE`**:让窗口从屏幕捕获里消失,于是抓"自己背后"时
750
+ **不用把 `-alpha` 设 0 再恢复** —— 那个来回会逼 DWM 把整个桌面重排两次,
751
+ 视频在播时最贵,肉眼就是"松手闪一下"。`DSH_GLASS_WDA=0` 可关(录屏要用)。
752
+ - **静帧跳帧**:用未模糊的原图缩到 48×30 比灰度差,`mean>0.8` 才算动了;
753
+ 没动且运动已停 0.3 秒就直接复用上一帧,整条管线(抓屏 17ms + 糊 + 色散)全跳过。
754
+ 慢速滚动不会先停一两帧 —— 阈值比"定时到点就重算"灵敏。
755
+ - **边缘折射换成 SDF 法线向外采样**:老做法是"整图放大一点、再按边缘权重把放大版盖回",
756
+ 边缘看到的是**自己被放大的内容**,像贴了层凸透镜贴纸。现在沿圆角矩形 signed distance
757
+ field 的梯度法线**向外**取样本,边上一窄条里塞的是**框外**的画面,被压扁折进来。
758
+ - **底板 1/8 → 1/4**:1/8 放大 8 倍时边缘和背景细节都发虚。
759
+ - **文字可读性**:新增 `text_on_glass()`(整段文字 + 右下 1px 深色影子)和
760
+ `on_glass_fill()`(按那个点的背景亮度决定用浅字还是深字)。影子用在气泡正文、
761
+ 标题栏名字、系统行、输入槽;翻色用在标题栏名字。
762
+ **没有逐字建 item** —— 玻璃上几十像素内明暗本来就不变,整段取一次样就够,
763
+ 长列表滚动时 item 数不翻倍。
764
+
765
+ **依赖**:Pillow + 可选 `mss`;**numpy 也是可选**(只给 SDF 折射用,没装自动退回老折射)。
766
+
767
+ ### 参考并移植了上游的 PR
768
+
769
+ - **#13 `feat/liquid-glass-speed`**:O(n²) → O(n) 的追加优化(只 layout 新气泡、resize debounce 70ms、
770
+ Configure 合并到 16ms、after_idle 批量、mtime 缓存、玻璃尺寸没变不重画、拖动只画边框)。
771
+ 它的数据是 210 条消息从 14.22s 降到 605ms(23×)。**这次没合**:那个 PR 基于 1314 行的旧
772
+ `window.py`,我们这边已经 2632 行(液态玻璃二版 + 本轮改动),冲突面太大;但思路(尤其
773
+ "玻璃尺寸没变不重画")以后可以逐条移植。
774
+ - **#15 `feat/live-glass-window`**:独立一套 `glass_window.py` / `glass_window_gpu.py`。
775
+ **没有整包拿过来**(它是第二套 UI,切过去会丢掉气泡、meta、入场动画、折叠、改名这些交互),
776
+ 而是逐项移植了它的机制:`WDA_EXCLUDEFROMCAPTURE`、静帧跳帧、SDF 法线折射、1/4 底板、
777
+ 文字影子与按背景翻色。GPU 合成(moderngl)没有采用 —— 需要额外依赖且仅限 Windows/OpenGL 3.3+。
778
+
779
+ ## [0.1.1] - 2026-11-01
780
+ **依赖升到 `dsh-video-storyboard@^0.6.0`。** 分镜从"固定宫格"改成"档位排布"——
781
+ 一格 = 一个镜头、格子大小跟切点密度走,`boardOptions()` 返回的参数从
782
+ `cells / sheets / minGap` 换成 `maxFrames / maxSheets / minFrames`。旧的参数名在 0.6.0 里已经不存在,
783
+ 所以这一版**必须**配 0.6.0 及以上,不能和 0.5.x 混装。
784
+
785
+ ### 台词写完之后不再递整段清单(防剧透)
786
+
787
+ 用户反馈"老是剧透后面的"。根因不是提示词不够狠:写台词时必须把整段 5 分钟的清单交出去,
788
+ 写完它仍然留在上下文里,模型就会把它当成"我知道后面"的凭据 —— 光说"不许提"压不住真实内容。
789
+ 现在台词一就绪就换成一句简报("台词已就绪,清单不再提供"),模型手里真的没有后面的信息。
790
+
791
+ 顺带在提示词里加了一句自问:「这句话是不是只有已经看过 xx 秒之后的人才写得出来?」
792
+ 不确定的事用"现在"而不是"接下来"。
793
+
794
+ ### Liquid glass, second pass — the window was still ugly (2026-11-01, later)
795
+
796
+ Verbatim feedback: "看一下 watch-together 的悬浮窗设计,太丑了现在" — the first liquid-glass pass
797
+ had the vocabulary right and the physics wrong. Five defects, all of them visible in a screenshot:
798
+
799
+ **The corners were not round.** `round_rect` and `squircle_mask` both used a superellipse with
800
+ `n = 5`, and at `n = 5` the curve is within 0.6% of the straight edge until the last few pixels —
801
+ a 22px radius rendered as a near-square corner with a tiny fillet. `squircle_mask` had a second,
802
+ independent bug: the row-solve was inverted (`x` grew from 0 instead of `r`), which cut the corners
803
+ out as *squares*. Both now use `n ≈ 2.2` and solve each row's span directly (O(h) instead of O(w·h),
804
+ and it buys 2× supersampling for free).
805
+
806
+ **The chrome was opaque.** The header was a `tk.Frame` and the composer a second one; Tk widgets
807
+ must have an opaque background, so the top and bottom strips of a "glass" window were dead black.
808
+ Both are now drawn on the canvas (status dot, title, count, `▾`/`✕` as hit-tested canvas items,
809
+ the input well as a rounded polygon). Only the `Entry` stays a real widget — it has to be opaque, so
810
+ it lives inside a deliberate *inset* well.
811
+
812
+ **Bubbles were paper.** Each one was filled with a flat `#3a4459`. They are now cut from the same
813
+ blurred backdrop as the panel (`plate()`), with only a white/blue wash on top — they transmit what
814
+ is behind them.
815
+
816
+ **Tint was global and blue.** One tint for the whole window, and a blue-grey `#171a21`, which fights
817
+ every colourful frame it sits on. Tint is now per-plate and *neutral*: measure that plate's mean
818
+ luminance and solve for "how opaque does the ink need to be to land under 84" (`a = (L-84)/(L-12)`).
819
+ Over a white page it darkens itself; over a dark scene it stays transparent.
820
+
821
+ **The sheen was made of lines.** Diagonals stacked with a 3px step left a visible weave across the
822
+ panel. Every gradient is now computed on a 16×16 canvas and upscaled bicubically.
823
+
824
+ Also added: **dispersion** (warm outside, cool inside, full strength around the whole chamfer and
825
+ stronger at the four corners, because a fillet has curvature everywhere but compound curvature at
826
+ the corners), **edge fading** in the message list (rows fade in/out across a 30px band instead of
827
+ popping at the clip boundary — suppressed on the side that has no more content, otherwise the newest
828
+ message is permanently the faintest), a **200ms entrance** per new bubble (8 frames: 10px rise +
829
+ alpha ramp + text colour lerp), and **smooth scrolling** (5 frames × 16ms) so the fade band has
830
+ something to fade across. The scrollbar moved out into the margin beside the panel.
831
+
832
+ Two long-standing bugs fell out of this: `Meta.paint` ended with a leftover `self.cv.tag_lower("bg")`
833
+ from the pre-canvas version — `Meta` has no `cv`, so the exception aborted `_reflow` mid-list and only
834
+ the newest message was ever visible; and the backdrop image was created after the messages without
835
+ `tag_lower`, so any repaint buried them.
836
+
837
+ ### Performance — the glass was re-baked on every frame (2026-11-01, same session)
838
+
839
+ "背景的模糊还是很卡" — measured, not guessed. One panel plate cost **520ms**, a slab 90ms,
840
+ a bubble 28ms. The culprit was `_ring`: it built **two full-size fill masks and subtracted them**,
841
+ and every plate needs five or six rings (rim, soft rim, bottom shade, warm, cool, edge weight), so
842
+ a 665×594 panel spent ~100ms in that one function plus ~15ms per `squircle_mask`.
843
+
844
+ Three fixes, in order of payoff:
845
+
846
+ - **Ring solved per row, no intermediate images.** A ring's row is just two short segments — left
847
+ and right — so the inner and outer x are solved directly (`_ring`), and middle rows are skipped
848
+ entirely. O(h) instead of O(w·h), and no subtraction allocations. 100ms → 3.7ms.
849
+ - **Everything smooth is computed at ¼ scale.** `_corner_weight`, `_edge_weight` and `refract`'s
850
+ bevel weight are soft blobs, not features: build them at 665/4 and upscale bilinearly. Gaussian
851
+ blur cost drops 16×, and the bevel mask (14 rectangle outlines over the full image) went from
852
+ ~20ms to ~1ms.
853
+ - **Supersampled masks now downsample with `Image.BOX`** instead of LANCZOS. For an exact 2×
854
+ reduction BOX *is* the 2×2 average — same result, ~4× faster. `squircle_mask` 15ms → 4.9ms.
855
+
856
+ Result: panel 520 → **50ms**, slab 90 → **6.8ms**, bubble 28 → **8ms**; `_paint` with a warm cache
857
+ **1.3ms**, `_reflow` **0.5ms**, cold repaint (backdrop changed) **76ms**, window open **387ms**.
858
+
859
+ Also: the R/B channel-scaled displacement (`chroma_edge`) is now **off by default**
860
+ (`DSH_WATCH_CHROMA_EDGE=1` turns it back on). It cost two full-size channel resizes per plate
861
+ (+18ms) and was invisible — the backdrop is already blurred and inked, so there is no contrast left
862
+ at the rim to disperse. The visible dispersion is the warm-outside/cool-inside tint pair, which stays.
863
+
864
+ Finally, resizing no longer re-bakes: while the resize grip is held the panel is a bilinear scale of
865
+ the last baked plate (1.2ms instead of 50ms), and a precise re-bake happens 300ms after release.
866
+
867
+ ### Performance, second pass — the backdrop was recomputed on every mouse release (2026-11-01)
868
+
869
+ "超级卡,绝对不止一两百毫秒" … "拖动根本不会刷新" … "碰到屏幕边缘松手百分百闪一下".
870
+
871
+ Measured, the picture was different from the first pass: `_paint` was already fast (1.3ms warm),
872
+ but **every time a drag or resize settled**, `_refresh_backdrop` cost **165ms** — and during the drag
873
+ the backdrop never updated at all, because refresh was debounced to 420ms after release.
874
+
875
+ What was actually slow, in order of payoff:
876
+
877
+ - **`_ring` built two full-size fill masks and subtracted them**, and every plate needs five or six
878
+ rings. Rewritten to solve each row's inner and outer x directly and draw two short segments —
879
+ O(h), no intermediate allocations. 100ms → 3.7ms per plate. (While rewriting it I dropped the
880
+ `width` argument on the floor: the band came out as "from the edge to `inset`", which made a
881
+ 1px highlight vanish entirely and pushed the inner shade line onto the rim, darkening it. The
882
+ tell was "the glass has no edge and looks grey". Fixed by solving both boundaries properly.)
883
+ - **Everything smooth is now built at ¼ scale and upscaled**: curvature weight, dispersion weight,
884
+ and the bevel weight in `refract`. They are blobs, not detail. Gaussian cost drops 16×.
885
+ - **The "light" layers are pure geometry** — sheen, rim, inner shade, warm/cool fringes do not
886
+ depend on the backdrop at all. They are composed once per size into `_light_overlay` and cached;
887
+ a re-bake now pays one `alpha_composite` instead of six.
888
+ - Tint and wash are both flat colours over flat colours, so they are blended into a single colour
889
+ and applied once. Mean luminance is measured on a 48×48 copy (the mean does not care about
890
+ resolution). 2× supersampled masks downsample with `Image.BOX` instead of LANCZOS.
891
+ - **The stage is now one full-screen capture at ¼ resolution**, taken at open while the window is
892
+ still withdrawn. Any later position is a *crop*, never a re-grab — the old "window + margin"
893
+ stage ran out of bounds whenever the widget was near a screen edge, and falling out of bounds
894
+ is exactly the "release → hitch → flash" the user was seeing.
895
+ - **Dragging refreshes live**: `_live_backdrop()` crops from the stage and `_paint_glass_only()`
896
+ swaps only the panel and the two slabs — the header, bubbles and composer do not move relative
897
+ to the window and are not redrawn. Throttled to 30ms (the mouse is 120Hz). Two hidden costs fell
898
+ out of this: `_window_rect()` calls `update_idletasks()`, which silently ran a *full* repaint on
899
+ every frame (+17ms), and position-only `<Configure>` events repainted the entire window.
900
+ - Bubble plates are invalidated by their own counter (`chat_glass_ver`), so a small drag no longer
901
+ re-bakes six bubbles per frame; only panel/slab caches are dropped.
902
+ - Edge-of-screen windows now only need to *overlap* the stage, not sit inside it; the off-screen
903
+ part is cropped short and padded. And a settle within 8s of the last capture does not re-capture
904
+ at all — the stage is refreshed for free while the window is hidden.
905
+
906
+ Numbers (665×594 panel, 150% DPI): a panel plate 520ms → **7.7ms**, slab 90 → **0.9ms**, bubble
907
+ 28 → **0.9ms**; `_paint` warm 1.3ms, `_reflow` 0.5ms; **dragging costs 24–28ms per frame (~38fps)
908
+ where it used to be frozen**; window open 510ms including the full-screen stage.
909
+
910
+ ### Fixed — optional services must go through `ctx.get()`
911
+
912
+ `ctx?.attachments?.saveImage` looks like a runtime probe but throws in a real host: cordis's `ctx`
913
+ is a Proxy whose `get` trap **throws** `cannot get property "xxx" without inject` when a service was
914
+ not declared in `inject`. `?.` only guards `null`/`undefined`, not exceptions.
915
+
916
+ All optional-service lookups now go through `serviceOf(ctx, name)` (in `src/timer.js`): it prefers
917
+ `ctx.get(name)` — cordis's documented way to ask for an optional dependency, returning `undefined`
918
+ when absent — and only falls back to property access inside a `try`.
919
+
920
+ ### Liquid-glass window, one stream, and a name you can change (2026-11-01)
921
+
922
+ Reported as: the scripted lines (warm amber, with a "台词" label) and the assistant's replies (cool
923
+ grey, labelled "陪看") read like two different people talking in one stream — and the window itself
924
+ looked like a plain dark panel.
925
+
926
+ **One stream, one look.** `ROLE` now maps `line` and `assistant` to the *same* colours, and the head
927
+ line shows **only the timestamp** — no "台词", no "陪看". Only the user's own messages keep a tint
928
+ (so you can still tell which side you are on).
929
+
930
+ **Timestamps are wall-clock now** (`HH:MM:SS`), for every role. Scripted lines used to show their
931
+ playback position (`01:26.0`) while everything else showed local time — two time bases in one
932
+ stream, so reading it meant converting in your head. Seconds are included because a segment runs
933
+ 2–5 minutes and several messages share the same minute; `HH:MM` alone would make the stamps useless
934
+ for telling them apart. A message with no `at` gets no head line at all (an empty label still eats
935
+ a full line of height).
936
+
937
+ **Liquid glass.** Three things carry the effect, because tkinter cannot blur what is behind it:
938
+
939
+ - **24px+ radius** — and `round_rect` no longer uses `smooth=True`, which renders a 22px radius as
940
+ roughly 14px (it smooths a polygon rather than following an arc). It now samples each corner arc
941
+ directly.
942
+ - **A refractive edge**: a 1px inner highlight along the top, plus an outer border split into a lit
943
+ upper half and a shadowed lower half — what a real piece of glass does.
944
+ - **Slight window transparency** (`-alpha 0.975`, `DSH_WATCH_GLASS_ALPHA` to tune, ≥1 disables).
945
+ The desktop shows through just enough to read as glass without competing with the text.
946
+
947
+ Buttons and the input field are **pills** now (`Pill` class + a Canvas-backed field): a square
948
+ "发送" button next to a 24px-rounded panel was the most obviously un-Apple thing left.
949
+
950
+ **The title is editable.** Click the name in the header, type, press Enter — saved as `name` in
951
+ `~/.dsh/watch-window.json` and restored next launch. Committing uses an explicit `_editing` flag
952
+ rather than `winfo_ismapped()`, which is still `False` on the frame right after `pack()` and would
953
+ silently swallow a fast Enter.
954
+
955
+ **Fixed:** `meta` entries (wake failures, mic status) were falling through to the assistant bubble
956
+ style — a screenful of `[一起看] 叫醒失败` rendered as full-size cards. They now use the grey
957
+ one-line `Meta` row that already existed for exactly this.
958
+
959
+ **Fixed:** the saved geometry was clamped against `sw - 120` instead of the window's own width, so a
960
+ 700px-wide window could be restored 580px off the right edge.
961
+
962
+ ### No more self-made "queued messages", one reminder per interjection, and a hideable window (2026-11-01)
963
+
964
+ Reported as three things that turned out to be one root cause plus two design gaps.
965
+
966
+ **The queue strip.** `wakeSession` delivers through `agent.followup()`, which lands in the host
967
+ inbox's `next-turn`. DSH's `QueueDock` renders **every** row of `next-turn` and does not filter by
968
+ `source.kind` — so the plugin's own instructions showed up in the input box as pending messages the
969
+ user never typed ("插话栏自动出现"). Two consequences fixed here:
970
+
971
+ - **The hangup note no longer goes through `followup`.** Closing the window is still a hangup (clock
972
+ stops, nothing is rebuilt, no lines are spoken), but the explanation is now written into
973
+ `watch.json` and handed to the model on its next tool result (`takeHangupNote`). The watch loop
974
+ already has the model blocked inside an interrupted tool call, so nothing is lost — and the queue
975
+ strip stays empty. `markHungUp(input, env, note)` carries the text; taking it clears it.
976
+ - **`[未回应]` is emitted once per interjection.** It used to be appended to *every* tool result
977
+ until the model answered with `say`, so one message from the user could be read as three separate
978
+ events ("大肥鱼已经重复了"). `noteInterjected` also no longer restarts the clock when the same
979
+ sentence arrives twice inside the 3-minute TTL.
980
+ - **The interjection prompt is two sentences, not a wall of ⚠️.** Same requirements
981
+ (`say` first, `speakNow`, lines in the same call), a fifth of the length — it is rendered in the
982
+ queue strip, so its size is user-visible.
983
+
984
+ ### `window: "hide" | "show"` — put the window away without ending the watch
985
+
986
+ Closing the window means "I am done watching". Hiding it does not: the process stays alive, the
987
+ clock keeps running, lines keep being spoken, nothing is marked as hung up. Reported as
988
+ "如果有其他功能隐藏悬浮窗会更好".
989
+
990
+ - `watch_together({ window: "hide" })` writes `hidden: true` into `~/.dsh/watch-window.json`;
991
+ `window.py` polls its config every 200 ms (`_sync_visible`) and does `withdraw()` / `deiconify()`.
992
+ `withdraw` rather than `iconify`: an always-on-top floating window should leave no taskbar entry
993
+ behind.
994
+ - `openFloatingWindow` clears `hidden` **before any early return**, so a window that was hidden when
995
+ the process died does not come back invisible.
996
+
997
+ ### Two-track prefetch (2026-11-01) — subtitles no longer wait for the pictures
998
+
999
+ The picture side is the slow one: a segment costs a download plus a scan (10–20 s, 20–90 s for the
1000
+ first), while the text for the same window arrives in a few seconds (site CC: instant; local ASR
1001
+ RTF 0.019 ≈ 6 s per 5-minute segment). They used to be produced and delivered as one package, so
1002
+ the text sat in the slow batch's shadow. Now they are two independent tracks over the **same**
1003
+ batch table and the **same** look-ahead window.
1004
+
1005
+ - **New subtitle track** (`transcribe` → `dsh-video-storyboard/transcript-pass`). Mirrors the picture
1006
+ track line for line: same `plan.indexAt` / `windowAt`, its own `transcribed` set. "Whoever's window
1007
+ is full stops first" falls out of `find()` returning `undefined` — no extra rule.
1008
+ - **Two-part delivery.** When the text lands before its pictures, it is sent on its own
1009
+ (`[一起来看·台词] 03:00–06:00` + one timestamped sentence per line). When the picture batch
1010
+ arrives later it is built with `omitTranscript`, so the cells carry only times and the sentences are
1011
+ not repeated (measured: 17k vs 26k tokens per 2 hours, +50% when repeated).
1012
+ - **`feedTranscriptLeadMs`** (default 0 = send as soon as it lands). Raise it to ~20000 if the
1013
+ two-part delivery feels chatty and you would rather wait for one combined message.
1014
+ - **`transcriptTrack: false`** turns the whole track off.
1015
+ - **Failures don't sink the loop.** A failed transcription is not marked as done, so the next tick
1016
+ retries; three failures in a row blacklist that segment for 10 minutes (a missing ASR service
1017
+ should not be hit every 2 seconds). The picture track is never blocked by it.
1018
+ - **Cross-track timestamps now share one clock.** `transcribedAt` / blacklist times were stamped with
1019
+ `Date.now()` while the tick compares against the injectable `deps.now()`; the difference was
1020
+ negative by a trillion milliseconds, so the "skip for 10 minutes" and "wait N ms before feeding"
1021
+ gates were both permanently bypassed (feeding never fired at all).
1022
+
1023
+ ### Experience pass (2026-11-01) — the minutes spent staring at nothing
1024
+
1025
+ Same code, same contract; what changes is what the user sees (or hears) while waiting.
1026
+
1027
+ - **A slow build now says something.** The first batch of a film needs a download plus a scan
1028
+ (20–90 s) and a tool call cannot speak — so the window stayed empty and the only signal was
1029
+ silence. After 4 s of building (`DSH_WATCH_SLOW_BUILD_MS`) one `meta` line is appended to the
1030
+ stream: 「正在取 03:00–06:00 这一段…」. Fast segments write nothing.
1031
+ - **The measured latency is finally used on the main path.** `latency.js` has been calibrating
1032
+ "read position → result ready" for a while, but only the background clock (`shouldSpeak`) spent it;
1033
+ the blocking call still waited until `segment end - lead`, so on the same machine the clock spoke
1034
+ early and the tool call spoke late. `deliveryState` now uses `lead + aheadSeconds`, while the text
1035
+ still reports `lead` (what is pulled earlier is the work, not the sentence).
1036
+ - **Calibration only counts deliveries.** Not-yet calls take tens of milliseconds and are not samples;
1037
+ recording them dragged the EWMA towards zero (and wrote `latency.json` on every poll).
1038
+ - **The last batch is delivered at the tail.** The final segment's due point is `end - lead`, which for
1039
+ the last batch sits past the end of the film — the position never reaches it, so the user watched
1040
+ the ending and got nothing. Reaching/passing `dur - 1` now counts as due.
1041
+ - **`speech` only lists lines that are still ahead.** It used to echo the whole draft, including the
1042
+ lines the same call had just pruned as past — the model read them as "still going to be spoken".
1043
+ - **Delivery guidance trimmed ~45%** (≈1150 → ≈640 chars). It is resent every batch; the loop/pacing
1044
+ rules already live in the tool description, so only the hard rules stay here: write the lines,
1045
+ no spoilers, one sentence, `say` is the only visible channel.
1046
+
1047
+ ### Reading pass over the loop (2026-11-01) — six real bugs, one hot path
1048
+
1049
+ No new features. Everything below was found by reading the code against its own comments and then
1050
+ reproducing it; each fix carries a regression test that fails on the old code.
1051
+
1052
+ - **`lastDelivered: null` was read as batch 0.** A delivery blocked by the "no lines yet" gate writes
1053
+ `lastDelivered: null`, and `Number(null)` is `0` — exactly the first batch's start. That batch then
1054
+ counted as already delivered forever: `wait: true` woke up and answered "already delivered", image
1055
+ and manifest never handed over. Empty now stays `NaN`.
1056
+ - **Same film, two URL forms → the loop restarted.** `samePlan` compared the raw `input` string, but the
1057
+ extension reports `…/BV1g3xN6hEuw/?trackid=…&spm_id_from=…` while the model usually holds the clean
1058
+ link. Every second call therefore looked like a new source, wiping `spoken` and re-waking segments
1059
+ that had already been delivered. It now compares `sessionKey()`.
1060
+ - **`dur: null` became `0 s` on the bridge path.** `Number.isFinite(Number(s.dur))` passes for `null`,
1061
+ so a report without a duration set the baseline to 0; the next real reading (600 s) then differed by
1062
+ more than a second and was judged "video changed" — the clock stopped mid-film. `num()` in
1063
+ `position-bridge.js` and the baseline update now treat empty as empty.
1064
+ - **`waitForVideo` lost the hangup.** The input surface is prepared once (`prepared ??=`), and the
1065
+ early pre-warm for `waitForVideo` passed no arguments — so `input`/`open` never reached it. Without
1066
+ `input` the recorded hangup could not be matched, the window was re-opened, and the call went off to
1067
+ wait for a video instead of returning `[hangup]`.
1068
+ - **`dueLine` rewrote `watch.json` on every tick.** Its `dirty` flag was shared across segments: once one
1069
+ batch had pinned its un-timed lines, every later batch was written back unchanged — a full state write
1070
+ every 2 s for the rest of the film. The flag is per segment now.
1071
+ - **`waitUntil` / `waitForRefill` lied about why they stopped.** Breaking out because the user paused (or
1072
+ the film ended) still produced "waited to the cap". The text now names the real reason.
1073
+
1074
+ Hot path, same area:
1075
+
1076
+ - `cachedCues()` re-read and re-parsed the whole subtitle file on every tick (`dueLine` asks several
1077
+ times per tick). It is memoised on `path + size + mtime` now, and returns the **same array** so that
1078
+ `makeLagFn`'s memo can be keyed on array identity. `makeLagFn` additionally sorts once and looks up
1079
+ by binary search instead of a linear scan of every cue. 2000 cues × 5400 lookups: **66.7 ms → 0.8 ms**
1080
+ (×83), and the disk read/parse per tick is gone.
1081
+ - `lines-util.js` had its own `cacheDir()` that fell back to `~/AppData/Local` on every platform, so on
1082
+ Linux/macOS the subtitle cache landed in a directory that does not exist; it now uses the storyboard's
1083
+ `cacheDir()`. `findCachedMedia()` likewise uses `tmpdir()` instead of `LOCALAPPDATA/Temp`.
1084
+ - Dead exports removed: `plan.starts` (a 513-element array allocated on every `makePlan`),
1085
+ `legacySessionKey`, `wasWritten`, `MATERIAL_PARTS`. The input surface failing to start no longer fails
1086
+ the whole call — it is reported in the result instead.
1087
+
1088
+ Three rounds on 2026-10-31. The through-line: the plugin knew something, and the model (or the user)
1089
+ never found out — plus one window that needed to look like something people want to keep on screen.
1090
+
1091
+ ### Long-video recap — merged, but opt-in
1092
+
1093
+ PR #2, after one round of review. Its first shape prepended a 420-character `[前情]` to **every**
1094
+ delivery, partly built from the model's own scripted lines: second-hand context in a package whose
1095
+ contract is "raw material only — never retell what the user just watched", at ~200 tokens per
1096
+ segment, with no evidence it helped.
1097
+
1098
+ What shipped instead: off unless `recap: true` or `DSH_WATCH_RECAP=1` (`recap: false` beats the env
1099
+ var); only **cached subtitle sentences**, never the model's lines; `recapSegments` 1–3 (default 2),
1100
+ `recapMaxChars` 80–1200 (default 420); never reads past the current segment, never trims the live
1101
+ transcript, no ASR, no network. Whether it actually reduces retelling is still **unmeasured** — it
1102
+ stays opt-in until somebody measures it.
1103
+
1104
+ ### Observability: `statusOnly` can now answer "why is it slow"
1105
+
1106
+ Promised in issue #4. `pos + reason` says *what* the clock thinks, not *where it is stuck*.
1107
+
1108
+ - `segment { index, from, to, delivered, total }` — which batch, its bounds, how many were delivered
1109
+ this session, how many the film has (`total` is `null` when the duration is unknown). The last batch
1110
+ index is taken at `dur - 1 ms`, because a duration that lands exactly on a boundary would otherwise
1111
+ report one batch too many.
1112
+ - `speech { queued, lastLateSec, busyUntil }` — lines still waiting, how late the previous line was
1113
+ (from `dueLine`'s new `meta: true`, which also keeps the plain-string return for old callers), and
1114
+ when the serial voice engine frees up.
1115
+ - `build { inflight, cached, lastMs }` — which batch is being built, how many are cached, how long the
1116
+ last build took. The cache is passed into the loop for reporting only; it never influences a decision.
1117
+ - `queued` needs a disk read, so it is filled in `statusOnly` only, and a failure there is reported as
1118
+ `speech.queueError` instead of being swallowed (the first version of this swallowed a `ReferenceError`
1119
+ from a missing import and looked exactly like "there are no lines").
1120
+
1121
+ ### The floating window, rebuilt
1122
+
1123
+ "这个悬浮窗太丑了" — fair. The old one was a borderless frame with a `Text` widget that painted
1124
+ role-coloured **full-width stripes**, on a window Windows stretched from 96 dpi, reading the whole
1125
+ `chat.jsonl` every 200 ms.
1126
+
1127
+ - **Real bubbles.** Each message is its own rounded card (Canvas background + wrapped Label), sized
1128
+ to its content: script lines in amber with a left rule, the model in slate, the user's own words
1129
+ right-aligned in blue. Above each one, a muted line saying who and when (`台词 04:12.3` for a
1130
+ scripted line, `我 21:16` for chat).
1131
+ - **Per-monitor DPI awareness** before the window exists, and every size/font derived from the real
1132
+ scale factor. Unaware Tk windows are bitmap-stretched at 125/150%, which reads as "blurry and wrong".
1133
+ - **Rounded window** via `-transparentcolor` (Windows only; falls back to square corners), a 1 px
1134
+ border, and a hand-drawn 6 px scrollbar that only appears when the list actually scrolls.
1135
+ - **Does not steal focus.** `focus_force()` at startup meant pressing space to pause the video landed
1136
+ in the chat box; now the entry only takes focus inside the window.
1137
+ - **Does not fight your scrolling.** New lines auto-scroll only if you were already at the bottom.
1138
+ - **Incremental read.** Only the bytes appended since the last tick are parsed, and the first paint
1139
+ replays just the last 60 entries.
1140
+ - Resizable from the bottom-right grip; position and size persist in `~/.dsh/watch-window.json`.
1141
+
1142
+ ### Stop when the signal says stop: hangup, dead source, switched video
1143
+
1144
+ Reported as "换片或者我都关浏览器了还在念台词" and "关了悬浮窗 AI 还是会自动调出来,根本不会自动结束".
1145
+ Both were the same shape: the plugin knew the source was gone, and kept talking anyway.
1146
+
1147
+ - **Speech now requires a believable position.** The line queue only fired when the position was
1148
+ `fresh`, or `extrapolated` within `SAFETY_AFTER_MS` (20 s — the normal gap between probes).
1149
+ Before, the only thing excluded was `paused`; `estimate()` happily extrapolates a dead source
1150
+ forward and `pos` stays finite, so closing the browser kept reading lines out for minutes.
1151
+ Nothing is spoken on an `unknown` position, and the position-unknown give-up dropped from
1152
+ 10 min to 5 min (the watch should not sit there pretending).
1153
+ - **Closing the floating window is a hangup, treated like an interjection.** The window is the only
1154
+ way to talk mid-watch, so closing it means "I'm done":
1155
+ - the clock stops and **really wakes the model** — `wake:false` (the default) used to silence this
1156
+ too, because it shared the `wake` path with the segment-end reminder. User actions (hangup,
1157
+ video changed, video ended, seek, unreadable position, high-frequency mode) now use a separate
1158
+ always-real channel (`wakeSignal`), and the message says **do not call watch_together again and
1159
+ do not read out any more lines**;
1160
+ - the guard is stored on the loop and can be turned on later (`resumed` path used to freeze it,
1161
+ so a window opened by an earlier call was never guarded);
1162
+ - the next tool call **does nothing at all**: no frame, no clock, no window (`[hangup]` result).
1163
+ `sameWatch` previously required `args.input`, which the model never sends — so every call looked
1164
+ like "a new watch" and re-opened the window the user had just closed.
1165
+ - `wakeWithRetry` called an undefined `note()` in its failure branch (a `ReferenceError` swallowed by
1166
+ the ticker). Real wakes can fail, so it was reachable; now it records into `loop.logs`.
1167
+
1168
+ Tests: 247 pass, +4 in `test/hangup-guard.test.mjs` (dead source sends nothing, live source still
1169
+ speaks, hangup wakes with the right wording, post-hangup call is inert).
1170
+
1171
+ ### Interjections: speak first, then look
1172
+
1173
+ Reported as "它一声不吭先去 zoom,回来才说话". The root cause was not the model: a normal reply
1174
+ never reaches the floating window — only `say` does and only `say` is spoken. So "think, then look,
1175
+ then answer" was, from the user's side, complete silence for tens of seconds.
1176
+
1177
+ - One wording, one place (`src/interject.js`) for all five entry points (during a build, during the
1178
+ lookahead fill, during a blocking wait, `waitUntil`, `nextLine`). It now says exactly what to do:
1179
+ `watch_together({ say: "我看一眼", speakNow: true })` — one call, words written before any frame
1180
+ is built. `lines` and `say` can ride in the same call, so "台词优先" no longer means "stay silent".
1181
+ - Unanswered interjections are **tracked**: the next tool result ends with `[未回应] …你还没回`,
1182
+ until a call actually carries `say` (expires after 3 min). Previously the reminder existed only
1183
+ inside the message that woke the model, which it had already scrolled past.
1184
+ - `waitUntil` / `nextLine` called a function that **did not exist** (`chatResult`) — an interjection
1185
+ during either wait threw `ReferenceError` and the tool failed. Defined, and it reuses the same wording.
1186
+ - Waiting for a video to appear returned a result **without `text`**, which the host's `output.schema`
1187
+ requires. That path now returns a proper result.
1188
+
1189
+ ### Reply vs. scripted line: 12-second guard
1190
+
1191
+ Reported as "说话和插话的回复离太近,把后面那句改一下". Two lines spoken back to back on a serial
1192
+ TTS chain means the second one either drifts or is dropped by the adapter (queue > 3.5 s → `skipped`).
1193
+
1194
+ - `say` now marks the voice engine busy for its full spoken length (`src/reply-guard.js`), so the
1195
+ loop stops feeding scripted lines while a reply is still playing. Previously only the loop's own
1196
+ lines updated that clock — a reply was invisible to it.
1197
+ - Lines scheduled within 12 s of a reply are **withdrawn from the batch and handed back** to the
1198
+ model (`[lines·太近]`) with instructions to rewrite them around what was just said, or drop them.
1199
+ Withdrawn, not silently deleted: the user asked for "改一下", not "少一句".
1200
+
1201
+ ### Switching videos is noticed in ~2 s, not ~15 s
1202
+
1203
+ - The per-tick bridge read (every 2 s) now does the switch / end-of-video / big-jump checks, and
1204
+ keeps the `dur`/`url` baseline up to date. Before, all three lived in the 15-second CDP probe
1205
+ branch only, so a switch could go unnoticed for a quarter of a minute — while the clock kept
1206
+ computing segment boundaries against the old film.
1207
+ - The blocking wait in `watch-run` now compares each read against the film it started with and
1208
+ returns `[video-changed]` immediately. **This was the only reliable path**: the loop's wake goes
1209
+ through `followup()`, which is delivered *after* the current tool call returns — and that call was
1210
+ busy waiting.
1211
+ - `sourceSwitched()` centralises the test, and `Number(null) === 0` is explicitly guarded: a
1212
+ not-yet-known duration used to look like a "0-second film" and stop the watch instantly.
1213
+
1214
+ ### Cold start: don't wait a full minute for a video we can already identify
1215
+
1216
+ - The extension only reports while the tab is **visible** — and "一起看" is usually typed in another
1217
+ window. The position went stale after 5 s, the plugin concluded "no video", and sat in the 60 s
1218
+ wait. It now falls back to a **stale** sample (up to 2 min) to identify the film, marks the
1219
+ position `stale`, and lets the next fresh reading correct it.
1220
+ - Automatic waiting (no `waitForVideo`) dropped from 60 s to **20 s**; explicit `waitForVideo: true`
1221
+ stays at 120 s.
1222
+ - `probeBrowser()` is skipped when the extension already reports: one probe is `listTargets`
1223
+ (1.2 s) plus up to 8×1.5 s of CDP round-trips — pure overhead for a `browser:` line the extension
1224
+ just answered. The line now reads `browser: extension reporting <title> playing 03:20`.
1225
+
1226
+ Tests: 243 pass (`node --test`), 6 of them new in `test/interject-reply.test.mjs`.
1227
+
1228
+ ## [0.1.0] - 2026-11-01
1229
+ 首个发布版本。要求 `dsh-video-storyboard@^0.5.11`(字幕轨用到它的 `./transcript-pass` 子路径)。
1230
+
1231
+ ## [0.0.7] — 2026-10-31 (first release)
1232
+ The first published version. One tool, `watch_together`: it follows the user's real playback
1233
+ position, hands the model one storyboard + transcript per segment just before that segment ends,
1234
+ and speaks the scripted lines at the second they belong to.
1235
+
1236
+ **Licence: Apache-2.0** (the package was developed under MIT and switched before the first
1237
+ public release, to match `dsh-video-storyboard`). `LICENSE` is the full text, `NOTICE` states
1238
+ what the project deliberately does **not** do — no hosted video, no uploaded position, no DRM or
1239
+ paywall bypass, no bundled TTS engine.
1240
+
1241
+ ### Repo hygiene — the extension's manifest and icons were never committed
1242
+
1243
+ `.gitignore` carried `manifest*.json` and `*.png` (meant for CLI artifacts). Those two rules also
1244
+ swallowed `extension/manifest.json` and `extension/icons/*.png`, so a clone would have shipped an
1245
+ extension **with no manifest** — completely broken, and nothing would have failed until someone tried
1246
+ to load it. Both are now force-added, and the ignore rules are anchored (`/*.png`, `/*.meta.json`) so
1247
+ they can only ever catch files at the repo root. Also: `* cookies*.txt` (a pattern with a space, which
1248
+ never matched anything) is gone, `__pycache__` is out of the npm tarball via a new `.npmignore`, and
1249
+ `npm test` no longer requires the sibling `dsh-video-storyboard` checkout — it falls back to the
1250
+ installed copy, so a clone can run the suite.
1251
+
1252
+ ### Docs — one page per service, and the stale one is gone
1253
+
1254
+ `docs/WATCH.zh.md` still explained how to configure things around the **OS media session (SMTC)**,
1255
+ which was deleted a while ago: wrong rationale, wrong `confidence` values, wrong defaults. Deleted.
1256
+ Replaced by [`docs/CONFIG.zh.md`](docs/CONFIG.zh.md): ffmpeg → yt-dlp + cookies → subtitles/ASR →
1257
+ browser extension (9377) → debug port (9333) → voice (`voice.json` + `tts.json`) → floating window →
1258
+ cache locations → a one-page troubleshooting table. Every entry says **what breaks if you skip it**.
1259
+
1260
+ `README.md` got a 30-second start, a "what to configure" table, a corrected parameter table
1261
+ (`depth` is auto-by-time now, `lookahead` was missing), a CLI table that matches the 15 real
1262
+ subcommands, a privacy note for the extension, and a dev section. `docs/VOICE.zh.md` gained
1263
+ `state: 'skipped'` and a correction: `at` is a **playback second**, not a wall-clock timestamp.
1264
+
1265
+ ### `doctor` — three levels, because "not configured" is not "broken"
1266
+
1267
+ `FAIL` used to be printed for things that are merely "not set up yet": a missing cookie file (only
1268
+ needed for Bilibili), a closed debug port (the extension is the recommended channel), an extension
1269
+ that is loaded but has no video playing. First-run users read that as "something is broken" and went
1270
+ to reinstall the extension. Now: **OK / WAIT / FAIL**, only `plugin` and `ffmpeg` are fatal, and when
1271
+ the extension has checked in but nothing is playing, `doctor` says `READY — 播个视频就能读到位置`
1272
+ instead of "both position channels are down".
1273
+
1274
+ ### Performance — the chat watcher no longer re-reads the whole log every 150 ms
1275
+
1276
+ The blocking-wait loop polls `chat.jsonl` every 150 ms. Each poll re-read `readChat()` and parsed
1277
+ every line, so a two-hour session (thousands of entries) was decoding hundreds of KB several times a
1278
+ second, and getting slower the longer the session ran. `makeChatWatcher()` now keeps a byte offset
1279
+ and reads **only what was appended since last time** (falling back to a full re-read if the file
1280
+ shrank, i.e. it was cleared). Measured on a 5000-line log: **0.061 ms per poll, independent of file
1281
+ size**. `appendChat()` also stopped parsing the whole log to keep `at` monotonic — it reads the last
1282
+ 4 KB instead.
1283
+
1284
+ ### Tool description — pacing is now a rule the model can follow
1285
+
1286
+ `watch_together`'s description tells the model to keep lines **≥ 6 s apart** and why: speech is
1287
+ serialized, so a denser draft is thinned at runtime (engine busy → next line held; past the late
1288
+ grace → dropped). The three previous rounds of "台词太早 / 太密" all came from the model not knowing
1289
+ this budget.
1290
+
1291
+ ### Fixed — speech piled up in the engine queue, and an interjection could no longer break a blocked wait
1292
+
1293
+ Two reports in one message: "吐字太快,台词会挤到一起,只有上一句念完才到下一句,话太密会导致语音越来越
1294
+ 滞后" and "悬浮窗插话不能让他从等待中出来 —— 这个功能之前是好的".
1295
+
1296
+ **The voice queue.** `examples/voice-edge-tts` chains every `due` event onto an unbounded serial promise
1297
+ ("two lines never overlap"). Lines are now scheduled at the right second, so when they arrive faster
1298
+ than the engine can speak them the chain simply grows: speech drifts further from the picture with
1299
+ every line, and the caption (written on `spoken`) drifts with it.
1300
+
1301
+ - `src/watch-loop.js` — the clock now keeps a **voice budget**: after handing out a line it records
1302
+ `voiceBusyUntil = now + speechSeconds(len)` and will not hand out the next one while the engine is
1303
+ still talking. A line that misses its window by more than the late grace is dropped by `dueLine`
1304
+ as usual: **speak one line less rather than one line later**.
1305
+ - `src/speech.js` — `speechSeconds(chars)`: full spoken duration (`0.35 + chars/5`, 0.8–30 s).
1306
+ `speechLag()` stays as it was — that one answers "when may I start talking", this one answers
1307
+ "how long is the engine busy".
1308
+ - `examples/voice-edge-tts` — safety net: if a queued line has been waiting more than 3.5 s it is
1309
+ **abandoned** (logged) instead of spoken, and the queue empties immediately.
1310
+ - `src/speech-bus.js` / `src/chat-store.js` — a fourth state, `skipped`: the adapter reports that it
1311
+ gave up on a line, and `attachSpeechToChat` cancels the pending fallback timer for it. Without this
1312
+ the 2.5 s fallback would paint a caption for a line that was never spoken.
1313
+
1314
+ **The interjection.** `chat.jsonl` is a **consuming** channel: `poll()` marks a message read. The
1315
+ blocking wait and the watch loop share one watcher, and the loop's handler is `followup()` — which
1316
+ cannot interrupt a session that is sitting inside a tool call (the message is only processed when
1317
+ the turn ends). So whichever polled first decided the outcome, and the loop (every 2 s) sometimes
1318
+ won: the interjection was swallowed, the wait's `poll()` never saw it, and the user's "stop, I have a
1319
+ question" did nothing until the segment ended.
1320
+
1321
+ - `src/interrupt.js` — `enterChatWait()` / `chatWaiterCount()`: whoever is blocking on purpose
1322
+ **owns** the channel. `raceChat()` (storyboard build, prefetch) registers too.
1323
+ - `src/watch-loop.js` — `wakeOnChat` is skipped entirely while `chatWaiterCount() > 0`. The wake path
1324
+ still works when the model is idle (no waiter), which is its whole purpose.
1325
+ - `src/watch-run.js` (the `wait: true` loop), `src/watch-modes.js` (`waitUntil` / `waitForRefill` /
1326
+ `nextLine`), `src/watch-source.js` (`waitForVideo`) — all register as waiters for the duration of
1327
+ their loop.
1328
+
1329
+ Tests: `test/lines-timing.test.mjs` (engine busy → next line is not handed out; the overdue one is
1330
+ dropped), `test/chat.test.mjs` (`skipped` writes nothing, not even the fallback),
1331
+ `test/interject-anywhere.test.mjs` (the loop must not consume while a waiter is active; counter
1332
+ cannot go negative).
1333
+
1334
+ ### Fixed — scripted lines came out like a machine gun, and minutes before the picture
1335
+
1336
+ Reported as: "台词出现时间早了很多,而且和机关枪一样突突突一下出来一大堆,时间点都比视频早了".
1337
+
1338
+ The line queue is ordered by `at` (the second of the video this line is *for*) and fired by playback
1339
+ position, so the pacing is only as good as the `at` values. When a line was written **without** `at`
1340
+ (the model wrote prose only), `pinTimes()` decided when it would be said — and it took *the first N
1341
+ subtitle sentence starts of the segment*. Sixteen lines written for a 3-minute segment were therefore
1342
+ all packed into its first 62 seconds (181.6 → 244.2, measured on the live queue), i.e. one every
1343
+ 2–3 seconds: the clock ticks every 2 s and hands out at most one line per tick, which is exactly the
1344
+ "machine gun". The last 14 of them ran one to two minutes ahead of the picture they describe.
1345
+
1346
+ - `src/watch-lines.js` `pinTimes()` — each line now aims at its **even share of the segment**
1347
+ (`from + i*size/n`) and snaps to the nearest subtitle start within half a slot, so the queue is
1348
+ spread over the whole segment instead of stacked at its head. Falls back to the even share when no
1349
+ start is close enough, and **never goes backwards** (the old tail fallback could emit 152.8 → 150).
1350
+ - `src/watch-lines.js` `dueLine()` — pinning uses **the segment that line belongs to** (`sizeOf`),
1351
+ not the segment the user happens to be in. With the 1/2/3/4/5-minute ramp, a 60-second slot pinned
1352
+ with a 300-second size put its last lines outside the segment entirely.
1353
+ - `src/watch-lines.js` `saveLines()` — `at` given as **subtitle text** was resolved only against
1354
+ `recallSegments()`, which is a 4-entry in-process cache (empty in a fresh process, and lines are
1355
+ usually written in a different turn). A miss silently became "no `at`", i.e. the head of the
1356
+ segment — the other half of "the line is way too early". Now it reads the on-disk
1357
+ `subs-<key>.json` cache first, then falls back to memory, then to a fuzzy match (≥60 % of the
1358
+ characters), and only then warns.
1359
+ - `src/watch-run.js` — the delivery note pruned "past" lines with `Number(l.at)`, and
1360
+ `Number(null) === 0`: **every line without `at` was judged as second 0 and deleted** at delivery.
1361
+ The note now previews the same pinning the clock will use, so the reported "earliest …" time is the
1362
+ real one, and only lines whose *actual* time has passed are dropped (by text).
1363
+ - `src/watch-run.js` — the note now lists the landing times it will use (`[lines] 落点:…`) and warns
1364
+ when the average gap is under 6 s, instead of leaving the model to guess its own pacing.
1365
+ - `src/watch-loop.js` — with the extension as the position source, the anchor is now re-read **every
1366
+ tick** (a small local JSON, not CDP). Between the 15-second probes the clock extrapolated blindly,
1367
+ so after a pause the lines up to 15 s ahead were spoken **early** — extrapolation is bounded for
1368
+ lateness but nothing guarded earliness.
1369
+ - `src/latency.js` `aheadSeconds()` — returns 0 instead of `NaN` when `ms` is missing. `NaN` made
1370
+ `pos` `NaN`, every comparison false, and `shouldSpeak()` reported "due" for the first unspoken
1371
+ segment at every tick.
1372
+
1373
+ Tests: `test/pin-times.test.mjs` (the 16-line packing regression, monotonic fallback, cues bunched at
1374
+ the head), `test/watch-lines.test.mjs` (per-segment size, `at` from the on-disk subtitle cache),
1375
+ `test/lines-timing.test.mjs` (a stuck video must not speak the next line early).
1376
+
1377
+ ### Fixed — the caption appeared before the voice, because it waited on `due` instead of "actually speaking"
1378
+
1379
+ `attachSpeechToChat` wrote a line into `chat.jsonl` the moment `due` fired. But `due` only means
1380
+ "it is time to say this": synthesis still has to happen (edge-tts does a network round trip, then a
1381
+ fresh `ffplay` process — 0.6–2 s even for a short sentence). The floating window polls that file, so
1382
+ the text was already on screen a beat before anything was heard.
1383
+
1384
+ Delaying the voice instead (`speechLag`) would align the two, but push the voice further from the
1385
+ picture, which is the one thing this plugin cannot trade away. So the **caption** moves:
1386
+
1387
+ - `src/speech-bus.js` — a third state, `spoken`, plus `emitSpoken(event)` for engines to report
1388
+ "audio is starting now". The adapter API gains `emitSpoken`.
1389
+ - `src/chat-store.js` — writes on `spoken` when a `voice: true` subscriber exists; still writes on
1390
+ `due` when nobody will speak (the zero-dependency path must not go mute); falls back after
1391
+ `fallbackMs` (2.5 s, `DSH_WATCH_CAPTION_FALLBACK_MS`) for adapters that never report.
1392
+ Pairing is by `at|text`, not by `seq` — `spoken` is a **new** event, so `emitSpeech` gives it a
1393
+ new sequence number.
1394
+ - `examples/voice-edge-tts` — reports `spoken` right before playback starts (i.e. after synthesis).
1395
+ - `examples/floating-chat/window.py` — polls every 200 ms instead of 400 ms; the poll interval is
1396
+ the residual "text lags the voice" gap.
1397
+
1398
+ `test/chat.test.mjs` covers both new paths (waits for `spoken`; falls back when nobody reports, and
1399
+ does not write twice if `spoken` arrives afterwards).
1400
+
1401
+ ### Fixed — scripted lines never reached the chat window without a voice engine
1402
+
1403
+ `watch-loop.js` consumed the due line inside `if (speechSubscribers() > 0)`. That helper counts only
1404
+ `voice: true` subscribers (real engines), while `attachSpeechToChat` — the one that writes lines into
1405
+ `chat.jsonl`, which is exactly what the floating window reads — subscribes with `voice: false`.
1406
+ So with no voice adapter, or one that failed to load, a scripted line was **never taken from the
1407
+ queue at all**: not spoken, not displayed, and the queue silently accumulated.
1408
+
1409
+ Display and speaking are two separate things. The line is now handed out at its due moment
1410
+ regardless: `emitSpeech` delivers it to every subscriber, and only a real `voice: true` subscriber
1411
+ counts as "said" (`if (speechSubscribers() > 0) return;` still stops the wake, so nothing changes
1412
+ when a voice engine *is* attached).
1413
+
1414
+ `test/lines-to-chat.test.mjs` covers both sides. The test was checked against the bug: restoring the
1415
+ old condition makes the no-voice case fail while the with-voice case still passes.
1416
+
1417
+ ### Changed — `say` no longer reads as "only to answer an interjection"
1418
+
1419
+ It always worked at any moment: it writes the sentence into the shared stream and hands it to
1420
+ whoever listens for speech, exactly like a scripted line. But the description ended with
1421
+ "use it to answer an interjection", which reads as "only after the user speaks". A model follows
1422
+ that literally, so the one path for saying something **unprompted** went unused.
1423
+
1424
+ The description now says any time, and says it explicitly: something in the picture strikes you,
1425
+ the user asks something, a thought lands while waiting for the next batch — plus
1426
+ "do not wait for the user to speak first". It also states the cost, because that is what makes it
1427
+ usable mid-wait: no position read, no frame built, no batch advanced, one round trip.
1428
+
1429
+ `test/say.test.mjs` pins the wiring — parameter → stream (one `assistant` row with `say: true`) →
1430
+ speech event with `origin: 'chat'`, no image, no state advanced. The store layer was already covered
1431
+ by `test/chat.test.mjs`; the uncovered part was the parameter entry itself.
1432
+
1433
+ ### Added — an end-to-end test for "talk while the frame is building"
1434
+
1435
+ The mechanism already existed (`raceChat(buildSegment(...))` in `runWatchPass`), and
1436
+ `test/interrupt.test.mjs` covered `raceChat` itself — but the `built.kind === 'interrupted'`
1437
+ branch had **no** coverage. If a refactor ever dropped the wrapper, or `chatWatcherShared()` got
1438
+ replaced with a fresh watcher per call, every existing test would still pass.
1439
+
1440
+ `test/interject-build.test.mjs` builds a segment that takes 1.2 s, writes a user message at 0.2 s,
1441
+ and asserts all four things at once: the call returns before the build finishes, it carries that
1442
+ exact message, it carries no image, and the build still completes into the cache afterwards.
1443
+
1444
+ ### Changed — three implicit couplings now have exactly one source each
1445
+
1446
+ A pass over the module boundaries. Same behaviour except the `lead` fix at the end, which was a
1447
+ real bug: the parameter only worked on one of the three paths that used it.
1448
+
1449
+ - **`handler.js` stopped preparing UI.** The floating window, the chat service and the "where do I
1450
+ type" note moved to `input-surface.js` (`createInputSurface()`). `handler` is a router again —
1451
+ three exits: quick action, one pass, start the loop. The `widgetNote` variable no longer travels
1452
+ from the top of the function to the bottom.
1453
+ - **`watch-run.js` has one return shape.** Eleven exits each used to build their own ten-field
1454
+ object; now they all call one `pass()` closure. Adding a field is one edit instead of eleven, and
1455
+ a branch can no longer quietly forget one.
1456
+ - **One segment length.** `watch-state.js` exported `WATCH_SEGMENT = 120` while `batches.js`
1457
+ declared `DEFAULT_SEGMENT = 300`; whichever fallback fired first decided how long a segment was.
1458
+ `batches.js` is now the only source, and `WATCH_SEGMENT` is gone.
1459
+ - **One lead.** The delivery lead was hardcoded in three places: `batches.from()` produced
1460
+ `sayAt = to - 15`, `watch-loop.js` passed `lead: 15` to `shouldSpeak`, and only `watch-run.js`
1461
+ actually read `args.lead`. Segments no longer carry `sayAt`; `shouldSpeak` computes `to - lead`,
1462
+ and `startWatchLoop` takes `lead` from the caller. `lead: 60` now really moves the trigger point
1463
+ (checked against a 300 s segment: at 241 s, `lead=15` stays quiet, `lead=60` fires).
1464
+
1465
+ ### Removed — no more auto-launched browsers, no more browser widget
1466
+
1467
+ Both were early paths from before the browser extension existed. Neither could produce a position
1468
+ for the tab the user is actually watching, so both are gone rather than kept as fallbacks.
1469
+
1470
+ - **Auto-launching a browser**: `ensureWatchBrowser()` (`launchBrowser` + `waitForPort`), the
1471
+ `autoLaunch` flag on `runWatchPass`, the `attachOnly` parameter, and the `launchBrowser: true`
1472
+ branch in `~/.dsh/video.json`. The extension already reports `currentTime` every second from the
1473
+ page the user is on; opening a second Edge with its own profile never helped that page. When no
1474
+ position can be read the tool now asks "how far are you" instead of starting a program.
1475
+ - **The browser widget page**: `GET /widget`, `WIDGET_PAGE`, `openWidgetInBrowser()`, `widgetUrl()`,
1476
+ and the `documentPictureInPicture` button in the chat page. The input box is the native tkinter
1477
+ window (`examples/floating-chat/window.py`); the HTML page stays as a read-only fallback at `/`
1478
+ (`chatPageUrl()`), and is never opened automatically.
1479
+ - **Dead parameters**: `wakeOnLinesEmpty` (the handler never passed it, so its 30-line branch in
1480
+ `watch-loop.js` could never run), `title` (nothing in `src/` or in storyboard read it), and
1481
+ `segmentStart()` (every caller uses `plan.segmentAt()`). Parameter count 36 → 34.
1482
+
1483
+ ### Fixed — interjections used to get swallowed (four different ways)
1484
+
1485
+ The interjection path was the one place where losing user input was silent: nothing crashed, nothing
1486
+ logged, the words just never arrived. All four ways of losing them are now closed, and each one has
1487
+ a regression test (`test/cli-interrupt.test.mjs` — the CLI had **no** test coverage before this).
1488
+
1489
+ - **Between two `cue` runs.** Every `cue` is a fresh process, and the watcher took "however many
1490
+ lines exist right now" as its baseline — so anything the user typed while the model was thinking,
1491
+ building a segment or replying was never read by anyone. The read position now lives in
1492
+ `<watch>/chat-cursor.json`: a `cue` starts from where the last one stopped, and delivers what it
1493
+ finds the moment it enters the wait. Baseline is persisted as soon as it is established, because a
1494
+ `cue` that hears nothing (the common case) otherwise leaves no cursor for the next one.
1495
+ - **Two messages arriving in the same poll.** Both watchers (chat box and host session file) marked
1496
+ the whole batch as read and reported only the first, so the second was gone. They now consume up
1497
+ to the message they hand over and no further — "reply first, then take the next one".
1498
+ - **Wrong conversation.** `findActiveSessionFile()` took the most recently modified session jsonl
1499
+ across *all* projects, so a chat in another window could interrupt the watch session. It now
1500
+ prefers the project matching the current directory and only falls back to global when that one has
1501
+ no active session.
1502
+ - **The host writing old messages late.** WorkBuddy flushes a user's message into the session file
1503
+ *after* the reply to it. The watcher saw new bytes and treated them as a fresh interjection —
1504
+ interrupting the current turn with the message that started it. Messages whose `timestamp`
1505
+ predates the watcher are now ignored.
1506
+
1507
+ Also in this path: interjections heard via the host input box are appended to the chat stream too
1508
+ (they used to appear only in `cue`'s stdout, so the page showed a stream with a hole in it); the
1509
+ chat page puts the words back in the input box when a send fails instead of losing them; and
1510
+ `POST /api/say` answers `ok:false` for requests it did not write, which is what makes that recovery
1511
+ possible.
1512
+
1513
+ ### Fixed — `cue` and `say`
1514
+
1515
+ - `cue` no longer waits forever when the video changes underneath it. It compared against the
1516
+ segment delivery point of the *old* video, and if the new one was shorter, `deliverAt` was a
1517
+ position that would never be reached. It now detects a changed URL or duration and exits with
1518
+ `VIDEO-CHANGED` (pending lines are saved under the old source), and exits with `REWIND` when the
1519
+ user drags the progress bar back more than a minute — the model should hear about that instead of
1520
+ sitting on lines written for a position the user left.
1521
+ - Two `cue` processes can no longer run at once: a state file saying `blocking` with a **live** pid
1522
+ is refused with `BUSY` (exit 1). A dead pid is taken for what it is — the residue of a killed run —
1523
+ and does not block anything. `check` mode is read-only and never takes the lock.
1524
+ - `check` mode no longer leaves `cue-state.json` at `blocking`, which used to make the next run
1525
+ report "last wait was killed externally" for a run that was never waiting.
1526
+ - `say` called edge-tts once by hand and then again inside `speak()` (twice the synthesis, and the
1527
+ manual attempt passed the raw configured voice, so a SAPI-style name like `Huihui` never matched
1528
+ and silently fell back). It now calls `speak()` once, which does the mapping and the fallback.
1529
+ - `voices` was advertised in `help` and crashed with `cmdVoices is not defined` when called. It now
1530
+ lists the SAPI voices plus whether edge-tts is present and which voice is configured — the first
1531
+ place to look when "why am I still hearing the navigation lady" comes up.
1532
+
1533
+ ### Added — talk instead of type: a microphone button in the floating window
1534
+
1535
+ `examples/floating-chat/mic.py` is a separate process the window starts from its `麦` button. It
1536
+ listens, cuts what you say into utterances with the Silero VAD already sitting in `models-sherpa/`,
1537
+ transcribes each one, and writes it into the **same** `chat.jsonl` the typing path uses — so a
1538
+ running `cue` picks it up through the interjection cursor and the model answers without anyone
1539
+ typing a character. Measured end to end on this machine (i9-12900HX, int8 paraformer):
1540
+
1541
+ - one model instance ≈ **284 MB** working set, loads in ~2 s
1542
+ - a 3 s utterance transcribes in **0.15 s**; a 45 s one in ~1.2–3.3 s (RTF ≈ 0.05, 20× realtime)
1543
+ - concurrent transcription barely queues: a 3 s short request takes 0.14 s even while a 45 s
1544
+ transcription is running
1545
+
1546
+ **It runs its own model by default** (`--engine local`), which is the answer to "can ASR run twice":
1547
+ yes, and it is cheap. It also means the microphone never waits behind a video transcription. The
1548
+ existing service cannot offer that yet — see the note below. `--engine http` shares port 8000
1549
+ instead, saving 284 MB at the cost of queuing behind long audio.
1550
+
1551
+ **It refuses to hear itself.** The agent speaks through speakers; the microphone hears it; without a
1552
+ guard that gets transcribed as if the user had said it, and the model answers its own line forever.
1553
+ Every utterance is checked against `quiet-until.json` (the same window `say` and `cue` already take
1554
+ before speaking) and dropped if the agent is talking.
1555
+
1556
+ ### Added — acoustic echo cancellation, so the microphone hears you and not the computer
1557
+
1558
+ `examples/floating-chat/aec.py`: the microphone picks up whatever the speakers are playing, which
1559
+ means the video's narration gets transcribed as if you had said it. Since neither `speexdsp` nor
1560
+ `webrtc-audio-processing` builds on this machine (no C compiler, no wheels), this is a frequency-domain
1561
+ adaptive filter (overlap-save FDAF, power-normalised NLMS) in numpy — one FFT per 32 ms frame.
1562
+
1563
+ It captures the **loopback** channel (what the computer is playing, auto-detected as the
1564
+ speaker/loopback device, never "stereo mix" — that one can contain the microphone too) and subtracts
1565
+ the estimated echo from the microphone. On top of that, an utterance whose energy drops below
1566
+ `--echo-gate` (default 30 %) after cancellation is discarded outright: that is the hard guarantee
1567
+ that pure-echo segments are never transcribed, whatever the filter is doing.
1568
+
1569
+ Two things that mattered more than the filter itself:
1570
+
1571
+ - **Double-talk detection cannot compare against the echo estimate.** At startup the filter is zero,
1572
+ so the estimate is zero, so "mic > 2 × estimate" is always true, so the filter freezes and never
1573
+ converges (first version: 498 frames frozen, 0 dB). It now compares against the **reference**
1574
+ signal (Geigel-style), which does not depend on the filter's state.
1575
+ - **Measured on a synthetic but honest mixture** (real speech as the video, a different real speech
1576
+ segment as you, through a 150 ms-delayed reverberant echo path):
1577
+ ERLE **13.6 dB** during echo-only passage; the video's words in the transcript went from **25 % →
1578
+ 0 %**, and an 8 s passage with nothing but video audio produced **no transcription at all**.
1579
+
1580
+ Tunables: `--dt-ratio` (1.4 — mic peak vs reference peak before the filter freezes), `--taps`
1581
+ (8192 ≈ 512 ms of reverb tail), `--echo-gate`, `--no-aec`, `--loopback`.
1582
+
1583
+ Honest limits: it is a software AEC, not magic. The first second or two of your speech, right as the
1584
+ filter re-converges after you start talking, is where the damage shows (a few characters in the test
1585
+ above). Speaker loudness and room reverb both make it harder. **Headphones remove the problem
1586
+ entirely** — with headphones there is no echo to cancel, and everything above is unnecessary.
1587
+
1588
+ ### Added — a browser extension, so you never open a special window again
1589
+
1590
+ Position used to require a browser started with `--remote-debugging-port`, and Chromium 136+ refuses
1591
+ that flag on the default profile — so users had to keep a second, separate browser window open just
1592
+ for watching. That was the whole reason this package felt like it needed a "special browser".
1593
+
1594
+ `extension/` is an MV3 extension that reads `<video>.currentTime` from the page you are actually
1595
+ watching and POSTs it to the plugin's own localhost server (`127.0.0.1:9377/api/position`). After a
1596
+ one-time install it works in **your normal browser**, with your bookmarks and your logins.
1597
+
1598
+ - `src/position-bridge.js` — the receiving end: writes each report to
1599
+ `<cache>/position.json` (temp file + atomic rename) and treats anything older than 5 s as absent.
1600
+ It goes through a file rather than memory because the CLI is a **different process** and has to
1601
+ be able to read it too.
1602
+ - `POST /api/position` and `GET /api/position` on the existing chat server, with CORS and a
1603
+ Private-Network-Access opt-in (a page on https://bilibili.com talking to 127.0.0.1 needs both).
1604
+ - `readPositionOrNull()` now tries the extension report when CDP is not configured or returns
1605
+ nothing, so every existing call site gets the new channel for free.
1606
+ - `doctor` grew an `extension` row and now treats "either channel works" as ready instead of
1607
+ insisting on the debug port.
1608
+ - `docs/BRIDGE.zh.md` — step-by-step install guide written for someone who has never heard of a
1609
+ manifest file, including the eight failure modes people actually hit.
1610
+ - `node watch.mjs install-extension` (and `scripts/install-extension.cmd`) does everything that
1611
+ *can* be automated: copies the extension to `%LOCALAPPDATA%\\dsh-watch-together\\extension` so it
1612
+ survives moving the repo, puts that path on the clipboard, and opens `edge://extensions`.
1613
+ The last three clicks cannot be automated — Chrome 137 removed `--load-extension` from branded
1614
+ builds and extension installs are HMAC-protected, deliberately, because silent install is the
1615
+ malware channel. The guide says so plainly instead of pretending otherwise.
1616
+ - **The extension now says hello on load** (`POST /api/hello`, persisted as `extension.json`).
1617
+ Without it, "extension not installed" and "installed but no video playing" look identical from the
1618
+ outside — both are silence. `doctor` and `bridge` can now tell them apart.
1619
+ - `extension/welcome.html` opens on install/update: the three verification steps, plus what each
1620
+ popup state means. Install is the one moment the user has no idea what to expect.
1621
+ - `install-extension` no longer just prints and quits: it keeps the window open and **watches until
1622
+ the extension proves it is loaded** (`✓ 扩展装上了`), then until a real position arrives
1623
+ (`✅ 全部完成`). One double-click now covers install *and* verification, and the window cannot
1624
+ vanish mid-instruction because it is still polling.
1625
+ - `node watch.mjs install-extension --steps` re-prints just the three clicks without touching any
1626
+ file — for when the window scrolled past or was closed.
1627
+ - `install-extension` now waits for Enter when it has a TTY, so the instructions cannot vanish
1628
+ before being read (running it from an IDE "Run" button has no TTY, which is the common way this
1629
+ happened).
1630
+ - `ensureWatchBrowser(port, url)` now passes the film through: with `launchBrowser: true`, saying
1631
+ "陪我看这个 <link>" opens the dedicated window **at that link** instead of the Bilibili homepage.
1632
+ That is the zero-install path — no extension, no port config, at the cost of watching in that
1633
+ window. Both paths coexist; neither requires the other.
1634
+ - `node watch.mjs bridge` (and `scripts/bridge.cmd`) starts just the position receiver and says
1635
+ "✓ 收到上报" on the first report. Without it, a user who installs the extension and immediately
1636
+ looks at the popup sees "not connected" — because the server only runs during `watch_together`
1637
+ or `watch.mjs chat`, and concludes the install failed.
1638
+
1639
+ ### Added — closing the remaining "no one is listening" dead ends
1640
+
1641
+ - **Idle stop now wakes the model too.** Video-ended and video-changed already did; idle ("no movement
1642
+ for two segments") did not — and since the loop is stopped, nothing polls the chat box afterwards,
1643
+ so anything the user said next went nowhere. Now it wakes and says where it stopped.
1644
+ - **Waiting is polled, not slept through.** The 500 ms tick in the blocking wait now uses
1645
+ `sleepWithChat`, so a message is noticed within ~150 ms instead of up to 500 ms later.
1646
+ - **The tool description now tells the model what an interruption is:** a result carrying `chat` means
1647
+ "answer them first, then call again with the same arguments — the wait resumes, nothing is lost, and
1648
+ the image is already in the cache". Without this the model had no way to know.
1649
+ - **`doctor` distinguishes "nobody is receiving" from "extension not connected".** Both look like
1650
+ silence, and the old wording told the user to reinstall the extension — but if no server is running
1651
+ on 9377 the extension cannot report at all, and reinstalling would have changed nothing.
1652
+ - Stale SMTC-era wording removed from the strings the *model* reads (`input`/`cursor`/`title`
1653
+ descriptions, and the `browser:` line), which still talked about the OS media session.
1654
+
1655
+ ### Added — you can interrupt almost any wait, and it picks up where it left off
1656
+
1657
+ Every blocking wait in `watch_together` can now be interrupted by a message in the chat box, and in
1658
+ all cases the answer is "reply to them, then call again with the same arguments" — the tool resumes:
1659
+
1660
+ - **Building a segment** (8–10 s, longer with ASR) and **filling the lookahead buffer** (up to 4
1661
+ segments serially, 30 s+) — the most pointless kind of waiting, now interruptible.
1662
+ - **Waiting for the video to appear** (`waitForVideo`, up to 2 min).
1663
+ - **Waiting for a condition** (`waitUntil`) and **waiting for the next line** (`nextLine`).
1664
+ - Waiting to the delivery point and `cue` already listened; they now share one watcher (below).
1665
+
1666
+ The interrupted work is **not cancelled**: the storyboard keeps building in the background and lands
1667
+ in the cache, so the follow-up call returns it immediately instead of rebuilding it.
1668
+
1669
+ New `src/interrupt.js`:
1670
+ - `raceChat(promise)` — polls the chat while a slow promise runs; returns `interrupted` with the
1671
+ message, or `done`. Wakes on whichever happens first (the promise settling, or the next poll tick).
1672
+ The first version slept a fixed 500 ms per tick, which added half a second to *every* build —
1673
+ enough that playback passed the delivery point and the blocking wait returned instantly.
1674
+ - `sleepWithChat(ms)` — sleep that can be cut short by a message.
1675
+ - `chatWatcherShared()` — **one watcher for the whole process.** `makeChatWatcher()` baselines at
1676
+ creation time, so a fresh one per wait silently dropped anything the user said while the model was
1677
+ thinking, in the gap between two waits.
1678
+
1679
+ ### Added — it now reacts to what you do mid-video
1680
+
1681
+ Auditing the whole flow against the user's checklist surfaced three gaps where the plugin behaved
1682
+ correctly but **never told the model**, leaving it silent until the user poked it:
1683
+
1684
+ - **Video ended / video changed now wake the model once.** Previously they only stopped the loop, so
1685
+ the model sat blocked on the previous segment with no idea the film was over or had been replaced.
1686
+ - **Large seeks (>60 s, forward or backward) wake the model once** with where the user jumped to and
1687
+ from, with a 3-minute cooldown. Position tracking was already correct — it was the model that had
1688
+ no idea. Rewatching does not re-speak already-spoken segments (no immediate-repeat chatter).
1689
+ - **Only the visible tab reports** (`document.visibilityState`), plus a report on `visibilitychange`.
1690
+ Every tab with a `<video>` reports once per second; with two such tabs open the server received
1691
+ alternating positions and the plugin interpreted it as the user scrubbing wildly.
1692
+ - The simulator can now jump the playhead (`seeks: [{at, to}]`), and there are four new scenario
1693
+ tests covering: video changed wakes once, video ended wakes once, seek forward wakes once, rewatch
1694
+ wakes once and does not re-speak.
1695
+
1696
+ Note the jump check must run **before** the anchor is refreshed — comparing the new reading against
1697
+ the already-updated anchor measures zero. That was the first (failed) version.
1698
+
1699
+ ### Fixed
1700
+
1701
+ - **`bin/watch.mjs chat` ran its own copy of the chat server** — an inline `http.createServer` plus
1702
+ duplicated copies of both HTML templates (92 lines). The copies had drifted: it served `/`,
1703
+ `/widget`, `/api/messages`, `/api/say` but **not `/api/position` or `/api/hello`**. So running
1704
+ only `watch.mjs chat` (instead of `bridge`) meant extension reports hit 404 and the CLI path could
1705
+ never read a position. It also never called `attachSpeechToChat()`, so that chat box showed user
1706
+ messages but no script lines. It now uses `startChatServer()` + `attachSpeechToChat()` like the
1707
+ plugin and `bridge` do, and the duplicated templates are deleted.
1708
+ - **`watch.mjs reply` wrote straight to the stream** with `appendChat('assistant', …)`, so the text
1709
+ appeared in the chat box but was never handed to speech subscribers — a TTS adapter stayed silent
1710
+ while the page showed the words. It now uses `appendAssistantSay()`, which writes the stream *and*
1711
+ emits the speech event, matching what `watch_together({say})` does.
1712
+
1713
+ ### Fixed
1714
+
1715
+ - **The plugin passed the browser's debug port to `ensureChatSession()`**, so the chat server tried
1716
+ to bind 9333 — the port the browser is already using. The bind failed, the error was swallowed,
1717
+ and the chat box silently never came up in DSH. It now uses the chat port (9377) as intended.
1718
+ This also mattered for the extension: that server is where reports land.
1719
+
1720
+ ### Removed — the OS media session (SMTC) backend is gone
1721
+
1722
+ Position used to have two sources: the browser's DevTools port, and Windows' system media controls
1723
+ (read by a bundled `watch_smtc.py`). **SMTC is deleted**, along with everything that only existed
1724
+ because of it:
1725
+
1726
+ - `src/watch-probe.js` (121 lines) and `src/watch_smtc.py` (62 lines)
1727
+ - `src/resolve-playing.js` (153 lines) — it reversed a *title* into a source by searching filenames
1728
+ and then Bilibili. With CDP the page URL is the source, so this whole "guess the film" path is
1729
+ gone (it was also the thing most likely to pick the wrong video)
1730
+ - the `winrt` Python dependency (three packages) and the interpreter search
1731
+ - most of the extrapolation policy in `position.js`: the cap drops 180 s → 60 s, `FRESH_MS`
1732
+ becomes 5 s, and the safety margin now only applies after a *missed* read
1733
+ - `pickSession` / `probePlayback` / `describeStatus` and the `probe` injection point
1734
+
1735
+ Rationale: SMTC's `Position` only refreshes on player events (measured gaps of 143 s and 216 s), so
1736
+ treating it as a live position required extrapolating, and extrapolating over a wrong pause means
1737
+ every later segment is built on a wrong cursor. The benefit — "watch in whatever player you like" —
1738
+ did not survive contact with how it actually behaved.
1739
+
1740
+ What you give up: you now watch inside the dedicated browser window
1741
+ (`scripts/start-edge-debug.cmd`). Chromium 136+ refuses to open a DevTools port on the default
1742
+ profile, so that window necessarily has its own profile and needs a one-time login.
1743
+
1744
+ ### Fixed
1745
+
1746
+ - **`loop.built` / `loop.dur` / `loop.sourceUrl` leaked across films.** Starting a second watch
1747
+ session reused the previous film's duration, so the first read of the new film looked like a
1748
+ "video changed" event and stopped the loop immediately; `built` made prefetch skip segments it had
1749
+ built for the old film. Both are now reset when the source changes.
1750
+ - **`startWatchLoop` used `Date.now()` for the anchor while pricing time off its injected clock**,
1751
+ which made every simulated read look minutes old. It now uses the injected clock.
1752
+ - **The CLI's `pos()` never read SMTC at all**, so the CLI was browser-only even while the plugin
1753
+ had a fallback. Moot now that SMTC is gone, but it is why the tool seemed to demand a special
1754
+ browser.
1755
+
1756
+ ### Removed — dead code trimmed so there is one decision path
1757
+
1758
+ Two functions that duplicated live logic and were never called in production are gone:
1759
+
1760
+ - `dueDecision` (in `src/timer.js`) — a pure "should I speak now" decision that shadowed
1761
+ `position.shouldSpeak`. Nothing in the loop ever called it; only a test exercised the abandoned
1762
+ design. The "pause too long → stop" intent it carried is now not implemented (see note below).
1763
+ - `depthForBuffer` (in `src/batches.js`) — a count-based lookahead that duplicated `windowFor`,
1764
+ which the loop actually uses (position-based, so the invariant holds at every position, not just
1765
+ at segment starts). Its tests were redundant guards of that same invariant.
1766
+
1767
+ Net: 13 tests removed (8 for `dueDecision`, 5 for `depthForBuffer`); `windowFor`'s existing tests
1768
+ already cover "lookahead ≥ N seconds at every position", so no coverage was lost.
1769
+
1770
+ ### Changed — idle auto-stop now also covers a paused-and-abandoned video
1771
+
1772
+ The loop used to only stop itself on "no movement" when the last reading was a *playing* sample
1773
+ (`why === 'recent-refresh'`). A paused video reports a frozen position forever — `estimate` returns
1774
+ `why: 'paused'`, never stale — so pausing and walking away left the loop polling indefinitely. The
1775
+ idle check now also fires on a frozen *paused* position, after the same `2 × segment` grace period,
1776
+ and wakes you with "停了一会儿" so you can resume by calling `watch_together` again.
1777
+
1778
+ ### Fixed — voice adapter no longer hard-codes a voice
1779
+
1780
+ `examples/voice-edge-tts/index.mjs` used to fall back to `zh-CN-XiaoxuanNeural` when
1781
+ `~/.dsh/tts.json` had no `voice`. That baked one person's voice into the example, so shipping it
1782
+ would have dragged that choice into everyone's install. It now falls back to the neutral
1783
+ `zh-CN-YunxiNeural` and prints a one-line hint telling you to set `voice` in `~/.dsh/tts.json`
1784
+ (e.g. `"voice": "zh-CN-XiaoxuanNeural"`). Nothing about the voice ships in the package — you mount
1785
+ the adapter via `~/.dsh/voice.json` (or `DSH_VOICE_ADAPTER`) and pick the voice yourself.
1786
+
1787
+ ## Earlier — 0.1.0 draft, never published (2026-10-30)
1788
+
1789
+ The first cut as a standalone plugin. It was not published under this number; the version line now
1790
+ starts at 0.0.7, so this section is kept purely as a record of how the feature set got here. The feature existed inside `dsh-video-storyboard` 0.4.x as
1791
+ `src/watch/`; it is now its own package with its own entry point, its own version, and a one-way
1792
+ dependency on `dsh-video-storyboard`.
1793
+
1794
+ ### Added
1795
+
1796
+ - **`watch_together`** — watch a video together with a text-only agent. Instead of one whole-film
1797
+ storyboard, it follows the user's **real playback position** and hands over one segment at a time,
1798
+ `lead` seconds before the segment ends. The next segment is built while the user is still watching
1799
+ the current one, so delivery is perceived as instant (4/4 measured deliveries at 0.0 s).
1800
+ - **Ramp-up start.** Segment lengths grow `[60, 120, 180, 240]` → `segment`, so the first line lands
1801
+ around 45 s instead of after a full 5-minute batch. `ramp: []` disables the ladder.
1802
+ - **Double buffering.** `depth: 2` keeps the current batch plus the next one built, and starts the
1803
+ one after that while the user watches.
1804
+ - **Playback position straight from the page.** It reads `<video>.currentTime` over the DevTools
1805
+ protocol, so the value is exact, and the page URL becomes the source (`file:///D:/x.mp4` → local
1806
+ path) — no searching, no downloading, no asking. Never released with the OS media session (SMTC)
1807
+ backend documented below: SMTC's `Position` only refreshes on events, so using it as a live
1808
+ position meant extrapolating, and a wrong position poisons every later segment.
1809
+ - **Honest confidence levels.** The plugin reads every 15 s and extrapolates in between, which is
1810
+ normal and self-correcting. What it refuses to do is keep extrapolating after it has *missed* a
1811
+ read: past 20 s it demands an extra 5 s of margin before speaking, and past 60 s it stops
1812
+ guessing and asks for `cursor` instead.
1813
+ - **The speech seam, with no engine.** `src/speech-bus.js` exposes `onSpeech(handler, { voice })`,
1814
+ `emitSpeech()`, `speechEvents()` and `lastSpeech()`. The plugin ships no engine, no default
1815
+ adapter and no voice parameters; `watch_together` results carry `speech: [{ at, text, state }]`
1816
+ and the loop emits `state: 'due'` when a line is actually due.
1817
+ - **Adapters loaded by path.** `~/.dsh/voice.json` `{ "adapter": "<path or module>" }` (or
1818
+ `DSH_VOICE_ADAPTER`) is `import()`ed once at startup; the module exports `attach(api)` and returns
1819
+ a detach. Nothing is bundled, and a failure only logs a warning.
1820
+ - **`examples/voice-edge-tts/`** — a working adapter (edge-tts → `ffplay` → system-voice fallback).
1821
+ It prints `[voice 03:11.4] <line>` to stderr for every line that comes due; that log, not the
1822
+ audio, is what you want when checking *when* text fires.
1823
+ - **One text stream for the chat box.** `chat.jsonl` carries `line` (scripted), `assistant`
1824
+ (interjection) and `user`, with `say: true` marking the speakable ones.
1825
+ `watch_together({ say: "…" })` is how the model gets its interjection in — the plugin cannot read a
1826
+ normal reply. `attachSpeechToChat()` subscribes with `voice: false`, so a display-only consumer can
1827
+ never silence the loop.
1828
+ - **A localhost chat page** (`/` full view, `/widget` capsule) with an `/api/messages` long-poll and
1829
+ an `/api/say` callback. This is the only channel that actually reaches a blocked `watch_together`
1830
+ call — messages typed into the host's own input box are appended to the session log *after* the
1831
+ blocking call returns (measured: 42 s of polling, 0 bytes written).
1832
+ - **`examples/floating-chat/window.py`** — a real floating window without a browser: frameless,
1833
+ always-on-top, translucent, stdlib tkinter only. Reads the same `chat.jsonl`.
1834
+ - **`bin/watch.mjs`** — a CLI shell for sessions that have no `watch_together` tool. It imports the
1835
+ same `src/`, so behaviour cannot drift from the plugin.
1836
+
1837
+ ### Fixed
1838
+
1839
+ - **The CLI imported pre-refactor paths** (`src/browser-time.js`, `src/pipeline.js`, …) that no
1840
+ longer exist, so `bin/watch.mjs` could not even start. All imports now resolve through the
1841
+ `dsh-video-storyboard` package name.
1842
+
1843
+ ### Changed
1844
+
1845
+ - `detachAdapters()` no longer reaches into the bus's private subscriber map; it calls
1846
+ `__resetSpeech()` from `speech-bus.js`.
1847
+ - `watch-run.js` imported `./watch.js` twice; merged into one import.
1848
+
1849
+ ### Known limits
1850
+
1851
+ - **Speaker separation is not attempted.** Measured on the reference machine: per-sentence cam++
1852
+ embeddings split single-speaker material into 6 speakers; demucs pre-separation made no difference
1853
+ (median similarity 0.62 → 0.61); FunASR's `ClusterBackend` returns "one speaker" outright below 20
1854
+ speech segments — short clips are outside its operating range by design.
1855
+ - **Interjection audio can collide with a line already being spoken.** Windows mixes both SAPI
1856
+ instances, so `say` occupies `quiet-until.json` before speaking and `cue` skips lines inside that
1857
+ window (it skips rather than defers — deferring desynchronises from the picture). The remaining
1858
+ gap is the 3–8 s while a line is mid-speech, which cannot be cut short.
1859
+ - **CRLF-less assumption.** The chat page replaces `__PORT__` in the templates per start; changing
1860
+ the port while a browser tab is already open requires a reload.