dsh-mobile-plugin 0.5.95 → 0.5.97
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/README.md +37 -0
- package/config/agent-presets/standard/skills/dsh-mobile-kb/SKILL.md +4 -1
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/cloudflare.md +7 -6
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/jdxb.md +52 -0
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/network-guide.md +2 -1
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/zeronews.md +56 -0
- package/lib/cloudflared/runner.cjs +110 -33
- package/lib/cloudflared/wiring.cjs +17 -1
- package/lib/impl.js +23 -4
- package/lib/jdxb/probe.cjs +165 -0
- package/lib/jdxb/provision.cjs +218 -0
- package/lib/mobile/history-derive.js +18 -0
- package/lib/mobile/question-reply.js +159 -0
- package/lib/mobile/stream.js +25 -2
- package/lib/panel/index.html +26 -46
- package/lib/relay/config-store.js +64 -5
- package/lib/relay/control.js +51 -3
- package/lib/relay/core.js +21 -0
- package/lib/relay/lan-proxy.js +50 -14
- package/lib/relay/public-ip.cjs +82 -0
- package/lib/remote/host-control.cjs +19 -1
- package/lib/routes/control-plane.js +225 -23
- package/lib/routes/mobile-api.js +22 -0
- package/lib/update-install.cjs +3 -2
- package/lib/zeronews/probe.cjs +126 -0
- package/lib/zeronews/provision.cjs +128 -0
- package/lib/zeronews/runner.cjs +303 -0
- package/lib/zeronews/watcher.cjs +78 -0
- package/lib/zeronews/wiring.cjs +159 -0
- package/package.json +1 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// 读本机节点小宝设备端的状态与绑定链接,给面板「接入这条线路」用。
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 节点小宝(iepose)的设备端以系统服务方式装在本机,插件不启动、不管理它的进程 ——
|
|
6
|
+
* 它自己开机自启,死了也会自己重连。这里只做两件只读的事:问它「你装好没有、绑没绑」,
|
|
7
|
+
* 以及没绑时把它的绑定链接取出来交给面板。
|
|
8
|
+
*
|
|
9
|
+
* 为什么走宿主而不是面板直接 fetch:设备端本地管理口在回环上,面板在浏览器里跨域读它会被
|
|
10
|
+
* CORS 挡下;宿主是本机 node 进程,读回环没有跨域问题,而且这条路径本身是 localOnly 控制面。
|
|
11
|
+
*
|
|
12
|
+
* 端口是实测出来的、不是它对外的承诺:macOS 精简版 2080,Linux 安装脚本起在 9118。
|
|
13
|
+
* 两个都试,哪个先答话用哪个;都不答就是没装或没起。
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** 设备端本地管理口:按平台列候选,顺序即偏好。 */
|
|
17
|
+
const LOCAL_PORTS = { darwin: [2080], linux: [9118] };
|
|
18
|
+
/** /detect/version 是轻量探针,超时短;/bind 要等它去云端换短链,实测 5~16 秒。 */
|
|
19
|
+
const PROBE_TIMEOUT_MS = 3000;
|
|
20
|
+
const BIND_TIMEOUT_MS = 30_000;
|
|
21
|
+
|
|
22
|
+
function portsFor(platform) {
|
|
23
|
+
const key = String(platform || process.platform);
|
|
24
|
+
const list = LOCAL_PORTS[key];
|
|
25
|
+
return Array.isArray(list) ? list : [];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 问一个本地管理口要状态。返回 `{ ok, peerid, tun, workmode, error }`:
|
|
30
|
+
* `ok=false` 表示这个口没人应答(没装 / 没起 / 被别的程序占着)。
|
|
31
|
+
*/
|
|
32
|
+
async function probePort(port, options = {}) {
|
|
33
|
+
const doFetch = typeof options.fetchImpl === 'function'
|
|
34
|
+
? options.fetchImpl
|
|
35
|
+
: (typeof globalThis.fetch === 'function' ? globalThis.fetch : null);
|
|
36
|
+
if (!doFetch) return { ok: false, peerid: '', error: '当前环境没有可用的 fetch' };
|
|
37
|
+
const timeoutMs = Number(options.timeoutMs) > 0 ? Number(options.timeoutMs) : PROBE_TIMEOUT_MS;
|
|
38
|
+
const controller = typeof AbortController === 'function' ? new AbortController() : null;
|
|
39
|
+
const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : null;
|
|
40
|
+
try {
|
|
41
|
+
const response = await doFetch(`http://127.0.0.1:${port}/detect/version`, {
|
|
42
|
+
headers: { accept: 'application/json' },
|
|
43
|
+
...(controller ? { signal: controller.signal } : {}),
|
|
44
|
+
});
|
|
45
|
+
if (!response || response.ok !== true) return { ok: false, peerid: '', error: `HTTP ${response && response.status ? response.status : '?'}` };
|
|
46
|
+
const payload = await response.json();
|
|
47
|
+
// 名字对不上说明这个口是别的程序,不能因为「有个东西在 2080 上答话」就认它是节点小宝。
|
|
48
|
+
if (!payload || payload.name !== 'NodeBabyLinkService') return { ok: false, peerid: '', error: '端口上不是节点小宝' };
|
|
49
|
+
return {
|
|
50
|
+
ok: true,
|
|
51
|
+
peerid: typeof payload.peerid === 'string' ? payload.peerid : '',
|
|
52
|
+
tun: typeof payload.tun === 'string' ? payload.tun : '',
|
|
53
|
+
workmode: typeof payload.workmode === 'string' ? payload.workmode : '',
|
|
54
|
+
error: '',
|
|
55
|
+
};
|
|
56
|
+
} catch (error) {
|
|
57
|
+
const raw = error && error.message ? error.message : String(error);
|
|
58
|
+
return { ok: false, peerid: '', error: raw };
|
|
59
|
+
} finally {
|
|
60
|
+
if (timer) clearTimeout(timer);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 读本机设备端状态。
|
|
66
|
+
*
|
|
67
|
+
* @returns {Promise<{ supported: boolean, installed: boolean, bound: boolean, peerid: string,
|
|
68
|
+
* tun: string, port: number, error: string }>}
|
|
69
|
+
* `supported=false` 是这一版没接的平台(Windows 设备端没验过本地口,不乱猜);
|
|
70
|
+
* `installed=false` 表示本机找不到设备端;`bound=false` 表示装了但还没登录绑定。
|
|
71
|
+
*/
|
|
72
|
+
async function readStatus(options = {}) {
|
|
73
|
+
const platform = String(options.platform || process.platform);
|
|
74
|
+
const ports = Array.isArray(options.ports) ? options.ports : portsFor(platform);
|
|
75
|
+
if (!ports.length) {
|
|
76
|
+
return { supported: false, installed: false, bound: false, peerid: '', tun: '', port: 0, error: '这一版只接了 macOS 与 Linux 的节点小宝设备端' };
|
|
77
|
+
}
|
|
78
|
+
let lastError = '';
|
|
79
|
+
for (const port of ports) {
|
|
80
|
+
const result = await probePort(port, options);
|
|
81
|
+
if (result.ok) {
|
|
82
|
+
return {
|
|
83
|
+
supported: true,
|
|
84
|
+
installed: true,
|
|
85
|
+
bound: result.peerid !== '',
|
|
86
|
+
peerid: result.peerid,
|
|
87
|
+
tun: result.tun,
|
|
88
|
+
port,
|
|
89
|
+
error: '',
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
lastError = result.error || lastError;
|
|
93
|
+
}
|
|
94
|
+
return { supported: true, installed: false, bound: false, peerid: '', tun: '', port: 0, error: lastError };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 取设备端的绑定链接。设备端回 302 指向它的云端绑定页,把那一段 Location 原样交给面板。
|
|
99
|
+
* 已经绑过的设备不会再给链接(它回 404 或直接给已绑页面),这里按 `ok:false` 如实说明。
|
|
100
|
+
*/
|
|
101
|
+
async function readBindUrl(options = {}) {
|
|
102
|
+
const doFetch = typeof options.fetchImpl === 'function'
|
|
103
|
+
? options.fetchImpl
|
|
104
|
+
: (typeof globalThis.fetch === 'function' ? globalThis.fetch : null);
|
|
105
|
+
if (!doFetch) return { ok: false, url: '', error: '当前环境没有可用的 fetch' };
|
|
106
|
+
const port = Number(options.port) > 0 ? Number(options.port) : (portsFor(options.platform)[0] || 0);
|
|
107
|
+
if (!port) return { ok: false, url: '', error: '这一版没接这个平台' };
|
|
108
|
+
const timeoutMs = Number(options.timeoutMs) > 0 ? Number(options.timeoutMs) : BIND_TIMEOUT_MS;
|
|
109
|
+
const controller = typeof AbortController === 'function' ? new AbortController() : null;
|
|
110
|
+
const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : null;
|
|
111
|
+
try {
|
|
112
|
+
// 手动接管跳转:要的是那一跳的目标地址,不是跳过去之后的页面。
|
|
113
|
+
const response = await doFetch(`http://127.0.0.1:${port}/bind`, {
|
|
114
|
+
redirect: 'manual',
|
|
115
|
+
headers: { accept: 'text/html' },
|
|
116
|
+
...(controller ? { signal: controller.signal } : {}),
|
|
117
|
+
});
|
|
118
|
+
const location = response && response.headers && typeof response.headers.get === 'function'
|
|
119
|
+
? response.headers.get('location') : '';
|
|
120
|
+
if (typeof location === 'string' && /^https?:\/\//i.test(location.trim())) {
|
|
121
|
+
return { ok: true, url: location.trim(), error: '' };
|
|
122
|
+
}
|
|
123
|
+
return { ok: false, url: '', error: '设备端没有给出绑定链接(可能已经绑定过)' };
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (controller && controller.signal.aborted) {
|
|
126
|
+
return { ok: false, url: '', error: '向设备端要绑定链接超时,请确认它正在运行' };
|
|
127
|
+
}
|
|
128
|
+
const raw = error && error.message ? error.message : String(error);
|
|
129
|
+
return { ok: false, url: '', error: `连不上本机设备端:${raw}` };
|
|
130
|
+
} finally {
|
|
131
|
+
if (timer) clearTimeout(timer);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 把用户在面板里填的那一条归一成线路:`https://域名` 走 http 线路,`主机:端口` 走 tcp 线路。
|
|
137
|
+
*
|
|
138
|
+
* 两种都要认,因为节点小宝有「网页服务」和「TCP服务」两类;但对我们的 App 只有前者能用 ——
|
|
139
|
+
* 它的 TCP 网关会拦 HTTP 形状的流量(实测 GET/POST/HEAD/PUT/OPTIONS 全被换成一张拒绝页),
|
|
140
|
+
* 而 App 发的就是 HTTP。保留 tcp 形状是为了不把用户填的东西悄悄改掉。
|
|
141
|
+
*/
|
|
142
|
+
function lineOf(value) {
|
|
143
|
+
const raw = typeof value === 'string' ? value.trim().replace(/\/+$/, '') : '';
|
|
144
|
+
if (!raw) return null;
|
|
145
|
+
if (/^https?:\/\//i.test(raw)) {
|
|
146
|
+
try {
|
|
147
|
+
const url = new URL(raw);
|
|
148
|
+
if (!url.hostname) return null;
|
|
149
|
+
return { url: raw, transport: 'http' };
|
|
150
|
+
} catch {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const { tcpDirectTarget } = require('../relay/lan-network.cjs');
|
|
155
|
+
const target = tcpDirectTarget(raw);
|
|
156
|
+
return target ? { url: target, transport: 'tcp' } : null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
module.exports = {
|
|
160
|
+
LOCAL_PORTS,
|
|
161
|
+
lineOf,
|
|
162
|
+
probePort,
|
|
163
|
+
readStatus,
|
|
164
|
+
readBindUrl,
|
|
165
|
+
};
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// 节点小宝设备端的安装与启动:下载官方二进制、按平台装成系统服务、确保它在跑。
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 这一步跟 ZeroNews / cloudflared 最大的不同:那两个在自己目录里放个二进制就能跑,节点小宝要
|
|
6
|
+
* 装成**系统服务**——它的设备身份写在系统目录里,只有以 root 跑才存得住,否则每次重启都当新
|
|
7
|
+
* 设备(实测:普通用户跑,重启后 peerid 变空、线路全掉)。
|
|
8
|
+
*
|
|
9
|
+
* 所以这里绕不开一次管理员授权。插件能做的是把整件事自动化:自己下载、自己装、自己拉起,
|
|
10
|
+
* 用户只在系统弹出的授权框里确认一次(Touch ID / 输密码)。这是操作系统对「装系统服务」的
|
|
11
|
+
* 规矩,不是我们多要一步。
|
|
12
|
+
*
|
|
13
|
+
* 只做 macOS:它的 launchd 服务定义简单、我们也在这套上实测过。Linux 的 systemd 与 Windows
|
|
14
|
+
* 的服务注册各自还有一套没验过的细节,先如实报「这一版没接」,不猜着写。
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const { execFile } = require('node:child_process');
|
|
18
|
+
const fs = require('node:fs');
|
|
19
|
+
const os = require('node:os');
|
|
20
|
+
const path = require('node:path');
|
|
21
|
+
|
|
22
|
+
const VERSION = '4.3.5';
|
|
23
|
+
const INSTALL_DIR = '/usr/local/nblink';
|
|
24
|
+
const BINARY = path.join(INSTALL_DIR, 'NodeBabyLinkService');
|
|
25
|
+
const PLIST = '/Library/LaunchDaemons/com.iepose.NodeBabyLinkService.plist';
|
|
26
|
+
const LOG_DIR = path.join(INSTALL_DIR, 'logs');
|
|
27
|
+
const CDN = 'https://cdn.ionewu.com/upgrade/jdxb';
|
|
28
|
+
const DOWNLOAD_TIMEOUT_MS = 120_000;
|
|
29
|
+
/** 授权框等人点:给足三分钟,但别无限挂着。 */
|
|
30
|
+
const ELEVATE_TIMEOUT_MS = 180_000;
|
|
31
|
+
/** 装完等它把本地管理口听上。 */
|
|
32
|
+
const START_WAIT_MS = 15_000;
|
|
33
|
+
|
|
34
|
+
function platformKey(platform, arch) {
|
|
35
|
+
const p = String(platform || process.platform);
|
|
36
|
+
const a = String(arch || process.arch);
|
|
37
|
+
if (p !== 'darwin') return '';
|
|
38
|
+
if (a === 'arm64') return 'darwin-arm64';
|
|
39
|
+
if (a === 'x64') return 'darwin-x64';
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function downloadUrl(key) {
|
|
44
|
+
const arch = key === 'darwin-arm64' ? 'arm64' : 'amd64';
|
|
45
|
+
return `${CDN}/NodeBabyLinkService.darwin.${arch}.${VERSION}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 一个 Mach-O 可执行文件的开头;下载坏了/被挡成网页时当场认出来,别把垃圾装进系统目录。
|
|
50
|
+
* 小端与大端、32/64 位、以及 fat 包都算 —— 官方给的是小端 64 位(首字节 CF FA ED FE),
|
|
51
|
+
* 只按大端认会把真文件拒掉。
|
|
52
|
+
*/
|
|
53
|
+
const MACHO_MAGICS = new Set([0xfeedface, 0xfeedfacf, 0xcefaedfe, 0xcffaedfe, 0xcafebabe, 0xbebafeca]);
|
|
54
|
+
function looksLikeMachO(buffer) {
|
|
55
|
+
if (!buffer || buffer.length < 4) return false;
|
|
56
|
+
return MACHO_MAGICS.has(buffer.readUInt32BE(0));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** `launchctl list <label>`:加载了就有输出,没加载退出码非 0。 */
|
|
60
|
+
function serviceLoaded(options = {}) {
|
|
61
|
+
const run = typeof options.run === 'function' ? options.run : defaultRun;
|
|
62
|
+
return run('launchctl', ['list', 'com.iepose.NodeBabyLinkService'], { timeoutMs: 5000 })
|
|
63
|
+
.then((result) => result.code === 0 && /\bcom\.iepose\.NodeBabyLinkService\b/.test(result.stdout))
|
|
64
|
+
.catch(() => false);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function defaultRun(file, args, opts = {}) {
|
|
68
|
+
return new Promise((resolve) => {
|
|
69
|
+
execFile(file, args, { timeout: opts.timeoutMs || 10_000, maxBuffer: 1 << 20 }, (err, stdout, stderr) => {
|
|
70
|
+
resolve({ code: err ? (typeof err.code === 'number' ? err.code : 1) : 0, stdout: String(stdout || ''), stderr: String(stderr || '') });
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** 本机装没装:服务定义与二进制都在,才算装过(只装了一半的照实报没装)。 */
|
|
76
|
+
function installedSync() {
|
|
77
|
+
try {
|
|
78
|
+
return fs.existsSync(PLIST) && fs.existsSync(BINARY);
|
|
79
|
+
} catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function plistBody() {
|
|
85
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
86
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
87
|
+
<plist version="1.0">
|
|
88
|
+
<dict>
|
|
89
|
+
<key>Label</key>
|
|
90
|
+
<string>com.iepose.NodeBabyLinkService</string>
|
|
91
|
+
<key>ProgramArguments</key>
|
|
92
|
+
<array>
|
|
93
|
+
<string>${BINARY}</string>
|
|
94
|
+
</array>
|
|
95
|
+
<key>RunAtLoad</key>
|
|
96
|
+
<true/>
|
|
97
|
+
<key>KeepAlive</key>
|
|
98
|
+
<true/>
|
|
99
|
+
<key>StandardOutPath</key>
|
|
100
|
+
<string>${path.join(LOG_DIR, 'stdout.log')}</string>
|
|
101
|
+
<key>StandardErrorPath</key>
|
|
102
|
+
<string>${path.join(LOG_DIR, 'stderr.log')}</string>
|
|
103
|
+
</dict>
|
|
104
|
+
</plist>
|
|
105
|
+
`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 以管理员权限跑一段 shell。macOS 上就是系统自带的授权框(`do shell script ... with
|
|
110
|
+
* administrator privileges`);它会弹出 Touch ID / 密码,用户点一下确认,脚本才以 root 跑。
|
|
111
|
+
*
|
|
112
|
+
* 脚本先写到用户自己的临时目录(0700):同一个人能改的只有这一份,跨不过权限边界;写死命令
|
|
113
|
+
* 串反而要跟一堆引号打架,出错时也看不出哪一步断的。
|
|
114
|
+
*/
|
|
115
|
+
function runElevated(script, options = {}) {
|
|
116
|
+
const run = typeof options.run === 'function' ? options.run : defaultRun;
|
|
117
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-jdxb-'));
|
|
118
|
+
const file = path.join(dir, 'install.sh');
|
|
119
|
+
fs.writeFileSync(file, script, { mode: 0o700 });
|
|
120
|
+
// AppleScript 字符串里只需处理反斜杠与双引号;路径是我们自己造的,没有空格与怪字符。
|
|
121
|
+
const escaped = file.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
122
|
+
return run('osascript', ['-e', `do shell script "sh ${escaped}" with administrator privileges`], {
|
|
123
|
+
timeoutMs: options.timeoutMs || ELEVATE_TIMEOUT_MS,
|
|
124
|
+
}).finally(() => {
|
|
125
|
+
try { fs.rmSync(dir, { recursive: true, force: true }); } catch {}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 装好并拉起来。
|
|
131
|
+
*
|
|
132
|
+
* @returns {Promise<{ ok: boolean, installed: boolean, started: boolean, error: string }>}
|
|
133
|
+
* `ok=false` 时 `error` 是人能看懂的原因(下载失败 / 用户取消授权 / 服务没起来)。
|
|
134
|
+
*/
|
|
135
|
+
async function install(options = {}) {
|
|
136
|
+
const key = options.platformKey || platformKey(options.platform, options.arch);
|
|
137
|
+
if (!key) return { ok: false, installed: installedSync(), started: false, error: '这一版只接了 macOS 的自动安装' };
|
|
138
|
+
if (installedSync() && await serviceLoaded(options)) {
|
|
139
|
+
return { ok: true, installed: true, started: true, error: '' };
|
|
140
|
+
}
|
|
141
|
+
const fetchImpl = typeof options.fetchImpl === 'function' ? options.fetchImpl : globalThis.fetch;
|
|
142
|
+
if (typeof fetchImpl !== 'function') return { ok: false, installed: installedSync(), started: false, error: '当前环境没有可用的 fetch' };
|
|
143
|
+
|
|
144
|
+
let temp = '';
|
|
145
|
+
try {
|
|
146
|
+
const response = await fetchImpl(downloadUrl(key), { redirect: 'follow' });
|
|
147
|
+
if (!response || response.ok !== true) {
|
|
148
|
+
return { ok: false, installed: installedSync(), started: false, error: `下载设备端失败(HTTP ${response && response.status ? response.status : '?'})` };
|
|
149
|
+
}
|
|
150
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
151
|
+
if (!looksLikeMachO(buffer)) {
|
|
152
|
+
return { ok: false, installed: installedSync(), started: false, error: '下载到的不是可执行文件,可能被网络拦截了' };
|
|
153
|
+
}
|
|
154
|
+
temp = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-jdxb-bin-')), 'NodeBabyLinkService');
|
|
155
|
+
fs.writeFileSync(temp, buffer, { mode: 0o700 });
|
|
156
|
+
} catch (error) {
|
|
157
|
+
return { ok: false, installed: installedSync(), started: false, error: `下载设备端失败:${error && error.message ? error.message : String(error)}` };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const script = [
|
|
161
|
+
'set -e',
|
|
162
|
+
`mkdir -p '${INSTALL_DIR}' '${LOG_DIR}'`,
|
|
163
|
+
`cp '${temp}' '${BINARY}'`,
|
|
164
|
+
`chmod 755 '${BINARY}'`,
|
|
165
|
+
`cat > '${PLIST}' <<'PLIST_EOF'`,
|
|
166
|
+
plistBody(),
|
|
167
|
+
'PLIST_EOF',
|
|
168
|
+
`chmod 644 '${PLIST}'`,
|
|
169
|
+
`launchctl unload '${PLIST}' 2>/dev/null || true`,
|
|
170
|
+
`launchctl load -w '${PLIST}'`,
|
|
171
|
+
].join('\n');
|
|
172
|
+
|
|
173
|
+
const elevated = await runElevated(script, options);
|
|
174
|
+
try { fs.rmSync(path.dirname(temp), { recursive: true, force: true }); } catch {}
|
|
175
|
+
if (elevated.code !== 0) {
|
|
176
|
+
const detail = String(elevated.stderr || '').trim().split('\n').filter(Boolean).slice(-1)[0] || '';
|
|
177
|
+
// 用户点了取消时 osascript 会回 -128;这时别报「安装失败」,说清是他取消了。
|
|
178
|
+
const cancelled = /-128|User canceled/i.test(`${elevated.stderr || ''}${elevated.stdout || ''}`);
|
|
179
|
+
return {
|
|
180
|
+
ok: false,
|
|
181
|
+
installed: installedSync(),
|
|
182
|
+
started: false,
|
|
183
|
+
error: cancelled ? '授权被取消,设备端没有安装' : `安装没成功${detail ? `:${detail}` : ''}`,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// 脚本以 root 跑完了就当装上了:文件在不在不该由这个进程猜二遍(它也无权读 root 区)。
|
|
188
|
+
// 真要用得起来看的是下面这条端口应答。
|
|
189
|
+
const started = await waitForPort(options);
|
|
190
|
+
return { ok: started, installed: true, started, error: started ? '' : '设备端装好了,但本地管理口没起来,请查看系统服务状态' };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** 装完等管理口应答:`launchctl load` 返回不代表进程已经监听,别装完立刻报没起来。 */
|
|
194
|
+
async function waitForPort(options = {}) {
|
|
195
|
+
const probe = typeof options.probePort === 'function' ? options.probePort : require('./probe.cjs').probePort;
|
|
196
|
+
const port = Number(options.port) > 0 ? Number(options.port) : 2080;
|
|
197
|
+
const deadline = Date.now() + (Number(options.waitMs) > 0 ? Number(options.waitMs) : START_WAIT_MS);
|
|
198
|
+
while (Date.now() < deadline) {
|
|
199
|
+
const result = await probe(port, { timeoutMs: 1500 });
|
|
200
|
+
if (result && result.ok) return true;
|
|
201
|
+
if (typeof options.sleep === 'function') await options.sleep(500);
|
|
202
|
+
else await new Promise((resolve) => setTimeout(resolve, 500));
|
|
203
|
+
}
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
module.exports = {
|
|
208
|
+
VERSION,
|
|
209
|
+
INSTALL_DIR,
|
|
210
|
+
BINARY,
|
|
211
|
+
PLIST,
|
|
212
|
+
platformKey,
|
|
213
|
+
downloadUrl,
|
|
214
|
+
installedSync,
|
|
215
|
+
serviceLoaded,
|
|
216
|
+
install,
|
|
217
|
+
waitForPort,
|
|
218
|
+
};
|
|
@@ -48,6 +48,7 @@ const {
|
|
|
48
48
|
toolStepState,
|
|
49
49
|
} = require('./step-index.js');
|
|
50
50
|
const { deriveWorkflowRuns } = require('./workflow-runs.js');
|
|
51
|
+
const { createQuestionReplyTracker } = require('./question-reply.js');
|
|
51
52
|
|
|
52
53
|
/**
|
|
53
54
|
* 从 session.list 摘要行取会话标题(与桌面端侧栏同源,不再从 history 窗口猜):
|
|
@@ -533,6 +534,9 @@ function deriveMessages(events, sessionId, lookbackEvents) {
|
|
|
533
534
|
if (hit !== undefined) return hit;
|
|
534
535
|
}
|
|
535
536
|
const out = [];
|
|
537
|
+
// 问答累积器:`ask_user_question` 的调用先记题目、结果到达时折成一条 `question-reply` 行。
|
|
538
|
+
// 与直播(stream.js)各持一份,两边游标互不相干。
|
|
539
|
+
const questionReplies = createQuestionReplyTracker();
|
|
536
540
|
// 预扫描 tool/result 事件(同批次事件内,结果可能在调用块之前/之后出现)。
|
|
537
541
|
// `lookbackEvents` 是这一页**再往前**的一小段:倒着分页时工具结果常常落在比消息更早的位置
|
|
538
542
|
// (一轮里先跑工具、最后才写正文),只看这一页就看不出这一轮出过哪些图。
|
|
@@ -719,6 +723,9 @@ function deriveMessages(events, sessionId, lookbackEvents) {
|
|
|
719
723
|
return;
|
|
720
724
|
}
|
|
721
725
|
if (raw.type !== 'tool-call') return;
|
|
726
|
+
// `ask_user_question` 不进球过程:它答完会落成一条「问 + 答」气泡(见 question-reply.js),
|
|
727
|
+
// 再留一行空摘要的工具步骤只是同一次提问被画两遍。
|
|
728
|
+
if (raw.name === 'ask_user_question') return;
|
|
722
729
|
const callId = raw.id != null ? String(raw.id) : undefined;
|
|
723
730
|
const result = callId ? toolResults.get(callId) : undefined;
|
|
724
731
|
const rawArgs = typeof raw.arguments === 'string'
|
|
@@ -864,6 +871,17 @@ function deriveMessages(events, sessionId, lookbackEvents) {
|
|
|
864
871
|
const e = entry.event || entry;
|
|
865
872
|
const seq = e.seq;
|
|
866
873
|
const time = e.time;
|
|
874
|
+
// 问答派生:`ask_user_question` 的调用先记题目、结果到达时吐一条 `question-reply` 行。
|
|
875
|
+
// `tool/call` / `tool/result` 其余情况此前整条忽略,`assistant/message` 还要继续走下面的
|
|
876
|
+
// 消息折叠,所以只有前两种吃 `continue`。
|
|
877
|
+
if (e.type === 'tool/call' || e.type === 'tool/result') {
|
|
878
|
+
const reply = questionReplies.note(e);
|
|
879
|
+
if (reply) out.push(reply);
|
|
880
|
+
continue;
|
|
881
|
+
}
|
|
882
|
+
if (e.type === 'assistant/message' && e.data && e.data.message) {
|
|
883
|
+
questionReplies.note(e);
|
|
884
|
+
}
|
|
867
885
|
// 工作流那四类事件不在这里就地折:攒起来整窗看(见 `workflowEntries`)。
|
|
868
886
|
if (typeof e.type === 'string' && e.type.startsWith('tool-workflow/')) {
|
|
869
887
|
workflowEntries.push(entry.event ? entry : { event: e });
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `ask_user_question` 的问答派生(历史与直播共用这一份)。
|
|
5
|
+
*
|
|
6
|
+
* 桌面那边由 `dsh-client-ui-user-questions` 的 `answeredQuestionDefinition` 把「问 + 答」
|
|
7
|
+
* 折成一条右对齐的用户气泡(`QuestionReplyView`):每道题在上、用户给的答案在下,跳过显示
|
|
8
|
+
* 「已跳过」。手机此前只把提问卡收掉,对话记录里看不到用户选了什么 —— 这里补上同一件事。
|
|
9
|
+
*
|
|
10
|
+
* 只认 `ask_user_question` 的调用与其结果**成对**出现:
|
|
11
|
+
* - 计划评审(`intent.kind === 'plan-review'`)不是普通选择题,走它自己的接管卡,这里不出气泡;
|
|
12
|
+
* - pending(限时提问还没答)/ 失败 / 题数对不上 / 畸形的结果都不算,交回通用工具行;
|
|
13
|
+
* - 题里任一题带 plan-review、或没有题,整批都不出(与桌面 `callQuestions` 同口径)。
|
|
14
|
+
*
|
|
15
|
+
* 状态按 callId 记:调用先到、结果后到时才能把题目和答案配起来。历史与直播各持一份,
|
|
16
|
+
* 因为两边的游标互不相干(见 `history-derive.js` 与 `stream.js`)。
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** 计划评审的 intent.kind,出现在任一题里就不当普通提问。 */
|
|
20
|
+
const PLAN_REVIEW = 'plan-review';
|
|
21
|
+
|
|
22
|
+
function isRecord(value) {
|
|
23
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function parseJsonRecord(text) {
|
|
27
|
+
try {
|
|
28
|
+
const value = JSON.parse(text);
|
|
29
|
+
return isRecord(value) ? value : null;
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 从调用参数解析题目;解析失败 / 无题 / 有题带 plan-review intent 时返回 null。
|
|
37
|
+
*
|
|
38
|
+
* `arguments` 既可能是 JSON 原文,也可能是已解析对象(PTC / 合成事件两种形状都见过)。
|
|
39
|
+
*/
|
|
40
|
+
function questionsOf(args) {
|
|
41
|
+
const value = typeof args === 'string' ? parseJsonRecord(args) : (isRecord(args) ? args : null);
|
|
42
|
+
if (!value || !Array.isArray(value.questions) || value.questions.length === 0) return null;
|
|
43
|
+
const ids = new Set();
|
|
44
|
+
const questions = [];
|
|
45
|
+
for (const question of value.questions) {
|
|
46
|
+
if (!isRecord(question) || typeof question.id !== 'string' || typeof question.question !== 'string') return null;
|
|
47
|
+
if (ids.has(question.id)) return null;
|
|
48
|
+
if (isRecord(question.intent) && question.intent.kind === PLAN_REVIEW) return null;
|
|
49
|
+
ids.add(question.id);
|
|
50
|
+
questions.push({
|
|
51
|
+
id: question.id,
|
|
52
|
+
question: question.question,
|
|
53
|
+
...(typeof question.header === 'string' && question.header ? { header: question.header } : {}),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return questions;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 从工具结果解析答案批次;pending / 失败 / 题数对不上 / 畸形返回 null。
|
|
61
|
+
*
|
|
62
|
+
* 结果正文是宿主塞给模型的那段 JSON:`{"answers":[{"id","selected","custom"?}]}`。
|
|
63
|
+
*/
|
|
64
|
+
function answersOf(resultMessage, questions) {
|
|
65
|
+
if (!isRecord(resultMessage) || resultMessage.isError === true) return null;
|
|
66
|
+
const content = resultMessage.content;
|
|
67
|
+
if (!Array.isArray(content) || content.length !== 1) return null;
|
|
68
|
+
const block = content[0];
|
|
69
|
+
if (!isRecord(block) || block.type !== 'text' || typeof block.text !== 'string') return null;
|
|
70
|
+
const value = parseJsonRecord(block.text);
|
|
71
|
+
if (!value || value.pending === true || !Array.isArray(value.answers)) return null;
|
|
72
|
+
if (value.answers.length !== questions.length) return null;
|
|
73
|
+
const ids = new Set(questions.map((question) => question.id));
|
|
74
|
+
const answers = [];
|
|
75
|
+
for (const answer of value.answers) {
|
|
76
|
+
if (!isRecord(answer) || typeof answer.id !== 'string' || !ids.delete(answer.id)) return null;
|
|
77
|
+
if (!Array.isArray(answer.selected) || !answer.selected.every((label) => typeof label === 'string')) return null;
|
|
78
|
+
if (answer.custom !== undefined && typeof answer.custom !== 'string') return null;
|
|
79
|
+
answers.push({
|
|
80
|
+
id: answer.id,
|
|
81
|
+
selected: [...answer.selected],
|
|
82
|
+
...(answer.custom === undefined ? {} : { custom: answer.custom }),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return answers;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** 从工具结果事件取 callId(两种宿主形状:`message.source.callId` / `message.toolCallId`)。 */
|
|
89
|
+
function callIdOfResult(data) {
|
|
90
|
+
const message = data && data.message;
|
|
91
|
+
if (!isRecord(message)) return '';
|
|
92
|
+
const source = message.source;
|
|
93
|
+
if (isRecord(source) && source.callId != null) return String(source.callId);
|
|
94
|
+
return message.toolCallId != null ? String(message.toolCallId) : '';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 建一份问答累积器。`note(event)` 喂原始会话事件:
|
|
99
|
+
* - `tool/call` / `assistant/message` 里的 `ask_user_question` 调用 → 记下题目,返回 null;
|
|
100
|
+
* - 对应的 `tool/result` 且答案合法 → 吐出结构化行(`kind:'question-reply'`),否则 null。
|
|
101
|
+
*
|
|
102
|
+
* 返回的行形状对齐 App 的 `ChatMessage`(`text` 空串、内容全在 `questionReply` 上)。
|
|
103
|
+
*/
|
|
104
|
+
function createQuestionReplyTracker() {
|
|
105
|
+
/** callId → 题目数组。 */
|
|
106
|
+
const questionsByCall = new Map();
|
|
107
|
+
|
|
108
|
+
const rememberCall = (callId, args) => {
|
|
109
|
+
if (!callId) return;
|
|
110
|
+
const questions = questionsOf(args);
|
|
111
|
+
if (questions) questionsByCall.set(callId, questions);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
function note(event) {
|
|
115
|
+
if (!event || typeof event.type !== 'string') return null;
|
|
116
|
+
|
|
117
|
+
if (event.type === 'tool/call') {
|
|
118
|
+
const data = event.data;
|
|
119
|
+
if (!isRecord(data) || data.name !== 'ask_user_question') return null;
|
|
120
|
+
rememberCall(data.callId != null ? String(data.callId) : '', data.arguments);
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (event.type === 'assistant/message') {
|
|
125
|
+
const message = event.data && event.data.message;
|
|
126
|
+
if (!isRecord(message) || !Array.isArray(message.content)) return null;
|
|
127
|
+
for (const block of message.content) {
|
|
128
|
+
if (!isRecord(block) || block.type !== 'tool-call' || block.name !== 'ask_user_question') continue;
|
|
129
|
+
rememberCall(block.id != null ? String(block.id) : '', block.arguments);
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (event.type !== 'tool/result') return null;
|
|
135
|
+
const data = event.data;
|
|
136
|
+
const callId = callIdOfResult(data);
|
|
137
|
+
const questions = callId ? questionsByCall.get(callId) : undefined;
|
|
138
|
+
if (!questions) return null;
|
|
139
|
+
const answers = answersOf(data.message, questions);
|
|
140
|
+
if (!answers) return null;
|
|
141
|
+
questionsByCall.delete(callId);
|
|
142
|
+
return {
|
|
143
|
+
id: `question-reply-${callId}`,
|
|
144
|
+
kind: 'question-reply',
|
|
145
|
+
text: '',
|
|
146
|
+
questionReply: { callId, questions, answers },
|
|
147
|
+
seq: Number.isSafeInteger(event.seq) ? event.seq : 0,
|
|
148
|
+
time: typeof event.time === 'number' ? event.time : 0,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return { note };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
module.exports = {
|
|
156
|
+
createQuestionReplyTracker,
|
|
157
|
+
questionsOf,
|
|
158
|
+
answersOf,
|
|
159
|
+
};
|
package/lib/mobile/stream.js
CHANGED
|
@@ -43,6 +43,7 @@ const { callSessions } = require('./rpc.js');
|
|
|
43
43
|
const { unwrap } = require('./envelope.js');
|
|
44
44
|
const { normalizeJobs } = require('./jobs.js');
|
|
45
45
|
const { cutEvent, createToolNameIndex } = require('./wire-cut.js');
|
|
46
|
+
const { createQuestionReplyTracker } = require('./question-reply.js');
|
|
46
47
|
const { createPresentedStats } = require('./presented-file-stats.js');
|
|
47
48
|
const { noteLiveEvent, drainLiveSteps, liveStepsOf, liveStepsTurnOf, liveTurnFactsOf, drainLiveTurnFacts, seedLiveTurnFacts, claimLiveWriter, releaseLiveWriter, attachLiveSteps, broadcastLiveSteps } = require('./live-steps.js');
|
|
48
49
|
const { readTurnEvents } = require('./session-changes.js');
|
|
@@ -519,6 +520,9 @@ async function handleStream(ctx, req, res) {
|
|
|
519
520
|
const imageBudget = createTextImageBudget();
|
|
520
521
|
// 过程明细的减法(wire-cut.js)与它要的工具名索引:整条流共用一份,回放与实时帧都往里吸。
|
|
521
522
|
const toolNames = createToolNameIndex();
|
|
523
|
+
// 问答派生:`ask_user_question` 的调用与结果在减法之前先过一遍,折出「问 + 答」行推给手机
|
|
524
|
+
// (见 question-reply.js)。回放与实时帧共用同一份,断线续传也能把这一行补回来。
|
|
525
|
+
const questionReplies = createQuestionReplyTracker();
|
|
522
526
|
/**
|
|
523
527
|
* 跑着那一轮的过程清单一发(`session/live-steps`)。
|
|
524
528
|
*
|
|
@@ -564,7 +568,7 @@ async function handleStream(ctx, req, res) {
|
|
|
564
568
|
|
|
565
569
|
// 断线续传:回放 history 中 seq > resumeSeq 的事件(收敛状态)。
|
|
566
570
|
if (resumeSeq != null && resumeSeq > 0) {
|
|
567
|
-
const replay = await replaySince(ctx, sessionId, resumeSeq, res, ac.signal, (seq) => { lastDeliveredSeq = Math.max(lastDeliveredSeq, seq); }, streamAddress, sealFrame, imageBudget, toolNames, presentedStats, liveWriterId);
|
|
571
|
+
const replay = await replaySince(ctx, sessionId, resumeSeq, res, ac.signal, (seq) => { lastDeliveredSeq = Math.max(lastDeliveredSeq, seq); }, streamAddress, sealFrame, imageBudget, toolNames, presentedStats, liveWriterId, questionReplies);
|
|
568
572
|
if (replay.gap && !ac.signal.aborted) {
|
|
569
573
|
const value = { type: 'session/resync-required', sessionId, resumeSeq, oldestSeq: replay.oldestSeq };
|
|
570
574
|
// 旧实现在这里直接 `return`:既不清 keepAlive 也不 end,漏出一条永不收尾的连接。
|
|
@@ -644,6 +648,15 @@ async function handleStream(ctx, req, res) {
|
|
|
644
648
|
// 过程副本:推理正文与工具参数不上线路,但用户点开「正在读取文件」那一步时要
|
|
645
649
|
// 就地答得出来(落盘之前宿主的历史里还没有这一份,见 live-steps.js)。
|
|
646
650
|
noteLiveEvent(ctx, sessionId, event, liveWriterId);
|
|
651
|
+
// 问答派生要在 `cutEvent` 之前:工具参数与结果正文都不上线路,只能在电脑侧折成
|
|
652
|
+
// 一条 `question-reply` 行推给手机(见 question-reply.js)。
|
|
653
|
+
{
|
|
654
|
+
const replyItem = questionReplies.note(event);
|
|
655
|
+
if (replyItem) {
|
|
656
|
+
const value = { type: 'session/question-reply', sessionId, item: replyItem };
|
|
657
|
+
if (await pushOrdered(value, null) === 'closed') { clientGone = true; break; }
|
|
658
|
+
}
|
|
659
|
+
}
|
|
647
660
|
const facts = event.type === 'turn/start' ? null : drainLiveTurnFacts(ctx, sessionId, liveWriterId);
|
|
648
661
|
if (facts) {
|
|
649
662
|
const value = { type: 'session/turn-facts', sessionId, ...facts };
|
|
@@ -780,7 +793,7 @@ async function handleStream(ctx, req, res) {
|
|
|
780
793
|
* 从会话 history 回放 seq > sinceSeq 的事件(升序),逐个经附件解析后写 SSE。
|
|
781
794
|
* 通过 onDelivered(seq) 回报已交付的最大 seq,供上层去重。
|
|
782
795
|
*/
|
|
783
|
-
async function replaySince(ctx, sessionId, sinceSeq, res, signal, onDelivered, address, sealFrame = null, imageBudget = null, toolNames = null, presentedStats = null, liveWriterId) {
|
|
796
|
+
async function replaySince(ctx, sessionId, sinceSeq, res, signal, onDelivered, address, sealFrame = null, imageBudget = null, toolNames = null, presentedStats = null, liveWriterId, questionReplies = null) {
|
|
784
797
|
try {
|
|
785
798
|
// 子会话的重放也要带父会话(同 historyAddress 的口径),否则宿主回 agent-busy,
|
|
786
799
|
// 这条断线续传静默退化成「后面缺一段」。
|
|
@@ -828,6 +841,8 @@ async function replaySince(ctx, sessionId, sinceSeq, res, signal, onDelivered, a
|
|
|
828
841
|
// 漏掉的事件重走一遍,顺手折回去最省事(turn/start 的重置也照直播的口径生效)。
|
|
829
842
|
if (typeof e.type === 'string' && e.type.startsWith('tool-workflow/')) noteWorkflowEvent(ctx, sessionId, e);
|
|
830
843
|
const resolved = await resolveEventAttachments(ctx, sessionId, e, { referencesOnly: true });
|
|
844
|
+
// 问答派生要在减之前喂原始事件(参数与结果正文不上线路,见 question-reply.js)。
|
|
845
|
+
const replyItem = questionReplies ? questionReplies.note(resolved) : null;
|
|
831
846
|
let event = cutEvent(resolved, toolNames);
|
|
832
847
|
// 回放与直播同一副眼镜:整条不上线路的事件这里也跳过(见 wire-cut.js)。
|
|
833
848
|
if (!event) continue;
|
|
@@ -844,6 +859,14 @@ async function replaySince(ctx, sessionId, sinceSeq, res, signal, onDelivered, a
|
|
|
844
859
|
// 回放是「一次性灌几千条」,最容易把写队列撑爆:写不动就在这里等,别一口气塞完。
|
|
845
860
|
if (sent.needDrain && !(await waitForDrain(res, signal))) break;
|
|
846
861
|
if (Number.isFinite(event.seq)) onDelivered(event.seq);
|
|
862
|
+
// 这一事件折出的问答行单独补一帧:手机端把它并进消息列表(同 id 幂等去重)。
|
|
863
|
+
if (replyItem) {
|
|
864
|
+
const value = { type: 'session/question-reply', sessionId, item: replyItem };
|
|
865
|
+
const replySent = writeSse(res, value, { payload: value }, { burst: true, sealFrame });
|
|
866
|
+
if (!replySent.ok) break;
|
|
867
|
+
written += (replySent.bytes ?? 0);
|
|
868
|
+
if (replySent.needDrain && !(await waitForDrain(res, signal))) break;
|
|
869
|
+
}
|
|
847
870
|
// 字节到顶也一样:剩下的交给分页历史,别再灌。**但必须把缺口报出去** —— 只发前缀
|
|
848
871
|
// 而不说话,客户端会以为这一段就是全部,接着实时流往下走(它只按 seq 去重、不查跳跃),
|
|
849
872
|
// 缺掉的那一截永远不会被补。与 `gap` 同一个出口,上层据此发 resync。
|