Skip to content

Commit 3d87f8d

Browse files
ByteBard97claude
andcommitted
feat: write runtime port file for frontend discovery
After binding to a port (which may differ from configured due to auto-retry), writes the actual port number to {config_dir}/port. Removes the file on shutdown to prevent stale discovery. Frontends can read ~/Library/Application Support/{PluginName}/port to find the correct port, then verify via /health that the plugin identity matches. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bb1af6b commit 3d87f8d

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

plugin/src/HttpServer.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include <nlohmann/json.hpp>
2828

2929
#include <chrono>
30+
#include <cstdio>
31+
#include <fstream>
3032
#include <memory>
3133

3234
using json = nlohmann::json;
@@ -143,6 +145,12 @@ void HttpServer::Stop() {
143145
gServer.reset();
144146
}
145147

148+
// Remove runtime port file so stale ports aren't discovered
149+
{
150+
std::string portFilePath = ConfigManager::GetConfigDir() + "/port";
151+
std::remove(portFilePath.c_str());
152+
}
153+
146154
ready_.store(false);
147155
}
148156

@@ -602,6 +610,17 @@ void HttpServer::ServerThread() {
602610
}
603611
}
604612

613+
// Write a runtime port file so frontends can discover which port we bound to.
614+
// This is especially useful when port auto-retry shifted us to a different port.
615+
// File goes next to config: ~/Library/Application Support/{PluginName}/port
616+
{
617+
std::string portFilePath = ConfigManager::GetConfigDir() + "/port";
618+
std::ofstream portFile(portFilePath);
619+
if (portFile.is_open()) {
620+
portFile << port_;
621+
}
622+
}
623+
605624
// Mark as ready
606625
ready_.store(true);
607626

0 commit comments

Comments
 (0)