a4phone 1.1.0 → 1.1.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
@@ -35,8 +35,10 @@ if (cmd === 'setup') {
35
35
  } catch {
36
36
  process.exit(0);
37
37
  }
38
+ // 可选的 agent 标识:a4p hook [codex|claude],默认 claude
39
+ const agent = process.argv[3] === 'codex' ? 'codex' : 'claude';
38
40
  const { dispatchHook } = await import('../src/hook.mjs');
39
- const result = await dispatchHook(input);
41
+ const result = await dispatchHook(input, agent);
40
42
  if (result) {
41
43
  process.stdout.write(JSON.stringify(result) + '\n');
42
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "a4phone",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Claude Code 远程手机交互:任务完成通知、AskUserQuestion 提问与 PermissionRequest 权限请求手机点选(ntfy.sh)",
5
5
  "type": "module",
6
6
  "bin": {
package/src/asku.mjs CHANGED
@@ -3,7 +3,7 @@ import crypto from 'crypto';
3
3
  import { loadConfig } from './config.mjs';
4
4
  import { sendNotification, waitForResponse } from './ntfy.mjs';
5
5
 
6
- export async function handleAskUserQuestion(input) {
6
+ export async function handleAskUserQuestion(input, agentName) {
7
7
  const config = loadConfig();
8
8
  const questions = input.tool_input?.questions || [];
9
9
  if (!config.topic || !questions.length) return null;
@@ -25,7 +25,7 @@ export async function handleAskUserQuestion(input) {
25
25
  options.forEach((o, i) => lines.push(`${i + 1}. ${o.label}`));
26
26
  const sent = await sendNotification({
27
27
  ...config,
28
- title: `Claude Code: ${q.header || 'Question'}`,
28
+ title: `${agentName}: ${q.header || 'Question'}`,
29
29
  message: lines.join('\n'),
30
30
  actions,
31
31
  });
package/src/hook.mjs CHANGED
@@ -5,25 +5,31 @@ import { handleStop } from './stop.mjs';
5
5
  import { handleAskUserQuestion } from './asku.mjs';
6
6
  import { handlePermissionRequest } from './permission.mjs';
7
7
 
8
+ // 根据 agent 标识返回显示名称
9
+ export function agentName(agent) {
10
+ return agent === 'codex' ? 'Codex' : 'Claude Code';
11
+ }
12
+
8
13
  // 返回 hook 输出对象,或 null(null = 不干预,走终端默认流程)
9
- export async function dispatchHook(input) {
14
+ export async function dispatchHook(input, agent) {
10
15
  const event = input.hook_event_name;
11
16
  const isOut = readMode() === 'out';
17
+ const name = agentName(agent);
12
18
 
13
19
  if (event === 'Stop') {
14
- return handleStop(input);
20
+ return handleStop(input, name);
15
21
  }
16
22
 
17
23
  if (event === 'PreToolUse' && input.tool_name === 'AskUserQuestion') {
18
- await systemNotify('Claude Code', '有提问需要处理');
24
+ await systemNotify(name, '有提问需要处理');
19
25
  if (!isOut) return null; // 终端优先:不阻塞
20
- return handleAskUserQuestion(input);
26
+ return handleAskUserQuestion(input, name);
21
27
  }
22
28
 
23
29
  if (event === 'PermissionRequest') {
24
- await systemNotify('Claude Code', '有权限请求需要处理');
30
+ await systemNotify(name, '有权限请求需要处理');
25
31
  if (!isOut) return null; // 终端优先:不阻塞
26
- return handlePermissionRequest(input);
32
+ return handlePermissionRequest(input, name);
27
33
  }
28
34
 
29
35
  return null;
@@ -27,7 +27,7 @@ function formatMessage(tool_name, tool_input) {
27
27
  return message.length > MESSAGE_MAX_LENGTH ? message.slice(0, MESSAGE_MAX_LENGTH) + '...' : message;
28
28
  }
29
29
 
30
- export async function handlePermissionRequest(input) {
30
+ export async function handlePermissionRequest(input, agentName) {
31
31
  const config = loadConfig();
32
32
  if (!config.topic) return null;
33
33
 
@@ -43,7 +43,7 @@ export async function handlePermissionRequest(input) {
43
43
  actions.splice(1, 0, { action: 'http', label: 'Always Approve', url, method: 'POST', clear: false, body: JSON.stringify({ requestId, approved: true, alwaysAllow: true }) });
44
44
  }
45
45
 
46
- const sent = await sendNotification({ ...config, title: `Claude Code: ${tool_name}`, message, actions });
46
+ const sent = await sendNotification({ ...config, title: `${agentName}: ${tool_name}`, message, actions });
47
47
  if (!sent) return null;
48
48
 
49
49
  const isPlan = tool_name === 'ExitPlanMode';
package/src/setup.mjs CHANGED
@@ -48,22 +48,23 @@ const CODEX_MARKER_START = '# ===== a4phone hooks (auto-generated) =====';
48
48
  const CODEX_MARKER_END = '# ===== end a4phone hooks =====';
49
49
 
50
50
  // 生成 Codex 的 Hook 定义(数组嵌套表格,根级别)
51
+ // 命令带 codex 标识,便于 a4phone 动态显示触发方名称
51
52
  function codexHooksDefs() {
52
53
  return `[[hooks.Stop]]
53
54
  [[hooks.Stop.hooks]]
54
55
  type = "command"
55
- command = "a4p hook"
56
+ command = "a4p hook codex"
56
57
 
57
58
  [[hooks.PreToolUse]]
58
59
  matcher = "AskUserQuestion"
59
60
  [[hooks.PreToolUse.hooks]]
60
61
  type = "command"
61
- command = "a4p hook"
62
+ command = "a4p hook codex"
62
63
 
63
64
  [[hooks.PermissionRequest]]
64
65
  [[hooks.PermissionRequest.hooks]]
65
66
  type = "command"
66
- command = "a4p hook"`;
67
+ command = "a4p hook codex"`;
67
68
  }
68
69
 
69
70
  // 写入 Codex 配置(保留既有内容,幂等)
package/src/stop.mjs CHANGED
@@ -3,16 +3,16 @@ import { loadConfig } from './config.mjs';
3
3
  import { sendNotification } from './ntfy.mjs';
4
4
  import { systemNotify } from './notify.mjs';
5
5
 
6
- export async function handleStop(input) {
6
+ export async function handleStop(input, agentName) {
7
7
  const config = loadConfig();
8
8
  const cwd = input.cwd || '未知目录';
9
9
  const session = input.session_id ? input.session_id.slice(0, 8) : '—';
10
10
  const details = `任务已完成\n目录: ${cwd}\n会话: ${session}`;
11
- await systemNotify('Claude Code', '任务已完成');
11
+ await systemNotify(agentName, '任务已完成');
12
12
  if (config.topic) {
13
13
  await sendNotification({
14
14
  ...config,
15
- title: 'Claude Code',
15
+ title: agentName,
16
16
  message: details,
17
17
  });
18
18
  }