@lumenflow/core 2.2.2 → 2.3.2

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 (213) hide show
  1. package/dist/active-wu-detector.d.ts +1 -1
  2. package/dist/active-wu-detector.js +1 -1
  3. package/dist/arg-parser.js +51 -18
  4. package/dist/backlog-generator.d.ts +4 -4
  5. package/dist/backlog-generator.js +4 -4
  6. package/dist/backlog-sync-validator.js +1 -1
  7. package/dist/cleanup-lock.d.ts +9 -2
  8. package/dist/cleanup-lock.js +17 -7
  9. package/dist/code-path-validator.d.ts +3 -3
  10. package/dist/code-path-validator.js +3 -3
  11. package/dist/compliance-parser.d.ts +1 -1
  12. package/dist/compliance-parser.js +1 -1
  13. package/dist/constants/backlog-patterns.d.ts +1 -1
  14. package/dist/constants/backlog-patterns.js +1 -1
  15. package/dist/constants/dora-constants.d.ts +1 -1
  16. package/dist/constants/dora-constants.js +1 -1
  17. package/dist/constants/gate-constants.d.ts +1 -1
  18. package/dist/constants/gate-constants.js +1 -1
  19. package/dist/constants/linter-constants.d.ts +1 -1
  20. package/dist/constants/linter-constants.js +1 -1
  21. package/dist/constants/tokenizer-constants.d.ts +1 -1
  22. package/dist/constants/tokenizer-constants.js +1 -1
  23. package/dist/context/location-resolver.js +2 -1
  24. package/dist/context-validation-integration.d.ts +1 -0
  25. package/dist/core/scope-checker.d.ts +3 -3
  26. package/dist/core/scope-checker.js +3 -3
  27. package/dist/core/tool-runner.d.ts +5 -5
  28. package/dist/core/tool-runner.js +5 -5
  29. package/dist/core/tool.constants.d.ts +1 -1
  30. package/dist/core/tool.constants.js +1 -1
  31. package/dist/core/tool.schemas.d.ts +2 -2
  32. package/dist/core/tool.schemas.js +1 -1
  33. package/dist/core/worktree-guard.d.ts +1 -1
  34. package/dist/core/worktree-guard.js +1 -1
  35. package/dist/coverage-gate.d.ts +12 -3
  36. package/dist/coverage-gate.js +15 -8
  37. package/dist/date-utils.d.ts +4 -4
  38. package/dist/date-utils.js +4 -4
  39. package/dist/dependency-graph.d.ts +6 -0
  40. package/dist/dependency-graph.js +43 -2
  41. package/dist/dependency-guard.d.ts +2 -2
  42. package/dist/dependency-guard.js +3 -3
  43. package/dist/dependency-validator.d.ts +4 -4
  44. package/dist/dependency-validator.js +4 -7
  45. package/dist/domain/orchestration.constants.d.ts +31 -10
  46. package/dist/domain/orchestration.constants.js +45 -16
  47. package/dist/domain/orchestration.schemas.d.ts +54 -28
  48. package/dist/domain/orchestration.schemas.js +2 -2
  49. package/dist/domain/orchestration.types.d.ts +2 -2
  50. package/dist/domain/orchestration.types.js +2 -2
  51. package/dist/error-handler.d.ts +10 -10
  52. package/dist/error-handler.js +10 -10
  53. package/dist/file-classifiers.d.ts +6 -6
  54. package/dist/file-classifiers.js +6 -6
  55. package/dist/gates-config.d.ts +74 -0
  56. package/dist/gates-config.js +209 -2
  57. package/dist/git-adapter.d.ts +11 -11
  58. package/dist/git-adapter.js +11 -11
  59. package/dist/git-context-extractor.d.ts +112 -0
  60. package/dist/git-context-extractor.js +559 -0
  61. package/dist/hardcoded-strings.d.ts +1 -1
  62. package/dist/hardcoded-strings.js +1 -1
  63. package/dist/incremental-lint.d.ts +1 -1
  64. package/dist/incremental-lint.js +2 -2
  65. package/dist/incremental-test.d.ts +1 -1
  66. package/dist/incremental-test.js +1 -1
  67. package/dist/index.d.ts +13 -0
  68. package/dist/index.js +25 -0
  69. package/dist/invariants/check-automated-tests.d.ts +2 -2
  70. package/dist/invariants/check-automated-tests.js +3 -3
  71. package/dist/lane-checker.d.ts +28 -7
  72. package/dist/lane-checker.js +316 -159
  73. package/dist/lane-suggest-prompt.d.ts +108 -0
  74. package/dist/lane-suggest-prompt.js +359 -0
  75. package/dist/lane-validator.d.ts +3 -3
  76. package/dist/lane-validator.js +3 -3
  77. package/dist/logs-lib.d.ts +1 -1
  78. package/dist/logs-lib.js +1 -1
  79. package/dist/lumenflow-config-schema.d.ts +162 -0
  80. package/dist/lumenflow-config-schema.js +180 -0
  81. package/dist/manual-test-validator.d.ts +2 -2
  82. package/dist/manual-test-validator.js +3 -3
  83. package/dist/merge-lock.d.ts +8 -1
  84. package/dist/merge-lock.js +16 -7
  85. package/dist/micro-worktree.d.ts +81 -13
  86. package/dist/micro-worktree.js +98 -17
  87. package/dist/migration-deployer.d.ts +1 -1
  88. package/dist/migration-deployer.js +1 -1
  89. package/dist/orchestration-advisory-loader.d.ts +2 -2
  90. package/dist/orchestration-advisory-loader.js +10 -6
  91. package/dist/orchestration-advisory.d.ts +3 -3
  92. package/dist/orchestration-advisory.js +4 -4
  93. package/dist/orchestration-di.d.ts +4 -4
  94. package/dist/orchestration-di.js +4 -4
  95. package/dist/orchestration-rules.d.ts +4 -4
  96. package/dist/orchestration-rules.js +18 -10
  97. package/dist/orphan-detector.d.ts +3 -3
  98. package/dist/orphan-detector.js +3 -3
  99. package/dist/patrol-loop.d.ts +170 -0
  100. package/dist/patrol-loop.js +186 -0
  101. package/dist/process-detector.d.ts +5 -5
  102. package/dist/process-detector.js +5 -5
  103. package/dist/rebase-artifact-cleanup.d.ts +3 -3
  104. package/dist/rebase-artifact-cleanup.js +3 -3
  105. package/dist/resolve-policy.d.ts +195 -0
  106. package/dist/resolve-policy.js +203 -0
  107. package/dist/risk-detector.d.ts +2 -2
  108. package/dist/risk-detector.js +2 -2
  109. package/dist/rollback-utils.d.ts +1 -1
  110. package/dist/rollback-utils.js +1 -1
  111. package/dist/section-headings.d.ts +1 -1
  112. package/dist/section-headings.js +1 -1
  113. package/dist/spawn-escalation.d.ts +4 -4
  114. package/dist/spawn-escalation.js +3 -3
  115. package/dist/spawn-monitor.d.ts +4 -4
  116. package/dist/spawn-monitor.js +4 -4
  117. package/dist/spawn-recovery.d.ts +3 -3
  118. package/dist/spawn-recovery.js +3 -3
  119. package/dist/spawn-registry-schema.d.ts +2 -2
  120. package/dist/spawn-registry-schema.js +2 -2
  121. package/dist/spawn-registry-store.d.ts +2 -2
  122. package/dist/spawn-registry-store.js +2 -2
  123. package/dist/spawn-strategy.d.ts +17 -11
  124. package/dist/spawn-strategy.js +47 -44
  125. package/dist/spawn-tree.d.ts +3 -3
  126. package/dist/spawn-tree.js +3 -3
  127. package/dist/state-cleanup-core.d.ts +205 -0
  128. package/dist/state-cleanup-core.js +240 -0
  129. package/dist/state-doctor-core.d.ts +168 -0
  130. package/dist/state-doctor-core.js +251 -0
  131. package/dist/stream-error-handler.d.ts +67 -0
  132. package/dist/stream-error-handler.js +94 -0
  133. package/dist/telemetry.d.ts +1 -1
  134. package/dist/telemetry.js +1 -1
  135. package/dist/template-loader.d.ts +162 -0
  136. package/dist/template-loader.js +372 -0
  137. package/dist/test-baseline.d.ts +176 -0
  138. package/dist/test-baseline.js +282 -0
  139. package/dist/usecases/get-suggestions.usecase.d.ts +1 -1
  140. package/dist/validation/command-registry.js +37 -0
  141. package/dist/validators/backlog-sync.js +4 -2
  142. package/dist/worktree-scanner.d.ts +1 -1
  143. package/dist/worktree-scanner.js +1 -1
  144. package/dist/worktree-symlink.d.ts +3 -3
  145. package/dist/worktree-symlink.js +3 -3
  146. package/dist/wu-backlog-updater.d.ts +1 -1
  147. package/dist/wu-backlog-updater.js +1 -1
  148. package/dist/wu-claim-helpers.d.ts +1 -1
  149. package/dist/wu-claim-helpers.js +1 -1
  150. package/dist/wu-claim-resume.d.ts +1 -1
  151. package/dist/wu-claim-resume.js +1 -1
  152. package/dist/wu-consistency-checker.d.ts +1 -1
  153. package/dist/wu-consistency-checker.js +17 -11
  154. package/dist/wu-constants.d.ts +73 -21
  155. package/dist/wu-constants.js +65 -22
  156. package/dist/wu-done-branch-only.d.ts +1 -1
  157. package/dist/wu-done-branch-only.js +1 -1
  158. package/dist/wu-done-docs-generate.d.ts +1 -1
  159. package/dist/wu-done-docs-generate.js +1 -1
  160. package/dist/wu-done-messages.d.ts +2 -2
  161. package/dist/wu-done-messages.js +2 -2
  162. package/dist/wu-done-metadata.d.ts +3 -3
  163. package/dist/wu-done-metadata.js +3 -3
  164. package/dist/wu-done-pr.d.ts +1 -1
  165. package/dist/wu-done-pr.js +4 -2
  166. package/dist/wu-done-preflight.d.ts +8 -0
  167. package/dist/wu-done-preflight.js +18 -2
  168. package/dist/wu-done-ui.d.ts +3 -3
  169. package/dist/wu-done-ui.js +3 -3
  170. package/dist/wu-done-validation.d.ts +30 -0
  171. package/dist/wu-done-validation.js +106 -1
  172. package/dist/wu-done-worktree.d.ts +1 -1
  173. package/dist/wu-done-worktree.js +11 -1
  174. package/dist/wu-events-cleanup.d.ts +148 -0
  175. package/dist/wu-events-cleanup.js +401 -0
  176. package/dist/wu-helpers.d.ts +2 -2
  177. package/dist/wu-helpers.js +2 -2
  178. package/dist/wu-id-generator.d.ts +58 -0
  179. package/dist/wu-id-generator.js +103 -0
  180. package/dist/wu-lint.js +1 -1
  181. package/dist/wu-preflight-validators.d.ts +13 -1
  182. package/dist/wu-preflight-validators.js +56 -1
  183. package/dist/wu-recovery.d.ts +2 -2
  184. package/dist/wu-recovery.js +4 -4
  185. package/dist/wu-repair-core.d.ts +5 -5
  186. package/dist/wu-repair-core.js +6 -6
  187. package/dist/wu-schema-normalization.d.ts +1 -1
  188. package/dist/wu-schema-normalization.js +1 -1
  189. package/dist/wu-schema.d.ts +7 -7
  190. package/dist/wu-schema.js +8 -8
  191. package/dist/wu-spawn-context.d.ts +87 -0
  192. package/dist/wu-spawn-context.js +175 -0
  193. package/dist/wu-spawn-helpers.d.ts +1 -1
  194. package/dist/wu-spawn-helpers.js +1 -1
  195. package/dist/wu-spawn.d.ts +177 -4
  196. package/dist/wu-spawn.js +694 -72
  197. package/dist/wu-state-schema.d.ts +1 -1
  198. package/dist/wu-state-schema.js +1 -1
  199. package/dist/wu-state-store.d.ts +3 -3
  200. package/dist/wu-state-store.js +3 -3
  201. package/dist/wu-status-transition.d.ts +1 -1
  202. package/dist/wu-status-transition.js +1 -1
  203. package/dist/wu-status-updater.d.ts +3 -3
  204. package/dist/wu-status-updater.js +3 -3
  205. package/dist/wu-validation-constants.d.ts +2 -2
  206. package/dist/wu-validation-constants.js +2 -2
  207. package/dist/wu-validation.d.ts +3 -3
  208. package/dist/wu-validation.js +3 -3
  209. package/dist/wu-yaml-fixer.d.ts +2 -2
  210. package/dist/wu-yaml-fixer.js +3 -3
  211. package/dist/wu-yaml.d.ts +23 -0
  212. package/dist/wu-yaml.js +76 -2
  213. package/package.json +5 -2
