@polymorphism-tech/morph-spec 8.38.0 → 8.40.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.
Files changed (227) hide show
  1. package/CLAUDE.md +19 -8
  2. package/README.md +2 -2
  3. package/bin/morph-spec.js +60 -43
  4. package/claude-plugin.json +1 -1
  5. package/docs/CHEATSHEET.md +1 -1
  6. package/docs/QUICKSTART.md +1 -1
  7. package/framework/CLAUDE.md +3 -2
  8. package/framework/MORPH.md +1 -1
  9. package/framework/agents.json +36 -25
  10. package/framework/docs/CLI.md +2 -2
  11. package/framework/evals/rubrics/code-quality.md +4 -4
  12. package/framework/evals/rubrics/condensed.md +2 -2
  13. package/framework/mcp/registry.json +33 -2
  14. package/framework/rules/infrastructure-standards.md +0 -1
  15. package/framework/rules/morph-workflow.md +9 -4
  16. package/framework/skills/core/create-umbraco-lp/SKILL.md +1 -1
  17. package/framework/skills/core/migrate-lp-to-umbraco/SKILL.md +1 -1
  18. package/framework/skills/core/morph-apply/SKILL.md +5 -1
  19. package/framework/skills/core/morph-brainstorming/SKILL.md +1 -1
  20. package/framework/skills/core/morph-eval/SKILL.md +1 -1
  21. package/framework/skills/core/morph-hotfix/SKILL.md +1 -1
  22. package/framework/skills/core/morph-implement/SKILL.md +6 -1
  23. package/framework/skills/core/morph-media/SKILL.md +1 -1
  24. package/framework/skills/core/morph-plan/SKILL.md +4 -3
  25. package/framework/skills/core/morph-proposal/SKILL.md +1 -1
  26. package/framework/skills/core/morph-review/SKILL.md +1 -1
  27. package/framework/skills/core/morph-stack-scan/SKILL.md +1 -1
  28. package/framework/skills/core/morph-standards/SKILL.md +1 -1
  29. package/framework/skills/core/morph-uiux/SKILL.md +6 -5
  30. package/framework/standards/STANDARDS.json +3 -3
  31. package/framework/standards/ai-agents/context-providers.md +16 -26
  32. package/framework/standards/ai-agents/durable-workflows-hitl.md +15 -21
  33. package/framework/standards/ai-agents/modalities-image-gen.md +21 -25
  34. package/framework/standards/ai-agents/modalities-speech-to-text.md +4 -15
  35. package/framework/standards/ai-agents/modalities-text-to-speech.md +2 -11
  36. package/framework/standards/ai-agents/modalities-vision.md +1 -18
  37. package/framework/standards/ai-agents/prompt-sources.md +0 -4
  38. package/framework/standards/architecture/code-comments.md +52 -16
  39. package/framework/standards/backend/integrations/neon-auth/neon-auth.md +63 -50
  40. package/framework/standards/frontend/design-system/ai-image-generation.md +5 -5
  41. package/framework/standards/integration/mcp/mcp-tools.md +48 -117
  42. package/framework/templates/code/dotnet/abstractions/result.cs +0 -2
  43. package/framework/templates/code/dotnet/ai-agents/AgentBootstrap.cs.template +26 -39
  44. package/framework/templates/code/dotnet/ai-agents/EmbeddingService.cs.template +28 -68
  45. package/framework/templates/code/dotnet/ai-agents/ModelRegistry.cs.template +99 -117
  46. package/framework/templates/code/dotnet/ai-agents/PromptRepository.cs.template +2 -44
  47. package/framework/templates/code/dotnet/ai-agents/ResilientToolMiddleware.cs.template +40 -61
  48. package/framework/templates/code/dotnet/ai-agents/VectorSearchTool.cs.template +54 -107
  49. package/framework/templates/code/dotnet/ai-agents/model-registry.json.template +53 -58
  50. package/framework/templates/code/dotnet/contracts/contracts-vsa.cs +192 -281
  51. package/framework/templates/code/dotnet/database/migration.cs +49 -83
  52. package/framework/templates/code/dotnet/database/vector-entity.cs +2 -46
  53. package/framework/templates/code/dotnet/extensions/result-extensions.cs +0 -2
  54. package/framework/templates/code/dotnet/feature/validator.cs.hbs +11 -15
  55. package/framework/templates/code/dotnet/jobs/agent.cs +3 -51
  56. package/framework/templates/code/dotnet/jobs/job.cs +2 -97
  57. package/framework/templates/code/dotnet/test.cs +2 -87
  58. package/framework/templates/code/typescript/contracts.ts +140 -167
  59. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentApi.cs +1 -48
  60. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentFactory.cs +3 -79
  61. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentFactoryOptions.cs +1 -70
  62. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentSpec.cs +1 -47
  63. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentSpecOptions.cs +2 -99
  64. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/AiKitAssemblyMarker.cs +0 -6
  65. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Conversation/ConversationStore.cs +3 -88
  66. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Conversation/IConversationStore.cs +1 -41
  67. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Conversation/InMemoryConversationStore.cs +0 -21
  68. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/CountingChatClient.cs +1 -25
  69. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalAssertion.cs +2 -63
  70. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalCacheMissException.cs +0 -30
  71. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalCacheOptions.cs +1 -52
  72. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalCacheStamp.cs +3 -78
  73. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalFixture.cs +4 -109
  74. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalMode.cs +0 -22
  75. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalQualityEvaluators.cs +1 -36
  76. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalScenario.cs +2 -57
  77. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalSummary.cs +0 -75
  78. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/OfflineChatClient.cs +2 -59
  79. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/ShortPathResponseCache.cs +4 -111
  80. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/IMediaGenerator.cs +0 -34
  81. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/IMediaProvider.cs +1 -57
  82. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaArtifact.cs +0 -19
  83. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaDisclosure.cs +2 -74
  84. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaGenerator.cs +2 -33
  85. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaIdempotencyKey.cs +1 -43
  86. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaJob.cs +1 -96
  87. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaJobId.cs +0 -13
  88. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaJobState.cs +0 -27
  89. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaPricing.cs +0 -33
  90. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaProvenance.cs +0 -31
  91. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaRequest.cs +3 -75
  92. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaResult.cs +0 -42
  93. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaReview.cs +0 -39
  94. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaSeams.cs +1 -55
  95. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaStore.cs +3 -59
  96. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MorphMedia.cs +0 -46
  97. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/Providers/GoogleImageProvider.cs +3 -28
  98. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/Providers/OpenAIImageProvider.cs +7 -61
  99. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/Providers/VeoVideoProvider.cs +2 -37
  100. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Middleware/IUsageCostSink.cs +1 -23
  101. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Middleware/UsageCostMiddleware.cs +2 -82
  102. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Middleware/UsageCostRecord.cs +1 -68
  103. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Observability/MorphOpenTelemetryExtensions.cs +1 -62
  104. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Observability/MorphTelemetryOptions.cs +2 -62
  105. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Providers/IProviderClientFactory.cs +1 -25
  106. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Providers/ModelAlias.cs +0 -124
  107. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Providers/ModelRegistry.cs +1 -73
  108. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Rag/DeltaIngest.cs +1 -66
  109. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Rag/DeltaPlan.cs +0 -41
  110. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/AgentFactoryTests.cs +2 -112
  111. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/AgentSpecTests.cs +2 -43
  112. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/ConversationStoreTests.cs +5 -110
  113. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/DeltaIngestTests.cs +7 -103
  114. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalAssertionTests.cs +1 -42
  115. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalCacheMissTests.cs +1 -30
  116. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalCacheStampTests.cs +1 -19
  117. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalFailuresTests.cs +0 -48
  118. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalFixtureTests.cs +1 -29
  119. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalRefreshTests.cs +2 -38
  120. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalWorkspace.cs +1 -14
  121. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/KitEvals.cs +4 -69
  122. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/OfflineChatClientTests.cs +1 -10
  123. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeChatClient.cs +1 -57
  124. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeChatClientTests.cs +0 -26
  125. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeClock.cs +1 -19
  126. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeMediaProvider.cs +0 -32
  127. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeProviderClientFactory.cs +0 -14
  128. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeUsageCostSink.cs +0 -24
  129. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/InMemoryMediaStore.cs +0 -32
  130. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaAccessibilityTests.cs +0 -37
  131. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaAliasIsNotAnAgentTests.cs +0 -24
  132. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaDisclosureTests.cs +0 -78
  133. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaGeneratorTests.cs +0 -53
  134. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaIdempotencyKeyTests.cs +0 -44
  135. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaJobStateTests.cs +0 -44
  136. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaReviewTests.cs +0 -19
  137. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaStoreTests.cs +0 -24
  138. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/ModelRegistryTests.cs +6 -48
  139. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/SkeletonSmokeTests.cs +1 -13
  140. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/TelemetryTests.cs +2 -71
  141. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/UsageCostMiddlewareTests.cs +5 -100
  142. package/framework/templates/frontend/nextjs/Dockerfile.nextjs.hbs +39 -43
  143. package/framework/templates/frontend/nextjs/env.mjs.hbs +29 -32
  144. package/framework/templates/frontend/nextjs/page.tsx.hbs +21 -22
  145. package/framework/templates/frontend/nextjs/use-feature.ts.hbs +42 -54
  146. package/framework/templates/integrations/asaas-client.cs +332 -387
  147. package/framework/templates/integrations/asaas-webhook.cs +290 -351
  148. package/framework/templates/integrations/neon-auth-config.cs +9 -105
  149. package/framework/templates/project/validate.js +97 -120
  150. package/package.json +2 -2
  151. package/src/commands/dashboard/dashboard.js +80 -53
  152. package/src/commands/mcp/mcp-setup.js +37 -9
  153. package/src/commands/project/doctor.js +3 -5
  154. package/src/commands/project/init.js +6 -3
  155. package/src/commands/project/install-plugin-cmd.js +1 -1
  156. package/src/commands/project/update.js +5 -0
  157. package/src/dashboard/app/App.jsx +80 -16
  158. package/src/dashboard/app/components/ActivityFeed.jsx +172 -0
  159. package/src/dashboard/app/components/CommandPalette.jsx +155 -0
  160. package/src/dashboard/app/components/DetailPanel.jsx +47 -11
  161. package/src/dashboard/app/components/EntityLink.jsx +55 -0
  162. package/src/dashboard/app/components/ErrorBoundary.jsx +54 -0
  163. package/src/dashboard/app/components/FlowGraph.jsx +19 -17
  164. package/src/dashboard/app/components/KnowledgeMarkdown.jsx +53 -0
  165. package/src/dashboard/app/components/Markdown.jsx +47 -0
  166. package/src/dashboard/app/components/PhaseRail.jsx +111 -0
  167. package/src/dashboard/app/components/SearchFilter.jsx +40 -22
  168. package/src/dashboard/app/components/Sidebar.jsx +146 -37
  169. package/src/dashboard/app/hooks/useMorphQuery.js +54 -0
  170. package/src/dashboard/app/hooks/usePref.js +38 -0
  171. package/src/dashboard/app/lib/format.js +69 -0
  172. package/src/dashboard/app/lib/phases.js +56 -0
  173. package/src/dashboard/app/lib/project.js +50 -0
  174. package/src/dashboard/app/pages/Activity.jsx +24 -0
  175. package/src/dashboard/app/pages/AgentMap.jsx +371 -370
  176. package/src/dashboard/app/pages/FeatureDetail.jsx +604 -0
  177. package/src/dashboard/app/pages/Features.jsx +400 -0
  178. package/src/dashboard/app/pages/Guide.jsx +146 -0
  179. package/src/dashboard/app/pages/HookInspector.jsx +357 -322
  180. package/src/dashboard/app/pages/PhasePipeline.jsx +277 -408
  181. package/src/dashboard/app/pages/Portfolio.jsx +156 -0
  182. package/src/dashboard/app/pages/Rubrics.jsx +101 -0
  183. package/src/dashboard/app/pages/RulesMap.jsx +300 -273
  184. package/src/dashboard/app/pages/SkillsLibrary.jsx +483 -366
  185. package/src/dashboard/app/pages/Standards.jsx +407 -332
  186. package/src/dashboard/app/styles/index.css +187 -47
  187. package/src/dashboard/index.html +14 -12
  188. package/src/dashboard/package.json +32 -24
  189. package/src/dashboard/scanner/activity-scanner.js +351 -0
  190. package/src/dashboard/scanner/agents-scanner.js +59 -1
  191. package/src/dashboard/scanner/docs-scanner.js +59 -0
  192. package/src/dashboard/scanner/feature-status.js +10 -0
  193. package/src/dashboard/scanner/features-scanner.js +360 -0
  194. package/src/dashboard/scanner/index.js +14 -7
  195. package/src/dashboard/scanner/phases-scanner.js +14 -15
  196. package/src/dashboard/scanner/portfolio.js +153 -0
  197. package/src/dashboard/scanner/project-api.js +195 -0
  198. package/src/dashboard/scanner/rules-scanner.js +42 -37
  199. package/src/dashboard/scanner/skills-scanner.js +105 -43
  200. package/src/dashboard/scanner/standards-scanner.js +2 -0
  201. package/src/dashboard/vite-plugin-morph-data.js +134 -17
  202. package/src/lib/detectors/claude-config-detector.js +2 -7
  203. package/src/lib/detectors/index.js +5 -1
  204. package/src/lib/evaluator-report.js +22 -0
  205. package/src/lib/generators/settings-generator.js +208 -209
  206. package/src/lib/installers/mcp-installer.js +724 -719
  207. package/src/lib/installers/memory-installer.js +1 -2
  208. package/src/lib/projects/registry.js +154 -0
  209. package/src/lib/validators/code-budget/code-budget-validator.js +32 -4
  210. package/src/scripts/install-plugin.js +1 -1
  211. package/src/scripts/setup-infra.js +2 -4
  212. package/src/utils/agents-installer.js +57 -12
  213. package/src/utils/banner.js +1 -1
  214. package/src/commands/index.js +0 -13
  215. package/src/commands/project/checkpoint.js +0 -209
  216. package/src/core/state/phase-state-machine.js +0 -197
  217. package/src/dashboard/app/hooks/useDetailPanel.js +0 -15
  218. package/src/dashboard/app/pages/LiveState.jsx +0 -206
  219. package/src/dashboard/scanner/squads-scanner.js +0 -13
  220. package/src/dashboard/scanner/state-scanner.js +0 -85
  221. package/src/lib/generators/index.js +0 -10
  222. package/src/lib/hooks/hook-executor.js +0 -167
  223. package/src/lib/validators/checkpoint-persistence.js +0 -39
  224. package/src/lib/validators/shared/emit-validator-dispatch.js +0 -14
  225. package/src/lib/validators/shared/index.js +0 -12
  226. package/src/lib/validators/shared/issue-counter.js +0 -14
  227. package/src/lib/validators/shared/result-formatter.js +0 -124
