@fangyb/ahchat-bridge 0.1.12 → 0.1.13

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/dist/cli.cjs CHANGED
@@ -50536,8 +50536,7 @@ function installClaudeCli() {
50536
50536
  const envPath = process.env.PATH ?? "(unset)";
50537
50537
  logger24.error("claude not found after successful npm install -g", {
50538
50538
  npmGlobalBin: npmBin ?? "unknown",
50539
- pathDirectories: envPath.split(":").slice(0, 10),
50540
- // first 10 to avoid log spam
50539
+ pathDirectories: envPath.split(process.platform === "win32" ? ";" : ":").slice(0, 10),
50541
50540
  npmPrefix: (0, import_node_child_process2.execSync)("npm prefix -g", { timeout: 5e3 }).toString().trim() || "unknown"
50542
50541
  });
50543
50542
  return void 0;
@@ -51386,9 +51385,13 @@ var import_node_fs9 = __toESM(require("fs"), 1);
51386
51385
  var import_node_os12 = __toESM(require("os"), 1);
51387
51386
  var import_node_path20 = __toESM(require("path"), 1);
51388
51387
  var logger29 = createModuleLogger("bridge.protocol");
51389
- function getBridgeExePath() {
51390
- const pkgDir = import_node_path20.default.resolve(__dirname, "..");
51391
- return import_node_path20.default.join(pkgDir, "dist", "cli.cjs");
51388
+ function getStableExePath() {
51389
+ const bridgeDir = import_node_path20.default.join(import_node_os12.default.homedir(), ".ahchat", "bridge");
51390
+ import_node_fs9.default.mkdirSync(bridgeDir, { recursive: true });
51391
+ const stablePath = import_node_path20.default.join(bridgeDir, "cli.cjs");
51392
+ import_node_fs9.default.copyFileSync(__filename, stablePath);
51393
+ if (process.platform !== "win32") import_node_fs9.default.chmodSync(stablePath, 493);
51394
+ return stablePath;
51392
51395
  }
51393
51396
  function registerProtocolHandler() {
51394
51397
  const platform = import_node_os12.default.platform();
@@ -51402,99 +51405,106 @@ function registerProtocolHandler() {
51402
51405
  logger29.info("Protocol handler registered", { platform });
51403
51406
  }
51404
51407
  function registerWindows() {
51405
- const exe = getBridgeExePath();
51406
51408
  const nodeExe = process.execPath;
51407
- const ahchatDir = import_node_path20.default.join(import_node_os12.default.homedir(), ".ahchat");
51408
- const urlFilePath = import_node_path20.default.join(ahchatDir, ".bridge-launch-url");
51409
- import_node_fs9.default.mkdirSync(ahchatDir, { recursive: true });
51410
- const psScriptPath = import_node_path20.default.join(ahchatDir, "launch-bridge.ps1");
51411
- const psContent = `param([string]$url)
51412
- if (-not $url) {
51413
- if (Test-Path '${urlFilePath}') {
51414
- $url = Get-Content '${urlFilePath}' -Raw
51409
+ const stableExePath = getStableExePath();
51410
+ const bridgeDir = import_node_path20.default.join(import_node_os12.default.homedir(), ".ahchat", "bridge");
51411
+ const psLauncherPath = import_node_path20.default.join(bridgeDir, "launch-bridge.ps1");
51412
+ import_node_fs9.default.writeFileSync(
51413
+ psLauncherPath,
51414
+ [
51415
+ `param([string]$url)`,
51416
+ `& '${nodeExe.replace(/'/g, "''")}' '${stableExePath.replace(/'/g, "''")}' launch --url $url`
51417
+ ].join("\r\n")
51418
+ );
51419
+ const handlerValue = `powershell -ExecutionPolicy Bypass -File "${psLauncherPath}" -url "%1"`;
51420
+ const psRegisterPath = import_node_path20.default.join(bridgeDir, "register-protocol.ps1");
51421
+ import_node_fs9.default.writeFileSync(
51422
+ psRegisterPath,
51423
+ [
51424
+ `$handler = '${handlerValue.replace(/'/g, "''")}'`,
51425
+ `$icon = '${nodeExe.replace(/'/g, "''")}'`,
51426
+ `New-Item -Path 'HKCU:\\Software\\Classes\\ahchat' -Force | Out-Null`,
51427
+ `Set-ItemProperty -Path 'HKCU:\\Software\\Classes\\ahchat' -Name '(Default)' -Value 'URL:ahchat' -Force`,
51428
+ `New-ItemProperty -Path 'HKCU:\\Software\\Classes\\ahchat' -Name 'URL Protocol' -Value '' -PropertyType String -Force | Out-Null`,
51429
+ `New-Item -Path 'HKCU:\\Software\\Classes\\ahchat\\DefaultIcon' -Force | Out-Null`,
51430
+ `Set-ItemProperty -Path 'HKCU:\\Software\\Classes\\ahchat\\DefaultIcon' -Name '(Default)' -Value $icon -Force`,
51431
+ `New-Item -Path 'HKCU:\\Software\\Classes\\ahchat\\shell\\open\\command' -Force | Out-Null`,
51432
+ `Set-ItemProperty -Path 'HKCU:\\Software\\Classes\\ahchat\\shell\\open\\command' -Name '(Default)' -Value $handler -Force`
51433
+ ].join("\r\n")
51434
+ );
51435
+ try {
51436
+ (0, import_node_child_process3.execSync)(`powershell -ExecutionPolicy Bypass -File "${psRegisterPath}"`, { stdio: "pipe" });
51437
+ } catch (e7) {
51438
+ logger29.error("Failed to register Windows protocol handler", { error: e7 });
51439
+ throw new Error("Failed to register Windows protocol handler");
51415
51440
  }
