@lumenflow/mcp 2.21.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/LICENSE +661 -190
  2. package/dist/mcp-constants.d.ts +173 -0
  3. package/dist/mcp-constants.d.ts.map +1 -0
  4. package/dist/mcp-constants.js +191 -0
  5. package/dist/mcp-constants.js.map +1 -0
  6. package/dist/runtime-cache.d.ts +7 -0
  7. package/dist/runtime-cache.d.ts.map +1 -0
  8. package/dist/runtime-cache.js +26 -0
  9. package/dist/runtime-cache.js.map +1 -0
  10. package/dist/runtime-tool-resolver.constants.d.ts +33 -0
  11. package/dist/runtime-tool-resolver.constants.d.ts.map +1 -0
  12. package/dist/runtime-tool-resolver.constants.js +33 -0
  13. package/dist/runtime-tool-resolver.constants.js.map +1 -0
  14. package/dist/runtime-tool-resolver.d.ts +5 -0
  15. package/dist/runtime-tool-resolver.d.ts.map +1 -0
  16. package/dist/runtime-tool-resolver.js +2028 -0
  17. package/dist/runtime-tool-resolver.js.map +1 -0
  18. package/dist/server.d.ts.map +1 -1
  19. package/dist/server.js +30 -4
  20. package/dist/server.js.map +1 -1
  21. package/dist/tools/agent-tools.d.ts +1 -0
  22. package/dist/tools/agent-tools.d.ts.map +1 -1
  23. package/dist/tools/agent-tools.js +113 -41
  24. package/dist/tools/agent-tools.js.map +1 -1
  25. package/dist/tools/context-tools.d.ts +2 -1
  26. package/dist/tools/context-tools.d.ts.map +1 -1
  27. package/dist/tools/context-tools.js +23 -40
  28. package/dist/tools/context-tools.js.map +1 -1
  29. package/dist/tools/flow-tools.d.ts +1 -0
  30. package/dist/tools/flow-tools.d.ts.map +1 -1
  31. package/dist/tools/flow-tools.js +51 -64
  32. package/dist/tools/flow-tools.js.map +1 -1
  33. package/dist/tools/initiative-tools.d.ts.map +1 -1
  34. package/dist/tools/initiative-tools.js +198 -84
  35. package/dist/tools/initiative-tools.js.map +1 -1
  36. package/dist/tools/memory-tools.d.ts +2 -0
  37. package/dist/tools/memory-tools.d.ts.map +1 -1
  38. package/dist/tools/memory-tools.js +268 -166
  39. package/dist/tools/memory-tools.js.map +1 -1
  40. package/dist/tools/orchestration-tools.d.ts.map +1 -1
  41. package/dist/tools/orchestration-tools.js +99 -57
  42. package/dist/tools/orchestration-tools.js.map +1 -1
  43. package/dist/tools/parity-tools.d.ts +12 -0
  44. package/dist/tools/parity-tools.d.ts.map +1 -1
  45. package/dist/tools/parity-tools.js +776 -193
  46. package/dist/tools/parity-tools.js.map +1 -1
  47. package/dist/tools/runtime-task-constants.d.ts +19 -0
  48. package/dist/tools/runtime-task-constants.d.ts.map +1 -0
  49. package/dist/tools/runtime-task-constants.js +19 -0
  50. package/dist/tools/runtime-task-constants.js.map +1 -0
  51. package/dist/tools/runtime-task-tools.d.ts +10 -0
  52. package/dist/tools/runtime-task-tools.d.ts.map +1 -0
  53. package/dist/tools/runtime-task-tools.js +114 -0
  54. package/dist/tools/runtime-task-tools.js.map +1 -0
  55. package/dist/tools/setup-tools.d.ts +1 -0
  56. package/dist/tools/setup-tools.d.ts.map +1 -1
  57. package/dist/tools/setup-tools.js +150 -65
  58. package/dist/tools/setup-tools.js.map +1 -1
  59. package/dist/tools/validation-tools.d.ts +2 -0
  60. package/dist/tools/validation-tools.d.ts.map +1 -1
  61. package/dist/tools/validation-tools.js +98 -54
  62. package/dist/tools/validation-tools.js.map +1 -1
  63. package/dist/tools/wu-tools.d.ts +1 -1
  64. package/dist/tools/wu-tools.d.ts.map +1 -1
  65. package/dist/tools/wu-tools.js +444 -250
  66. package/dist/tools/wu-tools.js.map +1 -1
  67. package/dist/tools-shared.d.ts +81 -1
  68. package/dist/tools-shared.d.ts.map +1 -1
  69. package/dist/tools-shared.js +199 -1
  70. package/dist/tools-shared.js.map +1 -1
  71. package/dist/tools.d.ts +28 -2
  72. package/dist/tools.d.ts.map +1 -1
  73. package/dist/tools.js +59 -3
  74. package/dist/tools.js.map +1 -1
  75. package/dist/worktree-enforcement.d.ts +47 -0
  76. package/dist/worktree-enforcement.d.ts.map +1 -0
  77. package/dist/worktree-enforcement.js +152 -0
  78. package/dist/worktree-enforcement.js.map +1 -0
  79. package/package.json +5 -2
@@ -12,12 +12,74 @@ import { z } from 'zod';
12
12
  import { wuCreateSchema, wuClaimSchema, wuStatusSchema, wuDoneSchema, gatesSchema,
13
13
  // WU-1454: Lifecycle command schemas
14
14
  wuBlockSchema, wuUnblockSchema, wuEditSchema, wuReleaseSchema, wuRecoverSchema, wuRepairSchema, wuDepsSchema, wuPrepSchema, wuPreflightSchema, wuPruneSchema, wuDeleteSchema, wuCleanupSchema, wuSpawnSchema, wuValidateSchema, wuInferLaneSchema, wuUnlockLaneSchema, } from '@lumenflow/core';
