MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / SystemWorkspace

Function SystemWorkspace

graph-ui/src/system/SystemWorkspace.tsx:35–178  ·  view source on GitHub ↗
({ api, onOpenProjects, active = true, version, pollMs = 3000, project, configuration, listProjects }: SystemWorkspaceProps)

Source from the content-addressed store, hash-verified

33
34/** Daemon readings and configuration; project indexing uses the existing dialog. */
35export default function SystemWorkspace({ api, onOpenProjects, active = true, version, pollMs = 3000, project, configuration, listProjects }: SystemWorkspaceProps) {
36 const [tab, setTab] = useState<SystemTab>('overview');
37 const [paused, setPaused] = useState(false);
38 const [level, setLevel] = useState<'all' | 'error' | 'warn' | 'info'>('all');
39 const [scope, setScope] = useState<'daemon' | 'project' | 'unattributed'>('daemon');
40 const [copyStatus, setCopyStatus] = useState('');
41 const [followTail, setFollowTail] = useState(true);
42 const [indexesRefresh, setIndexesRefresh] = useState(0);
43 const logRef = useRef<HTMLDivElement>(null);
44 const readProcesses = useCallback(() => api.processes(), [api]);
45 const selectedProject = scope === 'project' ? project : undefined;
46 const readLogs = useCallback(async () => {
47 if (scope === 'project' && !selectedProject) throw new Error('Select a project to read its attributed events.');
48 const data = await api.logs(200, level === 'all' ? undefined : level, selectedProject, {
49 ...(scope === 'unattributed' ? { scope: 'unattributed' as const } : {}),
50 });
51 if ((scope !== 'daemon' || level !== 'all') && data.persistent !== true) throw new Error('Persistent history is unavailable. Filters require the daemon journal.');
52 if (scope === 'project' && (data.scope !== 'project' || data.project !== selectedProject)) throw new Error('The daemon did not confirm this project scope.');
53 if (scope === 'unattributed' && data.scope !== 'unattributed') throw new Error('The daemon did not confirm unattributed scope.');
54 return data;
55 }, [api, level, selectedProject, scope]);
56 const readJobs = useCallback(() => api.indexJobs(), [api]);
57 const processes = useSystemPoll(readProcesses, active, paused, pollMs);
58 const logs = useSystemPoll(readLogs, active && tab === 'logs', paused, pollMs);
59 const jobs = useSystemPoll(readJobs, active && tab === 'indexes', paused, pollMs);
60 const report = processes.data;
61 const self = report?.processes.find((process) => process.isSelf);
62 const visibleLines = logs.data?.lines ?? [];
63 const visibleRecords = logs.data?.records;
64 // Identical messages read as one line with a count; a repeated warning cannot push the rest out of view.
65 const logRows = useMemo(() => visibleRecords ? collapseRepeats(visibleRecords) : undefined, [visibleRecords]);
66 const selectedReading = tab === 'logs' ? logs : tab === 'indexes' ? jobs : processes;
67
68 useEffect(() => {
69 if (followTail && logRef.current) logRef.current.scrollTop = logRef.current.scrollHeight;
70 }, [logs.data, followTail, tab]);
71 useEffect(() => { setCopyStatus(''); }, [level, logs.data]);
72
73 const copyLogs = async () => {
74 try {
75 if (!navigator.clipboard?.writeText) throw new Error('Clipboard access is unavailable. Select and copy the visible text.');
76 await navigator.clipboard.writeText(logRows ? logRows.map(({ record, count }) => `${record.ts} ${record.level.toUpperCase()} ${record.source} #${record.id}${count > 1 ? ` ×${count}` : ''}\n${record.message}`).join('\n') : visibleLines.join('\n'));
77 setCopyStatus('Visible lines copied');
78 } catch (error) {
79 setCopyStatus(error instanceof Error ? error.message : 'Could not copy the log.');
80 }
81 };
82 const moveTab = (event: KeyboardEvent<HTMLButtonElement>, current: SystemTab) => {
83 const index = TABS.indexOf(current);
84 const target = event.key === 'ArrowDown' ? TABS[(index + 1) % TABS.length]
85 : event.key === 'ArrowUp' ? TABS[(index + TABS.length - 1) % TABS.length]
86 : event.key === 'Home' ? TABS[0] : event.key === 'End' ? TABS[TABS.length - 1] : undefined;
87 if (!target) return;
88 event.preventDefault();
89 setTab(target);
90 document.getElementById(`system-tab-${target}`)?.focus();
91 };
92

Callers

nothing calls this directly

Calls 14

useSystemPollFunction · 0.90
collapseRepeatsFunction · 0.90
memoryLabelFunction · 0.90
memoryTextFunction · 0.90
cpuTextFunction · 0.90
logLevelFunction · 0.90
repeatTitleFunction · 0.90
moveTabFunction · 0.85
configurationFunction · 0.85
copyLogsFunction · 0.85
processesMethod · 0.65
logsMethod · 0.65

Tested by

no test coverage detected