@polymorphism-tech/morph-spec 8.37.1 → 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 (317) hide show
  1. package/CLAUDE.md +37 -13
  2. package/README.md +2 -2
  3. package/bin/morph-spec.js +75 -49
  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 +6 -5
  8. package/framework/MORPH.md +25 -22
  9. package/framework/agents.json +96 -36
  10. package/framework/docs/CLI.md +54 -17
  11. package/framework/evals/rubrics/code-quality.md +5 -0
  12. package/framework/evals/rubrics/condensed.md +6 -2
  13. package/framework/evals/rubrics/contracts.md +20 -0
  14. package/framework/evals/rubrics/test-coverage.md +17 -6
  15. package/framework/hooks/README.md +9 -3
  16. package/framework/hooks/claude-code/core/graph-refresh-kick.js +52 -0
  17. package/framework/hooks/claude-code/core/telemetry-log.js +172 -87
  18. package/framework/hooks/claude-code/core/validate-completion.js +16 -90
  19. package/framework/hooks/claude-code/core/worktree-context.js +10 -0
  20. package/framework/hooks/shared/command-tokens.js +96 -0
  21. package/framework/hooks/shared/git-exclude.js +44 -0
  22. package/framework/hooks/shared/git-paths.js +52 -0
  23. package/framework/hooks/shared/graph-freshness.js +380 -0
  24. package/framework/hooks/shared/graph-refresh.js +416 -0
  25. package/framework/hooks/shared/morph-cli.js +17 -5
  26. package/framework/hooks/shared/redact-secrets.js +55 -0
  27. package/framework/hooks/shared/telemetry-logger.js +25 -2
  28. package/framework/hooks/shared/transcript-usage.js +80 -0
  29. package/framework/mcp/registry.json +33 -2
  30. package/framework/rubrics/backend.json +2 -2
  31. package/framework/rubrics/default.json +2 -2
  32. package/framework/rubrics/frontend.json +2 -2
  33. package/framework/rules/csharp-standards.md +1 -0
  34. package/framework/rules/infrastructure-standards.md +0 -1
  35. package/framework/rules/morph-workflow.md +10 -4
  36. package/framework/rules/nextjs-standards.md +1 -0
  37. package/framework/schemas/config.schema.json +41 -1
  38. package/framework/schemas/feature.schema.json +5 -1
  39. package/framework/skills/core/create-umbraco-lp/SKILL.md +1 -1
  40. package/framework/skills/core/migrate-lp-to-umbraco/SKILL.md +1 -1
  41. package/framework/skills/core/morph-apply/SKILL.md +40 -11
  42. package/framework/skills/core/morph-brainstorming/SKILL.md +16 -7
  43. package/framework/skills/core/morph-eval/SKILL.md +1 -1
  44. package/framework/skills/core/morph-hotfix/SKILL.md +1 -1
  45. package/framework/skills/core/morph-implement/SKILL.md +44 -10
  46. package/framework/skills/core/morph-media/SKILL.md +1 -1
  47. package/framework/skills/core/morph-plan/SKILL.md +73 -15
  48. package/framework/skills/core/morph-proposal/SKILL.md +1 -1
  49. package/framework/skills/core/morph-review/SKILL.md +51 -13
  50. package/framework/skills/core/morph-stack-scan/SKILL.md +1 -1
  51. package/framework/skills/core/morph-standards/SKILL.md +1 -1
  52. package/framework/skills/core/morph-uiux/SKILL.md +39 -13
  53. package/framework/standards/STANDARDS.json +189 -14
  54. package/framework/standards/ai-agents/context-providers.md +16 -26
  55. package/framework/standards/ai-agents/durable-workflows-hitl.md +15 -21
  56. package/framework/standards/ai-agents/modalities-image-gen.md +21 -25
  57. package/framework/standards/ai-agents/modalities-speech-to-text.md +4 -15
  58. package/framework/standards/ai-agents/modalities-text-to-speech.md +2 -11
  59. package/framework/standards/ai-agents/modalities-vision.md +1 -18
  60. package/framework/standards/ai-agents/prompt-sources.md +0 -4
  61. package/framework/standards/ai-agents/testing-ai.md +2 -1
  62. package/framework/standards/architecture/code-comments.md +100 -0
  63. package/framework/standards/backend/dotnet/testing.md +22 -0
  64. package/framework/standards/backend/integrations/neon-auth/neon-auth.md +63 -50
  65. package/framework/standards/frontend/admin-app/data-table.md +562 -0
  66. package/framework/standards/frontend/admin-app/feedback.md +236 -0
  67. package/framework/standards/frontend/admin-app/forms.md +232 -0
  68. package/framework/standards/frontend/admin-app/page-structure.md +203 -0
  69. package/framework/standards/frontend/design-system/ai-image-generation.md +5 -5
  70. package/framework/standards/frontend/nextjs/components.md +37 -58
  71. package/framework/standards/frontend/nextjs/data-fetching.md +1 -0
  72. package/framework/standards/frontend/nextjs/forms.md +31 -30
  73. package/framework/standards/frontend/nextjs/state-management.md +2 -1
  74. package/framework/standards/frontend/nextjs/testing.md +18 -0
  75. package/framework/standards/integration/mcp/mcp-tools.md +48 -117
  76. package/framework/templates/code/dotnet/abstractions/result.cs +0 -2
  77. package/framework/templates/code/dotnet/ai-agents/AgentBootstrap.cs.template +26 -39
  78. package/framework/templates/code/dotnet/ai-agents/EmbeddingService.cs.template +28 -68
  79. package/framework/templates/code/dotnet/ai-agents/ModelRegistry.cs.template +99 -117
  80. package/framework/templates/code/dotnet/ai-agents/PromptRepository.cs.template +2 -44
  81. package/framework/templates/code/dotnet/ai-agents/ResilientToolMiddleware.cs.template +40 -61
  82. package/framework/templates/code/dotnet/ai-agents/VectorSearchTool.cs.template +54 -107
  83. package/framework/templates/code/dotnet/ai-agents/model-registry.json.template +53 -58
  84. package/framework/templates/code/dotnet/contracts/contracts-vsa.cs +192 -281
  85. package/framework/templates/code/dotnet/database/migration.cs +49 -83
  86. package/framework/templates/code/dotnet/database/vector-entity.cs +2 -46
  87. package/framework/templates/code/dotnet/extensions/result-extensions.cs +0 -2
  88. package/framework/templates/code/dotnet/feature/validator.cs.hbs +11 -15
  89. package/framework/templates/code/dotnet/jobs/agent.cs +3 -51
  90. package/framework/templates/code/dotnet/jobs/job.cs +2 -97
  91. package/framework/templates/code/dotnet/test.cs +2 -87
  92. package/framework/templates/code/typescript/contracts.ts +140 -167
  93. package/framework/templates/context/design-system.md +3 -3
  94. package/framework/templates/docs/proposal.md +11 -0
  95. package/framework/templates/docs/spec.md +15 -0
  96. package/framework/templates/docs/ui-mockups.md +115 -98
  97. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentApi.cs +1 -48
  98. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentFactory.cs +3 -79
  99. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentFactoryOptions.cs +1 -70
  100. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentSpec.cs +1 -47
  101. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentSpecOptions.cs +2 -99
  102. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/AiKitAssemblyMarker.cs +0 -6
  103. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Conversation/ConversationStore.cs +3 -88
  104. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Conversation/IConversationStore.cs +1 -41
  105. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Conversation/InMemoryConversationStore.cs +0 -21
  106. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/CountingChatClient.cs +1 -25
  107. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalAssertion.cs +2 -63
  108. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalCacheMissException.cs +0 -30
  109. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalCacheOptions.cs +1 -52
  110. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalCacheStamp.cs +3 -78
  111. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalFixture.cs +4 -109
  112. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalMode.cs +0 -22
  113. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalQualityEvaluators.cs +1 -36
  114. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalScenario.cs +2 -57
  115. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalSummary.cs +0 -75
  116. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/OfflineChatClient.cs +2 -59
  117. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/ShortPathResponseCache.cs +4 -111
  118. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/IMediaGenerator.cs +0 -34
  119. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/IMediaProvider.cs +1 -57
  120. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaArtifact.cs +0 -19
  121. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaDisclosure.cs +2 -74
  122. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaGenerator.cs +2 -33
  123. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaIdempotencyKey.cs +1 -43
  124. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaJob.cs +1 -96
  125. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaJobId.cs +0 -13
  126. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaJobState.cs +0 -27
  127. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaPricing.cs +0 -33
  128. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaProvenance.cs +0 -31
  129. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaRequest.cs +3 -75
  130. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaResult.cs +0 -42
  131. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaReview.cs +0 -39
  132. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaSeams.cs +1 -55
  133. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaStore.cs +3 -59
  134. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MorphMedia.cs +0 -46
  135. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/Providers/GoogleImageProvider.cs +3 -28
  136. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/Providers/OpenAIImageProvider.cs +7 -61
  137. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/Providers/VeoVideoProvider.cs +2 -37
  138. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Middleware/IUsageCostSink.cs +1 -23
  139. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Middleware/UsageCostMiddleware.cs +2 -82
  140. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Middleware/UsageCostRecord.cs +1 -68
  141. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Observability/MorphOpenTelemetryExtensions.cs +1 -62
  142. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Observability/MorphTelemetryOptions.cs +2 -62
  143. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Providers/IProviderClientFactory.cs +1 -25
  144. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Providers/ModelAlias.cs +0 -124
  145. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Providers/ModelRegistry.cs +1 -73
  146. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Rag/DeltaIngest.cs +1 -66
  147. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Rag/DeltaPlan.cs +0 -41
  148. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/AgentFactoryTests.cs +2 -112
  149. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/AgentSpecTests.cs +2 -43
  150. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/ConversationStoreTests.cs +5 -110
  151. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/DeltaIngestTests.cs +7 -103
  152. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalAssertionTests.cs +1 -42
  153. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalCacheMissTests.cs +1 -30
  154. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalCacheStampTests.cs +1 -19
  155. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalFailuresTests.cs +0 -48
  156. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalFixtureTests.cs +1 -29
  157. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalRefreshTests.cs +2 -38
  158. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalWorkspace.cs +1 -14
  159. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/KitEvals.cs +4 -69
  160. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/OfflineChatClientTests.cs +1 -10
  161. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeChatClient.cs +1 -57
  162. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeChatClientTests.cs +0 -26
  163. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeClock.cs +1 -19
  164. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeMediaProvider.cs +0 -32
  165. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeProviderClientFactory.cs +0 -14
  166. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeUsageCostSink.cs +0 -24
  167. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/InMemoryMediaStore.cs +0 -32
  168. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaAccessibilityTests.cs +0 -37
  169. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaAliasIsNotAnAgentTests.cs +0 -24
  170. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaDisclosureTests.cs +0 -78
  171. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaGeneratorTests.cs +0 -53
  172. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaIdempotencyKeyTests.cs +0 -44
  173. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaJobStateTests.cs +0 -44
  174. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaReviewTests.cs +0 -19
  175. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaStoreTests.cs +0 -24
  176. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/ModelRegistryTests.cs +6 -48
  177. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/SkeletonSmokeTests.cs +1 -13
  178. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/TelemetryTests.cs +2 -71
  179. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/UsageCostMiddlewareTests.cs +5 -100
  180. package/framework/templates/feature/decisions.md +124 -122
  181. package/framework/templates/frontend/nextjs/Dockerfile.nextjs.hbs +39 -43
  182. package/framework/templates/frontend/nextjs/env.mjs.hbs +29 -32
  183. package/framework/templates/frontend/nextjs/page.tsx.hbs +21 -22
  184. package/framework/templates/frontend/nextjs/use-feature.ts.hbs +42 -54
  185. package/framework/templates/integrations/asaas-client.cs +332 -387
  186. package/framework/templates/integrations/asaas-webhook.cs +290 -351
  187. package/framework/templates/integrations/neon-auth-config.cs +9 -105
  188. package/framework/templates/project/validate.js +97 -120
  189. package/package.json +2 -2
  190. package/src/commands/dashboard/dashboard.js +80 -53
  191. package/src/commands/graph/affected.js +4 -3
  192. package/src/commands/graph/build.js +109 -18
  193. package/src/commands/graph/explain.js +8 -5
  194. package/src/commands/graph/status.js +14 -8
  195. package/src/commands/mcp/mcp-setup.js +37 -9
  196. package/src/commands/observability/cost.js +148 -18
  197. package/src/commands/project/doctor.js +85 -15
  198. package/src/commands/project/init.js +6 -3
  199. package/src/commands/project/install-plugin-cmd.js +1 -1
  200. package/src/commands/project/update.js +30 -0
  201. package/src/commands/project/worktree.js +73 -90
  202. package/src/commands/state/advance.js +18 -0
  203. package/src/commands/state/approve.js +15 -0
  204. package/src/commands/state/archive.js +62 -9
  205. package/src/commands/state/finish.js +62 -14
  206. package/src/commands/state/gate-check.js +8 -1
  207. package/src/commands/state/gate-decision.js +8 -4
  208. package/src/commands/state/report-check.js +90 -9
  209. package/src/commands/state/usecase.js +66 -0
  210. package/src/commands/tasks/dag.js +17 -2
  211. package/src/commands/validation/validate-feature.js +6 -1
  212. package/src/commands/validation/verify.js +20 -1
  213. package/src/dashboard/app/App.jsx +80 -16
  214. package/src/dashboard/app/components/ActivityFeed.jsx +172 -0
  215. package/src/dashboard/app/components/CommandPalette.jsx +155 -0
  216. package/src/dashboard/app/components/DetailPanel.jsx +47 -11
  217. package/src/dashboard/app/components/EntityLink.jsx +55 -0
  218. package/src/dashboard/app/components/ErrorBoundary.jsx +54 -0
  219. package/src/dashboard/app/components/FlowGraph.jsx +19 -17
  220. package/src/dashboard/app/components/KnowledgeMarkdown.jsx +53 -0
  221. package/src/dashboard/app/components/Markdown.jsx +47 -0
  222. package/src/dashboard/app/components/PhaseRail.jsx +111 -0
  223. package/src/dashboard/app/components/SearchFilter.jsx +40 -22
  224. package/src/dashboard/app/components/Sidebar.jsx +146 -37
  225. package/src/dashboard/app/hooks/useMorphQuery.js +54 -0
  226. package/src/dashboard/app/hooks/usePref.js +38 -0
  227. package/src/dashboard/app/lib/format.js +69 -0
  228. package/src/dashboard/app/lib/phases.js +56 -0
  229. package/src/dashboard/app/lib/project.js +50 -0
  230. package/src/dashboard/app/pages/Activity.jsx +24 -0
  231. package/src/dashboard/app/pages/AgentMap.jsx +371 -370
  232. package/src/dashboard/app/pages/FeatureDetail.jsx +604 -0
  233. package/src/dashboard/app/pages/Features.jsx +400 -0
  234. package/src/dashboard/app/pages/Guide.jsx +146 -0
  235. package/src/dashboard/app/pages/HookInspector.jsx +357 -322
  236. package/src/dashboard/app/pages/PhasePipeline.jsx +277 -408
  237. package/src/dashboard/app/pages/Portfolio.jsx +156 -0
  238. package/src/dashboard/app/pages/Rubrics.jsx +101 -0
  239. package/src/dashboard/app/pages/RulesMap.jsx +300 -273
  240. package/src/dashboard/app/pages/SkillsLibrary.jsx +483 -366
  241. package/src/dashboard/app/pages/Standards.jsx +407 -332
  242. package/src/dashboard/app/styles/index.css +187 -47
  243. package/src/dashboard/index.html +14 -12
  244. package/src/dashboard/package.json +32 -24
  245. package/src/dashboard/scanner/activity-scanner.js +351 -0
  246. package/src/dashboard/scanner/agents-scanner.js +63 -1
  247. package/src/dashboard/scanner/docs-scanner.js +59 -0
  248. package/src/dashboard/scanner/feature-status.js +10 -0
  249. package/src/dashboard/scanner/features-scanner.js +360 -0
  250. package/src/dashboard/scanner/hooks-scanner.js +8 -1
  251. package/src/dashboard/scanner/index.js +14 -7
  252. package/src/dashboard/scanner/phases-scanner.js +14 -15
  253. package/src/dashboard/scanner/portfolio.js +153 -0
  254. package/src/dashboard/scanner/project-api.js +195 -0
  255. package/src/dashboard/scanner/rules-scanner.js +42 -37
  256. package/src/dashboard/scanner/skills-scanner.js +105 -43
  257. package/src/dashboard/scanner/standards-scanner.js +4 -1
  258. package/src/dashboard/vite-plugin-morph-data.js +134 -17
  259. package/src/lib/ai/comment-stripper.js +101 -4
  260. package/src/lib/detectors/claude-config-detector.js +2 -7
  261. package/src/lib/detectors/index.js +5 -1
  262. package/src/lib/evaluator-report.js +47 -0
  263. package/src/lib/generators/handoff-generator.js +4 -18
  264. package/src/lib/generators/settings-generator.js +208 -209
  265. package/src/lib/git/default-branch.js +52 -0
  266. package/src/lib/git/tree-fingerprint.js +58 -0
  267. package/src/lib/git/tree-state.js +167 -0
  268. package/src/lib/graph/god-nodes.js +12 -3
  269. package/src/lib/graph/graph-health.js +48 -2
  270. package/src/lib/graph/graph-loader.js +99 -25
  271. package/src/lib/graph/graphifyignore.js +145 -28
  272. package/src/lib/graph/sanitize.js +117 -11
  273. package/src/lib/installers/mcp-installer.js +724 -719
  274. package/src/lib/installers/memory-installer.js +1 -2
  275. package/src/lib/projects/registry.js +154 -0
  276. package/src/lib/risk-detector.js +90 -0
  277. package/src/lib/specs/acervo-format.js +70 -0
  278. package/src/lib/specs/acervo-lifecycle.js +264 -0
  279. package/src/lib/specs/adr-index.js +169 -0
  280. package/src/lib/specs/revocations.js +156 -0
  281. package/src/lib/specs/screen-checklist.js +357 -0
  282. package/src/lib/specs/usecase-check.js +20 -16
  283. package/src/lib/specs/usecase-promoter.js +103 -38
  284. package/src/lib/specs/usecase-registry.js +7 -7
  285. package/src/lib/tasks/tasks-json-parser.js +2 -3
  286. package/src/lib/telemetry/metrics.js +386 -0
  287. package/src/lib/telemetry/telemetry-reader.js +161 -51
  288. package/src/lib/telemetry/verify-event.js +79 -0
  289. package/src/lib/validators/code-budget/code-budget-validator.js +200 -0
  290. package/src/lib/validators/code-budget/comment-scanner.js +75 -0
  291. package/src/lib/validators/code-budget/index.js +9 -0
  292. package/src/lib/validators/reuse/reuse-validator.js +4 -2
  293. package/src/lib/validators/reuse/symbol-scanner.js +27 -22
  294. package/src/lib/validators/validation-runner.js +21 -5
  295. package/src/lib/validators/verify-runner.js +11 -0
  296. package/src/lib/worktree/finish-backup.js +739 -0
  297. package/src/lib/worktree/ignored-triage.js +15 -8
  298. package/src/lib/worktree/worktree-audit.js +5 -0
  299. package/src/scripts/install-plugin.js +1 -1
  300. package/src/scripts/setup-infra.js +31 -22
  301. package/src/utils/agents-installer.js +338 -24
  302. package/src/utils/banner.js +1 -1
  303. package/src/utils/hooks-installer.js +75 -15
  304. package/src/commands/index.js +0 -13
  305. package/src/commands/project/checkpoint.js +0 -209
  306. package/src/core/state/phase-state-machine.js +0 -197
  307. package/src/dashboard/app/hooks/useDetailPanel.js +0 -15
  308. package/src/dashboard/app/pages/LiveState.jsx +0 -206
  309. package/src/dashboard/scanner/squads-scanner.js +0 -13
  310. package/src/dashboard/scanner/state-scanner.js +0 -85
  311. package/src/lib/generators/index.js +0 -10
  312. package/src/lib/hooks/hook-executor.js +0 -167
  313. package/src/lib/validators/checkpoint-persistence.js +0 -39
  314. package/src/lib/validators/shared/emit-validator-dispatch.js +0 -14
  315. package/src/lib/validators/shared/index.js +0 -12
  316. package/src/lib/validators/shared/issue-counter.js +0 -14
  317. package/src/lib/validators/shared/result-formatter.js +0 -124
