import { useEffect, useMemo, useState } from 'react'; import type { FormEvent, ReactNode } from 'react'; import projectCatalog from '../../../configs/projectos.generated.json'; type Project = { name: string; initial: string; tone: string; stage: string; kind: string; description?: string; updated: string; health: string }; type CatalogItem = { name: string; description: string; icon?: string; capabilities: string[] }; type Plan = { id?: string; question: string; project: string; intent?: string; council: string; agents: string[]; model: string; datasets: string; tools: string; logic: string; governance: string; created: string; executionReady?: boolean; governanceGate?: { missingIntegrations: string[]; approvalRequired: boolean } }; type Policy = { id: string; title: string; description: string; status: string; reviewed?: string }; type Snapshot = { id: string; project: string; created: string; state: Project }; type Manifest = { steps: CatalogItem[]; stages: CatalogItem[]; fabrics: CatalogItem[]; agents: CatalogItem[]; councils: CatalogItem[]; governance: CatalogItem[]; knowledge: CatalogItem[] }; type Collection = 'projects' | 'policies' | 'plans' | 'snapshots'; type Modal = { kind: 'new-project' } | { kind: 'project'; project: Project } | { kind: 'stage'; stage: string } | { kind: 'detail'; title: string; description: string; capabilities: string[]; eyebrow: string } | { kind: 'snapshot'; snapshot: Snapshot }; const seedProjects: Project[] = [ { name: 'Atlas Research', initial: 'A', tone: 'violet', stage: 'Active', kind: 'Research', updated: '12 min ago', health: 'Healthy' }, { name: 'Northstar Platform', initial: 'N', tone: 'blue', stage: 'Production', kind: 'Platform', updated: '1 hr ago', health: 'Healthy' }, { name: 'Signal Intelligence', initial: 'S', tone: 'orange', stage: 'Evolving', kind: 'Research', updated: 'Yesterday', health: 'Attention' }, { name: 'Common Ground', initial: 'C', tone: 'green', stage: 'Active', kind: 'Knowledge', updated: 'Oct 28', health: 'Healthy' } ]; const seedPolicies: Policy[] = [ { id: 'workspace-access', title: 'Workspace permission defaults', description: 'Proposal to restrict project write access to assigned contributors.', status: 'Pending' }, { id: 'dataset-trust', title: 'Dataset trust profile updates', description: 'Proposal to require a verified source for new external datasets.', status: 'Pending' } ]; const defaultManifest: Manifest = { steps: [], stages: [], fabrics: [], agents: [], councils: [], governance: [], knowledge: [] }; const navItems = [ ['overview', '◫', 'Overview'], ['projects', '▤', 'Projects'], ['decision', '⌘', 'Decision flow'], ['lifecycle', '⟳', 'Lifecycle'], ['fabrics', '◈', 'Fabrics'], ['agents', '♧', 'Agents'], ['councils', '◎', 'Councils'], ['governance', '⬡', 'Governance'], ['knowledge', '▧', 'Knowledge'] ] as const; function readLocal(key: Collection, fallback: T): T { try { return JSON.parse(localStorage.getItem(`projectos.${key}`) || 'null') ?? fallback; } catch { return fallback; } } function writeLocal(key: Collection, value: T): void { try { localStorage.setItem(`projectos.${key}`, JSON.stringify(value)); } catch { /* Browser storage may be disabled. */ } } function collectionRequest(key: Collection, value: unknown): void { writeLocal(key, value); fetch(`/api/state/${key}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(value) }).catch(() => undefined); } function stageTone(stage: string): string { if (stage === 'Production') return 'blue'; if (stage === 'Evolving') return 'orange'; if (stage === 'Archive' || stage === 'Obsolete') return 'muted'; return 'green'; } function localPlan(question: string, project: string): Plan { const text = question.toLowerCase(); const council = /policy|permission|trust|privacy|risk|approval|audit/.test(text) ? 'Governance Council' : /deploy|database|docker|runtime|infrastructure|install|server/.test(text) ? 'Infrastructure Council' : /design|architecture|system|structure|interface/.test(text) ? 'Architecture Council' : /build|implement|code|create|app|feature|fix/.test(text) ? 'Implementation Council' : /improv|evol|compare|roadmap|gap|frontier/.test(text) ? 'Evolution Council' : 'Research Council'; const agents = council === 'Research Council' ? ['Research Agent', 'Knowledge Agent'] : council === 'Governance Council' ? ['Governance Agent', 'Logic Agent'] : council === 'Infrastructure Council' ? ['Infrastructure Agent', 'Dependency Agent'] : council === 'Evolution Council' ? ['Delta Agent', 'Evolution Agent'] : council === 'Architecture Council' ? ['Logic Agent', 'Infrastructure Agent'] : ['Implementation Agent', 'Logic Agent']; return { question, project: project || 'Workspace level', intent: 'local-preview', council, agents, model: 'Not configured', datasets: project ? `${project} project context` : 'No dataset connected', tools: 'No tool adapters configured', logic: 'Draft created; feasibility has not been verified against a runtime.', governance: 'Blocked: execution requires configured providers, policies, and approval.', created: new Date().toISOString(), executionReady: false }; } export default function App() { const [view, setView] = useState('overview'); const [projects, setProjects] = useState(() => readLocal('projects', seedProjects)); const [policies, setPolicies] = useState(() => readLocal('policies', seedPolicies)); const [plans, setPlans] = useState(() => readLocal('plans', [])); const [snapshots, setSnapshots] = useState(() => readLocal('snapshots', [])); const [manifest, setManifest] = useState(defaultManifest); const [modal, setModal] = useState(null); const [plan, setPlan] = useState(null); const [query, setQuery] = useState(''); const [projectFilter, setProjectFilter] = useState('All'); const [toast, setToast] = useState(''); const pendingCount = policies.filter(policy => policy.status === 'Pending').length; useEffect(() => { let active = true; setManifest(projectCatalog as Manifest); fetch('/api/state').then(response => response.ok ? response.json() : Promise.reject()) .then(state => { if (!active) return; const nextProjects = Array.isArray(state.projects) ? state.projects : readLocal('projects', seedProjects); const nextPolicies = Array.isArray(state.policies) ? state.policies : readLocal('policies', seedPolicies); const nextPlans = Array.isArray(state.plans) ? state.plans : readLocal('plans', []); const nextSnapshots = Array.isArray(state.snapshots) ? state.snapshots : readLocal('snapshots', []); setProjects(nextProjects); setPolicies(nextPolicies); setPlans(nextPlans); setSnapshots(nextSnapshots); for (const [key, value, remote] of [['projects', nextProjects, state.projects], ['policies', nextPolicies, state.policies], ['plans', nextPlans, state.plans], ['snapshots', nextSnapshots, state.snapshots]] as const) { if (Array.isArray(remote)) writeLocal(key, value); else collectionRequest(key, value); } }).catch(() => undefined); return () => { active = false; }; }, []); useEffect(() => { if (!toast) return; const timer = window.setTimeout(() => setToast(''), 2600); return () => window.clearTimeout(timer); }, [toast]); const visibleProjects = useMemo(() => projects.filter(project => project.name.toLowerCase().includes(query.toLowerCase()) && (projectFilter === 'All' || (projectFilter === 'Research' ? project.kind === 'Research' : project.stage === projectFilter))), [projects, projectFilter, query]); const saveProjects = (next: Project[]) => { setProjects(next); collectionRequest('projects', next); }; const savePolicies = (next: Policy[]) => { setPolicies(next); collectionRequest('policies', next); }; const addProject = (event: FormEvent) => { event.preventDefault(); const form = new FormData(event.currentTarget); const name = String(form.get('name') || '').trim(); if (projects.some(project => project.name.toLowerCase() === name.toLowerCase())) { setToast('A project with that name already exists.'); return; } const tones = ['violet', 'blue', 'orange', 'green']; const project: Project = { name, initial: name[0].toUpperCase(), tone: tones[projects.length % tones.length], stage: 'Research', kind: String(form.get('kind') || '').trim() || 'General', description: String(form.get('description') || '').trim(), updated: 'Just now', health: 'Healthy' }; saveProjects([project, ...projects]); setModal(null); setView('projects'); setToast(`Project “${name}” created.`); }; const updateProject = (event: FormEvent, original: Project) => { event.preventDefault(); const form = new FormData(event.currentTarget); const next = projects.map(project => project.name === original.name ? { ...project, stage: String(form.get('stage')), kind: String(form.get('kind')).trim() || 'General', updated: 'Just now' } : project); saveProjects(next); setModal(null); setToast(`${original.name} updated.`); }; const updateStage = (event: FormEvent) => { event.preventDefault(); const form = new FormData(event.currentTarget); const name = String(form.get('project')); const stage = String(form.get('stage')); saveProjects(projects.map(project => project.name === name ? { ...project, stage, updated: 'Just now' } : project)); setModal(null); setToast(`${name} moved to ${stage}.`); }; const createSnapshot = (project: Project) => { const snapshot: Snapshot = { id: globalThis.crypto?.randomUUID?.() || String(Date.now()), project: project.name, created: new Date().toISOString(), state: { ...project } }; const next = [snapshot, ...snapshots]; setSnapshots(next); collectionRequest('snapshots', next); setModal(null); setToast(`Snapshot saved for ${project.name}.`); }; const reviewPolicy = (policy: Policy, status: string) => { savePolicies(policies.map(item => item.id === policy.id ? { ...item, status, reviewed: new Date().toISOString() } : item)); setToast(`${policy.title}: ${status.toLowerCase()}.`); }; const createPlan = async (event: FormEvent) => { event.preventDefault(); const form = new FormData(event.currentTarget); const question = String(form.get('question') || '').trim(); const project = String(form.get('project') || ''); try { const response = await fetch('/api/plans/draft', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ question, project }) }); if (!response.ok) throw new Error('Planner unavailable'); const result = await response.json() as Plan; const next = [result, ...plans.filter(item => item.id !== result.id)].slice(0, 100); setPlans(next); writeLocal('plans', next); setPlan(result); setToast('Planning draft created. It has not been executed.'); } catch { const result = localPlan(question, project); const next = [result, ...plans].slice(0, 100); setPlans(next); collectionRequest('plans', next); setPlan(result); setToast('Created a browser-only planning draft.'); } }; const stages = manifest.stages.length ? manifest.stages : ['Research', 'Active', 'Production', 'Evolving', 'Frontier Comparison', 'Delta Analysis', 'Missing Dependencies', 'Evolution Suggestions', 'Obsolete', 'Snapshot', 'Archive', 'Template'].map(name => ({ name, description: '', capabilities: [] })); const navTo = (target: string) => { setView(target); setPlan(null); window.scrollTo({ top: 0, behavior: 'smooth' }); }; const projectRows = (items: Project[]) => items.map(project => ); const catalogCards = (items: CatalogItem[], eyebrow: string) =>
{items.map(item => )}
; let page: ReactNode; if (view === 'projects') page = <> setModal({ kind: 'new-project' })}>+ New project} />
{['All', 'Research', 'Production', 'Evolving'].map(filter => )}
setQuery(event.target.value)} placeholder="Search projects" />
PROJECTSTAGEUPDATED
{visibleProjects.length ? projectRows(visibleProjects) :

No projects match your search.

}
; else if (view === 'decision') page = <>

Plan a question

Generate a routing proposal for review.

LOCAL DRAFT