@rekal/mem 0.0.0

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.
Files changed (80) hide show
  1. package/dist/db-BMh1OP4b.mjs +294 -0
  2. package/dist/doc-DnYN4jAU.mjs +116 -0
  3. package/dist/embed-rUMZxqed.mjs +100 -0
  4. package/dist/fs-DMp26Byo.mjs +32 -0
  5. package/dist/glob.d.mts +27 -0
  6. package/dist/glob.mjs +132 -0
  7. package/dist/index.d.mts +1465 -0
  8. package/dist/index.mjs +351 -0
  9. package/dist/llama-CT3dc9Cn.mjs +75 -0
  10. package/dist/models-DFQSgBNr.mjs +77 -0
  11. package/dist/openai-j2_2GM4J.mjs +76 -0
  12. package/dist/progress-B1JdNapX.mjs +263 -0
  13. package/dist/query-VFSpErTB.mjs +125 -0
  14. package/dist/runtime.node-DlQPaGrV.mjs +35 -0
  15. package/dist/search-BllHWtZF.mjs +166 -0
  16. package/dist/store-DE7S35SS.mjs +137 -0
  17. package/dist/transformers-CJ3QA2PK.mjs +55 -0
  18. package/dist/uri-CehXVDGB.mjs +28 -0
  19. package/dist/util-DNyrmcA3.mjs +11 -0
  20. package/dist/vfs-CNQbkhsf.mjs +222 -0
  21. package/foo.ts +3 -0
  22. package/foo2.ts +20 -0
  23. package/package.json +61 -0
  24. package/src/context.ts +77 -0
  25. package/src/db.ts +464 -0
  26. package/src/doc.ts +163 -0
  27. package/src/embed/base.ts +122 -0
  28. package/src/embed/index.ts +67 -0
  29. package/src/embed/llama.ts +111 -0
  30. package/src/embed/models.ts +104 -0
  31. package/src/embed/openai.ts +95 -0
  32. package/src/embed/transformers.ts +81 -0
  33. package/src/frecency.ts +58 -0
  34. package/src/fs.ts +36 -0
  35. package/src/glob.ts +163 -0
  36. package/src/index.ts +15 -0
  37. package/src/log.ts +60 -0
  38. package/src/md.ts +204 -0
  39. package/src/progress.ts +121 -0
  40. package/src/query.ts +131 -0
  41. package/src/runtime.bun.ts +33 -0
  42. package/src/runtime.node.ts +47 -0
  43. package/src/search.ts +230 -0
  44. package/src/snippet.ts +248 -0
  45. package/src/sqlite.ts +1 -0
  46. package/src/store.ts +180 -0
  47. package/src/uri.ts +28 -0
  48. package/src/util.ts +21 -0
  49. package/src/vfs.ts +257 -0
  50. package/test/doc.test.ts +61 -0
  51. package/test/fixtures/ignore-test/keep.md +0 -0
  52. package/test/fixtures/ignore-test/skip.log +0 -0
  53. package/test/fixtures/ignore-test/sub/keep.md +0 -0
  54. package/test/fixtures/store/agent/index.md +9 -0
  55. package/test/fixtures/store/agent/lessons.md +21 -0
  56. package/test/fixtures/store/agent/soul.md +28 -0
  57. package/test/fixtures/store/agent/tools.md +25 -0
  58. package/test/fixtures/store/concepts/frecency.md +30 -0
  59. package/test/fixtures/store/concepts/index.md +9 -0
  60. package/test/fixtures/store/concepts/memory-coherence.md +33 -0
  61. package/test/fixtures/store/concepts/rag.md +27 -0
  62. package/test/fixtures/store/index.md +9 -0
  63. package/test/fixtures/store/projects/index.md +9 -0
  64. package/test/fixtures/store/projects/rekall-inc/architecture.md +41 -0
  65. package/test/fixtures/store/projects/rekall-inc/decisions/index.md +9 -0
  66. package/test/fixtures/store/projects/rekall-inc/decisions/no-military.md +20 -0
  67. package/test/fixtures/store/projects/rekall-inc/index.md +28 -0
  68. package/test/fixtures/store/user/family.md +13 -0
  69. package/test/fixtures/store/user/index.md +9 -0
  70. package/test/fixtures/store/user/preferences.md +29 -0
  71. package/test/fixtures/store/user/profile.md +29 -0
  72. package/test/fs.test.ts +15 -0
  73. package/test/glob.test.ts +190 -0
  74. package/test/md.test.ts +177 -0
  75. package/test/query.test.ts +105 -0
  76. package/test/uri.test.ts +46 -0
  77. package/test/util.test.ts +62 -0
  78. package/test/vfs.test.ts +164 -0
  79. package/tsconfig.json +3 -0
  80. package/tsdown.config.ts +8 -0