@@ -1,370 +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
- // Domain persona color palette (v5 — flat, no tiers)
11
- const PERSONA_COLORS = {
12
- user: { bg: '#78350f', border: '#f59e0b', label: 'User' },
13
- 'dotnet-senior':{ bg: '#991b1b', border: '#ef4444', label: 'Backend' },
14
- 'ef-modeler': { bg: '#7c2d12', border: '#fb923c', label: 'Data' },
15
- 'maf-expert': { bg: '#1e3a5f', border: '#38bdf8', label: 'Agents' },
16
- 'nextjs-expert':{ bg: '#064e3b', border: '#34d399', label: 'Frontend' },
17
- 'ui-designer': { bg: '#4a1d96', border: '#a78bfa', label: 'Design' },
18
- 'infra-engineer':{ bg: '#1e3a5f', border: '#60a5fa', label: 'Infra' },
19
- 'evaluator': { bg: '#374151', border: '#9ca3af', label: 'Eval' },
20
- };
21
- const FALLBACK_PERSONA = { bg: '#1e40af', border: '#3b82f6', label: 'Persona' };
22
-
23
- // Custom AgentNode component
24
- function AgentNode({ data }) {
25
- const colors = data.isUser ? PERSONA_COLORS.user : (PERSONA_COLORS[data.personaId] || FALLBACK_PERSONA);
26
- return (
27
- <div
28
- className="rounded-lg px-3 py-2 min-w-[130px] max-w-[160px] cursor-pointer select-none"
29
- style={{ background: colors.bg, border: `1.5px solid ${colors.border}`, boxShadow: `0 0 8px ${colors.border}22` }}
30
- >
31
- <Handle type="target" position={Position.Top} style={{ background: colors.border, width: 8, height: 8 }} />
32
- <div className="text-white text-xs font-semibold leading-tight truncate" title={data.label}>
33
- {data.label}
34
- </div>
35
- <div className="text-gray-300 text-[10px] mt-0.5 truncate">
36
- {data.isUser ? 'Principal' : `${colors.label} · ${data.domains?.[0] || ''}`}
37
- </div>
38
- <Handle type="source" position={Position.Bottom} style={{ background: colors.border, width: 8, height: 8 }} />
39
- </div>
40
- );
41
- }
42
-
43
- const nodeTypes = { agentNode: AgentNode };
44
-
45
- // Dagre layout helpers
46
- function buildLayout(nodes, edges) {
47
- const g = new dagre.graphlib.Graph();
48
- g.setDefaultEdgeLabel(() => ({}));
49
- g.setGraph({ rankdir: 'TB', nodesep: 40, ranksep: 60, marginx: 20, marginy: 20 });
50
-
51
- nodes.forEach((n) => g.setNode(n.id, { width: 160, height: 60 }));
52
- edges.forEach((e) => g.setEdge(e.source, e.target));
53
-
54
- dagre.layout(g);
55
-
56
- return nodes.map((n) => {
57
- const pos = g.node(n.id);
58
- return { ...n, position: { x: pos.x - 80, y: pos.y - 30 } };
59
- });
60
- }
61
-
62
- // AgentDetail shown inside the panel
63
- function AgentDetail({ agent }) {
64
- const [showPrompt, setShowPrompt] = useState(false);
65
- const personaColors = PERSONA_COLORS[agent.id] || FALLBACK_PERSONA;
66
-
67
- return (
68
- <div className="text-sm text-gray-200 space-y-4">
69
- {/* Header */}
70
- <div>
71
- <div className="flex items-center gap-2 mb-1">
72
- <span className="px-2 py-0.5 rounded text-xs font-bold" style={{ background: personaColors.bg, color: personaColors.border, border: `1px solid ${personaColors.border}` }}>
73
- {personaColors.label}
74
- </span>
75
- <span className="text-gray-400 text-xs">{agent.domains?.[0] || ''}</span>
76
- </div>
77
- <p className="text-gray-400 text-xs">ID: <span className="text-gray-300 font-mono">{agent.id}</span></p>
78
- </div>
79
-
80
- {/* Active Phases */}
81
- {agent.activePhases?.length > 0 && (
82
- <div>
83
- <p className="text-gray-500 text-xs uppercase tracking-wide mb-1.5">Active Phases</p>
84
- <div className="flex flex-wrap gap-1">
85
- {agent.activePhases.map((p) => (
86
- <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>
87
- ))}
88
- </div>
89
- </div>
90
- )}
91
-
92
- {/* Validators */}
93
- {agent.validators?.length > 0 && (
94
- <div>
95
- <p className="text-gray-500 text-xs uppercase tracking-wide mb-1.5">Validators</p>
96
- <div className="flex flex-wrap gap-1">
97
- {agent.validators.map((v) => (
98
- <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>
99
- ))}
100
- </div>
101
- </div>
102
- )}
103
-
104
- {/* Standards */}
105
- {agent.standards?.length > 0 && (
106
- <div>
107
- <p className="text-gray-500 text-xs uppercase tracking-wide mb-1.5">Standards</p>
108
- <ul className="space-y-1">
109
- {agent.standards.map((s) => (
110
- <li key={s.id} className="flex items-center justify-between text-xs">
111
- <span className="font-mono text-gray-300">{s.id}</span>
112
- <div className="flex gap-1">
113
- {s.scope && <span className="px-1.5 py-0.5 bg-gray-800 rounded text-gray-400">{s.scope}</span>}
114
- {s.priority && <span className="px-1.5 py-0.5 bg-gray-800 rounded text-gray-400">{s.priority}</span>}
115
- </div>
116
- </li>
117
- ))}
118
- </ul>
119
- </div>
120
- )}
121
-
122
- {/* Domains */}
123
- {agent.domains?.length > 0 && (
124
- <div>
125
- <p className="text-gray-500 text-xs uppercase tracking-wide mb-1.5">Domains</p>
126
- <p className="text-gray-300 text-xs">{agent.domains.join(', ')}</p>
127
- </div>
128
- )}
129
-
130
- {/* Keywords */}
131
- {agent.keywords?.length > 0 && (
132
- <div>
133
- <p className="text-gray-500 text-xs uppercase tracking-wide mb-1.5">Keywords</p>
134
- <div className="flex flex-wrap gap-1">
135
- {agent.keywords.map((k) => (
136
- <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>
137
- ))}
138
- </div>
139
- </div>
140
- )}
141
-
142
- {/* Stacks */}
143
- {agent.stacks?.length > 0 && (
144
- <div>
145
- <p className="text-gray-500 text-xs uppercase tracking-wide mb-1.5">Stacks</p>
146
- <div className="flex flex-wrap gap-1">
147
- {agent.stacks.map((s) => (
148
- <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>
149
- ))}
150
- </div>
151
- </div>
152
- )}
153
-
154
- {/* Full Prompt toggle */}
155
- {agent.prompt && (
156
- <div>
157
- <button
158
- onClick={() => setShowPrompt((v) => !v)}
159
- 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"
160
- >
161
- {showPrompt ? 'Hide Full Prompt' : 'Show Full Prompt'}
162
- </button>
163
- {showPrompt && (
164
- <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">
165
- {agent.prompt}
166
- </pre>
167
- )}
168
- </div>
169
- )}
170
- </div>
171
- );
172
- }
173
-
174
- export default function AgentMap() {
175
- const { agents } = morphData;
176
- const [search, setSearch] = useState('');
177
- const [domainFilter, setDomainFilter] = useState('');
178
- const [groupFilter, setGroupFilter] = useState('');
179
- const [phaseFilter, setPhaseFilter] = useState('');
180
- const [stackFilter, setStackFilter] = useState('');
181
- const { panel, openPanel, closePanel } = useDetailPanel();
182
-
183
- // Derive unique groups, tiers, phases, and stacks for filters
184
- const allGroups = useMemo(() => [...new Set(agents.list.map((a) => a.domains?.[0]).filter(Boolean))].sort(), [agents.list]);
185
- const allDomains = useMemo(() => [...new Set(agents.list.flatMap((a) => a.domains || []))].sort(), [agents.list]);
186
- const allPhases = useMemo(() => {
187
- const phases = new Set();
188
- for (const a of agents.list) {
189
- for (const p of a.activePhases || []) {
190
- if (p !== '*') phases.add(p);
191
- }
192
- }
193
- return [...phases].sort();
194
- }, [agents.list]);
195
- const allStacks = useMemo(() => {
196
- const stacks = new Set();
197
- for (const a of agents.list) {
198
- for (const s of a.stacks || []) {
199
- stacks.add(s);
200
- }
201
- }
202
- return [...stacks].sort();
203
- }, [agents.list]);
204
-
205
- // Filtered agent ids (for highlight — we always show all nodes but dim non-matching)
206
- const matchedIds = useMemo(() => {
207
- const q = search.toLowerCase();
208
- return new Set(
209
- agents.list
210
- .filter((a) => {
211
- const matchesSearch = !q || a.title.toLowerCase().includes(q) || a.id.toLowerCase().includes(q) || a.keywords?.some((k) => k.toLowerCase().includes(q));
212
- const matchesDomain = !domainFilter || (a.domains || []).includes(domainFilter);
213
- const matchesGroup = !groupFilter || (a.domains || []).includes(groupFilter);
214
- const matchesPhase = !phaseFilter || (a.activePhases || []).includes('*') || (a.activePhases || []).includes(phaseFilter);
215
- const matchesStack = !stackFilter || (a.stacks || []).includes(stackFilter);
216
- return matchesSearch && matchesDomain && matchesGroup && matchesPhase && matchesStack;
217
- })
218
- .map((a) => a.id)
219
- );
220
- }, [agents.list, search, tierFilter, groupFilter, phaseFilter, stackFilter]);
221
-
222
- const hasFilter = search || domainFilter || groupFilter || phaseFilter || stackFilter;
223
-
224
- // Build React Flow nodes and edges
225
- const { nodes: layoutNodes, edges } = useMemo(() => {
226
- const rawNodes = [];
227
- const rawEdges = [];
228
-
229
- // User node at top
230
- rawNodes.push({
231
- id: '__user__',
232
- type: 'agentNode',
233
- data: { label: 'User', isUser: true, color: '#78350f' },
234
- position: { x: 0, y: 0 },
235
- });
236
-
237
- // Agent nodes
238
- for (const agent of agents.list) {
239
- const dimmed = hasFilter && !matchedIds.has(agent.id);
240
- const personaColors = PERSONA_COLORS[agent.id] || FALLBACK_PERSONA;
241
- rawNodes.push({
242
- id: agent.id,
243
- type: 'agentNode',
244
- data: {
245
- label: agent.title,
246
- personaId: agent.id,
247
- domains: agent.domains,
248
- color: personaColors.border,
249
- agentRef: agent,
250
- },
251
- style: dimmed ? { opacity: 0.2 } : {},
252
- position: { x: 0, y: 0 },
253
- });
254
- }
255
-
256
- // user → agent edges (flat — no hierarchy in v5)
257
- for (const agent of agents.list) {
258
- const personaColors = PERSONA_COLORS[agent.id] || FALLBACK_PERSONA;
259
- rawEdges.push({
260
- id: `rt-${agent.id}`,
261
- source: '__user__',
262
- target: agent.id,
263
- type: 'smoothstep',
264
- style: { stroke: personaColors.border, strokeWidth: 1.5 },
265
- animated: false,
266
- });
267
- }
268
-
269
- // validators edges (dashed purple) — Tier 4 validator agent → validated agent
270
- // agent.validators contains runner names like "architecture", "design-system", "nextjs-component"
271
- // which map to Tier 4 agent IDs like "architecture-expert", "design-system-validator", etc.
272
- // Match by finding the Tier 4 agent whose ID contains the validator runner name.
273
- const tier4Agents = agents.list.filter((a) => a.tier === 4);
274
- for (const agent of agents.list) {
275
- for (const v of agent.validators || []) {
276
- const validatorAgent = tier4Agents.find((a) => a.id.includes(v));
277
- if (validatorAgent) {
278
- rawEdges.push({
279
- id: `val-${validatorAgent.id}-${agent.id}`,
280
- source: validatorAgent.id,
281
- target: agent.id,
282
- type: 'smoothstep',
283
- style: { stroke: '#8b5cf6', strokeWidth: 1, strokeDasharray: '4 3' },
284
- animated: false,
285
- });
286
- }
287
- }
288
- }
289
-
290
- const layouted = buildLayout(rawNodes, rawEdges);
291
- return { nodes: layouted, edges: rawEdges };
292
- }, [agents.list, matchedIds, hasFilter]);
293
-
294
- const handleNodeClick = useCallback(
295
- (_event, node) => {
296
- if (node.id === '__user__') {
297
- openPanel('User (Principal)', <div className="text-gray-400 text-sm">The human operator. All Tier 1 orchestrators report to this node.</div>);
298
- return;
299
- }
300
- const agent = node.data.agentRef;
301
- if (agent) {
302
- openPanel(agent.title, <AgentDetail agent={agent} />);
303
- }
304
- },
305
- [openPanel]
306
- );
307
-
308
- const filterConfig = [
309
- { name: 'tier', label: 'Tier', options: allTiers, value: tierFilter },
310
- { name: 'group', label: 'Group', options: allGroups, value: groupFilter },
311
- { name: 'phase', label: 'Phase', options: allPhases, value: phaseFilter },
312
- { name: 'stack', label: 'Stack', options: allStacks, value: stackFilter },
313
- ];
314
-
315
- return (
316
- <div className="flex flex-col h-full">
317
- <SearchFilter
318
- placeholder="Search agents by name or keyword..."
319
- filters={filterConfig}
320
- onSearchChange={setSearch}
321
- onFilterChange={(name, value) => {
322
- if (name === 'tier') setTierFilter(value);
323
- if (name === 'group') setGroupFilter(value);
324
- if (name === 'phase') setPhaseFilter(value);
325
- if (name === 'stack') setStackFilter(value);
326
- }}
327
- />
328
-
329
- <div className="flex-1 relative">
330
- <FlowGraph
331
- nodes={layoutNodes}
332
- edges={edges}
333
- nodeTypes={nodeTypes}
334
- onNodeClick={handleNodeClick}
335
- fitView
336
- />
337
-
338
- {/* Legend */}
339
- <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">
340
- <p className="text-gray-400 font-semibold uppercase tracking-wide text-[10px] mb-2">Legend</p>
341
- {Object.entries(TIER_COLORS).map(([key, c]) => (
342
- <div key={key} className="flex items-center gap-2">
343
- <span className="inline-block w-3 h-3 rounded-sm flex-shrink-0" style={{ background: c.bg, border: `1px solid ${c.border}` }} />
344
- <span className="text-gray-300">{key === 'user' ? 'User' : `Tier ${key} — ${c.label}`}</span>
345
- </div>
346
- ))}
347
- <div className="border-t border-gray-700 mt-2 pt-2 space-y-1">
348
- <div className="flex items-center gap-2">
349
- <span className="inline-block w-6 border-t-2 border-blue-400" />
350
- <span className="text-gray-400">reports_to</span>
351
- </div>
352
- <div className="flex items-center gap-2">
353
- <span className="inline-block w-6 border-t-2 border-purple-400 border-dashed" />
354
- <span className="text-gray-400">validates</span>
355
- </div>
356
- </div>
357
- </div>
358
-
359
- {/* Agent count badge */}
360
- <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">
361
- {hasFilter ? `${matchedIds.size} / ${agents.list.length}` : agents.list.length} agents
362
- </div>
363
- </div>
364
-
365
- <DetailPanel open={panel.open} title={panel.title} onClose={closePanel}>
366
- {panel.content}
367
- </DetailPanel>
368
- </div>
369
- );
370
- }
1
+ import { useState, useMemo, useCallback } from 'react';
2
+ import { Handle, Position } from '@xyflow/react';
3
+ import dagre from '@dagrejs/dagre';
4
+ import { UserCircle, Robot } from '@phosphor-icons/react';
5
+ import morphData from 'virtual:morph-data';
6
+ import FlowGraph from '../components/FlowGraph.jsx';
7
+ import DetailPanel from '../components/DetailPanel.jsx';
8
+ import SearchFilter from '../components/SearchFilter.jsx';
9
+ import Markdown from '../components/Markdown.jsx';
10
+ import EntityLink, { useSelection } from '../components/EntityLink.jsx';
11
+ import { phaseMeta } from '../lib/phases.js';
12
+
13
+ /**
14
+ * `agents.json → color` is a color NAME (blue, cyan…), the one Claude Code
15
+ * paints the sub-agent with. The map reads the same name, so a persona looks
16
+ * the same here and in the terminal.
17
+ */
18
+ const COLOR_HEX = {
19
+ blue: '#60a5fa',
20
+ cyan: '#22d3ee',
21
+ purple: '#a78bfa',
22
+ green: '#34d399',
23
+ magenta: '#f472b6',
24
+ yellow: '#fbbf24',
25
+ red: '#f87171',
26
+ gray: '#9ca3af',
27
+ orange: '#fb923c',
28
+ pink: '#f472b6',
29
+ };
30
+ const FALLBACK_HEX = '#9ca3af';
31
+
32
+ /** The ONE color lookup: nodes, edges, detail badge and legend all read it. */
33
+ const personaColor = (agent) => COLOR_HEX[agent?.color] || FALLBACK_HEX;
34
+
35
+ /** `'*'` in a persona's `stack` means "every stack" — it is not a stack of its own. */
36
+ const UNIVERSAL_STACK = '*';
37
+
38
+ /** The node of the human + main thread. Never a persona id. */
39
+ const PRINCIPAL_ID = 'principal';
40
+
41
+ const NODE_W = 220;
42
+ const NODE_H = 64;
43
+
44
+ function AgentNode({ data }) {
45
+ const color = data.color;
46
+ const Icon = data.isUser ? UserCircle : Robot;
47
+ return (
48
+ <div
49
+ className="fluid flex cursor-pointer select-none items-start gap-2.5 rounded-xl bg-[var(--color-raised)] px-3.5 py-2.5 transition-shadow hover:shadow-[0_0_0_1px_var(--color-hair-strong)]"
50
+ style={{
51
+ width: NODE_W,
52
+ boxShadow: data.selected ? `0 0 0 2px ${color}` : `inset 0 0 0 1px var(--color-hair)`,
53
+ borderLeft: `3px solid ${color}`,
54
+ }}
55
+ >
56
+ <Handle type="target" position={Position.Top} style={{ background: color, width: 7, height: 7, border: 0 }} />
57
+ <Icon weight="light" size={18} className="mt-0.5 shrink-0" style={{ color }} />
58
+ <div className="min-w-0">
59
+ <div className="text-[13px] font-semibold leading-snug text-[var(--color-fg)]" title={data.label}>
60
+ {data.label}
61
+ </div>
62
+ <div className="mt-0.5 truncate text-[12px] text-[var(--color-dim)]">{data.sub}</div>
63
+ </div>
64
+ <Handle type="source" position={Position.Bottom} style={{ background: color, width: 7, height: 7, border: 0 }} />
65
+ </div>
66
+ );
67
+ }
68
+
69
+ const nodeTypes = { agentNode: AgentNode };
70
+
71
+ function buildLayout(nodes, edges) {
72
+ const g = new dagre.graphlib.Graph();
73
+ g.setDefaultEdgeLabel(() => ({}));
74
+ g.setGraph({ rankdir: 'TB', nodesep: 28, ranksep: 80, marginx: 20, marginy: 20 });
75
+ nodes.forEach((n) => g.setNode(n.id, { width: NODE_W, height: NODE_H }));
76
+ edges.forEach((e) => g.setEdge(e.source, e.target));
77
+ dagre.layout(g);
78
+ return nodes.map((n) => {
79
+ const pos = g.node(n.id);
80
+ return { ...n, position: { x: pos.x - NODE_W / 2, y: pos.y - NODE_H / 2 } };
81
+ });
82
+ }
83
+
84
+ /** Skills whose dispatch lines name this persona, or dispatch any implementer. */
85
+ function dispatchingSkills(agent) {
86
+ const implementer = (agent.activePhases || []).includes('implement');
87
+ return (morphData.skills || []).filter((s) => (s.dispatches || []).some(
88
+ (d) => (d.personas || []).includes(agent.id) || (d.generic && implementer),
89
+ ));
90
+ }
91
+
92
+ function toolsText(tools) {
93
+ if (!tools || (Array.isArray(tools) && tools.length === 0)) return 'todas as da sessão (herda)';
94
+ return Array.isArray(tools) ? tools.join(', ') : String(tools);
95
+ }
96
+
97
+ function Section({ title, children }) {
98
+ return (
99
+ <section>
100
+ <h3 className="mb-2 text-xs font-medium text-[var(--color-faint)]">{title}</h3>
101
+ {children}
102
+ </section>
103
+ );
104
+ }
105
+
106
+ function Chip({ children, mono = false }) {
107
+ return (
108
+ <span className={`inline-flex items-center rounded-full px-2 py-0.5 text-[12px] text-[var(--color-dim)] shadow-[inset_0_0_0_1px_var(--color-hair)] ${mono ? 'font-mono' : ''}`}>
109
+ {children}
110
+ </span>
111
+ );
112
+ }
113
+
114
+ // Exported for the render smoke test: no page state, only the persona.
115
+ export function AgentDetail({ agent }) {
116
+ const [tab, setTab] = useState('persona');
117
+ const color = personaColor(agent);
118
+ const stack = agent.stack || [];
119
+ const universal = stack.includes(UNIVERSAL_STACK);
120
+ const skills = dispatchingSkills(agent);
121
+ const standardName = (id) => (morphData.standards?.list || []).find((s) => s.id === id)?.name;
122
+
123
+ const facts = [
124
+ ['Modelo', agent.model || 'herda da sessão'],
125
+ ['Limite de turnos', agent.maxTurns != null ? String(agent.maxTurns) : 'sem limite declarado'],
126
+ ['Ferramentas', toolsText(agent.tools)],
127
+ ['Stack', universal ? 'universal (todas as stacks)' : (stack.join(', ') || '—')],
128
+ ];
129
+
130
+ return (
131
+ <div className="space-y-6 text-sm text-[var(--color-fg)]">
132
+ <div className="flex flex-wrap items-center gap-2">
133
+ <span className="inline-block h-2.5 w-2.5 rounded-full" style={{ background: color }} />
134
+ <span className="font-mono text-[12px] text-[var(--color-dim)]">morph-{agent.id}</span>
135
+ {(agent.domains || []).map((d) => <Chip key={d}>{d}</Chip>)}
136
+ </div>
137
+
138
+ <dl className="grid grid-cols-[max-content_1fr] gap-x-4 gap-y-1.5 rounded-xl bg-white/[0.03] px-4 py-3 shadow-[inset_0_0_0_1px_var(--color-hair)]">
139
+ {facts.map(([k, v]) => (
140
+ <div key={k} className="contents">
141
+ <dt className="text-xs leading-6 text-[var(--color-faint)]">{k}</dt>
142
+ <dd className="leading-6 text-[var(--color-dim)]">{v}</dd>
143
+ </div>
144
+ ))}
145
+ </dl>
146
+
147
+ <Section title="Fases em que trabalha">
148
+ {agent.activePhases?.length > 0 ? (
149
+ <div className="flex flex-wrap gap-2">
150
+ {agent.activePhases.map((p) => (
151
+ <EntityLink key={p} kind="phase" id={p} chip>{phaseMeta(p).label}</EntityLink>
152
+ ))}
153
+ </div>
154
+ ) : (
155
+ <p className="text-[var(--color-dim)]">Nenhuma skill de fase despacha esta persona.</p>
156
+ )}
157
+ </Section>
158
+
159
+ <Section title="Despachada por">
160
+ {skills.length > 0 ? (
161
+ <div className="flex flex-wrap gap-2">
162
+ {skills.map((s) => <EntityLink key={s.id} kind="skill" id={s.id} chip>{s.id}</EntityLink>)}
163
+ </div>
164
+ ) : (
165
+ <p className="text-[var(--color-dim)]">Nenhuma skill a despacha pelo nome.</p>
166
+ )}
167
+ </Section>
168
+
169
+ {agent.mcp?.length > 0 && (
170
+ <Section title="Servidores MCP">
171
+ <div className="flex flex-wrap gap-2">
172
+ {agent.mcp.map((m) => <Chip key={String(m)} mono>{String(m)}</Chip>)}
173
+ </div>
174
+ </Section>
175
+ )}
176
+
177
+ {agent.standards?.length > 0 && (
178
+ <Section title={`Standards que segue (${agent.standards.length})`}>
179
+ <div className="flex flex-wrap gap-2">
180
+ {agent.standards.map((id) => (
181
+ <EntityLink key={id} kind="standard" id={id} chip title={standardName(id)}>{id}</EntityLink>
182
+ ))}
183
+ </div>
184
+ </Section>
185
+ )}
186
+
187
+ {agent.keywords?.length > 0 && (
188
+ <Section title="Palavras-chave">
189
+ <div className="flex flex-wrap gap-1.5">
190
+ {agent.keywords.map((k) => <Chip key={k}>{k}</Chip>)}
191
+ </div>
192
+ </Section>
193
+ )}
194
+
195
+ <section>
196
+ <div role="tablist" className="mb-3 inline-flex rounded-full bg-white/[0.04] p-1 shadow-[inset_0_0_0_1px_var(--color-hair)]">
197
+ {[['persona', 'Persona'], ['prompt', 'Prompt gerado']].map(([id, label]) => (
198
+ <button
199
+ key={id}
200
+ type="button"
201
+ role="tab"
202
+ aria-selected={tab === id}
203
+ onClick={() => setTab(id)}
204
+ className={`fluid rounded-full px-3 py-1 text-[13px] transition-colors ${tab === id ? 'bg-white/[0.1] text-[var(--color-fg)]' : 'text-[var(--color-dim)] hover:text-[var(--color-fg)]'}`}
205
+ >
206
+ {label}
207
+ </button>
208
+ ))}
209
+ </div>
210
+ {tab === 'persona' ? (
211
+ agent.persona
212
+ ? <Markdown text={agent.persona} size="sm" />
213
+ : <p className="text-[var(--color-dim)]">Esta persona não tem texto de persona.</p>
214
+ ) : (
215
+ <>
216
+ <p className="mb-3 text-[13px] text-[var(--color-dim)]">
217
+ É o arquivo <code className="font-mono">.claude/agents/morph-{agent.id}.md</code> exatamente como o sub-agent o recebe.
218
+ </p>
219
+ {agent.prompt
220
+ ? <Markdown text={agent.prompt} size="sm" />
221
+ : <p className="text-[var(--color-dim)]">O prompt não foi gerado.</p>}
222
+ </>
223
+ )}
224
+ </section>
225
+ </div>
226
+ );
227
+ }
228
+
229
+ function PrincipalDetail() {
230
+ return (
231
+ <div className="space-y-3 text-sm text-[var(--color-dim)]">
232
+ <p>
233
+ Você conversa com a thread principal do Claude Code, que faz o papel de orquestrador. É ela que
234
+ despacha cada persona como sub-agent, com o prompt gerado de cada uma.
235
+ </p>
236
+ <p>As personas são planas: nenhuma manda na outra, e todas respondem à thread principal.</p>
237
+ </div>
238
+ );
239
+ }
240
+
241
+ export default function AgentMap() {
242
+ const { agents } = morphData;
243
+ const [search, setSearch] = useState('');
244
+ const [domainFilter, setDomainFilter] = useState('');
245
+ const [phaseFilter, setPhaseFilter] = useState('');
246
+ const [stackFilter, setStackFilter] = useState('');
247
+ const [sel, setSel] = useSelection();
248
+
249
+ const allDomains = useMemo(() => [...new Set(agents.list.flatMap((a) => a.domains || []))].sort(), [agents.list]);
250
+ const allPhases = useMemo(() => {
251
+ const phases = new Set(agents.list.flatMap((a) => a.activePhases || []));
252
+ // Pipeline order, not alphabetical.
253
+ return morphData.phases.list.map((p) => p.id).filter((id) => phases.has(id));
254
+ }, [agents.list]);
255
+ const allStacks = useMemo(() => {
256
+ const stacks = new Set(agents.list.flatMap((a) => a.stack || []));
257
+ stacks.delete(UNIVERSAL_STACK);
258
+ return [...stacks].sort();
259
+ }, [agents.list]);
260
+
261
+ const matchedIds = useMemo(() => {
262
+ const q = search.toLowerCase();
263
+ return new Set(agents.list.filter((a) => {
264
+ const matchesSearch = !q || a.title.toLowerCase().includes(q) || a.id.toLowerCase().includes(q) || a.keywords?.some((k) => k.toLowerCase().includes(q));
265
+ const matchesDomain = !domainFilter || (a.domains || []).includes(domainFilter);
266
+ const matchesPhase = !phaseFilter || (a.activePhases || []).includes(phaseFilter);
267
+ const matchesStack = !stackFilter || (a.stack || []).includes(UNIVERSAL_STACK) || (a.stack || []).includes(stackFilter);
268
+ return matchesSearch && matchesDomain && matchesPhase && matchesStack;
269
+ }).map((a) => a.id));
270
+ }, [agents.list, search, domainFilter, phaseFilter, stackFilter]);
271
+
272
+ const hasFilter = Boolean(search || domainFilter || phaseFilter || stackFilter);
273
+
274
+ const { nodes, edges } = useMemo(() => {
275
+ const rawNodes = [{
276
+ id: PRINCIPAL_ID,
277
+ type: 'agentNode',
278
+ data: { label: 'Você e a thread principal', sub: 'orquestra e despacha', isUser: true, color: 'var(--color-phase-proposal)', selected: sel === PRINCIPAL_ID },
279
+ position: { x: 0, y: 0 },
280
+ }];
281
+ const rawEdges = [];
282
+ for (const agent of agents.list) {
283
+ const dimmed = hasFilter && !matchedIds.has(agent.id);
284
+ const color = personaColor(agent);
285
+ rawNodes.push({
286
+ id: agent.id,
287
+ type: 'agentNode',
288
+ data: {
289
+ label: agent.title,
290
+ sub: [agent.domains?.[0], agent.model].filter(Boolean).join(' · '),
291
+ color,
292
+ selected: sel === agent.id,
293
+ },
294
+ style: dimmed ? { opacity: 0.25 } : {},
295
+ position: { x: 0, y: 0 },
296
+ });
297
+ rawEdges.push({
298
+ id: `rt-${agent.id}`,
299
+ source: PRINCIPAL_ID,
300
+ target: agent.id,
301
+ type: 'smoothstep',
302
+ style: { stroke: color, strokeWidth: 1.5, opacity: dimmed ? 0.25 : 0.7 },
303
+ });
304
+ }
305
+ return { nodes: buildLayout(rawNodes, rawEdges), edges: rawEdges };
306
+ }, [agents.list, matchedIds, hasFilter, sel]);
307
+
308
+ const handleNodeClick = useCallback((_event, node) => setSel(node.id), [setSel]);
309
+ const close = useCallback(() => setSel(null), [setSel]);
310
+
311
+ const selected = agents.list.find((a) => a.id === sel) || null;
312
+ const isPrincipal = sel === PRINCIPAL_ID;
313
+ const panelOpen = Boolean(selected || isPrincipal);
314
+
315
+ const filterConfig = [
316
+ { name: 'domain', label: 'Domínio', options: allDomains, value: domainFilter },
317
+ { name: 'phase', label: 'Fase', options: allPhases, value: phaseFilter },
318
+ { name: 'stack', label: 'Stack', options: allStacks, value: stackFilter },
319
+ ];
320
+
321
+ return (
322
+ <div className="flex h-full flex-col">
323
+ <SearchFilter
324
+ placeholder="Buscar persona por nome ou palavra-chave"
325
+ filters={filterConfig}
326
+ onSearchChange={setSearch}
327
+ onFilterChange={(name, value) => {
328
+ if (name === 'domain') setDomainFilter(value);
329
+ if (name === 'phase') setPhaseFilter(value);
330
+ if (name === 'stack') setStackFilter(value);
331
+ }}
332
+ />
333
+
334
+ <div className="relative flex-1">
335
+ <FlowGraph nodes={nodes} edges={edges} nodeTypes={nodeTypes} onNodeClick={handleNodeClick} fitView />
336
+
337
+ <div className="bezel absolute left-3 top-3 z-10 max-w-[18rem]">
338
+ <div className="bezel-core space-y-1.5 px-3.5 py-3 text-[12px]">
339
+ <p className="mb-1 font-medium text-[var(--color-faint)]">Personas</p>
340
+ {agents.list.map((a) => (
341
+ <button
342
+ key={a.id}
343
+ type="button"
344
+ onClick={() => setSel(a.id)}
345
+ className="fluid flex w-full items-center gap-2 text-left text-[var(--color-dim)] transition-colors hover:text-[var(--color-fg)]"
346
+ >
347
+ <span className="inline-block h-2.5 w-2.5 shrink-0 rounded-full" style={{ background: personaColor(a) }} />
348
+ <span className="truncate">{a.title}</span>
349
+ </button>
350
+ ))}
351
+ <p className="mt-2 border-t border-[var(--color-hair)] pt-2 text-[var(--color-faint)]">A linha liga quem despacha a quem é despachado.</p>
352
+ </div>
353
+ </div>
354
+
355
+ <div className="absolute right-3 top-3 z-10 rounded-full bg-[var(--color-ink)]/80 px-3 py-1.5 text-[12px] text-[var(--color-dim)] shadow-[inset_0_0_0_1px_var(--color-hair)]">
356
+ {hasFilter ? `${matchedIds.size} de ${agents.list.length}` : agents.list.length} personas
357
+ </div>
358
+ </div>
359
+
360
+ <DetailPanel
361
+ open={panelOpen}
362
+ title={selected ? selected.title : isPrincipal ? 'Você e a thread principal' : ''}
363
+ subtitle={selected ? `morph-${selected.id}` : isPrincipal ? 'Orquestrador' : undefined}
364
+ onClose={close}
365
+ >
366
+ {selected && <AgentDetail key={selected.id} agent={selected} />}
367
+ {isPrincipal && <PrincipalDetail />}
368
+ </DetailPanel>
369
+ </div>
370
+ );
371
+ }