agentic-sdlc-mcp 1.5.0 → 1.7.0

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 (72) hide show
  1. package/README.md +38 -6
  2. package/dist/config.d.ts.map +1 -1
  3. package/dist/config.js +1 -1
  4. package/dist/config.js.map +1 -1
  5. package/dist/github/codeowners.d.ts +24 -0
  6. package/dist/github/codeowners.d.ts.map +1 -0
  7. package/dist/github/codeowners.js +153 -0
  8. package/dist/github/codeowners.js.map +1 -0
  9. package/dist/github/context.d.ts +10 -0
  10. package/dist/github/context.d.ts.map +1 -1
  11. package/dist/github/context.js +10 -0
  12. package/dist/github/context.js.map +1 -1
  13. package/dist/github/pull-request-evidence.d.ts +123 -0
  14. package/dist/github/pull-request-evidence.d.ts.map +1 -0
  15. package/dist/github/pull-request-evidence.js +590 -0
  16. package/dist/github/pull-request-evidence.js.map +1 -0
  17. package/dist/policy/pull-request-policy.d.ts +35 -0
  18. package/dist/policy/pull-request-policy.d.ts.map +1 -0
  19. package/dist/policy/pull-request-policy.js +99 -0
  20. package/dist/policy/pull-request-policy.js.map +1 -0
  21. package/dist/policy/repository-policy-loader.d.ts +37 -0
  22. package/dist/policy/repository-policy-loader.d.ts.map +1 -0
  23. package/dist/policy/repository-policy-loader.js +144 -0
  24. package/dist/policy/repository-policy-loader.js.map +1 -0
  25. package/dist/policy/repository-policy.d.ts +98 -0
  26. package/dist/policy/repository-policy.d.ts.map +1 -0
  27. package/dist/policy/repository-policy.js +331 -0
  28. package/dist/policy/repository-policy.js.map +1 -0
  29. package/dist/rendering/markdown.d.ts +8 -0
  30. package/dist/rendering/markdown.d.ts.map +1 -0
  31. package/dist/rendering/markdown.js +27 -0
  32. package/dist/rendering/markdown.js.map +1 -0
  33. package/dist/review/pull-request-review.d.ts +77 -0
  34. package/dist/review/pull-request-review.d.ts.map +1 -0
  35. package/dist/review/pull-request-review.js +1185 -0
  36. package/dist/review/pull-request-review.js.map +1 -0
  37. package/dist/security/secret-scanner-evidence.d.ts +58 -0
  38. package/dist/security/secret-scanner-evidence.d.ts.map +1 -0
  39. package/dist/security/secret-scanner-evidence.js +414 -0
  40. package/dist/security/secret-scanner-evidence.js.map +1 -0
  41. package/dist/tools/agent-handoff.d.ts +50 -0
  42. package/dist/tools/agent-handoff.d.ts.map +1 -1
  43. package/dist/tools/agent-handoff.js +62 -1
  44. package/dist/tools/agent-handoff.js.map +1 -1
  45. package/dist/tools/plan-from-context.d.ts +23 -0
  46. package/dist/tools/plan-from-context.d.ts.map +1 -1
  47. package/dist/tools/plan-from-context.js +68 -6
  48. package/dist/tools/plan-from-context.js.map +1 -1
  49. package/dist/tools/quality-gate-status.d.ts +313 -5
  50. package/dist/tools/quality-gate-status.d.ts.map +1 -1
  51. package/dist/tools/quality-gate-status.js +737 -95
  52. package/dist/tools/quality-gate-status.js.map +1 -1
  53. package/dist/tools/release-readiness.d.ts +64 -0
  54. package/dist/tools/release-readiness.d.ts.map +1 -1
  55. package/dist/tools/release-readiness.js +170 -45
  56. package/dist/tools/release-readiness.js.map +1 -1
  57. package/dist/tools/repo-context.d.ts +44 -0
  58. package/dist/tools/repo-context.d.ts.map +1 -1
  59. package/dist/tools/repo-context.js +57 -0
  60. package/dist/tools/repo-context.js.map +1 -1
  61. package/dist/tools/review-pr.d.ts +134 -29
  62. package/dist/tools/review-pr.d.ts.map +1 -1
  63. package/dist/tools/review-pr.js +337 -313
  64. package/dist/tools/review-pr.js.map +1 -1
  65. package/dist/tools/workflow-permissions-audit.d.ts +14 -1
  66. package/dist/tools/workflow-permissions-audit.d.ts.map +1 -1
  67. package/dist/tools/workflow-permissions-audit.js +40 -15
  68. package/dist/tools/workflow-permissions-audit.js.map +1 -1
  69. package/dist/version.d.ts +1 -1
  70. package/dist/version.js +1 -1
  71. package/package.json +3 -1
  72. package/server.json +54 -0
@@ -1,14 +1,24 @@
1
1
  /**
2
2
  * Tool: quality_gate_status
3
3
  *
4
- * Core logic extracted as `categorizeChecks` and `handleQualityGateStatus`
5
- * for unit testing without MCP machinery.
4
+ * Evaluates real pull-request merge evidence while preserving ref-only CI
5
+ * compatibility and the legacy check-run summary fields.
6
6
  */
7
7
  import { z } from "zod";
8
- import { resolveRepo, getOctokit, paginateAll, handleGitHubError } from "../github/client.js";
8
+ import { resolveRepo, getOctokit, handleGitHubError } from "../github/client.js";
9
+ import { collectCiEvidence, collectPullRequestEvidence, } from "../github/pull-request-evidence.js";
10
+ import { safeMarkdownInline } from "../rendering/markdown.js";
11
+ import { loadRepositoryPolicy } from "../policy/repository-policy-loader.js";
12
+ import { evaluatePullRequestPolicy, } from "../policy/pull-request-policy.js";
9
13
  // ---------------------------------------------------------------------------
10
14
  // Schema
11
15
  // ---------------------------------------------------------------------------
