a4phone 1.1.1 → 1.1.2
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/package.json +1 -1
- package/src/setup.mjs +8 -1
package/package.json
CHANGED
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');
|