a4phone 1.7.2 → 1.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "a4phone",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "Claude Code / Codex / ZCode / Qoder / WorkBuddy / DSH 远程手机交互:任务完成通知(含 AI 最后输出)、提问/权限请求手机点选或文字作答、远程续聊(ntfy.sh;WorkBuddy 暂不支持续聊)",
5
5
  "type": "module",
6
6
  "bin": {
package/src/notify.mjs CHANGED
@@ -29,12 +29,36 @@ function Xml-Escape([string]\$value) {
29
29
  \$toast = [Windows.UI.Notifications.ToastNotification]::new(\$xmlDocument)
30
30
  [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier(\$env:A4P_TOAST_APPID).Show(\$toast)`;
31
31
 
32
+ // PowerShell 绝对路径(不走 PATH 解析:部分宿主进程的 PATH 不含
33
+ // System32\WindowsPowerShell\v1.0,spawn('powershell') 会直接 ENOENT)
34
+ function powershellExe() {
35
+ const root = process.env.SystemRoot || process.env.windir;
36
+ if (root) {
37
+ const abs = path.join(root, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe');
38
+ try { if (fs.existsSync(abs)) return abs; } catch {}
39
+ }
40
+ return 'powershell'; // 找不到就回退 PATH 解析,失败由 error 监听器兜住
41
+ }
42
+
43
+ // spawn 一个脱离的子进程弹通知。
44
+ // 关键:spawn 失败(ENOENT 等)是以 'error' 事件抛出的,没有监听器时属于
45
+ // unhandled error,会直接杀掉宿主进程——DSH/Codex 这类常驻进程每次任务完成都
46
+ // 调通知,一旦 PATH 异常就表现为“每完成一个任务进程就退出”。通知是尽力而为,
47
+ // 失败必须静默降级。
48
+ // 导出仅为便于单测覆盖监听器是否存在。
49
+ export function spawnDetached(cmd, args, opts) {
50
+ const child = spawn(cmd, args, opts);
51
+ child.on('error', () => {});
52
+ child.unref();
53
+ return child;
54
+ }
55
+
32
56
  // 直接 spawn PowerShell 弹系统通知(低层原语,守护进程代发时用)
33
57
  function showBalloon(title, message) {
34
58
  // 立即返回,不阻塞调用方
35
59
  const clean = (s) => (s || '').replace(/"/g, "'");
36
60
  if (process.platform === 'win32') {
37
- const child = spawn('powershell', ['-NoProfile', '-Sta', '-WindowStyle', 'Hidden', '-Command', WINDOWS_TOAST_SCRIPT], {
61
+ spawnDetached(powershellExe(), ['-NoProfile', '-Sta', '-WindowStyle', 'Hidden', '-Command', WINDOWS_TOAST_SCRIPT], {
38
62
  env: {
39
63
  ...process.env,
40
64
  A4P_TOAST_APPID: WINDOWS_POWERSHELL_AUMID,
@@ -45,15 +69,15 @@ function showBalloon(title, message) {
45
69
  stdio: 'ignore',
46
70
  windowsHide: true,
47
71
  });
48
- child.unref();
49
72
  return;
50
73
  }
51
74
  const t = clean(title);
52
75
  const m = clean(message);
53
- const child = process.platform === 'darwin'
54
- ? spawn('osascript', ['-e', `display notification "${m}" with title "${t}"`], { stdio: 'ignore' })
55
- : spawn('notify-send', [t, m], { stdio: 'ignore' });
56
- child.unref();
76
+ if (process.platform === 'darwin') {
77
+ spawnDetached('osascript', ['-e', `display notification "${m}" with title "${t}"`], { stdio: 'ignore' });
78
+ } else {
79
+ spawnDetached('notify-send', [t, m], { stdio: 'ignore' });
80
+ }
57
81
  }
58
82
 
59
83
  // 守护进程是否在运行(读 daemon.json 的 pid 探测存活)
package/src/setup.mjs CHANGED
@@ -3,7 +3,7 @@ import crypto from 'crypto';
3
3
  import fs from 'fs';
4
4
  import os from 'os';
5
5
  import path from 'path';
6
- import { fileURLToPath } from 'url';
6
+ import { fileURLToPath, pathToFileURL } from 'url';
7
7
  import { loadConfig, saveConfig } from './config.mjs';
8
8
 
9
9
  const SETTINGS_PATH = path.join(os.homedir(), '.claude', 'settings.json');
@@ -353,7 +353,8 @@ export function unconfigureZcode(zcodePath = ZCODE_CONFIG_PATH) {
353
353
  // 以 insert 形式追加到各 profile 的 cordis.patch.yml(热生效,无需重启)。
354
354
  // profile 发现机制:扫描 ~/.dsh/profiles/ 下所有含 cordis.yml 的子目录
355
355
  // (web / tui / dsh-tui 及后续新装的变体均可覆盖),插件 name 按各 profile
356
- // 目录分别计算相对路径;守护进程(a4p listen)周期重扫,新装 profile 自动补挂。
356
+ // 目录分别计算(同盘相对路径;跨盘退化为 file:// URL,见 dshPluginName);
357
+ // 守护进程(a4p listen)周期重扫,新装 profile 自动补挂。
357
358
  const DSH_PROFILES_DIR = path.join(os.homedir(), '.dsh', 'profiles');
358
359
  const DSH_MARKER_START = '# ===== a4phone dsh-hook (auto-generated) =====';
359
360
  const DSH_MARKER_END = '# ===== end a4phone dsh-hook =====';
@@ -368,6 +369,17 @@ function toPosix(p) {
368
369
  return p.split(path.sep).join('/');
369
370
  }
370
371
 
372
+ // 计算挂载条目里的插件 name(DSH loader 把它当 URL 解析):
373
+ // 同盘 → profile 相对路径(可移植,profile 目录整体搬家后仍有效);
374
+ // 跨盘 → Windows 的 path.relative 会直接返回绝对路径(如 E:/a4phone/...),
375
+ // loader 会把 `e:` 当成 URL 协议,启动即报 ERR_UNSUPPORTED_ESM_URL_SCHEME。
376
+ // 这种情况改用 file:// URL(唯一合法的 Windows 绝对路径写法)。
377
+ function dshPluginName(profileDir, pluginEntry) {
378
+ const rel = path.relative(profileDir, pluginEntry);
379
+ if (path.isAbsolute(rel)) return pathToFileURL(pluginEntry).href;
380
+ return toPosix(rel);
381
+ }
382
+
371
383
  // 生成 dsh-hook 的 patch 挂载块(marker 包裹,便于幂等替换/清理)
372
384
  function dshHookBlock(relName) {
373
385
  return `${DSH_MARKER_START}\n- insert:\n - id: dsh-hook\n name: "${relName}"\n${DSH_MARKER_END}`;
@@ -433,8 +445,8 @@ function mountDshHook({ profileDir, pluginEntry }) {
433
445
  let content = '';
434
446
  try { content = fs.readFileSync(patchPath, 'utf-8'); } catch {}
435
447
 
436
- // 已挂载本插件的最新相对路径 → 幂等跳过
437
- const rel = toPosix(path.relative(profileDir, pluginEntry));
448
+ // 已挂载本插件的最新路径 → 幂等跳过
449
+ const rel = dshPluginName(profileDir, pluginEntry);
438
450
  const block = dshHookBlock(rel);
439
451
  if (content.includes(DSH_MARKER_START) && content.includes(block)) return false;
440
452