Add port discovery for automatic daemon detection#13
Open
Nic-dorman wants to merge 4 commits intomainfrom
Open
Add port discovery for automatic daemon detection#13Nic-dorman wants to merge 4 commits intomainfrom
Nic-dorman wants to merge 4 commits intomainfrom
Conversation
antd now writes a daemon.port file on startup containing the REST and gRPC ports, enabling all SDK clients to auto-discover the daemon without hardcoded URLs. This supports managed mode where antd is spawned with --rest-port 0 for OS-assigned ports. Changes: - antd (Rust): port file lifecycle (atomic write/cleanup), --rest-port and --grpc-port CLI flags, pre-bound listeners for both servers - All 15 SDKs: discover module + auto-discover constructors for REST and gRPC clients - Default REST port corrected from 8080 to 8082 across all SDKs - ant-dev CLI: status/wallet/start commands use port-file discovery - Docs: README, llms.txt, llms-full.txt, skill.md updated Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Windows: remove target before rename (fs::rename fails if target exists on Windows, unlike Unix atomic replace) - Stale port file detection: antd now writes its PID as line 3 of the port file. Go SDK checks if the process is still alive before trusting the discovered ports (platform-specific: signal 0 on Unix, FindProcess on Windows) - Split Go processAlive into discover_unix.go / discover_windows.go with build tags for clean cross-compilation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
antd now writes its PID as line 3 of the port file. All SDKs validate
the PID before trusting discovered ports, preventing connections to
dead daemons after crashes.
Platform-specific approaches per language:
- Go: signal 0 (Unix), FindProcess (Windows) via build tags
- Python/MCP: os.kill(pid, 0) — cross-platform on Python 3
- Rust: kill -0 (Unix), tasklist (Windows) via cfg
- Java/Kotlin: ProcessHandle.of(pid).isPresent() — cross-platform
- C#: Process.GetProcessById — cross-platform on .NET 8+
- TypeScript: process.kill(pid, 0) — cross-platform in Node.js
- C++: kill(pid, 0) (Unix), OpenProcess (Windows) via ifdef
- Ruby: Process.kill(0, pid) — cross-platform
- Elixir: System.cmd("kill", ["-0", pid]) on Unix, trust on Windows
- Swift: kill(pid_t, 0) via C interop
- Dart: kill -0 on Unix, trust on Windows
- Lua: os.execute("kill -0") on Unix, trust on Windows
- PHP: posix_kill or /proc check on Unix, tasklist on Windows
- Zig: /proc check on Linux, trust on other platforms
All backward-compatible with 2-line port files (no PID).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
CORS: Restrict allowed origin to http://127.0.0.1:{port} instead of permissive Any. Prevents cross-origin CSRF from malicious webpages. Non-browser clients (SDKs, CLI, AI agents) are unaffected as they don't send Origin headers. Matches approach from ant-client. Wallet: Add GET /v1/wallet/address and GET /v1/wallet/balance REST endpoints to antd. Returns 400 if no EVM wallet is configured. Also adds NotImplemented error variant (HTTP 501 / gRPC UNIMPLEMENTED) for stubbed endpoints. SDK bindings added for wallet_address() and wallet_balance() across all 15 language SDKs + MCP server (2 new MCP tools). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was referenced Mar 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
daemon.portfile on startup (atomic write via temp+rename), cleans up on shutdown. Adds--rest-port/--grpc-portCLI flags supporting--rest-port 0for OS-assigned dynamic ports. Pre-binds both REST and gRPC listeners to capture actual ports before serving.%APPDATA%\ant\on Windows,~/.local/share/ant/on Linux,~/Library/Application Support/ant/on macOS).status,wallet, andstartcommands now use port-file discovery.Port file format is two lines (REST port, gRPC port). Single-line files are forward-compatible (gRPC falls back to default 50051).
Enables managed mode for consumers like indelible that spawn antd as a child process with a dynamic port.
Test plan
cargo checkpasses for antd (Rust)go test ./...passes for antd-go (8 discovery tests + existing suite)daemon.portfile written--rest-port 0, verify auto-discover connects🤖 Generated with Claude Code