@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,42 @@
1
+ /**
2
+ * WU Create Validators (WU-2107)
3
+ *
4
+ * Validation helpers for wu:create, including lane inference surfacing.
5
+ *
6
+ * When agents create WUs, this module helps surface lane inference suggestions
7
+ * to guide better lane selection and improve parallelization.
8
+ *
9
+ * NOTE: This is domain-specific WU workflow code, not a general utility.
10
+ * No external library exists for LumenFlow lane inference validation.
11
+ */
12
+ /**
13
+ * Generate a warning message when provided lane differs from inferred lane.
14
+ *
15
+ * Returns empty string if lanes match (no warning needed).
16
+ *
17
+ * @param {string} providedLane - Lane provided by the user
18
+ * @param {string} inferredLane - Lane suggested by inference
19
+ * @param {number} confidence - Confidence score (0-100)
20
+ * @returns {string} Warning message or empty string if lanes match
21
+ */
22
+ export declare function generateLaneMismatchWarning(providedLane: any, inferredLane: any, confidence: any): string;
23
+ /**
24
+ * Check if lane validation should show a suggestion
25
+ *
26
+ * @param {string} providedLane - Lane provided by the user
27
+ * @param {string[]} codePaths - Code paths from WU
28
+ * @param {string} description - WU description
29
+ * @param {Function} inferSubLane - Lane inference function
30
+ * @returns {{ shouldWarn: boolean, warning: string }} Validation result
31
+ */
32
+ export declare function validateLaneWithInference(providedLane: any, codePaths: any, description: any, inferSubLane: any): {
33
+ shouldWarn: boolean;
34
+ warning: string;
35
+ inferredLane?: undefined;
36
+ confidence?: undefined;
37
+ } | {
38
+ shouldWarn: boolean;
39
+ warning: string;
40
+ inferredLane: any;
41
+ confidence: any;
42
+ };
@@ -0,0 +1,93 @@
1
+ /**
2
+ * WU Create Validators (WU-2107)
3
+ *
4
+ * Validation helpers for wu:create, including lane inference surfacing.
5
+ *
6
+ * When agents create WUs, this module helps surface lane inference suggestions
7
+ * to guide better lane selection and improve parallelization.
8
+ *
9
+ * NOTE: This is domain-specific WU workflow code, not a general utility.
10
+ * No external library exists for LumenFlow lane inference validation.
11
+ */
12
+ /** Confidence threshold for showing suggestion (percentage) */
13
+ const CONFIDENCE_THRESHOLD_LOW = 30;
14
+ /**
15
+ * Generate a warning message when provided lane differs from inferred lane.
16
+ *
17
+ * Returns empty string if lanes match (no warning needed).
18
+ *
19
+ * @param {string} providedLane - Lane provided by the user
20
+ * @param {string} inferredLane - Lane suggested by inference
21
+ * @param {number} confidence - Confidence score (0-100)
22
+ * @returns {string} Warning message or empty string if lanes match
23
+ */
24
+ export function generateLaneMismatchWarning(providedLane, inferredLane, confidence) {
25
+ // Normalize lanes for comparison (handle parent-only vs sub-lane)
26
+ const normalizedProvided = providedLane.trim();
27
+ const normalizedInferred = inferredLane.trim();
28
+ // If lanes match exactly, no warning needed
29
+ if (normalizedProvided === normalizedInferred) {
30
+ return '';
31
+ }
32
+ // Check if provided is parent-only and inferred is a sub-lane of that parent
33
+ const inferredParent = normalizedInferred.split(':')[0].trim();
34
+ if (normalizedProvided === inferredParent) {
35
+ // User provided parent-only, suggest the specific sub-lane
36
+ return formatWarningMessage(normalizedInferred, confidence, true);
37
+ }
38
+ // Lanes are different, show suggestion
39
+ return formatWarningMessage(normalizedInferred, confidence, false);
40
+ }
41
+ /**
42
+ * Format the warning message based on confidence level
43
+ *
44
+ * @param {string} suggestedLane - The suggested lane
45
+ * @param {number} confidence - Confidence score (0-100)
46
+ * @param {boolean} isSubLaneSuggestion - True if suggesting sub-lane for parent-only input
47
+ * @returns {string} Formatted warning message
48
+ */
49
+ function formatWarningMessage(suggestedLane, confidence, isSubLaneSuggestion) {
50
+ const confidenceStr = `${confidence}%`;
51
+ if (confidence < CONFIDENCE_THRESHOLD_LOW) {
52
+ return (`Lane suggestion (low confidence ${confidenceStr}): "${suggestedLane}"\n` +
53
+ `Run: pnpm wu:infer-lane --id WU-XXX to verify\n` +
54
+ `See: .lumenflow.lane-inference.yaml for lane taxonomy`);
55
+ }
56
+ if (isSubLaneSuggestion) {
57
+ return (`Suggested sub-lane (${confidenceStr} confidence): "${suggestedLane}"\n` +
58
+ `Using specific sub-lanes improves parallelization.\n` +
59
+ `Run: pnpm wu:infer-lane --id WU-XXX to verify`);
60
+ }
61
+ return (`Lane inference suggests: "${suggestedLane}" (${confidenceStr} confidence)\n` +
62
+ `Consider using the inferred lane for better lane distribution.\n` +
63
+ `Run: pnpm wu:infer-lane --id WU-XXX to verify`);
64
+ }
65
+ /**
66
+ * Check if lane validation should show a suggestion
67
+ *
68
+ * @param {string} providedLane - Lane provided by the user
69
+ * @param {string[]} codePaths - Code paths from WU
70
+ * @param {string} description - WU description
71
+ * @param {Function} inferSubLane - Lane inference function
72
+ * @returns {{ shouldWarn: boolean, warning: string }} Validation result
73
+ */
74
+ export function validateLaneWithInference(providedLane, codePaths, description, inferSubLane) {
75
+ // Skip inference if no code paths provided
76
+ if (!codePaths || codePaths.length === 0) {
77
+ return { shouldWarn: false, warning: '' };
78
+ }
79
+ try {
80
+ const { lane: inferredLane, confidence } = inferSubLane(codePaths, description);
81
+ const warning = generateLaneMismatchWarning(providedLane, inferredLane, confidence);
82
+ return {
83
+ shouldWarn: warning.length > 0,
84
+ warning,
85
+ inferredLane,
86
+ confidence,
87
+ };
88
+ }
89
+ catch {
90
+ // Inference failed, don't block creation
91
+ return { shouldWarn: false, warning: '' };
92
+ }
93
+ }
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Branch-Only mode completion workflow for wu:done
4
+ * Extracted from wu-done.mjs (WU-1215 refactoring)
5
+ *
6
+ * Flow:
7
+ * 1. Switch to main branch
8
+ * 2. Merge lane branch (if not --no-merge)
9
+ * 3. Calculate paths relative to main checkout
10
+ * 4. Update metadata files (WU YAML, status.md, backlog.md, stamp)
11
+ * 5. Validate spec completeness
12
+ * 6. Stage and format files
13
+ * 7. Commit on main
14
+ * 8. Push to origin
15
+ */
16
+ /**
17
+ * @typedef {Object} BranchOnlyContext
18
+ * @property {string} id - WU ID (e.g., "WU-1215")
19
+ * @property {Object} args - Parsed CLI arguments
20
+ * @property {Object} docMain - WU YAML document from main checkout
21
+ * @property {string} title - WU title for commit message
22
+ * @property {boolean} isDocsOnly - Whether this is a docs-only WU
23
+ * @property {number} maxCommitLength - Max commit header length from commitlint
24
+ * @property {function} recordTransactionState - Transaction state recorder
25
+ * @property {function} rollbackTransaction - Transaction rollback function
26
+ * @property {function} validateStagedFiles - Staged files validator
27
+ */
28
+ /**
29
+ * @typedef {Object} BranchOnlyResult
30
+ * @property {boolean} success - Whether completion succeeded
31
+ * @property {boolean} committed - Whether changes were committed
32
+ * @property {boolean} pushed - Whether changes were pushed
33
+ * @property {boolean} merged - Whether lane branch was merged
34
+ */
35
+ /**
36
+ * Execute branch-only mode completion
37
+ *
38
+ * @param {BranchOnlyContext} context - Branch-only mode context
39
+ * @returns {Promise<BranchOnlyResult>} Completion result
40
+ * @throws {Error} On validation or git operation failure
41
+ */
42
+ export declare function executeBranchOnlyCompletion(context: any): Promise<{
43
+ success: boolean;
44
+ committed: boolean;
45
+ pushed: boolean;
46
+ merged: boolean;
47
+ recovered: boolean;
48
+ } | {
49
+ success: boolean;
50
+ committed: boolean;
51
+ pushed: boolean;
52
+ merged: boolean;
53
+ recovered?: undefined;
54
+ }>;
55
+ /**
56
+ * Merge lane branch to main with retry logic
57
+ * Internal helper for branch-only mode
58
+ *
59
+ * @param {string} laneBranch - Lane branch name to merge
60
+ * @throws {Error} On merge failure
61
+ */
62
+ declare function mergeLaneBranch(laneBranch: any): Promise<void>;
63
+ export { mergeLaneBranch };
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Branch-Only mode completion workflow for wu:done
4
+ * Extracted from wu-done.mjs (WU-1215 refactoring)
5
+ *
6
+ * Flow:
7
+ * 1. Switch to main branch
8
+ * 2. Merge lane branch (if not --no-merge)
9
+ * 3. Calculate paths relative to main checkout
10
+ * 4. Update metadata files (WU YAML, status.md, backlog.md, stamp)
11
+ * 5. Validate spec completeness
12
+ * 6. Stage and format files
13
+ * 7. Commit on main
14
+ * 8. Push to origin
15
+ */
16
+ import path from 'node:path';
17
+ import { defaultBranchFrom, branchExists, generateCommitMessage, updateMetadataFiles, stageAndFormatMetadata, } from './wu-done-validators.js';
18
+ import { getGitForCwd } from './git-adapter.js';
19
+ import { readWU } from './wu-yaml.js';
20
+ import { BRANCHES, REMOTES, LOG_PREFIX, EMOJI, STRING_LITERALS } from './wu-constants.js';
21
+ import { RECOVERY } from './wu-done-messages.js';
22
+ import { die, createError, ErrorCodes } from './error-handler.js';
23
+ import { validateWU, validateDoneWU } from './wu-schema.js';
24
+ import { assertTransition } from './state-machine.js';
25
+ import { detectZombieState, recoverZombieState } from './wu-recovery.js';
26
+ /**
27
+ * @typedef {Object} BranchOnlyContext
28
+ * @property {string} id - WU ID (e.g., "WU-1215")
29
+ * @property {Object} args - Parsed CLI arguments
30
+ * @property {Object} docMain - WU YAML document from main checkout
31
+ * @property {string} title - WU title for commit message
32
+ * @property {boolean} isDocsOnly - Whether this is a docs-only WU
33
+ * @property {number} maxCommitLength - Max commit header length from commitlint
34
+ * @property {function} recordTransactionState - Transaction state recorder
35
+ * @property {function} rollbackTransaction - Transaction rollback function
36
+ * @property {function} validateStagedFiles - Staged files validator
37
+ */
38
+ /**
39
+ * @typedef {Object} BranchOnlyResult
40
+ * @property {boolean} success - Whether completion succeeded
41
+ * @property {boolean} committed - Whether changes were committed
42
+ * @property {boolean} pushed - Whether changes were pushed
43
+ * @property {boolean} merged - Whether lane branch was merged
44
+ */
45
+ /**
46
+ * Execute branch-only mode completion
47
+ *
48
+ * @param {BranchOnlyContext} context - Branch-only mode context
49
+ * @returns {Promise<BranchOnlyResult>} Completion result
50
+ * @throws {Error} On validation or git operation failure
51
+ */
52
+ export async function executeBranchOnlyCompletion(context) {
53
+ const { id, args, docMain, title, isDocsOnly, maxCommitLength, recordTransactionState, rollbackTransaction, validateStagedFiles, } = context;
54
+ let merged = false;
55
+ // Step 1: Switch to main and optionally merge lane branch
56
+ const gitAdapter = getGitForCwd();
57
+ if (!args.noMerge) {
58
+ const laneBranch = await defaultBranchFrom(docMain);
59
+ if (laneBranch && (await branchExists(laneBranch))) {
60
+ console.log(`\n${LOG_PREFIX.DONE} Switching to ${BRANCHES.MAIN} for merge...`);
61
+ await gitAdapter.checkout(BRANCHES.MAIN);
62
+ await mergeLaneBranch(laneBranch);
63
+ merged = true;
64
+ }
65
+ else {
66
+ console.log(`${LOG_PREFIX.DONE} No lane branch found (${laneBranch || 'unknown'}), skipping merge`);
67
+ await gitAdapter.checkout(BRANCHES.MAIN);
68
+ }
69
+ }
70
+ else {
71
+ console.log(`\n${LOG_PREFIX.DONE} Switching to ${BRANCHES.MAIN} for completion commit...`);
72
+ await gitAdapter.checkout(BRANCHES.MAIN);
73
+ }
74
+ // Step 2: Calculate paths relative to main checkout
75
+ const metadataBasePath = '.';
76
+ const metadataWUPath = path.join(metadataBasePath, 'docs', '04-operations', 'tasks', 'wu', `${id}.yaml`);
77
+ const metadataStatusPath = path.join(metadataBasePath, 'docs', '04-operations', 'tasks', 'status.md');
78
+ const metadataBacklogPath = path.join(metadataBasePath, 'docs', '04-operations', 'tasks', 'backlog.md');
79
+ const metadataStampsDir = path.join(metadataBasePath, '.beacon', 'stamps');
80
+ const metadataStampPath = path.join(metadataStampsDir, `${id}.done`);
81
+ // Step 3: Read WU YAML and validate current state
82
+ const docForUpdate = readWU(metadataWUPath, id);
83
+ const currentStatus = docForUpdate.status || 'in_progress';
84
+ // Check for zombie state (recovery mode)
85
+ if (detectZombieState(docForUpdate, null)) {
86
+ await recoverZombieState({ id, doc: docForUpdate, _worktreePath: null, _args: args });
87
+ console.log(`\n${RECOVERY.SUCCESS}`);
88
+ console.log(`- WU: ${id} — ${title}`);
89
+ return { success: true, committed: false, pushed: false, merged, recovered: true };
90
+ }
91
+ // Validate state transition
92
+ try {
93
+ assertTransition(currentStatus, 'done', id);
94
+ }
95
+ catch (error) {
96
+ die(`State transition validation failed: ${error.message}`);
97
+ }
98
+ // Step 4: Record transaction state for atomic rollback
99
+ const transactionState = recordTransactionState(id, metadataWUPath, metadataStampPath, metadataBacklogPath, metadataStatusPath);
100
+ console.log(`${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Transaction BEGIN - state recorded for rollback (WU YAML + backlog + status)`);
101
+ try {
102
+ // Step 5: Validate spec completeness
103
+ const schemaResult = validateWU(docForUpdate);
104
+ if (!schemaResult.success) {
105
+ const errors = schemaResult.error.issues.map((issue) => ` - ${issue.path.join('.')}: ${issue.message}`);
106
+ die(`WU YAML validation failed:\n${errors.join(STRING_LITERALS.NEWLINE)}`);
107
+ }
108
+ const completenessResult = validateDoneWU(docForUpdate);
109
+ if (!completenessResult.valid) {
110
+ die(`Cannot mark WU as done - spec incomplete:\n ${completenessResult.errors.join('\n ')}`);
111
+ }
112
+ // Step 6: Update metadata files
113
+ // WU-1572: Now async for state store integration
114
+ await updateMetadataFiles({
115
+ id,
116
+ title,
117
+ doc: docForUpdate,
118
+ wuPath: metadataWUPath,
119
+ statusPath: metadataStatusPath,
120
+ backlogPath: metadataBacklogPath,
121
+ });
122
+ // Step 7: Stage and format files
123
+ await stageAndFormatMetadata({
124
+ id,
125
+ wuPath: metadataWUPath,
126
+ statusPath: metadataStatusPath,
127
+ backlogPath: metadataBacklogPath,
128
+ stampsDir: metadataStampsDir,
129
+ });
130
+ // Validate staged files
131
+ await validateStagedFiles(id, isDocsOnly);
132
+ // Step 8: Commit on main
133
+ const msg = generateCommitMessage(id, title, maxCommitLength);
134
+ const gitCwd = getGitForCwd();
135
+ await gitCwd.commit(msg);
136
+ console.log(`${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Metadata committed on main`);
137
+ // Step 9: Push to origin
138
+ await gitAdapter.push(REMOTES.ORIGIN, BRANCHES.MAIN);
139
+ console.log(`${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Pushed to ${REMOTES.ORIGIN}/${BRANCHES.MAIN}`);
140
+ return { success: true, committed: true, pushed: true, merged };
141
+ }
142
+ catch (err) {
143
+ // Atomic rollback on failure
144
+ await rollbackTransaction(transactionState, metadataWUPath, metadataStampPath, metadataBacklogPath, metadataStatusPath);
145
+ // Re-throw with context
146
+ console.log('\n╔══════════════════════════════════════════════════════════════════╗');
147
+ console.log('║ WU:DONE FAILED (Branch-Only Mode)');
148
+ console.log('╠══════════════════════════════════════════════════════════════════╣');
149
+ console.log(`║ Error: ${err.message}`);
150
+ console.log('║');
151
+ console.log('║ Transaction rolled back - WU remains not-done.');
152
+ console.log('║');
153
+ console.log('║ Recovery steps:');
154
+ console.log('║ 1. Fix the issue');
155
+ console.log(`║ 2. Retry: pnpm wu:done --id ${id}`);
156
+ console.log('╚══════════════════════════════════════════════════════════════════╝');
157
+ throw err;
158
+ }
159
+ }
160
+ /**
161
+ * Merge lane branch to main with retry logic
162
+ * Internal helper for branch-only mode
163
+ *
164
+ * @param {string} laneBranch - Lane branch name to merge
165
+ * @throws {Error} On merge failure
166
+ */
167
+ async function mergeLaneBranch(laneBranch) {
168
+ console.log(`${LOG_PREFIX.DONE} Merging ${laneBranch} to main (ff-only)...`);
169
+ const gitAdapter = getGitForCwd();
170
+ try {
171
+ // First attempt: fast-forward only
172
+ await gitAdapter.merge(laneBranch, { ffOnly: true });
173
+ console.log(`${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Lane branch merged to main`);
174
+ }
175
+ catch {
176
+ // Retry with pull if ff-only fails (main may have advanced)
177
+ console.log(`${LOG_PREFIX.DONE} ${EMOJI.WARNING} Fast-forward merge failed, attempting pull + retry...`);
178
+ try {
179
+ await gitAdapter.pull(REMOTES.ORIGIN, BRANCHES.MAIN);
180
+ await gitAdapter.merge(laneBranch, { ffOnly: true });
181
+ console.log(`${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Lane branch merged after pull`);
182
+ }
183
+ catch (retryErr) {
184
+ throw createError(ErrorCodes.GIT_ERROR, `Failed to merge lane branch ${laneBranch}: ${retryErr.message}\n` +
185
+ `Suggestion: Rebase your lane branch on main and retry:\n` +
186
+ ` cd worktrees/<lane>-<wu>; git rebase main`, { branch: laneBranch, error: retryErr.message });
187
+ }
188
+ }
189
+ }
190
+ // Export for testing
191
+ export { mergeLaneBranch };
@@ -0,0 +1,119 @@
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 } from './wu-constants.js';
11
+ export { LOG_PREFIX };
12
+ /**
13
+ * Recovery mode messages (WU-1159)
14
+ */
15
+ export declare const RECOVERY: {
16
+ DETECTED: string;
17
+ RESUMING: string;
18
+ EXPLANATION: string;
19
+ CREATING_STAMP: string;
20
+ STAMP_CREATED: string;
21
+ UPDATING_YAML: string;
22
+ YAML_UPDATED: string;
23
+ UPDATING_DOCS: string;
24
+ DOCS_UPDATED: string;
25
+ COMMITTING: string;
26
+ COMMIT_SUCCESS: string;
27
+ COMMIT_FAILED: (error: any) => string;
28
+ MARKERS_VERIFIED: string;
29
+ PROCEEDING_CLEANUP: string;
30
+ SUCCESS: string;
31
+ };
32
+ /**
33
+ * Worktree operations
34
+ */
35
+ export declare const WORKTREE: {
36
+ REMOVED: (path: any) => string;
37
+ NOT_FOUND: string;
38
+ REMOVE_FAILED: (path: any, error: any) => string;
39
+ PRESERVED_PR_MODE: string;
40
+ };
41
+ /**
42
+ * Branch operations
43
+ */
44
+ export declare const BRANCH: {
45
+ DELETED_LOCAL: (branch: any) => string;
46
+ DELETED_REMOTE: (branch: any) => string;
47
+ DELETE_FAILED: (branch: any, error: any) => string;
48
+ DELETE_REMOTE_FAILED: (error: any) => string;
49
+ PRESERVED_PR_MODE: string;
50
+ };
51
+ /**
52
+ * Completion messages
53
+ */
54
+ export declare const COMPLETION: {
55
+ SUCCESS_HEADER: (id: any, title: any) => string;
56
+ TRANSACTION_COMMIT: string;
57
+ };
58
+ /**
59
+ * State transition errors
60
+ */
61
+ export declare const STATE_TRANSITION: {
62
+ VALIDATION_FAILED: (error: any) => string;
63
+ };
64
+ /**
65
+ * Auto-rebase messages (WU-1303)
66
+ */
67
+ export declare const REBASE: {
68
+ STARTING: (branch: any, mainBranch: any) => string;
69
+ SUCCESS: string;
70
+ FAILED: (error: any) => string;
71
+ ABORTED: string;
72
+ MANUAL_FIX: (worktreePath: any, remote: any, mainBranch: any, branch: any) => string;
73
+ };
74
+ /**
75
+ * Pre-flight check messages (WU-755, WU-1303, WU-1370)
76
+ */
77
+ export declare const PREFLIGHT: {
78
+ RUNNING: string;
79
+ BRANCH_BEHIND: (commitsBehind: any, threshold: any) => string;
80
+ BRANCH_DRIFT_INFO: (commitsBehind: any) => string;
81
+ BRANCH_DRIFT_WARNING: (commitsBehind: any) => string;
82
+ DIVERGENCE_DETECTED: (commitCount: any) => string;
83
+ NO_DIVERGENCE: string;
84
+ NO_CONFLICTS: string;
85
+ ALREADY_MERGED: string;
86
+ ALREADY_MERGED_EXPLANATION: string;
87
+ BRANCH_INFO: (branch: any, branchTip: any, mergeBase: any, mainHead: any) => string;
88
+ BRANCH_DRIFT_ERROR: (mainAhead: any, threshold: any, remote: any, mainBranch: any) => string;
89
+ DIVERGENCE_ERROR: (commitCount: any, remote: any, mainBranch: any, branch: any) => string;
90
+ CONFLICT_ERROR: (remote?: string, mainBranch?: string) => string;
91
+ MERGE_COMMITS_DETECTED: (count: any) => string;
92
+ MERGE_COMMITS_REBASING: string;
93
+ NO_MERGE_COMMITS: string;
94
+ EMPTY_MERGE_WARNING: (commitCount: any) => string;
95
+ EMPTY_MERGE_CHECK: string;
96
+ CODE_PATHS_NOT_MODIFIED: (missingFiles: any) => string;
97
+ CODE_PATHS_VERIFIED: string;
98
+ };
99
+ /**
100
+ * Merge operation messages (WU-1303)
101
+ */
102
+ export declare const MERGE: {
103
+ STARTING: (branch: any) => string;
104
+ BRANCH_MERGE: (branch: any) => string;
105
+ SUCCESS: (branch: any) => string;
106
+ ATOMIC_SUCCESS: string;
107
+ FF_FAILED_RETRY: string;
108
+ UPDATED_MAIN: (remote: any) => string;
109
+ PUSHED: (remote: any, mainBranch: any) => string;
110
+ FF_MERGE_ERROR: (branch: any, mergeError: any, pullError: any, remote?: string, mainBranch?: string) => string;
111
+ FF_DIVERGED_ERROR: (branch: any, originalError: any, mainBranch?: string) => string;
112
+ FF_FAILED_NON_DIVERGED_ERROR: (branch: any, originalError: any, mainBranch?: string) => string;
113
+ };
114
+ /**
115
+ * Pre-push gate messages (WU-1303)
116
+ */
117
+ export declare const PREPUSH: {
118
+ WORKTREE_SKIP: string;
119
+ };