@vibescope/mcp-server 0.2.5 → 0.2.7

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 (82) hide show
  1. package/CHANGELOG.md +84 -84
  2. package/README.md +194 -194
  3. package/dist/cli.js +26 -26
  4. package/dist/handlers/tool-docs.js +828 -828
  5. package/dist/index.js +73 -73
  6. package/dist/templates/agent-guidelines.js +185 -185
  7. package/dist/token-tracking.js +4 -2
  8. package/dist/tools.js +65 -65
  9. package/dist/utils.js +11 -11
  10. package/docs/TOOLS.md +2053 -2053
  11. package/package.json +3 -2
  12. package/scripts/generate-docs.ts +212 -212
  13. package/scripts/version-bump.ts +203 -203
  14. package/src/api-client.test.ts +723 -723
  15. package/src/api-client.ts +2499 -2499
  16. package/src/cli.ts +212 -212
  17. package/src/handlers/__test-setup__.ts +236 -236
  18. package/src/handlers/__test-utils__.ts +87 -87
  19. package/src/handlers/blockers.test.ts +468 -468
  20. package/src/handlers/blockers.ts +163 -163
  21. package/src/handlers/bodies-of-work.test.ts +704 -704
  22. package/src/handlers/bodies-of-work.ts +526 -526
  23. package/src/handlers/connectors.test.ts +834 -834
  24. package/src/handlers/connectors.ts +229 -229
  25. package/src/handlers/cost.test.ts +462 -462
  26. package/src/handlers/cost.ts +285 -285
  27. package/src/handlers/decisions.test.ts +382 -382
  28. package/src/handlers/decisions.ts +153 -153
  29. package/src/handlers/deployment.test.ts +551 -551
  30. package/src/handlers/deployment.ts +541 -541
  31. package/src/handlers/discovery.test.ts +206 -206
  32. package/src/handlers/discovery.ts +390 -390
  33. package/src/handlers/fallback.test.ts +537 -537
  34. package/src/handlers/fallback.ts +194 -194
  35. package/src/handlers/file-checkouts.test.ts +750 -750
  36. package/src/handlers/file-checkouts.ts +185 -185
  37. package/src/handlers/findings.test.ts +633 -633
  38. package/src/handlers/findings.ts +239 -239
  39. package/src/handlers/git-issues.test.ts +631 -631
  40. package/src/handlers/git-issues.ts +136 -136
  41. package/src/handlers/ideas.test.ts +644 -644
  42. package/src/handlers/ideas.ts +207 -207
  43. package/src/handlers/index.ts +84 -84
  44. package/src/handlers/milestones.test.ts +475 -475
  45. package/src/handlers/milestones.ts +180 -180
  46. package/src/handlers/organizations.test.ts +826 -826
  47. package/src/handlers/organizations.ts +315 -315
  48. package/src/handlers/progress.test.ts +269 -269
  49. package/src/handlers/progress.ts +77 -77
  50. package/src/handlers/project.test.ts +546 -546
  51. package/src/handlers/project.ts +239 -239
  52. package/src/handlers/requests.test.ts +303 -303
  53. package/src/handlers/requests.ts +99 -99
  54. package/src/handlers/roles.test.ts +303 -303
  55. package/src/handlers/roles.ts +226 -226
  56. package/src/handlers/session.test.ts +875 -875
  57. package/src/handlers/session.ts +738 -738
  58. package/src/handlers/sprints.test.ts +732 -732
  59. package/src/handlers/sprints.ts +537 -537
  60. package/src/handlers/tasks.test.ts +907 -907
  61. package/src/handlers/tasks.ts +945 -945
  62. package/src/handlers/tool-categories.test.ts +66 -66
  63. package/src/handlers/tool-docs.ts +1096 -1096
  64. package/src/handlers/types.test.ts +259 -259
  65. package/src/handlers/types.ts +175 -175
  66. package/src/handlers/validation.test.ts +582 -582
  67. package/src/handlers/validation.ts +97 -97
  68. package/src/index.ts +792 -792
  69. package/src/setup.test.ts +233 -231
  70. package/src/setup.ts +370 -370
  71. package/src/templates/agent-guidelines.ts +210 -210
  72. package/src/token-tracking.test.ts +463 -453
  73. package/src/token-tracking.ts +166 -164
  74. package/src/tools.ts +3562 -3562
  75. package/src/utils.test.ts +683 -683
  76. package/src/utils.ts +436 -436
  77. package/src/validators.test.ts +223 -223
  78. package/src/validators.ts +249 -249
  79. package/tsconfig.json +16 -16
  80. package/vitest.config.ts +14 -14
  81. package/dist/knowledge.d.ts +0 -6
  82. package/dist/knowledge.js +0 -218