@@ -9,6 +9,32 @@
9
9
  import { z } from 'zod';
10
10
  // WU-1067: Import gates execution schema from canonical source
11
11
  import { GatesExecutionConfigSchema } from './gates-config.js';
12
+ // WU-1259: Import methodology config schema for resolvePolicy()
13
+ import { MethodologyConfigSchema } from './resolve-policy.js';
14
+ /**
15
+ * Event archival configuration (WU-1207)
16
+ *
17
+ * Configures archival of old WU events from .lumenflow/state/wu-events.jsonl
18
+ * to .lumenflow/archive/wu-events-YYYY-MM.jsonl to prevent unbounded growth.
19
+ */
20
+ export const EventArchivalConfigSchema = z.object({
21
+ /**
22
+ * Archive events older than this duration in milliseconds (default: 90 days).
23
+ * Completed WU events older than this are moved to monthly archive files.
24
+ * Active WU events (in_progress/blocked/waiting) are never archived.
25
+ */
26
+ archiveAfter: z
27
+ .number()
28
+ .int()
29
+ .positive()
30
+ .default(90 * 24 * 60 * 60 * 1000),
31
+ /**
32
+ * Whether to keep archive files (default: true).
33
+ * When true, archived events are preserved in monthly archive files.
34
+ * When false, archived events are deleted (not recommended for audit trails).
35
+ */
36
+ keepArchives: z.boolean().default(true),
37
+ });
12
38
  /**
13
39
  * Directory paths configuration
14
40
  */
