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
feat: add iOS native app template to scaffold system
Adam Eivy68e23d16ec63
diff --git a/client/src/pages/Templates.jsx b/client/src/pages/Templates.jsxindex 4c23ef16b9..d98fe61036 100644--- a/client/src/pages/Templates.jsx+++ b/client/src/pages/Templates.jsx@@ -1,6 +1,6 @@import { useState, useEffect } from 'react';import { useNavigate } from 'react-router-dom';-import { Layers, Code, Server, Globe, Plus } from 'lucide-react';+import { Layers, Code, Server, Globe, Smartphone, Plus } from 'lucide-react';import * as api from '../services/api';import DirectoryPicker from '../components/DirectoryPicker';@@ -8,7 +8,8 @@ const ICONS = {layers: Layers,code: Code,server: Server,- globe: Globe+ globe: Globe,+ smartphone: Smartphone};export default function Templates() {diff --git a/server/routes/detect.js b/server/routes/detect.jsindex d54cd8eb8c..1cfcc71291 100644--- a/server/routes/detect.js+++ b/server/routes/detect.js@@ -85,6 +85,15 @@ router.post('/repo', asyncHandler(async (req, res) => {}}+ // Check for iOS project (XcodeGen project.yml or .xcodeproj)+ if (existsSync(join(path, 'project.yml'))) {+ const ymlContent = await readFile(join(path, 'project.yml'), 'utf-8').catch(() => '');+ if (ymlContent.includes('platform: iOS') || ymlContent.includes("deploymentTarget:")) {+ result.type = 'ios-native';+ result.startCommands = ['open *.xcodeproj'];+ }+ }+// Check for .gitif (existsSync(join(path, '.git'))) {result.hasGit = true;diff --git a/server/routes/scaffold.js b/server/routes/scaffold.jsindex 41404b67ac..d804785ef4 100644--- a/server/routes/scaffold.js+++ b/server/routes/scaffold.js@@ -114,6 +114,15 @@ router.get('/templates', asyncHandler(async (req, res) => {icon: 'server',features: ['Express.js', 'CORS', 'Health endpoint'],ports: { ui: false, api: true }+ },+ {+ id: 'ios-native',+ name: 'iOS Native App',+ description: 'SwiftUI + XcodeGen with TestFlight deploy script',+ type: 'ios-native',+ icon: 'smartphone',+ features: ['SwiftUI', 'SwiftData', 'XcodeGen', 'TestFlight CI/CD', 'On-device processing'],+ ports: { ui: false, api: false }}];@@ -205,7 +214,8 @@ async function scaffoldApp(req, res) {'portos-stack': { api: true, ui: true },'vite-express': { api: true, ui: true },'vite-react': { api: false, ui: true },- 'express-api': { api: true, ui: false }+ 'express-api': { api: true, ui: false },+ 'ios-native': { api: false, ui: false }};const needs = templateNeedsPorts[template] || { api: false, ui: false };@@ -353,6 +363,363 @@ app.listen(PORT, '0.0.0.0', () => {`);addStep('Create Express project', 'done');+ } else if (template === 'ios-native') {+ // Create iOS native app with SwiftUI + XcodeGen+ const bundleId = `net.shadowpuppet.${name.replace(/[^a-zA-Z0-9]/g, '')}`;+ const teamId = 'TYQ32QCF6K';++ // project.yml (XcodeGen source of truth)+ await writeFile(join(repoPath, 'project.yml'), `name: ${name.replace(/[^a-zA-Z0-9_]/g, '_')}+options:+ bundleIdPrefix: net.shadowpuppet+ deploymentTarget:+ iOS: "17.0"+ xcodeVersion: "16.0"+ generateEmptyDirectories: true++settings:+ base:+ DEVELOPMENT_TEAM: ${teamId}+ MARKETING_VERSION: "1.0.0"+ CURRENT_PROJECT_VERSION: 1+ SWIFT_VERSION: "5.9"++targets:+ ${name.replace(/[^a-zA-Z0-9_]/g, '_')}:+ type: application+ platform: iOS+ sources:+ - path: ${name.replace(/[^a-zA-Z0-9_]/g, '_')}+ excludes:+ - Preview Content/PreviewAssets.xcassets+ - path: ${name.replace(/[^a-zA-Z0-9_]/g, '_')}/Preview Content/PreviewAssets.xcassets+ buildPhase: none+ settings:+ base:+ PRODUCT_BUNDLE_IDENTIFIER: ${bundleId}+ INFOPLIST_FILE: ${name.replace(/[^a-zA-Z0-9_]/g, '_')}/Info.plist+ ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon+ INFOPLIST_KEY_ITSAppUsesNonExemptEncryption: NO+ INFOPLIST_KEY_UISupportedInterfaceOrientations: "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"+ INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad: "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"+ INFOPLIST_KEY_UILaunchScreen_Generation: true+ DEVELOPMENT_ASSET_PATHS: "\\"${name.replace(/[^a-zA-Z0-9_]/g, '_')}/Preview Content\\""+ GENERATE_INFOPLIST_FILE: true+ scheme:+ testTargets:+ - ${name.replace(/[^a-zA-Z0-9_]/g, '_')}Tests++ ${name.replace(/[^a-zA-Z0-9_]/g, '_')}Tests:+ type: bundle.unit-test+ platform: iOS+ sources:+ - path: ${name.replace(/[^a-zA-Z0-9_]/g, '_')}Tests+ dependencies:+ - target: ${name.replace(/[^a-zA-Z0-9_]/g, '_')}+ settings:+ base:+ PRODUCT_BUNDLE_IDENTIFIER: ${bundleId}Tests+ GENERATE_INFOPLIST_FILE: true+ TEST_HOST: "$(BUILT_PRODUCTS_DIR)/${name.replace(/[^a-zA-Z0-9_]/g, '_')}.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/${name.replace(/[^a-zA-Z0-9_]/g, '_')}"+ BUNDLE_LOADER: "$(TEST_HOST)"+`);++ // Create source directories+ const targetName = name.replace(/[^a-zA-Z0-9_]/g, '_');+ const srcDir = join(repoPath, targetName);+ const previewDir = join(srcDir, 'Preview Content');+ const testsDir = join(repoPath, `${targetName}Tests`);++ await mkdir(srcDir, { recursive: true });+ await mkdir(previewDir, { recursive: true });+ await mkdir(testsDir, { recursive: true });++ // Info.plist+ await writeFile(join(srcDir, 'Info.plist'), `<?xml version="1.0" encoding="UTF-8"?>+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"+ "http://www.apple.com/DTDs/PropertyList-1.0.dtd">+<plist version="1.0">+<dict>+ <key>NSMicrophoneUsageDescription</key>+ <string>This app needs microphone access for audio recording.</string>+</dict>+</plist>+`);++ // App entry point+ await writeFile(join(srcDir, `${targetName}App.swift`), `import SwiftUI++@main+struct ${targetName}App: App {+ var body: some Scene {+ WindowGroup {+ ContentView()+ }+ }+}+`);++ // ContentView+ await writeFile(join(srcDir, 'ContentView.swift'), `import SwiftUI++struct ContentView: View {+ var body: some View {+ NavigationStack {+ VStack(spacing: 20) {+ Image(systemName: "app.fill")+ .font(.system(size: 60))+ .foregroundStyle(.blue)++ Text("${name}")+ .font(.largeTitle)+ .fontWeight(.bold)++ Text("Built with PortOS")+ .font(.subheadline)+ .foregroundStyle(.secondary)+ }+ .navigationTitle("${name}")+ }+ }+}+`);++ // Assets.xcassets+ await mkdir(join(srcDir, 'Assets.xcassets', 'AppIcon.appiconset'), { recursive: true });+ await writeFile(join(srcDir, 'Assets.xcassets', 'Contents.json'), '{"info":{"version":1,"author":"xcode"}}');+ await writeFile(join(srcDir, 'Assets.xcassets', 'AppIcon.appiconset', 'Contents.json'), `{+ "images": [{"idiom": "universal", "platform": "ios", "size": "1024x1024"}],+ "info": {"version": 1, "author": "xcode"}+}`);++ // Preview Assets+ await mkdir(join(previewDir, 'PreviewAssets.xcassets'), { recursive: true });+ await writeFile(join(previewDir, 'PreviewAssets.xcassets', 'Contents.json'), '{"info":{"version":1,"author":"xcode"}}');++ // Unit test+ await writeFile(join(testsDir, `${targetName}Tests.swift`), `import XCTest+@testable import ${targetName}++final class ${targetName}Tests: XCTestCase {+ func testAppLaunches() {+ XCTAssertTrue(true, "App scaffold is functional")+ }+}+`);++ // .env.example+ await writeFile(join(repoPath, '.env.example'), `TEAM_ID=${teamId}+APPSTORE_API_KEY_ID=YOUR_KEY_ID+APPSTORE_ISSUER_ID=YOUR_ISSUER_ID+APPSTORE_API_PRIVATE_KEY_PATH=~/Library/Mobile Documents/com~apple~CloudDocs/AppDev/AuthKey_XXXXXXXXXX.p8+`);++ // deploy.sh (TestFlight local deploy)+ const deployScript = `#!/bin/bash+set -euo pipefail++# ${name} - Local TestFlight Deploy+# Usage: ./deploy.sh [--skip-tests]++SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"+cd "$SCRIPT_DIR"++# Load environment+if [ -f .env ]; then+ set -a+ source .env+ set +a+else+ echo "❌ .env file not found. Copy .env.example to .env and fill in values."+ exit 1+fi++KEY_PATH="$APPSTORE_API_PRIVATE_KEY_PATH"++if [ ! -f "$KEY_PATH" ]; then+ echo "❌ API key not found at: $KEY_PATH"+ exit 1+fi++# Ensure altool can find the key+mkdir -p ~/.private_keys+KEY_FILENAME="AuthKey_\${APPSTORE_API_KEY_ID}.p8"+if [ ! -f ~/.private_keys/"$KEY_FILENAME" ]; then+ ln -sf "$KEY_PATH" ~/.private_keys/"$KEY_FILENAME"+ echo "🔑 Symlinked API key to ~/.private_keys/"+fi++PROJECT="${targetName}.xcodeproj"+SCHEME="${targetName}"+BUILD_DIR="$SCRIPT_DIR/build"+ARCHIVE_PATH="$BUILD_DIR/$SCHEME.xcarchive"+EXPORT_PATH="$BUILD_DIR/export"++# Auto-increment build number+CURRENT_BUILD=$(grep CURRENT_PROJECT_VERSION project.yml | head -1 | awk '{print $2}')+NEW_BUILD=$((CURRENT_BUILD + 1))+echo "📦 Build number: $CURRENT_BUILD → $NEW_BUILD"+/usr/bin/sed -i '' "s/CURRENT_PROJECT_VERSION: \${CURRENT_BUILD}/CURRENT_PROJECT_VERSION: \${NEW_BUILD}/" project.yml++# Regenerate Xcode project+echo "⚙️ Regenerating Xcode project..."+xcodegen generate++# Run tests (unless skipped)+if [ "\${1:-}" != "--skip-tests" ]; then+ echo "🧪 Running tests..."+ DESTINATION=$(+ if xcrun simctl list devices available | grep -q "iPhone 16"; then+ echo "platform=iOS Simulator,name=iPhone 16"+ elif xcrun simctl list devices available | grep -q "iPhone 15"; then+ echo "platform=iOS Simulator,name=iPhone 15"+ else+ echo "platform=iOS Simulator,name=iPhone 14"+ fi+ )+ xcodebuild test \\+ -project "$PROJECT" \\+ -scheme "$SCHEME" \\+ -only-testing:${targetName}Tests \\+ -destination "$DESTINATION" \\+ -configuration Debug \\+ CODE_SIGNING_ALLOWED=NO \\+ -quiet+ echo "✅ Tests passed"+fi++# Clean build directory+rm -rf "$BUILD_DIR"++# Archive+echo "📦 Archiving..."+xcodebuild archive \\+ -project "$PROJECT" \\+ -scheme "$SCHEME" \\+ -configuration Release \\+ -destination 'generic/platform=iOS' \\+ -archivePath "$ARCHIVE_PATH" \\+ CODE_SIGNING_ALLOWED=NO \\+ CODE_SIGN_IDENTITY="" \\+ CODE_SIGNING_REQUIRED=NO \\+ -quiet++echo "✅ Archive complete"++# Create exportOptions.plist+cat > "$BUILD_DIR/exportOptions.plist" <<EOF+<?xml version="1.0" encoding="UTF-8"?>+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"+ "http://www.apple.com/DTDs/PropertyList-1.0.dtd">+<plist version="1.0">+<dict>+ <key>method</key><string>app-store-connect</string>+ <key>teamID</key><string>$TEAM_ID</string>+ <key>signingStyle</key><string>automatic</string>+</dict>+</plist>+EOF++# Export IPA+echo "📤 Exporting IPA..."+xcodebuild -exportArchive \\+ -archivePath "$ARCHIVE_PATH" \\+ -exportOptionsPlist "$BUILD_DIR/exportOptions.plist" \\+ -exportPath "$EXPORT_PATH" \\+ -allowProvisioningUpdates \\+ -authenticationKeyPath "$KEY_PATH" \\+ -authenticationKeyID "$APPSTORE_API_KEY_ID" \\+ -authenticationKeyIssuerID "$APPSTORE_ISSUER_ID" \\+ -quiet++echo "✅ IPA exported"++# Upload to TestFlight+IPA_PATH="$EXPORT_PATH/$SCHEME.ipa"+if [ ! -f "$IPA_PATH" ]; then+ echo "❌ IPA not found at $IPA_PATH"+ ls -la "$EXPORT_PATH/"+ exit 1+fi++echo "🚀 Uploading to TestFlight..."+xcrun altool --upload-app \\+ --file "$IPA_PATH" \\+ --type ios \\+ --apiKey "$APPSTORE_API_KEY_ID" \\+ --apiIssuer "$APPSTORE_ISSUER_ID"++UPLOAD_EXIT=$?+if [ $UPLOAD_EXIT -ne 0 ]; then+ echo "❌ Upload failed with exit code $UPLOAD_EXIT"+ exit $UPLOAD_EXIT+fi++echo "✅ Upload complete! Build $NEW_BUILD submitted to TestFlight."++# Commit the build number bump+git add project.yml "$PROJECT/project.pbxproj"+git commit -m "build: bump to build $NEW_BUILD"+echo "📝 Committed build number bump"++# Clean up+rm -rf "$BUILD_DIR"+echo "🧹 Cleaned build artifacts"+`;+ await writeFile(join(repoPath, 'deploy.sh'), deployScript);+ // Make deploy.sh executable+ await execAsync(`chmod +x "${join(repoPath, 'deploy.sh')}"`, { windowsHide: true });++ // CLAUDE.md+ await writeFile(join(repoPath, 'CLAUDE.md'), `# ${name}++iOS native app built with SwiftUI and XcodeGen.++## Tech Stack++- **SwiftUI** + **SwiftData** (iOS 17.0+)+- **XcodeGen** for project generation (\`project.yml\` is the source of truth, not the \`.xcodeproj\`)+- Bundle ID: \`${bundleId}\`, Team: \`${teamId}\`++## Build Commands++\`\`\`bash+# Generate Xcode project (required after changing project.yml)+xcodegen generate++# Build+xcodebuild build -project ${targetName}.xcodeproj -scheme ${targetName} \\+ -destination 'platform=iOS Simulator,name=iPhone 16' CODE_SIGNING_ALLOWED=NO++# Run tests+xcodebuild test -project ${targetName}.xcodeproj -scheme ${targetName} \\+ -only-testing:${targetName}Tests \\+ -destination 'platform=iOS Simulator,name=iPhone 16' CODE_SIGNING_ALLOWED=NO+\`\`\`++## TestFlight Deployment++Local deploy via \`./deploy.sh\`:++\`\`\`bash+./deploy.sh # full: tests + archive + upload+./deploy.sh --skip-tests # skip tests for faster iteration+\`\`\`++Requires \`.env\` file with App Store Connect API credentials (see \`.env.example\`).+`);++ addStep('Create iOS project', 'done');++ // Run xcodegen if available+ const { stderr: xgenErr } = await execAsync('xcodegen generate', { cwd: repoPath, windowsHide: true })+ .catch(err => ({ stderr: err.message }));++ if (xgenErr && !xgenErr.includes('Created project')) {+ addStep('Generate Xcode project', 'error', xgenErr);+ } else {+ addStep('Generate Xcode project', 'done');+ }} else if (template === 'portos-stack') {// Create PortOS Stack - full monorepo with client, server, Tailwind, CI/CDconst clientDir = join(repoPath, 'client');@@ -1144,26 +1511,48 @@ module.exports = {`;}- await writeFile(join(repoPath, 'ecosystem.config.cjs'), ecosystemContent);- addStep('Create PM2 config', 'done');+ if (ecosystemContent) {+ await writeFile(join(repoPath, 'ecosystem.config.cjs'), ecosystemContent);+ addStep('Create PM2 config', 'done');+ }- // Run npm install- const installCmd = template === 'portos-stack' ? 'npm run install:all' : 'npm install';- const { stderr: installErr } = await execAsync(installCmd, { cwd: repoPath, windowsHide: true })- .catch(err => ({ stderr: err.message }));+ // Run npm install (skip for iOS — no npm)+ if (template !== 'ios-native') {+ const installCmd = template === 'portos-stack' ? 'npm run install:all' : 'npm install';+ const { stderr: installErr } = await execAsync(installCmd, { cwd: repoPath, windowsHide: true })+ .catch(err => ({ stderr: err.message }));- if (installErr && !installErr.includes('npm warn')) {- addStep('npm install', 'error', installErr);- } else {- addStep('npm install', 'done');+ if (installErr && !installErr.includes('npm warn')) {+ addStep('npm install', 'error', installErr);+ } else {+ addStep('npm install', 'done');+ }}// Initialize gitawait execAsync('git init', { cwd: repoPath, windowsHide: true });- // Create .gitignore - more comprehensive for portos-stack- const gitignoreContent = template === 'portos-stack'- ? `# Dependencies+ // Create .gitignore+ let gitignoreContent;+ if (template === 'ios-native') {+ gitignoreContent = `# Build output+build/+DerivedData/++# Environment files+.env++# OS files+.DS_Store++# IDE+*.swp+*.swo+xcuserdata/+*.xcworkspace+`;+ } else if (template === 'portos-stack') {+ gitignoreContent = `# Dependenciesnode_modules/# Build output@@ -1192,8 +1581,10 @@ Thumbs.db# PM2.pm2/-`- : 'node_modules\n.env\ndist\n';+`;+ } else {+ gitignoreContent = 'node_modules\n.env\ndist\n';+ }await writeFile(join(repoPath, '.gitignore'), gitignoreContent);await execAsync('git add -A', { cwd: repoPath, windowsHide: true });@@ -1226,11 +1617,13 @@ Thumbs.db'portos-stack': 'portos-stack','vite-react': 'vite','vite-express': 'vite+express',- 'express-api': 'single-node-server'+ 'express-api': 'single-node-server',+ 'ios-native': 'ios-native'};let pm2Names;let startCmds;+ let buildCmd;if (template === 'portos-stack') {pm2Names = [`${dirName}-server`, `${dirName}-ui`];@@ -1238,6 +1631,10 @@ Thumbs.db} else if (template === 'vite-express') {pm2Names = [`${dirName}-ui`, `${dirName}-api`];startCmds = ['npm run dev:all'];+ } else if (template === 'ios-native') {+ pm2Names = [];+ startCmds = [`open ${name.replace(/[^a-zA-Z0-9_]/g, '_')}.xcodeproj`];+ buildCmd = `xcodebuild build -project ${name.replace(/[^a-zA-Z0-9_]/g, '_')}.xcodeproj -scheme ${name.replace(/[^a-zA-Z0-9_]/g, '_')} -destination 'platform=iOS Simulator,name=iPhone 16' CODE_SIGNING_ALLOWED=NO`;} else {pm2Names = [dirName];startCmds = ['npm run dev'];@@ -1249,6 +1646,7 @@ Thumbs.dbtype: templateToType[template] || 'unknown',uiPort: uiPort || null,apiPort: apiPort || null,+ buildCommand: buildCmd,startCommands: startCmds,pm2ProcessNames: pm2Names,envFile: '.env'