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 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 35x 7x 28x 35x 35x 27x 891x 1x 35x 32x 96x 1x 35x 8x 16x 1x 35x 31x 31x 1x 35x 25x 75x 3x 35x 7x 21x 2x 15x 15x 15x 15x | import { z } from "zod";
import { flexibleBoolean, requiredId, paginationFields } from "../utils";
// ============================================================================
// browse_merge_requests - CQRS Query Tool (discriminated union schema)
// Actions: list, get, diffs, compare, versions, version
// Uses z.discriminatedUnion() for type-safe action handling.
// Schema pipeline flattens to flat JSON Schema for AI clients that don't support oneOf.
// ============================================================================
// ============================================================================
// Diff Exclusion Pattern Presets
// Used by diffs action to filter out noise from MR diffs
// ============================================================================
/**
* Common lock file patterns that are auto-generated and don't require manual review.
* These files typically contain thousands of lines of dependency versioning info.
*/
export const LOCKFILE_PATTERNS = [
"yarn.lock",
"package-lock.json",
"pnpm-lock.yaml",
"Gemfile.lock",
"Cargo.lock",
"poetry.lock",
"composer.lock",
"go.sum",
"Pipfile.lock",
"bun.lockb",
"shrinkwrap.yaml",
] as const;
/**
* Common generated/build output patterns that are compiled or minified.
* These files are machine-generated and shouldn't need code review.
* Directory patterns match at repo root; extension patterns match anywhere.
*/
export const GENERATED_PATTERNS = [
"dist/**",
"build/**",
".next/**",
".nuxt/**",
".output/**",
"coverage/**",
"**/*.min.js",
"**/*.min.css",
"**/*.map",
"**/*.js.map",
"**/*.css.map",
] as const;
/**
* Export presets for documentation and external use.
*/
export const DIFF_EXCLUSION_PRESETS = {
lockfiles: LOCKFILE_PATTERNS,
generated: GENERATED_PATTERNS,
} as const;
// --- Shared fields ---
const projectIdField = requiredId.describe("Project ID or URL-encoded path");
const mergeRequestIidField = requiredId.describe("Internal MR ID unique to project");
// --- Shared optional fields for get/diffs actions ---
const includeDivergedCommitsCountField = flexibleBoolean
.optional()
.describe("Include count of commits the source branch is behind target");
const includeRebaseInProgressField = flexibleBoolean
.optional()
.describe("Check if MR is currently being rebased");
// --- Shared not filter schema for list action ---
const NotFilterSchema = z
.object({
labels: z.union([z.string(), z.array(z.string())]).optional(),
milestone: z.string().optional(),
author_id: z.number().optional(),
author_username: z.string().optional(),
assignee_id: z.number().optional(),
assignee_username: z.string().optional(),
my_reaction_emoji: z.string().optional(),
})
.describe("Exclusion filters");
// --- Action: list ---
// Note: .passthrough() preserves unknown fields for superRefine validation
const ListMergeRequestsSchema = z
.object({
action: z.literal("list").describe("List merge requests with filtering"),
project_id: z.coerce
.string()
.optional()
.describe("Project ID or URL-encoded path. Optional for cross-project search."),
state: z
.enum(["opened", "closed", "locked", "merged", "all"])
.optional()
.describe("MR state filter"),
order_by: z
.enum(["created_at", "updated_at", "title", "priority"])
.optional()
.describe("Sort field"),
sort: z.enum(["asc", "desc"]).optional().describe("Sort direction"),
milestone: z.string().optional().describe('Filter by milestone title. Use "None" or "Any".'),
view: z.enum(["simple", "full"]).optional().describe("Response detail level"),
labels: z
.union([z.string(), z.array(z.string())])
.optional()
.describe("Filter by labels"),
with_labels_details: flexibleBoolean.optional().describe("Return full label objects"),
with_merge_status_recheck: flexibleBoolean
.optional()
.describe("Trigger async recheck of merge status"),
created_after: z.string().optional().describe("Filter MRs created after (ISO 8601)"),
created_before: z.string().optional().describe("Filter MRs created before (ISO 8601)"),
updated_after: z.string().optional().describe("Filter MRs modified after (ISO 8601)"),
updated_before: z.string().optional().describe("Filter MRs modified before (ISO 8601)"),
scope: z.enum(["created_by_me", "assigned_to_me", "all"]).optional().describe("Filter scope"),
author_id: z.number().optional().describe("Filter by author's user ID"),
author_username: z.string().optional().describe("Filter by author's username"),
assignee_id: z.number().optional().describe("Filter by assignee's user ID"),
assignee_username: z.string().optional().describe("Filter by assignee's username"),
my_reaction_emoji: z.string().optional().describe("Filter MRs you've reacted to"),
source_branch: z.string().optional().describe("Filter by source branch"),
target_branch: z.string().optional().describe("Filter by target branch"),
search: z.string().optional().describe("Text search in title/description"),
in: z.enum(["title", "description", "title,description"]).optional().describe("Search scope"),
wip: z.enum(["yes", "no"]).optional().describe("Draft/WIP filter"),
not: NotFilterSchema.optional(),
environment: z.string().optional().describe("Filter by deployment environment"),
deployed_before: z.string().optional().describe("Filter MRs deployed before"),
deployed_after: z.string().optional().describe("Filter MRs deployed after"),
approved_by_ids: z.array(z.string()).optional().describe("Filter MRs approved by user IDs"),
approved_by_usernames: z
.array(z.string())
.optional()
.describe("Filter MRs approved by usernames"),
reviewer_id: z.number().optional().describe("Filter by reviewer user ID"),
reviewer_username: z.string().optional().describe("Filter by reviewer username"),
with_api_entity_associations: flexibleBoolean
.optional()
.describe("Include extra API associations"),
min_access_level: z.number().optional().describe("Minimum access level filter (10-50)"),
...paginationFields(),
})
.passthrough();
// --- Action: get ---
// Note: .passthrough() preserves unknown fields for superRefine validation
const GetMergeRequestByIidSchema = z
.object({
action: z.literal("get").describe("Get single MR by IID or branch name"),
project_id: projectIdField,
merge_request_iid: mergeRequestIidField
.optional()
.describe("Internal MR ID. Required unless branch_name provided."),
branch_name: z.string().optional().describe("Find MR by its source branch name"),
include_diverged_commits_count: includeDivergedCommitsCountField,
include_rebase_in_progress: includeRebaseInProgressField,
})
.passthrough();
// --- Action: diffs ---
// Note: .passthrough() preserves unknown fields for superRefine validation
const DiffsMergeRequestSchema = z
.object({
action: z.literal("diffs").describe("Get file changes/diffs for an MR"),
project_id: projectIdField,
merge_request_iid: mergeRequestIidField,
include_diverged_commits_count: includeDivergedCommitsCountField,
include_rebase_in_progress: includeRebaseInProgressField,
// File exclusion options to reduce noise in diffs
exclude_patterns: z
.array(z.string())
.optional()
.describe("Custom glob patterns to exclude (e.g., ['vendor/**', '*.generated.ts'])"),
exclude_lockfiles: flexibleBoolean
.optional()
.describe(
"Exclude common lock files: yarn.lock, package-lock.json, Cargo.lock, etc. (default: false)"
),
exclude_generated: flexibleBoolean
.optional()
.describe(
"Exclude build output and minified files: dist/**, **/*.min.js, **/*.map, etc. (default: false)"
),
...paginationFields(),
})
.passthrough();
// --- Action: compare ---
// Note: .passthrough() preserves unknown fields for superRefine validation
const CompareMergeRequestSchema = z
.object({
action: z.literal("compare").describe("Compare two branches or commits"),
project_id: projectIdField,
from: z.string().describe("Source reference: branch name or commit SHA"),
to: z.string().describe("Target reference: branch name or commit SHA"),
straight: flexibleBoolean
.optional()
.describe("true=straight diff, false=three-way diff from common ancestor"),
})
.passthrough();
// --- Action: versions ---
// Lists all diff versions of an MR. Each push creates a new version.
// Note: .passthrough() preserves unknown fields for superRefine validation
const ListMergeRequestVersionsSchema = z
.object({
action: z
.literal("versions")
.describe("List all diff versions of an MR (each push creates a version)"),
project_id: projectIdField,
merge_request_iid: mergeRequestIidField,
...paginationFields(),
})
.passthrough();
// --- Action: version ---
// Gets specific MR diff version with file changes
// Note: .passthrough() preserves unknown fields for superRefine validation
const GetMergeRequestVersionSchema = z
.object({
action: z.literal("version").describe("Get specific MR diff version with file changes"),
project_id: projectIdField,
merge_request_iid: mergeRequestIidField,
version_id: requiredId.describe("Diff version ID from versions list"),
})
.passthrough();
// --- Discriminated union combining all actions ---
// Note: GetMergeRequestSchema uses .refine() which doesn't work with discriminatedUnion directly,
// so we use a two-step approach: discriminatedUnion for base validation, then refinement
const BrowseMergeRequestsBaseSchema = z.discriminatedUnion("action", [
ListMergeRequestsSchema,
GetMergeRequestByIidSchema,
DiffsMergeRequestSchema,
CompareMergeRequestSchema,
ListMergeRequestVersionsSchema,
GetMergeRequestVersionSchema,
]);
// Action-specific field sets for strict validation
const listOnlyFields = [
"state",
"order_by",
"sort",
"milestone",
"view",
"labels",
"with_labels_details",
"with_merge_status_recheck",
"created_after",
"created_before",
"updated_after",
"updated_before",
"scope",
"author_id",
"author_username",
"assignee_id",
"assignee_username",
"my_reaction_emoji",
"source_branch",
"target_branch",
"search",
"in",
"wip",
"not",
"environment",
"deployed_before",
"deployed_after",
"approved_by_ids",
"approved_by_usernames",
"reviewer_id",
"reviewer_username",
"with_api_entity_associations",
"min_access_level",
];
const compareOnlyFields = ["from", "to", "straight"];
const getOnlyFields = ["merge_request_iid", "branch_name"];
const versionOnlyFields = ["version_id"];
const diffsOnlyFields = ["exclude_patterns", "exclude_lockfiles", "exclude_generated"];
// Fields from get/diffs actions that are invalid for versions/version actions
// - branch_name: get-only
// - include_diverged_commits_count, include_rebase_in_progress: get and diffs
const fieldsInvalidForVersionActions = [
"branch_name",
"include_diverged_commits_count",
"include_rebase_in_progress",
];
// Apply refinement for 'get' action validation and action-specific field validation
export const BrowseMergeRequestsSchema = BrowseMergeRequestsBaseSchema.refine(
data => {
if (data.action === "get") {
return data.merge_request_iid !== undefined || data.branch_name !== undefined;
}
return true;
},
{
message: "Either merge_request_iid or branch_name must be provided for 'get' action",
path: ["merge_request_iid"],
}
).superRefine((data, ctx) => {
const input = data as Record<string, unknown>;
// Check for list-only fields used in non-list actions
if (data.action !== "list") {
for (const field of listOnlyFields) {
if (field in input && input[field] !== undefined) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `'${field}' is only valid for 'list' action`,
path: [field],
});
}
}
}
// Check for compare-only fields used in non-compare actions
if (data.action !== "compare") {
for (const field of compareOnlyFields) {
if (field in input && input[field] !== undefined) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `'${field}' is only valid for 'compare' action`,
path: [field],
});
}
}
}
// Check for get-only fields (merge_request_iid, branch_name) used in list action
if (data.action === "list") {
for (const field of getOnlyFields) {
if (field in input && input[field] !== undefined) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `'${field}' is only valid for 'get' action`,
path: [field],
});
}
}
}
// Check for version-only fields used in non-version actions
if (data.action !== "version") {
for (const field of versionOnlyFields) {
if (field in input && input[field] !== undefined) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `'${field}' is only valid for 'version' action`,
path: [field],
});
}
}
}
// Check for diffs-only fields used in non-diffs actions
if (data.action !== "diffs") {
for (const field of diffsOnlyFields) {
if (field in input && input[field] !== undefined) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `'${field}' is only valid for 'diffs' action`,
path: [field],
});
}
}
}
// Check for get/diffs shared fields used in versions/version actions
if (data.action === "versions" || data.action === "version") {
for (const field of fieldsInvalidForVersionActions) {
if (field in input && input[field] !== undefined) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `'${field}' is not valid for '${data.action}' action`,
path: [field],
});
}
}
}
});
// ============================================================================
// browse_mr_discussions - CQRS Query Tool (discriminated union schema)
// Actions: list, drafts, draft
// Uses z.discriminatedUnion() for type-safe action handling.
// Schema pipeline flattens to flat JSON Schema for AI clients that don't support oneOf.
// ============================================================================
// --- Action: list ---
const ListMrDiscussionsSchema = z.object({
action: z.literal("list").describe("List all discussion threads on an MR"),
project_id: projectIdField,
merge_request_iid: mergeRequestIidField,
...paginationFields(),
});
// --- Action: drafts ---
const ListDraftNotesSchema = z.object({
action: z.literal("drafts").describe("List unpublished draft notes on an MR"),
project_id: projectIdField,
merge_request_iid: mergeRequestIidField,
});
// --- Action: draft ---
const GetDraftNoteSchema = z.object({
action: z.literal("draft").describe("Get single draft note details"),
project_id: projectIdField,
merge_request_iid: mergeRequestIidField,
draft_note_id: requiredId.describe("Unique identifier of the draft note"),
});
// --- Discriminated union combining all actions ---
export const BrowseMrDiscussionsSchema = z.discriminatedUnion("action", [
ListMrDiscussionsSchema,
ListDraftNotesSchema,
GetDraftNoteSchema,
]);
// ============================================================================
// Export type definitions
// ============================================================================
export type BrowseMergeRequestsInput = z.infer<typeof BrowseMergeRequestsSchema>;
export type BrowseMrDiscussionsInput = z.infer<typeof BrowseMrDiscussionsSchema>;
|