51441
+ logger29.info("Windows protocol handler registered", { psLauncherPath });
51416
51442
  }
51417
- if (-not $url) {
51418
- Write-Error "No URL provided"
51419
- exit 1
51420
- }
51421
- & '${nodeExe}' '${exe}' launch --url $url
51422
- `;
51423
- import_node_fs9.default.writeFileSync(psScriptPath, psContent);
51424
- const handler = `powershell -ExecutionPolicy Bypass -File "${psScriptPath}" -url "%1"`;
51425
- const regCommands = [
51426
- `REG ADD "HKCU\\Software\\Classes\\ahchat" /ve /d "URL:ahchat" /f`,
51427
- `REG ADD "HKCU\\Software\\Classes\\ahchat" /v "URL Protocol" /d "" /f`,
51428
- `REG ADD "HKCU\\Software\\Classes\\ahchat\\DefaultIcon" /ve /d "${nodeExe}" /f`,
51429
- `REG ADD "HKCU\\Software\\Classes\\ahchat\\shell\\open\\command" /ve /t REG_SZ /d "${handler}" /f`
51430
- ];
51431
- for (const cmd of regCommands) {
51443
+ function registerMacOS() {
51444
+ const appDir = import_node_path20.default.join(import_node_os12.default.homedir(), "Applications", "AHChatBridge.app");
51445
+ const nodeExe = process.execPath;
51446
+ const stableExePath = getStableExePath();
51447
+ const bridgeDir = import_node_path20.default.join(import_node_os12.default.homedir(), ".ahchat", "bridge");
51448
+ const launchScriptPath = import_node_path20.default.join(bridgeDir, "launch-bridge.sh");
51449
+ import_node_fs9.default.writeFileSync(
51450
+ launchScriptPath,
51451
+ `#!/bin/bash
51452
+ exec ${JSON.stringify(nodeExe)} ${JSON.stringify(stableExePath)} launch --url "$1"
51453
+ `
51454
+ );
51455
+ import_node_fs9.default.chmodSync(launchScriptPath, 493);
51456
+ const escapedScriptPath = launchScriptPath.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
51457
+ const appleScript = [
51458
+ `on open location thisURL`,
51459
+ ` set launchScript to "${escapedScriptPath}"`,
51460
+ ` do shell script "/bin/bash " & (quoted form of launchScript) & " " & (quoted form of thisURL) & " >/tmp/ahchat-bridge.log 2>&1 &"`,
51461
+ `end open location`
51462
+ ].join("\n");
51463
+ const tmpScript = import_node_path20.default.join(import_node_os12.default.tmpdir(), "AHChatBridge.applescript");
51464
+ import_node_fs9.default.writeFileSync(tmpScript, appleScript);
51465
+ try {
51466
+ import_node_fs9.default.rmSync(appDir, { recursive: true, force: true });
51467
+ } catch {
51468
+ }
51469
+ try {
51470
+ (0, import_node_child_process3.execSync)(`osacompile -o ${JSON.stringify(appDir)} ${JSON.stringify(tmpScript)}`, { stdio: "pipe" });
51471
+ } finally {
51432
51472
  try {
51433
- (0, import_node_child_process3.execSync)(cmd, { stdio: "pipe" });
51434
- } catch (e7) {
51435
- logger29.error("Failed to register Windows protocol handler", { error: e7, cmd });
51436
- throw new Error(`Failed to register protocol handler: ${cmd}`);
51473
+ import_node_fs9.default.unlinkSync(tmpScript);
51474
+ } catch {
51437
51475
  }
51438
51476
  }
51439
- logger29.info("Windows protocol handler registered", { psScriptPath });
51440
- }
51441
- function registerMacOS() {
51442
- const appDir = import_node_path20.default.join(import_node_os12.default.homedir(), "Applications", "AHChatBridge.app");
51443
- const contentsDir = import_node_path20.default.join(appDir, "Contents");
51444
- const macosDir = import_node_path20.default.join(contentsDir, "MacOS");
51445
- const resourcesDir = import_node_path20.default.join(contentsDir, "Resources");
51446
- import_node_fs9.default.mkdirSync(macosDir, { recursive: true });
51447
- import_node_fs9.default.mkdirSync(resourcesDir, { recursive: true });
51448
- const infoPlist = `<?xml version="1.0" encoding="UTF-8"?>
51449
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
51450
- <plist version="1.0">
51451
- <dict>
51452
- <key>CFBundleName</key>
51453
- <string>AHChatBridge</string>
51454
- <key>CFBundleDisplayName</key>
51455
- <string>AHChat Bridge</string>
51456
- <key>CFBundleIdentifier</key>
51457
- <string>com.fangyb.ahchat-bridge</string>
51458
- <key>CFBundleVersion</key>
51459
- <string>0.1.0</string>
51460
- <key>CFBundlePackageType</key>
51461
- <string>APPL</string>
51462
- <key>CFBundleExecutable</key>
51463
- <string>launch.sh</string>
51464
- <key>CFBundleURLTypes</key>
51465
- <array>
51466
- <dict>
51467
- <key>CFBundleURLName</key>
51468
- <string>AHChat Bridge</string>
51469
- <key>CFBundleURLSchemes</key>
51470
- <array>
51471
- <string>ahchat</string>
51472
- </array>
51473
- </dict>
51474
- </array>
51475
- </dict>
51476
- </plist>`;
51477
- const launchScript = `#!/bin/bash
51478
- URL="$1"
51479
- exec "${process.execPath}" "${getBridgeExePath()}" launch --url "$URL"`;
51480
- import_node_fs9.default.writeFileSync(import_node_path20.default.join(contentsDir, "Info.plist"), infoPlist);
51481
- import_node_fs9.default.writeFileSync(import_node_path20.default.join(macosDir, "launch.sh"), launchScript);
51482
- import_node_fs9.default.chmodSync(import_node_path20.default.join(macosDir, "launch.sh"), 493);
51477
+ const plistPath = import_node_path20.default.join(appDir, "Contents", "Info.plist");
51478
+ const urlTypes = JSON.stringify([{ CFBundleURLName: "AHChat Bridge", CFBundleURLSchemes: ["ahchat"] }]);
51479
+ (0, import_node_child_process3.execSync)(
51480
+ `/usr/bin/plutil -insert CFBundleURLTypes -json ${JSON.stringify(urlTypes)} ${JSON.stringify(plistPath)}`,
51481
+ { stdio: "pipe" }
51482
+ );
51483
+ const lsregister = "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister";
51484
+ try {
51485
+ (0, import_node_child_process3.execSync)(`${lsregister} -f ${JSON.stringify(appDir)}`, { stdio: "pipe" });
51486
+ } catch (e7) {
51487
+ logger29.warn("lsregister failed; URL scheme registration may be delayed", { error: e7 });
51488
+ }
51483
51489
  logger29.info("macOS protocol handler registered", { appDir });
51484
51490
  }
51485
51491
  function registerLinux() {
51486
- const desktopFile = `[Desktop Entry]
51487
- Name=AHChat Bridge
51488
- Exec=${process.execPath} ${getBridgeExePath()} launch --url %u
51489
- Type=Application
51490
- NoDisplay=true
51491
- MimeType=x-scheme-handler/ahchat;`;
51492
+ const stableExePath = getStableExePath();
51493
+ const desktopFile = [
51494
+ `[Desktop Entry]`,
51495
+ `Name=AHChat Bridge`,
51496
+ `Exec=${process.execPath} ${stableExePath} launch --url %u`,
51497
+ `Type=Application`,
51498
+ `NoDisplay=true`,
51499
+ `MimeType=x-scheme-handler/ahchat;`
51500
+ ].join("\n");
51492
51501
  const desktopPath = import_node_path20.default.join(import_node_os12.default.homedir(), ".local", "share", "applications", "ahchat-bridge.desktop");
51493
51502
  import_node_fs9.default.mkdirSync(import_node_path20.default.dirname(desktopPath), { recursive: true });
51494
51503
  import_node_fs9.default.writeFileSync(desktopPath, desktopFile);
51495
51504
  try {
51496
51505
  (0, import_node_child_process3.execSync)("update-desktop-database ~/.local/share/applications/", { stdio: "pipe" });
51497
- } catch {
51506
+ } catch (e7) {
51507
+ logger29.warn("update-desktop-database not available; run it manually if needed", { error: e7 });
51498
51508
  }
51499
51509
  logger29.info("Linux protocol handler registered", { desktopPath });
51500
51510
  }
@@ -51502,16 +51512,16 @@ function unregisterProtocolHandler() {
51502
51512
  const platform = import_node_os12.default.platform();
51503
51513
  if (platform === "win32") {
51504
51514
  try {
51505
- (0, import_node_child_process3.execSync)('REG DELETE "HKCU\\Software\\Classes\\ahchat" /f', { stdio: "pipe" });
51506
- const psScriptPath = import_node_path20.default.join(import_node_os12.default.homedir(), ".ahchat", "launch-bridge.ps1");
51507
- const urlFilePath = import_node_path20.default.join(import_node_os12.default.homedir(), ".ahchat", ".bridge-launch-url");
51508
- try {
51509
- import_node_fs9.default.unlinkSync(psScriptPath);
51510
- } catch {
51511
- }
51512
- try {
51513
- import_node_fs9.default.unlinkSync(urlFilePath);
51514
- } catch {
51515
+ (0, import_node_child_process3.execSync)(
51516
+ `powershell -ExecutionPolicy Bypass -Command "Remove-Item -Path 'HKCU:\\Software\\Classes\\ahchat' -Recurse -Force -ErrorAction SilentlyContinue"`,
51517
+ { stdio: "pipe" }
51518
+ );
51519
+ const bridgeDir = import_node_path20.default.join(import_node_os12.default.homedir(), ".ahchat", "bridge");
51520
+ for (const f7 of ["launch-bridge.ps1", "register-protocol.ps1"]) {
51521
+ try {
51522
+ import_node_fs9.default.unlinkSync(import_node_path20.default.join(bridgeDir, f7));
51523
+ } catch {
51524
+ }
51515
51525
  }
51516
51526
  logger29.info("Windows protocol handler unregistered");
51517
51527
  } catch (e7) {
@@ -51581,7 +51591,7 @@ async function run(args) {
51581
51591
  }
51582
51592
  if (args.token) config2 = { ...config2, bridgeToken: args.token };
51583
51593
  if (args.dataDir) {
51584
- const resolved = args.dataDir.startsWith("~/") ? import_node_path21.default.join(import_node_os13.default.homedir(), args.dataDir.slice(2)) : args.dataDir;
51594
+ const resolved = /^~[/\\]/.test(args.dataDir) ? import_node_path21.default.join(import_node_os13.default.homedir(), args.dataDir.slice(2)) : args.dataDir;
51585
51595
  config2 = { ...config2, dataDir: resolved };
51586
51596
  }
51587
51597
  if (args.logLevel) config2 = { ...config2, logLevel: args.logLevel };
package/dist/index.js CHANGED
@@ -49949,8 +49949,7 @@ function installClaudeCli() {
49949
49949
  const envPath = process.env.PATH ?? "(unset)";
49950
49950
  logger24.error("claude not found after successful npm install -g", {
49951
49951
  npmGlobalBin: npmBin ?? "unknown",
49952
- pathDirectories: envPath.split(":").slice(0, 10),
49953
- // first 10 to avoid log spam
49952
+ pathDirectories: envPath.split(process.platform === "win32" ? ";" : ":").slice(0, 10),
49954
49953
  npmPrefix: execSync("npm prefix -g", { timeout: 5e3 }).toString().trim() || "unknown"
49955
49954
  });
49956
49955
  return void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fangyb/ahchat-bridge",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "files": [
5
5
  "dist"
6
6
  ],