a4phone 1.5.2 → 1.6.1

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/bin/a4p.mjs CHANGED
@@ -1,193 +1,194 @@
1
- #!/usr/bin/env node
2
- // a4phone 命令行入口
3
- // a4p setup 安装引导(生成话题、注册 Hook、显示二维码)
4
- // a4p out 外出模式(手机优先)
5
- // a4p home 终端优先模式(默认)
6
- // a4p status 查看当前模式
7
- // a4p hook 处理 Claude Code Hook(内部调用)
8
- // a4p listen 启动续聊守护进程(后台 / --stop / --status)
9
- // a4p resume 手动续聊最近会话
10
- // a4p last 查看最近会话记录
11
- // a4p test 发送测试通知
12
- // a4p uninstall 移除 Hook 和配置
13
- import fs from 'fs';
14
- import path from 'path';
15
- import os from 'os';
16
- import qrcode from 'qrcode-terminal';
17
- import { migrateLegacy, LOG_PATH, A4P_DIR } from '../src/paths.mjs';
18
-
19
- const SETTINGS_PATH = path.join(os.homedir(), '.claude', 'settings.json');
20
-
21
- // 把旧版家目录散点文件迁移到 ~/.a4phone/(幂等,无旧文件时仅建目录)
22
- migrateLegacy();
23
-
24
- function showHelp() {
25
- console.log('a4phone — Claude Code / Codex / DSH 远程手机交互\n');
26
- console.log('用法:');
27
- console.log(' a4p setup 安装引导(生成话题、注册 Hook、为全部 DSH profile 挂载插件、显示二维码)');
28
- console.log(' a4p out 外出模式(手机优先)');
29
- console.log(' a4p home 终端优先模式(默认)');
30
- console.log(' a4p status 查看当前模式');
31
- console.log(' a4p listen 后台运行续聊守护进程(无窗口)');
32
- console.log(' a4p listen --stop 停止守护进程');
33
- console.log(' a4p listen --status 查看守护进程状态');
34
- console.log(' a4p autostart 开机自启状态(--on 开启 / --off 关闭)');
35
- console.log(' a4p resume 手动续聊最近会话:a4p resume 要追加的内容');
36
- console.log(' a4p last 查看最近会话记录');
37
- console.log(' a4p test 发送测试通知');
38
- console.log(' a4p uninstall 移除 Hook 和配置');
39
- console.log(' a4p --version 查看版本号');
40
- console.log(' a4p help 显示本帮助');
41
- }
42
-
43
- const cmd = process.argv[2];
44
- const sub = process.argv[3];
45
-
46
- // ── 版本更新检查(默认开启)───────────────────────────────────────────
47
- // 守护进程(listen --daemon-child)自己有周期检查 + 手机推送,这里跳过;
48
- // hook 是 AI 每次事件都调用的热路径,跳过避免延迟;version/help 是脚本/查询场景跳过。
49
- // 其余命令:发现新版本时终端提示 + 手机推送(共用去重缓存,同一版本只提醒一次)。
50
- if (cmd && !['hook', '--version', '-v', 'version', 'help', '--help', '-h'].includes(cmd)
51
- && !(cmd === 'listen' && sub === '--daemon-child')) {
52
- const { checkForUpdate, makeConsoleNotifier } = await import('../src/update-check.mjs');
53
- const { sendNotification } = await import('../src/ntfy.mjs');
54
- const { loadConfig } = await import('../src/config.mjs');
55
- const cfg = loadConfig();
56
- const notifier = makeConsoleNotifier();
57
- checkForUpdate({
58
- config: cfg,
59
- // 命令路径用短超时:避免离线/慢网下命令进程被挂起的 fetch 拖住退出
60
- timeoutMs: 3000,
61
- notify: async (latest) => {
62
- await notifier(latest);
63
- // 终端提示之外再推送手机,确保用户不会遗落更新消息
64
- if (cfg.topic) {
65
- const ok = await sendNotification({
66
- ...cfg,
67
- title: 'a4phone',
68
- message: `检测到新版本 ${latest}\n\n请运行:npm install -g a4phone 升级`,
69
- });
70
- if (!ok) throw new Error('手机推送失败');
71
- }
72
- },
73
- }).catch(() => {});
74
- }
75
-
76
- if (cmd === '--version' || cmd === '-v' || cmd === 'version') {
77
- const pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
78
- console.log(pkg.version);
79
- } else if (cmd === 'setup') {
80
- const { runSetup } = await import('../src/setup.mjs');
81
- qrcode.setErrorLevel('L');
82
- await runSetup({ generateQR: (text, opts, cb) => qrcode.generate(text, opts, cb) });
83
- } else if (cmd === 'out' || cmd === 'home') {
84
- const { setMode } = await import('../src/mode.mjs');
85
- setMode(cmd);
86
- console.log(cmd === 'out'
87
- ? '外出模式已开启:提问/权限请求优先推送手机,超时兜底终端。'
88
- : '终端优先模式:提问/权限请求直接走终端,手机不参与。');
89
- } else if (cmd === 'status') {
90
- const { readMode } = await import('../src/mode.mjs');
91
- console.log(readMode() === 'out' ? '当前模式:外出(手机优先)' : '当前模式:终端优先(默认)');
92
- } else if (cmd === 'hook') {
93
- let input;
94
- try {
95
- input = JSON.parse(fs.readFileSync(0, 'utf-8'));
96
- } catch {
97
- process.exit(0);
98
- }
99
- // 可选的 agent 标识:a4p hook [codex|claude],默认 claude
100
- const agent = process.argv[3] === 'codex' ? 'codex' : 'claude';
101
- const { dispatchHook } = await import('../src/hook.mjs');
102
- const result = await dispatchHook(input, agent);
103
- if (result) {
104
- process.stdout.write(JSON.stringify(result) + '\n');
105
- }
106
- } else if (cmd === 'uninstall') {
107
- const { unregisterHooks, unconfigureCodex, unconfigureDsh } = await import('../src/setup.mjs');
108
- const { stopDaemon } = await import('../src/daemon.mjs');
109
- const { disableAutostart } = await import('../src/autostart.mjs');
110
- // 先停守护进程:Windows 上守护进程持有 daemon.log 句柄,直接删目录会失败且异常被静默吞掉
111
- await stopDaemon();
112
- disableAutostart();
113
- unregisterHooks(SETTINGS_PATH);
114
- unconfigureCodex();
115
- unconfigureDsh();
116
- // 新版 ~/.a4phone/ 目录 + 旧版家目录散点文件一并清理
117
- try { fs.rmSync(A4P_DIR, { recursive: true, force: true }); } catch {}
118
- for (const f of ['.a4phone.json', '.a4phone-mode.json', '.a4phone-last.json', '.a4phone-daemon.json', '.a4phone-daemon.log']) {
119
- try { fs.unlinkSync(path.join(os.homedir(), f)); } catch {}
120
- }
121
- console.log('a4phone 已卸载:Claude Code / Codex / DSH Hook 已移除,开机自启与配置已删除。');
122
- } else if (cmd === 'autostart') {
123
- const { enableAutostart, disableAutostart, isAutostartEnabled } = await import('../src/autostart.mjs');
124
- const mode = process.argv[3];
125
- if (mode === '--off') {
126
- const r = disableAutostart();
127
- console.log(r.ok ? '开机自启已关闭。' : `关闭失败:${r.reason}`);
128
- } else if (mode === '--on') {
129
- const r = enableAutostart();
130
- console.log(r.ok ? '开机自启已开启(登录时自动运行续聊守护进程)。' : `开启失败:${r.reason}`);
131
- } else {
132
- console.log(isAutostartEnabled()
133
- ? '开机自启:已开启(登录时自动运行续聊守护进程)'
134
- : '开机自启:未开启(运行 a4p autostart --on 开启)');
135
- }
136
- } else if (cmd === 'listen') {
137
- const sub = process.argv[3];
138
- if (sub === '--stop') {
139
- const { stopDaemon } = await import('../src/daemon.mjs');
140
- await stopDaemon();
141
- } else if (sub === '--status') {
142
- const { daemonStatus } = await import('../src/daemon.mjs');
143
- await daemonStatus();
144
- } else if (sub === '--daemon-child') {
145
- // 后台子进程:日志写入文件
146
- const { runListen, createLogWriter } = await import('../src/listen.mjs');
147
- const onLog = createLogWriter(LOG_PATH);
148
- await runListen({ onLog });
149
- } else {
150
- // 统一入口:a4p listen 即后台守护进程
151
- const { startDaemon } = await import('../src/daemon.mjs');
152
- await startDaemon();
153
- }
154
- } else if (cmd === 'resume') {
155
- const { runResume } = await import('../src/resume.mjs');
156
- const text = process.argv.slice(3).join(' ');
157
- if (!text.trim()) {
158
- console.error('用法: a4p resume 要追加的内容');
159
- process.exit(1);
160
- }
161
- const result = await runResume(text);
162
- if (!result.ok) {
163
- console.error(result.reason);
164
- process.exit(1);
165
- }
166
- console.log(`续聊完成(退出码 ${result.code}),结果已推送手机。`);
167
- } else if (cmd === 'last') {
168
- const { loadLastSession } = await import('../src/config.mjs');
169
- const last = loadLastSession();
170
- if (!last) {
171
- console.log('暂无最近会话记录,完成一次任务后自动记录。');
172
- } else {
173
- console.log('最近会话:');
174
- console.log(` 会话 ID: ${last.session_id}`);
175
- console.log(` 目录: ${last.cwd}`);
176
- console.log(` 来源: ${last.agent}`);
177
- console.log(` 时间: ${new Date(last.ts).toLocaleString()}`);
178
- }
179
- } else if (cmd === 'test') {
180
- const { loadConfig } = await import('../src/config.mjs');
181
- const { sendNotification } = await import('../src/ntfy.mjs');
182
- const config = loadConfig();
183
- if (!config.topic) {
184
- console.error('未配置话题,请先运行 a4p setup。');
185
- process.exit(1);
186
- }
187
- const ok = await sendNotification({ ...config, title: 'a4phone', message: '测试通知:如果手机收到,配置正常。' });
188
- console.log(ok ? '测试通知发送成功。' : '发送失败,请检查网络。');
189
- } else if (cmd === 'help' || cmd === '--help' || cmd === '-h') {
190
- showHelp();
191
- } else {
192
- showHelp();
193
- }
1
+ #!/usr/bin/env node
2
+ // a4phone 命令行入口
3
+ // a4p setup 安装引导(生成话题、注册 Hook、显示二维码)
4
+ // a4p out 外出模式(手机优先)
5
+ // a4p home 终端优先模式(默认)
6
+ // a4p status 查看当前模式
7
+ // a4p hook 处理 Claude Code Hook(内部调用)
8
+ // a4p listen 启动续聊守护进程(后台 / --stop / --status)
9
+ // a4p resume 手动续聊最近会话
10
+ // a4p last 查看最近会话记录
11
+ // a4p test 发送测试通知
12
+ // a4p uninstall 移除 Hook 和配置
13
+ import fs from 'fs';
14
+ import path from 'path';
15
+ import os from 'os';
16
+ import qrcode from 'qrcode-terminal';
17
+ import { migrateLegacy, LOG_PATH, A4P_DIR } from '../src/paths.mjs';
18
+
19
+ const SETTINGS_PATH = path.join(os.homedir(), '.claude', 'settings.json');
20
+
21
+ // 把旧版家目录散点文件迁移到 ~/.a4phone/(幂等,无旧文件时仅建目录)
22
+ migrateLegacy();
23
+
24
+ function showHelp() {
25
+ console.log('a4phone — Claude Code / Codex / ZCode / DSH 远程手机交互\n');
26
+ console.log('用法:');
27
+ console.log(' a4p setup 安装引导(生成话题、注册 Hook、为全部 DSH profile 挂载插件、显示二维码)');
28
+ console.log(' a4p out 外出模式(手机优先)');
29
+ console.log(' a4p home 终端优先模式(默认)');
30
+ console.log(' a4p status 查看当前模式');
31
+ console.log(' a4p listen 后台运行续聊守护进程(无窗口)');
32
+ console.log(' a4p listen --stop 停止守护进程');
33
+ console.log(' a4p listen --status 查看守护进程状态');
34
+ console.log(' a4p autostart 开机自启状态(--on 开启 / --off 关闭)');
35
+ console.log(' a4p resume 手动续聊最近会话:a4p resume 要追加的内容');
36
+ console.log(' a4p last 查看最近会话记录');
37
+ console.log(' a4p test 发送测试通知');
38
+ console.log(' a4p uninstall 移除 Hook 和配置');
39
+ console.log(' a4p --version 查看版本号');
40
+ console.log(' a4p help 显示本帮助');
41
+ }
42
+
43
+ const cmd = process.argv[2];
44
+ const sub = process.argv[3];
45
+
46
+ // ── 版本更新检查(默认开启)───────────────────────────────────────────
47
+ // 守护进程(listen --daemon-child)自己有周期检查 + 手机推送,这里跳过;
48
+ // hook 是 AI 每次事件都调用的热路径,跳过避免延迟;version/help 是脚本/查询场景跳过。
49
+ // 其余命令:发现新版本时终端提示 + 手机推送(共用去重缓存,同一版本只提醒一次)。
50
+ if (cmd && !['hook', '--version', '-v', 'version', 'help', '--help', '-h'].includes(cmd)
51
+ && !(cmd === 'listen' && sub === '--daemon-child')) {
52
+ const { checkForUpdate, makeConsoleNotifier } = await import('../src/update-check.mjs');
53
+ const { sendNotification } = await import('../src/ntfy.mjs');
54
+ const { loadConfig } = await import('../src/config.mjs');
55
+ const cfg = loadConfig();
56
+ const notifier = makeConsoleNotifier();
57
+ checkForUpdate({
58
+ config: cfg,
59
+ // 命令路径用短超时:避免离线/慢网下命令进程被挂起的 fetch 拖住退出
60
+ timeoutMs: 3000,
61
+ notify: async (latest) => {
62
+ await notifier(latest);
63
+ // 终端提示之外再推送手机,确保用户不会遗落更新消息
64
+ if (cfg.topic) {
65
+ const ok = await sendNotification({
66
+ ...cfg,
67
+ title: 'a4phone',
68
+ message: `检测到新版本 ${latest}\n\n请运行:npm install -g a4phone 升级`,
69
+ });
70
+ if (!ok) throw new Error('手机推送失败');
71
+ }
72
+ },
73
+ }).catch(() => {});
74
+ }
75
+
76
+ if (cmd === '--version' || cmd === '-v' || cmd === 'version') {
77
+ const pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
78
+ console.log(pkg.version);
79
+ } else if (cmd === 'setup') {
80
+ const { runSetup } = await import('../src/setup.mjs');
81
+ qrcode.setErrorLevel('L');
82
+ await runSetup({ generateQR: (text, opts, cb) => qrcode.generate(text, opts, cb) });
83
+ } else if (cmd === 'out' || cmd === 'home') {
84
+ const { setMode } = await import('../src/mode.mjs');
85
+ setMode(cmd);
86
+ console.log(cmd === 'out'
87
+ ? '外出模式已开启:提问/权限请求优先推送手机,超时兜底终端。'
88
+ : '终端优先模式:提问/权限请求直接走终端,手机不参与。');
89
+ } else if (cmd === 'status') {
90
+ const { readMode } = await import('../src/mode.mjs');
91
+ console.log(readMode() === 'out' ? '当前模式:外出(手机优先)' : '当前模式:终端优先(默认)');
92
+ } else if (cmd === 'hook') {
93
+ let input;
94
+ try {
95
+ input = JSON.parse(fs.readFileSync(0, 'utf-8'));
96
+ } catch {
97
+ process.exit(0);
98
+ }
99
+ // 可选的 agent 标识:a4p hook [codex|zcode|claude],默认 claude
100
+ const agent = ['codex', 'zcode'].includes(process.argv[3]) ? process.argv[3] : 'claude';
101
+ const { dispatchHook } = await import('../src/hook.mjs');
102
+ const result = await dispatchHook(input, agent);
103
+ if (result) {
104
+ process.stdout.write(JSON.stringify(result) + '\n');
105
+ }
106
+ } else if (cmd === 'uninstall') {
107
+ const { unregisterHooks, unconfigureCodex, unconfigureZcode, unconfigureDsh } = await import('../src/setup.mjs');
108
+ const { stopDaemon } = await import('../src/daemon.mjs');
109
+ const { disableAutostart } = await import('../src/autostart.mjs');
110
+ // 先停守护进程:Windows 上守护进程持有 daemon.log 句柄,直接删目录会失败且异常被静默吞掉
111
+ await stopDaemon();
112
+ disableAutostart();
113
+ unregisterHooks(SETTINGS_PATH);
114
+ unconfigureCodex();
115
+ unconfigureZcode();
116
+ unconfigureDsh();
117
+ // 新版 ~/.a4phone/ 目录 + 旧版家目录散点文件一并清理
118
+ try { fs.rmSync(A4P_DIR, { recursive: true, force: true }); } catch {}
119
+ for (const f of ['.a4phone.json', '.a4phone-mode.json', '.a4phone-last.json', '.a4phone-daemon.json', '.a4phone-daemon.log']) {
120
+ try { fs.unlinkSync(path.join(os.homedir(), f)); } catch {}
121
+ }
122
+ console.log('a4phone 已卸载:Claude Code / Codex / ZCode / DSH Hook 已移除,开机自启与配置已删除。');
123
+ } else if (cmd === 'autostart') {
124
+ const { enableAutostart, disableAutostart, isAutostartEnabled } = await import('../src/autostart.mjs');
125
+ const mode = process.argv[3];
126
+ if (mode === '--off') {
127
+ const r = disableAutostart();
128
+ console.log(r.ok ? '开机自启已关闭。' : `关闭失败:${r.reason}`);
129
+ } else if (mode === '--on') {
130
+ const r = enableAutostart();
131
+ console.log(r.ok ? '开机自启已开启(登录时自动运行续聊守护进程)。' : `开启失败:${r.reason}`);
132
+ } else {
133
+ console.log(isAutostartEnabled()
134
+ ? '开机自启:已开启(登录时自动运行续聊守护进程)'
135
+ : '开机自启:未开启(运行 a4p autostart --on 开启)');
136
+ }
137
+ } else if (cmd === 'listen') {
138
+ const sub = process.argv[3];
139
+ if (sub === '--stop') {
140
+ const { stopDaemon } = await import('../src/daemon.mjs');
141
+ await stopDaemon();
142
+ } else if (sub === '--status') {
143
+ const { daemonStatus } = await import('../src/daemon.mjs');
144
+ await daemonStatus();
145
+ } else if (sub === '--daemon-child') {
146
+ // 后台子进程:日志写入文件
147
+ const { runListen, createLogWriter } = await import('../src/listen.mjs');
148
+ const onLog = createLogWriter(LOG_PATH);
149
+ await runListen({ onLog });
150
+ } else {
151
+ // 统一入口:a4p listen 即后台守护进程
152
+ const { startDaemon } = await import('../src/daemon.mjs');
153
+ await startDaemon();
154
+ }
155
+ } else if (cmd === 'resume') {
156
+ const { runResume } = await import('../src/resume.mjs');
157
+ const text = process.argv.slice(3).join(' ');
158
+ if (!text.trim()) {
159
+ console.error('用法: a4p resume 要追加的内容');
160
+ process.exit(1);
161
+ }
162
+ const result = await runResume(text);
163
+ if (!result.ok) {
164
+ console.error(result.reason);
165
+ process.exit(1);
166
+ }
167
+ console.log(`续聊完成(退出码 ${result.code}),结果已推送手机。`);
168
+ } else if (cmd === 'last') {
169
+ const { loadLastSession } = await import('../src/config.mjs');
170
+ const last = loadLastSession();
171
+ if (!last) {
172
+ console.log('暂无最近会话记录,完成一次任务后自动记录。');
173
+ } else {
174
+ console.log('最近会话:');
175
+ console.log(` 会话 ID: ${last.session_id}`);
176
+ console.log(` 目录: ${last.cwd}`);
177
+ console.log(` 来源: ${last.agent}`);
178
+ console.log(` 时间: ${new Date(last.ts).toLocaleString()}`);
179
+ }
180
+ } else if (cmd === 'test') {
181
+ const { loadConfig } = await import('../src/config.mjs');
182
+ const { sendNotification } = await import('../src/ntfy.mjs');
183
+ const config = loadConfig();
184
+ if (!config.topic) {
185
+ console.error('未配置话题,请先运行 a4p setup。');
186
+ process.exit(1);
187
+ }
188
+ const ok = await sendNotification({ ...config, title: 'a4phone', message: '测试通知:如果手机收到,配置正常。' });
189
+ console.log(ok ? '测试通知发送成功。' : '发送失败,请检查网络。');
190
+ } else if (cmd === 'help' || cmd === '--help' || cmd === '-h') {
191
+ showHelp();
192
+ } else {
193
+ showHelp();
194
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "a4phone",
3
- "version": "1.5.2",
4
- "description": "Claude Code / Codex / DSH 远程手机交互:任务完成通知(含 AI 最后输出)、提问/权限请求手机点选或文字作答、远程续聊(ntfy.sh,含 DSH 会话续聊)",
3
+ "version": "1.6.1",
4
+ "description": "Claude Code / Codex / ZCode / DSH 远程手机交互:任务完成通知(含 AI 最后输出)、提问/权限请求手机点选或文字作答、远程续聊(ntfy.sh,含 DSH 会话续聊)",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "a4p": "bin/a4p.mjs"
package/src/hook.mjs CHANGED
@@ -1,42 +1,48 @@
1
- // Hook 分发器:根据 hook_event_name 决定处理逻辑
2
- import { readMode } from './mode.mjs';
3
- import { systemNotify } from './notify.mjs';
4
- import { handleStop } from './stop.mjs';
5
- import { handleAskUserQuestion } from './asku.mjs';
6
- import { handlePermissionRequest } from './permission.mjs';
7
-
8
- // 根据 agent 标识返回显示名称
9
- export function agentName(agent) {
10
- return agent === 'codex' ? 'Codex' : 'Claude Code';
11
- }
12
-
13
- // 返回 hook 输出对象,或 null(null = 不干预,走终端默认流程)
14
- export async function dispatchHook(input, agent) {
15
- const event = input.hook_event_name;
16
- const isOut = readMode() === 'out';
17
- const name = agentName(agent);
18
-
19
- if (event === 'Stop') {
20
- return handleStop(input, name);
21
- }
22
-
23
- if (event === 'PreToolUse') {
24
- // Claude Code 的提问工具叫 AskUserQuestion;Codex 的叫 request_user_input
25
- const isAsk =
26
- input.tool_name === 'AskUserQuestion' ||
27
- (agent === 'codex' && input.tool_name === 'request_user_input');
28
- if (isAsk) {
29
- await systemNotify(name, '有提问需要处理');
30
- if (!isOut) return null; // 终端优先:不阻塞
31
- return handleAskUserQuestion(input, name, agent);
32
- }
33
- }
34
-
35
- if (event === 'PermissionRequest') {
36
- await systemNotify(name, '有权限请求需要处理');
37
- if (!isOut) return null; // 终端优先:不阻塞
38
- return handlePermissionRequest(input, name);
39
- }
40
-
41
- return null;
42
- }
1
+ // Hook 分发器:根据 hook_event_name 决定处理逻辑
2
+ import { readMode } from './mode.mjs';
3
+ import { systemNotify } from './notify.mjs';
4
+ import { handleStop } from './stop.mjs';
5
+ import { handleAskUserQuestion } from './asku.mjs';
6
+ import { handlePermissionRequest } from './permission.mjs';
7
+
8
+ // 根据 agent 标识返回显示名称
9
+ export function agentName(agent) {
10
+ if (agent === 'codex') return 'Codex';
11
+ if (agent === 'zcode') return 'ZCode';
12
+ return 'Claude Code';
13
+ }
14
+
15
+ // 返回 hook 输出对象,或 null(null = 不干预,走终端默认流程)
16
+ export async function dispatchHook(input, agent) {
17
+ const event = input.hook_event_name;
18
+ const isOut = readMode() === 'out';
19
+ const name = agentName(agent);
20
+
21
+ if (event === 'Stop') {
22
+ return handleStop(input, name);
23
+ }
24
+
25
+ if (event === 'PreToolUse') {
26
+ // Claude Code 的提问工具叫 AskUserQuestion;Codex 的叫 request_user_input
27
+ const isAsk =
28
+ input.tool_name === 'AskUserQuestion' ||
29
+ (agent === 'codex' && input.tool_name === 'request_user_input');
30
+ if (isAsk) {
31
+ await systemNotify(name, '有提问需要处理');
32
+ if (!isOut) return null; // 终端优先:不阻塞
33
+ return handleAskUserQuestion(input, name, agent);
34
+ }
35
+ }
36
+
37
+ if (event === 'PermissionRequest') {
38
+ // ZCode 对 AskUserQuestion 会同时触发 PreToolUse 和 PermissionRequest 两次 hook;
39
+ // 提问提醒已由 PreToolUse 分支负责,这里跳过桌面弹窗,避免重复通知和误导性文案。
40
+ if (input.tool_name !== 'AskUserQuestion') {
41
+ await systemNotify(name, '有权限请求需要处理');
42
+ }
43
+ if (!isOut) return null; // 终端优先:不阻塞
44
+ return handlePermissionRequest(input, name);
45
+ }
46
+
47
+ return null;
48
+ }