@polymorphism-tech/morph-spec 10.12.1 → 11.0.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 +51 -340
  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 +8 -8
  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 +13 -11
  46. package/framework/rules/resend-standards.md +1 -1
  47. package/framework/rules/ui-design.md +4 -0
  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 +5 -341
  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 +15 -50
  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 +1 -34
  122. package/src/utils/atomic-json.js +27 -0
  123. package/src/utils/file-copier.js +4 -12
  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,143 +0,0 @@
1
- import { execFileSync } from 'node:child_process';
2
- import { readFileSync } from 'node:fs';
3
- import { basename, extname, join } from 'node:path';
4
- import { changedPathsAgainst, detectDefaultBranch } from '../git/default-branch.js';
5
- import { resolveBaseRef } from '../git/branch-classifier.js';
6
- import { contractsTouched, migrationsTouched } from '../risk-detector.js';
7
- import { isTestFile } from '../validators/reuse/symbol-scanner.js';
8
-
9
- const MAX_TEST_CLASSES = 40;
10
- const INLINE_FILTER = /(^|\s)(--filter|-Filter)\s+(?:"([^"]*)"|(\S+))/i;
11
- const SCRIPT_IN_COMMAND = /([\w./\\-]+\.(?:ps1|sh))\b/i;
12
- const PS_FILTER_PARAM = /\[string\]\s*\$Filter\b(?:\s*=\s*['"]([^'"]*)['"])?/i;
13
- const PS_FILTER_USED = /dotnet\s+test[^\n]*\$Filter\b/i;
14
- const FORWARDS_ARGS = /dotnet\s+test[^\n]*("?\$@"?|\$\{@\}|@args|\$args)/i;
15
- const EVAL_NODE =/(^|[-_])evals?($|[-_])/i;
16
- const DOC_PATH =/\.(md|mdx|txt|png|jpe?g|gif|svg|webp)$/i;
17
- const DOTNET_SOURCE = /\.(cs|razor|cshtml)$/i;
18
- const SCRIPT_SOURCE = /\.(tsx?|jsx?|mjs|cjs|css|json)$/i;
19
- // Everything compiles or resolves through these, so the diff says nothing about what they reach.
20
- const WIDE_PATH = /(^|\/)(package(-lock)?\.json|pnpm-lock\.yaml|yarn\.lock|global\.json|Directory\.(Build|Packages)\.(props|targets)|tsconfig[^/]*\.json|vitest\.config\.[^/]+|[^/]+\.(csproj|sln|slnx))$/i;
21
-
22
- const defaultGit = (args, cwd) => execFileSync('git', args, { cwd, stdio: 'pipe' }).toString();
23
-
24
- function mergeBase(baseRef, cwd, git) {
25
- try {
26
- return git(['merge-base', 'HEAD', baseRef], cwd).trim() || null;
27
- } catch {
28
- return null;
29
- }
30
- }
31
-
32
- function testFilesNaming(names, cwd, git) {
33
- if (names.length === 0) return [];
34
- try {
35
- const output = git(['grep', '-lw', ...names.flatMap((n) => ['-e', n]), '--', '*.cs'], cwd);
36
- return output.split(/\r?\n/).filter((path) => path && isTestFile(path));
37
- } catch {
38
- // git grep exits 1 when nothing matches.
39
- return [];
40
- }
41
- }
42
-
43
- const classOf = (path) => basename(path, extname(path));
44
-
45
- const readText = (path) => {
46
- try {
47
- return readFileSync(path, 'utf8');
48
- } catch {
49
- return null;
50
- }
51
- };
52
-
53
- /** Reads the wrapper the command calls, so a project gets the narrowing without declaring anything. */
54
- function scriptFilter(node, cwd, read) {
55
- const script = SCRIPT_IN_COMMAND.exec(node.command ?? '')?.[1];
56
- const text = script ? read(join(cwd, node.cwd ?? '.', script)) : null;
57
- if (!text) return null;
58
- if (PS_FILTER_USED.test(text)) {
59
- const param = PS_FILTER_PARAM.exec(text);
60
- if (param) return { flag: '-Filter', baseFilter: param[1] ?? null };
61
- }
62
- return FORWARDS_ARGS.test(text) ? { flag: '--filter' } : null;
63
- }
64
-
65
- function narrowDotnet(node, classes, cwd, read) {
66
- const selected = classes.map((c) => `FullyQualifiedName~${c}`).join('|');
67
- const inline = INLINE_FILTER.exec(node.command ?? '');
68
- if (inline) {
69
- const [whole, lead, flag, quoted, bare] = inline;
70
- return node.command.replace(whole, `${lead}${flag} "(${quoted ?? bare})&(${selected})"`);
71
- }
72
- const plain = /\bdotnet\s+test\b/.test(node.command ?? '') ? { flag: '--filter' } : null;
73
- const how = node.affected ?? plain ?? scriptFilter(node, cwd, read);
74
- if (!how) return null;
75
- const filter = how.baseFilter ? `(${how.baseFilter})&(${selected})` : selected;
76
- return `${node.command} ${how.flag} "${filter}"`;
77
- }
78
-
79
- function selectDotnet(node, relevant, cwd, git, read) {
80
- const tests = relevant.filter(isTestFile);
81
- const sources = relevant.filter((p) => !isTestFile(p)).map(classOf);
82
- const classes = [...new Set([...tests, ...testFilesNaming(sources, cwd, git)].map(classOf))].sort();
83
- if (classes.length === 0) return { skip: true };
84
- if (classes.length > MAX_TEST_CLASSES) return { wide: classes.length };
85
- const command = narrowDotnet(node, classes, cwd, read);
86
- // A command nothing can narrow runs whole, as it would without this.
87
- return command ? { node: { ...node, command, allowEmpty: true }, classes } : { node };
88
- }
89
-
90
- function selectVitest(node, base) {
91
- return { node: { ...node, command: `${node.command} --changed ${base} --passWithNoTests`, allowEmpty: true } };
92
- }
93
-
94
- function selectNode(node, { changed, base, cwd, git, read }) {
95
- // A project may run its evals as a plain dotnet node: they cost money, so the name counts too.
96
- if (node.e2e || node.evals || EVAL_NODE.test(node.id ?? '')) return { skip: true };
97
- const prefix = node.cwd && node.cwd !== '.' ? `${node.cwd.replace(/\\/g, '/').replace(/\/$/, '')}/` : '';
98
- const inside = changed.filter((p) => p.startsWith(prefix));
99
- if (node.runner === 'dotnet') {
100
- const relevant = inside.filter((p) => DOTNET_SOURCE.test(p));
101
- return relevant.length ? selectDotnet(node, relevant, cwd, git, read) : { skip: true };
102
- }
103
- // A generic runner (`none`, a script) tests whatever the project says it does: any code in its cwd reaches it.
104
- const generic = !node.runner || node.runner === 'none';
105
- const relevant = generic ? inside : inside.filter((p) => SCRIPT_SOURCE.test(p));
106
- if (relevant.length === 0) return { skip: true };
107
- return node.runner === 'vitest' ? selectVitest(node, base) : { node };
108
- }
109
-
110
- /** @returns {{ scope: 'full', reason: string } | { scope: 'affected', base: string, docsOnly: boolean, nodes: object[], skipped: string[] }} */
111
- export function selectAffected({ projectPath, nodes, deps = {} }) {
112
- const {
113
- git = defaultGit, changedPaths = changedPathsAgainst, read = readText,
114
- baseRefOf = (p) => resolveBaseRef(detectDefaultBranch(p), p),
115
- } = deps;
116
- const baseRef = baseRefOf(projectPath);
117
- const base = baseRef ? mergeBase(baseRef, projectPath, git) : null;
118
- if (!base) return { scope: 'full', reason: 'sem base de comparação com a branch padrão' };
119
-
120
- const changed = changedPaths(base, projectPath)
121
- .map((p) => p.replace(/\\/g, '/'))
122
- .filter((p) => !p.startsWith('.morph/'));
123
-
124
- const migration = migrationsTouched(changed);
125
- if (migration.length) return { scope: 'full', reason: `migration tocada: ${migration[0]}` };
126
- const contract = contractsTouched(changed);
127
- if (contract.length) return { scope: 'full', reason: `contrato tocado: ${contract[0]}` };
128
- // A test project's own file reaches only tests, which the complete run still covers.
129
- const wide = changed.find((p) => WIDE_PATH.test(p) && !isTestFile(p));
130
- if (wide) return { scope: 'full', reason: `arquivo que alcança o projeto inteiro: ${wide}` };
131
-
132
- const code = changed.filter((p) => !DOC_PATH.test(p));
133
- const context = { changed: code, base, cwd: projectPath, git, read };
134
- const selected = [];
135
- const skipped = [];
136
- for (const node of nodes) {
137
- const choice = selectNode(node, context);
138
- if (choice.wide) return { scope: 'full', reason: `código compartilhado: ${choice.wide} classes de teste alcançadas` };
139
- if (choice.skip) skipped.push(node.id);
140
- else selected.push(choice.node);
141
- }
142
- return { scope: 'affected', base, docsOnly: code.length === 0, nodes: selected, skipped };
143
- }
@@ -1,159 +0,0 @@
1
- import { spawn } from 'node:child_process';
2
- import { createHash } from 'node:crypto';
3
- import { closeSync, existsSync, mkdirSync, openSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
4
- import { join } from 'node:path';
5
- import { setTimeout as sleep } from 'node:timers/promises';
6
- import { backgroundArgs } from '../../../framework/hooks/shared/background-spawn.js';
7
- import { heavyDir } from '../../../framework/hooks/shared/heavy-holders.js';
8
- import { pidAlive } from '../../../framework/hooks/shared/process-alive.js';
9
- import { treeFingerprint } from '../git/tree-fingerprint.js';
10
-
11
- export const DETACH_STAGE_ENV = 'MORPH_VERIFY_STAGE';
12
- export const DETACH_RUN_ENV = 'MORPH_VERIFY_RUN';
13
- export const DETACH_WORKER_ENV = 'MORPH_VERIFY_WORKER_PID';
14
-
15
- const POLL_MS = 2_000;
16
- const MAX_RUN_MS = 3 * 60 * 60_000;
17
-
18
- export const EXIT_BUSY = 3;
19
-
20
- export function runPaths(cwd, feature, env = process.env) {
21
- const id = createHash('sha1').update(`${cwd}\0${feature}`).digest('hex').slice(0, 12);
22
- const base = join(heavyDir(env), `verify-${id}`);
23
- return { run: `${base}.json`, exit: `${base}.exit`, out: `${base}.out`, err: `${base}.err` };
24
- }
25
-
26
- const readJson = (path) => {
27
- try {
28
- return JSON.parse(readFileSync(path, 'utf8'));
29
- } catch {
30
- return null;
31
- }
32
- };
33
-
34
- const readExit = (path) => {
35
- try {
36
- return Number.parseInt(readFileSync(path, 'utf8'), 10);
37
- } catch {
38
- return null;
39
- }
40
- };
41
-
42
- const readText = (path) => {
43
- try {
44
- return readFileSync(path, 'utf8');
45
- } catch {
46
- return '';
47
- }
48
- };
49
-
50
- const removeRun = (paths) => {
51
- for (const file of Object.values(paths)) rmSync(file, { force: true });
52
- };
53
-
54
- // launch and watchdog run without a console on win32: every git the view spawns there opens a window.
55
- export const refreshesFeatureView = (env = process.env) => !['launch', 'watchdog'].includes(env[DETACH_STAGE_ENV]);
56
-
57
- export function matchesRun(record, { key, args }) {
58
- return record?.key === key && JSON.stringify(record.args) === JSON.stringify(args);
59
- }
60
-
61
- export function isRunning(record, paths, { isAlive = pidAlive, now = Date.now } = {}) {
62
- if (!record || existsSync(paths.exit)) return false;
63
- return isAlive(record.pid) && now() - record.startedAt < MAX_RUN_MS;
64
- }
65
-
66
- export const runFilesOf = (runFile) => ({
67
- run: runFile,
68
- exit: runFile.replace(/\.json$/, '.exit'),
69
- out: runFile.replace(/\.json$/, '.out'),
70
- err: runFile.replace(/\.json$/, '.err'),
71
- });
72
-
73
- function spawnStage(stage, { argv, cwd, env, paths, script, spawnFn = spawn }) {
74
- mkdirSync(join(paths.run, '..'), { recursive: true });
75
- const out = openSync(paths.out, 'a');
76
- const err = openSync(paths.err, 'a');
77
- try {
78
- const args = [script, ...argv];
79
- const child = spawnFn(process.execPath, stage === 'launch' ? args : backgroundArgs(args), {
80
- cwd,
81
- detached: true,
82
- windowsHide: true,
83
- stdio: ['ignore', out, err],
84
- env: { ...env, [DETACH_STAGE_ENV]: stage, [DETACH_RUN_ENV]: paths.run },
85
- });
86
- child.unref();
87
- return child;
88
- } finally {
89
- closeSync(out);
90
- closeSync(err);
91
- }
92
- }
93
-
94
- export function markWorkerExit(runFile, { processRef = process } = {}) {
95
- const exitFile = runFilesOf(runFile).exit;
96
- processRef.once('exit', (code) => {
97
- try {
98
- writeFileSync(exitFile, String(code ?? 1));
99
- } catch {}
100
- });
101
- }
102
-
103
- /**
104
- * The launcher exists to die: killing a process tree walks parent pids, so a worker whose
105
- * parent has exited is out of reach of whatever kills the session's background shell.
106
- */
107
- export function launchWorker({ env = process.env, cwd = process.cwd(), argv, script = process.argv[1], spawnFn }) {
108
- const runFile = env[DETACH_RUN_ENV];
109
- const paths = runFilesOf(runFile);
110
- const child = spawnStage('worker', { argv, cwd, env, paths, script, spawnFn });
111
- writeFileSync(runFile, JSON.stringify({ ...readJson(runFile), pid: child.pid }));
112
- spawnStage('watchdog', {
113
- argv, cwd, env: { ...env, [DETACH_WORKER_ENV]: String(child.pid) }, paths, script, spawnFn,
114
- });
115
- }
116
-
117
- export async function superviseVerify({
118
- feature, args, cwd = process.cwd(), env = process.env, script = process.argv[1], log = (m) => process.stderr.write(`${m}\n`),
119
- deps = {},
120
- }) {
121
- const {
122
- fingerprint = treeFingerprint, spawnFn, isAlive = pidAlive, now = Date.now, wait = sleep, pollMs = POLL_MS,
123
- } = deps;
124
- const paths = runPaths(cwd, feature, env);
125
- const key = fingerprint(cwd);
126
- let record = readJson(paths.run);
127
- const liveness = { isAlive, now };
128
-
129
- if (isRunning(record, paths, liveness) && !matchesRun(record, { key, args })) {
130
- log('verify: outra rodada desta feature ainda corre, sobre outra árvore; espero ela acabar');
131
- while (isRunning(record, paths, liveness)) await wait(pollMs);
132
- record = null;
133
- }
134
-
135
- const attachable = matchesRun(record, { key, args }) && (isRunning(record, paths, liveness) || existsSync(paths.exit));
136
- if (attachable) {
137
- log(`verify: retomo a rodada destacada iniciada às ${new Date(record.startedAt).toLocaleTimeString()}`);
138
- } else {
139
- removeRun(paths);
140
- mkdirSync(join(paths.run, '..'), { recursive: true });
141
- record = { pid: null, key, args, startedAt: now() };
142
- writeFileSync(paths.run, JSON.stringify(record));
143
- spawnStage('launch', { argv: args, cwd, env, paths, script, spawnFn });
144
- }
145
-
146
- while (!existsSync(paths.exit)) {
147
- const current = readJson(paths.run);
148
- const launching = !current?.pid && now() - record.startedAt < 30_000;
149
- if (!launching && !isRunning(current, paths, liveness)) break;
150
- await wait(pollMs);
151
- }
152
-
153
- const exitCode = readExit(paths.exit);
154
- const stdout = readText(paths.out);
155
- const stderr = readText(paths.err);
156
- removeRun(paths);
157
- const died = exitCode === null || (exitCode === EXIT_BUSY && !stdout.trim());
158
- return { exitCode: exitCode ?? EXIT_BUSY, stdout, stderr, died };
159
- }