a4phone 1.1.1 → 1.1.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/bin/a4p.mjs +20 -9
- package/package.json +3 -3
- package/src/setup.mjs +8 -1
package/bin/a4p.mjs
CHANGED
|
@@ -13,9 +13,25 @@ import qrcode from 'qrcode-terminal';
|
|
|
13
13
|
|
|
14
14
|
const SETTINGS_PATH = path.join(os.homedir(), '.claude', 'settings.json');
|
|
15
15
|
|
|
16
|
+
function showHelp() {
|
|
17
|
+
console.log('a4phone — Claude Code / Codex 远程手机交互\n');
|
|
18
|
+
console.log('用法:');
|
|
19
|
+
console.log(' a4p setup 安装引导(生成话题、注册 Hook、显示二维码)');
|
|
20
|
+
console.log(' a4p out 外出模式(手机优先)');
|
|
21
|
+
console.log(' a4p home 终端优先模式(默认)');
|
|
22
|
+
console.log(' a4p status 查看当前模式');
|
|
23
|
+
console.log(' a4p test 发送测试通知');
|
|
24
|
+
console.log(' a4p uninstall 移除 Hook 和配置');
|
|
25
|
+
console.log(' a4p --version 查看版本号');
|
|
26
|
+
console.log(' a4p help 显示本帮助');
|
|
27
|
+
}
|
|
28
|
+
|
|
16
29
|
const cmd = process.argv[2];
|
|
17
30
|
|
|
18
|
-
if (cmd === '
|
|
31
|
+
if (cmd === '--version' || cmd === '-v' || cmd === 'version') {
|
|
32
|
+
const pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
|
|
33
|
+
console.log(pkg.version);
|
|
34
|
+
} else if (cmd === 'setup') {
|
|
19
35
|
const { runSetup } = await import('../src/setup.mjs');
|
|
20
36
|
qrcode.setErrorLevel('L');
|
|
21
37
|
await runSetup({ generateQR: (text, opts, cb) => qrcode.generate(text, opts, cb) });
|
|
@@ -59,13 +75,8 @@ if (cmd === 'setup') {
|
|
|
59
75
|
}
|
|
60
76
|
const ok = await sendNotification({ ...config, title: 'a4phone', message: '测试通知:如果手机收到,配置正常。' });
|
|
61
77
|
console.log(ok ? '测试通知发送成功。' : '发送失败,请检查网络。');
|
|
78
|
+
} else if (cmd === 'help' || cmd === '--help' || cmd === '-h') {
|
|
79
|
+
showHelp();
|
|
62
80
|
} else {
|
|
63
|
-
|
|
64
|
-
console.log('用法:');
|
|
65
|
-
console.log(' a4p setup 安装引导(生成话题、注册 Hook)');
|
|
66
|
-
console.log(' a4p out 外出模式(手机优先)');
|
|
67
|
-
console.log(' a4p home 终端优先模式(默认)');
|
|
68
|
-
console.log(' a4p status 查看当前模式');
|
|
69
|
-
console.log(' a4p test 发送测试通知');
|
|
70
|
-
console.log(' a4p uninstall 移除 Hook 和配置');
|
|
81
|
+
showHelp();
|
|
71
82
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "a4phone",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "Claude Code 远程手机交互:任务完成通知、AskUserQuestion 提问与 PermissionRequest 权限请求手机点选(ntfy.sh)",
|
|
3
|
+
"version": "1.1.3",
|
|
4
|
+
"description": "Claude Code / Codex 远程手机交互:任务完成通知、AskUserQuestion 提问与 PermissionRequest 权限请求手机点选(ntfy.sh)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"a4p": "
|
|
7
|
+
"a4p": "bin/a4p.mjs"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"bin",
|
package/src/setup.mjs
CHANGED
|
@@ -13,12 +13,17 @@ function generateTopic() {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
// 把 Hook 合并写入 settings.json(保留既有配置)
|
|
16
|
+
// 返回 true=新写入,false=已存在跳过
|
|
16
17
|
export function registerHooks(settingsPath, hookCommand) {
|
|
17
18
|
let settings = {};
|
|
18
19
|
try {
|
|
19
20
|
settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
|
|
20
21
|
} catch {}
|
|
21
22
|
|
|
23
|
+
// 已配置相同 Hook 则跳过
|
|
24
|
+
const existing = settings.hooks?.Stop?.[0]?.hooks?.[0]?.command;
|
|
25
|
+
if (existing === hookCommand) return false;
|
|
26
|
+
|
|
22
27
|
settings.hooks = {
|
|
23
28
|
Stop: [{ matcher: '*', hooks: [{ type: 'command', command: hookCommand }] }],
|
|
24
29
|
PreToolUse: [{ matcher: 'AskUserQuestion', hooks: [{ type: 'command', command: hookCommand }] }],
|
|
@@ -26,6 +31,7 @@ export function registerHooks(settingsPath, hookCommand) {
|
|
|
26
31
|
};
|
|
27
32
|
fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
|
|
28
33
|
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
|
|
34
|
+
return true;
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
export function unregisterHooks(settingsPath) {
|
|
@@ -116,7 +122,7 @@ export async function runSetup({ generateQR }) {
|
|
|
116
122
|
}
|
|
117
123
|
saveConfig(config);
|
|
118
124
|
|
|
119
|
-
registerHooks(SETTINGS_PATH, hookCommand());
|
|
125
|
+
const claudeConfigured = registerHooks(SETTINGS_PATH, hookCommand());
|
|
120
126
|
const codexConfigured = configureCodex();
|
|
121
127
|
|
|
122
128
|
const subscribeUrl = `${config.server}/${config.topic}`;
|
|
@@ -132,6 +138,7 @@ export async function runSetup({ generateQR }) {
|
|
|
132
138
|
}
|
|
133
139
|
|
|
134
140
|
process.stdout.write('\n在 ntfy App 添加订阅,输入话题名称或扫描上方二维码。\n');
|
|
141
|
+
process.stdout.write(`Claude Code 配置:${claudeConfigured ? '已自动写入 ~/.claude/settings.json' : '已存在,跳过'}\n`);
|
|
135
142
|
process.stdout.write(`Codex 配置:${codexConfigured ? '已自动写入 ~/.codex/config.toml' : '已存在,跳过'}\n`);
|
|
136
143
|
process.stdout.write('模式切换:a4p out(外出/手机优先) / a4p home(终端优先) / a4p status\n');
|
|
137
144
|
process.stdout.write('重启 Claude Code / Codex 会话后 Hook 生效。\n');
|