@vibescope/mcp-server 0.2.3 → 0.2.5

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 (117) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/README.md +194 -138
  3. package/dist/api-client.d.ts +276 -8
  4. package/dist/api-client.js +123 -8
  5. package/dist/cli.d.ts +6 -3
  6. package/dist/cli.js +28 -10
  7. package/dist/handlers/blockers.d.ts +11 -0
  8. package/dist/handlers/blockers.js +37 -2
  9. package/dist/handlers/bodies-of-work.d.ts +2 -0
  10. package/dist/handlers/bodies-of-work.js +30 -1
  11. package/dist/handlers/connectors.js +2 -2
  12. package/dist/handlers/decisions.d.ts +11 -0
  13. package/dist/handlers/decisions.js +37 -2
  14. package/dist/handlers/deployment.d.ts +6 -0
  15. package/dist/handlers/deployment.js +33 -5
  16. package/dist/handlers/discovery.js +27 -11
  17. package/dist/handlers/fallback.js +12 -6
  18. package/dist/handlers/file-checkouts.d.ts +1 -0
  19. package/dist/handlers/file-checkouts.js +17 -2
  20. package/dist/handlers/findings.d.ts +5 -0
  21. package/dist/handlers/findings.js +19 -2
  22. package/dist/handlers/git-issues.js +4 -2
  23. package/dist/handlers/ideas.d.ts +5 -0
  24. package/dist/handlers/ideas.js +19 -2
  25. package/dist/handlers/progress.js +2 -2
  26. package/dist/handlers/project.d.ts +1 -0
  27. package/dist/handlers/project.js +35 -2
  28. package/dist/handlers/requests.js +6 -3
  29. package/dist/handlers/roles.js +13 -2
  30. package/dist/handlers/session.d.ts +12 -0
  31. package/dist/handlers/session.js +288 -25
  32. package/dist/handlers/sprints.d.ts +2 -0
  33. package/dist/handlers/sprints.js +30 -1
  34. package/dist/handlers/tasks.d.ts +25 -2
  35. package/dist/handlers/tasks.js +228 -35
  36. package/dist/handlers/tool-docs.js +834 -767
  37. package/dist/index.js +73 -73
  38. package/dist/knowledge.d.ts +6 -0
  39. package/dist/knowledge.js +218 -0
  40. package/dist/setup.d.ts +22 -0
  41. package/dist/setup.js +313 -0
  42. package/dist/templates/agent-guidelines.d.ts +18 -0
  43. package/dist/templates/agent-guidelines.js +207 -0
  44. package/dist/tools.js +527 -174
  45. package/dist/utils.d.ts +5 -2
  46. package/dist/utils.js +101 -62
  47. package/docs/TOOLS.md +2053 -2053
  48. package/package.json +51 -46
  49. package/scripts/generate-docs.ts +212 -212
  50. package/scripts/version-bump.ts +203 -0
  51. package/src/api-client.test.ts +723 -723
  52. package/src/api-client.ts +2499 -2140
  53. package/src/cli.ts +27 -10
  54. package/src/handlers/__test-setup__.ts +236 -231
  55. package/src/handlers/__test-utils__.ts +87 -87
  56. package/src/handlers/blockers.test.ts +468 -392
  57. package/src/handlers/blockers.ts +163 -109
  58. package/src/handlers/bodies-of-work.test.ts +704 -704
  59. package/src/handlers/bodies-of-work.ts +526 -468
  60. package/src/handlers/connectors.test.ts +834 -834
  61. package/src/handlers/connectors.ts +229 -229
  62. package/src/handlers/cost.test.ts +462 -462
  63. package/src/handlers/cost.ts +285 -285
  64. package/src/handlers/decisions.test.ts +382 -313
  65. package/src/handlers/decisions.ts +153 -99
  66. package/src/handlers/deployment.test.ts +551 -470
  67. package/src/handlers/deployment.ts +541 -508
  68. package/src/handlers/discovery.test.ts +206 -206
  69. package/src/handlers/discovery.ts +390 -374
  70. package/src/handlers/fallback.test.ts +537 -536
  71. package/src/handlers/fallback.ts +194 -188
  72. package/src/handlers/file-checkouts.test.ts +750 -670
  73. package/src/handlers/file-checkouts.ts +185 -165
  74. package/src/handlers/findings.test.ts +633 -633
  75. package/src/handlers/findings.ts +239 -203
  76. package/src/handlers/git-issues.test.ts +631 -631
  77. package/src/handlers/git-issues.ts +136 -134
  78. package/src/handlers/ideas.test.ts +644 -644
  79. package/src/handlers/ideas.ts +207 -175
  80. package/src/handlers/index.ts +84 -84
  81. package/src/handlers/milestones.test.ts +475 -475
  82. package/src/handlers/milestones.ts +180 -180
  83. package/src/handlers/organizations.test.ts +826 -826
  84. package/src/handlers/organizations.ts +315 -315
  85. package/src/handlers/progress.test.ts +269 -269
  86. package/src/handlers/progress.ts +77 -77
  87. package/src/handlers/project.test.ts +546 -546
  88. package/src/handlers/project.ts +239 -194
  89. package/src/handlers/requests.test.ts +303 -272
  90. package/src/handlers/requests.ts +99 -96
  91. package/src/handlers/roles.test.ts +303 -303
  92. package/src/handlers/roles.ts +226 -208
  93. package/src/handlers/session.test.ts +875 -576
  94. package/src/handlers/session.ts +738 -425
  95. package/src/handlers/sprints.test.ts +732 -732
  96. package/src/handlers/sprints.ts +537 -477
  97. package/src/handlers/tasks.test.ts +907 -980
  98. package/src/handlers/tasks.ts +945 -716
  99. package/src/handlers/tool-categories.test.ts +66 -66
  100. package/src/handlers/tool-docs.ts +1096 -1024
  101. package/src/handlers/types.test.ts +259 -0
  102. package/src/handlers/types.ts +175 -175
  103. package/src/handlers/validation.test.ts +582 -582
  104. package/src/handlers/validation.ts +97 -97
  105. package/src/index.ts +792 -792
  106. package/src/setup.test.ts +231 -0
  107. package/src/setup.ts +370 -0
  108. package/src/templates/agent-guidelines.ts +210 -0
  109. package/src/token-tracking.test.ts +453 -453
  110. package/src/token-tracking.ts +164 -164
  111. package/src/tools.ts +3562 -3208
  112. package/src/utils.test.ts +683 -681
  113. package/src/utils.ts +436 -392
  114. package/src/validators.test.ts +223 -223
  115. package/src/validators.ts +249 -249
  116. package/tsconfig.json +16 -16
  117. package/vitest.config.ts +14 -14
