@customize-agent/knowledge 4.3.0 → 4.3.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.
@@ -324,7 +324,11 @@ export function cleanExtractedText(input) {
324
324
  return { text: input.text, removedChars: 0, removedLines: 0, stats: zeroStats() };
325
325
  const docKind = detectDocKind(input.fileName || '', input.text.slice(0, 4000));
326
326
  const isCad = input.category === 'cad' || input.category === 'diagram';
327
- const lines = input.text.split(/\r?\n/u);
327
+ // CAD 控制码还原前置:确定性无损替换(%%U/%%O 格式开关删除、%%%→%),
328
+ // 不参与行级启发式删除与 30% 回退保护——纯图纸文件(标高/图元行占比高)常触发
329
+ // 回退保护使整个清洗作废,控制码还原若挂在行级规则里会随之失效
330
+ const sourceText = isCad ? cleanCadControlCodes(input.text) : input.text;
331
+ const lines = sourceText.split(/\r?\n/u);
328
332
  const totalLines = lines.length;
329
333
  // 全文高重复行统计(页眉/页脚/图框标题栏判定依据)
330
334
  const lineCounts = new Map();
@@ -451,10 +455,7 @@ export function cleanExtractedText(input) {
451
455
  index += 1;
452
456
  continue;
453
457
  }
454
- // 11. 图纸:CAD 文本格式控制码还原(%%U/%%O 格式开关删除、%%D/%%P/%%C 符号映射、
455
- // %%% 百分号转义「95%%%」→「95%」;还原后行保留,仅替换字符)
456
- const keptLine = isCad && CAD_CONTROL_CODE_RE.test(line) ? cleanCadControlCodes(line) : line;
457
- kept.push(keptLine);
458
+ kept.push(line);
458
459
  index += 1;
459
460
  }
460
461
  const resultText = kept.join('\n');
@@ -462,13 +463,14 @@ export function cleanExtractedText(input) {
462
463
  // 1) 行级启发式删除导致剩余不足原文 30% → 判定误伤,回退原文;
463
464
  // 2) K2 章节级删除(标题 + 规模/内容 + 边界三重证据)置信度高,不参与 30% 判定,
464
465
  // 否则通用条款占比高的合同文件永远洗不掉;但剩余不足原文 10% 时仍整体回退(防极端全删)
465
- const totalChars = input.text.trim().length;
466
+ // 回退时返回 sourceText(已做 CAD 控制码还原),保证确定性还原在回退路径同样生效
467
+ const totalChars = sourceText.trim().length;
466
468
  const remainingRatio = totalChars > 0 ? resultText.trim().length / totalChars : 1;
467
469
  const lineLevelRemovedChars = removedChars - sectionRemovedChars;
468
470
  const lineLevelSafe = lineLevelRemovedChars === 0 || remainingRatio >= 0.3;
469
471
  const extremeSafe = remainingRatio >= 0.1;
470
472
  if (removedChars > 0 && totalChars > 2000 && (!lineLevelSafe || !extremeSafe)) {
471
- return { text: input.text, removedChars: 0, removedLines: 0, stats: zeroStats() };
473
+ return { text: sourceText, removedChars: 0, removedLines: 0, stats: zeroStats() };
472
474
  }
473
475
  return { text: resultText, removedChars, removedLines, stats };
474
476
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@customize-agent/knowledge",
3
- "version": "4.3.0",
3
+ "version": "4.3.1",
4
4
  "description": "Local knowledge base infrastructure for customize-agent",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",