@polymorphism-tech/morph-spec 10.12.0 → 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 +31 -86
  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,231 +0,0 @@
1
- import chalk from 'chalk';
2
- import { existsSync, renameSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'fs';
3
- import { join, resolve, sep } from 'path';
4
- import { execFileSync } from 'child_process';
5
- import { ADR_INDEX_PATHSPEC, updateAdrIndex } from '../../lib/specs/adr-index.js';
6
- import { isValidFeatureName } from '../project/worktree.js';
7
- import { RECAP_FILES, writeRecap } from './recap.js';
8
- import { GATE_NAME, featureRef } from '../../../framework/hooks/shared/owner-words.js';
9
- import { SESSION_MARK } from '../../../framework/hooks/shared/next-step.js';
10
- import { featureSummary } from '../../../framework/hooks/shared/report-progress.js';
11
-
12
- function assertContained(scopeDir, name, target) {
13
- const scopeAbs = resolve(scopeDir) + sep;
14
- const targetAbs = resolve(target);
15
- if (targetAbs !== resolve(scopeDir) && !(targetAbs + sep).startsWith(scopeAbs)) {
16
- throw new Error(`recusado: "${name}" resolve para fora de ${scopeDir}`);
17
- }
18
- }
19
-
20
- // Archived = `status: "completed"` + `archivedAt`; there is no separate "archived" status.
21
-
22
- function isGitRepo(cwd) {
23
- try {
24
- execFileSync('git', ['rev-parse', '--is-inside-work-tree'], { cwd, stdio: 'pipe' });
25
- return true;
26
- } catch {
27
- return false;
28
- }
29
- }
30
-
31
- function readReviewApproved(fjPath) {
32
- try {
33
- const fj = JSON.parse(readFileSync(fjPath, 'utf8'));
34
- const gates = fj?.approvalGates || fj?.approvals || {};
35
- return gates?.review?.approved === true;
36
- } catch {
37
- return false;
38
- }
39
- }
40
-
41
- /**
42
- * Never calls process.exit, and resolves everything from `cwd` so `finish` can archive inside a
43
- * worktree. Idempotent: an existing archive returns `{ ok: true, alreadyArchived: true }`.
44
- */
45
- // plan.md stays: a squash merge drops every file born and pruned inside the branch.
46
- function pruneArchive(dir) {
47
- for (const entry of readdirSync(dir)) {
48
- if (entry === 'feature.json' || Object.values(RECAP_FILES).includes(entry)) continue;
49
- if (entry !== '2-plan') { rmSync(join(dir, entry), { recursive: true, force: true }); continue; }
50
- for (const planEntry of readdirSync(join(dir, entry))) {
51
- if (planEntry !== 'plan.md') rmSync(join(dir, entry, planEntry), { recursive: true, force: true });
52
- }
53
- }
54
- }
55
-
56
- export function runArchive(feature, opts = {}) {
57
- const cwd = opts.cwd || process.cwd();
58
-
59
- // Validated BEFORE any path is built: `../../.claude` would let renameSync move a directory
60
- // outside .morph/features/.
61
- if (!isValidFeatureName(feature)) {
62
- return { ok: false, error: 'invalid-feature-name' };
63
- }
64
-
65
- const featuresDir = join(cwd, '.morph', 'features');
66
- const archiveDir = join(cwd, '.morph', 'archive');
67
- const featuresPath = join(featuresDir, feature);
68
- const archivePath = join(archiveDir, feature);
69
- assertContained(featuresDir, feature, featuresPath);
70
- assertContained(archiveDir, feature, archivePath);
71
- const featPathspec = join('.morph', 'features', feature);
72
- const archivePathspec = join('.morph', 'archive', feature);
73
-
74
- // Checked FIRST so a re-run after a partial finish reports "already done", never "not found".
75
- if (existsSync(archivePath)) {
76
- return { ok: true, alreadyArchived: true, archived: false, archivePath };
77
- }
78
-
79
- if (!existsSync(featuresPath)) {
80
- return { ok: false, error: 'feature-folder-not-found' };
81
- }
82
-
83
- const fjPathBefore = join(featuresPath, 'feature.json');
84
- if (!opts.force && !readReviewApproved(fjPathBefore)) {
85
- return { ok: false, error: 'review-not-approved' };
86
- }
87
-
88
- const useGit = opts.git !== false && isGitRepo(cwd);
89
- let archivedFromSha = null;
90
- if (useGit) {
91
- try { archivedFromSha = execFileSync('git', ['rev-parse', 'HEAD'], { cwd, stdio: 'pipe' }).toString().trim(); } catch { /* no commit yet */ }
92
- }
93
-
94
- // `git mv` keeps history and stages in one step; an untracked folder falls back to rename.
95
- mkdirSync(archiveDir, { recursive: true });
96
- let staged = false;
97
- if (useGit) {
98
- try {
99
- execFileSync('git', ['mv', featuresPath, archivePath], { cwd, stdio: 'pipe' });
100
- staged = true;
101
- } catch {
102
- renameSync(featuresPath, archivePath);
103
- try {
104
- execFileSync('git', ['add', '-A', '--', featPathspec, archivePathspec], { cwd, stdio: 'pipe' });
105
- staged = true;
106
- } catch { /* not fatal — the move succeeded */ }
107
- }
108
- } else {
109
- renameSync(featuresPath, archivePath);
110
- }
111
-
112
- const fjPathAfter = join(archivePath, 'feature.json');
113
- if (existsSync(fjPathAfter)) {
114
- try {
115
- const fj = JSON.parse(readFileSync(fjPathAfter, 'utf8'));
116
- fj.status = 'completed';
117
- fj.archivedAt = new Date().toISOString();
118
- if (archivedFromSha) fj.archivedFrom = { sha: archivedFromSha };
119
- fj.updatedAt = fj.archivedAt;
120
- writeFileSync(fjPathAfter, JSON.stringify(fj, null, 2), 'utf8');
121
- if (useGit && staged) {
122
- try { execFileSync('git', ['add', '--', archivePathspec], { cwd, stdio: 'pipe' }); } catch { /* non-fatal */ }
123
- }
124
- } catch { /* non-fatal — the move is what matters */ }
125
- }
126
-
127
- // Fail-open: the ADR index must never block archiving.
128
- let adrIndex = { changed: false, added: [], revoked: [], narrowed: [], problems: [] };
129
- try {
130
- adrIndex = updateAdrIndex(cwd, archivePath);
131
- } catch { /* fail-open */ }
132
- if (useGit && staged && adrIndex.changed) {
133
- try { execFileSync('git', ['add', '-A', '--', ADR_INDEX_PATHSPEC], { cwd, stdio: 'pipe' }); } catch { /* non-fatal */ }
134
- }
135
-
136
- // Before the prune: the recap reads the Gate 3 reports the archive does not keep.
137
- const recap = opts.recap === false ? null : writeRecap(archivePath, archivePath, feature, { cwd });
138
- pruneArchive(archivePath);
139
- if (useGit && staged) {
140
- try { execFileSync('git', ['add', '-A', '--', archivePathspec], { cwd, stdio: 'pipe' }); } catch { /* non-fatal */ }
141
- }
142
-
143
- // Scoped to this feature's pathspec, never `commit -a`. The ADR index joins only when it
144
- // changed: git refuses a pathspec that matches nothing, leaving the tree dirty for the merge.
145
- let committed = false;
146
- if (useGit && staged) {
147
- const pathspecs = [
148
- featPathspec,
149
- archivePathspec,
150
- ...(adrIndex.changed ? [ADR_INDEX_PATHSPEC] : []),
151
- ];
152
- try {
153
- execFileSync('git', ['commit', '-m', `chore(morph): archive ${feature}`, '--', ...pathspecs], { cwd, stdio: 'pipe' });
154
- committed = true;
155
- } catch { /* nothing to commit / no identity — not fatal, the move + stage stand */ }
156
- }
157
-
158
- // Not saveState: it would re-create .morph/features/{name}/feature.json and undo the archive.
159
- const rootPath = join(cwd, '.morph', 'state.json');
160
- if (existsSync(rootPath)) {
161
- try {
162
- const root = JSON.parse(readFileSync(rootPath, 'utf8'));
163
- if (root.features && root.features[feature]) {
164
- delete root.features[feature];
165
- root.metadata = root.metadata || {};
166
- root.metadata.totalFeatures = Object.keys(root.features).length;
167
- writeFileSync(rootPath, JSON.stringify(root, null, 2), 'utf8');
168
- }
169
- } catch { /* index is derivable — non-fatal */ }
170
- }
171
-
172
- return {
173
- ok: true, archived: true, committed, staged, archivePath,
174
- recap: recap?.ok ? recap.path : null,
175
- revocationProblems: adrIndex.problems,
176
- adrIndex: adrIndex.changed ? { added: adrIndex.added, revoked: adrIndex.revoked, narrowed: adrIndex.narrowed } : null,
177
- };
178
- }
179
-
180
- // Unlike `runArchive`, an already-archived feature is reported as a refusal here.
181
- export async function archiveCommand(featureName, options = {}) {
182
- try {
183
- const result = runArchive(featureName, {
184
- cwd: process.cwd(),
185
- force: options.force,
186
- git: options.git,
187
- });
188
-
189
- if (!result.ok) {
190
- if (result.error === 'invalid-feature-name') {
191
- console.error(chalk.red(`\n❌ Identificador da feature inválido: "${featureName}"`));
192
- console.error(chalk.gray('Use kebab-case: letras minúsculas, números e hífens (ex.: "cadastro-de-cliente")\n'));
193
- } else if (result.error === 'feature-folder-not-found') {
194
- console.error(chalk.red(`\n❌ Não achei a feature ${featureName} neste projeto (.morph/features/${featureName}).\n`));
195
- } else if (result.error === 'review-not-approved') {
196
- console.error(chalk.red(`\n❌ A entrega de ${featureName} ainda não passou pela ${GATE_NAME.review}.`));
197
- console.error(chalk.gray(' Só se arquiva o que foi aprovado.'));
198
- console.log(chalk.gray(` ${SESSION_MARK} morph-spec approve ${featureName} review, ou --force.\n`));
199
- } else {
200
- console.error(chalk.red(`\n❌ Não deu para arquivar a feature: ${result.error}\n`));
201
- }
202
- process.exit(1);
203
- }
204
-
205
- if (result.alreadyArchived) {
206
- console.error(chalk.red(`\n❌ A feature ${featureName} já está arquivada (.morph/archive/${featureName}).\n`));
207
- process.exit(1);
208
- }
209
-
210
- let ref = featureName;
211
- try { ref = featureRef(featureName, JSON.parse(readFileSync(join(result.archivePath, 'feature.json'), 'utf8')), featureSummary(result.archivePath)); } catch { /* the slug still names it */ }
212
- console.log(chalk.green(`\n📦 Feature ${ref} arquivada: marcada como concluída e guardada em .morph/archive/${featureName}/`));
213
- if (result.recap) console.log(chalk.gray(` Resumo animado da entrega: ${result.recap} (com narração: morph-spec recap ${featureName} --piper)`));
214
- if (result.adrIndex) {
215
- const { added, revoked, narrowed } = result.adrIndex;
216
- console.log(chalk.gray(` Decisões do projeto (.morph/specs/adrs/): ${added.length} nova(s), ${revoked.length} revogada(s), ${narrowed.length} com alcance reduzido.`));
217
- }
218
- if (result.revocationProblems?.length) {
219
- console.log(chalk.yellow(`\n⚠️ ${result.revocationProblems.length} revogação(ões) de decisão pedida(s) no plano NÃO foi(ram) aplicada(s):`));
220
- for (const p of result.revocationProblems) {
221
- console.log(chalk.yellow(` ${p.message}`));
222
- }
223
- }
224
- if (result.committed) console.log(chalk.gray(' A mudança já está em commit na branch atual.\n'));
225
- else if (result.staged) console.log(chalk.gray(' A mudança está pronta no git, falta o commit.\n'));
226
- else console.log('');
227
- } catch (error) {
228
- console.error(chalk.red(`\n❌ Não deu para arquivar a feature: ${error.message}\n`));
229
- process.exit(1);
230
- }
231
- }
@@ -1,67 +0,0 @@
1
- import { planAutoApprovalBlock } from './gate-check.js';
2
- import { uiuxAutoApprovalBlock } from '../../lib/specs/screen-checklist.js';
3
- import { GATE_NAME } from '../../../framework/hooks/shared/owner-words.js';
4
- import { SESSION_MARK } from '../../../framework/hooks/shared/next-step.js';
5
- import { ASK_OWNER } from '../../lib/risk-detector.js';
6
-
7
- const HUMAN_SIGN = `${ASK_OWNER}; a resposta "aprovado" do dono grava a aprovação (state-sync), ou ele mesmo aprova num terminal com --approver <nome>`;
8
-
9
- /**
10
- * Why an "auto" signature may not stamp `gate`, or null when it may. The one rule
11
- * `approve` and `advance` share: they write the same `approvalGates` entry.
12
- * `title` and `hints` are for the owner; `todo` is the exact action for the session.
13
- */
14
- export function autoApprovalRefusal({ cwd, featureName, feature, gate, approvedBy }) {
15
- if (approvedBy !== 'auto' || !gate) return null;
16
-
17
- if (gate === 'review' && feature.workType === 'hotfix') {
18
- return {
19
- title: 'Correção urgente: a entrega precisa da sua aprovação. Ela não é aprovada sozinha.',
20
- hints: ['Hotfix exige aprovação humana na Revisão independente.'],
21
- todo: HUMAN_SIGN,
22
- };
23
- }
24
-
25
- const decision = feature.gateDecisions?.[gate];
26
- if (decision?.pause === true) {
27
- return {
28
- title: `A ${GATE_NAME[gate] ?? gate} parou e espera você. Ela não é aprovada sozinha.`,
29
- hints: [`Motivo: ${decision.reason || 'risco detectado'}`],
30
- todo: `a decisão gravada (gateDecisions.${gate}) é pause:true: ${HUMAN_SIGN}. `
31
- + `Se o dono disser que o motivo já não vale, grave: \`morph-spec gate-decision ${featureName} ${gate} --pause false --reason "<motivo do dono>"\``,
32
- };
33
- }
34
-
35
- if (gate === 'plan') {
36
- const block = planAutoApprovalBlock(cwd, featureName, feature);
37
- if (block) {
38
- return {
39
- title: 'O plano não pode ser aprovado sozinho.',
40
- hints: [`Motivo: ${block.reason}`],
41
- todo: `${block.todo ?? HUMAN_SIGN}. O --force não dispensa`,
42
- };
43
- }
44
- }
45
-
46
- if (gate === 'uiux') {
47
- const block = uiuxAutoApprovalBlock(cwd, featureName, feature);
48
- if (block) {
49
- return {
50
- title: 'As telas não podem ser aprovadas sozinhas.',
51
- hints: [`Motivo: ${block}`],
52
- todo: 'complete o checklist (skill morph-uiux) e rode de novo. Sem como completar: '
53
- + `${HUMAN_SIGN}; se o dono já decidiu a pausa, grave: \`morph-spec gate-decision ${featureName} uiux --pause false --reason "<motivo do dono>"\`. `
54
- + 'O --force não dispensa o checklist',
55
- };
56
- }
57
- }
58
-
59
- return null;
60
- }
61
-
62
- export function printRefusal(chalk, refusal) {
63
- console.error(chalk.red(`\n✗ ${refusal.title}`));
64
- for (const line of refusal.hints) console.error(` ${line}`);
65
- if (refusal.todo) console.error(chalk.gray(` ${SESSION_MARK} ${refusal.todo}`));
66
- console.error('');
67
- }
@@ -1,274 +0,0 @@
1
- import chalk from 'chalk';
2
- import { execFileSync } from 'child_process';
3
- import { mkdirSync, cpSync, readFileSync, writeFileSync, existsSync } from 'fs';
4
- import { join } from 'path';
5
- import { createFeature, setApprovalGate, getFeature } from '../../core/state/state-manager.js';
6
- import { WORK_TYPES, DEFAULT_WORK_TYPE, POLICY_APPROVER_PREFIX, isValidWorkType, getWorkType } from '../../core/work-types.js';
7
- import { detectWorkType } from '../../lib/work-type-detector.js';
8
- import { runWorktreeSetup, materializeState, isGitRepo, branchExists, buildBranchName } from '../project/worktree.js';
9
- import { detectDefaultBranch, freshDefaultRef } from '../../lib/git/default-branch.js';
10
- import { writePlanSkeleton } from '../../lib/plan/plan-template.js';
11
- import { seedDotnetBuildIgnores } from '../../lib/stack/dotnet-build-ignores.js';
12
- import { reportDotnetIgnores } from './advance.js';
13
- import { GATE_NAME, WORK_NAME, featureRef } from '../../../framework/hooks/shared/owner-words.js';
14
- import { SESSION_MARK } from '../../../framework/hooks/shared/next-step.js';
15
-
16
- // Branches from the DEFAULT branch, never HEAD, so it never inherits another feature's commits.
17
- // `checkout: false` still CREATES the branch, which `finish` depends on. Fail-open: any git error
18
- // leaves the feature on the current branch, never a failed birth.
19
- function branchCommonFlow(featureName, { checkout = true } = {}) {
20
- const cwd = process.cwd();
21
- try {
22
- if (!isGitRepo(cwd)) return { branched: false, checkedOut: false, reason: 'not-a-git-repo' };
23
- const branch = buildBranchName(featureName);
24
- if (!detectDefaultBranch(cwd)) return { branched: false, checkedOut: false, reason: 'no-default-branch' };
25
- const defaultBranch = branchExists(branch, cwd) ? detectDefaultBranch(cwd) : freshDefaultRef(cwd);
26
- if (!branchExists(branch, cwd)) {
27
- execFileSync('git', ['branch', branch, defaultBranch], { cwd, stdio: 'pipe' });
28
- }
29
- const current = execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd, stdio: 'pipe' }).toString().trim();
30
- if (current === branch) return { branched: true, checkedOut: true, branch, from: defaultBranch };
31
- if (!checkout) return { branched: true, checkedOut: false, branch, from: defaultBranch, stayedOn: current };
32
- execFileSync('git', ['checkout', branch], { cwd, stdio: 'pipe' });
33
- return { branched: true, checkedOut: true, branch, from: defaultBranch, movedFrom: current };
34
- } catch {
35
- return { branched: false, checkedOut: false, reason: 'git-error' };
36
- }
37
- }
38
-
39
- // One builder for stdout and (under --json) stderr, so the two surfaces never drift.
40
- function branchMoveWarning({ branch, movedFrom }) {
41
- return [
42
- `⚠️ Esta pasta MUDOU de branch: ${movedFrom} → ${branch}`,
43
- ` O que ainda não estava em commit veio junto.`,
44
- ` Todo commit feito aqui daqui em diante vai para ${branch}, não para ${movedFrom}.`,
45
- ` Para criar a branch sem mudar esta pasta: --no-checkout.`,
46
- ` Para trabalhar em paralelo, com a feature numa pasta só dela: --worktree (o caminho recomendado).`,
47
- ];
48
- }
49
-
50
- const FEATURE_NAME_RE = /^[a-z0-9][a-z0-9-]*$/;
51
-
52
- const VALID_STATUSES = ['draft', 'in_progress', 'completed'];
53
- const VALID_DETECT_SOURCES = ['deterministic', 'llm', 'user'];
54
-
55
- // Pure control flow, so it can `process.exit` before any side effect happens.
56
- function resolveWorkType(options, now) {
57
- if (options.type !== undefined) {
58
- if (!isValidWorkType(options.type)) {
59
- console.error(chalk.red(`\n❌ --type não reconhecido: "${options.type}"`));
60
- console.error(chalk.gray(`Tipos aceitos: ${Object.keys(WORK_TYPES).join(', ')}\n`));
61
- process.exit(1);
62
- }
63
- if (options.detectSource !== undefined && !VALID_DETECT_SOURCES.includes(options.detectSource)) {
64
- console.error(chalk.red(`\n❌ --detect-source não reconhecido: "${options.detectSource}"`));
65
- console.error(chalk.gray(`Valores aceitos: ${VALID_DETECT_SOURCES.join(', ')}\n`));
66
- process.exit(1);
67
- }
68
- return {
69
- workType: options.type,
70
- workTypeDetection: {
71
- source: options.detectSource || 'user',
72
- confidence: 'high',
73
- decidedAt: now,
74
- },
75
- };
76
- }
77
-
78
- if (options.request !== undefined) {
79
- const d = detectWorkType({ text: options.request });
80
- if (d.confidence !== 'high') {
81
- // Ambiguity escalates to the caller, which re-runs `create --type`: nothing is created here, and
82
- // the output is always JSON since this is the machine-consumable half of the contract.
83
- console.log(JSON.stringify({ needsDecision: true, candidates: d.candidates, matched: d.matched }));
84
- process.exit(2);
85
- }
86
- return {
87
- workType: d.workType,
88
- workTypeDetection: {
89
- source: 'deterministic',
90
- confidence: 'high',
91
- matched: d.matched,
92
- decidedAt: now,
93
- },
94
- };
95
- }
96
-
97
- return { workType: DEFAULT_WORK_TYPE };
98
- }
99
-
100
- // Idempotent: an existing feature is reported and left untouched (no re-stamping, no
101
- // re-scaffolding, no worktree setup).
102
- export async function createCommand(featureName, options = {}) {
103
- try {
104
- if (!FEATURE_NAME_RE.test(featureName)) {
105
- console.error(chalk.red(`\n❌ Identificador da feature inválido: "${featureName}"`));
106
- console.error(chalk.gray('Use kebab-case: letras minúsculas, números e hífens (ex.: "cadastro-de-cliente")\n'));
107
- process.exit(1);
108
- }
109
-
110
- if (options.status !== undefined && !VALID_STATUSES.includes(options.status)) {
111
- console.error(chalk.red(`\n❌ --status não reconhecido: "${options.status}"`));
112
- console.error(chalk.gray(`Valores aceitos: ${VALID_STATUSES.join(', ')}\n`));
113
- process.exit(1);
114
- }
115
-
116
- // `--worktree` nunca move o checkout principal: aceitar `--no-checkout` junto em silêncio é fingir
117
- // que o pedido foi honrado. Recusa AQUI, antes de `createFeature`, a primeira mutação do `create`.
118
- if (options.worktree && options.checkout === false) {
119
- console.error(chalk.red(`\n❌ no-checkout-with-worktree: --no-checkout não se combina com --worktree`));
120
- console.error(chalk.gray(` O --worktree já não move o checkout desta árvore: a feature nasce em worktrees/${featureName},`));
121
- console.error(chalk.gray(` na branch morph/${featureName}, e o caminho de worktree nem chega a ler o --no-checkout.`));
122
- console.error(chalk.gray(` Para isolar a feature na própria árvore: morph-spec create ${featureName} --worktree`));
123
- console.error(chalk.gray(` Para criar só a branch morph/${featureName} sem mover esta árvore: morph-spec create ${featureName} --no-checkout\n`));
124
- process.exit(1);
125
- }
126
-
127
- const now = new Date().toISOString();
128
- const { workType, workTypeDetection } = resolveWorkType(options, now);
129
-
130
- // A NEW feature with no description source is refused: it is the one identity field a human
131
- // must supply. An idempotent re-run never demands it.
132
- const description = options.description ?? options.request ?? null;
133
- // Filesystem, not loadState: loadState throws when no state exists yet (birth from nothing).
134
- const alreadyExists = existsSync(join(process.cwd(), '.morph', 'features', featureName, 'feature.json'));
135
- if (!alreadyExists && (description === null || String(description).trim() === '')) {
136
- console.error(chalk.red(`\n❌ A feature "${featureName}" precisa nascer com uma descrição.`));
137
- console.error(chalk.gray(' Passe --description "<o quê e por quê>" (ou --request \'<pedido>\', que vira a descrição).'));
138
- console.error(chalk.gray(' É pela descrição que a feature aparece com nome nas listas e no status.\n'));
139
- process.exit(1);
140
- }
141
-
142
- const { feature, created } = await createFeature(featureName, {
143
- status: options.status,
144
- workType,
145
- workTypeDetection,
146
- name: options.name,
147
- description: description ?? undefined,
148
- });
149
-
150
- const featureDir = join(process.cwd(), '.morph', 'features', featureName);
151
- const wt = getWorkType(feature);
152
-
153
- let worktreeResult = null;
154
- let branchResult = null;
155
- let planSkeleton = null;
156
- let gitignoreAdded = [];
157
-
158
- if (created) {
159
- for (const folder of wt.scaffold) {
160
- mkdirSync(join(featureDir, folder), { recursive: true });
161
- }
162
-
163
- // NEVER "auto": the gate-guard hook special-cases it; `policy:{type}` keeps the audit honest.
164
- for (const gate of wt.skippedGates) {
165
- await setApprovalGate(featureName, gate, true, {
166
- approvedBy: `${POLICY_APPROVER_PREFIX}${workType}`,
167
- approvedAt: now,
168
- });
169
- }
170
-
171
- if (options.worktree) {
172
- worktreeResult = await runWorktreeSetup(featureName, {});
173
- if (worktreeResult?.created && worktreeResult.path) {
174
- try {
175
- // The root feature.json is not committed yet, so the worktree branch cannot have it: copy it in.
176
- cpSync(featureDir, join(worktreeResult.path, '.morph', 'features', featureName), { recursive: true });
177
- // `.worktree` is ROOT-OWNED: left in the branch copy it merges back at `finish` and leaves the
178
- // root dirty. verify reads the registration from the root copy only.
179
- try {
180
- const wtFeatureJson = join(worktreeResult.path, '.morph', 'features', featureName, 'feature.json');
181
- const fj = JSON.parse(readFileSync(wtFeatureJson, 'utf8'));
182
- if (fj.worktree) {
183
- delete fj.worktree;
184
- writeFileSync(wtFeatureJson, JSON.stringify(fj, null, 2), 'utf8');
185
- }
186
- } catch { /* fail-open — root copy still carries the registration for verify */ }
187
- // Re-materialize after the copy: the setup's earlier materialize ran with no features yet.
188
- const remat = await materializeState(worktreeResult.path);
189
- worktreeResult.materialized = remat.materialized;
190
- } catch { /* fail-open — the feature already exists in root */ }
191
- }
192
- } else {
193
- // Commander's `--no-checkout` sets options.checkout === false.
194
- branchResult = branchCommonFlow(featureName, { checkout: options.checkout !== false });
195
- }
196
-
197
- // protect-spec-files freezes an existing file once its approval is stamped,
198
- // so a type born pre-approved must create it itself. With a worktree it goes
199
- // only there: an extra file in the root copy makes `finish` refuse a dirty root.
200
- if (wt.scaffold.includes('2-plan') && !wt.skippedGates.includes('plan')) {
201
- const home = worktreeResult?.created && worktreeResult.path ? worktreeResult.path : process.cwd();
202
- try {
203
- planSkeleton = writePlanSkeleton(featureName, home);
204
- } catch (err) {
205
- planSkeleton = { written: false, error: err.message };
206
- }
207
- }
208
-
209
- const home = worktreeResult?.created && worktreeResult.path ? worktreeResult.path : process.cwd();
210
- gitignoreAdded = seedDotnetBuildIgnores(home, { featureName, configRoot: process.cwd() });
211
- }
212
-
213
- // `feature` predates the gate-stamping and worktree steps, which each round-trip state on disk.
214
- const finalFeature = created ? (getFeature(featureName) || feature) : feature;
215
-
216
- if (options.json) {
217
- const out = { feature: featureName, created, ...finalFeature };
218
- if (worktreeResult) out.worktree = worktreeResult;
219
- if (branchResult) out.branch = branchResult;
220
- if (planSkeleton) out.planSkeleton = planSkeleton;
221
- if (gitignoreAdded.length) out.gitignoreAdded = gitignoreAdded;
222
- if (gitignoreAdded.skipped) out.gitignoreSkipped = gitignoreAdded.skipped;
223
- // Under --json the move goes to stderr, so it survives `... --json > out.json`.
224
- if (branchResult?.movedFrom) {
225
- console.error(chalk.yellow(branchMoveWarning(branchResult).join('\n')));
226
- }
227
- console.log(JSON.stringify(out, null, 2));
228
- return;
229
- }
230
-
231
- const ref = featureRef(featureName, finalFeature);
232
- if (created) {
233
- console.log(chalk.green(`\n✅ Feature criada: ${ref}`));
234
- console.log(chalk.gray(` Tipo: ${WORK_NAME[finalFeature.workType] ?? finalFeature.workType} (${finalFeature.workType})`));
235
- reportDotnetIgnores(gitignoreAdded);
236
- if (planSkeleton?.written) {
237
- console.log(chalk.gray(' O plano começa de um modelo em branco, pronto para preencher.'));
238
- }
239
- if (wt.skippedGates.length) {
240
- const skipped = wt.skippedGates.map((g) => GATE_NAME[g] ?? g).join(', ');
241
- console.log(chalk.yellow(` Este tipo de trabalho dispensa: ${skipped}.`));
242
- }
243
- console.log(chalk.gray(` ${SESSION_MARK} ${wt.entrySkill}; pastas criadas em .morph/features/${featureName}/: ${wt.scaffold.join(', ')}\n`));
244
-
245
- if (worktreeResult) {
246
- if (worktreeResult.created) {
247
- console.log(chalk.green(' A feature ganhou uma pasta própria, separada da principal.'));
248
- console.log(chalk.gray(` ${SESSION_MARK} pasta ${worktreeResult.path} (branch ${worktreeResult.branch})`));
249
- console.log(chalk.gray(` ${worktreeResult.nextStep}\n`));
250
- } else {
251
- const why = worktreeResult.error || (worktreeResult.alreadyExists ? 'a pasta já existe' : 'motivo desconhecido');
252
- console.log(chalk.yellow(` ⚠️ Não deu para criar a pasta separada (${why}). A feature fica na pasta principal.\n`));
253
- }
254
- } else if (branchResult?.branched) {
255
- console.log(chalk.green(` O trabalho fica numa branch própria, separado de ${branchResult.from} até a entrega.`));
256
- console.log(chalk.gray(` ${SESSION_MARK} branch ${branchResult.branch}; para entregar: morph-spec finish ${featureName} --pr | --merge`));
257
- if (branchResult.movedFrom) {
258
- // Alert, not one more success line: the tree the dev is standing in moved.
259
- console.log('');
260
- for (const line of branchMoveWarning(branchResult)) console.log(chalk.yellow(` ${line}`));
261
- } else if (branchResult.checkedOut === false) {
262
- console.log(chalk.gray(` Esta pasta continua na branch ${branchResult.stayedOn} (--no-checkout).`));
263
- }
264
- console.log('');
265
- }
266
- } else {
267
- console.log(chalk.yellow(`\n⚠️ A feature ${ref} já existe. Nada foi mudado.`));
268
- console.log(chalk.gray(` Tipo: ${WORK_NAME[finalFeature.workType || 'feature'] ?? finalFeature.workType}. Criada em ${finalFeature.createdAt || 'data desconhecida'}.\n`));
269
- }
270
- } catch (error) {
271
- console.error(chalk.red(`\n❌ Não deu para criar a feature: ${error.message}\n`));
272
- process.exit(1);
273
- }
274
- }