@@ -50,6 +76,8 @@ export const BeaconPathsSchema = z.object({
50
76
  base: z.string().default('.lumenflow'),
51
77
  /** State directory (default: '.lumenflow/state') */
52
78
  stateDir: z.string().default('.lumenflow/state'),
79
+ /** Archive directory (default: '.lumenflow/archive') */
80
+ archiveDir: z.string().default('.lumenflow/archive'),
53
81
  /** Stamps directory (default: '.lumenflow/stamps') */
54
82
  stampsDir: z.string().default('.lumenflow/stamps'),
55
83
  /** Merge lock file (default: '.lumenflow/merge.lock') */
@@ -64,6 +92,11 @@ export const BeaconPathsSchema = z.object({
64
92
  incidents: z.string().default('.lumenflow/incidents'),
65
93
  /** Commands log file (default: '.lumenflow/commands.log') */
66
94
  commandsLog: z.string().default('.lumenflow/commands.log'),
95
+ /**
96
+ * WU-1207: Event archival configuration
97
+ * Controls archival of old WU events to prevent unbounded growth.
98
+ */
99
+ eventArchival: EventArchivalConfigSchema.default(() => EventArchivalConfigSchema.parse({})),
67
100
  });
68
101
  /**
69
102
  * Git configuration
@@ -175,6 +208,87 @@ export const GatesConfigSchema = z.object({
175
208
  */
176
209
  execution: GatesExecutionConfigSchema.optional(),
177
210
  });
