@lumenflow/core 1.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 (263) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +119 -0
  3. package/dist/active-wu-detector.d.ts +33 -0
  4. package/dist/active-wu-detector.js +106 -0
  5. package/dist/adapters/filesystem-metrics.adapter.d.ts +108 -0
  6. package/dist/adapters/filesystem-metrics.adapter.js +519 -0
  7. package/dist/adapters/terminal-renderer.adapter.d.ts +106 -0
  8. package/dist/adapters/terminal-renderer.adapter.js +337 -0
  9. package/dist/arg-parser.d.ts +63 -0
  10. package/dist/arg-parser.js +560 -0
  11. package/dist/backlog-editor.d.ts +98 -0
  12. package/dist/backlog-editor.js +179 -0
  13. package/dist/backlog-generator.d.ts +111 -0
  14. package/dist/backlog-generator.js +381 -0
  15. package/dist/backlog-parser.d.ts +45 -0
  16. package/dist/backlog-parser.js +102 -0
  17. package/dist/backlog-sync-validator.d.ts +78 -0
  18. package/dist/backlog-sync-validator.js +294 -0
  19. package/dist/branch-drift.d.ts +34 -0
  20. package/dist/branch-drift.js +51 -0
  21. package/dist/cleanup-install-config.d.ts +33 -0
  22. package/dist/cleanup-install-config.js +37 -0
  23. package/dist/cleanup-lock.d.ts +139 -0
  24. package/dist/cleanup-lock.js +313 -0
  25. package/dist/code-path-validator.d.ts +146 -0
  26. package/dist/code-path-validator.js +537 -0
  27. package/dist/code-paths-overlap.d.ts +55 -0
  28. package/dist/code-paths-overlap.js +245 -0
  29. package/dist/commands-logger.d.ts +77 -0
  30. package/dist/commands-logger.js +254 -0
  31. package/dist/commit-message-utils.d.ts +25 -0
  32. package/dist/commit-message-utils.js +41 -0
  33. package/dist/compliance-parser.d.ts +150 -0
  34. package/dist/compliance-parser.js +507 -0
  35. package/dist/constants/backlog-patterns.d.ts +20 -0
  36. package/dist/constants/backlog-patterns.js +23 -0
  37. package/dist/constants/dora-constants.d.ts +49 -0
  38. package/dist/constants/dora-constants.js +53 -0
  39. package/dist/constants/gate-constants.d.ts +15 -0
  40. package/dist/constants/gate-constants.js +15 -0
  41. package/dist/constants/linter-constants.d.ts +16 -0
  42. package/dist/constants/linter-constants.js +16 -0
  43. package/dist/constants/tokenizer-constants.d.ts +15 -0
  44. package/dist/constants/tokenizer-constants.js +15 -0
  45. package/dist/core/scope-checker.d.ts +97 -0
  46. package/dist/core/scope-checker.js +163 -0
  47. package/dist/core/tool-runner.d.ts +161 -0
  48. package/dist/core/tool-runner.js +393 -0
  49. package/dist/core/tool.constants.d.ts +105 -0
  50. package/dist/core/tool.constants.js +101 -0
  51. package/dist/core/tool.schemas.d.ts +226 -0
  52. package/dist/core/tool.schemas.js +226 -0
  53. package/dist/core/worktree-guard.d.ts +130 -0
  54. package/dist/core/worktree-guard.js +242 -0
  55. package/dist/coverage-gate.d.ts +108 -0
  56. package/dist/coverage-gate.js +196 -0
  57. package/dist/date-utils.d.ts +75 -0
  58. package/dist/date-utils.js +140 -0
  59. package/dist/dependency-graph.d.ts +142 -0
  60. package/dist/dependency-graph.js +550 -0
  61. package/dist/dependency-guard.d.ts +54 -0
  62. package/dist/dependency-guard.js +142 -0
  63. package/dist/dependency-validator.d.ts +105 -0
  64. package/dist/dependency-validator.js +154 -0
  65. package/dist/docs-path-validator.d.ts +36 -0
  66. package/dist/docs-path-validator.js +95 -0
  67. package/dist/domain/orchestration.constants.d.ts +99 -0
  68. package/dist/domain/orchestration.constants.js +97 -0
  69. package/dist/domain/orchestration.schemas.d.ts +280 -0
  70. package/dist/domain/orchestration.schemas.js +211 -0
  71. package/dist/domain/orchestration.types.d.ts +133 -0
  72. package/dist/domain/orchestration.types.js +12 -0
  73. package/dist/error-handler.d.ts +116 -0
  74. package/dist/error-handler.js +136 -0
  75. package/dist/file-classifiers.d.ts +62 -0
  76. package/dist/file-classifiers.js +108 -0
  77. package/dist/gates-agent-mode.d.ts +81 -0
  78. package/dist/gates-agent-mode.js +94 -0
  79. package/dist/generate-traceability.d.ts +107 -0
  80. package/dist/generate-traceability.js +411 -0
  81. package/dist/git-adapter.d.ts +395 -0
  82. package/dist/git-adapter.js +649 -0
  83. package/dist/git-staged-validator.d.ts +32 -0
  84. package/dist/git-staged-validator.js +48 -0
  85. package/dist/hardcoded-strings.d.ts +61 -0
  86. package/dist/hardcoded-strings.js +270 -0
  87. package/dist/incremental-lint.d.ts +78 -0
  88. package/dist/incremental-lint.js +129 -0
  89. package/dist/incremental-test.d.ts +39 -0
  90. package/dist/incremental-test.js +61 -0
  91. package/dist/index.d.ts +42 -0
  92. package/dist/index.js +61 -0
  93. package/dist/invariants/check-automated-tests.d.ts +50 -0
  94. package/dist/invariants/check-automated-tests.js +166 -0
  95. package/dist/invariants-runner.d.ts +103 -0
  96. package/dist/invariants-runner.js +527 -0
  97. package/dist/lane-checker.d.ts +50 -0
  98. package/dist/lane-checker.js +319 -0
  99. package/dist/lane-inference.d.ts +39 -0
  100. package/dist/lane-inference.js +195 -0
  101. package/dist/lane-lock.d.ts +211 -0
  102. package/dist/lane-lock.js +474 -0
  103. package/dist/lane-validator.d.ts +48 -0
  104. package/dist/lane-validator.js +114 -0
  105. package/dist/logs-lib.d.ts +104 -0
  106. package/dist/logs-lib.js +207 -0
  107. package/dist/lumenflow-config-schema.d.ts +272 -0
  108. package/dist/lumenflow-config-schema.js +207 -0
  109. package/dist/lumenflow-config.d.ts +95 -0
  110. package/dist/lumenflow-config.js +236 -0
  111. package/dist/manual-test-validator.d.ts +80 -0
  112. package/dist/manual-test-validator.js +200 -0
  113. package/dist/merge-lock.d.ts +115 -0
  114. package/dist/merge-lock.js +251 -0
  115. package/dist/micro-worktree.d.ts +159 -0
  116. package/dist/micro-worktree.js +427 -0
  117. package/dist/migration-deployer.d.ts +69 -0
  118. package/dist/migration-deployer.js +151 -0
  119. package/dist/orchestration-advisory-loader.d.ts +28 -0
  120. package/dist/orchestration-advisory-loader.js +87 -0
  121. package/dist/orchestration-advisory.d.ts +58 -0
  122. package/dist/orchestration-advisory.js +94 -0
  123. package/dist/orchestration-di.d.ts +48 -0
  124. package/dist/orchestration-di.js +57 -0
  125. package/dist/orchestration-rules.d.ts +57 -0
  126. package/dist/orchestration-rules.js +201 -0
  127. package/dist/orphan-detector.d.ts +131 -0
  128. package/dist/orphan-detector.js +226 -0
  129. package/dist/path-classifiers.d.ts +57 -0
  130. package/dist/path-classifiers.js +93 -0
  131. package/dist/piped-command-detector.d.ts +34 -0
  132. package/dist/piped-command-detector.js +64 -0
  133. package/dist/ports/dashboard-renderer.port.d.ts +112 -0
  134. package/dist/ports/dashboard-renderer.port.js +25 -0
  135. package/dist/ports/metrics-collector.port.d.ts +132 -0
  136. package/dist/ports/metrics-collector.port.js +26 -0
  137. package/dist/process-detector.d.ts +84 -0
  138. package/dist/process-detector.js +172 -0
  139. package/dist/prompt-linter.d.ts +72 -0
  140. package/dist/prompt-linter.js +312 -0
  141. package/dist/prompt-monitor.d.ts +15 -0
  142. package/dist/prompt-monitor.js +205 -0
  143. package/dist/rebase-artifact-cleanup.d.ts +145 -0
  144. package/dist/rebase-artifact-cleanup.js +433 -0
  145. package/dist/retry-strategy.d.ts +189 -0
  146. package/dist/retry-strategy.js +283 -0
  147. package/dist/risk-detector.d.ts +108 -0
  148. package/dist/risk-detector.js +252 -0
  149. package/dist/rollback-utils.d.ts +76 -0
  150. package/dist/rollback-utils.js +104 -0
  151. package/dist/section-headings.d.ts +43 -0
  152. package/dist/section-headings.js +49 -0
  153. package/dist/spawn-escalation.d.ts +90 -0
  154. package/dist/spawn-escalation.js +253 -0
  155. package/dist/spawn-monitor.d.ts +229 -0
  156. package/dist/spawn-monitor.js +672 -0
  157. package/dist/spawn-recovery.d.ts +82 -0
  158. package/dist/spawn-recovery.js +298 -0
  159. package/dist/spawn-registry-schema.d.ts +98 -0
  160. package/dist/spawn-registry-schema.js +108 -0
  161. package/dist/spawn-registry-store.d.ts +146 -0
  162. package/dist/spawn-registry-store.js +273 -0
  163. package/dist/spawn-tree.d.ts +121 -0
  164. package/dist/spawn-tree.js +285 -0
  165. package/dist/stamp-status-validator.d.ts +84 -0
  166. package/dist/stamp-status-validator.js +134 -0
  167. package/dist/stamp-utils.d.ts +100 -0
  168. package/dist/stamp-utils.js +229 -0
  169. package/dist/state-machine.d.ts +26 -0
  170. package/dist/state-machine.js +83 -0
  171. package/dist/system-map-validator.d.ts +80 -0
  172. package/dist/system-map-validator.js +272 -0
  173. package/dist/telemetry.d.ts +80 -0
  174. package/dist/telemetry.js +213 -0
  175. package/dist/token-counter.d.ts +51 -0
  176. package/dist/token-counter.js +145 -0
  177. package/dist/usecases/get-dashboard-data.usecase.d.ts +52 -0
  178. package/dist/usecases/get-dashboard-data.usecase.js +61 -0
  179. package/dist/usecases/get-suggestions.usecase.d.ts +100 -0
  180. package/dist/usecases/get-suggestions.usecase.js +153 -0
  181. package/dist/user-normalizer.d.ts +41 -0
  182. package/dist/user-normalizer.js +141 -0
  183. package/dist/validators/phi-constants.d.ts +97 -0
  184. package/dist/validators/phi-constants.js +152 -0
  185. package/dist/validators/phi-scanner.d.ts +58 -0
  186. package/dist/validators/phi-scanner.js +215 -0
  187. package/dist/worktree-ownership.d.ts +50 -0
  188. package/dist/worktree-ownership.js +74 -0
  189. package/dist/worktree-scanner.d.ts +103 -0
  190. package/dist/worktree-scanner.js +168 -0
  191. package/dist/worktree-symlink.d.ts +99 -0
  192. package/dist/worktree-symlink.js +359 -0
  193. package/dist/wu-backlog-updater.d.ts +17 -0
  194. package/dist/wu-backlog-updater.js +37 -0
  195. package/dist/wu-checkpoint.d.ts +124 -0
  196. package/dist/wu-checkpoint.js +233 -0
  197. package/dist/wu-claim-helpers.d.ts +26 -0
  198. package/dist/wu-claim-helpers.js +63 -0
  199. package/dist/wu-claim-resume.d.ts +106 -0
  200. package/dist/wu-claim-resume.js +276 -0
  201. package/dist/wu-consistency-checker.d.ts +95 -0
  202. package/dist/wu-consistency-checker.js +567 -0
  203. package/dist/wu-constants.d.ts +1275 -0
  204. package/dist/wu-constants.js +1382 -0
  205. package/dist/wu-create-validators.d.ts +42 -0
  206. package/dist/wu-create-validators.js +93 -0
  207. package/dist/wu-done-branch-only.d.ts +63 -0
  208. package/dist/wu-done-branch-only.js +191 -0
  209. package/dist/wu-done-messages.d.ts +119 -0
  210. package/dist/wu-done-messages.js +185 -0
  211. package/dist/wu-done-pr.d.ts +72 -0
  212. package/dist/wu-done-pr.js +174 -0
  213. package/dist/wu-done-retry-helpers.d.ts +85 -0
  214. package/dist/wu-done-retry-helpers.js +172 -0
  215. package/dist/wu-done-ui.d.ts +37 -0
  216. package/dist/wu-done-ui.js +69 -0
  217. package/dist/wu-done-validators.d.ts +411 -0
  218. package/dist/wu-done-validators.js +1229 -0
  219. package/dist/wu-done-worktree.d.ts +182 -0
  220. package/dist/wu-done-worktree.js +1097 -0
  221. package/dist/wu-helpers.d.ts +128 -0
  222. package/dist/wu-helpers.js +248 -0
  223. package/dist/wu-lint.d.ts +70 -0
  224. package/dist/wu-lint.js +234 -0
  225. package/dist/wu-paths.d.ts +171 -0
  226. package/dist/wu-paths.js +178 -0
  227. package/dist/wu-preflight-validators.d.ts +86 -0
  228. package/dist/wu-preflight-validators.js +251 -0
  229. package/dist/wu-recovery.d.ts +138 -0
  230. package/dist/wu-recovery.js +341 -0
  231. package/dist/wu-repair-core.d.ts +131 -0
  232. package/dist/wu-repair-core.js +669 -0
  233. package/dist/wu-schema-normalization.d.ts +17 -0
  234. package/dist/wu-schema-normalization.js +82 -0
  235. package/dist/wu-schema.d.ts +793 -0
  236. package/dist/wu-schema.js +881 -0
  237. package/dist/wu-spawn-helpers.d.ts +121 -0
  238. package/dist/wu-spawn-helpers.js +271 -0
  239. package/dist/wu-spawn.d.ts +158 -0
  240. package/dist/wu-spawn.js +1306 -0
  241. package/dist/wu-state-schema.d.ts +213 -0
  242. package/dist/wu-state-schema.js +156 -0
  243. package/dist/wu-state-store.d.ts +264 -0
  244. package/dist/wu-state-store.js +691 -0
  245. package/dist/wu-status-transition.d.ts +63 -0
  246. package/dist/wu-status-transition.js +382 -0
  247. package/dist/wu-status-updater.d.ts +25 -0
  248. package/dist/wu-status-updater.js +116 -0
  249. package/dist/wu-transaction-collectors.d.ts +116 -0
  250. package/dist/wu-transaction-collectors.js +272 -0
  251. package/dist/wu-transaction.d.ts +170 -0
  252. package/dist/wu-transaction.js +273 -0
  253. package/dist/wu-validation-constants.d.ts +60 -0
  254. package/dist/wu-validation-constants.js +66 -0
  255. package/dist/wu-validation.d.ts +118 -0
  256. package/dist/wu-validation.js +243 -0
  257. package/dist/wu-validator.d.ts +62 -0
  258. package/dist/wu-validator.js +325 -0
  259. package/dist/wu-yaml-fixer.d.ts +97 -0
  260. package/dist/wu-yaml-fixer.js +264 -0
  261. package/dist/wu-yaml.d.ts +86 -0
  262. package/dist/wu-yaml.js +222 -0
  263. package/package.json +114 -0