@@ -1,541 +1,541 @@
1
- /**
2
- * Deployment Handlers
3
- *
4
- * Handles deployment coordination and requirements:
5
- * - request_deployment
6
- * - claim_deployment_validation
7
- * - report_validation
8
- * - check_deployment_status
9
- * - start_deployment
10
- * - complete_deployment
11
- * - cancel_deployment
12
- * - add_deployment_requirement
13
- * - complete_deployment_requirement
14
- * - get_deployment_requirements
15
- */
16
-
17
- import type { Handler, HandlerRegistry } from './types.js';
18
- import {
19
- ValidationError,
20
- parseArgs,
21
- uuidValidator,
22
- createEnumValidator,
23
- } from '../validators.js';
24
- import { getApiClient } from '../api-client.js';
25
-
26
- const ENVIRONMENTS = ['development', 'staging', 'production'] as const;
27
- const VERSION_BUMPS = ['patch', 'minor', 'major'] as const;
28
- const REQUIREMENT_TYPES = ['migration', 'env_var', 'config', 'manual', 'breaking_change', 'agent_task'] as const;
29
- const REQUIREMENT_STAGES = ['preparation', 'deployment', 'verification'] as const;
30
- const REQUIREMENT_STATUSES = ['pending', 'completed', 'converted_to_task', 'all'] as const;
31
- const SCHEDULE_TYPES = ['once', 'hourly', 'daily', 'weekly', 'monthly'] as const;
32
-
33
- type Environment = typeof ENVIRONMENTS[number];
34
- type VersionBump = typeof VERSION_BUMPS[number];
35
- type RequirementType = typeof REQUIREMENT_TYPES[number];
36
- type RequirementStage = typeof REQUIREMENT_STAGES[number];
37
- type RequirementStatus = typeof REQUIREMENT_STATUSES[number];
38
- type ScheduleType = typeof SCHEDULE_TYPES[number];
39
-
40
- // ============================================================================
41
- // Argument Schemas
42
- // ============================================================================
43
-
44
- const requestDeploymentSchema = {
45
- project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
46
- environment: { type: 'string' as const, default: 'production', validate: createEnumValidator(ENVIRONMENTS) },
47
- version_bump: { type: 'string' as const, default: 'patch', validate: createEnumValidator(VERSION_BUMPS) },
48
- notes: { type: 'string' as const },
49
- git_ref: { type: 'string' as const },
50
- };
51
-
52
- const claimDeploymentValidationSchema = {
53
- project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
54
- };
55
-
56
- const reportValidationSchema = {
57
- project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
58
- build_passed: { type: 'boolean' as const, required: true as const },
59
- tests_passed: { type: 'boolean' as const },
60
- error_message: { type: 'string' as const },
61
- };
62
-
63
- const checkDeploymentStatusSchema = {
64
- project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
65
- };
66
-
67
- const startDeploymentSchema = {
68
- project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
69
- };
70
-
71
- const completeDeploymentSchema = {
72
- project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
73
- success: { type: 'boolean' as const, required: true as const },
74
- summary: { type: 'string' as const },
75
- };
76
-
77
- const cancelDeploymentSchema = {
78
- project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
79
- reason: { type: 'string' as const },
80
- };
81
-
82
- const addDeploymentRequirementSchema = {
83
- project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
84
- type: { type: 'string' as const, required: true as const, validate: createEnumValidator(REQUIREMENT_TYPES) },
85
- title: { type: 'string' as const, required: true as const },
86
- description: { type: 'string' as const },
87
- file_path: { type: 'string' as const },
88
- stage: { type: 'string' as const, default: 'preparation', validate: createEnumValidator(REQUIREMENT_STAGES) },
89
- blocking: { type: 'boolean' as const, default: false },
90
- recurring: { type: 'boolean' as const, default: true },
91
- };
92
-
93
- const completeDeploymentRequirementSchema = {
94
- requirement_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
95
- };
96
-
97
- const getDeploymentRequirementsSchema = {
98
- project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
99
- status: { type: 'string' as const, default: 'pending', validate: createEnumValidator(REQUIREMENT_STATUSES) },
100
- stage: { type: 'string' as const, validate: createEnumValidator([...REQUIREMENT_STAGES, 'all'] as const) },
101
- limit: { type: 'number' as const, default: 50 },
102
- offset: { type: 'number' as const, default: 0 },
103
- };
104
-
105
- const getDeploymentRequirementsStatsSchema = {
106
- project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
107
- };
108
-
109
- const scheduleDeploymentSchema = {
110
- project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
111
- environment: { type: 'string' as const, default: 'production', validate: createEnumValidator(ENVIRONMENTS) },
112
- version_bump: { type: 'string' as const, default: 'patch', validate: createEnumValidator(VERSION_BUMPS) },
113
- schedule_type: { type: 'string' as const, default: 'once', validate: createEnumValidator(SCHEDULE_TYPES) },
114
- scheduled_at: { type: 'string' as const, required: true as const },
115
- auto_trigger: { type: 'boolean' as const, default: true },
116
- hours_interval: { type: 'number' as const, default: 1 },
117
- notes: { type: 'string' as const },
118
- git_ref: { type: 'string' as const },
119
- };
120
-
121
- const getScheduledDeploymentsSchema = {
122
- project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
123
- include_disabled: { type: 'boolean' as const, default: false },
124
- limit: { type: 'number' as const, default: 50 },
125
- offset: { type: 'number' as const, default: 0 },
126
- };
127
-
128
- const updateScheduledDeploymentSchema = {
129
- schedule_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
130
- environment: { type: 'string' as const, validate: createEnumValidator(ENVIRONMENTS) },
131
- version_bump: { type: 'string' as const, validate: createEnumValidator(VERSION_BUMPS) },
132
- schedule_type: { type: 'string' as const, validate: createEnumValidator(SCHEDULE_TYPES) },
133
- scheduled_at: { type: 'string' as const },
134
- auto_trigger: { type: 'boolean' as const },
135
- hours_interval: { type: 'number' as const },
136
- enabled: { type: 'boolean' as const },
137
- notes: { type: 'string' as const },
138
- git_ref: { type: 'string' as const },
139
- };
140
-
141
- const deleteScheduledDeploymentSchema = {
142
- schedule_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
143
- };
144
-
145
- const triggerScheduledDeploymentSchema = {
146
- schedule_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
147
- };
148
-
149
- const checkDueDeploymentsSchema = {
150
- project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
151
- };
152
-
153
- export const requestDeployment: Handler = async (args, ctx) => {
154
- const { project_id, environment, version_bump, notes, git_ref } = parseArgs(args, requestDeploymentSchema);
155
- const { session } = ctx;
156
-
157
- const apiClient = getApiClient();
158
- const response = await apiClient.requestDeployment(project_id, {
159
- environment,
160
- version_bump,
161
- notes,
162
- git_ref
163
- });
164
-
165
- if (!response.ok) {
166
- return { result: { error: response.error || 'Failed to request deployment' }, isError: true };
167
- }
168
-
169
- return { result: response.data };
170
- };
171
-
172
- export const claimDeploymentValidation: Handler = async (args, ctx) => {
173
- const { project_id } = parseArgs(args, claimDeploymentValidationSchema);
174
- const { session } = ctx;
175
-
176
- const apiClient = getApiClient();
177
- const response = await apiClient.claimDeploymentValidation(
178
- project_id,
179
- session.currentSessionId || undefined
180
- );
181
-
182
- if (!response.ok) {
183
- return { result: { error: response.error || 'Failed to claim deployment validation' }, isError: true };
184
- }
185
-
186
- return { result: response.data };
187
- };
188
-
189
- export const reportValidation: Handler = async (args, ctx) => {
190
- const { project_id, build_passed, tests_passed, error_message } = parseArgs(args, reportValidationSchema);
191
- const { session } = ctx;
192
-
193
- const apiClient = getApiClient();
194
- const response = await apiClient.reportValidation(project_id, {
195
- build_passed,
196
- tests_passed: tests_passed ?? true,
197
- error_message
198
- });
199
-
200
- if (!response.ok) {
201
- return { result: { error: response.error || 'Failed to report validation' }, isError: true };
202
- }
203
-
204
- return { result: response.data };
205
- };
206
-
207
- export const checkDeploymentStatus: Handler = async (args, ctx) => {
208
- const { project_id } = parseArgs(args, checkDeploymentStatusSchema);
209
-
210
- const apiClient = getApiClient();
211
- const response = await apiClient.checkDeploymentStatus(project_id);
212
-
213
- if (!response.ok) {
214
- return { result: { error: response.error || 'Failed to check deployment status' }, isError: true };
215
- }
216
-
217
- return { result: response.data };
218
- };
219
-
220
- export const startDeployment: Handler = async (args, ctx) => {
221
- const { project_id } = parseArgs(args, startDeploymentSchema);
222
- const { session } = ctx;
223
-
224
- const apiClient = getApiClient();
225
- const response = await apiClient.startDeployment(
226
- project_id,
227
- session.currentSessionId || undefined
228
- );
229
-
230
- if (!response.ok) {
231
- return { result: { error: response.error || 'Failed to start deployment' }, isError: true };
232
- }
233
-
234
- return { result: response.data };
235
- };
236
-
237
- export const completeDeployment: Handler = async (args, ctx) => {
238
- const { project_id, success, summary } = parseArgs(args, completeDeploymentSchema);
239
- const { session } = ctx;
240
-
241
- const apiClient = getApiClient();
242
- const response = await apiClient.completeDeployment(project_id, {
243
- success,
244
- summary
245
- });
246
-
247
- if (!response.ok) {
248
- return { result: { error: response.error || 'Failed to complete deployment' }, isError: true };
249
- }
250
-
251
- return { result: response.data };
252
- };
253
-
254
- export const cancelDeployment: Handler = async (args, ctx) => {
255
- const { project_id, reason } = parseArgs(args, cancelDeploymentSchema);
256
-
257
- const apiClient = getApiClient();
258
- const response = await apiClient.cancelDeployment(project_id, reason);
259
-
260
- if (!response.ok) {
261
- return { result: { error: response.error || 'Failed to cancel deployment' }, isError: true };
262
- }
263
-
264
- return { result: response.data };
265
- };
266
-
267
- export const addDeploymentRequirement: Handler = async (args, ctx) => {
268
- const { project_id, type, title, description, file_path, stage, blocking, recurring } = parseArgs(args, addDeploymentRequirementSchema);
269
-
270
- const apiClient = getApiClient();
271
- const response = await apiClient.addDeploymentRequirement(project_id, {
272
- type: type as 'migration' | 'env_var' | 'config' | 'manual' | 'breaking_change' | 'agent_task',
273
- title,
274
- description,
275
- file_path,
276
- stage: stage as 'preparation' | 'deployment' | 'verification',
277
- blocking,
278
- recurring
279
- });
280
-
281
- if (!response.ok) {
282
- return { result: { error: response.error || 'Failed to add deployment requirement' }, isError: true };
283
- }
284
-
285
- return { result: response.data };
286
- };
287
-
288
- export const completeDeploymentRequirement: Handler = async (args, ctx) => {
289
- const { requirement_id } = parseArgs(args, completeDeploymentRequirementSchema);
290
-
291
- const apiClient = getApiClient();
292
- const response = await apiClient.completeDeploymentRequirement(requirement_id);
293
-
294
- if (!response.ok) {
295
- return { result: { error: response.error || 'Failed to complete deployment requirement' }, isError: true };
296
- }
297
-
298
- return { result: response.data };
299
- };
300
-
301
- export const getDeploymentRequirements: Handler = async (args, ctx) => {
302
- const { project_id, status, stage, limit, offset } = parseArgs(args, getDeploymentRequirementsSchema);
303
-
304
- const apiClient = getApiClient();
305
- const response = await apiClient.getDeploymentRequirements(project_id, {
306
- status: status as 'pending' | 'completed' | 'converted_to_task' | 'all',
307
- stage: stage as 'preparation' | 'deployment' | 'verification' | 'all' | undefined,
308
- limit,
309
- offset
310
- });
311
-
312
- if (!response.ok) {
313
- return { result: { error: response.error || 'Failed to get deployment requirements' }, isError: true };
314
- }
315
-
316
- return { result: response.data };
317
- };
318
-
319
- /**
320
- * Get aggregate statistics about deployment requirements for a project.
321
- * Returns total count and breakdowns by status, stage, and type.
322
- * More token-efficient than get_deployment_requirements when you just need to understand the overall state.
323
- */
324
- export const getDeploymentRequirementsStats: Handler = async (args, ctx) => {
325
- const { project_id } = parseArgs(args, getDeploymentRequirementsStatsSchema);
326
-
327
- const apiClient = getApiClient();
328
- const response = await apiClient.getDeploymentRequirementsStats(project_id);
329
-
330
- if (!response.ok) {
331
- return { result: { error: response.error || 'Failed to get deployment requirements stats' }, isError: true };
332
- }
333
-
334
- return { result: response.data };
335
- };
336
-
337
- // ============================================================================
338
- // Scheduled Deployments
339
- // ============================================================================
340
-
341
- export const scheduleDeployment: Handler = async (args, ctx) => {
342
- const {
343
- project_id,
344
- environment,
345
- version_bump,
346
- schedule_type,
347
- scheduled_at,
348
- auto_trigger,
349
- hours_interval,
350
- notes,
351
- git_ref,
352
- } = parseArgs(args, scheduleDeploymentSchema);
353
-
354
- // Parse and validate scheduled_at
355
- const scheduledDate = new Date(scheduled_at);
356
- if (isNaN(scheduledDate.getTime())) {
357
- throw new ValidationError('Invalid scheduled_at date format', {
358
- field: 'scheduled_at',
359
- hint: 'Use ISO 8601 format, e.g., 2025-01-15T14:00:00Z',
360
- });
361
- }
362
-
363
- if (scheduledDate.getTime() <= Date.now()) {
364
- throw new ValidationError('scheduled_at must be in the future', {
365
- field: 'scheduled_at',
366
- });
367
- }
368
-
369
- // Validate hours_interval for hourly schedule type (default is 1)
370
- const hoursInterval = hours_interval ?? 1;
371
- if (schedule_type === 'hourly' && (hoursInterval < 1 || hoursInterval > 24)) {
372
- throw new ValidationError('hours_interval must be between 1 and 24', {
373
- field: 'hours_interval',
374
- });
375
- }
376
-
377
- const apiClient = getApiClient();
378
- const response = await apiClient.scheduleDeployment(project_id, {
379
- environment: environment as 'development' | 'staging' | 'production',
380
- version_bump: version_bump as 'patch' | 'minor' | 'major',
381
- schedule_type: schedule_type as 'once' | 'hourly' | 'daily' | 'weekly' | 'monthly',
382
- scheduled_at: scheduledDate.toISOString(),
383
- auto_trigger,
384
- hours_interval: hoursInterval,
385
- notes,
386
- git_ref
387
- });
388
-
389
- if (!response.ok) {
390
- return { result: { error: response.error || 'Failed to schedule deployment' }, isError: true };
391
- }
392
-
393
- return { result: response.data };
394
- };
395
-
396
- export const getScheduledDeployments: Handler = async (args, ctx) => {
397
- const { project_id, include_disabled, limit, offset } = parseArgs(args, getScheduledDeploymentsSchema);
398
-
399
- const apiClient = getApiClient();
400
- const response = await apiClient.getScheduledDeployments(project_id, {
401
- includeDisabled: include_disabled,
402
- limit,
403
- offset
404
- });
405
-
406
- if (!response.ok) {
407
- return { result: { error: response.error || 'Failed to get scheduled deployments' }, isError: true };
408
- }
409
-
410
- return { result: response.data };
411
- };
412
-
413
- export const updateScheduledDeployment: Handler = async (args, ctx) => {
414
- const {
415
- schedule_id,
416
- environment,
417
- version_bump,
418
- schedule_type,
419
- scheduled_at,
420
- auto_trigger,
421
- hours_interval,
422
- enabled,
423
- notes,
424
- git_ref,
425
- } = parseArgs(args, updateScheduledDeploymentSchema);
426
-
427
- const updates: Record<string, unknown> = {};
428
-
429
- if (environment !== undefined) updates.environment = environment;
430
- if (version_bump !== undefined) updates.version_bump = version_bump;
431
- if (schedule_type !== undefined) updates.schedule_type = schedule_type;
432
-
433
- if (scheduled_at !== undefined) {
434
- const scheduledDate = new Date(scheduled_at);
435
- if (isNaN(scheduledDate.getTime())) {
436
- throw new ValidationError('Invalid scheduled_at date format');
437
- }
438
- updates.scheduled_at = scheduledDate.toISOString();
439
- }
440
-
441
- if (auto_trigger !== undefined) updates.auto_trigger = auto_trigger;
442
- if (hours_interval !== undefined) {
443
- if (hours_interval < 1 || hours_interval > 24) {
444
- throw new ValidationError('hours_interval must be between 1 and 24');
445
- }
446
- updates.hours_interval = hours_interval;
447
- }
448
- if (enabled !== undefined) updates.enabled = enabled;
449
- if (notes !== undefined) updates.notes = notes;
450
- if (git_ref !== undefined) updates.git_ref = git_ref;
451
-
452
- if (Object.keys(updates).length === 0) {
453
- return { result: { success: false, error: 'No updates provided' } };
454
- }
455
-
456
- const apiClient = getApiClient();
457
- const response = await apiClient.updateScheduledDeployment(schedule_id, updates as {
458
- environment?: 'development' | 'staging' | 'production';
459
- version_bump?: 'patch' | 'minor' | 'major';
460
- schedule_type?: 'once' | 'hourly' | 'daily' | 'weekly' | 'monthly';
461
- scheduled_at?: string;
462
- auto_trigger?: boolean;
463
- hours_interval?: number;
464
- enabled?: boolean;
465
- notes?: string;
466
- git_ref?: string;
467
- });
468
-
469
- if (!response.ok) {
470
- return { result: { error: response.error || 'Failed to update scheduled deployment' }, isError: true };
471
- }
472
-
473
- return { result: response.data };
474
- };
475
-
476
- export const deleteScheduledDeployment: Handler = async (args, ctx) => {
477
- const { schedule_id } = parseArgs(args, deleteScheduledDeploymentSchema);
478
-
479
- const apiClient = getApiClient();
480
- const response = await apiClient.deleteScheduledDeployment(schedule_id);
481
-
482
- if (!response.ok) {
483
- return { result: { error: response.error || 'Failed to delete scheduled deployment' }, isError: true };
484
- }
485
-
486
- return { result: response.data };
487
- };
488
-
489
- export const triggerScheduledDeployment: Handler = async (args, ctx) => {
490
- const { schedule_id } = parseArgs(args, triggerScheduledDeploymentSchema);
491
- const { session } = ctx;
492
-
493
- const apiClient = getApiClient();
494
- const response = await apiClient.triggerScheduledDeployment(
495
- schedule_id,
496
- session.currentSessionId || undefined
497
- );
498
-
499
- if (!response.ok) {
500
- return { result: { error: response.error || 'Failed to trigger scheduled deployment' }, isError: true };
501
- }
502
-
503
- return { result: response.data };
504
- };
505
-
506
- export const checkDueDeployments: Handler = async (args, ctx) => {
507
- const { project_id } = parseArgs(args, checkDueDeploymentsSchema);
508
-
509
- const apiClient = getApiClient();
510
- const response = await apiClient.checkDueDeployments(project_id);
511
-
512
- if (!response.ok) {
513
- return { result: { error: response.error || 'Failed to check due deployments' }, isError: true };
514
- }
515
-
516
- return { result: response.data };
517
- };
518
-
519
- /**
520
- * Deployment handlers registry
521
- */
522
- export const deploymentHandlers: HandlerRegistry = {
523
- request_deployment: requestDeployment,
524
- claim_deployment_validation: claimDeploymentValidation,
525
- report_validation: reportValidation,
526
- check_deployment_status: checkDeploymentStatus,
527
- start_deployment: startDeployment,
528
- complete_deployment: completeDeployment,
529
- cancel_deployment: cancelDeployment,
530
- add_deployment_requirement: addDeploymentRequirement,
531
- complete_deployment_requirement: completeDeploymentRequirement,
532
- get_deployment_requirements: getDeploymentRequirements,
533
- get_deployment_requirements_stats: getDeploymentRequirementsStats,
534
- // Scheduled deployments
535
- schedule_deployment: scheduleDeployment,
536
- get_scheduled_deployments: getScheduledDeployments,
537
- update_scheduled_deployment: updateScheduledDeployment,
538
- delete_scheduled_deployment: deleteScheduledDeployment,
539
- trigger_scheduled_deployment: triggerScheduledDeployment,
540
- check_due_deployments: checkDueDeployments,
541
- };
1
+ /**
2
+ * Deployment Handlers
3
+ *
4
+ * Handles deployment coordination and requirements:
5
+ * - request_deployment
6
+ * - claim_deployment_validation
7
+ * - report_validation
8
+ * - check_deployment_status
9
+ * - start_deployment
10
+ * - complete_deployment
11
+ * - cancel_deployment
12
+ * - add_deployment_requirement
13
+ * - complete_deployment_requirement
14
+ * - get_deployment_requirements
15
+ */
16
+
17
+ import type { Handler, HandlerRegistry } from './types.js';
18
+ import {
19
+ ValidationError,
20
+ parseArgs,
21
+ uuidValidator,
22
+ createEnumValidator,
23
+ } from '../validators.js';
24
+ import { getApiClient } from '../api-client.js';
25
+
26
+ const ENVIRONMENTS = ['development', 'staging', 'production'] as const;
27
+ const VERSION_BUMPS = ['patch', 'minor', 'major'] as const;
28
+ const REQUIREMENT_TYPES = ['migration', 'env_var', 'config', 'manual', 'breaking_change', 'agent_task'] as const;
29
+ const REQUIREMENT_STAGES = ['preparation', 'deployment', 'verification'] as const;
30
+ const REQUIREMENT_STATUSES = ['pending', 'completed', 'converted_to_task', 'all'] as const;
31
+ const SCHEDULE_TYPES = ['once', 'hourly', 'daily', 'weekly', 'monthly'] as const;
32
+
33
+ type Environment = typeof ENVIRONMENTS[number];
34
+ type VersionBump = typeof VERSION_BUMPS[number];
35
+ type RequirementType = typeof REQUIREMENT_TYPES[number];
36
+ type RequirementStage = typeof REQUIREMENT_STAGES[number];
37
+ type RequirementStatus = typeof REQUIREMENT_STATUSES[number];
38
+ type ScheduleType = typeof SCHEDULE_TYPES[number];
39
+
40
+ // ============================================================================
41
+ // Argument Schemas
42
+ // ============================================================================
43
+
44
+ const requestDeploymentSchema = {
45
+ project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
46
+ environment: { type: 'string' as const, default: 'production', validate: createEnumValidator(ENVIRONMENTS) },
47
+ version_bump: { type: 'string' as const, default: 'patch', validate: createEnumValidator(VERSION_BUMPS) },
48
+ notes: { type: 'string' as const },
49
+ git_ref: { type: 'string' as const },
50
+ };
51
+
52
+ const claimDeploymentValidationSchema = {
53
+ project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
54
+ };
55
+
56
+ const reportValidationSchema = {
57
+ project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
58
+ build_passed: { type: 'boolean' as const, required: true as const },
59
+ tests_passed: { type: 'boolean' as const },
60
+ error_message: { type: 'string' as const },
61
+ };
62
+
63
+ const checkDeploymentStatusSchema = {
64
+ project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
65
+ };
66
+
67
+ const startDeploymentSchema = {
68
+ project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
69
+ };
70
+
71
+ const completeDeploymentSchema = {
72
+ project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
73
+ success: { type: 'boolean' as const, required: true as const },
74
+ summary: { type: 'string' as const },
75
+ };
76
+
77
+ const cancelDeploymentSchema = {
78
+ project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
79
+ reason: { type: 'string' as const },
80
+ };
81
+
82
+ const addDeploymentRequirementSchema = {
83
+ project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
84
+ type: { type: 'string' as const, required: true as const, validate: createEnumValidator(REQUIREMENT_TYPES) },
85
+ title: { type: 'string' as const, required: true as const },
86
+ description: { type: 'string' as const },
87
+ file_path: { type: 'string' as const },
88
+ stage: { type: 'string' as const, default: 'preparation', validate: createEnumValidator(REQUIREMENT_STAGES) },
89
+ blocking: { type: 'boolean' as const, default: false },
90
+ recurring: { type: 'boolean' as const, default: true },
91
+ };
92
+
93
+ const completeDeploymentRequirementSchema = {
94
+ requirement_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
95
+ };
96
+
97
+ const getDeploymentRequirementsSchema = {
98
+ project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
99
+ status: { type: 'string' as const, default: 'pending', validate: createEnumValidator(REQUIREMENT_STATUSES) },
100
+ stage: { type: 'string' as const, validate: createEnumValidator([...REQUIREMENT_STAGES, 'all'] as const) },
101
+ limit: { type: 'number' as const, default: 50 },
102
+ offset: { type: 'number' as const, default: 0 },
103
+ };
104
+
105
+ const getDeploymentRequirementsStatsSchema = {
106
+ project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
107
+ };
108
+
109
+ const scheduleDeploymentSchema = {
110
+ project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
111
+ environment: { type: 'string' as const, default: 'production', validate: createEnumValidator(ENVIRONMENTS) },
112
+ version_bump: { type: 'string' as const, default: 'patch', validate: createEnumValidator(VERSION_BUMPS) },
113
+ schedule_type: { type: 'string' as const, default: 'once', validate: createEnumValidator(SCHEDULE_TYPES) },
114
+ scheduled_at: { type: 'string' as const, required: true as const },
115
+ auto_trigger: { type: 'boolean' as const, default: true },
116
+ hours_interval: { type: 'number' as const, default: 1 },
117
+ notes: { type: 'string' as const },
118
+ git_ref: { type: 'string' as const },
119
+ };
120
+
121
+ const getScheduledDeploymentsSchema = {
122
+ project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
123
+ include_disabled: { type: 'boolean' as const, default: false },
124
+ limit: { type: 'number' as const, default: 50 },
125
+ offset: { type: 'number' as const, default: 0 },
126
+ };
127
+
128
+ const updateScheduledDeploymentSchema = {
129
+ schedule_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
130
+ environment: { type: 'string' as const, validate: createEnumValidator(ENVIRONMENTS) },
131
+ version_bump: { type: 'string' as const, validate: createEnumValidator(VERSION_BUMPS) },
132
+ schedule_type: { type: 'string' as const, validate: createEnumValidator(SCHEDULE_TYPES) },
133
+ scheduled_at: { type: 'string' as const },
134
+ auto_trigger: { type: 'boolean' as const },
135
+ hours_interval: { type: 'number' as const },
136
+ enabled: { type: 'boolean' as const },
137
+ notes: { type: 'string' as const },
138
+ git_ref: { type: 'string' as const },
139
+ };
140
+
141
+ const deleteScheduledDeploymentSchema = {
142
+ schedule_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
143
+ };
144
+
145
+ const triggerScheduledDeploymentSchema = {
146
+ schedule_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
147
+ };
148
+
149
+ const checkDueDeploymentsSchema = {
150
+ project_id: { type: 'string' as const, required: true as const, validate: uuidValidator },
151
+ };
152
+
153
+ export const requestDeployment: Handler = async (args, ctx) => {
154
+ const { project_id, environment, version_bump, notes, git_ref } = parseArgs(args, requestDeploymentSchema);
155
+ const { session } = ctx;
156
+
157
+ const apiClient = getApiClient();
158
+ const response = await apiClient.requestDeployment(project_id, {
159
+ environment,
160
+ version_bump,
161
+ notes,
162
+ git_ref
163
+ });
164
+
165
+ if (!response.ok) {
166
+ return { result: { error: response.error || 'Failed to request deployment' }, isError: true };
167
+ }
168
+
169
+ return { result: response.data };
170
+ };
171
+
172
+ export const claimDeploymentValidation: Handler = async (args, ctx) => {
173
+ const { project_id } = parseArgs(args, claimDeploymentValidationSchema);
174
+ const { session } = ctx;
175
+
176
+ const apiClient = getApiClient();
177
+ const response = await apiClient.claimDeploymentValidation(
178
+ project_id,
179
+ session.currentSessionId || undefined
180
+ );
181
+
182
+ if (!response.ok) {
183
+ return { result: { error: response.error || 'Failed to claim deployment validation' }, isError: true };
184
+ }
185
+
186
+ return { result: response.data };
187
+ };
188
+
189
+ export const reportValidation: Handler = async (args, ctx) => {
190
+ const { project_id, build_passed, tests_passed, error_message } = parseArgs(args, reportValidationSchema);
191
+ const { session } = ctx;
192
+
193
+ const apiClient = getApiClient();
194
+ const response = await apiClient.reportValidation(project_id, {
195
+ build_passed,
196
+ tests_passed: tests_passed ?? true,
197
+ error_message
198
+ });
199
+
200
+ if (!response.ok) {
201
+ return { result: { error: response.error || 'Failed to report validation' }, isError: true };
202
+ }
203
+
204
+ return { result: response.data };
205
+ };
206
+
207
+ export const checkDeploymentStatus: Handler = async (args, ctx) => {
208
+ const { project_id } = parseArgs(args, checkDeploymentStatusSchema);
209
+
210
+ const apiClient = getApiClient();
211
+ const response = await apiClient.checkDeploymentStatus(project_id);
212
+
213
+ if (!response.ok) {
214
+ return { result: { error: response.error || 'Failed to check deployment status' }, isError: true };
215
+ }
216
+
217
+ return { result: response.data };
218
+ };
219
+
220
+ export const startDeployment: Handler = async (args, ctx) => {
221
+ const { project_id } = parseArgs(args, startDeploymentSchema);
222
+ const { session } = ctx;
223
+
224
+ const apiClient = getApiClient();
225
+ const response = await apiClient.startDeployment(
226
+ project_id,
227
+ session.currentSessionId || undefined
228
+ );
229
+
230
+ if (!response.ok) {
231
+ return { result: { error: response.error || 'Failed to start deployment' }, isError: true };
232
+ }
233
+
234
+ return { result: response.data };
235
+ };
236
+
237
+ export const completeDeployment: Handler = async (args, ctx) => {
238
+ const { project_id, success, summary } = parseArgs(args, completeDeploymentSchema);
239
+ const { session } = ctx;
240
+
241
+ const apiClient = getApiClient();
242
+ const response = await apiClient.completeDeployment(project_id, {
243
+ success,
244
+ summary
245
+ });
246
+
247
+ if (!response.ok) {
248
+ return { result: { error: response.error || 'Failed to complete deployment' }, isError: true };
249
+ }
250
+
251
+ return { result: response.data };
252
+ };
253
+
254
+ export const cancelDeployment: Handler = async (args, ctx) => {
255
+ const { project_id, reason } = parseArgs(args, cancelDeploymentSchema);
256
+
257
+ const apiClient = getApiClient();
258
+ const response = await apiClient.cancelDeployment(project_id, reason);
259
+
260
+ if (!response.ok) {
261
+ return { result: { error: response.error || 'Failed to cancel deployment' }, isError: true };
262
+ }
263
+
264
+ return { result: response.data };
265
+ };
266
+
267
+ export const addDeploymentRequirement: Handler = async (args, ctx) => {
268
+ const { project_id, type, title, description, file_path, stage, blocking, recurring } = parseArgs(args, addDeploymentRequirementSchema);
269
+
270
+ const apiClient = getApiClient();
271
+ const response = await apiClient.addDeploymentRequirement(project_id, {
272
+ type: type as 'migration' | 'env_var' | 'config' | 'manual' | 'breaking_change' | 'agent_task',
273
+ title,
274
+ description,
275
+ file_path,
276
+ stage: stage as 'preparation' | 'deployment' | 'verification',
277
+ blocking,
278
+ recurring
279
+ });
280
+
281
+ if (!response.ok) {
282
+ return { result: { error: response.error || 'Failed to add deployment requirement' }, isError: true };
283
+ }
284
+
285
+ return { result: response.data };
286
+ };
287
+
288
+ export const completeDeploymentRequirement: Handler = async (args, ctx) => {
289
+ const { requirement_id } = parseArgs(args, completeDeploymentRequirementSchema);
290
+
291
+ const apiClient = getApiClient();
292
+ const response = await apiClient.completeDeploymentRequirement(requirement_id);
293
+
294
+ if (!response.ok) {
295
+ return { result: { error: response.error || 'Failed to complete deployment requirement' }, isError: true };
296
+ }
297
+
298
+ return { result: response.data };
299
+ };
300
+
301
+ export const getDeploymentRequirements: Handler = async (args, ctx) => {
302
+ const { project_id, status, stage, limit, offset } = parseArgs(args, getDeploymentRequirementsSchema);
303
+
304
+ const apiClient = getApiClient();
305
+ const response = await apiClient.getDeploymentRequirements(project_id, {
306
+ status: status as 'pending' | 'completed' | 'converted_to_task' | 'all',
307
+ stage: stage as 'preparation' | 'deployment' | 'verification' | 'all' | undefined,
308
+ limit,
309
+ offset
310
+ });
311
+
312
+ if (!response.ok) {
313
+ return { result: { error: response.error || 'Failed to get deployment requirements' }, isError: true };
314
+ }
315
+
316
+ return { result: response.data };
317
+ };
318
+
319
+ /**
320
+ * Get aggregate statistics about deployment requirements for a project.
321
+ * Returns total count and breakdowns by status, stage, and type.
322
+ * More token-efficient than get_deployment_requirements when you just need to understand the overall state.
323
+ */
324
+ export const getDeploymentRequirementsStats: Handler = async (args, ctx) => {
325
+ const { project_id } = parseArgs(args, getDeploymentRequirementsStatsSchema);
326
+
327
+ const apiClient = getApiClient();
328
+ const response = await apiClient.getDeploymentRequirementsStats(project_id);
329
+
330
+ if (!response.ok) {
331
+ return { result: { error: response.error || 'Failed to get deployment requirements stats' }, isError: true };
332
+ }
333
+
334
+ return { result: response.data };
335
+ };
336
+
337
+ // ============================================================================
338
+ // Scheduled Deployments
339
+ // ============================================================================
340
+
341
+ export const scheduleDeployment: Handler = async (args, ctx) => {
342
+ const {
343
+ project_id,
344
+ environment,
345
+ version_bump,
346
+ schedule_type,
347
+ scheduled_at,
348
+ auto_trigger,
349
+ hours_interval,
350
+ notes,
351
+ git_ref,
352
+ } = parseArgs(args, scheduleDeploymentSchema);
353
+
354
+ // Parse and validate scheduled_at
355
+ const scheduledDate = new Date(scheduled_at);
356
+ if (isNaN(scheduledDate.getTime())) {
357
+ throw new ValidationError('Invalid scheduled_at date format', {
358
+ field: 'scheduled_at',
359
+ hint: 'Use ISO 8601 format, e.g., 2025-01-15T14:00:00Z',
360
+ });
361
+ }
362
+
363
+ if (scheduledDate.getTime() <= Date.now()) {
364
+ throw new ValidationError('scheduled_at must be in the future', {
365
+ field: 'scheduled_at',
366
+ });
367
+ }
368
+
369
+ // Validate hours_interval for hourly schedule type (default is 1)
370
+ const hoursInterval = hours_interval ?? 1;
371
+ if (schedule_type === 'hourly' && (hoursInterval < 1 || hoursInterval > 24)) {
372
+ throw new ValidationError('hours_interval must be between 1 and 24', {
373
+ field: 'hours_interval',
374
+ });
375
+ }
376
+
377
+ const apiClient = getApiClient();
378
+ const response = await apiClient.scheduleDeployment(project_id, {
379
+ environment: environment as 'development' | 'staging' | 'production',
380
+ version_bump: version_bump as 'patch' | 'minor' | 'major',
381
+ schedule_type: schedule_type as 'once' | 'hourly' | 'daily' | 'weekly' | 'monthly',
382
+ scheduled_at: scheduledDate.toISOString(),
383
+ auto_trigger,
384
+ hours_interval: hoursInterval,
385
+ notes,
386
+ git_ref
387
+ });
388
+
389
+ if (!response.ok) {
390
+ return { result: { error: response.error || 'Failed to schedule deployment' }, isError: true };
391
+ }
392
+
393
+ return { result: response.data };
394
+ };
395
+
396
+ export const getScheduledDeployments: Handler = async (args, ctx) => {
397
+ const { project_id, include_disabled, limit, offset } = parseArgs(args, getScheduledDeploymentsSchema);
398
+
399
+ const apiClient = getApiClient();
400
+ const response = await apiClient.getScheduledDeployments(project_id, {
401
+ includeDisabled: include_disabled,
402
+ limit,
403
+ offset
404
+ });
405
+
406
+ if (!response.ok) {
407
+ return { result: { error: response.error || 'Failed to get scheduled deployments' }, isError: true };
408
+ }
409
+
410
+ return { result: response.data };
411
+ };
412
+
413
+ export const updateScheduledDeployment: Handler = async (args, ctx) => {
414
+ const {
415
+ schedule_id,
416
+ environment,
417
+ version_bump,
418
+ schedule_type,
419
+ scheduled_at,
420
+ auto_trigger,
421
+ hours_interval,
422
+ enabled,
423
+ notes,
424
+ git_ref,
425
+ } = parseArgs(args, updateScheduledDeploymentSchema);
426
+
427
+ const updates: Record<string, unknown> = {};
428
+
429
+ if (environment !== undefined) updates.environment = environment;
430
+ if (version_bump !== undefined) updates.version_bump = version_bump;
431
+ if (schedule_type !== undefined) updates.schedule_type = schedule_type;
432
+
433
+ if (scheduled_at !== undefined) {
434
+ const scheduledDate = new Date(scheduled_at);
435
+ if (isNaN(scheduledDate.getTime())) {
436
+ throw new ValidationError('Invalid scheduled_at date format');
437
+ }
438
+ updates.scheduled_at = scheduledDate.toISOString();
439
+ }
440
+
441
+ if (auto_trigger !== undefined) updates.auto_trigger = auto_trigger;
442
+ if (hours_interval !== undefined) {
443
+ if (hours_interval < 1 || hours_interval > 24) {
444
+ throw new ValidationError('hours_interval must be between 1 and 24');
445
+ }
446
+ updates.hours_interval = hours_interval;
447
+ }
448
+ if (enabled !== undefined) updates.enabled = enabled;
449
+ if (notes !== undefined) updates.notes = notes;
450
+ if (git_ref !== undefined) updates.git_ref = git_ref;
451
+
452
+ if (Object.keys(updates).length === 0) {
453
+ return { result: { success: false, error: 'No updates provided' } };
454
+ }
455
+
456
+ const apiClient = getApiClient();
457
+ const response = await apiClient.updateScheduledDeployment(schedule_id, updates as {
458
+ environment?: 'development' | 'staging' | 'production';
459
+ version_bump?: 'patch' | 'minor' | 'major';
460
+ schedule_type?: 'once' | 'hourly' | 'daily' | 'weekly' | 'monthly';
461
+ scheduled_at?: string;
462
+ auto_trigger?: boolean;
463
+ hours_interval?: number;
464
+ enabled?: boolean;
465
+ notes?: string;
466
+ git_ref?: string;
467
+ });
468
+
469
+ if (!response.ok) {
470
+ return { result: { error: response.error || 'Failed to update scheduled deployment' }, isError: true };
471
+ }
472
+
473
+ return { result: response.data };
474
+ };
475
+
476
+ export const deleteScheduledDeployment: Handler = async (args, ctx) => {
477
+ const { schedule_id } = parseArgs(args, deleteScheduledDeploymentSchema);
478
+
479
+ const apiClient = getApiClient();
480
+ const response = await apiClient.deleteScheduledDeployment(schedule_id);
481
+
482
+ if (!response.ok) {
483
+ return { result: { error: response.error || 'Failed to delete scheduled deployment' }, isError: true };
484
+ }
485
+
486
+ return { result: response.data };
487
+ };
488
+
489
+ export const triggerScheduledDeployment: Handler = async (args, ctx) => {
490
+ const { schedule_id } = parseArgs(args, triggerScheduledDeploymentSchema);
491
+ const { session } = ctx;
492
+
493
+ const apiClient = getApiClient();
494
+ const response = await apiClient.triggerScheduledDeployment(
495
+ schedule_id,
496
+ session.currentSessionId || undefined
497
+ );
498
+
499
+ if (!response.ok) {
500
+ return { result: { error: response.error || 'Failed to trigger scheduled deployment' }, isError: true };
501
+ }
502
+
503
+ return { result: response.data };
504
+ };
505
+
506
+ export const checkDueDeployments: Handler = async (args, ctx) => {
507
+ const { project_id } = parseArgs(args, checkDueDeploymentsSchema);
508
+
509
+ const apiClient = getApiClient();
510
+ const response = await apiClient.checkDueDeployments(project_id);
511
+
512
+ if (!response.ok) {
513
+ return { result: { error: response.error || 'Failed to check due deployments' }, isError: true };
514
+ }
515
+
516
+ return { result: response.data };
517
+ };
518
+
519
+ /**
520
+ * Deployment handlers registry
521
+ */
522
+ export const deploymentHandlers: HandlerRegistry = {
523
+ request_deployment: requestDeployment,
524
+ claim_deployment_validation: claimDeploymentValidation,
525
+ report_validation: reportValidation,
526
+ check_deployment_status: checkDeploymentStatus,
527
+ start_deployment: startDeployment,
528
+ complete_deployment: completeDeployment,
529
+ cancel_deployment: cancelDeployment,
530
+ add_deployment_requirement: addDeploymentRequirement,
531
+ complete_deployment_requirement: completeDeploymentRequirement,
532
+ get_deployment_requirements: getDeploymentRequirements,
533
+ get_deployment_requirements_stats: getDeploymentRequirementsStats,
534
+ // Scheduled deployments
535
+ schedule_deployment: scheduleDeployment,
536
+ get_scheduled_deployments: getScheduledDeployments,
537
+ update_scheduled_deployment: updateScheduledDeployment,
538
+ delete_scheduled_deployment: deleteScheduledDeployment,
539
+ trigger_scheduled_deployment: triggerScheduledDeployment,
540
+ check_due_deployments: checkDueDeployments,
541
+ };