Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 67x 67x 54x 13x 36x | import { z } from 'zod';
import { flexibleBoolean, paginationFields, requiredId, numericId } from '../utils';
import {
ARTIFACT_DEFAULT_BYTES,
ARTIFACT_MAX_BYTES,
ARTIFACT_MAX_OFFSET,
encodeArtifactPath,
} from './artifact-path';
// Pipeline related schemas
export const GitLabPipelineSchema = z.object({
id: z.coerce.string(),
project_id: z.coerce.string(),
sha: z.string(),
ref: z.string(),
status: z.string(),
source: z.string().optional(),
created_at: z.string(),
updated_at: z.string(),
web_url: z.string(),
duration: z.number().nullable().optional(),
started_at: z.string().nullable().optional(),
finished_at: z.string().nullable().optional(),
coverage: z.coerce.number().nullable().optional(),
user: z
.object({
id: z.coerce.string(),
name: z.string(),
username: z.string(),
avatar_url: z.string().nullable().optional(),
})
.optional(),
detailed_status: z
.object({
icon: z.string().optional(),
text: z.string().optional(),
label: z.string().optional(),
group: z.string().optional(),
tooltip: z.string().optional(),
has_details: flexibleBoolean.optional(),
details_path: z.string().optional(),
illustration: z
.object({
image: z.string().optional(),
size: z.string().optional(),
title: z.string().optional(),
})
.nullable()
.optional(),
favicon: z.string().optional(),
})
.optional(),
});
// Pipeline job related schemas
export const GitLabPipelineJobSchema = z.object({
id: z.coerce.string(),
status: z.string(),
stage: z.string(),
name: z.string(),
ref: z.string(),
tag: flexibleBoolean,
coverage: z.coerce.number().nullable().optional(),
allow_failure: flexibleBoolean.optional(),
created_at: z.string(),
started_at: z.string().optional(),
finished_at: z.string().optional(),
duration: z.number().optional(),
queued_duration: z.number().optional(),
user: z
.object({
id: z.coerce.string(),
name: z.string(),
username: z.string(),
state: z.string(),
avatar_url: z.string().nullable().optional(),
web_url: z.string(),
})
.optional(),
commit: z
.object({
id: z.string(),
short_id: z.string(),
title: z.string(),
author_name: z.string(),
author_email: z.string(),
created_at: z.string(),
message: z.string(),
})
.optional(),
pipeline: z
.object({
id: z.coerce.string(),
project_id: z.coerce.string(),
ref: z.string(),
sha: z.string(),
status: z.string(),
})
.optional(),
web_url: z.string(),
});
// Pipeline trigger job (bridge) schema
export const GitLabPipelineTriggerJobSchema = z.object({
id: z.coerce.string(),
status: z.string(),
stage: z.string(),
name: z.string(),
ref: z.string(),
tag: flexibleBoolean,
coverage: z.coerce.number().nullable().optional(),
allow_failure: flexibleBoolean.optional(),
created_at: z.string(),
started_at: z.string().optional(),
finished_at: z.string().optional(),
duration: z.number().optional(),
queued_duration: z.number().optional(),
user: z
.object({
id: z.coerce.string(),
name: z.string(),
username: z.string(),
state: z.string(),
avatar_url: z.string().nullable().optional(),
web_url: z.string(),
})
.optional(),
commit: z
.object({
id: z.string(),
short_id: z.string(),
title: z.string(),
author_name: z.string(),
author_email: z.string(),
created_at: z.string(),
message: z.string(),
})
.optional(),
pipeline: z
.object({
id: z.coerce.string(),
project_id: z.coerce.string(),
ref: z.string(),
sha: z.string(),
status: z.string(),
})
.optional(),
web_url: z.string(),
downstream_pipeline: z
.object({
id: z.coerce.string(),
sha: z.string(),
ref: z.string(),
status: z.string(),
created_at: z.string(),
updated_at: z.string(),
web_url: z.string(),
})
.optional(),
});
// ============================================================================
// Shared enums for pipeline filtering
// ============================================================================
const PipelineScopeSchema = z
.enum(['running', 'pending', 'finished', 'branches', 'tags'])
.describe('The scope of pipelines to return');
const PipelineStatusSchema = z
.enum([
'created',
'waiting_for_resource',
'preparing',
'pending',
'running',
'success',
'failed',
'canceled',
'skipped',
'manual',
'scheduled',
])
.describe('The status of pipelines to return');
const PipelineSourceSchema = z
.enum([
'push',
'web',
'trigger',
'schedule',
'api',
'external',
'chat',
'webide',
'merge_request_event',
'external_pull_request_event',
'parent_pipeline',
'ondemand_dast_scan',
'ondemand_dast_validation',
])
.describe('The source of pipelines');
const JobScopeSchema = z
.enum(['created', 'pending', 'running', 'failed', 'success', 'canceled', 'skipped', 'manual'])
.describe('Scope of jobs to show');
const TriggerJobScopeSchema = z
.enum([
'created',
'pending',
'running',
'failed',
'success',
'canceled',
'skipped',
'manual',
'waiting_for_resource',
'preparing',
])
.describe('Scope of trigger jobs to show');
// ============================================================================
// browse_pipelines - CQRS Query Tool (discriminated union schema)
// Actions: list, get, jobs, triggers, job, logs, artifact_file
// Uses z.discriminatedUnion() for type-safe action handling.
// Schema pipeline flattens to flat JSON Schema for AI clients that don't support oneOf.
// ============================================================================
// --- Shared fields ---
const projectIdField = requiredId.describe('Project ID or URL-encoded path');
// --- Action: list ---
const ListPipelinesSchema = z.object({
action: z.literal('list').describe('List pipelines with filtering'),
project_id: projectIdField,
scope: PipelineScopeSchema.optional().describe('Pipeline scope filter'),
status: PipelineStatusSchema.optional().describe('Pipeline status filter'),
source: PipelineSourceSchema.optional().describe('Pipeline source filter'),
ref: z.string().optional().describe('Filter by branch or tag ref'),
sha: z.string().optional().describe('Filter by SHA'),
yaml_errors: z.boolean().optional().describe('Filter by YAML errors'),
name: z.string().optional().describe('Filter by name of user who triggered pipeline'),
username: z.string().optional().describe('Filter by username who triggered pipeline'),
updated_after: z.string().optional().describe('ISO 8601 datetime to filter by updated_after'),
updated_before: z.string().optional().describe('ISO 8601 datetime to filter by updated_before'),
order_by: z
.enum(['id', 'status', 'ref', 'updated_at', 'user_id'])
.optional()
.describe('Order pipelines by'),
sort: z.enum(['asc', 'desc']).optional().describe('Sort order'),
...paginationFields(),
});
// --- Action: get ---
const GetPipelineSchema = z.object({
action: z.literal('get').describe('Get single pipeline details'),
project_id: projectIdField,
pipeline_id: numericId.describe('The ID of the pipeline'),
});
// --- Action: jobs ---
const ListPipelineJobsSchema = z.object({
action: z.literal('jobs').describe('List jobs in a pipeline'),
project_id: projectIdField,
pipeline_id: numericId.describe('The ID of the pipeline'),
job_scope: z.array(JobScopeSchema).optional().describe('Scope of jobs to show'),
include_retried: z.boolean().optional().describe('Include retried jobs in the response'),
...paginationFields(),
});
// --- Action: triggers ---
const ListPipelineTriggersSchema = z.object({
action: z.literal('triggers').describe('List bridge/trigger jobs in a pipeline'),
project_id: projectIdField,
pipeline_id: numericId.describe('The ID of the pipeline'),
trigger_scope: z
.array(TriggerJobScopeSchema)
.optional()
.describe('Scope of trigger jobs to show'),
include_retried: z.boolean().optional().describe('Include retried jobs in the response'),
...paginationFields(),
});
// --- Action: job ---
const GetJobSchema = z.object({
action: z.literal('job').describe('Get single job details'),
project_id: projectIdField,
job_id: numericId.describe('The ID of the job'),
});
// --- Action: logs ---
const GetJobLogsSchema = z.object({
action: z
.literal('logs')
.describe('Read job logs with bounded memory and explicit byte truncation'),
project_id: projectIdField,
job_id: numericId.describe('The ID of the job'),
per_page: z
.number()
.int()
.min(1)
.max(10000)
.optional()
.describe(
'Maximum source lines to return (default: 200, max: 10000). Up to 16 KiB per line and 1 MiB per page of source bytes; omitted content is reported in truncation.lines. Use with start for pagination',
),
start: z
.number()
.int()
.optional()
.describe(
'Start from specific line number (0-based). Positive from beginning, negative from end (e.g., -100 = last 100 lines). Use nextStart from previous response to paginate',
),
});
const GetArtifactFileSchema = z.object({
action: z
.literal('artifact_file')
.describe(
'Read one artifact file as bounded UTF-8 text; inspect job metadata to choose its path',
),
project_id: projectIdField,
job_id: numericId.describe('The ID of the job that uploaded artifacts:paths'),
artifact_path: z
.string()
.min(1)
.max(4096)
.refine((path) => {
try {
encodeArtifactPath(path);
return true;
} catch {
return false;
}
}, 'Expected a relative artifact file path without traversal')
.describe(
'Relative path within artifacts:paths, such as reports/test-results.txt; reports-only uploads are not archive entries',
),
byte_offset: z
.number()
.int()
.min(0)
.max(ARTIFACT_MAX_OFFSET)
.default(0)
.describe(
'Source byte offset (default: 0, max: 20 MiB); use next_byte_offset to preserve UTF-8 boundaries',
),
byte_limit: z
.number()
.int()
.min(1)
.max(ARTIFACT_MAX_BYTES)
.default(ARTIFACT_DEFAULT_BYTES)
.describe(
'Maximum source bytes returned (default: 64 KiB, max: 1 MiB). An undersized window cannot split a UTF-8 character',
),
});
// --- Discriminated union combining all actions ---
export const BrowsePipelinesSchema = z.discriminatedUnion('action', [
ListPipelinesSchema,
GetPipelineSchema,
ListPipelineJobsSchema,
ListPipelineTriggersSchema,
GetJobSchema,
GetJobLogsSchema,
GetArtifactFileSchema,
]);
// ============================================================================
// Type exports
// ============================================================================
export type BrowsePipelinesInput = z.infer<typeof BrowsePipelinesSchema>;
export type GitLabPipeline = z.infer<typeof GitLabPipelineSchema>;
export type GitLabPipelineJob = z.infer<typeof GitLabPipelineJobSchema>;
export type GitLabPipelineTriggerJob = z.infer<typeof GitLabPipelineTriggerJobSchema>;
|