@@ -0,0 +1,185 @@
1
+ /**
2
+ * @file wu-done-messages.mjs
3
+ * @description Constants and message templates for wu-done operations
4
+ * WU-1159: Eliminate string literals (DRY/SOLID compliance)
5
+ * WU-1281: Use centralized LOG_PREFIX and EMOJI from wu-constants.mjs
6
+ *
7
+ * All log messages, error messages, and text templates extracted to constants.
8
+ * Prevents duplication and makes text maintainable.
9
+ */
10
+ import { LOG_PREFIX, EMOJI, REMOTES, BRANCHES } from './wu-constants.js';
11
+ // Re-export LOG_PREFIX for backwards compatibility
12
+ export { LOG_PREFIX };
13
+ /**
14
+ * Recovery mode messages (WU-1159)
15
+ */
16
+ export const RECOVERY = {
17
+ DETECTED: `${LOG_PREFIX.DONE} ${EMOJI.WARNING} RECOVERY MODE: Status is already "done" but worktree exists.`,
18
+ RESUMING: `${LOG_PREFIX.DONE} ${EMOJI.WARNING} Resuming cleanup to complete the WU...`,
19
+ EXPLANATION: `${LOG_PREFIX.DONE} This typically happens when a previous wu:done crashed mid-completion.`,
20
+ CREATING_STAMP: `${LOG_PREFIX.DONE} Creating missing stamp file...`,
21
+ STAMP_CREATED: `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Stamp file created`,
22
+ UPDATING_YAML: `${LOG_PREFIX.DONE} Updating WU YAML to ensure completion markers...`,
23
+ YAML_UPDATED: `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} WU YAML updated with completion markers`,
24
+ UPDATING_DOCS: `${LOG_PREFIX.DONE} Ensuring status.md and backlog.md are updated...`,
25
+ DOCS_UPDATED: `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Documentation files verified`,
26
+ COMMITTING: `${LOG_PREFIX.DONE} Committing recovery changes to prevent data loss...`,
27
+ COMMIT_SUCCESS: `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Recovery changes committed to main`,
28
+ COMMIT_FAILED: (error) => `${LOG_PREFIX.DONE} ${EMOJI.WARNING} Could not commit recovery changes: ${error} (metadata still on disk)`,
29
+ MARKERS_VERIFIED: `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Recovery mode: All completion markers verified`,
30
+ PROCEEDING_CLEANUP: `${LOG_PREFIX.DONE} Proceeding to cleanup (worktree removal and branch deletion)...`,
31
+ SUCCESS: `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Recovery mode successful - zombie state cleaned up`,
32
+ };
33
+ /**
34
+ * Worktree operations
35
+ */
36
+ export const WORKTREE = {
37
+ REMOVED: (path) => `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Removed worktree ${path}`,
38
+ NOT_FOUND: `${LOG_PREFIX.DONE} Worktree not found; skipping removal`,
39
+ REMOVE_FAILED: (path, error) => `${LOG_PREFIX.DONE} Could not remove worktree ${path}: ${error}`,
40
+ PRESERVED_PR_MODE: `${LOG_PREFIX.DONE} ${EMOJI.WARNING} Worktree preserved (PR mode - run wu:cleanup after PR merge)`,
41
+ };
42
+ /**
43
+ * Branch operations
44
+ */
45
+ export const BRANCH = {
46
+ DELETED_LOCAL: (branch) => `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Deleted local branch ${branch}`,
47
+ DELETED_REMOTE: (branch) => `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Deleted remote branch ${branch}`,
48
+ DELETE_FAILED: (branch, error) => `${LOG_PREFIX.DONE} Could not delete branch ${branch}: ${error}`,
49
+ DELETE_REMOTE_FAILED: (error) => `${LOG_PREFIX.DONE} Could not delete remote branch: ${error}`,
50
+ PRESERVED_PR_MODE: `${LOG_PREFIX.DONE} ${EMOJI.WARNING} Branch preserved (PR mode - delete manually after merge)`,
51
+ };
52
+ /**
53
+ * Completion messages
54
+ */
55
+ export const COMPLETION = {
56
+ SUCCESS_HEADER: (id, title) => `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Marked done, pushed, and cleaned up.\n- WU: ${id} — ${title}`,
57
+ TRANSACTION_COMMIT: `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Transaction COMMIT - all steps succeeded (WU-755)`,
58
+ };
59
+ /**
60
+ * State transition errors
61
+ */
62
+ export const STATE_TRANSITION = {
63
+ VALIDATION_FAILED: (error) => `State transition validation failed: ${error}`,
64
+ };
65
+ /**
66
+ * Auto-rebase messages (WU-1303)
67
+ */
68
+ export const REBASE = {
69
+ STARTING: (branch, mainBranch) => `${LOG_PREFIX.DONE} ${EMOJI.WRENCH} Auto-rebasing ${branch} onto ${mainBranch}...`,
70
+ SUCCESS: `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Auto-rebase completed successfully`,
71
+ FAILED: (error) => `${LOG_PREFIX.DONE} ${EMOJI.FAILURE} Auto-rebase failed: ${error}`,
72
+ ABORTED: `${LOG_PREFIX.DONE} ${EMOJI.INFO} Rebase aborted - worktree left clean`,
73
+ MANUAL_FIX: (worktreePath, remote, mainBranch, branch) => `Auto-rebase failed due to conflicts.\n\n` +
74
+ `Manual resolution required:\n` +
75
+ ` 1. cd ${worktreePath}\n` +
76
+ ` 2. git fetch ${remote} ${mainBranch}\n` +
77
+ ` 3. git rebase ${remote}/${mainBranch}\n` +
78
+ ` 4. Resolve conflicts and run: git rebase --continue\n` +
79
+ ` 5. git push --force-with-lease ${remote} ${branch}\n` +
80
+ ` 6. Return to main checkout and retry: pnpm wu:done --id <WU-ID>`,
81
+ };
82
+ /**
83
+ * Pre-flight check messages (WU-755, WU-1303, WU-1370)
84
+ */
85
+ export const PREFLIGHT = {
86
+ RUNNING: `\n${LOG_PREFIX.DONE} Running pre-flight checks (WU-755)...`,
87
+ BRANCH_BEHIND: (commitsBehind, threshold) => `${LOG_PREFIX.DONE} ${EMOJI.INFO} Branch is ${commitsBehind} commits behind main (threshold: ${threshold})`,
88
+ // WU-1370: Graduated drift warning messages
89
+ BRANCH_DRIFT_INFO: (commitsBehind) => `${LOG_PREFIX.DONE} ${EMOJI.INFO} Branch is ${commitsBehind} commits behind main. Consider rebasing to reduce merge conflicts.`,
90
+ BRANCH_DRIFT_WARNING: (commitsBehind) => `${LOG_PREFIX.DONE} ${EMOJI.WARNING} Branch is ${commitsBehind} commits behind main. Rebase recommended before completing.`,
91
+ DIVERGENCE_DETECTED: (commitCount) => `${LOG_PREFIX.DONE} ${EMOJI.WARNING} Branch divergence detected: main is ${commitCount} commit(s) ahead`,
92
+ NO_DIVERGENCE: `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Pre-flight: No branch divergence (main has not advanced)`,
93
+ NO_CONFLICTS: `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Pre-flight: No merge conflicts detected`,
94
+ ALREADY_MERGED: `\n${LOG_PREFIX.DONE} ${EMOJI.INFO} Branch already merged to main - proceeding with metadata-only completion`,
95
+ ALREADY_MERGED_EXPLANATION: ` This is normal when code was merged via emergency fix or manual merge.`,
96
+ BRANCH_INFO: (branch, branchTip, mergeBase, mainHead) => `${LOG_PREFIX.DONE} ${EMOJI.INFO} Branch ${branch} is already merged to main\n` +
97
+ ` Branch tip: ${branchTip}\n` +
98
+ ` Merge-base: ${mergeBase}\n` +
99
+ ` Main HEAD: ${mainHead}`,
100
+ BRANCH_DRIFT_ERROR: (mainAhead, threshold, remote, mainBranch) => `āš ļø BRANCH DRIFT DETECTED (WU-755 pre-flight check)\n\n` +
101
+ `Your branch is ${mainAhead} commits behind main (threshold: ${threshold} commits).\n` +
102
+ `This increases risk of merge conflicts at completion.\n\n` +
103
+ `REQUIRED: Rebase your branch before completing:\n` +
104
+ ` 1. cd into your worktree\n` +
105
+ ` 2. Run: git fetch ${remote} ${mainBranch} && git rebase ${remote}/${mainBranch}\n` +
106
+ ` 3. Resolve any conflicts that arise\n` +
107
+ ` 4. Return to main checkout and retry: pnpm wu:done --id <WU-ID>`,
108
+ DIVERGENCE_ERROR: (commitCount, remote, mainBranch, branch) => `āš ļø BRANCH DIVERGENCE DETECTED (emergency fix protection)\n\n` +
109
+ `Main has advanced ${commitCount} commit(s) since your branch was created.\n` +
110
+ `Fast-forward merge is impossible.\n\n` +
111
+ `REQUIRED: Rebase your branch onto current main:\n` +
112
+ ` 1. cd into your worktree\n` +
113
+ ` 2. Fetch latest main: git fetch ${remote} ${mainBranch}\n` +
114
+ ` 3. Rebase onto main: git rebase ${remote}/${mainBranch}\n` +
115
+ ` 4. Force-push lane branch: git push --force-with-lease ${remote} ${branch}\n` +
116
+ ` 5. Return to main checkout and retry`,
117
+ CONFLICT_ERROR: (remote = REMOTES.ORIGIN, mainBranch = BRANCHES.MAIN) => `āš ļø MERGE CONFLICTS DETECTED (WU-755 pre-flight check)\n\n` +
118
+ `Cannot complete WU - merge conflicts found between main and your branch.\n\n` +
119
+ `REQUIRED: Resolve conflicts before completing:\n` +
120
+ ` 1. cd into your worktree\n` +
121
+ ` 2. Run: git fetch ${remote} ${mainBranch} && git rebase ${remote}/${mainBranch}\n` +
122
+ ` 3. Resolve conflicts that arise during rebase\n` +
123
+ ` 4. Run: git rebase --continue after resolving each conflict\n` +
124
+ ` 5. Return to main checkout and retry`,
125
+ // WU-1384: Merge commit detection for linear history enforcement
126
+ MERGE_COMMITS_DETECTED: (count) => `${LOG_PREFIX.DONE} ${EMOJI.WARNING} Detected ${count} merge commit(s) in lane branch (GitHub requires linear history)`,
127
+ MERGE_COMMITS_REBASING: `${LOG_PREFIX.DONE} ${EMOJI.WRENCH} Rebasing to eliminate merge commits and maintain linear history...`,
128
+ NO_MERGE_COMMITS: `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Pre-flight: No merge commits in branch (linear history)`,
129
+ // WU-1456: Empty merge detection - prevents completing WUs with no actual work
130
+ EMPTY_MERGE_WARNING: (commitCount) => `\n${LOG_PREFIX.DONE} āš ļø WARNING: Only ${commitCount} commit(s) on lane branch beyond claim.\n` +
131
+ ` This may indicate no code changes were committed before running wu:done.\n` +
132
+ ` If this is intentional (docs-only or metadata update), you may proceed.\n` +
133
+ ` Otherwise, check that your changes were committed in the worktree.\n`,
134
+ EMPTY_MERGE_CHECK: `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Pre-flight: Branch has work commits beyond claim`,
135
+ // WU-1460: code_paths blocker - prevents completing WUs with code_paths defined but files not modified
136
+ CODE_PATHS_NOT_MODIFIED: (missingFiles) => `Cannot complete WU - code_paths files were NOT modified in any commits.\n\n` +
137
+ `This WU defines code_paths that should have been implemented:\n` +
138
+ missingFiles.map((f) => ` - ${f}`).join('\n') +
139
+ `\n\nThis error prevents completing a WU without actually committing the code.\n` +
140
+ `The worktree would be deleted and your work would be lost.\n\n` +
141
+ `REQUIRED: Commit your code changes before running wu:done:\n` +
142
+ ` 1. cd into your worktree\n` +
143
+ ` 2. git add <your files>\n` +
144
+ ` 3. git commit -m "feat: <description>"\n` +
145
+ ` 4. Return to main and retry: pnpm wu:done --id <WU-ID>`,
146
+ CODE_PATHS_VERIFIED: `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Pre-flight: code_paths files modified in commits`,
147
+ };
148
+ /**
149
+ * Merge operation messages (WU-1303)
150
+ */
151
+ export const MERGE = {
152
+ STARTING: (branch) => `\n${LOG_PREFIX.DONE} Merging lane branch to main (metadata + code)...`,
153
+ BRANCH_MERGE: (branch) => `\n${LOG_PREFIX.DONE} Merging branch ${branch} to main (fast-forward only)...`,
154
+ SUCCESS: (branch) => `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Merged ${branch} successfully (fast-forward)`,
155
+ ATOMIC_SUCCESS: `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Metadata and code merged to main atomically`,
156
+ FF_FAILED_RETRY: `${LOG_PREFIX.DONE} ${EMOJI.WARNING} Fast-forward failed, updating main and retrying...`,
157
+ UPDATED_MAIN: (remote) => `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Updated main from ${remote}, retrying merge...`,
158
+ PUSHED: (remote, mainBranch) => `${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Pushed to ${remote}/${mainBranch}`,
159
+ FF_MERGE_ERROR: (branch, mergeError, pullError, remote = REMOTES.ORIGIN, mainBranch = BRANCHES.MAIN) => `Fast-forward merge failed and retry with git pull also failed.\n\n` +
160
+ `Original merge error: ${mergeError}\n` +
161
+ `Pull error: ${pullError}\n\n` +
162
+ `Manual fix required:\n` +
163
+ ` 1. git pull ${remote} ${mainBranch}\n` +
164
+ ` 2. Resolve any conflicts\n` +
165
+ ` 3. Switch to your worktree and rebase onto ${mainBranch}\n` +
166
+ ` 4. Return to main checkout and retry`,
167
+ FF_DIVERGED_ERROR: (branch, originalError, mainBranch = BRANCHES.MAIN) => `Fast-forward merge failed for ${branch}.\n\n` +
168
+ `This means your branch has diverged from ${mainBranch}.\n` +
169
+ `To fix:\n` +
170
+ ` 1. Switch to your worktree: cd <worktree-path>\n` +
171
+ ` 2. Rebase onto ${mainBranch}: git rebase ${mainBranch}\n` +
172
+ ` 3. Return to main checkout and retry`,
173
+ FF_FAILED_NON_DIVERGED_ERROR: (branch, originalError, mainBranch = BRANCHES.MAIN) => `Fast-forward merge failed for ${branch}, but ${mainBranch} is an ancestor.\n\n` +
174
+ `This indicates the merge did not fail due to divergence.\n` +
175
+ `Underlying git error: ${originalError}\n\n` +
176
+ `Next steps:\n` +
177
+ ` 1. Re-run: pnpm wu:done --id <WU-ID>\n` +
178
+ ` 2. If it repeats, check for concurrent git activity and retry after a short wait`,
179
+ };
180
+ /**
181
+ * Pre-push gate messages (WU-1303)
182
+ */
183
+ export const PREPUSH = {
184
+ WORKTREE_SKIP: '[pre-push] Worktree detected - skipping gates (validated at merge via wu:done)',
185
+ };
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * PR mode completion workflow for wu:done
4
+ * Extracted from wu-done.mjs (WU-1215 refactoring)
5
+ *
6
+ * PR mode creates a GitHub PR instead of auto-merging to main.
7
+ * Used for:
8
+ * - External agents requiring review (claimed_mode: worktree-pr)
9
+ * - High-risk WUs (requires_review: true in WU YAML)
10
+ * - One-off PR creation (--create-pr flag)
11
+ */
12
+ /**
13
+ * @typedef {Object} PRContext
14
+ * @property {string} branch - Lane branch name
15
+ * @property {string} id - WU ID (e.g., "WU-1215")
16
+ * @property {string} title - WU title for PR title
17
+ * @property {Object} doc - WU YAML document
18
+ * @property {boolean} [draft] - Whether to create as draft PR
19
+ */
20
+ /**
21
+ * @typedef {Object} PRResult
22
+ * @property {boolean} success - Whether PR creation succeeded
23
+ * @property {string|null} prUrl - URL of created PR (null if gh CLI unavailable)
24
+ * @property {boolean} ghAvailable - Whether gh CLI is available
25
+ */
26
+ /**
27
+ * Check if PR mode is enabled for this WU
28
+ *
29
+ * @param {Object} doc - WU YAML document
30
+ * @param {Object} args - CLI arguments
31
+ * @returns {boolean} Whether PR mode is enabled
32
+ */
33
+ export declare function isPRModeEnabled(doc: any, args: any): any;
34
+ /**
35
+ * Check if gh CLI is available
36
+ *
37
+ * @returns {boolean} Whether gh CLI is available
38
+ */
39
+ export declare function isGhCliAvailable(): boolean;
40
+ /**
41
+ * Create a GitHub PR for the lane branch
42
+ *
43
+ * @param {PRContext} context - PR context
44
+ * @returns {Promise<PRResult>} PR creation result
45
+ */
46
+ export declare function createPR(context: any): Promise<{
47
+ success: boolean;
48
+ prUrl: string;
49
+ ghAvailable: boolean;
50
+ }>;
51
+ /**
52
+ * Build the PR body from WU document
53
+ *
54
+ * @param {Object} doc - WU YAML document
55
+ * @param {string} id - WU ID
56
+ * @returns {string} PR body markdown
57
+ */
58
+ export declare function buildPRBody(doc: any, id: any): string;
59
+ /**
60
+ * Print message when gh CLI is not available
61
+ *
62
+ * @param {string} branch - Lane branch name
63
+ * @param {string} id - WU ID
64
+ */
65
+ export declare function printGhCliMissingMessage(branch: any, id: any): void;
66
+ /**
67
+ * Print success message with next steps after PR creation
68
+ *
69
+ * @param {string} prUrl - URL of created PR
70
+ * @param {string} id - WU ID
71
+ */
72
+ export declare function printPRCreatedMessage(prUrl: any, id: any): void;
@@ -0,0 +1,174 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * PR mode completion workflow for wu:done
4
+ * Extracted from wu-done.mjs (WU-1215 refactoring)
5
+ *
6
+ * PR mode creates a GitHub PR instead of auto-merging to main.
7
+ * Used for:
8
+ * - External agents requiring review (claimed_mode: worktree-pr)
9
+ * - High-risk WUs (requires_review: true in WU YAML)
10
+ * - One-off PR creation (--create-pr flag)
11
+ */
12
+ import { execSync } from 'node:child_process';
13
+ import { getGitForCwd } from './git-adapter.js';
14
+ import { createError, ErrorCodes } from './error-handler.js';
15
+ import { LOG_PREFIX, EMOJI, REMOTES, STDIO } from './wu-constants.js';
16
+ /**
17
+ * @typedef {Object} PRContext
18
+ * @property {string} branch - Lane branch name
19
+ * @property {string} id - WU ID (e.g., "WU-1215")
20
+ * @property {string} title - WU title for PR title
21
+ * @property {Object} doc - WU YAML document
22
+ * @property {boolean} [draft] - Whether to create as draft PR
23
+ */
24
+ /**
25
+ * @typedef {Object} PRResult
26
+ * @property {boolean} success - Whether PR creation succeeded
27
+ * @property {string|null} prUrl - URL of created PR (null if gh CLI unavailable)
28
+ * @property {boolean} ghAvailable - Whether gh CLI is available
29
+ */
30
+ /**
31
+ * Check if PR mode is enabled for this WU
32
+ *
33
+ * @param {Object} doc - WU YAML document
34
+ * @param {Object} args - CLI arguments
35
+ * @returns {boolean} Whether PR mode is enabled
36
+ */
37
+ export function isPRModeEnabled(doc, args) {
38
+ const claimedMode = doc.claimed_mode || 'worktree';
39
+ const requiresReview = doc.requires_review === true;
40
+ return claimedMode === 'worktree-pr' || args.createPR || requiresReview;
41
+ }
42
+ /**
43
+ * Check if gh CLI is available
44
+ *
45
+ * @returns {boolean} Whether gh CLI is available
46
+ */
47
+ export function isGhCliAvailable() {
48
+ try {
49
+ execSync('gh --version', { encoding: 'utf-8', stdio: STDIO.IGNORE });
50
+ return true;
51
+ }
52
+ catch {
53
+ return false;
54
+ }
55
+ }
56
+ /**
57
+ * Create a GitHub PR for the lane branch
58
+ *
59
+ * @param {PRContext} context - PR context
60
+ * @returns {Promise<PRResult>} PR creation result
61
+ */
62
+ export async function createPR(context) {
63
+ const { branch, id, title, doc, draft = false } = context;
64
+ console.log(`\n${LOG_PREFIX.DONE} Creating PR for ${branch}...`);
65
+ // Check if gh CLI is available
66
+ if (!isGhCliAvailable()) {
67
+ printGhCliMissingMessage(branch, id);
68
+ return { success: false, prUrl: null, ghAvailable: false };
69
+ }
70
+ // Push branch to remote
71
+ try {
72
+ await getGitForCwd().push(REMOTES.ORIGIN, branch);
73
+ }
74
+ catch (e) {
75
+ throw createError(ErrorCodes.GIT_ERROR, `Failed to push branch ${branch}: ${e.message}`, {
76
+ branch,
77
+ operation: 'push',
78
+ originalError: e.message,
79
+ });
80
+ }
81
+ // Build PR body
82
+ const body = buildPRBody(doc, id);
83
+ const prTitle = `${id}: ${title}`;
84
+ const draftFlag = draft ? '--draft' : '';
85
+ // Create PR via gh CLI
86
+ try {
87
+ const prUrl = execSync(`gh pr create --title ${JSON.stringify(prTitle)} --body ${JSON.stringify(body)} ${draftFlag} --head ${JSON.stringify(branch)} --base main`, { encoding: 'utf-8' }).trim();
88
+ console.log(`${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} PR created: ${prUrl}`);
89
+ return { success: true, prUrl, ghAvailable: true };
90
+ }
91
+ catch (e) {
92
+ throw createError(ErrorCodes.GIT_ERROR, `Failed to create PR: ${e.message}`, {
93
+ branch,
94
+ id,
95
+ operation: 'pr-create',
96
+ originalError: e.message,
97
+ });
98
+ }
99
+ }
100
+ /**
101
+ * Build the PR body from WU document
102
+ *
103
+ * @param {Object} doc - WU YAML document
104
+ * @param {string} id - WU ID
105
+ * @returns {string} PR body markdown
106
+ */
107
+ export function buildPRBody(doc, id) {
108
+ const wuPath = `docs/04-operations/tasks/wu/${id}.yaml`;
109
+ const description = doc.description || doc.problem || '';
110
+ const acceptance = doc.acceptance_criteria || doc.acceptance || {};
111
+ let body = `## Summary\n\n${description}\n\n`;
112
+ if (Object.keys(acceptance).length > 0) {
113
+ body += `## Acceptance Criteria\n\n`;
114
+ for (const [key, criteria] of Object.entries(acceptance)) {
115
+ body += `**${key}:**\n`;
116
+ if (Array.isArray(criteria)) {
117
+ for (const item of criteria) {
118
+ body += `- ${item}\n`;
119
+ }
120
+ }
121
+ else if (typeof criteria === 'object') {
122
+ for (const [subkey, items] of Object.entries(criteria)) {
123
+ body += `- ${subkey}:\n`;
124
+ if (Array.isArray(items)) {
125
+ for (const item of items) {
126
+ body += ` - ${item}\n`;
127
+ }
128
+ }
129
+ }
130
+ }
131
+ body += `\n`;
132
+ }
133
+ }
134
+ body += `\nšŸ¤– Generated with [Claude Code](https://claude.com/claude-code)\n\n`;
135
+ body += `WU YAML: ${wuPath}`;
136
+ return body;
137
+ }
138
+ /**
139
+ * Print message when gh CLI is not available
140
+ *
141
+ * @param {string} branch - Lane branch name
142
+ * @param {string} id - WU ID
143
+ */
144
+ export function printGhCliMissingMessage(branch, id) {
145
+ console.error();
146
+ console.error('╔═══════════════════════════════════════════════════════════════════╗');
147
+ console.error('ā•‘ GH CLI NOT AVAILABLE');
148
+ console.error('╠═══════════════════════════════════════════════════════════════════╣');
149
+ console.error('ā•‘ The gh CLI tool is required to create PRs.');
150
+ console.error('ā•‘');
151
+ console.error('ā•‘ Manual PR creation steps:');
152
+ console.error(`ā•‘ 1. Push branch: git push origin ${branch}`);
153
+ console.error('ā•‘ 2. Create PR in GitHub UI');
154
+ console.error(`ā•‘ 3. After merge, run: pnpm wu:cleanup --id ${id}`);
155
+ console.error('ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•');
156
+ }
157
+ /**
158
+ * Print success message with next steps after PR creation
159
+ *
160
+ * @param {string} prUrl - URL of created PR
161
+ * @param {string} id - WU ID
162
+ */
163
+ export function printPRCreatedMessage(prUrl, id) {
164
+ console.log('\n╔═══════════════════════════════════════════════════════════════════╗');
165
+ console.log('ā•‘ PR CREATED - NEXT STEPS');
166
+ console.log('╠═══════════════════════════════════════════════════════════════════╣');
167
+ console.log(`ā•‘ PR URL: ${prUrl}`);
168
+ console.log('ā•‘');
169
+ console.log('ā•‘ Next steps:');
170
+ console.log('ā•‘ 1. Review the PR in GitHub UI');
171
+ console.log('ā•‘ 2. Merge the PR when ready');
172
+ console.log(`ā•‘ 3. Run cleanup: pnpm wu:cleanup --id ${id}`);
173
+ console.log('ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•');
174
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * WU-1584: Retry and recovery helpers for wu:done
3
+ *
4
+ * Handles:
5
+ * - Squashing duplicate completion commits from retry attempts
6
+ * - Detecting and counting previous completion attempts
7
+ * - Preparing zombie recovery with squash
8
+ * - Handling parallel completions with auto-rebase
9
+ *
10
+ * @module wu-done-retry-helpers
11
+ */
12
+ /**
13
+ * Count previous completion attempt commits for a WU on the current branch
14
+ *
15
+ * WU-1584 Fix #1: Detect duplicate commits from retries
16
+ *
17
+ * Searches commit history for commits matching the completion pattern
18
+ * for the specified WU ID.
19
+ *
20
+ * @param {string} wuId - WU ID (e.g., 'WU-1584')
21
+ * @param {object} gitAdapter - Git adapter instance
22
+ * @returns {Promise<number>} Number of completion attempt commits found
23
+ */
24
+ export declare function countPreviousCompletionAttempts(wuId: any, gitAdapter: any): Promise<number>;
25
+ /**
26
+ * Squash previous completion attempt commits into a single commit
27
+ *
28
+ * WU-1584 Fix #1: Running wu:done N times should result in exactly 1 completion commit
29
+ *
30
+ * Uses git reset --soft to combine multiple completion attempts while
31
+ * preserving the staged changes for the new completion commit.
32
+ *
33
+ * @param {string} wuId - WU ID for logging
34
+ * @param {number} count - Number of commits to squash
35
+ * @param {object} gitAdapter - Git adapter instance
36
+ * @param {SquashCompletionAttemptsOptions} [options] - Options
37
+ * @returns {Promise<{ squashed: boolean, count: number }>} Result
38
+ */
39
+ export interface SquashCompletionAttemptsOptions {
40
+ /** Use --soft when true; --hard when false (recovery) */
41
+ preserveIndex?: boolean;
42
+ }
43
+ export declare function squashPreviousCompletionAttempts(wuId: any, count: any, gitAdapter: any, options?: SquashCompletionAttemptsOptions): Promise<{
44
+ squashed: boolean;
45
+ count: any;
46
+ }>;
47
+ /**
48
+ * Prepare zombie recovery with squash of previous attempts
49
+ *
50
+ * WU-1584 Fix #2: Recovery loop should squash previous attempt commits
51
+ *
52
+ * When recovering from zombie state (status=done but worktree exists),
53
+ * first squash any previous completion attempts to avoid "rebase hell".
54
+ *
55
+ * @param {string} wuId - WU ID
56
+ * @param {object} gitAdapter - Git adapter instance
57
+ * @returns {Promise<{ squashedCount: number }>} Result
58
+ */
59
+ export declare function prepareRecoveryWithSquash(wuId: any, gitAdapter: any): Promise<{
60
+ squashedCount: any;
61
+ }>;
62
+ /**
63
+ * Handle parallel completions with auto-rebase
64
+ *
65
+ * WU-1584 Fix #3: detectParallelCompletions() should trigger rebase, not just warn
66
+ *
67
+ * When parallel completions are detected (main has advanced since claim),
68
+ * triggers auto-rebase instead of proceeding with merge that will fail.
69
+ *
70
+ * @param {string} wuId - WU ID
71
+ * @param {object} doc - WU YAML document containing baseline_main_sha
72
+ * @param {object} gitAdapter - Git adapter instance
73
+ * @param {HandleParallelCompletionsOptions} options - Options
74
+ * @returns {Promise<{ parallelDetected: boolean, rebaseTriggered: boolean }>}
75
+ */
76
+ export interface HandleParallelCompletionsOptions {
77
+ /** Path to worktree */
78
+ worktreePath?: string;
79
+ /** Whether auto-rebase is enabled (default: true) */
80
+ autoRebase?: boolean;
81
+ }
82
+ export declare function handleParallelCompletions(wuId: any, doc: any, gitAdapter: any, options?: HandleParallelCompletionsOptions): Promise<{
83
+ parallelDetected: boolean;
84
+ rebaseTriggered: boolean;
85
+ }>;