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 directory picker for template creation
Adam Eivyc4d223c9bac6
diff --git a/.changelog/v0.9.x.md b/.changelog/v0.9.x.mdnew file mode 100644index 0000000000..129b2cce0a--- /dev/null+++ b/.changelog/v0.9.x.md@@ -0,0 +1,26 @@+# Release Notes - v0.9.x++**Release Date:** YYYY-MM-DD++## 🎉 Features++### Template Creation Enhancement+- **Directory Picker for Template Target Path**: Replaced freeform text input with interactive directory browser on `/templates` page+ - Default directory now set to parent of PortOS project (`/Users/antic/github.com/atomantic`)+ - Visual folder navigation with breadcrumb-style current path display+ - Double-click folders to select or use "Select Current" button+ - "Parent" and "Default" navigation buttons for easy directory traversal++## 🔧 Improvements++### API+- Added `GET /api/directories` endpoint for browsing file system directories+ - Returns current path, parent path (if available), and list of subdirectories+ - Filters out hidden directories (starting with `.`)+ - Defaults to parent of PortOS project directory when no path specified++### UI Components+- New `DirectoryPicker` component in `client/src/components/DirectoryPicker.jsx`+ - Dropdown interface with folder icons and navigation+ - Real-time directory browsing without typing paths+ - Keyboard and mouse navigation supportdiff --git a/client/src/components/DirectoryPicker.jsx b/client/src/components/DirectoryPicker.jsxnew file mode 100644index 0000000000..cbf464c491--- /dev/null+++ b/client/src/components/DirectoryPicker.jsx@@ -0,0 +1,136 @@+import { useState, useEffect } from 'react';+import { Folder, ChevronRight, Home, ArrowUp, Loader2 } from 'lucide-react';+import * as api from '../services/api';++export default function DirectoryPicker({ value, onChange, label = 'Select Directory' }) {+ const [currentPath, setCurrentPath] = useState('');+ const [parentPath, setParentPath] = useState(null);+ const [directories, setDirectories] = useState([]);+ const [loading, setLoading] = useState(false);+ const [error, setError] = useState(null);+ const [isOpen, setIsOpen] = useState(false);++ useEffect(() => {+ loadDirectories();+ }, []);++ const loadDirectories = async (path = null) => {+ setLoading(true);+ setError(null);++ const result = await api.getDirectories(path).catch(err => {+ setError(err.message);+ return null;+ });++ if (result) {+ setCurrentPath(result.currentPath);+ setParentPath(result.parentPath);+ setDirectories(result.directories);+ }++ setLoading(false);+ };++ const handleSelectDirectory = (dirPath) => {+ onChange(dirPath);+ setIsOpen(false);+ };++ const handleNavigate = (path) => {+ loadDirectories(path);+ };++ return (+ <div className="relative">+ <label className="block text-sm text-gray-400 mb-1">{label} *</label>++ {/* Selected Directory Display */}+ <button+ type="button"+ onClick={() => setIsOpen(!isOpen)}+ className="w-full px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white focus:border-port-accent focus:outline-none font-mono text-left flex items-center justify-between"+ >+ <span className="truncate">{value || currentPath || 'Select a directory...'}</span>+ <ChevronRight size={16} className={`flex-shrink-0 transition-transform ${isOpen ? 'rotate-90' : ''}`} />+ </button>++ {/* Directory Browser Dropdown */}+ {isOpen && (+ <div className="absolute z-50 mt-1 w-full bg-port-card border border-port-border rounded-lg shadow-xl max-h-96 overflow-hidden flex flex-col">+ {/* Current Path Header */}+ <div className="sticky top-0 bg-port-card border-b border-port-border p-3 flex items-center gap-2">+ <Folder size={16} className="text-port-accent flex-shrink-0" />+ <span className="text-sm text-gray-400 truncate font-mono">{currentPath}</span>+ </div>++ {/* Navigation Controls */}+ <div className="border-b border-port-border p-2 flex gap-2">+ {parentPath && (+ <button+ type="button"+ onClick={() => handleNavigate(parentPath)}+ className="flex items-center gap-2 px-3 py-1.5 text-sm text-gray-400 hover:text-white hover:bg-port-border rounded transition-colors"+ disabled={loading}+ >+ <ArrowUp size={14} />+ <span>Parent</span>+ </button>+ )}+ <button+ type="button"+ onClick={() => handleNavigate(null)}+ className="flex items-center gap-2 px-3 py-1.5 text-sm text-gray-400 hover:text-white hover:bg-port-border rounded transition-colors"+ disabled={loading}+ >+ <Home size={14} />+ <span>Default</span>+ </button>+ <button+ type="button"+ onClick={() => handleSelectDirectory(currentPath)}+ className="ml-auto px-3 py-1.5 text-sm bg-port-accent hover:bg-port-accent/80 text-white rounded transition-colors"+ disabled={loading}+ >+ Select Current+ </button>+ </div>++ {/* Directory List */}+ <div className="overflow-y-auto flex-1">+ {loading ? (+ <div className="flex items-center justify-center p-8">+ <Loader2 size={24} className="text-gray-500 animate-spin" />+ </div>+ ) : error ? (+ <div className="p-4 text-center text-port-error text-sm">{error}</div>+ ) : directories.length === 0 ? (+ <div className="p-4 text-center text-gray-500 text-sm">No subdirectories</div>+ ) : (+ <div className="p-2">+ {directories.map(dir => (+ <button+ key={dir.path}+ type="button"+ onClick={() => handleNavigate(dir.path)}+ onDoubleClick={() => handleSelectDirectory(dir.path)}+ className="w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-300 hover:text-white hover:bg-port-border rounded transition-colors group"+ >+ <Folder size={14} className="text-gray-500 group-hover:text-port-accent flex-shrink-0" />+ <span className="truncate">{dir.name}</span>+ <ChevronRight size={14} className="ml-auto flex-shrink-0 text-gray-600 group-hover:text-gray-400" />+ </button>+ ))}+ </div>+ )}+ </div>++ {/* Footer Help */}+ <div className="border-t border-port-border p-2 text-xs text-gray-500">+ Double-click a folder to select it, or use "Select Current"+ </div>+ </div>+ )}+ </div>+ );+}diff --git a/client/src/pages/Templates.jsx b/client/src/pages/Templates.jsxindex 2912c75a7b..f363c2d8db 100644--- a/client/src/pages/Templates.jsx+++ b/client/src/pages/Templates.jsx@@ -2,6 +2,7 @@ import { useState, useEffect } from 'react';import { useNavigate } from 'react-router-dom';import { Layers, Code, Server, Globe, Plus } from 'lucide-react';import * as api from '../services/api';+import DirectoryPicker from '../components/DirectoryPicker';const ICONS = {layers: Layers,@@ -112,14 +113,10 @@ export default function Templates() {</div><div>- <label className="block text-sm text-gray-400 mb-1">Target Directory *</label>- <input- type="text"+ <DirectoryPickervalue={targetPath}- onChange={(e) => setTargetPath(e.target.value)}- placeholder="/Users/you/projects"- required- className="w-full px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white focus:border-port-accent focus:outline-none font-mono"+ onChange={setTargetPath}+ label="Target Directory"/><p className="text-xs text-gray-500 mt-1">App will be created at: {targetPath ? `${targetPath}/${appName || 'app-name'}` : '...'}diff --git a/client/src/services/api.js b/client/src/services/api.jsindex 40e31f6045..fffb214aa0 100644--- a/client/src/services/api.js+++ b/client/src/services/api.js@@ -94,6 +94,11 @@ export const detectWithAi = (path, providerId) => request('/detect/ai', {// Templates & Scaffoldexport const getTemplates = () => request('/templates');+export const getDirectories = (path = null) => {+ const params = path ? `?path=${encodeURIComponent(path)}` : '';+ return request(`/directories${params}`);+};+export const scaffoldApp = (data) => request('/scaffold', {method: 'POST',body: JSON.stringify(data)diff --git a/server/routes/scaffold.js b/server/routes/scaffold.jsindex 7a0e673f6a..615f1cc5a0 100644--- a/server/routes/scaffold.js+++ b/server/routes/scaffold.js@@ -1,10 +1,11 @@import { Router } from 'express';-import { mkdir, writeFile, readdir, copyFile, readFile } from 'fs/promises';+import { mkdir, writeFile, readdir, copyFile, readFile, stat } from 'fs/promises';import { existsSync } from 'fs';-import { join, dirname } from 'path';+import { join, dirname, resolve } from 'path';import { fileURLToPath } from 'url';import { exec, spawn } from 'child_process';import { promisify } from 'util';+import { homedir } from 'os';import { createApp, getReservedPorts } from '../services/apps.js';import { asyncHandler, ServerError } from '../lib/errorHandler.js';@@ -15,6 +16,51 @@ const TEMPLATES_DIR = join(__dirname, '../../templates');const router = Router();+// GET /api/directories - Browse directories for directory picker+router.get('/directories', asyncHandler(async (req, res) => {+ const { path: dirPath } = req.query;++ // Default to parent of PortOS project if no path provided+ const defaultPath = resolve(join(__dirname, '../../..'));+ const targetPath = dirPath ? resolve(dirPath) : defaultPath;++ // Validate path exists and is a directory+ if (!existsSync(targetPath)) {+ throw new ServerError('Directory does not exist', {+ status: 400,+ code: 'INVALID_PATH'+ });+ }++ const stats = await stat(targetPath);+ if (!stats.isDirectory()) {+ throw new ServerError('Path is not a directory', {+ status: 400,+ code: 'NOT_A_DIRECTORY'+ });+ }++ // Read directory contents+ const entries = await readdir(targetPath, { withFileTypes: true });+ const directories = entries+ .filter(entry => entry.isDirectory() && !entry.name.startsWith('.'))+ .map(entry => ({+ name: entry.name,+ path: join(targetPath, entry.name)+ }))+ .sort((a, b) => a.name.localeCompare(b.name));++ // Get parent directory info+ const parentPath = dirname(targetPath);+ const canGoUp = parentPath !== targetPath; // Can't go above root++ res.json({+ currentPath: targetPath,+ parentPath: canGoUp ? parentPath : null,+ directories+ });+}));+// GET /api/templates - List available templatesrouter.get('/templates', asyncHandler(async (req, res) => {const templates = [