@@ -0,0 +1,1465 @@
1
+ import * as _$node_fs0 from "node:fs";
2
+ import { EventEmitter } from "node:events";
3
+ import { inspect } from "node:util";
4
+ import { Database } from "bun:sqlite";
5
+
6
+ //#region ../../node_modules/.bun/type-fest@5.5.0/node_modules/type-fest/source/union-to-intersection.d.ts
7
+ /**
8
+ Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
9
+
10
+ Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
11
+
12
+ @example
13
+ ```
14
+ import type {UnionToIntersection} from 'type-fest';
15
+
16
+ type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
17
+
18
+ type Intersection = UnionToIntersection<Union>;
19
+ //=> {the(): void} & {great(arg: string): void} & {escape: boolean}
20
+ ```
21
+
22
+ @category Type
23
+ */
24
+ type UnionToIntersection<Union> = (// `extends unknown` is always going to be the case and is used to convert the
25
+ // `Union` into a [distributive conditional
26
+ // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
27
+ Union extends unknown // The union type is used as the only argument to a function since the union
28
+ // of function arguments is an intersection.
29
+ ? (distributedUnion: Union) => void // This won't happen.
30
+ : never // Infer the `Intersection` type since TypeScript represents the positional
31
+ // arguments of unions of functions as an intersection of the union.
32
+ ) extends ((mergedIntersection: infer Intersection) => void) // The `& Union` is to ensure result of `UnionToIntersection<A | B>` is always assignable to `A | B`
33
+ ? Intersection & Union : never;
34
+ //#endregion
35
+ //#region ../../node_modules/.bun/type-fest@5.5.0/node_modules/type-fest/source/keys-of-union.d.ts
36
+ /**
37
+ Create a union of all keys from a given type, even those exclusive to specific union members.
38
+
39
+ Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
40
+
41
+ @link https://stackoverflow.com/a/49402091
42
+
43
+ @example
44
+ ```
45
+ import type {KeysOfUnion} from 'type-fest';
46
+
47
+ type A = {
48
+ common: string;
49
+ a: number;
50
+ };
51
+
52
+ type B = {
53
+ common: string;
54
+ b: string;
55
+ };
56
+
57
+ type C = {
58
+ common: string;
59
+ c: boolean;
60
+ };
61
+
62
+ type Union = A | B | C;
63
+
64
+ type CommonKeys = keyof Union;
65
+ //=> 'common'
66
+
67
+ type AllKeys = KeysOfUnion<Union>;
68
+ //=> 'common' | 'a' | 'b' | 'c'
69
+ ```
70
+
71
+ @category Object
72
+ */
73
+ type KeysOfUnion<ObjectType> = // Hack to fix https://github.com/sindresorhus/type-fest/issues/1008
74
+ keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
75
+ //#endregion
76
+ //#region ../../node_modules/.bun/type-fest@5.5.0/node_modules/type-fest/source/is-any.d.ts
77
+ /**
78
+ Returns a boolean for whether the given type is `any`.
79
+
80
+ @link https://stackoverflow.com/a/49928360/1490091
81
+
82
+ Useful in type utilities, such as disallowing `any`s to be passed to a function.
83
+
84
+ @example
85
+ ```
86
+ import type {IsAny} from 'type-fest';
87
+
88
+ const typedObject = {a: 1, b: 2} as const;
89
+ const anyObject: any = {a: 1, b: 2};
90
+
91
+ function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {
92
+ return object[key];
93
+ }
94
+
95
+ const typedA = get(typedObject, 'a');
96
+ //=> 1
97
+
98
+ const anyA = get(anyObject, 'a');
99
+ //=> any
100
+ ```
101
+
102
+ @category Type Guard
103
+ @category Utilities
104
+ */
105
+ type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
106
+ //#endregion
107
+ //#region ../../node_modules/.bun/type-fest@5.5.0/node_modules/type-fest/source/is-optional-key-of.d.ts
108
+ /**
109
+ Returns a boolean for whether the given key is an optional key of type.
110
+
111
+ This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
112
+
113
+ @example
114
+ ```
115
+ import type {IsOptionalKeyOf} from 'type-fest';
116
+
117
+ type User = {
118
+ name: string;
119
+ surname: string;
120
+
121
+ luckyNumber?: number;
122
+ };
123
+
124
+ type Admin = {
125
+ name: string;
126
+ surname?: string;
127
+ };
128
+
129
+ type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
130
+ //=> true
131
+
132
+ type T2 = IsOptionalKeyOf<User, 'name'>;
133
+ //=> false
134
+
135
+ type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
136
+ //=> boolean
137
+
138
+ type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
139
+ //=> false
140
+
141
+ type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
142
+ //=> boolean
143
+ ```
144
+
145
+ @category Type Guard
146
+ @category Utilities
147
+ */
148
+ type IsOptionalKeyOf<Type extends object, Key extends keyof Type> = IsAny<Type | Key> extends true ? never : Key extends keyof Type ? Type extends Record<Key, Type[Key]> ? false : true : false;
149
+ //#endregion
150
+ //#region ../../node_modules/.bun/type-fest@5.5.0/node_modules/type-fest/source/optional-keys-of.d.ts
151
+ /**
152
+ Extract all optional keys from the given type.
153
+
154
+ This is useful when you want to create a new type that contains different type values for the optional keys only.
155
+
156
+ @example
157
+ ```
158
+ import type {OptionalKeysOf, Except} from 'type-fest';
159
+
160
+ type User = {
161
+ name: string;
162
+ surname: string;
163
+
164
+ luckyNumber?: number;
165
+ };
166
+
167
+ const REMOVE_FIELD = Symbol('remove field symbol');
168
+ type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
169
+ [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
170
+ };
171
+
172
+ const update1: UpdateOperation<User> = {
173
+ name: 'Alice',
174
+ };
175
+
176
+ const update2: UpdateOperation<User> = {
177
+ name: 'Bob',
178
+ luckyNumber: REMOVE_FIELD,
179
+ };
180
+ ```
181
+
182
+ @category Utilities
183
+ */
184
+ type OptionalKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
185
+ ? (keyof { [Key in keyof Type as IsOptionalKeyOf<Type, Key> extends false ? never : Key]: never }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
186
+ : never;
187
+ //#endregion
188
+ //#region ../../node_modules/.bun/type-fest@5.5.0/node_modules/type-fest/source/required-keys-of.d.ts
189
+ /**
190
+ Extract all required keys from the given type.
191
+
192
+ This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
193
+
194
+ @example
195
+ ```
196
+ import type {RequiredKeysOf} from 'type-fest';
197
+
198
+ declare function createValidation<
199
+ Entity extends object,
200
+ Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
201
+ >(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
202
+
203
+ type User = {
204
+ name: string;
205
+ surname: string;
206
+ luckyNumber?: number;
207
+ };
208
+
209
+ const validator1 = createValidation<User>('name', value => value.length < 25);
210
+ const validator2 = createValidation<User>('surname', value => value.length < 25);
211
+
212
+ // @ts-expect-error
213
+ const validator3 = createValidation<User>('luckyNumber', value => value > 0);
214
+ // Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
215
+ ```
216
+
217
+ @category Utilities
218
+ */
219
+ type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
220
+ ? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
221
+ //#endregion
222
+ //#region ../../node_modules/.bun/type-fest@5.5.0/node_modules/type-fest/source/is-never.d.ts
223
+ /**
224
+ Returns a boolean for whether the given type is `never`.
225
+
226
+ @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
227
+ @link https://stackoverflow.com/a/53984913/10292952
228
+ @link https://www.zhenghao.io/posts/ts-never
229
+
230
+ Useful in type utilities, such as checking if something does not occur.
231
+
232
+ @example
233
+ ```
234
+ import type {IsNever, And} from 'type-fest';
235
+
236
+ type A = IsNever<never>;
237
+ //=> true
238
+
239
+ type B = IsNever<any>;
240
+ //=> false
241
+
242
+ type C = IsNever<unknown>;
243
+ //=> false
244
+
245
+ type D = IsNever<never[]>;
246
+ //=> false
247
+
248
+ type E = IsNever<object>;
249
+ //=> false
250
+
251
+ type F = IsNever<string>;
252
+ //=> false
253
+ ```
254
+
255
+ @example
256
+ ```
257
+ import type {IsNever} from 'type-fest';
258
+
259
+ type IsTrue<T> = T extends true ? true : false;
260
+
261
+ // When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
262
+ type A = IsTrue<never>;
263
+ //=> never
264
+
265
+ // If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
266
+ type IsTrueFixed<T> =
267
+ IsNever<T> extends true ? false : T extends true ? true : false;
268
+
269
+ type B = IsTrueFixed<never>;
270
+ //=> false
271
+ ```
272
+
273
+ @category Type Guard
274
+ @category Utilities
275
+ */
276
+ type IsNever<T> = [T] extends [never] ? true : false;
277
+ //#endregion
278
+ //#region ../../node_modules/.bun/type-fest@5.5.0/node_modules/type-fest/source/if.d.ts
279
+ /**
280
+ An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
281
+
282
+ Use-cases:
283
+ - You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.
284
+
285
+ Note:
286
+ - Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.
287
+ - Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
288
+
289
+ @example
290
+ ```
291
+ import type {If} from 'type-fest';
292
+
293
+ type A = If<true, 'yes', 'no'>;
294
+ //=> 'yes'
295
+
296
+ type B = If<false, 'yes', 'no'>;
297
+ //=> 'no'
298
+
299
+ type C = If<boolean, 'yes', 'no'>;
300
+ //=> 'yes' | 'no'
301
+
302
+ type D = If<any, 'yes', 'no'>;
303
+ //=> 'yes' | 'no'
304
+
305
+ type E = If<never, 'yes', 'no'>;
306
+ //=> 'no'
307
+ ```
308
+
309
+ @example
310
+ ```
311
+ import type {If, IsAny, IsNever} from 'type-fest';
312
+
313
+ type A = If<IsAny<unknown>, 'is any', 'not any'>;
314
+ //=> 'not any'
315
+
316
+ type B = If<IsNever<never>, 'is never', 'not never'>;
317
+ //=> 'is never'
318
+ ```
319
+
320
+ @example
321
+ ```
322
+ import type {If, IsEqual} from 'type-fest';
323
+
324
+ type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
325
+
326
+ type A = IfEqual<string, string, 'equal', 'not equal'>;
327
+ //=> 'equal'
328
+
329
+ type B = IfEqual<string, number, 'equal', 'not equal'>;
330
+ //=> 'not equal'
331
+ ```
332
+
333
+ Note: Sometimes using the `If` type can make an implementation non–tail-recursive, which can impact performance. In such cases, it’s better to use a conditional directly. Refer to the following example:
334
+
335
+ @example
336
+ ```
337
+ import type {If, IsEqual, StringRepeat} from 'type-fest';
338
+
339
+ type HundredZeroes = StringRepeat<'0', 100>;
340
+
341
+ // The following implementation is not tail recursive
342
+ type Includes<S extends string, Char extends string> =
343
+ S extends `${infer First}${infer Rest}`
344
+ ? If<IsEqual<First, Char>,
345
+ 'found',
346
+ Includes<Rest, Char>>
347
+ : 'not found';
348
+
349
+ // Hence, instantiations with long strings will fail
350
+ // @ts-expect-error
351
+ type Fails = Includes<HundredZeroes, '1'>;
352
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
353
+ // Error: Type instantiation is excessively deep and possibly infinite.
354
+
355
+ // However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
356
+ type IncludesWithoutIf<S extends string, Char extends string> =
357
+ S extends `${infer First}${infer Rest}`
358
+ ? IsEqual<First, Char> extends true
359
+ ? 'found'
360
+ : IncludesWithoutIf<Rest, Char>
361
+ : 'not found';
362
+
363
+ // Now, instantiations with long strings will work
364
+ type Works = IncludesWithoutIf<HundredZeroes, '1'>;
365
+ //=> 'not found'
366
+ ```
367
+
368
+ @category Type Guard
369
+ @category Utilities
370
+ */
371
+ type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
372
+ //#endregion
373
+ //#region ../../node_modules/.bun/type-fest@5.5.0/node_modules/type-fest/source/simplify.d.ts
374
+ /**
375
+ Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
376
+
377
+ @example
378
+ ```
379
+ import type {Simplify} from 'type-fest';
380
+
381
+ type PositionProps = {
382
+ top: number;
383
+ left: number;
384
+ };
385
+
386
+ type SizeProps = {
387
+ width: number;
388
+ height: number;
389
+ };
390
+
391
+ // In your editor, hovering over `Props` will show a flattened object with all the properties.
392
+ type Props = Simplify<PositionProps & SizeProps>;
393
+ ```
394
+
395
+ Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
396
+
397
+ If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
398
+
399
+ @example
400
+ ```
401
+ import type {Simplify} from 'type-fest';
402
+
403
+ interface SomeInterface {
404
+ foo: number;
405
+ bar?: string;
406
+ baz: number | undefined;
407
+ }
408
+
409
+ type SomeType = {
410
+ foo: number;
411
+ bar?: string;
412
+ baz: number | undefined;
413
+ };
414
+
415
+ const literal = {foo: 123, bar: 'hello', baz: 456};
416
+ const someType: SomeType = literal;
417
+ const someInterface: SomeInterface = literal;
418
+
419
+ declare function fn(object: Record<string, unknown>): void;
420
+
421
+ fn(literal); // Good: literal object type is sealed
422
+ fn(someType); // Good: type is sealed
423
+ // @ts-expect-error
424
+ fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
425
+ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
426
+ ```
427
+
428
+ @link https://github.com/microsoft/TypeScript/issues/15300
429
+ @see {@link SimplifyDeep}
430
+ @category Object
431
+ */
432
+ type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
433
+ //#endregion
434
+ //#region ../../node_modules/.bun/type-fest@5.5.0/node_modules/type-fest/source/is-equal.d.ts
435
+ /**
436
+ Returns a boolean for whether the two given types are equal.
437
+
438
+ @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
439
+ @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
440
+
441
+ Use-cases:
442
+ - If you want to make a conditional branch based on the result of a comparison of two types.
443
+
444
+ @example
445
+ ```
446
+ import type {IsEqual} from 'type-fest';
447
+
448
+ // This type returns a boolean for whether the given array includes the given item.
449
+ // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
450
+ type Includes<Value extends readonly any[], Item> =
451
+ Value extends readonly [Value[0], ...infer rest]
452
+ ? IsEqual<Value[0], Item> extends true
453
+ ? true
454
+ : Includes<rest, Item>
455
+ : false;
456
+ ```
457
+
458
+ @category Type Guard
459
+ @category Utilities
460
+ */
461
+ type IsEqual<A, B> = [A] extends [B] ? [B] extends [A] ? _IsEqual<A, B> : false : false;
462
+ // This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
463
+ type _IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
464
+ //#endregion
465
+ //#region ../../node_modules/.bun/type-fest@5.5.0/node_modules/type-fest/source/omit-index-signature.d.ts
466
+ /**
467
+ Omit any index signatures from the given object type, leaving only explicitly defined properties.
468
+
469
+ This is the counterpart of `PickIndexSignature`.
470
+
471
+ Use-cases:
472
+ - Remove overly permissive signatures from third-party types.
473
+
474
+ This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
475
+
476
+ It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
477
+
478
+ (The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
479
+
480
+ ```
481
+ const indexed: Record<string, unknown> = {}; // Allowed
482
+
483
+ // @ts-expect-error
484
+ const keyed: Record<'foo', unknown> = {}; // Error
485
+ // TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
486
+ ```
487
+
488
+ Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
489
+
490
+ ```
491
+ type Indexed = {} extends Record<string, unknown>
492
+ ? '✅ `{}` is assignable to `Record<string, unknown>`'
493
+ : '❌ `{}` is NOT assignable to `Record<string, unknown>`';
494
+
495
+ type IndexedResult = Indexed;
496
+ //=> '✅ `{}` is assignable to `Record<string, unknown>`'
497
+
498
+ type Keyed = {} extends Record<'foo' | 'bar', unknown>
499
+ ? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
500
+ : '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
501
+
502
+ type KeyedResult = Keyed;
503
+ //=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`'
504
+ ```
505
+
506
+ Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
507
+
508
+ ```
509
+ type OmitIndexSignature<ObjectType> = {
510
+ [KeyType in keyof ObjectType // Map each key of `ObjectType`...
511
+ ]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
512
+ };
513
+ ```
514
+
515
+ ...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
516
+
517
+ ```
518
+ type OmitIndexSignature<ObjectType> = {
519
+ [KeyType in keyof ObjectType
520
+ // Is `{}` assignable to `Record<KeyType, unknown>`?
521
+ as {} extends Record<KeyType, unknown>
522
+ ? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
523
+ : KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
524
+ ]: ObjectType[KeyType];
525
+ };
526
+ ```
527
+
528
+ If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
529
+
530
+ @example
531
+ ```
532
+ import type {OmitIndexSignature} from 'type-fest';
533
+
534
+ type Example = {
535
+ // These index signatures will be removed.
536
+ [x: string]: any;
537
+ [x: number]: any;
538
+ [x: symbol]: any;
539
+ [x: `head-${string}`]: string;
540
+ [x: `${string}-tail`]: string;
541
+ [x: `head-${string}-tail`]: string;
542
+ [x: `${bigint}`]: string;
543
+ [x: `embedded-${number}`]: string;
544
+
545
+ // These explicitly defined keys will remain.
546
+ foo: 'bar';
547
+ qux?: 'baz';
548
+ };
549
+
550
+ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
551
+ //=> {foo: 'bar'; qux?: 'baz'}
552
+ ```
553
+
554
+ @see {@link PickIndexSignature}
555
+ @category Object
556
+ */
557
+ type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
558
+ //#endregion
559
+ //#region ../../node_modules/.bun/type-fest@5.5.0/node_modules/type-fest/source/pick-index-signature.d.ts
560
+ /**
561
+ Pick only index signatures from the given object type, leaving out all explicitly defined properties.
562
+
563
+ This is the counterpart of `OmitIndexSignature`.
564
+
565
+ @example
566
+ ```
567
+ import type {PickIndexSignature} from 'type-fest';
568
+
569
+ declare const symbolKey: unique symbol;
570
+
571
+ type Example = {
572
+ // These index signatures will remain.
573
+ [x: string]: unknown;
574
+ [x: number]: unknown;
575
+ [x: symbol]: unknown;
576
+ [x: `head-${string}`]: string;
577
+ [x: `${string}-tail`]: string;
578
+ [x: `head-${string}-tail`]: string;
579
+ [x: `${bigint}`]: string;
580
+ [x: `embedded-${number}`]: string;
581
+
582
+ // These explicitly defined keys will be removed.
583
+ ['kebab-case-key']: string;
584
+ [symbolKey]: string;
585
+ foo: 'bar';
586
+ qux?: 'baz';
587
+ };
588
+
589
+ type ExampleIndexSignature = PickIndexSignature<Example>;
590
+ // {
591
+ // [x: string]: unknown;
592
+ // [x: number]: unknown;
593
+ // [x: symbol]: unknown;
594
+ // [x: `head-${string}`]: string;
595
+ // [x: `${string}-tail`]: string;
596
+ // [x: `head-${string}-tail`]: string;
597
+ // [x: `${bigint}`]: string;
598
+ // [x: `embedded-${number}`]: string;
599
+ // }
600
+ ```
601
+
602
+ @see {@link OmitIndexSignature}
603
+ @category Object
604
+ */
605
+ type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
606
+ //#endregion
607
+ //#region ../../node_modules/.bun/type-fest@5.5.0/node_modules/type-fest/source/merge.d.ts
608
+ // Merges two objects without worrying about index signatures.
609
+ type SimpleMerge<Destination, Source> = Simplify<{ [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source>;
610
+ /**
611
+ Merge two types into a new type. Keys of the second type overrides keys of the first type.
612
+
613
+ This is different from the TypeScript `&` (intersection) operator. With `&`, conflicting property types are intersected, which often results in `never`. For example, `{a: string} & {a: number}` makes `a` become `string & number`, which resolves to `never`. With `Merge`, the second type's keys cleanly override the first, so `Merge<{a: string}, {a: number}>` gives `{a: number}` as expected. `Merge` also produces a flattened type (via `Simplify`), making it more readable in IDE tooltips compared to `A & B`.
614
+
615
+ @example
616
+ ```
617
+ import type {Merge} from 'type-fest';
618
+
619
+ type Foo = {
620
+ a: string;
621
+ b: number;
622
+ };
623
+
624
+ type Bar = {
625
+ a: number; // Conflicts with Foo['a']
626
+ c: boolean;
627
+ };
628
+
629
+ // With `&`, `a` becomes `string & number` which is `never`. Not what you want.
630
+ type WithIntersection = (Foo & Bar)['a'];
631
+ //=> never
632
+
633
+ // With `Merge`, `a` is cleanly overridden to `number`.
634
+ type WithMerge = Merge<Foo, Bar>['a'];
635
+ //=> number
636
+ ```
637
+
638
+ @example
639
+ ```
640
+ import type {Merge} from 'type-fest';
641
+
642
+ type Foo = {
643
+ [x: string]: unknown;
644
+ [x: number]: unknown;
645
+ foo: string;
646
+ bar: symbol;
647
+ };
648
+
649
+ type Bar = {
650
+ [x: number]: number;
651
+ [x: symbol]: unknown;
652
+ bar: Date;
653
+ baz: boolean;
654
+ };
655
+
656
+ export type FooBar = Merge<Foo, Bar>;
657
+ //=> {
658
+ // [x: string]: unknown;
659
+ // [x: number]: number;
660
+ // [x: symbol]: unknown;
661
+ // foo: string;
662
+ // bar: Date;
663
+ // baz: boolean;
664
+ // }
665
+ ```
666
+
667
+ Note: If you want a merge type that more accurately reflects the runtime behavior of object spread or `Object.assign`, refer to the {@link ObjectMerge} type.
668
+
669
+ @see {@link ObjectMerge}
670
+ @category Object
671
+ */
672
+ type Merge<Destination, Source> = Destination extends unknown // For distributing `Destination`
673
+ ? Source extends unknown // For distributing `Source`
674
+ ? If<IsEqual<Destination, Source>, Destination, _Merge<Destination, Source>> : never // Should never happen
675
+ : never;
676
+ // Should never happen
677
+ type _Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
678
+ //#endregion
679
+ //#region ../../node_modules/.bun/type-fest@5.5.0/node_modules/type-fest/source/internal/object.d.ts
680
+ /**
681
+ Works similar to the built-in `Pick` utility type, except for the following differences:
682
+ - Distributes over union types and allows picking keys from any member of the union type.
683
+ - Primitives types are returned as-is.
684
+ - Picks all keys if `Keys` is `any`.
685
+ - Doesn't pick `number` from a `string` index signature.
686
+
687
+ @example
688
+ ```
689
+ type ImageUpload = {
690
+ url: string;
691
+ size: number;
692
+ thumbnailUrl: string;
693
+ };
694
+
695
+ type VideoUpload = {
696
+ url: string;
697
+ duration: number;
698
+ encodingFormat: string;
699
+ };
700
+
701
+ // Distributes over union types and allows picking keys from any member of the union type
702
+ type MediaDisplay = HomomorphicPick<ImageUpload | VideoUpload, "url" | "size" | "duration">;
703
+ //=> {url: string; size: number} | {url: string; duration: number}
704
+
705
+ // Primitive types are returned as-is
706
+ type Primitive = HomomorphicPick<string | number, 'toUpperCase' | 'toString'>;
707
+ //=> string | number
708
+
709
+ // Picks all keys if `Keys` is `any`
710
+ type Any = HomomorphicPick<{a: 1; b: 2} | {c: 3}, any>;
711
+ //=> {a: 1; b: 2} | {c: 3}
712
+
713
+ // Doesn't pick `number` from a `string` index signature
714
+ type IndexSignature = HomomorphicPick<{[k: string]: unknown}, number>;
715
+ //=> {}
716
+ */
717
+ type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = { [P in keyof T as Extract<P, Keys>]: T[P] };
718
+ /**
719
+ Merges user specified options with default options.
720
+
721
+ @example
722
+ ```
723
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
724
+ type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
725
+ type SpecifiedOptions = {leavesOnly: true};
726
+
727
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
728
+ //=> {maxRecursionDepth: 10; leavesOnly: true}
729
+ ```
730
+
731
+ @example
732
+ ```
733
+ // Complains if default values are not provided for optional options
734
+
735
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
736
+ type DefaultPathsOptions = {maxRecursionDepth: 10};
737
+ type SpecifiedOptions = {};
738
+
739
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
740
+ // ~~~~~~~~~~~~~~~~~~~
741
+ // Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
742
+ ```
743
+
744
+ @example
745
+ ```
746
+ // Complains if an option's default type does not conform to the expected type
747
+
748
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
749
+ type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
750
+ type SpecifiedOptions = {};
751
+
752
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
753
+ // ~~~~~~~~~~~~~~~~~~~
754
+ // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
755
+ ```
756
+
757
+ @example
758
+ ```
759
+ // Complains if an option's specified type does not conform to the expected type
760
+
761
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
762
+ type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
763
+ type SpecifiedOptions = {leavesOnly: 'yes'};
764
+
765
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
766
+ // ~~~~~~~~~~~~~~~~
767
+ // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
768
+ ```
769
+ */
770
+ type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key]: SpecifiedOptions[Key] }> & Required<Options>>>>;
771
+ //#endregion
772
+ //#region ../../node_modules/.bun/type-fest@5.5.0/node_modules/type-fest/source/except.d.ts
773
+ /**
774
+ Filter out keys from an object.
775
+
776
+ Returns `never` if `Exclude` is strictly equal to `Key`.
777
+ Returns `never` if `Key` extends `Exclude`.
778
+ Returns `Key` otherwise.
779
+
780
+ @example
781
+ ```
782
+ type Filtered = Filter<'foo', 'foo'>;
783
+ //=> never
784
+ ```
785
+
786
+ @example
787
+ ```
788
+ type Filtered = Filter<'bar', string>;
789
+ //=> never
790
+ ```
791
+
792
+ @example
793
+ ```
794
+ type Filtered = Filter<'bar', 'foo'>;
795
+ //=> 'bar'
796
+ ```
797
+
798
+ @see {Except}
799
+ */
800
+ type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
801
+ type ExceptOptions = {
802
+ /**
803
+ Disallow assigning non-specified properties.
804
+ Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
805
+ @default false
806
+ */
807
+ requireExactProps?: boolean;
808
+ };
809
+ type DefaultExceptOptions = {
810
+ requireExactProps: false;
811
+ };
812
+ /**
813
+ Create a type from an object type without certain keys.
814
+
815
+ We recommend setting the `requireExactProps` option to `true`.
816
+
817
+ This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
818
+
819
+ This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
820
+
821
+ @example
822
+ ```
823
+ import type {Except} from 'type-fest';
824
+
825
+ type Foo = {
826
+ a: number;
827
+ b: string;
828
+ };
829
+
830
+ type FooWithoutA = Except<Foo, 'a'>;
831
+ //=> {b: string}
832
+
833
+ // @ts-expect-error
834
+ const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
835
+ // errors: 'a' does not exist in type '{ b: string; }'
836
+
837
+ type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
838
+ //=> {a: number} & Partial<Record<'b', never>>
839
+
840
+ // @ts-expect-error
841
+ const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
842
+ // errors at 'b': Type 'string' is not assignable to type 'undefined'.
843
+
844
+ // The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
845
+
846
+ // Consider the following example:
847
+
848
+ type UserData = {
849
+ [metadata: string]: string;
850
+ email: string;
851
+ name: string;
852
+ role: 'admin' | 'user';
853
+ };
854
+
855
+ // `Omit` clearly doesn't behave as expected in this case:
856
+ type PostPayload = Omit<UserData, 'email'>;
857
+ //=> {[x: string]: string; [x: number]: string}
858
+
859
+ // In situations like this, `Except` works better.
860
+ // It simply removes the `email` key while preserving all the other keys.
861
+ type PostPayloadFixed = Except<UserData, 'email'>;
862
+ //=> {[x: string]: string; name: string; role: 'admin' | 'user'}
863
+ ```
864
+
865
+ @category Object
866
+ */
867
+ type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
868
+ type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = { [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType] } & (Options['requireExactProps'] extends true ? Partial<Record<KeysType, never>> : {});
869
+ //#endregion
870
+ //#region ../../node_modules/.bun/type-fest@5.5.0/node_modules/type-fest/source/set-optional.d.ts
871
+ /**
872
+ Create a type that makes the given keys optional. The remaining keys are kept as is. The sister of the `SetRequired` type.
873
+
874
+ Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are optional.
875
+
876
+ @example
877
+ ```
878
+ import type {SetOptional} from 'type-fest';
879
+
880
+ type Foo = {
881
+ a: number;
882
+ b?: string;
883
+ c: boolean;
884
+ };
885
+
886
+ type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
887
+ //=> {a: number; b?: string; c?: boolean}
888
+ ```
889
+
890
+ @category Object
891
+ */
892
+ type SetOptional<BaseType, Keys extends keyof BaseType> = (BaseType extends ((...arguments_: never) => any) ? (...arguments_: Parameters<BaseType>) => ReturnType<BaseType> : unknown) & _SetOptional<BaseType, Keys>;
893
+ type _SetOptional<BaseType, Keys extends keyof BaseType> = BaseType extends unknown // To distribute `BaseType` when it's a union type.
894
+ ? Simplify< // Pick just the keys that are readonly from the base type.
895
+ Except<BaseType, Keys> & // Pick the keys that should be mutable from the base type and make them mutable.
896
+ Partial<HomomorphicPick<BaseType, Keys>>> : never;
897
+ //#endregion
898
+ //#region src/log.d.ts
899
+ type LogLevel = (typeof LOG_LEVELS)[number];
900
+ type LogFn<T = void> = (...msg: unknown[]) => T;
901
+ type Logger<T = void> = Record<LogLevel, LogFn<T>>;
902
+ declare const LOG_LEVELS: readonly ["cancel", "info", "success", "warn", "error", "debug", "fatal", "prompt", "log", "trace"];
903
+ declare function isLogLevel(level: string): level is LogLevel;
904
+ declare function shouldLog(level: string, minLevel?: LogLevel): boolean;
905
+ declare abstract class LoggerBase<T = void> implements Logger<T> {
906
+ cancel: LogFn<T>;
907
+ info: LogFn<T>;
908
+ success: LogFn<T>;
909
+ warn: LogFn<T>;
910
+ error: LogFn<T>;
911
+ debug: LogFn<T>;
912
+ fatal: LogFn<T>;
913
+ prompt: LogFn<T>;
914
+ log: LogFn<T>;
915
+ trace: LogFn<T>;
916
+ constructor();
917
+ protected abstract _log(level: LogLevel, ...msg: unknown[]): T;
918
+ }
919
+ //#endregion
920
+ //#region src/runtime.node.d.ts
921
+ declare function parseYaml(content: string): unknown;
922
+ //#endregion
923
+ //#region src/util.d.ts
924
+ declare function hash(content: string): string;
925
+ declare function toError(err: unknown): Error;
926
+ type Events = Record<string, unknown[]>;
927
+ type TypedEmitter<T extends Events> = {
928
+ on<K extends keyof T>(event: K, fn: (...args: T[K]) => void): TypedEmitter<T>;
929
+ off<K extends keyof T>(event: K, fn: (...args: T[K]) => void): TypedEmitter<T>;
930
+ once<K extends keyof T>(event: K, fn: (...args: T[K]) => void): TypedEmitter<T>;
931
+ emit<K extends keyof T>(event: K, ...args: T[K]): boolean;
932
+ };
933
+ //#endregion
934
+ //#region src/progress.d.ts
935
+ type ProgressOpts = {
936
+ max?: number;
937
+ status?: string;
938
+ value?: number;
939
+ };
940
+ type ProgressEvents = {
941
+ update: [progress: Progress];
942
+ done: [progress: Progress];
943
+ };
944
+ declare const Progress_base: new () => TypedEmitter<ProgressEvents>;
945
+ declare class Progress extends Progress_base {
946
+ #private;
947
+ name: string;
948
+ constructor(name: string, opts?: ProgressOpts);
949
+ get group(): boolean;
950
+ set(opts: ProgressOpts | number): this;
951
+ get status(): string;
952
+ set status(status: string);
953
+ set value(value: number);
954
+ get value(): number;
955
+ set max(max: number);
956
+ get max(): number;
957
+ get done(): boolean;
958
+ get ratio(): number;
959
+ get pct(): number;
960
+ stop(): void;
961
+ children(): Progress[];
962
+ child(name: string, opts?: ProgressOpts): Progress;
963
+ [inspect.custom](_depth: number, _options: object): string;
964
+ toString(indent?: number): string;
965
+ }
966
+ //#endregion
967
+ //#region src/md.d.ts
968
+ type MarkdownSection = {
969
+ content: string[];
970
+ context: string[]; /** full heading text with markdown syntax, e.g. "## Section 1.2" */
971
+ headingText: string; /** heading without markdown syntax, e.g. "Section 1.2" */
972
+ heading: string;
973
+ level: number;
974
+ offset: number;
975
+ };
976
+ type MarkdownDoc = {
977
+ body: string;
978
+ bodyOffset: number;
979
+ frontmatter: Frontmatter;
980
+ frontmatterText?: string;
981
+ sections: MarkdownSection[];
982
+ text: string;
983
+ };
984
+ type Frontmatter = Record<string, unknown>;
985
+ declare function parseFrontmatter(text: string): Omit<MarkdownDoc, "sections">;
986
+ declare function parseMarkdown(text: string): MarkdownDoc;
987
+ declare function parseSections(md: string): MarkdownSection[];
988
+ declare function chunkText(text: string, tok: TokenCounter, size?: number): string[];
989
+ declare function chunkMarkdown(md: string, tok: TokenCounter, size?: number): string[];
990
+ //#endregion
991
+ //#region src/doc.d.ts
992
+ type DocFrontmatter = {
993
+ description?: string;
994
+ tags?: string[];
995
+ entities?: string[];
996
+ } & Frontmatter;
997
+ type DocHeading = {
998
+ level: number;
999
+ text: string;
1000
+ };
1001
+ declare class Doc {
1002
+ #private;
1003
+ uri: string;
1004
+ path: string;
1005
+ hash: string;
1006
+ updated: Date;
1007
+ headings: DocHeading[];
1008
+ parsed: MarkdownDoc;
1009
+ protected constructor(uri: string, path: string);
1010
+ /** Full original markdown text, including frontmatter. */
1011
+ get text(): string;
1012
+ /** Markdown body without frontmatter. */
1013
+ get body(): string;
1014
+ /** Parsed frontmatter as an object. */
1015
+ get fm(): DocFrontmatter;
1016
+ /** Name of the doc, derived from the file or folder name, without extension */
1017
+ get name(): string;
1018
+ get $description(): string | undefined;
1019
+ /** Desc from frontmatter or packed from headings. */
1020
+ get description(): string | undefined;
1021
+ /** Title from fontmatter or first heading */
1022
+ get $title(): string | undefined;
1023
+ /** `$title` if it doesn't contain the name, otherwise `name - $title` */
1024
+ get title(): string;
1025
+ get tags(): string[];
1026
+ get entities(): string[];
1027
+ get isDir(): boolean;
1028
+ protected load(): Promise<Doc | undefined>;
1029
+ static load(entry: string | VfsEntry): Promise<Doc | undefined>;
1030
+ static load(uri: string, path?: string): Promise<Doc | undefined>;
1031
+ }
1032
+ //#endregion
1033
+ //#region src/vfs.d.ts
1034
+ declare class Node {
1035
+ uri: string;
1036
+ doc: Doc;
1037
+ constructor(uri: string, doc: Doc);
1038
+ }
1039
+ type VfsFolder = {
1040
+ uri: string;
1041
+ path: string;
1042
+ merge?: boolean;
1043
+ };
1044
+ type VfsEntry = {
1045
+ uri: string;
1046
+ path?: string;
1047
+ };
1048
+ type VfsPath = {
1049
+ node: VfsNode;
1050
+ path: string;
1051
+ };
1052
+ type VfsNode = {
1053
+ name: string;
1054
+ parent?: VfsNode;
1055
+ uri: string;
1056
+ paths: string[];
1057
+ depth: number;
1058
+ children: Map<string, VfsNode>;
1059
+ };
1060
+ type VfsFindOptions = {
1061
+ /** URI to start from, defaults to root */uri?: string;
1062
+ depth?: number;
1063
+ pattern?: string;
1064
+ ignoreCase?: boolean;
1065
+ limit?: number;
1066
+ type?: "file" | "directory";
1067
+ };
1068
+ type VfsView = {
1069
+ uri: string;
1070
+ node: VfsNode;
1071
+ paths: VfsPath[];
1072
+ };
1073
+ type VfsScope = VfsView & {
1074
+ map: (path: string) => string | undefined;
1075
+ };
1076
+ declare class Vfs {
1077
+ #private;
1078
+ ctx: Context;
1079
+ constructor(ctx: Context);
1080
+ get folders(): VfsFolder[];
1081
+ isFolder(path: string): boolean;
1082
+ getScope(uri?: string, opts?: {
1083
+ children?: boolean;
1084
+ }): VfsScope;
1085
+ getNode(uri: string, create?: boolean): VfsNode;
1086
+ resolve(node: VfsNode | string, opts?: {
1087
+ children?: boolean;
1088
+ }): VfsView;
1089
+ addFolder(folder: VfsFolder): void;
1090
+ matcher(opts?: VfsFindOptions): (uri: string) => boolean;
1091
+ find(opts?: VfsFindOptions): AsyncGenerator<VfsEntry>;
1092
+ ls(opts?: Omit<VfsFindOptions, "depth">): AsyncGenerator<VfsEntry, void, any>;
1093
+ /** Normalizes the URI and path to a real path if it exists **/
1094
+ normPath(p: VfsPath): VfsEntry;
1095
+ }
1096
+ //#endregion
1097
+ //#region src/search.d.ts
1098
+ type SearchMode = "hybrid" | "vec" | "fts";
1099
+ type SearchScore = {
1100
+ score: number;
1101
+ display_score?: number;
1102
+ rank: number;
1103
+ };
1104
+ type SearchResult = {
1105
+ uri: string;
1106
+ path: string;
1107
+ doc: DocRow;
1108
+ scores: Partial<Record<SearchMode, SearchScore>>;
1109
+ match: {
1110
+ fts?: FTSResult;
1111
+ vec?: VecResult;
1112
+ };
1113
+ } & VfsEntry;
1114
+ type SearchResultMap = {
1115
+ hybrid: HybridSR;
1116
+ vec: VecSR;
1117
+ fts: FtsSR;
1118
+ };
1119
+ type HybridSR = SearchResult & {
1120
+ scores: {
1121
+ hybrid: SearchScore;
1122
+ };
1123
+ };
1124
+ type VecSR = SearchResult & {
1125
+ scores: {
1126
+ vec: SearchScore;
1127
+ };
1128
+ match: {
1129
+ vec: VecResult;
1130
+ };
1131
+ };
1132
+ type FtsSR = SearchResult & {
1133
+ scores: {
1134
+ fts: SearchScore;
1135
+ };
1136
+ match: {
1137
+ fts: FTSResult;
1138
+ };
1139
+ };
1140
+ type SearchOptions = {
1141
+ limit?: number;
1142
+ uri?: string;
1143
+ mode?: SearchMode;
1144
+ };
1145
+ type FtsSearchOptions = Omit<SearchOptions, "mode"> & {
1146
+ op?: "AND" | "OR";
1147
+ };
1148
+ declare class Search {
1149
+ db: Db;
1150
+ ctx: Context;
1151
+ private constructor();
1152
+ static load(ctx: Context): Promise<Search>;
1153
+ search(query: string, opts?: SearchOptions): Promise<SearchResult[]>;
1154
+ searchVec(query: string, opts?: Omit<SearchOptions, "mode"> & {
1155
+ slice?: boolean;
1156
+ }): Promise<VecSR[]>;
1157
+ searchFts(query: string, opts?: FtsSearchOptions): Promise<FtsSR[]>;
1158
+ rank<M extends SearchMode>(mode: M, results: SearchResultMap[M][]): SearchResultMap[M][];
1159
+ /** Reciprocal Rank Fusion: merge FTS and vector results */
1160
+ private fuse;
1161
+ }
1162
+ //#endregion
1163
+ //#region src/store.d.ts
1164
+ type StoreChunk = EmbedderChunk & {
1165
+ doc_id: number;
1166
+ doc: Doc;
1167
+ };
1168
+ declare class Store {
1169
+ db: Db;
1170
+ ctx: Context;
1171
+ private constructor();
1172
+ static load(ctx: Context): Promise<Store>;
1173
+ add(doc: Doc): number;
1174
+ chunk(id: number, doc: Doc): Promise<StoreChunk[]>;
1175
+ index(): Promise<Map<number, Doc>>;
1176
+ embed(docs: Map<number, Doc>): Promise<void>;
1177
+ sync(opts?: {
1178
+ embed?: boolean;
1179
+ }): Promise<void>;
1180
+ prune(syncStart: string): Promise<void>;
1181
+ }
1182
+ //#endregion
1183
+ //#region src/context.d.ts
1184
+ type ContextEvents = {
1185
+ log: [level: LogLevel, ...msg: unknown[]];
1186
+ progress: [progress: Progress];
1187
+ };
1188
+ type ContextOptions = {
1189
+ embedder?: EmbedderOptions;
1190
+ folders?: VfsFolder[];
1191
+ root?: string;
1192
+ };
1193
+ declare class Context extends LoggerBase {
1194
+ #private;
1195
+ opts: ContextOptions;
1196
+ events: TypedEmitter<ContextEvents> & EventEmitter;
1197
+ constructor(opts?: ContextOptions);
1198
+ protected _log(level: LogLevel, ...msg: unknown[]): void;
1199
+ get root(): string;
1200
+ db(): Promise<Db>;
1201
+ search(): Promise<Search>;
1202
+ store(): Promise<Store>;
1203
+ embedder(): Promise<Embedder>;
1204
+ vfs(): Promise<Vfs>;
1205
+ }
1206
+ //#endregion
1207
+ //#region src/embed/base.d.ts
1208
+ declare class Embedder {
1209
+ #private;
1210
+ ctx: Context;
1211
+ opts: ResolvedEmbedderOptions;
1212
+ model: ResolvedEmbedderModel;
1213
+ status: Progress;
1214
+ constructor(ctx: Context);
1215
+ info(): {
1216
+ model: string;
1217
+ backend: ModelBackend;
1218
+ variant?: string;
1219
+ };
1220
+ backend(): Promise<EmbedderBackend>;
1221
+ transform(input: string | EmbedderDoc | EmbedderChunk): string;
1222
+ embed(input: string | EmbedderDoc | EmbedderChunk): Promise<number[]>;
1223
+ embed(input: (string | EmbedderDoc | EmbedderChunk)[]): Promise<number[][]>;
1224
+ chunk(input: string | EmbedderDoc): Promise<EmbedderChunk[]>;
1225
+ }
1226
+ //#endregion
1227
+ //#region src/embed/index.d.ts
1228
+ type TokenCounter = {
1229
+ toks(input: string): number;
1230
+ };
1231
+ type EmbedderDevice = "cpu" | "gpu" | "api";
1232
+ interface EmbedderBackend extends TokenCounter {
1233
+ device: EmbedderDevice;
1234
+ maxTokens: number;
1235
+ dims: number;
1236
+ embed(input: string[]): Promise<number[][]>;
1237
+ }
1238
+ type EmbedderDoc = {
1239
+ text: string;
1240
+ title?: string;
1241
+ };
1242
+ type EmbedderPrompt = {
1243
+ document?: (doc: EmbedderDoc) => string;
1244
+ query?: (query: string) => string;
1245
+ };
1246
+ type EmbedderModel = {
1247
+ uri: string;
1248
+ base?: string;
1249
+ models?: string[];
1250
+ prompt?: EmbedderPrompt;
1251
+ pooling?: "none" | "mean" | "cls" | "first_token" | "eos" | "last_token";
1252
+ };
1253
+ type ModelBackend = "transformers" | "llama" | "openai";
1254
+ type EmbedderContext = {
1255
+ opts: ResolvedEmbedderOptions;
1256
+ root: string;
1257
+ status: Progress;
1258
+ logger: Logger;
1259
+ };
1260
+ type EmbedderChunk = {
1261
+ seq: number;
1262
+ text: string;
1263
+ prompt: string;
1264
+ embedding?: number[];
1265
+ };
1266
+ type EmbedderOptions = {
1267
+ batchSize?: number;
1268
+ model?: EmbedderModel | string;
1269
+ maxTokens?: number;
1270
+ maxDims?: number;
1271
+ threads?: number;
1272
+ useGpu?: boolean;
1273
+ onProgress?: (status: Progress) => void;
1274
+ };
1275
+ type ResolvedEmbedderModel = Merge<EmbedderModel, {
1276
+ prompt: Required<EmbedderPrompt>;
1277
+ }>;
1278
+ type ResolvedEmbedderOptions = Merge<SetOptional<Required<EmbedderOptions>, "onProgress">, {
1279
+ model: ResolvedEmbedderModel;
1280
+ }>;
1281
+ //#endregion
1282
+ //#region src/db.d.ts
1283
+ type DocRow = {
1284
+ id: number;
1285
+ path: string;
1286
+ hash: string;
1287
+ body: string;
1288
+ vec_hash?: string;
1289
+ description: string;
1290
+ title: string;
1291
+ tags: string;
1292
+ entities: string;
1293
+ updated_at: string;
1294
+ synced_at?: string;
1295
+ deadline?: number;
1296
+ };
1297
+ type VecResult = {
1298
+ doc_id: number;
1299
+ path: string;
1300
+ seq: number;
1301
+ distance: number;
1302
+ score: number;
1303
+ rank?: number;
1304
+ };
1305
+ type FTSResult = {
1306
+ rowid: number;
1307
+ score: number;
1308
+ rank?: number;
1309
+ };
1310
+ type DbSearchOptions = {
1311
+ limit?: number;
1312
+ scope?: string[];
1313
+ };
1314
+ declare function hasEmbedding<T extends EmbedderChunk>(c: T): c is T & {
1315
+ embedding: number[];
1316
+ };
1317
+ declare function assertEmbeddings<T extends EmbedderChunk>(chunks: T[]): asserts chunks is (T & {
1318
+ embedding: number[];
1319
+ })[];
1320
+ declare class Db {
1321
+ #private;
1322
+ private constructor();
1323
+ static load(dbPath: string): Promise<Db>;
1324
+ private init;
1325
+ reset(): void;
1326
+ private initVec;
1327
+ getDoc(from: string | number): DocRow | undefined;
1328
+ getDocs(from?: (string | number)[]): Map<number, DocRow>;
1329
+ addDoc(row: Omit<DocRow, "id">): number;
1330
+ deleteDoc(id: number, tables?: {
1331
+ docs?: boolean;
1332
+ vec?: boolean;
1333
+ }): void;
1334
+ get vec(): {
1335
+ exists: boolean;
1336
+ dims?: number;
1337
+ init?: boolean;
1338
+ };
1339
+ getStatus(): {
1340
+ cache: number;
1341
+ dbSize: number;
1342
+ docs: number;
1343
+ docsWithDescription: number;
1344
+ lastSync: string | null;
1345
+ unembedded: number;
1346
+ vecDims: number | undefined;
1347
+ vecs: number;
1348
+ vocabTerms: number;
1349
+ };
1350
+ transaction<A extends any[], T>(fn: (...args: A) => T): {
1351
+ (...args: A): T;
1352
+ deferred: (...args: A) => T;
1353
+ immediate: (...args: A) => T;
1354
+ exclusive: (...args: A) => T;
1355
+ };
1356
+ getUnembeddedDocs(): DocRow[];
1357
+ touchDoc(id: number): void;
1358
+ markEmbedded(id: number, docHash: string): void;
1359
+ /** Delete docs not seen since the given sync timestamp, optionally scoped to a path prefix. */
1360
+ deleteStaleDocs(syncedBefore: string, prefix?: string): number;
1361
+ /** Scoped FTS search: only match docs whose path starts with one of the given prefixes */
1362
+ searchFts(query: string, opts?: DbSearchOptions): FTSResult[];
1363
+ /** * Gets weights for high-frequency terms.
1364
+ * Note: Truly common words will result in an IDF of 0 or less.
1365
+ */
1366
+ getStopWords(): Map<string, number>;
1367
+ getWeights(terms: string[]): number[];
1368
+ /** Insert embeddings into the vec table */
1369
+ insertEmbeddings(chunks: StoreChunk[]): void;
1370
+ /** Delete all vec entries for a doc */
1371
+ deleteEmbeddings(docId: number): void;
1372
+ /** Global KNN search, returns top results across all docs */
1373
+ searchVec(embedding: number[], opts?: DbSearchOptions): VecResult[];
1374
+ setDeadline(docId: number, deadline: number): void;
1375
+ getMeta(key: string): string | undefined;
1376
+ setMeta(key: string, value: string): void;
1377
+ cacheGet<T>(key: string): T | undefined;
1378
+ cacheSet<T>(key: string, value: T): T;
1379
+ cachePrune(maxEntries?: number): void;
1380
+ }
1381
+ //#endregion
1382
+ //#region src/fs.d.ts
1383
+ declare function sstat(path: string): _$node_fs0.Stats | undefined;
1384
+ declare function astat(path: string): Promise<_$node_fs0.Stats | undefined>;
1385
+ declare function findUp(root: string, name: string, stop?: string): string | undefined;
1386
+ declare function normPath(...paths: string[]): string;
1387
+ declare function gitRoot(path: string): string | undefined;
1388
+ //#endregion
1389
+ //#region src/query.d.ts
1390
+ type Token$1 = {
1391
+ type: "term";
1392
+ value: string;
1393
+ neg?: boolean;
1394
+ req?: boolean;
1395
+ field?: string;
1396
+ } | {
1397
+ type: "op";
1398
+ value: "AND" | "OR";
1399
+ } | {
1400
+ type: "paren";
1401
+ value: "(" | ")";
1402
+ };
1403
+ declare function tokenize(input: string): Token$1[];
1404
+ /** Build an FTS5 query string from user input */
1405
+ declare function toFts(input: string, defaultOp?: "AND" | "OR"): string;
1406
+ //#endregion
1407
+ //#region src/uri.d.ts
1408
+ declare const URI_PREFIX = "rekal://";
1409
+ declare function assertUri(uri: string): void;
1410
+ declare function normUri(uri?: string, dir?: boolean): string;
1411
+ declare function parentUri(uri: string): string | undefined;
1412
+ //#endregion
1413
+ //#region src/snippet.d.ts
1414
+ type Token = {
1415
+ text: string;
1416
+ lower: string;
1417
+ };
1418
+ type TokenWithScore = Token & {
1419
+ score: number;
1420
+ };
1421
+ type SnippetOptions = {
1422
+ query: string;
1423
+ lines?: number;
1424
+ stopWords?: Map<string, number>;
1425
+ };
1426
+ type SnippetWindow = {
1427
+ start: number;
1428
+ heat: number;
1429
+ coverage: number;
1430
+ score: number;
1431
+ };
1432
+ type SnippetResult = {
1433
+ lines: string[];
1434
+ tokens: Token[][];
1435
+ scores: number[];
1436
+ windows: SnippetWindow[];
1437
+ best: SnippetWindow;
1438
+ heat: number[];
1439
+ snippet: string[];
1440
+ };
1441
+ declare const WORD_REGEX: RegExp;
1442
+ declare function isStopWord(word: string): boolean;
1443
+ declare class Snippet {
1444
+ query: (Token & {
1445
+ score: number;
1446
+ })[];
1447
+ prefixes: Set<string>;
1448
+ prefixRegex: RegExp;
1449
+ opts: Required<SnippetOptions>;
1450
+ constructor(opts: SnippetOptions);
1451
+ normalize(text: string): string;
1452
+ tokenize(text: string, queryOnly?: boolean): Token[];
1453
+ score(token: Token, queryToken: Token): number;
1454
+ match(input: Token | string): TokenWithScore | undefined;
1455
+ scores(tokens: Token[][]): {
1456
+ coverage: Set<string>[];
1457
+ scores: number[];
1458
+ };
1459
+ heat(lines: string[], scores: number[]): number[];
1460
+ extract(text: string): SnippetResult;
1461
+ debug(result: SnippetResult): void;
1462
+ highlight(text: string, hl: (word: string, offset: number) => string): string;
1463
+ }
1464
+ //#endregion
1465
+ export { Context, ContextOptions, type Database, Db, DbSearchOptions, Doc, DocFrontmatter, DocRow, Embedder, EmbedderBackend, EmbedderChunk, EmbedderContext, EmbedderDevice, EmbedderDoc, EmbedderModel, EmbedderOptions, EmbedderPrompt, Events, FTSResult, Frontmatter, FtsSR, FtsSearchOptions, HybridSR, LOG_LEVELS, LogFn, LogLevel, Logger, LoggerBase, MarkdownDoc, MarkdownSection, ModelBackend, Node, Progress, ProgressOpts, ResolvedEmbedderModel, ResolvedEmbedderOptions, Search, SearchMode, SearchOptions, SearchResult, SearchScore, Snippet, SnippetOptions, SnippetResult, SnippetWindow, Store, StoreChunk, Token, TokenCounter, TokenWithScore, TypedEmitter, URI_PREFIX, VecResult, VecSR, Vfs, VfsEntry, VfsFindOptions, VfsFolder, VfsNode, VfsPath, VfsScope, VfsView, WORD_REGEX, assertEmbeddings, assertUri, astat, chunkMarkdown, chunkText, findUp, gitRoot, hasEmbedding, hash, isLogLevel, isStopWord, normPath, normUri, parentUri, parseFrontmatter, parseMarkdown, parseSections, parseYaml, shouldLog, sstat, toError, toFts, tokenize };