a4phone 1.4.1 → 1.4.3
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 +13 -11
- package/bin/a4p.mjs +2 -0
- package/dsh/lib/index.js +3 -2
- package/dsh/lib/phone-hooks.mjs +4 -0
- package/package.json +1 -1
- package/src/asku.mjs +2 -0
- package/src/batcher.mjs +6 -1
- package/src/dsh-resume.mjs +46 -10
- package/src/listen.mjs +3 -0
- package/src/update-check.mjs +18 -5
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
1
3
|
# a4phone
|
|
2
4
|
|
|
3
|
-
Claude Code / Codex
|
|
5
|
+
DSH(DeepSeek Harness)/ Claude Code / Codex 远程手机交互包。通过 [ntfy.sh](https://ntfy.sh) 在手机上接收任务完成通知(含 AI 最后输出),对 AI 提问与权限请求进行远程点选或文字作答,并可从手机直接继续对话。
|
|
4
6
|
|
|
5
7
|
## 功能
|
|
6
8
|
|
|
@@ -8,7 +10,7 @@ Claude Code / Codex / DSH(DeepSeek Harness)远程手机交互包。通过 [n
|
|
|
8
10
|
- **AI 提问交互**:`AskUserQuestion`(Codex 为 `request_user_input`,DSH 为 `ask_user_question`)→ 手机显示选项按钮点选,也可直接发送文字自由作答
|
|
9
11
|
- **权限请求交互**:`PermissionRequest` → 手机 Approve/Deny/Always Approve
|
|
10
12
|
- **DSH 一键挂载**:`a4p setup` 自动把内置 `dsh-hook` 插件挂到 DSH web profile,让 DeepSeek Harness 同样具备手机交互
|
|
11
|
-
- **远程续聊**:守护进程监听主话题,手机发文字即可与当前会话交流,形成完整远程对话闭环(Claude Code / Codex
|
|
13
|
+
- **远程续聊**:守护进程监听主话题,手机发文字即可与当前会话交流,形成完整远程对话闭环(DSH / Claude Code / Codex)
|
|
12
14
|
- **DSH 远程续聊**:手机发文字直接注入 DSH 正在运行的会话(`agent.followup`),手机消息与 AI 回复**实时出现在桌面端会话里**,无需另起进程、无会话锁冲突
|
|
13
15
|
- **后台守护进程**:`a4p listen` 无窗口后台运行,日志写入文件
|
|
14
16
|
- **自动更新提醒**:守护进程周期检查 npm 新版本并**推送手机提醒**;其他命令发现新版本时终端提示 + 手机推送(默认开启,可在配置关闭)
|
|
@@ -51,7 +53,7 @@ a4p help # 显示帮助
|
|
|
51
53
|
5. **默认注册开机自启**(Windows 启动文件夹写入隐藏 VBS,登录时自动运行守护进程)
|
|
52
54
|
6. 在终端显示二维码
|
|
53
55
|
|
|
54
|
-
然后用手机 ntfy App
|
|
56
|
+
然后用手机 ntfy App 扫描二维码或输入话题名称订阅;DSH 插件热生效无需重启,重启 Claude Code / Codex 会话后 Hook 生效。
|
|
55
57
|
|
|
56
58
|
> 开机自启无需管理员权限(当前用户启动文件夹),可用 `a4p autostart --off` 关闭、`--on` 重新开启;`a4p uninstall` 会一并移除。WSL/Linux 暂不支持自动注册,可手动用 tmux / systemd 常驻。
|
|
57
59
|
|
|
@@ -75,7 +77,7 @@ a4p status # 查看当前模式
|
|
|
75
77
|
|
|
76
78
|
### 远程续聊
|
|
77
79
|
|
|
78
|
-
在手机端直接向**主话题 `{topic}`** 发送文字,即可与最近会话(Claude Code / Codex
|
|
80
|
+
在手机端直接向**主话题 `{topic}`** 发送文字,即可与最近会话(DSH / Claude Code / Codex)继续对话——无需额外的续聊话题,你订阅的通知话题就是对话通道。
|
|
79
81
|
|
|
80
82
|
1. 启动续聊守护进程(后台无窗口运行):
|
|
81
83
|
|
|
@@ -89,7 +91,7 @@ a4p status # 查看当前模式
|
|
|
89
91
|
|
|
90
92
|
2. 手机 ntfy App 已订阅主话题 `{topic}`(`a4p setup` 生成,扫描二维码即可),向该话题发送任意文字即可。
|
|
91
93
|
|
|
92
|
-
3. 守护进程收到手机消息后,按最近会话的 agent 执行续聊(Claude Code:`claude --resume <会话> --continue -p`;Codex:`codex exec resume <会话> -o <临时文件> -`,`-o`
|
|
94
|
+
3. 守护进程收到手机消息后,按最近会话的 agent 执行续聊(DSH:经文件队列交给 `dsh web` 进程内的插件直接 `followup` 到当前 live 会话;Claude Code:`claude --resume <会话> --continue -p`;Codex:`codex exec resume <会话> -o <临时文件> -`,`-o` 捕获最后一条回复)。均为 headless,捕获回复后推回手机。Codex 会话若被窗口占用(thread-store conflict),a4phone 会自动把它 fork 成新线程续聊——**不需要关闭原窗口**,原会话原样保留,手机对话在 fork 上继续。
|
|
93
95
|
|
|
94
96
|
4. 无需守护进程时,也可在电脑上手动续聊:
|
|
95
97
|
|
|
@@ -103,7 +105,7 @@ a4p status # 查看当前模式
|
|
|
103
105
|
a4p last
|
|
104
106
|
```
|
|
105
107
|
|
|
106
|
-
> 续聊完全 headless 运行(无需窗口标题匹配、前台焦点或剪贴板,也不依赖你当前是否开着终端),支持 Claude Code
|
|
108
|
+
> 续聊完全 headless 运行(无需窗口标题匹配、前台焦点或剪贴板,也不依赖你当前是否开着终端),支持 DSH、Claude Code 与 Codex 会话(按最近会话的 agent 自动选择续聊方式)。续聊回合内若再次触发提问/权限请求,仍会推送手机,形成完整的远程对话闭环。
|
|
107
109
|
>
|
|
108
110
|
> **积压合并**:一轮续聊最长可达 `resumeTimeout`(默认 30 分钟),期间手机连续发来的消息会自动**合并为一个批次**一次性续聊(不再逐条排队、每条一个独立轮次),保证手机内容一定能送达 AI;积压批次持久化到 `~/.a4phone/pending-batch.json`,守护进程重启/崩溃后自动恢复,不丢消息。
|
|
109
111
|
|
|
@@ -167,7 +169,7 @@ command = "a4p hook codex"
|
|
|
167
169
|
|
|
168
170
|
## 原理
|
|
169
171
|
|
|
170
|
-
Hook(Claude Code / Codex)拦截事件后,通过 ntfy.sh 推送带按钮的通知到手机;手机点选或发送文字后,决策经响应话题回传并注入会话。`Stop` 事件同时把 AI 最后输出从会话记录中抽取出来推送手机。
|
|
172
|
+
DSH 插件与 Hook(Claude Code / Codex)拦截事件后,通过 ntfy.sh 推送带按钮的通知到手机;手机点选或发送文字后,决策经响应话题回传并注入会话。`Stop` 事件同时把 AI 最后输出从会话记录中抽取出来推送手机。
|
|
171
173
|
|
|
172
174
|
```
|
|
173
175
|
AI助手触发事件 → a4p hook → ntfy.sh 推送手机 → 手机点选/文字作答 → 决策回传 → 注入会话
|
|
@@ -177,13 +179,13 @@ AI助手触发事件 → a4p hook → ntfy.sh 推送手机 → 手机点选/文
|
|
|
177
179
|
|
|
178
180
|
```
|
|
179
181
|
手机向 {topic} 发文字 → 守护进程 a4p listen
|
|
180
|
-
→ claude --resume <会话> --continue -p(headless,stdin 作为消息)
|
|
181
|
-
→ 或 codex exec resume <会话> -o <临时文件> -(Codex,-o 捕获最后一条回复)
|
|
182
182
|
→ 或 DSH:a4p 写 req 文件 → dsh web 进程内插件 agent.followup 注入会话
|
|
183
183
|
→ whenIdle 等待轮次结束 → 提取回复写 resp 文件 → a4p 轮询取回
|
|
184
|
+
→ 或 claude --resume <会话> --continue -p(headless,stdin 作为消息)
|
|
185
|
+
→ 或 codex exec resume <会话> -o <临时文件> -(Codex,-o 捕获最后一条回复)
|
|
184
186
|
→ AI 回复写入会话并回推手机
|
|
185
|
-
→(Codex 会话被窗口占用时自动 fork 新线程续聊,无需关闭原窗口)
|
|
186
187
|
→(DSH 续聊直接发生在桌面正在运行的会话上,手机与桌面看到同一段对话)
|
|
188
|
+
→(Codex 会话被窗口占用时自动 fork 新线程续聊,无需关闭原窗口)
|
|
187
189
|
```
|
|
188
190
|
|
|
189
191
|
### Hook 输出格式
|
|
@@ -195,7 +197,7 @@ AI助手触发事件 → a4p hook → ntfy.sh 推送手机 → 手机点选/文
|
|
|
195
197
|
|
|
196
198
|
- 需 Node.js 18+,手机端安装 ntfy App
|
|
197
199
|
- 手机订阅后,请在**订阅设置**中开启"即时交付",否则消息需手动刷新才能收到
|
|
198
|
-
- 续聊支持 Claude Code
|
|
200
|
+
- 续聊支持 DSH、Claude Code 与 Codex 会话(按最近会话的 agent 自动选择方式);DSH 续聊需 `dsh web` 正在运行且已挂载新版插件;Codex 续聊通过 `codex exec resume` 执行,需 Codex CLI 已登录、hook 已信任
|
|
199
201
|
- DSH 支持任务完成通知 / 提问作答 / 权限审批 / 远程续聊(经内置 `dsh-hook` 插件)
|
|
200
202
|
- 续聊期间守护进程会自动临时切换为外出模式,结束后恢复原模式
|
|
201
203
|
- Claude Code 会话同一时间只能被一个进程占用,`--resume` 续聊前请先结束终端里仍在运行的原会话;Codex 会话被占用时 a4phone 会自动 fork 新线程续聊(复制会话为新线程 ID,原窗口不受影响,手机对话在 fork 上继续)
|
package/bin/a4p.mjs
CHANGED
|
@@ -56,6 +56,8 @@ if (cmd && !['hook', '--version', '-v', 'version', 'help', '--help', '-h'].inclu
|
|
|
56
56
|
const notifier = makeConsoleNotifier();
|
|
57
57
|
checkForUpdate({
|
|
58
58
|
config: cfg,
|
|
59
|
+
// 命令路径用短超时:避免离线/慢网下命令进程被挂起的 fetch 拖住退出
|
|
60
|
+
timeoutMs: 3000,
|
|
59
61
|
notify: async (latest) => {
|
|
60
62
|
await notifier(latest);
|
|
61
63
|
// 终端提示之外再推送手机,确保用户不会遗落更新消息
|
package/dsh/lib/index.js
CHANGED
|
@@ -111,8 +111,9 @@ function apply(ctx, config = {}) {
|
|
|
111
111
|
turn: data.turn,
|
|
112
112
|
reasonKind: data.reason.kind,
|
|
113
113
|
});
|
|
114
|
-
//
|
|
115
|
-
|
|
114
|
+
// 仅顶层会话推送通知(P3-2:subagent 轮次完成也会触发 turn/end,
|
|
115
|
+
// 若一并推送会刷屏;日志仍全量记录便于排查)
|
|
116
|
+
if (phoneEnabled && !isResumeInflight(session.id) && !session.header?.parentSession) {
|
|
116
117
|
handleTaskComplete(session.id, { turn: data.turn }).catch((error) =>
|
|
117
118
|
ctx.logger.warn(`dsh-hook: 任务完成推送失败: ${String(error)}`)
|
|
118
119
|
);
|
package/dsh/lib/phone-hooks.mjs
CHANGED
|
@@ -84,6 +84,8 @@ export async function handleAskUserQuestion(exec) {
|
|
|
84
84
|
const answers = [];
|
|
85
85
|
for (const q of questions) {
|
|
86
86
|
const options = Array.isArray(q.options) ? q.options : [];
|
|
87
|
+
// 无选项的提问无法手机作答,直接跳过(与 asku.mjs 一致,避免推送后干等超时回退)
|
|
88
|
+
if (!options.length) continue;
|
|
87
89
|
const requestId = crypto.randomUUID();
|
|
88
90
|
// ntfy 最多允许 3 个 action 按钮(超过返回 HTTP 400,推送失败)。
|
|
89
91
|
// 选项 ≤3 → 按钮点选;>3 → 降级为文本编号列表 + 文字作答(waitForResponse 支持自由文本)。
|
|
@@ -106,6 +108,8 @@ export async function handleAskUserQuestion(exec) {
|
|
|
106
108
|
? `(也可直接向话题 ${cfg.topic}-response 发送文字作答)`
|
|
107
109
|
: `(选项较多,请回复编号如「3」,或直接向话题 ${cfg.topic}-response 发送文字作答)`
|
|
108
110
|
);
|
|
111
|
+
// 浏览器兜底:未订阅响应话题的用户可打开网页版直接回复(自由作答/编号回复都需要)
|
|
112
|
+
lines.push(`(如未订阅响应话题,可浏览器打开 ${cfg.server}/${cfg.topic}-response 直接回复)`);
|
|
109
113
|
if (!useActions && options.length > 3) {
|
|
110
114
|
process.stderr.write(`[dsh-hook] 选项 ${options.length} 个超 ntfy 按钮上限(3),已降级为文字作答\n`);
|
|
111
115
|
}
|
package/package.json
CHANGED
package/src/asku.mjs
CHANGED
|
@@ -61,6 +61,8 @@ export async function handleAskUserQuestion(input, agentName, agent = 'claude')
|
|
|
61
61
|
? `(也可直接向话题 ${config.topic}-response 发送文字作答)`
|
|
62
62
|
: `(选项较多,请回复编号如「3」,或直接向话题 ${config.topic}-response 发送文字作答)`
|
|
63
63
|
);
|
|
64
|
+
// 浏览器兜底:未订阅响应话题的用户可打开网页版直接回复(自由作答/编号回复都需要)
|
|
65
|
+
lines.push(`(如未订阅响应话题,可浏览器打开 ${config.server}/${config.topic}-response 直接回复)`);
|
|
64
66
|
const sent = await sendNotification({
|
|
65
67
|
...config,
|
|
66
68
|
title: `${agentName}: ${q.header || 'Question'}`,
|
package/src/batcher.mjs
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// batcher.submit(text, msgTime); // 立即返回 drain 的 promise(fire-and-forget 也行)
|
|
15
15
|
// batcher.restore(texts, msgTime); // 启动时恢复上次未处理的批次
|
|
16
16
|
// batcher.pendingCount / batcher.pendingSnapshot() // 持久化与检查用
|
|
17
|
-
export function createBatcher({ run, log = () => {} }) {
|
|
17
|
+
export function createBatcher({ run, log = () => {}, onTake = null }) {
|
|
18
18
|
let draining = null; // 正在执行的 drain 循环(防止并发)
|
|
19
19
|
const pending = { texts: [], msgTime: null };
|
|
20
20
|
|
|
@@ -36,6 +36,11 @@ export function createBatcher({ run, log = () => {} }) {
|
|
|
36
36
|
const msgTime = pending.msgTime;
|
|
37
37
|
pending.texts = [];
|
|
38
38
|
pending.msgTime = null;
|
|
39
|
+
// 取批即通知(P4-1:调用方在此删除持久化文件——批次已交付给续聊管线,
|
|
40
|
+
// 进程崩溃不再恢复它,a4p 侧实现 at-most-once,避免同一条消息重复注入)
|
|
41
|
+
if (onTake) {
|
|
42
|
+
try { onTake({ texts, msgTime }); } catch {}
|
|
43
|
+
}
|
|
39
44
|
try {
|
|
40
45
|
await run({ text: texts.join('\n\n'), count: texts.length, msgTime });
|
|
41
46
|
} catch (error) {
|
package/src/dsh-resume.mjs
CHANGED
|
@@ -83,6 +83,33 @@ export async function waitForResponseFile(id, timeoutMs, pollMs = POLL_INTERVAL_
|
|
|
83
83
|
return null;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/** DSH 续聊专用轮询:等待 resp 的同时周期复查心跳,插件中途死亡时快速失败
|
|
87
|
+
* (P4-2:避免 dsh web 退出后手机端干等满 resumeTimeout)。
|
|
88
|
+
* 返回 { died: true } 表示心跳丢失;null 表示超时;否则为 resp 内容。 */
|
|
89
|
+
export async function waitForDshReply(id, timeoutMs, {
|
|
90
|
+
isAlive,
|
|
91
|
+
heartbeatCheckMs = 10_000,
|
|
92
|
+
pollMs = POLL_INTERVAL_MS,
|
|
93
|
+
dir = DSH_JOB_DIR,
|
|
94
|
+
} = {}) {
|
|
95
|
+
const deadline = Date.now() + timeoutMs;
|
|
96
|
+
let lastCheck = 0;
|
|
97
|
+
while (Date.now() < deadline) {
|
|
98
|
+
const resp = readResponse(id, dir);
|
|
99
|
+
if (resp) {
|
|
100
|
+
clearResponse(id, dir);
|
|
101
|
+
return resp;
|
|
102
|
+
}
|
|
103
|
+
const now = Date.now();
|
|
104
|
+
if (isAlive && now - lastCheck >= heartbeatCheckMs) {
|
|
105
|
+
lastCheck = now;
|
|
106
|
+
if (!isAlive()) return { died: true };
|
|
107
|
+
}
|
|
108
|
+
await new Promise((r) => setTimeout(r, pollMs));
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
86
113
|
/** 回复文本截断:去空行,取末尾一段(与 Claude/Codex 续聊的回推格式一致) */
|
|
87
114
|
export function clipReply(reply) {
|
|
88
115
|
const clean = (reply || '')
|
|
@@ -106,12 +133,15 @@ export async function runDshResume(text, { config = null, onLog = (s) => {} } =
|
|
|
106
133
|
const textClean = (text || '').trim();
|
|
107
134
|
if (!textClean) return { ok: false, reason: '续聊内容为空。' };
|
|
108
135
|
|
|
136
|
+
// 失败反馈:把失败原因推回手机(P3-1:与 Claude/Codex 路径一致,手机端不干等无反馈)
|
|
137
|
+
const pushFailure = async (message) => {
|
|
138
|
+
await sendNotification({ ...config, title: 'DSH', message: `续聊失败\n\n${message}` });
|
|
139
|
+
};
|
|
140
|
+
|
|
109
141
|
if (!isDshAlive()) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
'请确认 dsh web 正在运行,且已挂载新版 dsh-hook 插件(可重新执行 a4p setup 挂载)。',
|
|
114
|
-
};
|
|
142
|
+
const reason = '未检测到运行中的 DSH(dsh web 进程心跳过期)。\n请确认 dsh web 正在运行,且已挂载新版 dsh-hook 插件(可重新执行 a4p setup 挂载)。';
|
|
143
|
+
await pushFailure(reason);
|
|
144
|
+
return { ok: false, reason };
|
|
115
145
|
}
|
|
116
146
|
|
|
117
147
|
// 最近 DSH 会话优先指定目标;无则交给插件兜底选最近顶层会话
|
|
@@ -122,13 +152,19 @@ export async function runDshResume(text, { config = null, onLog = (s) => {} } =
|
|
|
122
152
|
onLog(`DSH 续聊请求已提交${sessionId ? `(会话 ${sessionId.slice(0, 8)})` : ''},等待 dsh web 回复…`);
|
|
123
153
|
|
|
124
154
|
const timeoutMs = (config.resumeTimeout ?? 1800) * 1000;
|
|
125
|
-
|
|
155
|
+
// 轮询期间周期复查心跳:插件中途死亡立即失败(P4-2),不再干等满超时
|
|
156
|
+
const resp = await waitForDshReply(req.id, timeoutMs, { isAlive: () => isDshAlive() });
|
|
126
157
|
if (!resp) {
|
|
127
158
|
clearRequest(req.id);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
159
|
+
const reason = '续聊超时:dsh web 进程未在限时内回复(请确认 dsh web 正在运行,会话未被占用)。';
|
|
160
|
+
await pushFailure(reason);
|
|
161
|
+
return { ok: false, reason };
|
|
162
|
+
}
|
|
163
|
+
if (resp.died) {
|
|
164
|
+
clearRequest(req.id);
|
|
165
|
+
const reason = 'dsh web 进程在续聊中途退出(心跳丢失),续聊已中断,请重新发送消息。';
|
|
166
|
+
await pushFailure(reason);
|
|
167
|
+
return { ok: false, reason };
|
|
132
168
|
}
|
|
133
169
|
|
|
134
170
|
let message;
|
package/src/listen.mjs
CHANGED
|
@@ -79,6 +79,9 @@ export async function runListen({ onLog = (s) => console.log(s) } = {}) {
|
|
|
79
79
|
|
|
80
80
|
const batcher = createBatcher({
|
|
81
81
|
log: onLog,
|
|
82
|
+
// 取批即删持久化文件(P4-1 a4p 侧 at-most-once):批次一旦交给续聊管线,
|
|
83
|
+
// 进程崩溃后不再恢复,避免同一条手机消息重复注入会话
|
|
84
|
+
onTake: persistSnapshot,
|
|
82
85
|
run: async ({ text, count, msgTime }) => {
|
|
83
86
|
try {
|
|
84
87
|
if (msgTime != null && isMessageStale(msgTime)) return false; // 旧消息,丢弃
|
package/src/update-check.mjs
CHANGED
|
@@ -14,6 +14,9 @@ import { sendNotification } from './ntfy.mjs';
|
|
|
14
14
|
|
|
15
15
|
/** 默认检查间隔(小时):守护进程周期检查与命令级限频共用 */
|
|
16
16
|
export const DEFAULT_INTERVAL_HOURS = 6;
|
|
17
|
+
/** 查询失败后的背退重试间隔:失败也记录 lastCheck,但只按该间隔限频,
|
|
18
|
+
避免离线/慢网下每次命令都重试网络(命令会因挂起的 fetch 卡住进程退出) */
|
|
19
|
+
export const FAIL_RETRY_MS = 30 * 60 * 1000;
|
|
17
20
|
|
|
18
21
|
/** 查询源:国内镜像优先(与用户 npm 配置一致,国内网络更稳),官方兜底 */
|
|
19
22
|
const REGISTRIES = [
|
|
@@ -111,6 +114,7 @@ export async function checkForUpdate({
|
|
|
111
114
|
minIntervalMs = null,
|
|
112
115
|
localVersion = getLocalVersion(),
|
|
113
116
|
latestVersion = undefined,
|
|
117
|
+
timeoutMs = 8000,
|
|
114
118
|
} = {}) {
|
|
115
119
|
const cfg = config || {};
|
|
116
120
|
if (cfg.checkUpdates === false) {
|
|
@@ -119,14 +123,23 @@ export async function checkForUpdate({
|
|
|
119
123
|
|
|
120
124
|
const cache = loadCache(cachePath);
|
|
121
125
|
const intervalMs = minIntervalMs ?? (cfg.updateIntervalHours ?? DEFAULT_INTERVAL_HOURS) * 3600 * 1000;
|
|
122
|
-
|
|
126
|
+
// 本地版本升级后忽略限频:旧版本时代的 lastCheck 不应推迟新版本的首次检查
|
|
127
|
+
// (否则用户升级后要等一整个间隔才能收到新版本提醒)
|
|
128
|
+
const versionChanged = cache.version !== localVersion;
|
|
129
|
+
if (!versionChanged && now - (cache.lastCheck || 0) < intervalMs) {
|
|
123
130
|
// 未到期:限频跳过(不访问网络)
|
|
124
131
|
return { checked: false, hasUpdate: false, local: localVersion, latest: cache.knownLatest || null, notified: false };
|
|
125
132
|
}
|
|
126
133
|
|
|
127
|
-
const latest = latestVersion !== undefined ? latestVersion : await fetchLatestVersion();
|
|
134
|
+
const latest = latestVersion !== undefined ? latestVersion : await fetchLatestVersion({ timeoutMs });
|
|
128
135
|
if (!latest) {
|
|
129
|
-
//
|
|
136
|
+
// 查询失败:记录 lastCheck 为"interval - 背退间隔"之前,使下次重试落在 FAIL_RETRY_MS 之后,
|
|
137
|
+
// 避免离线/慢网下每次命令都重新访问网络(P2:命令会因挂起的 fetch 卡住退出)
|
|
138
|
+
saveCache({
|
|
139
|
+
lastCheck: now - (intervalMs - FAIL_RETRY_MS),
|
|
140
|
+
knownLatest: cache.knownLatest,
|
|
141
|
+
version: localVersion,
|
|
142
|
+
}, cachePath);
|
|
130
143
|
return { checked: true, hasUpdate: false, local: localVersion, latest: null, notified: false };
|
|
131
144
|
}
|
|
132
145
|
|
|
@@ -139,12 +152,12 @@ export async function checkForUpdate({
|
|
|
139
152
|
} catch (error) {
|
|
140
153
|
onLog(`更新提醒发送失败(将在下次检查重试): ${String(error?.message ?? error)}`);
|
|
141
154
|
// 提醒失败:不更新 knownLatest,下次检查会重试;只记录检查时间
|
|
142
|
-
saveCache({ lastCheck: now, knownLatest: cache.knownLatest }, cachePath);
|
|
155
|
+
saveCache({ lastCheck: now, knownLatest: cache.knownLatest, version: localVersion }, cachePath);
|
|
143
156
|
return { checked: true, hasUpdate, local: localVersion, latest, notified: false };
|
|
144
157
|
}
|
|
145
158
|
}
|
|
146
159
|
|
|
147
|
-
saveCache({ lastCheck: now, knownLatest: hasUpdate ? latest : cache.knownLatest }, cachePath);
|
|
160
|
+
saveCache({ lastCheck: now, knownLatest: hasUpdate ? latest : cache.knownLatest, version: localVersion }, cachePath);
|
|
148
161
|
return { checked: true, hasUpdate, local: localVersion, latest, notified: isNewVersion };
|
|
149
162
|
}
|
|
150
163
|
|