@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
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Patrol Loop Module (WU-1242)
3
+ *
4
+ * Continuous patrol loop for monitoring spawn health.
5
+ * The 'Witness patrol' pattern - keeps the spawn fleet healthy by
6
+ * checking status at configurable intervals with exponential backoff
7
+ * on repeated failures.
8
+ *
9
+ * Features:
10
+ * - Configurable patrol interval (default 5min)
11
+ * - Exponential backoff on failures (max 1hr)
12
+ * - Graceful shutdown support
13
+ * - Cycle callbacks for status reporting
14
+ * - Error handling with continuation
15
+ *
16
+ * @see {@link packages/@lumenflow/cli/src/orchestrate-monitor.ts} - CLI integration
17
+ * @see {@link packages/@lumenflow/core/src/__tests__/patrol-loop.test.ts} - Tests
18
+ */
19
+ /**
20
+ * Default patrol interval (5 minutes in milliseconds)
21
+ */
22
+ export const DEFAULT_PATROL_INTERVAL_MS = 5 * 60 * 1000;
23
+ /**
24
+ * Maximum backoff interval (1 hour in milliseconds)
25
+ */
26
+ export const MAX_BACKOFF_MS = 60 * 60 * 1000;
27
+ /**
28
+ * Calculates the backoff interval based on consecutive failures.
29
+ * Uses exponential backoff with a maximum of 1 hour.
30
+ *
31
+ * Backoff formula: baseInterval * 2^(failures-1), capped at MAX_BACKOFF_MS
32
+ *
33
+ * @param consecutiveFailures - Number of consecutive failures (1-indexed)
34
+ * @param baseIntervalMs - Base interval in milliseconds
35
+ * @returns Backoff interval in milliseconds
36
+ *
37
+ * @example
38
+ * calculateBackoff(1, 5*60*1000) // 5 minutes (no backoff yet)
39
+ * calculateBackoff(2, 5*60*1000) // 10 minutes (2x)
40
+ * calculateBackoff(3, 5*60*1000) // 20 minutes (4x)
41
+ */
42
+ export function calculateBackoff(consecutiveFailures, baseIntervalMs) {
43
+ if (consecutiveFailures <= 1) {
44
+ return baseIntervalMs;
45
+ }
46
+ // Exponential backoff: baseInterval * 2^(failures-1)
47
+ const multiplier = Math.pow(2, consecutiveFailures - 1);
48
+ const backoffMs = baseIntervalMs * multiplier;
49
+ // Cap at maximum backoff
50
+ return Math.min(backoffMs, MAX_BACKOFF_MS);
51
+ }
52
+ /**
53
+ * Patrol loop for continuous spawn monitoring.
54
+ *
55
+ * @example
56
+ * const patrol = new PatrolLoop({
57
+ * checkFn: async () => {
58
+ * const result = await runMonitor();
59
+ * return {
60
+ * healthy: result.stuckSpawns.length === 0,
61
+ * stuckCount: result.stuckSpawns.length,
62
+ * zombieCount: result.zombieLocks.length,
63
+ * };
64
+ * },
65
+ * intervalMs: 5 * 60 * 1000, // 5 minutes
66
+ * onCycle: (result, meta) => {
67
+ * console.log(`Cycle ${meta.cycleNumber}: ${result.healthy ? 'healthy' : 'issues detected'}`);
68
+ * },
69
+ * });
70
+ *
71
+ * patrol.start();
72
+ * // Later...
73
+ * patrol.stop();
74
+ */
75
+ export class PatrolLoop {
76
+ checkFn;
77
+ baseIntervalMs;
78
+ onCycle;
79
+ onError;
80
+ timer = null;
81
+ running = false;
82
+ failures = 0;
83
+ cycles = 0;
84
+ /**
85
+ * Creates a new PatrolLoop instance.
86
+ *
87
+ * @param options - Patrol loop configuration
88
+ */
89
+ constructor(options) {
90
+ this.checkFn = options.checkFn;
91
+ this.baseIntervalMs = options.intervalMs ?? DEFAULT_PATROL_INTERVAL_MS;
92
+ this.onCycle = options.onCycle;
93
+ this.onError = options.onError;
94
+ }
95
+ /**
96
+ * The configured base interval in milliseconds.
97
+ */
98
+ get intervalMs() {
99
+ return this.baseIntervalMs;
100
+ }
101
+ /**
102
+ * Whether the patrol loop is currently running.
103
+ */
104
+ get isRunning() {
105
+ return this.running;
106
+ }
107
+ /**
108
+ * Number of consecutive failures (resets on success).
109
+ */
110
+ get consecutiveFailures() {
111
+ return this.failures;
112
+ }
113
+ /**
114
+ * Total number of completed patrol cycles.
115
+ */
116
+ get totalCycles() {
117
+ return this.cycles;
118
+ }
119
+ /**
120
+ * Starts the patrol loop.
121
+ * Does nothing if already running.
122
+ */
123
+ start() {
124
+ if (this.running) {
125
+ return; // Already running, don't create duplicate timers
126
+ }
127
+ this.running = true;
128
+ this.scheduleNextCycle();
129
+ }
130
+ /**
131
+ * Stops the patrol loop.
132
+ * Safe to call even if not running.
133
+ */
134
+ stop() {
135
+ this.running = false;
136
+ if (this.timer) {
137
+ clearTimeout(this.timer);
138
+ this.timer = null;
139
+ }
140
+ }
141
+ /**
142
+ * Schedules the next patrol cycle.
143
+ */
144
+ scheduleNextCycle() {
145
+ if (!this.running) {
146
+ return;
147
+ }
148
+ const intervalMs = calculateBackoff(this.failures, this.baseIntervalMs);
149
+ this.timer = setTimeout(() => {
150
+ void this.runCycle().then(() => this.scheduleNextCycle());
151
+ }, intervalMs);
152
+ }
153
+ /**
154
+ * Runs a single patrol cycle.
155
+ */
156
+ async runCycle() {
157
+ if (!this.running) {
158
+ return;
159
+ }
160
+ this.cycles++;
161
+ const cycleNumber = this.cycles;
162
+ try {
163
+ const result = await this.checkFn();
164
+ // Success - reset failure count
165
+ this.failures = 0;
166
+ // Call cycle callback
167
+ if (this.onCycle) {
168
+ const meta = {
169
+ cycleNumber,
170
+ intervalMs: this.baseIntervalMs,
171
+ consecutiveFailures: this.failures,
172
+ timestamp: new Date(),
173
+ };
174
+ this.onCycle(result, meta);
175
+ }
176
+ }
177
+ catch (error) {
178
+ // Failure - increment failure count
179
+ this.failures++;
180
+ // Call error callback
181
+ if (this.onError) {
182
+ this.onError(error instanceof Error ? error : new Error(String(error)), cycleNumber);
183
+ }
184
+ }
185
+ }
186
+ }
@@ -7,12 +7,12 @@
7
7
  *