@@ -1,468 +1,526 @@
1
- /**
2
- * Bodies of Work Handlers
3
- *
4
- * Handles grouping tasks into bodies of work with phases:
5
- * - create_body_of_work
6
- * - update_body_of_work
7
- * - get_body_of_work
8
- * - get_bodies_of_work
9
- * - delete_body_of_work
10
- * - add_task_to_body_of_work
11
- * - remove_task_from_body_of_work
12
- * - activate_body_of_work
13
- * - add_task_dependency
14
- * - remove_task_dependency
15
- * - get_task_dependencies
16
- * - get_next_body_of_work_task
17
- *
18
- * MIGRATED: Uses Vibescope API client instead of direct Supabase
19
- */
20
-
21
- import type { Handler, HandlerRegistry } from './types.js';
22
- import { parseArgs, uuidValidator, createEnumValidator } from '../validators.js';
23
- import { getApiClient } from '../api-client.js';
24
-
25
- const BODY_OF_WORK_STATUSES = ['draft', 'active', 'completed', 'cancelled'] as const;
26
- const TASK_PHASES = ['pre', 'core', 'post'] as const;
27
- const DEPLOY_ENVIRONMENTS = ['development', 'staging', 'production'] as const;
28
- const VERSION_BUMPS = ['patch', 'minor', 'major'] as const;
29
- const DEPLOY_TRIGGERS = ['all_completed', 'all_completed_validated'] as const;
30
-
31
- type BodyOfWorkStatus = typeof BODY_OF_WORK_STATUSES[number];
32
- type TaskPhase = typeof TASK_PHASES[number];
33
- type DeployEnvironment = typeof DEPLOY_ENVIRONMENTS[number];
34
- type VersionBump = typeof VERSION_BUMPS[number];
35
- type DeployTrigger = typeof DEPLOY_TRIGGERS[number];
36
-
37
- // ============================================================================
38
- // Argument Schemas
39
- // ============================================================================
40
-
41
- const createBodyOfWorkSchema = {
42
- project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
43
- title: { type: 'string' as const, required: true as const },
44
- description: { type: 'string' as const },
45
- auto_deploy_on_completion: { type: 'boolean' as const },
46
- deploy_environment: { type: 'string' as const, validate: createEnumValidator(DEPLOY_ENVIRONMENTS) },
47
- deploy_version_bump: { type: 'string' as const, validate: createEnumValidator(VERSION_BUMPS) },
48
- deploy_trigger: { type: 'string' as const, validate: createEnumValidator(DEPLOY_TRIGGERS) },
49
- };
50
-
51
- const updateBodyOfWorkSchema = {
52
- body_of_work_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
53
- title: { type: 'string' as const },
54
- description: { type: 'string' as const },
55
- auto_deploy_on_completion: { type: 'boolean' as const },
56
- deploy_environment: { type: 'string' as const, validate: createEnumValidator(DEPLOY_ENVIRONMENTS) },
57
- deploy_version_bump: { type: 'string' as const, validate: createEnumValidator(VERSION_BUMPS) },
58
- deploy_trigger: { type: 'string' as const, validate: createEnumValidator(DEPLOY_TRIGGERS) },
59
- };
60
-
61
- const getBodyOfWorkSchema = {
62
- body_of_work_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
63
- summary_only: { type: 'boolean' as const, default: false },
64
- };
65
-
66
- const getBodiesOfWorkSchema = {
67
- project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
68
- status: { type: 'string' as const, validate: createEnumValidator(BODY_OF_WORK_STATUSES) },
69
- limit: { type: 'number' as const, default: 50 },
70
- offset: { type: 'number' as const, default: 0 },
71
- search_query: { type: 'string' as const },
72
- };
73
-
74
- const deleteBodyOfWorkSchema = {
75
- body_of_work_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
76
- };
77
-
78
- const addTaskToBodyOfWorkSchema = {
79
- body_of_work_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
80
- task_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
81
- phase: { type: 'string' as const, validate: createEnumValidator(TASK_PHASES) },
82
- order_index: { type: 'number' as const },
83
- };
84
-
85
- const removeTaskFromBodyOfWorkSchema = {
86
- task_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
87
- };
88
-
89
- const activateBodyOfWorkSchema = {
90
- body_of_work_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
91
- };
92
-
93
- const addTaskDependencySchema = {
94
- body_of_work_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
95
- task_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
96
- depends_on_task_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
97
- };
98
-
99
- const removeTaskDependencySchema = {
100
- task_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
101
- depends_on_task_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
102
- };
103
-
104
- const getTaskDependenciesSchema = {
105
- body_of_work_id: { type: 'string' as const, validate: uuidValidator },
106
- task_id: { type: 'string' as const, validate: uuidValidator },
107
- };
108
-
109
- const getNextBodyOfWorkTaskSchema = {
110
- body_of_work_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
111
- };
112
-
113
- export const createBodyOfWork: Handler = async (args, ctx) => {
114
- const {
115
- project_id,
116
- title,
117
- description,
118
- auto_deploy_on_completion,
119
- deploy_environment,
120
- deploy_version_bump,
121
- deploy_trigger,
122
- } = parseArgs(args, createBodyOfWorkSchema);
123
-
124
- const { session } = ctx;
125
- const apiClient = getApiClient();
126
-
127
- const response = await apiClient.proxy<{
128
- success: boolean;
129
- body_of_work_id: string;
130
- }>('create_body_of_work', {
131
- project_id,
132
- title,
133
- description,
134
- auto_deploy_on_completion,
135
- deploy_environment,
136
- deploy_version_bump,
137
- deploy_trigger
138
- }, {
139
- session_id: session.currentSessionId,
140
- persona: session.currentPersona,
141
- instance_id: session.instanceId
142
- });
143
-
144
- if (!response.ok) {
145
- return { result: { error: response.error || 'Failed to create body of work' }, isError: true };
146
- }
147
-
148
- return {
149
- result: {
150
- success: true,
151
- body_of_work_id: response.data?.body_of_work_id,
152
- title,
153
- status: 'draft',
154
- message: 'Body of work created. Add tasks with add_task_to_body_of_work, then activate with activate_body_of_work.',
155
- },
156
- };
157
- };
158
-
159
- export const updateBodyOfWork: Handler = async (args, ctx) => {
160
- const {
161
- body_of_work_id,
162
- title,
163
- description,
164
- auto_deploy_on_completion,
165
- deploy_environment,
166
- deploy_version_bump,
167
- deploy_trigger,
168
- } = parseArgs(args, updateBodyOfWorkSchema);
169
-
170
- // Check if any updates provided
171
- if (title === undefined && description === undefined && auto_deploy_on_completion === undefined &&
172
- deploy_environment === undefined && deploy_version_bump === undefined && deploy_trigger === undefined) {
173
- return { result: { success: true, message: 'No updates provided' } };
174
- }
175
-
176
- const apiClient = getApiClient();
177
-
178
- const response = await apiClient.proxy<{ success: boolean }>('update_body_of_work', {
179
- body_of_work_id,
180
- title,
181
- description,
182
- auto_deploy_on_completion,
183
- deploy_environment,
184
- deploy_version_bump,
185
- deploy_trigger
186
- });
187
-
188
- if (!response.ok) {
189
- return { result: { error: response.error || 'Failed to update body of work' }, isError: true };
190
- }
191
-
192
- return { result: { success: true, body_of_work_id } };
193
- };
194
-
195
- export const getBodyOfWork: Handler = async (args, ctx) => {
196
- const { body_of_work_id, summary_only } = parseArgs(args, getBodyOfWorkSchema);
197
-
198
- const apiClient = getApiClient();
199
-
200
- // Response type varies based on summary_only
201
- const response = await apiClient.proxy<{
202
- body_of_work: {
203
- id: string;
204
- title: string;
205
- description?: string;
206
- status: string;
207
- progress_percentage: number;
208
- };
209
- // Full response includes tasks grouped by phase
210
- tasks?: {
211
- pre: unknown[];
212
- core: unknown[];
213
- post: unknown[];
214
- };
215
- // Summary response includes counts and next task
216
- task_counts?: {
217
- pre: { total: number; completed: number };
218
- core: { total: number; completed: number };
219
- post: { total: number; completed: number };
220
- total: number;
221
- completed: number;
222
- in_progress: number;
223
- };
224
- current_task?: { id: string; title: string } | null;
225
- next_task?: { id: string; title: string; priority: number } | null;
226
- }>('get_body_of_work', { body_of_work_id, summary_only });
227
-
228
- if (!response.ok) {
229
- return { result: { error: response.error || 'Failed to get body of work' }, isError: true };
230
- }
231
-
232
- return { result: response.data };
233
- };
234
-
235
- export const getBodiesOfWork: Handler = async (args, ctx) => {
236
- const { project_id, status, limit, offset, search_query } = parseArgs(args, getBodiesOfWorkSchema);
237
-
238
- const apiClient = getApiClient();
239
-
240
- const response = await apiClient.proxy<{
241
- bodies_of_work: Array<{
242
- id: string;
243
- title: string;
244
- description?: string;
245
- status: string;
246
- progress_percentage: number;
247
- task_counts: {
248
- pre: { total: number; completed: number };
249
- core: { total: number; completed: number };
250
- post: { total: number; completed: number };
251
- };
252
- }>;
253
- total_count: number;
254
- has_more: boolean;
255
- }>('get_bodies_of_work', {
256
- project_id,
257
- status,
258
- limit: Math.min(limit ?? 50, 100),
259
- offset,
260
- search_query
261
- });
262
-
263
- if (!response.ok) {
264
- return { result: { error: response.error || 'Failed to fetch bodies of work' }, isError: true };
265
- }
266
-
267
- return { result: response.data };
268
- };
269
-
270
- export const deleteBodyOfWork: Handler = async (args, ctx) => {
271
- const { body_of_work_id } = parseArgs(args, deleteBodyOfWorkSchema);
272
-
273
- const apiClient = getApiClient();
274
-
275
- const response = await apiClient.proxy<{ success: boolean }>('delete_body_of_work', {
276
- body_of_work_id
277
- });
278
-
279
- if (!response.ok) {
280
- return { result: { error: response.error || 'Failed to delete body of work' }, isError: true };
281
- }
282
-
283
- return { result: { success: true, message: 'Body of work deleted. Tasks are preserved.' } };
284
- };
285
-
286
- export const addTaskToBodyOfWork: Handler = async (args, ctx) => {
287
- const { body_of_work_id, task_id, phase, order_index } = parseArgs(args, addTaskToBodyOfWorkSchema);
288
-
289
- const apiClient = getApiClient();
290
-
291
- const response = await apiClient.proxy<{
292
- success: boolean;
293
- body_of_work_id: string;
294
- task_id: string;
295
- phase: string;
296
- order_index: number;
297
- }>('add_task_to_body_of_work', {
298
- body_of_work_id,
299
- task_id,
300
- phase: phase || 'core',
301
- order_index
302
- });
303
-
304
- if (!response.ok) {
305
- return { result: { error: response.error || 'Failed to add task to body of work' }, isError: true };
306
- }
307
-
308
- return { result: response.data };
309
- };
310
-
311
- export const removeTaskFromBodyOfWork: Handler = async (args, ctx) => {
312
- const { task_id } = parseArgs(args, removeTaskFromBodyOfWorkSchema);
313
-
314
- const apiClient = getApiClient();
315
-
316
- const response = await apiClient.proxy<{
317
- success: boolean;
318
- body_of_work_id?: string;
319
- message?: string;
320
- }>('remove_task_from_body_of_work', { task_id });
321
-
322
- if (!response.ok) {
323
- return { result: { error: response.error || 'Failed to remove task from body of work' }, isError: true };
324
- }
325
-
326
- return { result: response.data };
327
- };
328
-
329
- export const activateBodyOfWork: Handler = async (args, ctx) => {
330
- const { body_of_work_id } = parseArgs(args, activateBodyOfWorkSchema);
331
-
332
- const apiClient = getApiClient();
333
-
334
- const response = await apiClient.proxy<{
335
- success: boolean;
336
- body_of_work_id: string;
337
- title: string;
338
- status: string;
339
- message: string;
340
- }>('activate_body_of_work', { body_of_work_id });
341
-
342
- if (!response.ok) {
343
- return { result: { error: response.error || 'Failed to activate body of work' }, isError: true };
344
- }
345
-
346
- return { result: response.data };
347
- };
348
-
349
- export const addTaskDependency: Handler = async (args, ctx) => {
350
- const { body_of_work_id, task_id, depends_on_task_id } = parseArgs(args, addTaskDependencySchema);
351
-
352
- if (task_id === depends_on_task_id) {
353
- return { result: { error: 'A task cannot depend on itself' }, isError: true };
354
- }
355
-
356
- const apiClient = getApiClient();
357
-
358
- const response = await apiClient.proxy<{
359
- success: boolean;
360
- body_of_work_id: string;
361
- task_id: string;
362
- depends_on_task_id: string;
363
- message: string;
364
- }>('add_task_dependency', {
365
- body_of_work_id,
366
- task_id,
367
- depends_on_task_id
368
- });
369
-
370
- if (!response.ok) {
371
- return { result: { error: response.error || 'Failed to add task dependency' }, isError: true };
372
- }
373
-
374
- return { result: response.data };
375
- };
376
-
377
- export const removeTaskDependency: Handler = async (args, ctx) => {
378
- const { task_id, depends_on_task_id } = parseArgs(args, removeTaskDependencySchema);
379
-
380
- const apiClient = getApiClient();
381
-
382
- const response = await apiClient.proxy<{
383
- success: boolean;
384
- task_id: string;
385
- depends_on_task_id: string;
386
- }>('remove_task_dependency', {
387
- task_id,
388
- depends_on_task_id
389
- });
390
-
391
- if (!response.ok) {
392
- return { result: { error: response.error || 'Failed to remove task dependency' }, isError: true };
393
- }
394
-
395
- return { result: response.data };
396
- };
397
-
398
- export const getTaskDependencies: Handler = async (args, ctx) => {
399
- const { body_of_work_id, task_id } = parseArgs(args, getTaskDependenciesSchema);
400
-
401
- if (!body_of_work_id && !task_id) {
402
- return { result: { error: 'Either body_of_work_id or task_id is required' }, isError: true };
403
- }
404
-
405
- const apiClient = getApiClient();
406
-
407
- const response = await apiClient.proxy<{
408
- dependencies: Array<{
409
- id: string;
410
- task_id: string;
411
- depends_on_task_id: string;
412
- created_at: string;
413
- }>;
414
- }>('get_task_dependencies', {
415
- body_of_work_id,
416
- task_id
417
- });
418
-
419
- if (!response.ok) {
420
- return { result: { error: response.error || 'Failed to fetch task dependencies' }, isError: true };
421
- }
422
-
423
- return { result: response.data };
424
- };
425
-
426
- export const getNextBodyOfWorkTask: Handler = async (args, ctx) => {
427
- const { body_of_work_id } = parseArgs(args, getNextBodyOfWorkTaskSchema);
428
-
429
- const apiClient = getApiClient();
430
-
431
- const response = await apiClient.proxy<{
432
- next_task: {
433
- id: string;
434
- title: string;
435
- phase: string;
436
- priority: number;
437
- } | null;
438
- body_of_work?: {
439
- id: string;
440
- title: string;
441
- };
442
- message?: string;
443
- }>('get_next_body_of_work_task', { body_of_work_id });
444
-
445
- if (!response.ok) {
446
- return { result: { error: response.error || 'Failed to get next body of work task' }, isError: true };
447
- }
448
-
449
- return { result: response.data };
450
- };
451
-
452
- /**
453
- * Bodies of Work handlers registry
454
- */
455
- export const bodiesOfWorkHandlers: HandlerRegistry = {
456
- create_body_of_work: createBodyOfWork,
457
- update_body_of_work: updateBodyOfWork,
458
- get_body_of_work: getBodyOfWork,
459
- get_bodies_of_work: getBodiesOfWork,
460
- delete_body_of_work: deleteBodyOfWork,
461
- add_task_to_body_of_work: addTaskToBodyOfWork,
462
- remove_task_from_body_of_work: removeTaskFromBodyOfWork,
463
- activate_body_of_work: activateBodyOfWork,
464
- add_task_dependency: addTaskDependency,
465
- remove_task_dependency: removeTaskDependency,
466
- get_task_dependencies: getTaskDependencies,
467
- get_next_body_of_work_task: getNextBodyOfWorkTask,
468
- };
1
+ /**
2
+ * Bodies of Work Handlers
3
+ *
4
+ * Handles grouping tasks into bodies of work with phases:
5
+ * - create_body_of_work
6
+ * - update_body_of_work
7
+ * - get_body_of_work
8
+ * - get_bodies_of_work
9
+ * - delete_body_of_work
10
+ * - add_task_to_body_of_work
11
+ * - remove_task_from_body_of_work
12
+ * - activate_body_of_work
13
+ * - add_task_dependency
14
+ * - remove_task_dependency
15
+ * - get_task_dependencies
16
+ * - get_next_body_of_work_task
17
+ *
18
+ * MIGRATED: Uses Vibescope API client instead of direct Supabase
19
+ */
20
+
21
+ import type { Handler, HandlerRegistry } from './types.js';
22
+ import { parseArgs, uuidValidator, createEnumValidator } from '../validators.js';
23
+ import { getApiClient } from '../api-client.js';
24
+
25
+ const BODY_OF_WORK_STATUSES = ['draft', 'active', 'completed', 'cancelled', 'archived'] as const;
26
+ const TASK_PHASES = ['pre', 'core', 'post'] as const;
27
+ const DEPLOY_ENVIRONMENTS = ['development', 'staging', 'production'] as const;
28
+ const VERSION_BUMPS = ['patch', 'minor', 'major'] as const;
29
+ const DEPLOY_TRIGGERS = ['all_completed', 'all_completed_validated'] as const;
30
+
31
+ type BodyOfWorkStatus = typeof BODY_OF_WORK_STATUSES[number];
32
+ type TaskPhase = typeof TASK_PHASES[number];
33
+ type DeployEnvironment = typeof DEPLOY_ENVIRONMENTS[number];
34
+ type VersionBump = typeof VERSION_BUMPS[number];
35
+ type DeployTrigger = typeof DEPLOY_TRIGGERS[number];
36
+
37
+ // ============================================================================
38
+ // Argument Schemas
39
+ // ============================================================================
40
+
41
+ const createBodyOfWorkSchema = {
42
+ project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
43
+ title: { type: 'string' as const, required: true as const },
44
+ description: { type: 'string' as const },
45
+ auto_deploy_on_completion: { type: 'boolean' as const },
46
+ deploy_environment: { type: 'string' as const, validate: createEnumValidator(DEPLOY_ENVIRONMENTS) },
47
+ deploy_version_bump: { type: 'string' as const, validate: createEnumValidator(VERSION_BUMPS) },
48
+ deploy_trigger: { type: 'string' as const, validate: createEnumValidator(DEPLOY_TRIGGERS) },
49
+ };
50
+
51
+ const updateBodyOfWorkSchema = {
52
+ body_of_work_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
53
+ title: { type: 'string' as const },
54
+ description: { type: 'string' as const },
55
+ auto_deploy_on_completion: { type: 'boolean' as const },
56
+ deploy_environment: { type: 'string' as const, validate: createEnumValidator(DEPLOY_ENVIRONMENTS) },
57
+ deploy_version_bump: { type: 'string' as const, validate: createEnumValidator(VERSION_BUMPS) },
58
+ deploy_trigger: { type: 'string' as const, validate: createEnumValidator(DEPLOY_TRIGGERS) },
59
+ };
60
+
61
+ const getBodyOfWorkSchema = {
62
+ body_of_work_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
63
+ summary_only: { type: 'boolean' as const, default: false },
64
+ };
65
+
66
+ const getBodiesOfWorkSchema = {
67
+ project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
68
+ status: { type: 'string' as const, validate: createEnumValidator(BODY_OF_WORK_STATUSES) },
69
+ limit: { type: 'number' as const, default: 50 },
70
+ offset: { type: 'number' as const, default: 0 },
71
+ search_query: { type: 'string' as const },
72
+ };
73
+
74
+ const deleteBodyOfWorkSchema = {
75
+ body_of_work_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
76
+ };
77
+
78
+ const addTaskToBodyOfWorkSchema = {
79
+ body_of_work_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
80
+ task_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
81
+ phase: { type: 'string' as const, validate: createEnumValidator(TASK_PHASES) },
82
+ order_index: { type: 'number' as const },
83
+ };
84
+
85
+ const removeTaskFromBodyOfWorkSchema = {
86
+ task_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
87
+ };
88
+
89
+ const activateBodyOfWorkSchema = {
90
+ body_of_work_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
91
+ };
92
+
93
+ const addTaskDependencySchema = {
94
+ body_of_work_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
95
+ task_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
96
+ depends_on_task_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
97
+ };
98
+
99
+ const removeTaskDependencySchema = {
100
+ task_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
101
+ depends_on_task_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
102
+ };
103
+
104
+ const getTaskDependenciesSchema = {
105
+ body_of_work_id: { type: 'string' as const, validate: uuidValidator },
106
+ task_id: { type: 'string' as const, validate: uuidValidator },
107
+ };
108
+
109
+ const getNextBodyOfWorkTaskSchema = {
110
+ body_of_work_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
111
+ };
112
+
113
+ export const createBodyOfWork: Handler = async (args, ctx) => {
114
+ const {
115
+ project_id,
116
+ title,
117
+ description,
118
+ auto_deploy_on_completion,
119
+ deploy_environment,
120
+ deploy_version_bump,
121
+ deploy_trigger,
122
+ } = parseArgs(args, createBodyOfWorkSchema);
123
+
124
+ const { session } = ctx;
125
+ const apiClient = getApiClient();
126
+
127
+ const response = await apiClient.proxy<{
128
+ success: boolean;
129
+ body_of_work_id: string;
130
+ }>('create_body_of_work', {
131
+ project_id,
132
+ title,
133
+ description,
134
+ auto_deploy_on_completion,
135
+ deploy_environment,
136
+ deploy_version_bump,
137
+ deploy_trigger
138
+ }, {
139
+ session_id: session.currentSessionId,
140
+ persona: session.currentPersona,
141
+ instance_id: session.instanceId
142
+ });
143
+
144
+ if (!response.ok) {
145
+ return { result: { error: response.error || 'Failed to create body of work' }, isError: true };
146
+ }
147
+
148
+ return {
149
+ result: {
150
+ success: true,
151
+ body_of_work_id: response.data?.body_of_work_id,
152
+ title,
153
+ status: 'draft',
154
+ message: 'Body of work created. Add tasks with add_task_to_body_of_work, then activate with activate_body_of_work.',
155
+ },
156
+ };
157
+ };
158
+
159
+ export const updateBodyOfWork: Handler = async (args, ctx) => {
160
+ const {
161
+ body_of_work_id,
162
+ title,
163
+ description,
164
+ auto_deploy_on_completion,
165
+ deploy_environment,
166
+ deploy_version_bump,
167
+ deploy_trigger,
168
+ } = parseArgs(args, updateBodyOfWorkSchema);
169
+
170
+ // Check if any updates provided
171
+ if (title === undefined && description === undefined && auto_deploy_on_completion === undefined &&
172
+ deploy_environment === undefined && deploy_version_bump === undefined && deploy_trigger === undefined) {
173
+ return { result: { success: true, message: 'No updates provided' } };
174
+ }
175
+
176
+ const apiClient = getApiClient();
177
+
178
+ const response = await apiClient.proxy<{ success: boolean }>('update_body_of_work', {
179
+ body_of_work_id,
180
+ title,
181
+ description,
182
+ auto_deploy_on_completion,
183
+ deploy_environment,
184
+ deploy_version_bump,
185
+ deploy_trigger
186
+ });
187
+
188
+ if (!response.ok) {
189
+ return { result: { error: response.error || 'Failed to update body of work' }, isError: true };
190
+ }
191
+
192
+ return { result: { success: true, body_of_work_id } };
193
+ };
194
+
195
+ export const getBodyOfWork: Handler = async (args, ctx) => {
196
+ const { body_of_work_id, summary_only } = parseArgs(args, getBodyOfWorkSchema);
197
+
198
+ const apiClient = getApiClient();
199
+
200
+ // Response type varies based on summary_only
201
+ const response = await apiClient.proxy<{
202
+ body_of_work: {
203
+ id: string;
204
+ title: string;
205
+ description?: string;
206
+ status: string;
207
+ progress_percentage: number;
208
+ total_estimated_minutes?: number;
209
+ completed_estimated_minutes?: number;
210
+ };
211
+ // Full response includes tasks grouped by phase
212
+ tasks?: {
213
+ pre: unknown[];
214
+ core: unknown[];
215
+ post: unknown[];
216
+ };
217
+ // Summary response includes counts and next task
218
+ task_counts?: {
219
+ pre: { total: number; completed: number };
220
+ core: { total: number; completed: number };
221
+ post: { total: number; completed: number };
222
+ total: number;
223
+ completed: number;
224
+ in_progress: number;
225
+ };
226
+ current_task?: { id: string; title: string } | null;
227
+ next_task?: { id: string; title: string; priority: number } | null;
228
+ }>('get_body_of_work', { body_of_work_id, summary_only });
229
+
230
+ if (!response.ok) {
231
+ return { result: { error: response.error || 'Failed to get body of work' }, isError: true };
232
+ }
233
+
234
+ return { result: response.data };
235
+ };
236
+
237
+ export const getBodiesOfWork: Handler = async (args, ctx) => {
238
+ const { project_id, status, limit, offset, search_query } = parseArgs(args, getBodiesOfWorkSchema);
239
+
240
+ const apiClient = getApiClient();
241
+
242
+ const response = await apiClient.proxy<{
243
+ bodies_of_work: Array<{
244
+ id: string;
245
+ title: string;
246
+ description?: string;
247
+ status: string;
248
+ progress_percentage: number;
249
+ total_estimated_minutes?: number;
250
+ completed_estimated_minutes?: number;
251
+ task_counts: {
252
+ pre: { total: number; completed: number };
253
+ core: { total: number; completed: number };
254
+ post: { total: number; completed: number };
255
+ };
256
+ }>;
257
+ total_count: number;
258
+ has_more: boolean;
259
+ }>('get_bodies_of_work', {
260
+ project_id,
261
+ status,
262
+ limit: Math.min(limit ?? 50, 100),
263
+ offset,
264
+ search_query
265
+ });
266
+
267
+ if (!response.ok) {
268
+ return { result: { error: response.error || 'Failed to fetch bodies of work' }, isError: true };
269
+ }
270
+
271
+ return { result: response.data };
272
+ };
273
+
274
+ export const deleteBodyOfWork: Handler = async (args, ctx) => {
275
+ const { body_of_work_id } = parseArgs(args, deleteBodyOfWorkSchema);
276
+
277
+ const apiClient = getApiClient();
278
+
279
+ const response = await apiClient.proxy<{ success: boolean }>('delete_body_of_work', {
280
+ body_of_work_id
281
+ });
282
+
283
+ if (!response.ok) {
284
+ return { result: { error: response.error || 'Failed to delete body of work' }, isError: true };
285
+ }
286
+
287
+ return { result: { success: true, message: 'Body of work deleted. Tasks are preserved.' } };
288
+ };
289
+
290
+ export const addTaskToBodyOfWork: Handler = async (args, ctx) => {
291
+ const { body_of_work_id, task_id, phase, order_index } = parseArgs(args, addTaskToBodyOfWorkSchema);
292
+
293
+ const apiClient = getApiClient();
294
+
295
+ const response = await apiClient.proxy<{
296
+ success: boolean;
297
+ body_of_work_id: string;
298
+ task_id: string;
299
+ phase: string;
300
+ order_index: number;
301
+ }>('add_task_to_body_of_work', {
302
+ body_of_work_id,
303
+ task_id,
304
+ phase: phase || 'core',
305
+ order_index
306
+ });
307
+
308
+ if (!response.ok) {
309
+ return { result: { error: response.error || 'Failed to add task to body of work' }, isError: true };
310
+ }
311
+
312
+ return { result: response.data };
313
+ };
314
+
315
+ export const removeTaskFromBodyOfWork: Handler = async (args, ctx) => {
316
+ const { task_id } = parseArgs(args, removeTaskFromBodyOfWorkSchema);
317
+
318
+ const apiClient = getApiClient();
319
+
320
+ const response = await apiClient.proxy<{
321
+ success: boolean;
322
+ body_of_work_id?: string;
323
+ message?: string;
324
+ }>('remove_task_from_body_of_work', { task_id });
325
+
326
+ if (!response.ok) {
327
+ return { result: { error: response.error || 'Failed to remove task from body of work' }, isError: true };
328
+ }
329
+
330
+ return { result: response.data };
331
+ };
332
+
333
+ export const activateBodyOfWork: Handler = async (args, ctx) => {
334
+ const { body_of_work_id } = parseArgs(args, activateBodyOfWorkSchema);
335
+
336
+ const apiClient = getApiClient();
337
+
338
+ const response = await apiClient.proxy<{
339
+ success: boolean;
340
+ body_of_work_id: string;
341
+ title: string;
342
+ status: string;
343
+ message: string;
344
+ }>('activate_body_of_work', { body_of_work_id });
345
+
346
+ if (!response.ok) {
347
+ return { result: { error: response.error || 'Failed to activate body of work' }, isError: true };
348
+ }
349
+
350
+ return { result: response.data };
351
+ };
352
+
353
+ export const addTaskDependency: Handler = async (args, ctx) => {
354
+ const { body_of_work_id, task_id, depends_on_task_id } = parseArgs(args, addTaskDependencySchema);
355
+
356
+ if (task_id === depends_on_task_id) {
357
+ return { result: { error: 'A task cannot depend on itself' }, isError: true };
358
+ }
359
+
360
+ const apiClient = getApiClient();
361
+
362
+ const response = await apiClient.proxy<{
363
+ success: boolean;
364
+ body_of_work_id: string;
365
+ task_id: string;
366
+ depends_on_task_id: string;
367
+ message: string;
368
+ }>('add_task_dependency', {
369
+ body_of_work_id,
370
+ task_id,
371
+ depends_on_task_id
372
+ });
373
+
374
+ if (!response.ok) {
375
+ return { result: { error: response.error || 'Failed to add task dependency' }, isError: true };
376
+ }
377
+
378
+ return { result: response.data };
379
+ };
380
+
381
+ export const removeTaskDependency: Handler = async (args, ctx) => {
382
+ const { task_id, depends_on_task_id } = parseArgs(args, removeTaskDependencySchema);
383
+
384
+ const apiClient = getApiClient();
385
+
386
+ const response = await apiClient.proxy<{
387
+ success: boolean;
388
+ task_id: string;
389
+ depends_on_task_id: string;
390
+ }>('remove_task_dependency', {
391
+ task_id,
392
+ depends_on_task_id
393
+ });
394
+
395
+ if (!response.ok) {
396
+ return { result: { error: response.error || 'Failed to remove task dependency' }, isError: true };
397
+ }
398
+
399
+ return { result: response.data };
400
+ };
401
+
402
+ export const getTaskDependencies: Handler = async (args, ctx) => {
403
+ const { body_of_work_id, task_id } = parseArgs(args, getTaskDependenciesSchema);
404
+
405
+ if (!body_of_work_id && !task_id) {
406
+ return { result: { error: 'Either body_of_work_id or task_id is required' }, isError: true };
407
+ }
408
+
409
+ const apiClient = getApiClient();
410
+
411
+ const response = await apiClient.proxy<{
412
+ dependencies: Array<{
413
+ id: string;
414
+ task_id: string;
415
+ depends_on_task_id: string;
416
+ created_at: string;
417
+ }>;
418
+ }>('get_task_dependencies', {
419
+ body_of_work_id,
420
+ task_id
421
+ });
422
+
423
+ if (!response.ok) {
424
+ return { result: { error: response.error || 'Failed to fetch task dependencies' }, isError: true };
425
+ }
426
+
427
+ return { result: response.data };
428
+ };
429
+
430
+ export const getNextBodyOfWorkTask: Handler = async (args, ctx) => {
431
+ const { body_of_work_id } = parseArgs(args, getNextBodyOfWorkTaskSchema);
432
+
433
+ const apiClient = getApiClient();
434
+
435
+ const response = await apiClient.proxy<{
436
+ next_task: {
437
+ id: string;
438
+ title: string;
439
+ phase: string;
440
+ priority: number;
441
+ } | null;
442
+ body_of_work?: {
443
+ id: string;
444
+ title: string;
445
+ };
446
+ message?: string;
447
+ }>('get_next_body_of_work_task', { body_of_work_id });
448
+
449
+ if (!response.ok) {
450
+ return { result: { error: response.error || 'Failed to get next body of work task' }, isError: true };
451
+ }
452
+
453
+ return { result: response.data };
454
+ };
455
+
456
+ // ============================================================================
457
+ // Archive / Unarchive Handlers
458
+ // ============================================================================
459
+
460
+ const archiveBodyOfWorkSchema = {
461
+ body_of_work_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
462
+ };
463
+
464
+ const unarchiveBodyOfWorkSchema = {
465
+ body_of_work_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
466
+ };
467
+
468
+ export const archiveBodyOfWork: Handler = async (args, ctx) => {
469
+ const { body_of_work_id } = parseArgs(args, archiveBodyOfWorkSchema);
470
+
471
+ const apiClient = getApiClient();
472
+
473
+ const response = await apiClient.proxy<{
474
+ success: boolean;
475
+ body_of_work_id: string;
476
+ title: string;
477
+ previous_status: string;
478
+ new_status: string;
479
+ }>('archive_body_of_work', { body_of_work_id });
480
+
481
+ if (!response.ok) {
482
+ return { result: { error: response.error || 'Failed to archive body of work' }, isError: true };
483
+ }
484
+
485
+ return { result: response.data };
486
+ };
487
+
488
+ export const unarchiveBodyOfWork: Handler = async (args, ctx) => {
489
+ const { body_of_work_id } = parseArgs(args, unarchiveBodyOfWorkSchema);
490
+
491
+ const apiClient = getApiClient();
492
+
493
+ const response = await apiClient.proxy<{
494
+ success: boolean;
495
+ body_of_work_id: string;
496
+ title: string;
497
+ previous_status: string;
498
+ new_status: string;
499
+ }>('unarchive_body_of_work', { body_of_work_id });
500
+
501
+ if (!response.ok) {
502
+ return { result: { error: response.error || 'Failed to unarchive body of work' }, isError: true };
503
+ }
504
+
505
+ return { result: response.data };
506
+ };
507
+
508
+ /**
509
+ * Bodies of Work handlers registry
510
+ */
511
+ export const bodiesOfWorkHandlers: HandlerRegistry = {
512
+ create_body_of_work: createBodyOfWork,
513
+ update_body_of_work: updateBodyOfWork,
514
+ get_body_of_work: getBodyOfWork,
515
+ get_bodies_of_work: getBodiesOfWork,
516
+ delete_body_of_work: deleteBodyOfWork,
517
+ add_task_to_body_of_work: addTaskToBodyOfWork,
518
+ remove_task_from_body_of_work: removeTaskFromBodyOfWork,
519
+ activate_body_of_work: activateBodyOfWork,
520
+ add_task_dependency: addTaskDependency,
521
+ remove_task_dependency: removeTaskDependency,
522
+ get_task_dependencies: getTaskDependencies,
523
+ get_next_body_of_work_task: getNextBodyOfWorkTask,
524
+ archive_body_of_work: archiveBodyOfWork,
525
+ unarchive_body_of_work: unarchiveBodyOfWork,
526
+ };