@polymorphism-tech/morph-spec 10.12.1 → 11.1.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 (323) hide show
  1. package/CLAUDE.md +27 -57
  2. package/README.md +53 -338
  3. package/bin/morph-spec.js +22 -373
  4. package/docs/CHEATSHEET.md +37 -166
  5. package/docs/QUICKSTART.md +14 -74
  6. package/framework/CLAUDE.md +15 -26
  7. package/framework/MORPH.md +34 -101
  8. package/framework/agents.json +12 -9
  9. package/framework/commands/morph-apply.md +5 -5
  10. package/framework/commands/morph-infra.md +1 -1
  11. package/framework/docs/CLI.md +74 -886
  12. package/framework/evals/review-checklist.md +14 -14
  13. package/framework/hooks/README.md +21 -189
  14. package/framework/hooks/claude-code/core/README.md +2 -5
  15. package/framework/hooks/claude-code/core/conventional-commit.js +2 -2
  16. package/framework/hooks/claude-code/core/denylist.json +3 -3
  17. package/framework/hooks/claude-code/core/graph-refresh-kick.js +2 -2
  18. package/framework/hooks/claude-code/core/masked-exit.js +6 -6
  19. package/framework/hooks/claude-code/core/pre-bash-denylist.js +2 -2
  20. package/framework/hooks/claude-code/core/protect-spec-files.js +17 -61
  21. package/framework/hooks/claude-code/core/stack-changed.js +35 -0
  22. package/framework/hooks/claude-code/core/validate-completion.js +32 -87
  23. package/framework/hooks/shared/{heavy-command.js → command-kind.js} +6 -79
  24. package/framework/hooks/shared/command-tokens.js +0 -139
  25. package/framework/hooks/shared/contract.js +14 -0
  26. package/framework/hooks/shared/feature-slug.js +21 -0
  27. package/framework/hooks/shared/frontend-locations.js +0 -1
  28. package/framework/hooks/shared/git-paths.js +0 -15
  29. package/framework/hooks/shared/graph-freshness.js +0 -19
  30. package/framework/hooks/shared/hook-response.js +0 -7
  31. package/framework/hooks/shared/morph-cli.js +2 -81
  32. package/framework/hooks/shared/owner-words.js +2 -120
  33. package/framework/hooks/shared/payload-utils.js +0 -39
  34. package/framework/hooks/shared/report-progress.js +7 -101
  35. package/framework/hooks/statusline.js +16 -60
  36. package/framework/mcp/registry.json +2 -2
  37. package/framework/rules/ai-agents-standards.md +1 -1
  38. package/framework/rules/asaas-standards.md +1 -1
  39. package/framework/rules/ef-standards.md +1 -1
  40. package/framework/rules/gsap-standards.md +1 -1
  41. package/framework/rules/hangfire-standards.md +1 -1
  42. package/framework/rules/implement-report.md +3 -3
  43. package/framework/rules/neon-auth-standards.md +1 -1
  44. package/framework/rules/nextjs-standards.md +1 -1
  45. package/framework/rules/plan-grammar.md +15 -13
  46. package/framework/rules/resend-standards.md +1 -1
  47. package/framework/rules/ui-design.md +5 -1
  48. package/framework/schemas/config.schema.json +95 -310
  49. package/framework/skills/README.md +12 -32
  50. package/framework/skills/core/create-umbraco-lp/SKILL.md +1 -1
  51. package/framework/skills/core/migrate-lp-to-umbraco/SKILL.md +1 -1
  52. package/framework/skills/core/morph-apply/SKILL.md +21 -46
  53. package/framework/skills/core/morph-plan/SKILL.md +28 -63
  54. package/framework/skills/core/morph-uiux/SKILL.md +23 -25
  55. package/framework/{templates/docs/ui-mockups.md → skills/core/morph-uiux/references/mockups.md} +4 -4
  56. package/framework/standards/STANDARDS.json +10 -11
  57. package/framework/standards/STANDARDS.meta.json +1 -1
  58. package/framework/standards/ai-agents/evals-with-cache.md +18 -32
  59. package/framework/standards/ai-agents/observability-patterns.md +2 -2
  60. package/framework/standards/architecture/code-comments.md +2 -5
  61. package/framework/standards/architecture/engineering-lens.md +1 -1
  62. package/framework/standards/backend/dotnet/testing.md +4 -4
  63. package/framework/standards/frontend/nextjs/lint.md +24 -10
  64. package/framework/standards/frontend/nextjs/testing.md +2 -2
  65. package/framework/standards/infrastructure/docker/local-compose-isolation.md +14 -30
  66. package/framework/templates/CLAUDE.md.core.guide.md +2 -2
  67. package/framework/templates/README.md +1 -1
  68. package/framework/templates/REGISTRY.json +3 -33
  69. package/framework/templates/docs/plan.md +3 -2
  70. package/framework/templates/dotnet/ai-kit/README.md +2 -4
  71. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalCacheMissException.cs +1 -1
  72. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalFixture.cs +1 -1
  73. package/package.json +1 -2
  74. package/src/commands/graph/explain.js +2 -1
  75. package/src/commands/graph/status.js +2 -1
  76. package/src/commands/mcp/mcp-setup.js +1 -2
  77. package/src/commands/project/doctor.js +13 -342
  78. package/src/commands/project/env.js +21 -52
  79. package/src/commands/project/init-contract.js +47 -0
  80. package/src/commands/project/init.js +36 -66
  81. package/src/commands/project/stack-scan.js +1 -1
  82. package/src/commands/project/update.js +16 -53
  83. package/src/commands/validation/check.js +128 -0
  84. package/src/commands/validation/plan-check.js +41 -64
  85. package/src/commands/validation/prove-red.js +1 -1
  86. package/src/core/paths/output-schema.js +0 -22
  87. package/src/core/templates/template-renderer.js +0 -14
  88. package/src/lib/ai/ai-project-scan.js +1 -6
  89. package/src/lib/check/attempts.js +38 -0
  90. package/src/lib/check/signals.js +145 -0
  91. package/src/lib/config/project-config.js +13 -0
  92. package/src/lib/contract/apply.js +62 -0
  93. package/src/lib/contract/defaults.js +96 -0
  94. package/src/lib/contract/merge.js +79 -0
  95. package/src/lib/contract/ports.js +43 -0
  96. package/src/lib/contract/scan.js +102 -0
  97. package/src/lib/detectors/claude-config-detector.js +7 -0
  98. package/src/lib/{procs → detectors}/mcp-config.js +1 -37
  99. package/src/lib/diff/diff-lines.js +64 -0
  100. package/src/lib/generators/architecture-scanner.js +1 -1
  101. package/src/lib/generators/scaffold-generator.js +0 -7
  102. package/src/lib/git/default-branch.js +0 -122
  103. package/src/lib/graph/diff-tree.js +2 -1
  104. package/src/lib/graph/god-nodes.js +2 -1
  105. package/src/lib/graph/graphify-runtime.js +0 -1
  106. package/src/lib/graph/graphifyignore.js +1 -1
  107. package/src/lib/graph/sanitize.js +2 -8
  108. package/src/lib/installers/memory-installer.js +15 -30
  109. package/src/lib/installers/stack-sync.js +16 -9
  110. package/src/lib/plan/checks.js +20 -64
  111. package/src/lib/plan/media.js +1 -1
  112. package/src/lib/plan/plan-parser.js +5 -5
  113. package/src/lib/review-reports.js +3 -77
  114. package/src/lib/scan/worktree-dirs.js +3 -0
  115. package/src/lib/specs/adr-index.js +2 -2
  116. package/src/lib/stack/dotnet-build-ignores.js +10 -2
  117. package/src/lib/stack/stack-scan.js +2 -2
  118. package/src/lib/stack-filter.js +3 -2
  119. package/src/lib/tests-audit/audit.js +1 -1
  120. package/src/scripts/setup-infra.js +6 -59
  121. package/src/utils/agents-installer.js +13 -37
  122. package/src/utils/atomic-json.js +27 -0
  123. package/src/utils/file-copier.js +24 -24
  124. package/src/utils/hooks-installer.js +9 -107
  125. package/claude-plugin.json +0 -14
  126. package/framework/commands/morph-archive.md +0 -46
  127. package/framework/commands/morph-hotfix.md +0 -17
  128. package/framework/commands/morph-preflight.md +0 -180
  129. package/framework/commands/morph-review.md +0 -15
  130. package/framework/commands/morph-status.md +0 -37
  131. package/framework/hooks/claude-code/core/block-destructive-worktree-removal.js +0 -80
  132. package/framework/hooks/claude-code/core/block-raw-worktree-add.js +0 -72
  133. package/framework/hooks/claude-code/core/enforce-phase-writes.js +0 -100
  134. package/framework/hooks/claude-code/core/gate-guard.js +0 -148
  135. package/framework/hooks/claude-code/core/heavy-gate.js +0 -78
  136. package/framework/hooks/claude-code/core/heavy-release.js +0 -23
  137. package/framework/hooks/claude-code/core/loop-detect.js +0 -79
  138. package/framework/hooks/claude-code/core/state-sync.js +0 -214
  139. package/framework/hooks/claude-code/core/telemetry-log.js +0 -259
  140. package/framework/hooks/claude-code/core/test-budget.js +0 -29
  141. package/framework/hooks/claude-code/core/worktree-context.js +0 -249
  142. package/framework/hooks/claude-code/core/worktree-create.js +0 -119
  143. package/framework/hooks/claude-code/core/worktree-env-inject.js +0 -68
  144. package/framework/hooks/claude-code/core/worktree-remove.js +0 -55
  145. package/framework/hooks/shared/build-check.js +0 -120
  146. package/framework/hooks/shared/claim-registry.js +0 -125
  147. package/framework/hooks/shared/e2e-check.js +0 -1022
  148. package/framework/hooks/shared/feature-locator.js +0 -82
  149. package/framework/hooks/shared/gate-event.js +0 -18
  150. package/framework/hooks/shared/gate-question.js +0 -20
  151. package/framework/hooks/shared/heavy-config.js +0 -113
  152. package/framework/hooks/shared/heavy-holders.js +0 -85
  153. package/framework/hooks/shared/heavy-slots.js +0 -280
  154. package/framework/hooks/shared/host-services.js +0 -440
  155. package/framework/hooks/shared/next-step.js +0 -181
  156. package/framework/hooks/shared/redact-secrets.js +0 -44
  157. package/framework/hooks/shared/reparse-scan.js +0 -40
  158. package/framework/hooks/shared/state-reader.js +0 -220
  159. package/framework/hooks/shared/state-writer.js +0 -112
  160. package/framework/hooks/shared/telemetry-logger.js +0 -101
  161. package/framework/hooks/shared/transcript-usage.js +0 -58
  162. package/framework/hooks/shared/worktree-root.js +0 -71
  163. package/framework/phases.json +0 -92
  164. package/framework/schemas/feature.schema.json +0 -242
  165. package/framework/skills/core/morph-apply/references/hotfix.md +0 -46
  166. package/framework/skills/core/morph-apply/references/machine.md +0 -30
  167. package/framework/skills/core/morph-apply/references/review.md +0 -77
  168. package/framework/skills/core/morph-plan/references/critique.md +0 -51
  169. package/framework/skills/core/morph-plan/references/interview.md +0 -37
  170. package/framework/templates/state.template.json +0 -17
  171. package/src/commands/dashboard/dashboard.js +0 -74
  172. package/src/commands/e2e/e2e.js +0 -400
  173. package/src/commands/observability/cost.js +0 -283
  174. package/src/commands/project/branch.js +0 -129
  175. package/src/commands/project/claim.js +0 -132
  176. package/src/commands/project/doctor-procs.js +0 -162
  177. package/src/commands/project/fleet.js +0 -66
  178. package/src/commands/project/heavy.js +0 -81
  179. package/src/commands/project/install-plugin-cmd.js +0 -27
  180. package/src/commands/project/status.js +0 -61
  181. package/src/commands/project/worktree.js +0 -1234
  182. package/src/commands/state/advance.js +0 -248
  183. package/src/commands/state/approve.js +0 -303
  184. package/src/commands/state/archive.js +0 -231
  185. package/src/commands/state/auto-approval.js +0 -67
  186. package/src/commands/state/create.js +0 -274
  187. package/src/commands/state/delete.js +0 -192
  188. package/src/commands/state/finish.js +0 -1247
  189. package/src/commands/state/gate-check.js +0 -244
  190. package/src/commands/state/gate-decision.js +0 -122
  191. package/src/commands/state/list.js +0 -244
  192. package/src/commands/state/next.js +0 -24
  193. package/src/commands/state/recap.js +0 -80
  194. package/src/commands/state/report-check.js +0 -244
  195. package/src/commands/state/retype.js +0 -110
  196. package/src/commands/validation/verify.js +0 -421
  197. package/src/core/state/feature-identity.js +0 -10
  198. package/src/core/state/gate-order.js +0 -23
  199. package/src/core/state/lifecycle-audit.js +0 -171
  200. package/src/core/state/state-manager.js +0 -523
  201. package/src/core/templates/template-seed.js +0 -21
  202. package/src/core/work-types.js +0 -44
  203. package/src/dashboard/app/App.jsx +0 -84
  204. package/src/dashboard/app/components/ActivityFeed.jsx +0 -166
  205. package/src/dashboard/app/components/CommandPalette.jsx +0 -144
  206. package/src/dashboard/app/components/DetailPanel.jsx +0 -43
  207. package/src/dashboard/app/components/EntityLink.jsx +0 -42
  208. package/src/dashboard/app/components/ErrorBoundary.jsx +0 -47
  209. package/src/dashboard/app/components/FlowGraph.jsx +0 -19
  210. package/src/dashboard/app/components/GatePauses.jsx +0 -116
  211. package/src/dashboard/app/components/KnowledgeMarkdown.jsx +0 -42
  212. package/src/dashboard/app/components/Markdown.jsx +0 -38
  213. package/src/dashboard/app/components/PhaseRail.jsx +0 -100
  214. package/src/dashboard/app/components/SearchFilter.jsx +0 -36
  215. package/src/dashboard/app/components/SessionMap.jsx +0 -77
  216. package/src/dashboard/app/components/Sidebar.jsx +0 -147
  217. package/src/dashboard/app/hooks/useMorphQuery.js +0 -44
  218. package/src/dashboard/app/hooks/usePref.js +0 -34
  219. package/src/dashboard/app/lib/format.js +0 -69
  220. package/src/dashboard/app/lib/phases.js +0 -75
  221. package/src/dashboard/app/lib/project.js +0 -38
  222. package/src/dashboard/app/main.jsx +0 -13
  223. package/src/dashboard/app/pages/Activity.jsx +0 -28
  224. package/src/dashboard/app/pages/AgentMap.jsx +0 -363
  225. package/src/dashboard/app/pages/FeatureDetail.jsx +0 -579
  226. package/src/dashboard/app/pages/Features.jsx +0 -393
  227. package/src/dashboard/app/pages/Guide.jsx +0 -145
  228. package/src/dashboard/app/pages/HookInspector.jsx +0 -444
  229. package/src/dashboard/app/pages/PhasePipeline.jsx +0 -273
  230. package/src/dashboard/app/pages/Portfolio.jsx +0 -190
  231. package/src/dashboard/app/pages/RulesMap.jsx +0 -285
  232. package/src/dashboard/app/pages/SkillsLibrary.jsx +0 -468
  233. package/src/dashboard/app/pages/Standards.jsx +0 -392
  234. package/src/dashboard/app/styles/index.css +0 -187
  235. package/src/dashboard/index.html +0 -14
  236. package/src/dashboard/package.json +0 -32
  237. package/src/dashboard/scanner/activity-scanner.js +0 -321
  238. package/src/dashboard/scanner/agents-scanner.js +0 -67
  239. package/src/dashboard/scanner/docs-scanner.js +0 -34
  240. package/src/dashboard/scanner/feature-status.js +0 -7
  241. package/src/dashboard/scanner/features-scanner.js +0 -397
  242. package/src/dashboard/scanner/hooks-scanner.js +0 -96
  243. package/src/dashboard/scanner/index.js +0 -21
  244. package/src/dashboard/scanner/phases-scanner.js +0 -14
  245. package/src/dashboard/scanner/portfolio.js +0 -129
  246. package/src/dashboard/scanner/project-api.js +0 -160
  247. package/src/dashboard/scanner/rules-scanner.js +0 -46
  248. package/src/dashboard/scanner/skills-scanner.js +0 -104
  249. package/src/dashboard/scanner/standards-scanner.js +0 -38
  250. package/src/dashboard/vite-plugin-morph-data.js +0 -120
  251. package/src/dashboard/vite.config.js +0 -26
  252. package/src/lib/ci/ci-verify.js +0 -30
  253. package/src/lib/ci/github-ci.js +0 -52
  254. package/src/lib/ci/pr-checks.js +0 -76
  255. package/src/lib/e2e/applicability.js +0 -39
  256. package/src/lib/e2e/compose-env.js +0 -80
  257. package/src/lib/e2e/stack-teardown.js +0 -96
  258. package/src/lib/git/branch-classifier.js +0 -104
  259. package/src/lib/git/evidence-staleness.js +0 -40
  260. package/src/lib/git/gh.js +0 -15
  261. package/src/lib/git/pending-prs.js +0 -58
  262. package/src/lib/git/pr-files.js +0 -31
  263. package/src/lib/git/pr-index.js +0 -39
  264. package/src/lib/git/tree-fingerprint.js +0 -58
  265. package/src/lib/git/tree-state.js +0 -125
  266. package/src/lib/heavy/cleanup.js +0 -72
  267. package/src/lib/heavy/gate.js +0 -168
  268. package/src/lib/heavy/live-stacks.js +0 -64
  269. package/src/lib/heavy/reclaim.js +0 -107
  270. package/src/lib/heavy/watchdog.js +0 -46
  271. package/src/lib/next-step.js +0 -12
  272. package/src/lib/plan/critique.js +0 -67
  273. package/src/lib/plan/plan-template.js +0 -18
  274. package/src/lib/procs/classify.js +0 -91
  275. package/src/lib/procs/list.js +0 -124
  276. package/src/lib/procs/prune.js +0 -47
  277. package/src/lib/procs/wslconfig.js +0 -70
  278. package/src/lib/projects/registry.js +0 -121
  279. package/src/lib/recap/piper.js +0 -36
  280. package/src/lib/recap/recap.js +0 -259
  281. package/src/lib/review-confirmation.js +0 -66
  282. package/src/lib/risk/diff-risk.js +0 -137
  283. package/src/lib/risk-detector.js +0 -638
  284. package/src/lib/specs/design-seed.js +0 -18
  285. package/src/lib/specs/screen-checklist.js +0 -315
  286. package/src/lib/stack/stack-profile.js +0 -69
  287. package/src/lib/tasks/eval-node.js +0 -293
  288. package/src/lib/tasks/linux-runner.js +0 -200
  289. package/src/lib/tasks/test-nodes.js +0 -414
  290. package/src/lib/tasks/test-runner.js +0 -569
  291. package/src/lib/telemetry/metrics.js +0 -384
  292. package/src/lib/telemetry/telemetry-reader.js +0 -276
  293. package/src/lib/telemetry/verify-event.js +0 -57
  294. package/src/lib/validators/code-budget/code-budget-validator.js +0 -170
  295. package/src/lib/validators/contracts/contract-compliance-validator.js +0 -219
  296. package/src/lib/validators/nextjs/next-component-validator.js +0 -142
  297. package/src/lib/validators/packages/package-validator.js +0 -310
  298. package/src/lib/validators/reuse/reuse-validator.js +0 -202
  299. package/src/lib/validators/reuse/symbol-scanner.js +0 -64
  300. package/src/lib/validators/validation-runner.js +0 -188
  301. package/src/lib/validators/verify-cache.js +0 -63
  302. package/src/lib/validators/verify-runner.js +0 -971
  303. package/src/lib/verify/affected.js +0 -143
  304. package/src/lib/verify/detached.js +0 -159
  305. package/src/lib/view/feature-html.js +0 -480
  306. package/src/lib/view/feature-page.client.js +0 -109
  307. package/src/lib/view/feature-page.css +0 -278
  308. package/src/lib/view/feature-view.js +0 -113
  309. package/src/lib/view/flow-layers.js +0 -79
  310. package/src/lib/view/flow-svg.js +0 -63
  311. package/src/lib/view/tokens.css +0 -18
  312. package/src/lib/work-type-detector.js +0 -81
  313. package/src/lib/worktree/dirs.js +0 -3
  314. package/src/lib/worktree/docker-audit.js +0 -175
  315. package/src/lib/worktree/env-allocator.js +0 -177
  316. package/src/lib/worktree/feature-truth.js +0 -145
  317. package/src/lib/worktree/finish-backup.js +0 -529
  318. package/src/lib/worktree/fleet-scanner.js +0 -223
  319. package/src/lib/worktree/ignored-triage.js +0 -136
  320. package/src/lib/worktree/vscode-settings.js +0 -112
  321. package/src/lib/worktree/worktree-audit.js +0 -323
  322. package/src/lib/worktree/worktree-include.js +0 -44
  323. package/src/scripts/install-plugin.js +0 -114