8
8
  * This is a NON-BLOCKING pre-flight check - it warns but doesn't fail wu:done.
9
9
  *
10
- * @see {@link tools/wu-done.mjs} - Integrates this as pre-flight check
11
- * @see {@link tools/lib/wu-constants.mjs} - Constants for log prefixes
10
+ * @see {@link packages/@lumenflow/cli/src/wu-done.ts} - Integrates this as pre-flight check
11
+ * @see {@link packages/@lumenflow/cli/src/lib/wu-constants.ts} - Constants for log prefixes
12
12
  */
13
13
  /**
14
14
  * Re-export interfering process names for external consumers.
15
- * Source of truth is PROCESS_DETECTION.INTERFERING_NAMES in wu-constants.mjs
15
+ * Source of truth is PROCESS_DETECTION.INTERFERING_NAMES in wu-constants.ts
16
16
  */
17
17
  export declare const INTERFERING_PROCESS_NAMES: string[];
18
18
  /**
@@ -71,14 +71,14 @@ export declare function detectBackgroundProcesses(worktreePath: any): Promise<{
71
71
  /**
72
72
  * Run background process detection as a pre-flight check.
73
73
  *
74
- * This is the main entry point for wu-done.mjs integration.
74
+ * This is the main entry point for wu-done.ts integration.
75
75
  * Logs warnings if background processes are detected but does NOT fail.
76
76
  *
77
77
  * @param {string} worktreePath - Path to the worktree directory
78
78
  * @returns {Promise<void>}
79
79
  *
80
80
  * @example
81
- * // In wu-done.mjs pre-flight checks:
81
+ * // In wu-done.ts pre-flight checks:
82
82
  * await runBackgroundProcessCheck(worktreePath);
83
83
  */
