Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex): mirror label-specific runtime env vars (API_PORT/UI_PORT/DEV_UI_PORT)

Adam Eivy244c4cddeeb7
diff --git a/server/services/streamingDetect.js b/server/services/streamingDetect.js
index 98ef8b5c22..4d4b766d15 100644
--- a/server/services/streamingDetect.js
+++ b/server/services/streamingDetect.js
@@ -598,6 +598,11 @@ function rewriteLabelInBlock(block, label, oldP, newP) {
const hasExplicitPortsSource = hasInlinePortsObj || hasPortsReference;
// `PORT`/`'PORT'`/`` `PORT` `` followed by `:` and optional whitespace.
const PORT_KEY = "['\"`]?\\bPORT\\b['\"`]?\\s*:\\s*";
+ // Label-specific runtime env var, mirroring parseEcosystemConfig's
+ // `<STEM>_PORT` → camelCased-stem labeling (API_PORT→api, UI_PORT→ui,
+ // DEV_UI_PORT→devUi). PM2 launches the process WITH this env var, so a shared
+ // inline `ports` edit that left it on the old value would revert at runtime.
+ const LABEL_ENV_KEY = { api: 'API_PORT', ui: 'UI_PORT', devUi: 'DEV_UI_PORT' }[label];
// Patterns are split by SCOPE:
// - portsObjPats run ONLY inside the inline `ports: { ... }` slice. The
@@ -615,6 +620,8 @@ function rewriteLabelInBlock(block, label, oldP, newP) {
// so they move WITH an inline ports object — fine to rewrite either way.
blockPats.push(`(${PORT_KEY}[^,}\\n]*?\\|\\|\\s*['"]?)${NUM}`); // PORT: … || N (fallback)
blockPats.push(`(${PORT_KEY})${NUM}`); // env PORT: N
+ // Label-specific runtime env var (API_PORT) — PM2 launches with it.
+ blockPats.push(`(['"\`]?\\b${LABEL_ENV_KEY}\\b['"\`]?\\s*:\\s*)${NUM}`); // env API_PORT: N
}
// A bare lowercase `port:` is parseEcosystemConfig's LAST-RESORT derivation
// (`directPortMatch`), consulted only when there's no ports object/env. So
@@ -637,6 +644,8 @@ function rewriteLabelInBlock(block, label, oldP, newP) {
// re-derives the old port on the next refresh).
blockPats.push(`(['"\`]?\\bVITE_PORT\\b['"\`]?\\s*:\\s*)${NUM}`); // env VITE_PORT: N
blockPats.push(`(--port\\s+)${NUM}`); // args --port N
+ // Label-specific runtime env var (UI_PORT / DEV_UI_PORT) — PM2 launches with it.
+ blockPats.push(`(['"\`]?\\b${LABEL_ENV_KEY}\\b['"\`]?\\s*:\\s*)${NUM}`); // env UI_PORT: N
}
if (!hasExplicitPortsSource) blockPats.push(`(${PORT_KEY})${NUM}`); // bare PORT of a UI-named process
}
diff --git a/server/services/streamingDetect.test.js b/server/services/streamingDetect.test.js
index 5035884f5f..c8b57fe323 100644
--- a/server/services/streamingDetect.test.js
+++ b/server/services/streamingDetect.test.js
@@ -560,6 +560,24 @@ module.exports = { apps: [
expect(parseEcosystemConfig(r.content).processes[0].ports.api).toBe(7000);
});
+ it('also rewrites the matching label-specific runtime env var (UI_PORT) alongside the ports key', () => {
+ // ports.ui and a same-valued UI_PORT env var (which PM2 launches with).
+ // Editing ui must move BOTH, or the process restarts on the old UI_PORT.
+ // The sibling api/API_PORT (same value) must be left alone.
+ const content = `module.exports = { apps: [
+ { name: 'srv', script: 's.js', ports: { api: 6000, ui: 6000 }, env: { API_PORT: 6000, UI_PORT: 6000 } }
+] };
+`;
+ const r = rewriteEcosystemPortsByProcess(content, [
+ { processName: 'srv', label: 'ui', oldPort: 6000, newPort: 7000 },
+ ]);
+ expect(r.applied).toHaveLength(1);
+ expect(r.content).toContain('ui: 7000');
+ expect(r.content).toContain('UI_PORT: 7000');
+ expect(r.content).toContain('api: 6000'); // sibling untouched
+ expect(r.content).toContain('API_PORT: 6000'); // sibling env untouched
+ });
+
it('does not rewrite a bare lowercase port: field when an inline ports object is the source', () => {
// parseEcosystemConfig reads ports.api and ignores `metadata.port`; the bare
// `port:` fallback is last-resort (only when there's no ports object), so it