211
+ /**
212
+ * WU-1203: Progress signals configuration for sub-agent coordination
213
+ *
214
+ * When enabled, spawn prompts will include mandatory progress signal directives
215
+ * at configurable triggers (milestone completion, tests pass, before gates, when blocked).
216
+ * Frequency-based signals (every N tool calls) also supported.
217
+ *
218
+ * Addresses sub-agent coordination needs without unnecessary token waste.
219
+ */
220
+ export const ProgressSignalsConfigSchema = z.object({
221
+ /**
222
+ * Enable mandatory progress signals in spawn prompts.
223
+ * When true, spawn prompts show "Progress Signals (Required at Milestones)"
224
+ * When false, spawn prompts show "Progress Signals (Optional)"
225
+ * @default false
226
+ */
227
+ enabled: z.boolean().default(false),
228
+ /**
229
+ * Send progress signals every N tool calls.
230
+ * Set to 0 to disable frequency-based signals.
231
+ * @default 0
232
+ */
233
+ frequency: z.number().int().nonnegative().default(0),
234
+ /**
235
+ * Signal after each acceptance criterion is completed.
236
+ * @default true
237
+ */
238
+ on_milestone: z.boolean().default(true),
239
+ /**
240
+ * Signal when tests first pass.
241
+ * @default true
242
+ */
243
+ on_tests_pass: z.boolean().default(true),
244
+ /**
245
+ * Signal before running gates.
246
+ * @default true
247
+ */
248
+ before_gates: z.boolean().default(true),
249
+ /**
250
+ * Signal when work is blocked.
251
+ * @default true
252
+ */
253
+ on_blocked: z.boolean().default(true),
254
+ /**
255
+ * Automatically checkpoint memory at signal milestones.
256
+ * @default false
257
+ */
258
+ auto_checkpoint: z.boolean().default(false),
259
+ });
260
+ /**
261
+ * Signal cleanup configuration (WU-1204)
262
+ *
263
+ * Configures TTL-based cleanup for signals in .lumenflow/memory/signals.jsonl
264
+ * to prevent unbounded growth.
265
+ */
266
+ export const SignalCleanupConfigSchema = z.object({
267
+ /**
268
+ * TTL for read signals in milliseconds (default: 7 days).
269
+ * Read signals older than this are removed during cleanup.
270
+ */
271
+ ttl: z
272
+ .number()
273
+ .int()
274
+ .positive()
275
+ .default(7 * 24 * 60 * 60 * 1000),
276
+ /**
277
+ * TTL for unread signals in milliseconds (default: 30 days).
278
+ * Unread signals get a longer TTL to ensure important signals aren't missed.
279
+ */
280
+ unreadTtl: z
281
+ .number()
282
+ .int()
283
+ .positive()
284
+ .default(30 * 24 * 60 * 60 * 1000),
285
+ /**
286
+ * Maximum number of signals to retain (default: 500).
287
+ * When exceeded, oldest signals are removed first (keeping newest).
288
+ * Active WU signals are always retained regardless of this limit.
289
+ */
290
+ maxEntries: z.number().int().positive().default(500),
291
+ });
178
292
  /**
179
293
  * Memory layer configuration
180
294
  */
@@ -195,6 +309,23 @@ export const MemoryConfigSchema = z.object({
195
309
  .default(30 * 24 * 60 * 60 * 1000),
196
310
  /** Enable auto-cleanup (default: true) */
197
311
  enableAutoCleanup: z.boolean().default(true),
312
+ /**
313
+ * WU-1203: Progress signals configuration for sub-agent coordination.
314
+ * Optional - when not provided, spawn prompts show "Progress Signals (Optional)".
315
+ */
316
+ progress_signals: ProgressSignalsConfigSchema.optional(),
317
+ /**
318
+ * WU-1204: Signal cleanup configuration
319
+ * Controls TTL-based cleanup for signals.jsonl to prevent unbounded growth.
320
+ */
321
+ signalCleanup: SignalCleanupConfigSchema.default(() => SignalCleanupConfigSchema.parse({})),
322
+ /**
323
+ * WU-1289: Maximum size in bytes for spawn memory context.
324
+ * Controls the maximum size of memory context injected into wu:spawn prompts.
325
+ * Larger values include more context but increase token usage.
326
+ * @default 4096 (4KB)
327
+ */
328
+ spawn_context_max_size: z.number().int().positive().default(4096),
198
329
  });
