@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,523 +0,0 @@
1
- import { readFileSync, writeFileSync, renameSync, unlinkSync, existsSync, mkdirSync, readdirSync } from 'fs';
2
- import { join, dirname } from 'path';
3
- import { getAllOutputPaths, getOutputPath } from '../paths/output-schema.js';
4
- import { derivePhaseFrom, diskArtifactProbe } from '../../../framework/hooks/shared/state-reader.js';
5
- import { recordGateEvent } from '../../../framework/hooks/shared/gate-event.js';
6
-
7
- const STATE_FILE_NAME = '.morph/state.json';
8
- const FEATURES_DIR_NAME = '.morph/features';
9
- const FEATURE_FILE_NAME = 'feature.json';
10
- export const CONFIG_FILE_NAME = '.morph/config/config.json';
11
-
12
- // Versions the feature-object schema, not the storage layout: the per-feature
13
- // split is detected by the presence of `feature.json`.
14
- const STATE_VERSION = '5.0.0';
15
-
16
- export function getStatePath() {
17
- return join(process.cwd(), STATE_FILE_NAME);
18
- }
19
-
20
- function getFeaturesDir() {
21
- return join(process.cwd(), FEATURES_DIR_NAME);
22
- }
23
-
24
- function getFeatureJsonPath(featureName) {
25
- return join(getFeaturesDir(), featureName, FEATURE_FILE_NAME);
26
- }
27
-
28
- function listFeatureNamesOnDisk() {
29
- const dir = getFeaturesDir();
30
- if (!existsSync(dir)) return [];
31
- try {
32
- return readdirSync(dir, { withFileTypes: true })
33
- .filter((e) => e.isDirectory())
34
- .map((e) => e.name);
35
- } catch {
36
- return [];
37
- }
38
- }
39
-
40
- function readFeatureJson(featureName) {
41
- const path = getFeatureJsonPath(featureName);
42
- if (!existsSync(path)) return null;
43
- try {
44
- return JSON.parse(readFileSync(path, 'utf8'));
45
- } catch {
46
- return null;
47
- }
48
- }
49
-
50
- function readProjectFromConfig() {
51
- const path = join(process.cwd(), CONFIG_FILE_NAME);
52
- if (!existsSync(path)) return null;
53
- try {
54
- const cfg = JSON.parse(readFileSync(path, 'utf8'));
55
- const p = cfg.project || cfg;
56
- if (!p) return null;
57
- const project = {};
58
- if (p.name) project.name = p.name;
59
- if (p.type) project.type = p.type;
60
- return Object.keys(project).length ? project : null;
61
- } catch {
62
- return null;
63
- }
64
- }
65
-
66
- // Per-process temp file then rename; the EPERM retry covers the brief Windows lock race.
67
- export function atomicWriteJson(targetPath, data) {
68
- const dir = dirname(targetPath);
69
- if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
70
-
71
- const tmpPath = `${targetPath}.tmp.${process.pid}`;
72
- writeFileSync(tmpPath, JSON.stringify(data, null, 2), 'utf8');
73
-
74
- const MAX_RETRIES = 5;
75
- for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
76
- try {
77
- renameSync(tmpPath, targetPath);
78
- return;
79
- } catch (err) {
80
- if (err.code === 'EPERM' && attempt < MAX_RETRIES) {
81
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 50 * (attempt + 1));
82
- } else {
83
- try { unlinkSync(tmpPath); } catch { }
84
- throw err;
85
- }
86
- }
87
- }
88
- }
89
-
90
- // saveState re-persists every feature; skipping byte-identical content keeps a
91
- // mutation on one feature from rewriting (and clobbering) its siblings' files.
92
- function writeFeatureJson(featureName, feature) {
93
- const path = getFeatureJsonPath(featureName);
94
- try {
95
- if (existsSync(path) && readFileSync(path, 'utf8') === JSON.stringify(feature, null, 2)) {
96
- return;
97
- }
98
- } catch { }
99
- atomicWriteJson(path, feature);
100
- }
101
-
102
- function scaffoldState() {
103
- return {
104
- version: STATE_VERSION,
105
- project: readProjectFromConfig() || { name: '{PROJECT_NAME}', type: 'dotnet-nextjs' },
106
- features: {},
107
- threads: {},
108
- metadata: { totalFeatures: 0, completedFeatures: 0, totalTimeSpent: 0 },
109
- };
110
- }
111
- // Delegates to the hook-side rule so the CLI and the hooks never disagree on a phase.
112
- export function derivePhase(featurePath) {
113
- let feature = null;
114
- try {
115
- const fjPath = join(featurePath, 'feature.json');
116
- if (existsSync(fjPath)) feature = JSON.parse(readFileSync(fjPath, 'utf8'));
117
- } catch { feature = null; }
118
- return derivePhaseFrom(feature, diskArtifactProbe(featurePath));
119
- }
120
-
121
- export function deriveOutputs(featureName, baseDir = process.cwd()) {
122
- const outputPaths = getAllOutputPaths(featureName);
123
- const result = {};
124
- for (const [type, { path: relPath }] of Object.entries(outputPaths)) {
125
- const absPath = join(baseDir, relPath);
126
- result[type] = { created: existsSync(absPath), path: relPath };
127
- }
128
- return result;
129
- }
130
-
131
- export function stateExists() {
132
- return existsSync(getStatePath());
133
- }
134
-
135
- export function loadState(throwOnError = true) {
136
- const statePath = getStatePath();
137
- const rootExists = existsSync(statePath);
138
- const featureNames = listFeatureNamesOnDisk();
139
- const featuresExist = featureNames.some((name) => existsSync(getFeatureJsonPath(name)));
140
-
141
- if (!rootExists && !featuresExist) {
142
- if (throwOnError) {
143
- throw new Error(`State file not found: ${statePath}\nRun 'morph-spec init' to initialize MORPH in this project.`);
144
- }
145
- return null;
146
- }
147
-
148
- let state;
149
- try {
150
- state = rootExists ? JSON.parse(readFileSync(statePath, 'utf8')) : scaffoldState();
151
- } catch (err) {
152
- if (throwOnError) {
153
- throw new Error(`Failed to parse state.json: ${err.message}`);
154
- }
155
- return null;
156
- }
157
-
158
- state.features = state.features || {};
159
- state.metadata = state.metadata || {};
160
- if (!state.project || !state.project.name || state.project.name === '{PROJECT_NAME}') {
161
- const fromConfig = readProjectFromConfig();
162
- if (fromConfig) state.project = { ...(state.project || {}), ...fromConfig };
163
- }
164
-
165
- // Snapshot before the migrations below bump it: the reconcile loop tells a
166
- // legacy monolith (materialize) from a deleted feature (prune) by this value.
167
- const fileVersion = rootExists ? state.version : null;
168
-
169
- let mutated = !rootExists;
170
-
171
- if (state.version === '3.0.0') {
172
- state.version = '4.0.0';
173
- for (const [name, feature] of Object.entries(state.features)) {
174
- if (!feature.outputs) continue;
175
- const outputPathMap = getAllOutputPaths(name);
176
- for (const [key, { path: newPath }] of Object.entries(outputPathMap)) {
177
- if (feature.outputs[key]) feature.outputs[key].path = newPath;
178
- }
179
- }
180
- mutated = true;
181
- }
182
-
183
- if (state.version && state.version.startsWith('4.')) {
184
- state.version = '5.0.0';
185
- for (const feature of Object.values(state.features)) {
186
- delete feature.outputs;
187
- delete feature.phase;
188
- delete feature.workflow;
189
- delete feature.workflowDetection;
190
- }
191
- mutated = true;
192
- }
193
-
194
- // Index entry without feature.json: a pre-v5 or rich entry is the sole copy of a
195
- // legacy monolith (materialize it); a v5 thin entry means the folder was deleted
196
- // (prune it, never resurrect). Safe because saveState always co-writes both.
197
- const isRichEntry = (f) =>
198
- f && typeof f === 'object' && Object.keys(f).some((k) => k !== 'status' && k !== 'updatedAt');
199
- const wasVersionMigration = fileVersion !== null && fileVersion !== STATE_VERSION;
200
- for (const [name, feature] of Object.entries(state.features)) {
201
- if (existsSync(getFeatureJsonPath(name))) continue;
202
- if (wasVersionMigration || isRichEntry(feature)) {
203
- writeFeatureJson(name, feature);
204
- } else {
205
- delete state.features[name];
206
- console.error(`ℹ morph-spec: dropped stale index entry "${name}" (feature folder was deleted).`);
207
- }
208
- mutated = true;
209
- }
210
-
211
- for (const name of featureNames) {
212
- const fj = readFeatureJson(name);
213
- if (fj) state.features[name] = fj;
214
- }
215
-
216
- if (mutated) {
217
- saveState(state);
218
- }
219
-
220
- return state;
221
- }
222
-
223
- export function saveState(state) {
224
- state.metadata = state.metadata || {};
225
- state.metadata.lastUpdated = new Date().toISOString();
226
- state.version = state.version || STATE_VERSION;
227
-
228
- const features = state.features || {};
229
-
230
- state.metadata.totalFeatures = Object.keys(features).length;
231
- state.metadata.completedFeatures = Object.values(features)
232
- .filter((f) => f && f.status === 'completed').length;
233
-
234
- // A cross-feature sweep: a sibling saved in another format (trailing newline) is
235
- // rewritten and dirties the tree. To change one feature, write its feature.json directly.
236
- const thinFeatures = {};
237
- for (const [name, feature] of Object.entries(features)) {
238
- writeFeatureJson(name, feature);
239
- thinFeatures[name] = { status: feature.status, updatedAt: feature.updatedAt };
240
- }
241
-
242
- atomicWriteJson(getStatePath(), {
243
- version: state.version,
244
- project: state.project,
245
- threads: state.threads || {},
246
- metadata: state.metadata,
247
- features: thinFeatures,
248
- });
249
- }
250
-
251
- export function initState(options = {}) {
252
- const { force = false, projectName = '{PROJECT_NAME}', projectType = 'dotnet-nextjs' } = options;
253
-
254
- if (stateExists() && !force) {
255
- throw new Error('State file already exists. Use force=true to overwrite.');
256
- }
257
-
258
- const initialState = {
259
- version: "5.0.0",
260
- project: {
261
- name: projectName,
262
- type: projectType,
263
- createdAt: new Date().toISOString(),
264
- updatedAt: new Date().toISOString()
265
- },
266
- features: {},
267
- threads: {},
268
- metadata: {
269
- totalFeatures: 0,
270
- completedFeatures: 0,
271
- totalTimeSpent: 0,
272
- lastUpdated: new Date().toISOString()
273
- }
274
- };
275
-
276
- saveState(initialState);
277
- return initialState;
278
- }
279
-
280
- export function getFeature(featureName) {
281
- const state = loadState();
282
- return state.features[featureName] || null;
283
- }
284
-
285
- async function ensureFeature(featureName) {
286
- const state = loadState();
287
-
288
- if (!state.features[featureName]) {
289
- state.features[featureName] = {
290
- status: "draft",
291
- createdAt: new Date().toISOString(),
292
- updatedAt: new Date().toISOString(),
293
- approvalGates: {
294
- plan: { approved: false, timestamp: null, approvedBy: null },
295
- uiux: { approved: false, timestamp: null, approvedBy: null },
296
- review: { approved: false, timestamp: null, approvedBy: null }
297
- },
298
- checkpoints: [],
299
- trustConfig: {},
300
- contextBundles: [],
301
- fileChanges: []
302
- };
303
-
304
- state.metadata.totalFeatures++;
305
- saveState(state);
306
- }
307
-
308
- return state.features[featureName];
309
- }
310
-
311
- export async function createFeature(featureName, options = {}) {
312
- const { status = 'in_progress', workType, workTypeDetection, name, description } = options;
313
- const state = loadState(false) || scaffoldState();
314
-
315
- const existing = state.features[featureName];
316
- if (existing) {
317
- return { feature: existing, created: false };
318
- }
319
-
320
- const now = new Date().toISOString();
321
- state.features[featureName] = {
322
- name: name || featureName,
323
- ...(description !== undefined && description !== null ? { description } : {}),
324
- status,
325
- workType: workType || 'feature',
326
- createdAt: now,
327
- updatedAt: now,
328
- approvalGates: {
329
- plan: { approved: false, timestamp: null, approvedBy: null },
330
- uiux: { approved: false, timestamp: null, approvedBy: null },
331
- review: { approved: false, timestamp: null, approvedBy: null }
332
- },
333
- gateDecisions: {},
334
- checkpoints: [],
335
- trustConfig: {},
336
- contextBundles: [],
337
- fileChanges: []
338
- };
339
-
340
- if (workTypeDetection) {
341
- state.features[featureName].workTypeDetection = workTypeDetection;
342
- }
343
-
344
- state.metadata.totalFeatures = Object.keys(state.features).length;
345
- saveState(state);
346
- return { feature: state.features[featureName], created: true };
347
- }
348
-
349
- export async function updateFeature(featureName, key, value) {
350
- await ensureFeature(featureName);
351
- const state = loadState(); // Load AFTER ensuring feature exists
352
-
353
- const keys = key.split('.');
354
- let target = state.features[featureName];
355
-
356
- for (let i = 0; i < keys.length - 1; i++) {
357
- if (!target[keys[i]]) {
358
- target[keys[i]] = {};
359
- }
360
- target = target[keys[i]];
361
- }
362
-
363
- const finalKey = keys[keys.length - 1];
364
- target[finalKey] = value;
365
- state.features[featureName].updatedAt = new Date().toISOString();
366
-
367
- saveState(state);
368
- }
369
-
370
- function normalizeOutputType(type) {
371
- if (!type.includes('-')) {
372
- return type;
373
- }
374
-
375
- const camelCase = type.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
376
-
377
- return camelCase;
378
- }
379
-
380
- function levenshteinDistance(a, b) {
381
- const matrix = [];
382
-
383
- for (let i = 0; i <= b.length; i++) {
384
- matrix[i] = [i];
385
- }
386
-
387
- for (let j = 0; j <= a.length; j++) {
388
- matrix[0][j] = j;
389
- }
390
-
391
- for (let i = 1; i <= b.length; i++) {
392
- for (let j = 1; j <= a.length; j++) {
393
- if (b.charAt(i - 1) === a.charAt(j - 1)) {
394
- matrix[i][j] = matrix[i - 1][j - 1];
395
- } else {
396
- matrix[i][j] = Math.min(
397
- matrix[i - 1][j - 1] + 1,
398
- matrix[i][j - 1] + 1,
399
- matrix[i - 1][j] + 1
400
- );
401
- }
402
- }
403
- }
404
-
405
- return matrix[b.length][a.length];
406
- }
407
-
408
- function findClosestMatch(inputType, validTypes) {
409
- let closestMatch = null;
410
- let minDistance = Infinity;
411
-
412
- const normalizedInput = inputType.toLowerCase();
413
-
414
- for (const validType of validTypes) {
415
- const distance = levenshteinDistance(normalizedInput, validType.toLowerCase());
416
-
417
- if (distance < minDistance && distance <= 3) {
418
- minDistance = distance;
419
- closestMatch = validType;
420
- }
421
-
422
- if (validType.toLowerCase().includes(normalizedInput) ||
423
- normalizedInput.includes(validType.toLowerCase())) {
424
- if (distance < minDistance) {
425
- minDistance = distance;
426
- closestMatch = validType;
427
- }
428
- }
429
- }
430
-
431
- return minDistance <= 3 ? closestMatch : null;
432
- }
433
-
434
- export async function markOutput(featureName, outputType) {
435
- await ensureFeature(featureName);
436
- const state = loadState();
437
-
438
- const normalized = normalizeOutputType(outputType);
439
-
440
- if (!state.features[featureName].outputs) {
441
- state.features[featureName].outputs = getAllOutputPaths(featureName);
442
- }
443
-
444
- if (!state.features[featureName].outputs[normalized]) {
445
- const validCamelCaseTypes = Object.keys(state.features[featureName].outputs);
446
- const suggestion = findClosestMatch(outputType, validCamelCaseTypes);
447
-
448
- let errorMsg = `Output type '${outputType}' not valid.`;
449
-
450
- if (suggestion) {
451
- errorMsg += `\n\nDid you mean '${suggestion}'?`;
452
- const kebabAlternative = {
453
- 'uiMockups': 'ui-mockups',
454
- 'implementReport': 'implement-report'
455
- }[suggestion];
456
- if (kebabAlternative) {
457
- errorMsg += ` (also accepts '${kebabAlternative}')`;
458
- }
459
- }
460
-
461
- errorMsg += `\n\nValid types:\n`;
462
- errorMsg += ` ${validCamelCaseTypes.join(', ')}\n`;
463
- errorMsg += `\nNote: kebab-case is also accepted (e.g., 'ui-mockups', 'implement-report')`;
464
-
465
- throw new Error(errorMsg);
466
- }
467
-
468
- state.features[featureName].outputs[normalized].created = true;
469
- state.features[featureName].updatedAt = new Date().toISOString();
470
-
471
- const outputPath = state.features[featureName].outputs[normalized].path;
472
- if (outputPath) {
473
- if (!Array.isArray(state.features[featureName].fileChanges)) {
474
- state.features[featureName].fileChanges = [];
475
- }
476
- state.features[featureName].fileChanges.push({
477
- path: outputPath,
478
- action: 'created',
479
- phase: state.features[featureName].phase,
480
- timestamp: new Date().toISOString()
481
- });
482
- }
483
-
484
- saveState(state);
485
- }
486
-
487
- export async function setApprovalGate(featureName, gate, approved, metadata = {}) {
488
- const state = loadState();
489
- const feature = await ensureFeature(featureName);
490
-
491
- if (!feature.approvalGates) {
492
- feature.approvalGates = {
493
- plan: { approved: false, timestamp: null, approvedBy: null },
494
- uiux: { approved: false, timestamp: null, approvedBy: null },
495
- review: { approved: false, timestamp: null, approvedBy: null }
496
- };
497
- }
498
-
499
- feature.approvalGates[gate] = {
500
- approved,
501
- timestamp: metadata.approvedAt || metadata.rejectedAt || new Date().toISOString(),
502
- approvedBy: metadata.approvedBy || metadata.rejectedBy || null,
503
- ...metadata
504
- };
505
-
506
- state.features[featureName] = feature;
507
- saveState(state);
508
- recordGateEvent(process.cwd(), {
509
- feature: featureName, gate, step: approved ? 'approve' : 'unapprove', approvedBy: feature.approvalGates[gate].approvedBy,
510
- });
511
- }
512
-
513
- export function getApprovalGate(featureName, gate) {
514
- const state = loadState();
515
- const feature = state.features[featureName];
516
-
517
- if (!feature || !feature.approvalGates) {
518
- return null;
519
- }
520
-
521
- return feature.approvalGates[gate] || null;
522
- }
523
-
@@ -1,21 +0,0 @@
1
- import { existsSync, mkdirSync, writeFileSync } from 'fs';
2
- import { dirname, join } from 'path';
3
- import { getTemplateById, resolveFrameworkTemplatePath } from './template-registry.js';
4
-
5
- /** The project-local override (same relative path as in the package) wins over the package copy. */
6
- export function templateSourcePath(templateId, cwd = process.cwd()) {
7
- const template = getTemplateById(templateId);
8
- const local = template ? join(cwd, '.morph', 'framework', 'templates', template.path) : null;
9
- return local && existsSync(local) ? local : resolveFrameworkTemplatePath(templateId);
10
- }
11
-
12
- export function writeIfAbsent(path, content) {
13
- mkdirSync(dirname(path), { recursive: true });
14
- try {
15
- writeFileSync(path, content, { encoding: 'utf8', flag: 'wx' });
16
- return { path, written: true };
17
- } catch (err) {
18
- if (err.code === 'EEXIST') return { path, written: false };
19
- throw err;
20
- }
21
- }
@@ -1,44 +0,0 @@
1
- export const DEFAULT_WORK_TYPE = 'feature';
2
- export const POLICY_APPROVER_PREFIX = 'policy:';
3
-
4
- export const WORK_TYPES = {
5
- feature: {
6
- label: 'Feature',
7
- scaffold: ['2-plan'],
8
- skippedGates: [],
9
- forcedPauseGates: [],
10
- entrySkill: 'morph-plan',
11
- },
12
- bug: {
13
- label: 'Bug fix',
14
- scaffold: ['2-plan'],
15
- skippedGates: [],
16
- forcedPauseGates: [],
17
- entrySkill: 'morph-plan',
18
- },
19
- chore: {
20
- label: 'Chore',
21
- scaffold: ['2-plan', '3-implement'],
22
- skippedGates: ['plan'],
23
- forcedPauseGates: [],
24
- entrySkill: 'morph-plan',
25
- },
26
- hotfix: {
27
- label: 'Hotfix',
28
- scaffold: ['2-plan', '3-implement'],
29
- skippedGates: ['plan'],
30
- forcedPauseGates: ['review'],
31
- entrySkill: 'morph-hotfix',
32
- },
33
- };
34
-
35
- export function isValidWorkType(t) {
36
- return Object.prototype.hasOwnProperty.call(WORK_TYPES, t);
37
- }
38
-
39
- export function getWorkType(feature) {
40
- // A bare WORK_TYPES[key] would resolve inherited names like "toString".
41
- return isValidWorkType(feature?.workType)
42
- ? WORK_TYPES[feature.workType]
43
- : WORK_TYPES[DEFAULT_WORK_TYPE];
44
- }
@@ -1,84 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- import { Routes, Route, Navigate, useLocation, useParams } from 'react-router-dom';
3
- import Sidebar, { MobileNav } from './components/Sidebar.jsx';
4
- import ErrorBoundary from './components/ErrorBoundary.jsx';
5
- import CommandPalette from './components/CommandPalette.jsx';
6
- import Portfolio from './pages/Portfolio.jsx';
7
- import Features, { isWorking } from './pages/Features.jsx';
8
- import FeatureDetail from './pages/FeatureDetail.jsx';
9
- import Activity from './pages/Activity.jsx';
10
- import AgentMap from './pages/AgentMap.jsx';
11
- import PhasePipeline from './pages/PhasePipeline.jsx';
12
- import HookInspector from './pages/HookInspector.jsx';
13
- import SkillsLibrary from './pages/SkillsLibrary.jsx';
14
- import RulesMap from './pages/RulesMap.jsx';
15
- import Standards from './pages/Standards.jsx';
16
- import Guide from './pages/Guide.jsx';
17
- import { useNow } from './hooks/usePref.js';
18
- import { useProjects, useCurrentProject, projectHref } from './lib/project.js';
19
-
20
- function usePulse(portfolio) {
21
- const now = useNow();
22
- const byProject = {};
23
- for (const p of portfolio?.projects || []) {
24
- const s = p.summary;
25
- byProject[p.id] = s
26
- ? { active: s.active, awaiting: s.awaiting, working: s.activeFeatures.filter((f) => isWorking(f, now)).length }
27
- : null;
28
- }
29
- const awaiting = Object.values(byProject).reduce((n, x) => n + (x?.awaiting || 0), 0);
30
- useEffect(() => {
31
- document.title = awaiting ? `(${awaiting}) morph-spec` : 'morph-spec';
32
- }, [awaiting]);
33
- return { byProject, awaiting };
34
- }
35
-
36
- function ProjectIndex() {
37
- const { project } = useParams();
38
- return <Navigate to={projectHref(project)} replace />;
39
- }
40
-
41
- export default function App() {
42
- const { pathname } = useLocation();
43
- const { data: portfolio } = useProjects();
44
- const current = useCurrentProject(portfolio);
45
- const pulse = usePulse(portfolio);
46
- const [palette, setPalette] = useState(false);
47
- useEffect(() => {
48
- const onKey = (e) => {
49
- if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'k') { e.preventDefault(); setPalette((o) => !o); }
50
- };
51
- window.addEventListener('keydown', onKey);
52
- return () => window.removeEventListener('keydown', onKey);
53
- }, []);
54
- const nav = { portfolio, current: current.id, pulse, onSearch: () => setPalette(true) };
55
- return (
56
- <div className="flex h-full overflow-hidden">
57
- <div className="ambient" aria-hidden="true" />
58
- <Sidebar {...nav} />
59
- <CommandPalette open={palette} onClose={() => setPalette(false)} portfolio={portfolio} project={current.id} />
60
- <main className="relative z-10 flex-1 overflow-auto">
61
- <MobileNav {...nav} />
62
- {/* Keyed by route: a boundary that caught an error stays in fallback until it remounts. */}
63
- <ErrorBoundary key={pathname} page={pathname}>
64
- <Routes>
65
- <Route path="/" element={<Portfolio />} />
66
- <Route path="/p/:project" element={<ProjectIndex />} />
67
- <Route path="/p/:project/features" element={<Features />} />
68
- <Route path="/p/:project/features/:name" element={<FeatureDetail />} />
69
- <Route path="/p/:project/activity" element={<Activity />} />
70
- <Route path="/guide" element={<Guide />} />
71
- <Route path="/guide/:doc" element={<Guide />} />
72
- <Route path="/agents" element={<AgentMap />} />
73
- <Route path="/phases" element={<PhasePipeline />} />
74
- <Route path="/hooks" element={<HookInspector />} />
75
- <Route path="/skills" element={<SkillsLibrary />} />
76
- <Route path="/rules" element={<RulesMap />} />
77
- <Route path="/standards" element={<Standards />} />
78
- <Route path="*" element={<Navigate to="/" replace />} />
79
- </Routes>
80
- </ErrorBoundary>
81
- </main>
82
- </div>
83
- );
84
- }