@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,223 +0,0 @@
1
- // Fail-open per FIELD: a corrupt feature.json or a git hiccup nulls that field, never the scan.
2
-
3
- import { execSync, execFileSync } from 'child_process';
4
- import { existsSync, readdirSync, readFileSync } from 'fs';
5
- import { join, resolve } from 'path';
6
- import { isGitRepo, resolvePrimaryRoot, parseWorktreeList } from '../../commands/project/worktree.js';
7
- import { hasOriginRemote } from '../git/default-branch.js';
8
- import { registryPath, resolveFleetConfig } from './env-allocator.js';
9
- import { branchToReadFrom, branchView } from './feature-truth.js';
10
- import {
11
- getFeature,
12
- derivePhaseForFeature,
13
- derivePhaseFrom,
14
- fileSetArtifactProbe,
15
- getPendingGates,
16
- pendingGatesFrom,
17
- } from '../../../framework/hooks/shared/state-reader.js';
18
- import { listClaims } from '../../../framework/hooks/shared/claim-registry.js';
19
- import { buildPrIndex } from '../git/pr-index.js';
20
- import { pendingPrFeatures } from '../git/pending-prs.js';
21
- import { implementProgress, implementProgressFrom } from '../../../framework/hooks/shared/report-progress.js';
22
-
23
- const counts = (progress) => (progress ? { done: progress.done, total: progress.total } : null);
24
-
25
- // A root-resident feature's report lives on `morph/{f}`; the root tree only has the pre-work copy.
26
- function scenarioCounts(featureDir, { root, feature, featureBranch } = {}) {
27
- if (featureBranch && root && feature) {
28
- const show = (rel) => {
29
- try {
30
- return execFileSync('git', ['show', `${featureBranch}:.morph/features/${feature}/${rel}`], { cwd: root, stdio: 'pipe' }).toString();
31
- } catch {
32
- return null;
33
- }
34
- };
35
- const onBranch = implementProgressFrom(show('2-plan/checks.json'), show('3-implement/report.md'), (id) => show(`3-implement/reports/${id}.md`));
36
- if (onBranch) return counts(onBranch);
37
- }
38
- return counts(implementProgress(featureDir));
39
- }
40
-
41
- function lastCommitRelative(root, branch) {
42
- try {
43
- return execFileSync('git', ['log', '-1', '--format=%cr', branch], { cwd: root, stdio: 'pipe' })
44
- .toString().trim() || null;
45
- } catch {
46
- return null;
47
- }
48
- }
49
-
50
- function dirtyCount(worktreePath) {
51
- try {
52
- const out = execFileSync('git', ['status', '--porcelain'], { cwd: worktreePath, stdio: 'pipe' }).toString();
53
- return out.split('\n').filter((l) => l.trim()).length;
54
- } catch {
55
- return null;
56
- }
57
- }
58
-
59
- // null = unknown (no origin, or the probe failed): entries get `remote: null`, never a false `pushed: false`.
60
- function remoteHeads(root) {
61
- if (!hasOriginRemote(root)) return null;
62
- try {
63
- const out = execFileSync('git', ['ls-remote', '--heads', 'origin'], {
64
- cwd: root, stdio: 'pipe', timeout: 5000,
65
- }).toString();
66
- const map = new Map();
67
- for (const line of out.split('\n')) {
68
- const m = line.match(/^([0-9a-f]{7,64})\s+refs\/heads\/(.+)$/);
69
- if (m) map.set(m[2].trim(), m[1]);
70
- }
71
- return map;
72
- } catch {
73
- return null;
74
- }
75
- }
76
-
77
- function remotePrs(root) {
78
- return buildPrIndex(root, { limit: 100 });
79
- }
80
-
81
- // A worktree's real branch may carry a `--fresh` date suffix; only root entries fall back to `morph/{f}`.
82
- function buildRemote(feature, branch, heads, prs) {
83
- if (!heads) return null;
84
- const remoteBranch = branch || `morph/${feature}`;
85
- const sha = heads.get(remoteBranch) || null;
86
- return { branch: remoteBranch, pushed: sha !== null, sha, pr: prs?.get(remoteBranch) || null };
87
- }
88
-
89
- function buildEntry(feature, { location, path, branch, root, allocations, blockSize, heads, prs, claims }) {
90
- let workType = null;
91
- let status = 'unknown';
92
- let phase = 'plan';
93
- let pendingGates = [];
94
-
95
- const featureBranch = branchToReadFrom(root, feature, location, branch);
96
-
97
- try {
98
- const view = featureBranch ? branchView(root, feature, featureBranch) : null;
99
- if (view) {
100
- workType = view.fj?.workType || null;
101
- status = view.fj?.status || 'unknown';
102
- phase = derivePhaseFrom(view.fj, fileSetArtifactProbe(view.files));
103
- pendingGates = pendingGatesFrom(view.fj);
104
- } else {
105
- const fj = getFeature(feature, path);
106
- workType = fj?.workType || null;
107
- status = fj?.status || 'unknown';
108
- phase = derivePhaseForFeature(feature, path);
109
- pendingGates = getPendingGates(feature, path);
110
- }
111
- } catch { /* fail-open */ }
112
-
113
- const featureDir = join(path, '.morph', 'features', feature);
114
- const alloc = allocations[feature];
115
- return {
116
- feature,
117
- workType,
118
- phase,
119
- status,
120
- pendingGates,
121
- location,
122
- path,
123
- branch,
124
- scenarios: scenarioCounts(featureDir, { root, feature, featureBranch }),
125
- env: alloc && Number.isInteger(alloc.base)
126
- ? { base: alloc.base, range: [alloc.base, alloc.base + blockSize - 1] }
127
- : null,
128
- lastCommit: location === 'worktree' && branch ? lastCommitRelative(root, branch) : null,
129
- dirty: location === 'worktree' ? dirtyCount(path) : null,
130
- remote: buildRemote(feature, branch, heads, prs),
131
- // A stale claim is reported, not hidden: "nobody is here" ≠ "somebody died here".
132
- claim: claims?.[feature] || null,
133
- };
134
- }
135
-
136
- export function scanFleet(cwd = process.cwd()) {
137
- if (!isGitRepo(cwd)) {
138
- return { root: resolve(cwd).replace(/\\/g, '/'), entries: [] };
139
- }
140
- const root = resolvePrimaryRoot(cwd);
141
-
142
- let allocations = {};
143
- const claims = {};
144
- try {
145
- const common = execSync('git rev-parse --git-common-dir', { cwd: root, stdio: 'pipe' }).toString().trim();
146
- if (common) {
147
- const gitCommonDir = resolve(root, common);
148
- try {
149
- const reg = JSON.parse(readFileSync(registryPath(gitCommonDir), 'utf8'));
150
- if (reg && typeof reg.allocations === 'object' && reg.allocations !== null) allocations = reg.allocations;
151
- } catch { /* env stays null per entry */ }
152
- for (const c of listClaims(gitCommonDir)) claims[c.feature] = c;
153
- }
154
- } catch { /* env and claim stay null per entry */ }
155
- const { blockSize } = resolveFleetConfig(root);
156
-
157
- const heads = remoteHeads(root);
158
- const prs = heads ? remotePrs(root) : null;
159
-
160
- const entries = [];
161
- const inWorktree = new Set();
162
-
163
- for (const e of parseWorktreeList(root)) {
164
- const m = e.branch && e.branch.match(/^refs\/heads\/morph\/(.+)$/);
165
- if (!m) continue;
166
- inWorktree.add(m[1]);
167
- entries.push(buildEntry(m[1], {
168
- location: 'worktree',
169
- path: e.path,
170
- branch: e.branch.replace(/^refs\/heads\//, ''),
171
- root,
172
- allocations,
173
- blockSize,
174
- heads,
175
- prs,
176
- claims,
177
- }));
178
- }
179
-
180
- try {
181
- const featuresDir = join(root, '.morph', 'features');
182
- if (existsSync(featuresDir)) {
183
- const names = readdirSync(featuresDir, { withFileTypes: true })
184
- .filter((d) => d.isDirectory())
185
- .map((d) => d.name)
186
- .filter((name) => !inWorktree.has(name) && existsSync(join(featuresDir, name, 'feature.json')));
187
- for (const name of names) {
188
- entries.push(buildEntry(name, {
189
- location: 'root', path: root, branch: null, root, allocations, blockSize, heads, prs, claims,
190
- }));
191
- }
192
- }
193
- } catch { /* fail-open */ }
194
-
195
- // Features that exist only as an open PR (what `finish --pr` leaves). Gate on `heads`, not
196
- // `prs !== null`: a `gh` that already ran and failed passes an explicit `null` index, so
197
- // `pendingPrFeatures` does not call `gh` a second time.
198
- try {
199
- const seen = new Set(entries.map((e) => e.feature));
200
- const pendOpts = heads ? { index: prs } : {};
201
- for (const p of pendingPrFeatures(root, pendOpts) || []) {
202
- if (seen.has(p.feature)) continue;
203
- entries.push({
204
- feature: p.feature,
205
- workType: null,
206
- phase: 'aguardando-merge',
207
- status: 'in_progress',
208
- pendingGates: [],
209
- location: 'pr-pending',
210
- path: null,
211
- branch: p.branch,
212
- scenarios: null,
213
- env: null,
214
- lastCommit: null,
215
- dirty: null,
216
- remote: { branch: p.branch, pushed: true, sha: null, pr: { number: p.number, state: p.state } },
217
- claim: null,
218
- });
219
- }
220
- } catch { /* fail-open */ }
221
-
222
- return { root, entries };
223
- }
@@ -1,136 +0,0 @@
1
- // `git worktree remove` deletes gitignored files and `git status` never shows them.
2
- // Every uncertainty classifies as EXCLUSIVE (backed up): being wrong that way costs a
3
- // copy, the other way costs the file.
4
-
5
- import { createHash } from 'crypto';
6
- import { existsSync, lstatSync, readdirSync, readFileSync } from 'fs';
7
- import { join } from 'path';
8
-
9
- // Only dirs their own tool rewrites from scratch. Never add `dist/`, `build/` or `coverage/`:
10
- // projects hand-write those. `.auth/` (Playwright session) is regenerated by the auth setup,
11
- // and keeping it out of the backup avoids copying credentials around.
12
- const DISPOSABLE_DIR_NAMES = new Set([
13
- 'bin', 'obj', 'node_modules', '__pycache__', 'test-results', '.auth',
14
- '.next', '.turbo', '.pytest_cache', 'TestResults', 'graphify-out',
15
- ]);
16
- const DISPOSABLE_FILE_RE = /\.tsbuildinfo$/;
17
-
18
- const REPLICABLE_MAX_FILES = 500;
19
- const REPLICABLE_MAX_BYTES = 8 * 1024 * 1024;
20
-
21
- // Narrower than the build set on purpose: an untracked `bin/` may be new code, a `test-results/` never is.
22
- const TEST_ARTIFACT_DIR_NAMES = new Set(['test-results', 'TestResults', 'playwright-report', 'blob-report']);
23
-
24
- /** @param {string} p - forward-slash relative path */
25
- export function isTestArtifact(p) {
26
- return p.split('/').filter(Boolean).some((seg) => TEST_ARTIFACT_DIR_NAMES.has(seg));
27
- }
28
-
29
- /** @param {string} p - forward-slash relative path */
30
- export function isDisposableBuildArtifact(p) {
31
- if (DISPOSABLE_FILE_RE.test(p)) return true;
32
- return p.split('/').filter(Boolean).some((seg) => DISPOSABLE_DIR_NAMES.has(seg));
33
- }
34
-
35
- function sha256OfFile(path) {
36
- try {
37
- return createHash('sha256').update(readFileSync(path)).digest('hex');
38
- } catch {
39
- return null;
40
- }
41
- }
42
-
43
- // lstat, never stat: reading THROUGH a junction is the failure the teardown path exists to prevent.
44
- function isRealFile(path) {
45
- try {
46
- return lstatSync(path).isFile();
47
- } catch {
48
- return false;
49
- }
50
- }
51
-
52
- function isRealDir(path) {
53
- try {
54
- return lstatSync(path).isDirectory();
55
- } catch {
56
- return false;
57
- }
58
- }
59
-
60
- // null on a link, an unreadable entry or either cap: none of them may be claimed replicable.
61
- function walkFiles(dir, budget) {
62
- const out = [];
63
- const stack = [''];
64
- while (stack.length) {
65
- const rel = stack.pop();
66
- let entries;
67
- try {
68
- entries = readdirSync(join(dir, rel), { withFileTypes: true });
69
- } catch {
70
- return null;
71
- }
72
- for (const e of entries) {
73
- const childRel = rel ? `${rel}/${e.name}` : e.name;
74
- const childAbs = join(dir, childRel);
75
- if (e.isSymbolicLink()) return null;
76
- if (e.isDirectory()) { stack.push(childRel); continue; }
77
- if (!e.isFile()) return null;
78
- let size;
79
- try { size = lstatSync(childAbs).size; } catch { return null; }
80
- budget.files += 1;
81
- budget.bytes += size;
82
- if (budget.files > REPLICABLE_MAX_FILES || budget.bytes > REPLICABLE_MAX_BYTES) return null;
83
- out.push(childRel);
84
- }
85
- }
86
- return out;
87
- }
88
-
89
- /**
90
- * False on any uncertainty. A directory needs the SAME file set: a root superset is
91
- * not a replica, because the worktree's own extra files would still be lost.
92
- */
93
- export function isReplicatedInRoot(worktreePath, rootPath, rel) {
94
- const src = join(worktreePath, rel);
95
- const dst = join(rootPath, rel);
96
- if (!existsSync(src) || !existsSync(dst)) return false;
97
-
98
- if (isRealFile(src)) {
99
- if (!isRealFile(dst)) return false;
100
- const a = sha256OfFile(src);
101
- const b = sha256OfFile(dst);
102
- return a !== null && a === b;
103
- }
104
-
105
- if (isRealDir(src)) {
106
- if (!isRealDir(dst)) return false;
107
- const srcFiles = walkFiles(src, { files: 0, bytes: 0 });
108
- if (srcFiles === null) return false;
109
- const dstFiles = walkFiles(dst, { files: 0, bytes: 0 });
110
- if (dstFiles === null) return false;
111
- if (srcFiles.length !== dstFiles.length) return false;
112
- const dstSet = new Set(dstFiles);
113
- for (const f of srcFiles) {
114
- if (!dstSet.has(f)) return false;
115
- const a = sha256OfFile(join(src, f));
116
- const b = sha256OfFile(join(dst, f));
117
- if (a === null || a !== b) return false;
118
- }
119
- return true;
120
- }
121
-
122
- return false;
123
- }
124
-
125
- // Disposable is checked first so `node_modules` never enters the hashing budget.
126
- export function triageIgnoredPaths({ worktreePath, rootPath, paths }) {
127
- const replicable = [];
128
- const disposable = [];
129
- const exclusive = [];
130
- for (const rel of paths) {
131
- if (isDisposableBuildArtifact(rel)) { disposable.push(rel); continue; }
132
- if (isReplicatedInRoot(worktreePath, rootPath, rel)) { replicable.push(rel); continue; }
133
- exclusive.push(rel);
134
- }
135
- return { replicable, disposable, exclusive };
136
- }
@@ -1,112 +0,0 @@
1
- import { execFileSync } from 'node:child_process';
2
- import { existsSync, readdirSync, readFileSync } from 'node:fs';
3
- import { join } from 'node:path';
4
- import { jsoncToJson, stripComments } from '../../../framework/hooks/shared/comment-stripper.js';
5
- import { ensureCommonExclude } from '../../../framework/hooks/shared/git-exclude.js';
6
- import { readProjectConfig } from '../../../framework/hooks/shared/heavy-config.js';
7
- import { getProjectTags } from '../stack-filter.js';
8
- import { realEffects } from '../installers/effects.js';
9
- import { WORKTREE_DIR_NAMES } from './dirs.js';
10
-
11
- const SETTINGS_REL = join('.vscode', 'settings.json');
12
- const EXCLUDE_MARKER = '# morph-spec: editor settings';
13
- const DEFAULT_INDENT = ' ';
14
- const DOTNET_ROOT_FILE = /\.(sln|slnx|csproj)$/i;
15
-
16
- const isDotnet = (root, config) => getProjectTags(config).includes('dotnet')
17
- || (() => { try { return readdirSync(root).some((n) => DOTNET_ROOT_FILE.test(n)); } catch { return false; } })();
18
-
19
- /** Globs per settings key. `bin/obj` leave `files.exclude` outside .NET: a JS `bin/` holds source. */
20
- export function desiredEditorSettings({ dotnet }) {
21
- const dirs = WORKTREE_DIR_NAMES.map((n) => `**/${n}/**`);
22
- const watched = Object.fromEntries([...dirs, '**/node_modules/**', '**/bin/**', '**/obj/**'].map((g) => [g, true]));
23
- const listed = Object.fromEntries([...dirs, '**/node_modules/**', ...(dotnet ? ['**/bin/**', '**/obj/**'] : [])].map((g) => [g, true]));
24
- return { 'files.watcherExclude': watched, 'search.exclude': { ...watched }, 'files.exclude': listed };
25
- }
26
-
27
- const isPlainObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
28
-
29
- function isTracked(root, rel) {
30
- try {
31
- execFileSync('git', ['ls-files', '--error-unmatch', '--', rel], { cwd: root, stdio: 'pipe' });
32
- return true;
33
- } catch {
34
- return false;
35
- }
36
- }
37
-
38
- function mergeMissing(current, wanted) {
39
- const added = [];
40
- const skipped = [];
41
- for (const [key, globs] of Object.entries(wanted)) {
42
- if (current[key] === undefined) {
43
- current[key] = { ...globs };
44
- added.push(...Object.keys(globs).map((g) => `${key}:${g}`));
45
- } else if (isPlainObject(current[key])) {
46
- for (const glob of Object.keys(globs)) {
47
- if (!(glob in current[key])) { current[key][glob] = true; added.push(`${key}:${glob}`); }
48
- }
49
- } else {
50
- skipped.push(key);
51
- }
52
- }
53
- return { added, skipped };
54
- }
55
-
56
- function snippetFor(wanted, present) {
57
- const missing = {};
58
- for (const [key, globs] of Object.entries(wanted)) {
59
- const gaps = Object.fromEntries(Object.entries(globs).filter(([g]) => !(isPlainObject(present?.[key]) && g in present[key])));
60
- if (Object.keys(gaps).length) missing[key] = gaps;
61
- }
62
- return JSON.stringify(missing, null, 2);
63
- }
64
-
65
- /**
66
- * Read-only. `write` carries the full new text; `suggest` carries the snippet to paste, because
67
- * rewriting would drop comments, trailing commas or a tracked file's cleanliness.
68
- */
69
- export function planEditorSettings(root, { config = readProjectConfig(root), env = process.env } = {}) {
70
- const file = join(root, SETTINGS_REL);
71
- if (config?.worktree?.editorSettings === false || env.MORPH_EDITOR_SETTINGS === '0') return { status: 'off', file };
72
-
73
- const wanted = desiredEditorSettings({ dotnet: isDotnet(root, config) });
74
- if (!existsSync(file)) {
75
- return { status: 'write', file, created: true, added: Object.entries(wanted).flatMap(([k, g]) => Object.keys(g).map((x) => `${k}:${x}`)), content: `${JSON.stringify(wanted, null, DEFAULT_INDENT)}\n` };
76
- }
77
-
78
- const suggest = (reason, present) => ({ status: 'suggest', file, reason, snippet: snippetFor(wanted, present) });
79
- let text;
80
- try { text = readFileSync(file, 'utf8'); } catch { return suggest('unreadable'); }
81
- const body = text.replace(/^\uFEFF/, '');
82
- let parsed;
83
- try { parsed = JSON.parse(jsoncToJson(body)); } catch { return suggest('unreadable'); }
84
- if (!isPlainObject(parsed)) return suggest('not-object');
85
- if (stripComments(body) !== body || jsoncToJson(body) !== stripComments(body)) return suggest('comments', parsed);
86
-
87
- const { added, skipped } = mergeMissing(parsed, wanted);
88
- if (!added.length) return { status: 'unchanged', file, ...(skipped.length ? { skipped } : {}) };
89
- if (isTracked(root, SETTINGS_REL)) return suggest('tracked', JSON.parse(jsoncToJson(body)));
90
-
91
- const indent = /^([ \t]+)"/m.exec(body)?.[1] ?? DEFAULT_INDENT;
92
- const eol = body.includes('\r\n') ? '\r\n' : '\n';
93
- const out = JSON.stringify(parsed, null, indent).replace(/\n/g, eol) + (/\n$/.test(body) ? eol : '');
94
- return { status: 'write', file, created: false, added, ...(skipped.length ? { skipped } : {}), content: `${text.startsWith('\uFEFF') ? '\uFEFF' : ''}${out}` };
95
- }
96
-
97
- /**
98
- * Applies the plan through `fx` (so `update --dry-run` predicts it). A created file joins the
99
- * common `info/exclude`: untracked, it would count as root dirt and `finish --merge` refuses that.
100
- */
101
- export function applyEditorSettings(root, { fx = realEffects(), config, env } = {}) {
102
- const plan = planEditorSettings(root, { config, env });
103
- const { content, ...report } = plan;
104
- if (plan.status !== 'write') return report;
105
- try {
106
- fx.writeFile(plan.file, content);
107
- if (plan.created && !fx.dryRun) ensureCommonExclude(root, ['/.vscode/settings.json'], EXCLUDE_MARKER);
108
- return { ...report, written: !fx.dryRun };
109
- } catch (err) {
110
- return { status: 'failed', file: plan.file, reason: String(err?.message ?? err).slice(0, 200) };
111
- }
112
- }