dsh-watch-together 0.2.11 → 0.2.13

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/package.json CHANGED
@@ -1,115 +1,118 @@
1
- {
2
- "name": "dsh-watch-together",
3
- "version": "0.2.11",
4
- "description": "Watch a video together with a text-only agent: follow the user's real playback position, hand over one segment at a time just before it ends, and keep a single text stream of scripted lines, interjections and the user's replies.",
5
- "keywords": [
6
- "dsh",
7
- "dsh-plugin",
8
- "deepseek-harness",
9
- "video",
10
- "watch-together",
11
- "watch-party",
12
- "companion",
13
- "playback",
14
- "subtitle",
15
- "caption",
16
- "tts"
17
- ],
18
- "homepage": "https://github.com/SAOS-3624/dsh-watch-together#readme",
19
- "bugs": {
20
- "url": "https://github.com/SAOS-3624/dsh-watch-together/issues"
21
- },
22
- "repository": {
23
- "type": "git",
24
- "url": "git+https://github.com/SAOS-3624/dsh-watch-together.git"
25
- },
26
- "author": "SAOS-3624",
27
- "license": "Apache-2.0",
28
- "type": "module",
29
- "main": "./src/index.js",
30
- "exports": {
31
- ".": "./src/index.js",
32
- "./client": "./lib/client.js",
33
- "./register": "./src/register.js",
34
- "./tool-spec": "./src/tool-spec.js",
35
- "./watch": "./src/watch.js",
36
- "./batches": "./src/batches.js",
37
- "./chat": "./src/chat.js",
38
- "./voice": "./src/voice.js",
39
- "./speech-bus": "./src/speech-bus.js",
40
- "./voice-adapter": "./src/voice-adapter.js",
41
- "./interfaces": "./src/interfaces.js",
42
- "./public-api": "./src/public-api.js",
43
- "./recognition-interface": "./src/recognition-interface.js",
44
- "./tts-interface": "./src/tts-interface.js",
45
- "./window-interface": "./src/window-interface.js",
46
- "./window-protocol": "./src/window-protocol.js"
47
- },
48
- "bin": {
49
- "dsh-watch": "./bin/watch.mjs",
50
- "dsh-watch-lines": "./bin/lines.mjs"
51
- },
52
- "files": [
53
- "src",
54
- "lib",
55
- "bin",
56
- "extension",
57
- "scripts",
58
- "docs",
59
- "cordis.patch.yml",
60
- "dsh.plugin.json",
61
- "README.md",
62
- "CHANGELOG.md",
63
- "LICENSE",
64
- "NOTICE",
65
- "examples/floating-chat/*.py",
66
- "examples/floating-chat/*.cmd",
67
- "examples/floating-chat/*.png",
68
- "examples/floating-chat/*.txt",
69
- "examples/voice-edge-tts/index.mjs"
70
- ],
71
- "engines": {
72
- "node": ">=20"
73
- },
74
- "scripts": {
75
- "test": "node --test",
76
- "pretest": "node scripts/sync-dep.mjs",
77
- "sync:dep": "node scripts/sync-dep.mjs",
78
- "prepublishOnly": "node scripts/check-syntax.mjs && node --test",
79
- "check": "node scripts/check-syntax.mjs",
80
- "doctor": "node bin/watch.mjs doctor",
81
- "install:extension": "node bin/watch.mjs install-extension",
82
- "sim": "node scripts/watch-sim.mjs",
83
- "e2e": "node scripts/watch-e2e.mjs"
84
- },
85
- "dependencies": {
86
- "dsh-video-storyboard": "^0.6.0"
87
- },
88
- "peerDependencies": {
89
- "@deepseek-ai/dsh-tools": ">=0.1.0-rc.7"
90
- },
91
- "peerDependenciesMeta": {
92
- "@deepseek-ai/dsh-tools": {
93
- "optional": true
94
- }
95
- },
96
- "dsh": {
97
- "bundle": {
98
- "patch": "./cordis.patch.yml"
99
- },
100
- "client": {
101
- "platform": "web"
102
- },
103
- "catalog": {
104
- "category": "tool",
105
- "summary": {
106
- "en": "Watch a video together with a text-only agent: it follows your real playback position and hands over one segment at a time, just before that segment ends.",
107
- "zh": "和只有文字的智能体一起看视频:跟着你真实的播放位置,一段一段把画面和台词交到它手上,在每段结束前说完。"
108
- },
109
- "capabilities": [
110
- "fs",
111
- "shell"
112
- ]
113
- }
114
- }
115
- }
1
+ {
2
+ "name": "dsh-watch-together",
3
+ "version": "0.2.13",
4
+ "description": "Watch a video together with a text-only agent: follow the user's real playback position, hand over one segment at a time just before it ends, and keep a single text stream of scripted lines, interjections and the user's replies.",
5
+ "keywords": [
6
+ "dsh",
7
+ "dsh-plugin",
8
+ "deepseek-harness",
9
+ "video",
10
+ "watch-together",
11
+ "watch-party",
12
+ "companion",
13
+ "playback",
14
+ "subtitle",
15
+ "caption",
16
+ "tts"
17
+ ],
18
+ "homepage": "https://github.com/SAOS-3624/dsh-watch-together#readme",
19
+ "bugs": {
20
+ "url": "https://github.com/SAOS-3624/dsh-watch-together/issues"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/SAOS-3624/dsh-watch-together.git"
25
+ },
26
+ "author": "SAOS-3624",
27
+ "license": "Apache-2.0",
28
+ "type": "module",
29
+ "main": "./src/index.js",
30
+ "exports": {
31
+ ".": "./src/index.js",
32
+ "./client": "./lib/client.js",
33
+ "./register": "./src/register.js",
34
+ "./tool-spec": "./src/tool-spec.js",
35
+ "./watch": "./src/watch.js",
36
+ "./batches": "./src/batches.js",
37
+ "./chat": "./src/chat.js",
38
+ "./voice": "./src/voice.js",
39
+ "./speech-bus": "./src/speech-bus.js",
40
+ "./voice-adapter": "./src/voice-adapter.js",
41
+ "./interfaces": "./src/interfaces.js",
42
+ "./public-api": "./src/public-api.js",
43
+ "./recognition-interface": "./src/recognition-interface.js",
44
+ "./tts-interface": "./src/tts-interface.js",
45
+ "./window-interface": "./src/window-interface.js",
46
+ "./window-protocol": "./src/window-protocol.js"
47
+ },
48
+ "bin": {
49
+ "dsh-watch": "./bin/watch.mjs",
50
+ "dsh-watch-lines": "./bin/lines.mjs"
51
+ },
52
+ "files": [
53
+ "src",
54
+ "lib",
55
+ "bin",
56
+ "extension",
57
+ "scripts",
58
+ "docs",
59
+ "cordis.patch.yml",
60
+ "dsh.plugin.json",
61
+ "README.md",
62
+ "CHANGELOG.md",
63
+ "LICENSE",
64
+ "NOTICE",
65
+ "examples/floating-chat/*.py",
66
+ "examples/floating-chat/*.cmd",
67
+ "examples/floating-chat/*.png",
68
+ "examples/floating-chat/*.txt",
69
+ "examples/voice-edge-tts/index.mjs",
70
+ "examples/voice-edge-tts/stream/*.mjs",
71
+ "examples/voice-edge-tts/stream/*.py",
72
+ "examples/voice-edge-tts/stream/*.mp3"
73
+ ],
74
+ "engines": {
75
+ "node": ">=20"
76
+ },
77
+ "scripts": {
78
+ "test": "node --test",
79
+ "pretest": "node scripts/sync-dep.mjs",
80
+ "sync:dep": "node scripts/sync-dep.mjs",
81
+ "prepublishOnly": "node scripts/check-syntax.mjs && node --test",
82
+ "check": "node scripts/check-syntax.mjs",
83
+ "doctor": "node bin/watch.mjs doctor",
84
+ "install:extension": "node bin/watch.mjs install-extension",
85
+ "sim": "node scripts/watch-sim.mjs",
86
+ "e2e": "node scripts/watch-e2e.mjs"
87
+ },
88
+ "dependencies": {
89
+ "dsh-video-storyboard": "^0.6.0"
90
+ },
91
+ "peerDependencies": {
92
+ "@deepseek-ai/dsh-tools": ">=0.1.0-rc.7"
93
+ },
94
+ "peerDependenciesMeta": {
95
+ "@deepseek-ai/dsh-tools": {
96
+ "optional": true
97
+ }
98
+ },
99
+ "dsh": {
100
+ "bundle": {
101
+ "patch": "./cordis.patch.yml"
102
+ },
103
+ "client": {
104
+ "platform": "web"
105
+ },
106
+ "catalog": {
107
+ "category": "tool",
108
+ "summary": {
109
+ "en": "Watch a video together with a text-only agent: it follows your real playback position and hands over one segment at a time, just before that segment ends.",
110
+ "zh": "和只有文字的智能体一起看视频:跟着你真实的播放位置,一段一段把画面和台词交到它手上,在每段结束前说完。"
111
+ },
112
+ "capabilities": [
113
+ "fs",
114
+ "shell"
115
+ ]
116
+ }
117
+ }
118
+ }
@@ -0,0 +1,102 @@
1
+ """check-multimonitor.py — 多显示器钳位的回归(不需要第二块显示器)。
2
+
3
+ 跑法(仓库根):
4
+
5
+ python scripts/check-multimonitor.py
6
+
7
+ 覆盖两件事:
8
+
9
+ 1. **单屏等价**:窗口整个在主屏里时,`CaptureSource._clamp_box` 必须和改之前
10
+ 逐像素一致(`max(0, l-PAD)` / `min(sw, r+PAD)`)。多屏支持不能把单屏观感改坏。
11
+ 2. **副屏可用**:副屏在主屏左边(坐标为负)时,钳位后必须仍有正面积 ——
12
+ 旧公式会算出 `gr <= gl` → 玻璃永远停在旧帧(#8)。
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import sys
18
+ from pathlib import Path
19
+
20
+ HERE = Path(__file__).resolve().parent
21
+ sys.path.insert(0, str(HERE.parent / "examples" / "floating-chat"))
22
+
23
+ from glass_capture import CaptureSource # noqa: E402
24
+
25
+ PAD = 40
26
+ SW, SH = 2560, 1440
27
+ # 副屏在主屏左边:虚拟桌面从 (-1920, 0) 开始,宽 1920+2560
28
+ LEFT_BOUNDS = (-1920, 0, 1920 + SW, SH)
29
+
30
+ failures: list[str] = []
31
+
32
+
33
+ def legacy_clamp(l, t, r, b, sw=SW, sh=SH, pad=PAD):
34
+ """改动前的实现,作为等价性基准。"""
35
+ return max(0, l - pad), max(0, t - pad), min(sw, r + pad), min(sh, b + pad)
36
+
37
+
38
+ def check(name, got, want):
39
+ if got != want:
40
+ failures.append(f"{name}: got {got} want {want}")
41
+
42
+
43
+ def test_single_screen_identical():
44
+ src = CaptureSource((SW, SH))
45
+ for l in range(-200, SW + 200, 137):
46
+ for t in range(-200, SH + 200, 151):
47
+ for w in (80, 420, 900):
48
+ for h in (78, 300, 700):
49
+ r, b = l + w, t + h
50
+ # 只比较"窗口矩形完全落在主屏内"的那部分:外面本来就该钳,
51
+ # 旧实现钳到 0 之后可能小于窗口矩形,语义不同
52
+ if not (0 <= l and 0 <= t and r <= SW and b <= SH):
53
+ continue
54
+ check(f"single {l},{t},{w},{h}",
55
+ src._clamp_box(l, t, r, b), legacy_clamp(l, t, r, b))
56
+
57
+
58
+ def test_second_screen_left():
59
+ src = CaptureSource((SW, SH), bounds=LEFT_BOUNDS)
60
+ # 窗口整个在左副屏上(x 为负)
61
+ l, t, w, h = -1500, 300, 420, 320
62
+ gl, gt, gr, gb = src._clamp_box(l, t, l + w, t + h)
63
+ if not (gr > gl and gb > gt):
64
+ failures.append(f"left screen produced empty box: {(gl, gt, gr, gb)}")
65
+ check("left screen left edge", gl, l - PAD) # 外扩一圈仍在虚拟桌面内
66
+ check("left screen right edge", gr, l + w + PAD)
67
+ check("left screen top", gt, t - PAD)
68
+
69
+
70
+ def test_spanning_both_screens():
71
+ src = CaptureSource((SW, SH), bounds=LEFT_BOUNDS)
72
+ # 跨屏:从 -300 到 500
73
+ l, t, r, b = -300, 200, 500, 600
74
+ gl, gt, gr, gb = src._clamp_box(l, t, r, b)
75
+ if not (gr > gl and gb > gt):
76
+ failures.append(f"spanning produced empty box: {(gl, gt, gr, gb)}")
77
+ check("spanning left", gl, -340)
78
+ check("spanning right", gr, 540)
79
+
80
+
81
+ def test_no_bounds_still_works():
82
+ # bounds=None(老调用方 / 单屏):行为与改动前一致
83
+ src = CaptureSource((SW, SH), bounds=None)
84
+ check("no bounds", src._clamp_box(100, 100, 500, 500), legacy_clamp(100, 100, 500, 500))
85
+
86
+
87
+ def main() -> int:
88
+ test_single_screen_identical()
89
+ test_second_screen_left()
90
+ test_spanning_both_screens()
91
+ test_no_bounds_still_works()
92
+ if failures:
93
+ print(f"FAIL ({len(failures)})")
94
+ for line in failures[:20]:
95
+ print(" " + line)
96
+ return 1
97
+ print("OK — 单屏逐像素等价,副屏/跨屏都有正面积")
98
+ return 0
99
+
100
+
101
+ if __name__ == "__main__":
102
+ raise SystemExit(main())
@@ -0,0 +1,88 @@
1
+ /**
2
+ * companion-api.js — 声音适配器能问核心的两个问题:**接下来念什么**、**现在播到哪**。
3
+ *
4
+ * ## 边界(issue #4 上定下来的,改之前先看)
5
+ *
6
+ * 这两个方法**必须是纯读**:核心不替适配器合成、不缓存音频、不知道合成要多久、
7
+ * 也不管适配器缓存几段。给到"下一两句是什么、现在播到哪"就够了 ——
8
+ * 决定预不预合成、什么时候丢过期音频,全在适配器自己。
9
+ *
10
+ * 为什么不能做成"核心帮你预合成":核心一旦开始管音频生命周期,就会出现第二个
11
+ * 声音引擎跟它抢话(core #27 的立场),而且合成慢的机器上要不要重试这种事,
12
+ * 核心根本没法知道。
13
+ *
14
+ * ## 和 `scheduled` 事件的关系
15
+ *
16
+ * `scheduled` 是**推**:核心在台词写好、还没到点时,逐句把未来 1 分钟内的句子发出来。
17
+ * 这两个方法是**拉**:适配器想知道"再往后呢 / 现在到哪了"时自己问。
18
+ * 两者不重复记账 —— `upcoming()` 读的是同一份台词槽,**不看**发过没发过。
19
+ *
20
+ * ## 别把这两个方法当"精确播放器"
21
+ *
22
+ * `at` 的单位是**播放秒**(不是墙钟),`pos` 是外推值(见 `position.js` 的三种可信度)。
23
+ * 位置只用来做"我合成的那句是不是已经过期"这种粗判断,别拿它算毫秒级同步。
24
+ */
25
+
26
+ import { readPlayhead } from './playhead.js';
27
+ import { upcomingLines } from './watch-lines.js';
28
+
29
+ /** 默认往前看多久(秒)。够盖住一次网络往返 + 排一句队,又不至于把整段台词都拉出来 */
30
+ export const DEFAULT_HORIZON_SEC = 20;
31
+ /**
32
+ * 上限。再长就不是"预取"了,而是在替核心做调度 ——
33
+ * 而且一次返回几十句会让适配器分不清哪些是马上要念的。
34
+ */
35
+ export const MAX_HORIZON_SEC = 120;
36
+
37
+ const clampHorizon = (n) => {
38
+ const v = Number(n);
39
+ if (!Number.isFinite(v)) return DEFAULT_HORIZON_SEC;
40
+ return Math.min(MAX_HORIZON_SEC, Math.max(1, v));
41
+ };
42
+
43
+ /**
44
+ * 现在播到哪了。
45
+ *
46
+ * @returns {{pos:number|null, dur:number|null,
47
+ * confidence:'fresh'|'extrapolated'|'unknown', staleMs:number|null}}
48
+ * `confidence` 不是 fresh 就别拿 `pos` 当实时值;
49
+ * `unknown` 时 `pos` 是 `null`(不是 0 —— 见 `playhead.js` 那段)。
50
+ */
51
+ export function position() {
52
+ const ph = readPlayhead();
53
+ return {
54
+ pos: ph.pos,
55
+ dur: ph.dur,
56
+ confidence: ph.confidence,
57
+ staleMs: ph.staleMs,
58
+ };
59
+ }
60
+
61
+ /**
62
+ * 接下来会念的台词(**只读**:不消费、不改槽位、不合成)。
63
+ *
64
+ * 只返回已经写好、而且带 `at` 的句子 —— 没写 `at` 的老台词还没钉到时间轴上,
65
+ * 拿去做预合成会排错顺序(见 `upcomingLines` 的注释)。
66
+ *
67
+ * **消费过的句子不会出现**:`dueLine` 会把念掉的那条从槽位里删掉,所以这里是
68
+ * "还欠着的"而不是"这一段的全文"。
69
+ *
70
+ * @param {{horizonSec?:number, env?:object}} [o]
71
+ * @returns {Promise<Array<{at:number, text:string, segment:number}>>} 按 `at` 升序;
72
+ * 没在陪看 / 位置不知道时是空数组
73
+ */
74
+ export async function upcoming({ horizonSec = DEFAULT_HORIZON_SEC, env = process.env } = {}) {
75
+ const ph = readPlayhead();
76
+ if (!ph.active || !ph.input || !Number.isFinite(ph.pos)) return [];
77
+ const rows = await upcomingLines(ph.input, {
78
+ after: ph.pos,
79
+ before: ph.pos + clampHorizon(horizonSec),
80
+ env,
81
+ });
82
+ // `from` 是段首秒数(和 `due`/`scheduled` 事件里的 `segment` 同一个口径),
83
+ // 适配器按 (input, segment, text) 做预合成缓存时要靠它对上号。
84
+ return rows.map((r) => ({ at: r.at, text: r.text, segment: r.from }));
85
+ }
86
+
87
+ /** 挂到 `attach(api)` 上的那两个方法。冻结,免得适配器改掉核心的实现 */
88
+ export const companionApi = Object.freeze({ upcoming, position });
@@ -0,0 +1,75 @@
1
+ /**
2
+ * playhead.js — "现在播到第几秒"对**外部**可见的那一层。
3
+ *
4
+ * ## 为什么需要它(而不是让调用方自己读)
5
+ *
6
+ * 位置有三条来路:扩展每秒上报(`position-bridge.js`)、调试端口每 15 秒探一次
7
+ * (`watch-browser.js`)、用户自己报的 cursor。**判断哪条可信、怎么外推、什么时候
8
+ * 承认不知道**,全在 `position.js` 那套锚点逻辑里。绕过去自己读 `position.json`
9
+ * 的调用方,等于把那套规则重写一遍 —— 十有八九会写出"位置停了还在往前推"。
10
+ *
11
+ * ## 为什么不做成从 watch-loop 里直接读
12
+ *
13
+ * `watch-loop → runtime-ports → voice-adapter → companion-api`,如果
14
+ * `companion-api` 再 import `watch-loop` 就成一个环。环在 ESM 里多数时候能跑,
15
+ * 但"多数时候"不是工程约定:一旦哪天有人在 watch-loop 顶层求值点什么,就会炸在
16
+ * 某个和本次改动毫无关系的测试里。所以循环**把结论推到这个小 store**,别人只读它。
17
+ *
18
+ * 写入方只有一个(`watch-loop.js` 的 `syncPlayhead()`),读取方可以有任意多个。
19
+ */
20
+
21
+ import { estimate } from './position.js';
22
+
23
+ /** 没有陪看时的固定形状 —— 字段齐全,调用方不用到处判空 */
24
+ const IDLE = Object.freeze({
25
+ active: false, input: null, dur: null, pos: null, confidence: 'unknown', staleMs: null,
26
+ });
27
+
28
+ let state = { active: false, input: null, dur: null, anchor: null };
29
+
30
+ /**
31
+ * 循环每一拍把当前状态推过来。
32
+ *
33
+ * `anchor` 是 `position.js` 的锚点原样对象:**不要把 pos 单独传**,
34
+ * 那样"读数多久以前读的"就丢了,外推和降级全都没法算。
35
+ */
36
+ export function setPlayhead({ active = true, input = null, dur = null, anchor = null } = {}) {
37
+ state = {
38
+ active: Boolean(active),
39
+ input: input ?? null,
40
+ dur: Number.isFinite(dur) ? Number(dur) : null,
41
+ anchor: anchor ?? null,
42
+ };
43
+ }
44
+
45
+ /** 停表 / 换片时清掉,别让适配器拿着上一支片子的位置去丢音频 */
46
+ export function clearPlayhead() {
47
+ state = { active: false, input: null, dur: null, anchor: null };
48
+ }
49
+
50
+ /**
51
+ * 读当前位置。
52
+ *
53
+ * **`confidence === 'unknown'` 时 `pos` 是 `null`,不是 0。**
54
+ * 这条和仓里其它地方反复踩的 `Number(null) === 0` 是同一个坑:
55
+ * 给个 0,调用方就会算出"我合成的音频比当前位置晚了 300 秒",然后默默丢光。
56
+ * 不知道就该是不知道。
57
+ *
58
+ * @param {number} [now] 注入当前时刻(测试/仿真用虚拟时间)
59
+ * @returns {{active:boolean, input:string|null, dur:number|null,
60
+ * pos:number|null, confidence:'fresh'|'extrapolated'|'unknown', staleMs:number|null}}
61
+ */
62
+ export function readPlayhead(now = Date.now()) {
63
+ if (!state.active || !state.anchor) return { ...IDLE, input: state.input, dur: state.dur };
64
+ const est = estimate(state.anchor, now);
65
+ const dur = state.dur ?? (Number.isFinite(state.anchor.dur) ? state.anchor.dur : null);
66
+ return {
67
+ active: true,
68
+ input: state.input,
69
+ dur,
70
+ // 承认不知道时不给数字:见上面那段
71
+ pos: est.confidence === 'unknown' || !Number.isFinite(est.pos) ? null : +est.pos.toFixed(1),
72
+ confidence: est.confidence,
73
+ staleMs: Number.isFinite(est.staleMs) ? Math.round(est.staleMs) : null,
74
+ };
75
+ }
package/src/public-api.js CHANGED
@@ -16,6 +16,13 @@ export {
16
16
  export { createRecognitionInterface } from './recognition-interface.js';
17
17
  export { createTtsInterface } from './tts-interface.js';
18
18
  export { createWindowInterface } from './window-interface.js';
19
+ export {
20
+ DEFAULT_HORIZON_SEC,
21
+ MAX_HORIZON_SEC,
22
+ companionApi,
23
+ position,
24
+ upcoming,
25
+ } from './companion-api.js';
19
26
  export {
20
27
  WINDOW_PROTOCOL_VERSION,
21
28
  WINDOW_EVENT_TYPES,
@@ -11,8 +11,10 @@
11
11
  * ```
12
12
  *
13
13
  * 适配器模块导出 `attach(api)`(或 default 导出同名函数),`api` 是
14
- * `{ onSpeech, speechSubscribers, emitSpeech, emitSpoken, lastSpeech }` ——
14
+ * `{ onSpeech, speechSubscribers, emitSpeech, emitSpoken, lastSpeech, upcoming, position }` ——
15
15
  * 合成完真的要出声时调一次 `emitSpoken(e)`,展示层才知道"字可以出现了"(见 `speech-bus.js`)。
16
+ * `upcoming()` / `position()` 是**只读**的两个问题"接下来念什么 / 现在播到哪"
17
+ * (形状见 `companion-api.js`,issue #4 定的边界:核心不做合成)。
16
18
  * `attach` 可以返回一个 detach 函数;不返回也行,但要自己管好退订。
17
19
  *
18
20
  * 和 `speech-bus.js` 的分工:总线不认识"文件路径""import""配置文件",
@@ -27,6 +29,7 @@ import { pathToFileURL } from 'node:url';
27
29
  import {
28
30
  emitSpeech, emitSpoken, lastSpeech, onSpeech, speechSubscribers,
29
31
  } from './speech-bus.js';
32
+ import { companionApi } from './companion-api.js';
30
33
 
31
34
  /**
32
35
  * 已挂载的适配器:specifier → { detach, subscriptions }。
@@ -122,6 +125,10 @@ export async function loadVoiceAdapter(spec, { log = () => {} } = {}) {
122
125
  try {
123
126
  const detach = await attach(trackedApi({
124
127
  onSpeech, speechSubscribers, emitSpeech, emitSpoken, lastSpeech,
128
+ // 只读的两个问题:接下来念什么、现在播到哪。**不是**可选的装饰 ——
129
+ // 适配器靠它们决定预不预合成、seek 之后丢不丢已经合成好的音频。
130
+ upcoming: companionApi.upcoming,
131
+ position: companionApi.position,
125
132
  }, subscriptions));
126
133
  attached.set(raw, {
127
134
  detach: typeof detach === 'function' ? detach : null,
package/src/voice.js CHANGED
@@ -31,3 +31,12 @@ export {
31
31
  detachAdapters,
32
32
  loadVoiceAdapter,
33
33
  } from './voice-adapter.js';
34
+
35
+ // 适配器"拉"的那两个只读方法。平时从 `attach(api)` 拿就行;
36
+ // 导出是给测试和同进程的伴生插件直接用的(形状见 companion-api.js)。
37
+ export {
38
+ DEFAULT_HORIZON_SEC,
39
+ MAX_HORIZON_SEC,
40
+ position,
41
+ upcoming,
42
+ } from './companion-api.js';
package/src/watch-loop.js CHANGED
@@ -22,6 +22,7 @@ import { readBrowserPosition, looksLikeVideoUrl } from 'dsh-video-storyboard/bro
22
22
  import { readBridge } from './position-bridge.js';
23
23
  import { getTtsPort, getWindowPort } from './runtime-ports.js';
24
24
  import { readPositionOrNull } from './watch-browser.js';
25
+ import { clearPlayhead, setPlayhead } from './playhead.js';
25
26
 
26
27
  import { speechSeconds } from './speech.js';
27
28
  import { consumeLine, dueLine, hasLine, loadLine, upcomingLines, WATCH_LEAD } from './watch.js';
@@ -277,9 +278,27 @@ export function stopWatchLoop(reason = 'stopped') {
277
278
  if (loop.active) loop.log(`[watch] loop stopped (${reason})`);
278
279
  loop.active = false;
279
280
  loop.lastReason = reason;
281
+ // 停表之后"现在播到哪"就没有意义了。留着的话,适配器会按上一支片子的位置
282
+ // 去丢音频 / 预合成,而且 `pos` 会一直外推到 60 秒上限才降级成 unknown。
283
+ clearPlayhead();
280
284
  return loopStatus();
281
285
  }
282
286
 
287
+ /**
288
+ * 把当前锚点推给 `playhead.js`(声音适配器的 `api.position()` 读它)。
289
+ *
290
+ * **走 store 而不是让适配器 import 本模块**:`watch-loop → runtime-ports →
291
+ * voice-adapter → companion-api`,再反向 import 就成环了(见 playhead.js 文件头)。
292
+ *
293
+ * 每 2 秒一拍推一次理论上冗余,但这样"锚点变了"的每一条路径(扩展上报、CDP 探针、
294
+ * 用户自报 cursor)都自动覆盖到,不会漏掉某一条 —— 漏一条的表现是"适配器以为
295
+ * 没 seek,其实已经跳了",很难从现象反推回来。
296
+ */
297
+ function syncPlayhead() {
298
+ if (!loop.active) { clearPlayhead(); return; }
299
+ setPlayhead({ active: true, input: loop.input, dur: loop.dur, anchor: loop.anchor });
300
+ }
301
+
283
302
  /**
284
303
  * 起循环。重复调用先停旧的(同一时刻只允许一段陪看)。
285
304
  *
@@ -323,12 +342,18 @@ export function startWatchLoop({
323
342
  // 只有真的开过窗才生效(`windowGuard: true` 由 handler 在窗口就绪时传);
324
343
  // 没开窗(环境变量关掉、Python 缺失、或压根不需要插话)时为 false,不会误停。
325
344
  windowGuard = false,
326
- // **悬浮窗里的插话,永远叫得醒**(默认开)。
327
- // 用户的原话:"插话能随时插入任何一个箭头对吗" —— 阻塞等待里本来就会 polling,
328
- // 但"我思考 / 钟在后台空转"的那段时间没人听。这一项就是补那段:
329
- // 钟每一拍顺手看一眼聊天框,有新消息就真的 wake 一次(只针对**用户的插话**,
330
- // 不是段末那种"该说话了"的打扰,所以和 `wake: false` 不冲突)。
331
- wakeOnChat = true,
345
+ // 悬浮窗里的插话要不要**主动叫醒**模型。
346
+ //
347
+ // 2026-11-04 默认改成 false。原来开着是为了补"我思考 / 钟在后台空转"那段——
348
+ // 阻塞等待里本来就会 poll,但那段时间没人听。代价是:`wakeSession` 走的是宿主的
349
+ // `agent.followup()`,而 DSH 的 QueueDock **不过滤 source**,于是用户在悬浮窗
350
+ // 每打一句话,输入框上方就多一条"排队消息"。悬浮窗里明明已经有气泡显示过了,
351
+ // 队列里再来一条既是噪音、又占住输入框。
352
+ //
353
+ // 关掉之后**不会丢话**:这一段整个跳过,`chatWatcher()` 也就不消费,
354
+ // 消息留在通道里,模型下次 `watch_together` 时 poll 得到。真正的阻塞等待
355
+ // (`wait` / `nextLine`)走的是另一条路,照旧能随时打断。
356
+ wakeOnChat = false,
332
357
  // **字幕轨**:只转写、不建图,跑到"当前位置 + 余量"为止。默认开(用户要的是"字先到先给")。
333
358
  // 关掉它就退回原来的行为:字和画面一起在图那一次给。
334
359
  transcriptTrack = true,
@@ -485,6 +510,7 @@ export function startWatchLoop({
485
510
  if (Number.isFinite(cursor)) {
486
511
  loop.anchor = makeAnchor({ pos: cursor, dur: loop.dur, status, updated: Date.now() }, Date.now());
487
512
  }
513
+ syncPlayhead();
488
514
  note('resumed (same input + same batch plan)');
489
515
  return { ok: true, resumed: true, ...loopStatus() };
490
516
  }
@@ -556,6 +582,9 @@ export function startWatchLoop({
556
582
  loop.anchor = Number.isFinite(cursor)
557
583
  ? makeAnchor({ pos: cursor, dur: null, status, updated: Date.now() })
558
584
  : null;
585
+ // 新一场:哪怕还没有锚点也要先推一次 —— 适配器这时候问 `position()` 应该看到
586
+ // `active: true / pos: null`("在陪看,但位置还不知道"),而不是上一支片子的残留值。
587
+ syncPlayhead();
559
588
 
560
589
  void readLatency().then((st) => { loop.aheadSec = aheadSeconds(st); });
561
590
 
@@ -742,6 +771,9 @@ export function startWatchLoop({
742
771
  loop.aheadSec = aheadSeconds(st);
743
772
  }
744
773
 
774
+ // 这一拍的位置已经落定(桥上报 / CDP 探针都跑完了),推给适配器那边
775
+ syncPlayhead();
776
+
745
777
  if (!loop.anchor) {
746
778
  loop.lastReason = 'no-anchor';
747
779
  // 从来没读到过位置:没有锚点可变旧,只能靠这个计时器兜底。