The best way to control Claude Code, Codex and more from any computer or phone

main
patch 651 lines 24 KB
Raw
1 diff --git a/dist/fff-api.d.ts b/dist/fff-api.d.ts
2 index 0f90eedca20655ccd30b8f28e433b2094341fbdf..c2ef86927d6e3ab0e8584330fa0ac3fdacc06cf5 100644
3 --- a/dist/fff-api.d.ts
4 +++ b/dist/fff-api.d.ts
5 @@ -199,7 +199,7 @@ export type Location = {
6 export interface SearchResult {
7 /** Matched file items */
8 items: FileItem[];
9 - /** Corresponding scores for each item */
10 + /** Corresponding scores for each item. Empty when the page has more than 200 items (patched in T3 Code to skip per-item score FFI calls). */
11 scores: Score[];
12 /** Total number of files that matched */
13 totalMatched: number;
14 @@ -238,7 +238,7 @@ export interface DirSearchOptions {
15 export interface DirSearchResult {
16 /** Matched directory items */
17 items: DirItem[];
18 - /** Corresponding scores for each item */
19 + /** Corresponding scores for each item. Empty when the page has more than 200 items (patched in T3 Code to skip per-item score FFI calls). */
20 scores: Score[];
21 /** Total number of directories that matched */
22 totalMatched: number;
23 @@ -262,7 +262,7 @@ export type MixedItem = {
24 export interface MixedSearchResult {
25 /** Matched items (files and directories interleaved by score) */
26 items: MixedItem[];
27 - /** Corresponding scores for each item */
28 + /** Corresponding scores for each item. Empty when the page has more than 200 items (patched in T3 Code to skip per-item score FFI calls). */
29 scores: Score[];
30 /** Total number of items (files + dirs) that matched */
31 totalMatched: number;
32 diff --git a/dist/finder.d.ts b/dist/finder.d.ts
33 index 452102d720cc19b0560cfc9e2f1a320687047c92..704b52c3d076c50c3bf15e96a574385c9862670c 100644
34 --- a/dist/finder.d.ts
35 +++ b/dist/finder.d.ts
36 @@ -242,6 +242,18 @@ export declare class FileFinder implements FileFinderApi {
37 * background watcher might have missed.
38 */
39 scanFiles(): Result<void>;
40 + /**
41 + * Trigger a rescan without blocking the JS thread. Patched in T3 Code.
42 + */
43 + scanFilesAsync(): Promise<Result<void>>;
44 + /** `fileSearch` without blocking the JS thread. Patched in T3 Code. */
45 + fileSearchAsync(query: string, options?: SearchOptions): Promise<Result<SearchResult>>;
46 + /** `directorySearch` without blocking the JS thread. Patched in T3 Code. */
47 + directorySearchAsync(query: string, options?: DirSearchOptions): Promise<Result<DirSearchResult>>;
48 + /** `mixedSearch` without blocking the JS thread. Patched in T3 Code. */
49 + mixedSearchAsync(query: string, options?: SearchOptions): Promise<Result<MixedSearchResult>>;
50 + /** `grep` without blocking the JS thread. Patched in T3 Code. */
51 + grepAsync(query: string, options?: GrepOptions): Promise<Result<GrepResult>>;
52 /**
53 * Check if a scan is currently in progress.
54 */
55 @@ -254,6 +266,10 @@ export declare class FileFinder implements FileFinderApi {
56 * Get the current scan progress.
57 */
58 getScanProgress(): Result<ScanProgress>;
59 + /**
60 + * Read scan progress without blocking the JS thread. Patched in T3 Code.
61 + */
62 + getScanProgressAsync(): Promise<Result<ScanProgress>>;
63 /**
64 * Wait for the initial file scan to complete.
65 * Non-blocking: polls `isScanning` and yields to the event loop between checks.
66 @@ -360,6 +376,8 @@ export declare class FileFinder implements FileFinderApi {
67 */
68 watch(callback: WatchBatchCallback, options?: WatchOptions): Result<WatchUnsubscribe>;
69 watch(pattern: string, callback: WatchBatchCallback, options?: WatchOptions): Result<WatchUnsubscribe>;
70 + /** `watch(callback)` without blocking the JS thread. Patched in T3 Code. */
71 + watchAsync(callback: WatchBatchCallback, options?: WatchOptions): Promise<Result<WatchUnsubscribe>>;
72 /**
73 * Get health check information.
74 *
75 diff --git a/dist/index.js b/dist/index.js
76 index 7c1d722eabc8d8eb98998eb48c5fe9d70b749d10..69bfa2cc9023103f52cc469bbec917eab68fa806 100644
77 --- a/dist/index.js
78 +++ b/dist/index.js
79 @@ -1,7 +1,7 @@
80 // src/binary.ts
81 import { existsSync, readFileSync } from "fs";
82 import { createRequire } from "module";
83 -import { dirname, join } from "path";
84 +import { dirname, join, sep } from "path";
85 import { fileURLToPath } from "url";
86
87 // src/platform.ts
88 @@ -120,6 +120,16 @@ function getPackageDir() {
89 function binaryExists() {
90 return findBinary() !== null;
91 }
92 +function resolveUnpackedAsarPath(binaryPath) {
93 + const pathSegments = binaryPath.split(sep);
94 + const asarIndex = pathSegments.findLastIndex((segment) => segment.endsWith(".asar"));
95 + if (asarIndex === -1) {
96 + return binaryPath;
97 + }
98 + pathSegments[asarIndex] = `${pathSegments[asarIndex]}.unpacked`;
99 + const unpackedPath = pathSegments.join(sep);
100 + return existsSync(unpackedPath) ? unpackedPath : binaryPath;
101 +}
102 function resolveFromNpmPackage() {
103 const packageName = getNpmPackageName();
104 try {
105 @@ -128,7 +138,7 @@ function resolveFromNpmPackage() {
106 const packageDir = dirname(packageJsonPath);
107 const binaryPath = join(packageDir, getLibFilename());
108 if (existsSync(binaryPath)) {
109 - return binaryPath;
110 + return resolveUnpackedAsarPath(binaryPath);
111 }
112 } catch {
113 }
114 @@ -262,6 +272,7 @@ function snakeToCamel(obj) {
115 return result;
116 }
117 function readCString(ptr) {
118 + if (typeof ptr === "string") return ptr;
119 if (isNullPointer(ptr)) return null;
120 try {
121 const [str] = restorePointer({
122 @@ -303,6 +314,26 @@ function freeResult(resultPtr) {
123 function readResultEnvelope(funcName, paramsType, paramsValue) {
124 loadLibrary();
125 const { rawPtr, struct: structData } = callRaw(funcName, paramsType, paramsValue);
126 + return envelopeFromRaw(rawPtr, structData);
127 +}
128 +async function readResultEnvelopeOnNativeThread(funcName, paramsType, paramsValue) {
129 + loadLibrary();
130 + const rawPtr = await load({
131 + library: LIBRARY_KEY,
132 + funcName,
133 + retType: DataType.External,
134 + paramsType,
135 + paramsValue,
136 + freeResultMemory: false,
137 + runInNewThread: true
138 + });
139 + const [structData] = restorePointer({
140 + retType: [FFF_RESULT_STRUCT],
141 + paramsValue: wrapPointer([rawPtr])
142 + });
143 + return envelopeFromRaw(rawPtr, structData);
144 +}
145 +function envelopeFromRaw(rawPtr, structData) {
146 if (structData.success === 0) {
147 const errorStr = readCString(structData.error);
148 freeResult(rawPtr);
149 @@ -311,13 +342,17 @@ function readResultEnvelope(funcName, paramsType, paramsValue) {
150 return { rawPtr, struct: structData };
151 }
152 function callVoidResult(funcName, paramsType, paramsValue) {
153 - const res = readResultEnvelope(funcName, paramsType, paramsValue);
154 + return voidResultFromEnvelope(readResultEnvelope(funcName, paramsType, paramsValue));
155 +}
156 +function voidResultFromEnvelope(res) {
157 if ("ok" in res) return res;
158 freeResult(res.rawPtr);
159 return { ok: true, value: void 0 };
160 }
161 function callIntResult(funcName, paramsType, paramsValue) {
162 - const res = readResultEnvelope(funcName, paramsType, paramsValue);
163 + return intResultFromEnvelope(readResultEnvelope(funcName, paramsType, paramsValue));
164 +}
165 +function intResultFromEnvelope(res) {
166 if ("ok" in res) return res;
167 const value = Number(res.struct.int_value);
168 freeResult(res.rawPtr);
169 @@ -417,18 +452,20 @@ function ffiCreate(basePath, frecencyDbPath, historyDbPath, _useUnsafeNoLock, en
170 }
171 function ffiDestroy(handle) {
172 loadLibrary();
173 - load({
174 + return load({
175 library: LIBRARY_KEY,
176 funcName: "fff_destroy",
177 retType: DataType.Void,
178 paramsType: [DataType.External],
179 - paramsValue: [handle]
180 + paramsValue: [handle],
181 + runInNewThread: true
182 + }).catch(() => {
183 });
184 }
185 var FFF_FILE_ITEM_STRUCT = {
186 - relative_path: DataType.External,
187 - file_name: DataType.External,
188 - git_status: DataType.External,
189 + relative_path: DataType.String,
190 + file_name: DataType.String,
191 + git_status: DataType.String,
192 size: DataType.U64,
193 modified: DataType.U64,
194 access_frecency_score: DataType.I64,
195 @@ -445,8 +482,9 @@ var FFF_SCORE_STRUCT = {
196 distance_penalty: DataType.I32,
197 current_file_penalty: DataType.I32,
198 combo_match_boost: DataType.I32,
199 + path_alignment_bonus: DataType.I32,
200 exact_match: DataType.U8,
201 - match_type: DataType.External
202 + match_type: DataType.String
203 };
204 var FFF_SEARCH_RESULT_STRUCT = {
205 items: DataType.External,
206 @@ -462,8 +500,8 @@ var FFF_SEARCH_RESULT_STRUCT = {
207 location_end_col: DataType.I32
208 };
209 var FFF_DIR_ITEM_STRUCT = {
210 - relative_path: DataType.External,
211 - dir_name: DataType.External,
212 + relative_path: DataType.String,
213 + dir_name: DataType.String,
214 max_access_frecency: DataType.I32
215 };
216 var FFF_DIR_SEARCH_RESULT_STRUCT = {
217 @@ -475,9 +513,9 @@ var FFF_DIR_SEARCH_RESULT_STRUCT = {
218 };
219 var FFF_MIXED_ITEM_STRUCT = {
220 item_type: DataType.U8,
221 - relative_path: DataType.External,
222 - display_name: DataType.External,
223 - git_status: DataType.External,
224 + relative_path: DataType.String,
225 + display_name: DataType.String,
226 + git_status: DataType.String,
227 size: DataType.U64,
228 modified: DataType.U64,
229 access_frecency_score: DataType.I64,
230 @@ -500,10 +538,10 @@ var FFF_MIXED_SEARCH_RESULT_STRUCT = {
231 location_end_col: DataType.I32
232 };
233 var FFF_GREP_MATCH_STRUCT = {
234 - relative_path: DataType.External,
235 - file_name: DataType.External,
236 - git_status: DataType.External,
237 - line_content: DataType.External,
238 + relative_path: DataType.String,
239 + file_name: DataType.String,
240 + git_status: DataType.String,
241 + line_content: DataType.String,
242 match_ranges: DataType.External,
243 context_before: DataType.External,
244 context_after: DataType.External,
245 @@ -598,18 +636,13 @@ function readMixedItemFromRaw(raw) {
246 }
247 function callAccessor(funcName, resultPtr, index, structDef) {
248 loadLibrary();
249 - const elemPtr = load({
250 + return load({
251 library: LIBRARY_KEY,
252 funcName,
253 - retType: DataType.External,
254 + retType: structDef,
255 paramsType: [DataType.External, DataType.U32],
256 paramsValue: [resultPtr, index]
257 });
258 - const [raw] = restorePointer({
259 - retType: [structDef],
260 - paramsValue: wrapPointer([elemPtr])
261 - });
262 - return raw;
263 }
264 function ptrOffset(base, bytes) {
265 return load({
266 @@ -766,6 +799,7 @@ function parseSearchResult(rawPtr) {
267 }
268 const items = [];
269 const scores = [];
270 + const includeScores = count <= 200;
271 for (let i = 0; i < count; i++) {
272 const rawItem = callAccessor(
273 "fff_search_result_get_item",
274 @@ -774,13 +808,15 @@ function parseSearchResult(rawPtr) {
275 FFF_FILE_ITEM_STRUCT
276 );
277 items.push(readFileItemFromRaw(rawItem));
278 - const rawScore = callAccessor(
279 - "fff_search_result_get_score",
280 - handlePtr,
281 - i,
282 - FFF_SCORE_STRUCT
283 - );
284 - scores.push(readScoreFromRaw(rawScore));
285 + if (includeScores) {
286 + const rawScore = callAccessor(
287 + "fff_search_result_get_score",
288 + handlePtr,
289 + i,
290 + FFF_SCORE_STRUCT
291 + );
292 + scores.push(readScoreFromRaw(rawScore));
293 + }
294 }
295 load({
296 library: LIBRARY_KEY,
297 @@ -824,6 +860,7 @@ function parseDirSearchResult(rawPtr) {
298 const count = sr.count;
299 const items = [];
300 const scores = [];
301 + const includeScores = count <= 200;
302 for (let i = 0; i < count; i++) {
303 const rawItem = callAccessor(
304 "fff_dir_search_result_get_item",
305 @@ -832,13 +869,15 @@ function parseDirSearchResult(rawPtr) {
306 FFF_DIR_ITEM_STRUCT
307 );
308 items.push(readDirItemFromRaw(rawItem));
309 - const rawScore = callAccessor(
310 - "fff_dir_search_result_get_score",
311 - handlePtr,
312 - i,
313 - FFF_SCORE_STRUCT
314 - );
315 - scores.push(readScoreFromRaw(rawScore));
316 + if (includeScores) {
317 + const rawScore = callAccessor(
318 + "fff_dir_search_result_get_score",
319 + handlePtr,
320 + i,
321 + FFF_SCORE_STRUCT
322 + );
323 + scores.push(readScoreFromRaw(rawScore));
324 + }
325 }
326 load({
327 library: LIBRARY_KEY,
328 @@ -897,6 +936,7 @@ function parseMixedSearchResult(rawPtr) {
329 }
330 const items = [];
331 const scores = [];
332 + const includeScores = count <= 200;
333 for (let i = 0; i < count; i++) {
334 const rawItem = callAccessor(
335 "fff_mixed_search_result_get_item",
336 @@ -905,13 +945,15 @@ function parseMixedSearchResult(rawPtr) {
337 FFF_MIXED_ITEM_STRUCT
338 );
339 items.push(readMixedItemFromRaw(rawItem));
340 - const rawScore = callAccessor(
341 - "fff_mixed_search_result_get_score",
342 - handlePtr,
343 - i,
344 - FFF_SCORE_STRUCT
345 - );
346 - scores.push(readScoreFromRaw(rawScore));
347 + if (includeScores) {
348 + const rawScore = callAccessor(
349 + "fff_mixed_search_result_get_score",
350 + handlePtr,
351 + i,
352 + FFF_SCORE_STRUCT
353 + );
354 + scores.push(readScoreFromRaw(rawScore));
355 + }
356 }
357 load({
358 library: LIBRARY_KEY,
359 @@ -932,7 +974,7 @@ function parseMixedSearchResult(rawPtr) {
360 }
361 return { ok: true, value: result };
362 }
363 -function ffiSearch(handle, query, currentFile, maxThreads, pageIndex, pageSize, comboBoostMultiplier, minComboCount) {
364 +function ffiSearch(handle, query, currentFile, maxThreads, pageIndex, pageSize, comboBoostMultiplier, minComboCount, onNativeThread = false) {
365 loadLibrary();
366 const rawPtr = load({
367 library: LIBRARY_KEY,
368 @@ -966,9 +1008,10 @@ function ffiSearch(handle, query, currentFile, maxThreads, pageIndex, pageSize,
369 comboBoostMultiplier,
370 minComboCount
371 ],
372 - freeResultMemory: false
373 + freeResultMemory: false,
374 + runInNewThread: onNativeThread
375 });
376 - return parseSearchResult(rawPtr);
377 + return onNativeThread ? rawPtr.then(parseSearchResult) : parseSearchResult(rawPtr);
378 }
379 function ffiGlob(handle, pattern, currentFile, maxThreads, pageIndex, pageSize) {
380 loadLibrary();
381 @@ -995,7 +1038,7 @@ function ffiGlob(handle, pattern, currentFile, maxThreads, pageIndex, pageSize)
382 });
383 return parseSearchResult(rawPtr);
384 }
385 -function ffiSearchDirectories(handle, query, currentFile, maxThreads, pageIndex, pageSize) {
386 +function ffiSearchDirectories(handle, query, currentFile, maxThreads, pageIndex, pageSize, onNativeThread = false) {
387 loadLibrary();
388 const rawPtr = load({
389 library: LIBRARY_KEY,
390 @@ -1016,11 +1059,12 @@ function ffiSearchDirectories(handle, query, currentFile, maxThreads, pageIndex,
391 // page_size
392 ],
393 paramsValue: [handle, query, currentFile ?? "", maxThreads, pageIndex, pageSize],
394 - freeResultMemory: false
395 + freeResultMemory: false,
396 + runInNewThread: onNativeThread
397 });
398 - return parseDirSearchResult(rawPtr);
399 + return onNativeThread ? rawPtr.then(parseDirSearchResult) : parseDirSearchResult(rawPtr);
400 }
401 -function ffiSearchMixed(handle, query, currentFile, maxThreads, pageIndex, pageSize, comboBoostMultiplier, minComboCount) {
402 +function ffiSearchMixed(handle, query, currentFile, maxThreads, pageIndex, pageSize, comboBoostMultiplier, minComboCount, onNativeThread = false) {
403 loadLibrary();
404 const rawPtr = load({
405 library: LIBRARY_KEY,
406 @@ -1054,11 +1098,12 @@ function ffiSearchMixed(handle, query, currentFile, maxThreads, pageIndex, pageS
407 comboBoostMultiplier,
408 minComboCount
409 ],
410 - freeResultMemory: false
411 + freeResultMemory: false,
412 + runInNewThread: onNativeThread
413 });
414 - return parseMixedSearchResult(rawPtr);
415 + return onNativeThread ? rawPtr.then(parseMixedSearchResult) : parseMixedSearchResult(rawPtr);
416 }
417 -function ffiLiveGrep(handle, query, mode, maxFileSize, maxMatchesPerFile, smartCase, fileOffset, pageLimit, timeBudgetMs, enforceTimeBudget, beforeContext, afterContext, classifyDefinitions) {
418 +function ffiLiveGrep(handle, query, mode, maxFileSize, maxMatchesPerFile, smartCase, fileOffset, pageLimit, timeBudgetMs, enforceTimeBudget, beforeContext, afterContext, classifyDefinitions, onNativeThread = false) {
419 loadLibrary();
420 const rawPtr = load({
421 library: LIBRARY_KEY,
422 @@ -1107,9 +1152,10 @@ function ffiLiveGrep(handle, query, mode, maxFileSize, maxMatchesPerFile, smartC
423 afterContext,
424 classifyDefinitions
425 ],
426 - freeResultMemory: false
427 + freeResultMemory: false,
428 + runInNewThread: onNativeThread
429 });
430 - return parseGrepResult(rawPtr);
431 + return onNativeThread ? rawPtr.then(parseGrepResult) : parseGrepResult(rawPtr);
432 }
433 function ffiMultiGrep(handle, patternsJoined, constraints, maxFileSize, maxMatchesPerFile, smartCase, fileOffset, pageLimit, timeBudgetMs, enforceTimeBudget, beforeContext, afterContext, classifyDefinitions) {
434 loadLibrary();
435 @@ -1188,7 +1234,11 @@ var FFF_SCAN_PROGRESS_STRUCT = {
436 };
437 function ffiGetScanProgress(handle) {
438 loadLibrary();
439 - const res = readResultEnvelope("fff_get_scan_progress", [DataType.External], [handle]);
440 + return scanProgressFromEnvelope(
441 + readResultEnvelope("fff_get_scan_progress", [DataType.External], [handle])
442 + );
443 +}
444 +function scanProgressFromEnvelope(res) {
445 if ("ok" in res) return res;
446 const handlePtr = res.struct.handle;
447 freeResult(res.rawPtr);
448 @@ -1429,6 +1479,10 @@ var FileFinder = class _FileFinder {
449 handle;
450 /** Native ids of this instance's active watch subscriptions. */
451 watchers = /* @__PURE__ */ new Set();
452 + /** Patched in T3 Code: in-flight native-thread calls by function name. */
453 + nativeThreadCalls = /* @__PURE__ */ new Map();
454 + /** Patched in T3 Code: the last search queued on a native thread. */
455 + nativeSearchTail = null;
456 constructor(handle) {
457 this.handle = handle;
458 }
459 @@ -1485,11 +1539,147 @@ var FileFinder = class _FileFinder {
460 destroy() {
461 if (this.handle !== null) {
462 const handle = this.handle;
463 - ffiDestroy(handle);
464 + const watchers = this.watchers;
465 this.handle = null;
466 - ffiWatchCleanupAfterDestroy(handle, this.watchers);
467 - this.watchers.clear();
468 + this.watchers = /* @__PURE__ */ new Set();
469 + // Patched in T3 Code: freeing the handle waits on the picker lock, so it runs on a
470 + // native thread, after any native-thread call still using the handle.
471 + const release = () => ffiDestroy(handle).finally(() => {
472 + ffiWatchCleanupAfterDestroy(handle, watchers);
473 + });
474 + const pending = [...this.nativeThreadCalls.values()];
475 + if (this.nativeSearchTail) pending.push(this.nativeSearchTail);
476 + if (pending.length > 0) {
477 + Promise.allSettled(pending).then(release);
478 + } else {
479 + release();
480 + }
481 + }
482 + }
483 + /**
484 + * Patched in T3 Code: runs a handle-only call on a libuv pool thread so waiting on fff's
485 + * picker lock never blocks the JS thread. Concurrent callers share one call, so one finder
486 + * holds at most one pool thread per function.
487 + */
488 + callOnNativeThread(funcName, fromEnvelope) {
489 + const guard = this.ensureAlive();
490 + if (!guard.ok) return Promise.resolve(guard);
491 + const pending = this.nativeThreadCalls.get(funcName);
492 + if (pending) return pending;
493 + const call = readResultEnvelopeOnNativeThread(funcName, [DataType.External], [guard.value]).then(fromEnvelope, (cause) => err(String(cause))).finally(() => {
494 + this.nativeThreadCalls.delete(funcName);
495 + });
496 + this.nativeThreadCalls.set(funcName, call);
497 + return call;
498 + }
499 + /**
500 + * Patched in T3 Code: runs a search or subscription on a libuv pool thread. They run one at a
501 + * time per finder, so while fff's watcher holds the picker lock a finder holds at most one pool
502 + * thread.
503 + */
504 + searchOnNativeThread(search) {
505 + const guard = this.ensureAlive();
506 + if (!guard.ok) return Promise.resolve(guard);
507 + const call = (this.nativeSearchTail ?? Promise.resolve()).then(() => {
508 + const alive = this.ensureAlive();
509 + return alive.ok ? search(alive.value) : alive;
510 + }).catch((cause) => err(String(cause)));
511 + this.nativeSearchTail = call;
512 + call.finally(() => {
513 + if (this.nativeSearchTail === call) this.nativeSearchTail = null;
514 + });
515 + return call;
516 + }
517 + /** Patched in T3 Code: `fileSearch` without blocking the JS thread. */
518 + fileSearchAsync(query, options) {
519 + return this.searchOnNativeThread((handle) => ffiSearch(
520 + handle,
521 + query,
522 + options?.currentFile ?? "",
523 + options?.maxThreads ?? 0,
524 + options?.pageIndex ?? 0,
525 + options?.pageSize ?? 0,
526 + options?.comboBoostMultiplier ?? 0,
527 + options?.minComboCount ?? 0,
528 + true
529 + ));
530 + }
531 + /** Patched in T3 Code: `directorySearch` without blocking the JS thread. */
532 + directorySearchAsync(query, options) {
533 + return this.searchOnNativeThread((handle) => ffiSearchDirectories(
534 + handle,
535 + query,
536 + options?.currentFile ?? null,
537 + options?.maxThreads ?? 0,
538 + options?.pageIndex ?? 0,
539 + options?.pageSize ?? 0,
540 + true
541 + ));
542 + }
543 + /** Patched in T3 Code: `mixedSearch` without blocking the JS thread. */
544 + mixedSearchAsync(query, options) {
545 + return this.searchOnNativeThread((handle) => ffiSearchMixed(
546 + handle,
547 + query,
548 + options?.currentFile ?? "",
549 + options?.maxThreads ?? 0,
550 + options?.pageIndex ?? 0,
551 + options?.pageSize ?? 0,
552 + options?.comboBoostMultiplier ?? 0,
553 + options?.minComboCount ?? 0,
554 + true
555 + ));
556 + }
557 + /**
558 + * Patched in T3 Code: `watch` without blocking the JS thread. Subscribing takes the picker lock,
559 + * which fff's watcher holds while it indexes a new directory.
560 + */
561 + watchAsync(callback, options) {
562 + if (typeof callback !== "function") {
563 + return Promise.resolve(err("watch callback must be a function"));
564 }
565 + const ignore = options?.ignore ?? [];
566 + return this.searchOnNativeThread(async (handle) => {
567 + const registered = ensureWatchCallbackRegistered(handle);
568 + if (!registered.ok) return registered;
569 + const created = intResultFromEnvelope(await readResultEnvelopeOnNativeThread(
570 + "fff_watch_args",
571 + [DataType.External, DataType.String, DataType.StringArray, DataType.U32],
572 + [handle, "", ignore, ignore.length]
573 + ));
574 + if (!created.ok) return created;
575 + // fff_destroy drops the native subscription of a finder destroyed meanwhile.
576 + if (this.handle !== handle) return this.ensureAlive();
577 + const watchId = created.value;
578 + watchHandlers.set(watchId, callback);
579 + this.watchers.add(watchId);
580 + return {
581 + ok: true,
582 + value: () => {
583 + if (!this.watchers.delete(watchId)) return;
584 + if (this.handle !== null) ffiUnwatch(this.handle, watchId);
585 + }
586 + };
587 + });
588 + }
589 + /** Patched in T3 Code: `grep` without blocking the JS thread. */
590 + grepAsync(query, options) {
591 + return this.searchOnNativeThread((handle) => ffiLiveGrep(
592 + handle,
593 + query,
594 + options?.mode ?? "plain",
595 + options?.maxFileSize ?? 0,
596 + options?.maxMatchesPerFile ?? 0,
597 + options?.smartCase ?? true,
598 + options?.cursor?._offset ?? 0,
599 + options?.pageSize ?? 0,
600 + options?.timeBudgetMs ?? 0,
601 + options?.enforceTimeBudget ?? false,
602 + options?.beforeContext ?? 0,
603 + options?.afterContext ?? 0,
604 + options?.classifyDefinitions ?? false,
605 + true
606 + ));
607 }
608 /**
609 * Check if this instance has been destroyed.
610 @@ -1757,6 +1947,18 @@ var FileFinder = class _FileFinder {
611 if (!guard.ok) return guard;
612 return ffiScanFiles(guard.value);
613 }
614 + /**
615 + * Trigger a rescan without blocking the JS thread. Patched in T3 Code.
616 + */
617 + scanFilesAsync() {
618 + return this.callOnNativeThread("fff_scan_files", voidResultFromEnvelope);
619 + }
620 + /**
621 + * Read scan progress without blocking the JS thread. Patched in T3 Code.
622 + */
623 + getScanProgressAsync() {
624 + return this.callOnNativeThread("fff_get_scan_progress", scanProgressFromEnvelope);
625 + }
626 /**
627 * Check if a scan is currently in progress.
628 */
629 @@ -1838,7 +2040,8 @@ var FileFinder = class _FileFinder {
630 if (!guard.ok) return guard;
631 const deadline = Date.now() + timeoutMs;
632 while (true) {
633 - const progress = this.getScanProgress();
634 + // Patched in T3 Code: the progress read takes the picker lock.
635 + const progress = await this.getScanProgressAsync();
636 if (!progress.ok) return progress;
637 if (!progress.value.isScanning && progress.value.isWarmupComplete) {
638 return { ok: true, value: true };
639 diff --git a/package.json b/package.json
640 index e000a78b3f79826200979ebb3fe297b599bcea67..84325461c2d963cb42cf72267079d36a419c1398 100644
641 --- a/package.json
642 +++ b/package.json
643 @@ -11,7 +11,7 @@
644 ".": {
645 "types": "./dist/index.d.ts",
646 "import": "./dist/index.js",
647 - "require": "./dist/index.cjs",
648 + "require": "./dist/index.js",
649 "default": "./dist/index.js"
650 },
651 "./package.json": "./package.json"