dsh-mobile-plugin 0.5.135 → 0.5.137
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/config/agent-presets/standard/skills/dsh-mobile-kb/references/zeronews.md +1 -1
- package/lib/cloudflared/runner.cjs +10 -5
- package/lib/cloudflared/wiring.cjs +10 -9
- package/lib/impl.js +1 -1
- package/lib/mobile/approval-facts.js +12 -0
- package/lib/mobile/patch-files.js +46 -0
- package/lib/mobile/step-index.js +7 -0
- package/lib/panel/index.html +4 -4
- package/lib/relay/pairing-check.cjs +9 -1
- package/lib/shared/route-order.cjs +21 -2
- package/lib/zeronews/account.cjs +45 -6
- package/lib/zeronews/provision.cjs +78 -3
- package/lib/zeronews/purge.cjs +3 -1
- package/lib/zeronews/runner.cjs +82 -12
- package/lib/zeronews/upgrade.cjs +260 -0
- package/lib/zeronews/watcher.cjs +2 -2
- package/lib/zeronews/wiring.cjs +183 -13
- package/package.json +14 -15
|
@@ -34,7 +34,7 @@ token 只进一次本机客户端配置,面板不留存、不显示;之后
|
|
|
34
34
|
- **一直停在安装/连接中**:多半是下载官方客户端慢或网络不通。第一次慢属正常,超过一分钟没动静再查网络,别催用户重装。
|
|
35
35
|
- **连接失败,提示 AuthToken 写入失败**:token 没复制完整(少字符、带了空格)。回「快速开始」页重新复制整串;还不行就换「浏览器登录」那条老路。
|
|
36
36
|
- **提示等待浏览器确认超时**:浏览器那条路等了 5 分钟没等到登录,让用户改走 AuthToken 那条。
|
|
37
|
-
-
|
|
37
|
+
- **提示客户端已连上但没拿到隧道地址**:先看概览卡的「最近心跳」和「在线设备」——心跳是空的、在线设备 0,说明本机客户端还没真正连上云端,这种情况先到本页「彻底清理」从头接入一次,往往重登就好了(换过节点、或老身份失效时常见);别一上来就按额度满处理。心跳正常、在线设备也在,仍拿不到地址,再去 ZeroNews 控制台看是不是免费额度已经占满了(只有一条),把旧隧道删掉再试。刚接入的先等一会儿再点连接。
|
|
38
38
|
- **提示客户端意外退出**:插件会自己安排重连,等它退避重试即可;连续失败再查网络。
|
|
39
39
|
- **面板显示已连接、手机里没有这条线路**:地址要等下一轮心跳才到手机(通常几十秒),让手机切回 App 前台或重连一次;另外确认电脑这侧没关掉地址上报。
|
|
40
40
|
- **面板显示未连接、地址也空了**:那是断开后的正常状态,不是掉线;要恢复就点「连接」,不需要再粘 token。
|
|
@@ -184,6 +184,7 @@ function createCloudflaredRunner(options = {}) {
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
async function launch() {
|
|
187
|
+
if (!desired || exists(paths.disabled)) return status();
|
|
187
188
|
if (child) return status();
|
|
188
189
|
if (starting) { await starting; return status(); }
|
|
189
190
|
const token = ++generation;
|
|
@@ -194,7 +195,7 @@ function createCloudflaredRunner(options = {}) {
|
|
|
194
195
|
let got;
|
|
195
196
|
try { got = await ensure({}); }
|
|
196
197
|
catch (err) { got = { ok: false, message: err && err.message ? err.message : String(err) }; }
|
|
197
|
-
if (!desired || generation !== token) return;
|
|
198
|
+
if (!desired || generation !== token || exists(paths.disabled)) return;
|
|
198
199
|
// ensureCloudflared 成功时回 { path, version, source }(没有 ok 字段),失败才抛错;
|
|
199
200
|
// 这里按「有没有 path」判成功,兼容注入的假实现回 { ok:true, path } 的写法。
|
|
200
201
|
if (!got || !got.path) {
|
|
@@ -325,9 +326,13 @@ function createCloudflaredRunner(options = {}) {
|
|
|
325
326
|
return status();
|
|
326
327
|
}
|
|
327
328
|
|
|
328
|
-
|
|
329
|
+
// 默认仍是手动操作;自动调用须保留用户的关闭标记。
|
|
330
|
+
async function start({ userInitiated = true } = {}) {
|
|
331
|
+
if (!userInitiated && exists(paths.disabled)) return status();
|
|
329
332
|
if (!desired) { desired = true; retries = 0; }
|
|
330
|
-
|
|
333
|
+
if (userInitiated) {
|
|
334
|
+
try { removeDisabled(); } catch (err) { error = `记录启用状态失败:${err && err.message ? err.message : err}`; }
|
|
335
|
+
}
|
|
331
336
|
if (retryTimer !== null) { clearTimer(retryTimer); retryTimer = null; }
|
|
332
337
|
return launch();
|
|
333
338
|
}
|
|
@@ -361,13 +366,13 @@ function createCloudflaredRunner(options = {}) {
|
|
|
361
366
|
return launch();
|
|
362
367
|
}
|
|
363
368
|
|
|
364
|
-
async function stop() {
|
|
369
|
+
async function stop({ userInitiated = true } = {}) {
|
|
365
370
|
desired = false;
|
|
366
371
|
stopProcess();
|
|
367
372
|
requestedLocalPort = 0;
|
|
368
373
|
waitingForPort = false;
|
|
369
374
|
// 显式关掉:写关闭标记落盘,下次宿主启动不再自动拉起。
|
|
370
|
-
writeDisabled();
|
|
375
|
+
if (userInitiated) writeDisabled();
|
|
371
376
|
return status();
|
|
372
377
|
}
|
|
373
378
|
|
|
@@ -92,10 +92,10 @@ function mountCloudflare(options) {
|
|
|
92
92
|
catch (error) { warn('还原手填直连地址失败:%s', error && error.message ? error.message : error); }
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
//
|
|
95
|
+
// 控制面开关默认是手动操作;自动启停不改用户的关闭标记。
|
|
96
96
|
// 任何一步出错都不许把异常抛回调用方(会变成面板 500 / 甚至未捕获拒绝),只记日志并把状态交回去。
|
|
97
|
-
const start = async () => {
|
|
98
|
-
try { await runner.start(); }
|
|
97
|
+
const start = async ({ userInitiated = true } = {}) => {
|
|
98
|
+
try { await runner.start({ userInitiated }); }
|
|
99
99
|
catch (error) { warn('启动 Cloudflare 隧道失败:%s', error && error.message ? error.message : error); }
|
|
100
100
|
return runner.status();
|
|
101
101
|
};
|
|
@@ -105,8 +105,8 @@ function mountCloudflare(options) {
|
|
|
105
105
|
try { await settings.update({ cloudflareUrl: '' }); }
|
|
106
106
|
catch (error) { warn('撤掉 Cloudflare 地址失败:%s', error && error.message ? error.message : error); }
|
|
107
107
|
};
|
|
108
|
-
const stop = async () => {
|
|
109
|
-
try { await runner.stop(); }
|
|
108
|
+
const stop = async ({ userInitiated = true } = {}) => {
|
|
109
|
+
try { await runner.stop({ userInitiated }); }
|
|
110
110
|
catch (error) { warn('停止 Cloudflare 隧道失败:%s', error && error.message ? error.message : error); }
|
|
111
111
|
// runner 停进程时会走「地址撤回」,这里再兜一次:面板回包里也不能留旧地址。
|
|
112
112
|
await clearAddress();
|
|
@@ -124,6 +124,7 @@ function mountCloudflare(options) {
|
|
|
124
124
|
// 上一次 reconcile 时的协议族策略:变了就重启正在跑的 cloudflared,让 --edge-ip-version 生效。
|
|
125
125
|
let lastIpVersionPolicy = null;
|
|
126
126
|
const reconcile = async (initial = false) => {
|
|
127
|
+
if (!runner.shouldAutoStart()) return runner.status();
|
|
127
128
|
const policy = state.ipVersionPolicy || 'auto';
|
|
128
129
|
if (lastIpVersionPolicy !== null && policy !== lastIpVersionPolicy && typeof runner.restartForPolicy === 'function') {
|
|
129
130
|
const now = status();
|
|
@@ -134,16 +135,16 @@ function mountCloudflare(options) {
|
|
|
134
135
|
if (shouldFallback()) {
|
|
135
136
|
if (!fallbackOn) { await rememberManual(); fallbackOn = true; }
|
|
136
137
|
const now = status();
|
|
137
|
-
if (!now.running && !now.starting) await start();
|
|
138
|
+
if (!now.running && !now.starting) await start({ userInitiated: false });
|
|
138
139
|
// 判定落地后纠偏落点:隧道可能在回环判定出来之前就按 lanPort 起了,此时专属入口已就绪,
|
|
139
140
|
// 但进程仍指着被遮蔽的旧端口。syncLocalPort 幂等,端口没变就不会真重启。
|
|
140
141
|
else if (now.running) await syncLocalPort();
|
|
141
142
|
} else if (fallbackOn) {
|
|
142
143
|
fallbackOn = false;
|
|
143
|
-
await stop();
|
|
144
|
+
await stop({ userInitiated: false });
|
|
144
145
|
} else if (initial && !routeAvailable() && runner.shouldAutoStart()) {
|
|
145
146
|
const now = status();
|
|
146
|
-
if (!now.running && !now.starting) await start();
|
|
147
|
+
if (!now.running && !now.starting) await start({ userInitiated: false });
|
|
147
148
|
} else if (!initial) {
|
|
148
149
|
await restoreManual();
|
|
149
150
|
}
|
|
@@ -171,7 +172,7 @@ function mountCloudflare(options) {
|
|
|
171
172
|
if (!(host && host.runner)) {
|
|
172
173
|
mount('cloudflare 隧道进程', () => ctx.effect(() => {
|
|
173
174
|
if (hasGate) void reconcile(true).catch(error => warn('自动判定 Cloudflare 兜底失败:%s', error && error.message ? error.message : error));
|
|
174
|
-
else if (runner.shouldAutoStart()) Promise.resolve(runner.start()).catch((error) => warn('自动启动 Cloudflare 隧道失败:%s', error && error.message ? error.message : error));
|
|
175
|
+
else if (runner.shouldAutoStart()) Promise.resolve(runner.start({ userInitiated: false })).catch((error) => warn('自动启动 Cloudflare 隧道失败:%s', error && error.message ? error.message : error));
|
|
175
176
|
return () => { void runner.dispose(); void restoreManual(); };
|
|
176
177
|
}, `${name}: cloudflare runner`));
|
|
177
178
|
}
|
package/lib/impl.js
CHANGED
|
@@ -433,7 +433,7 @@ function apply(ctx) {
|
|
|
433
433
|
// iOS / APNs 推送出口(完成/失败 + 审批/提问卡):直接请求总控,中转不再管推送。
|
|
434
434
|
// 鉴权用本机那枚总控设备令牌;还没拿到令牌(没连过总控)就不发,下次收尾再试。
|
|
435
435
|
pushNotify = createPushNotifier({
|
|
436
|
-
controlTarget: () => (state.controlToken && state.instanceId
|
|
436
|
+
controlTarget: () => (state.controlReportEnabled !== false && state.controlToken && state.instanceId
|
|
437
437
|
? { baseUrl: CONTROL_BASE_URL, token: state.controlToken, instanceId: state.instanceId }
|
|
438
438
|
: null),
|
|
439
439
|
workspaceIdOf: ({ sessionId }) => require('./mobile/workspace-id.js').workspaceIdOf(ctx, { sessionId }),
|
|
@@ -23,6 +23,9 @@ const MAX_TARGETS = 3;
|
|
|
23
23
|
/** 一条事实最多几个分句。 */
|
|
24
24
|
const MAX_CLAUSES = 3;
|
|
25
25
|
|
|
26
|
+
/** `apply_patch` 的路径要从补丁头里读,参数里没有单个 `file_path`。 */
|
|
27
|
+
const { patchFilePaths } = require('./patch-files.js');
|
|
28
|
+
|
|
26
29
|
/** 删除类程序:高亮。 */
|
|
27
30
|
const DELETE_PROGS = new Set(['rm', 'rmdir', 'unlink', 'shred']);
|
|
28
31
|
/**
|
|
@@ -295,6 +298,15 @@ function callToPiece(toolName, args) {
|
|
|
295
298
|
return { clause: `改 ${baseOf(p)}`, highlight: false, classKey: `${name}:${d}` };
|
|
296
299
|
}
|
|
297
300
|
|
|
301
|
+
if (name === 'apply_patch') {
|
|
302
|
+
const paths = patchFilePaths(isRecord(args) ? args.input : '');
|
|
303
|
+
if (paths.length === 0) return { clause: '', highlight: false, classKey: 'tool:apply_patch' };
|
|
304
|
+
const head = baseOf(paths[0]);
|
|
305
|
+
const d = dirKeyOf(paths[0], opts.cwd);
|
|
306
|
+
const clause = paths.length === 1 ? `改 ${head}` : `改 ${head} 等 ${paths.length} 个文件`;
|
|
307
|
+
return { clause, highlight: false, classKey: `apply_patch:${d}` };
|
|
308
|
+
}
|
|
309
|
+
|
|
298
310
|
if (name === 'read' || name === 'read_image') {
|
|
299
311
|
const p = pathOf(args);
|
|
300
312
|
if (!p) return { clause: '', highlight: false, classKey: `tool:${name}` };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `apply_patch` 的补丁正文 → 这次要改哪些文件。
|
|
5
|
+
*
|
|
6
|
+
* 宿主从 0.2.3 起把 `apply_patch` 默认摆到模型面前:一次调用能改好几个文件,路径写在补丁头
|
|
7
|
+
* 里(`*** Add File:` / `*** Update File:` / `*** Move to:`),参数里没有 `file_path`。手机
|
|
8
|
+
* 这边凡是「按路径说话」的地方(步骤摘要、审批卡的类别键)都得从补丁正文里读,否则那一行
|
|
9
|
+
* 只剩工具名。
|
|
10
|
+
*
|
|
11
|
+
* 规矩:删文件不算产出(点开也没有东西可看),移动只留落点(源文件已经没了)。路径相对会话
|
|
12
|
+
* 工作目录,显示前由调用方自己取最后一段。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** 补丁头里那三种会留下文件的写法;`*** Update File:` 可能跟着 `*** Move to:` 改落点。 */
|
|
16
|
+
const FILE_HEADER = /^\*\*\* (?:Add|Update) File:\s*(.+)$/;
|
|
17
|
+
const MOVE_HEADER = /^\*\*\* Move to:\s*(.+)$/;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {unknown} patch 补丁正文(`apply_patch` 的 `input`)。
|
|
21
|
+
* @returns {string[]} 去重后的路径,按补丁里的出现顺序。
|
|
22
|
+
*/
|
|
23
|
+
function patchFilePaths(patch) {
|
|
24
|
+
if (typeof patch !== 'string' || patch === '') return [];
|
|
25
|
+
const out = [];
|
|
26
|
+
/** 上一行落下的是不是「可能被 Move to 改掉的更新目标」。 */
|
|
27
|
+
let movable = false;
|
|
28
|
+
for (const raw of patch.split(/\r?\n/)) {
|
|
29
|
+
const line = raw.trim();
|
|
30
|
+
const file = FILE_HEADER.exec(line);
|
|
31
|
+
if (file) {
|
|
32
|
+
out.push(file[1].trim());
|
|
33
|
+
movable = line.startsWith('*** Update');
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const move = MOVE_HEADER.exec(line);
|
|
37
|
+
if (move) {
|
|
38
|
+
if (movable && out.length > 0) out.pop();
|
|
39
|
+
out.push(move[1].trim());
|
|
40
|
+
movable = false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return [...new Set(out.filter(Boolean))];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = { patchFilePaths };
|
package/lib/mobile/step-index.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
const { toolResultState } = require('./tool-result-state.js');
|
|
13
|
+
const { patchFilePaths } = require('./patch-files.js');
|
|
13
14
|
|
|
14
15
|
/** 一步摘要的字数上限:清单是一行省略,再长也看不见,白白占线路。 */
|
|
15
16
|
const STEP_SUMMARY_MAX = 72;
|
|
@@ -96,6 +97,12 @@ function toolStepSummary(name, rawArgs) {
|
|
|
96
97
|
case 'read':
|
|
97
98
|
case 'read_image':
|
|
98
99
|
return clampSummary(firstStringArg(args, ['file_path', 'path']) || firstStringArg(args, ['description']));
|
|
100
|
+
case 'apply_patch': {
|
|
101
|
+
// 参数里没有单个路径:一次能改好几个文件,路径在补丁头里。摘要取前三份,多了说个数。
|
|
102
|
+
const paths = patchFilePaths(firstStringArg(args, ['input', 'patch']));
|
|
103
|
+
if (paths.length === 0) return clampSummary(firstStringArg(args, ['description']));
|
|
104
|
+
return clampSummary(paths.length <= 3 ? paths.join('、') : `${paths.slice(0, 3).join('、')} 等 ${paths.length} 个`);
|
|
105
|
+
}
|
|
99
106
|
case 'grep':
|
|
100
107
|
case 'glob':
|
|
101
108
|
return clampSummary(firstStringArg(args, ['pattern', 'query']) || firstStringArg(args, ['path']));
|