15
- import { ErrorCodes, ErrorMessages, CliArgs, SuccessMessages, getCore, success, error, buildWuPromptArgs, runCliCommand, } from '../tools-shared.js';
15
+ import { ErrorCodes, ErrorMessages, CliArgs, SuccessMessages, getCore, success, error, buildWuPromptArgs, executeViaPack, } from '../tools-shared.js';
16
+ import { CliCommands, MetadataKeys } from '../mcp-constants.js';
17
+ /**
18
+ * WU-1805: Fallback messages for WU query tools when executeViaPack
19
+ * returns no structured data.
20
+ */
21
+ const WuQueryMessages = {
22
+ STATUS_FAILED: 'wu:status failed',
23
+ CREATE_PASSED: 'WU created successfully',
24
+ CREATE_FAILED: 'wu:create failed',
25
+ CLAIM_PASSED: 'WU claimed successfully',
26
+ CLAIM_FAILED: 'wu:claim failed',
27
+ DEPS_FAILED: 'wu:deps failed',
28
+ PREFLIGHT_PASSED: 'Preflight checks passed',
29
+ PREFLIGHT_FAILED: 'wu:preflight failed',
30
+ VALIDATE_PASSED: 'WU is valid',
31
+ VALIDATE_FAILED: 'wu:validate failed',
32
+ INFER_LANE_FAILED: 'wu:infer-lane failed',
33
+ };
34
+ const WuStateTransitionMessages = {
35
+ BLOCK_PASSED: 'WU blocked successfully',
36
+ BLOCK_FAILED: 'wu:block failed',
37
+ UNBLOCK_PASSED: 'WU unblocked successfully',
38
+ UNBLOCK_FAILED: 'wu:unblock failed',
39
+ EDIT_PASSED: 'WU edited successfully',
40
+ EDIT_FAILED: 'wu:edit failed',
41
+ RELEASE_PASSED: 'WU released successfully',
42
+ RELEASE_FAILED: 'wu:release failed',
43
+ };
44
+ const WuCompletionLifecycleMessages = {
45
+ SANDBOX_PASSED: 'WU sandbox command completed successfully',
46
+ SANDBOX_FAILED: 'wu:sandbox failed',
47
+ DONE_PASSED: 'WU completed successfully',
48
+ DONE_FAILED: 'wu:done failed',
49
+ PREP_PASSED: 'WU prep completed',
50
+ PREP_FAILED: 'wu:prep failed',
51
+ PRUNE_PASSED: 'Prune completed',
52
+ PRUNE_FAILED: 'wu:prune failed',
53
+ DELETE_PASSED: 'WU deleted',
54
+ DELETE_FAILED: 'wu:delete failed',
55
+ CLEANUP_PASSED: 'Cleanup complete',
56
+ CLEANUP_FAILED: 'wu:cleanup failed',
57
+ };
58
+ const WuDelegationAndGatesMessages = {
59
+ GATES_FAILED: 'Gates failed',
60
+ BRIEF_PASSED: 'Brief prompt generated',
61
+ BRIEF_FAILED: 'wu:brief failed',
62
+ DELEGATE_PASSED: 'Delegation prompt generated',
63
+ DELEGATE_FAILED: 'wu:delegate failed',
64
+ UNLOCK_PASSED: 'Lane unlocked',
65
+ UNLOCK_FAILED: 'wu:unlock-lane failed',
66
+ };
67
+ const GatesRuntimeConstants = {
68
+ FALLBACK_TIMEOUT_MS: 600000,
69
+ };
70
+ const WuQueryFlags = {
71
+ NO_STRICT: '--no-strict',
72
+ WORKTREE: '--worktree',
73
+ DEPTH: '--depth',
74
+ DIRECTION: '--direction',
75
+ PATHS: '--paths',
76
+ DESC: '--desc',
77
+ };
16
78
  /**
17
79
  * wu_status - Get status of a specific WU
18
- * Uses CLI shell-out for consistency
19
80
  *
20
81
  * WU-1431: Uses shared wuStatusSchema for parity with CLI
82
+ * WU-1805: Migrated from CLI shell-out to executeViaPack (runtime-first)
21
83
  * Note: CLI allows id to be optional (auto-detect from worktree), but MCP requires it
22
84
  * since there's no "current directory" concept for MCP clients
23
85
  */
@@ -32,21 +94,18 @@ export const wuStatusTool = {
32
94
  if (!input.id) {
33
95
  return error(ErrorMessages.ID_REQUIRED, ErrorCodes.MISSING_PARAMETER);
34
96
  }
35
- const args = ['--id', input.id, '--json'];
36
- const cliOptions = { projectRoot: options?.projectRoot };
37
- const result = await runCliCommand('wu:status', args, cliOptions);
38
- if (result.success) {
39
- try {
40
- const data = JSON.parse(result.stdout);
41
- return success(data);
42
- }
43
- catch {
44
- return success({ message: result.stdout });
45
- }
46
- }
47
- else {
48
- return error(result.stderr || result.error?.message || 'wu:status failed', ErrorCodes.WU_STATUS_ERROR);
49
- }
97
+ const args = [CliArgs.ID, input.id, CliArgs.JSON];
98
+ const result = await executeViaPack(CliCommands.WU_STATUS, input, {
99
+ projectRoot: options?.projectRoot,
100
+ fallback: {
101
+ command: CliCommands.WU_STATUS,
102
+ args,
103
+ errorCode: ErrorCodes.WU_STATUS_ERROR,
104
+ },
105
+ });
106
+ return result.success
107
+ ? success(result.data ?? { message: result.data })
108
+ : error(result.error?.message ?? WuQueryMessages.STATUS_FAILED, ErrorCodes.WU_STATUS_ERROR);
50
109
  },
51
110
  };
