@abraca/mcp 2.49.0 → 2.51.0

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.
@@ -12975,6 +12975,7 @@ var HookBridge = class {
12975
12975
  this.server = server;
12976
12976
  this.httpServer = null;
12977
12977
  this._port = null;
12978
+ this.portFileTimer = null;
12978
12979
  this.portFilePath = process.env.ABRA_HOOK_PORT_FILE || node_path.join(node_os.homedir(), ".abracadabra-mcp-hook.port");
12979
12980
  }
12980
12981
  get port() {
@@ -12997,19 +12998,30 @@ var HookBridge = class {
12997
12998
  }
12998
12999
  this._port = addr.port;
12999
13000
  this.httpServer = srv;
13000
- try {
13001
- node_fs.writeFileSync(this.portFilePath, String(this._port), "utf-8");
13002
- } catch (err) {
13003
- console.error(`[hook-bridge] Warning: could not write port file: ${err.message}`);
13004
- }
13001
+ this.writePortFile();
13002
+ this.portFileTimer = setInterval(() => this.writePortFile(), 2e3);
13003
+ this.portFileTimer.unref?.();
13005
13004
  console.error(`[hook-bridge] Listening on 127.0.0.1:${this._port}`);
13006
13005
  console.error(`[hook-bridge] Port file: ${this.portFilePath}`);
13007
13006
  resolve(this._port);
13008
13007
  });
13009
13008
  });
13010
13009
  }
13010
+ /** Write the current listening port to the shared port file (best-effort). */
13011
+ writePortFile() {
13012
+ if (this._port == null) return;
13013
+ try {
13014
+ node_fs.writeFileSync(this.portFilePath, String(this._port), "utf-8");
13015
+ } catch (err) {
13016
+ console.error(`[hook-bridge] Warning: could not write port file: ${err.message}`);
13017
+ }
13018
+ }
13011
13019
  /** Shut down the HTTP server and remove the port file. */
13012
13020
  async destroy() {
13021
+ if (this.portFileTimer) {
13022
+ clearInterval(this.portFileTimer);
13023
+ this.portFileTimer = null;
13024
+ }
13013
13025
  if (this.httpServer) {
13014
13026
  await new Promise((resolve) => {
13015
13027
  this.httpServer.close(() => resolve());
@@ -13017,7 +13029,7 @@ var HookBridge = class {
13017
13029
  this.httpServer = null;
13018
13030
  }
13019
13031
  try {
13020
- node_fs.unlinkSync(this.portFilePath);
13032
+ if (node_fs.readFileSync(this.portFilePath, "utf-8").trim() === String(this._port)) node_fs.unlinkSync(this.portFilePath);
13021
13033
  } catch {}
13022
13034
  this._port = null;
13023
13035
  console.error("[hook-bridge] Shut down");