@lumenflow/core 2.2.2 → 2.3.1

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
@@ -28,6 +28,7 @@ import { TEST_TYPES, LOG_PREFIX, EMOJI } from './wu-constants.js';
28
28
  import { BaseWUSchema } from './wu-schema.js';
29
29
  // WU-1810: Import fixer to detect fixable issues
30
30
  import { detectFixableIssues, FIXABLE_ISSUES } from './wu-yaml-fixer.js';
31
+ import fg from 'fast-glob';
31
32
  /**
32
33
  * Result structure for preflight validation
33
34
  * @typedef {object} PreflightResult
@@ -44,14 +45,16 @@ import { detectFixableIssues, FIXABLE_ISSUES } from './wu-yaml-fixer.js';
44
45
  * @param {string[]} [params.errors=[]] - Error messages
45
46
  * @param {string[]} [params.missingCodePaths=[]] - Missing code paths
46
47
  * @param {string[]} [params.missingTestPaths=[]] - Missing test paths
48
+ * @param {Record<string, string[]>} [params.suggestedTestPaths={}] - Suggested test paths
47
49
  * @returns {PreflightResult}
48
50
  */
49
- export function createPreflightResult({ valid, errors = [], missingCodePaths = [], missingTestPaths = [], }) {
51
+ export function createPreflightResult({ valid, errors = [], missingCodePaths = [], missingTestPaths = [], suggestedTestPaths = {}, }) {
50
52
  return {
51
53
  valid,
52
54
  errors,
53
55
  missingCodePaths,
54
56
  missingTestPaths,
57
+ suggestedTestPaths,
55
58
  };
56
59
  }
57
60
  /**
@@ -209,11 +212,23 @@ export async function validatePreflight(id, options = {}) {
209
212
  allErrors.push(...testPathsResult.errors);
210
213
  missingTestPaths.push(...testPathsResult.missing);
211
214
  }
215
+ // Step 5 (WU-1154): Generate suggestions for missing test paths
216
+ let suggestedTestPaths = {};
217
+ if (missingTestPaths.length > 0) {
218
+ const searchRoot = worktreePath || rootDir;
219
+ try {
220
+ suggestedTestPaths = await findSuggestedTestPaths(missingTestPaths, searchRoot);
221
+ }
222
+ catch (err) {
223
+ process.env.DEBUG && console.log(`[wu-preflight] Failed to find suggestions: ${err.message}`);
224
+ }
225
+ }
212
226
  return createPreflightResult({
213
227
  valid: allErrors.length === 0,
214
228
  errors: allErrors,
215
229
  missingCodePaths,
216
230
  missingTestPaths,
231
+ suggestedTestPaths,
217
232
  });
218
233
  }
219
234
  /**
@@ -249,3 +264,43 @@ export function formatPreflightResult(id, result) {
249
264
  }
250
265
  // Export PreflightResult type for documentation
251
266
  export const PreflightResult = {};
267
+ /**
268
+ * Find suggested paths for missing test files
269
+ *
270
+ * @param {string[]} missingPaths - List of missing test paths
271
+ * @param {string} rootDir - Root directory to search in
272
+ * @returns {Promise<Record<string, string[]>>} Map of missing path -> suggestions
273
+ */
274
+ export async function findSuggestedTestPaths(missingPaths, rootDir) {
275
+ const suggestions = {};
276
+ if (missingPaths.length === 0)
277
+ return suggestions;
278
+ // Cache strict searches to avoid re-reading fs
279
+ const globOptions = {
280
+ cwd: rootDir,
281
+ caseSensitiveMatch: false,
282
+ limit: 5,
283
+ ignore: ['**/node_modules/**'],
284
+ };
285
+ for (const missingPath of missingPaths) {
286
+ const filename = path.basename(missingPath);
287
+ const basename = path.basename(filename, path.extname(filename));
288
+ const cleanBasename = basename.replace(/(\.test|\.spec)$/, '');
289
+ // Strategy 1: Search for exact filename elsewhere
290
+ let matches = await fg(`**/${filename}`, globOptions);
291
+ // Strategy 2: Search for filename with different extension (ts/js/mjs)
292
+ if (matches.length === 0) {
293
+ matches = await fg(`**/${basename}.{ts,js,mjs,tsx,jsx}`, globOptions);
294
+ }
295
+ // Strategy 3: Search for fuzzy match on basename (without .test/.spec)
296
+ if (matches.length === 0) {
297
+ // Look for the code file the test might be for
298
+ matches = await fg(`**/${cleanBasename}.{ts,js,mjs,tsx,jsx}`, globOptions);
299
+ }
300
+ if (matches.length > 0) {
301
+ // Filter out the missing path itself if it somehow showed up
302
+ suggestions[missingPath] = matches.filter((m) => m !== missingPath);
303
+ }
304
+ }
305
+ return suggestions;
306
+ }
@@ -11,8 +11,8 @@
11
11
  * Recovery mode is idempotent - safe to run multiple times
12
12
  *
13
13
  * NOTE (WU-1826): Core recovery functions are now re-exported from
14
- * tools/lib/wu-repair-core.mjs for use by the unified wu:repair command.
15
- * This module remains the canonical implementation used by wu-done.mjs.
14
+ * tools/lib/wu-repair-core.ts for use by the unified wu:repair command.
15
+ * This module remains the canonical implementation used by wu-done.ts.
16
16
  */
17
17
  /**
18
18
  * WU-1335: Maximum number of recovery attempts before escalating to manual intervention
@@ -11,8 +11,8 @@
11
11
  * Recovery mode is idempotent - safe to run multiple times
12
12
  *
13
13
  * NOTE (WU-1826): Core recovery functions are now re-exported from
14
- * tools/lib/wu-repair-core.mjs for use by the unified wu:repair command.
15
- * This module remains the canonical implementation used by wu-done.mjs.
14
+ * tools/lib/wu-repair-core.ts for use by the unified wu:repair command.
15
+ * This module remains the canonical implementation used by wu-done.ts.
16
16
  */
17
17
  import { existsSync, readFileSync, unlinkSync, writeFileSync, mkdirSync } from 'node:fs';
18
18
  import { join, isAbsolute } from 'node:path';
@@ -221,7 +221,7 @@ export function resetWorktreeYAMLForRecovery({ worktreePath, id, doc }) {
221
221
  console.log(`${LOG_PREFIX.DONE} ${EMOJI.SUCCESS} Reset worktree YAML to in_progress for recovery`);
222
222
  return { reset: true };
223
223
  }
224
- // Note: updateBacklogMd removed (WU-1163) - now uses shared moveWUToDoneBacklog from wu-backlog-updater.mjs
224
+ // Note: updateBacklogMd removed (WU-1163) - now uses shared moveWUToDoneBacklog from wu-backlog-updater.ts
225
225
  /**
226
226
  * Recover from zombie state
227
227
  *
@@ -299,7 +299,7 @@ export async function recoverZombieState({ id, doc, _worktreePath, _args }) {
299
299
  console.log(RECOVERY.COMMITTING);
300
300
  try {
301
301
  await git.add([stampPath, wuPath, statusPath, backlogPath]);
302
- // WU-1383: Set recovery mode env var to bypass stamp existence check in validate.mjs
302
+ // WU-1383: Set recovery mode env var to bypass stamp existence check in validate.ts
303
303
  // During recovery, stamp and status=done are committed atomically, but pre-commit
304
304
  // hooks run mid-commit when both files are staged but validation sees inconsistent state
305
305
  process.env.WU_RECOVERY_ID = id;
@@ -7,12 +7,12 @@
7
7
  * - Admin repair (--admin mode): administrative fixes for done WUs
8
8
  *
9
9
  * This module consolidates logic from:
10
- * - wu-consistency-checker.mjs (consistency checks)
11
- * - wu-repair-claim.mjs (claim metadata repair)
12
- * - wu-admin-repair.mjs (admin fixes)
13
- * - wu-recovery.mjs (zombie state recovery)
10
+ * - wu-consistency-checker.ts (consistency checks)
11
+ * - wu-repair-claim.ts (claim metadata repair)
12
+ * - wu-admin-repair.ts (admin fixes)
13
+ * - wu-recovery.ts (zombie state recovery)
14
14
  *
15
- * @see {@link ../wu-repair.mjs} - Unified CLI interface
15
+ * @see {@link ../wu-repair.ts} - Unified CLI interface
16
16
  */
17
17
  import { checkWUConsistency, checkAllWUConsistency, repairWUInconsistency } from './wu-consistency-checker.js';
18
18
  export { checkWUConsistency, checkAllWUConsistency, repairWUInconsistency };
@@ -7,12 +7,12 @@
7
7
  * - Admin repair (--admin mode): administrative fixes for done WUs
8
8
  *
9
9
  * This module consolidates logic from:
10
- * - wu-consistency-checker.mjs (consistency checks)
11
- * - wu-repair-claim.mjs (claim metadata repair)
12
- * - wu-admin-repair.mjs (admin fixes)
13
- * - wu-recovery.mjs (zombie state recovery)
10
+ * - wu-consistency-checker.ts (consistency checks)
11
+ * - wu-repair-claim.ts (claim metadata repair)
12
+ * - wu-admin-repair.ts (admin fixes)
13
+ * - wu-recovery.ts (zombie state recovery)
14
14
  *
15
- * @see {@link ../wu-repair.mjs} - Unified CLI interface
15
+ * @see {@link ../wu-repair.ts} - Unified CLI interface
16
16
  */
17
17
  import path from 'node:path';
18
18
  import { existsSync, writeFileSync, appendFileSync, mkdirSync, readFileSync } from 'node:fs';
@@ -29,7 +29,7 @@ import { validateLaneFormat } from './lane-checker.js';
29
29
  import { normalizeToDateString } from './date-utils.js';
30
30
  // Re-export for backwards compatibility
31
31
  export { checkWUConsistency, checkAllWUConsistency, repairWUInconsistency };
32
- // Re-export recovery utilities from wu-recovery.mjs
32
+ // Re-export recovery utilities from wu-recovery.ts
33
33
  export { detectZombieState, recoverZombieState, resetWorktreeYAMLForRecovery, getRecoveryMarkerPath, getRecoveryAttemptCount, incrementRecoveryAttempt, clearRecoveryAttempts, shouldEscalateToManualIntervention, MAX_RECOVERY_ATTEMPTS, } from './wu-recovery.js';
34
34
  const PREFIX = LOG_PREFIX.REPAIR;
35
35
  // ============================================================================
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @file wu-schema-normalization.mjs
2
+ * @file wu-schema-normalization.ts
3
3
  * @description Schema normalization for legacy WU YAML formats (WU-2004)
4
4
  *
5
5
  * Handles migration of legacy fields to current schema:
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @file wu-schema-normalization.mjs
2
+ * @file wu-schema-normalization.ts
3
3
  * @description Schema normalization for legacy WU YAML formats (WU-2004)
4
4
  *
5
5
  * Handles migration of legacy fields to current schema:
@@ -12,11 +12,11 @@
12
12
  * - WUSchema: Extends base + placeholder rejection (for wu:claim, wu:done)
13
13
  * - ReadyWUSchema: Alias for BaseWUSchema (for wu:create, wu:edit)
14
14
  *
15
- * @see {@link tools/wu-done.mjs} - Consumer (validates spec completeness, uses WUSchema)
16
- * @see {@link tools/wu-claim.mjs} - Consumer (validates spec completeness, uses WUSchema)
17
- * @see {@link tools/wu-create.mjs} - Consumer (structural validation, uses ReadyWUSchema)
18
- * @see {@link tools/wu-edit.mjs} - Consumer (structural validation, uses ReadyWUSchema)
19
- * @see {@link tools/validate.mjs} - Consumer (CI validation)
15
+ * @see {@link packages/@lumenflow/cli/src/wu-done.ts} - Consumer (validates spec completeness, uses WUSchema)
16
+ * @see {@link packages/@lumenflow/cli/src/wu-claim.ts} - Consumer (validates spec completeness, uses WUSchema)
17
+ * @see {@link packages/@lumenflow/cli/src/wu-create.ts} - Consumer (structural validation, uses ReadyWUSchema)
18
+ * @see {@link packages/@lumenflow/cli/src/wu-edit.ts} - Consumer (structural validation, uses ReadyWUSchema)
19
+ * @see {@link packages/@lumenflow/cli/src/validate.ts} - Consumer (CI validation)
20
20
  * @see {@link apps/web/src/lib/llm/schemas/orchestrator.ts} - Pattern reference
21
21
  */
22
22
  import { z } from 'zod';
@@ -27,11 +27,11 @@ import { z } from 'zod';
27
27
  * Single source of truth for placeholder detection (DRY principle).
28
28
  *
29
29
  * @example
30
- * // tools/wu-create.mjs
30
+ * // tools/wu-create.ts
31
31
  * description: `${PLACEHOLDER_SENTINEL} Describe the work...`
32
32
  *
33
33
  * @example
34
- * // tools/validate.mjs
34
+ * // tools/validate.ts
35
35
  * if (doc.description.includes(PLACEHOLDER_SENTINEL)) { error(); }
36
36
  */
37
37
  export declare const PLACEHOLDER_SENTINEL = "[PLACEHOLDER]";
package/dist/wu-schema.js CHANGED
@@ -12,11 +12,11 @@
12
12
  * - WUSchema: Extends base + placeholder rejection (for wu:claim, wu:done)
13
13
  * - ReadyWUSchema: Alias for BaseWUSchema (for wu:create, wu:edit)
14
14
  *
15
- * @see {@link tools/wu-done.mjs} - Consumer (validates spec completeness, uses WUSchema)
16
- * @see {@link tools/wu-claim.mjs} - Consumer (validates spec completeness, uses WUSchema)
17
- * @see {@link tools/wu-create.mjs} - Consumer (structural validation, uses ReadyWUSchema)
18
- * @see {@link tools/wu-edit.mjs} - Consumer (structural validation, uses ReadyWUSchema)
19
- * @see {@link tools/validate.mjs} - Consumer (CI validation)
15
+ * @see {@link packages/@lumenflow/cli/src/wu-done.ts} - Consumer (validates spec completeness, uses WUSchema)
16
+ * @see {@link packages/@lumenflow/cli/src/wu-claim.ts} - Consumer (validates spec completeness, uses WUSchema)
17
+ * @see {@link packages/@lumenflow/cli/src/wu-create.ts} - Consumer (structural validation, uses ReadyWUSchema)
18
+ * @see {@link packages/@lumenflow/cli/src/wu-edit.ts} - Consumer (structural validation, uses ReadyWUSchema)
19
+ * @see {@link packages/@lumenflow/cli/src/validate.ts} - Consumer (CI validation)
20
20
  * @see {@link apps/web/src/lib/llm/schemas/orchestrator.ts} - Pattern reference
21
21
  */
22
22
  import { z } from 'zod';
@@ -48,11 +48,11 @@ const VALID_STATUSES = [
48
48
  * Single source of truth for placeholder detection (DRY principle).
49
49
  *
50
50
  * @example
51
- * // tools/wu-create.mjs
51
+ * // tools/wu-create.ts
52
52
  * description: `${PLACEHOLDER_SENTINEL} Describe the work...`
53
53
  *
54
54
  * @example
55
- * // tools/validate.mjs
55
+ * // tools/validate.ts
56
56
  * if (doc.description.includes(PLACEHOLDER_SENTINEL)) { error(); }
57
57
  */
58
58
  export const PLACEHOLDER_SENTINEL = '[PLACEHOLDER]';
@@ -86,7 +86,7 @@ const NEWLINE_PATTERN = /\\n|\n/;
86
86
  * This transform auto-repairs: ["a\nb\nc"] → ["a", "b", "c"]
87
87
  *
88
88
  * @example
89
- * // Input: ["tools/a.mjs\ntools/b.js"]
89
+ * // Input: ["tools/a.ts\ntools/b.js"]
90
90
  * // Output: ["tools/a.js", "tools/b.js"]
91
91
  */
92
92
  const normalizedStringArray = z.array(z.string()).transform((arr) => arr
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Memory Context Integration for wu:spawn (WU-1240, WU-1287)
3
+ *
4
+ * Thin wrapper that delegates to @lumenflow/memory's generateContext function.
5
+ * Provides spawn-specific formatting (## Memory Context header) while leveraging
6
+ * the full feature set of mem-context-core (lane filter, recency, decay).
7
+ *
8
+ * WU-1287: Refactored to eliminate duplicate logic. Now delegates to
9
+ * mem-context-core.generateContext for all memory context generation,
10
+ * ensuring spawn prompts benefit from lane filtering, recency limits,
11
+ * and decay/prioritization features.
12
+ *
13
+ * Features:
14
+ * - Detects memory layer initialization (memory.jsonl existence)
15
+ * - Delegates to mem-context-core for context generation
16
+ * - Respects lane filter, recency limits, decay/prioritization from mem-context-core
17
+ * - Configurable max context size (default 4KB, from .lumenflow.config.yaml)
18
+ * - Graceful skip when memory not initialized or @lumenflow/memory unavailable
19
+ * - No LLM calls (vendor-agnostic)
20
+ *
21
+ * @see {@link packages/@lumenflow/memory/src/mem-context-core.ts} - Core context generation
22
+ */
23
+ import type { LumenFlowConfig } from './lumenflow-config-schema.js';
24
+ /**
25
+ * Section header for memory context in spawn prompts
26
+ */
27
+ export declare const MEMORY_CONTEXT_SECTION_HEADER = "## Memory Context";
28
+ /**
29
+ * Options for generating memory context
30
+ */
31
+ export interface GenerateMemoryContextOptions {
32
+ /** WU ID to filter context for */
33
+ wuId: string;
34
+ /** Lane to filter context for (WU-1281: enables lane-specific filtering) */
35
+ lane?: string;
36
+ /** Maximum size of context block in bytes (default: 4096) */
37
+ maxSize?: number;
38
+ /** WU-1238: Sort by decay score instead of recency (default: false) */
39
+ sortByDecay?: boolean;
40
+ /** WU-1238: Track access for included nodes (default: false) */
41
+ trackAccess?: boolean;
42
+ /** WU-1281: Maximum number of recent summaries to include (default: 5) */
43
+ maxRecentSummaries?: number;
44
+ /** WU-1281: Maximum number of project nodes to include (default: 10) */
45
+ maxProjectNodes?: number;
46
+ }
47
+ /**
48
+ * Checks if the memory layer is initialized.
49
+ *
50
+ * The memory layer is considered initialized when:
51
+ * 1. The .lumenflow/memory directory exists
52
+ * 2. memory.jsonl file exists and is non-empty
53
+ *
54
+ * @param baseDir - Project root directory
55
+ * @returns true if memory layer is initialized, false otherwise
56
+ */
57
+ export declare function checkMemoryLayerInitialized(baseDir: string): Promise<boolean>;
58
+ /**
59
+ * Gets the maximum context size from config or returns default.
60
+ *
61
+ * Reads from config.memory.spawn_context_max_size, defaulting to 4KB.
62
+ *
63
+ * @param config - LumenFlow configuration object
64
+ * @returns Maximum context size in bytes
65
+ */
66
+ export declare function getMemoryContextMaxSize(config: Partial<LumenFlowConfig>): number;
67
+ /**
68
+ * Generates the Memory Context section for wu:spawn prompts.
69
+ *
70
+ * WU-1287: Delegates to mem-context-core.generateContext for all context
71
+ * generation logic, ensuring spawn prompts benefit from:
72
+ * - Lane filtering (WU-1281)
73
+ * - Recency limits (WU-1281)
74
+ * - Decay-based prioritization (WU-1238)
75
+ * - WU-specific content prioritization (WU-1281)
76
+ *
77
+ * Context includes (via mem-context-core):
78
+ * 1. WU-specific context (checkpoints, notes matching wu_id) - high priority
79
+ * 2. Summaries relevant to the WU
80
+ * 3. Discoveries related to the WU
81
+ * 4. Project profile items (lifecycle=project memories) - lower priority, may be truncated
82
+ *
83
+ * @param baseDir - Project root directory
84
+ * @param options - Generation options (wuId, lane, maxSize, etc.)
85
+ * @returns Formatted Memory Context section, or empty string if no context
86
+ */
87
+ export declare function generateMemoryContextSection(baseDir: string, options: GenerateMemoryContextOptions): Promise<string>;
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Memory Context Integration for wu:spawn (WU-1240, WU-1287)
3
+ *
4
+ * Thin wrapper that delegates to @lumenflow/memory's generateContext function.
5
+ * Provides spawn-specific formatting (## Memory Context header) while leveraging
6
+ * the full feature set of mem-context-core (lane filter, recency, decay).
7
+ *
8
+ * WU-1287: Refactored to eliminate duplicate logic. Now delegates to
9
+ * mem-context-core.generateContext for all memory context generation,
10
+ * ensuring spawn prompts benefit from lane filtering, recency limits,
11
+ * and decay/prioritization features.
12
+ *
13
+ * Features:
14
+ * - Detects memory layer initialization (memory.jsonl existence)
15
+ * - Delegates to mem-context-core for context generation
16
+ * - Respects lane filter, recency limits, decay/prioritization from mem-context-core
17
+ * - Configurable max context size (default 4KB, from .lumenflow.config.yaml)
18
+ * - Graceful skip when memory not initialized or @lumenflow/memory unavailable
19
+ * - No LLM calls (vendor-agnostic)
20
+ *
21
+ * @see {@link packages/@lumenflow/memory/src/mem-context-core.ts} - Core context generation
22
+ */
23
+ import { existsSync, statSync } from 'node:fs';
24
+ import path from 'node:path';
25
+ /**
26
+ * Default maximum context size in bytes (4KB)
27
+ */
28
+ const DEFAULT_MAX_SIZE = 4096;
29
+ /**
30
+ * Memory layer paths
31
+ */
32
+ const MEMORY_PATHS = {
33
+ MEMORY_DIR: '.lumenflow/memory',
34
+ MEMORY_FILE: 'memory.jsonl',
35
+ };
36
+ /**
37
+ * Section header for memory context in spawn prompts
38
+ */
39
+ export const MEMORY_CONTEXT_SECTION_HEADER = '## Memory Context';
40
+ /**
41
+ * Checks if the memory layer is initialized.
42
+ *
43
+ * The memory layer is considered initialized when:
44
+ * 1. The .lumenflow/memory directory exists
45
+ * 2. memory.jsonl file exists and is non-empty
46
+ *
47
+ * @param baseDir - Project root directory
48
+ * @returns true if memory layer is initialized, false otherwise
49
+ */
50
+ export async function checkMemoryLayerInitialized(baseDir) {
51
+ const memoryFilePath = path.join(baseDir, MEMORY_PATHS.MEMORY_DIR, MEMORY_PATHS.MEMORY_FILE);
52
+ if (!existsSync(memoryFilePath)) {
53
+ return false;
54
+ }
55
+ try {
56
+ const stats = statSync(memoryFilePath);
57
+ return stats.size > 0;
58
+ }
59
+ catch {
60
+ return false;
61
+ }
62
+ }
63
+ /**
64
+ * Gets the maximum context size from config or returns default.
65
+ *
66
+ * Reads from config.memory.spawn_context_max_size, defaulting to 4KB.
67
+ *
68
+ * @param config - LumenFlow configuration object
69
+ * @returns Maximum context size in bytes
70
+ */
71
+ export function getMemoryContextMaxSize(config) {
72
+ const memoryConfig = config;
73
+ return memoryConfig?.memory?.spawn_context_max_size ?? DEFAULT_MAX_SIZE;
74
+ }
75
+ function hasGenerateContext(module) {
76
+ if (!module || typeof module !== 'object') {
77
+ return false;
78
+ }
79
+ const candidate = module;
80
+ return typeof candidate.generateContext === 'function';
81
+ }
82
+ /**
83
+ * Dynamically imports and calls generateContext from @lumenflow/memory.
84
+ *
85
+ * @param baseDir - Project root directory
86
+ * @param options - Generation options
87
+ * @returns Result from mem-context-core.generateContext, or null if unavailable
88
+ */
89
+ async function callMemContextCore(baseDir, options) {
90
+ try {
91
+ // Dynamic import of optional peer dependency
92
+ // Use a non-literal import to avoid compile-time dependency on optional peer
93
+ const memoryModuleName = '@lumenflow/memory';
94
+ const memModule = (await import(memoryModuleName));
95
+ if (!hasGenerateContext(memModule)) {
96
+ return null;
97
+ }
98
+ return await memModule.generateContext(baseDir, options);
99
+ }
100
+ catch {
101
+ // @lumenflow/memory not available - return null for graceful degradation
102
+ return null;
103
+ }
104
+ }
105
+ /**
106
+ * Converts mem-context-core output format to spawn prompt format.
107
+ *
108
+ * mem-context-core uses "## Section" headers, but spawn prompts expect
109
+ * "### Section" for subsections under "## Memory Context".
110
+ *
111
+ * @param contextBlock - Raw context block from mem-context-core
112
+ * @param wuId - WU ID for the intro line
113
+ * @returns Formatted context with spawn-specific header structure
114
+ */
115
+ function formatForSpawnPrompt(contextBlock, wuId) {
116
+ if (!contextBlock || contextBlock.trim() === '') {
117
+ return '';
118
+ }
119
+ // Remove the mem:context header comment if present
120
+ let content = contextBlock.replace(/^<!--\s*mem:context[^>]*-->\s*\n*/m, '');
121
+ // Convert ## headers to ### for subsection nesting under ## Memory Context
122
+ content = content.replace(/^## /gm, '### ');
123
+ // Build the full Memory Context section with spawn-specific formatting
124
+ const header = `${MEMORY_CONTEXT_SECTION_HEADER}\n\n`;
125
+ const intro = `Prior context from memory layer for ${wuId}:\n\n`;
126
+ return header + intro + content.trim() + '\n';
127
+ }
128
+ /**
129
+ * Generates the Memory Context section for wu:spawn prompts.
130
+ *
131
+ * WU-1287: Delegates to mem-context-core.generateContext for all context
132
+ * generation logic, ensuring spawn prompts benefit from:
133
+ * - Lane filtering (WU-1281)
134
+ * - Recency limits (WU-1281)
135
+ * - Decay-based prioritization (WU-1238)
136
+ * - WU-specific content prioritization (WU-1281)
137
+ *
138
+ * Context includes (via mem-context-core):
139
+ * 1. WU-specific context (checkpoints, notes matching wu_id) - high priority
140
+ * 2. Summaries relevant to the WU
141
+ * 3. Discoveries related to the WU
142
+ * 4. Project profile items (lifecycle=project memories) - lower priority, may be truncated
143
+ *
144
+ * @param baseDir - Project root directory
145
+ * @param options - Generation options (wuId, lane, maxSize, etc.)
146
+ * @returns Formatted Memory Context section, or empty string if no context
147
+ */
148
+ export async function generateMemoryContextSection(baseDir, options) {
149
+ const { wuId, lane, maxSize = DEFAULT_MAX_SIZE, sortByDecay = false, trackAccess = false, maxRecentSummaries, maxProjectNodes, } = options;
150
+ // Check if memory layer is initialized
151
+ const isInitialized = await checkMemoryLayerInitialized(baseDir);
152
+ if (!isInitialized) {
153
+ return '';
154
+ }
155
+ // Delegate to mem-context-core.generateContext
156
+ const result = await callMemContextCore(baseDir, {
157
+ wuId,
158
+ maxSize,
159
+ sortByDecay,
160
+ trackAccess,
161
+ lane,
162
+ maxRecentSummaries,
163
+ maxProjectNodes,
164
+ });
165
+ // Graceful degradation if @lumenflow/memory is not available
166
+ if (!result) {
167
+ return '';
168
+ }
169
+ // If no context was generated, return empty
170
+ if (!result.success || result.stats.totalNodes === 0) {
171
+ return '';
172
+ }
173
+ // Format for spawn prompt
174
+ return formatForSpawnPrompt(result.contextBlock, wuId);
175
+ }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @file wu-spawn-helpers.mjs
2
+ * @file wu-spawn-helpers.ts
3
3
  * Helper functions for wu:spawn thinking mode and model configuration (WU-1577)
4
4
  *
5
5
  * Provides:
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @file wu-spawn-helpers.mjs
2
+ * @file wu-spawn-helpers.ts
3
3
  * Helper functions for wu:spawn thinking mode and model configuration (WU-1577)
4
4
  *
5
5
  * Provides: