dsh-watch-together 0.0.7 → 0.1.0

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
@@ -3,6 +3,328 @@
3
3
  All notable changes to **dsh-watch-together** are documented here.
4
4
  This package starts its own version line at `0.0.7` — it is not a continuation of `dsh-video-storyboard`.
5
5
 
6
+ ## [0.1.0] - 2026-11-01
7
+
8
+ 首个发布版本。要求 `dsh-video-storyboard@^0.5.11`(字幕轨用到它的 `./transcript-pass` 子路径)。
9
+
10
+ ### Fixed — optional services must go through `ctx.get()`
11
+
12
+ `ctx?.attachments?.saveImage` looks like a runtime probe but throws in a real host: cordis's `ctx`
13
+ is a Proxy whose `get` trap **throws** `cannot get property "xxx" without inject` when a service was
14
+ not declared in `inject`. `?.` only guards `null`/`undefined`, not exceptions.
15
+
16
+ All optional-service lookups now go through `serviceOf(ctx, name)` (in `src/timer.js`): it prefers
17
+ `ctx.get(name)` — cordis's documented way to ask for an optional dependency, returning `undefined`
18
+ when absent — and only falls back to property access inside a `try`.
19
+
20
+ ### Liquid-glass window, one stream, and a name you can change (2026-11-01)
21
+
22
+ Reported as: the scripted lines (warm amber, with a "台词" label) and the assistant's replies (cool
23
+ grey, labelled "陪看") read like two different people talking in one stream — and the window itself
24
+ looked like a plain dark panel.
25
+
26
+ **One stream, one look.** `ROLE` now maps `line` and `assistant` to the *same* colours, and the head
27
+ line shows **only the timestamp** — no "台词", no "陪看". Only the user's own messages keep a tint
28
+ (so you can still tell which side you are on).
29
+
30
+ **Timestamps are wall-clock now** (`HH:MM:SS`), for every role. Scripted lines used to show their
31
+ playback position (`01:26.0`) while everything else showed local time — two time bases in one
32
+ stream, so reading it meant converting in your head. Seconds are included because a segment runs
33
+ 2–5 minutes and several messages share the same minute; `HH:MM` alone would make the stamps useless
34
+ for telling them apart. A message with no `at` gets no head line at all (an empty label still eats
35
+ a full line of height).
36
+
37
+ **Liquid glass.** Three things carry the effect, because tkinter cannot blur what is behind it:
38
+
39
+ - **24px+ radius** — and `round_rect` no longer uses `smooth=True`, which renders a 22px radius as
40
+ roughly 14px (it smooths a polygon rather than following an arc). It now samples each corner arc
41
+ directly.
42
+ - **A refractive edge**: a 1px inner highlight along the top, plus an outer border split into a lit
43
+ upper half and a shadowed lower half — what a real piece of glass does.
44
+ - **Slight window transparency** (`-alpha 0.975`, `DSH_WATCH_GLASS_ALPHA` to tune, ≥1 disables).
45
+ The desktop shows through just enough to read as glass without competing with the text.
46
+
47
+ Buttons and the input field are **pills** now (`Pill` class + a Canvas-backed field): a square
48
+ "发送" button next to a 24px-rounded panel was the most obviously un-Apple thing left.
49
+
50
+ **The title is editable.** Click the name in the header, type, press Enter — saved as `name` in
51
+ `~/.dsh/watch-window.json` and restored next launch. Committing uses an explicit `_editing` flag
52
+ rather than `winfo_ismapped()`, which is still `False` on the frame right after `pack()` and would
53
+ silently swallow a fast Enter.
54
+
55
+ **Fixed:** `meta` entries (wake failures, mic status) were falling through to the assistant bubble
56
+ style — a screenful of `[一起看] 叫醒失败` rendered as full-size cards. They now use the grey
57
+ one-line `Meta` row that already existed for exactly this.
58
+
59
+ **Fixed:** the saved geometry was clamped against `sw - 120` instead of the window's own width, so a
60
+ 700px-wide window could be restored 580px off the right edge.
61
+
62
+ ### No more self-made "queued messages", one reminder per interjection, and a hideable window (2026-11-01)
63
+
64
+ Reported as three things that turned out to be one root cause plus two design gaps.
65
+
66
+ **The queue strip.** `wakeSession` delivers through `agent.followup()`, which lands in the host
67
+ inbox's `next-turn`. DSH's `QueueDock` renders **every** row of `next-turn` and does not filter by
68
+ `source.kind` — so the plugin's own instructions showed up in the input box as pending messages the
69
+ user never typed ("插话栏自动出现"). Two consequences fixed here:
70
+
71
+ - **The hangup note no longer goes through `followup`.** Closing the window is still a hangup (clock
72
+ stops, nothing is rebuilt, no lines are spoken), but the explanation is now written into
73
+ `watch.json` and handed to the model on its next tool result (`takeHangupNote`). The watch loop
74
+ already has the model blocked inside an interrupted tool call, so nothing is lost — and the queue
75
+ strip stays empty. `markHungUp(input, env, note)` carries the text; taking it clears it.
76
+ - **`[未回应]` is emitted once per interjection.** It used to be appended to *every* tool result
77
+ until the model answered with `say`, so one message from the user could be read as three separate
78
+ events ("大肥鱼已经重复了"). `noteInterjected` also no longer restarts the clock when the same
79
+ sentence arrives twice inside the 3-minute TTL.
80
+ - **The interjection prompt is two sentences, not a wall of ⚠️.** Same requirements
81
+ (`say` first, `speakNow`, lines in the same call), a fifth of the length — it is rendered in the
82
+ queue strip, so its size is user-visible.
83
+
84
+ ### `window: "hide" | "show"` — put the window away without ending the watch
85
+
86
+ Closing the window means "I am done watching". Hiding it does not: the process stays alive, the
87
+ clock keeps running, lines keep being spoken, nothing is marked as hung up. Reported as
88
+ "如果有其他功能隐藏悬浮窗会更好".
89
+
90
+ - `watch_together({ window: "hide" })` writes `hidden: true` into `~/.dsh/watch-window.json`;
91
+ `window.py` polls its config every 200 ms (`_sync_visible`) and does `withdraw()` / `deiconify()`.
92
+ `withdraw` rather than `iconify`: an always-on-top floating window should leave no taskbar entry
93
+ behind.
94
+ - `openFloatingWindow` clears `hidden` **before any early return**, so a window that was hidden when
95
+ the process died does not come back invisible.
96
+
97
+ ### Two-track prefetch (2026-11-01) — subtitles no longer wait for the pictures
98
+
99
+ The picture side is the slow one: a segment costs a download plus a scan (10–20 s, 20–90 s for the
100
+ first), while the text for the same window arrives in a few seconds (site CC: instant; local ASR
101
+ RTF 0.019 ≈ 6 s per 5-minute segment). They used to be produced and delivered as one package, so
102
+ the text sat in the slow batch's shadow. Now they are two independent tracks over the **same**
103
+ batch table and the **same** look-ahead window.
104
+
105
+ - **New subtitle track** (`transcribe` → `dsh-video-storyboard/transcript-pass`). Mirrors the picture
106
+ track line for line: same `plan.indexAt` / `windowAt`, its own `transcribed` set. "Whoever's window
107
+ is full stops first" falls out of `find()` returning `undefined` — no extra rule.
108
+ - **Two-part delivery.** When the text lands before its pictures, it is sent on its own
109
+ (`[一起来看·台词] 03:00–06:00` + one timestamped sentence per line). When the picture batch
110
+ arrives later it is built with `omitTranscript`, so the cells carry only times and the sentences are
111
+ not repeated (measured: 17k vs 26k tokens per 2 hours, +50% when repeated).
112
+ - **`feedTranscriptLeadMs`** (default 0 = send as soon as it lands). Raise it to ~20000 if the
113
+ two-part delivery feels chatty and you would rather wait for one combined message.
114
+ - **`transcriptTrack: false`** turns the whole track off.
115
+ - **Failures don't sink the loop.** A failed transcription is not marked as done, so the next tick
116
+ retries; three failures in a row blacklist that segment for 10 minutes (a missing ASR service
117
+ should not be hit every 2 seconds). The picture track is never blocked by it.
118
+ - **Cross-track timestamps now share one clock.** `transcribedAt` / blacklist times were stamped with
119
+ `Date.now()` while the tick compares against the injectable `deps.now()`; the difference was
120
+ negative by a trillion milliseconds, so the "skip for 10 minutes" and "wait N ms before feeding"
121
+ gates were both permanently bypassed (feeding never fired at all).
122
+
123
+ ### Experience pass (2026-11-01) — the minutes spent staring at nothing
124
+
125
+ Same code, same contract; what changes is what the user sees (or hears) while waiting.
126
+
127
+ - **A slow build now says something.** The first batch of a film needs a download plus a scan
128
+ (20–90 s) and a tool call cannot speak — so the window stayed empty and the only signal was
129
+ silence. After 4 s of building (`DSH_WATCH_SLOW_BUILD_MS`) one `meta` line is appended to the
130
+ stream: 「正在取 03:00–06:00 这一段…」. Fast segments write nothing.
131
+ - **The measured latency is finally used on the main path.** `latency.js` has been calibrating
132
+ "read position → result ready" for a while, but only the background clock (`shouldSpeak`) spent it;
133
+ the blocking call still waited until `segment end - lead`, so on the same machine the clock spoke
134
+ early and the tool call spoke late. `deliveryState` now uses `lead + aheadSeconds`, while the text
135
+ still reports `lead` (what is pulled earlier is the work, not the sentence).
136
+ - **Calibration only counts deliveries.** Not-yet calls take tens of milliseconds and are not samples;
137
+ recording them dragged the EWMA towards zero (and wrote `latency.json` on every poll).
138
+ - **The last batch is delivered at the tail.** The final segment's due point is `end - lead`, which for
139
+ the last batch sits past the end of the film — the position never reaches it, so the user watched
140
+ the ending and got nothing. Reaching/passing `dur - 1` now counts as due.
141
+ - **`speech` only lists lines that are still ahead.** It used to echo the whole draft, including the
142
+ lines the same call had just pruned as past — the model read them as "still going to be spoken".
143
+ - **Delivery guidance trimmed ~45%** (≈1150 → ≈640 chars). It is resent every batch; the loop/pacing
144
+ rules already live in the tool description, so only the hard rules stay here: write the lines,
145
+ no spoilers, one sentence, `say` is the only visible channel.
146
+
147
+ ### Reading pass over the loop (2026-11-01) — six real bugs, one hot path
148
+
149
+ No new features. Everything below was found by reading the code against its own comments and then
150
+ reproducing it; each fix carries a regression test that fails on the old code.
151
+
152
+ - **`lastDelivered: null` was read as batch 0.** A delivery blocked by the "no lines yet" gate writes
153
+ `lastDelivered: null`, and `Number(null)` is `0` — exactly the first batch's start. That batch then
154
+ counted as already delivered forever: `wait: true` woke up and answered "already delivered", image
155
+ and manifest never handed over. Empty now stays `NaN`.
156
+ - **Same film, two URL forms → the loop restarted.** `samePlan` compared the raw `input` string, but the
157
+ extension reports `…/BV1g3xN6hEuw/?trackid=…&spm_id_from=…` while the model usually holds the clean
158
+ link. Every second call therefore looked like a new source, wiping `spoken` and re-waking segments
159
+ that had already been delivered. It now compares `sessionKey()`.
160
+ - **`dur: null` became `0 s` on the bridge path.** `Number.isFinite(Number(s.dur))` passes for `null`,
161
+ so a report without a duration set the baseline to 0; the next real reading (600 s) then differed by
162
+ more than a second and was judged "video changed" — the clock stopped mid-film. `num()` in
163
+ `position-bridge.js` and the baseline update now treat empty as empty.
164
+ - **`waitForVideo` lost the hangup.** The input surface is prepared once (`prepared ??=`), and the
165
+ early pre-warm for `waitForVideo` passed no arguments — so `input`/`open` never reached it. Without
166
+ `input` the recorded hangup could not be matched, the window was re-opened, and the call went off to
167
+ wait for a video instead of returning `[hangup]`.
168
+ - **`dueLine` rewrote `watch.json` on every tick.** Its `dirty` flag was shared across segments: once one
169
+ batch had pinned its un-timed lines, every later batch was written back unchanged — a full state write
170
+ every 2 s for the rest of the film. The flag is per segment now.
171
+ - **`waitUntil` / `waitForRefill` lied about why they stopped.** Breaking out because the user paused (or
172
+ the film ended) still produced "waited to the cap". The text now names the real reason.
173
+
174
+ Hot path, same area:
175
+
176
+ - `cachedCues()` re-read and re-parsed the whole subtitle file on every tick (`dueLine` asks several
177
+ times per tick). It is memoised on `path + size + mtime` now, and returns the **same array** so that
178
+ `makeLagFn`'s memo can be keyed on array identity. `makeLagFn` additionally sorts once and looks up
179
+ by binary search instead of a linear scan of every cue. 2000 cues × 5400 lookups: **66.7 ms → 0.8 ms**
180
+ (×83), and the disk read/parse per tick is gone.
181
+ - `lines-util.js` had its own `cacheDir()` that fell back to `~/AppData/Local` on every platform, so on
182
+ Linux/macOS the subtitle cache landed in a directory that does not exist; it now uses the storyboard's
183
+ `cacheDir()`. `findCachedMedia()` likewise uses `tmpdir()` instead of `LOCALAPPDATA/Temp`.
184
+ - Dead exports removed: `plan.starts` (a 513-element array allocated on every `makePlan`),
185
+ `legacySessionKey`, `wasWritten`, `MATERIAL_PARTS`. The input surface failing to start no longer fails
186
+ the whole call — it is reported in the result instead.
187
+
188
+ Three rounds on 2026-10-31. The through-line: the plugin knew something, and the model (or the user)
189
+ never found out — plus one window that needed to look like something people want to keep on screen.
190
+
191
+ ### Long-video recap — merged, but opt-in
192
+
193
+ PR #2, after one round of review. Its first shape prepended a 420-character `[前情]` to **every**
194
+ delivery, partly built from the model's own scripted lines: second-hand context in a package whose
195
+ contract is "raw material only — never retell what the user just watched", at ~200 tokens per
196
+ segment, with no evidence it helped.
197
+
198
+ What shipped instead: off unless `recap: true` or `DSH_WATCH_RECAP=1` (`recap: false` beats the env
199
+ var); only **cached subtitle sentences**, never the model's lines; `recapSegments` 1–3 (default 2),
200
+ `recapMaxChars` 80–1200 (default 420); never reads past the current segment, never trims the live
201
+ transcript, no ASR, no network. Whether it actually reduces retelling is still **unmeasured** — it
202
+ stays opt-in until somebody measures it.
203
+
204
+ ### Observability: `statusOnly` can now answer "why is it slow"
205
+
206
+ Promised in issue #4. `pos + reason` says *what* the clock thinks, not *where it is stuck*.
207
+
208
+ - `segment { index, from, to, delivered, total }` — which batch, its bounds, how many were delivered
209
+ this session, how many the film has (`total` is `null` when the duration is unknown). The last batch
210
+ index is taken at `dur - 1 ms`, because a duration that lands exactly on a boundary would otherwise
211
+ report one batch too many.
212
+ - `speech { queued, lastLateSec, busyUntil }` — lines still waiting, how late the previous line was
213
+ (from `dueLine`'s new `meta: true`, which also keeps the plain-string return for old callers), and
214
+ when the serial voice engine frees up.
215
+ - `build { inflight, cached, lastMs }` — which batch is being built, how many are cached, how long the
216
+ last build took. The cache is passed into the loop for reporting only; it never influences a decision.
217
+ - `queued` needs a disk read, so it is filled in `statusOnly` only, and a failure there is reported as
218
+ `speech.queueError` instead of being swallowed (the first version of this swallowed a `ReferenceError`
219
+ from a missing import and looked exactly like "there are no lines").
220
+
221
+ ### The floating window, rebuilt
222
+
223
+ "这个悬浮窗太丑了" — fair. The old one was a borderless frame with a `Text` widget that painted
224
+ role-coloured **full-width stripes**, on a window Windows stretched from 96 dpi, reading the whole
225
+ `chat.jsonl` every 200 ms.
226
+
227
+ - **Real bubbles.** Each message is its own rounded card (Canvas background + wrapped Label), sized
228
+ to its content: script lines in amber with a left rule, the model in slate, the user's own words
229
+ right-aligned in blue. Above each one, a muted line saying who and when (`台词 04:12.3` for a
230
+ scripted line, `我 21:16` for chat).
231
+ - **Per-monitor DPI awareness** before the window exists, and every size/font derived from the real
232
+ scale factor. Unaware Tk windows are bitmap-stretched at 125/150%, which reads as "blurry and wrong".
233
+ - **Rounded window** via `-transparentcolor` (Windows only; falls back to square corners), a 1 px
234
+ border, and a hand-drawn 6 px scrollbar that only appears when the list actually scrolls.
235
+ - **Does not steal focus.** `focus_force()` at startup meant pressing space to pause the video landed
236
+ in the chat box; now the entry only takes focus inside the window.
237
+ - **Does not fight your scrolling.** New lines auto-scroll only if you were already at the bottom.
238
+ - **Incremental read.** Only the bytes appended since the last tick are parsed, and the first paint
239
+ replays just the last 60 entries.
240
+ - Resizable from the bottom-right grip; position and size persist in `~/.dsh/watch-window.json`.
241
+
242
+ ### Stop when the signal says stop: hangup, dead source, switched video
243
+
244
+ Reported as "换片或者我都关浏览器了还在念台词" and "关了悬浮窗 AI 还是会自动调出来,根本不会自动结束".
245
+ Both were the same shape: the plugin knew the source was gone, and kept talking anyway.
246
+
247
+ - **Speech now requires a believable position.** The line queue only fired when the position was
248
+ `fresh`, or `extrapolated` within `SAFETY_AFTER_MS` (20 s — the normal gap between probes).
249
+ Before, the only thing excluded was `paused`; `estimate()` happily extrapolates a dead source
250
+ forward and `pos` stays finite, so closing the browser kept reading lines out for minutes.
251
+ Nothing is spoken on an `unknown` position, and the position-unknown give-up dropped from
252
+ 10 min to 5 min (the watch should not sit there pretending).
253
+ - **Closing the floating window is a hangup, treated like an interjection.** The window is the only
254
+ way to talk mid-watch, so closing it means "I'm done":
255
+ - the clock stops and **really wakes the model** — `wake:false` (the default) used to silence this
256
+ too, because it shared the `wake` path with the segment-end reminder. User actions (hangup,
257
+ video changed, video ended, seek, unreadable position, high-frequency mode) now use a separate
258
+ always-real channel (`wakeSignal`), and the message says **do not call watch_together again and
259
+ do not read out any more lines**;
260
+ - the guard is stored on the loop and can be turned on later (`resumed` path used to freeze it,
261
+ so a window opened by an earlier call was never guarded);
262
+ - the next tool call **does nothing at all**: no frame, no clock, no window (`[hangup]` result).
263
+ `sameWatch` previously required `args.input`, which the model never sends — so every call looked
264
+ like "a new watch" and re-opened the window the user had just closed.
265
+ - `wakeWithRetry` called an undefined `note()` in its failure branch (a `ReferenceError` swallowed by
266
+ the ticker). Real wakes can fail, so it was reachable; now it records into `loop.logs`.
267
+
268
+ Tests: 247 pass, +4 in `test/hangup-guard.test.mjs` (dead source sends nothing, live source still
269
+ speaks, hangup wakes with the right wording, post-hangup call is inert).
270
+
271
+ ### Interjections: speak first, then look
272
+
273
+ Reported as "它一声不吭先去 zoom,回来才说话". The root cause was not the model: a normal reply
274
+ never reaches the floating window — only `say` does and only `say` is spoken. So "think, then look,
275
+ then answer" was, from the user's side, complete silence for tens of seconds.
276
+
277
+ - One wording, one place (`src/interject.js`) for all five entry points (during a build, during the
278
+ lookahead fill, during a blocking wait, `waitUntil`, `nextLine`). It now says exactly what to do:
279
+ `watch_together({ say: "我看一眼", speakNow: true })` — one call, words written before any frame
280
+ is built. `lines` and `say` can ride in the same call, so "台词优先" no longer means "stay silent".
281
+ - Unanswered interjections are **tracked**: the next tool result ends with `[未回应] …你还没回`,
282
+ until a call actually carries `say` (expires after 3 min). Previously the reminder existed only
283
+ inside the message that woke the model, which it had already scrolled past.
284
+ - `waitUntil` / `nextLine` called a function that **did not exist** (`chatResult`) — an interjection
285
+ during either wait threw `ReferenceError` and the tool failed. Defined, and it reuses the same wording.
286
+ - Waiting for a video to appear returned a result **without `text`**, which the host's `output.schema`
287
+ requires. That path now returns a proper result.
288
+
289
+ ### Reply vs. scripted line: 12-second guard
290
+
291
+ Reported as "说话和插话的回复离太近,把后面那句改一下". Two lines spoken back to back on a serial
292
+ TTS chain means the second one either drifts or is dropped by the adapter (queue > 3.5 s → `skipped`).
293
+
294
+ - `say` now marks the voice engine busy for its full spoken length (`src/reply-guard.js`), so the
295
+ loop stops feeding scripted lines while a reply is still playing. Previously only the loop's own
296
+ lines updated that clock — a reply was invisible to it.
297
+ - Lines scheduled within 12 s of a reply are **withdrawn from the batch and handed back** to the
298
+ model (`[lines·太近]`) with instructions to rewrite them around what was just said, or drop them.
299
+ Withdrawn, not silently deleted: the user asked for "改一下", not "少一句".
300
+
301
+ ### Switching videos is noticed in ~2 s, not ~15 s
302
+
303
+ - The per-tick bridge read (every 2 s) now does the switch / end-of-video / big-jump checks, and
304
+ keeps the `dur`/`url` baseline up to date. Before, all three lived in the 15-second CDP probe
305
+ branch only, so a switch could go unnoticed for a quarter of a minute — while the clock kept
306
+ computing segment boundaries against the old film.
307
+ - The blocking wait in `watch-run` now compares each read against the film it started with and
308
+ returns `[video-changed]` immediately. **This was the only reliable path**: the loop's wake goes
309
+ through `followup()`, which is delivered *after* the current tool call returns — and that call was
310
+ busy waiting.
311
+ - `sourceSwitched()` centralises the test, and `Number(null) === 0` is explicitly guarded: a
312
+ not-yet-known duration used to look like a "0-second film" and stop the watch instantly.
313
+
314
+ ### Cold start: don't wait a full minute for a video we can already identify
315
+
316
+ - The extension only reports while the tab is **visible** — and "一起看" is usually typed in another
317
+ window. The position went stale after 5 s, the plugin concluded "no video", and sat in the 60 s
318
+ wait. It now falls back to a **stale** sample (up to 2 min) to identify the film, marks the
319
+ position `stale`, and lets the next fresh reading correct it.
320
+ - Automatic waiting (no `waitForVideo`) dropped from 60 s to **20 s**; explicit `waitForVideo: true`
321
+ stays at 120 s.
322
+ - `probeBrowser()` is skipped when the extension already reports: one probe is `listTargets`
323
+ (1.2 s) plus up to 8×1.5 s of CDP round-trips — pure overhead for a `browser:` line the extension
324
+ just answered. The line now reads `browser: extension reporting <title> playing 03:20`.
325
+
326
+ Tests: 243 pass (`node --test`), 6 of them new in `test/interject-reply.test.mjs`.
327
+
6
328
  ## [0.0.7] — 2026-10-31 (first release)
7
329
 
8
330
  The first published version. One tool, `watch_together`: it follows the user's real playback