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): redact install paths from the pm2 probe's failure log

[._.]/ Adam Eivy6948a10fe112
diff --git a/scripts/pm2-daemon-refresh.js b/scripts/pm2-daemon-refresh.js
index ed6fb26fa2..1c9d196b51 100644
--- a/scripts/pm2-daemon-refresh.js
+++ b/scripts/pm2-daemon-refresh.js
@@ -28,6 +28,7 @@
*/
import { readFileSync, realpathSync } from 'fs';
+import { homedir } from 'os';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { isDirectlyInvoked } from './lib/directInvocation.js';
@@ -127,6 +128,25 @@ async function fetchReport(pm2) {
}
}
+/**
+ * Replace this install's own paths in a probe error before it is logged.
+ *
+ * A pm2 socket or package-read failure names absolute paths, and update.sh
+ * appends everything here to data/update.log — which backups sweep up. The
+ * repo-root and home substitutions keep the message diagnostic (which file,
+ * which errno) without carrying the OS username off the machine.
+ * @param {string} message
+ */
+export function redactPaths(message) {
+ const home = homedir();
+ return String(message ?? '')
+ // Repo root first — it lives under home, so the broader rule would eat it.
+ .split(ROOT_DIR)
+ .join('<repo>')
+ .split(home)
+ .join('~');
+}
+
async function runCli() {
let verdict = { needed: true, reason: 'could not inspect the running daemon' };
try {
@@ -138,7 +158,7 @@ async function runCli() {
expectedVersion: JSON.parse(readFileSync(join(pm2Dir, 'package.json'), 'utf8')).version,
});
} catch (err) {
- verdict = { needed: true, reason: `daemon probe failed: ${err.message}` };
+ verdict = { needed: true, reason: `daemon probe failed: ${redactPaths(err.message)}` };
}
console.log(`${verdict.needed ? '🔄' : '✅'} PM2 daemon refresh ${verdict.needed ? 'needed' : 'skipped'}: ${verdict.reason}`);
return verdict.needed ? 0 : 1;
diff --git a/scripts/pm2-daemon-refresh.test.js b/scripts/pm2-daemon-refresh.test.js
index b97f81ab6a..f3c148535d 100644
--- a/scripts/pm2-daemon-refresh.test.js
+++ b/scripts/pm2-daemon-refresh.test.js
@@ -1,8 +1,8 @@
import { afterAll, describe, expect, it } from 'vitest';
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'fs';
-import { tmpdir } from 'os';
+import { homedir, tmpdir } from 'os';
import { join } from 'path';
-import { daemonEntryFromArgv, daemonNeedsRefresh } from './pm2-daemon-refresh.js';
+import { daemonEntryFromArgv, daemonNeedsRefresh, redactPaths } from './pm2-daemon-refresh.js';
// A real file on disk, because the path comparison realpath()s both sides — a
// fixture that doesn't exist would silently take the literal-spelling fallback
@@ -74,3 +74,22 @@ describe('daemonNeedsRefresh', () => {
expect(check({ argv: ['/usr/bin/node', spelled] }).needed).toBe(false);
});
});
+
+describe('redactPaths', () => {
+ it('strips the home directory so the OS username never reaches update.log', () => {
+ // update.sh appends this to data/update.log, which backup snapshots sweep up.
+ const message = `ENOENT: no such file, open '${join(homedir(), 'somewhere', 'package.json')}'`;
+ const redacted = redactPaths(message);
+ expect(redacted).not.toContain(homedir());
+ // join(), not a forward-slash literal — the separator is a backslash on Windows.
+ expect(redacted).toContain(join('~', 'somewhere', 'package.json'));
+ });
+
+ it('keeps the diagnostic parts of the message intact', () => {
+ expect(redactPaths('pm2 getReport timed out after 15000ms')).toBe('pm2 getReport timed out after 15000ms');
+ });
+
+ it('survives a missing message', () => {
+ expect(redactPaths(undefined)).toBe('');
+ });
+});