@comate/zulu 0.7.4-beta.1 → 0.7.4

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.
@@ -19,7 +19,7 @@ import require$$4$2 from 'assert';
19
19
  import zlib$1 from 'zlib';
20
20
  import require$$5$1, { EventEmitter as EventEmitter$3 } from 'events';
21
21
  import { spawnSync } from 'node:child_process';
22
- import require$$1$3, { randomUUID } from 'crypto';
22
+ import require$$1$3, { createHash, randomUUID } from 'crypto';
23
23
  import require$$13 from 'querystring';
24
24
  import require$$0$5 from 'buffer';
25
25
  import require$$1$4 from 'string_decoder';
@@ -7851,8 +7851,8 @@ class GitUtil {
7851
7851
  const deletedLineNumbers = new Set();
7852
7852
  const addedLines = [];
7853
7853
  const removedLines = [];
7854
- let oldLineNum = 0;
7855
- let newLineNum = 0;
7854
+ let oldLineNum = 1;
7855
+ let newLineNum = 1;
7856
7856
  changes.forEach((part)=>{
7857
7857
  if (part.added) {
7858
7858
  for(let i = 0; i < part.count; i++){
@@ -25882,7 +25882,7 @@ async function getKirinSyncSkillRecogRes(url, data) {
25882
25882
  try {
25883
25883
  // eslint-disable-next-line
25884
25884
  while(running){
25885
- await sleep(1 * 1000);
25885
+ await sleep$1(1 * 1000);
25886
25886
  const result = await fetchUrl(url, commonHeadersConfig, data, 'POST');
25887
25887
  if (!result) {
25888
25888
  continue;
@@ -25950,7 +25950,7 @@ async function getKirinSyncRes(url, data) {
25950
25950
  try {
25951
25951
  // eslint-disable-next-line
25952
25952
  while(running){
25953
- await sleep(1 * 1000);
25953
+ await sleep$1(1 * 1000);
25954
25954
  const result = await fetchUrl(url, commonHeadersConfig, data, 'POST');
25955
25955
  if (!result) {
25956
25956
  continue;
@@ -26015,7 +26015,7 @@ async function getKirinSyncGDPPathList(url, data) {
26015
26015
  // eslint-disable-next-line
26016
26016
  while(Date.now() < endTime){
26017
26017
  try {
26018
- await sleep(1 * 1000);
26018
+ await sleep$1(1 * 1000);
26019
26019
  const result = await fetchUrl(url, commonHeadersConfig, data, 'POST');
26020
26020
  // 0-排队中 1-新建 2-执行中 3-执行成功 4-执行失败 5-强制终止
26021
26021
  if (!result || result.result.taskStatus <= 2) {
@@ -26064,7 +26064,7 @@ async function getKirinSyncGDPPathList(url, data) {
26064
26064
  async function getKirinAsyncStrategyResult(taskId, timeout = 180 * 1000) {
26065
26065
  const endTime = Date.now() + timeout;
26066
26066
  while(Date.now() < endTime){
26067
- await sleep(1 * 1000);
26067
+ await sleep$1(1 * 1000);
26068
26068
  const result = await fetchUrl(`https://kirin.baidu-int.com/api/task/${taskId}`, commonHeadersConfig, {}, 'GET');
26069
26069
  if (!result || !result.result || result.result.taskStatus <= 2) {
26070
26070
  continue;
@@ -26112,7 +26112,7 @@ async function getKirinCodeGenerateAsyncStrategyResult(taskId) {
26112
26112
  try {
26113
26113
  // eslint-disable-next-line
26114
26114
  while(running){
26115
- await sleep(1 * 1000);
26115
+ await sleep$1(1 * 1000);
26116
26116
  const result = await fetchUrl(`${kirinAsynResCallBackURL}/${taskId}`, commonHeadersConfig, {}, 'GET');
26117
26117
  if (!result) {
26118
26118
  continue;
@@ -26520,7 +26520,7 @@ async function* sameSessionDeal(codeGeneratedParams, sessionAccessToken) {
26520
26520
  message: '\n\n'
26521
26521
  };
26522
26522
  while(true){
26523
- await sleep(0.5 * 1000);
26523
+ await sleep$1(0.5 * 1000);
26524
26524
  const { done, value } = await modelReader.read();
26525
26525
  if (done) {
26526
26526
  break;
@@ -26661,7 +26661,7 @@ async function* feedCodeGenerateProcess(codeGeneratedParams) {
26661
26661
  type: 'flushReplace',
26662
26662
  message: '解析您的目标,启动生成,全程预估' + i + 's,请耐心等待......\n\n'
26663
26663
  };
26664
- await sleep(5 * 1000);
26664
+ await sleep$1(5 * 1000);
26665
26665
  }
26666
26666
  yield {
26667
26667
  type: 'flushReplace',
@@ -26803,7 +26803,7 @@ async function queryResult(hopeStatus, data) {
26803
26803
  try {
26804
26804
  // eslint-disable-next-line
26805
26805
  while(running){
26806
- await sleep(1 * 1000);
26806
+ await sleep$1(1 * 1000);
26807
26807
  const result = await fetchUrl(qadcSelectCodeGenStageInfoURL, qadcHeadersConfig, data);
26808
26808
  if (!result) {
26809
26809
  continue;
@@ -27281,7 +27281,7 @@ class CodeModificationProvider extends SkillProvider {
27281
27281
  this.result.push(/*#__PURE__*/ jsx("p", {
27282
27282
  children: " "
27283
27283
  }));
27284
- await sleep(1000);
27284
+ await sleep$1(1000);
27285
27285
  yield this.stream.flush(/*#__PURE__*/ jsx("card", {
27286
27286
  color: "green",
27287
27287
  children: result
@@ -27430,7 +27430,7 @@ class CodeModificationProvider extends SkillProvider {
27430
27430
  this.result.push(/*#__PURE__*/ jsx("p", {
27431
27431
  children: " "
27432
27432
  }));
27433
- await sleep(1000);
27433
+ await sleep$1(1000);
27434
27434
  yield this.stream.flush(/*#__PURE__*/ jsx("card", {
27435
27435
  color: "green",
27436
27436
  children: searchResItemList
@@ -66683,7 +66683,7 @@ class OPSelfTestProvider extends SkillProvider {
66683
66683
  'case_filter_taskid:[' + caseFiltertaskID + '], test_case_taskid:[' + testCaseTaskId + '],' + `rd:[${userName}],` + 'query:[' + this.currentContext.query + '],' + 'conf:[' + this.currentContext.activeFileLineContent + '], ' + 'success');
66684
66684
  return;
66685
66685
  }
66686
- await sleep(3 * 1000);
66686
+ await sleep$1(3 * 1000);
66687
66687
  }
66688
66688
  } finally{
66689
66689
  clearTimeout(timer);
@@ -67368,7 +67368,7 @@ function formatDuration(duration) {
67368
67368
  return duration.toFixed(2) + ' ms';
67369
67369
  }
67370
67370
  }
67371
- function sleep(ms) {
67371
+ function sleep$1(ms) {
67372
67372
  return new Promise((resolve)=>setTimeout(resolve, ms));
67373
67373
  }
67374
67374
  async function getGitUtilObj(filePath) {
@@ -67562,7 +67562,7 @@ async function updateChunk2Qadc(chunkStr, keyValue, tableName = 'fea_gen_record'
67562
67562
  return;
67563
67563
  } else {
67564
67564
  --tryTimes;
67565
- await sleep(1.5 * 1000);
67565
+ await sleep$1(1.5 * 1000);
67566
67566
  }
67567
67567
  }
67568
67568
  } // eslint-disable-next-line
@@ -68967,18 +68967,6 @@ async function getRealFileBatchAccept(replacementInfo, finalFileContent, rdName,
68967
68967
  return await jetBatchAccept(replacementInfo, finalFileContent, rdName, moduleName, cwd);
68968
68968
  }
68969
68969
  }
68970
- async function ensureFilePathExists(filePath) {
68971
- const dir = path$6.dirname(filePath); // 获取文件所在目录
68972
- try {
68973
- // 递归创建文件夹,确保路径存在
68974
- await fs$5.mkdir(dir, {
68975
- recursive: true
68976
- });
68977
- return true;
68978
- } catch (err) {
68979
- return false;
68980
- }
68981
- }
68982
68970
  function setToString(inputSet, sort) {
68983
68971
  const array = Array.from(inputSet);
68984
68972
  if (sort) array.sort(sort);
@@ -69024,6 +69012,25 @@ async function update2Qadc(tableName, key, data) {
69024
69012
  status: false
69025
69013
  };
69026
69014
  }
69015
+ async function chunkArray(arr, chunkSize) {
69016
+ const result = [];
69017
+ for(let i = 0; i < arr.length; i += chunkSize){
69018
+ result.push(arr.slice(i, i + chunkSize));
69019
+ }
69020
+ return result;
69021
+ }
69022
+ /**
69023
+ * 获取文件中指定行的内容
69024
+ * @param filePath 文件路径
69025
+ * @param lineNumber 行号,从1开始
69026
+ */ async function readLine(filePath, lineNumber) {
69027
+ // 读取整个文件为字符串
69028
+ const content = await fs$5.readFile(filePath, 'utf-8');
69029
+ // 按行拆分
69030
+ const lines = content.split(/\r?\n/);
69031
+ // lineNumber从1开始,数组索引从0开始
69032
+ return lines[lineNumber - 1];
69033
+ }
69027
69034
 
69028
69035
  class AmisWebGen extends SkillProvider {
69029
69036
  static{
@@ -69599,74 +69606,6 @@ const compareVersions = (v1, v2) => {
69599
69606
  return 0;
69600
69607
  };
69601
69608
 
69602
- async function isNeedScanPythonFile(userName, moduleName) {
69603
- try {
69604
- const payload = {
69605
- userName: userName,
69606
- moduleName: moduleName
69607
- };
69608
- const res = await axios.post('http://10.143.161.42:8001/py-sa/config', payload, {
69609
- timeout: 2 * 1000
69610
- });
69611
- if (res.status !== 200) {
69612
- return false;
69613
- }
69614
- return res.data.data.isNeedScan;
69615
- } catch (e) {
69616
- return false;
69617
- }
69618
- }
69619
- async function scanPyFile(absolutePath, changedLines) {
69620
- const targetStr = 'get_instance_by_service';
69621
- const results = [];
69622
- try {
69623
- const fileContent = Fs__default.readFileSync(absolutePath, 'utf8');
69624
- const lines = fileContent.split('\n');
69625
- for (const lineNum of changedLines){
69626
- const lineIdx = lineNum;
69627
- const line = lines[lineIdx];
69628
- if (!line) {
69629
- continue;
69630
- }
69631
- const index = line.indexOf(targetStr);
69632
- if (index !== -1) {
69633
- results.push({
69634
- range: {
69635
- startLine: lineNum + 1,
69636
- startCharacter: index + 1,
69637
- endLine: lineNum + 1,
69638
- endCharacter: index + targetStr.length + 2
69639
- },
69640
- code: {
69641
- value: 'Mario 算子开发编码规范',
69642
- target: 'https://ku.baidu-int.com/knowledge/HFVrC7hq1Q/M-jemr5Dhg/2xzxBuZiEr/xPaw-YfXS-pYle'
69643
- },
69644
- textMessage: '请勿直接使用get_instance_by_service,请参考马里奥算子开发编码规范要求,动态获取请求下游服务',
69645
- severity: 'WARNING',
69646
- repairData: {
69647
- source: 'SADiagnostic',
69648
- pluginName: 'devaux',
69649
- capability: 'SAProvider',
69650
- query: '修复代码中的漏洞',
69651
- data: undefined
69652
- },
69653
- sourceCode: targetStr,
69654
- contextCode: []
69655
- });
69656
- }
69657
- }
69658
- } catch (e) {
69659
- return {
69660
- absolutePath: '',
69661
- diagnostics: []
69662
- };
69663
- }
69664
- return {
69665
- absolutePath: absolutePath,
69666
- diagnostics: results
69667
- };
69668
- }
69669
-
69670
69609
  var util;
69671
69610
  (function (util) {
69672
69611
  util.assertEqual = (val) => val;
@@ -74160,7 +74099,7 @@ async function queryAETaskWithTimeOut(timeout, taskInfo) {
74160
74099
  while(running){
74161
74100
  const response = await queryAETask(taskInfo);
74162
74101
  if (response == null) {
74163
- await sleep(1 * 1000);
74102
+ await sleep$1(1 * 1000);
74164
74103
  continue;
74165
74104
  }
74166
74105
  if (!response.success) {
@@ -74176,7 +74115,7 @@ async function queryAETaskWithTimeOut(timeout, taskInfo) {
74176
74115
  if (response.data.status === "COMPLETED") {
74177
74116
  return response;
74178
74117
  }
74179
- await sleep(3 * 1000);
74118
+ await sleep$1(3 * 1000);
74180
74119
  continue;
74181
74120
  }
74182
74121
  } catch (error) {
@@ -74765,6 +74704,207 @@ async function getMarkdownLanguage(filename) {
74765
74704
  return map[ext] || ''; // 不认识的扩展名,返回空字符串 }
74766
74705
  }
74767
74706
 
74707
+ const WBOX_TASK_SCAN_TYPE = 4;
74708
+ const WBOX_SCAN_TOOL_ID = 131;
74709
+ const WBOX_SCAN_RUN_MODE = 2;
74710
+ const WBOX_AI_CR_REGULAR_ID = 2522;
74711
+ const WBOX_REPORT_BUG_URL = 'http://wbox.baidu-int.com/api/bugs/add';
74712
+ /**
74713
+ * 获取带时间戳的 SHA-1 哈希字符串
74714
+ * @param input 输入字符串
74715
+ * @returns SHA-1 十六进制哈希字符串
74716
+ */ function getSha1Str(input) {
74717
+ // 获取当前时间戳(纳秒级)
74718
+ // 注意:JavaScript 中时间戳是毫秒级,这里使用 high-resolution time API 获取纳秒级精度
74719
+ const timestamp = process.hrtime.bigint(); // Node.js 环境
74720
+ // 浏览器环境可以使用 performance.now() * 1e6 获取微秒级精度
74721
+ // 将时间戳转换为字符串并拼接到输入字符串
74722
+ const inputWithTimestamp = `${input}${timestamp}`;
74723
+ // 创建一个 SHA-1 哈希对象
74724
+ const hash = createHash('sha1');
74725
+ // 将拼接后的字符串写入哈希对象
74726
+ hash.update(inputWithTimestamp, 'utf8');
74727
+ // 获取哈希值的十六进制字符串
74728
+ return hash.digest('hex');
74729
+ }
74730
+ async function wboxScanTaskRegister(user, toolName, filePath, git) {
74731
+ const agileModuleName = await git.getModuleName();
74732
+ const userName = user ? user.name : 'unknown';
74733
+ const taskId = await wboxRegisterInner({
74734
+ taskType: WBOX_TASK_SCAN_TYPE,
74735
+ agileModuleName: agileModuleName ? agileModuleName : 'unknown',
74736
+ toolId: WBOX_SCAN_TOOL_ID,
74737
+ agilePipelineTriggerUser: user ? user.name : 'unknown',
74738
+ agileCheckinAuthor: user ? user.name : 'unknown',
74739
+ agileCompileBranch: await git.getBranch(),
74740
+ runMode: WBOX_SCAN_RUN_MODE,
74741
+ agileBaseRevision: await git.getCommitId(),
74742
+ agile_Revision: getSha1Str(filePath + await await git.getBranch() + userName),
74743
+ stage: toolName
74744
+ });
74745
+ return taskId;
74746
+ }
74747
+ async function uploadDiffToBos(wboxTaskID, relativePath, absolutePath) {
74748
+ const bosStsSession = await getSessionTokens();
74749
+ const bosStsClient = new BosUtil(bosStsSession.data.access_key_id, bosStsSession.data.secret_access_key, 'https://qep-public.bj.bcebos.com', bosStsSession.data.session_token);
74750
+ await bosStsClient.putObjFromFile('wbox', `devaux/${wboxTaskID}/${relativePath}`, absolutePath);
74751
+ const bosDownloadUrl = await bosStsClient.generatePresignedUrl('wbox', `devaux/${wboxTaskID}/${relativePath}`);
74752
+ return bosDownloadUrl;
74753
+ }
74754
+ async function getPromptFromDevAuxServer(filePath, bosURL, taskID, diffLines) {
74755
+ try {
74756
+ const payload = {
74757
+ filePath: filePath,
74758
+ bosURL: bosURL,
74759
+ taskID: taskID,
74760
+ diffLines: diffLines
74761
+ };
74762
+ const res = await axios.post('http://10.143.161.42:8006/devaux/get_prompt', payload, {
74763
+ timeout: 2 * 1000
74764
+ });
74765
+ if (res.status !== 200) {
74766
+ return undefined;
74767
+ }
74768
+ return res.data;
74769
+ } catch (e) {
74770
+ return undefined;
74771
+ }
74772
+ }
74773
+ // 带重试机制的请求函数
74774
+ async function makeRequestWithRetry({ url, payload, headers, timeout, maxRetries, retryDelay }) {
74775
+ let lastError;
74776
+ for(let attempt = 1; attempt <= maxRetries; attempt++){
74777
+ try {
74778
+ const resp = await axios.post(url, payload, {
74779
+ headers,
74780
+ timeout
74781
+ });
74782
+ if (resp.status === 200) {
74783
+ return resp.data;
74784
+ } else {
74785
+ // 状态码非200,抛出错误以触发重试
74786
+ throw new Error(`HTTP状态码错误: ${resp.status}`);
74787
+ }
74788
+ } catch (error) {
74789
+ lastError = error;
74790
+ // 如果是最后一次重试,直接抛出错误
74791
+ if (attempt === maxRetries) {
74792
+ throw lastError;
74793
+ }
74794
+ // 计算下一次重试的延迟时间(指数退避)
74795
+ const delay = retryDelay * Math.pow(2, attempt - 1);
74796
+ // 等待一段时间后重试
74797
+ await sleep(delay);
74798
+ }
74799
+ }
74800
+ throw lastError;
74801
+ }
74802
+ // 睡眠函数,用于重试延迟
74803
+ function sleep(ms) {
74804
+ return new Promise((resolve)=>setTimeout(resolve, ms));
74805
+ }
74806
+ // 可选:如果你想限制并发数量,可以使用以下版本
74807
+ async function getAICRResultFromModelWithConcurrency(aiCRPrompt, retryConfig = {}, concurrencyLimit = 5) {
74808
+ const { maxRetries = 3, retryDelay = 1000, timeout = 300 * 1000 } = retryConfig;
74809
+ const payloads = aiCRPrompt.request_model_payload;
74810
+ const results = [];
74811
+ // 分批处理,控制并发数
74812
+ for(let i = 0; i < payloads.length; i += concurrencyLimit){
74813
+ const batch = payloads.slice(i, i + concurrencyLimit);
74814
+ const batchPromises = batch.map((payload)=>makeRequestWithRetry({
74815
+ url: aiCRPrompt.url,
74816
+ payload,
74817
+ headers: aiCRPrompt.request_model_header,
74818
+ timeout,
74819
+ maxRetries,
74820
+ retryDelay
74821
+ }).catch((error)=>{
74822
+ console.error('请求失败:', error.message);
74823
+ return undefined;
74824
+ }));
74825
+ const batchResults = await Promise.all(batchPromises);
74826
+ const successfulResults = batchResults.filter((result)=>result !== undefined);
74827
+ results.push(...successfulResults);
74828
+ }
74829
+ return results.length > 0 ? results : undefined;
74830
+ }
74831
+ async function submitBug2Wbox(relativePath, diagnosticRes, taskID, userName) {
74832
+ const req = [];
74833
+ for (const diag of diagnosticRes){
74834
+ req.push({
74835
+ taskId: taskID,
74836
+ bugSource: 0,
74837
+ bugContext: diag.textMessage,
74838
+ bugReason: '',
74839
+ caseContext: '',
74840
+ codeContext: '',
74841
+ codeFile: relativePath,
74842
+ codeFunction: '',
74843
+ codeErrorLines: diag.sourceCode,
74844
+ bugUser: userName,
74845
+ regularId: WBOX_AI_CR_REGULAR_ID,
74846
+ isDiff: 0
74847
+ });
74848
+ }
74849
+ if (req.length !== 0) {
74850
+ const reqSlice = await chunkArray(req, 200);
74851
+ for (const slice of reqSlice){
74852
+ try {
74853
+ const resp = await axios.post(WBOX_REPORT_BUG_URL, slice, {
74854
+ timeout: 300 * 1000 // 超时设置为5min
74855
+ });
74856
+ if (resp.status !== 200) {
74857
+ return undefined;
74858
+ }
74859
+ } catch (e) {
74860
+ continue;
74861
+ }
74862
+ }
74863
+ }
74864
+ }
74865
+ async function wboxScanTaskCallBack(data) {
74866
+ const response = await fetch(WBOX_HOST + WBOX_API.get('callback'), {
74867
+ method: 'PUT',
74868
+ headers: {
74869
+ 'Content-Type': 'application/json'
74870
+ },
74871
+ body: JSON.stringify(data)
74872
+ });
74873
+ const result = await response.json();
74874
+ if (result.code === 0) {
74875
+ return result.data.task_report_url;
74876
+ }
74877
+ return '';
74878
+ }
74879
+ function extractFirstJSON(s) {
74880
+ // 从第一个 { 开始,逐字符匹配到平衡的 } 為止
74881
+ const start = s.indexOf('{');
74882
+ if (start === -1) return null;
74883
+ let depth = 0;
74884
+ for(let i = start; i < s.length; i++){
74885
+ if (s[i] === '{') depth++;
74886
+ else if (s[i] === '}') {
74887
+ depth--;
74888
+ if (depth === 0) {
74889
+ const substr = s.slice(start, i + 1);
74890
+ try {
74891
+ return JSON.parse(substr);
74892
+ } catch (e) {
74893
+ return null;
74894
+ }
74895
+ }
74896
+ }
74897
+ }
74898
+ return null;
74899
+ }
74900
+ async function cleanAndValidate(output) {
74901
+ const obj = extractFirstJSON(output);
74902
+ if (!obj || !obj.hasOwnProperty('defects')) return {
74903
+ defects: []
74904
+ };
74905
+ return obj;
74906
+ }
74907
+
74768
74908
  class SAProvider extends SkillProvider {
74769
74909
  static{
74770
74910
  this.description = '静态代码扫描';
@@ -74873,23 +75013,32 @@ class SAProvider extends SkillProvider {
74873
75013
  if (!await this.requestIsWhiteListUser()) {
74874
75014
  return false;
74875
75015
  }
74876
- // 确保路径存在
74877
- if (!await ensureFilePathExists(this.comateGoLanguageBinPath)) {
74878
- return false;
74879
- }
74880
- const fileExist = await checkFileExists(this.comateGoLanguageBinPath);
74881
- const needUpgrade = await this.checkVersion();
74882
- // bin存在且版本落后或者bin不存在就更新
74883
- // 更新失败退出
74884
- if (fileExist && needUpgrade || !fileExist) {
74885
- if (!await this.downloadComateLanBinPath()) {
74886
- return false;
75016
+ return true;
75017
+ }
75018
+ async getComicAICRConfig(aiCRParams) {
75019
+ try {
75020
+ const res = await axios.post('http://ai-coding.now.baidu-int.com/ai-coding/get-config/cr', aiCRParams, {
75021
+ timeout: 5 * 1000
75022
+ });
75023
+ if (res.status !== 200) {
75024
+ return undefined;
74887
75025
  }
75026
+ return res.data.data;
75027
+ } catch (e) {
75028
+ return undefined;
74888
75029
  }
74889
- return true;
74890
75030
  }
74891
- async getConfig(username) {
74892
- return this.requestAiCRConfig(username);
75031
+ async getConfig(username, params) {
75032
+ if (params === undefined || params.type === undefined || params.type !== 'AICR') {
75033
+ return this.requestAiCRConfig(username);
75034
+ } else {
75035
+ const module = await this.git.getModuleName();
75036
+ const aiCRParams = {
75037
+ userName: username,
75038
+ repo: module === 'unknown' ? params.repo : module
75039
+ };
75040
+ return this.getComicAICRConfig(aiCRParams);
75041
+ }
74893
75042
  }
74894
75043
  // eslint-disable-next-line
74895
75044
  async getScanResult(absolutePath) {
@@ -74899,18 +75048,9 @@ class SAProvider extends SkillProvider {
74899
75048
  diagnostics: []
74900
75049
  };
74901
75050
  }
74902
- if (getExtName(absolutePath) !== '.go' && getExtName(absolutePath) !== '.py') {
74903
- return {
74904
- absolutePath: '',
74905
- diagnostics: []
74906
- };
74907
- }
74908
- if (getExtName(absolutePath) === '.go' && !this.isInit) {
74909
- await this.init();
74910
- }
74911
75051
  // 切换到对应的文件所在的根目录
74912
75052
  const dir = path$6.dirname(absolutePath);
74913
- const oldWd = process.cwd();
75053
+ process.cwd();
74914
75054
  process.chdir(dir);
74915
75055
  const fileContent = (await readFile(absolutePath)).toString();
74916
75056
  const relativePath = path$6.relative(this.cwd, absolutePath);
@@ -74922,60 +75062,100 @@ class SAProvider extends SkillProvider {
74922
75062
  diagnostics: []
74923
75063
  };
74924
75064
  }
74925
- const moduleName = await this.git.getModuleName();
74926
- if (getExtName(absolutePath) === '.py' && await isNeedScanPythonFile(userInfo ? userInfo.name : 'unknown', moduleName)) {
74927
- return scanPyFile(absolutePath, changedLineNumbers);
74928
- } else if (getExtName(absolutePath) === '.py') {
75065
+ setToString(changedLineNumbers, (a, b)=>a - b);
75066
+ const wboxTaskID = await wboxScanTaskRegister(userInfo, "devaux-local-ai-cr", absolutePath, this.git);
75067
+ let isSuccess = true;
75068
+ try {
75069
+ const bosURL = await uploadDiffToBos(wboxTaskID, relativePath, absolutePath);
75070
+ if (!bosURL) {
75071
+ isSuccess = false;
75072
+ return {
75073
+ absolutePath: '',
75074
+ diagnostics: []
75075
+ };
75076
+ }
75077
+ const aiCRParam = await getPromptFromDevAuxServer(relativePath, bosURL, wboxTaskID, Array.from(changedLineNumbers));
75078
+ if (!aiCRParam) {
75079
+ isSuccess = false;
75080
+ return {
75081
+ absolutePath: '',
75082
+ diagnostics: []
75083
+ };
75084
+ }
75085
+ const modelResp = await getAICRResultFromModelWithConcurrency(aiCRParam, {
75086
+ maxRetries: 3
75087
+ }, 10);
75088
+ if (!modelResp) {
75089
+ isSuccess = false;
75090
+ return {
75091
+ absolutePath: '',
75092
+ diagnostics: []
75093
+ };
75094
+ }
75095
+ const diagnosticRes = [];
75096
+ for (const res of modelResp){
75097
+ try {
75098
+ const content = await cleanAndValidate(res.choices[0].message.content);
75099
+ for (const out of content.defects){
75100
+ const codeAalysisResultJsonObj = {
75101
+ uri: `file://${absolutePath}`,
75102
+ range: {
75103
+ start: {
75104
+ line: out.start_line,
75105
+ character: out.start_column
75106
+ },
75107
+ end: {
75108
+ line: out.start_line,
75109
+ character: 2
75110
+ }
75111
+ },
75112
+ message: out.message,
75113
+ errorSourceCode: await readLine(absolutePath, out.start_line),
75114
+ funcStr: ''
75115
+ };
75116
+ const diagnostic = CodeAnalysisResult.parse(codeAalysisResultJsonObj);
75117
+ diagnosticRes.push({
75118
+ range: {
75119
+ startLine: diagnostic.range.start.line,
75120
+ startCharacter: 1,
75121
+ endLine: diagnostic.range.end.line + 1,
75122
+ endCharacter: 1
75123
+ },
75124
+ textMessage: diagnostic.message,
75125
+ severity: 'WARNING',
75126
+ repairData: {
75127
+ source: 'SADiagnostic',
75128
+ pluginName: 'devaux',
75129
+ capability: 'SAProvider',
75130
+ query: '',
75131
+ data: diagnostic
75132
+ },
75133
+ sourceCode: diagnostic.errorSourceCode,
75134
+ contextCode: []
75135
+ });
75136
+ }
75137
+ } catch (e) {
75138
+ continue;
75139
+ }
75140
+ }
75141
+ await submitBug2Wbox(relativePath, diagnosticRes, wboxTaskID, userInfo ? userInfo.name : 'unknown');
74929
75142
  return {
74930
- absolutePath: '',
74931
- diagnostics: []
75143
+ absolutePath: absolutePath,
75144
+ diagnostics: diagnosticRes
74932
75145
  };
74933
- }
74934
- let changedLinesStr = setToString(changedLineNumbers, (a, b)=>a - b);
74935
- changedLinesStr = `{"change_lines": ${changedLinesStr}}`;
74936
- // eslint-disable-next-line
74937
- const checkResOutputObj = spawnSync$1(`${this.comateGoLanguageBinPath} check ${absolutePath} '${changedLinesStr}'`, {
74938
- shell: true
74939
- });
74940
- if (checkResOutputObj.status) {
74941
- process.chdir(oldWd);
75146
+ } catch (e) {
75147
+ isSuccess = false;
74942
75148
  return {
74943
- absolutePath: '',
75149
+ absolutePath: absolutePath,
74944
75150
  diagnostics: []
74945
75151
  };
75152
+ } finally{
75153
+ await wboxScanTaskCallBack({
75154
+ taskId: wboxTaskID ? wboxTaskID : 0,
75155
+ status: isSuccess ? 2 : 1,
75156
+ caller: userInfo ? userInfo.name : 'unknown'
75157
+ });
74946
75158
  }
74947
- const outputs = splitLines(checkResOutputObj.stdout.toString());
74948
- const diagnosticRes = [];
74949
- for (const out of outputs){
74950
- try {
74951
- const diagnostic = CodeAnalysisResult.parse(JSON.parse(out));
74952
- diagnosticRes.push({
74953
- range: {
74954
- startLine: diagnostic.range.start.line + 1,
74955
- startCharacter: diagnostic.range.start.character + 1,
74956
- endLine: diagnostic.range.end.line + 1,
74957
- endCharacter: diagnostic.range.end.character + 2
74958
- },
74959
- textMessage: diagnostic.message,
74960
- severity: 'WARNING',
74961
- repairData: {
74962
- source: 'SADiagnostic',
74963
- pluginName: 'devaux',
74964
- capability: 'SAProvider',
74965
- query: '',
74966
- data: diagnostic
74967
- },
74968
- sourceCode: diagnostic.errorSourceCode,
74969
- contextCode: []
74970
- });
74971
- } catch (err) {
74972
- continue;
74973
- }
74974
- }
74975
- return {
74976
- absolutePath: absolutePath,
74977
- diagnostics: diagnosticRes
74978
- };
74979
75159
  }
74980
75160
  async *execute() {
74981
75161
  try {
@@ -75149,7 +75329,7 @@ class SAProvider extends SkillProvider {
75149
75329
  yield stream.flushReplaceLast(/*#__PURE__*/ jsx("loading", {
75150
75330
  children: "没有检测到当前目录代码仓Clone完毕,正在加载中,请稍候。。。。。。"
75151
75331
  }));
75152
- await sleep(1 * 1000);
75332
+ await sleep$1(1 * 1000);
75153
75333
  }
75154
75334
  clearTimeout(timer);
75155
75335
  if (!isOK) {