grepmax 0.7.41 → 0.7.43
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.
|
@@ -47,14 +47,12 @@ exports.startWatcher = startWatcher;
|
|
|
47
47
|
const fs = __importStar(require("node:fs"));
|
|
48
48
|
const path = __importStar(require("node:path"));
|
|
49
49
|
const chokidar_1 = require("chokidar");
|
|
50
|
-
const filter_builder_1 = require("../utils/filter-builder");
|
|
51
50
|
const config_1 = require("../../config");
|
|
52
51
|
const cache_check_1 = require("../utils/cache-check");
|
|
53
52
|
const file_utils_1 = require("../utils/file-utils");
|
|
54
53
|
const logger_1 = require("../utils/logger");
|
|
55
54
|
const lock_1 = require("../utils/lock");
|
|
56
55
|
const pool_1 = require("../workers/pool");
|
|
57
|
-
const llm_client_1 = require("../workers/summarize/llm-client");
|
|
58
56
|
const watcher_batch_1 = require("./watcher-batch");
|
|
59
57
|
// Chokidar ignored — must exclude heavy directories to keep FD count low.
|
|
60
58
|
// On macOS, chokidar uses FSEvents (single FD) but falls back to fs.watch()
|
|
@@ -87,19 +85,16 @@ function startWatcher(opts) {
|
|
|
87
85
|
let closed = false;
|
|
88
86
|
let consecutiveLockFailures = 0;
|
|
89
87
|
let currentBatchAc = null;
|
|
90
|
-
let summarizationAc = null;
|
|
91
88
|
const MAX_RETRIES = 5;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
usePolling: true,
|
|
100
|
-
|
|
101
|
-
binaryInterval: 10000,
|
|
102
|
-
});
|
|
89
|
+
// macOS: FSEvents is a single-FD kernel API — no EMFILE risk and no polling.
|
|
90
|
+
// Linux: inotify is event-driven but uses one FD per watch; fall back to
|
|
91
|
+
// polling for monorepos to avoid hitting ulimit.
|
|
92
|
+
// Override with GMAX_WATCH_POLL=1 to force polling on any platform.
|
|
93
|
+
const forcePoll = process.env.GMAX_WATCH_POLL === "1";
|
|
94
|
+
const usePoll = forcePoll || process.platform !== "darwin";
|
|
95
|
+
const watcher = (0, chokidar_1.watch)(projectRoot, Object.assign({ ignored: exports.WATCHER_IGNORE_PATTERNS, ignoreInitial: true, persistent: true }, (usePoll
|
|
96
|
+
? { usePolling: true, interval: 5000, binaryInterval: 10000 }
|
|
97
|
+
: {})));
|
|
103
98
|
watcher.on("error", (err) => {
|
|
104
99
|
console.error(`[${wtag}] Watcher error:`, err);
|
|
105
100
|
});
|
|
@@ -130,7 +125,6 @@ function startWatcher(opts) {
|
|
|
130
125
|
(0, logger_1.log)(wtag, `Processing ${batch.size} changed files: ${filenames.join(", ")}`);
|
|
131
126
|
const start = Date.now();
|
|
132
127
|
let reindexed = 0;
|
|
133
|
-
const changedIds = [];
|
|
134
128
|
try {
|
|
135
129
|
const lock = yield (0, lock_1.acquireWriterLockWithRetry)(dataDir, {
|
|
136
130
|
maxRetries: 3,
|
|
@@ -184,10 +178,6 @@ function startWatcher(opts) {
|
|
|
184
178
|
deletes.push(absPath);
|
|
185
179
|
if (result.vectors.length > 0) {
|
|
186
180
|
vectors.push(...result.vectors);
|
|
187
|
-
// Track IDs of new vectors for summarization
|
|
188
|
-
for (const v of result.vectors) {
|
|
189
|
-
changedIds.push(v.id);
|
|
190
|
-
}
|
|
191
181
|
}
|
|
192
182
|
metaUpdates.set(absPath, metaEntry);
|
|
193
183
|
reindexed++;
|
|
@@ -274,48 +264,6 @@ function startWatcher(opts) {
|
|
|
274
264
|
scheduleBatch();
|
|
275
265
|
}
|
|
276
266
|
}
|
|
277
|
-
// Cancel previous summarization before starting a new one
|
|
278
|
-
summarizationAc === null || summarizationAc === void 0 ? void 0 : summarizationAc.abort();
|
|
279
|
-
summarizationAc = new AbortController();
|
|
280
|
-
const sumSignal = summarizationAc.signal;
|
|
281
|
-
if (changedIds.length > 0) {
|
|
282
|
-
(() => __awaiter(this, void 0, void 0, function* () {
|
|
283
|
-
try {
|
|
284
|
-
const table = yield vectorDb.ensureTable();
|
|
285
|
-
for (const id of changedIds) {
|
|
286
|
-
if (sumSignal.aborted)
|
|
287
|
-
break;
|
|
288
|
-
const escaped = (0, filter_builder_1.escapeSqlString)(id);
|
|
289
|
-
const rows = yield table
|
|
290
|
-
.query()
|
|
291
|
-
.select(["id", "path", "content"])
|
|
292
|
-
.where(`id = '${escaped}'`)
|
|
293
|
-
.limit(1)
|
|
294
|
-
.toArray();
|
|
295
|
-
if (rows.length === 0)
|
|
296
|
-
continue;
|
|
297
|
-
const r = rows[0];
|
|
298
|
-
const lang = path.extname(String(r.path || "")).replace(/^\./, "") ||
|
|
299
|
-
"unknown";
|
|
300
|
-
const summaries = yield (0, llm_client_1.summarizeChunks)([
|
|
301
|
-
{
|
|
302
|
-
code: String(r.content || ""),
|
|
303
|
-
language: lang,
|
|
304
|
-
file: String(r.path || ""),
|
|
305
|
-
},
|
|
306
|
-
]);
|
|
307
|
-
if (sumSignal.aborted)
|
|
308
|
-
break;
|
|
309
|
-
if (summaries === null || summaries === void 0 ? void 0 : summaries[0]) {
|
|
310
|
-
yield vectorDb.updateRows([id], "summary", [summaries[0]]);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
catch (_a) {
|
|
315
|
-
// Summarizer unavailable or aborted — skip
|
|
316
|
-
}
|
|
317
|
-
}))();
|
|
318
|
-
}
|
|
319
267
|
});
|
|
320
268
|
const onFileEvent = (event, absPath) => {
|
|
321
269
|
if (closed)
|
|
@@ -348,7 +296,6 @@ function startWatcher(opts) {
|
|
|
348
296
|
close: () => __awaiter(this, void 0, void 0, function* () {
|
|
349
297
|
closed = true;
|
|
350
298
|
currentBatchAc === null || currentBatchAc === void 0 ? void 0 : currentBatchAc.abort();
|
|
351
|
-
summarizationAc === null || summarizationAc === void 0 ? void 0 : summarizationAc.abort();
|
|
352
299
|
if (debounceTimer)
|
|
353
300
|
clearTimeout(debounceTimer);
|
|
354
301
|
clearInterval(ftsInterval);
|
|
@@ -4,5 +4,8 @@ exports.isFileCached = isFileCached;
|
|
|
4
4
|
function isFileCached(cached, stats) {
|
|
5
5
|
if (!cached)
|
|
6
6
|
return false;
|
|
7
|
-
|
|
7
|
+
// Truncate to millisecond — APFS returns sub-ms precision that can
|
|
8
|
+
// differ across stat calls or serialization round-trips.
|
|
9
|
+
return (Math.trunc(cached.mtimeMs) === Math.trunc(stats.mtimeMs) &&
|
|
10
|
+
cached.size === stats.size);
|
|
8
11
|
}
|
package/package.json
CHANGED