52
111
  /**
@@ -66,9 +125,9 @@ export const wuCreateTool = {
66
125
  if (!input.title) {
67
126
  return error(ErrorMessages.TITLE_REQUIRED, ErrorCodes.MISSING_PARAMETER);
68
127
  }
69
- const args = ['--lane', input.lane, '--title', input.title];
128
+ const args = [CliArgs.LANE, input.lane, '--title', input.title];
70
129
  if (input.id)
71
- args.push('--id', input.id);
130
+ args.push(CliArgs.ID, input.id);
72
131
  if (input.description)
73
132
  args.push(CliArgs.DESCRIPTION, input.description);
74
133
  if (input.acceptance) {
@@ -83,14 +142,22 @@ export const wuCreateTool = {
83
142
  }
84
143
  if (input.exposure)
85
144
  args.push('--exposure', input.exposure);
86
- const cliOptions = { projectRoot: options?.projectRoot };
87
- const result = await runCliCommand('wu:create', args, cliOptions);
88
- if (result.success) {
89
- return success({ message: result.stdout || 'WU created successfully' });
90
- }
91
- else {
92
- return error(result.stderr || result.error?.message || 'wu:create failed', ErrorCodes.WU_CREATE_ERROR);
93
- }
145
+ const result = await executeViaPack(CliCommands.WU_CREATE, input, {
146
+ projectRoot: options?.projectRoot,
147
+ contextInput: {
148
+ metadata: {
149
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
150
+ },
151
+ },
152
+ fallback: {
153
+ command: CliCommands.WU_CREATE,
154
+ args,
155
+ errorCode: ErrorCodes.WU_CREATE_ERROR,
156
+ },
157
+ });
158
+ return result.success
159
+ ? success(result.data ?? { message: WuQueryMessages.CREATE_PASSED })
160
+ : error(result.error?.message ?? WuQueryMessages.CREATE_FAILED, ErrorCodes.WU_CREATE_ERROR);
94
161
  },
95
162
  };
96
163
  /**
@@ -121,7 +188,7 @@ export const wuClaimTool = {
121
188
  if (!input.lane) {
122
189
  return error(ErrorMessages.LANE_REQUIRED, ErrorCodes.MISSING_PARAMETER);
123
190
  }
124
- const args = ['--id', input.id, '--lane', input.lane];
191
+ const args = [CliArgs.ID, input.id, CliArgs.LANE, input.lane];
125
192
  // WU-1491: Pass mode flags through to CLI
126
193
  if (input.cloud)
127
194
  args.push('--cloud');
@@ -138,14 +205,22 @@ export const wuClaimTool = {
138
205
  }
139
206
  args.push('--sandbox', '--', ...sandboxCommand);
140
207
  }
141
- const cliOptions = { projectRoot: options?.projectRoot };
142
- const result = await runCliCommand('wu:claim', args, cliOptions);
143
- if (result.success) {
144
- return success({ message: result.stdout || 'WU claimed successfully' });
145
- }
146
- else {
147
- return error(result.stderr || result.error?.message || 'wu:claim failed', ErrorCodes.WU_CLAIM_ERROR);
148
- }
208
+ const result = await executeViaPack(CliCommands.WU_CLAIM, input, {
209
+ projectRoot: options?.projectRoot,
210
+ contextInput: {
211
+ metadata: {
212
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
213
+ },
214
+ },
215
+ fallback: {
216
+ command: CliCommands.WU_CLAIM,
217
+ args,
218
+ errorCode: ErrorCodes.WU_CLAIM_ERROR,
219
+ },
220
+ });
221
+ return result.success
222
+ ? success(result.data ?? { message: WuQueryMessages.CLAIM_PASSED })
223
+ : error(result.error?.message ?? WuQueryMessages.CLAIM_FAILED, ErrorCodes.WU_CLAIM_ERROR);
149
224
  },
150
225
  };
151
226
  /**
@@ -171,19 +246,27 @@ export const wuSandboxTool = {
171
246
  if (command.length === 0) {
172
247
  return error('command is required', ErrorCodes.MISSING_PARAMETER);
173
248
  }
174
- const args = ['--id', input.id];
249
+ const args = [CliArgs.ID, input.id];
175
250
  if (input.worktree) {
176
251
  args.push('--worktree', input.worktree);
177
252
  }
178
253
  args.push('--', ...command);
179
- const cliOptions = { projectRoot: options?.projectRoot };
180
- const result = await runCliCommand('wu:sandbox', args, cliOptions);
181
- if (result.success) {
182
- return success({ message: result.stdout || 'WU sandbox command completed successfully' });
183
- }
184
- else {
185
- return error(result.stderr || result.error?.message || 'wu:sandbox failed', ErrorCodes.WU_CLAIM_ERROR);
186
- }
254
+ const result = await executeViaPack(CliCommands.WU_SANDBOX, input, {
255
+ projectRoot: options?.projectRoot,
256
+ contextInput: {
257
+ metadata: {
258
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
259
+ },
260
+ },
261
+ fallback: {
262
+ command: CliCommands.WU_SANDBOX,
263
+ args,
264
+ errorCode: ErrorCodes.WU_CLAIM_ERROR,
265
+ },
266
+ });
267
+ return result.success
268
+ ? success(result.data ?? { message: WuCompletionLifecycleMessages.SANDBOX_PASSED })
269
+ : error(result.error?.message ?? WuCompletionLifecycleMessages.SANDBOX_FAILED, ErrorCodes.WU_CLAIM_ERROR);
187
270
  },
188
271
  };
189
272
  /**
@@ -214,22 +297,30 @@ export const wuDoneTool = {
214
297
  catch {
215
298
  // If we can't determine context, proceed anyway - CLI will validate
216
299
  }
217
- const args = ['--id', input.id];
300
+ const args = [CliArgs.ID, input.id];
218
301
  if (input.skip_gates) {
219
302
  args.push('--skip-gates');
220
303
  if (input.reason)
221
- args.push('--reason', input.reason);
304
+ args.push(CliArgs.REASON, input.reason);
222
305
  if (input.fix_wu)
223
306
  args.push('--fix-wu', input.fix_wu);
224
307
  }
225
- const cliOptions = { projectRoot: options?.projectRoot };
226
- const result = await runCliCommand('wu:done', args, cliOptions);
227
- if (result.success) {
228
- return success({ message: result.stdout || 'WU completed successfully' });
229
- }
230
- else {
231
- return error(result.stderr || result.error?.message || 'wu:done failed', ErrorCodes.WU_DONE_ERROR);
232
- }
308
+ const result = await executeViaPack(CliCommands.WU_DONE, input, {
309
+ projectRoot: options?.projectRoot,
310
+ contextInput: {
311
+ metadata: {
312
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
313
+ },
314
+ },
315
+ fallback: {
316
+ command: CliCommands.WU_DONE,
317
+ args,
318
+ errorCode: ErrorCodes.WU_DONE_ERROR,
319
+ },
320
+ });
321
+ return result.success
322
+ ? success(result.data ?? { message: WuCompletionLifecycleMessages.DONE_PASSED })
323
+ : error(result.error?.message ?? WuCompletionLifecycleMessages.DONE_FAILED, ErrorCodes.WU_DONE_ERROR);
233
324
  },
234
325
  };
235
326
  /**
@@ -247,17 +338,25 @@ export const gatesRunTool = {
247
338
  if (input.docs_only) {
248
339
  args.push(CliArgs.DOCS_ONLY);
249
340
  }
250
- const cliOptions = {
341
+ const result = await executeViaPack(CliCommands.GATES, input, {
251
342
  projectRoot: options?.projectRoot,
252
- timeout: 600000, // 10 minutes for gates
253
- };
254
- const result = await runCliCommand('gates', args, cliOptions);
255
- if (result.success) {
256
- return success({ message: result.stdout || SuccessMessages.ALL_GATES_PASSED });
257
- }
258
- else {
259
- return error(result.stderr || result.error?.message || 'Gates failed', ErrorCodes.GATES_ERROR);
260
- }
343
+ contextInput: {
344
+ metadata: {
345
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
346
+ },
347
+ },
348
+ fallback: {
349
+ command: CliCommands.GATES,
350
+ args,
351
+ errorCode: ErrorCodes.GATES_ERROR,
352
+ },
353
+ fallbackCliOptions: {
354
+ timeout: GatesRuntimeConstants.FALLBACK_TIMEOUT_MS,
355
+ },
356
+ });
357
+ return result.success
358
+ ? success(result.data ?? { message: SuccessMessages.ALL_GATES_PASSED })
359
+ : error(result.error?.message ?? WuDelegationAndGatesMessages.GATES_FAILED, ErrorCodes.GATES_ERROR);
261
360
  },
262
361
  };
263
362
  /**
@@ -275,18 +374,26 @@ export const wuBlockTool = {
275
374
  if (!input.reason) {
276
375
  return error(ErrorMessages.REASON_REQUIRED, ErrorCodes.MISSING_PARAMETER);
277
376
  }
278
- const args = ['--id', input.id, '--reason', input.reason];
377
+ const args = [CliArgs.ID, input.id, CliArgs.REASON, input.reason];
279
378
  if (input.remove_worktree) {
280
379
  args.push('--remove-worktree');
281
380
  }
282
- const cliOptions = { projectRoot: options?.projectRoot };
283
- const result = await runCliCommand('wu:block', args, cliOptions);
284
- if (result.success) {
285
- return success({ message: result.stdout || 'WU blocked successfully' });
286
- }
287
- else {
288
- return error(result.stderr || result.error?.message || 'wu:block failed', ErrorCodes.WU_BLOCK_ERROR);
289
- }
381
+ const result = await executeViaPack(CliCommands.WU_BLOCK, input, {
382
+ projectRoot: options?.projectRoot,
383
+ contextInput: {
384
+ metadata: {
385
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
386
+ },
387
+ },
388
+ fallback: {
389
+ command: CliCommands.WU_BLOCK,
390
+ args,
391
+ errorCode: ErrorCodes.WU_BLOCK_ERROR,
392
+ },
393
+ });
394
+ return result.success
395
+ ? success(result.data ?? { message: WuStateTransitionMessages.BLOCK_PASSED })
396
+ : error(result.error?.message ?? WuStateTransitionMessages.BLOCK_FAILED, ErrorCodes.WU_BLOCK_ERROR);
290
397
  },
291
398
  };
292
399
  /**
@@ -301,19 +408,27 @@ export const wuUnblockTool = {
301
408
  if (!input.id) {
302
409
  return error(ErrorMessages.ID_REQUIRED, ErrorCodes.MISSING_PARAMETER);
303
410
  }
304
- const args = ['--id', input.id];
411
+ const args = [CliArgs.ID, input.id];
305
412
  if (input.reason)
306
- args.push('--reason', input.reason);
413
+ args.push(CliArgs.REASON, input.reason);
307
414
  if (input.create_worktree)
308
415
  args.push('--create-worktree');
309
- const cliOptions = { projectRoot: options?.projectRoot };
310
- const result = await runCliCommand('wu:unblock', args, cliOptions);
311
- if (result.success) {
312
- return success({ message: result.stdout || 'WU unblocked successfully' });
313
- }
314
- else {
315
- return error(result.stderr || result.error?.message || 'wu:unblock failed', ErrorCodes.WU_UNBLOCK_ERROR);
316
- }
416
+ const result = await executeViaPack(CliCommands.WU_UNBLOCK, input, {
417
+ projectRoot: options?.projectRoot,
418
+ contextInput: {
419
+ metadata: {
420
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
421
+ },
422
+ },
423
+ fallback: {
424
+ command: CliCommands.WU_UNBLOCK,
425
+ args,
426
+ errorCode: ErrorCodes.WU_UNBLOCK_ERROR,
427
+ },
428
+ });
429
+ return result.success
430
+ ? success(result.data ?? { message: WuStateTransitionMessages.UNBLOCK_PASSED })
431
+ : error(result.error?.message ?? WuStateTransitionMessages.UNBLOCK_FAILED, ErrorCodes.WU_UNBLOCK_ERROR);
317
432
  },
318
433
  };
319
434
  /**
@@ -328,7 +443,7 @@ export const wuEditTool = {
328
443
  if (!input.id) {
329
444
  return error(ErrorMessages.ID_REQUIRED, ErrorCodes.MISSING_PARAMETER);
330
445
  }
331
- const args = ['--id', input.id];
446
+ const args = [CliArgs.ID, input.id];
332
447
  if (input.description)
333
448
  args.push(CliArgs.DESCRIPTION, input.description);
334
449
  if (input.acceptance) {
@@ -344,7 +459,7 @@ export const wuEditTool = {
344
459
  }
345
460
  }
346
461
  if (input.lane)
347
- args.push('--lane', input.lane);
462
+ args.push(CliArgs.LANE, input.lane);
348
463
  if (input.priority)
349
464
  args.push('--priority', input.priority);
350
465
  if (input.initiative)
@@ -353,14 +468,22 @@ export const wuEditTool = {
353
468
  args.push(CliArgs.PHASE, String(input.phase));
354
469
  if (input.no_strict)
355
470
  args.push('--no-strict');
356
- const cliOptions = { projectRoot: options?.projectRoot };
357
- const result = await runCliCommand('wu:edit', args, cliOptions);
358
- if (result.success) {
359
- return success({ message: result.stdout || 'WU edited successfully' });
360
- }
361
- else {
362
- return error(result.stderr || result.error?.message || 'wu:edit failed', ErrorCodes.WU_EDIT_ERROR);
363
- }
471
+ const result = await executeViaPack(CliCommands.WU_EDIT, input, {
472
+ projectRoot: options?.projectRoot,
473
+ contextInput: {
474
+ metadata: {
475
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
476
+ },
477
+ },
478
+ fallback: {
479
+ command: CliCommands.WU_EDIT,
480
+ args,
481
+ errorCode: ErrorCodes.WU_EDIT_ERROR,
482
+ },
483
+ });
484
+ return result.success
485
+ ? success(result.data ?? { message: WuStateTransitionMessages.EDIT_PASSED })
486
+ : error(result.error?.message ?? WuStateTransitionMessages.EDIT_FAILED, ErrorCodes.WU_EDIT_ERROR);
364
487
  },
365
488
  };
366
489
  /**
@@ -375,17 +498,25 @@ export const wuReleaseTool = {
375
498
  if (!input.id) {
376
499
  return error(ErrorMessages.ID_REQUIRED, ErrorCodes.MISSING_PARAMETER);
377
500
  }
378
- const args = ['--id', input.id];
501
+ const args = [CliArgs.ID, input.id];
379
502
  if (input.reason)
380
- args.push('--reason', input.reason);
381
- const cliOptions = { projectRoot: options?.projectRoot };
382
- const result = await runCliCommand('wu:release', args, cliOptions);
383
- if (result.success) {
384
- return success({ message: result.stdout || 'WU released successfully' });
385
- }
386
- else {
387
- return error(result.stderr || result.error?.message || 'wu:release failed', ErrorCodes.WU_RELEASE_ERROR);
388
- }
503
+ args.push(CliArgs.REASON, input.reason);
504
+ const result = await executeViaPack(CliCommands.WU_RELEASE, input, {
505
+ projectRoot: options?.projectRoot,
506
+ contextInput: {
507
+ metadata: {
508
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
509
+ },
510
+ },
511
+ fallback: {
512
+ command: CliCommands.WU_RELEASE,
513
+ args,
514
+ errorCode: ErrorCodes.WU_RELEASE_ERROR,
515
+ },
516
+ });
517
+ return result.success
518
+ ? success(result.data ?? { message: WuStateTransitionMessages.RELEASE_PASSED })
519
+ : error(result.error?.message ?? WuStateTransitionMessages.RELEASE_FAILED, ErrorCodes.WU_RELEASE_ERROR);
389
520
  },
390
521
  };
391
522
  /**
@@ -400,27 +531,29 @@ export const wuRecoverTool = {
400
531
  if (!input.id) {
401
532
  return error(ErrorMessages.ID_REQUIRED, ErrorCodes.MISSING_PARAMETER);
402
533
  }
403
- const args = ['--id', input.id];
534
+ const args = [CliArgs.ID, input.id];
404
535
  if (input.action)
405
536
  args.push('--action', input.action);
406
537
  if (input.force)
407
- args.push('--force');
538
+ args.push(CliArgs.FORCE);
408
539
  if (input.json)
409
540
  args.push(CliArgs.JSON);
410
- const cliOptions = { projectRoot: options?.projectRoot };
411
- const result = await runCliCommand('wu:recover', args, cliOptions);
412
- if (result.success) {
413
- try {
414
- const data = JSON.parse(result.stdout);
415
- return success(data);
416
- }
417
- catch {
418
- return success({ message: result.stdout || 'WU recovered successfully' });
419
- }
420
- }
421
- else {
422
- return error(result.stderr || result.error?.message || 'wu:recover failed', ErrorCodes.WU_RECOVER_ERROR);
423
- }
541
+ const result = await executeViaPack(CliCommands.WU_RECOVER, input, {
542
+ projectRoot: options?.projectRoot,
543
+ contextInput: {
544
+ metadata: {
545
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
546
+ },
547
+ },
548
+ fallback: {
549
+ command: CliCommands.WU_RECOVER,
550
+ args,
551
+ errorCode: ErrorCodes.WU_RECOVER_ERROR,
552
+ },
553
+ });
554
+ return result.success
555
+ ? success(result.data ?? { message: 'WU recovered successfully' })
556
+ : error(result.error?.message ?? 'wu:recover failed', ErrorCodes.WU_RECOVER_ERROR);
424
557
  },
425
558
  };
426
559
  /**
@@ -434,7 +567,7 @@ export const wuRepairTool = {
434
567
  async execute(input, options) {
435
568
  const args = [];
436
569
  if (input.id)
437
- args.push('--id', input.id);
570
+ args.push(CliArgs.ID, input.id);
438
571
  if (input.check)
439
572
  args.push('--check');
440
573
  if (input.all)
@@ -445,14 +578,22 @@ export const wuRepairTool = {
445
578
  args.push('--admin');
446
579
  if (input.repair_state)
447
580
  args.push('--repair-state');
448
- const cliOptions = { projectRoot: options?.projectRoot };
449
- const result = await runCliCommand('wu:repair', args, cliOptions);
450
- if (result.success) {
451
- return success({ message: result.stdout || 'WU repair completed' });
452
- }
453
- else {
454
- return error(result.stderr || result.error?.message || 'wu:repair failed', ErrorCodes.WU_REPAIR_ERROR);
455
- }
581
+ const result = await executeViaPack(CliCommands.WU_REPAIR, input, {
582
+ projectRoot: options?.projectRoot,
583
+ contextInput: {
584
+ metadata: {
585
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
586
+ },
587
+ },
588
+ fallback: {
589
+ command: CliCommands.WU_REPAIR,
590
+ args,
591
+ errorCode: ErrorCodes.WU_REPAIR_ERROR,
592
+ },
593
+ });
594
+ return result.success
595
+ ? success(result.data ?? { message: 'WU repair completed' })
596
+ : error(result.error?.message ?? 'wu:repair failed', ErrorCodes.WU_REPAIR_ERROR);
456
597
  },
457
598
  };
458
599
  /**
@@ -467,27 +608,24 @@ export const wuDepsTool = {
467
608
  if (!input.id) {
468
609
  return error(ErrorMessages.ID_REQUIRED, ErrorCodes.MISSING_PARAMETER);
469
610
  }
470
- const args = ['--id', input.id];
611
+ const args = [CliArgs.ID, input.id];
471
612
  if (input.format)
472
- args.push('--format', input.format);
613
+ args.push(CliArgs.FORMAT, input.format);
473
614
  if (input.depth)
474
- args.push('--depth', String(input.depth));
615
+ args.push(WuQueryFlags.DEPTH, String(input.depth));
475
616
  if (input.direction)
476
- args.push('--direction', input.direction);
477
- const cliOptions = { projectRoot: options?.projectRoot };
478
- const result = await runCliCommand('wu:deps', args, cliOptions);
479
- if (result.success) {
480
- try {
481
- const data = JSON.parse(result.stdout);
482
- return success(data);
483
- }
484
- catch {
485
- return success({ message: result.stdout });
486
- }
487
- }
488
- else {
489
- return error(result.stderr || result.error?.message || 'wu:deps failed', ErrorCodes.WU_DEPS_ERROR);
490
- }
617
+ args.push(WuQueryFlags.DIRECTION, input.direction);
618
+ const result = await executeViaPack(CliCommands.WU_DEPS, input, {
619
+ projectRoot: options?.projectRoot,
620
+ fallback: {
621
+ command: CliCommands.WU_DEPS,
622
+ args,
623
+ errorCode: ErrorCodes.WU_DEPS_ERROR,
624
+ },
625
+ });
626
+ return result.success
627
+ ? success(result.data ?? { message: result.data })
628
+ : error(result.error?.message ?? WuQueryMessages.DEPS_FAILED, ErrorCodes.WU_DEPS_ERROR);
491
629
  },
492
630
  };
493
631
  /**
@@ -502,22 +640,27 @@ export const wuPrepTool = {
502
640
  if (!input.id) {
503
641
  return error(ErrorMessages.ID_REQUIRED, ErrorCodes.MISSING_PARAMETER);
504
642
  }
505
- const args = ['--id', input.id];
643
+ const args = [CliArgs.ID, input.id];
506
644
  if (input.docs_only)
507
645
  args.push(CliArgs.DOCS_ONLY);
508
646
  if (input.full_tests)
509
647
  args.push('--full-tests');
510
- const cliOptions = {
648
+ const result = await executeViaPack(CliCommands.WU_PREP, input, {
511
649
  projectRoot: options?.projectRoot,
512
- timeout: 600000, // 10 minutes for gates
513
- };
514
- const result = await runCliCommand('wu:prep', args, cliOptions);
515
- if (result.success) {
516
- return success({ message: result.stdout || 'WU prep completed' });
517
- }
518
- else {
519
- return error(result.stderr || result.error?.message || 'wu:prep failed', ErrorCodes.WU_PREP_ERROR);
520
- }
650
+ contextInput: {
651
+ metadata: {
652
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
653
+ },
654
+ },
655
+ fallback: {
656
+ command: CliCommands.WU_PREP,
657
+ args,
658
+ errorCode: ErrorCodes.WU_PREP_ERROR,
659
+ },
660
+ });
661
+ return result.success
662
+ ? success(result.data ?? { message: WuCompletionLifecycleMessages.PREP_PASSED })
663
+ : error(result.error?.message ?? WuCompletionLifecycleMessages.PREP_FAILED, ErrorCodes.WU_PREP_ERROR);
521
664
  },
522
665
  };
523
666
  /**
@@ -532,17 +675,20 @@ export const wuPreflightTool = {
532
675
  if (!input.id) {
533
676
  return error(ErrorMessages.ID_REQUIRED, ErrorCodes.MISSING_PARAMETER);
534
677
  }
535
- const args = ['--id', input.id];
678
+ const args = [CliArgs.ID, input.id];
536
679
  if (input.worktree)
537
- args.push('--worktree', input.worktree);
538
- const cliOptions = { projectRoot: options?.projectRoot };
539
- const result = await runCliCommand('wu:preflight', args, cliOptions);
540
- if (result.success) {
541
- return success({ message: result.stdout || 'Preflight checks passed' });
542
- }
543
- else {
544
- return error(result.stderr || result.error?.message || 'wu:preflight failed', ErrorCodes.WU_PREFLIGHT_ERROR);
545
- }
680
+ args.push(WuQueryFlags.WORKTREE, input.worktree);
681
+ const result = await executeViaPack(CliCommands.WU_PREFLIGHT, input, {
682
+ projectRoot: options?.projectRoot,
683
+ fallback: {
684
+ command: CliCommands.WU_PREFLIGHT,
685
+ args,
686
+ errorCode: ErrorCodes.WU_PREFLIGHT_ERROR,
687
+ },
688
+ });
689
+ return result.success
690
+ ? success(result.data ?? { message: WuQueryMessages.PREFLIGHT_PASSED })
691
+ : error(result.error?.message ?? WuQueryMessages.PREFLIGHT_FAILED, ErrorCodes.WU_PREFLIGHT_ERROR);
546
692
  },
547
693
  };
548
694
  /**
@@ -556,15 +702,23 @@ export const wuPruneTool = {
556
702
  async execute(input, options) {
557
703
  const args = [];
558
704
  if (input.execute)
559
- args.push('--execute');
560
- const cliOptions = { projectRoot: options?.projectRoot };
561
- const result = await runCliCommand('wu:prune', args, cliOptions);
562
- if (result.success) {
563
- return success({ message: result.stdout || 'Prune completed' });
564
- }
565
- else {
566
- return error(result.stderr || result.error?.message || 'wu:prune failed', ErrorCodes.WU_PRUNE_ERROR);
567
- }
705
+ args.push(CliArgs.EXECUTE);
706
+ const result = await executeViaPack(CliCommands.WU_PRUNE, input, {
707
+ projectRoot: options?.projectRoot,
708
+ contextInput: {
709
+ metadata: {
710
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
711
+ },
712
+ },
713
+ fallback: {
714
+ command: CliCommands.WU_PRUNE,
715
+ args,
716
+ errorCode: ErrorCodes.WU_PRUNE_ERROR,
717
+ },
718
+ });
719
+ return result.success
720
+ ? success(result.data ?? { message: WuCompletionLifecycleMessages.PRUNE_PASSED })
721
+ : error(result.error?.message ?? WuCompletionLifecycleMessages.PRUNE_FAILED, ErrorCodes.WU_PRUNE_ERROR);
568
722
  },
569
723
  };
570
724
  /**
@@ -581,19 +735,27 @@ export const wuDeleteTool = {
581
735
  }
582
736
  const args = [];
583
737
  if (input.id)
584
- args.push('--id', input.id);
738
+ args.push(CliArgs.ID, input.id);
585
739
  if (input.dry_run)
586
740
  args.push(CliArgs.DRY_RUN);
587
741
  if (input.batch)
588
742
  args.push('--batch', input.batch);
589
- const cliOptions = { projectRoot: options?.projectRoot };
590
- const result = await runCliCommand('wu:delete', args, cliOptions);
591
- if (result.success) {
592
- return success({ message: result.stdout || 'WU deleted' });
593
- }
594
- else {
595
- return error(result.stderr || result.error?.message || 'wu:delete failed', ErrorCodes.WU_DELETE_ERROR);
596
- }
743
+ const result = await executeViaPack(CliCommands.WU_DELETE, input, {
744
+ projectRoot: options?.projectRoot,
745
+ contextInput: {
746
+ metadata: {
747
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
748
+ },
749
+ },
750
+ fallback: {
751
+ command: CliCommands.WU_DELETE,
752
+ args,
753
+ errorCode: ErrorCodes.WU_DELETE_ERROR,
754
+ },
755
+ });
756
+ return result.success
757
+ ? success(result.data ?? { message: WuCompletionLifecycleMessages.DELETE_PASSED })
758
+ : error(result.error?.message ?? WuCompletionLifecycleMessages.DELETE_FAILED, ErrorCodes.WU_DELETE_ERROR);
597
759
  },
598
760
  };
599
761
  /**
@@ -608,17 +770,25 @@ export const wuCleanupTool = {
608
770
  if (!input.id) {
609
771
  return error(ErrorMessages.ID_REQUIRED, ErrorCodes.MISSING_PARAMETER);
610
772
  }
611
- const args = ['--id', input.id];
773
+ const args = [CliArgs.ID, input.id];
612
774
  if (input.artifacts)
613
775
  args.push('--artifacts');
614
- const cliOptions = { projectRoot: options?.projectRoot };
615
- const result = await runCliCommand('wu:cleanup', args, cliOptions);
616
- if (result.success) {
617
- return success({ message: result.stdout || 'Cleanup complete' });
618
- }
619
- else {
620
- return error(result.stderr || result.error?.message || 'wu:cleanup failed', ErrorCodes.WU_CLEANUP_ERROR);
621
- }
776
+ const result = await executeViaPack(CliCommands.WU_CLEANUP, input, {
777
+ projectRoot: options?.projectRoot,
778
+ contextInput: {
779
+ metadata: {
780
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
781
+ },
782
+ },
783
+ fallback: {
784
+ command: CliCommands.WU_CLEANUP,
785
+ args,
786
+ errorCode: ErrorCodes.WU_CLEANUP_ERROR,
787
+ },
788
+ });
789
+ return result.success
790
+ ? success(result.data ?? { message: WuCompletionLifecycleMessages.CLEANUP_PASSED })
791
+ : error(result.error?.message ?? WuCompletionLifecycleMessages.CLEANUP_FAILED, ErrorCodes.WU_CLEANUP_ERROR);
622
792
  },
623
793
  };
624
794
  /**
@@ -636,14 +806,22 @@ export const wuBriefTool = {
636
806
  return error(ErrorMessages.ID_REQUIRED, ErrorCodes.MISSING_PARAMETER);
637
807
  }
638
808
  const args = buildWuPromptArgs(input);
639
- const cliOptions = { projectRoot: options?.projectRoot };
640
- const result = await runCliCommand('wu:brief', args, cliOptions);
641
- if (result.success) {
642
- return success({ message: result.stdout || 'Brief prompt generated' });
643
- }
644
- else {
645
- return error(result.stderr || result.error?.message || 'wu:brief failed', ErrorCodes.WU_BRIEF_ERROR);
646
- }
809
+ const result = await executeViaPack(CliCommands.WU_BRIEF, input, {
810
+ projectRoot: options?.projectRoot,
811
+ contextInput: {
812
+ metadata: {
813
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
814
+ },
815
+ },
816
+ fallback: {
817
+ command: CliCommands.WU_BRIEF,
818
+ args,
819
+ errorCode: ErrorCodes.WU_BRIEF_ERROR,
820
+ },
821
+ });
822
+ return result.success
823
+ ? success(result.data ?? { message: WuDelegationAndGatesMessages.BRIEF_PASSED })
824
+ : error(result.error?.message ?? WuDelegationAndGatesMessages.BRIEF_FAILED, ErrorCodes.WU_BRIEF_ERROR);
647
825
  },
648
826
  };
649
827
  /**
@@ -661,14 +839,22 @@ export const wuDelegateTool = {
661
839
  return error(ErrorMessages.PARENT_WU_REQUIRED, ErrorCodes.MISSING_PARAMETER);
662
840
  }
663
841
  const args = buildWuPromptArgs(input);
664
- const cliOptions = { projectRoot: options?.projectRoot };
665
- const result = await runCliCommand('wu:delegate', args, cliOptions);
666
- if (result.success) {
667
- return success({ message: result.stdout || 'Delegation prompt generated' });
668
- }
669
- else {
670
- return error(result.stderr || result.error?.message || 'wu:delegate failed', ErrorCodes.WU_DELEGATE_ERROR);
671
- }
842
+ const result = await executeViaPack(CliCommands.WU_DELEGATE, input, {
843
+ projectRoot: options?.projectRoot,
844
+ contextInput: {
845
+ metadata: {
846
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
847
+ },
848
+ },
849
+ fallback: {
850
+ command: CliCommands.WU_DELEGATE,
851
+ args,
852
+ errorCode: ErrorCodes.WU_DELEGATE_ERROR,
853
+ },
854
+ });
855
+ return result.success
856
+ ? success(result.data ?? { message: WuDelegationAndGatesMessages.DELEGATE_PASSED })
857
+ : error(result.error?.message ?? WuDelegationAndGatesMessages.DELEGATE_FAILED, ErrorCodes.WU_DELEGATE_ERROR);
672
858
  },
673
859
  };
674
860
  /**
@@ -683,17 +869,20 @@ export const wuValidateTool = {
683
869
  if (!input.id) {
684
870
  return error(ErrorMessages.ID_REQUIRED, ErrorCodes.MISSING_PARAMETER);
685
871
  }
686
- const args = ['--id', input.id];
872
+ const args = [CliArgs.ID, input.id];
687
873
  if (input.no_strict)
688
- args.push('--no-strict');
689
- const cliOptions = { projectRoot: options?.projectRoot };
690
- const result = await runCliCommand('wu:validate', args, cliOptions);
691
- if (result.success) {
692
- return success({ message: result.stdout || 'WU is valid' });
693
- }
694
- else {
695
- return error(result.stderr || result.error?.message || 'wu:validate failed', ErrorCodes.WU_VALIDATE_ERROR);
696
- }
874
+ args.push(WuQueryFlags.NO_STRICT);
875
+ const result = await executeViaPack(CliCommands.WU_VALIDATE, input, {
876
+ projectRoot: options?.projectRoot,
877
+ fallback: {
878
+ command: CliCommands.WU_VALIDATE,
879
+ args,
880
+ errorCode: ErrorCodes.WU_VALIDATE_ERROR,
881
+ },
882
+ });
883
+ return result.success
884
+ ? success(result.data ?? { message: WuQueryMessages.VALIDATE_PASSED })
885
+ : error(result.error?.message ?? WuQueryMessages.VALIDATE_FAILED, ErrorCodes.WU_VALIDATE_ERROR);
697
886
  },
698
887
  };
699
888
  /**
@@ -707,22 +896,25 @@ export const wuInferLaneTool = {
707
896
  async execute(input, options) {
708
897
  const args = [];
709
898
  if (input.id)
710
- args.push('--id', input.id);
899
+ args.push(CliArgs.ID, input.id);
711
900
  if (input.paths) {
712
901
  for (const p of input.paths) {
713
- args.push('--paths', p);
902
+ args.push(WuQueryFlags.PATHS, p);
714
903
  }
715
904
  }
716
905
  if (input.desc)
717
- args.push('--desc', input.desc);
718
- const cliOptions = { projectRoot: options?.projectRoot };
719
- const result = await runCliCommand('wu:infer-lane', args, cliOptions);
720
- if (result.success) {
721
- return success({ lane: result.stdout?.trim() || 'Unknown' });
722
- }
723
- else {
724
- return error(result.stderr || result.error?.message || 'wu:infer-lane failed', ErrorCodes.WU_INFER_LANE_ERROR);
725
- }
906
+ args.push(WuQueryFlags.DESC, input.desc);
907
+ const result = await executeViaPack(CliCommands.WU_INFER_LANE, input, {
908
+ projectRoot: options?.projectRoot,
909
+ fallback: {
910
+ command: CliCommands.WU_INFER_LANE,
911
+ args,
912
+ errorCode: ErrorCodes.WU_INFER_LANE_ERROR,
913
+ },
914
+ });
915
+ return result.success
916
+ ? success(result.data ?? { lane: 'Unknown' })
917
+ : error(result.error?.message ?? WuQueryMessages.INFER_LANE_FAILED, ErrorCodes.WU_INFER_LANE_ERROR);
726
918
  },
727
919
  };
728
920
  /**
@@ -740,29 +932,31 @@ export const wuUnlockLaneTool = {
740
932
  }
741
933
  const args = [];
742
934
  if (input.lane)
743
- args.push('--lane', input.lane);
935
+ args.push(CliArgs.LANE, input.lane);
744
936
  if (input.reason)
745
- args.push('--reason', input.reason);
937
+ args.push(CliArgs.REASON, input.reason);
746
938
  if (input.force)
747
- args.push('--force');
939
+ args.push(CliArgs.FORCE);
748
940
  if (input.list)
749
941
  args.push('--list');
750
942
  if (input.status)
751
- args.push('--status');
752
- const cliOptions = { projectRoot: options?.projectRoot };
753
- const result = await runCliCommand('wu:unlock-lane', args, cliOptions);
754
- if (result.success) {
755
- try {
756
- const data = JSON.parse(result.stdout);
757
- return success(data);
758
- }
759
- catch {
760
- return success({ message: result.stdout || 'Lane unlocked' });
761
- }
762
- }
763
- else {
764
- return error(result.stderr || result.error?.message || 'wu:unlock-lane failed', ErrorCodes.WU_UNLOCK_LANE_ERROR);
765
- }
943
+ args.push(CliArgs.STATUS);
944
+ const result = await executeViaPack(CliCommands.WU_UNLOCK_LANE, input, {
945
+ projectRoot: options?.projectRoot,
946
+ contextInput: {
947
+ metadata: {
948
+ [MetadataKeys.PROJECT_ROOT]: options?.projectRoot,
949
+ },
950
+ },
951
+ fallback: {
952
+ command: CliCommands.WU_UNLOCK_LANE,
953
+ args,
954
+ errorCode: ErrorCodes.WU_UNLOCK_LANE_ERROR,
955
+ },
956
+ });
957
+ return result.success
958
+ ? success(result.data ?? { message: WuDelegationAndGatesMessages.UNLOCK_PASSED })
959
+ : error(result.error?.message ?? WuDelegationAndGatesMessages.UNLOCK_FAILED, ErrorCodes.WU_UNLOCK_LANE_ERROR);
766
960
  },
767
961
  };
768
962
  //# sourceMappingURL=wu-tools.js.map