From 2c8d59633bf98241d6efa4d05166328d9ab28239 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Mar 2026 14:41:36 +0100 Subject: [PATCH 1/2] Add --host flag to control server bind address (#1) * Initial plan * Add --host flag to bind server to custom address (e.g. 0.0.0.0) Co-authored-by: abien <254409+abien@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: abien <254409+abien@users.noreply.github.com> --- README.md | 1 + src/server/cli.ts | 13 +++++++++++++ src/server/index.ts | 21 ++++++++++++++++----- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fb051f8..c72dfef 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ Opens a dashboard at `http://localhost:50234` showing live agent sessions, tool | Flag | Description | |------|-------------| | `--port ` | Server port (default: 50234) | +| `--host
` | Bind address (default: localhost, use 0.0.0.0 for all interfaces) | | `--no-browser` | Don't auto-open browser | | `--project ` | Set project directory for plan tracking | | `--help` | Show help | diff --git a/src/server/cli.ts b/src/server/cli.ts index 47df7ef..d63b322 100644 --- a/src/server/cli.ts +++ b/src/server/cli.ts @@ -2,6 +2,7 @@ import { DEFAULT_PORT } from "../shared/constants"; export interface CLIFlags { port: number; + host: string; noBrowser: boolean; projectPath: string | null; showHelp: boolean; @@ -11,6 +12,7 @@ export function parseArgs(): CLIFlags { const args = process.argv.slice(2); const flags: CLIFlags = { port: DEFAULT_PORT, + host: "localhost", noBrowser: false, projectPath: null, showHelp: false, @@ -29,6 +31,15 @@ export function parseArgs(): CLIFlags { flags.port = parseInt(portValue); i++; } + } else if (arg === "--host") { + const hostValue = args[i + 1]; + if (hostValue && /^[a-zA-Z0-9.\-:]+$/.test(hostValue)) { + flags.host = hostValue; + i++; + } else if (hostValue) { + console.warn(`[ocwatch] Invalid --host value ignored: ${hostValue}`); + i++; + } } else if (arg === "--project") { const projectPath = args[i + 1]; if (projectPath) { @@ -49,6 +60,7 @@ Usage: ocwatch [options] Options: --port Server port (default: 50234) + --host
Bind address (default: localhost, use 0.0.0.0 for all interfaces) --no-browser Skip auto-opening browser --project Set default project filter --help, -h Show this help message @@ -56,6 +68,7 @@ Options: Examples: ocwatch ocwatch --port 50999 + ocwatch --host 0.0.0.0 ocwatch --no-browser ocwatch --project /path/to/project `); diff --git a/src/server/index.ts b/src/server/index.ts index 9e786c6..ebafa77 100755 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -76,10 +76,18 @@ app.use("*", errorHandler); app.use( "/api/*", - cors({ - origin: ["http://localhost:3000", "http://localhost:50234"], - credentials: true, - }) + cors( + flags.host === "0.0.0.0" + ? { origin: "*", credentials: false } + : { + origin: [ + `http://localhost:3000`, + `http://localhost:${flags.port}`, + `http://${flags.host}:${flags.port}`, + ], + credentials: true, + } + ) ); registerRoutes(app, { defaultProjectIdPromise }); @@ -103,10 +111,13 @@ app.notFound(async (c) => { export { app }; const port = flags.port; -const url = `http://localhost:${port}`; +const hostname = flags.host; +const displayHost = hostname === "0.0.0.0" ? "localhost" : hostname; +const url = `http://${displayHost}:${port}`; export default { port, + hostname, fetch: app.fetch, }; From 40840614e02830b88110cf2b51cf1e53380a2ff9 Mon Sep 17 00:00:00 2001 From: Alexander Bien Date: Sat, 7 Mar 2026 12:28:40 +0100 Subject: [PATCH 2/2] fix(server): handle IPv6 wildcard in --host flag and warn on missing value Address PR review feedback: - CORS and displayHost now treat :: (IPv6) as wildcard alongside 0.0.0.0 - --host with no value warns instead of silently falling back to localhost --- src/server/cli.ts | 2 ++ src/server/index.ts | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/server/cli.ts b/src/server/cli.ts index d63b322..7d7f6dd 100644 --- a/src/server/cli.ts +++ b/src/server/cli.ts @@ -39,6 +39,8 @@ export function parseArgs(): CLIFlags { } else if (hostValue) { console.warn(`[ocwatch] Invalid --host value ignored: ${hostValue}`); i++; + } else { + console.warn(`[ocwatch] --host requires a value`); } } else if (arg === "--project") { const projectPath = args[i + 1]; diff --git a/src/server/index.ts b/src/server/index.ts index ebafa77..a9da550 100755 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -69,6 +69,8 @@ async function getDefaultProjectIdFromFlag(projectPath: string | null): Promise< const defaultProjectIdPromise = getDefaultProjectIdFromFlag(flags.projectPath); +const isWildcard = flags.host === "0.0.0.0" || flags.host === "::"; + const app = new Hono(); app.use("*", compress()); @@ -77,7 +79,7 @@ app.use("*", errorHandler); app.use( "/api/*", cors( - flags.host === "0.0.0.0" + isWildcard ? { origin: "*", credentials: false } : { origin: [ @@ -112,7 +114,7 @@ export { app }; const port = flags.port; const hostname = flags.host; -const displayHost = hostname === "0.0.0.0" ? "localhost" : hostname; +const displayHost = isWildcard ? "localhost" : hostname; const url = `http://${displayHost}:${port}`; export default {