From 11990be86dc3db530f9effbf65674c778afaa4a8 Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Tue, 20 Oct 2026 20:11:16 +0000 Subject: [PATCH 1/4] proxies: single-source clef/agy/antigravity-ls ports via env (follow-up to #431) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #431 single-sourced the codex-proxy port (CODEX_PROXY_PORT) and left the sibling proxies as a follow-up (tracked as #435). This applies the identical pattern to the remaining three: - home/common/default.nix: clefProxyPort = 18742, agyProxyPort = 18743, antigravityLsProxyPort = 18745 join codexProxyPort in the let block. Each flows to its systemd user service Environment and to home.sessionVariables (CLEF_PROXY_PORT / AGY_PROXY_PORT / ANTIGRAVITY_LS_PROXY_PORT). - .opencode/opencode.jsonc: the antigravity-agy and antigravity-ls providers now build their baseURL from {env:AGY_PROXY_PORT} / {env:ANTIGRAVITY_LS_PROXY_PORT}, with the same do-not-hardcode comment as openai-codex. clef-proxy has no opencode.jsonc consumer (its models ride the Cloudflare gateway), so it gets the nix-side single source only. - The bin/*.mjs proxies keep their current ports as fallback defaults, unchanged. Verified: nix-instantiate --parse on default.nix; a throwaway opencode serve (1.18.31) with the edited config and the three vars set resolved all three provider baseURLs to 127.0.0.1:18743/18744/18745. After this change the only 1874x literals left in default.nix are the four let-block definitions, and opencode.jsonc has none. Known caveat, shared with #431 and tracked separately in #434: {env:...} substitution has no fallback when a variable is unset, so these baseURLs inherit exactly the behaviour CODEX_PROXY_PORT has today — no better, no worse. --- .opencode/opencode.jsonc | 11 +++++++++-- home/common/default.nix | 28 ++++++++++++++++++---------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/.opencode/opencode.jsonc b/.opencode/opencode.jsonc index f3c0e55647..6fa7ca6804 100644 --- a/.opencode/opencode.jsonc +++ b/.opencode/opencode.jsonc @@ -1847,7 +1847,10 @@ "npm": "@ai-sdk/openai-compatible", "name": "Antigravity CLI (via agy)", "options": { - "baseURL": "http://127.0.0.1:18743/v1", + // Port comes from AGY_PROXY_PORT (set by home config from the + // same single definition the agy-proxy service binds) — never + // hardcode a port here; see the openai-codex provider note. + "baseURL": "http://127.0.0.1:{env:AGY_PROXY_PORT}/v1", "apiKey": "agy-local" }, "models": { @@ -1929,7 +1932,11 @@ "npm": "@ai-sdk/openai-compatible", "name": "Antigravity Language Server (Direct gRPC/ConnectRPC)", "options": { - "baseURL": "http://127.0.0.1:18745/v1", + // Port comes from ANTIGRAVITY_LS_PROXY_PORT (set by home config + // from the same single definition the antigravity-ls-proxy + // service binds) — never hardcode a port here; see the + // openai-codex provider note. + "baseURL": "http://127.0.0.1:{env:ANTIGRAVITY_LS_PROXY_PORT}/v1", "apiKey": "antigravity-local" }, "models": { diff --git a/home/common/default.nix b/home/common/default.nix index 3ac7abff6d..556f51155f 100644 --- a/home/common/default.nix +++ b/home/common/default.nix @@ -7,12 +7,17 @@ ... }: let - # The codex proxy's port, defined ONCE. It flows to the systemd user - # service (which binds it), to the shell session (CODEX_PROXY_PORT), and - # into opencode.jsonc's openai-codex baseURL via {env:CODEX_PROXY_PORT} - # substitution — so the three can never drift apart, and a new device - # that applies this config gets a consistent port automatically. + # Local proxy ports, each defined ONCE. Each value flows to the systemd + # user service that binds it, to the shell session (_PROXY_PORT), + # and — for the proxies opencode talks to — into opencode.jsonc's + # baseURL via {env:...} substitution, so the copies can never drift + # apart and a new device that applies this config gets consistent ports + # automatically. The bin/*.mjs proxies keep the same numbers as fallback + # defaults when the env var is absent. + clefProxyPort = 18742; + agyProxyPort = 18743; codexProxyPort = 18744; + antigravityLsProxyPort = 18745; # Upstream prebuilt release binaries for tools where nixpkgs trails upstream. # See pkgs/latest-cli/default.nix for the rationale, the tradeoffs, and the # list of things deliberately NOT bumped. @@ -463,7 +468,7 @@ in Restart = "always"; RestartSec = 3; Environment = [ - "CLEF_PROXY_PORT=18742" + "CLEF_PROXY_PORT=${toString clefProxyPort}" "CLEF_PROXY_HOST=127.0.0.1" ]; }; @@ -486,7 +491,7 @@ in Restart = "always"; RestartSec = 3; Environment = [ - "AGY_PROXY_PORT=18743" + "AGY_PROXY_PORT=${toString agyProxyPort}" "AGY_PROXY_HOST=127.0.0.1" ]; }; @@ -532,7 +537,7 @@ in Restart = "always"; RestartSec = 3; Environment = [ - "ANTIGRAVITY_LS_PROXY_PORT=18745" + "ANTIGRAVITY_LS_PROXY_PORT=${toString antigravityLsProxyPort}" "ANTIGRAVITY_LS_PROXY_HOST=127.0.0.1" "ANTIGRAVITY_LS_BIN=${antigravity-hub}/share/antigravity/resources/bin/language_server" ]; @@ -1182,9 +1187,12 @@ in OPENCODE_EXPERIMENTAL_OXFMT = "1"; OPENCODE_EXPERIMENTAL_EXA = "1"; OPENCODE_EXPERIMENTAL_EVENT_SYSTEM = "1"; - # Single source for the codex proxy port (see the let block): - # opencode.jsonc reads it via {env:CODEX_PROXY_PORT}. + # Single source for the local proxy ports (see the let block): + # opencode.jsonc reads them via {env:...} substitution. + CLEF_PROXY_PORT = toString clefProxyPort; + AGY_PROXY_PORT = toString agyProxyPort; CODEX_PROXY_PORT = toString codexProxyPort; + ANTIGRAVITY_LS_PROXY_PORT = toString antigravityLsProxyPort; OPENCODE_EXPERIMENTAL_ICON_DISCOVERY = "1"; OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT = "1"; # File watcher off by default (Drew, 2026-10-20): the working trees From b047a2b46021ea083ffd9cc7edc0edcba2b794b9 Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Tue, 20 Oct 2026 20:11:23 +0000 Subject: [PATCH 2/4] proxies: publish endpoint.json so clients can discover the bound port MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each of the four proxies now writes $XDG_STATE_HOME//endpoint.json ({host, port, pid, url}) when it starts listening and removes it on exit (SIGTERM/SIGINT/exit; antigravity-ls-proxy reuses its existing signal handlers via the exit hook). Atomic write via temp file + rename, and every failure is swallowed — publication can never take a proxy down. This is the publish half of the port-file discovery design evaluated in #437 (the pattern Chrome DevTools' DevToolsActivePort and Jupyter's runtime files use): any tool that can read a file can now find the running proxy without assuming its port, which is what makes future dynamic ports possible. The fixed single-sourced ports remain the contract for static-config consumers like opencode.jsonc, which cannot read files; #437 lays out the options and the decision needed there. Verified: node --check on all four files; smoke test — clef-proxy on a scratch port with a temp XDG_STATE_HOME wrote the correct endpoint.json (port taken from the bound env port, not the default) and removed it on SIGTERM. --- bin/agy-proxy.mjs | 36 ++++++++++++++++++++++++++++++++++++ bin/antigravity-ls-proxy.mjs | 31 +++++++++++++++++++++++++++++++ bin/clef-proxy.mjs | 34 ++++++++++++++++++++++++++++++++++ bin/codex-proxy.mjs | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+) diff --git a/bin/agy-proxy.mjs b/bin/agy-proxy.mjs index d606ebc6a2..ac1e9b50af 100755 --- a/bin/agy-proxy.mjs +++ b/bin/agy-proxy.mjs @@ -3,10 +3,45 @@ import http from 'node:http'; import { spawn } from 'node:child_process'; import crypto from 'node:crypto'; import fs from 'node:fs'; +import path from 'node:path'; +import os from 'node:os'; const PORT = parseInt(process.env.AGY_PROXY_PORT || '18743', 10); const HOST = process.env.AGY_PROXY_HOST || '127.0.0.1'; +// Publish the bound endpoint so other tools can find this proxy without +// knowing its port in advance: $XDG_STATE_HOME//endpoint.json +// (default ~/.local/state//endpoint.json), written on listen, +// removed on exit. +const publishEndpoint = () => { + try { + const stateHome = + process.env.XDG_STATE_HOME || path.join(os.homedir(), '.local', 'state'); + const dir = path.join(stateHome, 'agy-proxy'); + fs.mkdirSync(dir, { recursive: true }); + const file = path.join(dir, 'endpoint.json'); + fs.writeFileSync( + `${file}.tmp`, + JSON.stringify({ host: HOST, port: PORT, pid: process.pid, url: `http://${HOST}:${PORT}` }) + '\n', + ); + fs.renameSync(`${file}.tmp`, file); + const cleanup = () => { + try { + fs.unlinkSync(file); + } catch {} + }; + process.on('exit', cleanup); + process.on('SIGTERM', () => { + cleanup(); + process.exit(0); + }); + process.on('SIGINT', () => { + cleanup(); + process.exit(0); + }); + } catch {} +}; + const MODELS = [ { id: 'gemini-3.8-flash', name: 'Gemini 3.8 Flash (agy)', efforts: ['low', 'medium', 'high'], defaultEffort: 'medium' }, { id: 'gemini-3.7-flash', name: 'Gemini 3.7 Flash (agy)', efforts: ['low', 'medium', 'high'], defaultEffort: 'medium' }, @@ -581,6 +616,7 @@ const server = http.createServer((req, res) => { }); server.listen(PORT, HOST, () => { + publishEndpoint(); console.log(`Antigravity agy Proxy listening on http://${HOST}:${PORT}`); console.log(`Endpoints:`); console.log(` - GET http://${HOST}:${PORT}/health`); diff --git a/bin/antigravity-ls-proxy.mjs b/bin/antigravity-ls-proxy.mjs index c7d9faa223..28b8b95e93 100755 --- a/bin/antigravity-ls-proxy.mjs +++ b/bin/antigravity-ls-proxy.mjs @@ -3,10 +3,40 @@ import http from 'node:http'; import { spawn, execSync } from 'node:child_process'; import crypto from 'node:crypto'; import fs from 'node:fs'; +import path from 'node:path'; +import os from 'node:os'; const PORT = parseInt(process.env.ANTIGRAVITY_LS_PROXY_PORT || '18745', 10); const HOST = process.env.ANTIGRAVITY_LS_PROXY_HOST || '127.0.0.1'; +// Publish the bound endpoint so other tools can find this proxy without +// knowing its port in advance: $XDG_STATE_HOME//endpoint.json +// (default ~/.local/state//endpoint.json), written on listen, +// removed on exit. This file already registers SIGTERM/SIGINT handlers +// (see below, calling lsManager.cleanup() then process.exit(0)), so this +// helper does not register duplicate signal handlers; the 'exit' cleanup +// it registers runs on that existing exit path. +const publishEndpoint = () => { + try { + const stateHome = + process.env.XDG_STATE_HOME || path.join(os.homedir(), '.local', 'state'); + const dir = path.join(stateHome, 'antigravity-ls-proxy'); + fs.mkdirSync(dir, { recursive: true }); + const file = path.join(dir, 'endpoint.json'); + fs.writeFileSync( + `${file}.tmp`, + JSON.stringify({ host: HOST, port: PORT, pid: process.pid, url: `http://${HOST}:${PORT}` }) + '\n', + ); + fs.renameSync(`${file}.tmp`, file); + const cleanup = () => { + try { + fs.unlinkSync(file); + } catch {} + }; + process.on('exit', cleanup); + } catch {} +}; + const DEFAULT_MANAGED_HTTP_PORT = 48999; const DEFAULT_MANAGED_HTTPS_PORT = 48998; const MANAGED_CSRF_TOKEN = 'antigravity-ls-local-token-' + crypto.randomUUID().slice(0, 8); @@ -746,6 +776,7 @@ const server = http.createServer(async (req, res) => { }); server.listen(PORT, HOST, () => { + publishEndpoint(); console.log(`Antigravity Language Server Proxy listening on http://${HOST}:${PORT}`); console.log(`Endpoints:`); console.log(` - GET http://${HOST}:${PORT}/health`); diff --git a/bin/clef-proxy.mjs b/bin/clef-proxy.mjs index a68b9dd531..9d8f5421bb 100755 --- a/bin/clef-proxy.mjs +++ b/bin/clef-proxy.mjs @@ -7,6 +7,39 @@ import os from 'node:os'; const PORT = parseInt(process.env.CLEF_PROXY_PORT || '18742', 10); const HOST = process.env.CLEF_PROXY_HOST || '127.0.0.1'; +// Publish the bound endpoint so other tools can find this proxy without +// knowing its port in advance: $XDG_STATE_HOME//endpoint.json +// (default ~/.local/state//endpoint.json), written on listen, +// removed on exit. +const publishEndpoint = () => { + try { + const stateHome = + process.env.XDG_STATE_HOME || path.join(os.homedir(), '.local', 'state'); + const dir = path.join(stateHome, 'clef-proxy'); + fs.mkdirSync(dir, { recursive: true }); + const file = path.join(dir, 'endpoint.json'); + fs.writeFileSync( + `${file}.tmp`, + JSON.stringify({ host: HOST, port: PORT, pid: process.pid, url: `http://${HOST}:${PORT}` }) + '\n', + ); + fs.renameSync(`${file}.tmp`, file); + const cleanup = () => { + try { + fs.unlinkSync(file); + } catch {} + }; + process.on('exit', cleanup); + process.on('SIGTERM', () => { + cleanup(); + process.exit(0); + }); + process.on('SIGINT', () => { + cleanup(); + process.exit(0); + }); + } catch {} +}; + const readConfigFileSync = (filename, fallback = '') => { try { const fullPath = path.join(os.homedir(), '.config', 'cloudflare', filename); @@ -129,6 +162,7 @@ const server = http.createServer(async (req, res) => { }); server.listen(PORT, HOST, () => { + publishEndpoint(); console.log(`Clef System One Proxy listening on http://${HOST}:${PORT}`); console.log(`Endpoint: http://${HOST}:${PORT}/v1/systemone`); }); diff --git a/bin/codex-proxy.mjs b/bin/codex-proxy.mjs index 1fca049ca5..c5c66fad46 100755 --- a/bin/codex-proxy.mjs +++ b/bin/codex-proxy.mjs @@ -3,10 +3,45 @@ import http from 'node:http'; import { spawn } from 'node:child_process'; import crypto from 'node:crypto'; import fs from 'node:fs'; +import path from 'node:path'; +import os from 'node:os'; const PORT = parseInt(process.env.CODEX_PROXY_PORT || '18744', 10); const HOST = process.env.CODEX_PROXY_HOST || '127.0.0.1'; +// Publish the bound endpoint so other tools can find this proxy without +// knowing its port in advance: $XDG_STATE_HOME//endpoint.json +// (default ~/.local/state//endpoint.json), written on listen, +// removed on exit. +const publishEndpoint = () => { + try { + const stateHome = + process.env.XDG_STATE_HOME || path.join(os.homedir(), '.local', 'state'); + const dir = path.join(stateHome, 'codex-proxy'); + fs.mkdirSync(dir, { recursive: true }); + const file = path.join(dir, 'endpoint.json'); + fs.writeFileSync( + `${file}.tmp`, + JSON.stringify({ host: HOST, port: PORT, pid: process.pid, url: `http://${HOST}:${PORT}` }) + '\n', + ); + fs.renameSync(`${file}.tmp`, file); + const cleanup = () => { + try { + fs.unlinkSync(file); + } catch {} + }; + process.on('exit', cleanup); + process.on('SIGTERM', () => { + cleanup(); + process.exit(0); + }); + process.on('SIGINT', () => { + cleanup(); + process.exit(0); + }); + } catch {} +}; + const MODELS = [ { id: 'gpt-6.1-sol', name: 'GPT-6.1 Sol (codex)', efforts: ['low', 'medium', 'high', 'xhigh', 'max', 'ultra'], defaultEffort: 'medium' }, { id: 'gpt-6-astra', name: 'GPT-6 Astra (codex)', efforts: ['low', 'medium', 'high', 'xhigh', 'max', 'ultra'], defaultEffort: 'medium' }, @@ -378,6 +413,7 @@ const server = http.createServer((req, res) => { }); server.listen(PORT, HOST, () => { + publishEndpoint(); console.log(`[codex-proxy] OpenAI-compatible bridge listening on http://${HOST}:${PORT}`); console.log(`[codex-proxy] Resolved codex binary: ${CODEX_BIN}`); }); From 2a230077859d3e4eec5167385a6c7e86ae3614f0 Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Wed, 21 Oct 2026 07:16:55 -0500 Subject: [PATCH 3/4] fix(proxies): give every {env:} proxy baseURL a :- fallback port (#434) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stacked on #438 (base: proxy-ports-single-source). Fixes #434. The {env:VAR} baseURLs from #431/#438 resolve to an empty port in any launch that does not inherit the home-manager session variables (systemd service, desktop, VS Code) — a silently dead provider. The :- form resolves to the proxy's own fallback port when the variable is unset or empty, so the client and the proxy script (which keeps the same literal as its fallback) can no longer disagree. The fallback syntax is added to the opencode fork in developing-today/opencode PR #232 (ConfigVariable.substitute); on an opencode without it, the token degrades to the old empty substitution — no worse than #431 as-is. - .opencode/opencode.jsonc: CODEX_PROXY_PORT:-18744, AGY_PROXY_PORT:-18743, ANTIGRAVITY_LS_PROXY_PORT:-18745. - New .github/scripts/check-proxy-port-fallbacks.sh, run by nix-ci on every PR: every fallback copy (script defaults + config defaults) must match the single let-block definition in home/common/default.nix; a bare {env:VAR} or a literal port in opencode.jsonc fails by name. Ablation-verified both ways. --- .github/scripts/check-proxy-port-fallbacks.sh | 70 +++++++++++++++++++ .github/workflows/nix-ci.yml | 7 ++ .opencode/opencode.jsonc | 6 +- 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100755 .github/scripts/check-proxy-port-fallbacks.sh diff --git a/.github/scripts/check-proxy-port-fallbacks.sh b/.github/scripts/check-proxy-port-fallbacks.sh new file mode 100755 index 0000000000..98421c11ed --- /dev/null +++ b/.github/scripts/check-proxy-port-fallbacks.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +# Guard the local-proxy ports against silent drift (#434, #435). +# +# Each proxy's port is defined once, in the let block of +# home/common/default.nix, and flows to the systemd service environment +# and the shell session variables. Two places keep a literal copy BY +# DESIGN, as the documented fallback for launches that never see those +# variables: +# +# - bin/-proxy.mjs: process.env. || '' +# - .opencode/opencode.jsonc: {env::-} in the provider +# baseURL (opencode's {env:VAR} substitution has no fallback of its +# own; the :- form is what keeps a non-shell launch — systemd +# service, desktop, VS Code — from resolving to an empty port). +# +# This script fails, naming the offender, when any copy disagrees with +# the let-block definition, when a baseURL loses its :- fallback, or +# when a bare {env:} or a literal proxy port reappears in +# opencode.jsonc. Clef has no opencode.jsonc consumer (its models ride +# the Cloudflare gateway), so only its script fallback is checked. +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +nix_file="$repo_root/home/common/default.nix" +config_file="$repo_root/.opencode/opencode.jsonc" + +# var | let binding | proxy script | has an opencode.jsonc baseURL +proxies=( + "CLEF_PROXY_PORT|clefProxyPort|bin/clef-proxy.mjs|no" + "AGY_PROXY_PORT|agyProxyPort|bin/agy-proxy.mjs|yes" + "CODEX_PROXY_PORT|codexProxyPort|bin/codex-proxy.mjs|yes" + "ANTIGRAVITY_LS_PROXY_PORT|antigravityLsProxyPort|bin/antigravity-ls-proxy.mjs|yes" +) + +failed=0 +for entry in "${proxies[@]}"; do + IFS='|' read -r var let_name script has_config <<<"$entry" + + let_port="$(grep -E "^[[:space:]]*${let_name} = [0-9]+;" "$nix_file" | grep -oE '[0-9]+' | head -1 || true)" + if [[ -z $let_port ]]; then + echo "::error::${let_name} definition not found in home/common/default.nix." + failed=1 + continue + fi + + if ! grep -qF "process.env.${var} || '${let_port}'" "$repo_root/$script"; then + echo "::error::$script fallback for ${var} does not match the ${let_name} definition (${let_port}) in home/common/default.nix." + failed=1 + fi + + if [[ $has_config == yes ]] && ! grep -qF "{env:${var}:-${let_port}}" "$config_file"; then + echo "::error::.opencode/opencode.jsonc has no {env:${var}:-${let_port}} baseURL — the fallback must match the ${let_name} definition (${let_port}); a bare {env:${var}} resolves to an empty port outside a home-manager shell (#434)." + failed=1 + fi + if grep -qF "{env:${var}}" "$config_file"; then + echo "::error::.opencode/opencode.jsonc uses a bare {env:${var}} with no :- fallback (#434)." + failed=1 + fi +done + +if grep -qE '127\.0\.0\.1:1874[0-9]' "$config_file"; then + echo "::error::.opencode/opencode.jsonc hardcodes a literal proxy port — use {env::-} so the copies cannot drift (#435)." + failed=1 +fi + +if [[ $failed -ne 0 ]]; then + exit 1 +fi + +echo "proxy port fallbacks match the home/common/default.nix definitions (${#proxies[@]} proxies)." diff --git a/.github/workflows/nix-ci.yml b/.github/workflows/nix-ci.yml index b9abe85d21..fbc44888eb 100644 --- a/.github/workflows/nix-ci.yml +++ b/.github/workflows/nix-ci.yml @@ -29,6 +29,13 @@ jobs: - uses: actions/checkout@v7 with: fetch-depth: 0 + # The proxy ports' fallback copies (bin/*.mjs script defaults and + # the {env:VAR:-port} defaults in .opencode/opencode.jsonc) must + # match the single definitions in home/common/default.nix, or a + # non-shell launch silently dials the wrong — or an empty — port + # (#434, #435). Pure bash/grep: no Nix needed. + - name: Check proxy port fallbacks match their definitions + run: .github/scripts/check-proxy-port-fallbacks.sh - uses: DeterminateSystems/nix-installer-action@3138316df39ed29be04236d7ffc686fa525866aa # v23 - name: Check formatting for changed files env: diff --git a/.opencode/opencode.jsonc b/.opencode/opencode.jsonc index 6fa7ca6804..8ac56c32d9 100644 --- a/.opencode/opencode.jsonc +++ b/.opencode/opencode.jsonc @@ -1850,7 +1850,7 @@ // Port comes from AGY_PROXY_PORT (set by home config from the // same single definition the agy-proxy service binds) — never // hardcode a port here; see the openai-codex provider note. - "baseURL": "http://127.0.0.1:{env:AGY_PROXY_PORT}/v1", + "baseURL": "http://127.0.0.1:{env:AGY_PROXY_PORT:-18743}/v1", "apiKey": "agy-local" }, "models": { @@ -1936,7 +1936,7 @@ // from the same single definition the antigravity-ls-proxy // service binds) — never hardcode a port here; see the // openai-codex provider note. - "baseURL": "http://127.0.0.1:{env:ANTIGRAVITY_LS_PROXY_PORT}/v1", + "baseURL": "http://127.0.0.1:{env:ANTIGRAVITY_LS_PROXY_PORT:-18745}/v1", "apiKey": "antigravity-local" }, "models": { @@ -2676,7 +2676,7 @@ // same single definition the codex-proxy service binds) — never // hardcode a port here; a hardcoded one silently breaks on any // device where the proxy isn't on that exact port. - "baseURL": "http://127.0.0.1:{env:CODEX_PROXY_PORT}/v1", + "baseURL": "http://127.0.0.1:{env:CODEX_PROXY_PORT:-18744}/v1", "apiKey": "codex-local" }, "models": { From bd19d6313d3a239445bd982d462da4b130f5a891 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Thu, 22 Oct 2026 19:26:12 -0500 Subject: [PATCH 4/4] fix(home): single-source design-code port, teach guard parseProxyPort --- .github/scripts/check-proxy-port-fallbacks.sh | 7 +++++-- .opencode/opencode.jsonc | 10 +++++----- home/common/default.nix | 4 +++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/scripts/check-proxy-port-fallbacks.sh b/.github/scripts/check-proxy-port-fallbacks.sh index 98421c11ed..6a8a83401f 100755 --- a/.github/scripts/check-proxy-port-fallbacks.sh +++ b/.github/scripts/check-proxy-port-fallbacks.sh @@ -7,7 +7,8 @@ # DESIGN, as the documented fallback for launches that never see those # variables: # -# - bin/-proxy.mjs: process.env. || '' +# - bin/-proxy.mjs: parseProxyPort('', ) (or the older +# process.env. || '' form) # - .opencode/opencode.jsonc: {env::-} in the provider # baseURL (opencode's {env:VAR} substitution has no fallback of its # own; the :- form is what keeps a non-shell launch — systemd @@ -30,6 +31,7 @@ proxies=( "AGY_PROXY_PORT|agyProxyPort|bin/agy-proxy.mjs|yes" "CODEX_PROXY_PORT|codexProxyPort|bin/codex-proxy.mjs|yes" "ANTIGRAVITY_LS_PROXY_PORT|antigravityLsProxyPort|bin/antigravity-ls-proxy.mjs|yes" + "DESIGN_CODE_PROXY_PORT|designCodeProxyPort|bin/design-code-proxy.mjs|yes" ) failed=0 @@ -43,7 +45,8 @@ for entry in "${proxies[@]}"; do continue fi - if ! grep -qF "process.env.${var} || '${let_port}'" "$repo_root/$script"; then + if ! grep -qF "parseProxyPort('${var}', ${let_port})" "$repo_root/$script" && + ! grep -qF "process.env.${var} || '${let_port}'" "$repo_root/$script"; then echo "::error::$script fallback for ${var} does not match the ${let_name} definition (${let_port}) in home/common/default.nix." failed=1 fi diff --git a/.opencode/opencode.jsonc b/.opencode/opencode.jsonc index 7d532b0499..ab6c216000 100644 --- a/.opencode/opencode.jsonc +++ b/.opencode/opencode.jsonc @@ -3092,7 +3092,7 @@ "npm": "@ai-sdk/openai-compatible", "name": "ChatGPT (via Codex)", "options": { - "baseURL": "http://127.0.0.1:18744/v1", + "baseURL": "http://127.0.0.1:{env:CODEX_PROXY_PORT:-18744}/v1", "apiKey": "codex-local" }, "models": { @@ -3394,7 +3394,7 @@ "npm": "@ai-sdk/openai-compatible", "name": "Design Code", "options": { - "baseURL": "http://127.0.0.1:18746/v1", + "baseURL": "http://127.0.0.1:{env:DESIGN_CODE_PROXY_PORT:-18746}/v1", "apiKey": "design-local" }, "models": { @@ -3481,7 +3481,7 @@ "npm": "@ai-sdk/openai-compatible", "name": "Code Design", "options": { - "baseURL": "http://127.0.0.1:18746/v1", + "baseURL": "http://127.0.0.1:{env:DESIGN_CODE_PROXY_PORT:-18746}/v1", "apiKey": "design-local" }, "models": { @@ -3568,7 +3568,7 @@ "npm": "@ai-sdk/openai-compatible", "name": "Open Design", "options": { - "baseURL": "http://127.0.0.1:18746/v1", + "baseURL": "http://127.0.0.1:{env:DESIGN_CODE_PROXY_PORT:-18746}/v1", "apiKey": "design-local" }, "models": { @@ -3655,7 +3655,7 @@ "npm": "@ai-sdk/openai-compatible", "name": "OpenDesign", "options": { - "baseURL": "http://127.0.0.1:18746/v1", + "baseURL": "http://127.0.0.1:{env:DESIGN_CODE_PROXY_PORT:-18746}/v1", "apiKey": "design-local" }, "models": { diff --git a/home/common/default.nix b/home/common/default.nix index 72cb90c82a..29c2027851 100644 --- a/home/common/default.nix +++ b/home/common/default.nix @@ -18,6 +18,7 @@ let agyProxyPort = 18743; codexProxyPort = 18744; antigravityLsProxyPort = 18745; + designCodeProxyPort = 18746; # Upstream prebuilt release binaries for tools where nixpkgs trails upstream. # See pkgs/latest-cli/default.nix for the rationale, the tradeoffs, and the # list of things deliberately NOT bumped. @@ -579,7 +580,7 @@ in Restart = "always"; RestartSec = 3; Environment = [ - "DESIGN_CODE_PROXY_PORT=18746" + "DESIGN_CODE_PROXY_PORT=${toString designCodeProxyPort}" "DESIGN_CODE_PROXY_HOST=127.0.0.1" ]; }; @@ -1247,6 +1248,7 @@ in AGY_PROXY_PORT = toString agyProxyPort; CODEX_PROXY_PORT = toString codexProxyPort; ANTIGRAVITY_LS_PROXY_PORT = toString antigravityLsProxyPort; + DESIGN_CODE_PROXY_PORT = toString designCodeProxyPort; OPENCODE_EXPERIMENTAL_ICON_DISCOVERY = "1"; OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT = "1"; # File watcher off by default (Drew, 2026-10-20): the working trees