84
84
  export declare function runBackgroundProcessCheck(worktreePath: any): Promise<void>;
@@ -7,14 +7,14 @@
7
7
  *
8
8
  * This is a NON-BLOCKING pre-flight check - it warns but doesn't fail wu:done.
9
9
  *
10
- * @see {@link tools/wu-done.mjs} - Integrates this as pre-flight check
11
- * @see {@link tools/lib/wu-constants.mjs} - Constants for log prefixes
10
+ * @see {@link packages/@lumenflow/cli/src/wu-done.ts} - Integrates this as pre-flight check
11
+ * @see {@link packages/@lumenflow/cli/src/lib/wu-constants.ts} - Constants for log prefixes
12
12
  */
13
13
  import psList from 'ps-list';
14
14
  import { LOG_PREFIX, EMOJI, PROCESS_DETECTION, STRING_LITERALS } from './wu-constants.js';
15
15
  /**
16
16
  * Re-export interfering process names for external consumers.
17
- * Source of truth is PROCESS_DETECTION.INTERFERING_NAMES in wu-constants.mjs
17
+ * Source of truth is PROCESS_DETECTION.INTERFERING_NAMES in wu-constants.ts
18
18
  */
19
19
  export const INTERFERING_PROCESS_NAMES = PROCESS_DETECTION.INTERFERING_NAMES;
20
20
  /**
@@ -148,14 +148,14 @@ export async function detectBackgroundProcesses(worktreePath) {
148
148
  /**
149
149
  * Run background process detection as a pre-flight check.
150
150
  *
151
- * This is the main entry point for wu-done.mjs integration.
151
+ * This is the main entry point for wu-done.ts integration.
152
152
  * Logs warnings if background processes are detected but does NOT fail.
153
153
  *
154
154
  * @param {string} worktreePath - Path to the worktree directory
155
155
  * @returns {Promise<void>}
156
156
  *
157
157
  * @example
158
- * // In wu-done.mjs pre-flight checks:
158
+ * // In wu-done.ts pre-flight checks:
159
159
  * await runBackgroundProcessCheck(worktreePath);
160
160
  */
