@polymorphism-tech/morph-spec 4.19.0 → 4.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/bin/morph-spec.js +11 -0
- package/bin/task-manager.js +35 -10
- package/claude-plugin.json +1 -1
- package/docs/CHEATSHEET.md +1 -1
- package/docs/QUICKSTART.md +1 -1
- package/framework/agents/architecture/architecture-expert.md +12 -0
- package/framework/agents/architecture/packages-validator.md +12 -0
- package/framework/agents/architecture/security-expert.md +12 -0
- package/framework/agents/frontend/design-system-validator.md +12 -0
- package/framework/agents/frontend/nextjs-component-validator.md +12 -0
- package/framework/hooks/claude-code/post-tool-use/dispatch.js +20 -3
- package/framework/hooks/claude-code/post-tool-use/validator-feedback.js +60 -11
- package/framework/rubrics/backend.json +36 -0
- package/framework/rubrics/default.json +36 -0
- package/framework/rubrics/frontend.json +36 -0
- package/framework/skills/level-0-meta/morph-frontend-review/SKILL.md +1 -1
- package/framework/skills/level-1-workflows/morph-phase-codebase-analysis/SKILL.md +1 -1
- package/framework/skills/level-1-workflows/morph-phase-design/SKILL.md +1 -1
- package/framework/skills/level-1-workflows/morph-phase-implement/SKILL.md +1 -1
- package/framework/skills/level-1-workflows/morph-phase-plan/SKILL.md +1 -1
- package/framework/skills/level-1-workflows/morph-phase-tasks/SKILL.md +1 -1
- package/framework/skills/level-1-workflows/morph-phase-uiux/SKILL.md +1 -1
- package/framework/skills/level-1-workflows/morph-scope-escalation/SKILL.md +1 -1
- package/package.json +1 -1
- package/src/commands/dashboard/dashboard.js +53 -0
- package/src/dashboard/app/App.jsx +31 -0
- package/src/dashboard/app/components/DetailPanel.jsx +11 -0
- package/src/dashboard/app/components/FlowGraph.jsx +17 -0
- package/src/dashboard/app/components/SearchFilter.jsx +22 -0
- package/src/dashboard/app/components/Sidebar.jsx +45 -0
- package/src/dashboard/app/hooks/useDetailPanel.js +15 -0
- package/src/dashboard/app/main.jsx +13 -0
- package/src/dashboard/app/pages/AgentMap.jsx +371 -0
- package/src/dashboard/app/pages/HookInspector.jsx +418 -0
- package/src/dashboard/app/pages/LiveState.jsx +239 -0
- package/src/dashboard/app/pages/PhasePipeline.jsx +410 -0
- package/src/dashboard/app/pages/RulesMap.jsx +273 -0
- package/src/dashboard/app/pages/SkillsLibrary.jsx +367 -0
- package/src/dashboard/app/pages/Standards.jsx +332 -0
- package/src/dashboard/app/pages/Workflows.jsx +346 -0
- package/src/dashboard/app/styles/index.css +47 -0
- package/src/dashboard/index.html +12 -0
- package/src/dashboard/package.json +24 -0
- package/src/dashboard/scanner/agents-scanner.js +35 -0
- package/src/dashboard/scanner/hooks-scanner.js +41 -0
- package/src/dashboard/scanner/index.js +21 -0
- package/src/dashboard/scanner/phases-scanner.js +15 -0
- package/src/dashboard/scanner/rubrics-scanner.js +12 -0
- package/src/dashboard/scanner/rules-scanner.js +37 -0
- package/src/dashboard/scanner/skills-scanner.js +43 -0
- package/src/dashboard/scanner/squads-scanner.js +13 -0
- package/src/dashboard/scanner/standards-scanner.js +26 -0
- package/src/dashboard/scanner/state-scanner.js +8 -0
- package/src/dashboard/scanner/workflows-scanner.js +18 -0
- package/src/dashboard/vite-plugin-morph-data.js +17 -0
- package/src/dashboard/vite.config.js +24 -0
- package/src/lib/checkpoints/checkpoint-hooks.js +2 -1
- package/src/lib/generators/recap-generator.js +15 -0
- package/src/lib/validators/score-aggregator.js +244 -0
- package/src/lib/validators/validation-runner.js +44 -0
- package/src/scripts/setup-infra.js +8 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
import { resolve, dirname } from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
|
|
9
|
+
export async function dashboardCommand(options = {}) {
|
|
10
|
+
const port = options.port || '3200';
|
|
11
|
+
const dashboardDir = resolve(__dirname, '..', '..', 'dashboard');
|
|
12
|
+
const nodeModules = resolve(dashboardDir, 'node_modules');
|
|
13
|
+
|
|
14
|
+
// Check if dashboard dependencies are installed
|
|
15
|
+
if (!existsSync(nodeModules)) {
|
|
16
|
+
console.log(chalk.yellow('Installing dashboard dependencies...'));
|
|
17
|
+
const install = spawn('npm', ['install'], {
|
|
18
|
+
cwd: dashboardDir,
|
|
19
|
+
stdio: 'inherit',
|
|
20
|
+
shell: true,
|
|
21
|
+
});
|
|
22
|
+
await new Promise((res, rej) => {
|
|
23
|
+
install.on('close', (code) => (code === 0 ? res() : rej(new Error(`npm install failed with code ${code}`))));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
console.log(chalk.cyan(`\n Starting morph-spec dashboard at http://localhost:${port}\n`));
|
|
28
|
+
|
|
29
|
+
const env = {
|
|
30
|
+
...process.env,
|
|
31
|
+
MORPH_PROJECT_DIR: process.cwd(),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const viteArgs = ['vite', '--port', port];
|
|
35
|
+
if (options.open !== false) viteArgs.push('--open');
|
|
36
|
+
|
|
37
|
+
const vite = spawn('npx', viteArgs, {
|
|
38
|
+
cwd: dashboardDir,
|
|
39
|
+
stdio: 'inherit',
|
|
40
|
+
shell: true,
|
|
41
|
+
env,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
vite.on('error', (err) => {
|
|
45
|
+
console.error(chalk.red(`Failed to start dashboard: ${err.message}`));
|
|
46
|
+
process.exit(1);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
process.on('SIGINT', () => {
|
|
50
|
+
vite.kill();
|
|
51
|
+
process.exit(0);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Routes, Route, Navigate } from 'react-router-dom';
|
|
2
|
+
import Sidebar from './components/Sidebar.jsx';
|
|
3
|
+
import AgentMap from './pages/AgentMap.jsx';
|
|
4
|
+
import PhasePipeline from './pages/PhasePipeline.jsx';
|
|
5
|
+
import HookInspector from './pages/HookInspector.jsx';
|
|
6
|
+
import SkillsLibrary from './pages/SkillsLibrary.jsx';
|
|
7
|
+
import RulesMap from './pages/RulesMap.jsx';
|
|
8
|
+
import Standards from './pages/Standards.jsx';
|
|
9
|
+
import Workflows from './pages/Workflows.jsx';
|
|
10
|
+
import LiveState from './pages/LiveState.jsx';
|
|
11
|
+
|
|
12
|
+
export default function App() {
|
|
13
|
+
return (
|
|
14
|
+
<div className="flex h-screen bg-gray-950 text-gray-100 overflow-hidden">
|
|
15
|
+
<Sidebar />
|
|
16
|
+
<main className="flex-1 overflow-auto">
|
|
17
|
+
<Routes>
|
|
18
|
+
<Route path="/" element={<Navigate to="/agents" replace />} />
|
|
19
|
+
<Route path="/agents" element={<AgentMap />} />
|
|
20
|
+
<Route path="/phases" element={<PhasePipeline />} />
|
|
21
|
+
<Route path="/hooks" element={<HookInspector />} />
|
|
22
|
+
<Route path="/skills" element={<SkillsLibrary />} />
|
|
23
|
+
<Route path="/rules" element={<RulesMap />} />
|
|
24
|
+
<Route path="/standards" element={<Standards />} />
|
|
25
|
+
<Route path="/workflows" element={<Workflows />} />
|
|
26
|
+
<Route path="/state" element={<LiveState />} />
|
|
27
|
+
</Routes>
|
|
28
|
+
</main>
|
|
29
|
+
</div>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default function DetailPanel({ open, title, onClose, children }) {
|
|
2
|
+
return (
|
|
3
|
+
<div className={`fixed top-0 right-0 h-full w-96 bg-gray-900 border-l border-gray-700 shadow-2xl transform transition-transform duration-200 ease-in-out z-50 ${open ? 'translate-x-0' : 'translate-x-full'}`}>
|
|
4
|
+
<div className="flex items-center justify-between p-4 border-b border-gray-700">
|
|
5
|
+
<h2 className="text-white font-semibold text-lg truncate">{title}</h2>
|
|
6
|
+
<button onClick={onClose} className="text-gray-400 hover:text-white text-xl leading-none">×</button>
|
|
7
|
+
</div>
|
|
8
|
+
<div className="p-4 overflow-y-auto h-[calc(100%-57px)]">{children}</div>
|
|
9
|
+
</div>
|
|
10
|
+
);
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ReactFlow, Controls, MiniMap, Background } from '@xyflow/react';
|
|
2
|
+
|
|
3
|
+
export default function FlowGraph({ nodes, edges, nodeTypes, onNodeClick, fitView = true, className = '' }) {
|
|
4
|
+
return (
|
|
5
|
+
<div className={`w-full h-full ${className}`} style={{ minHeight: '500px' }}>
|
|
6
|
+
<ReactFlow
|
|
7
|
+
nodes={nodes} edges={edges} nodeTypes={nodeTypes} onNodeClick={onNodeClick}
|
|
8
|
+
fitView={fitView} proOptions={{ hideAttribution: true }}
|
|
9
|
+
defaultEdgeOptions={{ type: 'smoothstep', animated: false, style: { stroke: '#475569', strokeWidth: 1.5 } }}
|
|
10
|
+
>
|
|
11
|
+
<Background color="#1e293b" gap={20} />
|
|
12
|
+
<Controls position="bottom-right" />
|
|
13
|
+
<MiniMap nodeColor={(node) => node.data?.color || '#475569'} maskColor="rgba(0, 0, 0, 0.7)" position="bottom-left" />
|
|
14
|
+
</ReactFlow>
|
|
15
|
+
</div>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export default function SearchFilter({ placeholder = 'Search...', filters = [], onSearchChange, onFilterChange }) {
|
|
4
|
+
const [search, setSearch] = useState('');
|
|
5
|
+
function handleSearchChange(e) {
|
|
6
|
+
setSearch(e.target.value);
|
|
7
|
+
onSearchChange?.(e.target.value);
|
|
8
|
+
}
|
|
9
|
+
return (
|
|
10
|
+
<div className="flex items-center gap-3 p-3 bg-gray-900 border-b border-gray-800">
|
|
11
|
+
<input type="text" value={search} onChange={handleSearchChange} placeholder={placeholder}
|
|
12
|
+
className="flex-1 bg-gray-800 border border-gray-700 rounded-md px-3 py-1.5 text-sm text-gray-100 placeholder-gray-500 focus:outline-none focus:border-blue-500" />
|
|
13
|
+
{filters.map(({ name, label, options, value }) => (
|
|
14
|
+
<select key={name} value={value} onChange={(e) => onFilterChange?.(name, e.target.value)}
|
|
15
|
+
className="bg-gray-800 border border-gray-700 rounded-md px-2 py-1.5 text-sm text-gray-300 focus:outline-none focus:border-blue-500">
|
|
16
|
+
<option value="">{label}: All</option>
|
|
17
|
+
{options.map((opt) => (<option key={opt} value={opt}>{opt}</option>))}
|
|
18
|
+
</select>
|
|
19
|
+
))}
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { NavLink } from 'react-router-dom';
|
|
2
|
+
|
|
3
|
+
const NAV_ITEMS = [
|
|
4
|
+
{ to: '/agents', label: 'Agent Map', icon: '🗺️' },
|
|
5
|
+
{ to: '/phases', label: 'Phases', icon: '⚡' },
|
|
6
|
+
{ to: '/hooks', label: 'Hooks', icon: '🔗' },
|
|
7
|
+
{ to: '/skills', label: 'Skills', icon: '🧩' },
|
|
8
|
+
{ to: '/rules', label: 'Rules', icon: '📏' },
|
|
9
|
+
{ to: '/standards', label: 'Standards', icon: '📋' },
|
|
10
|
+
{ to: '/workflows', label: 'Workflows', icon: '🔄' },
|
|
11
|
+
{ to: '/state', label: 'Live State', icon: '📊' },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
export default function Sidebar() {
|
|
15
|
+
return (
|
|
16
|
+
<nav className="w-52 flex-shrink-0 bg-gray-900 border-r border-gray-800 flex flex-col">
|
|
17
|
+
<div className="px-4 py-4 border-b border-gray-800">
|
|
18
|
+
<h1 className="text-sm font-semibold text-gray-300 tracking-wide uppercase">
|
|
19
|
+
morph-spec
|
|
20
|
+
</h1>
|
|
21
|
+
<p className="text-xs text-gray-500 mt-0.5">Dashboard</p>
|
|
22
|
+
</div>
|
|
23
|
+
<ul className="flex-1 py-2">
|
|
24
|
+
{NAV_ITEMS.map(({ to, label, icon }) => (
|
|
25
|
+
<li key={to}>
|
|
26
|
+
<NavLink
|
|
27
|
+
to={to}
|
|
28
|
+
className={({ isActive }) =>
|
|
29
|
+
[
|
|
30
|
+
'flex items-center gap-2.5 px-4 py-2 text-sm transition-colors',
|
|
31
|
+
isActive
|
|
32
|
+
? 'bg-blue-900/40 border-r-2 border-blue-500 text-blue-300'
|
|
33
|
+
: 'text-gray-400 hover:bg-gray-800 hover:text-gray-200',
|
|
34
|
+
].join(' ')
|
|
35
|
+
}
|
|
36
|
+
>
|
|
37
|
+
<span className="text-base leading-none">{icon}</span>
|
|
38
|
+
<span>{label}</span>
|
|
39
|
+
</NavLink>
|
|
40
|
+
</li>
|
|
41
|
+
))}
|
|
42
|
+
</ul>
|
|
43
|
+
</nav>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
export function useDetailPanel() {
|
|
4
|
+
const [panel, setPanel] = useState({ open: false, title: '', content: null });
|
|
5
|
+
|
|
6
|
+
const openPanel = useCallback((title, content) => {
|
|
7
|
+
setPanel({ open: true, title, content });
|
|
8
|
+
}, []);
|
|
9
|
+
|
|
10
|
+
const closePanel = useCallback(() => {
|
|
11
|
+
setPanel((prev) => ({ ...prev, open: false }));
|
|
12
|
+
}, []);
|
|
13
|
+
|
|
14
|
+
return { panel, openPanel, closePanel };
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { StrictMode } from 'react';
|
|
2
|
+
import { createRoot } from 'react-dom/client';
|
|
3
|
+
import { BrowserRouter } from 'react-router-dom';
|
|
4
|
+
import App from './App.jsx';
|
|
5
|
+
import './styles/index.css';
|
|
6
|
+
|
|
7
|
+
createRoot(document.getElementById('root')).render(
|
|
8
|
+
<StrictMode>
|
|
9
|
+
<BrowserRouter>
|
|
10
|
+
<App />
|
|
11
|
+
</BrowserRouter>
|
|
12
|
+
</StrictMode>
|
|
13
|
+
);
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { useState, useMemo, useCallback } from 'react';
|
|
2
|
+
import { Handle, Position } from '@xyflow/react';
|
|
3
|
+
import dagre from '@dagrejs/dagre';
|
|
4
|
+
import morphData from 'virtual:morph-data';
|
|
5
|
+
import FlowGraph from '../components/FlowGraph.jsx';
|
|
6
|
+
import DetailPanel from '../components/DetailPanel.jsx';
|
|
7
|
+
import SearchFilter from '../components/SearchFilter.jsx';
|
|
8
|
+
import { useDetailPanel } from '../hooks/useDetailPanel.js';
|
|
9
|
+
|
|
10
|
+
// Tier color palette: bg color, border color
|
|
11
|
+
const TIER_COLORS = {
|
|
12
|
+
user: { bg: '#78350f', border: '#f59e0b', label: 'User' },
|
|
13
|
+
1: { bg: '#991b1b', border: '#ef4444', label: 'T1' },
|
|
14
|
+
2: { bg: '#9a3412', border: '#f97316', label: 'T2' },
|
|
15
|
+
3: { bg: '#1e40af', border: '#3b82f6', label: 'T3' },
|
|
16
|
+
4: { bg: '#6d28d9', border: '#8b5cf6', label: 'T4' },
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Custom AgentNode component
|
|
20
|
+
function AgentNode({ data }) {
|
|
21
|
+
const colors = data.isUser ? TIER_COLORS.user : (TIER_COLORS[data.tier] || TIER_COLORS[4]);
|
|
22
|
+
return (
|
|
23
|
+
<div
|
|
24
|
+
className="rounded-lg px-3 py-2 min-w-[130px] max-w-[160px] cursor-pointer select-none"
|
|
25
|
+
style={{ background: colors.bg, border: `1.5px solid ${colors.border}`, boxShadow: `0 0 8px ${colors.border}22` }}
|
|
26
|
+
>
|
|
27
|
+
<Handle type="target" position={Position.Top} style={{ background: colors.border, width: 8, height: 8 }} />
|
|
28
|
+
<div className="text-white text-xs font-semibold leading-tight truncate" title={data.label}>
|
|
29
|
+
{data.label}
|
|
30
|
+
</div>
|
|
31
|
+
<div className="text-gray-300 text-[10px] mt-0.5 truncate">
|
|
32
|
+
{data.isUser ? 'Principal' : `${colors.label} · ${data.group || ''}`}
|
|
33
|
+
</div>
|
|
34
|
+
<Handle type="source" position={Position.Bottom} style={{ background: colors.border, width: 8, height: 8 }} />
|
|
35
|
+
</div>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const nodeTypes = { agentNode: AgentNode };
|
|
40
|
+
|
|
41
|
+
// Dagre layout helpers
|
|
42
|
+
function buildLayout(nodes, edges) {
|
|
43
|
+
const g = new dagre.graphlib.Graph();
|
|
44
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
45
|
+
g.setGraph({ rankdir: 'TB', nodesep: 40, ranksep: 60, marginx: 20, marginy: 20 });
|
|
46
|
+
|
|
47
|
+
nodes.forEach((n) => g.setNode(n.id, { width: 160, height: 60 }));
|
|
48
|
+
edges.forEach((e) => g.setEdge(e.source, e.target));
|
|
49
|
+
|
|
50
|
+
dagre.layout(g);
|
|
51
|
+
|
|
52
|
+
return nodes.map((n) => {
|
|
53
|
+
const pos = g.node(n.id);
|
|
54
|
+
return { ...n, position: { x: pos.x - 80, y: pos.y - 30 } };
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// AgentDetail shown inside the panel
|
|
59
|
+
function AgentDetail({ agent }) {
|
|
60
|
+
const [showPrompt, setShowPrompt] = useState(false);
|
|
61
|
+
const tierColors = TIER_COLORS[agent.tier] || TIER_COLORS[4];
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<div className="text-sm text-gray-200 space-y-4">
|
|
65
|
+
{/* Header */}
|
|
66
|
+
<div>
|
|
67
|
+
<div className="flex items-center gap-2 mb-1">
|
|
68
|
+
<span className="px-2 py-0.5 rounded text-xs font-bold" style={{ background: tierColors.bg, color: tierColors.border, border: `1px solid ${tierColors.border}` }}>
|
|
69
|
+
Tier {agent.tier}
|
|
70
|
+
</span>
|
|
71
|
+
<span className="text-gray-400 text-xs">{agent.group}</span>
|
|
72
|
+
</div>
|
|
73
|
+
<p className="text-gray-400 text-xs">ID: <span className="text-gray-300 font-mono">{agent.id}</span></p>
|
|
74
|
+
{agent.reportsTo && (
|
|
75
|
+
<p className="text-gray-400 text-xs mt-0.5">Reports to: <span className="text-blue-300 font-mono">{agent.reportsTo}</span></p>
|
|
76
|
+
)}
|
|
77
|
+
</div>
|
|
78
|
+
|
|
79
|
+
{/* Active Phases */}
|
|
80
|
+
{agent.activePhases?.length > 0 && (
|
|
81
|
+
<div>
|
|
82
|
+
<p className="text-gray-500 text-xs uppercase tracking-wide mb-1.5">Active Phases</p>
|
|
83
|
+
<div className="flex flex-wrap gap-1">
|
|
84
|
+
{agent.activePhases.map((p) => (
|
|
85
|
+
<span key={p} className="px-2 py-0.5 bg-blue-900/50 border border-blue-700 rounded text-xs text-blue-300">{p}</span>
|
|
86
|
+
))}
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
)}
|
|
90
|
+
|
|
91
|
+
{/* Validators */}
|
|
92
|
+
{agent.validators?.length > 0 && (
|
|
93
|
+
<div>
|
|
94
|
+
<p className="text-gray-500 text-xs uppercase tracking-wide mb-1.5">Validators</p>
|
|
95
|
+
<div className="flex flex-wrap gap-1">
|
|
96
|
+
{agent.validators.map((v) => (
|
|
97
|
+
<span key={v} className="px-2 py-0.5 bg-purple-900/50 border border-purple-700 rounded text-xs text-purple-300">{v}</span>
|
|
98
|
+
))}
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
)}
|
|
102
|
+
|
|
103
|
+
{/* Standards */}
|
|
104
|
+
{agent.standards?.length > 0 && (
|
|
105
|
+
<div>
|
|
106
|
+
<p className="text-gray-500 text-xs uppercase tracking-wide mb-1.5">Standards</p>
|
|
107
|
+
<ul className="space-y-1">
|
|
108
|
+
{agent.standards.map((s) => (
|
|
109
|
+
<li key={s.id} className="flex items-center justify-between text-xs">
|
|
110
|
+
<span className="font-mono text-gray-300">{s.id}</span>
|
|
111
|
+
<div className="flex gap-1">
|
|
112
|
+
{s.scope && <span className="px-1.5 py-0.5 bg-gray-800 rounded text-gray-400">{s.scope}</span>}
|
|
113
|
+
{s.priority && <span className="px-1.5 py-0.5 bg-gray-800 rounded text-gray-400">{s.priority}</span>}
|
|
114
|
+
</div>
|
|
115
|
+
</li>
|
|
116
|
+
))}
|
|
117
|
+
</ul>
|
|
118
|
+
</div>
|
|
119
|
+
)}
|
|
120
|
+
|
|
121
|
+
{/* Domains */}
|
|
122
|
+
{agent.domains?.length > 0 && (
|
|
123
|
+
<div>
|
|
124
|
+
<p className="text-gray-500 text-xs uppercase tracking-wide mb-1.5">Domains</p>
|
|
125
|
+
<p className="text-gray-300 text-xs">{agent.domains.join(', ')}</p>
|
|
126
|
+
</div>
|
|
127
|
+
)}
|
|
128
|
+
|
|
129
|
+
{/* Keywords */}
|
|
130
|
+
{agent.keywords?.length > 0 && (
|
|
131
|
+
<div>
|
|
132
|
+
<p className="text-gray-500 text-xs uppercase tracking-wide mb-1.5">Keywords</p>
|
|
133
|
+
<div className="flex flex-wrap gap-1">
|
|
134
|
+
{agent.keywords.map((k) => (
|
|
135
|
+
<span key={k} className="px-1.5 py-0.5 bg-gray-800 border border-gray-700 rounded text-xs text-gray-400">{k}</span>
|
|
136
|
+
))}
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
)}
|
|
140
|
+
|
|
141
|
+
{/* Stacks */}
|
|
142
|
+
{agent.stacks?.length > 0 && (
|
|
143
|
+
<div>
|
|
144
|
+
<p className="text-gray-500 text-xs uppercase tracking-wide mb-1.5">Stacks</p>
|
|
145
|
+
<div className="flex flex-wrap gap-1">
|
|
146
|
+
{agent.stacks.map((s) => (
|
|
147
|
+
<span key={s} className="px-1.5 py-0.5 bg-green-900/50 border border-green-700 rounded text-xs text-green-300">{s}</span>
|
|
148
|
+
))}
|
|
149
|
+
</div>
|
|
150
|
+
</div>
|
|
151
|
+
)}
|
|
152
|
+
|
|
153
|
+
{/* Full Prompt toggle */}
|
|
154
|
+
{agent.prompt && (
|
|
155
|
+
<div>
|
|
156
|
+
<button
|
|
157
|
+
onClick={() => setShowPrompt((v) => !v)}
|
|
158
|
+
className="w-full text-left px-3 py-1.5 bg-gray-800 hover:bg-gray-700 border border-gray-700 rounded text-xs text-gray-300 transition-colors"
|
|
159
|
+
>
|
|
160
|
+
{showPrompt ? 'Hide Full Prompt' : 'Show Full Prompt'}
|
|
161
|
+
</button>
|
|
162
|
+
{showPrompt && (
|
|
163
|
+
<pre className="mt-2 p-3 bg-gray-950 border border-gray-800 rounded text-[10px] text-gray-400 overflow-x-auto whitespace-pre-wrap font-mono leading-relaxed max-h-64 overflow-y-auto">
|
|
164
|
+
{agent.prompt}
|
|
165
|
+
</pre>
|
|
166
|
+
)}
|
|
167
|
+
</div>
|
|
168
|
+
)}
|
|
169
|
+
</div>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export default function AgentMap() {
|
|
174
|
+
const { agents } = morphData;
|
|
175
|
+
const [search, setSearch] = useState('');
|
|
176
|
+
const [tierFilter, setTierFilter] = useState('');
|
|
177
|
+
const [groupFilter, setGroupFilter] = useState('');
|
|
178
|
+
const [phaseFilter, setPhaseFilter] = useState('');
|
|
179
|
+
const [stackFilter, setStackFilter] = useState('');
|
|
180
|
+
const { panel, openPanel, closePanel } = useDetailPanel();
|
|
181
|
+
|
|
182
|
+
// Derive unique groups, tiers, phases, and stacks for filters
|
|
183
|
+
const allGroups = useMemo(() => [...new Set(agents.list.map((a) => a.group).filter(Boolean))].sort(), [agents.list]);
|
|
184
|
+
const allTiers = useMemo(() => [...new Set(agents.list.map((a) => String(a.tier)))].sort(), [agents.list]);
|
|
185
|
+
const allPhases = useMemo(() => {
|
|
186
|
+
const phases = new Set();
|
|
187
|
+
for (const a of agents.list) {
|
|
188
|
+
for (const p of a.activePhases || []) {
|
|
189
|
+
if (p !== '*') phases.add(p);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return [...phases].sort();
|
|
193
|
+
}, [agents.list]);
|
|
194
|
+
const allStacks = useMemo(() => {
|
|
195
|
+
const stacks = new Set();
|
|
196
|
+
for (const a of agents.list) {
|
|
197
|
+
for (const s of a.stacks || []) {
|
|
198
|
+
stacks.add(s);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return [...stacks].sort();
|
|
202
|
+
}, [agents.list]);
|
|
203
|
+
|
|
204
|
+
// Filtered agent ids (for highlight — we always show all nodes but dim non-matching)
|
|
205
|
+
const matchedIds = useMemo(() => {
|
|
206
|
+
const q = search.toLowerCase();
|
|
207
|
+
return new Set(
|
|
208
|
+
agents.list
|
|
209
|
+
.filter((a) => {
|
|
210
|
+
const matchesSearch = !q || a.title.toLowerCase().includes(q) || a.id.toLowerCase().includes(q) || a.keywords?.some((k) => k.toLowerCase().includes(q));
|
|
211
|
+
const matchesTier = !tierFilter || String(a.tier) === tierFilter;
|
|
212
|
+
const matchesGroup = !groupFilter || a.group === groupFilter;
|
|
213
|
+
const matchesPhase = !phaseFilter || (a.activePhases || []).includes('*') || (a.activePhases || []).includes(phaseFilter);
|
|
214
|
+
const matchesStack = !stackFilter || (a.stacks || []).includes(stackFilter);
|
|
215
|
+
return matchesSearch && matchesTier && matchesGroup && matchesPhase && matchesStack;
|
|
216
|
+
})
|
|
217
|
+
.map((a) => a.id)
|
|
218
|
+
);
|
|
219
|
+
}, [agents.list, search, tierFilter, groupFilter, phaseFilter, stackFilter]);
|
|
220
|
+
|
|
221
|
+
const hasFilter = search || tierFilter || groupFilter || phaseFilter || stackFilter;
|
|
222
|
+
|
|
223
|
+
// Build React Flow nodes and edges
|
|
224
|
+
const { nodes: layoutNodes, edges } = useMemo(() => {
|
|
225
|
+
const rawNodes = [];
|
|
226
|
+
const rawEdges = [];
|
|
227
|
+
|
|
228
|
+
// User node at top
|
|
229
|
+
rawNodes.push({
|
|
230
|
+
id: '__user__',
|
|
231
|
+
type: 'agentNode',
|
|
232
|
+
data: { label: 'User', isUser: true, color: '#78350f' },
|
|
233
|
+
position: { x: 0, y: 0 },
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
// Agent nodes
|
|
237
|
+
for (const agent of agents.list) {
|
|
238
|
+
const dimmed = hasFilter && !matchedIds.has(agent.id);
|
|
239
|
+
const tierColors = TIER_COLORS[agent.tier] || TIER_COLORS[4];
|
|
240
|
+
rawNodes.push({
|
|
241
|
+
id: agent.id,
|
|
242
|
+
type: 'agentNode',
|
|
243
|
+
data: {
|
|
244
|
+
label: agent.title,
|
|
245
|
+
tier: agent.tier,
|
|
246
|
+
group: agent.group,
|
|
247
|
+
color: tierColors.border,
|
|
248
|
+
agentRef: agent,
|
|
249
|
+
},
|
|
250
|
+
style: dimmed ? { opacity: 0.2 } : {},
|
|
251
|
+
position: { x: 0, y: 0 },
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// reports_to edges (solid, tier-colored)
|
|
256
|
+
for (const agent of agents.list) {
|
|
257
|
+
const source = agent.reportsTo === 'user' ? '__user__' : agent.reportsTo;
|
|
258
|
+
if (!source) continue;
|
|
259
|
+
const tierColors = TIER_COLORS[agent.tier] || TIER_COLORS[4];
|
|
260
|
+
rawEdges.push({
|
|
261
|
+
id: `rt-${agent.id}`,
|
|
262
|
+
source,
|
|
263
|
+
target: agent.id,
|
|
264
|
+
type: 'smoothstep',
|
|
265
|
+
style: { stroke: tierColors.border, strokeWidth: 1.5 },
|
|
266
|
+
animated: false,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// validators edges (dashed purple) — Tier 4 validator agent → validated agent
|
|
271
|
+
// agent.validators contains runner names like "architecture", "design-system", "nextjs-component"
|
|
272
|
+
// which map to Tier 4 agent IDs like "architecture-expert", "design-system-validator", etc.
|
|
273
|
+
// Match by finding the Tier 4 agent whose ID contains the validator runner name.
|
|
274
|
+
const tier4Agents = agents.list.filter((a) => a.tier === 4);
|
|
275
|
+
for (const agent of agents.list) {
|
|
276
|
+
for (const v of agent.validators || []) {
|
|
277
|
+
const validatorAgent = tier4Agents.find((a) => a.id.includes(v));
|
|
278
|
+
if (validatorAgent) {
|
|
279
|
+
rawEdges.push({
|
|
280
|
+
id: `val-${validatorAgent.id}-${agent.id}`,
|
|
281
|
+
source: validatorAgent.id,
|
|
282
|
+
target: agent.id,
|
|
283
|
+
type: 'smoothstep',
|
|
284
|
+
style: { stroke: '#8b5cf6', strokeWidth: 1, strokeDasharray: '4 3' },
|
|
285
|
+
animated: false,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const layouted = buildLayout(rawNodes, rawEdges);
|
|
292
|
+
return { nodes: layouted, edges: rawEdges };
|
|
293
|
+
}, [agents.list, matchedIds, hasFilter]);
|
|
294
|
+
|
|
295
|
+
const handleNodeClick = useCallback(
|
|
296
|
+
(_event, node) => {
|
|
297
|
+
if (node.id === '__user__') {
|
|
298
|
+
openPanel('User (Principal)', <div className="text-gray-400 text-sm">The human operator. All Tier 1 orchestrators report to this node.</div>);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const agent = node.data.agentRef;
|
|
302
|
+
if (agent) {
|
|
303
|
+
openPanel(agent.title, <AgentDetail agent={agent} />);
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
[openPanel]
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
const filterConfig = [
|
|
310
|
+
{ name: 'tier', label: 'Tier', options: allTiers, value: tierFilter },
|
|
311
|
+
{ name: 'group', label: 'Group', options: allGroups, value: groupFilter },
|
|
312
|
+
{ name: 'phase', label: 'Phase', options: allPhases, value: phaseFilter },
|
|
313
|
+
{ name: 'stack', label: 'Stack', options: allStacks, value: stackFilter },
|
|
314
|
+
];
|
|
315
|
+
|
|
316
|
+
return (
|
|
317
|
+
<div className="flex flex-col h-full">
|
|
318
|
+
<SearchFilter
|
|
319
|
+
placeholder="Search agents by name or keyword..."
|
|
320
|
+
filters={filterConfig}
|
|
321
|
+
onSearchChange={setSearch}
|
|
322
|
+
onFilterChange={(name, value) => {
|
|
323
|
+
if (name === 'tier') setTierFilter(value);
|
|
324
|
+
if (name === 'group') setGroupFilter(value);
|
|
325
|
+
if (name === 'phase') setPhaseFilter(value);
|
|
326
|
+
if (name === 'stack') setStackFilter(value);
|
|
327
|
+
}}
|
|
328
|
+
/>
|
|
329
|
+
|
|
330
|
+
<div className="flex-1 relative">
|
|
331
|
+
<FlowGraph
|
|
332
|
+
nodes={layoutNodes}
|
|
333
|
+
edges={edges}
|
|
334
|
+
nodeTypes={nodeTypes}
|
|
335
|
+
onNodeClick={handleNodeClick}
|
|
336
|
+
fitView
|
|
337
|
+
/>
|
|
338
|
+
|
|
339
|
+
{/* Legend */}
|
|
340
|
+
<div className="absolute top-3 left-3 bg-gray-900/90 border border-gray-700 rounded-lg p-3 text-xs space-y-1.5 z-10">
|
|
341
|
+
<p className="text-gray-400 font-semibold uppercase tracking-wide text-[10px] mb-2">Legend</p>
|
|
342
|
+
{Object.entries(TIER_COLORS).map(([key, c]) => (
|
|
343
|
+
<div key={key} className="flex items-center gap-2">
|
|
344
|
+
<span className="inline-block w-3 h-3 rounded-sm flex-shrink-0" style={{ background: c.bg, border: `1px solid ${c.border}` }} />
|
|
345
|
+
<span className="text-gray-300">{key === 'user' ? 'User' : `Tier ${key} — ${c.label}`}</span>
|
|
346
|
+
</div>
|
|
347
|
+
))}
|
|
348
|
+
<div className="border-t border-gray-700 mt-2 pt-2 space-y-1">
|
|
349
|
+
<div className="flex items-center gap-2">
|
|
350
|
+
<span className="inline-block w-6 border-t-2 border-blue-400" />
|
|
351
|
+
<span className="text-gray-400">reports_to</span>
|
|
352
|
+
</div>
|
|
353
|
+
<div className="flex items-center gap-2">
|
|
354
|
+
<span className="inline-block w-6 border-t-2 border-purple-400 border-dashed" />
|
|
355
|
+
<span className="text-gray-400">validates</span>
|
|
356
|
+
</div>
|
|
357
|
+
</div>
|
|
358
|
+
</div>
|
|
359
|
+
|
|
360
|
+
{/* Agent count badge */}
|
|
361
|
+
<div className="absolute top-3 right-3 bg-gray-900/90 border border-gray-700 rounded-lg px-3 py-1.5 text-xs text-gray-400 z-10">
|
|
362
|
+
{hasFilter ? `${matchedIds.size} / ${agents.list.length}` : agents.list.length} agents
|
|
363
|
+
</div>
|
|
364
|
+
</div>
|
|
365
|
+
|
|
366
|
+
<DetailPanel open={panel.open} title={panel.title} onClose={closePanel}>
|
|
367
|
+
{panel.content}
|
|
368
|
+
</DetailPanel>
|
|
369
|
+
</div>
|
|
370
|
+
);
|
|
371
|
+
}
|