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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat: swap API/UI ports and DRY up port references
Adam Eivy8c27afae4714
diff --git a/.changelog/v1.23.x.md b/.changelog/v1.23.x.mdnew file mode 100644index 0000000000..4c369bceee--- /dev/null+++ b/.changelog/v1.23.x.md@@ -0,0 +1,18 @@+# Release v1.23.x - Changelog++Released: YYYY-MM-DD++## Overview++Port swap and DRY port references.++## 🔧 Improvements++- **Swap API/UI ports**: Express API server now runs on port 5555 (was 5554), Vite dev UI on 5554 (was 5555). All other ports (5556-5560) unchanged.+- **DRY port references**: New `server/lib/ports.js` module provides single source of truth for `PORTS`, `DEFAULT_PEER_PORT`, and `PORTOS_UI_URL` — eliminates duplicate definitions across 6+ server files.+- **Fix Security page media URLs**: Video and audio streams now use relative paths (`/api/media/video`) instead of hardcoded `hostname:port`, working correctly through Vite proxy in dev and same-origin in production.++## ⚠️ Migration Notes++- Existing peers in `data/instances.json` have `port: 5554` persisted. Remote instances need the same port swap, or peers need to be re-added with port 5555.+- `data/apps.json` auto-reconciles via `forceSync` on next server start — no manual data migration needed.diff --git a/.planning/codebase/ARCHITECTURE.md b/.planning/codebase/ARCHITECTURE.mdindex 947ed17e25..9873e45c3c 100644--- a/.planning/codebase/ARCHITECTURE.md+++ b/.planning/codebase/ARCHITECTURE.md@@ -21,7 +21,7 @@- Location: `client/src/`- Contains: React pages, reusable components, service clients, hooks, utilities- Depends on: HTTP API via `api.js`, WebSocket via `socket.js`-- Used by: End users via Vite dev server (port 5555) or production build+- Used by: End users via Vite dev server (port 5554) or production build**API Layer (Routes):**- Purpose: HTTP request handlers that validate input and delegate to services@@ -121,11 +121,11 @@**Server Initialization:**- Location: `server/index.js`- Triggers: `npm run dev` or `pm2 start ecosystem.config.cjs`-- Responsibilities: Create Express app, initialize Socket.IO, load routes, set middleware, start HTTP server on port 5554+- Responsibilities: Create Express app, initialize Socket.IO, load routes, set middleware, start HTTP server on port 5555**Client Initialization:**- Location: `client/src/main.jsx` → `App.jsx`-- Triggers: Vite dev server (port 5555) or production build+- Triggers: Vite dev server (port 5554) or production build- Responsibilities: Set up React Router, initialize hooks, load Layout component with nested routes**PM2 CoS Runner Process:**diff --git a/.planning/codebase/STACK.md b/.planning/codebase/STACK.mdindex fa51fcbe45..2c42eccebc 100644--- a/.planning/codebase/STACK.md+++ b/.planning/codebase/STACK.md@@ -93,11 +93,11 @@- Process environment variables via `ecosystem.config.cjs`:- `NODE_ENV`: 'development' (base)- `TZ`: 'UTC' (all timestamps in UTC)- - `PORT`: 5554 (API), configurable per process+ - `PORT`: 5555 (API), configurable per process- `HOST`: '0.0.0.0' (server), '127.0.0.1' (CDP/CoS)**Build Configuration:**-- Vite config: `client/vite.config.js` (port 5555, API proxy to 5554)+- Vite config: `client/vite.config.js` (port 5554, API proxy to 5555)- Tailwind config: `client/tailwind.config.js` (custom design tokens)- PostCSS: `client/postcss.config.js` (Tailwind + Autoprefixer)- Server test: `server/vitest.config.js` (30% coverage threshold)@@ -143,8 +143,8 @@## Port AllocationDefined in `ecosystem.config.cjs`:-- **5554**: Express API server (core PortOS backend)-- **5555**: Vite client dev server (React UI)+- **5554**: Vite client dev server (React UI)+- **5555**: Express API server (core PortOS backend)- **5556**: Chrome CDP (browser remote debugging)- **5557**: Browser health check endpoint- **5558**: Chief of Staff (CoS) agent runnerdiff --git a/CLAUDE.md b/CLAUDE.mdindex 6e29b132e3..c6a9cdc043 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -8,10 +8,10 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co# Install all dependenciesnpm run install:all-# Start (builds client, serves production UI + API on port 5554)+# Start (builds client, serves production UI + API on port 5555)npm start-# Development (Vite hot-reload on 5555, API on 5554)+# Development (Vite hot-reload on 5554, API on 5555)npm run dev# Run tests@@ -30,14 +30,14 @@ PortOS is a single-user, internal tool running on a private network behind Tails## Architecture-PortOS is a monorepo with Express.js server (port 5554) and React/Vite client (port 5555). PM2 manages app lifecycles. Data persists to JSON files in `./data/`.+PortOS is a monorepo with Express.js server (port 5555) and React/Vite client (port 5554). PM2 manages app lifecycles. Data persists to JSON files in `./data/`.### Port AllocationPortOS uses ports 5554-5560. Define all ports in `ecosystem.config.cjs` using the `ports` object:```javascript-ports: { api: 5554, health: 5555 } // labeled ports for documentation+ports: { api: 5555, health: 5554 } // labeled ports for documentation```See `docs/PORTS.md` for the full port allocation guide.diff --git a/README.md b/README.mdindex 683600f9a1..8916982a57 100644--- a/README.md+++ b/README.md@@ -77,7 +77,7 @@ pm2 start ecosystem.config.cjspm2 save```-Access PortOS at http://localhost:5555 (or via Tailscale at http://[your-machine]:5555). PM2 keeps PortOS running in the background and auto-restarts on reboot (with `pm2 save` + `pm2 startup`).+Access PortOS at http://localhost:5554 (or via Tailscale at http://[your-machine]:5554). PM2 keeps PortOS running in the background and auto-restarts on reboot (with `pm2 save` + `pm2 startup`).## Network Access@@ -93,8 +93,8 @@ PortOS binds to `0.0.0.0` so you can access it from any device on your Tailscale```PortOS/-├── client/ # React + Vite frontend (port 5555)-├── server/ # Express.js API (port 5554)+├── client/ # React + Vite frontend (port 5554)+├── server/ # Express.js API (port 5555)├── data/ # Runtime data (apps, providers, history)├── data.sample/ # Sample configurations to copy├── docs/ # Documentation and screenshotsdiff --git a/autofixer/ui.js b/autofixer/ui.jsindex fc089d7f83..89f738c384 100644--- a/autofixer/ui.js+++ b/autofixer/ui.js@@ -850,7 +850,7 @@ app.get('/', async (req, res) => {// Set dynamic PortOS Dashboard linkdocument.getElementById('portosDashboardLink').href =- window.location.protocol + '//' + window.location.hostname + ':5555';+ window.location.protocol + '//' + window.location.hostname + ':5554';// Initial loadfetchApps();diff --git a/client/package.json b/client/package.jsonindex e4f9c18690..5a2965cd2b 100644--- a/client/package.json+++ b/client/package.json@@ -4,7 +4,7 @@"private": true,"type": "module","scripts": {- "dev": "vite --host 0.0.0.0 --port 5555",+ "dev": "vite --host 0.0.0.0 --port 5554","build": "vite build","preview": "vite preview"},diff --git a/client/src/pages/Instances.jsx b/client/src/pages/Instances.jsxindex 3f72b12d5d..622fead94d 100644--- a/client/src/pages/Instances.jsx+++ b/client/src/pages/Instances.jsx@@ -137,7 +137,7 @@ function SelfCard({ self, onUpdate }) {function AddPeerForm({ onAdd }) {const [address, setAddress] = useState('');- const [port, setPort] = useState('5554');+ const [port, setPort] = useState('5555');const [name, setName] = useState('');const [adding, setAdding] = useState(false);@@ -151,7 +151,7 @@ function AddPeerForm({ onAdd }) {setAdding(false);if (!result) return;setAddress('');- setPort('5554');+ setPort('5555');setName('');onAdd();toast.success('Peer added');diff --git a/client/src/pages/Security.jsx b/client/src/pages/Security.jsxindex 931be6e551..d51526c330 100644--- a/client/src/pages/Security.jsx+++ b/client/src/pages/Security.jsx@@ -148,16 +148,15 @@ export default function Security() {if (!streaming) return;const timestamp = Date.now();- const protocol = window.location.protocol;// Set video source to server streamif (videoRef.current && videoEnabled) {- videoRef.current.src = `${protocol}//${window.location.hostname}:5554/api/media/video?t=${timestamp}`;+ videoRef.current.src = `/api/media/video?t=${timestamp}`;}// Set audio source to server stream and set up analyzerif (audioRef.current && audioEnabled) {- audioRef.current.src = `${protocol}//${window.location.hostname}:5554/api/media/audio?t=${timestamp}`;+ audioRef.current.src = `/api/media/audio?t=${timestamp}`;audioRef.current.play().then(() => {setupAudioAnalyser(audioRef.current);diff --git a/client/vite.config.js b/client/vite.config.jsindex 02c221ffd8..a896053ddc 100644--- a/client/vite.config.js+++ b/client/vite.config.js@@ -4,13 +4,13 @@ import react from '@vitejs/plugin-react';export default defineConfig(({ mode }) => {const env = loadEnv(mode, process.cwd(), 'VITE_');const API_HOST = env.VITE_API_HOST || 'localhost';- const API_TARGET = `http://${API_HOST}:5554`;+ const API_TARGET = `http://${API_HOST}:5555`;return {plugins: [react()],server: {host: '0.0.0.0',- port: 5555,+ port: 5554,open: false,proxy: {'/api': {diff --git a/docs/API.md b/docs/API.mdindex 535648b870..84a33825f1 100644--- a/docs/API.md+++ b/docs/API.md@@ -1,11 +1,11 @@# API Reference-PortOS exposes a REST API on port 5554 and WebSocket events via Socket.IO.+PortOS exposes a REST API on port 5555 and WebSocket events via Socket.IO.## Base URL```-http://localhost:5554/api+http://localhost:5555/api```## Security Model@@ -427,7 +427,7 @@ PortOS is designed for personal/developer use on trusted networks. It implements## WebSocket Events-Connect to Socket.IO at `http://localhost:5554`.+Connect to Socket.IO at `http://localhost:5555`.### Log Streaming@@ -573,7 +573,7 @@ socket.on('provider:status:changed', ({ providerId, status, reason }) => {### Register an App```bash-curl -X POST http://localhost:5554/api/apps \+curl -X POST http://localhost:5555/api/apps \-H "Content-Type: application/json" \-d '{"name": "My App",@@ -587,7 +587,7 @@ curl -X POST http://localhost:5554/api/apps \### Execute AI Run```bash-curl -X POST http://localhost:5554/api/runs \+curl -X POST http://localhost:5555/api/runs \-H "Content-Type: application/json" \-d '{"prompt": "List all files in the current directory",@@ -598,7 +598,7 @@ curl -X POST http://localhost:5554/api/runs \### Get PM2 Process Logs```bash-curl http://localhost:5554/api/logs/portos-server?lines=50+curl http://localhost:5555/api/logs/portos-server?lines=50```## Error Responsesdiff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.mdindex 51f02e4aad..ea9ea6efe6 100644--- a/docs/ARCHITECTURE.md+++ b/docs/ARCHITECTURE.md@@ -11,7 +11,7 @@ PortOS is a monorepo application with a React frontend and Express.js backend, m│ ││ ┌────────────────────┐ ┌──────────────────────────────────────┐ ││ │ React Client │ │ Express Server │ │-│ │ (port 5555) │ HTTP │ (port 5554) │ │+│ │ (port 5554) │ HTTP │ (port 5555) │ ││ │ │ <---------> │ │ ││ │ ┌──────────────┐ │ │ ┌──────────┐ ┌──────────────────┐ │ ││ │ │ Pages │ │ │ │ Routes │──│ Services │ │ │@@ -304,8 +304,8 @@ Error severity levels:| Process | Port | Script | Purpose ||---------|------|--------|---------|-| portos-server | 5554 | `server/index.js` | Main Express API server |-| portos-client | 5555 | `client/` (Vite) | React frontend dev server |+| portos-client | 5554 | `client/` (Vite) | React frontend dev server |+| portos-server | 5555 | `server/index.js` | Main Express API server || portos-browser | 5556 (CDP), 5557 (health) | `browser/server.js` | Persistent Chromium with CDP for web automation || portos-cos | 5558 | `server/cos-runner/index.js` | Isolated CoS agent runner || portos-autofixer | 5559 | `autofixer/server.js` | Autonomous crash detection and Claude CLI repair |diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.mdindex cbaee817ec..5e1c28efe2 100644--- a/docs/CONTRIBUTING.md+++ b/docs/CONTRIBUTING.md@@ -75,12 +75,12 @@ refactor: code restructuring```PortOS/-├── client/ # React + Vite frontend (port 5555)+├── client/ # React + Vite frontend (port 5554)│ └── src/│ ├── components/│ ├── pages/│ └── services/-├── server/ # Express.js API (port 5554)+├── server/ # Express.js API (port 5555)│ ├── routes/│ ├── services/│ └── lib/diff --git a/docs/PORTS.md b/docs/PORTS.mdindex eff8eda2d6..2c1c531bad 100644--- a/docs/PORTS.md+++ b/docs/PORTS.md@@ -23,8 +23,8 @@ Common port labels:| Port | Process | Label | Description ||------|---------|-------|-------------|-| 5554 | portos-server | api | Main API server |-| 5555 | portos-client | ui | Vite dev server (React UI) |+| 5554 | portos-client | ui | Vite dev server (React UI) |+| 5555 | portos-server | api | Main API server || 5556 | portos-browser | cdp | Chrome DevTools Protocol || 5557 | portos-browser | health | Browser health check API || 5558 | portos-cos | api | CoS Agent Runner (isolated process) |@@ -101,10 +101,10 @@ PortOS automatically detects ports from env vars:## Viewing Port UsageThe PortOS apps list shows all ports for each process:-- Single port: `process-name:5554`+- Single port: `process-name:5555`- Multiple ports: `process-name (cdp:5556,health:5557)`Use the API to get detailed port information:```bash-curl http://localhost:5554/api/apps | jq '.[].processes'+curl http://localhost:5555/api/apps | jq '.[].processes'```diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.mdindex 604d16bd9c..478f0bb86e 100644--- a/docs/TROUBLESHOOTING.md+++ b/docs/TROUBLESHOOTING.md@@ -56,8 +56,8 @@ cp -r data.sample/* data/```bash# Verify server is listening on all interfaces-netstat -an | grep 5554-# Should show: *.5554 or 0.0.0.0:5554+netstat -an | grep 5555+# Should show: *.5555 or 0.0.0.0:5555```### WebSocket Disconnectionsdiff --git a/docs/features/browser.md b/docs/features/browser.mdindex 9e73f48a81..6c606b3efd 100644--- a/docs/features/browser.md+++ b/docs/features/browser.md@@ -7,7 +7,7 @@ Manage the persistent CDP/Playwright browser instance used by PortOS for web autThe browser runs as a separate PM2 process (`portos-browser`) that launches a Chromium instance with Chrome DevTools Protocol (CDP) enabled. The PortOS server communicates with it via HTTP health checks and the CDP debug endpoint.```-PortOS Server (5554)+PortOS Server (5555)├── /api/browser routes → browserService.js│ ├── Health check → portos-browser health endpoint (5557)│ ├── CDP pages → CDP debug endpoint (5556)diff --git a/docs/features/cos-agent-runner.md b/docs/features/cos-agent-runner.mdindex 40bd60ee83..b1afac944a 100644--- a/docs/features/cos-agent-runner.md+++ b/docs/features/cos-agent-runner.md@@ -19,7 +19,7 @@ A separate `portos-cos` PM2 process that:```┌─────────────────┐ HTTP/Socket.IO ┌─────────────────┐│ portos-server │ ──────────────────► │ portos-cos │-│ (5554) │ spawn/terminate │ (5558) │+│ (5555) │ spawn/terminate │ (5558) ││ │ ◄────────────────── │ ││ subAgentSpawner│ events/output │ cos-runner │└─────────────────┘ └────────┬────────┘diff --git a/ecosystem.config.cjs b/ecosystem.config.cjsindex ae1d8281eb..4e3406289b 100644--- a/ecosystem.config.cjs+++ b/ecosystem.config.cjs@@ -12,8 +12,8 @@ const BASE_ENV = {};const PORTS = {- API: 5554, // Express API server- UI: 5555, // Vite dev server (client)+ API: 5555, // Express API server+ UI: 5554, // Vite dev server (client)CDP: 5556, // Chrome DevTools Protocol (browser automation)CDP_HEALTH: 5557, // Browser health check endpointCOS: 5558, // Chief of Staff agent runnerdiff --git a/package-lock.json b/package-lock.jsonindex 8f2e9c24c8..08337c3dcc 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "portos",- "version": "1.22.3",+ "version": "1.23.0","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "portos",- "version": "1.22.3",+ "version": "1.23.0","license": "MIT","dependencies": {"express": "^4.21.2",diff --git a/package.json b/package.jsonindex ab43001b5f..37c8b8aa9f 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "portos",- "version": "1.22.3",+ "version": "1.23.0","private": true,"description": "Local dev machine App OS portal","author": "Adam Eivy (@antic|@atomantic)",diff --git a/server/index.js b/server/index.jsindex 015fbe93ff..6d2bc42c48 100644--- a/server/index.js+++ b/server/index.js@@ -76,7 +76,7 @@ const __dirname = dirname(__filename);const app = express();const httpServer = createServer(app);-const PORT = process.env.PORT || 5554;+const PORT = process.env.PORT || 5555;const HOST = process.env.HOST || '0.0.0.0';// Socket.IO with relative path support for Tailscalediff --git a/server/lib/ports.js b/server/lib/ports.jsnew file mode 100644index 0000000000..30c433ac75--- /dev/null+++ b/server/lib/ports.js@@ -0,0 +1,4 @@+export const PORTS = { API: 5555, UI: 5554 };+export const DEFAULT_PEER_PORT = PORTS.API;+export const PORTOS_UI_URL = process.env.PORTOS_UI_URL+ || `http://localhost:${process.env.PORT_UI || PORTS.UI}`;diff --git a/server/lib/validation.test.js b/server/lib/validation.test.jsindex b85d958e42..7ebb4ac6b5 100644--- a/server/lib/validation.test.js+++ b/server/lib/validation.test.js@@ -126,10 +126,10 @@ describe('validation.js', () => {});it('should accept valid devUiPort', () => {- const app = { name: 'Test', repoPath: '/path', devUiPort: 5555 };+ const app = { name: 'Test', repoPath: '/path', devUiPort: 5554 };const result = appSchema.safeParse(app);expect(result.success).toBe(true);- expect(result.data.devUiPort).toBe(5555);+ expect(result.data.devUiPort).toBe(5554);});it('should allow devUiPort to be null', () => {diff --git a/server/routes/apps.test.js b/server/routes/apps.test.jsindex ae005f2735..6693146dcd 100644--- a/server/routes/apps.test.js+++ b/server/routes/apps.test.js@@ -299,7 +299,7 @@ describe('Apps Routes', () => {name: 'Test App',pm2ProcessNames: ['test-app'],repoPath: '/tmp/test',- processes: [{ name: 'test-app', ports: { devUi: 5555 } }]+ processes: [{ name: 'test-app', ports: { devUi: 5554 } }]}];appsService.getAllApps.mockResolvedValue(mockApps);pm2Service.listProcesses.mockResolvedValue([]);@@ -307,7 +307,7 @@ describe('Apps Routes', () => {const response = await request(app).get('/api/apps');expect(response.status).toBe(200);- expect(response.body[0].devUiPort).toBe(5555);+ expect(response.body[0].devUiPort).toBe(5554);});it('should use explicit devUiPort over derived value', async () => {@@ -317,7 +317,7 @@ describe('Apps Routes', () => {pm2ProcessNames: ['test-app'],repoPath: '/tmp/test',devUiPort: 4444,- processes: [{ name: 'test-app', ports: { devUi: 5555 } }]+ processes: [{ name: 'test-app', ports: { devUi: 5554 } }]}];appsService.getAllApps.mockResolvedValue(mockApps);pm2Service.listProcesses.mockResolvedValue([]);diff --git a/server/routes/instances.js b/server/routes/instances.jsindex 624f79ce3d..5411942d4f 100644--- a/server/routes/instances.js+++ b/server/routes/instances.js@@ -8,6 +8,7 @@ import { Router } from 'express';import { z } from 'zod';import * as instances from '../services/instances.js';import { asyncHandler, ServerError } from '../lib/errorHandler.js';+import { DEFAULT_PEER_PORT } from '../lib/ports.js';const router = Router();@@ -16,7 +17,7 @@ const addPeerSchema = z.object({address: z.string().regex(/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/, 'Must be a valid IP address').refine(ip => !ip.startsWith('127.') && !ip.startsWith('169.254.'), 'Loopback and link-local addresses are not allowed'),- port: z.number().int().min(1).max(65535).default(5554),+ port: z.number().int().min(1).max(65535).default(DEFAULT_PEER_PORT),name: z.string().optional()});diff --git a/server/scripts/moltworld-explore.mjs b/server/scripts/moltworld-explore.mjsindex 8450a2d272..5d9d9de5f2 100755--- a/server/scripts/moltworld-explore.mjs+++ b/server/scripts/moltworld-explore.mjs@@ -22,7 +22,7 @@* MOLTWORLD_MIN_INTERVAL - Min seconds between joins (default: 180 = 3 min)* MOLTWORLD_MAX_INTERVAL - Max seconds between joins (default: 540 = 9 min)* MOLTWORLD_USE_WS - Set to "true" to route moves through PortOS WS relay- * PORTOS_API_BASE - PortOS server URL (default: http://localhost:5554)+ * PORTOS_API_BASE - PortOS server URL (default: http://localhost:5555)* LMSTUDIO_BASE_URL - LM Studio URL (default: http://localhost:1234)* LMSTUDIO_MODEL - Model name (default: gpt-oss-20b)* LMSTUDIO_ENABLED - Set to "false" to disable (default: true)@@ -54,7 +54,7 @@ const MAX_INTERVAL_S = parseInt(process.env.MOLTWORLD_MAX_INTERVAL, 10) || 540;// PortOS WebSocket relay configconst USE_WS = process.env.MOLTWORLD_USE_WS === 'true';-const PORTOS_API_BASE = process.env.PORTOS_API_BASE || 'http://localhost:5554';+const PORTOS_API_BASE = process.env.PORTOS_API_BASE || 'http://localhost:5555';// LM Studio configconst LMSTUDIO_URL = process.env.LMSTUDIO_BASE_URL || 'http://localhost:1234';diff --git a/server/services/apps.js b/server/services/apps.jsindex 312068687d..c19a9f493f 100644--- a/server/services/apps.js+++ b/server/services/apps.js@@ -4,6 +4,7 @@ import { v4 as uuidv4 } from 'uuid';import EventEmitter from 'events';import { ensureDir, readJSONFile, PATHS } from '../lib/fileUtils.js';import { SELF_IMPROVEMENT_TASK_TYPES } from './taskSchedule.js';+import { PORTS } from '../lib/ports.js';const DATA_DIR = PATHS.data;const APPS_FILE = join(DATA_DIR, 'apps.json');@@ -20,9 +21,9 @@ function buildPortosApp() {description: 'Local App OS portal for dev machines',repoPath: PATHS.root,type: 'express',- uiPort: 5554,- devUiPort: 5555,- apiPort: 5554,+ uiPort: PORTS.API,+ devUiPort: PORTS.UI,+ apiPort: PORTS.API,buildCommand: 'npm run build',startCommands: ['npm start'],pm2ProcessNames: [@@ -34,9 +35,9 @@ function buildPortosApp() {'portos-browser'],processes: [- { name: 'portos-server', port: 5554, ports: { api: 5554 } },+ { name: 'portos-server', port: PORTS.API, ports: { api: PORTS.API } },{ name: 'portos-cos', port: 5558, ports: { api: 5558 } },- { name: 'portos-ui', port: 5555, ports: { devUi: 5555 } },+ { name: 'portos-ui', port: PORTS.UI, ports: { devUi: PORTS.UI } },{ name: 'portos-autofixer', port: 5559, ports: { api: 5559 } },{ name: 'portos-autofixer-ui', port: 5560, ports: { ui: 5560 } },{ name: 'portos-browser', port: 5556, ports: { cdp: 5556, health: 5557 } }@@ -400,8 +401,8 @@ export async function getReservedPorts() {}// Also reserve PortOS ports- ports.add(5554);- ports.add(5555);+ ports.add(PORTS.API);+ ports.add(PORTS.UI);return Array.from(ports).sort((a, b) => a - b);}diff --git a/server/services/cos.js b/server/services/cos.jsindex 84a67e2f4b..7d4cded4cc 100644--- a/server/services/cos.js+++ b/server/services/cos.js@@ -29,7 +29,7 @@ import { recordDecision, DECISION_TYPES } from './decisionLog.js';import { cosEvents as _cosEvents } from './cosEvents.js';export const cosEvents = _cosEvents;-const PORTOS_UI_URL = process.env.PORTOS_UI_URL || `http://localhost:${process.env.PORT_UI || 5555}`;+import { PORTOS_UI_URL } from '../lib/ports.js';const _execAsync = promisify(exec);const _execFileAsync = promisify(execFile);diff --git a/server/services/instances.js b/server/services/instances.jsindex ee14215ee1..60b7cbc07c 100644--- a/server/services/instances.js+++ b/server/services/instances.js@@ -12,6 +12,7 @@ import { dataPath, readJSONFile, ensureDir, PATHS } from '../lib/fileUtils.js';import { createMutex } from '../lib/asyncMutex.js';import { instanceEvents } from './instanceEvents.js';import { connectToPeer, disconnectFromPeer } from './peerSocketRelay.js';+import { DEFAULT_PEER_PORT } from '../lib/ports.js';const INSTANCES_FILE = dataPath('instances.json');const PROBE_TIMEOUT_MS = 5000;@@ -85,7 +86,7 @@ export async function getPeers() {return data.peers;}-export async function addPeer({ address, port = 5554, name }) {+export async function addPeer({ address, port = DEFAULT_PEER_PORT, name }) {const peer = await withData(async (data) => {const entry = {id: crypto.randomUUID(),@@ -287,7 +288,7 @@ async function announceSelf(address, port) {const data = await loadData();if (!data.self) return;- const selfPort = parseInt(process.env.PORT, 10) || 5554;+ const selfPort = parseInt(process.env.PORT, 10) || DEFAULT_PEER_PORT;const url = `http://${address}:${port}/api/instances/peers/announce`;const controller = new AbortController();diff --git a/server/services/selfImprovement.js b/server/services/selfImprovement.jsindex d9d079a6bc..49903b7ede 100644--- a/server/services/selfImprovement.js+++ b/server/services/selfImprovement.js@@ -13,8 +13,7 @@*/import { cosEvents, getConfig } from './cos.js';--const PORTOS_UI_URL = process.env.PORTOS_UI_URL || `http://localhost:${process.env.PORT_UI || 5555}`;+import { PORTOS_UI_URL } from '../lib/ports.js';// Known routes to analyzeconst ROUTES = [diff --git a/server/services/streamingDetect.js b/server/services/streamingDetect.jsindex 8e2752fa3d..394839a2ea 100644--- a/server/services/streamingDetect.js+++ b/server/services/streamingDetect.js@@ -54,7 +54,7 @@ export function parseEcosystemConfig(content) {// Extract PORTS object - handles both flat and nested structures// Flat: const PORTS = { WEB: 5550, API: 5551 }- // Nested: const PORTS = { server: { api: 5554 }, client: { ui: 5555 } }+ // Nested: const PORTS = { server: { api: 5555 }, client: { ui: 5554 } }const portsObjStart = content.match(/(?:const|let|var)\s+PORTS\s*=\s*\{/);if (portsObjStart) {const startIdx = portsObjStart.index + portsObjStart[0].length - 1;diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.jsindex 5097283d5b..6d506072c7 100644--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@ -21,8 +21,7 @@ import { cosEvents, emitLog } from './cos.js';import { readJSONFile } from '../lib/fileUtils.js';import { getAdaptiveCooldownMultiplier } from './taskLearning.js';import { isTaskTypeEnabledForApp, getAppTaskTypeInterval, getActiveApps, getAppTaskTypeOverrides } from './apps.js';--const PORTOS_UI_URL = process.env.PORTOS_UI_URL || `http://localhost:${process.env.PORT_UI || 5555}`;+import { PORTOS_UI_URL } from '../lib/ports.js';const __filename = fileURLToPath(import.meta.url);const __dirname = dirname(__filename);