@vibescope/mcp-server 0.5.0 → 0.5.2

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