@code-sentinel-cli/code-sentinel-cli 4.0.15 → 4.0.16
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.
- package/dist/bin.js +229 -49
- package/dist/index.d.ts +1 -0
- package/dist/index.js +229 -49
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -37674,7 +37674,7 @@ Language guard retry: the previous response contained an empty or English explan
|
|
|
37674
37674
|
return { status: "error", vulnerable: false, reason: `L\u1ED7i th\u1EF1c thi LLM: ${message}` };
|
|
37675
37675
|
}
|
|
37676
37676
|
}
|
|
37677
|
-
var OLLAMA_DEFAULT_BASE, NETMIND_DEFAULT_BASE, OPENCODE_GO_DEFAULT_BASE, stripTrailingSlash2, buildLanguageModel, resolveModelOverride, pingTarget, shouldUseRawJsonChat, openAICompatibleChatUrl, REASONING_HEADROOM_TOKENS, NETMIND_MINIMAX_M3_MODEL, NETMIND_SMALL_PROMPT_MAX_CHARS, NETMIND_MEDIUM_PROMPT_MAX_CHARS, NETMIND_SMALL_OUTPUT_TOKENS, NETMIND_MEDIUM_OUTPUT_TOKENS, NETMIND_LARGE_OUTPUT_TOKENS, NETMIND_MAX_OUTPUT_TOKENS, supportsNetmindJsonResponseFormat, emptyResponseDiagnostics, effectiveMaxTokensFor, completeRawOpenAICompatibleJsonChat, createAiSdkProvider, createFallbackClient, DEFAULT_MAX_RETRIES, DEFAULT_BASE_DELAY_MS, DEFAULT_MAX_DELAY_MS, DEFAULT_RESET_SAFETY_MS, DEFAULT_JITTER_MS, sleep, isRateLimitError, parseProviderRetryDelayMs, rateLimitRetryDelayMs, createRateLimitRetryClient, numberLines, renderPrompt, cache, loadPromptTemplate, nullableOptional, AI_VIOLATION_MESSAGE_MAX_LENGTH, aiViolationSchema, aiResponseSchema, stripCodeFence, parseAiResponse, createInMemoryCache, VIETNAMESE_OUTPUT_POLICY_VERSION, VIETNAMESE_OUTPUT_INSTRUCTION, TOKEN_BUDGET_WARN_DEFAULT, CHARS_PER_TOKEN, SAFETY_MARGIN, estimateTokens, formatTokenWarning, braceDelta, chunkSourceForAi, renderAuthorizationGuards, CACHE_NAMESPACE, DEFAULT_PROVIDER_RETRY_MAX_RETRIES, DEFAULT_PROVIDER_RETRY_MAX_DELAY_MS, DEFAULT_ADAPTIVE_RETRY_MAX_RETRIES, DEFAULT_ADAPTIVE_CONTEXT_REDUCTION_FACTOR, DEFAULT_ADAPTIVE_TIMEOUT_MULTIPLIER, DEFAULT_ADAPTIVE_MAX_DELAY_MS, DEFAULT_PROVIDER_TIMEOUT_MS, sleep2, providerRetryDelayMs, adaptiveFailureKind, compactClusterContext, findingDedupeKey, dedupeFindings, capFindings, createAiExecutor, PATH_FAST_PATHS, SPRING_BOOT_PATTERNS, ANGULAR_PATTERNS, FLUTTER_PATTERNS, ENTRY_HINTS, ALL_PATTERNS, matchesRule, classifyLayer, classifyLayers, PRIMARY_LAYER_CANDIDATES, TEST_AND_GENERATED, LAYER_SUFFIXES, FILE_SUFFIX_RE, ANY_EXT_RE, dropExt, stripPascalSuffix, normalize2, extractDomainTokens, extractDomainTokensBatch, TRIVIAL_TOKENS, sharesDomainToken, TS_IMPORT_RE, JAVA_IMPORT_RE, extractImports, POSIX_SEP_RE, sharedDirDepth, resolveImportTarget, KIND_STRENGTH, upsertEdge, buildEdges, ADVICE_ANNOTATION, isGlobalAdviceFile, findGlobalAdvicePaths, DEFAULT_MAX_CANDIDATES, DEFAULT_MAX_SUPPORT_FILES, DEFAULT_TOKEN_BUDGET, SCORE_DIRECT_NEIGHBOR, SCORE_SECOND_DEGREE, SCORE_SIBLING_STEM, SCORE_ANGULAR_TEMPLATE_SIBLING, SCORE_DOMAIN_TOKEN, PENALTY_TEST_VS_NON_TEST, PENALTY_GENERATED, SCORE_GLOBAL_ADVICE, prefilterCandidates, layerFlowBonus, isTest, isGenerated, scoreFor, tokensOf, trimToBudget, toMember, clusterIdFor, createClusterAssembler, CLUSTER_TREE_BUILDER_VERSION, DEFAULT_MODULE_DEPTH, posixDirname, moduleGroupKey, uniqueSortedPaths, memberFingerprint, featureNodeFor, moduleNodeFor, appNodeFor, countCrossModuleEdges, createClusterTreeBuilder, TRANSACTIONAL, TYPE_DECL3, METHOD_NAME2, MUTATION_CALL, LEADING_ANNOTATION2, SPRING_TX_SUPPORT_IMPORT, PROGRAMMATIC_TYPE, PROGRAMMATIC_CALL, INLINE_TEMPLATE_CALL, CONTROL_FLOW_NAMES, maskNonCode, methodNameFromHeader, methodAt, delegatedTargetAt, collectProgrammaticReceivers, readAttr, skipToDeclaration2, countMutations, lineOf25, configuredReadOnly, extractProgrammaticFromFile, extractFromFile2, extractTransactionBoundaries, renderPrDiffPrompt, nullableOptional2, prDiffResponseSchema, createPrDiffReviewer, renderGroupedRulePrompt, confidenceLabelSchema, severitySchema, groupedResponseSchema, labelToConfidence, createGroupedRuleReviewer, renderPerRulePrompt, createPerRuleReviewer, DEFAULT_MAX_TOKENS, SYSTEM_PROMPT, SCHEMA_PROMPT, clip, buildUserPrompt, extractJsonObject, describeUnusableAnswer, createRuntimeAuthHypothesisResolver, DEFAULT_MAX_TOKENS2, SYSTEM_PROMPT2, SCHEMA_PROMPT2, clip2, buildUserPrompt2, describeUnusableAnswer2, createRuntimeDataSeedResolver, endpointSchema, extractJsonObject2, HTTP_METHODS, PARAMETER_KINDS, ENGLISH_REASON_WORDS, ENGLISH_TECHNICAL_WORDS, VIETNAMESE_DIACRITICS, isLikelyEnglishReason, normalizeTriageReason, parseEndpointHint, checkAiConnection;
|
|
37677
|
+
var OLLAMA_DEFAULT_BASE, NETMIND_DEFAULT_BASE, OPENCODE_GO_DEFAULT_BASE, stripTrailingSlash2, buildLanguageModel, resolveModelOverride, pingTarget, shouldUseRawJsonChat, openAICompatibleChatUrl, REASONING_HEADROOM_TOKENS, NETMIND_MINIMAX_M3_MODEL, NETMIND_SMALL_PROMPT_MAX_CHARS, NETMIND_MEDIUM_PROMPT_MAX_CHARS, NETMIND_SMALL_OUTPUT_TOKENS, NETMIND_MEDIUM_OUTPUT_TOKENS, NETMIND_LARGE_OUTPUT_TOKENS, NETMIND_MAX_OUTPUT_TOKENS, supportsNetmindJsonResponseFormat, emptyResponseDiagnostics, effectiveMaxTokensFor, completeRawOpenAICompatibleJsonChat, createAiSdkProvider, createFallbackClient, DEFAULT_MAX_RETRIES, DEFAULT_BASE_DELAY_MS, DEFAULT_MAX_DELAY_MS, DEFAULT_RESET_SAFETY_MS, DEFAULT_JITTER_MS, sleep, isRateLimitError, parseProviderRetryDelayMs, rateLimitRetryDelayMs, createRateLimitRetryClient, numberLines, renderPrompt, cache, loadPromptTemplate, nullableOptional, AI_VIOLATION_MESSAGE_MAX_LENGTH, aiViolationSchema, aiResponseSchema, stripCodeFence, parseAiResponse, createInMemoryCache, VIETNAMESE_OUTPUT_POLICY_VERSION, VIETNAMESE_OUTPUT_INSTRUCTION, TOKEN_BUDGET_WARN_DEFAULT, CHARS_PER_TOKEN, SAFETY_MARGIN, estimateTokens, formatTokenWarning, braceDelta, chunkSourceForAi, renderAuthorizationGuards, CACHE_NAMESPACE, DEFAULT_PROVIDER_RETRY_MAX_RETRIES, DEFAULT_PROVIDER_RETRY_MAX_DELAY_MS, DEFAULT_ADAPTIVE_RETRY_MAX_RETRIES, DEFAULT_ADAPTIVE_CONTEXT_REDUCTION_FACTOR, DEFAULT_ADAPTIVE_TIMEOUT_MULTIPLIER, DEFAULT_ADAPTIVE_MAX_DELAY_MS, DEFAULT_PROVIDER_TIMEOUT_MS, sleep2, providerRetryDelayMs, adaptiveFailureKind, compactClusterContext, findingDedupeKey, dedupeFindings, capFindings, createAiExecutor, PATH_FAST_PATHS, SPRING_BOOT_PATTERNS, ANGULAR_PATTERNS, FLUTTER_PATTERNS, ENTRY_HINTS, ALL_PATTERNS, matchesRule, classifyLayer, classifyLayers, PRIMARY_LAYER_CANDIDATES, TEST_AND_GENERATED, LAYER_SUFFIXES, FILE_SUFFIX_RE, ANY_EXT_RE, dropExt, stripPascalSuffix, normalize2, extractDomainTokens, extractDomainTokensBatch, TRIVIAL_TOKENS, sharesDomainToken, TS_IMPORT_RE, JAVA_IMPORT_RE, extractImports, POSIX_SEP_RE, sharedDirDepth, resolveImportTarget, KIND_STRENGTH, upsertEdge, buildEdges, ADVICE_ANNOTATION, isGlobalAdviceFile, findGlobalAdvicePaths, DEFAULT_MAX_CANDIDATES, DEFAULT_MAX_SUPPORT_FILES, DEFAULT_TOKEN_BUDGET, SCORE_DIRECT_NEIGHBOR, SCORE_SECOND_DEGREE, SCORE_SIBLING_STEM, SCORE_ANGULAR_TEMPLATE_SIBLING, SCORE_DOMAIN_TOKEN, PENALTY_TEST_VS_NON_TEST, PENALTY_GENERATED, SCORE_GLOBAL_ADVICE, prefilterCandidates, layerFlowBonus, isTest, isGenerated, scoreFor, tokensOf, trimToBudget, toMember, clusterIdFor, createClusterAssembler, CLUSTER_TREE_BUILDER_VERSION, DEFAULT_MODULE_DEPTH, posixDirname, moduleGroupKey, uniqueSortedPaths, memberFingerprint, featureNodeFor, moduleNodeFor, appNodeFor, countCrossModuleEdges, createClusterTreeBuilder, TRANSACTIONAL, TYPE_DECL3, METHOD_NAME2, MUTATION_CALL, LEADING_ANNOTATION2, SPRING_TX_SUPPORT_IMPORT, PROGRAMMATIC_TYPE, PROGRAMMATIC_CALL, INLINE_TEMPLATE_CALL, CONTROL_FLOW_NAMES, maskNonCode, methodNameFromHeader, methodAt, delegatedTargetAt, collectProgrammaticReceivers, readAttr, skipToDeclaration2, countMutations, lineOf25, configuredReadOnly, extractProgrammaticFromFile, extractFromFile2, extractTransactionBoundaries, renderPrDiffPrompt, nullableOptional2, prDiffResponseSchema, createPrDiffReviewer, renderGroupedRulePrompt, confidenceLabelSchema, SEVERITY_ALIASES, severitySchema, groupedResponseSchema, labelToConfidence, createGroupedRuleReviewer, renderPerRulePrompt, createPerRuleReviewer, DEFAULT_MAX_TOKENS, SYSTEM_PROMPT, SCHEMA_PROMPT, clip, buildUserPrompt, extractJsonObject, describeUnusableAnswer, createRuntimeAuthHypothesisResolver, DEFAULT_MAX_TOKENS2, SYSTEM_PROMPT2, SCHEMA_PROMPT2, clip2, buildUserPrompt2, describeUnusableAnswer2, createRuntimeDataSeedResolver, endpointSchema, extractJsonObject2, HTTP_METHODS, PARAMETER_KINDS, ENGLISH_REASON_WORDS, ENGLISH_TECHNICAL_WORDS, VIETNAMESE_DIACRITICS, isLikelyEnglishReason, normalizeTriageReason, parseEndpointHint, checkAiConnection;
|
|
37678
37678
|
var init_dist4 = __esm({
|
|
37679
37679
|
"../ai-engine/dist/index.js"() {
|
|
37680
37680
|
init_dist();
|
|
@@ -40230,7 +40230,27 @@ ${file.content}
|
|
|
40230
40230
|
return parts.join("\n");
|
|
40231
40231
|
};
|
|
40232
40232
|
confidenceLabelSchema = external_exports.enum(["low", "medium", "high"]).optional();
|
|
40233
|
-
|
|
40233
|
+
SEVERITY_ALIASES = {
|
|
40234
|
+
info: "info",
|
|
40235
|
+
low: "info",
|
|
40236
|
+
minor: "info",
|
|
40237
|
+
note: "info",
|
|
40238
|
+
suggestion: "info",
|
|
40239
|
+
warning: "warning",
|
|
40240
|
+
warn: "warning",
|
|
40241
|
+
medium: "warning",
|
|
40242
|
+
moderate: "warning",
|
|
40243
|
+
error: "error",
|
|
40244
|
+
high: "error",
|
|
40245
|
+
major: "error",
|
|
40246
|
+
blocker: "blocker",
|
|
40247
|
+
critical: "blocker",
|
|
40248
|
+
fatal: "blocker"
|
|
40249
|
+
};
|
|
40250
|
+
severitySchema = external_exports.preprocess(
|
|
40251
|
+
(value) => typeof value === "string" ? SEVERITY_ALIASES[value.trim().toLowerCase()] : void 0,
|
|
40252
|
+
external_exports.enum(["info", "warning", "error", "blocker"]).optional()
|
|
40253
|
+
);
|
|
40234
40254
|
groupedResponseSchema = external_exports.object({
|
|
40235
40255
|
ruleResults: external_exports.array(
|
|
40236
40256
|
external_exports.object({
|
|
@@ -60367,11 +60387,11 @@ var definedBuildValue = (value, fallback) => typeof value === "string" && value.
|
|
|
60367
60387
|
var getCliBuildMetadata = (version2) => ({
|
|
60368
60388
|
version: version2,
|
|
60369
60389
|
gitSha: definedBuildValue(
|
|
60370
|
-
"
|
|
60390
|
+
"9da49e9424a8" ,
|
|
60371
60391
|
"unknown"
|
|
60372
60392
|
),
|
|
60373
60393
|
buildTimestamp: definedBuildValue(
|
|
60374
|
-
"2026-11-
|
|
60394
|
+
"2026-11-27T06:51:28.365Z" ,
|
|
60375
60395
|
"unknown"
|
|
60376
60396
|
),
|
|
60377
60397
|
configSchemaRange: definedBuildValue(
|
|
@@ -66484,6 +66504,9 @@ var collectPrRuleGroups = (rules, options = {}) => {
|
|
|
66484
66504
|
})).sort((a, b) => a.id.localeCompare(b.id));
|
|
66485
66505
|
};
|
|
66486
66506
|
var classifyRuleApplicability = (rule, profile) => {
|
|
66507
|
+
if (profile.file.language !== void 0 && rule.languages.length > 0 && !rule.languages.includes(profile.file.language)) {
|
|
66508
|
+
return PR_RULE_APPLICABILITY.NOT_APPLICABLE;
|
|
66509
|
+
}
|
|
66487
66510
|
const routing = rule.prRouting;
|
|
66488
66511
|
if (!routing) return PR_RULE_APPLICABILITY.UNKNOWN;
|
|
66489
66512
|
if (routing.targetLayers.length > 0 && !routing.targetLayers.includes(profile.layer)) {
|
|
@@ -66966,6 +66989,31 @@ var createOneShotPhaseLogger = (env = process.env) => {
|
|
|
66966
66989
|
}
|
|
66967
66990
|
};
|
|
66968
66991
|
};
|
|
66992
|
+
|
|
66993
|
+
// src/review-gate.ts
|
|
66994
|
+
init_dist2();
|
|
66995
|
+
init_exit_codes();
|
|
66996
|
+
var resolveGatePolicy = (configGate, override, skipOverride) => ({
|
|
66997
|
+
aiPolicy: override ?? configGate.aiPolicy,
|
|
66998
|
+
aiMinConfidence: configGate.aiMinConfidence,
|
|
66999
|
+
aiSkipPolicy: skipOverride ?? configGate.aiSkipPolicy
|
|
67000
|
+
});
|
|
67001
|
+
var computeGateResult = (findings2, ruleKindById, policy) => {
|
|
67002
|
+
let gatingBlocker = 0;
|
|
67003
|
+
let gatingError = 0;
|
|
67004
|
+
let advisoryErrorPlus = 0;
|
|
67005
|
+
for (const f of findings2) {
|
|
67006
|
+
const source = ruleKindById.get(f.ruleId) === "ai" ? "ai" : "deterministic";
|
|
67007
|
+
if (findingGates(f, source, policy)) {
|
|
67008
|
+
if (f.severity === "blocker") gatingBlocker++;
|
|
67009
|
+
else if (f.severity === "error") gatingError++;
|
|
67010
|
+
} else if (source === "ai" && meetsSeverity(f.severity, "error")) {
|
|
67011
|
+
advisoryErrorPlus++;
|
|
67012
|
+
}
|
|
67013
|
+
}
|
|
67014
|
+
const exitCode = gatingBlocker > 0 ? EXIT.FINDINGS_BLOCKER : gatingError > 0 ? EXIT.FINDINGS_ERROR : EXIT.SUCCESS;
|
|
67015
|
+
return { exitCode, gatingError, gatingBlocker, advisoryErrorPlus };
|
|
67016
|
+
};
|
|
66969
67017
|
var Counters = ({ counts, sourceCounts }) => /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
|
|
66970
67018
|
/* @__PURE__ */ jsxs(Box, { children: [
|
|
66971
67019
|
/* @__PURE__ */ jsx(Text, { color: "blue", children: "\u258C" }),
|
|
@@ -67682,6 +67730,9 @@ var createGitLabClient = (options) => {
|
|
|
67682
67730
|
if (!result.ok) return result;
|
|
67683
67731
|
return toMergeRequest(result.value);
|
|
67684
67732
|
},
|
|
67733
|
+
async fetchCurrentUser() {
|
|
67734
|
+
return request("GET", "/user");
|
|
67735
|
+
},
|
|
67685
67736
|
async listNotes(target) {
|
|
67686
67737
|
return requestAllPages(mrPath(target, "/notes"));
|
|
67687
67738
|
},
|
|
@@ -67710,6 +67761,27 @@ var createGitLabClient = (options) => {
|
|
|
67710
67761
|
});
|
|
67711
67762
|
if (!result.ok) return result;
|
|
67712
67763
|
return ok(void 0);
|
|
67764
|
+
},
|
|
67765
|
+
async listDiscussions(target) {
|
|
67766
|
+
return requestAllPages(mrPath(target, "/discussions"));
|
|
67767
|
+
},
|
|
67768
|
+
async compareCommits(target, from, to) {
|
|
67769
|
+
const query = `from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}&straight=true`;
|
|
67770
|
+
const result = await request(
|
|
67771
|
+
"GET",
|
|
67772
|
+
`/projects/${encodeProjectPath(target.projectPath)}/repository/compare?${query}`
|
|
67773
|
+
);
|
|
67774
|
+
if (!result.ok) return result;
|
|
67775
|
+
return ok(result.value.diffs ?? []);
|
|
67776
|
+
},
|
|
67777
|
+
async resolveDiscussion(target, discussionId) {
|
|
67778
|
+
const result = await request(
|
|
67779
|
+
"PUT",
|
|
67780
|
+
mrPath(target, `/discussions/${encodeURIComponent(discussionId)}`),
|
|
67781
|
+
{ resolved: true }
|
|
67782
|
+
);
|
|
67783
|
+
if (!result.ok) return result;
|
|
67784
|
+
return ok(void 0);
|
|
67713
67785
|
}
|
|
67714
67786
|
};
|
|
67715
67787
|
};
|
|
@@ -67718,9 +67790,13 @@ var createGitLabClient = (options) => {
|
|
|
67718
67790
|
init_dist2();
|
|
67719
67791
|
init_dist5();
|
|
67720
67792
|
init_dist();
|
|
67721
|
-
var
|
|
67793
|
+
var summaryMarker = (kind) => `<!-- code-sentinel:pr-review:${kind} -->`;
|
|
67794
|
+
var LEGACY_SUMMARY_MARKER = "<!-- code-sentinel:pr-review -->";
|
|
67795
|
+
var SUMMARY_MARKER_PATTERN = /<!-- code-sentinel:pr-review(?::(static|ai))? -->/;
|
|
67722
67796
|
var fingerprintMarker = (fingerprint) => `<!-- code-sentinel:finding ${fingerprint} -->`;
|
|
67723
67797
|
var FINDING_MARKER_PATTERN = /code-sentinel:finding\s+([a-f0-9]+)/g;
|
|
67798
|
+
var inlineKindMarker = (kind) => `<!-- code-sentinel:kind ${kind} -->`;
|
|
67799
|
+
var INLINE_KIND_PATTERN = /code-sentinel:kind (static|ai)/;
|
|
67724
67800
|
var SEVERITIES = ["blocker", "error", "warning", "info"];
|
|
67725
67801
|
var escapeTableCell2 = (value) => value.replace(/\\/g, "\\\\").replace(/\|/g, "\\|").replace(/\r?\n/g, "<br>");
|
|
67726
67802
|
var countBySeverity3 = (findings2) => {
|
|
@@ -67739,9 +67815,10 @@ var renderPrSummary = (options) => {
|
|
|
67739
67815
|
...options.summaryOnly
|
|
67740
67816
|
].sort(compareFindings);
|
|
67741
67817
|
const severityCounts = countBySeverity3(allFindings);
|
|
67818
|
+
const kind = options.reviewKind ?? "static";
|
|
67742
67819
|
const lines = [
|
|
67743
|
-
|
|
67744
|
-
|
|
67820
|
+
summaryMarker(kind),
|
|
67821
|
+
`## Code Sentinel PR Review Report (${kind === "ai" ? "AI + static" : "static"})`,
|
|
67745
67822
|
"",
|
|
67746
67823
|
`**Run**: \`${options.runId}\``,
|
|
67747
67824
|
"",
|
|
@@ -67786,8 +67863,9 @@ var renderPrSummary = (options) => {
|
|
|
67786
67863
|
}
|
|
67787
67864
|
return lines.join("\n");
|
|
67788
67865
|
};
|
|
67789
|
-
var renderInlineComment = (item16) => [
|
|
67866
|
+
var renderInlineComment = (item16, kind) => [
|
|
67790
67867
|
fingerprintMarker(item16.fingerprint),
|
|
67868
|
+
inlineKindMarker(kind),
|
|
67791
67869
|
`**${item16.finding.ruleId}** (${item16.finding.severity})`,
|
|
67792
67870
|
"",
|
|
67793
67871
|
item16.finding.message,
|
|
@@ -67795,7 +67873,92 @@ var renderInlineComment = (item16) => [
|
|
|
67795
67873
|
item16.finding.suggestion ? `
|
|
67796
67874
|
Suggestion: ${item16.finding.suggestion}` : ""
|
|
67797
67875
|
].filter((part) => part.length > 0).join("\n");
|
|
67798
|
-
var isCodeSentinelNote = (body) =>
|
|
67876
|
+
var isCodeSentinelNote = (body) => SUMMARY_MARKER_PATTERN.test(body) || body.includes("code-sentinel:finding");
|
|
67877
|
+
var isOwnNote = (note, currentUserId) => note.author === void 0 ? true : currentUserId !== null && note.author.id === currentUserId;
|
|
67878
|
+
var isOwnSummaryOfKind = (note, kind, currentUserId) => isOwnNote(note, currentUserId) && (note.body.includes(summaryMarker(kind)) || note.body.includes(LEGACY_SUMMARY_MARKER));
|
|
67879
|
+
var touchedOldLines = (diff) => {
|
|
67880
|
+
const touched = /* @__PURE__ */ new Set();
|
|
67881
|
+
let oldLine = 0;
|
|
67882
|
+
for (const line2 of diff.split("\n")) {
|
|
67883
|
+
const hunk = /^@@ -(\d+)(?:,\d+)? \+\d+(?:,\d+)? @@/.exec(line2);
|
|
67884
|
+
if (hunk) {
|
|
67885
|
+
oldLine = Number(hunk[1]);
|
|
67886
|
+
continue;
|
|
67887
|
+
}
|
|
67888
|
+
if (line2.startsWith("-")) {
|
|
67889
|
+
touched.add(oldLine);
|
|
67890
|
+
oldLine++;
|
|
67891
|
+
} else if (line2.startsWith("+") || line2.startsWith("\\")) ; else {
|
|
67892
|
+
oldLine++;
|
|
67893
|
+
}
|
|
67894
|
+
}
|
|
67895
|
+
return touched;
|
|
67896
|
+
};
|
|
67897
|
+
var pruneStaleOwnFindings = async (options, kind, currentUserId) => {
|
|
67898
|
+
const removedNoteIds = /* @__PURE__ */ new Set();
|
|
67899
|
+
const standing = /* @__PURE__ */ new Set();
|
|
67900
|
+
const discussions = await options.client.listDiscussions(options.target);
|
|
67901
|
+
if (!discussions.ok) return discussions;
|
|
67902
|
+
const current = new Set(options.inlineable.map((item16) => item16.fingerprint));
|
|
67903
|
+
const touchedByFrom = /* @__PURE__ */ new Map();
|
|
67904
|
+
const codeChanged = async (head) => {
|
|
67905
|
+
const from = head.position?.head_sha;
|
|
67906
|
+
const path = head.position?.new_path;
|
|
67907
|
+
const line2 = head.position?.new_line;
|
|
67908
|
+
if (!options.headSha || !from || !path || !line2 || from === options.headSha) return ok(false);
|
|
67909
|
+
let byPath = touchedByFrom.get(from);
|
|
67910
|
+
if (!byPath) {
|
|
67911
|
+
const diffs = await options.client.compareCommits(options.target, from, options.headSha);
|
|
67912
|
+
if (!diffs.ok) return diffs;
|
|
67913
|
+
byPath = new Map(diffs.value.map((d) => [d.old_path, touchedOldLines(d.diff)]));
|
|
67914
|
+
touchedByFrom.set(from, byPath);
|
|
67915
|
+
}
|
|
67916
|
+
return ok(byPath.get(path)?.has(line2) ?? false);
|
|
67917
|
+
};
|
|
67918
|
+
let deleted = 0;
|
|
67919
|
+
let resolved = 0;
|
|
67920
|
+
for (const discussion of discussions.value) {
|
|
67921
|
+
const head = discussion.notes[0];
|
|
67922
|
+
if (!head) continue;
|
|
67923
|
+
let prune = false;
|
|
67924
|
+
if (currentUserId !== null && isStaleOwnFinding(head, kind, currentUserId, current)) {
|
|
67925
|
+
const changed = await codeChanged(head);
|
|
67926
|
+
if (!changed.ok) return changed;
|
|
67927
|
+
prune = changed.value;
|
|
67928
|
+
}
|
|
67929
|
+
if (!prune) {
|
|
67930
|
+
const key = standingKey(head);
|
|
67931
|
+
if (key) standing.add(key);
|
|
67932
|
+
continue;
|
|
67933
|
+
}
|
|
67934
|
+
if (discussion.notes.length === 1) {
|
|
67935
|
+
const result = await options.client.deleteNote(options.target, head.id);
|
|
67936
|
+
if (!result.ok) return result;
|
|
67937
|
+
removedNoteIds.add(head.id);
|
|
67938
|
+
deleted++;
|
|
67939
|
+
} else {
|
|
67940
|
+
const result = await options.client.resolveDiscussion(options.target, discussion.id);
|
|
67941
|
+
if (!result.ok) return result;
|
|
67942
|
+
resolved++;
|
|
67943
|
+
}
|
|
67944
|
+
}
|
|
67945
|
+
return ok({ deleted, resolved, removedNoteIds, standing });
|
|
67946
|
+
};
|
|
67947
|
+
var standingKey = (note) => {
|
|
67948
|
+
const ruleId = /\*\*([^*\s]+)\*\*/.exec(note.body)?.[1];
|
|
67949
|
+
const path = note.position?.new_path;
|
|
67950
|
+
const line2 = note.position?.new_line;
|
|
67951
|
+
if (!ruleId || !path || !line2 || !note.body.includes("code-sentinel:finding")) return null;
|
|
67952
|
+
return `${ruleId}|${path}|${line2}`;
|
|
67953
|
+
};
|
|
67954
|
+
var itemKey = (item16) => `${item16.finding.ruleId}|${item16.position.newPath}|${item16.position.newLine ?? ""}`;
|
|
67955
|
+
var isStaleOwnFinding = (head, kind, currentUserId, current) => {
|
|
67956
|
+
if (head.author?.id !== currentUserId || head.resolved === true) return false;
|
|
67957
|
+
const fingerprint = /code-sentinel:finding\s+([a-f0-9]+)/.exec(head.body)?.[1];
|
|
67958
|
+
if (!fingerprint || current.has(fingerprint)) return false;
|
|
67959
|
+
const noteKind = INLINE_KIND_PATTERN.exec(head.body)?.[1];
|
|
67960
|
+
return noteKind === void 0 || noteKind === kind;
|
|
67961
|
+
};
|
|
67799
67962
|
var publishPrReview = async (options) => {
|
|
67800
67963
|
const summaryBody = renderPrSummary(options);
|
|
67801
67964
|
if (options.dryRun) {
|
|
@@ -67804,23 +67967,32 @@ var publishPrReview = async (options) => {
|
|
|
67804
67967
|
inlinePosted: 0,
|
|
67805
67968
|
inlineSkipped: 0,
|
|
67806
67969
|
inlineFailed: 0,
|
|
67807
|
-
deletedExisting: 0
|
|
67970
|
+
deletedExisting: 0,
|
|
67971
|
+
staleDeleted: 0,
|
|
67972
|
+
staleResolved: 0
|
|
67808
67973
|
});
|
|
67809
67974
|
}
|
|
67975
|
+
const kind = options.reviewKind ?? "static";
|
|
67976
|
+
const currentUser = await options.client.fetchCurrentUser();
|
|
67977
|
+
const currentUserId = currentUser.ok ? currentUser.value.id : null;
|
|
67810
67978
|
const notesResult = await options.client.listNotes(options.target);
|
|
67811
67979
|
if (!notesResult.ok) return notesResult;
|
|
67812
67980
|
let activeNotes = notesResult.value;
|
|
67813
67981
|
let deletedExisting = 0;
|
|
67814
67982
|
if (options.cleanupExistingComments) {
|
|
67983
|
+
const kept = [];
|
|
67815
67984
|
for (const note of activeNotes) {
|
|
67816
|
-
if (!isCodeSentinelNote(note.body))
|
|
67985
|
+
if (!isCodeSentinelNote(note.body) || !isOwnNote(note, currentUserId)) {
|
|
67986
|
+
kept.push(note);
|
|
67987
|
+
continue;
|
|
67988
|
+
}
|
|
67817
67989
|
const deleted = await options.client.deleteNote(options.target, note.id);
|
|
67818
67990
|
if (!deleted.ok) return deleted;
|
|
67819
67991
|
deletedExisting++;
|
|
67820
67992
|
}
|
|
67821
|
-
activeNotes =
|
|
67993
|
+
activeNotes = kept;
|
|
67822
67994
|
}
|
|
67823
|
-
const existingSummary = activeNotes.find((note) => note
|
|
67995
|
+
const existingSummary = activeNotes.find((note) => isOwnSummaryOfKind(note, kind, currentUserId));
|
|
67824
67996
|
if (existingSummary) {
|
|
67825
67997
|
const updated = await options.client.updateNote(
|
|
67826
67998
|
options.target,
|
|
@@ -67833,10 +68005,21 @@ var publishPrReview = async (options) => {
|
|
|
67833
68005
|
if (!created.ok) return created;
|
|
67834
68006
|
}
|
|
67835
68007
|
if (options.summaryOnlyMode) {
|
|
67836
|
-
return ok({
|
|
68008
|
+
return ok({
|
|
68009
|
+
summaryBody,
|
|
68010
|
+
inlinePosted: 0,
|
|
68011
|
+
inlineSkipped: 0,
|
|
68012
|
+
inlineFailed: 0,
|
|
68013
|
+
deletedExisting,
|
|
68014
|
+
staleDeleted: 0,
|
|
68015
|
+
staleResolved: 0
|
|
68016
|
+
});
|
|
67837
68017
|
}
|
|
68018
|
+
const pruned = await pruneStaleOwnFindings(options, kind, currentUserId);
|
|
68019
|
+
if (!pruned.ok) return pruned;
|
|
67838
68020
|
const existingFingerprints = /* @__PURE__ */ new Set();
|
|
67839
68021
|
for (const note of activeNotes) {
|
|
68022
|
+
if (pruned.value.removedNoteIds.has(note.id)) continue;
|
|
67840
68023
|
for (const match of note.body.matchAll(FINDING_MARKER_PATTERN)) {
|
|
67841
68024
|
if (match[1]) existingFingerprints.add(match[1]);
|
|
67842
68025
|
}
|
|
@@ -67846,13 +68029,13 @@ var publishPrReview = async (options) => {
|
|
|
67846
68029
|
let inlineSkipped = options.inlineable.length - budgeted.length;
|
|
67847
68030
|
let inlineFailed = 0;
|
|
67848
68031
|
for (const item16 of budgeted) {
|
|
67849
|
-
if (existingFingerprints.has(item16.fingerprint)) {
|
|
68032
|
+
if (existingFingerprints.has(item16.fingerprint) || pruned.value.standing.has(itemKey(item16))) {
|
|
67850
68033
|
inlineSkipped++;
|
|
67851
68034
|
continue;
|
|
67852
68035
|
}
|
|
67853
68036
|
const result = await options.client.createDiscussion(
|
|
67854
68037
|
options.target,
|
|
67855
|
-
renderInlineComment(item16),
|
|
68038
|
+
renderInlineComment(item16, kind),
|
|
67856
68039
|
item16.position
|
|
67857
68040
|
);
|
|
67858
68041
|
if (!result.ok) {
|
|
@@ -67861,7 +68044,15 @@ var publishPrReview = async (options) => {
|
|
|
67861
68044
|
}
|
|
67862
68045
|
inlinePosted++;
|
|
67863
68046
|
}
|
|
67864
|
-
return ok({
|
|
68047
|
+
return ok({
|
|
68048
|
+
summaryBody,
|
|
68049
|
+
inlinePosted,
|
|
68050
|
+
inlineSkipped,
|
|
68051
|
+
inlineFailed,
|
|
68052
|
+
deletedExisting,
|
|
68053
|
+
staleDeleted: pruned.value.deleted,
|
|
68054
|
+
staleResolved: pruned.value.resolved
|
|
68055
|
+
});
|
|
67865
68056
|
};
|
|
67866
68057
|
|
|
67867
68058
|
// src/pr/static-review.ts
|
|
@@ -68407,6 +68598,11 @@ var printDryRunSummary = (target, findings2, reportPaths, codeQualityPath) => {
|
|
|
68407
68598
|
}
|
|
68408
68599
|
console.log(green(` GitLab Code Quality: ${codeQualityPath}`));
|
|
68409
68600
|
};
|
|
68601
|
+
var computePrGate = (findings2, ruleKindById, configGate, aiGatePolicy) => computeGateResult(
|
|
68602
|
+
findings2,
|
|
68603
|
+
new Map([...ruleKindById, ["ai/pr-diff-review", "ai"]]),
|
|
68604
|
+
resolveGatePolicy(configGate, aiGatePolicy)
|
|
68605
|
+
);
|
|
68410
68606
|
var sourceCountsForFindings = (findings2, ruleKindById) => {
|
|
68411
68607
|
const counts = { static: 0, ai: 0 };
|
|
68412
68608
|
for (const finding of findings2) {
|
|
@@ -69265,6 +69461,9 @@ var runPrReview = async (options) => {
|
|
|
69265
69461
|
staticResult.ruleKindById
|
|
69266
69462
|
),
|
|
69267
69463
|
maxInlineComments,
|
|
69464
|
+
// A static-only CI bot and a developer's AI run each keep their own MR summary.
|
|
69465
|
+
reviewKind: (aiStats?.succeeded ?? 0) > 0 ? "ai" : "static",
|
|
69466
|
+
headSha: mr.diffRefs.headSha,
|
|
69268
69467
|
summaryOnlyMode: options.summaryOnly,
|
|
69269
69468
|
cleanupExistingComments: config.prReview.cleanupExistingComments,
|
|
69270
69469
|
dryRun: !options.post
|
|
@@ -69296,7 +69495,7 @@ var runPrReview = async (options) => {
|
|
|
69296
69495
|
console.log(green(`Posted GitLab PR review for ${target.projectPath}!${target.iid}`));
|
|
69297
69496
|
console.log(
|
|
69298
69497
|
gray(
|
|
69299
|
-
` Deleted existing: ${publishResult.value.deletedExisting}; inline posted: ${publishResult.value.inlinePosted}; inline skipped: ${publishResult.value.inlineSkipped}; inline failed: ${publishResult.value.inlineFailed}`
|
|
69498
|
+
` Deleted existing: ${publishResult.value.deletedExisting}; inline posted: ${publishResult.value.inlinePosted}; inline skipped: ${publishResult.value.inlineSkipped}; inline failed: ${publishResult.value.inlineFailed}; stale removed: ${publishResult.value.staleDeleted}; stale resolved: ${publishResult.value.staleResolved}`
|
|
69300
69499
|
)
|
|
69301
69500
|
);
|
|
69302
69501
|
} else if (!options.silent) {
|
|
@@ -69309,16 +69508,17 @@ var runPrReview = async (options) => {
|
|
|
69309
69508
|
);
|
|
69310
69509
|
}
|
|
69311
69510
|
}
|
|
69312
|
-
|
|
69313
|
-
|
|
69314
|
-
|
|
69315
|
-
|
|
69316
|
-
|
|
69317
|
-
|
|
69318
|
-
|
|
69319
|
-
|
|
69320
|
-
|
|
69321
|
-
|
|
69511
|
+
const gate = computePrGate(
|
|
69512
|
+
mergedFindings,
|
|
69513
|
+
staticResult.ruleKindById,
|
|
69514
|
+
config.review.gate,
|
|
69515
|
+
options.aiGatePolicy
|
|
69516
|
+
);
|
|
69517
|
+
phaseLog.info(
|
|
69518
|
+
"quality-gate",
|
|
69519
|
+
`exit_code=${gate.exitCode} gating_blocker=${gate.gatingBlocker} gating_error=${gate.gatingError} advisory_ai_error_plus=${gate.advisoryErrorPlus}`
|
|
69520
|
+
);
|
|
69521
|
+
return gate.exitCode;
|
|
69322
69522
|
} catch (error) {
|
|
69323
69523
|
phaseLog.error(activeReviewPhase, error.message);
|
|
69324
69524
|
const renderer = getInkRenderer();
|
|
@@ -71380,27 +71580,6 @@ var SERVER_RUN_PROGRESS_PREFIX = "cs-progress ";
|
|
|
71380
71580
|
var log2 = (silent, msg) => {
|
|
71381
71581
|
if (!silent) console.log(msg);
|
|
71382
71582
|
};
|
|
71383
|
-
var resolveGatePolicy = (configGate, override, skipOverride) => ({
|
|
71384
|
-
aiPolicy: override ?? configGate.aiPolicy,
|
|
71385
|
-
aiMinConfidence: configGate.aiMinConfidence,
|
|
71386
|
-
aiSkipPolicy: skipOverride ?? configGate.aiSkipPolicy
|
|
71387
|
-
});
|
|
71388
|
-
var computeGateResult = (findings2, ruleKindById, policy) => {
|
|
71389
|
-
let gatingBlocker = 0;
|
|
71390
|
-
let gatingError = 0;
|
|
71391
|
-
let advisoryErrorPlus = 0;
|
|
71392
|
-
for (const f of findings2) {
|
|
71393
|
-
const source = ruleKindById.get(f.ruleId) === "ai" ? "ai" : "deterministic";
|
|
71394
|
-
if (findingGates(f, source, policy)) {
|
|
71395
|
-
if (f.severity === "blocker") gatingBlocker++;
|
|
71396
|
-
else if (f.severity === "error") gatingError++;
|
|
71397
|
-
} else if (source === "ai" && meetsSeverity(f.severity, "error")) {
|
|
71398
|
-
advisoryErrorPlus++;
|
|
71399
|
-
}
|
|
71400
|
-
}
|
|
71401
|
-
const exitCode = gatingBlocker > 0 ? EXIT.FINDINGS_BLOCKER : gatingError > 0 ? EXIT.FINDINGS_ERROR : EXIT.SUCCESS;
|
|
71402
|
-
return { exitCode, gatingError, gatingBlocker, advisoryErrorPlus };
|
|
71403
|
-
};
|
|
71404
71583
|
var escalateExitForCoverage = (baseExit, coverageBlocks) => baseExit === EXIT.SUCCESS && coverageBlocks ? EXIT.RUNTIME : baseExit;
|
|
71405
71584
|
var hasIncompleteQueuedFullCoverage = (isRunnerInvocation, runtimeSinceRef2, aiStats) => isRunnerInvocation && (runtimeSinceRef2 === void 0 || runtimeSinceRef2.length === 0) && aiStats !== void 0 && countRecallRiskSkips(aiStats) > 0;
|
|
71406
71585
|
var rulesToRerun = (aiStats) => {
|
|
@@ -71430,6 +71609,7 @@ var runReview = async (options = {}) => {
|
|
|
71430
71609
|
prWorkspace: options.prWorkspace,
|
|
71431
71610
|
prAiStrategy: options.prAiStrategy,
|
|
71432
71611
|
aiOff: options.aiOff === true,
|
|
71612
|
+
...options.aiGatePolicy !== void 0 ? { aiGatePolicy: options.aiGatePolicy } : {},
|
|
71433
71613
|
mode: options.mode,
|
|
71434
71614
|
...options.scope !== void 0 ? { scope: options.scope } : {},
|
|
71435
71615
|
minSeverity: options.minSeverity,
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -37674,7 +37674,7 @@ Language guard retry: the previous response contained an empty or English explan
|
|
|
37674
37674
|
return { status: "error", vulnerable: false, reason: `L\u1ED7i th\u1EF1c thi LLM: ${message}` };
|
|
37675
37675
|
}
|
|
37676
37676
|
}
|
|
37677
|
-
var OLLAMA_DEFAULT_BASE, NETMIND_DEFAULT_BASE, OPENCODE_GO_DEFAULT_BASE, stripTrailingSlash2, buildLanguageModel, resolveModelOverride, pingTarget, shouldUseRawJsonChat, openAICompatibleChatUrl, REASONING_HEADROOM_TOKENS, NETMIND_MINIMAX_M3_MODEL, NETMIND_SMALL_PROMPT_MAX_CHARS, NETMIND_MEDIUM_PROMPT_MAX_CHARS, NETMIND_SMALL_OUTPUT_TOKENS, NETMIND_MEDIUM_OUTPUT_TOKENS, NETMIND_LARGE_OUTPUT_TOKENS, NETMIND_MAX_OUTPUT_TOKENS, supportsNetmindJsonResponseFormat, emptyResponseDiagnostics, effectiveMaxTokensFor, completeRawOpenAICompatibleJsonChat, createAiSdkProvider, createFallbackClient, DEFAULT_MAX_RETRIES, DEFAULT_BASE_DELAY_MS, DEFAULT_MAX_DELAY_MS, DEFAULT_RESET_SAFETY_MS, DEFAULT_JITTER_MS, sleep, isRateLimitError, parseProviderRetryDelayMs, rateLimitRetryDelayMs, createRateLimitRetryClient, numberLines, renderPrompt, cache, loadPromptTemplate, nullableOptional, AI_VIOLATION_MESSAGE_MAX_LENGTH, aiViolationSchema, aiResponseSchema, stripCodeFence, parseAiResponse, createInMemoryCache, VIETNAMESE_OUTPUT_POLICY_VERSION, VIETNAMESE_OUTPUT_INSTRUCTION, TOKEN_BUDGET_WARN_DEFAULT, CHARS_PER_TOKEN, SAFETY_MARGIN, estimateTokens, formatTokenWarning, braceDelta, chunkSourceForAi, renderAuthorizationGuards, CACHE_NAMESPACE, DEFAULT_PROVIDER_RETRY_MAX_RETRIES, DEFAULT_PROVIDER_RETRY_MAX_DELAY_MS, DEFAULT_ADAPTIVE_RETRY_MAX_RETRIES, DEFAULT_ADAPTIVE_CONTEXT_REDUCTION_FACTOR, DEFAULT_ADAPTIVE_TIMEOUT_MULTIPLIER, DEFAULT_ADAPTIVE_MAX_DELAY_MS, DEFAULT_PROVIDER_TIMEOUT_MS, sleep2, providerRetryDelayMs, adaptiveFailureKind, compactClusterContext, findingDedupeKey, dedupeFindings, capFindings, createAiExecutor, PATH_FAST_PATHS, SPRING_BOOT_PATTERNS, ANGULAR_PATTERNS, FLUTTER_PATTERNS, ENTRY_HINTS, ALL_PATTERNS, matchesRule, classifyLayer, classifyLayers, PRIMARY_LAYER_CANDIDATES, TEST_AND_GENERATED, LAYER_SUFFIXES, FILE_SUFFIX_RE, ANY_EXT_RE, dropExt, stripPascalSuffix, normalize2, extractDomainTokens, extractDomainTokensBatch, TRIVIAL_TOKENS, sharesDomainToken, TS_IMPORT_RE, JAVA_IMPORT_RE, extractImports, POSIX_SEP_RE, sharedDirDepth, resolveImportTarget, KIND_STRENGTH, upsertEdge, buildEdges, ADVICE_ANNOTATION, isGlobalAdviceFile, findGlobalAdvicePaths, DEFAULT_MAX_CANDIDATES, DEFAULT_MAX_SUPPORT_FILES, DEFAULT_TOKEN_BUDGET, SCORE_DIRECT_NEIGHBOR, SCORE_SECOND_DEGREE, SCORE_SIBLING_STEM, SCORE_ANGULAR_TEMPLATE_SIBLING, SCORE_DOMAIN_TOKEN, PENALTY_TEST_VS_NON_TEST, PENALTY_GENERATED, SCORE_GLOBAL_ADVICE, prefilterCandidates, layerFlowBonus, isTest, isGenerated, scoreFor, tokensOf, trimToBudget, toMember, clusterIdFor, createClusterAssembler, CLUSTER_TREE_BUILDER_VERSION, DEFAULT_MODULE_DEPTH, posixDirname, moduleGroupKey, uniqueSortedPaths, memberFingerprint, featureNodeFor, moduleNodeFor, appNodeFor, countCrossModuleEdges, createClusterTreeBuilder, TRANSACTIONAL, TYPE_DECL3, METHOD_NAME2, MUTATION_CALL, LEADING_ANNOTATION2, SPRING_TX_SUPPORT_IMPORT, PROGRAMMATIC_TYPE, PROGRAMMATIC_CALL, INLINE_TEMPLATE_CALL, CONTROL_FLOW_NAMES, maskNonCode, methodNameFromHeader, methodAt, delegatedTargetAt, collectProgrammaticReceivers, readAttr, skipToDeclaration2, countMutations, lineOf25, configuredReadOnly, extractProgrammaticFromFile, extractFromFile2, extractTransactionBoundaries, renderPrDiffPrompt, nullableOptional2, prDiffResponseSchema, createPrDiffReviewer, renderGroupedRulePrompt, confidenceLabelSchema, severitySchema, groupedResponseSchema, labelToConfidence, createGroupedRuleReviewer, renderPerRulePrompt, createPerRuleReviewer, DEFAULT_MAX_TOKENS, SYSTEM_PROMPT, SCHEMA_PROMPT, clip, buildUserPrompt, extractJsonObject, describeUnusableAnswer, createRuntimeAuthHypothesisResolver, DEFAULT_MAX_TOKENS2, SYSTEM_PROMPT2, SCHEMA_PROMPT2, clip2, buildUserPrompt2, describeUnusableAnswer2, createRuntimeDataSeedResolver, endpointSchema, extractJsonObject2, HTTP_METHODS, PARAMETER_KINDS, ENGLISH_REASON_WORDS, ENGLISH_TECHNICAL_WORDS, VIETNAMESE_DIACRITICS, isLikelyEnglishReason, normalizeTriageReason, parseEndpointHint, checkAiConnection;
|
|
37677
|
+
var OLLAMA_DEFAULT_BASE, NETMIND_DEFAULT_BASE, OPENCODE_GO_DEFAULT_BASE, stripTrailingSlash2, buildLanguageModel, resolveModelOverride, pingTarget, shouldUseRawJsonChat, openAICompatibleChatUrl, REASONING_HEADROOM_TOKENS, NETMIND_MINIMAX_M3_MODEL, NETMIND_SMALL_PROMPT_MAX_CHARS, NETMIND_MEDIUM_PROMPT_MAX_CHARS, NETMIND_SMALL_OUTPUT_TOKENS, NETMIND_MEDIUM_OUTPUT_TOKENS, NETMIND_LARGE_OUTPUT_TOKENS, NETMIND_MAX_OUTPUT_TOKENS, supportsNetmindJsonResponseFormat, emptyResponseDiagnostics, effectiveMaxTokensFor, completeRawOpenAICompatibleJsonChat, createAiSdkProvider, createFallbackClient, DEFAULT_MAX_RETRIES, DEFAULT_BASE_DELAY_MS, DEFAULT_MAX_DELAY_MS, DEFAULT_RESET_SAFETY_MS, DEFAULT_JITTER_MS, sleep, isRateLimitError, parseProviderRetryDelayMs, rateLimitRetryDelayMs, createRateLimitRetryClient, numberLines, renderPrompt, cache, loadPromptTemplate, nullableOptional, AI_VIOLATION_MESSAGE_MAX_LENGTH, aiViolationSchema, aiResponseSchema, stripCodeFence, parseAiResponse, createInMemoryCache, VIETNAMESE_OUTPUT_POLICY_VERSION, VIETNAMESE_OUTPUT_INSTRUCTION, TOKEN_BUDGET_WARN_DEFAULT, CHARS_PER_TOKEN, SAFETY_MARGIN, estimateTokens, formatTokenWarning, braceDelta, chunkSourceForAi, renderAuthorizationGuards, CACHE_NAMESPACE, DEFAULT_PROVIDER_RETRY_MAX_RETRIES, DEFAULT_PROVIDER_RETRY_MAX_DELAY_MS, DEFAULT_ADAPTIVE_RETRY_MAX_RETRIES, DEFAULT_ADAPTIVE_CONTEXT_REDUCTION_FACTOR, DEFAULT_ADAPTIVE_TIMEOUT_MULTIPLIER, DEFAULT_ADAPTIVE_MAX_DELAY_MS, DEFAULT_PROVIDER_TIMEOUT_MS, sleep2, providerRetryDelayMs, adaptiveFailureKind, compactClusterContext, findingDedupeKey, dedupeFindings, capFindings, createAiExecutor, PATH_FAST_PATHS, SPRING_BOOT_PATTERNS, ANGULAR_PATTERNS, FLUTTER_PATTERNS, ENTRY_HINTS, ALL_PATTERNS, matchesRule, classifyLayer, classifyLayers, PRIMARY_LAYER_CANDIDATES, TEST_AND_GENERATED, LAYER_SUFFIXES, FILE_SUFFIX_RE, ANY_EXT_RE, dropExt, stripPascalSuffix, normalize2, extractDomainTokens, extractDomainTokensBatch, TRIVIAL_TOKENS, sharesDomainToken, TS_IMPORT_RE, JAVA_IMPORT_RE, extractImports, POSIX_SEP_RE, sharedDirDepth, resolveImportTarget, KIND_STRENGTH, upsertEdge, buildEdges, ADVICE_ANNOTATION, isGlobalAdviceFile, findGlobalAdvicePaths, DEFAULT_MAX_CANDIDATES, DEFAULT_MAX_SUPPORT_FILES, DEFAULT_TOKEN_BUDGET, SCORE_DIRECT_NEIGHBOR, SCORE_SECOND_DEGREE, SCORE_SIBLING_STEM, SCORE_ANGULAR_TEMPLATE_SIBLING, SCORE_DOMAIN_TOKEN, PENALTY_TEST_VS_NON_TEST, PENALTY_GENERATED, SCORE_GLOBAL_ADVICE, prefilterCandidates, layerFlowBonus, isTest, isGenerated, scoreFor, tokensOf, trimToBudget, toMember, clusterIdFor, createClusterAssembler, CLUSTER_TREE_BUILDER_VERSION, DEFAULT_MODULE_DEPTH, posixDirname, moduleGroupKey, uniqueSortedPaths, memberFingerprint, featureNodeFor, moduleNodeFor, appNodeFor, countCrossModuleEdges, createClusterTreeBuilder, TRANSACTIONAL, TYPE_DECL3, METHOD_NAME2, MUTATION_CALL, LEADING_ANNOTATION2, SPRING_TX_SUPPORT_IMPORT, PROGRAMMATIC_TYPE, PROGRAMMATIC_CALL, INLINE_TEMPLATE_CALL, CONTROL_FLOW_NAMES, maskNonCode, methodNameFromHeader, methodAt, delegatedTargetAt, collectProgrammaticReceivers, readAttr, skipToDeclaration2, countMutations, lineOf25, configuredReadOnly, extractProgrammaticFromFile, extractFromFile2, extractTransactionBoundaries, renderPrDiffPrompt, nullableOptional2, prDiffResponseSchema, createPrDiffReviewer, renderGroupedRulePrompt, confidenceLabelSchema, SEVERITY_ALIASES, severitySchema, groupedResponseSchema, labelToConfidence, createGroupedRuleReviewer, renderPerRulePrompt, createPerRuleReviewer, DEFAULT_MAX_TOKENS, SYSTEM_PROMPT, SCHEMA_PROMPT, clip, buildUserPrompt, extractJsonObject, describeUnusableAnswer, createRuntimeAuthHypothesisResolver, DEFAULT_MAX_TOKENS2, SYSTEM_PROMPT2, SCHEMA_PROMPT2, clip2, buildUserPrompt2, describeUnusableAnswer2, createRuntimeDataSeedResolver, endpointSchema, extractJsonObject2, HTTP_METHODS, PARAMETER_KINDS, ENGLISH_REASON_WORDS, ENGLISH_TECHNICAL_WORDS, VIETNAMESE_DIACRITICS, isLikelyEnglishReason, normalizeTriageReason, parseEndpointHint, checkAiConnection;
|
|
37678
37678
|
var init_dist4 = __esm({
|
|
37679
37679
|
"../ai-engine/dist/index.js"() {
|
|
37680
37680
|
init_dist();
|
|
@@ -40230,7 +40230,27 @@ ${file.content}
|
|
|
40230
40230
|
return parts.join("\n");
|
|
40231
40231
|
};
|
|
40232
40232
|
confidenceLabelSchema = external_exports.enum(["low", "medium", "high"]).optional();
|
|
40233
|
-
|
|
40233
|
+
SEVERITY_ALIASES = {
|
|
40234
|
+
info: "info",
|
|
40235
|
+
low: "info",
|
|
40236
|
+
minor: "info",
|
|
40237
|
+
note: "info",
|
|
40238
|
+
suggestion: "info",
|
|
40239
|
+
warning: "warning",
|
|
40240
|
+
warn: "warning",
|
|
40241
|
+
medium: "warning",
|
|
40242
|
+
moderate: "warning",
|
|
40243
|
+
error: "error",
|
|
40244
|
+
high: "error",
|
|
40245
|
+
major: "error",
|
|
40246
|
+
blocker: "blocker",
|
|
40247
|
+
critical: "blocker",
|
|
40248
|
+
fatal: "blocker"
|
|
40249
|
+
};
|
|
40250
|
+
severitySchema = external_exports.preprocess(
|
|
40251
|
+
(value) => typeof value === "string" ? SEVERITY_ALIASES[value.trim().toLowerCase()] : void 0,
|
|
40252
|
+
external_exports.enum(["info", "warning", "error", "blocker"]).optional()
|
|
40253
|
+
);
|
|
40234
40254
|
groupedResponseSchema = external_exports.object({
|
|
40235
40255
|
ruleResults: external_exports.array(
|
|
40236
40256
|
external_exports.object({
|
|
@@ -60367,11 +60387,11 @@ var definedBuildValue = (value, fallback) => typeof value === "string" && value.
|
|
|
60367
60387
|
var getCliBuildMetadata = (version2) => ({
|
|
60368
60388
|
version: version2,
|
|
60369
60389
|
gitSha: definedBuildValue(
|
|
60370
|
-
"
|
|
60390
|
+
"9da49e9424a8" ,
|
|
60371
60391
|
"unknown"
|
|
60372
60392
|
),
|
|
60373
60393
|
buildTimestamp: definedBuildValue(
|
|
60374
|
-
"2026-11-
|
|
60394
|
+
"2026-11-27T06:51:28.365Z" ,
|
|
60375
60395
|
"unknown"
|
|
60376
60396
|
),
|
|
60377
60397
|
configSchemaRange: definedBuildValue(
|
|
@@ -66514,6 +66534,9 @@ var collectPrRuleGroups = (rules, options = {}) => {
|
|
|
66514
66534
|
})).sort((a, b) => a.id.localeCompare(b.id));
|
|
66515
66535
|
};
|
|
66516
66536
|
var classifyRuleApplicability = (rule, profile) => {
|
|
66537
|
+
if (profile.file.language !== void 0 && rule.languages.length > 0 && !rule.languages.includes(profile.file.language)) {
|
|
66538
|
+
return PR_RULE_APPLICABILITY.NOT_APPLICABLE;
|
|
66539
|
+
}
|
|
66517
66540
|
const routing = rule.prRouting;
|
|
66518
66541
|
if (!routing) return PR_RULE_APPLICABILITY.UNKNOWN;
|
|
66519
66542
|
if (routing.targetLayers.length > 0 && !routing.targetLayers.includes(profile.layer)) {
|
|
@@ -66996,6 +67019,31 @@ var createOneShotPhaseLogger = (env = process.env) => {
|
|
|
66996
67019
|
}
|
|
66997
67020
|
};
|
|
66998
67021
|
};
|
|
67022
|
+
|
|
67023
|
+
// src/review-gate.ts
|
|
67024
|
+
init_dist2();
|
|
67025
|
+
init_exit_codes();
|
|
67026
|
+
var resolveGatePolicy = (configGate, override, skipOverride) => ({
|
|
67027
|
+
aiPolicy: override ?? configGate.aiPolicy,
|
|
67028
|
+
aiMinConfidence: configGate.aiMinConfidence,
|
|
67029
|
+
aiSkipPolicy: skipOverride ?? configGate.aiSkipPolicy
|
|
67030
|
+
});
|
|
67031
|
+
var computeGateResult = (findings2, ruleKindById, policy) => {
|
|
67032
|
+
let gatingBlocker = 0;
|
|
67033
|
+
let gatingError = 0;
|
|
67034
|
+
let advisoryErrorPlus = 0;
|
|
67035
|
+
for (const f of findings2) {
|
|
67036
|
+
const source = ruleKindById.get(f.ruleId) === "ai" ? "ai" : "deterministic";
|
|
67037
|
+
if (findingGates(f, source, policy)) {
|
|
67038
|
+
if (f.severity === "blocker") gatingBlocker++;
|
|
67039
|
+
else if (f.severity === "error") gatingError++;
|
|
67040
|
+
} else if (source === "ai" && meetsSeverity(f.severity, "error")) {
|
|
67041
|
+
advisoryErrorPlus++;
|
|
67042
|
+
}
|
|
67043
|
+
}
|
|
67044
|
+
const exitCode = gatingBlocker > 0 ? EXIT.FINDINGS_BLOCKER : gatingError > 0 ? EXIT.FINDINGS_ERROR : EXIT.SUCCESS;
|
|
67045
|
+
return { exitCode, gatingError, gatingBlocker, advisoryErrorPlus };
|
|
67046
|
+
};
|
|
66999
67047
|
var Counters = ({ counts, sourceCounts }) => /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
|
|
67000
67048
|
/* @__PURE__ */ jsxs(Box, { children: [
|
|
67001
67049
|
/* @__PURE__ */ jsx(Text, { color: "blue", children: "\u258C" }),
|
|
@@ -67712,6 +67760,9 @@ var createGitLabClient = (options) => {
|
|
|
67712
67760
|
if (!result.ok) return result;
|
|
67713
67761
|
return toMergeRequest(result.value);
|
|
67714
67762
|
},
|
|
67763
|
+
async fetchCurrentUser() {
|
|
67764
|
+
return request("GET", "/user");
|
|
67765
|
+
},
|
|
67715
67766
|
async listNotes(target) {
|
|
67716
67767
|
return requestAllPages(mrPath(target, "/notes"));
|
|
67717
67768
|
},
|
|
@@ -67740,6 +67791,27 @@ var createGitLabClient = (options) => {
|
|
|
67740
67791
|
});
|
|
67741
67792
|
if (!result.ok) return result;
|
|
67742
67793
|
return ok(void 0);
|
|
67794
|
+
},
|
|
67795
|
+
async listDiscussions(target) {
|
|
67796
|
+
return requestAllPages(mrPath(target, "/discussions"));
|
|
67797
|
+
},
|
|
67798
|
+
async compareCommits(target, from, to) {
|
|
67799
|
+
const query = `from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}&straight=true`;
|
|
67800
|
+
const result = await request(
|
|
67801
|
+
"GET",
|
|
67802
|
+
`/projects/${encodeProjectPath(target.projectPath)}/repository/compare?${query}`
|
|
67803
|
+
);
|
|
67804
|
+
if (!result.ok) return result;
|
|
67805
|
+
return ok(result.value.diffs ?? []);
|
|
67806
|
+
},
|
|
67807
|
+
async resolveDiscussion(target, discussionId) {
|
|
67808
|
+
const result = await request(
|
|
67809
|
+
"PUT",
|
|
67810
|
+
mrPath(target, `/discussions/${encodeURIComponent(discussionId)}`),
|
|
67811
|
+
{ resolved: true }
|
|
67812
|
+
);
|
|
67813
|
+
if (!result.ok) return result;
|
|
67814
|
+
return ok(void 0);
|
|
67743
67815
|
}
|
|
67744
67816
|
};
|
|
67745
67817
|
};
|
|
@@ -67748,9 +67820,13 @@ var createGitLabClient = (options) => {
|
|
|
67748
67820
|
init_dist2();
|
|
67749
67821
|
init_dist5();
|
|
67750
67822
|
init_dist();
|
|
67751
|
-
var
|
|
67823
|
+
var summaryMarker = (kind) => `<!-- code-sentinel:pr-review:${kind} -->`;
|
|
67824
|
+
var LEGACY_SUMMARY_MARKER = "<!-- code-sentinel:pr-review -->";
|
|
67825
|
+
var SUMMARY_MARKER_PATTERN = /<!-- code-sentinel:pr-review(?::(static|ai))? -->/;
|
|
67752
67826
|
var fingerprintMarker = (fingerprint) => `<!-- code-sentinel:finding ${fingerprint} -->`;
|
|
67753
67827
|
var FINDING_MARKER_PATTERN = /code-sentinel:finding\s+([a-f0-9]+)/g;
|
|
67828
|
+
var inlineKindMarker = (kind) => `<!-- code-sentinel:kind ${kind} -->`;
|
|
67829
|
+
var INLINE_KIND_PATTERN = /code-sentinel:kind (static|ai)/;
|
|
67754
67830
|
var SEVERITIES = ["blocker", "error", "warning", "info"];
|
|
67755
67831
|
var escapeTableCell2 = (value) => value.replace(/\\/g, "\\\\").replace(/\|/g, "\\|").replace(/\r?\n/g, "<br>");
|
|
67756
67832
|
var countBySeverity3 = (findings2) => {
|
|
@@ -67769,9 +67845,10 @@ var renderPrSummary = (options) => {
|
|
|
67769
67845
|
...options.summaryOnly
|
|
67770
67846
|
].sort(compareFindings);
|
|
67771
67847
|
const severityCounts = countBySeverity3(allFindings);
|
|
67848
|
+
const kind = options.reviewKind ?? "static";
|
|
67772
67849
|
const lines = [
|
|
67773
|
-
|
|
67774
|
-
|
|
67850
|
+
summaryMarker(kind),
|
|
67851
|
+
`## Code Sentinel PR Review Report (${kind === "ai" ? "AI + static" : "static"})`,
|
|
67775
67852
|
"",
|
|
67776
67853
|
`**Run**: \`${options.runId}\``,
|
|
67777
67854
|
"",
|
|
@@ -67816,8 +67893,9 @@ var renderPrSummary = (options) => {
|
|
|
67816
67893
|
}
|
|
67817
67894
|
return lines.join("\n");
|
|
67818
67895
|
};
|
|
67819
|
-
var renderInlineComment = (item16) => [
|
|
67896
|
+
var renderInlineComment = (item16, kind) => [
|
|
67820
67897
|
fingerprintMarker(item16.fingerprint),
|
|
67898
|
+
inlineKindMarker(kind),
|
|
67821
67899
|
`**${item16.finding.ruleId}** (${item16.finding.severity})`,
|
|
67822
67900
|
"",
|
|
67823
67901
|
item16.finding.message,
|
|
@@ -67825,7 +67903,92 @@ var renderInlineComment = (item16) => [
|
|
|
67825
67903
|
item16.finding.suggestion ? `
|
|
67826
67904
|
Suggestion: ${item16.finding.suggestion}` : ""
|
|
67827
67905
|
].filter((part) => part.length > 0).join("\n");
|
|
67828
|
-
var isCodeSentinelNote = (body) =>
|
|
67906
|
+
var isCodeSentinelNote = (body) => SUMMARY_MARKER_PATTERN.test(body) || body.includes("code-sentinel:finding");
|
|
67907
|
+
var isOwnNote = (note, currentUserId) => note.author === void 0 ? true : currentUserId !== null && note.author.id === currentUserId;
|
|
67908
|
+
var isOwnSummaryOfKind = (note, kind, currentUserId) => isOwnNote(note, currentUserId) && (note.body.includes(summaryMarker(kind)) || note.body.includes(LEGACY_SUMMARY_MARKER));
|
|
67909
|
+
var touchedOldLines = (diff) => {
|
|
67910
|
+
const touched = /* @__PURE__ */ new Set();
|
|
67911
|
+
let oldLine = 0;
|
|
67912
|
+
for (const line2 of diff.split("\n")) {
|
|
67913
|
+
const hunk = /^@@ -(\d+)(?:,\d+)? \+\d+(?:,\d+)? @@/.exec(line2);
|
|
67914
|
+
if (hunk) {
|
|
67915
|
+
oldLine = Number(hunk[1]);
|
|
67916
|
+
continue;
|
|
67917
|
+
}
|
|
67918
|
+
if (line2.startsWith("-")) {
|
|
67919
|
+
touched.add(oldLine);
|
|
67920
|
+
oldLine++;
|
|
67921
|
+
} else if (line2.startsWith("+") || line2.startsWith("\\")) ; else {
|
|
67922
|
+
oldLine++;
|
|
67923
|
+
}
|
|
67924
|
+
}
|
|
67925
|
+
return touched;
|
|
67926
|
+
};
|
|
67927
|
+
var pruneStaleOwnFindings = async (options, kind, currentUserId) => {
|
|
67928
|
+
const removedNoteIds = /* @__PURE__ */ new Set();
|
|
67929
|
+
const standing = /* @__PURE__ */ new Set();
|
|
67930
|
+
const discussions = await options.client.listDiscussions(options.target);
|
|
67931
|
+
if (!discussions.ok) return discussions;
|
|
67932
|
+
const current = new Set(options.inlineable.map((item16) => item16.fingerprint));
|
|
67933
|
+
const touchedByFrom = /* @__PURE__ */ new Map();
|
|
67934
|
+
const codeChanged = async (head) => {
|
|
67935
|
+
const from = head.position?.head_sha;
|
|
67936
|
+
const path = head.position?.new_path;
|
|
67937
|
+
const line2 = head.position?.new_line;
|
|
67938
|
+
if (!options.headSha || !from || !path || !line2 || from === options.headSha) return ok(false);
|
|
67939
|
+
let byPath = touchedByFrom.get(from);
|
|
67940
|
+
if (!byPath) {
|
|
67941
|
+
const diffs = await options.client.compareCommits(options.target, from, options.headSha);
|
|
67942
|
+
if (!diffs.ok) return diffs;
|
|
67943
|
+
byPath = new Map(diffs.value.map((d) => [d.old_path, touchedOldLines(d.diff)]));
|
|
67944
|
+
touchedByFrom.set(from, byPath);
|
|
67945
|
+
}
|
|
67946
|
+
return ok(byPath.get(path)?.has(line2) ?? false);
|
|
67947
|
+
};
|
|
67948
|
+
let deleted = 0;
|
|
67949
|
+
let resolved = 0;
|
|
67950
|
+
for (const discussion of discussions.value) {
|
|
67951
|
+
const head = discussion.notes[0];
|
|
67952
|
+
if (!head) continue;
|
|
67953
|
+
let prune = false;
|
|
67954
|
+
if (currentUserId !== null && isStaleOwnFinding(head, kind, currentUserId, current)) {
|
|
67955
|
+
const changed = await codeChanged(head);
|
|
67956
|
+
if (!changed.ok) return changed;
|
|
67957
|
+
prune = changed.value;
|
|
67958
|
+
}
|
|
67959
|
+
if (!prune) {
|
|
67960
|
+
const key = standingKey(head);
|
|
67961
|
+
if (key) standing.add(key);
|
|
67962
|
+
continue;
|
|
67963
|
+
}
|
|
67964
|
+
if (discussion.notes.length === 1) {
|
|
67965
|
+
const result = await options.client.deleteNote(options.target, head.id);
|
|
67966
|
+
if (!result.ok) return result;
|
|
67967
|
+
removedNoteIds.add(head.id);
|
|
67968
|
+
deleted++;
|
|
67969
|
+
} else {
|
|
67970
|
+
const result = await options.client.resolveDiscussion(options.target, discussion.id);
|
|
67971
|
+
if (!result.ok) return result;
|
|
67972
|
+
resolved++;
|
|
67973
|
+
}
|
|
67974
|
+
}
|
|
67975
|
+
return ok({ deleted, resolved, removedNoteIds, standing });
|
|
67976
|
+
};
|
|
67977
|
+
var standingKey = (note) => {
|
|
67978
|
+
const ruleId = /\*\*([^*\s]+)\*\*/.exec(note.body)?.[1];
|
|
67979
|
+
const path = note.position?.new_path;
|
|
67980
|
+
const line2 = note.position?.new_line;
|
|
67981
|
+
if (!ruleId || !path || !line2 || !note.body.includes("code-sentinel:finding")) return null;
|
|
67982
|
+
return `${ruleId}|${path}|${line2}`;
|
|
67983
|
+
};
|
|
67984
|
+
var itemKey = (item16) => `${item16.finding.ruleId}|${item16.position.newPath}|${item16.position.newLine ?? ""}`;
|
|
67985
|
+
var isStaleOwnFinding = (head, kind, currentUserId, current) => {
|
|
67986
|
+
if (head.author?.id !== currentUserId || head.resolved === true) return false;
|
|
67987
|
+
const fingerprint = /code-sentinel:finding\s+([a-f0-9]+)/.exec(head.body)?.[1];
|
|
67988
|
+
if (!fingerprint || current.has(fingerprint)) return false;
|
|
67989
|
+
const noteKind = INLINE_KIND_PATTERN.exec(head.body)?.[1];
|
|
67990
|
+
return noteKind === void 0 || noteKind === kind;
|
|
67991
|
+
};
|
|
67829
67992
|
var publishPrReview = async (options) => {
|
|
67830
67993
|
const summaryBody = renderPrSummary(options);
|
|
67831
67994
|
if (options.dryRun) {
|
|
@@ -67834,23 +67997,32 @@ var publishPrReview = async (options) => {
|
|
|
67834
67997
|
inlinePosted: 0,
|
|
67835
67998
|
inlineSkipped: 0,
|
|
67836
67999
|
inlineFailed: 0,
|
|
67837
|
-
deletedExisting: 0
|
|
68000
|
+
deletedExisting: 0,
|
|
68001
|
+
staleDeleted: 0,
|
|
68002
|
+
staleResolved: 0
|
|
67838
68003
|
});
|
|
67839
68004
|
}
|
|
68005
|
+
const kind = options.reviewKind ?? "static";
|
|
68006
|
+
const currentUser = await options.client.fetchCurrentUser();
|
|
68007
|
+
const currentUserId = currentUser.ok ? currentUser.value.id : null;
|
|
67840
68008
|
const notesResult = await options.client.listNotes(options.target);
|
|
67841
68009
|
if (!notesResult.ok) return notesResult;
|
|
67842
68010
|
let activeNotes = notesResult.value;
|
|
67843
68011
|
let deletedExisting = 0;
|
|
67844
68012
|
if (options.cleanupExistingComments) {
|
|
68013
|
+
const kept = [];
|
|
67845
68014
|
for (const note of activeNotes) {
|
|
67846
|
-
if (!isCodeSentinelNote(note.body))
|
|
68015
|
+
if (!isCodeSentinelNote(note.body) || !isOwnNote(note, currentUserId)) {
|
|
68016
|
+
kept.push(note);
|
|
68017
|
+
continue;
|
|
68018
|
+
}
|
|
67847
68019
|
const deleted = await options.client.deleteNote(options.target, note.id);
|
|
67848
68020
|
if (!deleted.ok) return deleted;
|
|
67849
68021
|
deletedExisting++;
|
|
67850
68022
|
}
|
|
67851
|
-
activeNotes =
|
|
68023
|
+
activeNotes = kept;
|
|
67852
68024
|
}
|
|
67853
|
-
const existingSummary = activeNotes.find((note) => note
|
|
68025
|
+
const existingSummary = activeNotes.find((note) => isOwnSummaryOfKind(note, kind, currentUserId));
|
|
67854
68026
|
if (existingSummary) {
|
|
67855
68027
|
const updated = await options.client.updateNote(
|
|
67856
68028
|
options.target,
|
|
@@ -67863,10 +68035,21 @@ var publishPrReview = async (options) => {
|
|
|
67863
68035
|
if (!created.ok) return created;
|
|
67864
68036
|
}
|
|
67865
68037
|
if (options.summaryOnlyMode) {
|
|
67866
|
-
return ok({
|
|
68038
|
+
return ok({
|
|
68039
|
+
summaryBody,
|
|
68040
|
+
inlinePosted: 0,
|
|
68041
|
+
inlineSkipped: 0,
|
|
68042
|
+
inlineFailed: 0,
|
|
68043
|
+
deletedExisting,
|
|
68044
|
+
staleDeleted: 0,
|
|
68045
|
+
staleResolved: 0
|
|
68046
|
+
});
|
|
67867
68047
|
}
|
|
68048
|
+
const pruned = await pruneStaleOwnFindings(options, kind, currentUserId);
|
|
68049
|
+
if (!pruned.ok) return pruned;
|
|
67868
68050
|
const existingFingerprints = /* @__PURE__ */ new Set();
|
|
67869
68051
|
for (const note of activeNotes) {
|
|
68052
|
+
if (pruned.value.removedNoteIds.has(note.id)) continue;
|
|
67870
68053
|
for (const match of note.body.matchAll(FINDING_MARKER_PATTERN)) {
|
|
67871
68054
|
if (match[1]) existingFingerprints.add(match[1]);
|
|
67872
68055
|
}
|
|
@@ -67876,13 +68059,13 @@ var publishPrReview = async (options) => {
|
|
|
67876
68059
|
let inlineSkipped = options.inlineable.length - budgeted.length;
|
|
67877
68060
|
let inlineFailed = 0;
|
|
67878
68061
|
for (const item16 of budgeted) {
|
|
67879
|
-
if (existingFingerprints.has(item16.fingerprint)) {
|
|
68062
|
+
if (existingFingerprints.has(item16.fingerprint) || pruned.value.standing.has(itemKey(item16))) {
|
|
67880
68063
|
inlineSkipped++;
|
|
67881
68064
|
continue;
|
|
67882
68065
|
}
|
|
67883
68066
|
const result = await options.client.createDiscussion(
|
|
67884
68067
|
options.target,
|
|
67885
|
-
renderInlineComment(item16),
|
|
68068
|
+
renderInlineComment(item16, kind),
|
|
67886
68069
|
item16.position
|
|
67887
68070
|
);
|
|
67888
68071
|
if (!result.ok) {
|
|
@@ -67891,7 +68074,15 @@ var publishPrReview = async (options) => {
|
|
|
67891
68074
|
}
|
|
67892
68075
|
inlinePosted++;
|
|
67893
68076
|
}
|
|
67894
|
-
return ok({
|
|
68077
|
+
return ok({
|
|
68078
|
+
summaryBody,
|
|
68079
|
+
inlinePosted,
|
|
68080
|
+
inlineSkipped,
|
|
68081
|
+
inlineFailed,
|
|
68082
|
+
deletedExisting,
|
|
68083
|
+
staleDeleted: pruned.value.deleted,
|
|
68084
|
+
staleResolved: pruned.value.resolved
|
|
68085
|
+
});
|
|
67895
68086
|
};
|
|
67896
68087
|
|
|
67897
68088
|
// src/pr/static-review.ts
|
|
@@ -68437,6 +68628,11 @@ var printDryRunSummary = (target, findings2, reportPaths, codeQualityPath) => {
|
|
|
68437
68628
|
}
|
|
68438
68629
|
console.log(green(` GitLab Code Quality: ${codeQualityPath}`));
|
|
68439
68630
|
};
|
|
68631
|
+
var computePrGate = (findings2, ruleKindById, configGate, aiGatePolicy) => computeGateResult(
|
|
68632
|
+
findings2,
|
|
68633
|
+
new Map([...ruleKindById, ["ai/pr-diff-review", "ai"]]),
|
|
68634
|
+
resolveGatePolicy(configGate, aiGatePolicy)
|
|
68635
|
+
);
|
|
68440
68636
|
var sourceCountsForFindings = (findings2, ruleKindById) => {
|
|
68441
68637
|
const counts = { static: 0, ai: 0 };
|
|
68442
68638
|
for (const finding of findings2) {
|
|
@@ -69295,6 +69491,9 @@ var runPrReview = async (options) => {
|
|
|
69295
69491
|
staticResult.ruleKindById
|
|
69296
69492
|
),
|
|
69297
69493
|
maxInlineComments,
|
|
69494
|
+
// A static-only CI bot and a developer's AI run each keep their own MR summary.
|
|
69495
|
+
reviewKind: (aiStats?.succeeded ?? 0) > 0 ? "ai" : "static",
|
|
69496
|
+
headSha: mr.diffRefs.headSha,
|
|
69298
69497
|
summaryOnlyMode: options.summaryOnly,
|
|
69299
69498
|
cleanupExistingComments: config.prReview.cleanupExistingComments,
|
|
69300
69499
|
dryRun: !options.post
|
|
@@ -69326,7 +69525,7 @@ var runPrReview = async (options) => {
|
|
|
69326
69525
|
console.log(green(`Posted GitLab PR review for ${target.projectPath}!${target.iid}`));
|
|
69327
69526
|
console.log(
|
|
69328
69527
|
gray(
|
|
69329
|
-
` Deleted existing: ${publishResult.value.deletedExisting}; inline posted: ${publishResult.value.inlinePosted}; inline skipped: ${publishResult.value.inlineSkipped}; inline failed: ${publishResult.value.inlineFailed}`
|
|
69528
|
+
` Deleted existing: ${publishResult.value.deletedExisting}; inline posted: ${publishResult.value.inlinePosted}; inline skipped: ${publishResult.value.inlineSkipped}; inline failed: ${publishResult.value.inlineFailed}; stale removed: ${publishResult.value.staleDeleted}; stale resolved: ${publishResult.value.staleResolved}`
|
|
69330
69529
|
)
|
|
69331
69530
|
);
|
|
69332
69531
|
} else if (!options.silent) {
|
|
@@ -69339,16 +69538,17 @@ var runPrReview = async (options) => {
|
|
|
69339
69538
|
);
|
|
69340
69539
|
}
|
|
69341
69540
|
}
|
|
69342
|
-
|
|
69343
|
-
|
|
69344
|
-
|
|
69345
|
-
|
|
69346
|
-
|
|
69347
|
-
|
|
69348
|
-
|
|
69349
|
-
|
|
69350
|
-
|
|
69351
|
-
|
|
69541
|
+
const gate = computePrGate(
|
|
69542
|
+
mergedFindings,
|
|
69543
|
+
staticResult.ruleKindById,
|
|
69544
|
+
config.review.gate,
|
|
69545
|
+
options.aiGatePolicy
|
|
69546
|
+
);
|
|
69547
|
+
phaseLog.info(
|
|
69548
|
+
"quality-gate",
|
|
69549
|
+
`exit_code=${gate.exitCode} gating_blocker=${gate.gatingBlocker} gating_error=${gate.gatingError} advisory_ai_error_plus=${gate.advisoryErrorPlus}`
|
|
69550
|
+
);
|
|
69551
|
+
return gate.exitCode;
|
|
69352
69552
|
} catch (error) {
|
|
69353
69553
|
phaseLog.error(activeReviewPhase, error.message);
|
|
69354
69554
|
const renderer = getInkRenderer();
|
|
@@ -71410,27 +71610,6 @@ var SERVER_RUN_PROGRESS_PREFIX = "cs-progress ";
|
|
|
71410
71610
|
var log2 = (silent, msg) => {
|
|
71411
71611
|
if (!silent) console.log(msg);
|
|
71412
71612
|
};
|
|
71413
|
-
var resolveGatePolicy = (configGate, override, skipOverride) => ({
|
|
71414
|
-
aiPolicy: override ?? configGate.aiPolicy,
|
|
71415
|
-
aiMinConfidence: configGate.aiMinConfidence,
|
|
71416
|
-
aiSkipPolicy: skipOverride ?? configGate.aiSkipPolicy
|
|
71417
|
-
});
|
|
71418
|
-
var computeGateResult = (findings2, ruleKindById, policy) => {
|
|
71419
|
-
let gatingBlocker = 0;
|
|
71420
|
-
let gatingError = 0;
|
|
71421
|
-
let advisoryErrorPlus = 0;
|
|
71422
|
-
for (const f of findings2) {
|
|
71423
|
-
const source = ruleKindById.get(f.ruleId) === "ai" ? "ai" : "deterministic";
|
|
71424
|
-
if (findingGates(f, source, policy)) {
|
|
71425
|
-
if (f.severity === "blocker") gatingBlocker++;
|
|
71426
|
-
else if (f.severity === "error") gatingError++;
|
|
71427
|
-
} else if (source === "ai" && meetsSeverity(f.severity, "error")) {
|
|
71428
|
-
advisoryErrorPlus++;
|
|
71429
|
-
}
|
|
71430
|
-
}
|
|
71431
|
-
const exitCode = gatingBlocker > 0 ? EXIT.FINDINGS_BLOCKER : gatingError > 0 ? EXIT.FINDINGS_ERROR : EXIT.SUCCESS;
|
|
71432
|
-
return { exitCode, gatingError, gatingBlocker, advisoryErrorPlus };
|
|
71433
|
-
};
|
|
71434
71613
|
var escalateExitForCoverage = (baseExit, coverageBlocks) => baseExit === EXIT.SUCCESS && coverageBlocks ? EXIT.RUNTIME : baseExit;
|
|
71435
71614
|
var hasIncompleteQueuedFullCoverage = (isRunnerInvocation, runtimeSinceRef2, aiStats) => isRunnerInvocation && (runtimeSinceRef2 === void 0 || runtimeSinceRef2.length === 0) && aiStats !== void 0 && countRecallRiskSkips(aiStats) > 0;
|
|
71436
71615
|
var rulesToRerun = (aiStats) => {
|
|
@@ -71460,6 +71639,7 @@ var runReview = async (options = {}) => {
|
|
|
71460
71639
|
prWorkspace: options.prWorkspace,
|
|
71461
71640
|
prAiStrategy: options.prAiStrategy,
|
|
71462
71641
|
aiOff: options.aiOff === true,
|
|
71642
|
+
...options.aiGatePolicy !== void 0 ? { aiGatePolicy: options.aiGatePolicy } : {},
|
|
71463
71643
|
mode: options.mode,
|
|
71464
71644
|
...options.scope !== void 0 ? { scope: options.scope } : {},
|
|
71465
71645
|
minSeverity: options.minSeverity,
|