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
address review: validate deploy flags, guard deploy handler errors, resolve remote ref fallback, validate submodule path type, use structured backup error code
Adam Eivy1b34e41af719
diff --git a/server/lib/socketValidation.js b/server/lib/socketValidation.jsindex 63fe8e6db8..7bbf848287 100644--- a/server/lib/socketValidation.js+++ b/server/lib/socketValidation.js@@ -59,9 +59,15 @@ export const appStandardizeSchema = z.object({});// app:deploy — app ID and optional flags for Xcode deploy+const appDeployFlagSchema = z.string()+ .trim()+ .min(1, 'flag cannot be empty')+ .max(64, 'flag must be 64 characters or fewer')+ .regex(/^--?[A-Za-z0-9][A-Za-z0-9-]*$/, 'flag must be a valid CLI flag (e.g. -f or --force)');+export const appDeploySchema = z.object({appId: z.string().min(1, 'appId is required'),- flags: z.array(z.string()).default([])+ flags: z.array(appDeployFlagSchema).max(20, 'no more than 20 flags are allowed').default([])});// =============================================================================diff --git a/server/routes/git.js b/server/routes/git.jsindex 08c0eaa04c..72a00c29b3 100644--- a/server/routes/git.js+++ b/server/routes/git.js@@ -29,8 +29,8 @@ router.get('/submodules/status', asyncHandler(async (req, res) => {// POST /api/git/submodules/update - Update a specific submodulerouter.post('/submodules/update', asyncHandler(async (req, res) => {const { path } = req.body;- if (!path) {- throw new ServerError('path is required', { status: 400, code: 'VALIDATION_ERROR' });+ if (!path || typeof path !== 'string') {+ throw new ServerError('path must be a non-empty string', { status: 400, code: 'VALIDATION_ERROR' });}const newCommit = await git.updateSubmodule(path);res.json({ success: true, newCommit });diff --git a/server/services/git.js b/server/services/git.jsindex 06468d0194..16313ef702 100644--- a/server/services/git.js+++ b/server/services/git.js@@ -962,9 +962,25 @@ export async function getSubmodules() {async function fetchRemoteInfo(fullPath, currentCommit) {await execGitSafe(['fetch', 'origin'], fullPath, { timeout: 15000 });+ // Resolve the remote default branch — origin/HEAD may not exist in all clones+ let remoteRef = 'origin/HEAD';+ const headCheck = await execGitSafe(['rev-parse', 'origin/HEAD'], fullPath);+ if (headCheck.exitCode !== 0) {+ // Fallback: try origin/main then origin/master+ const mainCheck = await execGitSafe(['rev-parse', 'origin/main'], fullPath);+ if (mainCheck.exitCode === 0) {+ remoteRef = 'origin/main';+ } else {+ const masterCheck = await execGitSafe(['rev-parse', 'origin/master'], fullPath);+ if (masterCheck.exitCode === 0) {+ remoteRef = 'origin/master';+ }+ }+ }+const [latestResult, msgResult] = await Promise.all([- execGitSafe(['rev-parse', 'origin/HEAD'], fullPath),- execGitSafe(['log', '-1', '--format=%s', 'origin/HEAD'], fullPath)+ execGitSafe(['rev-parse', remoteRef], fullPath),+ execGitSafe(['log', '-1', '--format=%s', remoteRef], fullPath)]);let latestCommit = null;@@ -972,7 +988,7 @@ async function fetchRemoteInfo(fullPath, currentCommit) {if (latestResult.exitCode === 0) {latestCommit = latestResult.stdout.trim().substring(0, 7);const countResult = await execGitSafe(- ['rev-list', '--count', `${currentCommit}..origin/HEAD`],+ ['rev-list', '--count', `${currentCommit}..${remoteRef}`],fullPath);behind = parseInt(countResult.stdout.trim(), 10) || 0;diff --git a/server/services/pm2Standardizer.js b/server/services/pm2Standardizer.jsindex 0c5fb6daf2..6be1553d73 100644--- a/server/services/pm2Standardizer.js+++ b/server/services/pm2Standardizer.js@@ -321,7 +321,7 @@ export async function createGitBackup(repoPath) {// Refuse to overwrite uncommitted changesconst { stdout: statusOut } = await execAsync('git status --porcelain', { cwd: repoPath, windowsHide: true });if (statusOut.trim()) {- return { success: false, reason: 'Working tree has uncommitted changes — commit or discard them before standardizing' };+ return { success: false, code: 'DIRTY_WORKTREE', reason: 'Working tree has uncommitted changes — commit or discard them before standardizing' };}const timestamp = Date.now();@@ -422,7 +422,7 @@ export async function applyStandardization(repoPath, plan) {console.log(`📦 Created backup branch: ${backup.branch}`);} else {console.log(`⚠️ Could not create backup: ${backup.reason}`);- if (backup.reason?.includes('uncommitted changes')) {+ if (backup.code === 'DIRTY_WORKTREE') {return { success: false, error: backup.reason, filesModified: [], errors: [backup.reason] };}}diff --git a/server/services/socket.js b/server/services/socket.jsindex f616a031ca..496442e03a 100644--- a/server/services/socket.js+++ b/server/services/socket.js@@ -393,7 +393,13 @@ export function initSocket(io) {const data = validateSocketData(appDeploySchema, rawData, socket, 'app:deploy');if (!data) return;- const app = await appsService.getAppById(data.appId);+ let app;+ try {+ app = await appsService.getAppById(data.appId);+ } catch (err) {+ socket.emit('app:deploy:error', { message: `Failed to look up app: ${err.message}` });+ return;+ }if (!app) {socket.emit('app:deploy:error', { message: 'App not found' });return;@@ -409,7 +415,14 @@ export function initSocket(io) {socket.emit(`app:deploy:${type}`, { ...payload, timestamp: Date.now() });};- const result = await appDeployer.deployApp(app, data.flags, emit);+ let result;+ try {+ result = await appDeployer.deployApp(app, data.flags, emit);+ } catch (err) {+ console.error(`❌ Deploy error for ${app.name}: ${err.message}`);+ socket.emit('app:deploy:error', { message: err.message });+ return;+ }socket.emit('app:deploy:complete', { success: result.success, code: result.code });console.log(`${result.success ? '✅' : '❌'} Deploy ${result.success ? 'complete' : 'failed'} for ${app.name}`);});