@@ -1,366 +1,483 @@
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
- // Colors for skill categories (v5 — all skills in skills/core/)
11
- const LEVEL_COLORS = {
12
- 'core': { bg: '#134e4a', border: '#14b8a6', label: 'Core' },
13
- };
14
- const FALLBACK_LEVEL = { bg: '#1a2e1a', border: '#4ade80', label: 'Skill' };
15
-
16
- // Phase color (indigo)
17
- const PHASE_COLOR = { bg: '#1e1b4b', border: '#818cf8', text: '#e0e7ff' };
18
-
19
- // SkillNode: teal/green border
20
- function SkillNode({ data }) {
21
- const c = LEVEL_COLORS[data.level] || FALLBACK_LEVEL;
22
- return (
23
- <div
24
- className="rounded-lg px-3 py-2 min-w-[140px] max-w-[170px] cursor-pointer select-none"
25
- style={{ background: c.bg, border: `1.5px solid ${c.border}`, boxShadow: `0 0 8px ${c.border}22` }}
26
- >
27
- <Handle type="target" position={Position.Top} style={{ background: c.border, width: 7, height: 7 }} />
28
- <div className="text-white text-xs font-semibold leading-tight truncate" title={data.label}>
29
- {data.label}
30
- </div>
31
- <div className="mt-0.5 text-[10px] font-medium" style={{ color: c.border }}>
32
- {(LEVEL_COLORS[data.level] || FALLBACK_LEVEL).label}
33
- </div>
34
- <Handle type="source" position={Position.Bottom} style={{ background: c.border, width: 7, height: 7 }} />
35
- </div>
36
- );
37
- }
38
-
39
- // PhaseRefNode: indigo border, shows phase name
40
- function PhaseRefNode({ data }) {
41
- return (
42
- <div
43
- className="rounded-lg px-4 py-2.5 min-w-[130px] select-none cursor-default"
44
- style={{ background: PHASE_COLOR.bg, border: `1.5px solid ${PHASE_COLOR.border}`, boxShadow: `0 0 8px ${PHASE_COLOR.border}33` }}
45
- >
46
- <Handle type="source" position={Position.Bottom} style={{ background: PHASE_COLOR.border, width: 7, height: 7 }} />
47
- <div className="text-white text-xs font-bold leading-tight truncate" title={data.label}>
48
- {data.label}
49
- </div>
50
- <div className="mt-0.5 text-[10px]" style={{ color: PHASE_COLOR.text }}>
51
- phase
52
- </div>
53
- </div>
54
- );
55
- }
56
-
57
- const nodeTypes = { skillNode: SkillNode, phaseRefNode: PhaseRefNode };
58
-
59
- // Shorten a trigger string for use as edge label
60
- function shortTrigger(trigger) {
61
- if (!trigger) return '';
62
- // "on:task:start" → "task:start", "/morph-proposal" → "morph-proposal"
63
- return trigger.replace(/^on:/, '').replace(/^\//, '');
64
- }
65
-
66
- // Build dagre layout for the skills graph
67
- function buildLayout(nodes, edges) {
68
- const g = new dagre.graphlib.Graph();
69
- g.setDefaultEdgeLabel(() => ({}));
70
- g.setGraph({ rankdir: 'TB', nodesep: 50, ranksep: 80, marginx: 20, marginy: 20 });
71
-
72
- for (const n of nodes) {
73
- const w = n.type === 'phaseRefNode' ? 150 : 170;
74
- const h = n.type === 'phaseRefNode' ? 52 : 58;
75
- g.setNode(n.id, { width: w, height: h });
76
- }
77
- for (const e of edges) {
78
- g.setEdge(e.source, e.target);
79
- }
80
-
81
- dagre.layout(g);
82
-
83
- return nodes.map((n) => {
84
- const pos = g.node(n.id);
85
- const halfW = n.type === 'phaseRefNode' ? 75 : 85;
86
- const halfH = n.type === 'phaseRefNode' ? 26 : 29;
87
- return { ...n, position: { x: pos.x - halfW, y: pos.y - halfH } };
88
- });
89
- }
90
-
91
- // Detail panel for a skill
92
- function SkillDetail({ skill }) {
93
- const c = LEVEL_COLORS[skill.level] || FALLBACK_LEVEL;
94
-
95
- return (
96
- <div className="text-sm text-gray-200 space-y-4">
97
- {/* Header badges */}
98
- <div className="flex flex-wrap gap-2">
99
- <span
100
- className="px-2 py-0.5 rounded text-xs font-bold"
101
- style={{ background: c.bg, color: c.border, border: `1px solid ${c.border}` }}
102
- >
103
- {c.label}
104
- </span>
105
- <span
106
- className={`px-2 py-0.5 rounded text-xs font-medium border ${
107
- skill.userInvocable
108
- ? 'bg-green-900/40 border-green-600 text-green-300'
109
- : 'bg-gray-800 border-gray-600 text-gray-400'
110
- }`}
111
- >
112
- {skill.userInvocable ? 'User-invocable' : 'Internal'}
113
- </span>
114
- </div>
115
-
116
- {/* ID */}
117
- <div>
118
- <p className="text-gray-500 text-xs uppercase tracking-wide mb-1">Skill ID</p>
119
- <p className="font-mono text-xs text-gray-300">{skill.id}</p>
120
- </div>
121
-
122
- {/* Description */}
123
- {skill.description && (
124
- <div>
125
- <p className="text-gray-500 text-xs uppercase tracking-wide mb-1">Description</p>
126
- <p className="text-gray-300 text-xs leading-relaxed">{skill.description}</p>
127
- </div>
128
- )}
129
-
130
- {/* Allowed tools */}
131
- {skill.allowedTools?.length > 0 && (
132
- <div>
133
- <p className="text-gray-500 text-xs uppercase tracking-wide mb-1.5">Allowed Tools</p>
134
- <div className="flex flex-wrap gap-1">
135
- {skill.allowedTools.map((t) => (
136
- <span key={t} className="px-1.5 py-0.5 bg-gray-800 border border-gray-600 rounded text-xs text-gray-300 font-mono">
137
- {t}
138
- </span>
139
- ))}
140
- </div>
141
- </div>
142
- )}
143
-
144
- {/* Full content */}
145
- {skill.content && (
146
- <div>
147
- <p className="text-gray-500 text-xs uppercase tracking-wide mb-1.5">Full Content</p>
148
- <pre className="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-72 overflow-y-auto">
149
- {skill.content}
150
- </pre>
151
- </div>
152
- )}
153
- </div>
154
- );
155
- }
156
-
157
- export default function SkillsLibrary() {
158
- const { skills, phases } = morphData;
159
- const [search, setSearch] = useState('');
160
- const [levelFilter, setLevelFilter] = useState('');
161
- const { panel, openPanel, closePanel } = useDetailPanel();
162
-
163
- // All unique levels for filter dropdown
164
- const allLevels = useMemo(
165
- () => [...new Set(skills.map((s) => s.level).filter(Boolean))].sort(),
166
- [skills]
167
- );
168
-
169
- // Matched skill IDs based on search + level filter
170
- const matchedIds = useMemo(() => {
171
- const q = search.toLowerCase();
172
- return new Set(
173
- skills
174
- .filter((s) => {
175
- const matchesSearch =
176
- !q ||
177
- s.name.toLowerCase().includes(q) ||
178
- s.id.toLowerCase().includes(q) ||
179
- s.description.toLowerCase().includes(q);
180
- const matchesLevel = !levelFilter || s.level === levelFilter;
181
- return matchesSearch && matchesLevel;
182
- })
183
- .map((s) => s.id)
184
- );
185
- }, [skills, search, levelFilter]);
186
-
187
- const hasFilter = search || levelFilter;
188
-
189
- // Build a map: skillId → [{ phaseId, trigger }] for all connected phases
190
- const skillToPhases = useMemo(() => {
191
- const map = new Map();
192
- for (const phase of phases.list) {
193
- for (const rs of phase.requiredSkills || []) {
194
- if (!rs.skill) continue;
195
- if (!map.has(rs.skill)) map.set(rs.skill, []);
196
- map.get(rs.skill).push({ phaseId: phase.id, trigger: rs.trigger });
197
- }
198
- }
199
- return map;
200
- }, [phases.list]);
201
-
202
- // Set of phase IDs that actually connect to at least one skill
203
- const connectedPhaseIds = useMemo(() => {
204
- const ids = new Set();
205
- for (const phase of phases.list) {
206
- if (phase.requiredSkills?.some((rs) => rs.skill)) {
207
- ids.add(phase.id);
208
- }
209
- }
210
- return ids;
211
- }, [phases.list]);
212
-
213
- // Build nodes + edges
214
- const { nodes: layoutNodes, edges } = useMemo(() => {
215
- const rawNodes = [];
216
- const rawEdges = [];
217
-
218
- // Phase nodes (top row) — only phases with required skills
219
- const connectedPhases = phases.list.filter((p) => connectedPhaseIds.has(p.id));
220
- for (const phase of connectedPhases) {
221
- rawNodes.push({
222
- id: `phase:${phase.id}`,
223
- type: 'phaseRefNode',
224
- data: {
225
- label: phase.displayName,
226
- phaseId: phase.id,
227
- color: PHASE_COLOR.border,
228
- },
229
- position: { x: 0, y: 0 },
230
- });
231
- }
232
-
233
- // Skill nodes
234
- for (const skill of skills) {
235
- const dimmed = hasFilter && !matchedIds.has(skill.id);
236
- const c = LEVEL_COLORS[skill.level] || FALLBACK_LEVEL;
237
- rawNodes.push({
238
- id: skill.id,
239
- type: 'skillNode',
240
- data: {
241
- label: skill.name,
242
- level: skill.level,
243
- skillRef: skill,
244
- color: c.border,
245
- },
246
- style: dimmed ? { opacity: 0.2 } : {},
247
- position: { x: 0, y: 0 },
248
- });
249
- }
250
-
251
- // Edges: phase → skill with trigger label
252
- const edgeIndex = new Map(); // track (phaseId,skillId) pairs to avoid duplicates
253
- for (const phase of phases.list) {
254
- for (const rs of phase.requiredSkills || []) {
255
- if (!rs.skill) continue;
256
- const key = `${phase.id}::${rs.skill}`;
257
- if (edgeIndex.has(key)) continue;
258
- edgeIndex.set(key, true);
259
-
260
- const label = shortTrigger(rs.trigger);
261
- rawEdges.push({
262
- id: `edge-${phase.id}-${rs.skill}`,
263
- source: `phase:${phase.id}`,
264
- target: rs.skill,
265
- type: 'smoothstep',
266
- label: label || undefined,
267
- labelStyle: { fontSize: 9, fill: '#94a3b8' },
268
- labelBgStyle: { fill: '#0f172a', fillOpacity: 0.85 },
269
- labelBgPadding: [3, 2],
270
- style: { stroke: PHASE_COLOR.border, strokeWidth: 1.5, opacity: 0.7 },
271
- });
272
- }
273
- }
274
-
275
- const layouted = buildLayout(rawNodes, rawEdges);
276
- return { nodes: layouted, edges: rawEdges };
277
- }, [skills, phases.list, matchedIds, hasFilter, connectedPhaseIds]);
278
-
279
- const handleNodeClick = useCallback(
280
- (_event, node) => {
281
- if (node.type === 'phaseRefNode') {
282
- // No detail panel for phase nodes per spec
283
- return;
284
- }
285
- const skill = node.data.skillRef;
286
- if (skill) {
287
- openPanel(skill.name, <SkillDetail skill={skill} />);
288
- }
289
- },
290
- [openPanel]
291
- );
292
-
293
- const filterConfig = [
294
- { name: 'level', label: 'Level', options: allLevels, value: levelFilter },
295
- ];
296
-
297
- // Unconnected skill count
298
- const unconnectedCount = useMemo(
299
- () => skills.filter((s) => !skillToPhases.has(s.id)).length,
300
- [skills, skillToPhases]
301
- );
302
-
303
- return (
304
- <div className="flex flex-col h-full">
305
- <SearchFilter
306
- placeholder="Search skills by name or description..."
307
- filters={filterConfig}
308
- onSearchChange={setSearch}
309
- onFilterChange={(name, value) => {
310
- if (name === 'level') setLevelFilter(value);
311
- }}
312
- />
313
-
314
- <div className="flex-1 relative">
315
- <FlowGraph
316
- nodes={layoutNodes}
317
- edges={edges}
318
- nodeTypes={nodeTypes}
319
- onNodeClick={handleNodeClick}
320
- fitView
321
- />
322
-
323
- {/* Legend */}
324
- <div className="absolute top-3 left-3 bg-gray-900/90 border border-gray-700 rounded-lg p-3 text-xs space-y-2 z-10">
325
- <p className="text-gray-400 font-semibold uppercase tracking-wide text-[10px] mb-2">Legend</p>
326
- <div className="flex items-center gap-2">
327
- <span
328
- className="inline-block w-10 h-4 rounded-sm flex-shrink-0"
329
- style={{ background: PHASE_COLOR.bg, border: `1.5px solid ${PHASE_COLOR.border}` }}
330
- />
331
- <span className="text-gray-300">Phase</span>
332
- </div>
333
- {Object.entries(LEVEL_COLORS).map(([level, c]) => (
334
- <div key={level} className="flex items-center gap-2">
335
- <span
336
- className="inline-block w-10 h-4 rounded-sm flex-shrink-0"
337
- style={{ background: c.bg, border: `1.5px solid ${c.border}` }}
338
- />
339
- <span className="text-gray-300">{c.label}</span>
340
- </div>
341
- ))}
342
- <div className="border-t border-gray-700 mt-2 pt-2">
343
- <div className="flex items-center gap-2">
344
- <span className="inline-block w-6 border-t-2 border-indigo-400" style={{ opacity: 0.7 }} />
345
- <span className="text-gray-400">phase → skill</span>
346
- </div>
347
- </div>
348
- </div>
349
-
350
- {/* Stats badge */}
351
- <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 space-y-0.5">
352
- <div>
353
- {hasFilter ? `${matchedIds.size} / ${skills.length}` : skills.length} skills
354
- </div>
355
- {unconnectedCount > 0 && (
356
- <div className="text-gray-600">{unconnectedCount} unlinked</div>
357
- )}
358
- </div>
359
- </div>
360
-
361
- <DetailPanel open={panel.open} title={panel.title} onClose={closePanel}>
362
- {panel.content}
363
- </DetailPanel>
364
- </div>
365
- );
366
- }
1
+ import { useState, useMemo, useCallback } from 'react';
2
+ import { useNavigate } from 'react-router-dom';
3
+ import { Handle, Position } from '@xyflow/react';
4
+ import { Terminal, Robot, UsersThree } 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, entityHref } from '../components/EntityLink.jsx';
11
+ import { phaseMeta } from '../lib/phases.js';
12
+ import { splitFrontmatter } from '../lib/format.js';
13
+
14
+ const SUPPORT_LABEL = 'Skills de apoio';
15
+ const GENERIC_ID = 'persona:*';
16
+ const GENERIC_LABEL = 'implementadores (morph-{id})';
17
+ const SUPPORT_COLOR = 'var(--color-dim)';
18
+ const PERSONA_COLOR = 'var(--color-ok)';
19
+
20
+ const INVOKE_YES = 'invocável por você';
21
+ const INVOKE_NO = 'só interna';
22
+
23
+ const tint = (color, pct = 14) => `color-mix(in srgb, ${color} ${pct}%, var(--color-core))`;
24
+
25
+ // ─── Nodes ────────────────────────────────────────────────────────────────────
26
+
27
+ const HANDLE = { width: 7, height: 7, border: 0 };
28
+
29
+ function PhaseNode({ data }) {
30
+ return (
31
+ <div
32
+ className="w-[220px] cursor-pointer select-none rounded-xl px-4 py-2.5"
33
+ style={{ background: tint(data.color, 18), boxShadow: `inset 0 0 0 1.5px ${data.color}` }}
34
+ >
35
+ <div className="text-[13px] font-semibold leading-tight text-[var(--color-fg)]">{data.label}</div>
36
+ <div className="mt-0.5 text-xs" style={{ color: data.color }}>
37
+ fase{data.optional ? ' opcional' : ''}
38
+ </div>
39
+ <Handle type="source" position={Position.Bottom} style={{ ...HANDLE, background: data.color }} />
40
+ </div>
41
+ );
42
+ }
43
+
44
+ function SkillNode({ data }) {
45
+ return (
46
+ <div
47
+ className="w-[220px] cursor-pointer select-none rounded-xl px-3.5 py-2 transition-opacity"
48
+ style={{
49
+ background: tint(data.color, 12),
50
+ boxShadow: `inset 0 0 0 1.5px ${data.color}`,
51
+ opacity: data.dimmed ? 0.2 : 1,
52
+ }}
53
+ >
54
+ <Handle type="target" position={Position.Top} id="top-in" style={{ ...HANDLE, background: data.color }} />
55
+ <div className="flex items-center gap-1.5">
56
+ <span className="truncate font-mono text-[13px] font-medium text-[var(--color-fg)]" title={data.label}>{data.label}</span>
57
+ {data.userInvocable && <Terminal weight="light" size={13} className="shrink-0 text-[var(--color-dim)]" aria-label="invocável por você" />}
58
+ </div>
59
+ <div className="mt-0.5 text-xs text-[var(--color-dim)]">
60
+ {data.dispatchCount > 0 ? `${data.dispatchCount} prompt${data.dispatchCount > 1 ? 's' : ''} a sub-agents` : data.sub}
61
+ </div>
62
+ <Handle type="source" position={Position.Bottom} id="bottom-out" style={{ ...HANDLE, background: data.color }} />
63
+ <Handle type="source" position={Position.Top} id="top-out" style={{ ...HANDLE, background: data.color, left: '70%' }} />
64
+ </div>
65
+ );
66
+ }
67
+
68
+ function PersonaNode({ data }) {
69
+ const Icon = data.generic ? UsersThree : Robot;
70
+ return (
71
+ <div
72
+ className="w-[220px] cursor-pointer select-none rounded-full px-4 py-2 transition-opacity"
73
+ style={{
74
+ background: tint(PERSONA_COLOR, 10),
75
+ boxShadow: `inset 0 0 0 1.5px ${PERSONA_COLOR}`,
76
+ opacity: data.dimmed ? 0.25 : 1,
77
+ }}
78
+ >
79
+ <Handle type="target" position={Position.Top} id="top-in" style={{ ...HANDLE, background: PERSONA_COLOR }} />
80
+ <div className="flex items-center gap-2">
81
+ <Icon weight="light" size={15} className="shrink-0 text-[var(--color-ok)]" />
82
+ <span className="truncate font-mono text-[13px] text-[var(--color-fg)]" title={data.label}>{data.label}</span>
83
+ </div>
84
+ <Handle type="target" position={Position.Bottom} id="bottom-in" style={{ ...HANDLE, background: PERSONA_COLOR }} />
85
+ </div>
86
+ );
87
+ }
88
+
89
+ function GroupNode({ data }) {
90
+ return (
91
+ <div
92
+ className="pointer-events-none rounded-2xl"
93
+ style={{ width: data.width, height: data.height, boxShadow: 'inset 0 0 0 1px var(--color-hair-strong)', background: 'rgb(255 255 255 / 0.015)' }}
94
+ >
95
+ <div className="px-4 pt-3 text-[13px] font-medium text-[var(--color-dim)]">{data.label}</div>
96
+ </div>
97
+ );
98
+ }
99
+
100
+ const nodeTypes = { phaseNode: PhaseNode, skillNode: SkillNode, personaNode: PersonaNode, groupNode: GroupNode };
101
+
102
+ // ─── Graph model ──────────────────────────────────────────────────────────────
103
+
104
+ /** The phase a skill belongs to: its own `phase`, or the phase whose `skill` it is. */
105
+ function skillPhaseOf(skill, phases) {
106
+ if (skill.phase) return skill.phase;
107
+ return phases.find((p) => p.skill === skill.id)?.id || null;
108
+ }
109
+
110
+ /** The persona targets of a skill's dispatches: generic ones go to the one "implementadores" node. */
111
+ function dispatchTargets(skill) {
112
+ const out = new Set();
113
+ for (const d of skill.dispatches || []) {
114
+ if (d.generic) out.add(GENERIC_ID);
115
+ else for (const p of d.personas || []) out.add(p);
116
+ }
117
+ return [...out];
118
+ }
119
+
120
+ const COL = 250;
121
+ const ROW_PHASE = 0;
122
+ const ROW_SKILL = 120;
123
+ const ROW_PERSONA = 290;
124
+ const ROW_SUPPORT = 440;
125
+ const SUPPORT_PER_ROW = 5;
126
+
127
+ function buildGraph({ skills, phases, agents, isMatch, hasFilter }) {
128
+ const nodes = [];
129
+ const edges = [];
130
+ const phaseSkills = new Map(); // phaseId → skill[]
131
+ const support = [];
132
+ for (const s of skills) {
133
+ const ph = skillPhaseOf(s, phases);
134
+ if (ph && phases.some((p) => p.id === ph)) {
135
+ if (!phaseSkills.has(ph)) phaseSkills.set(ph, []);
136
+ phaseSkills.get(ph).push(s);
137
+ } else support.push(s);
138
+ }
139
+
140
+ // Row 0 + 1: one column per phase, its skill(s) below it.
141
+ phases.forEach((p, i) => {
142
+ const meta = phaseMeta(p.id);
143
+ const x = i * COL;
144
+ nodes.push({
145
+ id: `phase:${p.id}`, type: 'phaseNode', position: { x, y: ROW_PHASE },
146
+ data: { label: meta.label, color: meta.color, optional: p.optional, phaseId: p.id },
147
+ });
148
+ (phaseSkills.get(p.id) || []).forEach((s, j) => {
149
+ nodes.push(skillNode(s, x, ROW_SKILL + j * 70, meta.color, meta.label));
150
+ edges.push({
151
+ id: `e:phase:${p.id}->${s.id}`, source: `phase:${p.id}`, target: s.id, targetHandle: 'top-in',
152
+ style: { stroke: meta.color, strokeWidth: 1.5, opacity: hasFilter && !isMatch(s) ? 0.12 : 0.8 },
153
+ });
154
+ });
155
+ });
156
+
157
+ // Row 3+: the support skills, in a labelled group under the personas.
158
+ const supportCols = Math.min(SUPPORT_PER_ROW, Math.max(1, support.length));
159
+ const supportRows = Math.ceil(support.length / supportCols);
160
+ const supportWidth = supportCols * COL;
161
+ const gridWidth = Math.max(phases.length * COL, supportWidth);
162
+ const supportX0 = (gridWidth - supportWidth) / 2;
163
+ if (support.length) {
164
+ nodes.push({
165
+ id: 'group:support', type: 'groupNode', position: { x: supportX0 - 15, y: ROW_SUPPORT - 45 },
166
+ data: { label: `${SUPPORT_LABEL} (fora do pipeline de fases)`, width: supportWidth, height: supportRows * 80 + 45 },
167
+ selectable: false, draggable: false, focusable: false, zIndex: -1,
168
+ });
169
+ }
170
+ support.forEach((s, i) => {
171
+ const x = supportX0 + (i % supportCols) * COL;
172
+ const y = ROW_SUPPORT + Math.floor(i / supportCols) * 80;
173
+ nodes.push(skillNode(s, x, y, SUPPORT_COLOR, SUPPORT_LABEL));
174
+ });
175
+
176
+ // Row 2: the personas the skills dispatch prompts to.
177
+ const personaIds = new Set();
178
+ for (const s of skills) for (const t of dispatchTargets(s)) personaIds.add(t);
179
+ const agentOrder = agents.map((a) => a.id);
180
+ const personas = [...personaIds].sort((a, b) => {
181
+ if (a === GENERIC_ID) return 1;
182
+ if (b === GENERIC_ID) return -1;
183
+ return (agentOrder.indexOf(a) + 1 || 99) - (agentOrder.indexOf(b) + 1 || 99);
184
+ });
185
+ const personaX0 = (gridWidth - personas.length * COL) / 2;
186
+ personas.forEach((pid, i) => {
187
+ const touched = skills.filter((s) => dispatchTargets(s).includes(pid));
188
+ nodes.push({
189
+ id: `persona:${pid}`, type: 'personaNode', position: { x: personaX0 + i * COL, y: ROW_PERSONA },
190
+ data: {
191
+ label: pid === GENERIC_ID ? GENERIC_LABEL : `morph-${pid}`,
192
+ personaId: pid === GENERIC_ID ? null : pid,
193
+ generic: pid === GENERIC_ID,
194
+ color: PERSONA_COLOR,
195
+ dimmed: hasFilter && !touched.some(isMatch),
196
+ },
197
+ });
198
+ });
199
+
200
+ // skill → persona, from the dispatch prompts.
201
+ const supportIds = new Set(support.map((s) => s.id));
202
+ for (const s of skills) {
203
+ const fromSupport = supportIds.has(s.id);
204
+ for (const pid of dispatchTargets(s)) {
205
+ edges.push({
206
+ id: `e:${s.id}->persona:${pid}`,
207
+ source: s.id, sourceHandle: fromSupport ? 'top-out' : 'bottom-out',
208
+ target: `persona:${pid}`, targetHandle: fromSupport ? 'bottom-in' : 'top-in',
209
+ style: { stroke: PERSONA_COLOR, strokeWidth: 1.25, strokeDasharray: '5 4', opacity: hasFilter && !isMatch(s) ? 0.1 : 0.6 },
210
+ });
211
+ }
212
+ }
213
+
214
+ return { nodes, edges, supportCount: support.length, linkedCount: skills.length - support.length };
215
+
216
+ function skillNode(s, x, y, color, sub) {
217
+ return {
218
+ id: s.id, type: 'skillNode', position: { x, y },
219
+ data: {
220
+ label: s.id, sub, color, skillId: s.id,
221
+ userInvocable: Boolean(s.userInvocable),
222
+ dispatchCount: (s.dispatches || []).length,
223
+ dimmed: hasFilter && !isMatch(s),
224
+ },
225
+ };
226
+ }
227
+ }
228
+
229
+ // ─── Detail ───────────────────────────────────────────────────────────────────
230
+
231
+ function Section({ title, children }) {
232
+ return (
233
+ <section className="space-y-2">
234
+ <h3 className="text-xs font-medium text-[var(--color-faint)]">{title}</h3>
235
+ {children}
236
+ </section>
237
+ );
238
+ }
239
+
240
+ function PromptBlock({ text, label = 'Prompt enviado ao sub-agent' }) {
241
+ return (
242
+ <div
243
+ className="overflow-hidden rounded-xl"
244
+ style={{ background: tint('var(--color-phase-implement)', 8), boxShadow: 'inset 0 0 0 1px color-mix(in srgb, var(--color-phase-implement) 45%, transparent)' }}
245
+ >
246
+ <div className="flex items-center gap-1.5 border-b border-[var(--color-hair)] px-3 py-1.5 text-xs text-[var(--color-phase-implement)]">
247
+ <Robot weight="light" size={14} />
248
+ {label}
249
+ </div>
250
+ <pre className="m-0 overflow-x-auto whitespace-pre-wrap px-3 py-2.5 font-mono text-xs leading-relaxed text-[var(--color-fg)]">{text}</pre>
251
+ </div>
252
+ );
253
+ }
254
+
255
+ /** Plain text of a hast node (the `node` react-markdown hands to overrides). */
256
+ function hastText(node) {
257
+ if (!node) return '';
258
+ if (node.type === 'text') return node.value || '';
259
+ return (node.children || []).map(hastText).join('');
260
+ }
261
+
262
+ function isDispatchBlock(text) {
263
+ const t = text.trimStart();
264
+ return t.startsWith('dispatch Agent') || t.includes('subagent_type');
265
+ }
266
+
267
+ const SKILL_MD_COMPONENTS = {
268
+ pre({ node, ...rest }) {
269
+ const text = hastText(node);
270
+ if (isDispatchBlock(text)) return <PromptBlock text={text.replace(/\n$/, '')} />;
271
+ return <pre {...rest} />;
272
+ },
273
+ };
274
+
275
+ function DispatchItem({ d }) {
276
+ const personas = d.personas || [];
277
+ return (
278
+ <li className="space-y-2 rounded-xl bg-white/[0.02] p-3 shadow-[inset_0_0_0_1px_var(--color-hair)]">
279
+ <div className="flex flex-wrap items-center gap-1.5 text-xs text-[var(--color-dim)]">
280
+ <span>Para</span>
281
+ {d.generic ? (
282
+ <span className="rounded-full px-2 py-0.5 font-mono text-xs text-[var(--color-fg)] shadow-[inset_0_0_0_1px_var(--color-hair-strong)]">
283
+ qualquer implementador (morph-{'{id}'})
284
+ </span>
285
+ ) : personas.length ? (
286
+ personas.map((p) => <EntityLink key={p} kind="persona" id={p} chip>{`morph-${p}`}</EntityLink>)
287
+ ) : d.builtin?.length ? (
288
+ d.builtin.map((b) => (
289
+ <span key={b} className="rounded-full px-2 py-0.5 font-mono text-xs text-[var(--color-fg)] shadow-[inset_0_0_0_1px_var(--color-hair-strong)]" title="sub-agent nativo do Claude Code, não uma persona do morph-spec">
290
+ {b}
291
+ </span>
292
+ ))
293
+ ) : (
294
+ <span>sub-agent não identificado</span>
295
+ )}
296
+ </div>
297
+ {d.context && (
298
+ <div className="text-sm text-[var(--color-dim)]">
299
+ <Markdown text={d.context} size="sm" />
300
+ </div>
301
+ )}
302
+ {d.text && <PromptBlock text={d.text} />}
303
+ </li>
304
+ );
305
+ }
306
+
307
+ export function SkillDetail({ skill, phases = morphData.phases?.list || [] }) {
308
+ const phaseId = skillPhaseOf(skill, phases);
309
+ const dispatches = skill.dispatches || [];
310
+ const stacks = skill.stacks || [];
311
+ const body = useMemo(() => splitFrontmatter(skill.content || '').body, [skill.content]);
312
+
313
+ return (
314
+ <div className="space-y-6 text-sm text-[var(--color-dim)]">
315
+ {skill.description && <p className="leading-relaxed text-[var(--color-fg)]">{skill.description}</p>}
316
+
317
+ <dl className="grid grid-cols-[max-content_1fr] gap-x-4 gap-y-2 rounded-xl bg-white/[0.03] px-4 py-3 shadow-[inset_0_0_0_1px_var(--color-hair)]">
318
+ {skill.whenToInvoke && (
319
+ <>
320
+ <dt className="text-xs leading-6 text-[var(--color-faint)]">Quando usar</dt>
321
+ <dd className="leading-6">{skill.whenToInvoke}</dd>
322
+ </>
323
+ )}
324
+ <dt className="text-xs leading-6 text-[var(--color-faint)]">Fase</dt>
325
+ <dd className="leading-6">
326
+ {phaseId
327
+ ? <EntityLink kind="phase" id={phaseId}>{phaseMeta(phaseId).label}</EntityLink>
328
+ : <span>Skill de apoio (não pertence a uma fase)</span>}
329
+ </dd>
330
+ <dt className="text-xs leading-6 text-[var(--color-faint)]">Invocação</dt>
331
+ <dd className="leading-6">
332
+ {skill.userInvocable
333
+ ? <>você pode rodar <code className="rounded bg-white/[0.06] px-1.5 py-0.5 font-mono text-xs text-[var(--color-fg)]">/{skill.id}</code></>
334
+ : 'interna: o orquestrador a carrega, você não a chama direto'}
335
+ </dd>
336
+ {stacks.length > 0 && (
337
+ <>
338
+ <dt className="text-xs leading-6 text-[var(--color-faint)]">Stacks</dt>
339
+ <dd className="flex flex-wrap gap-1.5 py-0.5">
340
+ {stacks.map((s) => (
341
+ <span key={s} className="rounded-full px-2 py-0.5 font-mono text-xs shadow-[inset_0_0_0_1px_var(--color-hair)]">{s}</span>
342
+ ))}
343
+ </dd>
344
+ </>
345
+ )}
346
+ {skill.allowedTools?.length > 0 && (
347
+ <>
348
+ <dt className="text-xs leading-6 text-[var(--color-faint)]">Ferramentas</dt>
349
+ <dd className="flex flex-wrap gap-1.5 py-0.5">
350
+ {skill.allowedTools.map((t) => (
351
+ <span key={t} className="rounded-full px-2 py-0.5 font-mono text-xs shadow-[inset_0_0_0_1px_var(--color-hair)]">{t}</span>
352
+ ))}
353
+ </dd>
354
+ </>
355
+ )}
356
+ </dl>
357
+
358
+ {dispatches.length > 0 && (
359
+ <Section title={`Prompts enviados a sub-agents (${dispatches.length})`}>
360
+ <ul className="space-y-3">
361
+ {dispatches.map((d) => <DispatchItem key={d.index} d={d} />)}
362
+ </ul>
363
+ </Section>
364
+ )}
365
+
366
+ {body.trim() && (
367
+ <Section title="SKILL.md completo">
368
+ <Markdown text={body} size="sm" components={SKILL_MD_COMPONENTS} />
369
+ </Section>
370
+ )}
371
+ </div>
372
+ );
373
+ }
374
+
375
+ // ─── Page ─────────────────────────────────────────────────────────────────────
376
+
377
+ export default function SkillsLibrary() {
378
+ const skills = morphData.skills || [];
379
+ const phases = morphData.phases?.list || [];
380
+ const agents = morphData.agents?.list || [];
381
+ const navigate = useNavigate();
382
+ const [sel, setSel] = useSelection();
383
+ const [search, setSearch] = useState('');
384
+ const [phaseFilter, setPhaseFilter] = useState('');
385
+ const [invokeFilter, setInvokeFilter] = useState('');
386
+
387
+ const phaseOptions = useMemo(() => [...phases.map((p) => phaseMeta(p.id).label), SUPPORT_LABEL], [phases]);
388
+
389
+ const isMatch = useCallback((s) => {
390
+ const q = search.trim().toLowerCase();
391
+ if (q) {
392
+ const hay = [s.id, s.name, s.description, s.whenToInvoke].filter(Boolean).join(' ').toLowerCase();
393
+ if (!hay.includes(q)) return false;
394
+ }
395
+ if (phaseFilter) {
396
+ const ph = skillPhaseOf(s, phases);
397
+ const label = ph ? phaseMeta(ph).label : SUPPORT_LABEL;
398
+ if (label !== phaseFilter) return false;
399
+ }
400
+ if (invokeFilter === INVOKE_YES && !s.userInvocable) return false;
401
+ if (invokeFilter === INVOKE_NO && s.userInvocable) return false;
402
+ return true;
403
+ }, [search, phaseFilter, invokeFilter, phases]);
404
+
405
+ const hasFilter = Boolean(search.trim() || phaseFilter || invokeFilter);
406
+ const matchCount = useMemo(() => skills.filter(isMatch).length, [skills, isMatch]);
407
+
408
+ const graph = useMemo(
409
+ () => buildGraph({ skills, phases, agents, isMatch, hasFilter }),
410
+ [skills, phases, agents, isMatch, hasFilter],
411
+ );
412
+ const dispatchingCount = skills.filter((s) => (s.dispatches || []).length > 0).length;
413
+
414
+ const selected = sel ? skills.find((s) => s.id === sel) : null;
415
+ const selectedPhase = selected ? skillPhaseOf(selected, phases) : null;
416
+ const close = useCallback(() => setSel(null), [setSel]);
417
+
418
+ const onNodeClick = useCallback((_e, node) => {
419
+ if (node.type === 'skillNode') setSel(node.data.skillId);
420
+ else if (node.type === 'phaseNode') navigate(entityHref('phase', node.data.phaseId));
421
+ else if (node.type === 'personaNode' && node.data.personaId) navigate(entityHref('persona', node.data.personaId));
422
+ }, [setSel, navigate]);
423
+
424
+ const filters = [
425
+ { name: 'phase', label: 'Fase', options: phaseOptions, value: phaseFilter },
426
+ { name: 'invoke', label: 'Invocação', options: [INVOKE_YES, INVOKE_NO], value: invokeFilter },
427
+ ];
428
+
429
+ return (
430
+ <div className="flex h-full flex-col">
431
+ <SearchFilter
432
+ placeholder="Buscar skill por nome, descrição ou quando usar"
433
+ filters={filters}
434
+ onSearchChange={setSearch}
435
+ onFilterChange={(name, value) => {
436
+ if (name === 'phase') setPhaseFilter(value);
437
+ if (name === 'invoke') setInvokeFilter(value);
438
+ }}
439
+ />
440
+
441
+ <div className="relative flex-1">
442
+ <FlowGraph nodes={graph.nodes} edges={graph.edges} nodeTypes={nodeTypes} onNodeClick={onNodeClick} fitView />
443
+
444
+ <div className="absolute left-3 top-3 z-10 space-y-2 rounded-xl bg-[var(--color-ink)]/85 p-3 text-xs text-[var(--color-dim)] shadow-[inset_0_0_0_1px_var(--color-hair)] backdrop-blur">
445
+ <p className="text-[13px] font-medium text-[var(--color-fg)]">Legenda</p>
446
+ <div className="flex items-center gap-2">
447
+ <span className="inline-block h-3 w-8 rounded" style={{ boxShadow: 'inset 0 0 0 1.5px var(--color-phase-plan)' }} />
448
+ fase → skill que a conduz
449
+ </div>
450
+ <div className="flex items-center gap-2">
451
+ <span className="inline-block h-3 w-8 rounded" style={{ boxShadow: `inset 0 0 0 1.5px ${SUPPORT_COLOR}` }} />
452
+ skill de apoio (sem fase)
453
+ </div>
454
+ <div className="flex items-center gap-2">
455
+ <span className="inline-block w-8 border-t-2 border-dashed" style={{ borderColor: PERSONA_COLOR }} />
456
+ skill → sub-agent que ela despacha
457
+ </div>
458
+ <div className="flex items-center gap-2">
459
+ <Terminal weight="light" size={13} className="ml-2.5 mr-2.5" />
460
+ você pode rodar com /nome
461
+ </div>
462
+ </div>
463
+
464
+ <div className="absolute right-3 top-3 z-10 space-y-0.5 rounded-xl bg-[var(--color-ink)]/85 px-3 py-2 text-xs text-[var(--color-dim)] shadow-[inset_0_0_0_1px_var(--color-hair)] backdrop-blur">
465
+ <div className="text-[13px] text-[var(--color-fg)]">
466
+ {hasFilter ? `${matchCount} de ${skills.length} skills` : `${skills.length} skills`}
467
+ </div>
468
+ <div>{graph.linkedCount} conduzem uma fase · {graph.supportCount} de apoio</div>
469
+ <div>{dispatchingCount} despacham sub-agents</div>
470
+ </div>
471
+ </div>
472
+
473
+ <DetailPanel
474
+ open={Boolean(selected)}
475
+ title={selected?.name || ''}
476
+ subtitle={selected ? (selectedPhase ? `Skill da fase ${phaseMeta(selectedPhase).label}` : 'Skill de apoio') : ''}
477
+ onClose={close}
478
+ >
479
+ {selected && <SkillDetail skill={selected} phases={phases} />}
480
+ </DetailPanel>
481
+ </div>
482
+ );
483
+ }