@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,408 +1,277 @@
1
- import { useCallback, useMemo } from 'react';
2
- import { Handle, Position } from '@xyflow/react';
3
- import morphData from 'virtual:morph-data';
4
- import FlowGraph from '../components/FlowGraph.jsx';
5
- import DetailPanel from '../components/DetailPanel.jsx';
6
- import { useDetailPanel } from '../hooks/useDetailPanel.js';
7
-
8
- // Phase color palette by phase id
9
- const PHASE_COLORS = {
10
- proposal: { bg: '#166534', border: '#22c55e', text: '#bbf7d0' },
11
- uiux: { bg: '#854d0e', border: '#f59e0b', text: '#fef3c7' },
12
- plan: { bg: '#7c2d12', border: '#fb923c', text: '#fed7aa' },
13
- implement: { bg: '#0e7490', border: '#22d3ee', text: '#cffafe' },
14
- review: { bg: '#6d28d9', border: '#a78bfa', text: '#ede9fe' },
15
- };
16
-
17
- const GATED_PHASES = new Set(['uiux', 'plan', 'review']);
18
-
19
- // Gate node: small gold square with "G" label
20
- function GateNode({ data }) {
21
- return (
22
- <div
23
- title={data.label}
24
- className="flex items-center justify-center rounded-sm select-none cursor-default"
25
- style={{
26
- width: 32,
27
- height: 32,
28
- background: '#78350f',
29
- border: '2px solid #f59e0b',
30
- boxShadow: '0 0 8px #f59e0b44',
31
- color: '#fef3c7',
32
- fontWeight: 700,
33
- fontSize: 12,
34
- }}
35
- >
36
- <Handle type="target" position={Position.Left} style={{ background: '#f59e0b', width: 7, height: 7 }} />
37
- G
38
- <Handle type="source" position={Position.Right} style={{ background: '#f59e0b', width: 7, height: 7 }} />
39
- </div>
40
- );
41
- }
42
-
43
- // Phase node: colored block with name and optional/index badge
44
- function PhaseNode({ data }) {
45
- const c = PHASE_COLORS[data.phaseId] || PHASE_COLORS.sync;
46
- const isOptional = data.optional;
47
-
48
- return (
49
- <div
50
- className="rounded-lg px-4 py-3 min-w-[140px] select-none cursor-pointer"
51
- style={{
52
- background: c.bg,
53
- border: `2px ${isOptional ? 'dashed' : 'solid'} ${c.border}`,
54
- boxShadow: `0 0 10px ${c.border}33`,
55
- }}
56
- >
57
- <Handle type="target" position={Position.Left} style={{ background: c.border, width: 8, height: 8 }} />
58
-
59
- <div className="text-white text-sm font-bold leading-tight">{data.label}</div>
60
- <div className="mt-1 text-[10px] font-medium" style={{ color: c.text }}>
61
- {isOptional ? 'optional' : `index: ${data.index}`}
62
- </div>
63
-
64
- <Handle type="source" position={Position.Right} style={{ background: c.border, width: 8, height: 8 }} />
65
- </div>
66
- );
67
- }
68
-
69
- const nodeTypes = { phaseNode: PhaseNode, gateNode: GateNode };
70
-
71
- // Build nodes + edges with manual horizontal layout
72
- function buildPipelineGraph(phases) {
73
- const nodes = [];
74
- const edges = [];
75
-
76
- // Layout constants
77
- const PHASE_W = 150;
78
- const PHASE_H = 68;
79
- const GATE_W = 32;
80
- const GATE_H = 32;
81
- const GAP = 60; // gap between a phase and the next gate / phase
82
- const Y_CENTER = 0;
83
-
84
- // Pre-compute x positions for each phase and its preceding gate (if gated)
85
- // Walk phases left to right, tracking current x cursor
86
- let cursorX = 0;
87
- const phaseLayout = []; // { phase, x, gateX? }
88
-
89
- for (const phase of phases) {
90
- if (GATED_PHASES.has(phase.id)) {
91
- // Insert gate before this phase
92
- const gateX = cursorX;
93
- cursorX += GATE_W + GAP;
94
- phaseLayout.push({ phase, x: cursorX, gateX });
95
- } else {
96
- phaseLayout.push({ phase, x: cursorX, gateX: null });
97
- }
98
- cursorX += PHASE_W + GAP;
99
- }
100
-
101
- // Build nodes
102
- for (const { phase, x, gateX } of phaseLayout) {
103
- const c = PHASE_COLORS[phase.id] || PHASE_COLORS.sync;
104
-
105
- // Gate node (if any)
106
- if (gateX !== null) {
107
- nodes.push({
108
- id: `gate-${phase.id}`,
109
- type: 'gateNode',
110
- data: { label: `Gate: ${phase.displayName}` },
111
- position: { x: gateX, y: Y_CENTER + (PHASE_H - GATE_H) / 2 },
112
- });
113
- }
114
-
115
- // Phase node
116
- nodes.push({
117
- id: phase.id,
118
- type: 'phaseNode',
119
- data: {
120
- label: phase.displayName,
121
- phaseId: phase.id,
122
- optional: phase.optional,
123
- index: phase.index,
124
- color: c.border,
125
- phaseRef: phase,
126
- },
127
- position: { x, y: Y_CENTER },
128
- });
129
- }
130
-
131
- // Build edges: chain gates and phases in sequence
132
- // sequence: ph0 → gate-ph1 → ph1 → gate-ph2 → ph2 → ...
133
- for (let i = 0; i < phaseLayout.length; i++) {
134
- const curr = phaseLayout[i];
135
- const next = phaseLayout[i + 1];
136
-
137
- if (!next) continue;
138
-
139
- const sourceId = curr.phase.id;
140
-
141
- if (next.gateX !== null) {
142
- // phase → gate → next-phase (two edges)
143
- edges.push({
144
- id: `edge-${sourceId}-gate-${next.phase.id}`,
145
- source: sourceId,
146
- target: `gate-${next.phase.id}`,
147
- type: 'smoothstep',
148
- style: { stroke: '#475569', strokeWidth: 1.8 },
149
- });
150
- edges.push({
151
- id: `edge-gate-${next.phase.id}-${next.phase.id}`,
152
- source: `gate-${next.phase.id}`,
153
- target: next.phase.id,
154
- type: 'smoothstep',
155
- style: { stroke: '#475569', strokeWidth: 1.8 },
156
- });
157
- } else {
158
- // phase → phase (no gate)
159
- edges.push({
160
- id: `edge-${sourceId}-${next.phase.id}`,
161
- source: sourceId,
162
- target: next.phase.id,
163
- type: 'smoothstep',
164
- style: { stroke: '#475569', strokeWidth: 1.8 },
165
- });
166
- }
167
- }
168
-
169
- return { nodes, edges };
170
- }
171
-
172
- // Detail panel content for a phase
173
- function PhaseDetail({ phase, agents }) {
174
- const c = PHASE_COLORS[phase.id] || PHASE_COLORS.sync;
175
- const isGated = GATED_PHASES.has(phase.id);
176
-
177
- // Agents active in this phase
178
- const activeAgents = agents.filter(
179
- (a) => a.activePhases?.includes(phase.id) || a.activePhases?.includes('*')
180
- );
181
-
182
- return (
183
- <div className="text-sm text-gray-200 space-y-5">
184
- {/* Phase badge + optional/gated indicators */}
185
- <div className="flex flex-wrap items-center gap-2">
186
- <span
187
- className="px-2 py-0.5 rounded text-xs font-bold"
188
- style={{ background: c.bg, color: c.text, border: `1px solid ${c.border}` }}
189
- >
190
- Phase {phase.index}
191
- </span>
192
- {phase.optional && (
193
- <span className="px-2 py-0.5 rounded text-xs bg-gray-800 border border-dashed border-gray-600 text-gray-400">
194
- optional
195
- </span>
196
- )}
197
- {isGated && (
198
- <span className="px-2 py-0.5 rounded text-xs bg-yellow-900/50 border border-yellow-600 text-yellow-300">
199
- approval gate
200
- </span>
201
- )}
202
- {phase.folder && (
203
- <span className="px-2 py-0.5 rounded text-xs font-mono bg-gray-800 border border-gray-700 text-gray-400">
204
- {phase.folder}
205
- </span>
206
- )}
207
- </div>
208
-
209
- {/* Goals */}
210
- {phase.goals?.length > 0 && (
211
- <div>
212
- <p className="text-gray-500 text-xs uppercase tracking-wide mb-2">Goals</p>
213
- <ul className="space-y-1.5">
214
- {phase.goals.map((g, i) => (
215
- <li key={i} className="flex gap-2 text-xs text-gray-300">
216
- <span className="text-gray-600 flex-shrink-0">•</span>
217
- {g}
218
- </li>
219
- ))}
220
- </ul>
221
- </div>
222
- )}
223
-
224
- {/* Required outputs */}
225
- {phase.requiredOutputs?.length > 0 && (
226
- <div>
227
- <p className="text-gray-500 text-xs uppercase tracking-wide mb-2">Required Outputs</p>
228
- <div className="flex flex-wrap gap-1">
229
- {phase.requiredOutputs.map((o) => (
230
- <span key={o} className="px-2 py-0.5 rounded text-xs bg-green-900/50 border border-green-700 text-green-300 font-mono">
231
- {o}
232
- </span>
233
- ))}
234
- </div>
235
- </div>
236
- )}
237
-
238
- {/* Optional outputs */}
239
- {phase.optionalOutputs?.length > 0 && (
240
- <div>
241
- <p className="text-gray-500 text-xs uppercase tracking-wide mb-2">Optional Outputs</p>
242
- <div className="flex flex-wrap gap-1">
243
- {phase.optionalOutputs.map((o) => (
244
- <span key={o} className="px-2 py-0.5 rounded text-xs bg-gray-800 border border-gray-700 text-gray-400 font-mono">
245
- {o}
246
- </span>
247
- ))}
248
- </div>
249
- </div>
250
- )}
251
-
252
- {/* Active agents */}
253
- {activeAgents.length > 0 && (
254
- <div>
255
- <p className="text-gray-500 text-xs uppercase tracking-wide mb-2">Active Agents ({activeAgents.length})</p>
256
- <div className="space-y-1">
257
- {activeAgents.map((a) => (
258
- <div key={a.id} className="flex items-center justify-between text-xs px-2 py-1 bg-gray-800 rounded">
259
- <span className="text-gray-200 font-medium truncate">{a.title}</span>
260
- <span className="text-gray-500 ml-2 flex-shrink-0">T{a.tier}</span>
261
- </div>
262
- ))}
263
- </div>
264
- </div>
265
- )}
266
-
267
- {/* Required skills */}
268
- {phase.requiredSkills?.length > 0 && (
269
- <div>
270
- <p className="text-gray-500 text-xs uppercase tracking-wide mb-2">Required Skills</p>
271
- <div className="space-y-1">
272
- {phase.requiredSkills.map((s, i) => (
273
- <div key={i} className="flex items-start gap-2 text-xs">
274
- <span className="px-1.5 py-0.5 rounded bg-pink-900/50 border border-pink-700 text-pink-300 font-mono flex-shrink-0">
275
- {s.trigger}
276
- </span>
277
- <span className="text-gray-300 font-mono">{s.skill}</span>
278
- </div>
279
- ))}
280
- </div>
281
- </div>
282
- )}
283
-
284
- {/* Recommended MCPs */}
285
- {phase.recommendedMCPs?.length > 0 && (
286
- <div>
287
- <p className="text-gray-500 text-xs uppercase tracking-wide mb-2">Recommended MCPs</p>
288
- <div className="flex flex-wrap gap-1">
289
- {phase.recommendedMCPs.map((m) => (
290
- <span key={m} className="px-2 py-0.5 rounded text-xs bg-blue-900/50 border border-blue-700 text-blue-300 font-mono">
291
- {m}
292
- </span>
293
- ))}
294
- </div>
295
- </div>
296
- )}
297
-
298
- {/* Pause points */}
299
- {phase.pausePoints?.length > 0 && (
300
- <div>
301
- <p className="text-gray-500 text-xs uppercase tracking-wide mb-2">Pause Points</p>
302
- <div className="space-y-1">
303
- {phase.pausePoints.map((pp) => (
304
- <div key={pp.id} className="flex items-center gap-2 text-xs px-2 py-1.5 bg-yellow-900/20 border border-yellow-700/50 rounded">
305
- <span className="text-yellow-400 flex-shrink-0">&#x1F512;</span>
306
- <span className="text-yellow-200">{pp.label}</span>
307
- </div>
308
- ))}
309
- </div>
310
- </div>
311
- )}
312
- </div>
313
- );
314
- }
315
-
316
- export default function PhasePipeline() {
317
- const { phases, agents } = morphData;
318
- const { panel, openPanel, closePanel } = useDetailPanel();
319
-
320
- const { nodes, edges } = useMemo(() => buildPipelineGraph(phases.list), [phases.list]);
321
-
322
- const handleNodeClick = useCallback(
323
- (_event, node) => {
324
- if (node.type === 'gateNode') {
325
- // Extract phase id from gate id ("gate-design" → "design")
326
- const phaseId = node.id.replace('gate-', '');
327
- const phase = phases.list.find((p) => p.id === phaseId);
328
- if (phase) {
329
- openPanel(`Gate: ${phase.displayName}`, (
330
- <div className="text-sm text-gray-300 space-y-3">
331
- <p className="text-yellow-300 text-xs">This gate requires explicit approval before the phase can begin.</p>
332
- <p className="text-gray-400 text-xs">Gate ID: <span className="font-mono text-gray-300">{phaseId}</span></p>
333
- </div>
334
- ));
335
- }
336
- return;
337
- }
338
-
339
- if (node.type === 'phaseNode') {
340
- const phase = node.data.phaseRef;
341
- if (phase) {
342
- openPanel(phase.displayName, (
343
- <PhaseDetail phase={phase} agents={agents.list} />
344
- ));
345
- }
346
- }
347
- },
348
- [openPanel, phases.list, agents.list]
349
- );
350
-
351
- return (
352
- <div className="flex flex-col h-full">
353
- {/* Header */}
354
- <div className="px-6 py-4 border-b border-gray-800 flex-shrink-0">
355
- <h1 className="text-white text-xl font-bold">Phase Pipeline</h1>
356
- <p className="text-gray-400 text-sm mt-0.5">
357
- Horizontal workflow of the 7 morph-spec phases. Gold gates mark required approval points. Dashed borders indicate optional phases.
358
- </p>
359
- </div>
360
-
361
- {/* Flow graph */}
362
- <div className="flex-1 relative">
363
- <FlowGraph
364
- nodes={nodes}
365
- edges={edges}
366
- nodeTypes={nodeTypes}
367
- onNodeClick={handleNodeClick}
368
- fitView
369
- />
370
-
371
- {/* Legend */}
372
- <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">
373
- <p className="text-gray-400 font-semibold uppercase tracking-wide text-[10px] mb-2">Legend</p>
374
- <div className="flex items-center gap-2">
375
- <span className="inline-block w-10 h-4 rounded-sm" style={{ background: '#166534', border: '2px solid #22c55e' }} />
376
- <span className="text-gray-300">Phase (solid = required)</span>
377
- </div>
378
- <div className="flex items-center gap-2">
379
- <span className="inline-block w-10 h-4 rounded-sm" style={{ background: '#854d0e', border: '2px dashed #f59e0b' }} />
380
- <span className="text-gray-300">Phase (dashed = optional)</span>
381
- </div>
382
- <div className="flex items-center gap-2">
383
- <span
384
- className="inline-flex items-center justify-center rounded-sm text-[10px] font-bold flex-shrink-0"
385
- style={{ width: 20, height: 20, background: '#78350f', border: '2px solid #f59e0b', color: '#fef3c7' }}
386
- >
387
- G
388
- </span>
389
- <span className="text-gray-300">Approval Gate</span>
390
- </div>
391
- <div className="flex items-center gap-2">
392
- <span className="inline-block w-6 border-t-2 border-gray-500" />
393
- <span className="text-gray-400">Sequence</span>
394
- </div>
395
- </div>
396
-
397
- {/* Phase count badge */}
398
- <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">
399
- {phases.list.length} phases · {phases.list.filter((p) => GATED_PHASES.has(p.id)).length} gates
400
- </div>
401
- </div>
402
-
403
- <DetailPanel open={panel.open} title={panel.title} onClose={closePanel}>
404
- {panel.content}
405
- </DetailPanel>
406
- </div>
407
- );
408
- }
1
+ import { useCallback, useMemo } from 'react';
2
+ import { Handle, Position } from '@xyflow/react';
3
+ import { SealCheck, Pause } from '@phosphor-icons/react';
4
+ import morphData from 'virtual:morph-data';
5
+ import FlowGraph from '../components/FlowGraph.jsx';
6
+ import DetailPanel from '../components/DetailPanel.jsx';
7
+ import EntityLink, { useSelection } from '../components/EntityLink.jsx';
8
+ import { phaseMeta, GATE_LABEL } from '../lib/phases.js';
9
+
10
+ const phaseColor = (id) => `var(--color-phase-${id})`;
11
+
12
+ /** What each approval gate checks, in the words a reader of the pipeline needs. */
13
+ const GATE_CHECKS = {
14
+ proposal: 'Confere o escopo da proposta: o problema, o que entra e o que fica de fora, antes de gastar esforço em design ou plano.',
15
+ uiux: 'Confere o design das telas (mockups e checklist de tela). É opcional: só existe quando a feature passa pela fase de UI/UX.',
16
+ plan: 'Confere a spec, as tasks e o plano de implementação. Depois dele a spec congela e a implementação começa.',
17
+ review: 'Confere a avaliação independente: um avaliador em contexto novo dá o score, que precisa ser pelo menos 9, com o verify verde.',
18
+ };
19
+
20
+ const GATE_PREFIX = 'gate-';
21
+ const gateId = (phaseId) => `${GATE_PREFIX}${phaseId}`;
22
+ const hasGate = (phaseId) => Object.prototype.hasOwnProperty.call(GATE_LABEL, phaseId);
23
+
24
+ function GateNode({ data }) {
25
+ return (
26
+ <div
27
+ title={data.label}
28
+ className="fluid flex cursor-pointer select-none items-center gap-1.5 rounded-full bg-[var(--color-raised)] px-3 py-1.5 text-[12px] font-medium text-[var(--color-warn)] transition-shadow"
29
+ style={{ boxShadow: data.selected ? '0 0 0 2px var(--color-warn)' : 'inset 0 0 0 1px var(--color-warn)' }}
30
+ >
31
+ <Handle type="target" position={Position.Left} style={{ background: 'var(--color-warn)', width: 6, height: 6, border: 0 }} />
32
+ <SealCheck weight="light" size={15} />
33
+ {data.label}
34
+ <Handle type="source" position={Position.Right} style={{ background: 'var(--color-warn)', width: 6, height: 6, border: 0 }} />
35
+ </div>
36
+ );
37
+ }
38
+
39
+ function PhaseNode({ data }) {
40
+ const color = phaseColor(data.phaseId);
41
+ return (
42
+ <div
43
+ className="fluid cursor-pointer select-none rounded-xl bg-[var(--color-raised)] px-4 py-3 transition-shadow"
44
+ style={{
45
+ width: PHASE_W,
46
+ border: `1.5px ${data.optional ? 'dashed' : 'solid'} ${color}`,
47
+ boxShadow: data.selected ? `0 0 0 2px ${color}` : 'none',
48
+ }}
49
+ >
50
+ <Handle type="target" position={Position.Left} style={{ background: color, width: 7, height: 7, border: 0 }} />
51
+ <div className="text-[14px] font-semibold leading-tight text-[var(--color-fg)]">{data.label}</div>
52
+ <div className="mt-1 text-[12px] text-[var(--color-dim)]">
53
+ {data.optional ? 'opcional' : `fase ${data.position}`}
54
+ {data.skill ? ` · ${data.skill}` : ''}
55
+ </div>
56
+ <Handle type="source" position={Position.Right} style={{ background: color, width: 7, height: 7, border: 0 }} />
57
+ </div>
58
+ );
59
+ }
60
+
61
+ const nodeTypes = { phaseNode: PhaseNode, gateNode: GateNode };
62
+
63
+ const PHASE_W = 200;
64
+ const PHASE_H = 64;
65
+ const GATE_W = 150;
66
+ const GATE_H = 32;
67
+ const GAP = 48;
68
+
69
+ /** Left to right: each phase, then its gate (when it has one), then the next phase. */
70
+ function buildPipelineGraph(phases, sel) {
71
+ const nodes = [];
72
+ const edges = [];
73
+ const edge = (source, target) => edges.push({
74
+ id: `e-${source}-${target}`, source, target, type: 'smoothstep',
75
+ style: { stroke: 'var(--color-hair-strong)', strokeWidth: 1.5 },
76
+ });
77
+
78
+ let x = 0;
79
+ let prev = null;
80
+ phases.forEach((phase, i) => {
81
+ nodes.push({
82
+ id: phase.id,
83
+ type: 'phaseNode',
84
+ data: {
85
+ label: phaseMeta(phase.id).label,
86
+ phaseId: phase.id,
87
+ optional: phase.optional,
88
+ position: i + 1,
89
+ skill: phase.skill || null,
90
+ color: phaseColor(phase.id),
91
+ selected: sel === phase.id,
92
+ },
93
+ position: { x, y: 0 },
94
+ });
95
+ if (prev) edge(prev, phase.id);
96
+ prev = phase.id;
97
+ x += PHASE_W + GAP;
98
+
99
+ if (hasGate(phase.id)) {
100
+ const id = gateId(phase.id);
101
+ nodes.push({
102
+ id,
103
+ type: 'gateNode',
104
+ data: { label: GATE_LABEL[phase.id], color: 'var(--color-warn)', selected: sel === id },
105
+ position: { x, y: (PHASE_H - GATE_H) / 2 },
106
+ });
107
+ edge(prev, id);
108
+ prev = id;
109
+ x += GATE_W + GAP;
110
+ }
111
+ });
112
+ return { nodes, edges };
113
+ }
114
+
115
+ function Section({ title, children }) {
116
+ return (
117
+ <section>
118
+ <h3 className="mb-2 text-xs font-medium text-[var(--color-faint)]">{title}</h3>
119
+ {children}
120
+ </section>
121
+ );
122
+ }
123
+
124
+ function Chip({ children }) {
125
+ return (
126
+ <span className="inline-flex items-center rounded-full px-2 py-0.5 font-mono text-[12px] text-[var(--color-dim)] shadow-[inset_0_0_0_1px_var(--color-hair)]">
127
+ {children}
128
+ </span>
129
+ );
130
+ }
131
+
132
+ // Exported for the render smoke test: no page state, only the phase and the personas.
133
+ export function PhaseDetail({ phase, agents }) {
134
+ const color = phaseColor(phase.id);
135
+ // Personas this phase's skill dispatches (derived by the agents scanner).
136
+ const activeAgents = agents.filter((a) => a.activePhases?.includes(phase.id));
137
+
138
+ return (
139
+ <div className="space-y-6 text-sm text-[var(--color-fg)]">
140
+ <div className="flex flex-wrap items-center gap-2">
141
+ <span className="inline-block h-2.5 w-2.5 rounded-full" style={{ background: color }} />
142
+ {phase.optional && <Chip>opcional</Chip>}
143
+ {hasGate(phase.id) && <EntityLink kind="phase" id={gateId(phase.id)} chip>{GATE_LABEL[phase.id]}</EntityLink>}
144
+ {phase.folder && <Chip>{phase.folder}/</Chip>}
145
+ </div>
146
+
147
+ {phase.skill && (
148
+ <Section title="Skill que conduz a fase">
149
+ <EntityLink kind="skill" id={phase.skill} chip>{phase.skill}</EntityLink>
150
+ </Section>
151
+ )}
152
+
153
+ {phase.goals?.length > 0 && (
154
+ <Section title="Objetivos">
155
+ <ul className="list-disc space-y-1.5 pl-5 text-[var(--color-dim)]">
156
+ {phase.goals.map((g, i) => <li key={i}>{g}</li>)}
157
+ </ul>
158
+ </Section>
159
+ )}
160
+
161
+ {(phase.requiredOutputs?.length > 0 || phase.optionalOutputs?.length > 0) && (
162
+ <Section title="Artefatos que a fase produz">
163
+ <div className="space-y-2">
164
+ {phase.requiredOutputs?.length > 0 && (
165
+ <div className="flex flex-wrap items-center gap-1.5">
166
+ <span className="mr-1 text-[12px] text-[var(--color-dim)]">Obrigatórios:</span>
167
+ {phase.requiredOutputs.map((o) => <Chip key={o}>{o}</Chip>)}
168
+ </div>
169
+ )}
170
+ {phase.optionalOutputs?.length > 0 && (
171
+ <div className="flex flex-wrap items-center gap-1.5">
172
+ <span className="mr-1 text-[12px] text-[var(--color-dim)]">Opcionais:</span>
173
+ {phase.optionalOutputs.map((o) => <Chip key={o}>{o}</Chip>)}
174
+ </div>
175
+ )}
176
+ </div>
177
+ </Section>
178
+ )}
179
+
180
+ <Section title={`Personas despachadas (${activeAgents.length})`}>
181
+ {activeAgents.length > 0 ? (
182
+ <ul className="space-y-1">
183
+ {activeAgents.map((a) => (
184
+ <li key={a.id} className="flex items-center justify-between gap-3 rounded-lg bg-white/[0.03] px-3 py-1.5">
185
+ <EntityLink kind="persona" id={a.id}>{a.title}</EntityLink>
186
+ <span className="shrink-0 font-mono text-[12px] text-[var(--color-faint)]">morph-{a.id}</span>
187
+ </li>
188
+ ))}
189
+ </ul>
190
+ ) : (
191
+ <p className="text-[var(--color-dim)]">A thread principal conduz esta fase sem despachar persona.</p>
192
+ )}
193
+ </Section>
194
+
195
+ {phase.pausePoints?.length > 0 && (
196
+ <Section title="Pontos de pausa">
197
+ <ul className="space-y-1">
198
+ {phase.pausePoints.map((pp) => (
199
+ <li key={pp.id} className="flex items-center gap-2 rounded-lg bg-white/[0.03] px-3 py-1.5 text-[var(--color-dim)]">
200
+ <Pause weight="light" size={14} className="shrink-0 text-[var(--color-warn)]" />
201
+ {pp.label}
202
+ </li>
203
+ ))}
204
+ </ul>
205
+ </Section>
206
+ )}
207
+
208
+ {phase.recommendedMCPs?.length > 0 && (
209
+ <Section title="Servidores MCP recomendados">
210
+ <div className="flex flex-wrap gap-1.5">
211
+ {phase.recommendedMCPs.map((m) => <Chip key={m}>{m}</Chip>)}
212
+ </div>
213
+ </Section>
214
+ )}
215
+ </div>
216
+ );
217
+ }
218
+
219
+ function GateDetail({ phase }) {
220
+ return (
221
+ <div className="space-y-5 text-sm text-[var(--color-dim)]">
222
+ <p>{GATE_CHECKS[phase.id] || 'Ponto de aprovação ao fim desta fase.'}</p>
223
+ <p>
224
+ Fica ao fim da fase <EntityLink kind="phase" id={phase.id}>{phaseMeta(phase.id).label}</EntityLink>.
225
+ Com trust <code className="font-mono text-[var(--color-fg)]">auto</code> (o padrão) o gate passa sozinho,
226
+ a menos que um sinal de risco o pause; aí a decisão volta para você. Com trust <code className="font-mono text-[var(--color-fg)]">manual</code> ele
227
+ sempre espera a sua aprovação.
228
+ </p>
229
+ </div>
230
+ );
231
+ }
232
+
233
+ export default function PhasePipeline() {
234
+ const { phases, agents } = morphData;
235
+ const [sel, setSel] = useSelection();
236
+
237
+ const { nodes, edges } = useMemo(() => buildPipelineGraph(phases.list, sel), [phases.list, sel]);
238
+ const gateCount = phases.list.filter((p) => hasGate(p.id)).length;
239
+
240
+ const handleNodeClick = useCallback((_event, node) => setSel(node.id), [setSel]);
241
+ const close = useCallback(() => setSel(null), [setSel]);
242
+
243
+ const gatePhase = sel?.startsWith(GATE_PREFIX)
244
+ ? phases.list.find((p) => gateId(p.id) === sel && hasGate(p.id)) || null
245
+ : null;
246
+ const phase = gatePhase ? null : phases.list.find((p) => p.id === sel) || null;
247
+
248
+ let title = '';
249
+ let subtitle;
250
+ if (phase) { title = phaseMeta(phase.id).label; subtitle = phase.optional ? 'Fase opcional' : 'Fase'; }
251
+ if (gatePhase) { title = GATE_LABEL[gatePhase.id]; subtitle = 'Ponto de aprovação'; }
252
+
253
+ return (
254
+ <div className="flex h-full flex-col">
255
+ <div className="shrink-0 border-b border-[var(--color-hair)] px-6 py-4">
256
+ <h1 className="text-xl font-semibold tracking-tight text-[var(--color-fg)]">Fases</h1>
257
+ <p className="mt-0.5 text-sm text-[var(--color-dim)]">
258
+ O caminho de uma feature: {phases.list.length} fases, com {gateCount} pontos de aprovação.
259
+ Borda tracejada marca fase opcional. Clique numa fase ou num gate para ver os detalhes.
260
+ </p>
261
+ </div>
262
+
263
+ <div className="relative flex-1">
264
+ <FlowGraph nodes={nodes} edges={edges} nodeTypes={nodeTypes} onNodeClick={handleNodeClick} fitView />
265
+
266
+ <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)]">
267
+ {phases.list.length} fases · {gateCount} gates
268
+ </div>
269
+ </div>
270
+
271
+ <DetailPanel open={Boolean(phase || gatePhase)} title={title} subtitle={subtitle} onClose={close}>
272
+ {phase && <PhaseDetail key={phase.id} phase={phase} agents={agents.list} />}
273
+ {gatePhase && <GateDetail phase={gatePhase} />}
274
+ </DetailPanel>
275
+ </div>
276
+ );
277
+ }