199
330
  /**
200
331
  * UI configuration
@@ -325,6 +456,33 @@ export const ExperimentalConfigSchema = z.object({
325
456
  */
326
457
  recovery_command: z.boolean().default(true),
327
458
  });
459
+ /**
460
+ * WU-1270: Methodology telemetry configuration
461
+ *
462
+ * Opt-in telemetry to track which methodology modes are being used.
463
+ * Privacy-preserving: No PII or project-identifying information collected.
464
+ */
465
+ export const MethodologyTelemetryConfigSchema = z.object({
466
+ /**
467
+ * Enable methodology telemetry (opt-in).
468
+ * When true, tracks methodology.testing and methodology.architecture values
469
+ * on wu:spawn events. Data is privacy-preserving (no PII/project info).
470
+ * @default false
471
+ */
472
+ enabled: z.boolean().default(false),
473
+ });
474
+ /**
475
+ * WU-1270: Telemetry configuration
476
+ *
477
+ * Configuration for opt-in telemetry features.
478
+ */
479
+ export const TelemetryConfigSchema = z.object({
480
+ /**
481
+ * Methodology telemetry configuration (opt-in).
482
+ * Tracks methodology selection patterns for adoption insights.
483
+ */
484
+ methodology: MethodologyTelemetryConfigSchema.default(() => MethodologyTelemetryConfigSchema.parse({})),
485
+ });
328
486
  /**
329
487
  * Complete LumenFlow configuration schema
330
488
  */
@@ -351,6 +509,27 @@ export const LumenFlowConfigSchema = z.object({
351
509
  agents: AgentsConfigSchema.default(() => AgentsConfigSchema.parse({})),
352
510
  /** Experimental features (WU-1090) */
353
511
  experimental: ExperimentalConfigSchema.default(() => ExperimentalConfigSchema.parse({})),
512
+ /**
513
+ * WU-1270: Telemetry configuration
514
+ * Opt-in telemetry features for adoption tracking.
515
+ */
516
+ telemetry: TelemetryConfigSchema.default(() => TelemetryConfigSchema.parse({})),
517
+ /**
518
+ * WU-1259: Methodology configuration
519
+ * Single source of truth for testing/architecture methodology decisions.
520
+ * Used by both wu:spawn (prompt assembly) and gates (enforcement).
521
+ *
522
+ * @example
523
+ * ```yaml
524
+ * methodology:
525
+ * testing: 'tdd' # tdd | test-after | none
526
+ * architecture: 'hexagonal' # hexagonal | layered | none
527
+ * overrides:
528
+ * coverage_threshold: 85 # Override TDD's default 90%
529
+ * coverage_mode: 'warn' # Override TDD's default 'block'
530
+ * ```
531
+ */
532
+ methodology: MethodologyConfigSchema.optional(),
354
533
  });
355
534
  /**
356
535
  * Validate configuration data
@@ -358,6 +537,7 @@ export const LumenFlowConfigSchema = z.object({
358
537
  * @param data - Configuration data to validate
359
538
  * @returns Validation result with parsed config or errors
360
539
  */
540
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type -- Zod v4 return type inference
361
541
  export function validateConfig(data) {
362
542
  return LumenFlowConfigSchema.safeParse(data);
363
543
  }
@@ -11,7 +11,7 @@
11
11
  * - type: documentation only
12
12
  * - code_paths containing only documentation/config files (no code files)
13
13
  *
14
- * @see {@link tools/lib/wu-done-validators.mjs} - Integration point
14
+ * @see {@link packages/@lumenflow/cli/src/lib/wu-done-validators.ts} - Integration point
15
15
  * @see {@link docs/04-operations/_frameworks/lumenflow/lumenflow-complete.md} - TDD requirements
16
16
  */
17
17
  /**
@@ -41,7 +41,7 @@ export declare const EXEMPT_TYPES: readonly string[];
41
41
  /**
42
42
  * Determine if a file path represents a code file requiring automated tests.
43
43
  *
44
- * Code files are those with extensions like .mjs, .ts, .tsx, .js
44
+ * Code files are those with extensions like .ts, .ts, .tsx, .js
45
45
  * EXCEPT config files (vitest.config.ts, .eslintrc.js, etc.)
46
46
  *
47
47
  * @param {string} filePath - File path to check
@@ -11,7 +11,7 @@
11
11
  * - type: documentation only
12
12
  * - code_paths containing only documentation/config files (no code files)
13
13
  *
14
- * @see {@link tools/lib/wu-done-validators.mjs} - Integration point
14
+ * @see {@link packages/@lumenflow/cli/src/lib/wu-done-validators.ts} - Integration point
15
15
  * @see {@link docs/04-operations/_frameworks/lumenflow/lumenflow-complete.md} - TDD requirements
16
16
  */
17
17
  import path from 'node:path';
@@ -20,7 +20,7 @@ import { TEST_TYPES, WU_TYPES } from './wu-constants.js';
20
20
  * Code file extensions that require automated tests.
21
21
  * @constant {string[]}
22
22
  */
