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(apps): add deploy button for Xcode apps with deploy.sh

Adam Eivy0664d7a3bd0c
diff --git a/client/src/components/apps/AppDetailView.jsx b/client/src/components/apps/AppDetailView.jsx
index ea8856d197..6ba88adcf5 100644
--- a/client/src/components/apps/AppDetailView.jsx
+++ b/client/src/components/apps/AppDetailView.jsx
@@ -1,6 +1,7 @@
import { useState, useEffect, useCallback, useMemo } from 'react';
import { Link, useParams, useNavigate } from 'react-router-dom';
import { ArrowLeft, Play, Square, RotateCcw, ExternalLink, Hammer } from 'lucide-react';
+import DeployPanel from './DeployPanel';
import toast from '../ui/Toast';
import BrailleSpinner from '../BrailleSpinner';
import StatusBadge from '../StatusBadge';
@@ -223,6 +224,9 @@ export default function AppDetailView() {
<span className="text-xs">{buildLoading ? 'Building...' : 'Build'}</span>
</button>
)}
+ {app.hasDeployScript && (
+ <DeployPanel appId={appId} appName={app.name} />
+ )}
</div>
</div>
diff --git a/client/src/components/apps/DeployPanel.jsx b/client/src/components/apps/DeployPanel.jsx
new file mode 100644
index 0000000000..e5e2adfc74
--- /dev/null
+++ b/client/src/components/apps/DeployPanel.jsx
@@ -0,0 +1,141 @@
+import { useState, useRef, useEffect } from 'react';
+import { Rocket, X, ChevronDown } from 'lucide-react';
+import BrailleSpinner from '../BrailleSpinner';
+import { useAppDeploy } from '../../hooks/useAppDeploy';
+
+const FLAG_OPTIONS = [
+ { value: '--ios', label: 'iOS' },
+ { value: '--macos', label: 'macOS' },
+ { value: '--all', label: 'All Platforms' },
+ { value: '--skip-tests', label: 'Skip Tests' },
+];
+
+const PLATFORM_FLAGS = new Set(['--ios', '--macos', '--all']);
+
+export default function DeployPanel({ appId, appName }) {
+ const { output, isDeploying, error, result, startDeploy, clearDeploy } = useAppDeploy();
+ const [showOptions, setShowOptions] = useState(false);
+ const [selectedFlags, setSelectedFlags] = useState([]);
+ const outputRef = useRef(null);
+ const rafRef = useRef(null);
+ const isOpen = isDeploying || output.length > 0 || error || result;
+
+ // Throttled auto-scroll via rAF
+ useEffect(() => {
+ if (!outputRef.current) return;
+ if (rafRef.current) return;
+ rafRef.current = requestAnimationFrame(() => {
+ if (outputRef.current) outputRef.current.scrollTop = outputRef.current.scrollHeight;
+ rafRef.current = null;
+ });
+ }, [output]);
+
+ useEffect(() => () => { if (rafRef.current) cancelAnimationFrame(rafRef.current); }, []);
+
+ const toggleFlag = (flag) => {
+ setSelectedFlags(prev => {
+ if (PLATFORM_FLAGS.has(flag)) {
+ if (prev.includes(flag)) return prev.filter(f => f !== flag);
+ return flag === '--all'
+ ? [...prev.filter(f => !PLATFORM_FLAGS.has(f)), '--all']
+ : [...prev.filter(f => f !== '--all'), flag];
+ }
+ return prev.includes(flag) ? prev.filter(f => f !== flag) : [...prev, flag];
+ });
+ };
+
+ const handleDeploy = () => {
+ setShowOptions(false);
+ startDeploy(appId, selectedFlags);
+ };
+
+ return (
+ <div className="relative inline-flex">
+ <div className="inline-flex rounded-lg overflow-hidden border border-port-border">
+ <button
+ onClick={handleDeploy}
+ disabled={isDeploying}
+ className="px-2 py-1 bg-purple-500/20 text-purple-400 hover:bg-purple-500/30 transition-colors disabled:opacity-50 flex items-center gap-1"
+ >
+ <Rocket size={14} className={isDeploying ? 'animate-pulse' : ''} />
+ <span className="text-xs">{isDeploying ? 'Deploying...' : 'Deploy'}</span>
+ </button>
+ <button
+ onClick={() => setShowOptions(prev => !prev)}
+ disabled={isDeploying}
+ className="px-1 py-1 bg-purple-500/20 text-purple-400 hover:bg-purple-500/30 transition-colors disabled:opacity-50 border-l border-port-border"
+ >
+ <ChevronDown size={12} />
+ </button>
+ </div>
+
+ {showOptions && (
+ <div className="absolute top-full right-0 mt-1 z-50 bg-port-card border border-port-border rounded-lg shadow-xl p-2 min-w-[160px]">
+ {FLAG_OPTIONS.map(opt => (
+ <label key={opt.value} className="flex items-center gap-2 px-2 py-1.5 hover:bg-port-border/50 rounded cursor-pointer">
+ <input
+ type="checkbox"
+ checked={selectedFlags.includes(opt.value)}
+ onChange={() => toggleFlag(opt.value)}
+ className="accent-purple-500"
+ />
+ <span className="text-xs text-gray-300">{opt.label}</span>
+ </label>
+ ))}
+ <div className="border-t border-port-border mt-1 pt-1">
+ <button
+ onClick={handleDeploy}
+ className="w-full px-2 py-1.5 text-xs bg-purple-500/20 text-purple-400 hover:bg-purple-500/30 rounded transition-colors"
+ >
+ Deploy{selectedFlags.length > 0 ? ` (${selectedFlags.join(' ')})` : ''}
+ </button>
+ </div>
+ </div>
+ )}
+
+ {isOpen && (
+ <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4">
+ <div className="bg-port-bg border border-port-border rounded-xl shadow-2xl w-full max-w-3xl max-h-[80vh] flex flex-col">
+ <div className="flex items-center justify-between px-4 py-3 border-b border-port-border">
+ <div className="flex items-center gap-2">
+ <Rocket size={16} className="text-purple-400" />
+ <span className="text-sm font-medium text-white">Deploy: {appName}</span>
+ {isDeploying && <BrailleSpinner text="" className="text-xs text-purple-400" />}
+ </div>
+ {!isDeploying && (
+ <button onClick={clearDeploy} className="text-gray-400 hover:text-white transition-colors">
+ <X size={16} />
+ </button>
+ )}
+ </div>
+
+ <div
+ ref={outputRef}
+ className="flex-1 overflow-auto p-4 font-mono text-xs leading-relaxed bg-black/40"
+ >
+ {output.map((line, i) => (
+ <div
+ key={i}
+ className={
+ line.stream === 'stderr' ? 'text-port-error' :
+ line.stream === 'status' ? 'text-purple-400 font-bold' :
+ 'text-gray-300'
+ }
+ >
+ {line.text}
+ </div>
+ ))}
+ {error && <div className="text-port-error mt-2">Error: {error}</div>}
+ </div>
+
+ {result && (
+ <div className={`px-4 py-2 border-t border-port-border text-xs ${result.success ? 'text-port-success' : 'text-port-error'}`}>
+ {result.success ? 'Deploy completed successfully' : `Deploy failed (exit code ${result.code})`}
+ </div>
+ )}
+ </div>
+ </div>
+ )}
+ </div>
+ );
+}
diff --git a/client/src/hooks/useAppDeploy.js b/client/src/hooks/useAppDeploy.js
new file mode 100644
index 0000000000..518b7e9263
--- /dev/null
+++ b/client/src/hooks/useAppDeploy.js
@@ -0,0 +1,71 @@
+import { useState, useCallback, useEffect, useRef } from 'react';
+import socket from '../services/socket';
+
+const MAX_OUTPUT_LINES = 5000;
+
+/**
+ * Hook for streaming deploy.sh output via Socket.IO.
+ */
+export function useAppDeploy() {
+ const [output, setOutput] = useState([]);
+ const [isDeploying, setIsDeploying] = useState(false);
+ const [error, setError] = useState(null);
+ const [result, setResult] = useState(null);
+ const cleanupRef = useRef(null);
+
+ useEffect(() => () => cleanupRef.current?.(), []);
+
+ const appendOutput = useCallback((entry) => {
+ setOutput(prev => {
+ const next = [...prev, entry];
+ return next.length > MAX_OUTPUT_LINES ? next.slice(-MAX_OUTPUT_LINES) : next;
+ });
+ }, []);
+
+ const startDeploy = useCallback((appId, flags = []) => {
+ setOutput([]);
+ setError(null);
+ setResult(null);
+ setIsDeploying(true);
+
+ const onOutput = (data) => {
+ appendOutput({ text: data.text, stream: data.stream, ts: data.timestamp });
+ };
+ const onStatus = (data) => {
+ appendOutput({ text: `--- ${data.message} ---\n`, stream: 'status', ts: data.timestamp });
+ };
+ const onError = (data) => {
+ setError(data.message);
+ setIsDeploying(false);
+ cleanup();
+ };
+ const onComplete = (data) => {
+ setResult(data);
+ setIsDeploying(false);
+ cleanup();
+ };
+ const cleanup = () => {
+ socket.off('app:deploy:output', onOutput);
+ socket.off('app:deploy:status', onStatus);
+ socket.off('app:deploy:error', onError);
+ socket.off('app:deploy:complete', onComplete);
+ cleanupRef.current = null;
+ };
+
+ cleanupRef.current?.();
+ cleanupRef.current = cleanup;
+ socket.on('app:deploy:output', onOutput);
+ socket.on('app:deploy:status', onStatus);
+ socket.on('app:deploy:error', onError);
+ socket.on('app:deploy:complete', onComplete);
+ socket.emit('app:deploy', { appId, flags });
+ }, [appendOutput]);
+
+ const clearDeploy = useCallback(() => {
+ setOutput([]);
+ setError(null);
+ setResult(null);
+ }, []);
+
+ return { output, isDeploying, error, result, startDeploy, clearDeploy };
+}
diff --git a/server/lib/socketValidation.js b/server/lib/socketValidation.js
index c492c754cb..63fe8e6db8 100644
--- a/server/lib/socketValidation.js
+++ b/server/lib/socketValidation.js
@@ -58,6 +58,12 @@ export const appStandardizeSchema = z.object({
appId: z.string().min(1, 'appId is required')
});
+// app:deploy — app ID and optional flags for Xcode deploy
+export const appDeploySchema = z.object({
+ appId: z.string().min(1, 'appId is required'),
+ flags: z.array(z.string()).default([])
+});
+
// =============================================================================
// VALIDATION HELPER
// =============================================================================
diff --git a/server/routes/apps.js b/server/routes/apps.js
index 5863fc0bb2..f9d1eaf563 100644
--- a/server/routes/apps.js
+++ b/server/routes/apps.js
@@ -17,6 +17,7 @@ import { asyncHandler, ServerError } from '../lib/errorHandler.js';
import { safeJSONParse } from '../lib/fileUtils.js';
import { parseEcosystemFromPath, usesPm2 } from '../services/streamingDetect.js';
import { detectAppIcon, getIconContentType } from '../services/appIconDetect.js';
+import { hasDeployScript } from '../services/appDeployer.js';
const router = Router();
@@ -70,7 +71,7 @@ router.get('/', asyncHandler(async (req, res) => {
const enriched = await Promise.all(apps.map(async (app) => {
// Non-PM2 apps skip PM2 enrichment entirely
if (!usesPm2(app.type)) {
- return { ...app, pm2Status: {}, overallStatus: 'n/a' };
+ return { ...app, pm2Status: {}, overallStatus: 'n/a', hasDeployScript: hasDeployScript(app) };
}
const pm2Home = app.pm2Home || null;
@@ -123,7 +124,8 @@ router.get('/', asyncHandler(async (req, res) => {
devUiPort,
apiPort,
pm2Status: statuses,
- overallStatus
+ overallStatus,
+ hasDeployScript: hasDeployScript(app)
};
}));
@@ -181,7 +183,7 @@ router.get('/:id', loadApp, asyncHandler(async (req, res) => {
appVersion = pkg?.version || null;
}
- res.json({ ...app, uiPort, devUiPort, apiPort, overallStatus, pm2Status: statuses, appVersion });
+ res.json({ ...app, uiPort, devUiPort, apiPort, overallStatus, pm2Status: statuses, appVersion, hasDeployScript: hasDeployScript(app) });
}));
// GET /api/apps/:id/icon - Serve the app's detected icon image
diff --git a/server/services/appDeployer.js b/server/services/appDeployer.js
new file mode 100644
index 0000000000..304a311e88
--- /dev/null
+++ b/server/services/appDeployer.js
@@ -0,0 +1,94 @@
+import { spawn } from 'child_process';
+import { existsSync } from 'fs';
+import { join } from 'path';
+import { NON_PM2_TYPES } from './streamingDetect.js';
+
+const VALID_FLAGS = new Set(['--ios', '--macos', '--all', '--skip-tests']);
+const FLUSH_INTERVAL_MS = 80;
+
+// Per-app lock to prevent concurrent deploys
+const deployingApps = new Set();
+
+/**
+ * Check whether an app has a deploy.sh script
+ */
+export function hasDeployScript(app) {
+ if (!app?.repoPath) return false;
+ if (!NON_PM2_TYPES.has(app.type)) return false;
+ return existsSync(join(app.repoPath, 'deploy.sh'));
+}
+
+/**
+ * Run deploy.sh for an Xcode app with real-time output streaming.
+ *
+ * @param {object} app - App object with repoPath, type, name
+ * @param {string[]} flags - CLI flags (--ios, --macos, --all, --skip-tests)
+ * @param {function} emit - Callback (type, data) for streaming output
+ * @returns {Promise<{success: boolean, code: number}>}
+ */
+export function deployApp(app, flags, emit) {
+ const dir = app.repoPath;
+
+ if (deployingApps.has(dir)) {
+ emit('error', { message: 'Deploy already in progress for this app' });
+ return Promise.resolve({ success: false, code: -1 });
+ }
+
+ const safeFlags = flags.filter(f => VALID_FLAGS.has(f));
+
+ deployingApps.add(dir);
+ emit('status', { message: 'Starting deploy...', phase: 'start' });
+
+ // Buffer output and flush periodically to reduce socket message volume
+ let stdoutBuf = '';
+ let stderrBuf = '';
+ const flushOutput = () => {
+ if (stdoutBuf) { emit('output', { text: stdoutBuf, stream: 'stdout' }); stdoutBuf = ''; }
+ if (stderrBuf) { emit('output', { text: stderrBuf, stream: 'stderr' }); stderrBuf = ''; }
+ };
+ const flushTimer = setInterval(flushOutput, FLUSH_INTERVAL_MS);
+
+ const finish = (success, code) => {
+ clearInterval(flushTimer);
+ flushOutput();
+ deployingApps.delete(dir);
+ return { success, code };
+ };
+
+ return new Promise((resolve) => {
+ const child = spawn('bash', ['deploy.sh', ...safeFlags], {
+ cwd: dir,
+ shell: false,
+ windowsHide: true,
+ env: { ...process.env, FORCE_COLOR: '0' }
+ });
+
+ child.stdout.on('data', (data) => { stdoutBuf += data.toString(); });
+ child.stderr.on('data', (data) => { stderrBuf += data.toString(); });
+
+ child.on('close', (code) => {
+ const success = code === 0;
+ const result = finish(success, code);
+ emit('status', {
+ message: success ? 'Deploy complete' : `Deploy failed (exit code ${code})`,
+ phase: 'complete',
+ success,
+ code
+ });
+ resolve(result);
+ });
+
+ child.on('error', (err) => {
+ const result = finish(false, -1);
+ emit('error', { message: err.message });
+ resolve(result);
+ });
+ });
+}
+
+/**
+ * Check if an app is currently deploying
+ */
+export function isDeploying(appRepoPath) {
+ return deployingApps.has(appRepoPath);
+}
diff --git a/server/services/socket.js b/server/services/socket.js
index a48e8c0c03..f616a031ca 100644
--- a/server/services/socket.js
+++ b/server/services/socket.js
@@ -31,10 +31,12 @@ import {
shellSessionIdSchema,
shellStopSchema,
appUpdateSchema,
- appStandardizeSchema
+ appStandardizeSchema,
+ appDeploySchema
} from '../lib/socketValidation.js';
import * as appsService from './apps.js';
import * as appUpdater from './appUpdater.js';
+import * as appDeployer from './appDeployer.js';
// Store active log streams per socket
const activeStreams = new Map();
@@ -386,6 +388,32 @@ export function initSocket(io) {
console.log(`✅ Socket standardize complete for ${app.name}`);
});
+ // App deploy handler — streams real-time output from deploy.sh
+ socket.on('app:deploy', async (rawData) => {
+ const data = validateSocketData(appDeploySchema, rawData, socket, 'app:deploy');
+ if (!data) return;
+
+ const app = await appsService.getAppById(data.appId);
+ if (!app) {
+ socket.emit('app:deploy:error', { message: 'App not found' });
+ return;
+ }
+
+ if (!appDeployer.hasDeployScript(app)) {
+ socket.emit('app:deploy:error', { message: 'No deploy.sh found for this app' });
+ return;
+ }
+
+ console.log(`🚀 Deploy started for ${app.name} [${data.flags.join(', ') || 'default'}]`);
+ const emit = (type, payload) => {
+ socket.emit(`app:deploy:${type}`, { ...payload, timestamp: Date.now() });
+ };
+
+ const result = await appDeployer.deployApp(app, data.flags, emit);
+ socket.emit('app:deploy:complete', { success: result.success, code: result.code });
+ console.log(`${result.success ? '✅' : '❌'} Deploy ${result.success ? 'complete' : 'failed'} for ${app.name}`);
+ });
+
// Shell session handlers
socket.on('shell:start', (options) => {
const cwd = options?.cwd || undefined;