@@ -1,444 +0,0 @@
1
- import { useState, useMemo, useCallback } from 'react';
2
- import { Handle, Position, MarkerType } from '@xyflow/react';
3
- import { CaretDown, CaretRight } 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
-
9
- /** Colors are hex because the MiniMap cannot read CSS variables. */
10
- const EVENTS = {
11
- 'session-start': {
12
- label: 'Início da sessão', color: '#73daca',
13
- when: 'Dispara quando uma sessão do Claude Code começa, é retomada ou limpa.',
14
- power: 'Observa: não impede nada, mas pode injetar contexto na sessão.',
15
- },
16
- 'user-prompt': {
17
- label: 'Prompt do usuário', color: '#e0af68',
18
- when: 'Dispara quando o usuário envia uma mensagem, antes de o Claude processá-la.',
19
- power: 'Pode acrescentar contexto ao prompt ou barrá-lo.',
20
- },
21
- 'pre-tool-use': {
22
- label: 'Antes da ferramenta', color: '#7aa2f7', canBlock: true, toolEvent: true,
23
- when: 'Dispara antes de cada chamada de ferramenta que casa com o matcher (Bash, Write, Edit…).',
24
- power: 'Pode bloquear a chamada: a ferramenta não roda e o Claude recebe o motivo.',
25
- },
26
- 'post-tool-use': {
27
- label: 'Depois da ferramenta', color: '#bb9af7', toolEvent: true,
28
- when: 'Dispara depois que a ferramenta roda (inclui falhas e lotes de chamadas).',
29
- power: 'Observa o resultado: não desfaz a chamada, mas pode devolver um aviso ao Claude.',
30
- },
31
- stop: {
32
- label: 'Fim da resposta', color: '#f7768e',
33
- when: 'Dispara quando o Claude (ou um sub-agent) termina de responder.',
34
- power: 'Observa e valida; pode pedir que o Claude continue em vez de parar.',
35
- },
36
- 'pre-compact': {
37
- label: 'Antes de compactar', color: '#ff9e64',
38
- when: 'Dispara antes de o Claude Code compactar o histórico da conversa.',
39
- power: 'Observa: não impede a compactação.',
40
- },
41
- 'teammate-idle': {
42
- label: 'Colega ocioso', color: '#8d97a5',
43
- when: 'Dispara quando um colega de uma equipe de agentes fica ocioso.',
44
- power: 'Observa.',
45
- },
46
- 'worktree-create': {
47
- label: 'Criar worktree', color: '#9ece6a',
48
- when: 'Dispara quando o Claude Code cria uma worktree (claude -w, EnterWorktree, agente isolado).',
49
- power: 'Assume a criação: o morph-spec a delega ao próprio CLI.',
50
- },
51
- 'worktree-remove': {
52
- label: 'Remover worktree', color: '#ff9e64',
53
- when: 'Dispara quando o Claude Code remove uma worktree que ele criou.',
54
- power: 'Assume a remoção: o morph-spec a delega ao próprio CLI.',
55
- },
56
- unregistered: {
57
- label: 'Não registrados', color: '#5c6573',
58
- when: 'Arquivos de hook que o instalador não registra em nenhum evento.',
59
- power: 'Nunca disparam: estão no framework, mas fora da lista de hooks instalados.',
60
- },
61
- };
62
-
63
- function eventMeta(key) {
64
- return EVENTS[key] || { label: key, color: '#8d97a5', when: 'Evento sem descrição no dashboard.', power: '' };
65
- }
66
-
67
- /** A hook can register more than once under one event, so `?sel=` holds `event:name:matcher`. */
68
- export function hookKey(hook) {
69
- return `${hook.event}:${hook.name}:${hook.matcher || ''}`;
70
- }
71
-
72
- function findHook(hooks, sel) {
73
- if (!sel) return null;
74
- return hooks.find((h) => hookKey(h) === sel) || hooks.find((h) => h.name === sel) || null;
75
- }
76
-
77
- function matcherText(hook) {
78
- if (hook.matcher) return hook.matcher;
79
- return eventMeta(hook.event).toolEvent ? 'todas as ferramentas' : null;
80
- }
81
-
82
- const NODE_W = 280;
83
- const ROW_H = 26;
84
- const HEAD_H = 58;
85
- const nodeHeight = (count) => HEAD_H + Math.max(count, 1) * ROW_H;
86
-
87
- function EventGroupNode({ data }) {
88
- const { eventKey, hooks, onSelectHook, selectedKey } = data;
89
- const meta = eventMeta(eventKey);
90
-
91
- return (
92
- <div
93
- className="cursor-pointer select-none rounded-xl bg-[var(--color-raised)] px-3.5 py-3"
94
- style={{ width: NODE_W, boxShadow: `inset 0 0 0 1px var(--color-hair-strong), inset 3px 0 0 ${meta.color}` }}
95
- >
96
- <Handle type="target" position={Position.Left} style={{ background: meta.color, width: 8, height: 8, border: 'none' }} />
97
-
98
- <div className="mb-2 flex items-center justify-between gap-2">
99
- <span className="text-[13px] font-medium text-[var(--color-fg)]">{meta.label}</span>
100
- {meta.canBlock ? (
101
- <span className="rounded-full px-2 py-0.5 text-xs text-[var(--color-warn)] shadow-[inset_0_0_0_1px_var(--color-hair-strong)]">
102
- pode bloquear
103
- </span>
104
- ) : (
105
- <span className="text-xs text-[var(--color-faint)]">{hooks.length}</span>
106
- )}
107
- </div>
108
-
109
- {hooks.length === 0 ? (
110
- <p className="text-xs text-[var(--color-faint)]">Nenhum hook do morph-spec aqui.</p>
111
- ) : (
112
- <ul className="space-y-0.5">
113
- {hooks.map((h) => {
114
- const key = hookKey(h);
115
- const matcher = matcherText(h);
116
- return (
117
- <li key={key}>
118
- <button
119
- type="button"
120
- className="nodrag flex w-full items-center justify-between gap-2 rounded-md px-1.5 py-0.5 text-left text-xs transition-colors hover:bg-white/[0.06]"
121
- style={{ background: key === selectedKey ? 'rgb(255 255 255 / 0.08)' : undefined }}
122
- onClick={(e) => { e.stopPropagation(); onSelectHook(key); }}
123
- title={h.description || h.name}
124
- >
125
- <span className="truncate font-mono text-[var(--color-fg)]">{h.name}</span>
126
- {matcher && <span className="shrink-0 truncate font-mono text-[var(--color-dim)]" style={{ maxWidth: 110 }}>{matcher}</span>}
127
- </button>
128
- </li>
129
- );
130
- })}
131
- </ul>
132
- )}
133
-
134
- <Handle type="source" position={Position.Right} style={{ background: meta.color, width: 8, height: 8, border: 'none' }} />
135
- </div>
136
- );
137
- }
138
-
139
- function ToolNode() {
140
- return (
141
- <div className="cursor-pointer select-none rounded-xl bg-[var(--color-core)] px-5 py-3 text-center shadow-[inset_0_0_0_1px_var(--color-hair-strong)]" style={{ width: 150 }}>
142
- <Handle type="target" position={Position.Left} style={{ background: '#8d97a5', width: 8, height: 8, border: 'none' }} />
143
- <div className="text-sm font-medium text-[var(--color-fg)]">Ferramenta</div>
144
- <div className="mt-0.5 text-xs text-[var(--color-dim)]">executa</div>
145
- <Handle type="source" position={Position.Right} style={{ background: '#8d97a5', width: 8, height: 8, border: 'none' }} />
146
- </div>
147
- );
148
- }
149
-
150
- const nodeTypes = { eventGroupNode: EventGroupNode, toolNode: ToolNode };
151
-
152
- const COL_GAP = NODE_W + 90;
153
- const MAIN_ROW = ['session-start', 'user-prompt', 'pre-tool-use', '__tool__', 'post-tool-use'];
154
- const SIDE_ROW = ['worktree-create', 'worktree-remove', 'teammate-idle', 'unregistered'];
155
-
156
- function buildNodesAndEdges(hooksByEvent, onSelectHook, selectedKey) {
157
- const nodes = [];
158
- const edges = [];
159
- const hooksOf = (k) => hooksByEvent[k] || [];
160
-
161
- function addEventNode(eventKey, x, y) {
162
- nodes.push({
163
- id: eventKey,
164
- type: 'eventGroupNode',
165
- position: { x, y },
166
- data: { eventKey, hooks: hooksOf(eventKey), onSelectHook, selectedKey, color: eventMeta(eventKey).color },
167
- });
168
- }
169
-
170
- MAIN_ROW.forEach((key, i) => {
171
- if (key === '__tool__') {
172
- nodes.push({ id: '__tool__', type: 'toolNode', position: { x: i * COL_GAP + (NODE_W - 150) / 2, y: 20 }, data: { color: '#8d97a5' } });
173
- } else {
174
- addEventNode(key, i * COL_GAP, 0);
175
- }
176
- });
177
-
178
- const branchX = MAIN_ROW.length * COL_GAP;
179
- const stopH = nodeHeight(hooksOf('stop').length);
180
- addEventNode('stop', branchX, 0);
181
- addEventNode('pre-compact', branchX, stopH + 50);
182
-
183
- const mainBottom = Math.max(
184
- ...MAIN_ROW.filter((k) => k !== '__tool__').map((k) => nodeHeight(hooksOf(k).length)),
185
- stopH + 50 + nodeHeight(hooksOf('pre-compact').length),
186
- );
187
- const sideY = mainBottom + 110;
188
- const known = new Set([...MAIN_ROW, 'stop', 'pre-compact', ...SIDE_ROW]);
189
- const extra = Object.keys(hooksByEvent).filter((k) => !known.has(k));
190
- [...SIDE_ROW, ...extra].forEach((key, i) => addEventNode(key, i * COL_GAP, sideY));
191
-
192
- const solid = (id, source, target, color) => ({
193
- id, source, target, type: 'smoothstep',
194
- style: { stroke: color, strokeWidth: 1.8, opacity: 0.75 },
195
- markerEnd: { type: MarkerType.ArrowClosed, color },
196
- });
197
-
198
- edges.push(solid('e-ss-up', 'session-start', 'user-prompt', EVENTS['user-prompt'].color));
199
- edges.push(solid('e-up-ptu', 'user-prompt', 'pre-tool-use', EVENTS['pre-tool-use'].color));
200
- edges.push(solid('e-ptu-tool', 'pre-tool-use', '__tool__', '#8d97a5'));
201
- edges.push(solid('e-tool-pou', '__tool__', 'post-tool-use', EVENTS['post-tool-use'].color));
202
- edges.push(solid('e-pou-stop', 'post-tool-use', 'stop', EVENTS.stop.color));
203
- edges.push(solid('e-pou-compact', 'post-tool-use', 'pre-compact', EVENTS['pre-compact'].color));
204
- edges.push(solid('e-wt', 'worktree-create', 'worktree-remove', EVENTS['worktree-remove'].color));
205
- edges.push({
206
- id: 'e-loop', source: 'post-tool-use', target: 'user-prompt', type: 'smoothstep',
207
- style: { stroke: '#e0af68', strokeWidth: 1.4, strokeDasharray: '6 4', opacity: 0.7 },
208
- label: 'a conversa continua',
209
- labelStyle: { fill: '#e0af68', fontSize: 12 },
210
- labelBgStyle: { fill: '#12151b', fillOpacity: 0.9 },
211
- markerEnd: { type: MarkerType.ArrowClosed, color: '#e0af68' },
212
- });
213
-
214
- return { nodes, edges };
215
- }
216
-
217
- function Section({ title, children }) {
218
- return (
219
- <section>
220
- <h3 className="mb-2 text-xs font-medium text-[var(--color-faint)]">{title}</h3>
221
- {children}
222
- </section>
223
- );
224
- }
225
-
226
- function EventExplainer({ eventKey }) {
227
- const meta = eventMeta(eventKey);
228
- return (
229
- <div className="space-y-1.5 rounded-xl bg-white/[0.03] px-4 py-3 text-sm leading-relaxed shadow-[inset_0_0_0_1px_var(--color-hair)]">
230
- <p className="flex items-center gap-2 text-[var(--color-fg)]">
231
- <span className="inline-block h-2 w-2 shrink-0 rounded-full" style={{ background: meta.color }} />
232
- {meta.label}
233
- </p>
234
- <p className="text-[var(--color-dim)]">{meta.when}</p>
235
- {meta.power && <p className="text-[var(--color-dim)]">{meta.power}</p>}
236
- </div>
237
- );
238
- }
239
-
240
- function HookDetail({ hook, hookNames }) {
241
- const [showSource, setShowSource] = useState(false);
242
- const matcher = matcherText(hook);
243
-
244
- return (
245
- <div className="space-y-6 text-sm text-[var(--color-dim)]">
246
- <Section title="Quando roda">
247
- <EventExplainer eventKey={hook.event} />
248
- {hook.rawEvent && (
249
- <p className="mt-2 text-xs">Evento do Claude Code: <span className="font-mono text-[var(--color-fg)]">{hook.rawEvent}</span></p>
250
- )}
251
- </Section>
252
-
253
- {matcher && (
254
- <Section title="Ferramentas observadas">
255
- <code className="inline-block rounded-lg bg-white/[0.03] px-2.5 py-1 font-mono text-xs text-[var(--color-fg)] shadow-[inset_0_0_0_1px_var(--color-hair)]">{matcher}</code>
256
- </Section>
257
- )}
258
-
259
- {hook.description && (
260
- <Section title="O que faz">
261
- <p className="whitespace-pre-line leading-relaxed text-[var(--color-fg)]">{hook.description}</p>
262
- </Section>
263
- )}
264
-
265
- {hook.imports?.length > 0 && (
266
- <Section title="Importa">
267
- <div className="flex flex-wrap gap-1.5">
268
- {hook.imports.map((imp) => {
269
- const base = imp.split('/').pop().replace(/\.m?js$/, '');
270
- return hookNames.has(base) && base !== hook.name ? (
271
- <EntityLink key={imp} kind="hook" id={base} chip title={imp}>{base}</EntityLink>
272
- ) : (
273
- <span key={imp} title={imp} className="rounded-full px-2 py-0.5 font-mono text-[11px] text-[var(--color-dim)] shadow-[inset_0_0_0_1px_var(--color-hair)]">
274
- {imp}
275
- </span>
276
- );
277
- })}
278
- </div>
279
- </Section>
280
- )}
281
-
282
- <Section title="Código">
283
- <button
284
- type="button"
285
- onClick={() => setShowSource((v) => !v)}
286
- className="fluid flex w-full items-center gap-2 rounded-lg bg-white/[0.04] px-3 py-2 text-left text-xs text-[var(--color-fg)] shadow-[inset_0_0_0_1px_var(--color-hair)] transition-colors hover:bg-white/[0.07]"
287
- aria-expanded={showSource}
288
- >
289
- {showSource ? <CaretDown weight="light" size={14} /> : <CaretRight weight="light" size={14} />}
290
- <span className="font-mono">{hook.filename}</span>
291
- <span className="ml-auto text-[var(--color-faint)]">{showSource ? 'ocultar' : 'mostrar'}</span>
292
- </button>
293
- {showSource && (
294
- <pre className="mt-2 max-h-[28rem] overflow-auto rounded-lg bg-[var(--color-ink)] p-3 font-mono text-xs leading-relaxed text-[var(--color-dim)] shadow-[inset_0_0_0_1px_var(--color-hair)]">
295
- {hook.source}
296
- </pre>
297
- )}
298
- </Section>
299
- </div>
300
- );
301
- }
302
-
303
- function EventGroupDetail({ eventKey, hooks, onSelectHook }) {
304
- return (
305
- <div className="space-y-5 text-sm text-[var(--color-dim)]">
306
- <EventExplainer eventKey={eventKey} />
307
- <Section title={`${hooks.length} ${hooks.length === 1 ? 'hook registrado' : 'hooks registrados'}`}>
308
- {hooks.length === 0 ? (
309
- <p className="text-xs">O morph-spec não instala nenhum hook neste evento.</p>
310
- ) : (
311
- <ul className="space-y-2">
312
- {hooks.map((hook) => {
313
- const matcher = matcherText(hook);
314
- return (
315
- <li key={hookKey(hook)}>
316
- <button
317
- type="button"
318
- onClick={() => onSelectHook(hookKey(hook))}
319
- className="fluid w-full rounded-xl bg-white/[0.03] px-3.5 py-2.5 text-left shadow-[inset_0_0_0_1px_var(--color-hair)] transition-colors hover:bg-white/[0.06]"
320
- >
321
- <span className="flex items-center justify-between gap-2">
322
- <span className="font-mono text-xs text-[var(--color-fg)]">{hook.name}</span>
323
- {matcher && <span className="font-mono text-xs text-[var(--color-dim)]">{matcher}</span>}
324
- </span>
325
- {hook.description && (
326
- <span className="mt-1 line-clamp-2 block text-xs leading-snug">{hook.description}</span>
327
- )}
328
- </button>
329
- </li>
330
- );
331
- })}
332
- </ul>
333
- )}
334
- </Section>
335
- </div>
336
- );
337
- }
338
-
339
- function ToolDetail() {
340
- return (
341
- <div className="space-y-3 text-sm leading-relaxed text-[var(--color-dim)]">
342
- <p>
343
- A chamada de ferramenta que o Claude Code faz de fato: <span className="font-mono text-[var(--color-fg)]">Bash</span>,{' '}
344
- <span className="font-mono text-[var(--color-fg)]">Read</span>, <span className="font-mono text-[var(--color-fg)]">Edit</span> e as demais.
345
- </p>
346
- <p>
347
- Os hooks de antes da ferramenta rodam primeiro e podem bloqueá-la. Os de depois rodam com o resultado em mãos e só observam.
348
- </p>
349
- </div>
350
- );
351
- }
352
-
353
- export default function HookInspector() {
354
- const { hooks } = morphData;
355
- const [sel, setSel] = useSelection();
356
- // Event group and tool panels are local: only a hook has a shareable URL.
357
- const [aside, setAside] = useState(null);
358
-
359
- const hooksByEvent = useMemo(() => {
360
- const map = {};
361
- for (const hook of hooks) (map[hook.event] ||= []).push(hook);
362
- return map;
363
- }, [hooks]);
364
-
365
- const hookNames = useMemo(() => new Set(hooks.map((h) => h.name)), [hooks]);
366
- const selectedHook = findHook(hooks, sel);
367
- const selectedKey = selectedHook ? hookKey(selectedHook) : null;
368
-
369
- const { nodes, edges } = useMemo(
370
- () => buildNodesAndEdges(hooksByEvent, setSel, selectedKey),
371
- [hooksByEvent, setSel, selectedKey]
372
- );
373
-
374
- const handleNodeClick = useCallback((_event, node) => {
375
- if (node.type === 'toolNode') setAside({ type: 'tool' });
376
- else if (node.type === 'eventGroupNode') setAside({ type: 'event', key: node.data.eventKey });
377
- }, []);
378
-
379
- const closePanel = useCallback(() => {
380
- if (selectedHook) setSel(null);
381
- else setAside(null);
382
- }, [selectedHook, setSel]);
383
-
384
- const fileCount = hookNames.size;
385
- const registered = hooks.filter((h) => h.event !== 'unregistered').length;
386
- const unregistered = hooks.length - registered;
387
-
388
- let title = '';
389
- let subtitle;
390
- let content = null;
391
- if (selectedHook) {
392
- title = selectedHook.name;
393
- subtitle = [eventMeta(selectedHook.event).label, matcherText(selectedHook)].filter(Boolean).join(' · ');
394
- content = <HookDetail key={selectedKey} hook={selectedHook} hookNames={hookNames} />;
395
- } else if (aside?.type === 'event') {
396
- title = eventMeta(aside.key).label;
397
- subtitle = 'Evento do Claude Code';
398
- content = <EventGroupDetail eventKey={aside.key} hooks={hooksByEvent[aside.key] || []} onSelectHook={setSel} />;
399
- } else if (aside?.type === 'tool') {
400
- title = 'Ferramenta';
401
- subtitle = 'A chamada que os hooks cercam';
402
- content = <ToolDetail />;
403
- }
404
-
405
- return (
406
- <div className="flex h-full flex-col">
407
- <div className="flex shrink-0 flex-wrap items-center justify-between gap-3 border-b border-[var(--color-hair)] bg-[var(--color-ink)]/70 px-5 py-3 backdrop-blur">
408
- <div>
409
- <h1 className="text-base font-semibold leading-tight text-[var(--color-fg)]">Hooks</h1>
410
- <p className="mt-0.5 text-sm text-[var(--color-dim)]">
411
- {fileCount} {fileCount === 1 ? 'arquivo' : 'arquivos'}, {registered} {registered === 1 ? 'registro' : 'registros'} em eventos
412
- {unregistered > 0 ? `, ${unregistered} não ${unregistered === 1 ? 'registrado' : 'registrados'}` : ''}. Clique num hook para ler.
413
- </p>
414
- </div>
415
- <div className="flex flex-wrap gap-x-3 gap-y-1">
416
- {Object.entries(EVENTS).map(([key, { color, label }]) => (
417
- <span key={key} className="flex items-center gap-1.5 text-xs text-[var(--color-dim)]">
418
- <span className="inline-block h-2 w-2 rounded-full" style={{ background: color }} />
419
- {label}
420
- </span>
421
- ))}
422
- </div>
423
- </div>
424
-
425
- <div className="relative flex-1">
426
- <FlowGraph nodes={nodes} edges={edges} nodeTypes={nodeTypes} onNodeClick={handleNodeClick} fitView />
427
-
428
- <div className="absolute left-3 top-3 z-10 max-w-[240px] 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">
429
- <p className="text-[var(--color-faint)]">Como ler</p>
430
- <p>A linha de cima é a ordem de uma rodada: prompt, ferramenta, fim. A de baixo são eventos fora dessa rodada.</p>
431
- <p>À direita de cada hook, as ferramentas que ele observa.</p>
432
- <div className="flex items-center gap-2">
433
- <span className="inline-block w-5 border-t border-dashed" style={{ borderColor: '#e0af68' }} />
434
- <span>a conversa continua</span>
435
- </div>
436
- </div>
437
- </div>
438
-
439
- <DetailPanel open={Boolean(content)} title={title} subtitle={subtitle} onClose={closePanel}>
440
- {content}
441
- </DetailPanel>
442
- </div>
443
- );
444
- }