23
- const CODE_EXTENSIONS = Object.freeze(['.js', '.ts', '.tsx', '.mjs']);
23
+ const CODE_EXTENSIONS = Object.freeze(['.js', '.ts', '.tsx', '.ts']);
24
24
  /**
25
25
  * Non-code file extensions (documentation, data, config).
26
26
  * @constant {string[]}
@@ -67,7 +67,7 @@ export const EXEMPT_TYPES = Object.freeze([WU_TYPES.DOCUMENTATION]);
67
67
  /**
68
68
  * Determine if a file path represents a code file requiring automated tests.
69
69
  *
70
- * Code files are those with extensions like .mjs, .ts, .tsx, .js
70
+ * Code files are those with extensions like .ts, .ts, .tsx, .js
71
71
  * EXCEPT config files (vitest.config.ts, .eslintrc.js, etc.)
72
72
  *
73
73
  * @param {string} filePath - File path to check
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * WU-1747: Merge Lock Module
3
+ * WU-1174: Lock files moved to temp directory to avoid polluting main checkout
3
4
  *
4
5
  * Provides atomic locking mechanism for wu:done merge operations
5
6
  * to prevent race conditions during concurrent completions.
@@ -9,6 +10,7 @@
9
10
  * - Stale lock detection and auto-cleanup
10
11
  * - Idempotent re-acquisition for same WU
11
12
  * - Guaranteed cleanup via withMergeLock wrapper
13
+ * - Lock files stored in temp directory (not main checkout)
12
14
  *
13
15
  * @module merge-lock
14
16
  */
@@ -41,7 +43,12 @@ export declare const MERGE_LOCK_STALE_MS = 60000;
41
43
  * Options for lock file operations
42
44
  */
43
45
  interface MergeLockBaseDirOptions {
44
- /** Base directory (defaults to cwd) */
46
+ /**
47
+ * Base directory override (for testing only)
48
+ *
49
+ * WU-1174: In production, locks are always stored in LUMENFLOW_PATHS.LOCK_DIR
50
+ * (a temp directory). This option allows tests to use isolated directories.
51
+ */
45
52
  baseDir?: string;
46
53
  }
47
54
  /**
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * WU-1747: Merge Lock Module
3
+ * WU-1174: Lock files moved to temp directory to avoid polluting main checkout
3
4
  *
4
5
  * Provides atomic locking mechanism for wu:done merge operations
5
6
  * to prevent race conditions during concurrent completions.
@@ -9,13 +10,14 @@
9
10
  * - Stale lock detection and auto-cleanup
10
11
  * - Idempotent re-acquisition for same WU
11
12
  * - Guaranteed cleanup via withMergeLock wrapper
13
+ * - Lock files stored in temp directory (not main checkout)
12
14
  *
13
15
  * @module merge-lock
14
16
  */
15
17
  import { existsSync, readFileSync, writeFileSync, unlinkSync, mkdirSync } from 'node:fs';
16
18
  import path from 'node:path';
17
19
  import crypto from 'node:crypto';
18
- import { LOG_PREFIX, EMOJI, LUMENFLOW_PATHS } from './wu-constants.js';
20
+ import { LOG_PREFIX, EMOJI, LUMENFLOW_PATHS, LOCK_DIR_NAME } from './wu-constants.js';
19
21
  import { createError, ErrorCodes } from './error-handler.js';
20
22
  /**
21
23
  * Default timeout for waiting to acquire lock (ms)
@@ -36,12 +38,19 @@ const LOCK_POLL_INTERVAL_MS = 500;
36
38
  /**
37
39
  * Get the path to the merge lock file
38
40
  *
41
+ * WU-1174: Lock files are stored in a temp directory to avoid polluting
42
+ * the main checkout. The baseDir option is only for testing isolation.
43
+ *
39
44
  * @param {MergeLockBaseDirOptions} [options]
40
45
  * @returns {string} Path to lock file
41
46
  */
42
47
  function getLockPath(options = {}) {
43
- const baseDir = options.baseDir || process.cwd();
44
- return path.join(baseDir, LUMENFLOW_PATHS.BASE, LOCK_FILE_NAME);
48
+ // WU-1174: Use temp directory for locks (not main checkout's .lumenflow/)
49
+ // baseDir is only used for test isolation
50
+ const lockDir = options.baseDir
51
+ ? path.join(options.baseDir, LOCK_DIR_NAME)
52
+ : LUMENFLOW_PATHS.LOCK_DIR;
53
+ return path.join(lockDir, LOCK_FILE_NAME);
45
54
  }
46
55
  /**
47
56
  * Read lock file contents
@@ -71,10 +80,10 @@ function readLockFile(options = {}) {
71
80
  */