16
+ export const DEFAULT_BLOCKING_LABELS = [
17
+ "blocked",
18
+ "do-not-merge",
19
+ "release-blocker",
20
+ "security-blocker",
21
+ ];
12
22
  export const QualityGateInputSchema = z.object({
13
23
  owner: z.string().optional().describe("GitHub owner. Falls back to GITHUB_OWNER."),
14
24
  repo: z.string().optional().describe("GitHub repo. Falls back to GITHUB_REPO."),
@@ -18,6 +28,11 @@ export const QualityGateInputSchema = z.object({
18
28
  ref: z
19
29
  .string().optional()
20
30
  .describe("Git ref (branch name, commit SHA). Ignored if pullNumber is set."),
31
+ blockingLabels: z
32
+ .array(z.string().min(1))
33
+ .max(50)
34
+ .default([...DEFAULT_BLOCKING_LABELS])
35
+ .describe("Exact, case-insensitive PR labels that block the gate. Pass [] to disable."),
21
36
  });
22
37
  const CheckStatusShape = z.object({
23
38
  name: z.string(),
@@ -25,137 +40,763 @@ const CheckStatusShape = z.object({
25
40
  conclusion: z.string().nullable(),
26
41
  url: z.string().nullable(),
27
42
  });
43
+ const GateSignalShape = z.object({
44
+ name: z.string(),
45
+ source: z.enum(["check_run", "commit_status"]),
46
+ appId: z.number().int().nullable(),
47
+ state: z.enum(["passing", "failing", "pending", "skipped"]),
48
+ rawStatus: z.string().nullable(),
49
+ rawConclusion: z.string().nullable(),
50
+ rawState: z.string().nullable(),
51
+ url: z.string().nullable(),
52
+ });
53
+ const RequiredStatusCheckShape = z.object({
54
+ context: z.string(),
55
+ appId: z.number().int().nullable(),
56
+ });
57
+ const SignalBucketsShape = z.object({
58
+ passing: z.array(GateSignalShape),
59
+ failing: z.array(GateSignalShape),
60
+ pending: z.array(GateSignalShape),
61
+ skipped: z.array(GateSignalShape),
62
+ total: z.number().int().nonnegative(),
63
+ });
64
+ const LinkedIssueShape = z.object({
65
+ number: z.number().int().positive(),
66
+ title: z.string(),
67
+ url: z.string(),
68
+ });
69
+ const OwnershipGapShape = z.object({
70
+ owner: z.string(),
71
+ paths: z.array(z.string()),
72
+ });
73
+ const QualityGateEvidenceShape = z.object({
74
+ scope: z.enum(["pull_request", "ref"]),
75
+ checks: z.object({
76
+ checkRuns: SignalBucketsShape,
77
+ commitStatuses: SignalBucketsShape,
78
+ totalSignals: z.number().int().nonnegative(),
79
+ requiredContexts: z.array(z.string()),
80
+ requiredChecks: z.array(RequiredStatusCheckShape),
81
+ missingRequiredContexts: z.array(z.string()),
82
+ }),
83
+ pullRequest: z
84
+ .object({
85
+ draft: z.boolean(),
86
+ mergeable: z.boolean().nullable(),
87
+ mergeableState: z.string().nullable(),
88
+ baseBranch: z.string(),
89
+ })
90
+ .nullable(),
91
+ reviews: z
92
+ .object({
93
+ reviewDecision: z.enum(["APPROVED", "CHANGES_REQUESTED", "REVIEW_REQUIRED"]).nullable(),
94
+ approved: z.number().int().nonnegative(),
95
+ approvedUsers: z.array(z.string()),
96
+ changesRequestedUsers: z.array(z.string()),
97
+ requestedUsers: z.array(z.string()),
98
+ requestedTeams: z.array(z.string()),
99
+ required: z.number().int().nonnegative().nullable(),
100
+ requireCodeOwnerReviews: z.boolean().nullable(),
101
+ codeOwnerReviewSatisfied: z.boolean().nullable(),
102
+ ownershipGaps: z.array(OwnershipGapShape),
103
+ })
104
+ .nullable(),
105
+ branchProtection: z
106
+ .object({
107
+ classicEnabled: z.boolean(),
108
+ rulesetRuleTypes: z.array(z.string()),
109
+ pullRequestRuleRequirements: z.object({
110
+ allowedMergeMethods: z.array(z.string()).nullable(),
111
+ dismissStaleReviews: z.boolean(),
112
+ lockBranch: z.boolean(),
113
+ requiredConversationResolution: z.boolean(),
114
+ requireLastPushApproval: z.boolean(),
115
+ requiredLinearHistory: z.boolean(),
116
+ requiredReviewThreadResolution: z.boolean(),
117
+ requiredReviewersConfigured: z.boolean(),
118
+ requiredSignatures: z.boolean(),
119
+ strictRequiredStatusChecksPolicy: z.boolean(),
120
+ }),
121
+ })
122
+ .nullable(),
123
+ labels: z
124
+ .object({
125
+ all: z.array(z.string()),
126
+ blocking: z.array(z.string()),
127
+ })
128
+ .nullable(),
129
+ linkedIssues: z.array(LinkedIssueShape).nullable(),
130
+ });
28
131
  export const QualityGateOutputSchema = {
29
132
  contextLabel: z.string(),
30
133
  headSha: z.string(),
31
- conclusion: z.enum(["passing", "failing", "pending"]),
134
+ conclusion: z.enum([
135
+ "passing",
136
+ "failing",
137
+ "pending",
138
+ "needs_review",
139
+ "policy_gap",
140
+ "no_evidence",
141
+ ]),
32
142
  categories: z.object({
33
143
  failing: z.array(CheckStatusShape),
34
144
  pending: z.array(CheckStatusShape),
35
145
  passing: z.array(CheckStatusShape),
36
146
  skipped: z.array(CheckStatusShape),
37
147
  }),
38
- totalChecks: z.number().int(),
148
+ totalChecks: z.number().int().nonnegative(),
149
+ evidence: QualityGateEvidenceShape,
150
+ blockers: z.array(z.string()),
151
+ warnings: z.array(z.string()),
152
+ nextActions: z.array(z.string()),
153
+ degraded: z.boolean(),
154
+ unverifiedSignals: z.array(z.string()),
155
+ errors: z.array(z.string()),
156
+ policyDigest: z.string().optional(),
157
+ policySources: z.array(z.object({
158
+ kind: z.enum(["default", "repository"]), path: z.string().nullable(),
159
+ ref: z.string().nullable(), blobSha: z.string().nullable(), digest: z.string(),
160
+ })).optional(),
161
+ appliedPolicyRules: z.array(z.object({ id: z.string(), source: z.literal("repository") })).optional(),
162
+ policyDegraded: z.boolean().optional(),
39
163
  };
40
164
  // ---------------------------------------------------------------------------
41
- // Pure helpers (exported for testing)
165
+ // Pure helpers
42
166
  // ---------------------------------------------------------------------------
43
167
  /** Categorise raw check-run objects into pass/fail/pending/skipped buckets. */
44
168
  export function categorizeChecks(checkRuns) {
45
169
  const toStatus = (run) => ({
46
170
  name: run.name,
47
- status: run.status ?? "unknown",
48
- conclusion: run.conclusion ?? null,
171
+ status: toCheckRunStatus(run.status),
172
+ conclusion: toCheckRunConclusion(run.conclusion),
49
173
  url: run.html_url ?? null,
50
174
  });
51
175
  return {
52
176
  failing: checkRuns
53
- .filter((c) => c.conclusion === "failure" || c.conclusion === "timed_out")
177
+ .filter((run) => ["failure", "timed_out", "cancelled", "action_required"].includes(run.conclusion ?? ""))
54
178
  .map(toStatus),
55
179
  pending: checkRuns
56
- .filter((c) => c.status === "queued" || c.status === "in_progress" || c.status === "pending")
180
+ .filter((run) => ["queued", "in_progress", "pending"].includes(run.status ?? ""))
57
181
  .map(toStatus),
58
- passing: checkRuns.filter((c) => c.conclusion === "success").map(toStatus),
182
+ passing: checkRuns.filter((run) => run.conclusion === "success").map(toStatus),
59
183
  skipped: checkRuns
60
- .filter((c) => c.conclusion === "skipped" || c.conclusion === "neutral")
184
+ .filter((run) => run.conclusion === "skipped" || run.conclusion === "neutral")
61
185
  .map(toStatus),
62
186
  };
63
187
  }
64
- // ---------------------------------------------------------------------------
65
- // Core handler (exported for testing)
66
- // ---------------------------------------------------------------------------
67
- export async function handleQualityGateStatus(params, ref, octokit) {
68
- let headSha;
69
- let contextLabel;
70
- if (params.pullNumber) {
71
- const { data: pr } = await octokit.pulls.get({
72
- owner: ref.owner,
73
- repo: ref.repo,
74
- pull_number: params.pullNumber,
75
- });
76
- headSha = pr.head.sha;
77
- contextLabel = `PR #${params.pullNumber} (${pr.title})`;
188
+ function toCheckRunStatus(status) {
189
+ if (status === "queued" ||
190
+ status === "in_progress" ||
191
+ status === "completed" ||
192
+ status === "pending") {
193
+ return status;
78
194
  }
79
- else if (params.ref) {
80
- const { data: refData } = await octokit.git.getRef({
81
- owner: ref.owner,
82
- repo: ref.repo,
83
- ref: params.ref.replace(/^refs\//, ""),
84
- });
85
- headSha = refData.object.sha;
86
- contextLabel = `ref: ${params.ref}`;
195
+ return "unknown";
196
+ }
197
+ function toCheckRunConclusion(conclusion) {
198
+ if (conclusion === "success" ||
199
+ conclusion === "failure" ||
200
+ conclusion === "neutral" ||
201
+ conclusion === "cancelled" ||
202
+ conclusion === "skipped" ||
203
+ conclusion === "timed_out" ||
204
+ conclusion === "action_required") {
205
+ return conclusion;
87
206
  }
88
- else {
89
- throw new Error("Either pullNumber or ref is required.");
207
+ return null;
208
+ }
209
+ function signalToCheckStatus(signal) {
210
+ return {
211
+ name: signal.name,
212
+ status: toCheckRunStatus(signal.rawStatus),
213
+ conclusion: toCheckRunConclusion(signal.rawConclusion),
214
+ url: signal.url,
215
+ };
216
+ }
217
+ function categoriesFromCheckRuns(checkRuns) {
218
+ return {
219
+ failing: checkRuns.failing.map(signalToCheckStatus),
220
+ pending: checkRuns.pending.map(signalToCheckStatus),
221
+ passing: checkRuns.passing.map(signalToCheckStatus),
222
+ skipped: checkRuns.skipped.map(signalToCheckStatus),
223
+ };
224
+ }
225
+ function unique(values) {
226
+ return values.filter((value, index, all) => all.indexOf(value) === index);
227
+ }
228
+ function uniqueCaseInsensitive(values) {
229
+ const seen = new Set();
230
+ return values.filter((value) => {
231
+ const normalized = value.toLocaleLowerCase();
232
+ if (seen.has(normalized))
233
+ return false;
234
+ seen.add(normalized);
235
+ return true;
236
+ });
237
+ }
238
+ function nextActionsFor(conclusion) {
239
+ switch (conclusion) {
240
+ case "failing":
241
+ return ["Resolve the known failing merge blockers before proceeding."];
242
+ case "pending":
243
+ return ["Wait for pending signals or required contexts, then run the gate again."];
244
+ case "needs_review":
245
+ return ["Complete the required human review and approval steps."];
246
+ case "policy_gap":
247
+ return ["Restore evidence access or configure the missing merge protection policy."];
248
+ case "no_evidence":
249
+ return ["Run or configure verifiable CI signals before treating this revision as safe."];
250
+ case "passing":
251
+ return ["Request final human merge approval."];
90
252
  }
91
- // Paginate check runs (repos with many checks can exceed 100)
92
- const allRuns = await paginateAll((page, perPage) => octokit.checks
93
- .listForRef({
94
- owner: ref.owner,
95
- repo: ref.repo,
96
- ref: headSha,
97
- per_page: perPage,
98
- page,
99
- })
100
- .then((r) => r.data.check_runs), 300);
101
- const cats = categorizeChecks(allRuns);
102
- const overallConclusion = cats.failing.length > 0
103
- ? "failing"
104
- : cats.pending.length > 0
105
- ? "pending"
106
- : "passing";
107
- const conclusionLabel = overallConclusion === "passing"
108
- ? "[PASS] All checks passed"
109
- : overallConclusion === "failing"
110
- ? "[FAIL] Some checks are failing"
111
- : "[PENDING] Checks are still running";
112
- const structured = {
113
- contextLabel,
253
+ }
254
+ function allSignals(ci) {
255
+ return [
256
+ ...ci.checkRuns.passing,
257
+ ...ci.checkRuns.failing,
258
+ ...ci.checkRuns.pending,
259
+ ...ci.checkRuns.skipped,
260
+ ...ci.commitStatuses.passing,
261
+ ...ci.commitStatuses.failing,
262
+ ...ci.commitStatuses.pending,
263
+ ...ci.commitStatuses.skipped,
264
+ ];
265
+ }
266
+ function requiredContextsState(evidence) {
267
+ const requiredChecks = evidence.branchProtection.requiredStatusChecks?.length > 0
268
+ ? evidence.branchProtection.requiredStatusChecks
269
+ : evidence.branchProtection.requiredStatusContexts.map((context) => ({
270
+ context,
271
+ appId: null,
272
+ }));
273
+ const required = uniqueCaseInsensitive(requiredChecks.map((check) => check.context));
274
+ const signals = allSignals(evidence.ci);
275
+ const satisfiedSignals = signals.filter((signal) => signal.state === "passing" || signal.state === "skipped");
276
+ const matches = (check, signal) => check.context.toLocaleLowerCase() === signal.name.toLocaleLowerCase() &&
277
+ (check.appId === null ||
278
+ (signal.source === "check_run" && signal.appId === check.appId));
279
+ const missingChecks = requiredChecks.filter((check) => !signals.some((signal) => matches(check, signal)));
280
+ return {
281
+ required,
282
+ missing: uniqueCaseInsensitive(missingChecks.map((check) => check.context)),
283
+ satisfiedByPassingOrSkipped: requiredChecks.length > 0 &&
284
+ requiredChecks.every((check) => satisfiedSignals.some((signal) => matches(check, signal))),
285
+ };
286
+ }
287
+ function hasReviewPolicy(evidence) {
288
+ const requirements = evidence.branchProtection.pullRequestRuleRequirements;
289
+ return ((evidence.reviews.requiredApprovals ?? 0) > 0 ||
290
+ evidence.reviews.requireCodeOwnerReviews === true ||
291
+ requirements?.dismissStaleReviews === true ||
292
+ requirements?.requireLastPushApproval === true);
293
+ }
294
+ const MODELED_MERGE_RULE_TYPES = new Set(["pull_request", "required_status_checks"]);
295
+ const SAFE_IGNORE_MERGE_RULE_TYPES = new Set([
296
+ "creation",
297
+ "deletion",
298
+ "non_fast_forward",
299
+ ]);
300
+ function mergePolicyState(evidence) {
301
+ const reviewPolicyConfigured = hasReviewPolicy(evidence);
302
+ const hasRequiredContexts = evidence.branchProtection.requiredStatusContexts.length > 0;
303
+ const pullRequestRequirements = evidence.branchProtection.pullRequestRuleRequirements;
304
+ const unmodeledRules = evidence.branchProtection.rulesetRuleTypes.filter((type) => {
305
+ const normalized = type.toLocaleLowerCase();
306
+ if (normalized === "pull_request")
307
+ return !reviewPolicyConfigured;
308
+ if (normalized === "required_status_checks")
309
+ return !hasRequiredContexts;
310
+ if (SAFE_IGNORE_MERGE_RULE_TYPES.has(normalized))
311
+ return false;
312
+ return !MODELED_MERGE_RULE_TYPES.has(normalized);
313
+ });
314
+ if (pullRequestRequirements?.requiredReviewThreadResolution) {
315
+ unmodeledRules.push("pull_request.required_review_thread_resolution");
316
+ }
317
+ if (pullRequestRequirements?.requiredReviewersConfigured) {
318
+ unmodeledRules.push("pull_request.required_reviewers");
319
+ }
320
+ if (Array.isArray(pullRequestRequirements?.allowedMergeMethods)) {
321
+ unmodeledRules.push("pull_request.allowed_merge_methods");
322
+ }
323
+ if (pullRequestRequirements?.strictRequiredStatusChecksPolicy) {
324
+ unmodeledRules.push("required_status_checks.strict_required_status_checks_policy");
325
+ }
326
+ if (pullRequestRequirements?.requiredConversationResolution) {
327
+ unmodeledRules.push("branch_protection.required_conversation_resolution");
328
+ }
329
+ if (pullRequestRequirements?.requiredSignatures) {
330
+ unmodeledRules.push("branch_protection.required_signatures");
331
+ }
332
+ if (pullRequestRequirements?.requiredLinearHistory) {
333
+ unmodeledRules.push("branch_protection.required_linear_history");
334
+ }
335
+ if (pullRequestRequirements?.lockBranch) {
336
+ unmodeledRules.push("branch_protection.lock_branch");
337
+ }
338
+ const modeled = reviewPolicyConfigured || hasRequiredContexts;
339
+ const uniqueUnmodeledRules = uniqueCaseInsensitive(unmodeledRules);
340
+ return {
341
+ hasAnyPolicy: modeled || uniqueUnmodeledRules.length > 0,
342
+ unmodeledRules: uniqueUnmodeledRules,
343
+ };
344
+ }
345
+ function sourceWarnings(evidence) {
346
+ const warnings = [];
347
+ const unverified = new Set(evidence.unverifiedSignals);
348
+ if (evidence.linkedIssues === null || unverified.has("linked_issues")) {
349
+ warnings.push("linked issue 证据无法验证。 ");
350
+ }
351
+ else if (evidence.linkedIssues.length === 0) {
352
+ warnings.push("此 PR 未关联 issue;建议补充可追溯的工作项。 ");
353
+ }
354
+ if (!unverified.has("branch_protection") &&
355
+ !unverified.has("branch_rules") &&
356
+ !hasReviewPolicy(evidence)) {
357
+ warnings.push("未配置 required review 规则;这在单维护者仓库中可能是合理选择。 ");
358
+ }
359
+ if (evidence.reviews.requireCodeOwnerReviews !== true &&
360
+ evidence.reviews.ownershipGaps.length > 0) {
361
+ warnings.push("CODEOWNERS 路由存在缺口,但未配置强制 CODEOWNER 审查。 ");
362
+ }
363
+ for (const source of evidence.unverifiedSignals) {
364
+ warnings.push(`证据来源 ${source} 无法完整验证。`);
365
+ }
366
+ return unique(warnings.map((warning) => warning.trim()));
367
+ }
368
+ /**
369
+ * Evaluate PR evidence with a stable, explicit decision priority.
370
+ * Known failures always remain authoritative even when other evidence is degraded.
371
+ */
372
+ export function evaluateQualityGate(evidence, blockingLabels) {
373
+ const configuredLabels = new Set(blockingLabels.map((label) => label.toLocaleLowerCase()));
374
+ const matchedBlockingLabels = evidence.pullRequest.labels.filter((label) => configuredLabels.has(label.toLocaleLowerCase()));
375
+ const contexts = requiredContextsState(evidence);
376
+ const reviewPolicyConfigured = hasReviewPolicy(evidence);
377
+ const mergePolicy = mergePolicyState(evidence);
378
+ const unverifiedSignals = unique([
379
+ ...evidence.unverifiedSignals,
380
+ ...evidence.ci.unverifiedSignals,
381
+ ]);
382
+ const unverified = new Set(unverifiedSignals);
383
+ const aggregateReviewUnverified = unverified.has("review_decision");
384
+ const restReviewsVerified = !unverified.has("reviews");
385
+ const failingReasons = [];
386
+ const pendingReasons = [];
387
+ const reviewReasons = [];
388
+ const policyReasons = [];
389
+ const mergeableState = evidence.pullRequest.mergeableState?.toLocaleLowerCase() ?? null;
390
+ const computingMergeableStates = new Set(["unknown", "queued", "checking", "pending"]);
391
+ const explicitlyFailingMergeableStates = new Set(["dirty", "unstable"]);
392
+ const nonBlockingMergeableStates = new Set(["clean", "has_hooks", "draft"]);
393
+ for (const item of [
394
+ ...evidence.ci.checkRuns.failing,
395
+ ...evidence.ci.commitStatuses.failing,
396
+ ]) {
397
+ failingReasons.push(`CI signal failed: ${item.name} (${item.source}).`);
398
+ }
399
+ if (evidence.pullRequest.mergeable === false) {
400
+ failingReasons.push("GitHub reports that the PR is not mergeable.");
401
+ }
402
+ if (mergeableState !== null && explicitlyFailingMergeableStates.has(mergeableState)) {
403
+ failingReasons.push(`GitHub reports a failing mergeability state: ${mergeableState}.`);
404
+ }
405
+ if (evidence.reviews.reviewDecision === "CHANGES_REQUESTED") {
406
+ failingReasons.push(evidence.reviews.changesRequestedUsers.length > 0
407
+ ? `Changes requested by: ${evidence.reviews.changesRequestedUsers.join(", ")}.`
408
+ : "A reviewer requested changes.");
409
+ }
410
+ if (aggregateReviewUnverified &&
411
+ restReviewsVerified &&
412
+ evidence.reviews.changesRequestedUsers.length > 0) {
413
+ failingReasons.push(`Changes requested by: ${evidence.reviews.changesRequestedUsers.join(", ")}.`);
414
+ }
415
+ for (const label of matchedBlockingLabels) {
416
+ failingReasons.push(`Blocking label matched: ${label}.`);
417
+ }
418
+ for (const item of [
419
+ ...evidence.ci.checkRuns.pending,
420
+ ...evidence.ci.commitStatuses.pending,
421
+ ]) {
422
+ pendingReasons.push(`CI signal is pending: ${item.name} (${item.source}).`);
423
+ }
424
+ if (evidence.pullRequest.mergeable === null) {
425
+ pendingReasons.push("GitHub has not finished computing PR mergeability.");
426
+ }
427
+ if (mergeableState !== null && computingMergeableStates.has(mergeableState)) {
428
+ pendingReasons.push(`GitHub mergeability state is still computing: ${mergeableState}.`);
429
+ }
430
+ if (mergeableState === "behind") {
431
+ pendingReasons.push("The pull request head is behind the base branch and must be updated.");
432
+ }
433
+ if (contexts.missing.length > 0) {
434
+ pendingReasons.push(`Required status contexts are missing: ${contexts.missing.join(", ")}.`);
435
+ }
436
+ if (evidence.pullRequest.draft)
437
+ reviewReasons.push("The pull request is still a draft.");
438
+ if (evidence.reviews.reviewDecision === "REVIEW_REQUIRED") {
439
+ reviewReasons.push("GitHub reports that review is required.");
440
+ }
441
+ if (evidence.reviews.reviewDecision === null &&
442
+ !unverified.has("reviews") &&
443
+ evidence.reviews.requiredApprovals !== null &&
444
+ evidence.reviews.requiredApprovals > evidence.reviews.approvedUsers.length) {
445
+ reviewReasons.push(`Approvals are incomplete: ${evidence.reviews.approvedUsers.length}/${evidence.reviews.requiredApprovals}.`);
446
+ }
447
+ const criticalSources = [
448
+ "branch_protection",
449
+ "branch_rules",
450
+ "check_runs",
451
+ "commit_statuses",
452
+ ];
453
+ if (aggregateReviewUnverified) {
454
+ criticalSources.push("review_decision");
455
+ policyReasons.push("Aggregate review decision is unavailable; review blockers cannot be fully ruled out.");
456
+ if (!restReviewsVerified)
457
+ criticalSources.push("reviews");
458
+ }
459
+ if (reviewPolicyConfigured && evidence.reviews.reviewDecision === null) {
460
+ criticalSources.push("review_decision");
461
+ policyReasons.push("Aggregate review decision is unavailable for the configured review policy.");
462
+ }
463
+ if (evidence.reviews.requireCodeOwnerReviews === true) {
464
+ criticalSources.push("code_owner_review", "codeowners", "changed_files");
465
+ }
466
+ const missingCriticalSources = unique(criticalSources.filter((source) => unverified.has(source)));
467
+ if (missingCriticalSources.length > 0) {
468
+ policyReasons.push(`Critical evidence sources are incomplete: ${missingCriticalSources.join(", ")}.`);
469
+ }
470
+ if (evidence.reviews.requireCodeOwnerReviews === true &&
471
+ evidence.reviews.reviewDecision !== "APPROVED" &&
472
+ evidence.reviews.codeOwnerReviewSatisfied === null) {
473
+ policyReasons.push("Required CODEOWNER review 无法验证。 ");
474
+ }
475
+ if (mergePolicy.unmodeledRules.length > 0) {
476
+ policyReasons.push(`Unmodeled merge rules cannot be verified: ${mergePolicy.unmodeledRules.join(", ")}.`);
477
+ }
478
+ if (mergeableState === "blocked") {
479
+ policyReasons.push("GitHub reports that merging is blocked, but the underlying check or review requirement must be resolved from its specific evidence.");
480
+ }
481
+ else if (mergeableState !== null &&
482
+ !computingMergeableStates.has(mergeableState) &&
483
+ mergeableState !== "behind" &&
484
+ !explicitlyFailingMergeableStates.has(mergeableState) &&
485
+ !nonBlockingMergeableStates.has(mergeableState)) {
486
+ policyReasons.push(`GitHub returned an unrecognized mergeability state: ${mergeableState}.`);
487
+ }
488
+ if (!unverified.has("branch_protection") &&
489
+ !unverified.has("branch_rules") &&
490
+ !mergePolicy.hasAnyPolicy) {
491
+ policyReasons.push("No verified merge-relevant protection policy was found.");
492
+ }
493
+ let conclusion;
494
+ if (failingReasons.length > 0)
495
+ conclusion = "failing";
496
+ else if (pendingReasons.length > 0)
497
+ conclusion = "pending";
498
+ else if (reviewReasons.length > 0)
499
+ conclusion = "needs_review";
500
+ else if (policyReasons.length > 0)
501
+ conclusion = "policy_gap";
502
+ else if (evidence.ci.checkRuns.passing.length === 0 &&
503
+ evidence.ci.commitStatuses.passing.length === 0 &&
504
+ !contexts.satisfiedByPassingOrSkipped &&
505
+ !(reviewPolicyConfigured && evidence.reviews.reviewDecision === "APPROVED")) {
506
+ conclusion = "no_evidence";
507
+ }
508
+ else
509
+ conclusion = "passing";
510
+ const noEvidenceReasons = conclusion === "no_evidence"
511
+ ? ["No verified passing CI signal is available for this pull request."]
512
+ : [];
513
+ return {
514
+ conclusion,
515
+ blockers: unique([
516
+ ...failingReasons,
517
+ ...pendingReasons,
518
+ ...reviewReasons,
519
+ ...policyReasons.map((reason) => reason.trim()),
520
+ ...noEvidenceReasons,
521
+ ]),
522
+ warnings: sourceWarnings(evidence),
523
+ nextActions: nextActionsFor(conclusion),
524
+ matchedBlockingLabels,
525
+ missingRequiredContexts: contexts.missing,
526
+ };
527
+ }
528
+ function evaluateRefQualityGate(ci) {
529
+ const failingReasons = [
530
+ ...ci.checkRuns.failing,
531
+ ...ci.commitStatuses.failing,
532
+ ].map((item) => `CI signal failed: ${item.name} (${item.source}).`);
533
+ const pendingReasons = [
534
+ ...ci.checkRuns.pending,
535
+ ...ci.commitStatuses.pending,
536
+ ].map((item) => `CI signal is pending: ${item.name} (${item.source}).`);
537
+ const warnings = ci.unverifiedSignals.map((source) => `CI evidence source ${source} could not be fully verified.`);
538
+ let conclusion;
539
+ if (failingReasons.length > 0)
540
+ conclusion = "failing";
541
+ else if (pendingReasons.length > 0)
542
+ conclusion = "pending";
543
+ else if (ci.unverifiedSignals.length > 0 ||
544
+ ci.totalSignals === 0 ||
545
+ (ci.checkRuns.passing.length === 0 && ci.commitStatuses.passing.length === 0)) {
546
+ conclusion = "no_evidence";
547
+ }
548
+ else
549
+ conclusion = "passing";
550
+ return {
551
+ conclusion,
552
+ blockers: unique([
553
+ ...failingReasons,
554
+ ...pendingReasons,
555
+ ...(conclusion === "no_evidence"
556
+ ? ["No complete, verified passing CI evidence is available for this ref."]
557
+ : []),
558
+ ]),
559
+ warnings,
560
+ nextActions: nextActionsFor(conclusion),
561
+ matchedBlockingLabels: [],
562
+ missingRequiredContexts: [],
563
+ };
564
+ }
565
+ function buildPullRequestResult(evidence, decision) {
566
+ const unverifiedSignals = unique([
567
+ ...evidence.unverifiedSignals,
568
+ ...evidence.ci.unverifiedSignals,
569
+ ]);
570
+ return {
571
+ contextLabel: `PR #${evidence.pullRequest.number} (${evidence.pullRequest.title})`,
572
+ headSha: evidence.pullRequest.headSha,
573
+ conclusion: decision.conclusion,
574
+ categories: categoriesFromCheckRuns(evidence.ci.checkRuns),
575
+ totalChecks: evidence.ci.checkRuns.total,
576
+ evidence: {
577
+ scope: "pull_request",
578
+ checks: {
579
+ checkRuns: evidence.ci.checkRuns,
580
+ commitStatuses: evidence.ci.commitStatuses,
581
+ totalSignals: evidence.ci.totalSignals,
582
+ requiredContexts: uniqueCaseInsensitive(evidence.branchProtection.requiredStatusContexts),
583
+ requiredChecks: evidence.branchProtection.requiredStatusChecks,
584
+ missingRequiredContexts: decision.missingRequiredContexts,
585
+ },
586
+ pullRequest: {
587
+ draft: evidence.pullRequest.draft,
588
+ mergeable: evidence.pullRequest.mergeable,
589
+ mergeableState: evidence.pullRequest.mergeableState,
590
+ baseBranch: evidence.pullRequest.baseBranch,
591
+ },
592
+ reviews: {
593
+ reviewDecision: evidence.reviews.reviewDecision,
594
+ approved: evidence.reviews.approvedUsers.length,
595
+ approvedUsers: evidence.reviews.approvedUsers,
596
+ changesRequestedUsers: evidence.reviews.changesRequestedUsers,
597
+ requestedUsers: evidence.reviews.requestedUsers,
598
+ requestedTeams: evidence.reviews.requestedTeams,
599
+ required: evidence.reviews.requiredApprovals,
600
+ requireCodeOwnerReviews: evidence.reviews.requireCodeOwnerReviews,
601
+ codeOwnerReviewSatisfied: evidence.reviews.codeOwnerReviewSatisfied,
602
+ ownershipGaps: evidence.reviews.ownershipGaps,
603
+ },
604
+ branchProtection: {
605
+ classicEnabled: evidence.branchProtection.classicEnabled,
606
+ rulesetRuleTypes: evidence.branchProtection.rulesetRuleTypes,
607
+ pullRequestRuleRequirements: evidence.branchProtection.pullRequestRuleRequirements,
608
+ },
609
+ labels: {
610
+ all: evidence.pullRequest.labels,
611
+ blocking: decision.matchedBlockingLabels,
612
+ },
613
+ linkedIssues: evidence.linkedIssues,
614
+ },
615
+ blockers: decision.blockers,
616
+ warnings: decision.warnings,
617
+ nextActions: decision.nextActions,
618
+ degraded: evidence.degraded || unverifiedSignals.length > 0,
619
+ unverifiedSignals,
620
+ errors: evidence.errors,
621
+ };
622
+ }
623
+ function buildRefResult(refName, headSha, ci, decision) {
624
+ return {
625
+ contextLabel: `ref: ${refName}`,
114
626
  headSha,
115
- conclusion: overallConclusion,
116
- categories: cats,
117
- totalChecks: allRuns.length,
627
+ conclusion: decision.conclusion,
628
+ categories: categoriesFromCheckRuns(ci.checkRuns),
629
+ totalChecks: ci.checkRuns.total,
630
+ evidence: {
631
+ scope: "ref",
632
+ checks: {
633
+ checkRuns: ci.checkRuns,
634
+ commitStatuses: ci.commitStatuses,
635
+ totalSignals: ci.totalSignals,
636
+ requiredContexts: [],
637
+ requiredChecks: [],
638
+ missingRequiredContexts: [],
639
+ },
640
+ pullRequest: null,
641
+ reviews: null,
642
+ branchProtection: null,
643
+ labels: null,
644
+ linkedIssues: null,
645
+ },
646
+ blockers: decision.blockers,
647
+ warnings: decision.warnings,
648
+ nextActions: decision.nextActions,
649
+ degraded: ci.unverifiedSignals.length > 0,
650
+ unverifiedSignals: unique(ci.unverifiedSignals),
651
+ errors: ci.errors,
118
652
  };
653
+ }
654
+ function renderQualityGateMarkdown(result) {
655
+ const inline = (value, maxLength = 300) => safeMarkdownInline(value, { maxLength });
119
656
  const lines = [
120
- `# Quality Gate Status - ${contextLabel}`,
657
+ `# Quality Gate Status - ${inline(result.contextLabel, 400)}`,
121
658
  "",
122
- `**Commit:** \`${headSha.slice(0, 8)}\``,
123
- `**Conclusion:** ${conclusionLabel}`,
659
+ `**Commit:** ${inline(result.headSha.slice(0, 40), 80)}`,
660
+ `**Conclusion:** ${inline(result.conclusion)}`,
661
+ `**Evidence degraded:** ${result.degraded ? "yes" : "no"}`,
124
662
  "",
125
- `| | Count |`,
126
- `|---|---|`,
127
- `| Passing | ${cats.passing.length} |`,
128
- `| Failing | ${cats.failing.length} |`,
129
- `| Pending | ${cats.pending.length} |`,
130
- `| Skipped | ${cats.skipped.length} |`,
131
- `| Total | ${allRuns.length} |`,
663
+ "| Check runs | Count |",
664
+ "|---|---:|",
665
+ `| Passing | ${result.categories.passing.length} |`,
666
+ `| Failing | ${result.categories.failing.length} |`,
667
+ `| Pending | ${result.categories.pending.length} |`,
668
+ `| Skipped | ${result.categories.skipped.length} |`,
669
+ `| Total | ${result.totalChecks} |`,
670
+ "",
671
+ `**All CI signals:** ${result.evidence.checks.totalSignals}`,
132
672
  ];
133
- if (cats.failing.length > 0) {
134
- lines.push("", "## [FAIL] Failing Checks");
135
- cats.failing.forEach((c) => {
136
- const link = c.url ? ` - [view](${c.url})` : "";
137
- lines.push(`- **${c.name}**: ${c.conclusion}${link}`);
138
- });
673
+ const reviewDetails = result.evidence.reviews;
674
+ if (reviewDetails) {
675
+ const reviewLines = [
676
+ reviewDetails.approvedUsers.length > 0
677
+ ? `- Approved: ${reviewDetails.approvedUsers.map((user) => inline(user)).join(", ")}`
678
+ : null,
679
+ reviewDetails.changesRequestedUsers.length > 0
680
+ ? `- Changes requested: ${reviewDetails.changesRequestedUsers.map((user) => inline(user)).join(", ")}`
681
+ : null,
682
+ reviewDetails.requestedUsers.length > 0
683
+ ? `- Requested users: ${reviewDetails.requestedUsers.map((user) => inline(user)).join(", ")}`
684
+ : null,
685
+ reviewDetails.requestedTeams.length > 0
686
+ ? `- Requested teams: ${reviewDetails.requestedTeams.map((team) => inline(team)).join(", ")}`
687
+ : null,
688
+ ].filter((line) => line !== null);
689
+ if (reviewLines.length > 0)
690
+ lines.push("", "## Review Details", ...reviewLines);
139
691
  }
140
- if (cats.pending.length > 0) {
141
- lines.push("", "## [PENDING] Pending Checks");
142
- cats.pending.forEach((c) => lines.push(`- **${c.name}**: ${c.status}`));
692
+ if (result.blockers.length > 0) {
693
+ lines.push("", "## Blockers", ...result.blockers.map((item) => `- ${inline(item, 500)}`));
143
694
  }
144
- if (cats.passing.length > 0) {
145
- lines.push("", "## [PASS] Passing Checks");
146
- cats.passing.forEach((c) => lines.push(`- ${c.name}`));
695
+ if (result.warnings.length > 0) {
696
+ lines.push("", "## Warnings", ...result.warnings.map((item) => `- ${inline(item, 500)}`));
147
697
  }
148
- lines.push("", "## Next Actions");
149
- if (cats.failing.length > 0) {
150
- lines.push("- Fix the failing checks listed above before proceeding.", "- Use `review_pr_against_standard` for deeper analysis of PR issues.");
698
+ if (result.errors.length > 0) {
699
+ lines.push("", "## Notes", ...result.errors.map((error) => `- ${inline(error, 500)}`));
151
700
  }
152
- else if (cats.pending.length > 0) {
153
- lines.push("- Wait for pending checks to complete, then re-run this tool.");
701
+ if (result.policyDigest) {
702
+ lines.push("", "## Policy Provenance", `- Digest: \`${inline(result.policyDigest, 80)}\``, `- Status: ${result.policyDegraded ? "degraded" : "verified"}`, `- Applied rules: ${result.appliedPolicyRules?.map((rule) => inline(rule.id)).join(", ") || "none"}`);
703
+ for (const source of result.policySources ?? []) {
704
+ lines.push(`- Source: ${inline(source.path ?? "built-in")} @ ${inline(source.ref ?? "default")} (blob: ${inline(source.blobSha ?? "n/a")})`);
705
+ }
706
+ }
707
+ if (result.categories.failing.length > 0) {
708
+ lines.push("", "## Failing Check Runs", ...result.categories.failing.map((item) => `- **${inline(item.name)}**: ${inline(item.conclusion ?? "unknown")}`));
709
+ }
710
+ if (result.categories.pending.length > 0) {
711
+ lines.push("", "## Pending Check Runs", ...result.categories.pending.map((item) => `- **${inline(item.name)}**: ${inline(item.status ?? "unknown")}`));
712
+ }
713
+ lines.push("", "## Next Actions", ...result.nextActions.map((item) => `- ${inline(item, 500)}`));
714
+ return lines.join("\n");
715
+ }
716
+ // ---------------------------------------------------------------------------
717
+ // Core handler
718
+ // ---------------------------------------------------------------------------
719
+ function normalizeCommitRef(input) {
720
+ return input.replace(/^refs\/(?=(?:heads|tags)\/)/, "");
721
+ }
722
+ export async function handleQualityGateStatus(params, ref, octokit) {
723
+ let structured;
724
+ if (params.pullNumber) {
725
+ const evidence = await collectPullRequestEvidence({ pullNumber: params.pullNumber }, ref, octokit);
726
+ let policyDecision = null;
727
+ let appliedPolicyRules = [];
728
+ const getContent = octokit.repos.getContent;
729
+ if (typeof getContent === "function") {
730
+ const loaded = await loadRepositoryPolicy(ref, evidence.pullRequest.baseSha ?? evidence.pullRequest.baseBranch, octokit);
731
+ policyDecision = evaluatePullRequestPolicy(loaded, {
732
+ paths: evidence.changedFiles.flatMap((file) => file.previousFilename ? [file.filename, file.previousFilename] : [file.filename]),
733
+ changedFilesComplete: !evidence.unverifiedSignals.includes("changed_files"),
734
+ linkedIssues: evidence.linkedIssues,
735
+ approvedUsers: evidence.reviews.approvedUsers,
736
+ requestedUsers: evidence.reviews.requestedUsers,
737
+ requestedTeams: evidence.reviews.requestedTeams,
738
+ codeOwnerReviewSatisfied: evidence.reviews.codeOwnerReviewSatisfied,
739
+ });
740
+ for (const required of policyDecision.requiredChecks) {
741
+ const trustedPassing = evidence.ci.checkRuns.passing.some((signal) => signal.name.toLocaleLowerCase() === required.name.toLocaleLowerCase() &&
742
+ signal.appId === required.appId);
743
+ if (!trustedPassing) {
744
+ policyDecision.policyGaps.push({
745
+ ruleId: "ci.required_checks",
746
+ message: `Required check ${required.name} is not passing from check_run App ${required.appId}.`,
747
+ });
748
+ }
749
+ }
750
+ appliedPolicyRules = loaded.appliedRules;
751
+ evidence.branchProtection.requiredStatusChecks = [
752
+ ...evidence.branchProtection.requiredStatusChecks,
753
+ ...policyDecision.requiredChecks
754
+ .filter((policyCheck) => !evidence.branchProtection.requiredStatusChecks.some((check) => check.context.toLocaleLowerCase() === policyCheck.name.toLocaleLowerCase() &&
755
+ check.appId === policyCheck.appId))
756
+ .map((policyCheck) => ({ context: policyCheck.name, appId: policyCheck.appId })),
757
+ ];
758
+ }
759
+ const labels = [
760
+ ...(params.blockingLabels ?? DEFAULT_BLOCKING_LABELS),
761
+ ...(policyDecision?.blockingLabels ?? []),
762
+ ];
763
+ const decision = evaluateQualityGate(evidence, labels);
764
+ if (decision.conclusion !== "failing" && decision.conclusion !== "pending") {
765
+ if ((policyDecision?.blockers.length ?? 0) > 0 || (policyDecision?.pendingReviews.length ?? 0) > 0) {
766
+ decision.conclusion = "needs_review";
767
+ }
768
+ else if ((policyDecision?.policyGaps.length ?? 0) > 0) {
769
+ decision.conclusion = "policy_gap";
770
+ }
771
+ }
772
+ const policyReasons = [
773
+ ...(policyDecision?.blockers ?? []),
774
+ ...(policyDecision?.pendingReviews ?? []),
775
+ ...(policyDecision?.policyGaps ?? []),
776
+ ].map((reason) => `[${reason.ruleId}] ${reason.message}`);
777
+ decision.blockers = unique([...decision.blockers, ...policyReasons]);
778
+ structured = buildPullRequestResult(evidence, decision);
779
+ if (policyDecision) {
780
+ structured.policyDigest = policyDecision.policyDigest;
781
+ structured.policySources = policyDecision.policySources;
782
+ structured.appliedPolicyRules = appliedPolicyRules;
783
+ structured.policyDegraded = policyDecision.policyDegraded;
784
+ }
785
+ }
786
+ else if (params.ref) {
787
+ const { data: commit } = await octokit.repos.getCommit({
788
+ owner: ref.owner,
789
+ repo: ref.repo,
790
+ ref: normalizeCommitRef(params.ref),
791
+ });
792
+ const headSha = commit.sha;
793
+ const evidence = await collectCiEvidence(ref, headSha, octokit);
794
+ structured = buildRefResult(params.ref, headSha, evidence, evaluateRefQualityGate(evidence));
154
795
  }
155
796
  else {
156
- lines.push("- All checks pass. Safe to request review or merge.", "- Run `release_readiness_check` for a full pre-release assessment.");
797
+ throw new Error("Either pullNumber or ref is required.");
157
798
  }
158
- return { text: lines.join("\n"), structured };
799
+ return { text: renderQualityGateMarkdown(structured), structured };
159
800
  }
160
801
  // ---------------------------------------------------------------------------
161
802
  // Registration
@@ -163,14 +804,15 @@ export async function handleQualityGateStatus(params, ref, octokit) {
163
804
  export function registerQualityGateStatusTool(server) {
164
805
  server.registerTool("quality_gate_status", {
165
806
  title: "Quality Gate Status",
166
- description: `Read check-run results for a pull request or git ref.
807
+ description: `Evaluate real merge-gate evidence for a pull request or CI evidence for a git ref.
167
808
 
168
809
  Args:
169
810
  - owner, repo: Repository coordinates.
170
- - pullNumber (number?): PR number (preferred).
171
- - ref (string?): Branch name or commit SHA.
811
+ - pullNumber (number?): PR number (preferred); evaluates CI, reviews, policy, labels, and mergeability.
812
+ - ref (string?): Branch name or commit SHA; evaluates CI only.
813
+ - blockingLabels (string[]): Exact case-insensitive PR labels that block merging. Pass [] to disable.
172
814
 
173
- Returns: Summary of all check runs with pass/fail/pending counts and next actions.`,
815
+ Returns: A structured evidence packet, blockers, warnings, next actions, and a conservative conclusion.`,
174
816
  inputSchema: QualityGateInputSchema,
175
817
  outputSchema: QualityGateOutputSchema,
176
818
  annotations: {