summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorCharles David Mupende <[email protected]>2025-11-07 02:37:23 +0100
committerGitHub <[email protected]>2025-11-06 19:37:23 -0600
commitd0f5c825bd2bb83378545c996dc566de25df6f1c (patch)
tree844e87e7fad02bfcbfde119d1c7158ecc50a372f /packages
parent9f603e39a6ed863a4edaddeeb5444804fc0b8998 (diff)
downloadopencode-d0f5c825bd2bb83378545c996dc566de25df6f1c.tar.gz
opencode-d0f5c825bd2bb83378545c996dc566de25df6f1c.zip
feat: implement network IP retrieval for remote access in web command (#3945)
Diffstat (limited to 'packages')
-rw-r--r--packages/opencode/src/cli/cmd/web.ts59
1 files changed, 53 insertions, 6 deletions
diff --git a/packages/opencode/src/cli/cmd/web.ts b/packages/opencode/src/cli/cmd/web.ts
index 8fc8a9915..9d3a42539 100644
--- a/packages/opencode/src/cli/cmd/web.ts
+++ b/packages/opencode/src/cli/cmd/web.ts
@@ -2,6 +2,29 @@ import { Server } from "../../server/server"
import { UI } from "../ui"
import { cmd } from "./cmd"
import open from "open"
+import { networkInterfaces } from "os"
+
+function getNetworkIPs() {
+ const nets = networkInterfaces()
+ const results: string[] = []
+
+ for (const name of Object.keys(nets)) {
+ const net = nets[name]
+ if (!net) continue
+
+ for (const netInfo of net) {
+ // Skip internal and non-IPv4 addresses
+ if (netInfo.internal || netInfo.family !== "IPv4") continue
+
+ // Skip Docker bridge networks (typically 172.x.x.x)
+ if (netInfo.address.startsWith("172.")) continue
+
+ results.push(netInfo.address)
+ }
+ }
+
+ return results
+}
export const WebCommand = cmd({
command: "web",
@@ -29,12 +52,36 @@ export const WebCommand = cmd({
UI.empty()
UI.println(UI.logo(" "))
UI.empty()
- UI.println(
- UI.Style.TEXT_INFO_BOLD + " Web interface: ",
- UI.Style.TEXT_NORMAL,
- server.url.toString(),
- )
- open(server.url.toString()).catch(() => {})
+
+ if (hostname === "0.0.0.0") {
+ // Show localhost for local access
+ const localhostUrl = `http://localhost:${server.port}`
+ UI.println(
+ UI.Style.TEXT_INFO_BOLD + " Local access: ",
+ UI.Style.TEXT_NORMAL,
+ localhostUrl,
+ )
+
+ // Show network IPs for remote access
+ const networkIPs = getNetworkIPs()
+ if (networkIPs.length > 0) {
+ for (const ip of networkIPs) {
+ UI.println(
+ UI.Style.TEXT_INFO_BOLD + " Network access: ",
+ UI.Style.TEXT_NORMAL,
+ `http://${ip}:${server.port}`,
+ )
+ }
+ }
+
+ // Open localhost in browser
+ open(localhostUrl.toString()).catch(() => {})
+ } else {
+ const displayUrl = server.url.toString()
+ UI.println(UI.Style.TEXT_INFO_BOLD + " Web interface: ", UI.Style.TEXT_NORMAL, displayUrl)
+ open(displayUrl).catch(() => {})
+ }
+
await new Promise(() => {})
await server.stop()
},