72
81
  function writeLockFile(lockInfo, options = {}) {
73
82
  const lockPath = getLockPath(options);
74
- const lumenflowDir = path.dirname(lockPath);
75
- // Ensure .lumenflow directory exists
76
- if (!existsSync(lumenflowDir)) {
77
- mkdirSync(lumenflowDir, { recursive: true });
83
+ const lockDir = path.dirname(lockPath);
84
+ // WU-1174: Ensure lock directory exists (temp directory, not .lumenflow/)
85
+ if (!existsSync(lockDir)) {
86
+ mkdirSync(lockDir, { recursive: true });
78
87
  }
79
88
  writeFileSync(lockPath, JSON.stringify(lockInfo, null, 2));
80
89
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Micro-Worktree Operations
3
3
  *
4
- * Race-safe micro-worktree isolation pattern extracted from wu-create.mjs (WU-1262).
4
+ * Race-safe micro-worktree isolation pattern extracted from wu-create.ts (WU-1262).
5
5
  * Provides shared infrastructure for commands that need to modify main branch
6
6
  * atomically without switching checkout.
7
7
  *
@@ -23,11 +23,51 @@
23
23
  * - Cleanup guaranteed even on failure
24
24
  *
25
25
  * Consumers:
26
- * @see {@link tools/wu-create.mjs} - WU creation (WU-1262, WU-1439)
27
- * @see {@link tools/wu-edit.mjs} - Spec edits (WU-1274)
28
- * @see {@link tools/initiative-create.mjs} - Initiative creation (WU-1439)
26
+ * @see {@link packages/@lumenflow/cli/src/wu-create.ts} - WU creation (WU-1262, WU-1439)
27
+ * @see {@link packages/@lumenflow/cli/src/wu-edit.ts} - Spec edits (WU-1274)
28
+ * @see {@link packages/@lumenflow/cli/src/initiative-create.ts} - Initiative creation (WU-1439)
29
29
  */
30
30
  import type { GitAdapter } from './git-adapter.js';
31
+ /**
32
+ * Context passed to the execute function in withMicroWorktree
33
+ */
34
+ interface MicroWorktreeContext {
35
+ /** Path to the micro-worktree directory */
36
+ worktreePath: string;
37
+ /** GitAdapter instance for the micro-worktree */
38
+ gitWorktree: GitAdapter;
39
+ }
40
+ /**
41
+ * Result returned by the execute function in withMicroWorktree
42
+ */
43
+ interface MicroWorktreeExecuteResult {
44
+ /** Commit message for the changes */
45
+ commitMessage: string;
46
+ /** List of files that were modified */
47
+ files: string[];
48
+ }
49
+ /**
50
+ * Options for withMicroWorktree
51
+ */
52
+ interface WithMicroWorktreeOptions {
53
+ /** Operation name (e.g., 'wu-create', 'wu-edit') */
54
+ operation: string;
55
+ /** WU ID (e.g., 'WU-123') */
56
+ id: string;
57
+ /** Log prefix for console output */
58
+ logPrefix?: string;
59
+ /** Skip local main merge, push directly to origin/main */
60
+ pushOnly?: boolean;
61
+ /** Async function to execute in micro-worktree */
62
+ execute: (context: MicroWorktreeContext) => Promise<MicroWorktreeExecuteResult>;
63
+ }
64
+ /**
65
+ * Result from withMicroWorktree
66
+ */
67
+ interface WithMicroWorktreeResult extends MicroWorktreeExecuteResult {
68
+ /** Git ref to use for worktree creation */
69
+ ref: string;
70
+ }
31
71
  /**
32
72
  * Maximum retry attempts for ff-only merge when main moves
33
73
  *
@@ -35,6 +75,14 @@ import type { GitAdapter } from './git-adapter.js';
35
75
  * concurrently. Each retry fetches latest main and rebases.
36
76
  */
37
77
  export declare const MAX_MERGE_RETRIES = 3;
78
+ /**
79
+ * Maximum retry attempts for push when origin/main advances
80
+ *
81
+ * WU-1179: When push fails due to race condition (origin advanced while we
82
+ * were working), rollback local main to origin/main and retry.
83
+ * Each retry: fetch -> rebase temp branch -> re-merge -> push.
84
+ */
85
+ export declare const MAX_PUSH_RETRIES = 3;
38
86
  /**
39
87
  * Environment variable name for LUMENFLOW_FORCE bypass
40
88
  *
@@ -60,14 +108,14 @@ export declare const DEFAULT_LOG_PREFIX = "[micro-wt]";
60
108
  * @param {string} id - WU ID (e.g., 'wu-123')
61
109
  * @returns {string} Temp branch name (e.g., 'tmp/wu-create/wu-123')
62
110
  */
63
- export declare function getTempBranchName(operation: any, id: any): string;
111
+ export declare function getTempBranchName(operation: string, id: string): string;
64
112
  /**
65
113
  * Create micro-worktree in /tmp directory
66
114
  *
67
115
  * @param {string} prefix - Directory prefix (e.g., 'wu-create-', 'wu-edit-')
68
116
  * @returns {string} Path to created micro-worktree directory
69
117
  */
70
- export declare function createMicroWorktreeDir(prefix: any): string;
118
+ export declare function createMicroWorktreeDir(prefix: string): string;
71
119
  /**
72
120
  * Parse git worktree list output to find worktrees by branch
73
121
  *
@@ -77,7 +125,7 @@ export declare function createMicroWorktreeDir(prefix: any): string;
77
125
  * @param {string} branchName - Branch name to search for (e.g., 'tmp/wu-create/wu-123')
78
126
  * @returns {string|null} Worktree path if found, null otherwise
79
127
  */
80
- export declare function findWorktreeByBranch(worktreeListOutput: any, branchName: any): any;
128
+ export declare function findWorktreeByBranch(worktreeListOutput: string, branchName: string): string | null;
81
129
  /**
82
130
  * Clean up orphaned micro-worktree and temp branch from a previous interrupted operation
83
131
  *
@@ -95,7 +143,7 @@ export declare function findWorktreeByBranch(worktreeListOutput: any, branchName
95
143
  * @param {string} logPrefix - Log prefix for console output
96
144
  * @returns {Promise<{cleanedWorktree: boolean, cleanedBranch: boolean}>} Cleanup status
97
145
  */
98
- export declare function cleanupOrphanedMicroWorktree(operation: any, id: any, gitAdapter: any, logPrefix?: string): Promise<{
146
+ export declare function cleanupOrphanedMicroWorktree(operation: string, id: string, gitAdapter: GitAdapter, logPrefix?: string): Promise<{
99
147
  cleanedWorktree: boolean;
100
148
  cleanedBranch: boolean;
101
149
  }>;
@@ -112,7 +160,7 @@ export declare function cleanupOrphanedMicroWorktree(operation: any, id: any, gi
112
160
  * @param {string} branchName - Temp branch name
113
161
  * @param {string} logPrefix - Log prefix for console output
114
162
  */
115
- export declare function cleanupMicroWorktree(worktreePath: any, branchName: any, logPrefix?: string): Promise<void>;
163
+ export declare function cleanupMicroWorktree(worktreePath: string, branchName: string, logPrefix?: string): Promise<void>;
116
164
  /**
117
165
  * Stage changes including deletions in micro-worktree
118
166
  *
@@ -124,7 +172,7 @@ export declare function cleanupMicroWorktree(worktreePath: any, branchName: any,
124
172
  * @param {string[]|undefined} files - Files to stage (undefined/empty = stage all)
125
173
  * @returns {Promise<void>}
126
174
  */
127
- export declare function stageChangesWithDeletions(gitWorktree: any, files: any): Promise<void>;
175
+ export declare function stageChangesWithDeletions(gitWorktree: GitAdapter, files: string[] | undefined): Promise<void>;
128
176
  /**
129
177
  * Format files using prettier before committing
130
178
  *
@@ -135,7 +183,7 @@ export declare function stageChangesWithDeletions(gitWorktree: any, files: any):
135
183
  * @param {string} worktreePath - Path to the micro-worktree
136
184
  * @param {string} logPrefix - Log prefix for console output
137
185
  */
138
- export declare function formatFiles(files: any, worktreePath: any, logPrefix?: string): Promise<void>;
186
+ export declare function formatFiles(files: string[] | undefined, worktreePath: string, logPrefix?: string): Promise<void>;
139
187
  /**
140
188
  * Merge temp branch to main with ff-only and retry logic
141
189
  *
@@ -147,7 +195,26 @@ export declare function formatFiles(files: any, worktreePath: any, logPrefix?: s
147
195
  * @param {string} logPrefix - Log prefix for console output
148
196
  * @throws {Error} If merge fails after all retries
149
197
  */
150
- export declare function mergeWithRetry(tempBranchName: any, microWorktreePath: any, logPrefix?: string): Promise<void>;
198
+ export declare function mergeWithRetry(tempBranchName: string, microWorktreePath: string, logPrefix?: string): Promise<void>;
199
+ /**
200
+ * Push to origin/main with retry logic for race conditions
201
+ *
202
+ * WU-1179: When push fails because origin/main advanced (race condition with
203
+ * parallel agents), this function rolls back local main to origin/main and
204
+ * retries the full sequence: fetch -> rebase temp branch -> re-merge -> push.
205
+ *
206
+ * This prevents the scenario where local main is left diverged from origin
207
+ * after a push failure.
208
+ *
209
+ * @param {Object} mainGit - GitAdapter instance for main checkout
210
+ * @param {Object} worktreeGit - GitAdapter instance for micro-worktree
211
+ * @param {string} remote - Remote name (e.g., 'origin')
212
+ * @param {string} branch - Branch name (e.g., 'main')
213
+ * @param {string} tempBranchName - Temp branch that was merged (for rebase)
214
+ * @param {string} logPrefix - Log prefix for console output
215
+ * @throws {Error} If push fails after all retries
216
+ */
217
+ export declare function pushWithRetry(mainGit: GitAdapter, worktreeGit: GitAdapter, remote: string, branch: string, tempBranchName: string, logPrefix?: string): Promise<void>;
151
218
  /**
152
219
  * Push using refspec with LUMENFLOW_FORCE to bypass pre-push hooks
153
220
  *
@@ -188,4 +255,5 @@ export declare function pushRefspecWithForce(gitAdapter: GitAdapter, remote: str
188
255
  * @returns {Promise<Object>} Result with ref property for worktree creation
189
256
  * @throws {Error} If any step fails (cleanup still runs)
190
257
  */
191
- export declare function withMicroWorktree(options: any): Promise<any>;
258
+ export declare function withMicroWorktree(options: WithMicroWorktreeOptions): Promise<WithMicroWorktreeResult>;
259
+ export {};