@codesherlock/codesherlock-beta-mcp-server 0.0.1
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/.env +9 -0
- package/README.md +185 -0
- package/build/handlers/analyzeCommitHandler.d.ts +36 -0
- package/build/handlers/analyzeCommitHandler.d.ts.map +1 -0
- package/build/handlers/analyzeCommitHandler.js +397 -0
- package/build/handlers/analyzeCommitHandler.js.map +1 -0
- package/build/handlers/events.d.ts +7 -0
- package/build/handlers/events.d.ts.map +1 -0
- package/build/handlers/events.js +15 -0
- package/build/handlers/events.js.map +1 -0
- package/build/handlers/resources.d.ts +10 -0
- package/build/handlers/resources.d.ts.map +1 -0
- package/build/handlers/resources.js +14 -0
- package/build/handlers/resources.js.map +1 -0
- package/build/handlers/tools.d.ts +6 -0
- package/build/handlers/tools.d.ts.map +1 -0
- package/build/handlers/tools.js +29 -0
- package/build/handlers/tools.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +82 -0
- package/build/index.js.map +1 -0
- package/build/schemas/toolSchemas.d.ts +50 -0
- package/build/schemas/toolSchemas.d.ts.map +1 -0
- package/build/schemas/toolSchemas.js +48 -0
- package/build/schemas/toolSchemas.js.map +1 -0
- package/build/services/backendApiService.d.ts +81 -0
- package/build/services/backendApiService.d.ts.map +1 -0
- package/build/services/backendApiService.js +265 -0
- package/build/services/backendApiService.js.map +1 -0
- package/build/services/commitReviewService.d.ts +71 -0
- package/build/services/commitReviewService.d.ts.map +1 -0
- package/build/services/commitReviewService.js +506 -0
- package/build/services/commitReviewService.js.map +1 -0
- package/build/services/gitService.d.ts +159 -0
- package/build/services/gitService.d.ts.map +1 -0
- package/build/services/gitService.js +778 -0
- package/build/services/gitService.js.map +1 -0
- package/build/services/loggingService.d.ts +64 -0
- package/build/services/loggingService.d.ts.map +1 -0
- package/build/services/loggingService.js +185 -0
- package/build/services/loggingService.js.map +1 -0
- package/build/services/zipService.d.ts +9 -0
- package/build/services/zipService.d.ts.map +1 -0
- package/build/services/zipService.js +47 -0
- package/build/services/zipService.js.map +1 -0
- package/build/tests/analysisFormatter.test.d.ts +2 -0
- package/build/tests/analysisFormatter.test.d.ts.map +1 -0
- package/build/tests/analysisFormatter.test.js +92 -0
- package/build/tests/analysisFormatter.test.js.map +1 -0
- package/build/tests/analyzeCommitHandler.test.d.ts +2 -0
- package/build/tests/analyzeCommitHandler.test.d.ts.map +1 -0
- package/build/tests/analyzeCommitHandler.test.js +111 -0
- package/build/tests/analyzeCommitHandler.test.js.map +1 -0
- package/build/tests/backendApiService.test.d.ts +2 -0
- package/build/tests/backendApiService.test.d.ts.map +1 -0
- package/build/tests/backendApiService.test.js +109 -0
- package/build/tests/backendApiService.test.js.map +1 -0
- package/build/tests/commitReviewService.test.d.ts +2 -0
- package/build/tests/commitReviewService.test.d.ts.map +1 -0
- package/build/tests/commitReviewService.test.js +120 -0
- package/build/tests/commitReviewService.test.js.map +1 -0
- package/build/tests/errorExtractor.test.d.ts +2 -0
- package/build/tests/errorExtractor.test.d.ts.map +1 -0
- package/build/tests/errorExtractor.test.js +61 -0
- package/build/tests/errorExtractor.test.js.map +1 -0
- package/build/tests/loggingService.test.d.ts +2 -0
- package/build/tests/loggingService.test.d.ts.map +1 -0
- package/build/tests/loggingService.test.js +153 -0
- package/build/tests/loggingService.test.js.map +1 -0
- package/build/tests/setup.test.d.ts +2 -0
- package/build/tests/setup.test.d.ts.map +1 -0
- package/build/tests/setup.test.js +7 -0
- package/build/tests/setup.test.js.map +1 -0
- package/build/tests/tools.test.d.ts +2 -0
- package/build/tests/tools.test.d.ts.map +1 -0
- package/build/tests/tools.test.js +58 -0
- package/build/tests/tools.test.js.map +1 -0
- package/build/utils/analysisFormatter.d.ts +40 -0
- package/build/utils/analysisFormatter.d.ts.map +1 -0
- package/build/utils/analysisFormatter.js +97 -0
- package/build/utils/analysisFormatter.js.map +1 -0
- package/build/utils/errorExtractor.d.ts +36 -0
- package/build/utils/errorExtractor.d.ts.map +1 -0
- package/build/utils/errorExtractor.js +178 -0
- package/build/utils/errorExtractor.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import WebSocket from "ws";
|
|
2
|
+
import JSZip from "jszip";
|
|
3
|
+
import { File, Blob } from "node:buffer";
|
|
4
|
+
import { logger } from "./loggingService.js";
|
|
5
|
+
/**
|
|
6
|
+
* Backend API Service
|
|
7
|
+
* Handles HTTP API calls and WebSocket connections for commit review
|
|
8
|
+
*/
|
|
9
|
+
export class BackendApiService {
|
|
10
|
+
baseUrl;
|
|
11
|
+
wsBaseUrl;
|
|
12
|
+
apiKey;
|
|
13
|
+
constructor(baseUrl, apiKey) {
|
|
14
|
+
if (!baseUrl || baseUrl.trim() === "") {
|
|
15
|
+
throw new Error("BACKEND_API_URL environment variable is required but not set. Please configure it in your .env file or environment variables.");
|
|
16
|
+
}
|
|
17
|
+
this.baseUrl = baseUrl;
|
|
18
|
+
// Convert HTTP/HTTPS URLs to WebSocket URLs (ws/wss)
|
|
19
|
+
// Handle both http:// and https:// protocols correctly
|
|
20
|
+
if (baseUrl.startsWith("https://")) {
|
|
21
|
+
this.wsBaseUrl = baseUrl.replace(/^https/, "wss");
|
|
22
|
+
}
|
|
23
|
+
else if (baseUrl.startsWith("http://")) {
|
|
24
|
+
this.wsBaseUrl = baseUrl.replace(/^http/, "ws");
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// If URL doesn't start with http/https, assume ws protocol
|
|
28
|
+
logger.logWarning("Backend URL doesn't start with http/https, assuming WebSocket protocol", { baseUrl });
|
|
29
|
+
this.wsBaseUrl = baseUrl;
|
|
30
|
+
}
|
|
31
|
+
this.apiKey = apiKey;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Submit commit review to backend
|
|
35
|
+
*/
|
|
36
|
+
async submitCommitReview(params) {
|
|
37
|
+
try {
|
|
38
|
+
const url = `${this.baseUrl}/v2/commit-review/${params.factor}`;
|
|
39
|
+
const formData = new FormData();
|
|
40
|
+
formData.append("user_id", params.user_id);
|
|
41
|
+
formData.append("repo_name", params.repo_name);
|
|
42
|
+
formData.append("commit_id", params.commit_id);
|
|
43
|
+
formData.append("username", params.username);
|
|
44
|
+
formData.append("factor", params.factor);
|
|
45
|
+
// Build ZIP
|
|
46
|
+
const zip = new JSZip();
|
|
47
|
+
zip.file("files.json", params.files_json);
|
|
48
|
+
const filesBuffer = await zip.generateAsync({ type: "nodebuffer" });
|
|
49
|
+
// Convert Buffer → Blob → File
|
|
50
|
+
const blob = new Blob([filesBuffer], { type: "application/zip" });
|
|
51
|
+
formData.append("files_zip", new File([blob], "files.zip", { type: "application/zip" }));
|
|
52
|
+
if (params.organization_name) {
|
|
53
|
+
formData.append("organization_name", params.organization_name);
|
|
54
|
+
}
|
|
55
|
+
const response = await fetch(url, {
|
|
56
|
+
method: "POST",
|
|
57
|
+
headers: {
|
|
58
|
+
...(this.apiKey ? { "X-CS-MCP-API-Key": this.apiKey } : {})
|
|
59
|
+
},
|
|
60
|
+
body: formData
|
|
61
|
+
});
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
let errorDetail = "Unknown error";
|
|
64
|
+
let rawBody;
|
|
65
|
+
let parsedBody;
|
|
66
|
+
try {
|
|
67
|
+
// Try to parse JSON error response (FastAPI typically returns {detail: "message"})
|
|
68
|
+
parsedBody = await response.json();
|
|
69
|
+
errorDetail = parsedBody.detail || parsedBody.error || parsedBody.message || JSON.stringify(parsedBody);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// If not JSON, use text response
|
|
73
|
+
const errorText = await response.text();
|
|
74
|
+
rawBody = errorText;
|
|
75
|
+
errorDetail = errorText || `HTTP ${response.status}`;
|
|
76
|
+
}
|
|
77
|
+
// Prepare safe string values for logging (logger expects string properties)
|
|
78
|
+
const parsedBodyString = parsedBody ? JSON.stringify(parsedBody) : "";
|
|
79
|
+
const rawBodyString = rawBody ?? "";
|
|
80
|
+
// Log full backend error response for easier debugging
|
|
81
|
+
logger.logError("Backend commit-review HTTP error response", new Error(errorDetail), {
|
|
82
|
+
url,
|
|
83
|
+
status: String(response.status),
|
|
84
|
+
parsedBody: parsedBodyString,
|
|
85
|
+
rawBody: rawBodyString,
|
|
86
|
+
});
|
|
87
|
+
// Create error with status code in message for extraction
|
|
88
|
+
const error = new Error(`HTTP error! status: ${response.status}, detail: ${errorDetail}`);
|
|
89
|
+
error.statusCode = response.status;
|
|
90
|
+
error.errorDetail = errorDetail;
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
// Handle 202 Accepted response (FastAPI returns this for background processing)
|
|
94
|
+
if (response.status === 202) {
|
|
95
|
+
let data = {};
|
|
96
|
+
try {
|
|
97
|
+
// Try to parse JSON response (FastAPI may return JSON with message)
|
|
98
|
+
const contentType = response.headers.get("content-type");
|
|
99
|
+
if (contentType && contentType.includes("application/json")) {
|
|
100
|
+
data = await response.json();
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// If not JSON, read as text
|
|
104
|
+
const text = await response.text();
|
|
105
|
+
data = { message: text || "Commit review request received. Processing in the background." };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// If parsing fails, use default message
|
|
110
|
+
data = { message: "Commit review request received. Processing in the background." };
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
success: true,
|
|
114
|
+
data,
|
|
115
|
+
analysisId: data.analysis_id ? String(data.analysis_id) : undefined,
|
|
116
|
+
message: data.message || "Commit review submitted successfully"
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
// Handle other success responses (200, etc.)
|
|
120
|
+
let data = {};
|
|
121
|
+
try {
|
|
122
|
+
data = await response.json();
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
// If JSON parsing fails, create a default response
|
|
126
|
+
logger.logWarning("Failed to parse JSON response, using default", { status: String(response.status) });
|
|
127
|
+
data = { message: "Commit review submitted successfully" };
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
success: true,
|
|
131
|
+
data,
|
|
132
|
+
analysisId: data.analysis_id ? String(data.analysis_id) : undefined,
|
|
133
|
+
message: data.message || "Commit review submitted successfully"
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
logger.logError("Error submitting commit review", error);
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* WebSocket connection for real-time commit analysis
|
|
143
|
+
*/
|
|
144
|
+
connectWebSocket(userId, onMessage, onError, onClose) {
|
|
145
|
+
return new Promise((resolve, reject) => {
|
|
146
|
+
try {
|
|
147
|
+
const wsUrl = `${this.wsBaseUrl}/v2/ws/${userId}`;
|
|
148
|
+
logger.logInfo("Connecting to WebSocket", { wsUrl, userId });
|
|
149
|
+
// Validate WebSocket URL format
|
|
150
|
+
if (!wsUrl.startsWith("ws://") && !wsUrl.startsWith("wss://")) {
|
|
151
|
+
const error = new Error(`Invalid WebSocket URL format: ${wsUrl}. ` +
|
|
152
|
+
`Expected URL to start with ws:// or wss://. ` +
|
|
153
|
+
`Please check your BACKEND_API_URL configuration.`);
|
|
154
|
+
logger.logError("Invalid WebSocket URL format", error, { wsUrl, baseUrl: this.baseUrl, wsBaseUrl: this.wsBaseUrl });
|
|
155
|
+
reject(error);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const ws = new WebSocket(wsUrl);
|
|
159
|
+
ws.on("open", () => {
|
|
160
|
+
logger.logInfo("WebSocket connection opened", { userId });
|
|
161
|
+
resolve(ws);
|
|
162
|
+
});
|
|
163
|
+
ws.on("message", (data) => {
|
|
164
|
+
try {
|
|
165
|
+
const message = JSON.parse(data.toString());
|
|
166
|
+
onMessage(message);
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
logger.logError("Error parsing WebSocket message", error);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
ws.on("error", (error) => {
|
|
173
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
174
|
+
const enhancedError = new Error(`WebSocket connection failed: ${errorMessage}. ` +
|
|
175
|
+
`URL: ${wsUrl}. ` +
|
|
176
|
+
`Please verify that the backend service is running and accessible.`);
|
|
177
|
+
logger.logError("WebSocket error", enhancedError, { userId, wsUrl });
|
|
178
|
+
onError?.(enhancedError);
|
|
179
|
+
reject(enhancedError);
|
|
180
|
+
});
|
|
181
|
+
ws.on("close", (code, reason) => {
|
|
182
|
+
const reasonStr = reason.toString();
|
|
183
|
+
// Log close events with more detail for debugging
|
|
184
|
+
if (code !== 1000) {
|
|
185
|
+
logger.logWarning("WebSocket closed unexpectedly", {
|
|
186
|
+
userId,
|
|
187
|
+
code: String(code),
|
|
188
|
+
reason: reasonStr,
|
|
189
|
+
wsUrl
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
onClose?.(code, reasonStr);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
197
|
+
const enhancedError = new Error(`Failed to create WebSocket connection: ${errorMessage}. ` +
|
|
198
|
+
`Please check your network connection and backend service availability.`);
|
|
199
|
+
logger.logError("Error creating WebSocket connection", enhancedError, {
|
|
200
|
+
userId,
|
|
201
|
+
wsBaseUrl: this.wsBaseUrl
|
|
202
|
+
});
|
|
203
|
+
reject(enhancedError);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
async sendDiff(diff, metadata) {
|
|
208
|
+
return {
|
|
209
|
+
success: true,
|
|
210
|
+
message: "Diff received (legacy method)"
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
async getAnalysisResults(analysisId) {
|
|
214
|
+
throw new Error("Not implemented");
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Get user information from secure route
|
|
218
|
+
* Uses API key authentication to fetch authenticated user details
|
|
219
|
+
* @returns User information including user_id and username
|
|
220
|
+
*/
|
|
221
|
+
async getUserFromSecureRoute() {
|
|
222
|
+
try {
|
|
223
|
+
const url = `${this.baseUrl}/v2/secure_route`;
|
|
224
|
+
if (!this.apiKey) {
|
|
225
|
+
throw new Error("API key is required for secure route authentication");
|
|
226
|
+
}
|
|
227
|
+
const response = await fetch(url, {
|
|
228
|
+
method: "POST",
|
|
229
|
+
headers: {
|
|
230
|
+
"X-CS-MCP-API-Key": this.apiKey,
|
|
231
|
+
"Content-Type": "application/json"
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
if (!response.ok) {
|
|
235
|
+
let errorDetail = "Unknown error";
|
|
236
|
+
try {
|
|
237
|
+
// Try to parse JSON error response (FastAPI typically returns {detail: "message"})
|
|
238
|
+
const errorJson = await response.json();
|
|
239
|
+
errorDetail = errorJson.detail || JSON.stringify(errorJson);
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
// If not JSON, use text response
|
|
243
|
+
const errorText = await response.text();
|
|
244
|
+
errorDetail = errorText || `HTTP ${response.status}`;
|
|
245
|
+
}
|
|
246
|
+
logger.logError(`HTTP error! status: ${response.status}, detail: ${errorDetail}`);
|
|
247
|
+
if (response.status === 401) {
|
|
248
|
+
throw new Error(errorDetail || "Authentication required. Please provide a valid API key.");
|
|
249
|
+
}
|
|
250
|
+
else if (response.status === 404) {
|
|
251
|
+
throw new Error(errorDetail || "User not found.");
|
|
252
|
+
}
|
|
253
|
+
throw new Error(errorDetail || `HTTP error! status: ${response.status}`);
|
|
254
|
+
}
|
|
255
|
+
const user = await response.json();
|
|
256
|
+
logger.logInfo("User retrieved from secure route", { user_id: user.userid });
|
|
257
|
+
return user;
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
logger.logError("Error fetching user from secure route", error);
|
|
261
|
+
throw error;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=backendApiService.js.map
|
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,iBAAiB,CAAC,CAAC;gBACtD,CAAC;gBAED,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,uBAAuB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;YAC7E,CAAC;YAED,MAAM,IAAI,GAAQ,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YAExC,MAAM,CAAC,OAAO,CAAC,kCAAkC,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YAE7E,OAAO,IAAI,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,CAAC,QAAQ,CAAC,uCAAuC,EAAE,KAAc,CAAC,CAAC;YACzE,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { BackendApiService } from "./backendApiService.js";
|
|
2
|
+
import { FileChange } from "./gitService.js";
|
|
3
|
+
/**
|
|
4
|
+
* Commit Review Service
|
|
5
|
+
* Handles the full flow of submitting commit review and receiving results via WebSocket
|
|
6
|
+
*/
|
|
7
|
+
export declare class CommitReviewService {
|
|
8
|
+
private backendApiService;
|
|
9
|
+
constructor(backendApiService: BackendApiService);
|
|
10
|
+
/**
|
|
11
|
+
* Submit commit review and wait for analysis results via WebSocket
|
|
12
|
+
* @param params - Commit review parameters
|
|
13
|
+
* @returns Analysis results
|
|
14
|
+
*/
|
|
15
|
+
submitAndWaitForResults(params: CommitReviewSubmitParams): Promise<CommitReviewResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Collect analysis results via an already-established WebSocket connection
|
|
18
|
+
* This method reuses an existing WebSocket connection instead of creating a new one
|
|
19
|
+
* @param ws - Already-established WebSocket connection (must be in OPEN state)
|
|
20
|
+
* @param userId - User ID for logging
|
|
21
|
+
* @param timeoutMs - Maximum time to wait for results (default: 10 minutes)
|
|
22
|
+
* @returns Array of analysis results
|
|
23
|
+
*/
|
|
24
|
+
private collectResultsViaEstablishedWebSocket;
|
|
25
|
+
/**
|
|
26
|
+
* Connect to WebSocket and collect analysis results
|
|
27
|
+
* Handles edge cases:
|
|
28
|
+
* - Timeout scenarios (backend takes too long)
|
|
29
|
+
* - Empty results (no files to analyze)
|
|
30
|
+
* - Partial results (some files succeed, others fail)
|
|
31
|
+
* - WebSocket completion without explicit completion signal
|
|
32
|
+
* @param userId - User ID for WebSocket connection
|
|
33
|
+
* @param onConnection - Callback when connection is established
|
|
34
|
+
* @param timeoutMs - Maximum time to wait for results (default: 10 minutes)
|
|
35
|
+
* @returns Array of analysis results
|
|
36
|
+
*/
|
|
37
|
+
private collectResultsViaWebSocket;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Commit review submit parameters
|
|
41
|
+
*/
|
|
42
|
+
export interface CommitReviewSubmitParams {
|
|
43
|
+
factor: "power_analysis" | "owasp" | "cwe";
|
|
44
|
+
user_id: string;
|
|
45
|
+
repo_name: string;
|
|
46
|
+
commit_id: string;
|
|
47
|
+
username: string;
|
|
48
|
+
file_changes: FileChange[];
|
|
49
|
+
organization_name?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Analysis result item
|
|
53
|
+
*/
|
|
54
|
+
export interface AnalysisResultItem {
|
|
55
|
+
analysis: any;
|
|
56
|
+
language?: string;
|
|
57
|
+
file_name: string;
|
|
58
|
+
analysisId: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Commit review result
|
|
62
|
+
*/
|
|
63
|
+
export interface CommitReviewResult {
|
|
64
|
+
[key: string]: unknown;
|
|
65
|
+
success: boolean;
|
|
66
|
+
analysisId?: string;
|
|
67
|
+
message?: string;
|
|
68
|
+
results?: AnalysisResultItem[];
|
|
69
|
+
error?: string;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=commitReviewService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commitReviewService.d.ts","sourceRoot":"","sources":["../../src/services/commitReviewService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