@customize-agent/knowledge 4.0.24 → 4.0.26

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.
@@ -62,7 +62,7 @@ export class MultiProjectManager {
62
62
  }
63
63
  async search(projectRoot, query, options = {}) {
64
64
  const limit = options.limit ?? 10;
65
- const scope = options.scope ?? 'all';
65
+ const scope = options.scope ?? 'project';
66
66
  const project = await this.getProject(projectRoot);
67
67
  await this.ensureFreshForSearch(projectRoot, project);
68
68
  if (scope === 'project')
@@ -83,7 +83,7 @@ export class MultiProjectManager {
83
83
  };
84
84
  }
85
85
  async semanticSearch(projectRoot, query, options = {}) {
86
- const scope = options.scope ?? 'all';
86
+ const scope = options.scope ?? 'project';
87
87
  const project = await this.getProject(projectRoot);
88
88
  await this.ensureFreshForSearch(projectRoot, project);
89
89
  if (scope === 'project') {
@@ -38,6 +38,7 @@ export declare class TesseractJsProvider implements OcrProvider {
38
38
  private _available;
39
39
  private worker;
40
40
  private workerPromise;
41
+ private workerLock;
41
42
  private warnings;
42
43
  get available(): boolean;
43
44
  recognize(input: {
@@ -11,7 +11,11 @@ import { fileURLToPath } from 'node:url';
11
11
  import { resolveAndImport, resolvePackage } from './module-resolver.js';
12
12
  // ─── 路径工具 ───────────────────────────────────────────────────
13
13
  const knowledgeDir = path.dirname(fileURLToPath(import.meta.url));
14
- const OCR_NATIVE_NOISE_PATTERNS = [/^Image too small to scale!!/u, /^Line cannot be recognized!!$/u];
14
+ const OCR_NATIVE_NOISE_PATTERNS = [
15
+ /Image too small to scale/u,
16
+ /Line cannot be recognized/u,
17
+ /empty image/iu
18
+ ];
15
19
  const OCR_NOISE_SUPPRESSION_KEY = Symbol.for('customize-agent.ocr-noise-suppression');
16
20
  function ocrNoiseSuppressionState() {
17
21
  const globalState = globalThis;
@@ -30,8 +34,7 @@ function isNativeOcrNoise(chunk) {
30
34
  const text = Buffer.isBuffer(chunk) ? chunk.toString('utf8') : chunk instanceof Uint8Array ? Buffer.from(chunk).toString('utf8') : typeof chunk === 'string' ? chunk : '';
31
35
  if (!text)
32
36
  return false;
33
- const lines = text.split(/\r?\n/u).map(line => line.trim()).filter(Boolean);
34
- return lines.length > 0 && lines.every(line => OCR_NATIVE_NOISE_PATTERNS.some(pattern => pattern.test(line)));
37
+ return OCR_NATIVE_NOISE_PATTERNS.some(pattern => pattern.test(text));
35
38
  }
36
39
  async function suppressNativeOcrNoise(operation) {
37
40
  const state = ocrNoiseSuppressionState();
@@ -64,12 +67,48 @@ async function suppressNativeOcrNoise(operation) {
64
67
  }
65
68
  }
66
69
  }
67
- // ─── Tesseract.js Provider(主 OCR 引擎,跨平台) ──────────────
70
+ // 临时屏蔽 Tesseract 底层 WASM 污染日志
71
+ function withSilencedConsole(fn) {
72
+ const originalLog = console.log;
73
+ const originalWarn = console.warn;
74
+ const originalError = console.error;
75
+ const filter = (orig) => (...args) => {
76
+ const msg = String(args[0] || '');
77
+ if (msg.includes('Line cannot be recognized') || msg.includes('Image too small to scale')) {
78
+ return;
79
+ }
80
+ orig(...args);
81
+ };
82
+ console.log = filter(originalLog);
83
+ console.warn = filter(originalWarn);
84
+ console.error = filter(originalError);
85
+ try {
86
+ const result = fn();
87
+ if (result instanceof Promise) {
88
+ return result.finally(() => {
89
+ console.log = originalLog;
90
+ console.warn = originalWarn;
91
+ console.error = originalError;
92
+ });
93
+ }
94
+ console.log = originalLog;
95
+ console.warn = originalWarn;
96
+ console.error = originalError;
97
+ return result;
98
+ }
99
+ catch (error) {
100
+ console.log = originalLog;
101
+ console.warn = originalWarn;
102
+ console.error = originalError;
103
+ throw error;
104
+ }
105
+ }
68
106
  export class TesseractJsProvider {
69
107
  id = 'tesseract.js';
70
108
  _available = null;
71
109
  worker = null;
72
110
  workerPromise = null;
111
+ workerLock = Promise.resolve();
73
112
  warnings = [];
74
113
  get available() {
75
114
  if (this._available !== null)
@@ -115,8 +154,19 @@ export class TesseractJsProvider {
115
154
  return { text: '', confidence: 0, regions: [], warnings: [`image too small for OCR: ${width}x${height}`] };
116
155
  }
117
156
  try {
118
- const worker = await this.getWorker();
119
- const result = await suppressNativeOcrNoise(() => worker.recognize(pngPath));
157
+ const worker = await withSilencedConsole(() => this.getWorker());
158
+ let unlock;
159
+ const nextLock = new Promise(resolve => { unlock = resolve; });
160
+ const currentLock = this.workerLock;
161
+ this.workerLock = currentLock.then(() => nextLock).catch(() => nextLock);
162
+ await currentLock;
163
+ let result;
164
+ try {
165
+ result = await withSilencedConsole(() => suppressNativeOcrNoise(() => worker.recognize(pngPath)));
166
+ }
167
+ finally {
168
+ unlock();
169
+ }
120
170
  const text = (result.data.text ?? '').trim();
121
171
  const lines = (result.data.lines ?? []);
122
172
  const regions = lines
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@customize-agent/knowledge",
3
- "version": "4.0.24",
3
+ "version": "4.0.26",
4
4
  "description": "Local knowledge base infrastructure for customize-agent",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",