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: editable app documents with git commit on save
Adam Eivyd717b7fde4cf
diff --git a/.changelog/v1.24.x.md b/.changelog/v1.24.x.mdnew file mode 100644index 0000000000..5b8f31d40a--- /dev/null+++ b/.changelog/v1.24.x.md@@ -0,0 +1,14 @@+# Release v1.24.x - Changelog++Released: YYYY-MM-DD++## Overview++Editable app documents with automatic git commit on save.++## 🎉 Features++- **Editable Documents**: App document pages (PLAN.md, CLAUDE.md, GOALS.md) under the Documents tab can now be edited in-place with a monospace textarea editor+- **Git Commit on Save**: Saving a document automatically stages the file, commits it to the app's git repo, and shows the commit hash in a toast notification+- **Create Missing Documents**: Missing documents show "Create" buttons that open the editor for new file creation+- **No-Change Detection**: Saving without actual changes shows an info toast instead of creating an empty commitdiff --git a/client/src/components/apps/tabs/DocumentsTab.jsx b/client/src/components/apps/tabs/DocumentsTab.jsxindex 90a4c6de68..91b91c2c5d 100644--- a/client/src/components/apps/tabs/DocumentsTab.jsx+++ b/client/src/components/apps/tabs/DocumentsTab.jsx@@ -1,5 +1,6 @@import { useState, useEffect } from 'react';-import { RefreshCw, FileText } from 'lucide-react';+import { RefreshCw, FileText, Pencil, Save, X, Plus } from 'lucide-react';+import toast from 'react-hot-toast';import BrailleSpinner from '../../BrailleSpinner';import MarkdownOutput from '../../cos/MarkdownOutput';import * as api from '../../../services/api';@@ -11,6 +12,9 @@ export default function DocumentsTab({ appId, repoPath }) {const [selectedDoc, setSelectedDoc] = useState(null);const [docContent, setDocContent] = useState(null);const [loadingDoc, setLoadingDoc] = useState(false);+ const [editing, setEditing] = useState(false);+ const [editContent, setEditContent] = useState('');+ const [saving, setSaving] = useState(false);const fetchDocuments = async () => {setLoading(true);@@ -28,12 +32,52 @@ export default function DocumentsTab({ appId, repoPath }) {const loadDocument = async (filename) => {setSelectedDoc(filename);+ setEditing(false);setLoadingDoc(true);const data = await api.getAppDocument(appId, filename).catch(() => null);setDocContent(data?.content || null);setLoadingDoc(false);};+ const enterEditMode = () => {+ setEditContent(docContent || '');+ setEditing(true);+ };++ const enterCreateMode = (filename) => {+ setSelectedDoc(filename);+ setDocContent(null);+ setEditContent('');+ setEditing(true);+ };++ const cancelEdit = () => {+ setEditing(false);+ setEditContent('');+ };++ const handleSave = async () => {+ setSaving(true);+ const result = await api.saveAppDocument(appId, selectedDoc, editContent).catch(() => null);+ setSaving(false);++ if (!result) {+ toast.error('Failed to save document');+ return;+ }++ if (result.noChanges) {+ toast('No changes to commit', { icon: 'ℹ️' });+ setEditing(false);+ return;+ }++ toast.success(`Committed ${result.created ? 'new' : 'updated'} ${selectedDoc} (${result.hash})`);+ setDocContent(editContent);+ setEditing(false);+ fetchDocuments();+ };+useEffect(() => {fetchDocuments();}, [appId]);@@ -63,13 +107,26 @@ export default function DocumentsTab({ appId, repoPath }) {</button></div>- {existingDocs.length === 0 ? (+ {existingDocs.length === 0 && !editing ? (<div className="bg-port-card border border-port-border rounded-lg p-8 text-center"><FileText size={32} className="text-gray-600 mx-auto mb-3" /><p className="text-gray-400 mb-2">No documents found</p>- <p className="text-xs text-gray-500">+ <p className="text-xs text-gray-500 mb-4">Looking for: {documents.map(d => d.filename).join(', ')}</p>+ {missingDocs.length > 0 && (+ <div className="flex gap-2 justify-center">+ {missingDocs.map(doc => (+ <button+ key={doc.filename}+ onClick={() => enterCreateMode(doc.filename)}+ 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"+ >+ <Plus size={14} /> Create {doc.filename}+ </button>+ ))}+ </div>+ )}</div>) : (<div className="flex flex-col sm:flex-row gap-4">@@ -90,8 +147,17 @@ export default function DocumentsTab({ appId, repoPath }) {</button>))}{missingDocs.length > 0 && (- <div className="text-xs text-gray-600 mt-2 hidden sm:block">- Not found: {missingDocs.map(d => d.filename).join(', ')}+ <div className="hidden sm:block mt-2 space-y-1">+ <div className="text-xs text-gray-600">Create:</div>+ {missingDocs.map(doc => (+ <button+ key={doc.filename}+ onClick={() => enterCreateMode(doc.filename)}+ className="w-full px-3 py-1.5 rounded-lg text-xs text-left text-gray-500 hover:text-port-accent hover:bg-port-card border border-transparent hover:border-port-border transition-colors flex items-center gap-1"+ >+ <Plus size={12} /> {doc.filename}+ </button>+ ))}</div>)}</div>@@ -100,8 +166,47 @@ export default function DocumentsTab({ appId, repoPath }) {<div className="flex-1 bg-port-card border border-port-border rounded-lg p-4 min-h-[300px] overflow-auto">{loadingDoc ? (<BrailleSpinner text="Loading document" />+ ) : editing ? (+ <div className="space-y-3">+ <div className="flex items-center justify-between">+ <span className="text-sm text-gray-400">Editing {selectedDoc}</span>+ <div className="flex gap-2">+ <button+ onClick={cancelEdit}+ disabled={saving}+ className="px-3 py-1.5 bg-port-border hover:bg-port-border/80 text-white rounded-lg text-xs flex items-center gap-1"+ >+ <X size={14} /> Cancel+ </button>+ <button+ onClick={handleSave}+ disabled={saving}+ 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"+ >+ {saving ? <BrailleSpinner size="sm" /> : <Save size={14} />}+ {saving ? 'Saving...' : 'Save & Commit'}+ </button>+ </div>+ </div>+ <textarea+ value={editContent}+ onChange={e => setEditContent(e.target.value)}+ className="w-full h-[500px] bg-[#0d0d0d] text-gray-200 border border-port-border rounded-lg p-3 font-mono text-sm resize-y focus:outline-none focus:border-port-accent/50"+ spellCheck={false}+ />+ </div>) : docContent ? (- <MarkdownOutput content={docContent} />+ <div>+ <div className="flex justify-end mb-2">+ <button+ onClick={enterEditMode}+ className="px-3 py-1.5 bg-port-border hover:bg-port-border/80 text-white rounded-lg text-xs flex items-center gap-1"+ >+ <Pencil size={14} /> Edit+ </button>+ </div>+ <MarkdownOutput content={docContent} />+ </div>) : selectedDoc ? (<p className="text-gray-500 text-sm">Failed to load document</p>) : (diff --git a/client/src/services/api.js b/client/src/services/api.jsindex a4c392dd5c..6574aae25d 100644--- a/client/src/services/api.js+++ b/client/src/services/api.js@@ -155,6 +155,11 @@ export const getAppLogs = (id, lines = 100, processName) => {export const getAppDocuments = (id) => request(`/apps/${id}/documents`);export const getAppDocument = (id, filename) => request(`/apps/${id}/documents/${filename}`);+export const saveAppDocument = (id, filename, content, commitMessage) =>+ request(`/apps/${id}/documents/${filename}`, {+ method: 'PUT',+ body: JSON.stringify({ content, ...(commitMessage && { commitMessage }) })+ });export const getAppAgents = (id, limit = 50) => request(`/apps/${id}/agents?limit=${limit}`);// Portsdiff --git a/package-lock.json b/package-lock.jsonindex 08337c3dcc..75113fd693 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "portos",- "version": "1.23.0",+ "version": "1.24.0","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "portos",- "version": "1.23.0",+ "version": "1.24.0","license": "MIT","dependencies": {"express": "^4.21.2",diff --git a/package.json b/package.jsonindex 37c8b8aa9f..83cfe8412b 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "portos",- "version": "1.23.0",+ "version": "1.24.0","private": true,"description": "Local dev machine App OS portal","author": "Adam Eivy (@antic|@atomantic)",diff --git a/server/routes/apps.js b/server/routes/apps.jsindex 1b31d3c0c0..bfa4dac0b8 100644--- a/server/routes/apps.js+++ b/server/routes/apps.js@@ -1,7 +1,7 @@import { Router } from 'express';import { spawn } from 'child_process';import { existsSync } from 'fs';-import { readFile } from 'fs/promises';+import { readFile, writeFile } from 'fs/promises';import { join, resolve } from 'path';import * as appsService from '../services/apps.js';import { notifyAppsChanged, PORTOS_APP_ID } from '../services/apps.js';@@ -9,7 +9,9 @@ import * as pm2Service from '../services/pm2.js';import * as appUpdater from '../services/appUpdater.js';import * as cos from '../services/cos.js';import { logAction } from '../services/history.js';+import { z } from 'zod';import { validateRequest, appSchema, appUpdateSchema } from '../lib/validation.js';+import * as git from '../services/git.js';import { asyncHandler, ServerError } from '../lib/errorHandler.js';import { parseEcosystemFromPath } from '../services/streamingDetect.js';@@ -636,6 +638,11 @@ router.post('/:id/refresh-config', loadApp, asyncHandler(async (req, res) => {const ALLOWED_DOCUMENTS = ['PLAN.md', 'CLAUDE.md', 'GOALS.md'];+const documentUpdateSchema = z.object({+ content: z.string().max(500000),+ commitMessage: z.string().max(200).optional()+});+// GET /api/apps/:id/documents - List which documents existrouter.get('/:id/documents', loadApp, asyncHandler(async (req, res) => {const app = req.loadedApp;@@ -693,6 +700,44 @@ router.get('/:id/documents/:filename', loadApp, asyncHandler(async (req, res) =>res.json({ filename, content });}));+// PUT /api/apps/:id/documents/:filename - Update a document and git commit+router.put('/:id/documents/:filename', loadApp, asyncHandler(async (req, res) => {+ const app = req.loadedApp;+ const { filename } = req.params;++ if (!ALLOWED_DOCUMENTS.includes(filename)) {+ throw new ServerError('Document not in allowlist', { status: 400, code: 'INVALID_DOCUMENT' });+ }++ if (!app.repoPath || !existsSync(app.repoPath)) {+ throw new ServerError('App repo path does not exist', { status: 400, code: 'PATH_NOT_FOUND' });+ }++ const filePath = join(app.repoPath, filename);+ const resolved = resolve(filePath);++ if (!resolved.startsWith(resolve(app.repoPath))) {+ throw new ServerError('Invalid document path', { status: 400, code: 'PATH_TRAVERSAL' });+ }++ const { content, commitMessage } = documentUpdateSchema.parse(req.body);+ const created = !existsSync(resolved);++ await writeFile(resolved, content, 'utf-8');+ await git.stageFiles(app.repoPath, [filename]);++ const status = await git.getStatus(app.repoPath);+ if (status.clean) {+ return res.json({ success: true, noChanges: true });+ }++ const message = commitMessage || `docs: update ${filename} via PortOS`;+ const result = await git.commit(app.repoPath, message);+ console.log(`📝 ${created ? 'Created' : 'Updated'} ${filename} in ${app.name} (${result.hash})`);++ res.json({ success: true, hash: result.hash, created });+}));+// ============================================================// Agent History Endpoints// ============================================================