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

feat: live activity log for app update/standardize, fix PM2 restart crash

Adam Eivy375acf283c82
diff --git a/.changelog/v1.25.x.md b/.changelog/v1.25.x.md
index 89795e40cf..32f7029f94 100644
--- a/.changelog/v1.25.x.md
+++ b/.changelog/v1.25.x.md
@@ -10,11 +10,14 @@ Reusable ProcessesTab component with per-app process views and a bug fix for cle
- **App Processes Tab**: Each app's detail view now has a "Processes" tab showing only that app's PM2 processes with live logs, restart/stop/start controls
- **Reusable ProcessesTab**: Extracted process management UI into a shared component used by both the DevTools Processes page and app detail views
+- **Live Activity Log**: Update and Standardize PM2 operations now show real-time step progress (git pull, npm install, restart, analyze, backup, apply) via socket streaming instead of just a spinner
+- **Apps Sidebar Dashboard Link**: Apps sidebar section now includes a Dashboard link at top for quick access to the apps list
## 🐛 Fixes
- **Clear Failed Runs**: Fixed "Only filter=failed is supported" error when clicking Clear Failed on the DevTools Runs page — client was sending wrong query parameter
- **CoS Productivity Tab**: Auto-recalculate productivity data from agent history on first visit instead of showing empty state when `productivity.json` hasn't been generated yet
+- **Update with stopped PM2 processes**: Clicking Update on an app whose PM2 processes aren't running no longer crashes — restart failures are captured per-process and reported as warnings while the update still succeeds
## 🔧 Improvements
diff --git a/client/src/components/Layout.jsx b/client/src/components/Layout.jsx
index 81671953b0..45f034d031 100644
--- a/client/src/components/Layout.jsx
+++ b/client/src/components/Layout.jsx
@@ -50,6 +50,7 @@ import {
Compass,
Eye,
Scale,
+ LayoutDashboard,
Lightbulb
} from 'lucide-react';
import packageJson from '../../package.json';
@@ -203,11 +204,15 @@ export default function Layout() {
if (item.dynamic !== 'apps') return item;
return {
...item,
- children: sidebarApps.map(app => ({
- to: `/apps/${app.id}`,
- label: app.name,
- icon: Package
- }))
+ children: [
+ { to: '/apps', label: 'Dashboard', icon: LayoutDashboard, end: true },
+ { separator: true },
+ ...sidebarApps.map(app => ({
+ to: `/apps/${app.id}`,
+ label: app.name,
+ icon: Package
+ }))
+ ]
};
}), [sidebarApps]);
@@ -387,7 +392,10 @@ export default function Layout() {
{/* Children items */}
{expandedSections[item.label] && !collapsed && (
<div className="ml-4 mt-1">
- {item.children.map((child) => {
+ {item.children.map((child, childIndex) => {
+ if (child.separator) {
+ return <div key={`child-sep-${childIndex}`} className="mx-3 my-1 border-t border-port-border" />;
+ }
const ChildIcon = child.icon;
if (child.external) {
const childHref = child.dynamicHost
@@ -409,13 +417,17 @@ export default function Layout() {
</a>
);
}
+ const childActive = child.end
+ ? location.pathname === child.to
+ : isActive(child.to);
return (
<NavLink
key={child.to}
to={child.to}
+ end={child.end}
onClick={() => setMobileOpen(false)}
className={`flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-colors ${
- isActive(child.to)
+ childActive
? 'bg-port-accent/10 text-port-accent'
: 'text-gray-500 hover:text-white hover:bg-port-border/50'
}`}
diff --git a/client/src/components/apps/ActivityLog.jsx b/client/src/components/apps/ActivityLog.jsx
new file mode 100644
index 0000000000..72298a8a49
--- /dev/null
+++ b/client/src/components/apps/ActivityLog.jsx
@@ -0,0 +1,46 @@
+import BrailleSpinner from '../BrailleSpinner';
+import { Check, AlertTriangle, X, SkipForward } from 'lucide-react';
+
+const STATUS_CONFIG = {
+ running: { icon: null, color: 'text-port-accent', bg: 'bg-port-accent/10' },
+ done: { icon: Check, color: 'text-port-success', bg: 'bg-port-success/10' },
+ warning: { icon: AlertTriangle, color: 'text-port-warning', bg: 'bg-port-warning/10' },
+ error: { icon: X, color: 'text-port-error', bg: 'bg-port-error/10' },
+ skipped: { icon: SkipForward, color: 'text-gray-500', bg: 'bg-gray-500/10' },
+};
+
+export default function ActivityLog({ steps, error, completed }) {
+ if (!steps.length && !error) return null;
+
+ return (
+ <div className="mt-3 bg-port-card border border-port-border rounded-lg p-3 space-y-1.5">
+ {steps.map((s) => {
+ const cfg = STATUS_CONFIG[s.status] || STATUS_CONFIG.running;
+ const Icon = cfg.icon;
+ return (
+ <div key={s.step} className={`flex items-start gap-2 px-2 py-1 rounded ${cfg.bg}`}>
+ <span className={`flex-shrink-0 mt-0.5 ${cfg.color}`}>
+ {s.status === 'running' ? <BrailleSpinner text="" className="text-xs" /> : Icon && <Icon size={14} />}
+ </span>
+ <span className="text-xs text-gray-300">
+ <span className="font-mono text-white">{s.step}</span>
+ {s.message && <span className="ml-2 text-gray-400">{s.message}</span>}
+ </span>
+ </div>
+ );
+ })}
+ {error && (
+ <div className="flex items-start gap-2 px-2 py-1 rounded bg-port-error/10">
+ <X size={14} className="text-port-error flex-shrink-0 mt-0.5" />
+ <span className="text-xs text-port-error">{error}</span>
+ </div>
+ )}
+ {completed && !error && (
+ <div className="flex items-start gap-2 px-2 py-1 rounded bg-port-success/10">
+ <Check size={14} className="text-port-success flex-shrink-0 mt-0.5" />
+ <span className="text-xs text-port-success">Operation complete</span>
+ </div>
+ )}
+ </div>
+ );
+}
diff --git a/client/src/components/apps/tabs/OverviewTab.jsx b/client/src/components/apps/tabs/OverviewTab.jsx
index 2d957097ed..6f1f63a5fb 100644
--- a/client/src/components/apps/tabs/OverviewTab.jsx
+++ b/client/src/components/apps/tabs/OverviewTab.jsx
@@ -1,8 +1,10 @@
-import { useState, useEffect } from 'react';
+import { useState, useEffect, useMemo } from 'react';
import { FolderOpen, Terminal, Code, RefreshCw, Wrench, Archive, ArchiveRestore, Ticket, ExternalLink, Download } from 'lucide-react';
import toast from 'react-hot-toast';
import BrailleSpinner from '../../BrailleSpinner';
import EditAppModal from '../EditAppModal';
+import ActivityLog from '../ActivityLog';
+import { useAppOperation } from '../../../hooks/useAppOperation';
import * as api from '../../../services/api';
function KanbanBoard({ tickets }) {
@@ -72,13 +74,16 @@ function KanbanBoard({ tickets }) {
export default function OverviewTab({ app, onRefresh }) {
const [editingApp, setEditingApp] = useState(null);
- const [updating, setUpdating] = useState(false);
const [refreshingConfig, setRefreshingConfig] = useState(false);
- const [standardizing, setStandardizing] = useState(false);
const [archiving, setArchiving] = useState(false);
const [jiraTickets, setJiraTickets] = useState(null);
const [loadingTickets, setLoadingTickets] = useState(false);
+ const onComplete = useMemo(() => () => onRefresh(), [onRefresh]);
+ const { steps, isOperating, operationType, error, completed, startUpdate, startStandardize } = useAppOperation({ onComplete });
+ const updating = isOperating && operationType === 'update';
+ const standardizing = isOperating && operationType === 'standardize';
+
useEffect(() => {
if (app?.jira?.enabled && app.jira.instanceId && app.jira.projectKey) {
setLoadingTickets(true);
@@ -89,14 +94,7 @@ export default function OverviewTab({ app, onRefresh }) {
}
}, [app?.jira?.enabled, app?.jira?.instanceId, app?.jira?.projectKey]);
- const handleUpdate = async () => {
- setUpdating(true);
- const result = await api.pullAndUpdateApp(app.id).catch(() => null);
- setUpdating(false);
- if (result?.success) {
- toast.success(`Updated ${app.name} (${result.steps?.length || 0} steps)`);
- }
- };
+ const handleUpdate = () => startUpdate(app.id);
const handleRefreshConfig = async () => {
setRefreshingConfig(true);
@@ -105,29 +103,7 @@ export default function OverviewTab({ app, onRefresh }) {
onRefresh();
};
- const handleStandardize = async () => {
- setStandardizing(true);
- const analysis = await api.analyzeStandardizationByApp(app.id).catch(err => {
- toast.error(`Analysis failed: ${err.message}`);
- return null;
- });
- if (!analysis?.success) {
- setStandardizing(false);
- return;
- }
- const result = await api.applyStandardizationByApp(app.id, analysis).catch(err => {
- toast.error(`Apply failed: ${err.message}`);
- return null;
- });
- setStandardizing(false);
- if (result?.success) {
- const msg = result.backupBranch
- ? `Standardized! Backup: ${result.backupBranch}`
- : `Standardized ${result.filesModified?.length || 0} files`;
- toast.success(msg);
- onRefresh();
- }
- };
+ const handleStandardize = () => startStandardize(app.id);
const handleArchive = async () => {
setArchiving(true);
@@ -268,7 +244,7 @@ export default function OverviewTab({ app, onRefresh }) {
</button>
<button
onClick={handleUpdate}
- disabled={updating}
+ disabled={isOperating}
className="px-3 py-1.5 bg-port-success/20 text-port-success hover:bg-port-success/30 rounded-lg text-xs flex items-center gap-1 disabled:opacity-50"
>
<Download size={14} className={updating ? 'animate-bounce' : ''} />
@@ -284,7 +260,7 @@ export default function OverviewTab({ app, onRefresh }) {
</button>
<button
onClick={handleStandardize}
- disabled={standardizing}
+ disabled={isOperating}
className="px-3 py-1.5 bg-port-accent/20 text-port-accent hover:bg-port-accent/30 rounded-lg text-xs flex items-center gap-1 disabled:opacity-50"
>
<Wrench size={14} className={standardizing ? 'animate-spin' : ''} />
@@ -312,6 +288,9 @@ export default function OverviewTab({ app, onRefresh }) {
)}
</div>
+ {/* Activity Log */}
+ <ActivityLog steps={steps} error={error} completed={completed} />
+
{/* Edit Modal */}
{editingApp && (
<EditAppModal
diff --git a/client/src/hooks/useAppOperation.js b/client/src/hooks/useAppOperation.js
new file mode 100644
index 0000000000..152a73e79b
--- /dev/null
+++ b/client/src/hooks/useAppOperation.js
@@ -0,0 +1,112 @@
+import { useState, useCallback, useEffect, useRef } from 'react';
+import socket from '../services/socket';
+
+/**
+ * Hook for socket-based app operations (update, standardize) with live step tracking.
+ */
+export function useAppOperation({ onComplete } = {}) {
+ const [steps, setSteps] = useState([]);
+ const [isOperating, setIsOperating] = useState(false);
+ const [operatingAppId, setOperatingAppId] = useState(null);
+ const [operationType, setOperationType] = useState(null);
+ const [error, setError] = useState(null);
+ const [completed, setCompleted] = useState(false);
+ const clearTimerRef = useRef(null);
+
+ // Clear auto-dismiss timer on unmount
+ useEffect(() => () => clearTimeout(clearTimerRef.current), []);
+
+ const handleStep = useCallback((data) => {
+ setSteps(prev => {
+ const existing = prev.findIndex(s => s.step === data.step);
+ const entry = { step: data.step, status: data.status, message: data.message, timestamp: data.timestamp };
+ if (existing >= 0) {
+ const next = [...prev];
+ next[existing] = entry;
+ return next;
+ }
+ return [...prev, entry];
+ });
+ }, []);
+
+ const finish = useCallback((opType) => {
+ setIsOperating(false);
+ setCompleted(true);
+ clearTimerRef.current = setTimeout(() => {
+ setSteps([]);
+ setCompleted(false);
+ setOperatingAppId(null);
+ setOperationType(null);
+ setError(null);
+ }, 5000);
+ }, []);
+
+ const startUpdate = useCallback((appId) => {
+ clearTimeout(clearTimerRef.current);
+ setSteps([]);
+ setError(null);
+ setCompleted(false);
+ setIsOperating(true);
+ setOperatingAppId(appId);
+ setOperationType('update');
+
+ const onStep = (data) => handleStep(data);
+ const onError = (data) => {
+ setError(data.message);
+ setIsOperating(false);
+ cleanup();
+ };
+ const onDone = (data) => {
+ if (data.steps?.some(s => s.warning)) {
+ setSteps(prev => prev.map(s => s.step === 'restart' && s.status === 'running' ? { ...s, status: 'warning', message: data.steps.find(ds => ds.warning)?.warning } : s));
+ }
+ finish('update');
+ onComplete?.();
+ cleanup();
+ };
+ const cleanup = () => {
+ socket.off('app:update:step', onStep);
+ socket.off('app:update:error', onError);
+ socket.off('app:update:complete', onDone);
+ };
+
+ socket.on('app:update:step', onStep);
+ socket.on('app:update:error', onError);
+ socket.on('app:update:complete', onDone);
+ socket.emit('app:update', { appId });
+ }, [handleStep, finish, onComplete]);
+
+ const startStandardize = useCallback((appId) => {
+ clearTimeout(clearTimerRef.current);
+ setSteps([]);
+ setError(null);
+ setCompleted(false);
+ setIsOperating(true);
+ setOperatingAppId(appId);
+ setOperationType('standardize');
+
+ const onStep = (data) => handleStep(data);
+ const onError = (data) => {
+ setError(data.message);
+ setIsOperating(false);
+ cleanup();
+ };
+ const onDone = () => {
+ finish('standardize');
+ onComplete?.();
+ cleanup();
+ };
+ const cleanup = () => {
+ socket.off('app:standardize:step', onStep);
+ socket.off('app:standardize:error', onError);
+ socket.off('app:standardize:complete', onDone);
+ };
+
+ socket.on('app:standardize:step', onStep);
+ socket.on('app:standardize:error', onError);
+ socket.on('app:standardize:complete', onDone);
+ socket.emit('app:standardize', { appId });
+ }, [handleStep, finish, onComplete]);
+
+ return { steps, isOperating, operatingAppId, operationType, error, completed, startUpdate, startStandardize };
+}
diff --git a/client/src/pages/Apps.jsx b/client/src/pages/Apps.jsx
index 55e8f8f539..a572a41205 100644
--- a/client/src/pages/Apps.jsx
+++ b/client/src/pages/Apps.jsx
@@ -4,6 +4,8 @@ import { ExternalLink, Play, Square, RotateCcw, FolderOpen, Terminal, Code, Refr
import toast from 'react-hot-toast';
import BrailleSpinner from '../components/BrailleSpinner';
import StatusBadge from '../components/StatusBadge';
+import ActivityLog from '../components/apps/ActivityLog';
+import { useAppOperation } from '../hooks/useAppOperation';
import * as api from '../services/api';
import socket from '../services/socket';
@@ -86,8 +88,6 @@ export default function Apps() {
const [expandedId, setExpandedId] = useState(null);
const [actionLoading, setActionLoading] = useState({});
const [refreshingConfig, setRefreshingConfig] = useState({});
- const [standardizing, setStandardizing] = useState({});
- const [updating, setUpdating] = useState({});
const [building, setBuilding] = useState({});
const [archiving, setArchiving] = useState({});
const [showArchived, setShowArchived] = useState(false);
@@ -100,6 +100,8 @@ export default function Apps() {
setLoading(false);
}, []);
+ const { steps, isOperating, operatingAppId, operationType, error, completed, startUpdate, startStandardize } = useAppOperation({ onComplete: fetchApps });
+
useEffect(() => {
fetchApps();
@@ -142,15 +144,7 @@ export default function Apps() {
setActionLoading(prev => ({ ...prev, [app.id]: null }));
};
- const handleUpdate = async (app) => {
- setUpdating(prev => ({ ...prev, [app.id]: true }));
- const result = await api.pullAndUpdateApp(app.id).catch(() => null);
- setUpdating(prev => ({ ...prev, [app.id]: false }));
- if (result?.success) {
- const stepCount = result.steps?.length || 0;
- toast.success(`Updated ${app.name} (${stepCount} steps)`);
- }
- };
+ const handleUpdate = (app) => startUpdate(app.id);
const handleBuild = async (app) => {
setBuilding(prev => ({ ...prev, [app.id]: true }));
@@ -168,36 +162,7 @@ export default function Apps() {
fetchApps();
};
- const handleStandardize = async (app) => {
- setStandardizing(prev => ({ ...prev, [app.id]: true }));
-
- // Step 1: Analyze
- const analysis = await api.analyzeStandardizationByApp(app.id).catch(err => {
- toast.error(`Analysis failed: ${err.message}`);
- return null;
- });
-
- if (!analysis?.success) {
- setStandardizing(prev => ({ ...prev, [app.id]: false }));
- return;
- }
-
- // Step 2: Apply
- const result = await api.applyStandardizationByApp(app.id, analysis).catch(err => {
- toast.error(`Apply failed: ${err.message}`);
- return null;
- });
-
- setStandardizing(prev => ({ ...prev, [app.id]: false }));
-
- if (result?.success) {
- const msg = result.backupBranch
- ? `Standardized! Backup: ${result.backupBranch}`
- : `Standardized ${result.filesModified?.length || 0} files`;
- toast.success(msg);
- fetchApps();
- }
- };
+ const handleStandardize = (app) => startStandardize(app.id);
const toggleExpand = async (id) => {
const newExpandedId = expandedId === id ? null : id;
@@ -602,12 +567,12 @@ export default function Apps() {
</button>
<button
onClick={() => handleUpdate(app)}
- disabled={updating[app.id]}
+ disabled={isOperating}
className="px-3 py-1.5 bg-port-success/20 text-port-success hover:bg-port-success/30 rounded-lg text-xs flex items-center gap-1 disabled:opacity-50"
aria-label="Pull latest code, install dependencies, run setup, and restart"
>
- <Download size={14} aria-hidden="true" className={updating[app.id] ? 'animate-bounce' : ''} />
- {updating[app.id] ? 'Updating...' : 'Update'}
+ <Download size={14} aria-hidden="true" className={operatingAppId === app.id && operationType === 'update' ? 'animate-bounce' : ''} />
+ {operatingAppId === app.id && operationType === 'update' ? 'Updating...' : 'Update'}
</button>
{app.buildCommand && (
<button
@@ -632,15 +597,20 @@ export default function Apps() {
{(!app.processes?.length || app.processes.some(p => !p.ports || Object.keys(p.ports).length === 0)) && (
<button
onClick={() => handleStandardize(app)}
- disabled={standardizing[app.id]}
+ disabled={isOperating}
className="px-3 py-1.5 bg-port-accent/20 text-port-accent hover:bg-port-accent/30 rounded-lg text-xs flex items-center gap-1 disabled:opacity-50"
aria-label="Standardize PM2 config: move all ports to ecosystem.config.cjs"
>
- <Wrench size={14} aria-hidden="true" className={standardizing[app.id] ? 'animate-spin' : ''} />
- {standardizing[app.id] ? 'Standardizing...' : 'Standardize PM2'}
+ <Wrench size={14} aria-hidden="true" className={operatingAppId === app.id && operationType === 'standardize' ? 'animate-spin' : ''} />
+ {operatingAppId === app.id && operationType === 'standardize' ? 'Standardizing...' : 'Standardize PM2'}
</button>
)}
</div>
+
+ {/* Activity Log */}
+ {operatingAppId === app.id && (
+ <ActivityLog steps={steps} error={error} completed={completed} />
+ )}
</div>
</div>
)}
diff --git a/package-lock.json b/package-lock.json
index d2db0ce31d..28ba5ddb5a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "portos",
- "version": "1.25.1",
+ "version": "1.26.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "portos",
- "version": "1.25.1",
+ "version": "1.26.0",
"license": "MIT",
"dependencies": {
"express": "^4.21.2",
diff --git a/package.json b/package.json
index 320b8c9051..e48c41854b 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "portos",
- "version": "1.25.1",
+ "version": "1.26.0",
"private": true,
"description": "Local dev machine App OS portal",
"author": "Adam Eivy (@antic|@atomantic)",
diff --git a/server/lib/socketValidation.js b/server/lib/socketValidation.js
index f09b2d19d9..cd0c9e24f7 100644
--- a/server/lib/socketValidation.js
+++ b/server/lib/socketValidation.js
@@ -50,6 +50,11 @@ export const appUpdateSchema = z.object({
appId: z.string().min(1, 'appId is required')
});
+// app:standardize — app ID for PM2 standardization
+export const appStandardizeSchema = z.object({
+ appId: z.string().min(1, 'appId is required')
+});
+
// =============================================================================
// VALIDATION HELPER
// =============================================================================
diff --git a/server/services/appUpdater.js b/server/services/appUpdater.js
index dd6feeb15e..4fe6bfb740 100644
--- a/server/services/appUpdater.js
+++ b/server/services/appUpdater.js
@@ -99,11 +99,20 @@ async function _doUpdate(app, emit) {
const processNames = app.pm2ProcessNames || [];
if (processNames.length > 0) {
emit('restart', 'running', 'Restarting app...');
- for (const name of processNames) {
- await pm2Service.restartApp(name, app.pm2Home);
+ const restartResults = await Promise.all(
+ processNames.map(name =>
+ pm2Service.restartApp(name, app.pm2Home).then(() => null, e => e)
+ )
+ );
+ const failures = processNames.filter((_, i) => restartResults[i]);
+ if (failures.length > 0) {
+ const msg = `${processNames.length - failures.length}/${processNames.length} restarted (failed: ${failures.join(', ')})`;
+ emit('restart', 'warning', msg);
+ steps.push({ step: 'restart', success: true, warning: msg });
+ } else {
+ emit('restart', 'done', `Restarted ${processNames.length} process(es)`);
+ steps.push({ step: 'restart', success: true });
}
- emit('restart', 'done', `Restarted ${processNames.length} process(es)`);
- steps.push({ step: 'restart', success: true });
}
return { success: true, steps };
diff --git a/server/services/socket.js b/server/services/socket.js
index 3f03baeb14..69058a2a47 100644
--- a/server/services/socket.js
+++ b/server/services/socket.js
@@ -25,7 +25,8 @@ import {
shellInputSchema,
shellResizeSchema,
shellStopSchema,
- appUpdateSchema
+ appUpdateSchema,
+ appStandardizeSchema
} from '../lib/socketValidation.js';
import * as appsService from './apps.js';
import * as appUpdater from './appUpdater.js';
@@ -299,6 +300,74 @@ export function initSocket(io) {
}
});
+ // App standardize handler — streams progress via socket
+ socket.on('app:standardize', async (rawData) => {
+ const data = validateSocketData(appStandardizeSchema, rawData, socket, 'app:standardize');
+ if (!data) return;
+
+ const app = await appsService.getAppById(data.appId);
+ if (!app) {
+ socket.emit('app:standardize:error', { message: 'App not found' });
+ return;
+ }
+
+ console.log(`🔧 Socket standardize started for ${app.name}`);
+ const emit = (step, status, message) => {
+ socket.emit('app:standardize:step', { step, status, message, timestamp: Date.now() });
+ };
+
+ // Step 1: Analyze
+ emit('analyze', 'running', 'Analyzing project configuration...');
+ const analysis = await pm2Standardizer.analyzeApp(app.repoPath)
+ .catch(err => ({ success: false, error: err.message }));
+
+ if (!analysis.success) {
+ emit('analyze', 'error', analysis.error);
+ socket.emit('app:standardize:error', { message: analysis.error });
+ return;
+ }
+ emit('analyze', 'done', `Found ${analysis.proposedChanges.processes?.length || 0} processes`);
+
+ // Step 2: Backup
+ emit('backup', 'running', 'Creating git backup...');
+ const backup = await pm2Standardizer.createGitBackup(app.repoPath)
+ .catch(err => ({ success: false, reason: err.message }));
+
+ if (backup.success) {
+ emit('backup', 'done', `Backup branch: ${backup.branch}`);
+ } else {
+ emit('backup', 'skipped', backup.reason || 'No git repository');
+ }
+
+ // Step 3: Apply
+ emit('apply', 'running', 'Writing ecosystem.config.cjs...');
+ const result = await pm2Standardizer.applyStandardization(app.repoPath, analysis)
+ .catch(err => ({ success: false, errors: [err.message] }));
+
+ if (result.errors?.length > 0) {
+ emit('apply', 'error', result.errors.join(', '));
+ socket.emit('app:standardize:error', { message: result.errors.join(', ') });
+ return;
+ }
+ emit('apply', 'done', `Modified ${result.filesModified.length} files`);
+
+ // Update app with new PM2 process names
+ if (analysis.proposedChanges?.processes) {
+ const pm2ProcessNames = analysis.proposedChanges.processes.map(p => p.name);
+ await appsService.updateApp(data.appId, { pm2ProcessNames });
+ }
+
+ socket.emit('app:standardize:complete', {
+ success: true,
+ result: {
+ backupBranch: result.backupBranch,
+ filesModified: result.filesModified,
+ processes: analysis.proposedChanges.processes
+ }
+ });
+ console.log(`✅ Socket standardize complete for ${app.name}`);
+ });
+
// Shell session handlers
socket.on('shell:start', () => {
const sessionId = shellService.createShellSession(socket);