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([issue-1975]): add View System Logs button to failed AI runs
[._.]/ Adam Eivya78a37ae4de5
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 70e00eaaf3..5f88a525db 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -30,6 +30,7 @@## Dev Tools+- **[issue-1975] View system logs straight from a failed AI run.** Failed runs in **Dev Tools → AI Runs History** now have a **View System Logs** button (both a quick icon on the collapsed row and a labeled button in the expanded error panel) that pops open the relevant PortOS system log — `portos-cos` for CoS-agent runs, `portos-server` for everything else — so an operator who doesn't know where the logs live can read the full error context without leaving the page. The log viewer includes a process picker and a tail-length selector, and is a reusable `ProcessLogModal` that any part of the app can open. (Closes #1975)- **[issue-1946] Download full videos from a YouTube or x.com URL.** A new **Dev Tools → Video Downloader** page lets you paste a YouTube (video/shorts/youtu.be) or x.com/Twitter status URL and download the *full video* (not just the audio, which is #1945's job) via `yt-dlp` — the same host dependency the music-video track import already uses. The clip lands in your video storage as a distinguishable `downloaded-<id>.mp4`, gets an auto-generated thumbnail, and — because it's written as a `source: 'download'` entry into the shared video-history store — also shows up in your media gallery alongside AI-generated renders (no new "library" concept; the existing media asset index picks it up through the same completed-video path it already uses, and prunes it on delete). Download progress streams live (download % → merging → finalizing) with a Cancel button, and the page lists everything you've downloaded (thumbnail, title, source link, age) with delete. x.com/Twitter pulls are best-effort — login-walled or rate-limited posts surface a clear error rather than a generic failure. Long/huge downloads are bounded (≤1h, ≤2GB) so a livestream or archive URL can't eat disk unbounded. `POST /api/devtools/video-download` (`server/services/videoDownload.js`, `server/routes/videoDownload.js`) mirrors #1945's async-job/SSE pattern. (Closes #1946)## Architecturediff --git a/client/src/components/ui/ProcessLogModal.jsx b/client/src/components/ui/ProcessLogModal.jsxnew file mode 100644index 0000000000..316fd7287a--- /dev/null+++ b/client/src/components/ui/ProcessLogModal.jsx@@ -0,0 +1,137 @@+/**+ * ProcessLogModal — a self-contained viewer for a PM2 process's system log.+ *+ * Built so an operator who doesn't know where the system logs live can open the+ * relevant log straight from wherever an error surfaced (e.g. a failed AI run in+ * RunsHistoryPage). Fetches a static tail via `getProcessLogs` (not the live SSE+ * stream — a past failure's context is already written), with a process picker,+ * a tail-length selector, and a manual refresh.+ */++import { useState, useEffect, useCallback } from 'react';+import { RefreshCw, X } from 'lucide-react';+import Modal from './Modal';+import BrailleSpinner from '../BrailleSpinner';+import * as api from '../../services/api';++// Map an AI run's source to the PM2 process whose system log holds the full+// context for that run. CoS-agent runs are driven by the `portos-cos` process;+// everything else (DevTools runs) is driven by the main `portos-server`.+export function runLogProcessName(source) {+ return source === 'cos-agent' ? 'portos-cos' : 'portos-server';+}++const TAIL_OPTIONS = [100, 250, 500, 1000, 2000];++export default function ProcessLogModal({ open, onClose, processName, title = 'System Logs' }) {+ const [processes, setProcesses] = useState([]);+ const [selected, setSelected] = useState(processName || '');+ const [tailLines, setTailLines] = useState(200);+ const [logs, setLogs] = useState('');+ const [loading, setLoading] = useState(false);+ const [error, setError] = useState('');++ // When the modal opens, seed the selected process from the caller's hint and+ // load the picker options. Guard against a late response landing after close.+ useEffect(() => {+ if (!open) return;+ let cancelled = false;+ setSelected(processName || '');+ api.getLogProcesses()+ .then((list) => { if (!cancelled) setProcesses(Array.isArray(list) ? list : []); })+ .catch(() => { if (!cancelled) setProcesses([]); });+ return () => { cancelled = true; };+ }, [open, processName]);++ const loadLogs = useCallback(async () => {+ if (!selected) return;+ setLoading(true);+ setError('');+ const res = await api.getProcessLogs(selected, tailLines).catch((err) => {+ setError(err?.message || 'Failed to load logs');+ return null;+ });+ if (res) setLogs(res.logs || '');+ setLoading(false);+ }, [selected, tailLines]);++ // Fetch whenever the modal is open and the process / tail length changes.+ useEffect(() => {+ if (!open || !selected) return;+ loadLogs();+ }, [open, selected, tailLines, loadLogs]);++ if (!open) return null;++ return (+ <Modal open={open} onClose={onClose} size="3xl" align="top" ariaLabel={title}>+ <div className="bg-port-card border border-port-border rounded-xl overflow-hidden flex flex-col max-h-[80vh]">+ <div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3 px-4 sm:px-6 py-3 border-b border-port-border">+ <span className="text-base sm:text-lg font-medium text-white">{title}</span>+ <div className="flex flex-wrap items-center gap-2 sm:gap-3">+ <div className="flex items-center gap-1.5">+ <label htmlFor="log-process" className="text-xs text-gray-500">Process</label>+ <select+ id="log-process"+ value={selected}+ onChange={(e) => setSelected(e.target.value)}+ className="px-2 py-1 text-xs bg-port-bg border border-port-border rounded text-white max-w-[10rem]"+ >+ {/* Keep the caller's hinted process selectable even if PM2 isn't+ reporting it (e.g. dev server not under PM2) so the fetch can+ still surface a helpful error. */}+ {selected && !processes.some((p) => p.name === selected) && (+ <option value={selected}>{selected}</option>+ )}+ {processes.map((p) => (+ <option key={p.name} value={p.name}>{p.name}</option>+ ))}+ </select>+ </div>+ <div className="flex items-center gap-1.5">+ <label htmlFor="log-tail" className="text-xs text-gray-500">Tail</label>+ <select+ id="log-tail"+ value={tailLines}+ onChange={(e) => setTailLines(Number(e.target.value))}+ className="px-2 py-1 text-xs bg-port-bg border border-port-border rounded text-white"+ >+ {TAIL_OPTIONS.map((n) => (+ <option key={n} value={n}>{n}</option>+ ))}+ </select>+ </div>+ <button+ onClick={loadLogs}+ disabled={loading || !selected}+ className="p-1.5 text-gray-400 hover:text-white transition-colors disabled:opacity-50"+ title="Refresh logs"+ aria-label="Refresh logs"+ >+ <RefreshCw size={14} className={loading ? 'animate-spin' : ''} />+ </button>+ <button+ onClick={onClose}+ className="p-1.5 text-gray-400 hover:text-white transition-colors"+ title="Close"+ aria-label="Close logs"+ >+ <X size={18} />+ </button>+ </div>+ </div>+ <div className="flex-1 overflow-auto bg-port-bg p-3 sm:p-4 min-h-[16rem]">+ {loading && !logs ? (+ <BrailleSpinner text="Loading logs" />+ ) : error ? (+ <div className="text-sm text-port-error font-mono">{error}</div>+ ) : logs ? (+ <pre className="text-xs text-gray-300 font-mono whitespace-pre-wrap break-all">{logs}</pre>+ ) : (+ <div className="text-sm text-gray-500">No log output.</div>+ )}+ </div>+ </div>+ </Modal>+ );+}diff --git a/client/src/components/ui/ProcessLogModal.test.jsx b/client/src/components/ui/ProcessLogModal.test.jsxnew file mode 100644index 0000000000..b5f42d1d89--- /dev/null+++ b/client/src/components/ui/ProcessLogModal.test.jsx@@ -0,0 +1,62 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';+import { render, screen, fireEvent, waitFor, within } from '@testing-library/react';++vi.mock('../../services/api', () => ({+ getLogProcesses: vi.fn(),+ getProcessLogs: vi.fn(),+}));++import { getLogProcesses, getProcessLogs } from '../../services/api';+import ProcessLogModal, { runLogProcessName } from './ProcessLogModal';++describe('runLogProcessName', () => {+ it('maps cos-agent runs to the portos-cos process', () => {+ expect(runLogProcessName('cos-agent')).toBe('portos-cos');+ });++ it('maps devtools and unknown sources to the main portos-server process', () => {+ expect(runLogProcessName('devtools')).toBe('portos-server');+ expect(runLogProcessName(undefined)).toBe('portos-server');+ });+});++describe('ProcessLogModal', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ getLogProcesses.mockResolvedValue([{ name: 'portos-server' }, { name: 'portos-cos' }]);+ getProcessLogs.mockResolvedValue({ processName: 'portos-server', lines: 200, logs: 'boot ok\nerror: boom' });+ });++ it('renders nothing when closed', () => {+ const { container } = render(<ProcessLogModal open={false} onClose={() => {}} processName="portos-server" />);+ expect(container).toBeEmptyDOMElement();+ expect(getProcessLogs).not.toHaveBeenCalled();+ });++ it('fetches and shows the selected process log when opened', async () => {+ render(<ProcessLogModal open onClose={() => {}} processName="portos-server" />);+ await waitFor(() => expect(getProcessLogs).toHaveBeenCalledWith('portos-server', 200));+ expect(await screen.findByText(/error: boom/)).toBeInTheDocument();+ });++ it('refetches with the new tail length when changed', async () => {+ render(<ProcessLogModal open onClose={() => {}} processName="portos-server" />);+ await waitFor(() => expect(getProcessLogs).toHaveBeenCalledWith('portos-server', 200));+ fireEvent.change(screen.getByLabelText('Tail'), { target: { value: '500' } });+ await waitFor(() => expect(getProcessLogs).toHaveBeenCalledWith('portos-server', 500));+ });++ it('surfaces a fetch error instead of log text', async () => {+ getProcessLogs.mockRejectedValueOnce(new Error('daemon down'));+ render(<ProcessLogModal open onClose={() => {}} processName="portos-server" />);+ expect(await screen.findByText('daemon down')).toBeInTheDocument();+ });++ it('keeps the hinted process selectable even when PM2 does not report it', async () => {+ getLogProcesses.mockResolvedValueOnce([{ name: 'portos-cos' }]);+ render(<ProcessLogModal open onClose={() => {}} processName="portos-server" />);+ await waitFor(() => expect(getProcessLogs).toHaveBeenCalledWith('portos-server', 200));+ const select = screen.getByLabelText('Process');+ expect(within(select).getByRole('option', { name: 'portos-server' })).toBeInTheDocument();+ });+});diff --git a/client/src/pages/RunsHistoryPage.jsx b/client/src/pages/RunsHistoryPage.jsxindex db4690819d..a42a37e107 100644--- a/client/src/pages/RunsHistoryPage.jsx+++ b/client/src/pages/RunsHistoryPage.jsx@@ -1,10 +1,11 @@import { useState, useEffect, useCallback } from 'react';import { useNavigate } from 'react-router-dom';-import { Trash2, RotateCcw, MessageSquarePlus } from 'lucide-react';+import { Trash2, RotateCcw, MessageSquarePlus, ScrollText } from 'lucide-react';import * as api from '../services/api';import { formatTime, formatRuntime, formatBytes, formatDateTime } from '../utils/formatters';import BrailleSpinner from '../components/BrailleSpinner';import Banner from '../components/ui/Banner';+import ProcessLogModal, { runLogProcessName } from '../components/ui/ProcessLogModal';import { writeClipboardSilently } from '../lib/clipboard';export function RunsHistoryPage() {@@ -15,6 +16,8 @@ export function RunsHistoryPage() {const [expandedDetails, setExpandedDetails] = useState({});const [sourceFilter, setSourceFilter] = useState('all');const [statusFilter, setStatusFilter] = useState('all');+ // The failed run whose system logs are open in the log modal, or null.+ const [logModalRun, setLogModalRun] = useState(null);const loadRuns = useCallback(async () => {setLoading(true);@@ -272,6 +275,16 @@ export function RunsHistoryPage() {<div className="flex items-center gap-3 pl-8 sm:pl-0"><span className={`w-2 h-2 rounded-full shrink-0 ${run.success ? 'bg-port-success' : run.success === false ? 'bg-port-error' : 'bg-port-warning'}`} /><span className="text-sm text-gray-500 shrink-0">{formatTime(run.startTime)}</span>+ {run.success === false && (+ <button+ onClick={(e) => { e.stopPropagation(); setLogModalRun(run); }}+ className="p-1 text-gray-500 hover:text-port-accent transition-colors sm:opacity-0 sm:group-hover:opacity-100"+ title="View system logs"+ data-testid={`view-logs-${run.id}`}+ >+ <ScrollText size={14} />+ </button>+ )}{run.success !== null && (<buttononClick={(e) => handleResume(run, e)}@@ -419,6 +432,18 @@ export function RunsHistoryPage() {</div></Banner>)}+ {/* Jump straight to the system logs for the full error context,+ for operators who don't know where the logs live. */}+ <div className="mt-3">+ <button+ onClick={() => setLogModalRun(run)}+ className="flex items-center gap-2 px-3 py-1.5 text-sm bg-port-card border border-port-border hover:border-port-accent text-gray-300 hover:text-white rounded-lg transition-colors"+ data-testid={`view-logs-expanded-${run.id}`}+ >+ <ScrollText size={14} />+ View System Logs+ </button>+ </div></div>);})()}@@ -444,6 +469,13 @@ export function RunsHistoryPage() {</div>)}</div>++ <ProcessLogModal+ open={!!logModalRun}+ onClose={() => setLogModalRun(null)}+ processName={logModalRun ? runLogProcessName(logModalRun.source) : ''}+ title={logModalRun ? `System Logs — ${runLogProcessName(logModalRun.source)}` : 'System Logs'}+ /></div>);}diff --git a/client/src/services/README.md b/client/src/services/README.mdindex 407b4c1dab..e82c175779 100644--- a/client/src/services/README.md+++ b/client/src/services/README.md@@ -47,6 +47,7 @@ toasts on throw). **Custom catch ⇒ `silent: true`** — otherwise toasts fire| `apiGit.js` | Git operations. || `apiGithub.js` | GitHub repo metadata. || `apiHistory.js` | Historical logs / runs. |+| `apiLogs.js` | Live PM2 system logs: list processes + fetch a process's recent log tail. || `apiPorts.js` | Port forwarding / allocation. || `apiProviders.js` | AI provider config. || `apiReferenceRepos.js` | Per-app reference-repo registry. |diff --git a/client/src/services/api.js b/client/src/services/api.jsindex ecf99b1b3c..e62840c8fa 100644--- a/client/src/services/api.js+++ b/client/src/services/api.js@@ -12,6 +12,7 @@ export * from './apiScaffold.js';export * from './apiProviders.js';export * from './apiRuns.js';export * from './apiHistory.js';+export * from './apiLogs.js';export * from './apiCommands.js';export * from './apiGit.js';export * from './apiCatalog.js';diff --git a/client/src/services/apiLogs.js b/client/src/services/apiLogs.jsnew file mode 100644index 0000000000..44102ea5fd--- /dev/null+++ b/client/src/services/apiLogs.js@@ -0,0 +1,10 @@+import { request } from './apiCore.js';++// System (PM2) logs+// List every PM2 process so a log viewer can offer a process picker.+export const getLogProcesses = () => request('/logs/processes');++// Fetch the recent tail of a PM2 process's system log. Returns+// `{ processName, lines, logs }` where `logs` is the raw multi-line text.+export const getProcessLogs = (processName, lines = 200) =>+ request(`/logs/${encodeURIComponent(processName)}?lines=${lines}`);