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
fix(standardize): emit the ecosystem file as an object literal the port parser can still read
Adam Eivy7f12de15eece
diff --git a/server/services/pm2Standardizer.js b/server/services/pm2Standardizer.jsindex a2b9d72bc3..4954f15bd3 100644--- a/server/services/pm2Standardizer.js+++ b/server/services/pm2Standardizer.js@@ -433,6 +433,23 @@ function parseAnalysisResponse(response, promptToStrip = '') {/*** Generate ecosystem.config.cjs content from processes*/+const IDENTIFIER_KEY_RE = /^[A-Za-z_$][\w$]*$/;++/** A JS object literal with unquoted identifier keys; every other token is JSON-encoded. */+function jsObjectLiteral(value, depth = 1) {+ const pad = ' '.repeat(depth);+ const close = ' '.repeat(depth - 1);+ if (Array.isArray(value)) {+ return value.length === 0 ? '[]' : `[\n${value.map((item) => `${pad}${jsObjectLiteral(item, depth + 1)}`).join(',\n')}\n${close}]`;+ }+ if (value !== null && typeof value === 'object') {+ const entries = Object.entries(value).filter(([, item]) => item !== undefined);+ if (entries.length === 0) return '{}';+ return `{\n${entries.map(([key, item]) => `${pad}${IDENTIFIER_KEY_RE.test(key) ? key : JSON.stringify(key)}: ${jsObjectLiteral(item, depth + 1)}`).join(',\n')}\n${close}}`;+ }+ return JSON.stringify(value) ?? 'null';+}+function generateEcosystemContent(processes, appName) {const apps = processes.map(proc => {const config = {@@ -463,13 +480,16 @@ function generateEcosystemContent(processes, appName) {return config;});- // Plain JSON is a valid JS object literal and PM2 `require()`s this file.- // Every process field is model output steered by the scanned repository, so- // the old quote rewrite (which left `'` unescaped) could turn a value into code.+ // PM2 `require()`s this file and parseEcosystemConfig (streamingDetect.js)+ // reads it back with regexes keyed on bare `name:` / `ports:` / `env:` keys,+ // so the literal keeps identifier keys unquoted. Every value is model output+ // steered by the scanned repository: strings are JSON-encoded (the old quote+ // rewrite left `'` free to close the string and run code on load) and a key+ // that is not an identifier is quoted the same way.return `// PM2 Ecosystem Configuration// ${PORTOS_ECOSYSTEM_MARKER}-module.exports = ${JSON.stringify({ apps }, null, 2)};+module.exports = ${jsObjectLiteral({ apps })};`;}diff --git a/server/services/pm2Standardizer.test.js b/server/services/pm2Standardizer.test.jsindex 846d37cd05..0c542c8892 100644--- a/server/services/pm2Standardizer.test.js+++ b/server/services/pm2Standardizer.test.js@@ -400,12 +400,16 @@ describe('applyStandardization — preserve existing ecosystem.config.cjs', () =describe('model-authored plan fields at the apply sink', () => {it('emits an ecosystem file PM2 can load even when a model string carries quotes', () => {const hostile = "x' + require('child_process').execSync('id') + '";- const content = standardizerInternals.generateEcosystemContent([{ name: "it's", cwd: '.', script: 'x.js', env: { HOSTILE: hostile, 'key"name': 1 } }], 'app');+ const content = standardizerInternals.generateEcosystemContent([{ name: "it's", cwd: '.', script: 'x.js', ports: { ui: 5570 }, env: { HOSTILE: hostile, 'key"name': 1, 'a: 1, b': 2 } }], 'app');expect(content).toContain(PORTOS_ECOSYSTEM_MARKER);+ // parseEcosystemConfig (streamingDetect.js) keys on bare identifier keys.+ expect(content).toMatch(/\n\s+name: "it's",\n/);+ expect(content).toMatch(/\n\s+ports: \{\n\s+ui: 5570\n/);const module = { exports: {} };new Function('module', content)(module);expect(module.exports.apps[0].env.HOSTILE).toBe(hostile);expect(module.exports.apps[0].env['key"name']).toBe(1);+ expect(module.exports.apps[0].env['a: 1, b']).toBe(2);expect(module.exports.apps[0].name).toBe("it's");});