161
161
  export async function runBackgroundProcessCheck(worktreePath) {
@@ -10,9 +10,9 @@
10
10
  * Part of WU-1371: Post-rebase artifact cleanup
11
11
  * WU-1449: Extended to handle backlog/status duplicates after rebase
12
12
  *
13
- * @see {@link tools/wu-done.mjs} - Creates completion artifacts
14
- * @see {@link tools/lib/stamp-utils.mjs} - Stamp file utilities
15
- * @see {@link tools/lib/wu-recovery.mjs} - Related zombie state handling
13
+ * @see {@link packages/@lumenflow/cli/src/wu-done.ts} - Creates completion artifacts
14
+ * @see {@link packages/@lumenflow/cli/src/lib/stamp-utils.ts} - Stamp file utilities
15
+ * @see {@link packages/@lumenflow/cli/src/lib/wu-recovery.ts} - Related zombie state handling
16
16
  */
17
17
  /**
18
18
  * Detect rebased completion artifacts in a worktree
@@ -10,9 +10,9 @@
10
10
  * Part of WU-1371: Post-rebase artifact cleanup
11
11
  * WU-1449: Extended to handle backlog/status duplicates after rebase
12
12
  *
13
- * @see {@link tools/wu-done.mjs} - Creates completion artifacts
14
- * @see {@link tools/lib/stamp-utils.mjs} - Stamp file utilities
15
- * @see {@link tools/lib/wu-recovery.mjs} - Related zombie state handling
13
+ * @see {@link packages/@lumenflow/cli/src/wu-done.ts} - Creates completion artifacts
14
+ * @see {@link packages/@lumenflow/cli/src/lib/stamp-utils.ts} - Stamp file utilities
15
+ * @see {@link packages/@lumenflow/cli/src/lib/wu-recovery.ts} - Related zombie state handling
16
16
  */
17
17
  import { readFile, writeFile, unlink, access } from 'node:fs/promises';
18
18
  import { existsSync, rmSync } from 'node:fs';
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Resolve Policy - Single Source of Truth for Methodology Decisions
3
+ *
4
+ * WU-1259: Provides a unified policy resolver that both wu:spawn and gates use.
5
+ *
6
+ * This module:
7
+ * - Defines the methodology.* config schema
8
+ * - Implements resolvePolicy() to produce ResolvedPolicy
9
+ * - Applies precedence: template defaults -> methodology.overrides -> explicit gates.* -> CLI flags
10
+ *
11
+ * @module resolve-policy
12
+ */
13
+ import { z } from 'zod';
14
+ import type { LumenFlowConfig } from './lumenflow-config-schema.js';
15
+ /**
16
+ * Testing methodology options
17
+ */
18
+ export declare const TESTING_METHODOLOGY: {
19
+ readonly TDD: "tdd";
20
+ readonly TEST_AFTER: "test-after";
21
+ readonly NONE: "none";
22
+ };
23
+ export type TestingMethodology = (typeof TESTING_METHODOLOGY)[keyof typeof TESTING_METHODOLOGY];
24
+ /**
25
+ * Architecture methodology options
26
+ */
27
+ export declare const ARCHITECTURE_METHODOLOGY: {
28
+ readonly HEXAGONAL: "hexagonal";
29
+ readonly LAYERED: "layered";
30
+ readonly NONE: "none";
31
+ };
32
+ export type ArchitectureMethodology = (typeof ARCHITECTURE_METHODOLOGY)[keyof typeof ARCHITECTURE_METHODOLOGY];
33
+ /**
34
+ * Coverage mode options
35
+ */
36
+ export declare const COVERAGE_MODE: {
37
+ readonly BLOCK: "block";
38
+ readonly WARN: "warn";
39
+ readonly OFF: "off";
40
+ };
41
+ export type CoverageMode = (typeof COVERAGE_MODE)[keyof typeof COVERAGE_MODE];
42
+ /**
43
+ * Zod schema for testing methodology enum
44
+ */
45
+ export declare const TestingMethodologySchema: z.ZodEnum<{
46
+ tdd: "tdd";
47
+ "test-after": "test-after";
48
+ none: "none";
49
+ }>;
50
+ /**
51
+ * Zod schema for architecture methodology enum
52
+ */
53
+ export declare const ArchitectureMethodologySchema: z.ZodEnum<{
54
+ none: "none";
55
+ hexagonal: "hexagonal";
56
+ layered: "layered";
57
+ }>;
58
+ /**
59
+ * Zod schema for coverage mode enum
60
+ */
61
+ export declare const CoverageModeSchema: z.ZodEnum<{
62
+ off: "off";
63
+ warn: "warn";
64
+ block: "block";
65
+ }>;
66
+ /**
67
+ * Methodology overrides schema
68
+ *
69
+ * These allow tweaking template defaults without changing methodology.
70
+ */
71
+ export declare const MethodologyOverridesSchema: z.ZodObject<{
72
+ coverage_threshold: z.ZodOptional<z.ZodNumber>;
73
+ coverage_mode: z.ZodOptional<z.ZodEnum<{
74
+ off: "off";
75
+ warn: "warn";
76
+ block: "block";
77
+ }>>;
78
+ }, z.core.$strip>;
79
+ export type MethodologyOverrides = z.infer<typeof MethodologyOverridesSchema>;
80
+ /**
81
+ * Main methodology configuration schema
82
+ *
83
+ * Config example in .lumenflow.config.yaml:
84
+ * ```yaml
85
+ * methodology:
86
+ * testing: 'tdd' # tdd | test-after | none
87
+ * architecture: 'hexagonal' # hexagonal | layered | none
88
+ * overrides:
89
+ * coverage_threshold: 85 # Override TDD's default 90%
90
+ * coverage_mode: 'warn' # Override TDD's default 'block'
91
+ * ```
92
+ */
93
+ export declare const MethodologyConfigSchema: z.ZodObject<{
94
+ testing: z.ZodDefault<z.ZodEnum<{
95
+ tdd: "tdd";
96
+ "test-after": "test-after";
97
+ none: "none";
98
+ }>>;
99
+ architecture: z.ZodDefault<z.ZodEnum<{
100
+ none: "none";
101
+ hexagonal: "hexagonal";
102
+ layered: "layered";
103
+ }>>;
104
+ overrides: z.ZodOptional<z.ZodObject<{
105
+ coverage_threshold: z.ZodOptional<z.ZodNumber>;
106
+ coverage_mode: z.ZodOptional<z.ZodEnum<{
107
+ off: "off";
108
+ warn: "warn";
109
+ block: "block";
110
+ }>>;
111
+ }, z.core.$strip>>;
112
+ }, z.core.$strip>;
113
+ export type MethodologyConfig = z.infer<typeof MethodologyConfigSchema>;
114
+ /**
115
+ * The resolved policy used by wu:spawn and gates
116
+ *
117
+ * This is the single source of truth for methodology decisions.
118
+ * All consumers (spawn prompts, gate runners, etc.) should use this type.
119
+ */
120
+ export interface ResolvedPolicy {
121
+ /** Active testing methodology */
122
+ testing: TestingMethodology;
123
+ /** Active architecture methodology */
124
+ architecture: ArchitectureMethodology;
125
+ /** Resolved coverage threshold (0-100) */
126
+ coverage_threshold: number;
127
+ /** Resolved coverage mode */
128
+ coverage_mode: CoverageMode;
129
+ /** Whether tests are required for completion */
130
+ tests_required: boolean;
131
+ }
132
+ /**
133
+ * Options for resolvePolicy
134
+ */
135
+ export interface ResolvePolicyOptions {
136
+ /**
137
+ * Raw config object before Zod defaults were applied.
138
+ * Used to detect explicit vs default values for gates.* fields.
139
+ *
140
+ * When provided, only EXPLICIT gates.* settings override methodology.
141
+ * When not provided, any gates.* value (including defaults) overrides methodology.
142
+ */
143
+ rawConfig?: {
144
+ gates?: {
145
+ minCoverage?: number;
146
+ enableCoverage?: boolean;
147
+ };
148
+ };
149
+ }
150
+ /**
151
+ * Resolve the effective policy from configuration
152
+ *
153
+ * Precedence (highest to lowest):
154
+ * 1. CLI flags (not handled here - handled by command layer)
155
+ * 2. Explicit gates.* configuration (only if rawConfig provided to detect explicit vs default)
156
+ * 3. methodology.overrides
157
+ * 4. methodology template defaults
158
+ *
159
+ * This ensures backwards compatibility: existing users with explicit
160
+ * gates.* config see no change, while new users can use methodology
161
+ * config for a higher-level abstraction.
162
+ *
163
+ * @param config - The full LumenFlow configuration
164
+ * @param options - Options including rawConfig for explicit detection
165
+ * @returns The resolved policy for use by wu:spawn and gates
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * import { getConfig } from './lumenflow-config.js';
170
+ * import { resolvePolicy } from './resolve-policy.js';
171
+ *
172
+ * const config = getConfig();
173
+ * const policy = resolvePolicy(config);
174
+ *
175
+ * console.log(policy.coverage_threshold); // 90 (or configured value)
176
+ * console.log(policy.testing); // 'tdd' (or configured value)
177
+ * ```
178
+ *
179
+ * @example With raw config for explicit detection
180
+ * ```typescript
181
+ * const rawConfig = { methodology: { testing: 'test-after' } };
182
+ * const config = parseConfig(rawConfig);
183
+ * const policy = resolvePolicy(config, { rawConfig });
184
+ * // policy.coverage_threshold will be 70 (test-after template default)
185
+ * // because gates.minCoverage wasn't EXPLICITLY set
186
+ * ```
187
+ */
188
+ export declare function resolvePolicy(config: LumenFlowConfig, options?: ResolvePolicyOptions): ResolvedPolicy;
189
+ /**
190
+ * Create a default resolved policy
191
+ *
192
+ * Convenience function for when no config is available.
193
+ * Returns strict TDD defaults.
194
+ */
195
+ export declare function getDefaultPolicy(): ResolvedPolicy;
@@ -0,0 +1,203 @@
1
+ /**
2
+ * Resolve Policy - Single Source of Truth for Methodology Decisions
3
+ *
4
+ * WU-1259: Provides a unified policy resolver that both wu:spawn and gates use.
5
+ *
6
+ * This module:
7
+ * - Defines the methodology.* config schema
8
+ * - Implements resolvePolicy() to produce ResolvedPolicy
9
+ * - Applies precedence: template defaults -> methodology.overrides -> explicit gates.* -> CLI flags
10
+ *
11
+ * @module resolve-policy
12
+ */
13
+ import { z } from 'zod';
14
+ /**
15
+ * Testing methodology options
16
+ */
17
+ export const TESTING_METHODOLOGY = {
18
+ TDD: 'tdd',
19
+ TEST_AFTER: 'test-after',
20
+ NONE: 'none',
21
+ };
22
+ /**
23
+ * Architecture methodology options
24
+ */
25
+ export const ARCHITECTURE_METHODOLOGY = {
26
+ HEXAGONAL: 'hexagonal',
27
+ LAYERED: 'layered',
28
+ NONE: 'none',
29
+ };
30
+ /**
31
+ * Coverage mode options
32
+ */
33
+ export const COVERAGE_MODE = {
34
+ BLOCK: 'block',
35
+ WARN: 'warn',
36
+ OFF: 'off',
37
+ };
38
+ /**
39
+ * Zod schema for testing methodology enum
40
+ */
41
+ export const TestingMethodologySchema = z.enum(['tdd', 'test-after', 'none']);
42
+ /**
43
+ * Zod schema for architecture methodology enum
44
+ */
45
+ export const ArchitectureMethodologySchema = z.enum(['hexagonal', 'layered', 'none']);
46
+ /**
47
+ * Zod schema for coverage mode enum
48
+ */
49
+ export const CoverageModeSchema = z.enum(['block', 'warn', 'off']);
50
+ /**
51
+ * Methodology overrides schema
52
+ *
53
+ * These allow tweaking template defaults without changing methodology.
54
+ */
55
+ export const MethodologyOverridesSchema = z.object({
56
+ /** Override the default coverage threshold from the testing methodology */
57
+ coverage_threshold: z.number().min(0).max(100).optional(),
58
+ /** Override the default coverage mode from the testing methodology */
59
+ coverage_mode: CoverageModeSchema.optional(),
60
+ });
61
+ /**
62
+ * Main methodology configuration schema
63
+ *
64
+ * Config example in .lumenflow.config.yaml:
65
+ * ```yaml
66
+ * methodology:
67
+ * testing: 'tdd' # tdd | test-after | none
68
+ * architecture: 'hexagonal' # hexagonal | layered | none
69
+ * overrides:
70
+ * coverage_threshold: 85 # Override TDD's default 90%
71
+ * coverage_mode: 'warn' # Override TDD's default 'block'
72
+ * ```
73
+ */
74
+ export const MethodologyConfigSchema = z.object({
75
+ /** Testing methodology (default: 'tdd') */
76
+ testing: TestingMethodologySchema.default('tdd'),
77
+ /** Architecture methodology (default: 'hexagonal') */
78
+ architecture: ArchitectureMethodologySchema.default('hexagonal'),
79
+ /** Optional overrides for template defaults */
80
+ overrides: MethodologyOverridesSchema.optional(),
81
+ });
82
+ const TESTING_TEMPLATE_DEFAULTS = {
83
+ tdd: {
84
+ coverage_threshold: 90,
85
+ coverage_mode: 'block',
86
+ tests_required: true,
87
+ },
88
+ 'test-after': {
89
+ coverage_threshold: 70,
90
+ coverage_mode: 'warn',
91
+ tests_required: true,
92
+ },
93
+ none: {
94
+ coverage_threshold: 0,
95
+ coverage_mode: 'off',
96
+ tests_required: false,
97
+ },
98
+ };
99
+ /**
100
+ * Resolve the effective policy from configuration
101
+ *
102
+ * Precedence (highest to lowest):
103
+ * 1. CLI flags (not handled here - handled by command layer)
104
+ * 2. Explicit gates.* configuration (only if rawConfig provided to detect explicit vs default)
105
+ * 3. methodology.overrides
106
+ * 4. methodology template defaults
107
+ *
108
+ * This ensures backwards compatibility: existing users with explicit
109
+ * gates.* config see no change, while new users can use methodology
110
+ * config for a higher-level abstraction.
111
+ *
112
+ * @param config - The full LumenFlow configuration
113
+ * @param options - Options including rawConfig for explicit detection
114
+ * @returns The resolved policy for use by wu:spawn and gates
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * import { getConfig } from './lumenflow-config.js';
119
+ * import { resolvePolicy } from './resolve-policy.js';
120
+ *
121
+ * const config = getConfig();
122
+ * const policy = resolvePolicy(config);
123
+ *
124
+ * console.log(policy.coverage_threshold); // 90 (or configured value)
125
+ * console.log(policy.testing); // 'tdd' (or configured value)
126
+ * ```
127
+ *
128
+ * @example With raw config for explicit detection
129
+ * ```typescript
130
+ * const rawConfig = { methodology: { testing: 'test-after' } };
131
+ * const config = parseConfig(rawConfig);
132
+ * const policy = resolvePolicy(config, { rawConfig });
133
+ * // policy.coverage_threshold will be 70 (test-after template default)
134
+ * // because gates.minCoverage wasn't EXPLICITLY set
135
+ * ```
136
+ */
137
+ export function resolvePolicy(config, options = {}) {
138
+ const { rawConfig } = options;
139
+ // Parse methodology config (provides defaults if not specified)
140
+ const methodology = MethodologyConfigSchema.parse(config.methodology ?? {});
141
+ // Get template defaults based on testing methodology
142
+ const templateDefaults = TESTING_TEMPLATE_DEFAULTS[methodology.testing];
143
+ // Layer 1: Start with template defaults
144
+ let coverage_threshold = templateDefaults.coverage_threshold;
145
+ let coverage_mode = templateDefaults.coverage_mode;
146
+ const tests_required = templateDefaults.tests_required;
147
+ // Layer 2: Apply methodology.overrides (if specified)
148
+ if (methodology.overrides?.coverage_threshold !== undefined) {
149
+ coverage_threshold = methodology.overrides.coverage_threshold;
150
+ }
151
+ if (methodology.overrides?.coverage_mode !== undefined) {
152
+ coverage_mode = methodology.overrides.coverage_mode;
153
+ }
154
+ // Layer 3: Apply explicit gates.* configuration (highest precedence)
155
+ // This ensures backwards compatibility with existing gates config
156
+ //
157
+ // Key insight: We only want EXPLICIT gates.* to override methodology.
158
+ // If rawConfig is provided, we check if gates values were explicitly set.
159
+ // If rawConfig is NOT provided (legacy mode), we check if methodology
160
+ // was specified - if so, methodology controls unless gates differ from default.
161
+ const gates = config.gates;
162
+ // Determine if gates.minCoverage was explicitly set
163
+ const gatesMinCoverageExplicit = rawConfig !== undefined ? rawConfig.gates?.minCoverage !== undefined : false;
164
+ // Determine if gates.enableCoverage was explicitly set
165
+ const gatesEnableCoverageExplicit = rawConfig !== undefined ? rawConfig.gates?.enableCoverage !== undefined : false;
166
+ // Apply gates.minCoverage only if explicitly set, or if no methodology was specified
167
+ // (for backwards compatibility with pre-methodology configs)
168
+ const methodologySpecified = config.methodology !== undefined;
169
+ if (gatesMinCoverageExplicit || (!methodologySpecified && !rawConfig)) {
170
+ // gates.minCoverage overrides methodology coverage_threshold
171
+ if (gates?.minCoverage !== undefined) {
172
+ coverage_threshold = gates.minCoverage;
173
+ }
174
+ }
175
+ // gates.enableCoverage: false effectively sets coverage_mode to 'off'
176
+ if (gatesEnableCoverageExplicit || (!methodologySpecified && !rawConfig)) {
177
+ if (gates?.enableCoverage === false) {
178
+ coverage_mode = 'off';
179
+ }
180
+ }
181
+ return {
182
+ testing: methodology.testing,
183
+ architecture: methodology.architecture,
184
+ coverage_threshold,
185
+ coverage_mode,
186
+ tests_required,
187
+ };
188
+ }
189
+ /**
190
+ * Create a default resolved policy
191
+ *
192
+ * Convenience function for when no config is available.
193
+ * Returns strict TDD defaults.
194
+ */
195
+ export function getDefaultPolicy() {
196
+ return {
197
+ testing: 'tdd',
198
+ architecture: 'hexagonal',
199
+ coverage_threshold: 90,
200
+ coverage_mode: 'block',
201
+ tests_required: true,
202
+ };
203
+ }
@@ -15,8 +15,8 @@
15
15
  * healthcare domain (PHI, RLS, auth). No standard library exists for this
16
16
  * domain-specific classification.
17
17
  *
18
- * @see {@link tools/gates.mjs} - Consumer of risk detection
19
- * @see {@link tools/lib/file-classifiers.mjs} - File classification utilities
18
+ * @see {@link packages/@lumenflow/cli/src/gates.ts} - Consumer of risk detection
19
+ * @see {@link packages/@lumenflow/cli/src/lib/file-classifiers.ts} - File classification utilities
20
20
  */
21
21
  /**
22
22
  * Risk tier constants