ghost-bridge 1.0.1 → 1.0.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/dist/cli.js CHANGED
@@ -5451,6 +5451,13 @@ var require_lib = __commonJS({
5451
5451
  });
5452
5452
 
5453
5453
  // lib/utils.js
5454
+ var utils_exports = {};
5455
+ __export(utils_exports, {
5456
+ getExtensionPath: () => getExtensionPath,
5457
+ getServerCommandConfig: () => getServerCommandConfig,
5458
+ getServerPath: () => getServerPath,
5459
+ getUserExtensionDir: () => getUserExtensionDir
5460
+ });
5454
5461
  import path from "path";
5455
5462
  import os2 from "os";
5456
5463
  import { fileURLToPath } from "url";
@@ -6011,6 +6018,8 @@ import { fileURLToPath as fileURLToPath2 } from "url";
6011
6018
  import path5 from "path";
6012
6019
  import fs5 from "fs";
6013
6020
  import os7 from "os";
6021
+ import net from "net";
6022
+ import { spawn } from "child_process";
6014
6023
  var __filename = fileURLToPath2(import.meta.url);
6015
6024
  var __dirname = path5.dirname(__filename);
6016
6025
  var packageJsonParams = JSON.parse(
@@ -6036,22 +6045,54 @@ program2.command("extension").description("Show the path to the Chrome extension
6036
6045
  process.exit(1);
6037
6046
  }
6038
6047
  });
6039
- program2.command("start").description("Start the Ghost Bridge MCP server directly").action(async () => {
6048
+ function waitForTcp(port, timeoutMs = 15e3) {
6049
+ return new Promise((resolve) => {
6050
+ const deadline = Date.now() + timeoutMs;
6051
+ const tryOnce = () => {
6052
+ const sock = net.connect(port, "127.0.0.1");
6053
+ sock.once("connect", () => {
6054
+ sock.destroy();
6055
+ resolve(true);
6056
+ });
6057
+ sock.once("error", () => {
6058
+ sock.destroy();
6059
+ if (Date.now() > deadline) resolve(false);
6060
+ else setTimeout(tryOnce, 300);
6061
+ });
6062
+ };
6063
+ tryOnce();
6064
+ });
6065
+ }
6066
+ program2.command("start").description("Start the resident ghost-bridge daemon (idempotent)").action(async () => {
6040
6067
  try {
6041
- console.log(source_default.blue("Starting Ghost Bridge Server..."));
6042
- const serverPath = path5.join(__dirname, "../src/server.js");
6043
- if (fs5.existsSync(serverPath)) {
6044
- await import(serverPath);
6045
- } else {
6046
- const rootServerPath = path5.join(__dirname, "../server.js");
6047
- if (fs5.existsSync(rootServerPath)) {
6048
- await import(rootServerPath);
6049
- } else {
6050
- throw new Error("Could not find server.js");
6051
- }
6068
+ const { getServerPath: getServerPath2 } = await Promise.resolve().then(() => (init_utils(), utils_exports));
6069
+ const serverPath = getServerPath2();
6070
+ if (!fs5.existsSync(serverPath)) {
6071
+ throw new Error(`\u672A\u627E\u5230 server: ${serverPath}`);
6072
+ }
6073
+ const entry = readPortInfoFile();
6074
+ if (entry && isProcessAlive(entry.pid)) {
6075
+ console.log(source_default.green(`\u5E38\u9A7B\u670D\u52A1\u5DF2\u5728\u8FD0\u884C (PID: ${entry.pid}, \u7AEF\u53E3: ${entry.port})`));
6076
+ return;
6077
+ }
6078
+ console.log(source_default.blue(`\u6B63\u5728\u542F\u52A8\u5E38\u9A7B\u670D\u52A1 (${serverPath})...`));
6079
+ const child = spawn(process.execPath, [serverPath], {
6080
+ detached: true,
6081
+ stdio: "ignore",
6082
+ env: { ...process.env, GHOST_BRIDGE_DAEMON: "1" }
6083
+ });
6084
+ child.unref();
6085
+ const port = Number(process.env.GHOST_BRIDGE_PORT || 33333);
6086
+ const ok = await waitForTcp(port);
6087
+ if (!ok) {
6088
+ console.error(source_default.red(`\u670D\u52A1\u672A\u80FD\u5728\u9884\u671F\u65F6\u95F4\u5185\u5728\u7AEF\u53E3 ${port} \u5C31\u7EEA\uFF0C\u53EF\u67E5\u770B ~/.ghost-bridge/daemon.log`));
6089
+ process.exit(1);
6052
6090
  }
6091
+ const fresh = readPortInfoFile();
6092
+ console.log(source_default.green(`\u2705 ghost-bridge \u5E38\u9A7B\u670D\u52A1\u5DF2\u542F\u52A8 (PID: ${fresh?.pid ?? "-"}, \u7AEF\u53E3: ${port})`));
6093
+ console.log(source_default.dim("\u65E5\u5FD7: ~/.ghost-bridge/daemon.log | \u505C\u6B62: ghost-bridge stop"));
6053
6094
  } catch (error) {
6054
- console.error(source_default.red("Error starting server:"), error);
6095
+ console.error(source_default.red("Error starting daemon:"), error);
6055
6096
  process.exit(1);
6056
6097
  }
6057
6098
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Ghost Bridge",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "description": "Zero-restart Chrome debugger bridge for Claude MCP, optimized for no-sourcemap production debugging.",
6
6
  "permissions": [
7
7
  "debugger",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ghost-bridge",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Ghost Bridge: Zero-restart Chrome debugger bridge for Claude MCP. Includes CLI for easy setup.",