@ff-labs/fff-bun 0.10.4-nightly.e2cad2f → 0.10.5-dev.2a477d2

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.
package/dist/ffi.d.ts ADDED
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Bun FFI bindings for the fff-c native library
3
+ *
4
+ * This module uses Bun's native FFI to call into the Rust C library.
5
+ * All functions follow the Result pattern for error handling.
6
+ *
7
+ * The API is instance-based: `ffiCreate` returns an opaque handle that must
8
+ * be passed to all subsequent calls and freed with `ffiDestroy`.
9
+ */
10
+ import { type JSCallback, type Pointer } from "bun:ffi";
11
+ import type { DirSearchResult, GrepResult, MixedSearchResult, Result, ScanProgress, SearchResult, WatchEvent } from "./fff-api";
12
+ /**
13
+ * Opaque native handle type. Callers must not inspect or modify this value.
14
+ */
15
+ export type NativeHandle = Pointer;
16
+ /**
17
+ * Create a new file finder instance.
18
+ *
19
+ * Hand-encodes a [`FffCreateOptions`] struct (88 bytes, locked offsets — see
20
+ * `crates/fff-c/src/ffi_types.rs::options_layout_tests`) into a Buffer and
21
+ * passes its pointer to `fff_create_instance_with`. Inner cstring addresses
22
+ * come from Bun's native `ptr(buffer)` primitive — no round-trip helpers,
23
+ * no struct support gaps.
24
+ *
25
+ * Adding new options later means: (1) appending the field to
26
+ * `FffCreateOptions` in Rust, (2) bumping `FFF_CREATE_OPTIONS_VERSION`,
27
+ * (3) extending `FFF_CREATE_OPTIONS_SIZE` + offsets here. The C entry point
28
+ * never changes.
29
+ */
30
+ export declare function ffiCreate(basePath: string, frecencyDbPath: string, historyDbPath: string, _useUnsafeNoLock: boolean, enableMmapCache: boolean, enableContentIndexing: boolean, watch: boolean, aiMode: boolean, logFilePath: string, logLevel: string, cacheBudgetMaxFiles: bigint, cacheBudgetMaxBytes: bigint, cacheBudgetMaxFileSize: bigint, enableFsRootScanning: boolean, enableHomeDirScanning: boolean): Result<NativeHandle>;
31
+ /**
32
+ * Destroy and clean up an instance.
33
+ */
34
+ export declare function ffiDestroy(handle: NativeHandle): void;
35
+ /**
36
+ * Perform fuzzy search.
37
+ */
38
+ export declare function ffiSearch(handle: NativeHandle, query: string, currentFile: string, maxThreads: number, pageIndex: number, pageSize: number, comboBoostMultiplier: number, minComboCount: number): Result<SearchResult>;
39
+ /**
40
+ * Glob-only search. Bypasses the regular query parser, applies the pattern
41
+ * as a single `Constraint::Glob`, ranks by frecency, paginates.
42
+ */
43
+ export declare function ffiGlob(handle: NativeHandle, pattern: string, currentFile: string, maxThreads: number, pageIndex: number, pageSize: number): Result<SearchResult>;
44
+ /**
45
+ * Perform fuzzy directory search.
46
+ */
47
+ export declare function ffiSearchDirectories(handle: NativeHandle, query: string, currentFile: string | null, maxThreads: number, pageIndex: number, pageSize: number): Result<DirSearchResult>;
48
+ /**
49
+ * Perform mixed (files + directories) fuzzy search.
50
+ */
51
+ export declare function ffiSearchMixed(handle: NativeHandle, query: string, currentFile: string, maxThreads: number, pageIndex: number, pageSize: number, comboBoostMultiplier: number, minComboCount: number): Result<MixedSearchResult>;
52
+ /**
53
+ * Live grep - search file contents.
54
+ */
55
+ export declare function ffiLiveGrep(handle: NativeHandle, query: string, mode: string, maxFileSize: number, maxMatchesPerFile: number, smartCase: boolean, fileOffset: number, pageLimit: number, timeBudgetMs: number, beforeContext: number, afterContext: number, classifyDefinitions: boolean): Result<GrepResult>;
56
+ /**
57
+ * Multi-pattern grep - Aho-Corasick multi-needle search.
58
+ */
59
+ export declare function ffiMultiGrep(handle: NativeHandle, patternsJoined: string, constraints: string, maxFileSize: number, maxMatchesPerFile: number, smartCase: boolean, fileOffset: number, pageLimit: number, timeBudgetMs: number, beforeContext: number, afterContext: number, classifyDefinitions: boolean): Result<GrepResult>;
60
+ /**
61
+ * Trigger file scan.
62
+ */
63
+ export declare function ffiScanFiles(handle: NativeHandle): Result<void>;
64
+ /**
65
+ * Check if scanning.
66
+ */
67
+ export declare function ffiIsScanning(handle: NativeHandle): boolean;
68
+ /**
69
+ * Get the base path of the file picker.
70
+ */
71
+ export declare function ffiGetBasePath(handle: NativeHandle): Result<string | null>;
72
+ /**
73
+ * Get scan progress.
74
+ */
75
+ export declare function ffiGetScanProgress(handle: NativeHandle): Result<ScanProgress>;
76
+ /**
77
+ * Wait for scan to complete.
78
+ */
79
+ export declare function ffiWaitForScan(handle: NativeHandle, timeoutMs: number): Result<boolean>;
80
+ /**
81
+ * Restart index in new path.
82
+ */
83
+ export declare function ffiRestartIndex(handle: NativeHandle, newPath: string): Result<void>;
84
+ /**
85
+ * Parse an FffWatchEventBatch delivered to a watch callback, then free it.
86
+ * Ownership of the batch transfers to JS at callback time, so this MUST be
87
+ * called exactly once per delivered batch pointer.
88
+ */
89
+ export declare function readWatchEventBatch(batchPtr: Pointer | number | null): WatchEvent[];
90
+ /**
91
+ * Register the instance-wide watch callback. Must be called before the
92
+ * first `ffiWatch`. The caller owns `callback` (a threadsafe `JSCallback`
93
+ * built in finder.ts) and must keep it alive until after `ffiDestroy`
94
+ * returns for this handle — that call is the delivery quiescence barrier.
95
+ */
96
+ export declare function ffiSetWatchCallback(handle: NativeHandle, callback: JSCallback): Result<void>;
97
+ /**
98
+ * Subscribe to filesystem changes; batches are delivered through the
99
+ * instance callback registered with `ffiSetWatchCallback`, tagged with the
100
+ * watch id this function returns.
101
+ *
102
+ * @returns The native watch id carried in `FffResult.int_value`.
103
+ */
104
+ export declare function ffiWatch(handle: NativeHandle, pattern: string, ignore?: string[]): Result<number>;
105
+ /**
106
+ * Remove a watch subscription. Returns true if the id was found.
107
+ */
108
+ export declare function ffiUnwatch(handle: NativeHandle, watchId: number): Result<boolean>;
109
+ /**
110
+ * Refresh git status.
111
+ */
112
+ export declare function ffiRefreshGitStatus(handle: NativeHandle): Result<number>;
113
+ /**
114
+ * Track query completion.
115
+ */
116
+ export declare function ffiTrackQuery(handle: NativeHandle, query: string, filePath: string): Result<boolean>;
117
+ /**
118
+ * Get historical query.
119
+ */
120
+ export declare function ffiGetHistoricalQuery(handle: NativeHandle, offset: number): Result<string | null>;
121
+ /**
122
+ * Health check.
123
+ *
124
+ * `handle` can be null for a limited check (version + git only).
125
+ */
126
+ export declare function ffiHealthCheck(handle: NativeHandle | null, testPath: string): Result<unknown>;
127
+ /**
128
+ * Ensure the library is loaded.
129
+ *
130
+ * Loads the native library from the platform-specific npm package
131
+ * or a local dev build. Throws if the binary is not found.
132
+ */
133
+ export declare function ensureLoaded(): void;
134
+ /**
135
+ * Check if the library is available.
136
+ */
137
+ export declare function isAvailable(): boolean;
138
+ //# sourceMappingURL=ffi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ffi.d.ts","sourceRoot":"","sources":["../src/ffi.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAIL,KAAK,UAAU,EACf,KAAK,OAAO,EAGb,MAAM,SAAS,CAAC;AAGjB,OAAO,KAAK,EAEV,eAAe,EAGf,UAAU,EAGV,iBAAiB,EACjB,MAAM,EACN,YAAY,EAEZ,YAAY,EACZ,UAAU,EAEX,MAAM,WAAW,CAAC;AAwdnB;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC;AAEnC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CACvB,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EACtB,aAAa,EAAE,MAAM,EACrB,gBAAgB,EAAE,OAAO,EACzB,eAAe,EAAE,OAAO,EACxB,qBAAqB,EAAE,OAAO,EAC9B,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,mBAAmB,EAAE,MAAM,EAC3B,mBAAmB,EAAE,MAAM,EAC3B,sBAAsB,EAAE,MAAM,EAC9B,oBAAoB,EAAE,OAAO,EAC7B,qBAAqB,EAAE,OAAO,GAC7B,MAAM,CAAC,YAAY,CAAC,CAoDtB;AAiBD;;GAEG;AACH,wBAAgB,UAAU,C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AED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,UAAU,GACnB,MAAM,CAAC,IAAI,CAAC,CAOd;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,MAAM,EAAO,GACpB,MAAM,CAAC,MAAM,CAAC,CAyBhB;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAIjF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,CAIxE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,MAAM,CAAC,OAAO,CAAC,CAQjB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,GACb,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,CAIvB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,YAAY,GAAG,IAAI,EAC3B,QAAQ,EAAE,MAAM,GACf,MAAM,CAAC,OAAO,CAAC,CAOjB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI,IAAI,CAEnC;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,OAAO,CAOrC"}
@@ -0,0 +1,378 @@
1
+ /**
2
+ * FileFinder - High-level API for the fff file finder
3
+ *
4
+ * This class provides a type-safe, ergonomic API for file finding operations.
5
+ * Each instance owns an independent native file picker that can be created
6
+ * and destroyed independently. Multiple instances can coexist.
7
+ *
8
+ * All methods return Result types for explicit error handling.
9
+ */
10
+ import type { DirSearchOptions, DirSearchResult, InitOptions as FFFInitOptions, FileFinderApi, GlobOptions, GrepOptions, GrepResult, HealthCheck, MixedSearchResult, MultiGrepOptions, Result, ScanProgress, SearchOptions, SearchResult, WatchBatchCallback, WatchOptions, WatchUnsubscribe } from "./fff-api";
11
+ /**
12
+ * FileFinder - Fast file finder with fuzzy search
13
+ *
14
+ * Each instance is backed by an independent native file picker. Create as many
15
+ * as you need and destroy them when done.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { FileFinder } from "fff";
20
+ *
21
+ * // Create an instance
22
+ * const finder = FileFinder.create({ basePath: "/path/to/project" });
23
+ * if (!finder.ok) {
24
+ * console.error(finder.error);
25
+ * process.exit(1);
26
+ * }
27
+ *
28
+ * // Wait for initial scan
29
+ * await finder.value.waitForScan(5000);
30
+ *
31
+ * // Search for files
32
+ * const search = finder.value.search("main.ts");
33
+ * if (search.ok) {
34
+ * for (const item of search.value.items) {
35
+ * console.log(item.relativePath);
36
+ * }
37
+ * }
38
+ *
39
+ * // Cleanup
40
+ * finder.value.destroy();
41
+ * ```
42
+ */
43
+ export declare class FileFinder implements FileFinderApi {
44
+ private handle;
45
+ /** Active watch subscriptions: native watch id -> JS batch handler. */
46
+ private watchHandlers;
47
+ /**
48
+ * ONE threadsafe JSCallback per instance, registered lazily with
49
+ * `fff_set_watch_callback` on the first subscription and closed in
50
+ * `destroy()` after `fff_destroy` returns (the quiescence barrier).
51
+ */
52
+ private watchJsCallback;
53
+ private constructor();
54
+ /**
55
+ * Create a new file finder instance.
56
+ *
57
+ * @param options - Initialization options
58
+ * @returns Result containing the new FileFinder instance or an error
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * // Basic initialization
63
+ * const finder = FileFinder.create({ basePath: "/path/to/project" });
64
+ *
65
+ * // With custom database paths
66
+ * const finder = FileFinder.create({
67
+ * basePath: "/path/to/project",
68
+ * frecencyDbPath: "/custom/frecency.mdb",
69
+ * historyDbPath: "/custom/history.mdb",
70
+ * });
71
+ * ```
72
+ */
73
+ static create(options: FFFInitOptions): Result<FileFinder>;
74
+ /**
75
+ * Destroy and clean up all resources.
76
+ *
77
+ * Frees the native instance (unsubscribing all watches), then closes the
78
+ * instance watch trampoline. After calling this, the instance must not be
79
+ * used again.
80
+ */
81
+ destroy(): void;
82
+ /**
83
+ * Check if this instance has been destroyed.
84
+ */
85
+ get isDestroyed(): boolean;
86
+ /**
87
+ * Guard that returns an error if the instance has been destroyed.
88
+ */
89
+ private ensureAlive;
90
+ /**
91
+ * Search for files matching the query.
92
+ *
93
+ * The query supports fuzzy matching and special syntax:
94
+ * - `foo bar` - Match files containing "foo" and "bar"
95
+ * - `src/` - Match files in src directory
96
+ * - `file.ts:42` - Match file.ts with line 42
97
+ * - `file.ts:42:10` - Match file.ts with line 42, column 10
98
+ *
99
+ * @param query - Search query string
100
+ * @param options - Search options
101
+ * @returns Search results with matched files and scores
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const result = finder.search("main.ts", { pageSize: 10 });
106
+ * if (result.ok) {
107
+ * console.log(`Found ${result.value.totalMatched} files`);
108
+ * for (const item of result.value.items) {
109
+ * console.log(item.relativePath);
110
+ * }
111
+ * }
112
+ * ```
113
+ */
114
+ fileSearch(query: string, options?: SearchOptions): Result<SearchResult>;
115
+ /**
116
+ * Glob-only search.
117
+ *
118
+ * The pattern is applied as a single pass SIMD optimized prefiltering
119
+ * without any fuzzy matching involved. Faster and 100% compatible to npm `glob`.
120
+ *
121
+ * @param pattern - Glob pattern (required, non-empty)
122
+ * @param options - Glob search options (pagination, max threads, current file)
123
+ * @returns Search results with files matching the glob
124
+ */
125
+ glob(pattern: string, options?: GlobOptions): Result<SearchResult>;
126
+ /**
127
+ * Search for directories matching the query.
128
+ *
129
+ * @param query - Search query string
130
+ * @param options - Directory search options
131
+ * @returns Search results with matched directories and scores
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const result = finder.directorySearch("components", { pageSize: 10 });
136
+ * if (result.ok) {
137
+ * console.log(`Found ${result.value.totalMatched} directories`);
138
+ * for (const item of result.value.items) {
139
+ * console.log(item.relativePath);
140
+ * }
141
+ * }
142
+ * ```
143
+ */
144
+ directorySearch(query: string, options?: DirSearchOptions): Result<DirSearchResult>;
145
+ /**
146
+ * Search for files and directories together (mixed search).
147
+ *
148
+ * Results are interleaved by total score in descending order.
149
+ *
150
+ * @param query - Search query string
151
+ * @param options - Search options
152
+ * @returns Mixed search results with files and directories interleaved by score
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * const result = finder.mixedSearch("main", { pageSize: 20 });
157
+ * if (result.ok) {
158
+ * for (const entry of result.value.items) {
159
+ * if (entry.type === "file") {
160
+ * console.log(`File: ${entry.item.relativePath}`);
161
+ * } else {
162
+ * console.log(`Dir: ${entry.item.relativePath}`);
163
+ * }
164
+ * }
165
+ * }
166
+ * ```
167
+ */
168
+ mixedSearch(query: string, options?: SearchOptions): Result<MixedSearchResult>;
169
+ /**
170
+ * Search file contents (live grep).
171
+ *
172
+ * Searches through the contents of indexed files using the specified mode:
173
+ * - `"plain"` (default): SIMD-accelerated literal text matching
174
+ * - `"regex"`: Regular expression matching
175
+ * - `"fuzzy"`: Smith-Waterman fuzzy matching per line
176
+ *
177
+ * Supports pagination for large result sets. The result includes a `nextCursor`
178
+ * that can be passed back to fetch the next page.
179
+ *
180
+ * The query also supports constraint syntax:
181
+ * - `*.ts pattern` - Only search in TypeScript files
182
+ * - `src/ pattern` - Only search in the src directory
183
+ *
184
+ * @param query - Search query string
185
+ * @param options - Grep options (mode, pagination, limits)
186
+ * @returns Grep results with matched lines and file metadata
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * // First page
191
+ * const result = finder.grep("TODO", { mode: "plain" });
192
+ * if (result.ok) {
193
+ * for (const match of result.value.items) {
194
+ * console.log(`${match.relativePath}:${match.lineNumber}: ${match.lineContent}`);
195
+ * }
196
+ * // Fetch next page
197
+ * if (result.value.nextCursor) {
198
+ * const page2 = finder.grep("TODO", {
199
+ * cursor: result.value.nextCursor,
200
+ * });
201
+ * }
202
+ * }
203
+ * ```
204
+ */
205
+ grep(query: string, options?: GrepOptions): Result<GrepResult>;
206
+ /**
207
+ * Multi-pattern OR search using Aho-Corasick.
208
+ *
209
+ * Searches for lines matching ANY of the provided patterns using
210
+ * SIMD-accelerated multi-needle matching. Faster than regex alternation
211
+ * for literal text searches.
212
+ *
213
+ * Supports pagination. The result includes a `nextCursor` that can be
214
+ * passed back to fetch the next page.
215
+ *
216
+ * @param options - Multi-grep options including patterns and optional constraints
217
+ * @returns Grep results with matched lines and file metadata
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * const result = finder.multiGrep({
222
+ * patterns: ["VideoFrame", "video_frame", "PreloadedImage"],
223
+ * });
224
+ * if (result.ok) {
225
+ * for (const match of result.value.items) {
226
+ * console.log(`${match.relativePath}:${match.lineNumber}: ${match.lineContent}`);
227
+ * }
228
+ * }
229
+ * ```
230
+ */
231
+ multiGrep(options: MultiGrepOptions): Result<GrepResult>;
232
+ /**
233
+ * Trigger a rescan of the indexed directory.
234
+ *
235
+ * This is useful after major file system changes that the
236
+ * background watcher might have missed.
237
+ */
238
+ scanFiles(): Result<void>;
239
+ /**
240
+ * Check if a scan is currently in progress.
241
+ */
242
+ isScanning(): boolean;
243
+ /**
244
+ * Get the base path of the file picker (the root directory being indexed).
245
+ */
246
+ getBasePath(): Result<string | null>;
247
+ /**
248
+ * Get the current scan progress.
249
+ */
250
+ getScanProgress(): Result<ScanProgress>;
251
+ /**
252
+ * Wait for the initial file scan to complete.
253
+ *
254
+ * Non-blocking: polls `isScanning` and yields to the event loop between
255
+ * checks, so other async work keeps running while waiting.
256
+ *
257
+ * @param timeoutMs - Maximum time to wait in milliseconds (default: 5000)
258
+ * @returns true if scan completed, false if timed out
259
+ *
260
+ * @example
261
+ * ```typescript
262
+ * const finder = FileFinder.create({ basePath: "/path/to/project" });
263
+ * if (finder.ok) {
264
+ * const completed = await finder.value.waitForScan(10000);
265
+ * if (!completed.ok || !completed.value) {
266
+ * console.warn("Scan did not complete in time");
267
+ * }
268
+ * }
269
+ * ```
270
+ */
271
+ waitForScan(timeoutMs?: number): Promise<Result<boolean>>;
272
+ /**
273
+ * Wait for the initial file scan to complete, blocking the calling thread.
274
+ *
275
+ * Backed by the native `fff_wait_for_scan` call. Prefer {@link waitForScan}
276
+ * unless you specifically need synchronous blocking behaviour.
277
+ *
278
+ * @param timeoutMs - Maximum time to wait in milliseconds (default: 5000)
279
+ * @returns true if scan completed, false if timed out
280
+ */
281
+ waitForScanBlocking(timeoutMs?: number): Result<boolean>;
282
+ /**
283
+ * Wait until the index is fully ready: the scan has finished and the warmup
284
+ * (content indexing / bigram) phase has completed.
285
+ *
286
+ * Non-blocking — polls `getScanProgress` and yields to the event loop.
287
+ *
288
+ * @param timeoutMs - Maximum time to wait in milliseconds (default: 5000)
289
+ * @returns true if the index became ready, false if timed out
290
+ */
291
+ waitForIndexReady(timeoutMs?: number): Promise<Result<boolean>>;
292
+ /**
293
+ * Change the indexed directory to a new path.
294
+ *
295
+ * This stops the current file watcher and starts indexing the new directory.
296
+ *
297
+ * @param newPath - New directory path to index
298
+ */
299
+ reindex(newPath: string): Result<void>;
300
+ /**
301
+ * Refresh the git status cache.
302
+ *
303
+ * @returns Number of files with updated git status
304
+ */
305
+ refreshGitStatus(): Result<number>;
306
+ /**
307
+ * Track query completion for smart suggestions.
308
+ *
309
+ * Call this when a user selects a file from search results.
310
+ * This helps improve future search rankings for similar queries.
311
+ *
312
+ * @param query - The search query that was used
313
+ * @param selectedFilePath - The file path that was selected
314
+ */
315
+ trackQuery(query: string, selectedFilePath: string): Result<boolean>;
316
+ /**
317
+ * Get a historical query by offset.
318
+ *
319
+ * @param offset - Offset from most recent (0 = most recent)
320
+ * @returns The historical query string, or null if not found
321
+ */
322
+ getHistoricalQuery(offset: number): Result<string | null>;
323
+ /**
324
+ * Lazily create + register the instance-wide watch trampoline. Routes
325
+ * every delivered batch to the handler registered for its watch id;
326
+ * unknown ids (unsubscribe races) are benign — the batch is just freed.
327
+ */
328
+ private ensureWatchTrampoline;
329
+ /**
330
+ * Subscribe to filesystem changes matching `pattern` (glob, exact file,
331
+ * or directory subtree). Omit the pattern to watch the entire indexed
332
+ * tree. Normalized batches of up to 128 events are delivered on the JS event
333
+ * loop, with each path appearing at most once. See `FileFinderApi.watch`.
334
+ *
335
+ * @example
336
+ * ```typescript
337
+ * const sub = finder.watch("**\/*.ts", (events) => {
338
+ * for (const e of events) console.log(e.kind, e.path);
339
+ * });
340
+ * if (sub.ok) sub.value(); // unsubscribe
341
+ *
342
+ * // no pattern: everything under the indexed base path
343
+ * const all = finder.watch((events) => console.log(events.length));
344
+ * ```
345
+ */
346
+ watch(callback: WatchBatchCallback, options?: WatchOptions): Result<WatchUnsubscribe>;
347
+ watch(pattern: string, callback: WatchBatchCallback, options?: WatchOptions): Result<WatchUnsubscribe>;
348
+ /**
349
+ * Remove a subscription from the routing map, then from the native side.
350
+ * Map removal is synchronous on the JS thread, so once this returns the
351
+ * handler can never run again (late native batches miss the lookup).
352
+ * Idempotent.
353
+ */
354
+ private unwatchById;
355
+ /**
356
+ * Get health check information.
357
+ *
358
+ * Useful for debugging and verifying the file finder is working correctly.
359
+ *
360
+ * @param testPath - Optional path to test git repository detection
361
+ */
362
+ healthCheck(testPath?: string): Result<HealthCheck>;
363
+ /**
364
+ * Check if the native library is available.
365
+ */
366
+ static isAvailable(): boolean;
367
+ /** Ensure the native library is loaded. */
368
+ static ensureLoaded(): void;
369
+ /**
370
+ * Get a health check without requiring an instance.
371
+ *
372
+ * Returns limited info (version + git only, no picker/frecency/query data).
373
+ *
374
+ * @param testPath - Optional path to test git repository detection
375
+ */
376
+ static healthCheckStatic(testPath?: string): Result<HealthCheck>;
377
+ }
378
+ //# sourceMappingURL=finder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"finder.d.ts","sourceRoot":"","sources":["../src/finder.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAgCH,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,WA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O,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC,gBAAgB,CAAC;IACrF,KAAK,CACH,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,CAAC,EAAE,YAAY,GACrB,MAAM,CAAC,gBAAgB,CAAC;IAqC3B;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAOnB;;;;;;OAMG;IACH,WAAW,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC;IAInD;;OAEG;IACH,MAAM,CAAC,WAAW,IAAI,OAAO;IAI7B,2CAA2C;IAC3C,MAAM,CAAC,YAAY,IAAI,IAAI;IAI3B;;;;;;OAMG;IACH,MAAM,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC;CAGjE"}
@@ -0,0 +1,5 @@
1
+ export { binaryExists, findBinary } from "./download";
2
+ export type { DbHealth, DirItem, DirSearchOptions, DirSearchResult, err, FileFinderApi, FileItem, GrepCursor, GrepMatch, GrepMode, GrepOptions, GrepResult, HealthCheck, InitOptions, Location, MixedItem, MixedSearchResult, MultiGrepOptions, ok, Result, ScanProgress, Score, SearchOptions, SearchResult, WatchBatchCallback, WatchEvent, WatchEventKind, WatchOptions, WatchUnsubscribe, } from "./fff-api";
3
+ export { FileFinder } from "./finder";
4
+ export { getLibExtension, getLibFilename, getNpmPackageName, getTriple, } from "./platform";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACtD,YAAY,EACV,QAAQ,EACR,OAAO,EACP,gBAAgB,EAChB,eAAe,EACf,GAAG,EACH,aAAa,EACb,QAAQ,EACR,UAAU,EACV,SAAS,EACT,QAAQ,EACR,WAAW,EACX,UAAU,EACV,WAAW,EACX,WAAW,EACX,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,EAAE,EACF,MAAM,EACN,YAAY,EACZ,KAAK,EACL,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,UAAU,EACV,cAAc,EACd,YAAY,EACZ,gBAAgB,GACjB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EACL,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,SAAS,GACV,MAAM,YAAY,CAAC"}