Overview
Concrete tool for resolving jcode socket paths and Windows named-pipe endpoints on the client side, provided by the TypeScript SDK.
Description
The sockets module mirrors jcode-harness-api::sockets from the Rust side, ensuring the SDK client and the server bridge resolve the same runtime directory. runtimeDir() checks JCODE_RUNTIME_DIR, then XDG_RUNTIME_DIR, then macOS TMPDIR, and finally falls back to os.tmpdir() with a sanitized user discriminator. transportEndpoint() maps a Unix socket path to a Windows named pipe name (readable stem + SHA256 hash of the normalized path), pinned to the Rust derivation by tests. apiSocketPath() and legacySocketPath() return the versioned and legacy socket paths, each overridable via environment variables.
Usage
- Client connection: Call
apiSocketPath() or legacySocketPath() to get the socket to dial.
- Custom runtime directory: Set
JCODE_RUNTIME_DIR to relocate all sockets.
- Windows named pipes: Call
transportEndpoint() to convert a socket path to the pipe name the bridge publishes.
Code Reference
Source Location
Signature
export function runtimeDir(): string
export function transportEndpoint(socketPath: string): string
export function apiSocketPath(): string
export function legacySocketPath(): string
Import
import { runtimeDir, transportEndpoint, apiSocketPath, legacySocketPath } from "@1jehuang/jcode/sockets";
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| JCODE_RUNTIME_DIR |
env var |
No |
Override for the runtime directory
|
| JCODE_API_SOCKET |
env var |
No |
Override for the versioned API socket path
|
| JCODE_SOCKET |
env var |
No |
Override for the legacy daemon socket path
|
| socketPath |
string |
Yes (transportEndpoint) /// Unix socket path to convert to a pipe name
|
Outputs
| Name |
Type |
Description
|
| runtimeDir |
string /// Resolved runtime directory
|
| transportEndpoint |
string /// Socket path or Windows named-pipe name
|
| apiSocketPath |
string /// Path to the versioned harness API socket
|
| legacySocketPath |
string /// Path to the internal daemon socket
|
Usage Examples
Connect to the API Socket
import { apiSocketPath, transportEndpoint } from "@1jehuang/jcode/sockets";
import { createConnection } from "node:net";
const sockPath = apiSocketPath();
const endpoint = transportEndpoint(sockPath);
// On Unix, endpoint === sockPath; on Windows, endpoint is a named pipe
const socket = createConnection(endpoint);
Custom Runtime Directory
# Relocate all jcode sockets to a custom directory
export JCODE_RUNTIME_DIR=/tmp/jcode-custom
jcode run "do a task"
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.