diff --git a/extensions/remote-control/config.ts b/extensions/remote-control/config.ts index 69c2e4d..91fc99c 100644 --- a/extensions/remote-control/config.ts +++ b/extensions/remote-control/config.ts @@ -10,10 +10,22 @@ import os from "node:os"; import path from "node:path"; import type { ExtensionContext } from "@earendil-works/pi-coding-agent"; -const REMOTE_CONTROL_CONFIG_FILE = "remote-control.json"; +const REMOTE_CONTROL_CONFIG_FILE = "config.json"; export interface RemoteControlConfig { publicBaseUrl?: string; + advertisedBaseUrl?: string; + bindAddress?: string; +} + +/** Parse host and port from a "host:port" bindAddress string. */ +export function parseBindAddress(bindAddress: string): { host: string; port: number } { + const idx = bindAddress.lastIndexOf(":"); + if (idx === -1) return { host: bindAddress, port: 0 }; + return { + host: bindAddress.slice(0, idx) || "127.0.0.1", + port: Number.parseInt(bindAddress.slice(idx + 1), 10) || 0, + }; } function getAgentDir(): string { @@ -40,7 +52,7 @@ function getAgentDir(): string { } function getRemoteControlConfigPath(): string { - return path.join(getAgentDir(), REMOTE_CONTROL_CONFIG_FILE); + return path.join(os.homedir(), ".pi", "remote-control", REMOTE_CONTROL_CONFIG_FILE); } export async function readRemoteControlConfig(): Promise { @@ -82,7 +94,8 @@ export function buildRemoteControlUrl( token: string, ): string { const parsed = new URL(normalizePublicBaseUrl(publicBaseUrl)); - if (parsed.protocol === "http:") { + // Only override port when using http: and no fixed port was configured + if (parsed.protocol === "http:" && !parsed.port) { parsed.port = String(port); } parsed.searchParams.set("token", token); diff --git a/extensions/remote-control/html.ts b/extensions/remote-control/html.ts index 8bbd04f..7c77d09 100644 --- a/extensions/remote-control/html.ts +++ b/extensions/remote-control/html.ts @@ -12,6 +12,11 @@ export function buildHTML(nonce: string): string { π - remote-control + + + + +